authors
6 months ago
contact-info
6 months ago
eu-cookie-law
6 months ago
facebook-likebox
10 years ago
flickr
6 months ago
gallery
6 months ago
goodreads
6 months ago
google-translate
1 year ago
image-widget
6 months ago
instagram
3 months ago
internet-defense-league
1 year ago
milestone
3 months ago
my-community
6 months ago
social-icons
3 months ago
social-media-icons
6 months ago
top-posts
6 months ago
wordpress-post-widget
3 days ago
authors.php
6 months ago
blog-stats.php
6 months ago
class-jetpack-eu-cookie-law-widget.php
1 week ago
class-jetpack-instagram-widget.php
5 months ago
contact-info.php
1 week ago
customizer-controls.css
6 months ago
customizer-utils.js
1 year ago
facebook-likebox.php
1 week ago
flickr.php
6 months ago
gallery.php
1 week ago
goodreads.php
1 week ago
google-translate.php
1 week ago
gravatar-profile.css
6 months ago
gravatar-profile.php
1 week ago
image-widget.php
6 months ago
internet-defense-league.php
6 months ago
mailchimp.php
6 months ago
milestone.php
6 months ago
my-community.php
1 week ago
rsslinks-widget.php
1 week ago
simple-payments.php
6 months ago
social-icons.php
2 weeks ago
social-media-icons.php
6 months ago
top-posts.php
1 week ago
twitter-timeline-admin.js
1 year ago
twitter-timeline.php
1 week ago
upcoming-events.php
6 months ago
wordpress-post-widget.php
6 months ago
customizer-utils.js
120 lines
| 1 | /* global gapi, FB, twttr, PaypalExpressCheckout */ |
| 2 | |
| 3 | /** |
| 4 | * Utilities to work with widgets in Customizer. |
| 5 | */ |
| 6 | |
| 7 | /** |
| 8 | * Checks whether this Customizer supports partial widget refresh. |
| 9 | * @return {boolean} |
| 10 | */ |
| 11 | wp.customizerHasPartialWidgetRefresh = function () { |
| 12 | return ( |
| 13 | 'object' === typeof wp && |
| 14 | 'function' === typeof wp.customize && |
| 15 | 'object' === typeof wp.customize.selectiveRefresh && |
| 16 | 'object' === typeof wp.customize.widgetsPreview && |
| 17 | 'function' === typeof wp.customize.widgetsPreview.WidgetPartial |
| 18 | ); |
| 19 | }; |
| 20 | |
| 21 | /** |
| 22 | * Verifies that the placed widget ID contains the widget name. |
| 23 | * @param {object} placement |
| 24 | * @param {string} widgetName |
| 25 | * @return {*|boolean} |
| 26 | */ |
| 27 | wp.isJetpackWidgetPlaced = function ( placement, widgetName ) { |
| 28 | return placement.partial.widgetId && 0 === placement.partial.widgetId.indexOf( widgetName ); |
| 29 | }; |
| 30 | |
| 31 | /** |
| 32 | * Bind events for selective refresh in Customizer. |
| 33 | */ |
| 34 | ( function ( $ ) { |
| 35 | $( document ).ready( function () { |
| 36 | if ( wp && wp.customize && wp.customizerHasPartialWidgetRefresh() ) { |
| 37 | // Refresh widget contents when a partial is rendered. |
| 38 | wp.customize.selectiveRefresh.bind( 'partial-content-rendered', function ( placement ) { |
| 39 | if ( placement.container ) { |
| 40 | // Refresh Google+ |
| 41 | if ( |
| 42 | wp.isJetpackWidgetPlaced( placement, 'googleplus-badge' ) && |
| 43 | 'object' === typeof gapi && |
| 44 | gapi.person && |
| 45 | 'function' === typeof gapi.person.go |
| 46 | ) { |
| 47 | gapi.person.go( placement.container[ 0 ] ); |
| 48 | } |
| 49 | |
| 50 | // Refresh Facebook XFBML |
| 51 | else if ( |
| 52 | wp.isJetpackWidgetPlaced( placement, 'facebook-likebox' ) && |
| 53 | 'object' === typeof FB && |
| 54 | 'object' === typeof FB.XFBML && |
| 55 | 'function' === typeof FB.XFBML.parse |
| 56 | ) { |
| 57 | FB.XFBML.parse( placement.container[ 0 ], function () { |
| 58 | var $fbContainer = $( placement.container[ 0 ] ).find( '.fb_iframe_widget' ), |
| 59 | fbWidth = $fbContainer.data( 'width' ), |
| 60 | fbHeight = $fbContainer.data( 'height' ); |
| 61 | $fbContainer.find( 'span' ).css( { width: fbWidth, height: fbHeight } ); |
| 62 | setTimeout( function () { |
| 63 | $fbContainer |
| 64 | .find( 'iframe' ) |
| 65 | .css( { width: fbWidth, height: fbHeight, position: 'relative' } ); |
| 66 | }, 1 ); |
| 67 | } ); |
| 68 | } |
| 69 | |
| 70 | // Refresh Twitter |
| 71 | else if ( |
| 72 | wp.isJetpackWidgetPlaced( placement, 'twitter_timeline' ) && |
| 73 | 'object' === typeof twttr && |
| 74 | 'object' === typeof twttr.widgets && |
| 75 | 'function' === typeof twttr.widgets.load |
| 76 | ) { |
| 77 | twttr.widgets.load( placement.container[ 0 ] ); |
| 78 | } else if ( wp.isJetpackWidgetPlaced( placement, 'eu_cookie_law_widget' ) ) { |
| 79 | // Refresh EU Cookie Law |
| 80 | if ( $( '#eu-cookie-law' ).hasClass( 'top' ) ) { |
| 81 | $( '.widget_eu_cookie_law_widget' ).addClass( 'top' ); |
| 82 | } else { |
| 83 | $( '.widget_eu_cookie_law_widget' ).removeClass( 'top' ); |
| 84 | } |
| 85 | placement.container.fadeIn(); |
| 86 | } else if ( wp.isJetpackWidgetPlaced( placement, 'jetpack_simple_payments_widget' ) ) { |
| 87 | // Refresh Simple Payments Widget |
| 88 | try { |
| 89 | var buttonId = $( '.jetpack-simple-payments-button', placement.container ) |
| 90 | .attr( 'id' ) |
| 91 | .replace( '_button', '' ); |
| 92 | PaypalExpressCheckout.renderButton( null, null, buttonId, null ); |
| 93 | } catch { |
| 94 | // PaypalExpressCheckout may fail. |
| 95 | // For the same usage, see also: |
| 96 | // https://github.com/Automattic/jetpack/blob/6c1971e6bed7d3df793392a7a58ffe0afaeeb5fe/modules/simple-payments/simple-payments.php#L111 |
| 97 | } |
| 98 | } |
| 99 | } |
| 100 | } ); |
| 101 | |
| 102 | // Refresh widgets when they're moved. |
| 103 | wp.customize.selectiveRefresh.bind( 'partial-content-moved', function ( placement ) { |
| 104 | if ( placement.container ) { |
| 105 | // Refresh Twitter timeline iframe, since it has to be re-built. |
| 106 | if ( |
| 107 | wp.isJetpackWidgetPlaced( placement, 'twitter_timeline' ) && |
| 108 | placement.container.find( 'iframe.twitter-timeline:not([src]):first' ).length |
| 109 | ) { |
| 110 | placement.partial.refresh(); |
| 111 | } else if ( wp.isJetpackWidgetPlaced( placement, 'jetpack_simple_payments_widget' ) ) { |
| 112 | // Refresh Simple Payments Widget |
| 113 | placement.partial.refresh(); |
| 114 | } |
| 115 | } |
| 116 | } ); |
| 117 | } |
| 118 | } ); |
| 119 | } )( jQuery ); |
| 120 |