equal
deleted
inserted
replaced
1 /* |
1 /* |
2 * Script run inside a Customizer preview frame. |
2 * Script run inside a Customizer preview frame. |
|
3 * |
|
4 * @output wp-includes/js/customize-preview.js |
3 */ |
5 */ |
4 (function( exports, $ ){ |
6 (function( exports, $ ){ |
5 var api = wp.customize, |
7 var api = wp.customize, |
6 debounce, |
8 debounce, |
7 currentHistoryState = {}; |
9 currentHistoryState = {}; |
233 * |
235 * |
234 * @access private |
236 * @access private |
235 * @returns {void} |
237 * @returns {void} |
236 */ |
238 */ |
237 api.addLinkPreviewing = function addLinkPreviewing() { |
239 api.addLinkPreviewing = function addLinkPreviewing() { |
238 var linkSelectors = 'a[href], area'; |
240 var linkSelectors = 'a[href], area[href]'; |
239 |
241 |
240 // Inject links into initial document. |
242 // Inject links into initial document. |
241 $( document.body ).find( linkSelectors ).each( function() { |
243 $( document.body ).find( linkSelectors ).each( function() { |
242 api.prepareLinkPreview( this ); |
244 api.prepareLinkPreview( this ); |
243 } ); |
245 } ); |
333 * @returns {void} |
335 * @returns {void} |
334 */ |
336 */ |
335 api.prepareLinkPreview = function prepareLinkPreview( element ) { |
337 api.prepareLinkPreview = function prepareLinkPreview( element ) { |
336 var queryParams, $element = $( element ); |
338 var queryParams, $element = $( element ); |
337 |
339 |
|
340 // Skip elements with no href attribute. Check first to avoid more expensive checks down the road |
|
341 if ( ! element.hasAttribute( 'href' ) ) { |
|
342 return; |
|
343 } |
|
344 |
338 // Skip links in admin bar. |
345 // Skip links in admin bar. |
339 if ( $element.closest( '#wpadminbar' ).length ) { |
346 if ( $element.closest( '#wpadminbar' ).length ) { |
340 return; |
347 return; |
341 } |
348 } |
342 |
349 |
375 } |
382 } |
376 if ( api.settings.channel ) { |
383 if ( api.settings.channel ) { |
377 queryParams.customize_messenger_channel = api.settings.channel; |
384 queryParams.customize_messenger_channel = api.settings.channel; |
378 } |
385 } |
379 element.search = $.param( queryParams ); |
386 element.search = $.param( queryParams ); |
380 |
|
381 // Prevent links from breaking out of preview iframe. |
|
382 if ( api.settings.channel ) { |
|
383 element.target = '_self'; |
|
384 } |
|
385 }; |
387 }; |
386 |
388 |
387 /** |
389 /** |
388 * Inject the changeset UUID into Ajax requests. |
390 * Inject the changeset UUID into Ajax requests. |
389 * |
391 * |
777 */ |
779 */ |
778 handleUpdatedChangesetUuid = function( uuid ) { |
780 handleUpdatedChangesetUuid = function( uuid ) { |
779 api.settings.changeset.uuid = uuid; |
781 api.settings.changeset.uuid = uuid; |
780 |
782 |
781 // Update UUIDs in links and forms. |
783 // Update UUIDs in links and forms. |
782 $( document.body ).find( 'a[href], area' ).each( function() { |
784 $( document.body ).find( 'a[href], area[href]' ).each( function() { |
783 api.prepareLinkPreview( this ); |
785 api.prepareLinkPreview( this ); |
784 } ); |
786 } ); |
785 $( document.body ).find( 'form' ).each( function() { |
787 $( document.body ).find( 'form' ).each( function() { |
786 api.prepareFormPreview( this ); |
788 api.prepareFormPreview( this ); |
787 } ); |
789 } ); |
811 return; |
813 return; |
812 } |
814 } |
813 |
815 |
814 api.settings.changeset.autosaved = true; // Start deferring to any autosave once changeset is updated. |
816 api.settings.changeset.autosaved = true; // Start deferring to any autosave once changeset is updated. |
815 |
817 |
816 $( document.body ).find( 'a[href], area' ).each( function() { |
818 $( document.body ).find( 'a[href], area[href]' ).each( function() { |
817 api.prepareLinkPreview( this ); |
819 api.prepareLinkPreview( this ); |
818 } ); |
820 } ); |
819 $( document.body ).find( 'form' ).each( function() { |
821 $( document.body ).find( 'form' ).each( function() { |
820 api.prepareFormPreview( this ); |
822 api.prepareFormPreview( this ); |
821 } ); |
823 } ); |