Commit Graph

33 Commits

Author SHA1 Message Date
Daryl Koopersmith 1b42cd449c Media: Use correct variable name. see #21390.
git-svn-id: https://develop.svn.wordpress.org/trunk@22666 602fd350-edb4-49c9-b593-d223f7449a82
2012-11-19 06:43:01 +00:00
Daryl Koopersmith 5b426eac50 Media: Optimize media models.
* Merge `Composite` model with general `Attachments` model, as `Attachments.validate` and `Composite.evaluate` were functionally equivalent.
* Queries should only watch `wp.Uploader.queue`, as watching `Attachments.all` results in queries attempting to add attachments before their properties are set (which then results a few too many irrelevant adds/removes). `Attachments.all` should potentially be removed or rethought.

see #21390.


git-svn-id: https://develop.svn.wordpress.org/trunk@22655 602fd350-edb4-49c9-b593-d223f7449a82
2012-11-19 02:43:10 +00:00
Daryl Koopersmith 5c2e5e3231 Media: Remove redundant sorting logic from composite models. see #21390.
git-svn-id: https://develop.svn.wordpress.org/trunk@22654 602fd350-edb4-49c9-b593-d223f7449a82
2012-11-19 02:00:01 +00:00
Daryl Koopersmith 4a96fa19a4 Media: Only show the edit selection link for the media library. Make the upload attachments list sortable. Only retain the `silent` option when running `Attachments.validate()`. see #21390.
git-svn-id: https://develop.svn.wordpress.org/trunk@22597 602fd350-edb4-49c9-b593-d223f7449a82
2012-11-15 03:09:35 +00:00
Daryl Koopersmith 57e98a72d2 Media: Convert templates to use a data variable instead of with statements. see #21390.
git-svn-id: https://develop.svn.wordpress.org/trunk@22578 602fd350-edb4-49c9-b593-d223f7449a82
2012-11-14 21:51:41 +00:00
Daryl Koopersmith 57b09463e6 Media: Add backwards compatibility for attachment_fields_to_edit and attachment_fields_to_save. see #22186.
git-svn-id: https://develop.svn.wordpress.org/trunk@22541 602fd350-edb4-49c9-b593-d223f7449a82
2012-11-11 01:26:42 +00:00
Daryl Koopersmith 747016b9d5 Media templates: Alter escaping regular expression to prevent it from aggresively consuming input meant for interpolation. see #22344, #21390.
git-svn-id: https://develop.svn.wordpress.org/trunk@22539 602fd350-edb4-49c9-b593-d223f7449a82
2012-11-10 21:38:14 +00:00
Daryl Koopersmith 847a00f84b Media: Backwards compatibility for media_upload_tabs.
* Adds `createIframeStates()` to the `MediaFrame` view. It creates states and bindings for the `media_upload_tabs` output, and is included on `MediaFrame.Post` by default.
* Hijacks `tb_remove()` when the media modal is open to ensure the modal closes correctly.
* Adds a `chromeless` parameter to thickbox media tab URLs to render the UI without the old row of tabs.

see #22186, #21390.


git-svn-id: https://develop.svn.wordpress.org/trunk@22523 602fd350-edb4-49c9-b593-d223f7449a82
2012-11-10 07:51:37 +00:00
Daryl Koopersmith 63dd1ca518 Media JS: Use basic upload/library by default.
`wp.media` now recognizes the `frame` attribute (currently a string; either'select' or 'post') and defaults to using a basic select frame. It also checks for the existence of classes in a safer fashion, as it does not assume the `MediaFrame` property exists.

see #21390.


git-svn-id: https://develop.svn.wordpress.org/trunk@22495 602fd350-edb4-49c9-b593-d223f7449a82
2012-11-09 09:59:36 +00:00
Daryl Koopersmith 1401ee7928 Media: Add a basic starting frame for upload/library selection.
`media.view.MediaFrame.Select` is a frame class with a handful of sensible defaults to handle selecting and uploading items in the media library.

see #21390.


git-svn-id: https://develop.svn.wordpress.org/trunk@22494 602fd350-edb4-49c9-b593-d223f7449a82
2012-11-09 09:47:12 +00:00
Daryl Koopersmith 8f79cdaea4 Media JS: Add JIT composite library creation/destruction to states to allow for dynamically excluded Attachment models. see #21390.
git-svn-id: https://develop.svn.wordpress.org/trunk@22477 602fd350-edb4-49c9-b593-d223f7449a82
2012-11-09 01:23:20 +00:00
Daryl Koopersmith cf75c68b55 Media JS: Add media.model.Composite, to aid in the representation of joint views. see #21390.
git-svn-id: https://develop.svn.wordpress.org/trunk@22467 602fd350-edb4-49c9-b593-d223f7449a82
2012-11-08 15:32:40 +00:00
Daryl Koopersmith b636e94e47 Media: Integrate the gallery workflow with the media menu.
`wp.media.model.Query.more()`
* If a request has already been sent out for more attachments, return that request object instead of creating another.

