Sufyan

Waypoints.js

Mar 9th, 2016
166
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Pawn 17.44 KB | None | 0 0
  1. // Generated by CoffeeScript 1.6.2
  2. /*
  3. jQuery Waypoints - v2.0.3
  4. Copyright (c) 2011-2013 Caleb Troughton
  5. Dual licensed under the MIT license and GPL license.
  6. https://github.com/imakewebthings/jquery-waypoints/blob/master/licenses.txt
  7. */
  8. (function() {
  9.     var t = [].indexOf || function(t) {
  10.             for (var e = 0, n = this.length; e < n; e++) {
  11.                 if (e in this && this[e] === t) return e
  12.             }
  13.             return -1
  14.         },
  15.         e = [].slice;
  16.     (function(t, e) {
  17.         if (typeof define === "function" && define.amd) {
  18.             return define("waypoints", ["jquery"], function(n) {
  19.                 return e(n, t)
  20.             })
  21.         } else {
  22.             return e(t.jQuery, t)
  23.         }
  24.     })(this, function(n, r) {
  25.         var i, o, l, s, f, u, a, c, h, d, p, y, v, w, g, m;
  26.         i = n(r);
  27.         c = t.call(r, "ontouchstart") >= 0;
  28.         s = {
  29.             horizontal: {},
  30.             vertical: {}
  31.         };
  32.         f = 1;
  33.         a = {};
  34.         u = "waypoints-context-id";
  35.         p = "resize.waypoints";
  36.         y = "scroll.waypoints";
  37.         v = 1;
  38.         w = "waypoints-waypoint-ids";
  39.         g = "waypoint";
  40.         m = "waypoints";
  41.         o = function() {
  42.             function t(t) {
  43.                 var e = this;
  44.                 this.$element = t;
  45.                 this.element = t[0];
  46.                 this.didResize = false;
  47.                 this.didScroll = false;
  48.                 this.id = "context" + f++;
  49.                 this.oldScroll = {
  50.                     x: t.scrollLeft(),
  51.                     y: t.scrollTop()
  52.                 };
  53.                 this.waypoints = {
  54.                     horizontal: {},
  55.                     vertical: {}
  56.                 };
  57.                 t.data(u, this.id);
  58.                 a[this.id] = this;
  59.                 t.bind(y, function() {
  60.                     var t;
  61.                     if (!(e.didScroll || c)) {
  62.                         e.didScroll = true;
  63.                         t = function() {
  64.                             e.doScroll();
  65.                             return e.didScroll = false
  66.                         };
  67.                         return r.setTimeout(t, n[m].settings.scrollThrottle)
  68.                     }
  69.                 });
  70.                 t.bind(p, function() {
  71.                     var t;
  72.                     if (!e.didResize) {
  73.                         e.didResize = true;
  74.                         t = function() {
  75.                             n[m]("refresh");
  76.                             return e.didResize = false
  77.                         };
  78.                         return r.setTimeout(t, n[m].settings.resizeThrottle)
  79.                     }
  80.                 })
  81.             }
  82.             t.prototype.doScroll = function() {
  83.                 var t, e = this;
  84.                 t = {
  85.                     horizontal: {
  86.                         newScroll: this.$element.scrollLeft(),
  87.                         oldScroll: this.oldScroll.x,
  88.                         forward: "right",
  89.                         backward: "left"
  90.                     },
  91.                     vertical: {
  92.                         newScroll: this.$element.scrollTop(),
  93.                         oldScroll: this.oldScroll.y,
  94.                         forward: "down",
  95.                         backward: "up"
  96.                     }
  97.                 };
  98.                 if (c && (!t.vertical.oldScroll || !t.vertical.newScroll)) {
  99.                     n[m]("refresh")
  100.                 }
  101.                 n.each(t, function(t, r) {
  102.                     var i, o, l;
  103.                     l = [];
  104.                     o = r.newScroll > r.oldScroll;
  105.                     i = o ? r.forward : r.backward;
  106.                     n.each(e.waypoints[t], function(t, e) {
  107.                         var n, i;
  108.                         if (r.oldScroll < (n = e.offset) && n <= r.newScroll) {
  109.                             return l.push(e)
  110.                         } else if (r.newScroll < (i = e.offset) && i <= r.oldScroll) {
  111.                             return l.push(e)
  112.                         }
  113.                     });
  114.                     l.sort(function(t, e) {
  115.                         return t.offset - e.offset
  116.                     });
  117.                     if (!o) {
  118.                         l.reverse()
  119.                     }
  120.                     return n.each(l, function(t, e) {
  121.                         if (e.options.continuous || t === l.length - 1) {
  122.                             return e.trigger([i])
  123.                         }
  124.                     })
  125.                 });
  126.                 return this.oldScroll = {
  127.                     x: t.horizontal.newScroll,
  128.                     y: t.vertical.newScroll
  129.                 }
  130.             };
  131.             t.prototype.refresh = function() {
  132.                 var t, e, r, i = this;
  133.                 r = n.isWindow(this.element);
  134.                 e = this.$element.offset();
  135.                 this.doScroll();
  136.                 t = {
  137.                     horizontal: {
  138.                         contextOffset: r ? 0 : e.left,
  139.                         contextScroll: r ? 0 : this.oldScroll.x,
  140.                         contextDimension: this.$element.width(),
  141.                         oldScroll: this.oldScroll.x,
  142.                         forward: "right",
  143.                         backward: "left",
  144.                         offsetProp: "left"
  145.                     },
  146.                     vertical: {
  147.                         contextOffset: r ? 0 : e.top,
  148.                         contextScroll: r ? 0 : this.oldScroll.y,
  149.                         contextDimension: r ? n[m]("viewportHeight") : this.$element.height(),
  150.                         oldScroll: this.oldScroll.y,
  151.                         forward: "down",
  152.                         backward: "up",
  153.                         offsetProp: "top"
  154.                     }
  155.                 };
  156.                 return n.each(t, function(t, e) {
  157.                     return n.each(i.waypoints[t], function(t, r) {
  158.                         var i, o, l, s, f;
  159.                         i = r.options.offset;
  160.                         l = r.offset;
  161.                         o = n.isWindow(r.element) ? 0 : r.$element.offset()[e.offsetProp];
  162.                         if (n.isFunction(i)) {
  163.                             i = i.apply(r.element)
  164.                         } else if (typeof i === "string") {
  165.                             i = parseFloat(i);
  166.                             if (r.options.offset.indexOf("%") > -1) {
  167.                                 i = Math.ceil(e.contextDimension * i / 100)
  168.                             }
  169.                         }
  170.                         r.offset = o - e.contextOffset + e.contextScroll - i;
  171.                         if (r.options.onlyOnScroll && l != null || !r.enabled) {
  172.                             return
  173.                         }
  174.                         if (l !== null && l < (s = e.oldScroll) && s <= r.offset) {
  175.                             return r.trigger([e.backward])
  176.                         } else if (l !== null && l > (f = e.oldScroll) && f >= r.offset) {
  177.                             return r.trigger([e.forward])
  178.                         } else if (l === null && e.oldScroll >= r.offset) {
  179.                             return r.trigger([e.forward])
  180.                         }
  181.                     })
  182.                 })
  183.             };
  184.             t.prototype.checkEmpty = function() {
  185.                 if (n.isEmptyObject(this.waypoints.horizontal) && n.isEmptyObject(this.waypoints.vertical)) {
  186.                     this.$element.unbind([p, y].join(" "));
  187.                     return delete a[this.id]
  188.                 }
  189.             };
  190.             return t
  191.         }();
  192.         l = function() {
  193.             function t(t, e, r) {
  194.                 var i, o;
  195.                 r = n.extend({}, n.fn[g].defaults, r);
  196.                 if (r.offset === "bottom-in-view") {
  197.                     r.offset = function() {
  198.                         var t;
  199.                         t = n[m]("viewportHeight");
  200.                         if (!n.isWindow(e.element)) {
  201.                             t = e.$element.height()
  202.                         }
  203.                         return t - n(this).outerHeight()
  204.                     }
  205.                 }
  206.                 this.$element = t;
  207.                 this.element = t[0];
  208.                 this.axis = r.horizontal ? "horizontal" : "vertical";
  209.                 this.callback = r.handler;
  210.                 this.context = e;
  211.                 this.enabled = r.enabled;
  212.                 this.id = "waypoints" + v++;
  213.                 this.offset = null;
  214.                 this.options = r;
  215.                 e.waypoints[this.axis][this.id] = this;
  216.                 s[this.axis][this.id] = this;
  217.                 i = (o = t.data(w)) != null ? o : [];
  218.                 i.push(this.id);
  219.                 t.data(w, i)
  220.             }
  221.             t.prototype.trigger = function(t) {
  222.                 if (!this.enabled) {
  223.                     return
  224.                 }
  225.                 if (this.callback != null) {
  226.                     this.callback.apply(this.element, t)
  227.                 }
  228.                 if (this.options.triggerOnce) {
  229.                     return this.destroy()
  230.                 }
  231.             };
  232.             t.prototype.disable = function() {
  233.                 return this.enabled = false
  234.             };
  235.             t.prototype.enable = function() {
  236.                 this.context.refresh();
  237.                 return this.enabled = true
  238.             };
  239.             t.prototype.destroy = function() {
  240.                 delete s[this.axis][this.id];
  241.                 delete this.context.waypoints[this.axis][this.id];
  242.                 return this.context.checkEmpty()
  243.             };
  244.             t.getWaypointsByElement = function(t) {
  245.                 var e, r;
  246.                 r = n(t).data(w);
  247.                 if (!r) {
  248.                     return []
  249.                 }
  250.                 e = n.extend({}, s.horizontal, s.vertical);
  251.                 return n.map(r, function(t) {
  252.                     return e[t]
  253.                 })
  254.             };
  255.             return t
  256.         }();
  257.         d = {
  258.             init: function(t, e) {
  259.                 var r;
  260.                 if (e == null) {
  261.                     e = {}
  262.                 }
  263.                 if ((r = e.handler) == null) {
  264.                     e.handler = t
  265.                 }
  266.                 this.each(function() {
  267.                     var t, r, i, s;
  268.                     t = n(this);
  269.                     i = (s = e.context) != null ? s : n.fn[g].defaults.context;
  270.                     if (!n.isWindow(i)) {
  271.                         i = t.closest(i)
  272.                     }
  273.                     i = n(i);
  274.                     r = a[i.data(u)];
  275.                     if (!r) {
  276.                         r = new o(i)
  277.                     }
  278.                     return new l(t, r, e)
  279.                 });
  280.                 n[m]("refresh");
  281.                 return this
  282.             },
  283.             disable: function() {
  284.                 return d._invoke(this, "disable")
  285.             },
  286.             enable: function() {
  287.                 return d._invoke(this, "enable")
  288.             },
  289.             destroy: function() {
  290.                 return d._invoke(this, "destroy")
  291.             },
  292.             prev: function(t, e) {
  293.                 return d._traverse.call(this, t, e, function(t, e, n) {
  294.                     if (e > 0) {
  295.                         return t.push(n[e - 1])
  296.                     }
  297.                 })
  298.             },
  299.             next: function(t, e) {
  300.                 return d._traverse.call(this, t, e, function(t, e, n) {
  301.                     if (e < n.length - 1) {
  302.                         return t.push(n[e + 1])
  303.                     }
  304.                 })
  305.             },
  306.             _traverse: function(t, e, i) {
  307.                 var o, l;
  308.                 if (t == null) {
  309.                     t = "vertical"
  310.                 }
  311.                 if (e == null) {
  312.                     e = r
  313.                 }
  314.                 l = h.aggregate(e);
  315.                 o = [];
  316.                 this.each(function() {
  317.                     var e;
  318.                     e = n.inArray(this, l[t]);
  319.                     return i(o, e, l[t])
  320.                 });
  321.                 return this.pushStack(o)
  322.             },
  323.             _invoke: function(t, e) {
  324.                 t.each(function() {
  325.                     var t;
  326.                     t = l.getWaypointsByElement(this);
  327.                     return n.each(t, function(t, n) {
  328.                         n[e]();
  329.                         return true
  330.                     })
  331.                 });
  332.                 return this
  333.             }
  334.         };
  335.         n.fn[g] = function() {
  336.             var t, r;
  337.             r = arguments[0], t = 2 <= arguments.length ? e.call(arguments, 1) : [];
  338.             if (d[r]) {
  339.                 return d[r].apply(this, t)
  340.             } else if (n.isFunction(r)) {
  341.                 return d.init.apply(this, arguments)
  342.             } else if (n.isPlainObject(r)) {
  343.                 return d.init.apply(this, [null, r])
  344.             } else if (!r) {
  345.                 return n.error("jQuery Waypoints needs a callback function or handler option.")
  346.             } else {
  347.                 return n.error("The " + r + " method does not exist in jQuery Waypoints.")
  348.             }
  349.         };
  350.         n.fn[g].defaults = {
  351.             context: r,
  352.             continuous: true,
  353.             enabled: true,
  354.             horizontal: false,
  355.             offset: 0,
  356.             triggerOnce: false
  357.         };
  358.         h = {
  359.             refresh: function() {
  360.                 return n.each(a, function(t, e) {
  361.                     return e.refresh()
  362.                 })
  363.             },
  364.             viewportHeight: function() {
  365.                 var t;
  366.                 return (t = r.innerHeight) != null ? t : i.height()
  367.             },
  368.             aggregate: function(t) {
  369.                 var e, r, i;
  370.                 e = s;
  371.                 if (t) {
  372.                     e = (i = a[n(t).data(u)]) != null ? i.waypoints : void 0
  373.                 }
  374.                 if (!e) {
  375.                     return []
  376.                 }
  377.                 r = {
  378.                     horizontal: [],
  379.                     vertical: []
  380.                 };
  381.                 n.each(r, function(t, i) {
  382.                     n.each(e[t], function(t, e) {
  383.                         return i.push(e)
  384.                     });
  385.                     i.sort(function(t, e) {
  386.                         return t.offset - e.offset
  387.                     });
  388.                     r[t] = n.map(i, function(t) {
  389.                         return t.element
  390.                     });
  391.                     return r[t] = n.unique(r[t])
  392.                 });
  393.                 return r
  394.             },
  395.             above: function(t) {
  396.                 if (t == null) {
  397.                     t = r
  398.                 }
  399.                 return h._filter(t, "vertical", function(t, e) {
  400.                     return e.offset <= t.oldScroll.y
  401.                 })
  402.             },
  403.             below: function(t) {
  404.                 if (t == null) {
  405.                     t = r
  406.                 }
  407.                 return h._filter(t, "vertical", function(t, e) {
  408.                     return e.offset > t.oldScroll.y
  409.                 })
  410.             },
  411.             left: function(t) {
  412.                 if (t == null) {
  413.                     t = r
  414.                 }
  415.                 return h._filter(t, "horizontal", function(t, e) {
  416.                     return e.offset <= t.oldScroll.x
  417.                 })
  418.             },
  419.             right: function(t) {
  420.                 if (t == null) {
  421.                     t = r
  422.                 }
  423.                 return h._filter(t, "horizontal", function(t, e) {
  424.                     return e.offset > t.oldScroll.x
  425.                 })
  426.             },
  427.             enable: function() {
  428.                 return h._invoke("enable")
  429.             },
  430.             disable: function() {
  431.                 return h._invoke("disable")
  432.             },
  433.             destroy: function() {
  434.                 return h._invoke("destroy")
  435.             },
  436.             extendFn: function(t, e) {
  437.                 return d[t] = e
  438.             },
  439.             _invoke: function(t) {
  440.                 var e;
  441.                 e = n.extend({}, s.vertical, s.horizontal);
  442.                 return n.each(e, function(e, n) {
  443.                     n[t]();
  444.                     return true
  445.                 })
  446.             },
  447.             _filter: function(t, e, r) {
  448.                 var i, o;
  449.                 i = a[n(t).data(u)];
  450.                 if (!i) {
  451.                     return []
  452.                 }
  453.                 o = [];
  454.                 n.each(i.waypoints[e], function(t, e) {
  455.                     if (r(i, e)) {
  456.                         return o.push(e)
  457.                     }
  458.                 });
  459.                 o.sort(function(t, e) {
  460.                     return t.offset - e.offset
  461.                 });
  462.                 return n.map(o, function(t) {
  463.                     return t.element
  464.                 })
  465.             }
  466.         };
  467.         n[m] = function() {
  468.             var t, n;
  469.             n = arguments[0], t = 2 <= arguments.length ? e.call(arguments, 1) : [];
  470.             if (h[n]) {
  471.                 return h[n].apply(null, t)
  472.             } else {
  473.                 return h.aggregate.call(null, n)
  474.             }
  475.         };
  476.         n[m].settings = {
  477.             resizeThrottle: 100,
  478.             scrollThrottle: 30
  479.         };
  480.         return i.load(function() {
  481.             return n[m]("refresh")
  482.         })
  483.     })
  484. }).call(this);
Add Comment
Please, Sign In to add comment