/** * Script load in customizer preview (iframe) */ /* * Script run inside a Customizer preview frame. */ ( function( $ ) { "use strict"; function closeSidebar() { if ($("amp-sidebar").attr('open') === 'open') { $('.navbar-toggle').click(); } } function openSidebar() { if ($("amp-sidebar").attr('open') !== 'open') { $('.navbar-toggle').click(); } } function scrollToEnd() { $("html, body").animate({scrollTop: $(document).height()}, 500); } $(document).ready(function() { var c = wp.customize; /* ===================== Header ======================================= */ c('amp-wp-header-show-search', function (value) { value.bind(function (to) { /** * Toggle Search On/Off. */ $( '.navbar-search' ).toggle( '1' == to ); }); }); c('amp-wp-header-sticky', function (value) { value.bind(function (to) { /** * Toggle Header Sticky On/Off. */ if( '1' == to ) { $( 'body' ).addClass('sticky-nav'); } else { $( 'body' ).removeClass('sticky-nav'); } }); }); /* ===================== Sidebar ======================================= */ c('amp-wp-sidebar-show', function (value) { value.bind(function (to) { $( '.navbar-toggle' ).toggle( '1' == to ); closeSidebar(); }); }); c('amp-wp-sidebar-logo-text', function (value) { value.bind(function (to) { openSidebar(); $('.sidebar-brand .brand-name').html(to); }); }); c('amp-wp-sidebar-logo-img', function (value) { value.bind(openSidebar); }); c('amp-wp-sidebar-footer-text', function (value) { value.bind(function (to) { openSidebar(); $('.sidebar-footer-text').html(to); }); }); [ 'twitter', 'facebook', 'google_plus', 'email' ].forEach(function (k) { c('amp-wp-' + k, function (value) { value.bind(function (to) { var $wrapper = $('.social-item.' + k); $wrapper[ to ? 'show' : 'hide' ]().find('a').attr('href', to); openSidebar(); }); }); }); /* =========================== Footer Section ================================== */ c('amp-wp-footer-copyright-text', function (value) { value.bind(function (to) { closeSidebar(); scrollToEnd(); $('.amp-wp-copyright').html(to); }); }); c('amp-wp-footer-main-link', function (value) { value.bind(function (to) { scrollToEnd(); /** * Toggle Footer Menu Link On/Off. */ $( '.amp-wp-main-link' ).toggle( '1' == to ); }); }); /* ===================== Post Section =================================== */ c('amp-wp-post-show-thumbnail', function (value) { value.bind(function (to) { /** * Toggle Post Thumbnail On/Off. */ $( '.post-thumbnail' ).toggle( '1' == to ); }); }); c('amp-wp-post-show-comment', function (value) { value.bind(function (to) { scrollToEnd(); /** * Toggle Ccomment Wrapper On/Off. */ $( '.amp-wp-comments-wrapper' ).toggle( '1' == to ); }); }); c('amp-wp-post-show-related', function (value) { value.bind(function (to) { scrollToEnd(); /** * Toggle Related Posts Wrapper On/Off. */ $( '.related-posts-wrapper' ).toggle( '1' == to ); }); }); c('amp-wp-post-social-share-show', function (value) { value.bind(function (to) { scrollToEnd(); /** * Toggle Social Share On/Off. */ $( '.social-list-wrapper' ).toggle( 'show' == to ); }); }); c('amp-wp-post-social-share-count', function (value) { value.bind(function (to) { $(".post-social-list .share-handler .number") [ to === 'total' || to === 'total-and-site' ? 'show' : 'hide' ](); /** * Toggle Social Share Count On/Off. */ $(".post-social-list .social-item .number") [ to === 'total-and-site' ? 'show' : 'hide' ](); }); }); c('amp-wp-post-social-share', function (value) { function sortSocialNetworks(networks) { var $currentItem, pos = 0, $context = $(".post-social-list .social-list"), $items = $context.children('.social-item'); for (var net in networks) { $currentItem = $(".social-item." + net, $context); if ($currentItem.length) { $currentItem[ networks[ net ] != '0' ? 'show' : 'hide' ](); if ($currentItem.get(0) !== $items.get(pos)) { $currentItem.insertBefore($items.get(pos)); break; } } ++pos; } } sortSocialNetworks(this.get()[ 'amp-wp-post-social-share' ]); value.bind(function (networks) { scrollToEnd(); sortSocialNetworks.call(this, networks); }); }); /* ============================ Pages Section =========================== */ c('amp-wp-home-show-slide', function (value) { value.bind(function (to) { /** * Toggle Slider On/Off. */ $( '.homepage-slider' ).toggle( '1' === to ); }); }); /* ============================ Colors Section =========================== */ c('amp-wp-color-theme', function (value) { value.bind(function(to) { $('.pagination .nav-links .page-numbers.prev,.pagination .nav-links .page-numbers.next,.listing-item a.post-read-more,.post-terms.cats .term-type,.post-terms a:hover,.search-form .search-submit,.amp-wp-main-link a,.post-categories li a') .css('background', to); $('.single-post .post-meta a,.entry-content ul.amp-wp-shortcode-list li:before') .css('color', to); }); }); c('amp-wp-color-bg', function (value) { value.bind(function(to) { $('body.body').css('background', to); }); }); c('amp-wp-color-text', function (value) { value.bind(function(to) { $('.amp-wp-wrapper').css('color', to); }); }); c('amp-wp-color-footer-nav-bg', function (value) { value.bind(function(to) { scrollToEnd(); $('.amp-wp-footer-nav').css('background', to); }); }); c('amp-wp-color-footer-bg', function (value) { value.bind(function(to) { scrollToEnd(); $('.amp-wp-copyright').css('background', to); }); }); }); })( jQuery );