`wp.media.controller.Region`
* A region allows views to be swapped in and out of a section of the page without either view having to know about the other.
* Application components can use the same callbacks and resources by leveraging `Region.mode()`, which triggers a set of callbacks to create or transform the current view, but only if necessary.

`wp.media.view.Frame`
* Leverage `Region` controllers instead of forcing states to swap view objects, which causes states to fit more comfortably in the controller-camp.
* Add `previous()`, a method to fetch the previous state `id`.
* Separate out the default settings over several objects (so blank frames can be instantiated).

`wp.media.view.MediaFrame`
* The base `Frame` used for media management: handles integration with the `Modal` and `UploaderWindow` views.

`wp.media.view.MediaFrame.Post`
* Includes all default media states and callbacks necessary for inserting media into a post.

see #21390.


git-svn-id: https://develop.svn.wordpress.org/trunk@22437 602fd350-edb4-49c9-b593-d223f7449a82
2012-11-07 20:14:41 +00:00
Daryl Koopersmith c0ab768faa Use Mustache-insipired template tags.
Underscore's default ERB-style templates are incompatible with PHP when asp_tags is enabled. As a result, we've settled on an alternative syntax that should be familiar to devs: Mustache-inspired for interpolating and escaping content, and ERB-inspired for execution.

	`{{{a}}}` - interpolating
	`{{ a }}` - escaping
	`<# a #>` - execution

props rmccue. fixes #22344, see #21390.


git-svn-id: https://develop.svn.wordpress.org/trunk@22415 602fd350-edb4-49c9-b593-d223f7449a82
2012-11-07 08:41:17 +00:00
Daryl Koopersmith ee6bda8ddd Media JS: Improve handling of single attachments in selections.
* Adds `wp.media.model.Selection.single()` to specify a single item used in a multi-item selection.
* Fixes a bug where the `details` class would not be removed when "Clear Selection" was clicked.

see #21390.


git-svn-id: https://develop.svn.wordpress.org/trunk@22335 602fd350-edb4-49c9-b593-d223f7449a82
2012-10-30 23:15:16 +00:00
Daryl Koopersmith bc29728df2 Add attachment details to the media sidebar.
* Also moves most of the `Frame` view's `createSelection` method to a real `Selection` model (which inherits from the `Attachments` model).
* Properly assigns the library within the `Gallery` state, allowing for the `Gallery` state to inherit from the `Library` state.

see #21390.


git-svn-id: https://develop.svn.wordpress.org/trunk@22323 602fd350-edb4-49c9-b593-d223f7449a82
2012-10-29 15:13:02 +00:00
Daryl Koopersmith 15c451d2f6 Give media a heart transplant.
Revises the concept of the media controller and workspace views (i.e. two central points of control) to be more granular. The main media object is now the `Frame`, which is a hybrid view and state machine.

The state machine is a collection of states, which are just generic instances of `Backbone.Model`. This circumvents the problem of juggling global parameters when changing states. Each state contains its own event loop. All events are also forwarded to the frame itself (as is the case in all model/collection relationships).

The frame view contains several regions, each of which can be overridden without harming or re-rendering the other regions. These work well when used in conjunction with the state machine events.

