| 1 | Index: wp-includes/js/media-editor.js |
|---|
| 2 | =================================================================== |
|---|
| 3 | --- wp-includes/js/media-editor.js (revision 23065) |
|---|
| 4 | +++ wp-includes/js/media-editor.js (working copy) |
|---|
| 5 | @@ -320,6 +320,74 @@ |
|---|
| 6 | }; |
|---|
| 7 | }()); |
|---|
| 8 | |
|---|
| 9 | + wp.media.featuredImage = { |
|---|
| 10 | + get: function() { |
|---|
| 11 | + return wp.media.view.settings.post.featuredImageId; |
|---|
| 12 | + }, |
|---|
| 13 | + |
|---|
| 14 | + set: function( id ) { |
|---|
| 15 | + var settings = wp.media.view.settings; |
|---|
| 16 | + |
|---|
| 17 | + settings.post.featuredImageId = id; |
|---|
| 18 | + |
|---|
| 19 | + wp.media.post( 'set-post-thumbnail', { |
|---|
| 20 | + json: true, |
|---|
| 21 | + post_id: settings.post.id, |
|---|
| 22 | + thumbnail_id: settings.post.featuredImageId, |
|---|
| 23 | + _wpnonce: settings.post.nonce |
|---|
| 24 | + }).done( function( html ) { |
|---|
| 25 | + $( '.inside', '#postimagediv' ).html( html ); |
|---|
| 26 | + }); |
|---|
| 27 | + }, |
|---|
| 28 | + |
|---|
| 29 | + frame: function() { |
|---|
| 30 | + if ( this._frame ) |
|---|
| 31 | + return this._frame; |
|---|
| 32 | + |
|---|
| 33 | + this._frame = wp.media({ |
|---|
| 34 | + state: 'featured-image', |
|---|
| 35 | + states: [ new wp.media.controller.FeaturedImage() ] |
|---|
| 36 | + }); |
|---|
| 37 | + |
|---|
| 38 | + this._frame.on( 'toolbar:create:featured-image', function( toolbar ) { |
|---|
| 39 | + this.createSelectToolbar( toolbar, { |
|---|
| 40 | + text: wp.media.view.l10n.setFeaturedImage |
|---|
| 41 | + }); |
|---|
| 42 | + }, this._frame ); |
|---|
| 43 | + |
|---|
| 44 | + this._frame.state('featured-image').on( 'select', this.select ); |
|---|
| 45 | + return this._frame; |
|---|
| 46 | + }, |
|---|
| 47 | + |
|---|
| 48 | + select: function() { |
|---|
| 49 | + var settings = wp.media.view.settings, |
|---|
| 50 | + selection = this.get('selection').single(); |
|---|
| 51 | + |
|---|
| 52 | + if ( ! settings.post.featuredImageId ) |
|---|
| 53 | + return; |
|---|
| 54 | + |
|---|
| 55 | + wp.media.featuredImage.set( selection ? selection.id : -1 ); |
|---|
| 56 | + }, |
|---|
| 57 | + |
|---|
| 58 | + init: function() { |
|---|
| 59 | + // Open the content media manager to the 'featured image' tab when |
|---|
| 60 | + // the post thumbnail is clicked. |
|---|
| 61 | + $('#postimagediv').on( 'click', '#set-post-thumbnail', function( event ) { |
|---|
| 62 | + event.preventDefault(); |
|---|
| 63 | + // Stop propagation to prevent thickbox from activating. |
|---|
| 64 | + event.stopPropagation(); |
|---|
| 65 | + |
|---|
| 66 | + wp.media.featuredImage.frame().open(); |
|---|
| 67 | + |
|---|
| 68 | + // Update the featured image id when the 'remove' link is clicked. |
|---|
| 69 | + }).on( 'click', '#remove-post-thumbnail', function() { |
|---|
| 70 | + wp.media.view.settings.post.featuredImageId = -1; |
|---|
| 71 | + }); |
|---|
| 72 | + } |
|---|
| 73 | + }; |
|---|
| 74 | + |
|---|
| 75 | + $( wp.media.featuredImage.init ); |
|---|
| 76 | + |
|---|
| 77 | wp.media.editor = { |
|---|
| 78 | insert: function( h ) { |
|---|
| 79 | var mce = typeof(tinymce) != 'undefined', |
|---|
| 80 | @@ -443,24 +511,7 @@ |
|---|
| 81 | } |
|---|
| 82 | }, this ); |
|---|
| 83 | |
|---|
| 84 | - workflow.state('featured-image').on( 'select', function() { |
|---|
| 85 | - var settings = wp.media.view.settings, |
|---|
| 86 | - selection = this.get('selection').single(); |
|---|
| 87 | - |
|---|
| 88 | - if ( ! settings.post.featuredImageId ) |
|---|
| 89 | - return; |
|---|
| 90 | - |
|---|
| 91 | - settings.post.featuredImageId = selection ? selection.id : -1; |
|---|
| 92 | - wp.media.post( 'set-post-thumbnail', { |
|---|
| 93 | - json: true, |
|---|
| 94 | - post_id: settings.post.id, |
|---|
| 95 | - thumbnail_id: settings.post.featuredImageId, |
|---|
| 96 | - _wpnonce: settings.post.nonce |
|---|
| 97 | - }).done( function( html ) { |
|---|
| 98 | - $( '.inside', '#postimagediv' ).html( html ); |
|---|
| 99 | - }); |
|---|
| 100 | - }); |
|---|
| 101 | - |
|---|
| 102 | + workflow.state('featured-image').on( 'select', wp.media.featuredImage.select ); |
|---|
| 103 | workflow.setState( workflow.options.state ); |
|---|
| 104 | return workflow; |
|---|
| 105 | }, |
|---|
| 106 | @@ -586,37 +637,6 @@ |
|---|
| 107 | |
|---|
| 108 | wp.media.editor.open( editor ); |
|---|
| 109 | }); |
|---|
| 110 | - |
|---|
| 111 | - // Open the content media manager to the 'featured image' tab when |
|---|
| 112 | - // the post thumbnail is clicked. |
|---|
| 113 | - $('#postimagediv').on( 'click', '#set-post-thumbnail', function( event ) { |
|---|
| 114 | - event.preventDefault(); |
|---|
| 115 | - // Stop propagation to prevent thickbox from activating. |
|---|
| 116 | - event.stopPropagation(); |
|---|
| 117 | - |
|---|
| 118 | - // Always get the 'content' frame, since this is tailored to post.php. |
|---|
| 119 | - var frame = wp.media.editor.add('content'), |
|---|
| 120 | - initialState = frame.state().id, |
|---|
| 121 | - escape; |
|---|
| 122 | - |
|---|
| 123 | - escape = function() { |
|---|
| 124 | - // Only run this event once. |
|---|
| 125 | - this.off( 'escape', escape ); |
|---|
| 126 | - |
|---|
| 127 | - // If we're still on the 'featured-image' state, restore |
|---|
| 128 | - // the initial state. |
|---|
| 129 | - if ( 'featured-image' === this.state().id ) |
|---|
| 130 | - this.setState( initialState ); |
|---|
| 131 | - }; |
|---|
| 132 | - |
|---|
| 133 | - frame.on( 'escape', escape, frame ); |
|---|
| 134 | - |
|---|
| 135 | - frame.setState('featured-image').open(); |
|---|
| 136 | - |
|---|
| 137 | - // Update the featured image id when the 'remove' link is clicked. |
|---|
| 138 | - }).on( 'click', '#remove-post-thumbnail', function() { |
|---|
| 139 | - wp.media.view.settings.post.featuredImageId = -1; |
|---|
| 140 | - }); |
|---|
| 141 | } |
|---|
| 142 | }; |
|---|
| 143 | |
|---|
| 144 | Index: wp-includes/js/media-views.js |
|---|
| 145 | =================================================================== |
|---|
| 146 | --- wp-includes/js/media-views.js (revision 23065) |
|---|
| 147 | +++ wp-includes/js/media-views.js (working copy) |
|---|
| 148 | @@ -289,7 +289,7 @@ |
|---|
| 149 | this.frame.router.render( mode ); |
|---|
| 150 | |
|---|
| 151 | view = router.get(); |
|---|
| 152 | - if ( view.select ) |
|---|
| 153 | + if ( view && view.select ) |
|---|
| 154 | view.select( this.frame.content.mode() ); |
|---|
| 155 | }, |
|---|
| 156 | |
|---|
| 157 | @@ -304,7 +304,7 @@ |
|---|
| 158 | menu.mode( mode ); |
|---|
| 159 | |
|---|
| 160 | view = menu.get(); |
|---|
| 161 | - if ( view.select ) |
|---|
| 162 | + if ( view && view.select ) |
|---|
| 163 | view.select( this.id ); |
|---|
| 164 | }, |
|---|
| 165 | |
|---|
| 166 | @@ -357,6 +357,7 @@ |
|---|
| 167 | sidebar: 'settings', |
|---|
| 168 | content: 'upload', |
|---|
| 169 | router: 'browse', |
|---|
| 170 | + menu: 'default', |
|---|
| 171 | searchable: true, |
|---|
| 172 | filterable: false, |
|---|
| 173 | sortable: true, |
|---|
| 174 | @@ -669,7 +670,6 @@ |
|---|
| 175 | id: 'featured-image', |
|---|
| 176 | filterable: 'uploaded', |
|---|
| 177 | multiple: false, |
|---|
| 178 | - menu: 'main', |
|---|
| 179 | toolbar: 'featured-image', |
|---|
| 180 | title: l10n.featuredImageTitle, |
|---|
| 181 | priority: 60 |
|---|
| 182 | @@ -707,6 +707,17 @@ |
|---|
| 183 | }, |
|---|
| 184 | |
|---|
| 185 | activate: function() { |
|---|
| 186 | + this.updateSelection(); |
|---|
| 187 | + this.frame.on( 'open', this.updateSelection, this ); |
|---|
| 188 | + media.controller.Library.prototype.activate.apply( this, arguments ); |
|---|
| 189 | + }, |
|---|
| 190 | + |
|---|
| 191 | + deactivate: function() { |
|---|
| 192 | + this.frame.off( 'open', this.updateSelection, this ); |
|---|
| 193 | + media.controller.Library.prototype.deactivate.apply( this, arguments ); |
|---|
| 194 | + }, |
|---|
| 195 | + |
|---|
| 196 | + updateSelection: function() { |
|---|
| 197 | var selection = this.get('selection'), |
|---|
| 198 | id = media.view.settings.post.featuredImageId, |
|---|
| 199 | attachment; |
|---|
| 200 | @@ -717,7 +728,6 @@ |
|---|
| 201 | } |
|---|
| 202 | |
|---|
| 203 | selection.reset( attachment ? [ attachment ] : [] ); |
|---|
| 204 | - media.controller.Library.prototype.activate.apply( this, arguments ); |
|---|
| 205 | } |
|---|
| 206 | }); |
|---|
| 207 | |
|---|
| 208 | @@ -728,7 +738,7 @@ |
|---|
| 209 | defaults: { |
|---|
| 210 | id: 'embed', |
|---|
| 211 | url: '', |
|---|
| 212 | - menu: 'main', |
|---|
| 213 | + menu: 'default', |
|---|
| 214 | content: 'embed', |
|---|
| 215 | toolbar: 'main-embed', |
|---|
| 216 | type: 'link', |
|---|
| 217 | @@ -1231,6 +1241,9 @@ |
|---|
| 218 | model.frame = this; |
|---|
| 219 | model.trigger('ready'); |
|---|
| 220 | }, this ); |
|---|
| 221 | + |
|---|
| 222 | + if ( this.options.states ) |
|---|
| 223 | + this.states.add( this.options.states ); |
|---|
| 224 | }, |
|---|
| 225 | |
|---|
| 226 | reset: function() { |
|---|
| 227 | @@ -1294,6 +1307,9 @@ |
|---|
| 228 | // Bind default title creation. |
|---|
| 229 | this.on( 'title:create:default', this.createTitle, this ); |
|---|
| 230 | this.title.mode('default'); |
|---|
| 231 | + |
|---|
| 232 | + // Bind default menu. |
|---|
| 233 | + this.on( 'menu:create:default', this.createMenu, this ); |
|---|
| 234 | }, |
|---|
| 235 | |
|---|
| 236 | render: function() { |
|---|
| 237 | @@ -1350,12 +1366,12 @@ |
|---|
| 238 | src: tabUrl + '&tab=' + id, |
|---|
| 239 | title: title, |
|---|
| 240 | content: 'iframe', |
|---|
| 241 | - menu: 'main' |
|---|
| 242 | + menu: 'default' |
|---|
| 243 | }, options ) ); |
|---|
| 244 | }, this ); |
|---|
| 245 | |
|---|
| 246 | this.on( 'content:create:iframe', this.iframeContent, this ); |
|---|
| 247 | - this.on( 'menu:render:main', this.iframeMenu, this ); |
|---|
| 248 | + this.on( 'menu:render:default', this.iframeMenu, this ); |
|---|
| 249 | this.on( 'open', this.hijackThickbox, this ); |
|---|
| 250 | this.on( 'close', this.restoreThickbox, this ); |
|---|
| 251 | }, |
|---|
| 252 | @@ -1449,6 +1465,9 @@ |
|---|
| 253 | createStates: function() { |
|---|
| 254 | var options = this.options; |
|---|
| 255 | |
|---|
| 256 | + if ( this.options.states ) |
|---|
| 257 | + return; |
|---|
| 258 | + |
|---|
| 259 | // Add the default states. |
|---|
| 260 | this.states.add([ |
|---|
| 261 | // Main states. |
|---|
| 262 | @@ -1456,7 +1475,6 @@ |
|---|
| 263 | selection: options.selection, |
|---|
| 264 | library: media.query( options.library ), |
|---|
| 265 | multiple: options.multiple, |
|---|
| 266 | - menu: 'main', |
|---|
| 267 | title: options.title, |
|---|
| 268 | priority: 20 |
|---|
| 269 | }) |
|---|
| 270 | @@ -1464,7 +1482,6 @@ |
|---|
| 271 | }, |
|---|
| 272 | |
|---|
| 273 | bindHandlers: function() { |
|---|
| 274 | - this.on( 'menu:create:main', this.createMenu, this ); |
|---|
| 275 | this.on( 'router:create:browse', this.createRouter, this ); |
|---|
| 276 | this.on( 'router:render:browse', this.browseRouter, this ); |
|---|
| 277 | this.on( 'content:create:browse', this.browseContent, this ); |
|---|
| 278 | @@ -1550,7 +1567,6 @@ |
|---|
| 279 | id: 'insert', |
|---|
| 280 | title: l10n.insertMediaTitle, |
|---|
| 281 | priority: 20, |
|---|
| 282 | - menu: 'main', |
|---|
| 283 | toolbar: 'main-insert', |
|---|
| 284 | filterable: 'all', |
|---|
| 285 | library: media.query( options.library ), |
|---|
| 286 | @@ -1569,7 +1585,6 @@ |
|---|
| 287 | id: 'gallery', |
|---|
| 288 | title: l10n.createGalleryTitle, |
|---|
| 289 | priority: 40, |
|---|
| 290 | - menu: 'main', |
|---|
| 291 | toolbar: 'main-gallery', |
|---|
| 292 | filterable: 'uploaded', |
|---|
| 293 | multiple: 'add', |
|---|
| 294 | @@ -1609,10 +1624,7 @@ |
|---|
| 295 | |
|---|
| 296 | |
|---|
| 297 | if ( media.view.settings.post.featuredImageId ) { |
|---|
| 298 | - this.states.add( new media.controller.FeaturedImage({ |
|---|
| 299 | - controller: this, |
|---|
| 300 | - menu: 'main' |
|---|
| 301 | - }) ); |
|---|
| 302 | + this.states.add( new media.controller.FeaturedImage() ); |
|---|
| 303 | } |
|---|
| 304 | }, |
|---|
| 305 | |
|---|
| 306 | @@ -1626,7 +1638,7 @@ |
|---|
| 307 | |
|---|
| 308 | var handlers = { |
|---|
| 309 | menu: { |
|---|
| 310 | - 'main': 'mainMenu', |
|---|
| 311 | + 'default': 'mainMenu', |
|---|
| 312 | 'gallery': 'galleryMenu' |
|---|
| 313 | }, |
|---|
| 314 | |
|---|