diff --git src/wp-includes/js/media-views.js src/wp-includes/js/media-views.js
index b30e703..272a997 100644
|
|
|
1090 | 1090 | }); |
1091 | 1091 | |
1092 | 1092 | /** |
| 1093 | * wp.media.controller.EditImage |
| 1094 | * |
| 1095 | * @constructor |
| 1096 | * @augments wp.media.controller.State |
| 1097 | * @augments Backbone.Model |
| 1098 | */ |
| 1099 | media.controller.EditImage = media.controller.State.extend({ |
| 1100 | defaults: { |
| 1101 | id: 'edit-image', |
| 1102 | url: '', |
| 1103 | menu: false, |
| 1104 | content: 'edit-image', |
| 1105 | syncSelection: true |
| 1106 | }, |
| 1107 | |
| 1108 | activate: function() { |
| 1109 | |
| 1110 | this.syncSelection(); |
| 1111 | }, |
| 1112 | |
| 1113 | syncSelection: function() { |
| 1114 | var selection = this.get('selection'), |
| 1115 | manager = this.frame._selection; |
| 1116 | |
| 1117 | if ( ! this.get('syncSelection') || ! manager || ! selection ) { |
| 1118 | return; |
| 1119 | } |
| 1120 | |
| 1121 | // If the selection supports multiple items, validate the stored |
| 1122 | // attachments based on the new selection's conditions. Record |
| 1123 | // the attachments that are not included; we'll maintain a |
| 1124 | // reference to those. Other attachments are considered in flux. |
| 1125 | if ( selection.multiple ) { |
| 1126 | selection.reset( [], { silent: true }); |
| 1127 | selection.validateAll( manager.attachments ); |
| 1128 | manager.difference = _.difference( manager.attachments.models, selection.models ); |
| 1129 | } |
| 1130 | |
| 1131 | // Sync the selection's single item with the master. |
| 1132 | selection.single( manager.single ); |
| 1133 | } |
| 1134 | }); |
| 1135 | |
| 1136 | /** |
1093 | 1137 | * wp.media.controller.Embed |
1094 | 1138 | * |
1095 | 1139 | * @constructor |
… |
… |
|
1763 | 1807 | menu: 'gallery' |
1764 | 1808 | }), |
1765 | 1809 | |
1766 | | new media.controller.GalleryAdd() |
| 1810 | new media.controller.GalleryAdd(), |
| 1811 | |
| 1812 | new media.controller.EditImage( { selection: options.selection } ) |
1767 | 1813 | ]); |
1768 | 1814 | |
1769 | 1815 | |
… |
… |
|
1791 | 1837 | |
1792 | 1838 | content: { |
1793 | 1839 | 'embed': 'embedContent', |
| 1840 | 'edit-image': 'editImageContent', |
1794 | 1841 | 'edit-selection': 'editSelectionContent' |
1795 | 1842 | }, |
1796 | 1843 | |
… |
… |
|
1889 | 1936 | this.content.set( view ); |
1890 | 1937 | }, |
1891 | 1938 | |
| 1939 | editImageContent: function() { |
| 1940 | var selection = this.state().get('selection'), |
| 1941 | view = new media.view.EditImage( { model: selection.single() } ).render(); |
| 1942 | |
| 1943 | this.content.set( view ); |
| 1944 | |
| 1945 | // after bringing in the frame, load the actual editor via an ajax call |
| 1946 | view.loadEditor(); |
| 1947 | |
| 1948 | }, |
| 1949 | |
1892 | 1950 | // Toolbars |
1893 | 1951 | |
1894 | 1952 | /** |
… |
… |
|
2060 | 2118 | media.view.MediaFrame.Select.prototype.bindHandlers.apply( this, arguments ); |
2061 | 2119 | this.on( 'menu:create:image-details', this.createMenu, this ); |
2062 | 2120 | this.on( 'content:render:image-details', this.renderImageDetailsContent, this ); |
| 2121 | this.on( 'content:render:edit-image', this.editImageContent, this ); |
2063 | 2122 | this.on( 'menu:render:image-details', this.renderMenu, this ); |
2064 | 2123 | this.on( 'toolbar:render:image-details', this.renderImageDetailsToolbar, this ); |
2065 | 2124 | // override the select toolbar |
… |
… |
|
2083 | 2142 | toolbar: 'replace', |
2084 | 2143 | priority: 80, |
2085 | 2144 | displaySettings: true |
2086 | | }) |
| 2145 | }), |
| 2146 | new media.controller.EditImage( { image: this.image } ) |
2087 | 2147 | ]); |
2088 | 2148 | }, |
2089 | 2149 | |
… |
… |
|
2123 | 2183 | |
2124 | 2184 | }, |
2125 | 2185 | |
| 2186 | editImageContent: function() { |
| 2187 | var attachment = this.state().get('image').attachment, |
| 2188 | view; |
| 2189 | |
| 2190 | if ( ! attachment ) { |
| 2191 | return; |
| 2192 | } |
| 2193 | |
| 2194 | view = new media.view.EditImage( { model: attachment } ).render(); |
| 2195 | |
| 2196 | this.content.set( view ); |
| 2197 | |
| 2198 | // after bringing in the frame, load the actual editor via an ajax call |
| 2199 | view.loadEditor(); |
| 2200 | |
| 2201 | }, |
| 2202 | |
2126 | 2203 | renderImageDetailsToolbar: function() { |
2127 | 2204 | this.toolbar.set( new media.view.Toolbar({ |
2128 | 2205 | controller: this, |
… |
… |
|
4918 | 4995 | } |
4919 | 4996 | }, |
4920 | 4997 | |
4921 | | editAttachment: function() { |
4922 | | this.$el.addClass('needs-refresh'); |
| 4998 | editAttachment: function( event ) { |
| 4999 | event.preventDefault(); |
| 5000 | this.controller.setState( 'edit-image' ); |
4923 | 5001 | }, |
4924 | 5002 | /** |
4925 | 5003 | * @param {Object} event |
… |
… |
|
4929 | 5007 | event.preventDefault(); |
4930 | 5008 | this.model.fetch(); |
4931 | 5009 | } |
| 5010 | |
4932 | 5011 | }); |
4933 | 5012 | |
4934 | 5013 | /** |
… |
… |
|
5202 | 5281 | media.view.ImageDetails = media.view.Settings.AttachmentDisplay.extend({ |
5203 | 5282 | className: 'image-details', |
5204 | 5283 | template: media.template('image-details'), |
5205 | | |
| 5284 | events: { |
| 5285 | 'click .edit-attachment': 'editAttachment' |
| 5286 | }, |
5206 | 5287 | initialize: function() { |
5207 | 5288 | // used in AttachmentDisplay.prototype.updateLinkTo |
5208 | 5289 | this.options.attachment = this.model.attachment; |
… |
… |
|
5242 | 5323 | resetFocus: function() { |
5243 | 5324 | this.$( '.caption textarea' ).focus(); |
5244 | 5325 | this.$( '.embed-image-settings' ).scrollTop( 0 ); |
| 5326 | }, |
| 5327 | |
| 5328 | editAttachment: function( event ) { |
| 5329 | event.preventDefault(); |
| 5330 | this.controller.setState( 'edit-image' ); |
5245 | 5331 | } |
5246 | 5332 | }); |
| 5333 | |
| 5334 | |
| 5335 | media.view.EditImage = media.View.extend({ |
| 5336 | |
| 5337 | className: 'image-editor', |
| 5338 | template: media.template('image-editor'), |
| 5339 | |
| 5340 | initialize: function() { |
| 5341 | |
| 5342 | this.editor = window.imageEdit; |
| 5343 | media.View.prototype.initialize.apply( this, arguments ); |
| 5344 | }, |
| 5345 | |
| 5346 | prepare: function() { |
| 5347 | return this.model.toJSON(); |
| 5348 | }, |
| 5349 | |
| 5350 | render: function() { |
| 5351 | media.View.prototype.render.apply( this, arguments ); |
| 5352 | return this; |
| 5353 | }, |
| 5354 | |
| 5355 | loadEditor: function() { |
| 5356 | this.editor.open( this.model.get('id'), this.model.get('nonces').edit ); |
| 5357 | } |
| 5358 | |
| 5359 | }); |
| 5360 | |
5247 | 5361 | }(jQuery)); |
diff --git src/wp-includes/media-template.php src/wp-includes/media-template.php
index 93bf672..06f2c9a 100644
|
|
function wp_print_media_templates() { |
508 | 508 | <div class="thumbnail"> |
509 | 509 | <img src="{{ data.model.url }}" draggable="false" /> |
510 | 510 | </div> |
| 511 | <# if ( data.attachment ) { #> |
| 512 | <input type="button" class="edit-attachment button" value="<?php esc_attr_e( 'Edit Image' ); ?>" /> |
| 513 | <# } #> |
511 | 514 | |
512 | 515 | <div class="setting url"> |
513 | 516 | <?php // might want to make the url editable if it isn't an attachment ?> |
… |
… |
function wp_print_media_templates() { |
598 | 601 | </div> |
599 | 602 | </div> |
600 | 603 | </script> |
| 604 | |
| 605 | <script type="text/html" id="tmpl-image-editor"> |
| 606 | <div id="media-head-{{{ data.id }}}"></div> |
| 607 | <div id="image-editor-{{{ data.id }}}"></div> |
| 608 | </script> |
601 | 609 | <?php |
602 | 610 | |
603 | 611 | /** |
diff --git src/wp-includes/media.php src/wp-includes/media.php
index 12cc86b..21a58c1 100644
|
|
function wp_prepare_attachment_for_js( $attachment ) { |
1827 | 1827 | 'nonces' => array( |
1828 | 1828 | 'update' => false, |
1829 | 1829 | 'delete' => false, |
| 1830 | 'edit' => false |
1830 | 1831 | ), |
1831 | 1832 | 'editLink' => false, |
1832 | 1833 | ); |
1833 | 1834 | |
1834 | 1835 | if ( current_user_can( 'edit_post', $attachment->ID ) ) { |
1835 | 1836 | $response['nonces']['update'] = wp_create_nonce( 'update-post_' . $attachment->ID ); |
| 1837 | $response['nonces']['edit'] = wp_create_nonce( 'image_editor-' . $attachment->ID ); |
1836 | 1838 | $response['editLink'] = get_edit_post_link( $attachment->ID, 'raw' ); |
1837 | 1839 | } |
1838 | 1840 | |
diff --git src/wp-includes/script-loader.php src/wp-includes/script-loader.php
index 6e4488d..305019f 100644
|
|
function wp_default_scripts( &$scripts ) { |
385 | 385 | // To enqueue media-views or media-editor, call wp_enqueue_media(). |
386 | 386 | // Both rely on numerous settings, styles, and templates to operate correctly. |
387 | 387 | $scripts->add( 'media-views', "/wp-includes/js/media-views$suffix.js", array( 'utils', 'media-models', 'wp-plupload', 'jquery-ui-sortable' ), false, 1 ); |
388 | | $scripts->add( 'media-editor', "/wp-includes/js/media-editor$suffix.js", array( 'shortcode', 'media-views' ), false, 1 ); |
| 388 | $scripts->add( 'media-editor', "/wp-includes/js/media-editor$suffix.js", array( 'shortcode', 'media-views', 'image-edit' ), false, 1 ); |
389 | 389 | $scripts->add( 'mce-view', "/wp-includes/js/mce-view$suffix.js", array( 'shortcode', 'media-models' ), false, 1 ); |
390 | 390 | |
391 | 391 | if ( is_admin() ) { |