ru-se.com

Unnamed repository; edit this file 'description' to name the repository.
Log | Files | Refs

customize-preview.js (20451B)


      1 function materialisLiveUpdate(setting, callback) {
      2     var cb = function (value) {
      3         value.bind(callback);
      4     };
      5     var _setting = setting;
      6     wp.customize(_setting, cb);
      7 
      8     if (parent.CP_Customizer) {
      9         var _prefixedSetting = parent.CP_Customizer.slugPrefix() + "_" + setting;
     10         wp.customize(_prefixedSetting, cb);
     11     }
     12 }
     13 
     14 function materialisLiveUpdateHeader(settingPart, callback) {
     15     materialisLiveUpdate("header" + settingPart, function (value, oldValue) {
     16         callback(value, oldValue, false);
     17     });
     18 
     19     materialisLiveUpdate("inner_header" + settingPart, function (value, oldValue) {
     20         callback(value, oldValue, true);
     21     });
     22 }
     23 
     24 (function ($) {
     25     wp.customize('full_height_header', function (value) {
     26         value.bind(function (newval) {
     27             if (newval) {
     28                 $('.header-homepage').css('min-height', "100vh");
     29             } else {
     30                 $('.header-homepage').css('min-height', "");
     31             }
     32         });
     33     });
     34 
     35     wp.customize('header_show_overlay', function (value) {
     36         value.bind(function (newval) {
     37             if (newval) {
     38                 $('.header-homepage').addClass('color-overlay');
     39             } else {
     40                 $('.header-homepage').removeClass('color-overlay');
     41             }
     42         });
     43     });
     44     wp.customize('header_sticked_background', function (value) {
     45         value.bind(function (newval) {
     46             if (newval) {
     47                 $('.homepage.navigation-bar.fixto-fixed').css('background-color', newval);
     48             }
     49             var transparent = JSON.parse(wp.customize('header_nav_transparent').get());
     50             if (!transparent) {
     51                 $('.homepage.navigation-bar').css('background-color', newval);
     52             }
     53         });
     54     });
     55     wp.customize('header_nav_transparent', function (value) {
     56         value.bind(function (newval) {
     57             if (newval) {
     58                 $('.homepage.navigation-bar').removeClass('coloured-nav');
     59             } else {
     60                 $('.homepage.navigation-bar').css('background-color', '');
     61                 $('.homepage.navigation-bar').addClass('coloured-nav');
     62             }
     63         });
     64     });
     65     wp.customize('inner_header_sticked_background', function (value) {
     66         value.bind(function (newval) {
     67             if (newval) {
     68                 $('.navigation-bar:not(.homepage).fixto-fixed').css('background-color', newval);
     69             }
     70 
     71             var transparent = JSON.parse(wp.customize('inner_header_nav_transparent').get());
     72             if (!transparent) {
     73                 $('.navigation-bar:not(.homepage)').css('background-color', newval);
     74             }
     75         });
     76     });
     77     wp.customize('inner_header_nav_transparent', function (value) {
     78         value.bind(function (newval) {
     79             if (newval) {
     80                 $('.navigation-bar:not(.homepage)').removeClass('coloured-nav');
     81             } else {
     82                 $('.navigation-bar:not(.homepage)').addClass('coloured-nav');
     83             }
     84         });
     85     });
     86     wp.customize('inner_header_show_overlay', function (value) {
     87         value.bind(function (newval) {
     88             if (newval) {
     89                 $('.header').addClass('color-overlay');
     90             } else {
     91                 $('.header').removeClass('color-overlay');
     92             }
     93         });
     94     });
     95 
     96     wp.customize('header_gradient', function (value) {
     97         value.bind(function (newval, oldval) {
     98             $('.header-homepage').removeClass(oldval);
     99             $('.header-homepage').addClass(newval);
    100         });
    101     });
    102 
    103     wp.customize('inner_header_gradient', function (value) {
    104         value.bind(function (newval, oldval) {
    105             $('.header').removeClass(oldval);
    106             $('.header').addClass(newval);
    107         });
    108     });
    109 
    110 
    111     wp.customize('header_text_box_text_vertical_align', function (value) {
    112         value.bind(function (newVal, oldVal) {
    113             $('.header-hero-content-v-align').removeClass(oldVal).addClass(newVal);
    114         });
    115     });
    116 
    117     wp.customize('header_media_box_vertical_align', function (value) {
    118         value.bind(function (newVal, oldVal) {
    119             $('.header-hero-media-v-align').removeClass(oldVal).addClass(newVal);
    120         });
    121     });
    122 
    123     wp.customize('header_text_box_text_align', function (value) {
    124         value.bind(function (newVal, oldVal) {
    125             $('.materialis-front-page  .header-content .align-holder').removeClass(oldVal).addClass(newVal);
    126         });
    127     });
    128 
    129     function updateMobileBgImagePosition() {
    130         var position = wp.customize('header_bg_position_mobile').get(),
    131             positionParts = position.split(' '),
    132             offset = wp.customize('header_bg_position_mobile_offset').get(),
    133             styleHolder = jQuery('[data-name="custom-mobile-image-position"]');
    134 
    135         if (styleHolder.length == 0) {
    136             styleHolder = jQuery('<style data-name="custom-mobile-image-position"></style>');
    137             styleHolder.appendTo('head');
    138         }
    139 
    140 
    141         position = position + " " + offset + "px";
    142 
    143         styleHolder.text("" +
    144             "@media screen and (max-width: 767px) {\n" +
    145             "   .header-homepage {\n" +
    146             "       background-position: " + position + "!important ;\n" +
    147             "   }\n" +
    148             "}\n");
    149     }
    150 
    151     wp.customize('header_bg_position_mobile', function (value) {
    152         value.bind(updateMobileBgImagePosition);
    153     });
    154 
    155     wp.customize('header_bg_position_mobile_offset', function (value) {
    156         value.bind(updateMobileBgImagePosition);
    157     })
    158 
    159     // media frame //
    160     wp.customize('header_content_frame_offset_left', function (value) {
    161         value.bind(function (left) {
    162             var top = wp.customize('header_content_frame_offset_top').get();
    163             $('.materialis-front-page  .header-description .overlay-box-offset').css({
    164                 'transform': 'translate(' + left + '%,' + top + '%)'
    165             });
    166         });
    167     });
    168 
    169 
    170     wp.customize('header_content_frame_offset_top', function (value) {
    171         value.bind(function (top) {
    172             var left = wp.customize('header_content_frame_offset_left').get();
    173             $('.materialis-front-page  .header-description .overlay-box-offset').css({
    174                 'transform': 'translate(' + left + '%,' + top + '%)'
    175             });
    176         });
    177     });
    178 
    179     wp.customize('header_content_frame_width', function (value) {
    180         value.bind(function (width) {
    181             $('.materialis-front-page  .header-description .overlay-box-offset').css({
    182                 'width': width + '%'
    183             });
    184         });
    185     });
    186 
    187 
    188     wp.customize('header_content_frame_height', function (value) {
    189         value.bind(function (height) {
    190             $('.materialis-front-page  .header-description .overlay-box-offset').css({
    191                 'height': height + '%'
    192             });
    193         });
    194     });
    195 
    196     wp.customize('header_content_frame_thickness', function (value) {
    197         value.bind(function (thickness) {
    198             $('.materialis-front-page  .header-description .overlay-box-offset').css({
    199                 'border-width': thickness + 'px'
    200             });
    201         });
    202     });
    203 
    204     wp.customize('header_content_frame_show_over_image', function (value) {
    205         value.bind(function (value) {
    206             var zIndex = value ? "1" : "-1";
    207             $('.materialis-front-page  .header-description .overlay-box-offset').css('z-index', zIndex);
    208         });
    209     });
    210 
    211     wp.customize('header_content_frame_shadow', function (value) {
    212         value.bind(function (value) {
    213             var shadow = "mdc-elevation--z4";
    214             var frame = $('.materialis-front-page  .header-description .overlay-box-offset');
    215             if (value) {
    216                 frame.addClass(shadow);
    217             } else {
    218                 frame.removeClass(shadow);
    219             }
    220         });
    221     });
    222 
    223 
    224     wp.customize('header_content_frame_color', function (value) {
    225         value.bind(function (color) {
    226             var type = wp.customize('header_content_frame_type').get();
    227             var property = type + "-color";
    228             $('.materialis-front-page  .header-description .overlay-box-offset').css(property, color);
    229         });
    230     });
    231 
    232     wp.customize('header_content_frame_hide_on_mobile', function (value) {
    233         value.bind(function (hide) {
    234             $('.materialis-front-page  .header-description .overlay-box-offset').toggleClass('hide-xs');
    235         });
    236     });
    237 
    238     function updateTopBarInfo(area, index) {
    239         return function (value) {
    240             value.bind(function (html) {
    241                 var id = 'header_top_bar_' + area + '_info_field_' + index + '_icon';
    242                 $("[data-focus-control=" + id + "]").find('span').html(html);
    243             });
    244         }
    245     }
    246 
    247     var areas = ['area-left', 'area-right'];
    248     for (var i = 0; i < areas.length; i++) {
    249         for (var j = 0; j < 3; j++) {
    250             wp.customize('header_top_bar_' + areas[i] + '_info_field_' + j + '_text', updateTopBarInfo(areas[i], j));
    251         }
    252     }
    253 
    254 
    255     /* START FOOTER */
    256 
    257     function toggleFooterSocialIcon(index, selector) {
    258         return function (value) {
    259             value.bind(function (newval) {
    260                 if (newval) {
    261                     $('.footer .footer-social-icons ' + selector).eq(index).removeAttr('data-reiki-hidden');
    262                 } else {
    263                     $('.footer .footer-social-icons ' + selector).eq(index).attr('data-reiki-hidden', 'true');
    264                 }
    265             });
    266         }
    267     }
    268 
    269     function changeFooterSocialIcon(index, selector) {
    270         return function (value) {
    271             value.bind(function (newval, oldval) {
    272                 $('.footer .footer-social-icons ' + selector).eq(index).find('i').removeClass(oldval).addClass(newval);
    273             });
    274         }
    275     }
    276 
    277     for (var ki = 0; ki < 5; ki++) {
    278         wp.customize('footer_content_social_icon_' + ki + '_enabled', toggleFooterSocialIcon(ki, '.social-icon'));
    279         wp.customize('footer_content_social_icon_' + ki + '_icon', changeFooterSocialIcon(ki, '.social-icon'));
    280     }
    281 
    282 
    283     wp.customize('footer_paralax', function (value) {
    284         value.bind(function (newval) {
    285             if (newval) {
    286                 $('.footer').addClass('paralax');
    287                 materialisFooterParalax();
    288             }
    289             else {
    290                 $('.footer').removeClass('paralax');
    291                 materialisStopFooterParalax();
    292             }
    293         });
    294     });
    295 
    296     /* END FOOTER */
    297 
    298 })(jQuery);
    299 
    300 (function ($) {
    301 
    302     wp.customize('header_nav_border', function (value) {
    303         value.bind(function (newval) {
    304             if (newval) {
    305 
    306                 $('.materialis-front-page .navigation-bar.bordered:not(.fixto-fixed)').css({
    307                     "border-bottom-width": wp.customize('header_nav_border_thickness').get() + 'px',
    308                     'border-bottom-color': wp.customize('header_nav_border_color').get()
    309                 });
    310 
    311             }
    312         });
    313     });
    314     wp.customize('inner_header_nav_border', function (value) {
    315         value.bind(function (newval) {
    316             if (newval) {
    317                 $('.materialis-inner-page .navigation-bar.bordered:not(.fixto-fixed)').css({
    318                     "border-bottom-width": wp.customize('header_nav_border_thickness').get() + 'px',
    319                     'border-bottom-color': wp.customize('header_nav_border_color').get()
    320                 });
    321             }
    322         });
    323     });
    324 
    325 })(jQuery);
    326 
    327 (function ($) {
    328     function getGradientValue(setting) {
    329         var getValue = parent.CP_Customizer ? parent.CP_Customizer.utils.getValue : parent.Materialis.Utils.getValue;
    330         var control = parent.wp.customize.control(setting);
    331         var gradient = getValue(control);
    332         var colors = gradient.colors;
    333         var angle = gradient.angle;
    334         angle = parseFloat(angle);
    335         return parent.Materialis.Utils.getGradientString(colors, angle);
    336     }
    337 
    338     function recalculateHeaderOverlayGradient() {
    339         $('.header-homepage .background-overlay').css("background-image", getGradientValue('header_overlay_gradient_colors'));
    340     }
    341 
    342     function recalculateInnerHeaderOverlayGradient() {
    343         $('.header .background-overlay').css("background-image", getGradientValue('inner_header_overlay_gradient_colors'));
    344     }
    345 
    346     materialisLiveUpdate('header_overlay_gradient_colors', recalculateHeaderOverlayGradient);
    347     materialisLiveUpdate('inner_header_overlay_gradient_colors', recalculateInnerHeaderOverlayGradient);
    348 })(jQuery);
    349 
    350 (function ($) {
    351 
    352     // boxed layout //
    353 
    354     wp.customize('layout_boxed_content_enabled', function (value) {
    355         value.bind(function (value) {
    356             var $elements = $('body #page .page-content,body #page > .content ');
    357             if (value) {
    358                 $elements.addClass('mdc-elevation--z20 boxed-layout');
    359                 $elements.css({
    360                     'margin-top': '-' + wp.customize('layout_boxed_content_overlap_height').get() + 'px',
    361                 });
    362                 $('#page').css('background-color', wp.customize('layout_boxed_content_background_color').get());
    363 
    364                 $('.footer').removeClass('paralax');
    365                 materialisStopFooterParalax();
    366             } else {
    367                 $elements.removeClass('mdc-elevation--z20 boxed-layout');
    368                 $elements.css({
    369                     'margin-top': '0px',
    370                 });
    371 
    372                 $('#page').css('background-color', 'transparent');
    373             }
    374         });
    375     });
    376 
    377     wp.customize('layout_boxed_content_background_color', function (value) {
    378         value.bind(function (v) {
    379             $('#page').css('background-color', v);
    380         });
    381     });
    382 
    383     wp.customize('layout_boxed_content_overlap_height', function (value) {
    384         value.bind(function (value) {
    385             var $elements = $('body #page .page-content,body #page > .content ');
    386             $elements.css({
    387                 'margin-top': '-' + value + 'px'
    388             });
    389         });
    390     });
    391 
    392     // logo
    393 
    394     wp.customize('logo_max_height', function (value) {
    395         value.bind(function (newval) {
    396 
    397             currentActionTime = Math.round(+new Date()/1000);
    398 
    399             _.delay(function() {
    400                 if((Math.round(+new Date()/1000)) >= (currentActionTime + 3)) {
    401                     parent.CP_Customizer.preview.refresh();
    402                 }
    403             }, 3000);
    404 
    405         });
    406     });
    407 
    408 })(jQuery);
    409 
    410 (function ($) {
    411 
    412     // Text box background and Elevation
    413 
    414     function setMDCElevation(element, value) {
    415 
    416         element.attr('class', function (i, c) {
    417             return c.replace(/(^|\s)mdc-elevation-\S+/g, '');
    418         });
    419 
    420         if (value > 0) {
    421             element.addClass('mdc-elevation--z' + value);
    422         }
    423 
    424     }
    425 
    426     function setBorderWidth(element, value) {
    427         element.css({
    428             'border-width': value.top + ' ' + value.right + ' ' + value.bottom + ' ' + value.left,
    429             'border-style': 'solid'
    430         });
    431     }
    432 
    433     wp.customize('header_content_fullwidth', function (value) {
    434         value.bind(function (newval) {
    435 
    436             if (newval) {
    437                 $('.header-homepage .header-description').removeClass('gridContainer');
    438             } else {
    439                 $('.header-homepage .header-description').addClass('gridContainer');
    440             }
    441 
    442 
    443         });
    444     });
    445 
    446 
    447     wp.customize('header_text_box_background_border_thickness', function (value) {
    448         value.bind(function (newval) {
    449             var $element = $('.header-homepage .align-holder');
    450             setBorderWidth($element, newval);
    451         });
    452     });
    453 
    454     wp.customize('header_text_box_background_shadow', function (value) {
    455         value.bind(function (newval) {
    456             var $element = $('.header-homepage .align-holder');
    457             setMDCElevation($element, newval);
    458         });
    459     });
    460 
    461     wp.customize('header_content_title_background_border_thickness', function (value) {
    462         value.bind(function (newval) {
    463             var $element = $('.hero-title');
    464             setBorderWidth($element, newval);
    465         });
    466     });
    467 
    468     wp.customize('header_content_title_background_shadow', function (value) {
    469         value.bind(function (newval) {
    470             var $element = $('.hero-title');
    471             setMDCElevation($element, newval);
    472         });
    473     });
    474 
    475     wp.customize('header_content_subtitle_background_border_thickness', function (value) {
    476         value.bind(function (newval) {
    477             var $element = $('.header-subtitle');
    478             setBorderWidth($element, newval);
    479         });
    480     });
    481 
    482     wp.customize('header_content_subtitle_background_shadow', function (value) {
    483         value.bind(function (newval) {
    484             var $element = $('.header-subtitle');
    485             setMDCElevation($element, newval);
    486         });
    487     });
    488 
    489     wp.customize('header_content_subtitle2_background_border_thickness', function (value) {
    490         value.bind(function (newval) {
    491             var $element = $('.header-subtitle2');
    492             setBorderWidth($element, newval);
    493         });
    494     });
    495 
    496     wp.customize('header_content_subtitle2_background_shadow', function (value) {
    497         value.bind(function (newval) {
    498             var $element = $('.header-subtitle2');
    499             setMDCElevation($element, newval);
    500         });
    501     });
    502 
    503     wp.customize('header_content_buttons_background_border_thickness', function (value) {
    504         value.bind(function (newval) {
    505             var $element = $('.header-buttons-wrapper');
    506             setBorderWidth($element, newval);
    507         });
    508     });
    509 
    510     wp.customize('header_content_buttons_background_shadow', function (value) {
    511         value.bind(function (newval) {
    512             var $element = $('.header-buttons-wrapper');
    513             setMDCElevation($element, newval);
    514         });
    515     });
    516 
    517 
    518     wp.customize('header_overlap', function (value) {
    519         value.bind(function (newval) {
    520             var $element = $('body');
    521             if (newval) {
    522                 $element.addClass('overlap-first-section');
    523             } else {
    524                 $element.removeClass('overlap-first-section');
    525             }
    526         });
    527     });
    528 
    529 })(jQuery);
    530 
    531 
    532 (function ($) {
    533    materialisLiveUpdateHeader("_nav_border", function (value, oldValue, inner) {
    534         var selectorStart = inner ? '.materialis-inner-page' : '.materialis-front-page';
    535         var selector = ".navigation-bar";
    536 
    537         if (value) {
    538             $([selectorStart, selector].join(' ')).addClass('bordered');
    539         } else {
    540             $([selectorStart, selector].join(' ')).removeClass('bordered');
    541         }
    542     });
    543 
    544     materialisLiveUpdateHeader("_nav_sticked", function (value, oldValue, inner) {
    545 
    546         var selectorStart = inner ? '.materialis-inner-page' : '.materialis-front-page';
    547         var selector = ".navigation-bar";
    548         var $navBar = $([selectorStart, selector].join(' '));
    549 
    550         if($navBar.length) {
    551 
    552             if (value) {
    553                 $navBar.attr({
    554                     "data-sticky": 0,
    555                     "data-sticky-mobile": 1,
    556                     "data-sticky-to": "top"
    557                 });
    558 
    559                 if ($navBar.data().fixtoInstance) {
    560                     $navBar.data().fixtoInstance.start();
    561                 } else {
    562                     materialisMenuSticky();
    563                 }
    564 
    565             } else {
    566                 $navBar.removeAttr('data-sticky');
    567                 $navBar.removeAttr('data-sticky-mobile');
    568                 $navBar.removeAttr('data-sticky-to');
    569 
    570                 if ($navBar.data().fixtoInstance) {
    571                     $navBar.data().fixtoInstance.stop();
    572                 }
    573             }
    574 
    575         }
    576     });
    577 
    578 
    579     materialisLiveUpdateHeader('_slideshow_duration', function (value, oldValue, inner) {
    580         var selectorStart = inner ? '.materialis-inner-page' : '.materialis-front-page';
    581         var selector = inner ? ".header" : ".header-homepage";
    582         var $header = $([selectorStart, selector].join(' '));
    583 
    584         if ($header.data().backstretch) {
    585             $header.data().backstretch.options.duration = parseInt(value);
    586         }
    587 
    588     });
    589 
    590 
    591     materialisLiveUpdateHeader('_slideshow_speed', function (value, oldValue, inner) {
    592         var selectorStart = inner ? '.materialis-inner-page' : '.materialis-front-page';
    593         var selector = inner ? ".header" : ".header-homepage";
    594         var $header = $([selectorStart, selector].join(' '));
    595 
    596         if ($header.data().backstretch) {
    597             $header.data().backstretch.options.transitionDuration = parseInt(value);
    598         }
    599 
    600     });
    601 
    602 })(jQuery)