26 * |
26 * |
27 * @since 4.7.0 |
27 * @since 4.7.0 |
28 * @access private |
28 * @access private |
29 * |
29 * |
30 * @param {string} url URL. |
30 * @param {string} url URL. |
31 * @returns {string} URL with customized state. |
31 * @return {string} URL with customized state. |
32 */ |
32 */ |
33 injectUrlWithState = function( url ) { |
33 injectUrlWithState = function( url ) { |
34 var urlParser, oldQueryParams, newQueryParams; |
34 var urlParser, oldQueryParams, newQueryParams; |
35 urlParser = document.createElement( 'a' ); |
35 urlParser = document.createElement( 'a' ); |
36 urlParser.href = url; |
36 urlParser.href = url; |
100 * @augments wp.customize.Class |
100 * @augments wp.customize.Class |
101 * @mixes wp.customize.Events |
101 * @mixes wp.customize.Events |
102 */ |
102 */ |
103 api.Preview = api.Messenger.extend(/** @lends wp.customize.Preview.prototype */{ |
103 api.Preview = api.Messenger.extend(/** @lends wp.customize.Preview.prototype */{ |
104 /** |
104 /** |
105 * @param {object} params - Parameters to configure the messenger. |
105 * @param {Object} params - Parameters to configure the messenger. |
106 * @param {object} options - Extend any instance parameter or method with this object. |
106 * @param {Object} options - Extend any instance parameter or method with this object. |
107 */ |
107 */ |
108 initialize: function( params, options ) { |
108 initialize: function( params, options ) { |
109 var preview = this, urlParser = document.createElement( 'a' ); |
109 var preview = this, urlParser = document.createElement( 'a' ); |
110 |
110 |
111 api.Messenger.prototype.initialize.call( preview, params, options ); |
111 api.Messenger.prototype.initialize.call( preview, params, options ); |
274 * |
274 * |
275 * @param {HTMLAnchorElement|HTMLAreaElement} element Link element. |
275 * @param {HTMLAnchorElement|HTMLAreaElement} element Link element. |
276 * @param {string} element.search Query string. |
276 * @param {string} element.search Query string. |
277 * @param {string} element.pathname Path. |
277 * @param {string} element.pathname Path. |
278 * @param {string} element.host Host. |
278 * @param {string} element.host Host. |
279 * @param {object} [options] |
279 * @param {Object} [options] |
280 * @param {object} [options.allowAdminAjax=false] Allow admin-ajax.php requests. |
280 * @param {Object} [options.allowAdminAjax=false] Allow admin-ajax.php requests. |
281 * @returns {boolean} Is appropriate for changeset link. |
281 * @return {boolean} Is appropriate for changeset link. |
282 */ |
282 */ |
283 api.isLinkPreviewable = function isLinkPreviewable( element, options ) { |
283 api.isLinkPreviewable = function isLinkPreviewable( element, options ) { |
284 var matchesAllowedUrl, parsedAllowedUrl, args, elementHost; |
284 var matchesAllowedUrl, parsedAllowedUrl, args, elementHost; |
285 |
285 |
286 args = _.extend( {}, { allowAdminAjax: false }, options || {} ); |
286 args = _.extend( {}, { allowAdminAjax: false }, options || {} ); |
330 * |
330 * |
331 * @param {HTMLAnchorElement|HTMLAreaElement} element Link element. |
331 * @param {HTMLAnchorElement|HTMLAreaElement} element Link element. |
332 * @param {string} element.search Query string. |
332 * @param {string} element.search Query string. |
333 * @param {string} element.host Host. |
333 * @param {string} element.host Host. |
334 * @param {string} element.protocol Protocol. |
334 * @param {string} element.protocol Protocol. |
335 * @returns {void} |
335 * @return {void} |
336 */ |
336 */ |
337 api.prepareLinkPreview = function prepareLinkPreview( element ) { |
337 api.prepareLinkPreview = function prepareLinkPreview( element ) { |
338 var queryParams, $element = $( element ); |
338 var queryParams, $element = $( element ); |
339 |
339 |
340 // Skip elements with no href attribute. Check first to avoid more expensive checks down the road |
340 // Skip elements with no href attribute. Check first to avoid more expensive checks down the road. |
341 if ( ! element.hasAttribute( 'href' ) ) { |
341 if ( ! element.hasAttribute( 'href' ) ) { |
342 return; |
342 return; |
343 } |
343 } |
344 |
344 |
345 // Skip links in admin bar. |
345 // Skip links in admin bar. |
355 // Make sure links in preview use HTTPS if parent frame uses HTTPS. |
355 // Make sure links in preview use HTTPS if parent frame uses HTTPS. |
356 if ( api.settings.channel && 'https' === api.preview.scheme.get() && 'http:' === element.protocol && -1 !== api.settings.url.allowedHosts.indexOf( element.host ) ) { |
356 if ( api.settings.channel && 'https' === api.preview.scheme.get() && 'http:' === element.protocol && -1 !== api.settings.url.allowedHosts.indexOf( element.host ) ) { |
357 element.protocol = 'https:'; |
357 element.protocol = 'https:'; |
358 } |
358 } |
359 |
359 |
360 // Ignore links with class wp-playlist-caption |
360 // Ignore links with class wp-playlist-caption. |
361 if ( $element.hasClass( 'wp-playlist-caption' ) ) { |
361 if ( $element.hasClass( 'wp-playlist-caption' ) ) { |
362 return; |
362 return; |
363 } |
363 } |
364 |
364 |
365 if ( ! api.isLinkPreviewable( element ) ) { |
365 if ( ! api.isLinkPreviewable( element ) ) { |
397 api.addRequestPreviewing = function addRequestPreviewing() { |
397 api.addRequestPreviewing = function addRequestPreviewing() { |
398 |
398 |
399 /** |
399 /** |
400 * Rewrite Ajax requests to inject customizer state. |
400 * Rewrite Ajax requests to inject customizer state. |
401 * |
401 * |
402 * @param {object} options Options. |
402 * @param {Object} options Options. |
403 * @param {string} options.type Type. |
403 * @param {string} options.type Type. |
404 * @param {string} options.url URL. |
404 * @param {string} options.url URL. |
405 * @param {object} originalOptions Original options. |
405 * @param {Object} originalOptions Original options. |
406 * @param {XMLHttpRequest} xhr XHR. |
406 * @param {XMLHttpRequest} xhr XHR. |
407 * @returns {void} |
407 * @return {void} |
408 */ |
408 */ |
409 var prefilterAjax = function( options, originalOptions, xhr ) { |
409 var prefilterAjax = function( options, originalOptions, xhr ) { |
410 var urlParser, queryParams, requestMethod, dirtyValues = {}; |
410 var urlParser, queryParams, requestMethod, dirtyValues = {}; |
411 urlParser = document.createElement( 'a' ); |
411 urlParser = document.createElement( 'a' ); |
412 urlParser.href = options.url; |
412 urlParser.href = options.url; |
468 * Inject changeset UUID into forms, allowing preview to persist through submissions. |
468 * Inject changeset UUID into forms, allowing preview to persist through submissions. |
469 * |
469 * |
470 * @since 4.7.0 |
470 * @since 4.7.0 |
471 * @access protected |
471 * @access protected |
472 * |
472 * |
473 * @returns {void} |
473 * @return {void} |
474 */ |
474 */ |
475 api.addFormPreviewing = function addFormPreviewing() { |
475 api.addFormPreviewing = function addFormPreviewing() { |
476 |
476 |
477 // Inject inputs for forms in initial document. |
477 // Inject inputs for forms in initial document. |
478 $( document.body ).find( 'form' ).each( function() { |
478 $( document.body ).find( 'form' ).each( function() { |
624 |
624 |
625 /** |
625 /** |
626 * Preview changes to custom logo. |
626 * Preview changes to custom logo. |
627 * |
627 * |
628 * @param {number} attachmentId Attachment ID for custom logo. |
628 * @param {number} attachmentId Attachment ID for custom logo. |
629 * @returns {void} |
629 * @return {void} |
630 */ |
630 */ |
631 custom_logo: function( attachmentId ) { |
631 custom_logo: function( attachmentId ) { |
632 $( 'body' ).toggleClass( 'wp-custom-logo', !! attachmentId ); |
632 $( 'body' ).toggleClass( 'wp-custom-logo', !! attachmentId ); |
633 }, |
633 }, |
634 |
634 |
635 /** |
635 /** |
636 * Preview changes to custom css. |
636 * Preview changes to custom css. |
637 * |
637 * |
638 * @param {string} value Custom CSS.. |
638 * @param {string} value Custom CSS.. |
639 * @returns {void} |
639 * @return {void} |
640 */ |
640 */ |
641 custom_css: function( value ) { |
641 custom_css: function( value ) { |
642 $( '#wp-custom-css' ).text( value ); |
642 $( '#wp-custom-css' ).text( value ); |
643 }, |
643 }, |
644 |
644 |
645 /** |
645 /** |
646 * Preview changes to any of the background settings. |
646 * Preview changes to any of the background settings. |
647 * |
647 * |
648 * @returns {void} |
648 * @return {void} |
649 */ |
649 */ |
650 background: function() { |
650 background: function() { |
651 var css = '', settings = {}; |
651 var css = '', settings = {}; |
652 |
652 |
653 _.each( ['color', 'image', 'preset', 'position_x', 'position_y', 'size', 'repeat', 'attachment'], function( prop ) { |
653 _.each( ['color', 'image', 'preset', 'position_x', 'position_y', 'size', 'repeat', 'attachment'], function( prop ) { |
773 |
773 |
774 /** |
774 /** |
775 * Handle update to changeset UUID. |
775 * Handle update to changeset UUID. |
776 * |
776 * |
777 * @param {string} uuid - UUID. |
777 * @param {string} uuid - UUID. |
778 * @returns {void} |
778 * @return {void} |
779 */ |
779 */ |
780 handleUpdatedChangesetUuid = function( uuid ) { |
780 handleUpdatedChangesetUuid = function( uuid ) { |
781 api.settings.changeset.uuid = uuid; |
781 api.settings.changeset.uuid = uuid; |
782 |
782 |
783 // Update UUIDs in links and forms. |
783 // Update UUIDs in links and forms. |