Free cookie consent management tool by TermsFeed Policy Generator

source: branches/HiveStatistics/sources/HeuristicLab.Services.Hive.Statistics/3.3/Scripts/jquery.scrollstop.js @ 11552

Last change on this file since 11552 was 11030, checked in by mroscoe, 11 years ago
File size: 2.0 KB
Line 
1/*!
2 * jQuery Scrollstop Plugin v1.1.0
3 * https://github.com/ssorallen/jquery-scrollstop
4 */
5(function($) {
6  // $.event.dispatch was undocumented and was deprecated in jQuery 1.7[1]. It
7  // was replaced by $.event.handle in jQuery 1.9.
8  //
9  // Use the first of the available functions to support jQuery <1.8.
10  //
11  // [1] https://github.com/jquery/jquery-migrate/blob/master/src/event.js#L25
12  var dispatch = $.event.dispatch || $.event.handle;
13
14  var special = $.event.special,
15      uid1 = 'D' + (+new Date()),
16      uid2 = 'D' + (+new Date() + 1);
17
18  special.scrollstart = {
19    setup: function(data) {
20      var _data = $.extend({
21        latency: special.scrollstop.latency
22      }, data);
23
24      var timer,
25          handler = function(evt) {
26            var _self = this,
27                _args = arguments;
28
29            if (timer) {
30              clearTimeout(timer);
31            } else {
32              evt.type = 'scrollstart';
33              dispatch.apply(_self, _args);
34            }
35
36            timer = setTimeout(function() {
37              timer = null;
38            }, _data.latency);
39          };
40
41      $(this).bind('scroll', handler).data(uid1, handler);
42    },
43    teardown: function() {
44      $(this).unbind('scroll', $(this).data(uid1));
45    }
46  };
47
48  special.scrollstop = {
49    latency: 250,
50    setup: function(data) {
51      var _data = $.extend({
52        latency: special.scrollstop.latency
53      }, data);
54
55      var timer,
56          handler = function(evt) {
57            var _self = this,
58                _args = arguments;
59
60            if (timer) {
61              clearTimeout(timer);
62            }
63
64            timer = setTimeout(function() {
65              timer = null;
66              evt.type = 'scrollstop';
67              dispatch.apply(_self, _args);
68            }, _data.latency);
69          };
70
71      $(this).bind('scroll', handler).data(uid2, handler);
72    },
73    teardown: function() {
74      $(this).unbind('scroll', $(this).data(uid2));
75    }
76  };
77
78})(jQuery);
Note: See TracBrowser for help on using the repository browser.