PluginProbe
Jetpack – WP Security, Backup, Speed, & Growth / 6.2.2
Jetpack – WP Security, Backup, Speed, & Growth v6.2.2
16.2-beta 12.0.3 12.1.3 12.2.3 12.3.2 12.4.2 12.5.2 12.6.4 12.7.3 12.8.3 12.9.5 13.0.2 13.1.5 13.2.4 13.3.3 13.4.5 13.5.2 13.6.2 13.7.2 13.8.3 13.9.2 14.0.1 14.1.1 14.2.2 14.3.1 All 501 releases
jetpack / modules / widgets / customizer-utils.js

customizer-utils.js in Jetpack – WP Security, Backup, Speed, & Growth 6.2.2, at modules/widgets/customizer-utils.js

83 lines 3.1 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 /* global wp, gapi, FB, twttr */
2
3 /**
4 * Utilities to work with widgets in Customizer.
5 */
6
7 /**
8 * Checks whether this Customizer supports partial widget refresh.
9 * @returns {boolean}
10 */
11 wp.customizerHasPartialWidgetRefresh = function() {
12 return 'object' === typeof wp && 'function' === typeof wp.customize && 'object' === typeof wp.customize.selectiveRefresh && 'object' === typeof wp.customize.widgetsPreview && 'function' === typeof wp.customize.widgetsPreview.WidgetPartial;
13 };
14
15 /**
16 * Verifies that the placed widget ID contains the widget name.
17 * @param {object} placement
18 * @param {string} widgetName
19 * @returns {*|boolean}
20 */
21 wp.isJetpackWidgetPlaced = function( placement, widgetName ) {
22 return placement.partial.widgetId && 0 === placement.partial.widgetId.indexOf( widgetName );
23 };
24
25 /**
26 * Bind events for selective refresh in Customizer.
27 */
28 (function($){
29
30 $( document ).ready( function() {
31
32 if ( wp && wp.customize && wp.customizerHasPartialWidgetRefresh() ) {
33
34 // Refresh widget contents when a partial is rendered.
35 wp.customize.selectiveRefresh.bind( 'partial-content-rendered', function ( placement ) {
36 if ( placement.container ) {
37
38 // Refresh Google+
39 if ( wp.isJetpackWidgetPlaced( placement, 'googleplus-badge' ) && 'object' === typeof gapi && gapi.person && 'function' === typeof gapi.person.go ) {
40 gapi.person.go( placement.container[0] );
41 }
42
43 // Refresh Facebook XFBML
44 else if ( wp.isJetpackWidgetPlaced( placement, 'facebook-likebox' ) && 'object' === typeof FB && 'object' === typeof FB.XFBML && 'function' === typeof FB.XFBML.parse ) {
45 FB.XFBML.parse( placement.container[0], function() {
46 var $fbContainer = $( placement.container[0] ).find( '.fb_iframe_widget' ),
47 fbWidth = $fbContainer.data( 'width' ),
48 fbHeight = $fbContainer.data( 'height' );
49 $fbContainer.find( 'span' ).css( { 'width': fbWidth, 'height': fbHeight } );
50 setTimeout( function() {
51 $fbContainer.find( 'iframe' ).css( { 'width': fbWidth, 'height': fbHeight, 'position': 'relative' } );
52 }, 1 );
53 } );
54 }
55
56 // Refresh Twitter
57 else if ( wp.isJetpackWidgetPlaced( placement, 'twitter_timeline' ) && 'object' === typeof twttr && 'object' === typeof twttr.widgets && 'function' === typeof twttr.widgets.load ) {
58 twttr.widgets.load( placement.container[0] );
59 } else if ( wp.isJetpackWidgetPlaced( placement, 'eu_cookie_law_widget' ) ) {
60 // Refresh EU Cookie Law
61 if ( $( '#eu-cookie-law' ).hasClass( 'top' ) ) {
62 $( '.widget_eu_cookie_law_widget' ).addClass( 'top' );
63 } else {
64 $( '.widget_eu_cookie_law_widget' ).removeClass( 'top' );
65 }
66 placement.container.fadeIn();
67 }
68 }
69 } );
70
71 // Refresh widgets when they're moved.
72 wp.customize.selectiveRefresh.bind( 'partial-content-moved', function( placement ) {
73 if ( placement.container ) {
74 // Refresh Twitter timeline iframe, since it has to be re-built.
75 if ( wp.isJetpackWidgetPlaced( placement, 'twitter_timeline' ) && placement.container.find( 'iframe.twitter-timeline:not([src]):first' ).length ) {
76 placement.partial.refresh();
77 }
78 }
79 } );
80 }
81 } );
82 } )( jQuery );
83