-
Notifications
You must be signed in to change notification settings - Fork 281
/
hook.js
57 lines (54 loc) · 1.89 KB
/
hook.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
/**
* Hook
* Version: 2.0
* Author: Jordan Singer, Brandon Jacoby, Adam Girton
* Copyright (c) 2016 Hook. All rights reserved.
* https://github.com/jordansinger/Hook
*/
(function($, window, document, undefined) {
var win = $(this),
st = win.scrollTop() || window.pageYOffset,
called = false;
var methods = {
init: function(options) {
return this.each(function() {
var $this = $(this),
settings = $this.data("hook");
if (typeof(settings) === "undefined") {
var defaults = {
refresh: true, // refresh the page
callback: function() {}
};
settings = $.extend({}, defaults, options);
$this.data("hook", settings);
} else {
settings = $.extend({}, settings, options);
}
$(window).scroll(function(event) {
var st = $(window).scrollTop();
if (st <= 0) {
if (!settings.refresh) {
settings.callback();
} else {
$this.addClass("fadeIn");
window.location.reload();
}
}
});
});
}
};
$.fn.hook = function() {
var method = arguments[0];
if (methods[method]) {
method = methods[method];
arguments = Array.prototype.slice.call(arguments, 1);
} else if (typeof(method) === "object" || !method) {
method = methods.init;
} else {
$.error("Method " + method + " does not exist on jQuery.pluginName");
return this;
}
return method.apply(this, arguments);
};
})(jQuery, window, document);