summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
Diffstat (limited to 'plugins/jetpack/modules/theme-tools/site-logo/js/site-logo.js')
-rw-r--r--plugins/jetpack/modules/theme-tools/site-logo/js/site-logo.js46
1 files changed, 46 insertions, 0 deletions
diff --git a/plugins/jetpack/modules/theme-tools/site-logo/js/site-logo.js b/plugins/jetpack/modules/theme-tools/site-logo/js/site-logo.js
new file mode 100644
index 00000000..6c959c0c
--- /dev/null
+++ b/plugins/jetpack/modules/theme-tools/site-logo/js/site-logo.js
@@ -0,0 +1,46 @@
+/**
+ * JS for handling the Site Logo real-time display in the Customizer preview frame.
+ */
+( function( $ ) {
+ var api = wp.customize,
+ $body,
+ $anchor,
+ $logo,
+ size;
+
+ function cacheSelectors() {
+ $body = $( 'body' );
+ $anchor = $( '.site-logo-link' );
+ $logo = $( '.site-logo' );
+ size = $logo.attr( 'data-size' );
+ }
+
+ api( 'site_logo', function( value ) {
+ value.bind( function( newVal ) {
+ // grab selectors the first time through
+ if ( ! $body ) {
+ cacheSelectors();
+ }
+
+ // Let's update our preview logo.
+ if ( newVal && newVal.url ) {
+ // If the source was smaller than the size required by the theme, give the biggest we've got.
+ if ( ! newVal.sizes[ size ] ) {
+ size = 'full';
+ }
+
+ $logo.attr( {
+ height: newVal.sizes[ size ].height,
+ width: newVal.sizes[ size ].width,
+ src: newVal.sizes[ size ].url,
+ } );
+
+ $anchor.show();
+ $body.addClass( 'has-site-logo' );
+ } else {
+ $anchor.hide();
+ $body.removeClass( 'has-site-logo' );
+ }
+ } );
+ } );
+} )( jQuery );