/** * customizer.js * * * Instantly live-update customizer settings in the preview for improved user experience. */ /* global get_post_aj */ function bfastmag_html_entity_decode(string, quote_style) { 'use strict'; var hash_map = {}, symbol = '', tmp_str = '', entity = ''; tmp_str = string.toString(); if (false === (hash_map = bfastmag_get_html_translation_table('HTML_ENTITIES', quote_style))) { return false; } delete(hash_map['&']); hash_map['&'] = '&'; for (symbol in hash_map) { entity = hash_map[symbol]; tmp_str = tmp_str.split(entity) .join(symbol); } tmp_str = tmp_str.split(''') .join('\''); return tmp_str; } function bfastmag_get_html_translation_table(table, quote_style) { 'use strict'; var entities = {}, hash_map = {}, decimal; var constMappingTable = {}, constMappingQuoteStyle = {}; var useTable = {}, useQuoteStyle = {}; // Translate arguments constMappingTable[0] = 'HTML_SPECIALCHARS'; constMappingTable[1] = 'HTML_ENTITIES'; constMappingQuoteStyle[0] = 'ENT_NOQUOTES'; constMappingQuoteStyle[2] = 'ENT_COMPAT'; constMappingQuoteStyle[3] = 'ENT_QUOTES'; useTable = !isNaN(table) ? constMappingTable[table] : table ? table.toUpperCase() : 'HTML_SPECIALCHARS'; useQuoteStyle = !isNaN(quote_style) ? constMappingQuoteStyle[quote_style] : quote_style ? quote_style.toUpperCase() : 'ENT_COMPAT'; if (useTable !== 'HTML_SPECIALCHARS' && useTable !== 'HTML_ENTITIES') { throw new Error('Table: ' + useTable + ' not supported'); // return false; } entities['38'] = '&'; if (useTable === 'HTML_ENTITIES') { entities['160'] = ' '; entities['161'] = '¡'; entities['162'] = '¢'; entities['163'] = '£'; entities['164'] = '¤'; entities['165'] = '¥'; entities['166'] = '¦'; entities['167'] = '§'; entities['168'] = '¨'; entities['169'] = '©'; entities['170'] = 'ª'; entities['171'] = '«'; entities['172'] = '¬'; entities['173'] = '­'; entities['174'] = '®'; entities['175'] = '¯'; entities['176'] = '°'; entities['177'] = '±'; entities['178'] = '²'; entities['179'] = '³'; entities['180'] = '´'; entities['181'] = 'µ'; entities['182'] = '¶'; entities['183'] = '·'; entities['184'] = '¸'; entities['185'] = '¹'; entities['186'] = 'º'; entities['187'] = '»'; entities['188'] = '¼'; entities['189'] = '½'; entities['190'] = '¾'; entities['191'] = '¿'; entities['192'] = 'À'; entities['193'] = 'Á'; entities['194'] = 'Â'; entities['195'] = 'Ã'; entities['196'] = 'Ä'; entities['197'] = 'Å'; entities['198'] = 'Æ'; entities['199'] = 'Ç'; entities['200'] = 'È'; entities['201'] = 'É'; entities['202'] = 'Ê'; entities['203'] = 'Ë'; entities['204'] = 'Ì'; entities['205'] = 'Í'; entities['206'] = 'Î'; entities['207'] = 'Ï'; entities['208'] = 'Ð'; entities['209'] = 'Ñ'; entities['210'] = 'Ò'; entities['211'] = 'Ó'; entities['212'] = 'Ô'; entities['213'] = 'Õ'; entities['214'] = 'Ö'; entities['215'] = '×'; entities['216'] = 'Ø'; entities['217'] = 'Ù'; entities['218'] = 'Ú'; entities['219'] = 'Û'; entities['220'] = 'Ü'; entities['221'] = 'Ý'; entities['222'] = 'Þ'; entities['223'] = 'ß'; entities['224'] = 'à'; entities['225'] = 'á'; entities['226'] = 'â'; entities['227'] = 'ã'; entities['228'] = 'ä'; entities['229'] = 'å'; entities['230'] = 'æ'; entities['231'] = 'ç'; entities['232'] = 'è'; entities['233'] = 'é'; entities['234'] = 'ê'; entities['235'] = 'ë'; entities['236'] = 'ì'; entities['237'] = 'í'; entities['238'] = 'î'; entities['239'] = 'ï'; entities['240'] = 'ð'; entities['241'] = 'ñ'; entities['242'] = 'ò'; entities['243'] = 'ó'; entities['244'] = 'ô'; entities['245'] = 'õ'; entities['246'] = 'ö'; entities['247'] = '÷'; entities['248'] = 'ø'; entities['249'] = 'ù'; entities['250'] = 'ú'; entities['251'] = 'û'; entities['252'] = 'ü'; entities['253'] = 'ý'; entities['254'] = 'þ'; entities['255'] = 'ÿ'; } if (useQuoteStyle !== 'ENT_NOQUOTES') { entities['34'] = '"'; } if (useQuoteStyle === 'ENT_QUOTES') { entities['39'] = '''; } entities['60'] = '<'; entities['47'] = '/'; entities['62'] = '>'; // ascii decimals to real symbols for (decimal in entities) { if (entities.hasOwnProperty(decimal)) { hash_map[String.fromCharCode(decimal)] = entities[decimal]; } } return hash_map; } function bfastmag_strip_tags(input, allowed) { 'use strict'; allowed = (((allowed || '') + '') .toLowerCase() .match(/<[a-z][a-z0-9]*>/g) || []) .join(''); // making sure the allowed arg is a string containing only tags in lowercase () var tags = /<\/?([a-z][a-z0-9]*)\b[^>]*>/gi, commentsAndPhpTags = /|<\?(?:php)?[\s\S]*?\?>/gi; return input.replace(commentsAndPhpTags, '') .replace(tags, function ($0, $1) { return allowed.indexOf('<' + $1.toLowerCase() + '>') > -1 ? $0 : ''; }); } (function ($) { // Site title and description. wp.customize('blogname', function (value) { value.bind(function (to) { $('.site-title a').text(to); }); }); wp.customize('blogdescription', function (value) { value.bind(function (to) { $('.site-description').text(to); }); }); // Titles color wp.customize('bfastmag_title_color', function (value) { value.bind(function (to) { $('.title-border span, .page-header h1').css({'color': to}); }); }); // Sidebar text color. wp.customize('header_textcolor', function (value) { value.bind(function (to) { $('.bfastmag-content-right, .bfastmag-content-right a, .post .entry-content, .post .entry-content p, .post .entry-cats, .post .entry-cats a, .post .entry-comments,.post .entry-separator, .post .entry-footer a, .post .entry-footer span, .post .entry-footer .entry-cats, .post .entry-footer .entry-cats a, .author-content').css({'color': to}); }); }); // Top slider title color wp.customize('bfastmag_top_slider_post_title_color', function (value) { value.bind(function (to) { $('.bfastmag-featured-slider .entry-title a').css({'color': to}); }); }); // Top slider text color wp.customize('bfastmag_top_slider_post_text_color', function (value) { value.bind(function (to) { $('.bfastmag-featured-slider .tp-post-item-meta .tp-post-item-date, .bfastmag-featured-slider .tp-post-item-meta > a, .bfastmag-featured-slider .tp-post-item-meta .entry-separator').css({'color': to}); }); }); // Post title color wp.customize('bfastmag_blocks_post_title_color', function (value) { value.bind(function (to) { $('.bfastmag-content-left .entry-title a').css({'color': to}); }); }); // Post text color wp.customize('bfastmag_blocks_post_text_color', function (value) { value.bind(function (to) { $('.bfastmag-content-left .entry-meta .entry-separator, .bfastmag-content-left .entry-meta a, .bfastmag-content-left .bfastmag-fp-s3 .tp-post-item p, .bfastmag-content-left .bfastmag-related-posts .entry-content p, .bfastmag-content-left .bfastmag-related-posts .entry-cats .entry-label, .bfastmag-content-left .bfastmag-related-posts .entry-cats a, .bfastmag-content-left .bfastmag-related-posts > a, .bfastmag-content-left .bfastmag-related-posts .entry-footer > a').css({'color': to}); }); }); // Repeater wp.customize('bfastmag_social_links', function (value) { value.bind(function (to) { var obj = JSON.parse(to); var result = ''; obj.forEach(function (item) { result += ''; }); $('.social-links').html(result); }); }); // Logo wp.customize('custom_logo', function (value) { value.bind(function (to) { if (to !== '') { $('.custom-logo-link').removeClass('bfastmag_customizer_only'); $('.head-logo-container').addClass('bfastmag_customizer_only'); } else { $('.custom-logo-link').addClass('bfastmag_customizer_only'); $('.head-logo-container').removeClass('bfastmag_customizer_only'); } }); }); wp.customize('bfastmag_banner', function (value) { value.bind(function (to) { var obj = JSON.parse(to); if (obj.position !== '') { $('.bfastmag-a-d-v').attr('style', 'text-align:' + obj.position); } if (obj.choice === 'code') { if (obj.code !== '') { $('.bfastmag-a-d-v').html(bfastmag_html_entity_decode(obj.code)); } } else { if (obj.image_url !== '') { if (obj.link !== '') { $('.bfastmag-a-d-v').html('Banner link'); } else { $('.bfastmag-a-d-v').html('Banner link'); } } } }); }); // Featured Big Category wp.customize('bfastmag_featured_big_category', function (value) { value.bind(function (to) { jQuery.ajax({ url: get_post_aj.ajaxurl, type: 'post', data: { action: 'get_post_aj_act', section: 'bfastmag_featured_big_cat', category: to, tp_no_of_posts: 4 }, beforeSend: function () { jQuery('.featured-wrap').replaceWith(''); }, success: function (result) { jQuery('.featured-wrap').replaceWith(result); jQuery('.featured-wrap').addClass('animated'); } }); }); }); // Featured Slider Category wp.customize('bfastmag_featured_slider_category', function (value) { value.bind(function (to) { jQuery.ajax({ url: get_post_aj.ajaxurl, type: 'post', data: { action: 'get_post_aj_act', section: 'bfastmag_topslider_category', category: to, tp_no_of_posts: wp.customize._value.bfastmag_featured_slider_max_posts() }, beforeSend: function () { jQuery('.owl-carousel.bfastmag-top-carousel').replaceWith(''); }, success: function (result) { jQuery('.owl-carousel.bfastmag-top-carousel').replaceWith(result); jQuery('.owl-carousel.bfastmag-top-carousel').owlCarousel({ loop: true, margin: 0, responsiveClass: true, nav: false, navText: ['', ''], dots: true, autoplay: true, autoplayTimeout: 10000, lazyLoad: true, animateIn: true, responsive: { 0: {items: 1}, 600: {items: 2}, 992: {items: 3} } }); } }); }); }); // Featured Slider No of posts wp.customize('bfastmag_featured_slider_max_posts', function (value) { value.bind(function (to) { jQuery.ajax({ url: get_post_aj.ajaxurl, type: 'post', data: { action: 'get_post_aj_act', section: 'bfastmag_topslider_category', category: wp.customize._value.bfastmag_featured_slider_category(), tp_no_of_posts: to }, beforeSend: function () { jQuery('.owl-carousel.bfastmag-top-carousel').replaceWith(''); }, success: function (result) { jQuery('.owl-carousel.bfastmag-top-carousel').replaceWith(result); jQuery('.owl-carousel.bfastmag-top-carousel').owlCarousel({ loop: true, margin: 0, responsiveClass: true, nav: false, navText: ['', ''], dots: true, autoplay: true, autoplayTimeout: 10000, lazyLoad: true, animateIn: true, responsive: { 0: {items: 1}, 600: {items: 2}, 992: {items: 3} } }); } }); }); }); // Section1 title wp.customize('bfastmag_featured_slider_title', function (value) { value.bind(function (to) { if (to !== '') { $('.bfastmag-featured-slider .title-border').removeClass('bfastmag_customizer_only'); $('.bfastmag-featured-slider .title-border span').text(to); $('.bfastmag-featured-slider .title-border span').append(''); } else { $('.bfastmag-featured-slider .title-border').addClass('bfastmag_customizer_only'); } }); }); // Section1 title wp.customize('bfastmag_block1_title', function (value) { value.bind(function (to) { if (to !== '') { $('.bfastmag-block1 .title-border').removeClass('bfastmag_customizer_only'); $('.bfastmag-block1 .title-border span').text(to); $('.bfastmag-block1 .title-border span').append(''); } else { $('.bfastmag-block1 .title-border').addClass('bfastmag_customizer_only'); } }); }); // Section1 Category wp.customize('bfastmag_block1_category', function (value) { value.bind(function (to) { jQuery.ajax({ url: get_post_aj.ajaxurl, type: 'post', data: { action: 'get_post_aj_act', section: 'bfastmag_block1_category', category: to, tp_no_of_posts: wp.customize._value.bfastmag_block1_max_posts(), posts_per_page: wp.customize._value.bfastmag_block1_posts_per_page() }, beforeSend: function () { jQuery('.bfastmag-block1').find('.bfastmag-fp-s3').replaceWith('
Loading New Posts...
'); }, success: function (result) { jQuery('.bfastmag-block1').find('.bfastmag-fp-s3').replaceWith(result); jQuery('.owl-carousel.bfastmag-fp-s3-posts').owlCarousel({ loop: false, margin: 0, responsiveClass: true, nav: true, navText: ['', ''], dots: false, autoplay: true, autoplayTimeout: 15000, items: 1, lazyLoad: true, }); } }); }); }); // Section 1 number of posts wp.customize('bfastmag_block1_max_posts', function (value) { value.bind(function (to) { jQuery.ajax({ url: get_post_aj.ajaxurl, type: 'post', data: { action: 'get_post_aj_act', section: 'bfastmag_block1_category', tp_no_of_posts: to, posts_per_page: wp.customize._value.bfastmag_block1_posts_per_page(), category: wp.customize._value.bfastmag_block1_category() }, beforeSend: function () { jQuery('.bfastmag-block1').find('.bfastmag-fp-s3').replaceWith('
Loading New Posts...
'); }, success: function (result) { jQuery('.bfastmag-block1').find('.bfastmag-fp-s3').replaceWith(result); jQuery('.owl-carousel.bfastmag-fp-s3-posts').owlCarousel({ loop: false, margin: 0, responsiveClass: true, nav: true, navText: ['', ''], dots: false, autoplay: true, autoplayTimeout: 15000, items: 1, lazyLoad: true, }); } }); }); }); // Section 1 posts per page wp.customize('bfastmag_block1_posts_per_page', function (value) { value.bind(function (to) { jQuery.ajax({ url: get_post_aj.ajaxurl, type: 'post', data: { action: 'get_post_aj_act', section: 'bfastmag_block1_category', posts_per_page: to, category: wp.customize._value.bfastmag_block1_category(), tp_no_of_posts: wp.customize._value.bfastmag_block1_max_posts() }, beforeSend: function () { jQuery('.bfastmag-block1').find('.bfastmag-fp-s3').replaceWith('
Loading New Posts...
'); }, success: function (result) { jQuery('.bfastmag-block1').find('.bfastmag-fp-s3').replaceWith(result); jQuery('.owl-carousel.bfastmag-fp-s3-posts').owlCarousel({ loop: false, margin: 0, responsiveClass: true, nav: true, navText: ['', ''], dots: false, autoplay: true, autoplayTimeout: 15000, items: 1, lazyLoad: true, }); } }); }); }); // Section 2 Title wp.customize('bfastmag_block2_title', function (value) { value.bind(function (to) { if (to !== '') { $('.bfastmag-block2 .title-border').removeClass('bfastmag_customizer_only'); $('.bfastmag-block2 .title-border span').text(to); $('.bfastmag-block2 .title-border span').append(''); } else { $('.bfastmag-block2 .title-border').addClass('bfastmag_customizer_only'); } }); }); // Section2 Category wp.customize('bfastmag_block2_category', function (value) { value.bind(function (to) { jQuery.ajax({ url: get_post_aj.ajaxurl, type: 'post', data: { action: 'get_post_aj_act', section: 'bfastmag_block2_category', category: to, tp_no_of_posts: wp.customize._value.bfastmag_block2_max_posts(), }, beforeSend: function () { jQuery('.bfastmag-block2').find('.bfastmag-fp-s1').replaceWith('
Loading New Posts...
'); }, success: function (result) { jQuery('.bfastmag-block2').find('.bfastmag-fp-s1').replaceWith(result); jQuery('.owl-carousel.bfastmag-fp-s1-posts').owlCarousel({ loop: true, margin: 30, responsiveClass: true, nav: true, navText: ['', ''], dots: false, autoplay: true, autoplayTimeout: 12000, lazyLoad: true, animateIn: true, responsive: { 0: {items: 1}, 600: {items: 2}, 992: {items: 3} } }); } }); }); }); // Section 2 No of posts wp.customize('bfastmag_block2_max_posts', function (value) { value.bind(function (to) { jQuery.ajax({ url: get_post_aj.ajaxurl, type: 'post', data: { action: 'get_post_aj_act', section: 'bfastmag_block2_category', tp_no_of_posts: to, category: wp.customize._value.bfastmag_block2_category() }, beforeSend: function () { jQuery('.bfastmag-block2').find('.bfastmag-fp-s1').replaceWith('
Loading New Posts...
'); }, success: function (result) { jQuery('.bfastmag-block2').find('.bfastmag-fp-s1').replaceWith(result); jQuery('.owl-carousel.bfastmag-fp-s1-posts').owlCarousel({ loop: true, margin: 30, responsiveClass: true, nav: true, navText: ['', ''], dots: false, autoplay: true, autoplayTimeout: 12000, lazyLoad: true, animateIn: true, responsive: { 0: {items: 1}, 600: {items: 2}, 992: {items: 3} } }); } }); }); }); // Section3 Title wp.customize('bfastmag_block3_title', function (value) { value.bind(function (to) { if (to !== '') { $('.bfastmag-block3 .title-border').removeClass('bfastmag_customizer_only'); $('.bfastmag-block3 .title-border span').text(to); $('.bfastmag-block3 .title-border span').append(''); } else { $('.bfastmag-block3 .title-border').addClass('bfastmag_customizer_only'); } }); }); // Section3 Category wp.customize('bfastmag_block3_category', function (value) { value.bind(function (to) { jQuery.ajax({ url: get_post_aj.ajaxurl, type: 'post', data: { action: 'get_post_aj_act', section: 'bfastmag_block3_category', category: to, tp_no_of_posts: wp.customize._value.bfastmag_block3_max_posts() }, beforeSend: function () { jQuery('.bfastmag-block3').find('.bfastmag-fp-s2').replaceWith('
Loading New Posts...
'); }, success: function (result) { jQuery('.bfastmag-block3').find('.bfastmag-fp-s2').replaceWith(result); } }); }); }); // Section 3 No of posts wp.customize('bfastmag_block3_max_posts', function (value) { value.bind(function (to) { jQuery.ajax({ url: get_post_aj.ajaxurl, type: 'post', data: { action: 'get_post_aj_act', section: 'bfastmag_block3_category', tp_no_of_posts: to, category: wp.customize._value.bfastmag_block3_category() }, beforeSend: function () { jQuery('.bfastmag-block3').find('.bfastmag-fp-s2').replaceWith('
Loading New Posts...
'); }, success: function (result) { jQuery('.bfastmag-block3').find('.bfastmag-fp-s2').replaceWith(result); } }); }); }); // Section4 Title wp.customize('bfastmag_block4_title', function (value) { value.bind(function (to) { if (to !== '') { $('.bfastmag-block4 .title-border').removeClass('bfastmag_customizer_only'); $('.bfastmag-block4 .title-border span').text(to); $('.bfastmag-block4 .title-border span').append(''); } else { $('.bfastmag-block4 .title-border').addClass('bfastmag_customizer_only'); } }); }); // Section4 Category wp.customize('bfastmag_block4_category', function (value) { value.bind(function (to) { jQuery.ajax({ url: get_post_aj.ajaxurl, type: 'post', data: { action: 'get_post_aj_act', section: 'bfastmag_block4_category', category: to, tp_no_of_posts: wp.customize._value.bfastmag_block4_max_posts() }, beforeSend: function () { jQuery('.bfastmag-block4').find('.bfastmag-fp-s1').replaceWith('
Loading New Posts...
'); }, success: function (result) { jQuery('.bfastmag-block4').find('.bfastmag-fp-s1').replaceWith(result); jQuery('.owl-carousel.bfastmag-fp-s1-posts').owlCarousel({ loop: true, margin: 30, responsiveClass: true, nav: true, navText: ['', ''], dots: false, autoplay: true, autoplayTimeout: 12000, lazyLoad: true, animateIn: true, responsive: { 0: {items: 1}, 600: {items: 2}, 992: {items: 3} } }); } }); }); }); // Section 4 N0 of posts wp.customize('bfastmag_block4_max_posts', function (value) { value.bind(function (to) { jQuery.ajax({ url: get_post_aj.ajaxurl, type: 'post', data: { action: 'get_post_aj_act', section: 'bfastmag_block4_category', tp_no_of_posts: to, category: wp.customize._value.bfastmag_block4_category() }, beforeSend: function () { jQuery('.bfastmag-block4').find('.bfastmag-fp-s1').replaceWith('
Loading New Posts...
'); }, success: function (result) { jQuery('.bfastmag-block4').find('.bfastmag-fp-s1').replaceWith(result); jQuery('.owl-carousel.bfastmag-fp-s1-posts').owlCarousel({ loop: true, margin: 30, responsiveClass: true, nav: true, navText: ['', ''], dots: false, autoplay: true, autoplayTimeout: 12000, lazyLoad: true, animateIn: true, responsive: { 0: {items: 1}, 600: {items: 2}, 992: {items: 3} } }); } }); }); }); wp.customize('bfastmag_disable_single_hide_author', function (value) { value.bind(function (to) { if (true !== to) { $('.about-author ').removeClass('bfastmag_hide'); } else { $('.about-author ').addClass('bfastmag_hide'); } }); }); wp.customize('bfastmag_single_post_hide_related_posts', function (value) { value.bind(function (to) { if (true !== to) { $('.bfastmag-related-posts ').removeClass('bfastmag_hide'); $('.bfastmag-related-posts-title ').removeClass('bfastmag_hide'); } else { $('.bfastmag-related-posts ').addClass('bfastmag_hide'); $('.bfastmag-related-posts-title ').addClass('bfastmag_hide'); } }); }); wp.customize('bfastmag_disable_singlePost_featured_img', function (value) { value.bind(function (to) { if (true !== to) { $('.post .tp-post-thumbnail').removeClass('bfastmag_customizer_only'); } else { $('.post .tp-post-thumbnail').addClass('bfastmag_customizer_only'); } }); }); wp.customize('bfastmag_footer_logo', function (value) { value.bind(function (to) { $('.bfastmag-footer-logo img').attr('src', to); }); }); wp.customize('bfastmag_footer_link', function (value) { value.bind(function (to) { $('.bfastmag-footer-logo').attr('href', to); }); }); wp.customize('bfastmag_footer_text', function (value) { value.bind(function (to) { var escaped_content = bfastmag_strip_tags(to, '