Ticket #21776: 21776.7-refresh.diff
File 21776.7-refresh.diff, 21.2 KB (added by , 12 years ago) |
---|
-
wp-includes/js/media-editor.js
375 375 376 376 workflow = workflows[ id ] = wp.media( _.defaults( options || {}, { 377 377 frame: 'post', 378 state: 'upload', 378 379 title: wp.media.view.l10n.addMedia, 379 380 multiple: true 380 381 } ) ); … … 427 428 } 428 429 }, this ); 429 430 431 workflow.state('featured-image').on( 'select', function() { 432 var settings = wp.media.view.settings, 433 featuredImage = settings.featuredImage, 434 selection = this.get('selection').single(); 435 436 if ( ! featuredImage ) 437 return; 438 439 featuredImage.id = selection ? selection.id : -1; 440 wp.media.post( 'set-post-thumbnail', { 441 json: true, 442 post_id: settings.postId, 443 thumbnail_id: featuredImage.id, 444 _wpnonce: featuredImage.nonce 445 }).done( function( html ) { 446 $( '.inside', '#postimagediv' ).html( html ); 447 }); 448 }); 449 450 workflow.setState( workflow.options.state ); 430 451 return workflow; 431 452 }, 432 453 454 id: function( id ) { 455 if ( id ) 456 return id; 457 458 // If an empty `id` is provided, default to `wpActiveEditor`. 459 id = wpActiveEditor; 460 461 // If that doesn't work, fall back to `tinymce.activeEditor.id`. 462 if ( ! id && typeof tinymce !== 'undefined' && tinymce.activeEditor ) 463 id = tinymce.activeEditor.id; 464 465 // Last but not least, fall back to the empty string. 466 id = id || ''; 467 return id; 468 }, 469 433 470 get: function( id ) { 471 id = this.id( id ); 434 472 return workflows[ id ]; 435 473 }, 436 474 437 475 remove: function( id ) { 476 id = this.id( id ); 438 477 delete workflows[ id ]; 439 478 }, 440 479 … … 497 536 } 498 537 }, 499 538 539 open: function( id ) { 540 var workflow, editor; 541 542 id = this.id( id ); 543 544 // Save a bookmark of the caret position in IE. 545 if ( typeof tinymce !== 'undefined' ) { 546 editor = tinymce.get( id ); 547 548 if ( tinymce.isIE && editor && ! editor.isHidden() ) { 549 editor.focus(); 550 editor.windowManager.insertimagebookmark = editor.selection.getBookmark(); 551 } 552 } 553 554 workflow = this.get( id ); 555 556 // Initialize the editor's workflow if we haven't yet. 557 if ( ! workflow ) 558 workflow = this.add( id ); 559 560 return workflow.open(); 561 }, 562 500 563 init: function() { 501 564 $(document.body).on( 'click', '.insert-media', function( event ) { 502 565 var $this = $(this), … … 513 576 514 577 wp.media.editor.open( editor ); 515 578 }); 516 },517 579 518 open: function( id ) { 519 var workflow, editor; 580 // Open the content media manager to the 'featured image' tab when 581 // the post thumbnail is clicked. 582 $('#postimagediv').on( 'click', '#set-post-thumbnail', function( event ) { 583 event.preventDefault(); 584 // Stop propagation to prevent thickbox from activating. 585 event.stopPropagation(); 520 586 521 // If an empty `id` is provided, default to `wpActiveEditor`. 522 id = id || wpActiveEditor; 587 // Always get the 'content' frame, since this is tailored to post.php. 588 var frame = wp.media.editor.add('content'), 589 initialState = frame.state().id, 590 escape; 523 591 524 if ( typeof tinymce !== 'undefined' && tinymce.activeEditor ) { 525 // If that doesn't work, fall back to `tinymce.activeEditor`. 526 if ( ! id ) { 527 editor = tinymce.activeEditor; 528 id = id || editor.id; 529 } else { 530 editor = tinymce.get( id ); 531 } 592 escape = function() { 593 // Only run this event once. 594 this.off( 'escape', escape ); 532 595 533 // Save a bookmark of the caret position, needed for IE 534 if ( tinymce.isIE && editor && ! editor.isHidden() ) { 535 editor.focus(); 536 editor.windowManager.insertimagebookmark = editor.selection.getBookmark(); 537 } 538 } 596 // If we're still on the 'featured-image' state, restore 597 // the initial state. 598 if ( 'featured-image' === this.state().id ) 599 this.setState( initialState ); 600 }; 539 601 540 // Last but not least, fall back to the empty string. 541 id = id || ''; 602 frame.on( 'escape', escape, frame ); 542 603 543 workflow = wp.media.editor.get( id);604 frame.setState('featured-image').open(); 544 605 545 // If the workflow exists, open it. 546 // Initialize the editor's workflow if we haven't yet. 547 if ( workflow ) 548 workflow.open(); 549 else 550 workflow = wp.media.editor.add( id ); 551 552 return workflow; 606 // Update the featured image id when the 'remove' link is clicked. 607 }).on( 'click', '#remove-post-thumbnail', function() { 608 wp.media.view.settings.featuredImage.id = -1; 609 }); 553 610 } 554 611 }; 555 612 613 _.bindAll( wp.media.editor, 'open' ); 556 614 $( wp.media.editor.init ); 557 615 }(jQuery)); -
wp-includes/js/media-views.js
170 170 // created the `states` collection, or are trying to select a state 171 171 // that does not exist. 172 172 if ( ( previous && id === previous.id ) || ! this.states || ! this.states.get( id ) ) 173 return ;173 return this; 174 174 175 175 if ( previous ) { 176 176 previous.trigger('deactivate'); … … 179 179 180 180 this._state = id; 181 181 this.state().trigger('activate'); 182 183 return this; 182 184 }, 183 185 184 186 // Returns the previous active state. … … 549 551 } 550 552 }); 551 553 554 // wp.media.controller.FeaturedImage 555 // --------------------------------- 556 media.controller.FeaturedImage = media.controller.Library.extend({ 557 defaults: _.defaults({ 558 id: 'featured-image', 559 filterable: 'uploaded', 560 multiple: false, 561 menu: 'main', 562 toolbar: 'featured-image' 563 }, media.controller.Library.prototype.defaults ), 552 564 565 initialize: function() { 566 // If we haven't been provided a `library`, create a `Selection`. 567 if ( ! this.get('library') ) 568 this.set( 'library', media.query({ type: 'image' }) ); 569 570 media.controller.Library.prototype.initialize.apply( this, arguments ); 571 }, 572 573 activate: function() { 574 var selection = this.get('selection'), 575 id = media.view.settings.featuredImage.id; 576 577 if ( '' !== id && -1 !== id ) { 578 attachment = Attachment.get( id ); 579 attachment.fetch(); 580 } 581 582 selection.reset( attachment ? [ attachment ] : [] ); 583 media.controller.Library.prototype.activate.apply( this, arguments ); 584 } 585 }); 586 587 553 588 // wp.media.controller.Embed 554 589 // ------------------------- 555 590 media.controller.Embed = media.controller.State.extend({ … … 605 640 }, this ); 606 641 607 642 this.set( 'url', '' ); 608 this.frame.toolbar.view().refresh(); 643 644 if ( this.id === this.frame.state().id ) 645 this.frame.toolbar.view().refresh(); 609 646 } 610 647 }); 611 648 … … 1077 1114 if ( this.options.modal ) { 1078 1115 this.modal = new media.view.Modal({ 1079 1116 controller: this, 1080 $content: this.$el,1081 1117 title: this.options.title 1082 1118 }); 1119 1120 this.modal.content( this ); 1083 1121 } 1084 1122 1085 1123 // Force the uploader off if the upload limit has been exceeded or … … 1102 1140 this.on( 'attach', _.bind( this.views.ready, this.views ), this ); 1103 1141 }, 1104 1142 1105 render: function() {1106 if ( this.modal )1107 this.modal.render();1108 1109 media.view.Frame.prototype.render.apply( this, arguments );1110 return this;1111 },1112 1113 1143 createIframeStates: function( options ) { 1114 1144 var settings = media.view.settings, 1115 1145 tabs = settings.tabs, … … 1186 1216 }); 1187 1217 1188 1218 // Map some of the modal's methods to the frame. 1189 _.each(['open','close','attach','detach' ], function( method ) {1219 _.each(['open','close','attach','detach','escape'], function( method ) { 1190 1220 media.view.MediaFrame.prototype[ method ] = function( view ) { 1191 1221 if ( this.modal ) 1192 1222 this.modal[ method ].apply( this.modal, arguments ); … … 1202 1232 media.view.MediaFrame.prototype.initialize.apply( this, arguments ); 1203 1233 1204 1234 _.defaults( this.options, { 1205 state: 'upload',1206 1235 selection: [], 1207 1236 library: {}, 1208 1237 multiple: false … … 1349 1378 media.view.MediaFrame.Post = media.view.MediaFrame.Select.extend({ 1350 1379 initialize: function() { 1351 1380 _.defaults( this.options, { 1352 state: 'upload',1353 1381 multiple: true, 1354 1382 editing: false 1355 1383 }); … … 1409 1437 libraryState: 'gallery-edit' 1410 1438 }) 1411 1439 ]); 1440 1441 1442 if ( media.view.settings.featuredImage ) { 1443 this.states.add( new media.controller.FeaturedImage({ 1444 controller: this, 1445 menu: 'main' 1446 }) ); 1447 } 1412 1448 }, 1413 1449 1414 1450 bindHandlers: function() { … … 1427 1463 toolbar: { 1428 1464 'main-attachments': 'mainAttachmentsToolbar', 1429 1465 'main-embed': 'mainEmbedToolbar', 1466 'featured-image': 'featuredImageToolbar', 1430 1467 'gallery-edit': 'galleryEditToolbar', 1431 1468 'gallery-add': 'galleryAddToolbar' 1432 1469 } … … 1444 1481 media.view.MediaFrame.Select.prototype.mainMenu.call( this, { silent: true }); 1445 1482 1446 1483 this.menu.view().set({ 1447 separateLibrary: new media.View({1484 'library-separator': new media.View({ 1448 1485 className: 'separator', 1449 1486 priority: 60 1450 1487 }), 1451 embed: {1488 'embed': { 1452 1489 text: l10n.fromUrlTitle, 1453 1490 priority: 80 1454 1491 } 1455 1492 }); 1493 1494 if ( media.view.settings.featuredImage ) { 1495 this.menu.view().set( 'featured-image', { 1496 text: l10n.featuredImageTitle, 1497 priority: 100 1498 }); 1499 } 1456 1500 }, 1457 1501 1458 1502 galleryMenu: function() { … … 1559 1603 }) ); 1560 1604 }, 1561 1605 1606 featuredImageToolbar: function() { 1607 this.toolbar.view( new media.view.Toolbar.Select({ 1608 controller: this, 1609 text: l10n.setFeaturedImage, 1610 state: this.options.state || 'upload' 1611 }) ); 1612 }, 1613 1562 1614 mainEmbedToolbar: function() { 1563 1615 this.toolbar.view( new media.view.Toolbar.Embed({ 1564 1616 controller: this … … 1629 1681 }, 1630 1682 1631 1683 events: { 1632 'click .media-modal-backdrop, .media-modal-close': ' closeHandler',1684 'click .media-modal-backdrop, .media-modal-close': 'escapeHandler', 1633 1685 'keydown': 'keydown' 1634 1686 }, 1635 1687 … … 1643 1695 }); 1644 1696 }, 1645 1697 1646 render: function() { 1647 // Ensure content div exists. 1648 this.options.$content = this.options.$content || $('<div />'); 1649 1650 // Detach the content element from the DOM to prevent 1651 // `this.$el.html()` from garbage collecting its events. 1652 this.options.$content.detach(); 1653 1654 this.$el.html( this.template({ 1698 prepare: function() { 1699 return { 1655 1700 title: this.options.title 1656 }) ); 1657 1658 this.options.$content.addClass('media-modal-content'); 1659 this.$('.media-modal').append( this.options.$content ); 1660 return this; 1701 }; 1661 1702 }, 1662 1703 1663 1704 attach: function() { 1705 if ( this.views.attached ) 1706 return this; 1707 1708 if ( ! this.views.rendered ) 1709 this.render(); 1710 1664 1711 this.$el.appendTo( this.options.container ); 1712 1713 // Manually mark the view as attached and trigger ready. 1714 this.views.attached = true; 1715 this.views.ready(); 1716 1665 1717 return this.propagate('attach'); 1666 1718 }, 1667 1719 1668 1720 detach: function() { 1721 if ( this.$el.is(':visible') ) 1722 this.close(); 1723 1669 1724 this.$el.detach(); 1725 this.views.attached = false; 1670 1726 return this.propagate('detach'); 1671 1727 }, 1672 1728 1673 1729 open: function() { 1730 if ( this.$el.is(':visible') ) 1731 return this; 1732 1733 if ( ! this.views.attached ) 1734 this.attach(); 1735 1674 1736 this.$el.show().focus(); 1675 1737 return this.propagate('open'); 1676 1738 }, 1677 1739 1678 close: function() { 1740 close: function( options ) { 1741 if ( ! this.views.attached || ! this.$el.is(':visible') ) 1742 return this; 1743 1679 1744 this.$el.hide(); 1680 return this.propagate('close'); 1745 this.propagate('close'); 1746 1747 if ( options && options.escape ) 1748 this.propagate('escape'); 1749 1750 return this; 1681 1751 }, 1682 1752 1683 closeHandler: function( event ) { 1753 escape: function() { 1754 return this.close({ escape: true }); 1755 }, 1756 1757 escapeHandler: function( event ) { 1684 1758 event.preventDefault(); 1685 this. close();1759 this.escape(); 1686 1760 }, 1687 1761 1688 content: function( $content ) { 1689 // Detach any existing content to prevent events from being lost. 1690 if ( this.options.$content ) 1691 this.options.$content.detach(); 1692 1693 // Set and render the content. 1694 this.options.$content = ( $content instanceof Backbone.View ) ? $content.$el : $content; 1695 return this.render(); 1762 content: function( content ) { 1763 this.views.set( '.media-modal-content', content ); 1764 return this; 1696 1765 }, 1697 1766 1698 1767 // Triggers a modal event and if the `propagate` option is set, … … 1710 1779 // Close the modal when escape is pressed. 1711 1780 if ( 27 === event.which ) { 1712 1781 event.preventDefault(); 1713 this. close();1782 this.escape(); 1714 1783 return; 1715 1784 } 1716 1785 } -
wp-includes/js/media-models.js
30 30 frame = new MediaFrame.Post( attributes ); 31 31 32 32 delete attributes.frame; 33 // Set the default state. 34 frame.setState( frame.options.state ); 35 // Render, attach, and open the frame. 36 return frame.render().attach().open(); 33 34 return frame; 37 35 }; 38 36 39 37 _.extend( media, { model: {}, view: {}, controller: {} }); … … 235 233 236 234 // Overload the `update` request so properties can be saved. 237 235 } else if ( 'update' === method ) { 236 if ( ! this.get('nonces') ) 237 return $.Deferred().resolveWith( this ).promise(); 238 238 239 options = options || {}; 239 240 options.context = this; 240 241 -
wp-includes/media.php
1434 1434 $post = get_post( $args['post'] ); 1435 1435 $settings['postId'] = $post->ID; 1436 1436 $settings['nonce']['updatePost'] = wp_create_nonce( 'update-post_' . $post->ID ); 1437 1438 if ( current_theme_supports( 'post-thumbnails', $post->post_type ) && post_type_supports( $post->post_type, 'thumbnail' ) ) { 1439 1440 $featuredImageId = get_post_meta( $post->ID, '_thumbnail_id', true ); 1441 1442 $settings['featuredImage'] = array( 1443 'id' => $featuredImageId ? $featuredImageId : -1, 1444 'nonce' => wp_create_nonce( 'set_post_thumbnail-' . $post->ID ), 1445 ); 1446 } 1437 1447 } 1438 1448 1439 1449 $hier = $post && is_post_type_hierarchical( $post->post_type ); … … 1467 1477 // From URL 1468 1478 'fromUrlTitle' => __( 'From URL' ), 1469 1479 1480 // Featured Images 1481 'featuredImageTitle' => __( 'Featured Image' ), 1482 'setFeaturedImage' => __( 'Set featured image' ), 1483 1470 1484 // Gallery 1471 1485 'createGalleryTitle' => __( 'Create Gallery' ), 1472 1486 'editGalleryTitle' => __( 'Edit Gallery' ), … … 1511 1525 <div class="media-modal wp-core-ui"> 1512 1526 <h3 class="media-modal-title">{{ data.title }}</h3> 1513 1527 <a class="media-modal-close media-modal-icon" href="#" title="<?php esc_attr_e('Close'); ?>"></a> 1528 <div class="media-modal-content"></div> 1514 1529 </div> 1515 1530 <div class="media-modal-backdrop"> 1516 1531 <div></div> -
wp-includes/css/media-views.css
403 403 */ 404 404 .media-frame { 405 405 overflow: hidden; 406 position: absolute; 407 top: 0; 408 left: 0; 409 right: 0; 410 bottom: 0; 406 411 } 407 412 408 413 .media-frame .region-content { -
wp-admin/includes/ajax-actions.php
1674 1674 } 1675 1675 1676 1676 function wp_ajax_set_post_thumbnail() { 1677 $json = ! empty( $_REQUEST['json'] ); 1678 1677 1679 $post_ID = intval( $_POST['post_id'] ); 1678 if ( !current_user_can( 'edit_post', $post_ID ) ) 1679 wp_die( -1 ); 1680 if ( !current_user_can( 'edit_post', $post_ID ) ) { 1681 $json ? wp_send_json_error() : wp_die( -1 ); 1682 } 1680 1683 $thumbnail_id = intval( $_POST['thumbnail_id'] ); 1681 1684 1682 1685 check_ajax_referer( "set_post_thumbnail-$post_ID" ); 1683 1686 1684 1687 if ( $thumbnail_id == '-1' ) { 1685 if ( delete_post_thumbnail( $post_ID ) ) 1686 wp_die( _wp_post_thumbnail_html( null, $post_ID ) ); 1687 else 1688 wp_die( 0 ); 1688 if ( delete_post_thumbnail( $post_ID ) ) { 1689 $return = _wp_post_thumbnail_html( null, $post_ID ); 1690 $json ? wp_send_json_success( $return ) : wp_die( $return ); 1691 } else { 1692 $json ? wp_send_json_error() : wp_die( 0 ); 1693 } 1689 1694 } 1690 1695 1691 if ( set_post_thumbnail( $post_ID, $thumbnail_id ) ) 1692 wp_die( _wp_post_thumbnail_html( $thumbnail_id, $post_ID ) ); 1693 wp_die( 0 ); 1696 if ( set_post_thumbnail( $post_ID, $thumbnail_id ) ) { 1697 $return = _wp_post_thumbnail_html( $thumbnail_id, $post_ID ); 1698 $json ? wp_send_json_success( $return ) : wp_die( $return ); 1699 } 1700 1701 $json ? wp_send_json_error() : wp_die( 0 ); 1694 1702 } 1695 1703 1696 1704 function wp_ajax_date_format() { -
wp-admin/includes/post.php
199 199 set_post_format( $post_ID, false ); 200 200 } 201 201 202 // Featured Images203 if ( isset( $post_data['thumbnail_id'] ) ) {204 if ( '-1' == $post_data['thumbnail_id'] )205 delete_post_thumbnail( $post_ID );206 else207 set_post_thumbnail( $post_ID, $post_data['thumbnail_id'] );208 }209 210 202 // Meta Stuff 211 203 if ( isset($post_data['meta']) && $post_data['meta'] ) { 212 204 foreach ( $post_data['meta'] as $key => $value ) { -
wp-admin/includes/meta-boxes.php
1001 1001 * @since 2.9.0 1002 1002 */ 1003 1003 function post_thumbnail_meta_box( $post ) { 1004 global $_wp_additional_image_sizes; 1005 1006 ?><script type="text/javascript"> 1007 jQuery( function($) { 1008 var $element = $('#select-featured-image'), 1009 $thumbnailId = $element.find('input[name="thumbnail_id"]'), 1010 title = '<?php _e( "Choose a Featured Image" ); ?>', 1011 update = '<?php _e( "Update Featured Image" ); ?>', 1012 Attachment = wp.media.model.Attachment, 1013 frame, setFeaturedImage; 1014 1015 setFeaturedImage = function( thumbnailId ) { 1016 var selection; 1017 1018 $element.find('img').remove(); 1019 $element.toggleClass( 'has-featured-image', -1 != thumbnailId ); 1020 $thumbnailId.val( thumbnailId ); 1021 1022 if ( frame ) { 1023 selection = frame.state('library').get('selection'); 1024 1025 if ( -1 === thumbnailId ) 1026 selection.clear(); 1027 else 1028 selection.add( Attachment.get( thumbnailId ) ); 1029 } 1030 }; 1031 1032 $element.on( 'click', '.choose, img', function( event ) { 1033 var options, thumbnailId, attachment; 1034 1035 event.preventDefault(); 1036 1037 if ( frame ) { 1038 frame.open(); 1039 return; 1040 } 1041 1042 options = { 1043 title: title, 1044 library: { 1045 type: 'image' 1046 } 1047 }; 1048 1049 thumbnailId = $thumbnailId.val(); 1050 if ( '' !== thumbnailId && -1 !== thumbnailId ) { 1051 attachment = Attachment.get( thumbnailId ); 1052 attachment.fetch(); 1053 options.selection = [ attachment ]; 1054 } 1055 1056 frame = wp.media( options ); 1057 1058 frame.state('library').set( 'filterable', 'uploaded' ); 1059 1060 frame.toolbar.on( 'activate:select', function() { 1061 frame.toolbar.view().set({ 1062 select: { 1063 style: 'primary', 1064 text: update, 1065 1066 click: function() { 1067 var selection = frame.state().get('selection'), 1068 model = selection.first(), 1069 sizes = model.get('sizes'), 1070 size; 1071 1072 setFeaturedImage( model.id ); 1073 1074 // @todo: might need a size hierarchy equivalent. 1075 if ( sizes ) 1076 size = sizes['post-thumbnail'] || sizes.medium; 1077 1078 // @todo: Need a better way of accessing full size 1079 // data besides just calling toJSON(). 1080 size = size || model.toJSON(); 1081 1082 frame.close(); 1083 1084 $( '<img />', { 1085 src: size.url, 1086 width: size.width 1087 }).prependTo( $element ); 1088 } 1089 } 1090 }); 1091 }); 1092 1093 frame.toolbar.mode('select'); 1094 }); 1095 1096 $element.on( 'click', '.remove', function( event ) { 1097 event.preventDefault(); 1098 setFeaturedImage( -1 ); 1099 }); 1100 }); 1101 </script> 1102 1103 <?php 1104 $thumbnail_id = get_post_meta( $post->ID, '_thumbnail_id', true ); 1105 $thumbnail_size = isset( $_wp_additional_image_sizes['post-thumbnail'] ) ? 'post-thumbnail' : 'medium'; 1106 $thumbnail_html = wp_get_attachment_image( $thumbnail_id, $thumbnail_size ); 1107 1108 $classes = empty( $thumbnail_id ) ? '' : 'has-featured-image'; 1109 1110 ?><div id="select-featured-image" 1111 class="<?php echo esc_attr( $classes ); ?>" 1112 data-post-id="<?php echo esc_attr( $post->ID ); ?>"> 1113 <?php echo $thumbnail_html; ?> 1114 <input type="hidden" name="thumbnail_id" value="<?php echo esc_attr( $thumbnail_id ); ?>" /> 1115 <a href="#" class="choose button-secondary"><?php _e( 'Choose a Featured Image' ); ?></a> 1116 <a href="#" class="remove"><?php _e( 'Remove Featured Image' ); ?></a> 1117 </div> 1118 <?php 1004 $thumbnail_id = get_post_meta( $post->ID, '_thumbnail_id', true ); 1005 echo _wp_post_thumbnail_html( $thumbnail_id, $post->ID ); 1119 1006 } 1007 No newline at end of file -
wp-admin/js/custom-background.js
57 57 }); 58 58 }); 59 59 60 frame.setState('library') ;60 frame.setState('library').open(); 61 61 }); 62 62 }); 63 63 })(jQuery); 64 No newline at end of file -
wp-admin/js/custom-header.js
40 40 }); 41 41 }); 42 42 43 frame.setState('library') ;43 frame.setState('library').open(); 44 44 }); 45 45 }); 46 46 }(jQuery));