/** * 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 ); }); }); /* ============================ Colors Section =========================== */ c('amp-wp-color-theme', function (value) { value.bind(function(to) { $('.post-terms.cats .term-type,.post-terms a:hover,.search-form .search-submit,.amp-wp-main-link a,.sidebar-brand,.site-header,.listing-item a.post-read-more:hover') .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-footer').css('background', to); }); }); }); })( jQuery );