This removes the upload sidebar (don't worry, visible upload UI will return). Drag and drop uploading still works. The ability to upload has been abstracted into its own view (instead of being attached to the central workspace view).

Editing galleries is temporarily broken — the gallery creation and editing experiences will be unified in a future patch.

Adds events to detect dragging changes in `wp.Uploader` and adds methods to detect and leverage browser support for CSS3 transitions.

see #21390, #21809.


git-svn-id: https://develop.svn.wordpress.org/trunk@22320 602fd350-edb4-49c9-b593-d223f7449a82
2012-10-28 23:29:17 +00:00
Daryl Koopersmith 990d50661c Add a nonce to wp_ajax_save_attachment. see #21390, #21807.
git-svn-id: https://develop.svn.wordpress.org/trunk@22212 602fd350-edb4-49c9-b593-d223f7449a82
2012-10-12 16:02:45 +00:00
Daryl Koopersmith d27568e703 Caption editing in the media modal library.
* Adds a `describe` option to the workflow controller to support inline caption editing.
* For images, descriptions are mapped to the `caption` attribute.
* For other media items, descriptions are mapped to the `title` attribute.
* Descriptions are saved when the textarea's `change` event fires (i.e. when the textarea is blurred).

fixes #21807, see #21390.


git-svn-id: https://develop.svn.wordpress.org/trunk@22173 602fd350-edb4-49c9-b593-d223f7449a82
2012-10-10 23:32:48 +00:00
Jon Cave a2a8f675da Remove allowed query args before checking isEmpty() in Query model. See #21390.
git-svn-id: https://develop.svn.wordpress.org/trunk@22149 602fd350-edb4-49c9-b593-d223f7449a82
2012-10-09 22:55:49 +00:00
Daryl Koopersmith 91a3c62b3f Better thumbnail previews in the image editor.
* Images are auto-cropped, then fit to the preview on hover (with a slight delay). This is an experiment; we'll see how it turns out.
* Various style changes.

see #21390.


git-svn-id: https://develop.svn.wordpress.org/trunk@22137 602fd350-edb4-49c9-b593-d223f7449a82
2012-10-08 23:20:04 +00:00
Daryl Koopersmith a165bdfb83 Improve the lazy instantiation of the 'wp' JavaScript variable. props evansolomon, fixes #22113.
git-svn-id: https://develop.svn.wordpress.org/trunk@22126 602fd350-edb4-49c9-b593-d223f7449a82
2012-10-06 00:43:36 +00:00
Daryl Koopersmith d43c390e2b Use the new media modal to insert galleries into TinyMCE and the text editor.
'''Galleries'''

* Gallery insertion from the new media modal (into TinyMCE, the text editor, etc).
* Gallery previews in TinyMCE now use the `wp.mce.views` API.
* Disables the TinyMCE `wpgallery` plugin.
* Gallery previews consist of the first image of the gallery and the appearance of a stack. This will later be fleshed out to include more images/functionality (including editing the gallery, gallery properties, and showing the number of images in the gallery).
* Multiple galleries can be added to a single post.
* The gallery MCE view provides a bridge between the `wp.shortcode` and `Attachments` representation of a gallery, which allows the existing collection to persist when a gallery is initially created (preventing a request to the server for the query).


'''Shortcodes'''

* Renames `wp.shortcode.Match` to `wp.shortcode` to better expose the shortcode constructor.
* The `wp.shortcode` constructor now accepts an object of options instead of a `wp.shortcode.regexp()` match.
* A `wp.shortcode` instance can be created from a `wp.shortcode.regexp()` match by calling `wp.shortcode.fromMatch( match )`.
* Adds `wp.shortcode.string()`, which takes a set of shortcode parameters and converts them into a string.* Renames `wp.shortcode.prototype.text()` to `wp.shortcode.prototype.string()`.
* Adds an additional capture group to `wp.shortcode.regexp()` that records whether or not the shortcode has a closing tag. This allows us to improve the accuracy of the syntax used when transforming a shortcode object back into a string.

'''Media Models'''

* Prevents media `Query` models from observing the central `Attachments.all` object when query args without corresponding filters are set (otherwise, queries quickly amass false positives).
* Adds `post__in`, `post__not_in`, and `post_parent` as acceptable JS attachment `Query` args.
* `Attachments.more()` always returns a `$.promise` object.

see #21390, #21809, #21812, #21815, #21817.


git-svn-id: https://develop.svn.wordpress.org/trunk@22120 602fd350-edb4-49c9-b593-d223f7449a82
2012-10-05 04:23:59 +00:00
Daryl Koopersmith 4a90e0541a Media JS: Add support for filtering Attachment collections by mime type. see #21390, #21776, #21809.
git-svn-id: https://develop.svn.wordpress.org/trunk@22021 602fd350-edb4-49c9-b593-d223f7449a82
2012-09-26 20:50:13 +00:00
Daryl Koopersmith af4607a11e Media JS: Use correct reference to search term in the Attachments model search filter. see #21390.
git-svn-id: https://develop.svn.wordpress.org/trunk@22013 602fd350-edb4-49c9-b593-d223f7449a82
2012-09-26 15:13:22 +00:00
Daryl Koopersmith 0dd940e0c1 First pass on TinyMCE attachment in-editor UI.
* Adds in-editor UI for image attachments. Most of this UI should be able to migrate to all images in a future commit.
* Removes the wpeditimage TinyMCE plugin from the default plugins array.
* Add `wp.media.fit`, a helper method to constrain dimensions based upon a maximum width and/or height.
* Add html attribute parsing and string generation utilities (currently stored in mce-views).
* Calling `remove` on a TinyMCE views now ensures that the the parent and references are removed as well.
* Fixes a bug where we weren't sending the full array of results to matches in wp.mce.view.

see #21390, #21812, #21813.



git-svn-id: https://develop.svn.wordpress.org/trunk@22012 602fd350-edb4-49c9-b593-d223f7449a82
2012-09-26 14:12:54 +00:00
Daryl Koopersmith 7b999727ce Rename the attachment-thumbnail class in the media modal Attachment view to prevent conflicts with wp_get_attachment_image(). see #21390.
git-svn-id: https://develop.svn.wordpress.org/trunk@21909 602fd350-edb4-49c9-b593-d223f7449a82
2012-09-19 01:10:17 +00:00
Daryl Koopersmith b2fb76008e Ensure the Attachments model properties are correctly set for Query collections.
After shifting sorting and searching logic from the `Query` collection in [21898], it became apparent that `Query` collections should also have an accurate `props` model, as the model controls the aforementioned searching and sorting.

see #21921, #21809, and #21390.


git-svn-id: https://develop.svn.wordpress.org/trunk@21900 602fd350-edb4-49c9-b593-d223f7449a82
2012-09-18 22:19:05 +00:00
Daryl Koopersmith 592b23f94f Allow JS Attachments models to be searchable and sortable.
Moves `wp.media.model.Query` sorting and searching to the parent `wp.media.model.Attachments`.

Query parameters are stored in `attachments.props`, which is a `Backbone.Model`, and supports `order` (`'ASC'` or `'DESC'`), `orderby` (any `Attachment` model property name), `search` (a search term), and `query` (a boolean value that ties the `Attachments` collection to the server).

`wp.media.query( args )` now returns an `Attachments` set that is mapped to a `Query` collection instead of the `Query` collection itself. This allows you to change the query arguments by updating `attachments.props` instead of fetching the mirrored arguments, changing them, and passing them to `wp.media.query()` again.

fixes #21921, see #21390, #21809.


git-svn-id: https://develop.svn.wordpress.org/trunk@21898 602fd350-edb4-49c9-b593-d223f7449a82
2012-09-18 21:42:29 +00:00
Daryl Koopersmith 304569a26c Media JS: Add support for multiple views to the media workflow controller. see #21390.
git-svn-id: https://develop.svn.wordpress.org/trunk@21820 602fd350-edb4-49c9-b593-d223f7449a82
2012-09-11 21:13:07 +00:00
Daryl Koopersmith 44b205c027 Add wp.media(), a function to create a default media workflow.
This will be the main entry point for basic media development, and should hopefully help less experienced developers wrangle the new media APIs.

If you would like to see the new UI, navigate to the post editor and run the following in your browser's Javascript console:

	wp.media();

Well, that certainly feels a lot nicer to type.

see #21390.


git-svn-id: https://develop.svn.wordpress.org/trunk@21692 602fd350-edb4-49c9-b593-d223f7449a82
2012-08-31 20:44:02 +00:00
Daryl Koopersmith 8f7b835954 Media JS: Attachments collection API improvements.
Rename watch() and unwatch() to observe() and unobserve(), respectively, to avoid conflicts with Firefox's proprietary Object.prototype.watch method.

Rename validate() to validator(), and changed() to validate(), as the latter will be more frequently used, and better explains its purpose. Also, make the new validate() more concise.

see #21390.


git-svn-id: https://develop.svn.wordpress.org/trunk@21689 602fd350-edb4-49c9-b593-d223f7449a82
2012-08-31 18:38:32 +00:00
Daryl Koopersmith 5a4a17687a Add new media workflow scripts, styles, and templates.
Please note that this commit does not integrate media into the existing UI. If you would like to see the new UI, navigate to the post editor and run the following in your browser's Javascript console:

	new wp.media.controller.Workflow().render().modal.open();


The Javascript is broken up into two files, with the slugs media-models and media-views.

* media-models: The models are UI agnostic, and can be used independent of the views. If you'd like to create custom UIs, this is the script for you.

* media-views: This is the Media Experience. The views (and controllers) depend on the models (which are listed as a dependency and will automatically be included thanks to wp_enqueue_script). The views also require the media templates, media-view styles, and the plupload bridge settings. Perhaps we should create a function to include the whole shebang, but in the meantime...

To include media-views in the admin, run the following PHP in or after 'admin_enqueue_scripts':

	wp_enqueue_script( 'media-views' );
	wp_enqueue_style( 'media-views' );
	wp_plupload_default_settings();
	add_action( 'admin_footer', 'wp_print_media_templates' );

see #21390.



git-svn-id: https://develop.svn.wordpress.org/trunk@21683 602fd350-edb4-49c9-b593-d223f7449a82
2012-08-31 04:54:23 +00:00