Ticket #22731: 22731.2.diff
File 22731.2.diff, 8.5 KB (added by , 11 years ago) |
---|
-
wp-includes/js/media-editor.js
320 320 }; 321 321 }()); 322 322 323 wp.media.featuredImage = { 324 get: function() { 325 return wp.media.view.settings.post.featuredImageId; 326 }, 327 328 set: function( id ) { 329 var settings = wp.media.view.settings; 330 331 settings.post.featuredImageId = id; 332 333 wp.media.post( 'set-post-thumbnail', { 334 json: true, 335 post_id: settings.post.id, 336 thumbnail_id: settings.post.featuredImageId, 337 _wpnonce: settings.post.nonce 338 }).done( function( html ) { 339 $( '.inside', '#postimagediv' ).html( html ); 340 }); 341 }, 342 343 frame: function() { 344 if ( this._frame ) 345 return this._frame; 346 347 this._frame = wp.media({ 348 state: 'featured-image', 349 states: [ new wp.media.controller.FeaturedImage() ] 350 }); 351 352 this._frame.on( 'toolbar:create:featured-image', function( toolbar ) { 353 this.createSelectToolbar( toolbar, { 354 text: wp.media.view.l10n.setFeaturedImage 355 }); 356 }, this._frame ); 357 358 this._frame.state('featured-image').on( 'select', this.select ); 359 return this._frame; 360 }, 361 362 select: function() { 363 var settings = wp.media.view.settings, 364 selection = this.get('selection').single(); 365 366 if ( ! settings.post.featuredImageId ) 367 return; 368 369 wp.media.featuredImage.set( selection ? selection.id : -1 ); 370 }, 371 372 init: function() { 373 // Open the content media manager to the 'featured image' tab when 374 // the post thumbnail is clicked. 375 $('#postimagediv').on( 'click', '#set-post-thumbnail', function( event ) { 376 event.preventDefault(); 377 // Stop propagation to prevent thickbox from activating. 378 event.stopPropagation(); 379 380 wp.media.featuredImage.frame().open(); 381 382 // Update the featured image id when the 'remove' link is clicked. 383 }).on( 'click', '#remove-post-thumbnail', function() { 384 wp.media.view.settings.post.featuredImageId = -1; 385 }); 386 } 387 }; 388 389 $( wp.media.featuredImage.init ); 390 323 391 wp.media.editor = { 324 392 insert: function( h ) { 325 393 var mce = typeof(tinymce) != 'undefined', … … 443 511 } 444 512 }, this ); 445 513 446 workflow.state('featured-image').on( 'select', function() { 447 var settings = wp.media.view.settings, 448 selection = this.get('selection').single(); 449 450 if ( ! settings.post.featuredImageId ) 451 return; 452 453 settings.post.featuredImageId = selection ? selection.id : -1; 454 wp.media.post( 'set-post-thumbnail', { 455 json: true, 456 post_id: settings.post.id, 457 thumbnail_id: settings.post.featuredImageId, 458 _wpnonce: settings.post.nonce 459 }).done( function( html ) { 460 $( '.inside', '#postimagediv' ).html( html ); 461 }); 462 }); 463 514 workflow.state('featured-image').on( 'select', wp.media.featuredImage.select ); 464 515 workflow.setState( workflow.options.state ); 465 516 return workflow; 466 517 }, … … 586 637 587 638 wp.media.editor.open( editor ); 588 639 }); 589 590 // Open the content media manager to the 'featured image' tab when591 // the post thumbnail is clicked.592 $('#postimagediv').on( 'click', '#set-post-thumbnail', function( event ) {593 event.preventDefault();594 // Stop propagation to prevent thickbox from activating.595 event.stopPropagation();596 597 // Always get the 'content' frame, since this is tailored to post.php.598 var frame = wp.media.editor.add('content'),599 initialState = frame.state().id,600 escape;601 602 escape = function() {603 // Only run this event once.604 this.off( 'escape', escape );605 606 // If we're still on the 'featured-image' state, restore607 // the initial state.608 if ( 'featured-image' === this.state().id )609 this.setState( initialState );610 };611 612 frame.on( 'escape', escape, frame );613 614 frame.setState('featured-image').open();615 616 // Update the featured image id when the 'remove' link is clicked.617 }).on( 'click', '#remove-post-thumbnail', function() {618 wp.media.view.settings.post.featuredImageId = -1;619 });620 640 } 621 641 }; 622 642 -
wp-includes/js/media-views.js
289 289 this.frame.router.render( mode ); 290 290 291 291 view = router.get(); 292 if ( view .select )292 if ( view && view.select ) 293 293 view.select( this.frame.content.mode() ); 294 294 }, 295 295 … … 304 304 menu.mode( mode ); 305 305 306 306 view = menu.get(); 307 if ( view .select )307 if ( view && view.select ) 308 308 view.select( this.id ); 309 309 }, 310 310 … … 357 357 sidebar: 'settings', 358 358 content: 'upload', 359 359 router: 'browse', 360 menu: 'default', 360 361 searchable: true, 361 362 filterable: false, 362 363 sortable: true, … … 669 670 id: 'featured-image', 670 671 filterable: 'uploaded', 671 672 multiple: false, 672 menu: 'main',673 673 toolbar: 'featured-image', 674 674 title: l10n.featuredImageTitle, 675 675 priority: 60 … … 707 707 }, 708 708 709 709 activate: function() { 710 this.updateSelection(); 711 this.frame.on( 'open', this.updateSelection, this ); 712 media.controller.Library.prototype.activate.apply( this, arguments ); 713 }, 714 715 deactivate: function() { 716 this.frame.off( 'open', this.updateSelection, this ); 717 media.controller.Library.prototype.deactivate.apply( this, arguments ); 718 }, 719 720 updateSelection: function() { 710 721 var selection = this.get('selection'), 711 722 id = media.view.settings.post.featuredImageId, 712 723 attachment; … … 717 728 } 718 729 719 730 selection.reset( attachment ? [ attachment ] : [] ); 720 media.controller.Library.prototype.activate.apply( this, arguments );721 731 } 722 732 }); 723 733 … … 728 738 defaults: { 729 739 id: 'embed', 730 740 url: '', 731 menu: ' main',741 menu: 'default', 732 742 content: 'embed', 733 743 toolbar: 'main-embed', 734 744 type: 'link', … … 1231 1241 model.frame = this; 1232 1242 model.trigger('ready'); 1233 1243 }, this ); 1244 1245 if ( this.options.states ) 1246 this.states.add( this.options.states ); 1234 1247 }, 1235 1248 1236 1249 reset: function() { … … 1294 1307 // Bind default title creation. 1295 1308 this.on( 'title:create:default', this.createTitle, this ); 1296 1309 this.title.mode('default'); 1310 1311 // Bind default menu. 1312 this.on( 'menu:create:default', this.createMenu, this ); 1297 1313 }, 1298 1314 1299 1315 render: function() { … … 1350 1366 src: tabUrl + '&tab=' + id, 1351 1367 title: title, 1352 1368 content: 'iframe', 1353 menu: ' main'1369 menu: 'default' 1354 1370 }, options ) ); 1355 1371 }, this ); 1356 1372 1357 1373 this.on( 'content:create:iframe', this.iframeContent, this ); 1358 this.on( 'menu:render: main', this.iframeMenu, this );1374 this.on( 'menu:render:default', this.iframeMenu, this ); 1359 1375 this.on( 'open', this.hijackThickbox, this ); 1360 1376 this.on( 'close', this.restoreThickbox, this ); 1361 1377 }, … … 1449 1465 createStates: function() { 1450 1466 var options = this.options; 1451 1467 1468 if ( this.options.states ) 1469 return; 1470 1452 1471 // Add the default states. 1453 1472 this.states.add([ 1454 1473 // Main states. … … 1456 1475 selection: options.selection, 1457 1476 library: media.query( options.library ), 1458 1477 multiple: options.multiple, 1459 menu: 'main',1460 1478 title: options.title, 1461 1479 priority: 20 1462 1480 }) … … 1464 1482 }, 1465 1483 1466 1484 bindHandlers: function() { 1467 this.on( 'menu:create:main', this.createMenu, this );1468 1485 this.on( 'router:create:browse', this.createRouter, this ); 1469 1486 this.on( 'router:render:browse', this.browseRouter, this ); 1470 1487 this.on( 'content:create:browse', this.browseContent, this ); … … 1550 1567 id: 'insert', 1551 1568 title: l10n.insertMediaTitle, 1552 1569 priority: 20, 1553 menu: 'main',1554 1570 toolbar: 'main-insert', 1555 1571 filterable: 'all', 1556 1572 library: media.query( options.library ), … … 1569 1585 id: 'gallery', 1570 1586 title: l10n.createGalleryTitle, 1571 1587 priority: 40, 1572 menu: 'main',1573 1588 toolbar: 'main-gallery', 1574 1589 filterable: 'uploaded', 1575 1590 multiple: 'add', … … 1609 1624 1610 1625 1611 1626 if ( media.view.settings.post.featuredImageId ) { 1612 this.states.add( new media.controller.FeaturedImage({ 1613 controller: this, 1614 menu: 'main' 1615 }) ); 1627 this.states.add( new media.controller.FeaturedImage() ); 1616 1628 } 1617 1629 }, 1618 1630 … … 1626 1638 1627 1639 var handlers = { 1628 1640 menu: { 1629 ' main':'mainMenu',1641 'default': 'mainMenu', 1630 1642 'gallery': 'galleryMenu' 1631 1643 }, 1632 1644