Make WordPress Core

Ticket #36521: 36521.2.diff

File 36521.2.diff, 2.5 KB (added by westonruter, 7 years ago)
  • src/wp-admin/js/customize-controls.js

    diff --git src/wp-admin/js/customize-controls.js src/wp-admin/js/customize-controls.js
    index fad1087..dd7196b 100644
     
    17941794                                        control.pausePlayer();
    17951795                                });
    17961796
    1797                         control.setting.bind( function( value ) {
     1797                        /**
     1798                         * Set attachment data and render content.
     1799                         *
     1800                         * Note that BackgroundImage.prototype.ready applies this ready method
     1801                         * to itself. Since BackgroundImage is an UploadControl, the value
     1802                         * is the attachment URL instead of the attachment ID. In this case
     1803                         * we skip fetching the attachment data because we have no ID available,
     1804                         * and it is the responsibility of the UploadControl to set the control's
     1805                         * attachmentData before calling the renderContent method.
     1806                         *
     1807                         * @param {number|string} value Attachment
     1808                         */
     1809                        function setAttachmentDataAndRenderContent( value ) {
     1810                                var hasAttachmentData = $.Deferred();
     1811
     1812                                if ( control.extended( api.UploadControl ) ) {
     1813                                        hasAttachmentData.resolve();
     1814                                } else {
     1815                                        value = parseInt( value, 10 );
     1816                                        if ( _.isNaN( value ) || value <= 0 ) {
     1817                                                delete control.params.attachment;
     1818                                                hasAttachmentData.resolve();
     1819                                        } else if ( control.params.attachment && control.params.attachment.id === value ) {
     1820                                                hasAttachmentData.resolve();
     1821                                        }
     1822                                }
    17981823
    1799                                 // Send attachment information to the preview for possible use in `postMessage` transport.
    1800                                 wp.media.attachment( value ).fetch().done( function() {
    1801                                         wp.customize.previewer.send( control.setting.id + '-attachment-data', this.attributes );
     1824                                // Fetch the attachment data.
     1825                                if ( 'pending' === hasAttachmentData.state() ) {
     1826                                        wp.media.attachment( value ).fetch().done( function() {
     1827                                                control.params.attachment = this.attributes;
     1828                                                hasAttachmentData.resolve();
     1829
     1830                                                // Send attachment information to the preview for possible use in `postMessage` transport.
     1831                                                wp.customize.previewer.send( control.setting.id + '-attachment-data', this.attributes );
     1832                                        } );
     1833                                }
     1834
     1835                                hasAttachmentData.done( function() {
     1836                                        control.renderContent();
    18021837                                } );
     1838                        }
    18031839
    1804                                 // Re-render whenever the control's setting changes.
    1805                                 control.renderContent();
    1806                         } );
     1840                        // Ensure attachment data is initially set (for dynamically-instantiated controls).
     1841                        setAttachmentDataAndRenderContent( control.setting() );
     1842
     1843                        // Update the attachment data and re-render the control when the setting changes.
     1844                        control.setting.bind( setAttachmentDataAndRenderContent );
    18071845                },
    18081846
    18091847                pausePlayer: function () {