ru-se.com

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

sticky.js (3583B)


      1 (function () {
      2 
      3     window.materialisMenuSticky = function() {
      4         var $ = jQuery;
      5         var dataprefix = "data-sticky";
      6 
      7         function attrName(name) {
      8             return name ? dataprefix + "-" + name : dataprefix;
      9         }
     10 
     11         var stickyElements = $('[' + dataprefix + ']');
     12         stickyElements.each(function (index, el) {
     13             var $el = $(el);
     14 
     15             if ($el.data('stickData')) {
     16                 return;
     17             }
     18 
     19             var distance = parseInt($el.attr(attrName()));
     20             var stickyOnMobile = $el.attr(attrName("mobile")) == "1";
     21             var stickyOnTablet = true; //$el.attr(attrName("tablet")) == "1" ;
     22             var useShrink = $el.attr(attrName("shrinked")) == "1";
     23             var toBottom = $el.attr(attrName("to")) == "bottom";
     24             var always = $el.attr(attrName("always")) == "1";
     25             if (always) {
     26                 $el.addClass("fixto-fixed");
     27             }
     28 
     29             if (useShrink) {
     30                 $el.attr(attrName(), "initial");
     31             }
     32 
     33             var stickData = {
     34                 center: true,
     35                 responsiveWidth: true,
     36                 zIndex: (10000 + index),
     37                 topSpacing: distance,
     38                 stickyOnMobile: stickyOnMobile,
     39                 stickyOnTablet: stickyOnTablet,
     40                 useShrink: useShrink,
     41                 toBottom: toBottom,
     42                 useNativeSticky: false,
     43                 always:always
     44             }
     45 
     46             if (useShrink) {
     47                 return;
     48             }
     49 
     50 
     51             if (distance === 0 && jQuery('#wpadminbar').length && jQuery('#wpadminbar').css('position') === "absolute") {
     52                 distance = 0;
     53             }
     54 
     55             stickData['topSpacing'] = distance;
     56             stickData['top'] = distance;
     57 
     58             $el.data('stickData', stickData);
     59             $el.fixTo('body', stickData);
     60         });
     61 
     62         var resizeCallback = function () {
     63             var stickyElements = this.$els;
     64 
     65             if (window.innerWidth < 1024) {
     66                 stickyElements.each(function (index, el) {
     67                     var data = $(this).data();
     68                     var stickData = data.stickData;
     69 
     70                     if (!stickData) {
     71                         return;
     72                     }
     73 
     74                     var fixToInstance = data.fixtoInstance;
     75                     if (!fixToInstance)
     76                         return true;
     77 
     78                     if (window.innerWidth <= 767) {
     79                         if (!stickData.stickyOnMobile) {
     80                             fixToInstance.stop();
     81                         }
     82                     } else {
     83                         if (!stickData.stickyOnTablet) {
     84                             fixToInstance.stop();
     85                         }
     86                     }
     87                 });
     88             } else {
     89                 stickyElements.each(function (index, el) {
     90                     var data = $(this).data();
     91                     if (!data) {
     92                         return;
     93                     }
     94                     var fixToInstance = data.fixtoInstance;
     95                     if (!fixToInstance)
     96                         return true;
     97                     fixToInstance.start();
     98                 })
     99             }
    100         }
    101 
    102         .bind({
    103             "$els": stickyElements
    104         });
    105 
    106         $(window).bind('resize.sticky orientationchange.sticky', function () {
    107             setTimeout(resizeCallback, 50);
    108         });
    109         $(window).trigger('resize.sticky');
    110     }
    111 
    112     jQuery(document).ready(function ($) {
    113         materialisMenuSticky();
    114     });
    115 
    116 })();