Plugin Directory

Changeset 1525243


Ignore:
Timestamp:
10/31/2016 11:49:06 AM (9 years ago)
Author:
johansylvan
Message:

added debounce for scrollevents

Location:
custom-cookie-message
Files:
4 edited
7 copied

Legend:

Unmodified
Added
Removed
  • custom-cookie-message/tags/1.1/README.txt

    r1525138 r1525243  
    33Tags:  custom, cookie, message, consent, cookie bar, cookie compliance, cookie law, cookie notice, cookie notification, cookie notification bar, cookie notify, cookies, eu, eu cookie, eu cookie law, notice, notification, notify, custom cookie message, WPML, Polylang, Multisite, multisites
    44Requires at least: 1.0
    5 Tested up to: 1.0
    6 Stable tag: 1.0
     5Tested up to: 1.1
     6Stable tag: 1.1
    77License: GPLv2 or later
    88License URI: http://www.gnu.org/licenses/gpl-2.0.html
  • custom-cookie-message/tags/1.1/custom-cookie-message.php

    r1525170 r1525243  
    55 * Plugin URI: https://angrycreative.se/
    66 * Description: A customizable cookie message.
    7  * Version: 1.0
     7 * Version: 1.1
    88 * Author: johansylvan
    99 * Author URI: https://angrycreative.se/
  • custom-cookie-message/tags/1.1/js/ac-custom-cookie-message-frontend.js

    r1525170 r1525243  
    44 */
    55
     6//Debounce from David Walsh https://davidwalsh.name/javascript-debounce-function
     7function debounce(func, wait, immediate) {
     8    var timeout;
     9    return function() {
     10        var context = this, args = arguments;
     11        var later = function() {
     12            timeout = null;
     13            if (!immediate) func.apply(context, args);
     14        };
     15        var callNow = immediate && !timeout;
     16        clearTimeout(timeout);
     17        timeout = setTimeout(later, wait);
     18        if (callNow) func.apply(context, args);
     19    };
     20};
     21
    622
    723jQuery(document).ready(function($) {
    8     // Feature detect + local reference
    9         var storage = (function() {
    10             var uid = new Date;
    11             var storage;
    12             var result;
    13             try {
    14                 (storage = window.localStorage).setItem(uid, uid);
    15                 result = storage.getItem(uid) == uid;
    16                 storage.removeItem(uid);
    17                 return result && storage;
    18             } catch (exception) {}
    19         }());
     24    // Hide Header on on scroll
     25    var didScroll;
     26    var lastScrollTop = 0;
     27    var lastScrollBot = 0;
     28    var delta = 5;
     29    var navbarHeight = $('#custom-cookie-message-container').outerHeight();
     30
     31    var storage = (function() {
     32        var uid = new Date;
     33        var storage;
     34        var result;
     35        try {
     36            (storage = window.localStorage).setItem(uid, uid);
     37            result = storage.getItem(uid) == uid;
     38            storage.removeItem(uid);
     39            return result && storage;
     40        } catch (exception) {}
     41    }());
     42
     43    $(window).on('scroll', debounce( function () {
     44        hasScrolled();
     45    }, 250));
    2046
    2147    setTimeout(function() {
     
    3460            });
    3561        }
    36 
    37 
    38 
    3962    },10);
    4063
     
    5073        })
    5174        .done(function( data ) {
    52            
    5375            storage.setItem("ac-cookie-fallback", "fallback")
    5476            $('#custom-cookie-message-container').hide();
     
    5981        });
    6082    });
    61 
    62     // Hide Header on on scroll down
    63     var didScroll;
    64     var lastScrollTop = 0;
    65     var lastScrollBot = 0;
    66     var delta = 5;
    67     var navbarHeight = $('#custom-cookie-message-container').outerHeight();
    68 
    69     $(window).scroll(function(event){
    70         didScroll = true;
    71     });
    72 
    73     setInterval(function() {
    74         if (didScroll) {
    75             hasScrolled();
    76             didScroll = false;
    77         }
    78     }, 250);
    79 
     83   
    8084    function hasScrolled() {
    8185        var st = $(this).scrollTop();
     
    8690            return;
    8791
    88         // If they scrolled down and are past the navbar, add class .nav-up.
    89         // This is necessary so you never see what is "behind" the navbar.
    9092        if (st > lastScrollTop && st > navbarHeight){
    9193            // Scroll Down
  • custom-cookie-message/trunk/README.txt

    r1525138 r1525243  
    33Tags:  custom, cookie, message, consent, cookie bar, cookie compliance, cookie law, cookie notice, cookie notification, cookie notification bar, cookie notify, cookies, eu, eu cookie, eu cookie law, notice, notification, notify, custom cookie message, WPML, Polylang, Multisite, multisites
    44Requires at least: 1.0
    5 Tested up to: 1.0
    6 Stable tag: 1.0
     5Tested up to: 1.1
     6Stable tag: 1.1
    77License: GPLv2 or later
    88License URI: http://www.gnu.org/licenses/gpl-2.0.html
  • custom-cookie-message/trunk/custom-cookie-message.php

    r1525170 r1525243  
    55 * Plugin URI: https://angrycreative.se/
    66 * Description: A customizable cookie message.
    7  * Version: 1.0
     7 * Version: 1.1
    88 * Author: johansylvan
    99 * Author URI: https://angrycreative.se/
  • custom-cookie-message/trunk/js/ac-custom-cookie-message-frontend.js

    r1525170 r1525243  
    44 */
    55
     6//Debounce from David Walsh https://davidwalsh.name/javascript-debounce-function
     7function debounce(func, wait, immediate) {
     8    var timeout;
     9    return function() {
     10        var context = this, args = arguments;
     11        var later = function() {
     12            timeout = null;
     13            if (!immediate) func.apply(context, args);
     14        };
     15        var callNow = immediate && !timeout;
     16        clearTimeout(timeout);
     17        timeout = setTimeout(later, wait);
     18        if (callNow) func.apply(context, args);
     19    };
     20};
     21
    622
    723jQuery(document).ready(function($) {
    8     // Feature detect + local reference
    9         var storage = (function() {
    10             var uid = new Date;
    11             var storage;
    12             var result;
    13             try {
    14                 (storage = window.localStorage).setItem(uid, uid);
    15                 result = storage.getItem(uid) == uid;
    16                 storage.removeItem(uid);
    17                 return result && storage;
    18             } catch (exception) {}
    19         }());
     24    // Hide Header on on scroll
     25    var didScroll;
     26    var lastScrollTop = 0;
     27    var lastScrollBot = 0;
     28    var delta = 5;
     29    var navbarHeight = $('#custom-cookie-message-container').outerHeight();
     30
     31    var storage = (function() {
     32        var uid = new Date;
     33        var storage;
     34        var result;
     35        try {
     36            (storage = window.localStorage).setItem(uid, uid);
     37            result = storage.getItem(uid) == uid;
     38            storage.removeItem(uid);
     39            return result && storage;
     40        } catch (exception) {}
     41    }());
     42
     43    $(window).on('scroll', debounce( function () {
     44        hasScrolled();
     45    }, 250));
    2046
    2147    setTimeout(function() {
     
    3460            });
    3561        }
    36 
    37 
    38 
    3962    },10);
    4063
     
    5073        })
    5174        .done(function( data ) {
    52            
    5375            storage.setItem("ac-cookie-fallback", "fallback")
    5476            $('#custom-cookie-message-container').hide();
     
    5981        });
    6082    });
    61 
    62     // Hide Header on on scroll down
    63     var didScroll;
    64     var lastScrollTop = 0;
    65     var lastScrollBot = 0;
    66     var delta = 5;
    67     var navbarHeight = $('#custom-cookie-message-container').outerHeight();
    68 
    69     $(window).scroll(function(event){
    70         didScroll = true;
    71     });
    72 
    73     setInterval(function() {
    74         if (didScroll) {
    75             hasScrolled();
    76             didScroll = false;
    77         }
    78     }, 250);
    79 
     83   
    8084    function hasScrolled() {
    8185        var st = $(this).scrollTop();
     
    8690            return;
    8791
    88         // If they scrolled down and are past the navbar, add class .nav-up.
    89         // This is necessary so you never see what is "behind" the navbar.
    9092        if (st > lastScrollTop && st > navbarHeight){
    9193            // Scroll Down
Note: See TracChangeset for help on using the changeset viewer.