diff --git src/wp-includes/js/media-views.js src/wp-includes/js/media-views.js
index 745bf86..ddc5d09 100644
|
|
|
1086 | 1086 | }); |
1087 | 1087 | |
1088 | 1088 | /** |
| 1089 | * wp.media.controller.EditImage |
| 1090 | * |
| 1091 | * @constructor |
| 1092 | * @augments wp.media.controller.State |
| 1093 | * @augments Backbone.Model |
| 1094 | */ |
| 1095 | media.controller.EditImage = media.controller.State.extend({ |
| 1096 | defaults: { |
| 1097 | id: 'edit-image', |
| 1098 | url: '', |
| 1099 | menu: false, |
| 1100 | content: 'edit-image', |
| 1101 | syncSelection: true |
| 1102 | }, |
| 1103 | |
| 1104 | activate: function() { |
| 1105 | |
| 1106 | this.syncSelection(); |
| 1107 | }, |
| 1108 | |
| 1109 | syncSelection: function() { |
| 1110 | var selection = this.get('selection'), |
| 1111 | manager = this.frame._selection; |
| 1112 | |
| 1113 | if ( ! this.get('syncSelection') || ! manager || ! selection ) { |
| 1114 | return; |
| 1115 | } |
| 1116 | |
| 1117 | // If the selection supports multiple items, validate the stored |
| 1118 | // attachments based on the new selection's conditions. Record |
| 1119 | // the attachments that are not included; we'll maintain a |
| 1120 | // reference to those. Other attachments are considered in flux. |
| 1121 | if ( selection.multiple ) { |
| 1122 | selection.reset( [], { silent: true }); |
| 1123 | selection.validateAll( manager.attachments ); |
| 1124 | manager.difference = _.difference( manager.attachments.models, selection.models ); |
| 1125 | } |
| 1126 | |
| 1127 | // Sync the selection's single item with the master. |
| 1128 | selection.single( manager.single ); |
| 1129 | } |
| 1130 | }); |
| 1131 | |
| 1132 | /** |
1089 | 1133 | * wp.media.controller.Embed |
1090 | 1134 | * |
1091 | 1135 | * @constructor |
… |
… |
|
1758 | 1802 | menu: 'gallery' |
1759 | 1803 | }), |
1760 | 1804 | |
1761 | | new media.controller.GalleryAdd() |
| 1805 | new media.controller.GalleryAdd(), |
| 1806 | |
| 1807 | new media.controller.EditImage( { selection: options.selection } ) |
1762 | 1808 | ]); |
1763 | 1809 | |
1764 | 1810 | |
… |
… |
|
1786 | 1832 | |
1787 | 1833 | content: { |
1788 | 1834 | 'embed': 'embedContent', |
| 1835 | 'edit-image': 'editImageContent', |
1789 | 1836 | 'edit-selection': 'editSelectionContent' |
1790 | 1837 | }, |
1791 | 1838 | |
… |
… |
|
1883 | 1930 | this.content.set( view ); |
1884 | 1931 | }, |
1885 | 1932 | |
| 1933 | editImageContent: function() { |
| 1934 | var selection = this.state().get('selection'), |
| 1935 | view = new media.view.EditImage( { model: selection.single() } ).render(); |
| 1936 | |
| 1937 | this.content.set( view ); |
| 1938 | |
| 1939 | // after bringing in the frame, load the actual editor via an ajax call |
| 1940 | view.loadEditor(); |
| 1941 | |
| 1942 | }, |
| 1943 | |
1886 | 1944 | // Toolbars |
1887 | 1945 | |
1888 | 1946 | /** |
… |
… |
|
2054 | 2112 | media.view.MediaFrame.Select.prototype.bindHandlers.apply( this, arguments ); |
2055 | 2113 | this.on( 'menu:create:image-details', this.createMenu, this ); |
2056 | 2114 | this.on( 'content:render:image-details', this.renderImageDetailsContent, this ); |
| 2115 | this.on( 'content:render:edit-image', this.editImageContent, this ); |
2057 | 2116 | this.on( 'menu:render:image-details', this.renderMenu, this ); |
2058 | 2117 | this.on( 'toolbar:render:image-details', this.renderImageDetailsToolbar, this ); |
2059 | 2118 | // override the select toolbar |
… |
… |
|
2077 | 2136 | toolbar: 'replace', |
2078 | 2137 | priority: 80, |
2079 | 2138 | displaySettings: true |
2080 | | }) |
| 2139 | }), |
| 2140 | new media.controller.EditImage( { image: this.image } ) |
2081 | 2141 | ]); |
2082 | 2142 | }, |
2083 | 2143 | |
… |
… |
|
2117 | 2177 | |
2118 | 2178 | }, |
2119 | 2179 | |
| 2180 | editImageContent: function() { |
| 2181 | var attachment = this.state().get('image').attachment, |
| 2182 | view; |
| 2183 | |
| 2184 | if ( ! attachment ) { |
| 2185 | return; |
| 2186 | } |
| 2187 | |
| 2188 | view = new media.view.EditImage( { model: attachment } ).render(); |
| 2189 | |
| 2190 | this.content.set( view ); |
| 2191 | |
| 2192 | // after bringing in the frame, load the actual editor via an ajax call |
| 2193 | view.loadEditor(); |
| 2194 | |
| 2195 | }, |
| 2196 | |
2120 | 2197 | renderImageDetailsToolbar: function() { |
2121 | 2198 | this.toolbar.set( new media.view.Toolbar({ |
2122 | 2199 | controller: this, |
… |
… |
|
4906 | 4983 | }, |
4907 | 4984 | |
4908 | 4985 | editAttachment: function() { |
4909 | | this.$el.addClass('needs-refresh'); |
| 4986 | event.preventDefault(); |
| 4987 | this.controller.setState( 'edit-image' ); |
4910 | 4988 | }, |
4911 | 4989 | /** |
4912 | 4990 | * @param {Object} event |
… |
… |
|
4916 | 4994 | event.preventDefault(); |
4917 | 4995 | this.model.fetch(); |
4918 | 4996 | } |
| 4997 | |
4919 | 4998 | }); |
4920 | 4999 | |
4921 | 5000 | /** |
… |
… |
|
5189 | 5268 | media.view.ImageDetails = media.view.Settings.AttachmentDisplay.extend({ |
5190 | 5269 | className: 'image-details', |
5191 | 5270 | template: media.template('image-details'), |
5192 | | |
| 5271 | events: { |
| 5272 | 'click .edit-attachment': 'editAttachment' |
| 5273 | }, |
5193 | 5274 | initialize: function() { |
5194 | 5275 | // used in AttachmentDisplay.prototype.updateLinkTo |
5195 | 5276 | this.options.attachment = this.model.attachment; |
… |
… |
|
5229 | 5310 | resetFocus: function() { |
5230 | 5311 | this.$( '.caption textarea' ).focus(); |
5231 | 5312 | this.$( '.embed-image-settings' ).scrollTop( 0 ); |
| 5313 | }, |
| 5314 | |
| 5315 | editAttachment: function() { |
| 5316 | event.preventDefault(); |
| 5317 | this.controller.setState( 'edit-image' ); |
5232 | 5318 | } |
5233 | 5319 | }); |
| 5320 | |
| 5321 | |
| 5322 | media.view.EditImage = media.View.extend({ |
| 5323 | |
| 5324 | className: 'image-editor', |
| 5325 | template: media.template('image-editor'), |
| 5326 | |
| 5327 | initialize: function() { |
| 5328 | |
| 5329 | this.editor = window.imageEdit; |
| 5330 | media.View.prototype.initialize.apply( this, arguments ); |
| 5331 | }, |
| 5332 | |
| 5333 | prepare: function() { |
| 5334 | return this.model.toJSON(); |
| 5335 | }, |
| 5336 | |
| 5337 | render: function() { |
| 5338 | media.View.prototype.render.apply( this, arguments ); |
| 5339 | return this; |
| 5340 | }, |
| 5341 | |
| 5342 | loadEditor: function() { |
| 5343 | this.editor.open( this.model.get('id'), this.model.get('nonces').edit ); |
| 5344 | } |
| 5345 | |
| 5346 | }); |
| 5347 | |
5234 | 5348 | }(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 426eb97..4ad68fa 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() ) { |