From f078b8e5d94f959ac36dc17a15807ced07178faa Mon Sep 17 00:00:00 2001 From: imakewebthings Date: Wed, 14 May 2014 18:38:50 -0700 Subject: [PATCH 01/98] Directory restructuring --- Makefile | 17 - README.markdown => README.md | 0 bower.json | 19 -- examples/dial-controls/index.html | 292 ------------------ examples/scroll-analytics/index.html | 269 ---------------- .../waypoints-infinite.js | 0 .../waypoints-sticky.js | 0 waypoints.js => lib/waypoints.js | 0 .../infinite-scroll/waypoints-infinite.min.js | 8 - .../sticky-elements/waypoints-sticky.min.js | 8 - .../shortcuts}/infinite-scroll/index.html | 0 .../infinite-scroll/waypoints-infinite.coffee | 0 .../shortcuts}/sticky-elements/index.html | 0 .../sticky-elements/waypoints-sticky.coffee | 0 waypoints.coffee => src/waypoints.coffee | 0 waypoints.min.js | 8 - 16 files changed, 621 deletions(-) delete mode 100644 Makefile rename README.markdown => README.md (100%) delete mode 100644 bower.json delete mode 100644 examples/dial-controls/index.html delete mode 100644 examples/scroll-analytics/index.html rename {shortcuts/infinite-scroll => lib}/waypoints-infinite.js (100%) rename {shortcuts/sticky-elements => lib}/waypoints-sticky.js (100%) rename waypoints.js => lib/waypoints.js (100%) delete mode 100644 shortcuts/infinite-scroll/waypoints-infinite.min.js delete mode 100644 shortcuts/sticky-elements/waypoints-sticky.min.js rename {shortcuts => src/shortcuts}/infinite-scroll/index.html (100%) rename {shortcuts => src/shortcuts}/infinite-scroll/waypoints-infinite.coffee (100%) rename {shortcuts => src/shortcuts}/sticky-elements/index.html (100%) rename {shortcuts => src/shortcuts}/sticky-elements/waypoints-sticky.coffee (100%) rename waypoints.coffee => src/waypoints.coffee (100%) delete mode 100644 waypoints.min.js diff --git a/Makefile b/Makefile deleted file mode 100644 index 1513ef4a..00000000 --- a/Makefile +++ /dev/null @@ -1,17 +0,0 @@ -COFFEE = ./node_modules/coffee-script/bin/coffee -UGLIFY = ./node_modules/uglify-js/bin/uglifyjs - -setup: - npm install - -build: compile minify - -compile: - $(COFFEE) --compile waypoints.coffee shortcuts/*/*.coffee - -minify: - $(UGLIFY) -m --comments all -o waypoints.min.js waypoints.js - $(UGLIFY) -m --comments all -o shortcuts/infinite-scroll/waypoints-infinite.min.js shortcuts/infinite-scroll/waypoints-infinite.js - $(UGLIFY) -m --comments all -o shortcuts/sticky-elements/waypoints-sticky.min.js shortcuts/sticky-elements/waypoints-sticky.js - -.PHONY: setup build compile minify \ No newline at end of file diff --git a/README.markdown b/README.md similarity index 100% rename from README.markdown rename to README.md diff --git a/bower.json b/bower.json deleted file mode 100644 index 340f185e..00000000 --- a/bower.json +++ /dev/null @@ -1,19 +0,0 @@ -{ - "name": "jquery-waypoints", - "version": "2.0.5", - "main": "waypoints.js", - "description": "A jQuery plugin that makes it easy to execute a function whenever you scroll to an element.", - "ignore": [ - "**/.*", - "**/*.coffee", - "**/*.html", - "bower_components", - "examples", - "node_modules", - "Makefile", - "test" - ], - "dependencies": { - "jquery" : ">=1.8" - } -} diff --git a/examples/dial-controls/index.html b/examples/dial-controls/index.html deleted file mode 100644 index c59ce717..00000000 --- a/examples/dial-controls/index.html +++ /dev/null @@ -1,292 +0,0 @@ - - - - - - Dial Controls with jQuery Waypoints - - - - - - - - -
-

jQuery Waypoints

-

Dial Controls

-
- -
-
-
-

Font Size:

-
    -
  • 8px
  • -
  • 9px
  • -
  • 10px
  • -
  • 11px
  • -
  • 12px
  • -
  • 13px
  • -
  • 14px
  • -
-
-
- -
-

Line Height:

-
    -
  • .75
  • -
  • 1.0
  • -
  • 1.25
  • -
  • 1.5
  • -
  • 1.75
  • -
  • 2.0
  • -
  • 2.25
  • -
  • 2.5
  • -
-
-
- -
-

Text Color:

-
    -
  • #000
  • -
  • #222
  • -
  • #444
  • -
  • #666
  • -
  • #888
  • -
  • #aaa
  • -
-
-
-
- -
$('.dial li').waypoint( function(direction) {
-  var $active = $(this);
-  var property, value;
-
-  /* The waypoint is triggered at the top of each list item representing a dial section. When triggering in the down direction we want to use the dial section the waypoint is attached to. But in the up direction we want to use the previous dial section. */
-  if (direction === "up") {
-    $active = $active.prev();
-  }
-
-  /* If we triggered in the up direction and the result from 'prev' came back with an empty set of elements, it means we were on the first element in the list, and we should just use the original element. */
-  if (!$active.length) {
-    $active = $(this);
-  }
-
-  /* The property the dial controls is a data attribute on the ul. */
-  property = $active.closest('.dial').data('property');
-
-  /* The value for that property is a data attribute on each li. */
-  value = $active.data('value');
-	
-  $('#example-target').css(property, value);
-}, {
-  context: 'ul' // Make the scroll context the nearest ul.
-});
-
- - - - - - - - diff --git a/examples/scroll-analytics/index.html b/examples/scroll-analytics/index.html deleted file mode 100644 index 4fa9a1df..00000000 --- a/examples/scroll-analytics/index.html +++ /dev/null @@ -1,269 +0,0 @@ - - - - - - Scroll Analytics with jQuery Waypoints - - - - - - - - -
-

jQuery Waypoints

-

Scroll Analytics

-
- -
-
-

Lorem Ipsum

- -

Lorem ipsum dolor sit amet, consectetur adipiscing elit. Ut mi eros, commodo vel porttitor vitae, facilisis eu quam. Suspendisse elementum nibh vel velit bibendum vitae accumsan sem pellentesque. Aliquam quis nisl in felis elementum facilisis. Suspendisse potenti. Suspendisse vel ligula erat, mollis sagittis tortor. Vestibulum lobortis rutrum sapien, id sodales leo hendrerit in. Nullam at risus et lectus mattis elementum. Aliquam porta dignissim leo id iaculis. Donec id magna turpis. Morbi convallis lacus gravida velit condimentum suscipit. Nunc dui ipsum, congue sit amet euismod in, aliquet quis mauris. Mauris quis libero a diam egestas gravida. Phasellus bibendum, sem quis vulputate consectetur, quam nulla feugiat sem, eu sodales mi velit a tellus.

- -

Sed posuere pellentesque consequat. Cum sociis natoque penatibus et magnis dis parturient montes, nascetur ridiculus mus. Ut non faucibus lorem. Curabitur condimentum viverra lorem, eu suscipit mi vehicula ac. Mauris mattis, purus at vehicula ultricies, dolor quam tempus eros, in eleifend neque nulla at urna. Duis consequat faucibus pellentesque. Nulla facilisi. Maecenas id pellentesque sapien. Sed lobortis lectus vel nibh semper placerat. Pellentesque non diam lectus.

- -

Suspendisse pellentesque tempor est a cursus. Aliquam molestie, neque vitae ullamcorper dictum, velit mi varius justo, id blandit mauris dui a felis. Curabitur tortor arcu, ornare in tempor sit amet, varius ac elit. Nullam eleifend cursus consectetur.

- -
I’m an ad! (ID:8675309)
- -

Proin enim odio, vulputate non lacinia ut, iaculis et nisl. Sed bibendum, nulla vitae vestibulum tempor, urna nisi ullamcorper tortor, ut lacinia elit sapien sit amet metus. Duis congue sollicitudin elit, egestas porta ante pharetra id. Fusce dictum fermentum eros vitae interdum. In a justo nunc. Phasellus vel mi ante. Vestibulum ante ipsum primis in faucibus orci luctus et ultrices posuere cubilia Curae; Vivamus ac turpis in mauris posuere eleifend.

- -

Praesent congue vehicula laoreet. Pellentesque quis purus et felis condimentum suscipit.

- -

Nulla ultrices pulvinar quam, et hendrerit turpis rutrum nec. Maecenas tortor ligula, ultricies eget sagittis fringilla, malesuada eu risus. Class aptent taciti sociosqu ad litora torquent per conubia nostra, per inceptos himenaeos. Curabitur tempor, eros et aliquet congue, nunc nunc accumsan leo, sit amet ultrices magna sapien sit amet libero. Nunc iaculis diam non odio imperdiet nec aliquam sapien aliquet. Donec vulputate mi nec metus vehicula nec pretium orci accumsan. Cras non ante metus, eu interdum nulla. Morbi porttitor commodo varius. Integer vel nisi sit amet enim pellentesque convallis.

- -

Sed vitae libero sem. Morbi vel tincidunt libero. Quisque suscipit adipiscing mauris eget vestibulum. Mauris euismod ante nec felis varius ultricies. Nam lacinia blandit hendrerit. Sed mattis tortor vitae tellus sodales tincidunt. Nulla tellus eros, fringilla nec posuere tincidunt, semper a odio. Mauris justo neque, placerat ac dictum lobortis, tempor vel arcu. Quisque a mi at lacus vestibulum placerat a eu leo. Sed pharetra metus vitae nisi molestie aliquam. Curabitur feugiat aliquet lorem et suscipit.

- -
I’m an ad! (ID:5551234)
- -

Fusce tincidunt tincidunt elit vitae pulvinar. Ut id magna ut massa faucibus vehicula. Nunc rutrum eros quis nunc hendrerit porta. Nullam porttitor eleifend mauris, eget interdum velit rutrum egestas. Sed iaculis eros at mauris ultricies fermentum. Duis nec nunc ut leo cursus luctus eget ac nisl. Sed condimentum euismod nulla, ut auctor lectus fringilla sit amet. Proin ac magna eros, nec euismod nibh. Integer tellus velit, accumsan ut vulputate quis, vehicula sit amet urna. Aliquam ornare libero vitae ipsum pellentesque quis consequat mi varius. Aliquam a urna a nunc tristique volutpat. Nulla eu mi sit amet dolor dapibus bibendum. Aenean commodo, enim non tristique ultrices, nisi dolor rhoncus metus, ac porta tortor felis at quam. Donec a dui felis. Etiam id aliquam tortor.

- -

Suspendisse a rutrum purus.

- -

Pellentesque habitant morbi tristique senectus et netus et malesuada fames ac turpis egestas. Donec in quam metus, sed pharetra nisi. Nunc lacinia arcu eget eros molestie blandit.

- -

Ut at sem ut nibh molestie tempus. Nunc volutpat malesuada massa, vel auctor odio consequat consectetur. Suspendisse scelerisque nunc non quam suscipit vestibulum. Aliquam eu turpis sem, non ultrices tellus. Pellentesque vel velit lectus, a imperdiet arcu. Vivamus et turpis in libero consectetur gravida non id massa. Morbi ut urna mi. Phasellus pellentesque congue porttitor.

- -

Vivamus eu dolor urna, vel malesuada orci. Vivamus pellentesque tellus non tortor scelerisque consequat. Pellentesque habitant morbi tristique senectus et netus et malesuada fames ac turpis egestas. Pellentesque lacinia nibh consequat purus lobortis pretium. Sed lobortis fringilla auctor. Aliquam erat volutpat. Maecenas mollis lorem quis mauris pharetra non posuere dui luctus.

- -

Fusce tempor magna et metus rutrum volutpat. In pellentesque enim nec augue pretium egestas. Pellentesque viverra mauris eget enim rutrum sagittis vulputate ligula lobortis. Integer bibendum porttitor turpis at adipiscing. Nulla vulputate, ligula id adipiscing pharetra, lectus magna varius elit.

- -

A feugiat nisi nulla ut lorem. Etiam eu dui vitae erat molestie dignissim lacinia ac quam. Cras bibendum consequat risus sed tristique. Morbi mattis ultrices eros id iaculis. Maecenas vel euismod tellus. Aenean aliquet rhoncus quam ut gravida. Sed faucibus metus tellus, vitae suscipit neque. Morbi et odio vitae sem tempor eleifend. Praesent sagittis, magna sit amet commodo convallis, nibh lectus blandit sapien, vel congue lorem purus vitae magna. Curabitur velit metus, lacinia eu rhoncus at, facilisis eget est. Curabitur metus augue, ultricies id vehicula eget, tempor dignissim ipsum.

-
- -
-
I’m an ad! (ID:21)
- -

Related Posts

-
    -
  • Lorem
  • -
  • Lorem
  • -
  • Lorem
  • -
  • Lorem
  • -
  • Lorem
  • -
  • Lorem
  • -
  • Lorem
  • -
  • Lorem
  • -
  • Lorem
  • -
  • Lorem
  • -
  • Lorem
  • -
  • Lorem
  • -
  • Lorem
  • -
  • Lorem
  • -
- -

A feugiat nisi nulla ut lorem. Etiam eu dui vitae erat molestie dignissim lacinia ac quam. Cras bibendum consequat risus sed tristique. Morbi mattis ultrices eros id iaculis. Maecenas vel euismod tellus. Aenean aliquet rhoncus quam ut gravida. Sed faucibus metus tellus, vitae suscipit neque. Morbi et odio vitae sem tempor eleifend. Praesent sagittis, magna sit amet commodo convallis, nibh lectus blandit sapien, vel congue lorem purus vitae magna. Curabitur velit metus, lacinia eu rhoncus at, facilisis eget est. Curabitur metus augue, ultricies id vehicula eget, tempor dignissim ipsum.

- -
I’m an ad! (ID:12345)
-
-
- - - - - - - - \ No newline at end of file diff --git a/shortcuts/infinite-scroll/waypoints-infinite.js b/lib/waypoints-infinite.js similarity index 100% rename from shortcuts/infinite-scroll/waypoints-infinite.js rename to lib/waypoints-infinite.js diff --git a/shortcuts/sticky-elements/waypoints-sticky.js b/lib/waypoints-sticky.js similarity index 100% rename from shortcuts/sticky-elements/waypoints-sticky.js rename to lib/waypoints-sticky.js diff --git a/waypoints.js b/lib/waypoints.js similarity index 100% rename from waypoints.js rename to lib/waypoints.js diff --git a/shortcuts/infinite-scroll/waypoints-infinite.min.js b/shortcuts/infinite-scroll/waypoints-infinite.min.js deleted file mode 100644 index 006f4f02..00000000 --- a/shortcuts/infinite-scroll/waypoints-infinite.min.js +++ /dev/null @@ -1,8 +0,0 @@ -// Generated by CoffeeScript 1.6.2 -/* -Infinite Scroll Shortcut for jQuery Waypoints - v2.0.5 -Copyright (c) 2011-2014 Caleb Troughton -Licensed under the MIT license. -https://github.com/imakewebthings/jquery-waypoints/blob/master/licenses.txt -*/ -(function(){(function(n,e){if(typeof define==="function"&&define.amd){return define(["jquery","waypoints"],e)}else{return e(n.jQuery)}})(window,function(n){var e;e={container:"auto",items:".infinite-item",more:".infinite-more-link",offset:"bottom-in-view",loadingClass:"infinite-loading",onBeforePageLoad:n.noop,onAfterPageLoad:n.noop};return n.waypoints("extendFn","infinite",function(t){var i,o;o=n.extend({},n.fn.waypoint.defaults,e,t);if(n(o.more).length===0){return this}i=o.container==="auto"?this:n(o.container);o.handler=function(e){var t;if(e==="down"||e==="right"){t=n(this);o.onBeforePageLoad();t.waypoint("destroy");i.addClass(o.loadingClass);return n.get(n(o.more).attr("href"),function(e){var r,a,f,s;r=n(n.parseHTML(e));a=n(o.more);f=r.find(o.more);i.append(r.find(o.items));i.removeClass(o.loadingClass);if(f.length){a.replaceWith(f);s=function(){return t.waypoint(o)};setTimeout(s,0)}else{a.remove()}return o.onAfterPageLoad()})}};return this.waypoint(o)})})}).call(this); \ No newline at end of file diff --git a/shortcuts/sticky-elements/waypoints-sticky.min.js b/shortcuts/sticky-elements/waypoints-sticky.min.js deleted file mode 100644 index c3d01d36..00000000 --- a/shortcuts/sticky-elements/waypoints-sticky.min.js +++ /dev/null @@ -1,8 +0,0 @@ -// Generated by CoffeeScript 1.6.2 -/* -Sticky Elements Shortcut for jQuery Waypoints - v2.0.5 -Copyright (c) 2011-2014 Caleb Troughton -Licensed under the MIT license. -https://github.com/imakewebthings/jquery-waypoints/blob/master/licenses.txt -*/ -(function(){(function(t,n){if(typeof define==="function"&&define.amd){return define(["jquery","waypoints"],n)}else{return n(t.jQuery)}})(window,function(t){var n,i;n={wrapper:'
',stuckClass:"stuck",direction:"down right"};i=function(t,n){var i;t.wrap(n.wrapper);i=t.parent();return i.data("isWaypointStickyWrapper",true)};t.waypoints("extendFn","sticky",function(r){var e,a,s;a=t.extend({},t.fn.waypoint.defaults,n,r);e=i(this,a);s=a.handler;a.handler=function(n){var i,r;i=t(this).children(":first");r=a.direction.indexOf(n)!==-1;i.toggleClass(a.stuckClass,r);e.height(r?i.outerHeight():"");if(s!=null){return s.call(this,n)}};e.waypoint(a);return this.data("stuckClass",a.stuckClass)});return t.waypoints("extendFn","unsticky",function(){var t;t=this.parent();if(!t.data("isWaypointStickyWrapper")){return this}t.waypoint("destroy");this.unwrap();return this.removeClass(this.data("stuckClass"))})})}).call(this); \ No newline at end of file diff --git a/shortcuts/infinite-scroll/index.html b/src/shortcuts/infinite-scroll/index.html similarity index 100% rename from shortcuts/infinite-scroll/index.html rename to src/shortcuts/infinite-scroll/index.html diff --git a/shortcuts/infinite-scroll/waypoints-infinite.coffee b/src/shortcuts/infinite-scroll/waypoints-infinite.coffee similarity index 100% rename from shortcuts/infinite-scroll/waypoints-infinite.coffee rename to src/shortcuts/infinite-scroll/waypoints-infinite.coffee diff --git a/shortcuts/sticky-elements/index.html b/src/shortcuts/sticky-elements/index.html similarity index 100% rename from shortcuts/sticky-elements/index.html rename to src/shortcuts/sticky-elements/index.html diff --git a/shortcuts/sticky-elements/waypoints-sticky.coffee b/src/shortcuts/sticky-elements/waypoints-sticky.coffee similarity index 100% rename from shortcuts/sticky-elements/waypoints-sticky.coffee rename to src/shortcuts/sticky-elements/waypoints-sticky.coffee diff --git a/waypoints.coffee b/src/waypoints.coffee similarity index 100% rename from waypoints.coffee rename to src/waypoints.coffee diff --git a/waypoints.min.js b/waypoints.min.js deleted file mode 100644 index b9098f82..00000000 --- a/waypoints.min.js +++ /dev/null @@ -1,8 +0,0 @@ -// Generated by CoffeeScript 1.6.2 -/*! -jQuery Waypoints - v2.0.5 -Copyright (c) 2011-2014 Caleb Troughton -Licensed under the MIT license. -https://github.com/imakewebthings/jquery-waypoints/blob/master/licenses.txt -*/ -(function(){var t=[].indexOf||function(t){for(var e=0,n=this.length;e=0;s={horizontal:{},vertical:{}};f=1;c={};u="waypoints-context-id";p="resize.waypoints";y="scroll.waypoints";v=1;w="waypoints-waypoint-ids";g="waypoint";m="waypoints";o=function(){function t(t){var e=this;this.$element=t;this.element=t[0];this.didResize=false;this.didScroll=false;this.id="context"+f++;this.oldScroll={x:t.scrollLeft(),y:t.scrollTop()};this.waypoints={horizontal:{},vertical:{}};this.element[u]=this.id;c[this.id]=this;t.bind(y,function(){var t;if(!(e.didScroll||a)){e.didScroll=true;t=function(){e.doScroll();return e.didScroll=false};return r.setTimeout(t,n[m].settings.scrollThrottle)}});t.bind(p,function(){var t;if(!e.didResize){e.didResize=true;t=function(){n[m]("refresh");return e.didResize=false};return r.setTimeout(t,n[m].settings.resizeThrottle)}})}t.prototype.doScroll=function(){var t,e=this;t={horizontal:{newScroll:this.$element.scrollLeft(),oldScroll:this.oldScroll.x,forward:"right",backward:"left"},vertical:{newScroll:this.$element.scrollTop(),oldScroll:this.oldScroll.y,forward:"down",backward:"up"}};if(a&&(!t.vertical.oldScroll||!t.vertical.newScroll)){n[m]("refresh")}n.each(t,function(t,r){var i,o,l;l=[];o=r.newScroll>r.oldScroll;i=o?r.forward:r.backward;n.each(e.waypoints[t],function(t,e){var n,i;if(r.oldScroll<(n=e.offset)&&n<=r.newScroll){return l.push(e)}else if(r.newScroll<(i=e.offset)&&i<=r.oldScroll){return l.push(e)}});l.sort(function(t,e){return t.offset-e.offset});if(!o){l.reverse()}return n.each(l,function(t,e){if(e.options.continuous||t===l.length-1){return e.trigger([i])}})});return this.oldScroll={x:t.horizontal.newScroll,y:t.vertical.newScroll}};t.prototype.refresh=function(){var t,e,r,i=this;r=n.isWindow(this.element);e=this.$element.offset();this.doScroll();t={horizontal:{contextOffset:r?0:e.left,contextScroll:r?0:this.oldScroll.x,contextDimension:this.$element.width(),oldScroll:this.oldScroll.x,forward:"right",backward:"left",offsetProp:"left"},vertical:{contextOffset:r?0:e.top,contextScroll:r?0:this.oldScroll.y,contextDimension:r?n[m]("viewportHeight"):this.$element.height(),oldScroll:this.oldScroll.y,forward:"down",backward:"up",offsetProp:"top"}};return n.each(t,function(t,e){return n.each(i.waypoints[t],function(t,r){var i,o,l,s,f;i=r.options.offset;l=r.offset;o=n.isWindow(r.element)?0:r.$element.offset()[e.offsetProp];if(n.isFunction(i)){i=i.apply(r.element)}else if(typeof i==="string"){i=parseFloat(i);if(r.options.offset.indexOf("%")>-1){i=Math.ceil(e.contextDimension*i/100)}}r.offset=o-e.contextOffset+e.contextScroll-i;if(r.options.onlyOnScroll&&l!=null||!r.enabled){return}if(l!==null&&l<(s=e.oldScroll)&&s<=r.offset){return r.trigger([e.backward])}else if(l!==null&&l>(f=e.oldScroll)&&f>=r.offset){return r.trigger([e.forward])}else if(l===null&&e.oldScroll>=r.offset){return r.trigger([e.forward])}})})};t.prototype.checkEmpty=function(){if(n.isEmptyObject(this.waypoints.horizontal)&&n.isEmptyObject(this.waypoints.vertical)){this.$element.unbind([p,y].join(" "));return delete c[this.id]}};return t}();l=function(){function t(t,e,r){var i,o;if(r.offset==="bottom-in-view"){r.offset=function(){var t;t=n[m]("viewportHeight");if(!n.isWindow(e.element)){t=e.$element.height()}return t-n(this).outerHeight()}}this.$element=t;this.element=t[0];this.axis=r.horizontal?"horizontal":"vertical";this.callback=r.handler;this.context=e;this.enabled=r.enabled;this.id="waypoints"+v++;this.offset=null;this.options=r;e.waypoints[this.axis][this.id]=this;s[this.axis][this.id]=this;i=(o=this.element[w])!=null?o:[];i.push(this.id);this.element[w]=i}t.prototype.trigger=function(t){if(!this.enabled){return}if(this.callback!=null){this.callback.apply(this.element,t)}if(this.options.triggerOnce){return this.destroy()}};t.prototype.disable=function(){return this.enabled=false};t.prototype.enable=function(){this.context.refresh();return this.enabled=true};t.prototype.destroy=function(){delete s[this.axis][this.id];delete this.context.waypoints[this.axis][this.id];return this.context.checkEmpty()};t.getWaypointsByElement=function(t){var e,r;r=t[w];if(!r){return[]}e=n.extend({},s.horizontal,s.vertical);return n.map(r,function(t){return e[t]})};return t}();d={init:function(t,e){var r;e=n.extend({},n.fn[g].defaults,e);if((r=e.handler)==null){e.handler=t}this.each(function(){var t,r,i,s;t=n(this);i=(s=e.context)!=null?s:n.fn[g].defaults.context;if(!n.isWindow(i)){i=t.closest(i)}i=n(i);r=c[i[0][u]];if(!r){r=new o(i)}return new l(t,r,e)});n[m]("refresh");return this},disable:function(){return d._invoke.call(this,"disable")},enable:function(){return d._invoke.call(this,"enable")},destroy:function(){return d._invoke.call(this,"destroy")},prev:function(t,e){return d._traverse.call(this,t,e,function(t,e,n){if(e>0){return t.push(n[e-1])}})},next:function(t,e){return d._traverse.call(this,t,e,function(t,e,n){if(e<=t.oldScroll.y})},below:function(t){if(t==null){t=r}return h._filter(t,"vertical",function(t,e){return e.offset>t.oldScroll.y})},left:function(t){if(t==null){t=r}return h._filter(t,"horizontal",function(t,e){return e.offset<=t.oldScroll.x})},right:function(t){if(t==null){t=r}return h._filter(t,"horizontal",function(t,e){return e.offset>t.oldScroll.x})},enable:function(){return h._invoke("enable")},disable:function(){return h._invoke("disable")},destroy:function(){return h._invoke("destroy")},extendFn:function(t,e){return d[t]=e},_invoke:function(t){var e;e=n.extend({},s.vertical,s.horizontal);return n.each(e,function(e,n){n[t]();return true})},_filter:function(t,e,r){var i,o;i=c[n(t)[0][u]];if(!i){return[]}o=[];n.each(i.waypoints[e],function(t,e){if(r(i,e)){return o.push(e)}});o.sort(function(t,e){return t.offset-e.offset});return n.map(o,function(t){return t.element})}};n[m]=function(){var t,n;n=arguments[0],t=2<=arguments.length?e.call(arguments,1):[];if(h[n]){return h[n].apply(null,t)}else{return h.aggregate.call(null,n)}};n[m].settings={resizeThrottle:100,scrollThrottle:30};return i.on("load.waypoints",function(){return n[m]("refresh")})})}).call(this); \ No newline at end of file From b4076e6f4b318e52a843646543b6f5bd9fb088f2 Mon Sep 17 00:00:00 2001 From: imakewebthings Date: Sat, 17 May 2014 13:09:52 -0700 Subject: [PATCH 02/98] Move to testem without CoffeeScript --- .gitignore | 3 +- bower.json | 9 + gulpfile.js | 12 + package.json | 9 +- test/fixtures/standard.html | 86 ++-- test/index.html | 58 ++- test/settings.js | 1 + test/waypoints-spec.js | 828 ++++++++++++++++++++++++++++++++++++ testem.json | 18 + 9 files changed, 957 insertions(+), 67 deletions(-) create mode 100644 bower.json create mode 100644 gulpfile.js create mode 100644 test/settings.js create mode 100644 test/waypoints-spec.js create mode 100644 testem.json diff --git a/.gitignore b/.gitignore index 23246a9e..9e539ac7 100644 --- a/.gitignore +++ b/.gitignore @@ -2,4 +2,5 @@ .DS_Store /style.scss *.gz -node_modules \ No newline at end of file +node_modules +bower_components diff --git a/bower.json b/bower.json new file mode 100644 index 00000000..1b5d872a --- /dev/null +++ b/bower.json @@ -0,0 +1,9 @@ +{ + "name": "waypoints", + "private": true, + "devDependencies": { + "jquery": "~1.11.1", + "lodash": "~2.4.1", + "jasmine-jquery": "~1.7.0" + } +} diff --git a/gulpfile.js b/gulpfile.js new file mode 100644 index 00000000..610b2eaa --- /dev/null +++ b/gulpfile.js @@ -0,0 +1,12 @@ +var gulp = require('gulp') +var mochaPhantomJS = require('gulp-mocha-phantomjs') + +gulp.task('test', function() { + return gulp.src('test/index.html').pipe(mochaPhantomJS({ + reporter: 'tap' + })) +}) + +gulp.task('watch-test', function() { + gulp.watch(['lib/**', 'test/**'], ['test']) +}) diff --git a/package.json b/package.json index e184938a..ead9dd04 100644 --- a/package.json +++ b/package.json @@ -3,6 +3,10 @@ "version": "2.0.5", "author": "Caleb Troughton ", "description": "A jQuery plugin that makes it easy to execute a function whenever you scroll to an element.", + "scripts": { + "test": "testem ci", + "tdd": "testem" + }, "repository": { "type": "git", "url": "https://github.com/imakewebthings/jquery-waypoints.git" @@ -12,8 +16,7 @@ "scroll" ], "devDependencies": { - "coffee-script": "1.6.2", - "uglify-js" : "2.2.5" - }, + "gulp": "^3.6.2" + }, "license": "MIT" } diff --git a/test/fixtures/standard.html b/test/fixtures/standard.html index 7dbdb829..ec52c039 100644 --- a/test/fixtures/standard.html +++ b/test/fixtures/standard.html @@ -1,79 +1,79 @@
-
-
-
-
-
-
-
-
-
-
-
-
-
+
+
+
+
+
+
+
+
+
+
+
+
+
\ No newline at end of file + diff --git a/test/index.html b/test/index.html index 496ef7e4..046df371 100644 --- a/test/index.html +++ b/test/index.html @@ -1,26 +1,44 @@ - + - Jasmine Test Runner - - - - - - - + + + +Waypoints Test Runner (Mocha) + + + - - - - + +
- - - + + + + + + + + + + - + diff --git a/test/settings.js b/test/settings.js new file mode 100644 index 00000000..ac9582ba --- /dev/null +++ b/test/settings.js @@ -0,0 +1 @@ +jasmine.getFixtures().fixturesPath = 'test/fixtures' diff --git a/test/waypoints-spec.js b/test/waypoints-spec.js new file mode 100644 index 00000000..495877ee --- /dev/null +++ b/test/waypoints-spec.js @@ -0,0 +1,828 @@ +describe('jQuery Waypoints', function() { + var standard = 50 + var hit, $scroller, $target, $return = null + + function setHitTrue() { + hit = true + } + + beforeEach(function() { + loadFixtures('standard.html') + $scroller = $(window) + hit = false + }) + + afterEach(function() { + $.waypoints('destroy') + $scroller.scrollTop(0).scrollLeft(0) + waits(standard) + }) + + describe('#waypoint()', function() { + it ('errors out', function() { + expect(function() { + $('#same1').waypoint() + }).toThrow() + }) + }) + + describe('#waypoint(callback)', function() { + var currentDirection + + beforeEach(function() { + currentDirection = null + $target = $('#same1').waypoint(function(direction) { + currentDirection = direction + hit = true + }) + }) + + it('creates a waypoint', function() { + expect($.waypoints().vertical.length).toEqual(1) + }) + + it('triggers the callback', function() { + runs(function() { + $scroller.scrollTop($target.offset().top) + }) + waitsFor(function() { + return hit + }, 'callback to trigger') + }) + + it('uses the default offset', function(done) { + runs(function() { + $scroller.scrollTop($target.offset().top - 1) + }) + waits(standard) + runs(function() { + expect(hit).toBeFalsy() + $scroller.scrollTop($target.offset().top) + }) + waitsFor(function() { + return hit + }, 'callback to trigger') + }) + + it('passes correct directions', function() { + runs(function() { + $scroller.scrollTop($target.offset().top) + }) + waitsFor(function() { + return currentDirection === 'down' + }, 'down to trigger') + runs(function() { + $scroller.scrollTop($target.offset().top - 1) + }) + waitsFor(function() { + return currentDirection === 'up' + }, 'up to trigger') + }) + }) + + describe('#waypoint(options)', function() { + beforeEach(function() { + $target = $('#same1') + }) + + it('creates a waypoint', function() { + $target.waypoint({ triggerOnce: true }) + expect($.waypoints().vertical.length).toEqual(1) + }) + + it('respects a px offset', function() { + runs(function() { + $target.waypoint({ + offset: 50, + handler: setHitTrue + }) + $scroller.scrollTop($target.offset().top - 51) + }) + waits(standard) + runs(function() { + expect(hit).toBeFalsy() + $scroller.scrollTop($target.offset().top - 50) + }) + waitsFor(function() { + return hit + }, 'callback to trigger') + }) + + it('respects a % offset', function() { + var trigger = $target.offset().top - $.waypoints('viewportHeight') * .37 + runs(function() { + $target.waypoint({ + offset: '37%', + handler: setHitTrue + }) + $scroller.scrollTop(trigger - 1) + }) + waits(standard) + runs(function() { + expect(hit).toBeFalsy() + $scroller.scrollTop(trigger) + }) + waitsFor(function() { + return hit + }, 'callback to trigger') + }) + + it('respects a function offset', function() { + runs(function() { + $target.waypoint({ + offset: function() { + return -$(this).height() + }, + handler: setHitTrue + }) + $scroller.scrollTop($target.offset().top + $target.height() - 1) + }) + waits(standard) + runs(function() { + expect(hit).toBeFalsy() + $scroller.scrollTop($target.offset().top + $target.height()) + }) + waitsFor(function() { + return hit + }, 'callback to trigger') + }) + + it('respects the botton-in-view function alias', function() { + var top = $target.offset().top + var height = $target.outerHeight() + var windowHeight = $.waypoints('viewportHeight') + var inview = top + height - windowHeight + runs(function() { + $target.waypoint({ + offset: 'bottom-in-view', + handler: setHitTrue + }) + $scroller.scrollTop(inview - 1) + }) + waits(standard) + runs(function() { + expect(hit).toBeFalsy() + $scroller.scrollTop(inview) + }) + waitsFor(function() { + return hit + }, 'callback to trigger') + }) + + it('destroys the waypoint if triggerOnce is true', function() { + runs(function() { + $target.waypoint({ + triggerOnce: true + }) + $scroller.scrollTop($target.offset().top) + }) + waitsFor(function() { + return !$.waypoints().vertical.length + }, 'waypoint to be destroyed') + }) + + it('triggers if continuous is true and waypoint is not last', function() { + var $near1 = $('#near1') + var $near2 = $('#near2') + var hitcount = 0 + runs(function() { + $target.add($near1).add($near2).waypoint(function() { + hitcount += 1 + }) + $scroller.scrollTop($near2.offset().top) + }) + waitsFor(function() { + return hitcount === 3 + }, 'all waypoints to trigger') + }) + + it('does not trigger if continuous false, waypoint not last', function() { + var $near1 = $('#near1') + var $near2 = $('#near2') + var hitcount = 0 + runs(function() { + var callback = function() { + hitcount += 1 + } + $target.add($near2).waypoint(callback) + $near1.waypoint(callback, { + continuous: false + }) + $scroller.scrollTop($near2.offset().top) + }) + waitsFor(function() { + return hitcount === 2 + }, 'all waypoints to trigger') + }) + + it('triggers if continuous false, waypoint is last', function() { + var $near1 = $('#near1') + var $near2 = $('#near2') + var hitcount = 0 + runs(function() { + var callback = function() { + hitcount += 1 + } + $target.add($near1).waypoint(callback) + $near2.waypoint(callback, { + continuous: false + }) + $scroller.scrollTop($near2.offset().top) + }) + waitsFor(function() { + return hitcount === 3 + }, 'all waypoints to trigger') + }) + }) + + describe('#waypoint(callback, options)', function() { + beforeEach(function() { + $target = $('#same1').waypoint(setHitTrue, { + offset: -1 + }) + }) + + it('creates a waypoint', function() { + expect($.waypoints().vertical.length).toEqual(1) + }) + + it('respects options', function() { + runs(function() { + $scroller.scrollTop($target.offset().top) + }) + waits(standard) + runs(function() { + expect(hit).toBeFalsy() + $scroller.scrollTop($target.offset().top + 1) + }) + waitsFor(function() { + return hit + }, 'callback to trigger') + }) + }) + + describe('#waypoint("disable")', function() { + beforeEach(function() { + $target = $('#same1').waypoint(setHitTrue) + $return = $target.waypoint('disable') + }) + + it('disables callback triggers', function() { + runs(function() { + $scroller.scrollTop($target.offset().top) + }) + waits(standard) + runs(function() { + expect(hit).toBeFalsy() + }) + }) + + it('returns the same jQuery object for chaining', function() { + expect($return.get()).toEqual($target.get()) + }) + }) + + describe('#waypoint("enable")', function() { + beforeEach(function() { + $target = $('#same1').waypoint(setHitTrue) + $target.waypoint('disable') + $return = $target.waypoint('enable') + }) + + it('enables callback triggers', function() { + runs(function() { + $scroller.scrollTop($target.offset().top) + }) + waitsFor(function() { + return hit + }, 'callback to trigger') + }) + + it('returns the same jQuery object for chaining', function() { + expect($return.get()).toEqual($target.get()) + }) + }) + + describe('#waypoint("destroy")', function() { + beforeEach(function() { + $target = $('#same1').waypoint(setHitTrue) + $return = $target.waypoint('destroy') + }) + + it('removes waypoint from list of waypoints', function() { + expect($.waypoints().vertical.length).toEqual(0) + }) + + it('no longer triggers callback', function() { + runs(function() { + $scroller.scrollTop($target.offset().top) + }) + waits(standard) + runs(function() { + expect(hit).toBeFalsy() + }) + }) + + it('does not preserve callbacks if .waypoint recalled', function() { + runs(function() { + $target.waypoint({}) + $scroller.scrollTop($target.offset().top) + }) + waits(standard) + runs(function() { + expect(hit).toBeFalsy() + }) + }) + + it('returns the same jQuery object for chaining', function() { + expect($return.get()).toEqual($target.get()) + }) + + it('unregisters waypoint even if underlying nodes are removed', function() { + $target.remove() + $target.waypoint('destroy') + expect($.waypoints().vertical.length).toEqual(0) + }) + }) + + describe('#waypoint("prev")', function() { + it('returns jQuery object container previous waypoint', function() { + var $near = $('#near1') + $target = $('#same1') + $target.add($near).waypoint({}) + expect($near.waypoint('prev')[0]).toEqual($target[0]) + }) + + it('can be used in a non-window context', function() { + var $near = $('#inner2') + $target = $('#inner1') + $target.add($near).waypoint({}) + expect($near.waypoint('prev')[0]).toEqual($target[0]) + }) + }) + + describe('#waypoint("next")', function() { + it('returns jQuery object containing next waypoint', function() { + var $near = $('#near1') + $target = $('#same1') + $target.add($near).waypoint({}) + expect($target.waypoint('next')[0]).toEqual($near[0]) + }) + }) + + describe('jQuery#waypoints()', function() { + it('starts as an empty array for each axis', function() { + expect($.waypoints().vertical.length).toEqual(0) + expect($.waypoints().horizontal.length).toEqual(0) + }) + + it('returns waypoint elements', function() { + $target = $('#same1').waypoint({}) + expect($.waypoints().vertical[0]).toEqual($target[0]) + }) + + it('does not blow up with multiple waypoints', function() { + $target = $('.sameposition, #top').waypoint({}) + $target = $target.add($('#near1')).waypoint({}) + expect($.waypoints().vertical.length).toEqual(4) + expect($.waypoints().vertical[0]).toEqual($('#top')[0]) + }) + + it('returns horizontal elements', function() { + $target = $('#same1').waypoint({ + horizontal: true + }) + expect($.waypoints().horizontal[0]).toEqual($target[0]) + }) + + describe('Directional filters', function() { + var $other + + beforeEach(function() { + $target = $('#same1') + $other = $('#near1') + }) + + describe('above', function() { + it('returns only waypoints above current scroll', function() { + runs(function() { + $target.add($other).waypoint({}) + $scroller.scrollTop(1500) + }) + waitsFor(function() { + return $.waypoints('above')[0] === $target[0] + }, 'target to be above') + }) + }) + + describe('below', function() { + it('returns only waypoints below current scroll', function() { + runs(function() { + $target.add($other).waypoint({}) + $scroller.scrollTop(1500) + }) + waitsFor(function() { + return $.waypoints('below')[0] === $other[0] + }, 'other to be below') + }) + }) + + describe('left', function() { + it('returns only waypoints left of current scroll', function() { + runs(function() { + $target.add($other).waypoint({ + horizontal: true + }) + $scroller.scrollLeft(1500) + }) + waitsFor(function() { + return $.waypoints('left')[0] === $target[0] + }, 'target to be left') + }) + }) + + describe('right', function() { + it('returns only waypoints right of current scroll', function() { + runs(function() { + $target.add($other).waypoint({ + horizontal: true + }) + $scroller.scrollLeft(1500) + }) + waitsFor(function() { + return $.waypoints('right')[0] === $other[0] + }, 'other to be right') + }) + }) + }) + }) + + describe('jQuery#waypoints("refresh")', function() { + var currentDirection + + beforeEach(function() { + currentDirection = null + $target = $('#same1').waypoint(function(direction) { + currentDirection = direction + }) + }) + + it('triggers callback if refresh crosses scroll', function() { + var top = $target.offset().top + runs(function() { + $scroller.scrollTop(top - 1) + }) + waits(standard) + runs(function() { + $target.css('top', (top - 50) + 'px') + $.waypoints('refresh') + expect(currentDirection).toEqual('down') + $target.css('top', top + 'px') + $.waypoints('refresh') + expect(currentDirection).toEqual('up') + }) + }) + + it('does not trigger callback if onlyOnScroll true', function() { + var top, $other + runs(function() { + $other = $('#same1').waypoint({ + onlyOnScroll: true, + handler: setHitTrue + }) + top = $other.offset().top + }) + waits(standard) + runs(function() { + $other.css('top', (top - 50) + 'px') + $.waypoints('refresh') + expect(hit).toBeFalsy() + $other.css('top', top + 'px') + $.waypoints('refresh') + expect(hit).toBeFalsy() + }) + }) + + it('updates the offset', function() { + runs(function() { + $scroller.scrollTop($target.offset().top - 51) + $target.css('top', ($target.offset().top - 50) + 'px') + $.waypoints('refresh') + }) + waits(standard) + runs(function() { + expect(currentDirection).toBeFalsy() + $scroller.scrollTop($target.offset().top) + }) + waitsFor(function() { + return currentDirection + }, 'callback to trigger') + }) + }) + + describe('jQuery#waypoints("viewportHeight")', function() { + it('returns window innerHeight if it exists', function() { + if (window.innerHeight) { + expect($.waypoints('viewportHeight')).toEqual(window.innerHeight) + } + else { + expect($.waypoints('viewportHeight')).toEqual($(window).height()) + } + }) + }) + + describe('jQuery#waypoints("disable")', function() { + it('disables all waypoints', function() { + var count = 0 + runs(function() { + $target = $('.sameposition').waypoint(function() { + count += 1 + }) + $.waypoints('disable') + $scroller.scrollTop($target.offset().top + 50) + }) + waits(standard) + runs(function() { + expect(count).toEqual(0) + }) + }) + }) + + describe('jQuery#waypoints("enable")', function() { + it('enables all waypoints', function() { + var count = 0 + runs(function() { + $target = $('.sameposition').waypoint(function() { + count += 1 + }) + $.waypoints('disable') + $.waypoints('enable') + $scroller.scrollTop($target.offset().top + 50) + }) + waits(standard) + runs(function() { + expect(count).toEqual(2) + }) + }) + }) + + describe('jQuery#waypoints("destroy")', function() { + it('destroys all waypoints', function() { + $target = $('.sameposition').waypoint({}) + $.waypoints('destroy') + expect($.waypoints().vertical.length).toEqual(0) + }) + }) + + describe('jQuery#waypoints("extendFn", methodName, function")', function() { + it('adds method to the waypoint namespace', function() { + var currentArg + $.waypoints('extendFn', 'myMethod', function(arg) { + currentArg = arg + }) + $('#same1').waypoint('myMethod', 'test') + expect(currentArg).toEqual('test') + }) + }) + + describe('jQuery.waypoints.settings', function() { + var count, curId + + beforeEach(function() { + count = 0 + $('.sameposition, #near1, #near2').waypoint(function() { + count += 1 + curId = this.id + }) + }) + + it('throttles the scroll check', function() { + runs(function() { + $scroller.scrollTop($('#same1').offset().top) + expect(count).toEqual(0) + }) + waitsFor(function() { + return count === 2 + }, 'callbacks to trigger') + }) + + it('throttles the resize event and calls refresh', function() { + runs(function() { + $('#same1').css('top', '-1000px') + $(window).resize() + expect(count).toEqual(0) + }) + waitsFor(function() { + return count === 1 + }, 'callback to trigger') + }) + }) + + describe('non-window scroll context', function() { + beforeEach(function() { + $scroller = $('#bottom') + }) + + it('triggers the waypoint within its context', function() { + $target = $('#inner3').waypoint({ + context: '#bottom', + handler: setHitTrue + }) + runs(function() { + $scroller.scrollTop(199) + }) + waits(standard) + runs(function() { + expect(hit).toBeFalsy() + $scroller.scrollTop(200) + }) + waitsFor(function() { + return hit + }, 'callback to trigger') + }) + + it('respects a % offset within context', function() { + $target = $('#inner3').waypoint({ + context: '#bottom', + offset: '100%', + handler: setHitTrue + }) + runs(function() { + $scroller.scrollTop(149) + }) + waits(standard) + runs(function() { + expect(hit).toBeFalsy() + $scroller.scrollTop(150) + }) + waitsFor(function() { + return hit + }, 'callback to trigger') + }) + + it('respects function offsets within context', function() { + $target = $('#inner3').waypoint({ + context: '#bottom', + offset: function() { + return $(this).height() / 2 + }, + handler: setHitTrue + }) + runs(function() { + $scroller.scrollTop(149) + }) + waits(standard) + runs(function() { + expect(hit).toBeFalsy() + $scroller.scrollTop(150) + }) + waitsFor(function() { + return hit + }, 'callback to trigger') + }) + + it('respects bottom-in-view alias', function() { + $target = $('#inner3').waypoint({ + context: '#bottom', + offset: 'bottom-in-view', + handler: setHitTrue + }) + runs(function() { + $scroller.scrollTop(249) + }) + waits(standard) + runs(function() { + expect(hit).toBeFalsy() + $scroller.scrollTop(250) + }) + waitsFor(function() { + return hit + }, 'callback to trigger') + }) + }) + + describe('Waypoints added after load, Issue #28, 62, 63', function() { + it('triggers down on new but already reached waypoints', function() { + runs(function() { + $target = $('#same2') + $scroller.scrollTop($target.offset().top + 1) + }) + waits(standard) + runs(function() { + $target.waypoint(function(direction) { + hit = direction === 'down' + }) + }) + waitsFor(function() { + return hit + }, 'callback to trigger') + }) + }) + + describe('Multiple waypoints on the same element', function() { + var hit2 + + beforeEach(function() { + hit2 = false + $target = $('#same1').waypoint(setHitTrue) + $target.waypoint({ + offset: -50, + handler: function() { + hit2 = true + } + }) + }) + + it('triggers all handlers', function() { + runs(function() { + $scroller.scrollTop($target.offset().top + 50) + }) + waitsFor(function() { + return hit && hit2 + }, 'both callbacks to trigger') + }) + + it('uses only one element in $.waypoints array', function() { + expect($.waypoints().vertical.length).toEqual(1) + }) + + it('disables all waypoints on the element with #disable', function() { + runs(function() { + $target.waypoint('disable') + $scroller.scrollTop($target.offset().top + 50) + }) + waits(standard) + runs(function() { + expect(hit || hit2).toBeFalsy() + }) + }) + }) + + describe('Horizontal waypoints', function() { + var currentDirection + + beforeEach(function() { + currentDirection = null + $target = $('#same1').waypoint({ + horizontal: true, + handler: function(direction) { + currentDirection = direction + } + }) + }) + + it('triggers right/left direction', function() { + runs(function() { + $scroller.scrollLeft($target.offset().left) + }) + waitsFor(function() { + return currentDirection === 'right' + }, 'right direction to trigger') + runs(function() { + $scroller.scrollLeft($target.offset().left - 1) + }) + waitsFor(function() { + return currentDirection === 'left' + }, 'left direction to trigger') + }) + }) + + describe('Waypoints attached to window object, PR #86', function() { + $window = $(window) + + beforeEach(function() { + $target = $window.waypoint({ + offset: -$window.height(), + handler: setHitTrue + }) + }) + + it('triggers waypoint', function() { + runs(function() { + $window.scrollTop($window.height() + 1) + }) + waitsFor(function() { + return hit + }, 'callback to trigger') + }) + }) + + describe('Options object reuse, issue #253', function() { + beforeEach(function() { + var options = { + offset: 0 + } + $('#same1').waypoint($.noop, options) + $target = $('#same2').waypoint(setHitTrue, options) + }) + + it('does not override with previous waypoint handler', function() { + runs(function() { + $scroller.scrollTop($target.offset().top) + }) + waitsFor(function() { + return hit + }, 'callback to trigger') + }) + }) +}) diff --git a/testem.json b/testem.json new file mode 100644 index 00000000..8832f769 --- /dev/null +++ b/testem.json @@ -0,0 +1,18 @@ +{ + "framework": "jasmine", + "launch_in_dev": [ + "PhantomJS" + ], + "launch_in_ci": [ + "PhantomJS" + ], + "src_files": [ + "bower_components/jquery/dist/jquery.js", + "bower_components/jasmine-jquery/lib/jasmine-jquery.js", + "lib/waypoints.js", + "lib/waypoints-infinite.js", + "lib/waypoints-sticky.js", + "test/settings.js", + "test/*-spec.js" + ] +} From fe5bee61ae441b5a86f6e043decefe38278807e0 Mon Sep 17 00:00:00 2001 From: imakewebthings Date: Sat, 17 May 2014 16:36:17 -0700 Subject: [PATCH 03/98] Convert infinite and sticky specs --- test/fixtures/infinite.html | 4 +- test/waypoints-infinite-spec.js | 68 ++++++++++++++++++++++++++++ test/waypoints-spec.js | 2 +- test/waypoints-sticky-spec.js | 80 +++++++++++++++++++++++++++++++++ 4 files changed, 151 insertions(+), 3 deletions(-) create mode 100644 test/waypoints-infinite-spec.js create mode 100644 test/waypoints-sticky-spec.js diff --git a/test/fixtures/infinite.html b/test/fixtures/infinite.html index 687ea1bb..a8c3be73 100644 --- a/test/fixtures/infinite.html +++ b/test/fixtures/infinite.html @@ -6,7 +6,7 @@
- More + More \ No newline at end of file + diff --git a/test/waypoints-infinite-spec.js b/test/waypoints-infinite-spec.js new file mode 100644 index 00000000..2e5ece80 --- /dev/null +++ b/test/waypoints-infinite-spec.js @@ -0,0 +1,68 @@ +describe('Waypoints Infinite Scroll Shortcut', function() { + var standard = 50 + var $window = $(window) + var $items, $container, $more, beforeHit, afterHit + + beforeEach(function() { + loadFixtures('infinite.html') + $items = $('.infinite-item') + $container = $('.infinite-container') + $more = $('.infinite-more-link') + beforeHit = afterHit = false + }) + + afterEach(function() { + runs(function() { + $.waypoints('destroy') + $window.scrollTop(0) + }) + waits(standard) + }) + + it('returns the same jQuery object for chaining', function() { + expect($container.waypoint('infinite').get()).toEqual($container.get()) + }) + + describe('loading new pages', function() { + beforeEach(function() { + runs(function() { + var triggerPoint = $.waypoints('viewportHeight') - $container.height() + $container.waypoint('infinite', { + onBeforePageLoad: function() { + beforeHit = true + }, + onAfterPageLoad: function() { + afterHit = true + } + }) + $window.scrollTop(triggerPoint) + }) + waitsFor(function() { + return $('.infinite-container > .infinite-item').length > $items.length + }, 'new items to load') + }) + + it('replaces the more link with the new more link', function() { + expect($more[0]).not.toEqual($('.infinite-more-link')[0]) + }) + + it('fires the before callback', function() { + expect(beforeHit).toBeTruthy() + }) + + it('fires the after callback', function() { + expect(afterHit).toBeTruthy() + }) + }) + + describe('when there is no more link on initialization', function() { + beforeEach(function() { + $more.remove() + $container.waypoint('infinite') + }) + + it('does not create the waypoint', function() { + expect($.waypoints().vertical.length).toEqual(0) + }) + }) +}) diff --git a/test/waypoints-spec.js b/test/waypoints-spec.js index 495877ee..e39d1fe0 100644 --- a/test/waypoints-spec.js +++ b/test/waypoints-spec.js @@ -1,6 +1,6 @@ describe('jQuery Waypoints', function() { var standard = 50 - var hit, $scroller, $target, $return = null + var hit, $scroller, $target, $return function setHitTrue() { hit = true diff --git a/test/waypoints-sticky-spec.js b/test/waypoints-sticky-spec.js new file mode 100644 index 00000000..fc19ff3b --- /dev/null +++ b/test/waypoints-sticky-spec.js @@ -0,0 +1,80 @@ +describe('Waypoints Sticky Elements Shortcut', function() { + var standard = 50 + var $window = $(window) + var $sticky, $return, handlerSpy + + beforeEach(function() { + loadFixtures('sticky.html') + $sticky = $('.sticky') + handlerSpy = jasmine.createSpy('on handler') + $return = $sticky.waypoint('sticky', { + handler: handlerSpy + }) + }) + + afterEach(function() { + $.waypoints('destroy') + $window.scrollTop(0) + waits(standard) + }) + + it('returns the same jQuery object for chaining', function() { + expect($return.get()).toEqual($sticky.get()) + }) + + it('wraps the sticky element', function() { + expect($sticky.parent()).toHaveClass('sticky-wrapper') + }) + + it('gives the wrapper the same height as the sticky element', function() { + expect($sticky.parent().height()).toEqual($sticky.outerHeight()) + }) + + it('adds stuck class when you scroll to the element', function() { + runs(function() { + $window.scrollTop($sticky.offset().top) + }) + waitsFor(function() { + return $sticky.hasClass('stuck') + }, 'stuck class to apply') + runs(function() { + $window.scrollTop($window.scrollTop() - 1) + }) + waitsFor(function() { + return !$sticky.hasClass('stuck') + }) + }) + + it('executes handler option after stuck class applied', function() { + runs(function() { + $window.scrollTop($sticky.offset().top) + }) + waitsFor(function() { + return handlerSpy.callCount + }, 'callback to trigger') + }) + + describe('#waypoint("unsticky")', function() { + beforeEach(function() { + $return = $sticky.waypoint('unsticky') + }) + + it('returns the same jQuery object for chaining', function() { + expect($return.get()).toEqual($sticky.get()) + }) + + it('unwraps the sticky element', function() { + expect($sticky.parent()).not.toHaveClass('sticky-wrapper') + }) + + it('should not have stuck class', function() { + expect($sticky).not.toHaveClass('stuck') + }) + + it('does nothing if called on a non-sticky element', function() { + $parent = $sticky.parent() + $sticky.waypoint('unsticky') + expect($parent.closest('body')).toExist() + }) + }) +}) From 62642985b0793153c7dcdc5af042735a8fbe987e Mon Sep 17 00:00:00 2001 From: imakewebthings Date: Mon, 19 May 2014 16:43:08 -0700 Subject: [PATCH 04/98] EOD intermediate --- src/context.js | 224 ++++++++++++++++++ src/waypoint.js | 77 ++++++ test/waypoint-spec.js | 68 ++++++ ...te-spec.js => waypoints-infinite-xspec.js} | 0 ...icky-spec.js => waypoints-sticky-xspec.js} | 0 .../{waypoints-spec.js => waypoints-xspec.js} | 0 testem.json | 6 + 7 files changed, 375 insertions(+) create mode 100644 src/context.js create mode 100644 src/waypoint.js create mode 100644 test/waypoint-spec.js rename test/{waypoints-infinite-spec.js => waypoints-infinite-xspec.js} (100%) rename test/{waypoints-sticky-spec.js => waypoints-sticky-xspec.js} (100%) rename test/{waypoints-spec.js => waypoints-xspec.js} (100%) diff --git a/src/context.js b/src/context.js new file mode 100644 index 00000000..14fbb4fa --- /dev/null +++ b/src/context.js @@ -0,0 +1,224 @@ +(function() { + var keyCounter = 0 + var contexts = {} + + var Context = function(element) { + this.element = element + this.$element = $(element) + this.key = 'waypoint-context-' + keyCounter + this.didScroll = false + this.didResize = false + this.oldScroll = { + x: this.$element.scrollLeft(), + y: this.$element.scrollTop() + } + this.waypoints = { + vertical: [], + horizontal: [] + } + + element.waypointContextKey = this.key + contexts[element.waypointContextKey] = this + keyCounter += 1 + + this.createThrottledScrollHandler() + this.createThrottledResizeHandler() + } + + Context.prototype.createThrottledScrollHandler = function() { + var scrollHandler = $.proxy(function() { + this.handleScroll() + this.didScroll = false + }, this) + + this.$element.on('scroll.waypoints', $.proxy(function() { + if (!this.didScroll || Waypoint.isTouch) { + this.didScroll = true + window.setTimeout(scrollHandler, Waypoint.settings.scrollThrottle) + } + }, this)) + } + + Context.prototype.createThrottledResizeHandler = function() { + var resizeHandler = $.proxy(function() { + this.handleResize() + this.didResize = false + }, this) + + this.$element.on('resize.waypoints', $.proxy(function() { + if (!this.didResize) { + this.didResize = true + window.setTimeout(resizeHandler, Waypoint.settings.resizeThrottle) + } + })) + } + + Context.prototype.handleScroll = function(options) { + var axes = { + horizontal: { + newScroll: this.$element.scrollLeft(), + oldScroll: this.oldScroll.x, + forward: 'right', + backward: 'left' + }, + vertical: { + newScroll: this.$element.scrollTop(), + oldScroll: this.oldScroll.y, + forward: 'down', + backward: 'up' + } + } + var atTop = !axes.vertical.oldScroll || !axes.vertical.newScroll + var skipIOSRefresh = options && options.skipIOSRefresh + + /* Hack for iOS, needed because scrolls in mobile Safari that start + * or end with the URL bar showing will cause window height to change + * without firing a resize event. */ + if (Waypoint.isTouch && atTop && !skipIOSRefresh) { + this.refresh() + } + + $.each(axes, $.proxy(function(axisKey, axis) { + var triggered = [] + var isForward = axis.newScroll > axis.oldScroll + var direction = isForward ? axis.forward : axis.backward + + $.each(this.waypoints[axisKey], function(waypointKey, waypoint) { + var wasBeforeTriggerPoint = axis.oldScroll < waypoint.triggerPoint + var nowAfterTriggerPoint = axis.newScroll >= waypoint.triggerPoint + var crossedForward = wasBeforeTriggerPoint && nowAfterTriggerPoint + var crossedBackward = !wasBeforeTriggerPoint && !nowAfterTriggerPoint + if (crossedForward || crossedBackward) { + triggered.push(waypoint) + } + }) + + triggered.sort(function(a, b) { + return a.triggerPoint - b.triggerPoint + }) + if (!isForward) { + triggered.reverse() + } + $.each(triggered, function(i, waypoint) { + if (waypoint.options.continuous || i === triggered.length - 1) { + waypoint.trigger([direction]) + } + }) + }, this)) + + this.oldScroll = { + x: axes.horizontal.newScroll, + y: axes.vertical.newScroll + } + } + + Context.prototype.handleResize = function() { + + } + + Context.prototype.refresh = function() { + var isWindow = $.isWindow(this.element) + var contextOffset = this.$element.offset() + var height = isWindow ? Waypoint.viewportHeight() : this.$element.height() + var axes + + this.handleScroll({ + skipIOSRefresh: true + }) + axes = { + horizontal: { + contextOffset: isWindow ? 0 : contextOffset.left, + contextScroll: isWindow ? 0 : this.oldScroll.x, + contextDimension: this.$element.width(), + oldScroll: this.oldScroll.x, + forward: 'right', + backward: 'left', + offsetProp: 'left' + }, + vertical: { + contextOffset: isWindow ? 0 : contextOffset.top, + contextScroll: isWindow ? 0 : this.oldScroll.y, + contextDimension: height, + oldScroll: this.oldScroll.y, + forward: 'down', + backward: 'up', + offsetProp: 'top' + } + } + + $.each(axes, $.proxy(function(axisKey, axis) { + $.each(this.waypoints[axisKey], function(i, waypoint) { + var adjustment = waypoint.options.offset + var oldTriggerPoint = waypoint.triggerPoint + var elementOffset = 0 + var canTriggerOnRefresh = waypoint.canTriggerOnRefresh() + var freshWaypoint = oldTriggerPoint == null + var contextModifier + + if (!$.isWindow(waypoint.element)) { + elementOffset = waypoint.$element.offset()[axis.offsetProp] + } + + if (typeof adjustment === 'function') { + adjustment = adjustment.apply(waypoint.element) + } + else if (typeof adjustment === 'string') { + adjustment = parseFloat(adjustment) + if (waypoint.options.offset.indexOf('%') > - 1) { + adjustment = Math.ceil(axis.contextDimension * adjustment / 100) + } + } + + contextModifier = axis.contextScroll - axis.contextOffset + waypoint.triggerPoint = elementOffset + contextModifier - adjustment + + if (canTriggerOnRefresh) { + return + } + + var wasBeforeScroll = oldTriggerPoint < axis.oldScroll + var nowAfterScroll = waypoint.triggerPoint >= axis.oldScroll + var triggeredBackward = wasBeforeScroll && nowAfterScroll + var triggeredForward = !wasBeforeScroll && !nowAfterScroll + if (!freshWaypoint && triggeredBackward) { + waypoint.trigger([axis.backward]) + } + else if (!freshWaypoint && triggeredForward) { + waypoint.trigger([axis.forward]) + } + else if (freshWaypoint && waypoint.triggerPoint >= axis.oldScroll) { + waypoint.trigger([axis.forward]) + } + }) + }, this)) + } + + Context.prototype.add = function(waypoint) { + var axis = waypoint.options.horizontal ? 'horizontal' : 'vertical' + this.waypoints[axis][waypoint.key] = waypoint + } + + Context.prototype.remove = function(waypoint) { + var axis = waypoint.options.horizontal ? 'horizontal' : 'vertical' + delete this.waypoints[axis][waypoint.key] + } + + Context.prototype.checkEmpty = function() { + var horizontalEmpty = $.isEmptyObject(this.waypoints.horizontal) + var verticalEmpty = $.isEmptyObject(this.waypoints.vertical) + if (horizontalEmpty && verticalEmpty) { + this.$element.off('.waypoints') + delete contexts[this.key] + } + } + + Context.findByElement = function(element) { + return contexts[element.waypointContextKey] + } + + Context.findOrCreateByElement = function(element) { + return Context.findByElement(element) || new Context(element) + } + + window.Waypoint.Context = Context +})() diff --git a/src/waypoint.js b/src/waypoint.js new file mode 100644 index 00000000..829bc8cb --- /dev/null +++ b/src/waypoint.js @@ -0,0 +1,77 @@ +(function() { + var keyCounter = 0 + + var Waypoint = function(options) { + if (!options) { + throw new Error('No options passed to Waypoint constructor') + } + if (!options.element) { + throw new Error('No element option passed to Waypoint constructor') + } + + this.key = keyCounter + this.options = $.extend({}, Waypoint.defaults, options) + this.context = Waypoint.Context.findOrCreateByElement(this.options.context) + this.context.add(this) + this.callback = options.handler + this.element = this.options.element + this.$element = $(this.element) + this.axis = this.options.horizontal ? 'horizontal' : 'vertical' + this.enabled = this.options.enabled + this.triggerPoint = null + + keyCounter += 1 + } + + Waypoint.prototype.trigger = function(args) { + if (!this.enabled) { + return + } + if (this.callback) { + this.callback.apply(this.element, args) + } + if (this.options.triggerOnce) { + this.destroy() + } + } + + Waypoint.prototype.disable = function() { + this.enabled = false + } + + Waypoint.prototype.enable = function() { + this.context.refresh() + this.enabled = true + } + + Waypoint.prototype.destroy = function() { + this.context.remove(this) + this.context.checkEmpty() + } + + Waypoint.prototype.canTriggerOnRefresh = function() { + return (!this.options.onlyOnScroll || this.offset == null) && this.enabled + } + + Waypoint.defaults = { + context: window, + continuous: true, + enabled: true, + horizontal: false, + offset: 0, + triggerOnce: false + } + + Waypoint.settings = { + scrollThrottle: 30, + resizeThrottle: 100 + } + + Waypoint.isTouch = 'ontouchstart' in window + + Waypoint.viewportHeight = function() { + return window.innerHeight || document.documentElement.clientHeight + } + + window.Waypoint = Waypoint +})() diff --git a/test/waypoint-spec.js b/test/waypoint-spec.js new file mode 100644 index 00000000..cf60e6ca --- /dev/null +++ b/test/waypoint-spec.js @@ -0,0 +1,68 @@ +describe('Waypoint', function() { + var standard = 50 + var hit, $scroller, target, returnValue, $target + + beforeEach(function() { + loadFixtures('standard.html') + $scroller = $(window) + hit = false + }) + + afterEach(function() { + $scroller.scrollTop(0).scrollLeft() + waits(standard) + }) + + describe('new Waypoint()', function() { + it('errors out', function() { + expect(function() { + new Waypoint() + }).toThrow() + }) + }) + + describe('new Waypoint(options)', function() { + it('returns an instance of the Waypoint class', function() { + returnValue = new Waypoint({ + element: document.getElementById('same1') + }) + expect(returnValue instanceof Waypoint).toBeTruthy() + }) + + it('requires the element option', function() { + expect(function() { + new Waypoint({}) + }).toThrow() + }) + }) + + describe('handler option', function() { + var currentDirection + + beforeEach(function() { + $target = $('#same1') + currentDirection = null + new Waypoint({ + element: $target[0], + handler: function(direction) { + currentDirection = direction + } + }) + }) + + it('triggers with direction parameter', function() { + runs(function() { + $scroller.scrollTop($target.offset().top) + }) + waitsFor(function() { + return currentDirection === 'down' + }, 'down to trigger') + runs(function() { + $scroller.scrollTop($target.offset().top - 1) + }) + waitsFor(function() { + return currentDirection === 'up' + }, 'up to trigger') + }) + }) +}) diff --git a/test/waypoints-infinite-spec.js b/test/waypoints-infinite-xspec.js similarity index 100% rename from test/waypoints-infinite-spec.js rename to test/waypoints-infinite-xspec.js diff --git a/test/waypoints-sticky-spec.js b/test/waypoints-sticky-xspec.js similarity index 100% rename from test/waypoints-sticky-spec.js rename to test/waypoints-sticky-xspec.js diff --git a/test/waypoints-spec.js b/test/waypoints-xspec.js similarity index 100% rename from test/waypoints-spec.js rename to test/waypoints-xspec.js diff --git a/testem.json b/testem.json index 8832f769..0e5e80a9 100644 --- a/testem.json +++ b/testem.json @@ -12,6 +12,12 @@ "lib/waypoints.js", "lib/waypoints-infinite.js", "lib/waypoints-sticky.js", + + + "src/waypoint.js", + "src/context.js", + + "test/settings.js", "test/*-spec.js" ] From 7e005b6b4c7e6a710b2c4d5837dc48763b0c356b Mon Sep 17 00:00:00 2001 From: imakewebthings Date: Thu, 22 May 2014 16:06:23 -0700 Subject: [PATCH 05/98] EOD intermediate --- src/context.js | 15 ++- src/waypoint.js | 20 +++- test/settings.js | 1 + test/waypoint-spec.js | 210 +++++++++++++++++++++++++++++++++++++++++- 4 files changed, 233 insertions(+), 13 deletions(-) diff --git a/src/context.js b/src/context.js index 14fbb4fa..145b62ae 100644 --- a/src/context.js +++ b/src/context.js @@ -13,8 +13,8 @@ y: this.$element.scrollTop() } this.waypoints = { - vertical: [], - horizontal: [] + vertical: {}, + horizontal: {} } element.waypointContextKey = this.key @@ -160,7 +160,7 @@ } if (typeof adjustment === 'function') { - adjustment = adjustment.apply(waypoint.element) + adjustment = adjustment.apply(waypoint) } else if (typeof adjustment === 'string') { adjustment = parseFloat(adjustment) @@ -196,11 +196,13 @@ Context.prototype.add = function(waypoint) { var axis = waypoint.options.horizontal ? 'horizontal' : 'vertical' this.waypoints[axis][waypoint.key] = waypoint + this.refresh() } Context.prototype.remove = function(waypoint) { var axis = waypoint.options.horizontal ? 'horizontal' : 'vertical' delete this.waypoints[axis][waypoint.key] + this.checkEmpty() } Context.prototype.checkEmpty = function() { @@ -212,6 +214,13 @@ } } + Context.prototype.height = function() { + if ($.isWindow(this.element)) { + return Waypoint.viewportHeight() + } + return this.$element.height() + } + Context.findByElement = function(element) { return contexts[element.waypointContextKey] } diff --git a/src/waypoint.js b/src/waypoint.js index 829bc8cb..d9c7f286 100644 --- a/src/waypoint.js +++ b/src/waypoint.js @@ -9,17 +9,20 @@ throw new Error('No element option passed to Waypoint constructor') } - this.key = keyCounter + this.key = 'waypoint-' + keyCounter this.options = $.extend({}, Waypoint.defaults, options) - this.context = Waypoint.Context.findOrCreateByElement(this.options.context) - this.context.add(this) - this.callback = options.handler this.element = this.options.element this.$element = $(this.element) + this.callback = options.handler this.axis = this.options.horizontal ? 'horizontal' : 'vertical' this.enabled = this.options.enabled this.triggerPoint = null + this.context = Waypoint.Context.findOrCreateByElement(this.options.context) + if (Waypoint.offsetAliases[this.options.offset]) { + this.options.offset = Waypoint.offsetAliases[this.options.offset] + } + this.context.add(this) keyCounter += 1 } @@ -37,16 +40,17 @@ Waypoint.prototype.disable = function() { this.enabled = false + return this } Waypoint.prototype.enable = function() { this.context.refresh() this.enabled = true + return this } Waypoint.prototype.destroy = function() { this.context.remove(this) - this.context.checkEmpty() } Waypoint.prototype.canTriggerOnRefresh = function() { @@ -67,6 +71,12 @@ resizeThrottle: 100 } + Waypoint.offsetAliases = { + 'bottom-in-view': function() { + return this.context.height() - this.$element.outerHeight() + } + } + Waypoint.isTouch = 'ontouchstart' in window Waypoint.viewportHeight = function() { diff --git a/test/settings.js b/test/settings.js index ac9582ba..d2ea560c 100644 --- a/test/settings.js +++ b/test/settings.js @@ -1 +1,2 @@ jasmine.getFixtures().fixturesPath = 'test/fixtures' +jasmine.getEnv().defaultTimeoutInterval = 1000 diff --git a/test/waypoint-spec.js b/test/waypoint-spec.js index cf60e6ca..3711d9af 100644 --- a/test/waypoint-spec.js +++ b/test/waypoint-spec.js @@ -1,15 +1,27 @@ describe('Waypoint', function() { var standard = 50 - var hit, $scroller, target, returnValue, $target + var hit, $scroller, waypoint, $target, returnValue + + function setHitTrue() { + hit = true + } + + function hitToBeTrue() { + return hit + } beforeEach(function() { loadFixtures('standard.html') $scroller = $(window) hit = false + waypoint = null }) afterEach(function() { - $scroller.scrollTop(0).scrollLeft() + if (waypoint && waypoint.destroy) { + waypoint.destroy() + } + $scroller.scrollTop(0).scrollLeft(0) waits(standard) }) @@ -23,10 +35,10 @@ describe('Waypoint', function() { describe('new Waypoint(options)', function() { it('returns an instance of the Waypoint class', function() { - returnValue = new Waypoint({ + waypoint = new Waypoint({ element: document.getElementById('same1') }) - expect(returnValue instanceof Waypoint).toBeTruthy() + expect(waypoint instanceof Waypoint).toBeTruthy() }) it('requires the element option', function() { @@ -42,7 +54,7 @@ describe('Waypoint', function() { beforeEach(function() { $target = $('#same1') currentDirection = null - new Waypoint({ + waypoint = new Waypoint({ element: $target[0], handler: function(direction) { currentDirection = direction @@ -65,4 +77,192 @@ describe('Waypoint', function() { }, 'up to trigger') }) }) + + describe('offset option', function() { + beforeEach(function() { + $target = $('#same1') + }) + + it('takes a px offset', function(){ + runs(function() { + waypoint = new Waypoint({ + element: $target[0], + handler: setHitTrue, + offset: 50 + }) + $scroller.scrollTop($target.offset().top - 51) + }) + waits(standard) + runs(function() { + expect(hit).toBeFalsy() + $scroller.scrollTop($target.offset().top - 50) + }) + waitsFor(hitToBeTrue, 'callback to trigger') + }) + + it('takes a % offset', function() { + var trigger = $target.offset().top - Waypoint.viewportHeight() * .37 + runs(function() { + waypoint = new Waypoint({ + element: $target[0], + handler: setHitTrue, + offset: '37%' + }) + $scroller.scrollTop(trigger - 1) + }) + waits(standard) + runs(function() { + expect(hit).toBeFalsy() + $scroller.scrollTop(trigger) + }) + waitsFor(hitToBeTrue, 'callback to trigger') + }) + + it('takes a function offset', function() { + runs(function() { + waypoint = new Waypoint({ + element: $target[0], + handler: setHitTrue, + offset: function() { + return -this.$element.height() + } + }) + $scroller.scrollTop($target.offset().top + $target.height() - 1) + }) + waits(standard) + runs(function() { + expect(hit).toBeFalsy() + $scroller.scrollTop($target.offset().top + $target.height()) + }) + waitsFor(hitToBeTrue, 'callback to trigger') + }) + + it('takes a botton-in-view function alias', function() { + var top = $target.offset().top + var height = $target.outerHeight() + var windowHeight = Waypoint.viewportHeight() + var inview = top + height - windowHeight + runs(function() { + waypoint = new Waypoint({ + element: $target[0], + handler: setHitTrue, + offset: 'bottom-in-view' + }) + $scroller.scrollTop(inview - 1) + }) + waits(standard) + runs(function() { + expect(hit).toBeFalsy() + $scroller.scrollTop(inview) + }) + waitsFor(hitToBeTrue, 'callback to trigger') + }) + }) + + describe('triggerOnce option', function() { + it('destroys the waypoint after first trigger', function() { + runs(function() { + $target = $('#same1') + waypoint = new Waypoint({ + element: $target[0], + triggerOnce: true + }) + $scroller.scrollTop($target.offset().top) + }) + waitsFor(function() { + return !waypoint.context.waypoints.vertical[waypoint.key] + }, 'waypoint to be destroyed') + }) + }) + + describe('context option', function() { + it('needs specs', function() { + expect('implemented').toBeFalsy() + }) + }) + + describe('#disable()', function() { + beforeEach(function() { + $target = $('#same1') + waypoint = new Waypoint({ + element: $target[0], + handler: setHitTrue + }) + returnValue = waypoint.disable() + }) + + it('returns the same waypoint object for chaining', function() { + expect(returnValue).toEqual(waypoint) + }) + + it('disables callback triggers', function() { + runs(function() { + $scroller.scrollTop($target.offset().top) + }) + waits(standard) + runs(function() { + expect(hit).toBeFalsy() + }) + }) + }) + + describe('#enable()', function() { + beforeEach(function() { + $target = $('#same1') + waypoint = new Waypoint({ + element: $target[0], + handler: setHitTrue + }) + waypoint.disable() + returnValue = waypoint.enable() + }) + + it('returns the same waypoint instance for chaining', function() { + expect(returnValue).toEqual(waypoint) + }) + + it('enables callback triggers', function() { + runs(function() { + $scroller.scrollTop($target.offset().top) + }) + waitsFor(hitToBeTrue, 'callback to trigger') + }) + }) + + describe('#destroy()', function() { + beforeEach(function() { + $target = $('#same1') + waypoint = new Waypoint({ + element: $target[0], + handler: setHitTrue + }) + returnValue = waypoint.destroy() + }) + + it('returns undefined', function() { + expect(returnValue).toBeUndefined() + }) + + it('no longer triggers callbacks', function() { + runs(function() { + $scroller.scrollTop($target.offset().top) + }) + waits(standard) + runs(function() { + expect(hit).toBeFalsy() + }) + }) + }) + + describe('Waypoint.viewportHeight()', function() { + it('returns window innerHeight if it exists', function() { + var height = Waypoint.viewportHeight() + if (window.innerHeight) { + expect(height).toEqual(window.innerHeight) + } + else { + expect(height).toEqual(document.documentElement.clientHeight) + } + }) + }) }) From 5d0a8be0f4c0ce7f5e452ca69326a0cf1f3d9730 Mon Sep 17 00:00:00 2001 From: imakewebthings Date: Wed, 28 May 2014 12:42:54 -0700 Subject: [PATCH 06/98] End of basic Waypoint refactoring --- src/context.js | 7 +- src/waypoint.js | 2 +- test/waypoint-spec.js | 147 +++++++++++++++++++++++++++++++++++++++++- 3 files changed, 148 insertions(+), 8 deletions(-) diff --git a/src/context.js b/src/context.js index 145b62ae..8ecacea6 100644 --- a/src/context.js +++ b/src/context.js @@ -172,7 +172,7 @@ contextModifier = axis.contextScroll - axis.contextOffset waypoint.triggerPoint = elementOffset + contextModifier - adjustment - if (canTriggerOnRefresh) { + if (!canTriggerOnRefresh) { return } @@ -186,7 +186,7 @@ else if (!freshWaypoint && triggeredForward) { waypoint.trigger([axis.forward]) } - else if (freshWaypoint && waypoint.triggerPoint >= axis.oldScroll) { + else if (freshWaypoint && axis.oldScroll >= waypoint.triggerPoint) { waypoint.trigger([axis.forward]) } }) @@ -200,8 +200,7 @@ } Context.prototype.remove = function(waypoint) { - var axis = waypoint.options.horizontal ? 'horizontal' : 'vertical' - delete this.waypoints[axis][waypoint.key] + delete this.waypoints[waypoint.axis][waypoint.key] this.checkEmpty() } diff --git a/src/waypoint.js b/src/waypoint.js index d9c7f286..e1c76eb4 100644 --- a/src/waypoint.js +++ b/src/waypoint.js @@ -54,7 +54,7 @@ } Waypoint.prototype.canTriggerOnRefresh = function() { - return (!this.options.onlyOnScroll || this.offset == null) && this.enabled + return !this.options.onlyOnScroll || this.triggerPoint == null } Waypoint.defaults = { diff --git a/test/waypoint-spec.js b/test/waypoint-spec.js index 3711d9af..6edf3272 100644 --- a/test/waypoint-spec.js +++ b/test/waypoint-spec.js @@ -18,7 +18,7 @@ describe('Waypoint', function() { }) afterEach(function() { - if (waypoint && waypoint.destroy) { + if (waypoint) { waypoint.destroy() } $scroller.scrollTop(0).scrollLeft(0) @@ -46,6 +46,23 @@ describe('Waypoint', function() { new Waypoint({}) }).toThrow() }) + + it('triggers down on new already-reached waypoints', function() { + runs(function() { + $target = $('#same2') + $scroller.scrollTop($target.offset().top + 1) + }) + waits(standard) + runs(function() { + waypoint = new Waypoint({ + element: $target[0], + handler: function(direction) { + hit = direction === 'down' + } + }) + }) + waitsFor(hitToBeTrue, 'callback to trigger') + }) }) describe('handler option', function() { @@ -176,8 +193,132 @@ describe('Waypoint', function() { }) describe('context option', function() { - it('needs specs', function() { - expect('implemented').toBeFalsy() + beforeEach(function() { + $scroller = $('#bottom') + $target = $('#inner3') + }) + + it('works with px offset', function() { + waypoint = new Waypoint({ + element: $target[0], + handler: setHitTrue, + context: $scroller[0], + offset: 10 + }) + runs(function() { + $scroller.scrollTop(189) + }) + waits(standard) + runs(function() { + expect(hit).toBeFalsy() + $scroller.scrollTop(190) + }) + waitsFor(hitToBeTrue, 'callback to trigger') + }) + + it('works with % offset', function() { + waypoint = new Waypoint({ + element: $target[0], + handler: setHitTrue, + context: $scroller[0], + offset: '100%' + }) + runs(function() { + $scroller.scrollTop(149) + }) + waits(standard) + runs(function() { + expect(hit).toBeFalsy() + $scroller.scrollTop(150) + }) + waitsFor(hitToBeTrue, 'callback to trigger') + }) + + it('works with function offset', function() { + waypoint = new Waypoint({ + element: $target[0], + handler: setHitTrue, + context: $scroller[0], + offset: function() { + return this.$element.height() / 2 + } + }) + runs(function() { + $scroller.scrollTop(149) + }) + waits(standard) + runs(function() { + expect(hit).toBeFalsy() + $scroller.scrollTop(150) + }) + waitsFor(hitToBeTrue, 'callback to trigger') + }) + + it('works with bottom-in-view offset alias', function() { + waypoint = new Waypoint({ + element: $target[0], + handler: setHitTrue, + context: $scroller[0], + offset: 'bottom-in-view' + }) + runs(function() { + $scroller.scrollTop(249) + }) + waits(standard) + runs(function() { + expect(hit).toBeFalsy() + $scroller.scrollTop(250) + }) + waitsFor(hitToBeTrue, 'callback to trigger') + }) + }) + + describe('horizontal option', function() { + var currentDirection + + beforeEach(function() { + currentDirection = null + $target = $('#same1') + waypoint = new Waypoint({ + element: $target[0], + horizontal: true, + handler: function(direction) { + currentDirection = direction + } + }) + }) + + it('triggers right/left directions', function() { + runs(function() { + $scroller.scrollLeft($target.offset().left) + }) + waitsFor(function() { + return currentDirection === 'right' + }, 'right direction to trigger') + runs(function() { + $scroller.scrollLeft($target.offset().left - 1) + }) + waitsFor(function() { + return currentDirection === 'left' + }) + }) + }) + + describe('with window as the waypoint element', function() { + beforeEach(function() { + $target = $(window) + waypoint = new Waypoint({ + element: $target[0], + offset: -$target.height(), + handler: setHitTrue + }) + }) + + it('triggers waypoint', function() { + runs(function() { + $target.scrollTop($target.height() + 1) + }) + waitsFor(hitToBeTrue, 'callback to trigger') }) }) From 982eb15d7032f96566321f61172feae66c79b58b Mon Sep 17 00:00:00 2001 From: imakewebthings Date: Wed, 28 May 2014 15:41:29 -0700 Subject: [PATCH 07/98] New refresh signatures --- src/context.js | 16 ++++++++- src/waypoint.js | 29 ++++++++++------- test/context-spec.js | 75 +++++++++++++++++++++++++++++++++++++++++++ test/waypoint-spec.js | 8 +++++ 4 files changed, 116 insertions(+), 12 deletions(-) create mode 100644 test/context-spec.js diff --git a/src/context.js b/src/context.js index 8ecacea6..c3295017 100644 --- a/src/context.js +++ b/src/context.js @@ -113,7 +113,7 @@ } Context.prototype.handleResize = function() { - + Waypoint.refresh() } Context.prototype.refresh = function() { @@ -191,19 +191,24 @@ } }) }, this)) + + return this } + /* Internal */ Context.prototype.add = function(waypoint) { var axis = waypoint.options.horizontal ? 'horizontal' : 'vertical' this.waypoints[axis][waypoint.key] = waypoint this.refresh() } + /* Internal */ Context.prototype.remove = function(waypoint) { delete this.waypoints[waypoint.axis][waypoint.key] this.checkEmpty() } + /* Internal */ Context.prototype.checkEmpty = function() { var horizontalEmpty = $.isEmptyObject(this.waypoints.horizontal) var verticalEmpty = $.isEmptyObject(this.waypoints.vertical) @@ -213,6 +218,7 @@ } } + /* Internal */ Context.prototype.height = function() { if ($.isWindow(this.element)) { return Waypoint.viewportHeight() @@ -220,10 +226,18 @@ return this.$element.height() } + Context.refreshAll = function() { + $.each(contexts, function(contextId, context) { + context.refresh() + }) + } + + /* Internal */ Context.findByElement = function(element) { return contexts[element.waypointContextKey] } + /* Internal */ Context.findOrCreateByElement = function(element) { return Context.findByElement(element) || new Context(element) } diff --git a/src/waypoint.js b/src/waypoint.js index e1c76eb4..d5c41f61 100644 --- a/src/waypoint.js +++ b/src/waypoint.js @@ -26,17 +26,6 @@ keyCounter += 1 } - Waypoint.prototype.trigger = function(args) { - if (!this.enabled) { - return - } - if (this.callback) { - this.callback.apply(this.element, args) - } - if (this.options.triggerOnce) { - this.destroy() - } - } Waypoint.prototype.disable = function() { this.enabled = false @@ -53,10 +42,24 @@ this.context.remove(this) } + /* Internal */ Waypoint.prototype.canTriggerOnRefresh = function() { return !this.options.onlyOnScroll || this.triggerPoint == null } + /* Internal */ + Waypoint.prototype.trigger = function(args) { + if (!this.enabled) { + return + } + if (this.callback) { + this.callback.apply(this.element, args) + } + if (this.options.triggerOnce) { + this.destroy() + } + } + Waypoint.defaults = { context: window, continuous: true, @@ -83,5 +86,9 @@ return window.innerHeight || document.documentElement.clientHeight } + Waypoint.refresh = function() { + Waypoint.Context.refreshAll() + } + window.Waypoint = Waypoint })() diff --git a/test/context-spec.js b/test/context-spec.js new file mode 100644 index 00000000..51e5f480 --- /dev/null +++ b/test/context-spec.js @@ -0,0 +1,75 @@ +describe('Waypoint.Context', function() { + var standard = 50 + var currentDirection, $scroller, waypoint, $target, context + + function setDirection(direction) { + currentDirection = direction + } + + function hasDirection() { + return currentDirection != null + } + + beforeEach(function() { + loadFixtures('standard.html') + $scroller = $(window) + currentDirection = null + $target = $('#same1') + waypoint = new Waypoint({ + element: $target[0], + handler: setDirection + }) + context = waypoint.context + }) + + afterEach(function() { + waypoint.destroy() + $scroller.scrollTop(0).scrollLeft(0) + waits(standard) + }) + + describe('#refresh', function() { + it('updates trigger point of waypoints', function() { + var top = $target.offset().top + $target.css({ + top: top + 1 + }) + context.refresh() + expect(waypoint.triggerPoint).toEqual(top + 1) + }) + + it('triggers down direction if waypoint crosses upwards', function() { + $target.css('top', '-1px') + context.refresh() + expect(currentDirection).toEqual('down') + }) + + it('triggers up direction if waypoint crosses downwards', function() { + $target.css('top', '-1px') + context.refresh() + $target.css('top', '0px') + context.refresh() + expect(currentDirection).toEqual('up') + }) + + it('returns the same context instance for chaining', function() { + expect(context.refresh()).toEqual(context) + }) + }) + + describe('Waypoint.Context.refreshAll()', function() { + it('calls refresh on all contexts', function() { + var secondWaypoint = new Waypoint({ + element: $('#inner3')[0], + context: $('#bottom')[0] + }) + var secondContext = secondWaypoint.context + spyOn(context, 'refresh') + spyOn(secondContext, 'refresh') + Waypoint.Context.refreshAll() + expect(context.refresh).toHaveBeenCalled() + expect(secondContext.refresh).toHaveBeenCalled() + secondWaypoint.destroy() + }) + }) +}) diff --git a/test/waypoint-spec.js b/test/waypoint-spec.js index 6edf3272..60c0ebe8 100644 --- a/test/waypoint-spec.js +++ b/test/waypoint-spec.js @@ -406,4 +406,12 @@ describe('Waypoint', function() { } }) }) + + describe('Waypoint.refresh()', function() { + it('is an alias for Waypoint.Context.refreshAll', function() { + spyOn(Waypoint.Context, 'refreshAll') + Waypoint.refresh() + expect(Waypoint.Context.refreshAll).toHaveBeenCalled() + }) + }) }) From 8dabe8b2c6a7871c494e162d4158f90ce7a2bfc9 Mon Sep 17 00:00:00 2001 From: imakewebthings Date: Mon, 9 Jun 2014 12:56:05 -0700 Subject: [PATCH 08/98] Add waypoint Groups for continuous and next/prev grouping --- src/context.js | 50 +++++++++------------- src/group.js | 97 +++++++++++++++++++++++++++++++++++++++++++ src/waypoint.js | 17 ++++++-- test/group-spec.js | 72 ++++++++++++++++++++++++++++++++ test/waypoint-spec.js | 57 +++++++++++++++++++++++++ testem.json | 3 +- 6 files changed, 260 insertions(+), 36 deletions(-) create mode 100644 src/group.js create mode 100644 test/group-spec.js diff --git a/src/context.js b/src/context.js index c3295017..17c96f6c 100644 --- a/src/context.js +++ b/src/context.js @@ -54,6 +54,7 @@ } Context.prototype.handleScroll = function(options) { + var triggeredGroups = {} var axes = { horizontal: { newScroll: this.$element.scrollLeft(), @@ -68,18 +69,8 @@ backward: 'up' } } - var atTop = !axes.vertical.oldScroll || !axes.vertical.newScroll - var skipIOSRefresh = options && options.skipIOSRefresh - - /* Hack for iOS, needed because scrolls in mobile Safari that start - * or end with the URL bar showing will cause window height to change - * without firing a resize event. */ - if (Waypoint.isTouch && atTop && !skipIOSRefresh) { - this.refresh() - } $.each(axes, $.proxy(function(axisKey, axis) { - var triggered = [] var isForward = axis.newScroll > axis.oldScroll var direction = isForward ? axis.forward : axis.backward @@ -89,23 +80,16 @@ var crossedForward = wasBeforeTriggerPoint && nowAfterTriggerPoint var crossedBackward = !wasBeforeTriggerPoint && !nowAfterTriggerPoint if (crossedForward || crossedBackward) { - triggered.push(waypoint) - } - }) - - triggered.sort(function(a, b) { - return a.triggerPoint - b.triggerPoint - }) - if (!isForward) { - triggered.reverse() - } - $.each(triggered, function(i, waypoint) { - if (waypoint.options.continuous || i === triggered.length - 1) { - waypoint.trigger([direction]) + waypoint.queueTrigger(direction) + triggeredGroups[waypoint.group.id] = waypoint.group } }) }, this)) + $.each(triggeredGroups, function(key, group) { + group.flushTriggers() + }) + this.oldScroll = { x: axes.horizontal.newScroll, y: axes.vertical.newScroll @@ -113,18 +97,17 @@ } Context.prototype.handleResize = function() { - Waypoint.refresh() + Waypoint.Context.refreshAll() } Context.prototype.refresh = function() { var isWindow = $.isWindow(this.element) var contextOffset = this.$element.offset() var height = isWindow ? Waypoint.viewportHeight() : this.$element.height() + var triggeredGroups = {} var axes - this.handleScroll({ - skipIOSRefresh: true - }) + this.handleScroll() axes = { horizontal: { contextOffset: isWindow ? 0 : contextOffset.left, @@ -181,17 +164,24 @@ var triggeredBackward = wasBeforeScroll && nowAfterScroll var triggeredForward = !wasBeforeScroll && !nowAfterScroll if (!freshWaypoint && triggeredBackward) { - waypoint.trigger([axis.backward]) + waypoint.queueTrigger(axis.backward) + triggeredGroups[waypoint.group.id] = waypoint.group } else if (!freshWaypoint && triggeredForward) { - waypoint.trigger([axis.forward]) + waypoint.queueTrigger(axis.forward) + triggeredGroups[waypoint.group.id] = waypoint.group } else if (freshWaypoint && axis.oldScroll >= waypoint.triggerPoint) { - waypoint.trigger([axis.forward]) + waypoint.queueTrigger(axis.forward) + triggeredGroups[waypoint.group.id] = waypoint.group } }) }, this)) + $.each(triggeredGroups, function(key, group) { + group.flushTriggers() + }) + return this } diff --git a/src/group.js b/src/group.js new file mode 100644 index 00000000..54abbc5c --- /dev/null +++ b/src/group.js @@ -0,0 +1,97 @@ +(function() { + function byTriggerPoint(a, b) { + return a.triggerPoint - b.triggerPoint + } + + function byReverseTriggerPoint(a, b) { + return b.triggerPoint - a.triggerPoint + } + + var groups = { + vertical: {}, + horizontal: {} + } + + var Group = function(options) { + this.name = options.name + this.axis = options.axis + this.id = this.name + '-' + this.axis + this.waypoints = [] + this.clearTriggerQueues() + groups[this.axis][this.name] = this + } + + Group.prototype.previous = function(waypoint) { + this.sort() + var index = $.inArray(waypoint, this.waypoints) + return index ? this.waypoints[index - 1] : null + } + + Group.prototype.next = function(waypoint) { + this.sort() + var index = $.inArray(waypoint, this.waypoints) + var isLast = index === this.waypoints.length - 1 + return isLast ? null : this.waypoints[index + 1] + } + + Group.prototype.first = function() { + return this.waypoints[0] + } + + Group.prototype.last = function() { + return this.waypoints[this.waypoints.length - 1] + } + + /* Internal */ + Group.prototype.add = function(waypoint) { + this.waypoints.push(waypoint) + } + + /* Internal */ + Group.prototype.remove = function(waypoint) { + this.waypoints.splice($.inArray(waypoint), 1) + } + + /* Internal */ + Group.prototype.sort = function() { + this.waypoints.sort(function(a, b) { + return a.triggerPoint - b.triggerPoint + }) + } + + /* Internal */ + Group.prototype.clearTriggerQueues = function() { + this.triggerQueues = { + up: [], + down: [], + left: [], + right: [] + } + } + + /* Internal */ + Group.prototype.queueTrigger = function(waypoint, direction) { + this.triggerQueues[direction].push(waypoint) + } + + /* Internal */ + Group.prototype.flushTriggers = function() { + $.each(this.triggerQueues, function(direction, waypoints) { + var reverse = direction === 'up' || direction === 'left' + waypoints.sort(reverse ? byReverseTriggerPoint : byTriggerPoint) + $.each(waypoints, function(i, waypoint) { + if (waypoint.options.continuous || i === waypoints.length - 1) { + waypoint.trigger([direction]) + } + }) + }) + this.clearTriggerQueues() + } + + /* Internal */ + Group.findOrCreate = function(options) { + return groups[options.axis][options.name] || new Group(options) + } + + window.Waypoint.Group = Group +})() diff --git a/src/waypoint.js b/src/waypoint.js index d5c41f61..4f7a28d4 100644 --- a/src/waypoint.js +++ b/src/waypoint.js @@ -17,16 +17,20 @@ this.axis = this.options.horizontal ? 'horizontal' : 'vertical' this.enabled = this.options.enabled this.triggerPoint = null + this.group = Waypoint.Group.findOrCreate({ + name: this.options.group, + axis: this.axis + }) this.context = Waypoint.Context.findOrCreateByElement(this.options.context) if (Waypoint.offsetAliases[this.options.offset]) { this.options.offset = Waypoint.offsetAliases[this.options.offset] } this.context.add(this) + this.group.add(this) keyCounter += 1 } - Waypoint.prototype.disable = function() { this.enabled = false return this @@ -40,6 +44,7 @@ Waypoint.prototype.destroy = function() { this.context.remove(this) + this.group.remove(this) } /* Internal */ @@ -53,17 +58,23 @@ return } if (this.callback) { - this.callback.apply(this.element, args) + this.callback.apply(this, args) } if (this.options.triggerOnce) { this.destroy() } } + /* Internal */ + Waypoint.prototype.queueTrigger = function(direction) { + this.group.queueTrigger(this, direction) + } + Waypoint.defaults = { context: window, continuous: true, enabled: true, + group: 'default', horizontal: false, offset: 0, triggerOnce: false @@ -80,8 +91,6 @@ } } - Waypoint.isTouch = 'ontouchstart' in window - Waypoint.viewportHeight = function() { return window.innerHeight || document.documentElement.clientHeight } diff --git a/test/group-spec.js b/test/group-spec.js new file mode 100644 index 00000000..33d85032 --- /dev/null +++ b/test/group-spec.js @@ -0,0 +1,72 @@ +describe('Waypoint.Group', function() { + var standard = 50 + var currentDirection, firstWaypoint, secondWaypoint, customGroupWaypoint + var defaultGroup, customGroup + + function setDirection(direction) { + currentDirection = direction + } + + function hasDirection() { + return currentDirection != null + } + + beforeEach(function() { + loadFixtures('standard.html') + currentDirection = null + firstWaypoint = new Waypoint({ + element: $('#same1')[0], + handler: setDirection + }) + secondWaypoint = new Waypoint({ + element: $('#near1')[0], + handler: setDirection + }) + customGroupWaypoint = new Waypoint({ + element: $('#same2')[0], + handler: setDirection, + group: 'custom' + }) + defaultGroup = firstWaypoint.group + customGroup = customGroupWaypoint.group + }) + + afterEach(function() { + firstWaypoint.destroy() + secondWaypoint.destroy() + customGroupWaypoint.destroy() + waits(standard) + }) + + describe('#previous(waypoint)', function() { + it('returns previous waypoint based on trigger point', function() { + expect(defaultGroup.previous(secondWaypoint)).toEqual(firstWaypoint) + }) + + it('returns null if on the first waypoint in the group', function() { + expect(defaultGroup.previous(firstWaypoint)).toBeNull() + }) + }) + + describe('#next(waypoint)', function() { + it('returns next waypoint based on trigger point', function() { + expect(defaultGroup.next(firstWaypoint)).toEqual(secondWaypoint) + }) + + it('returns null if on the last waypoint in the group', function() { + expect(defaultGroup.next(secondWaypoint)).toBeNull() + }) + }) + + describe('#first()', function() { + it('returns the first waypoint based on trigger point', function() { + expect(defaultGroup.first()).toEqual(firstWaypoint) + }) + }) + + describe('#last()', function() { + it('returns the first waypoint based on trigger point', function() { + expect(defaultGroup.last()).toEqual(secondWaypoint) + }) + }) +}) diff --git a/test/waypoint-spec.js b/test/waypoint-spec.js index 60c0ebe8..434d1b63 100644 --- a/test/waypoint-spec.js +++ b/test/waypoint-spec.js @@ -304,6 +304,63 @@ describe('Waypoint', function() { }) }) + describe('continuous option', function() { + var $later, laterWaypoint, hitCount, hitWaypoint + + function incrementHitCount(direction) { + hitCount += 1 + hitWaypoint = this + } + + beforeEach(function() { + $target = $('#same1') + $later = $('#near1') + hitCount = 0 + waypoint = new Waypoint({ + element: $target[0], + continuous: false, + handler: incrementHitCount + }) + laterWaypoint = new Waypoint({ + element: $later[0], + continuous: false, + handler: incrementHitCount + }) + }) + + afterEach(function() { + laterWaypoint.destroy() + }) + + it('does not trigger the earlier waypoint', function() { + runs(function() { + $scroller.scrollTop($later.offset().top) + }) + waitsFor(function() { + return hitCount + }, 'later callback to trigger') + runs(function() { + expect(hitCount).toEqual(1) + expect(hitWaypoint).toEqual(laterWaypoint) + }) + }) + + it('prevents earlier trigger on refresh', function() { + runs(function() { + $target.css('top', '-1px') + $later.css('top', '-2px') + Waypoint.refresh() + }) + waitsFor(function() { + return hitCount + }, 'later callback to trigger') + runs(function() { + expect(hitCount).toEqual(1) + expect(hitWaypoint).toEqual(waypoint) + }) + }) + }) + describe('with window as the waypoint element', function() { beforeEach(function() { $target = $(window) diff --git a/testem.json b/testem.json index 0e5e80a9..47861f15 100644 --- a/testem.json +++ b/testem.json @@ -13,10 +13,9 @@ "lib/waypoints-infinite.js", "lib/waypoints-sticky.js", - "src/waypoint.js", "src/context.js", - + "src/group.js", "test/settings.js", "test/*-spec.js" From 109852243d8c8d89758015939a3f23af91673a20 Mon Sep 17 00:00:00 2001 From: imakewebthings Date: Wed, 11 Jun 2014 15:16:23 -0700 Subject: [PATCH 09/98] Waypoint.Sticky shortcut --- src/shortcuts/sticky.js | 49 +++++++++++++++++++++++ test/sticky-spec.js | 86 +++++++++++++++++++++++++++++++++++++++++ testem.json | 1 + 3 files changed, 136 insertions(+) create mode 100644 src/shortcuts/sticky.js create mode 100644 test/sticky-spec.js diff --git a/src/shortcuts/sticky.js b/src/shortcuts/sticky.js new file mode 100644 index 00000000..763a1b18 --- /dev/null +++ b/src/shortcuts/sticky.js @@ -0,0 +1,49 @@ +(function() { + var Sticky = function(options) { + this.options = $.extend({}, Waypoint.defaults, Sticky.defaults, options) + this.element = this.options.element + this.$element = $(this.element) + this.createWrapper() + this.createWaypoint() + } + + Sticky.prototype.destroy = function() { + this.waypoint.destroy() + this.$element.removeClass(this.options.stuckClass).unwrap() + } + + /* Internal */ + Sticky.prototype.createWrapper = function() { + this.$element.wrap(this.options.wrapper) + this.$wrapper = this.$element.parent() + this.wrapper = this.$wrapper[0] + } + + /* Internal */ + Sticky.prototype.createWaypoint = function() { + var originalHandler = this.options.handler + + this.waypoint = new Waypoint($.extend({}, this.options, { + element: this.wrapper, + handler: $.proxy(function(direction) { + var shouldBeStuck = this.options.direction.indexOf(direction) > -1 + var wrapperHeight = shouldBeStuck ? this.$element.outerHeight(true) : '' + + this.$element.toggleClass(this.options.stuckClass, shouldBeStuck) + this.$wrapper.height(wrapperHeight) + + if (originalHandler) { + originalHandler.call(this, direction) + } + }, this) + })) + } + + Sticky.defaults = { + wrapper: '
', + stuckClass: 'stuck', + direction: 'down right' + } + + window.Waypoint.Sticky = Sticky +})() diff --git a/test/sticky-spec.js b/test/sticky-spec.js new file mode 100644 index 00000000..47b2a30a --- /dev/null +++ b/test/sticky-spec.js @@ -0,0 +1,86 @@ +describe('Waypoint Sticky Shortcut', function() { + var standard = 50 + var $scroller = $(window) + var $sticky, waypoint, handlerSpy + + beforeEach(function() { + loadFixtures('sticky.html') + $sticky = $('.sticky') + handlerSpy = jasmine.createSpy('on handler') + waypoint = new Waypoint.Sticky({ + element: $sticky[0], + handler: handlerSpy + }) + }) + + afterEach(function() { + $scroller.scrollTop(0) + waits(standard) + }) + + describe('on init', function() { + afterEach(function() { + waypoint.destroy() + }) + + it('returns an instance of the Waypoint.Sticky class', function() { + expect(waypoint instanceof Waypoint.Sticky).toBeTruthy() + }) + + it('wraps the sticky element on init', function() { + expect($sticky.parent()).toHaveClass('sticky-wrapper') + }) + + describe('when sticky element is scrolled to', function() { + beforeEach(function() { + runs(function() { + $scroller.scrollTop($sticky.offset().top) + }) + waitsFor(function() { + return $sticky.hasClass('stuck') + }, 'stuck class to apply') + }) + + it('adds/removes stuck class', function() { + runs(function() { + $scroller.scrollTop($scroller.scrollTop() - 1) + }) + waitsFor(function() { + return !$sticky.hasClass('stuck') + }) + }) + + it('gives the wrapper the same height as the sticky element', function() { + expect($sticky.parent().height()).toEqual($sticky.outerHeight()) + }) + + it('executes handler option after stuck class applied', function() { + waitsFor(function() { + return handlerSpy.callCount + }, 'callback to trigger') + }) + }) + }) + + describe('#destroy', function() { + beforeEach(function() { + runs(function() { + $scroller.scrollTop($sticky.offset().top) + }) + waitsFor(function() { + return handlerSpy.callCount + }) + runs(function() { + waypoint.destroy() + }) + }) + + it('unwraps the sticky element', function() { + expect($sticky.parent()).not.toHaveClass('sticky-wrapper') + }) + + it('removes the stuck class', function() { + expect($sticky).not.toHaveClass('stuck') + }) + }) +}) diff --git a/testem.json b/testem.json index 47861f15..df6de925 100644 --- a/testem.json +++ b/testem.json @@ -16,6 +16,7 @@ "src/waypoint.js", "src/context.js", "src/group.js", + "src/shortcuts/*.js", "test/settings.js", "test/*-spec.js" From 7658570dfda2f87667f2a50b1379fdbf0a1f8a64 Mon Sep 17 00:00:00 2001 From: imakewebthings Date: Wed, 11 Jun 2014 16:56:37 -0700 Subject: [PATCH 10/98] Waypoint.Infinite class --- src/shortcuts/infinite.js | 67 ++++++++++++++++++++++++++++++++++++++ test/infinite-spec.js | 68 +++++++++++++++++++++++++++++++++++++++ 2 files changed, 135 insertions(+) create mode 100644 src/shortcuts/infinite.js create mode 100644 test/infinite-spec.js diff --git a/src/shortcuts/infinite.js b/src/shortcuts/infinite.js new file mode 100644 index 00000000..eeb2332f --- /dev/null +++ b/src/shortcuts/infinite.js @@ -0,0 +1,67 @@ +(function() { + var Infinite = function(options) { + this.options = $.extend({}, Infinite.defaults, options) + this.container = this.options.element + if (this.options.container !== 'auto') { + this.container = this.options.container + } + this.$container = $(this.container) + this.$more = $(this.options.more) + this.more = this.$more[0] + + if (this.more) { + this.setupHandler() + this.waypoint = new window.Waypoint(this.options) + } + } + + Infinite.prototype.destroy = function() { + if (this.waypoint) { + this.waypoint.destroy() + } + } + + /* Internal */ + Infinite.prototype.setupHandler = function() { + this.options.handler = $.proxy(function(direction) { + window.setTimeout($.proxy(function() { + this.options.onBeforePageLoad() + this.destroy() + this.$container.addClass(this.options.loadingClass) + + $.get($(this.options.more).attr('href'), $.proxy(function(data) { + var $data = $($.parseHTML(data)) + var $newMore = $data.find(this.options.more) + + this.$container.append($data.find(this.options.items)) + this.$container.removeClass(this.options.loadingClass) + + if (!$newMore.length) { + $newMore = $data.filter(this.options.more) + } + if ($newMore.length) { + this.$more.replaceWith($newMore) + this.waypoint = new Waypoint(this.options) + } + else { + this.$more.remove() + } + + this.options.onAfterPageLoad() + }, this), 0) + }, this)) + }, this) + } + + Infinite.defaults = { + container: 'auto', + items: '.infinite-item', + more: '.infinite-more-link', + offset: 'bottom-in-view', + loadingClass: 'infinite-loading', + onBeforePageLoad: $.noop, + onAfterPageLoad: $.noop + } + + window.Waypoint.Infinite = Infinite +})() diff --git a/test/infinite-spec.js b/test/infinite-spec.js new file mode 100644 index 00000000..cb9676ac --- /dev/null +++ b/test/infinite-spec.js @@ -0,0 +1,68 @@ +describe('Waypoint Sticky Shortcut', function() { + var standard = 50 + var $scroller = $(window) + var $container, $items, $more, waypoint, beforeSpy, afterSpy + + beforeEach(function() { + loadFixtures('infinite.html') + $items = $('.infinite-item') + $container = $('.infinite-container') + $more = $('.infinite-more-link') + beforeSpy = jasmine.createSpy('on before callback') + afterSpy = jasmine.createSpy('on after callback') + }) + + afterEach(function() { + waypoint.destroy() + $scroller.scrollTop(0) + waits(standard) + }) + + it('returns an instance of the Waypoint.Infinite class', function() { + waypoint = new Waypoint.Infinite({ + element: $container[0] + }) + expect(waypoint instanceof Waypoint.Infinite).toBeTruthy() + }) + + describe('loading new pages', function() { + beforeEach(function() { + runs(function() { + waypoint = new Waypoint.Infinite({ + element: $container[0], + onBeforePageLoad: beforeSpy, + onAfterPageLoad: afterSpy + }) + $scroller.scrollTop(Waypoint.viewportHeight() - $container.height()) + }) + waitsFor(function() { + return $('.infinite-container > .infinite-item').length > $items.length + }, 'new items to load') + }) + + it('replaces the more link with the new more link', function() { + expect($more[0]).not.toEqual($('.infinite-more-link')[0]) + }) + + it('fires the before callback', function() { + expect(beforeSpy.callCount).toBeTruthy() + }) + + it('fires the after callback', function() { + expect(afterSpy.callCount).toBeTruthy() + }) + }) + + describe('when there is no more link on initialization', function() { + beforeEach(function() { + $more.remove() + waypoint = new Waypoint.Infinite({ + element: $container[0] + }) + }) + + it('does not create the waypoint', function() { + expect(waypoint.waypoint).toBeFalsy() + }) + }) +}) From dd1c05faf958c82ef43e8062339a37838742d799 Mon Sep 17 00:00:00 2001 From: imakewebthings Date: Fri, 13 Jun 2014 11:06:39 -0700 Subject: [PATCH 11/98] Refactor jQuery dependency out to an adapter --- src/adapters/jquery.js | 34 +++++++++++++ src/context.js | 109 ++++++++++++++++++++++------------------- src/group.js | 16 +++--- src/waypoint.js | 18 ++++--- test/waypoint-spec.js | 4 +- testem.json | 1 + 6 files changed, 114 insertions(+), 68 deletions(-) create mode 100644 src/adapters/jquery.js diff --git a/src/adapters/jquery.js b/src/adapters/jquery.js new file mode 100644 index 00000000..e7e1098b --- /dev/null +++ b/src/adapters/jquery.js @@ -0,0 +1,34 @@ +(function() { + var $ = jQuery + + var JQueryAdapter = function(element) { + this.$element = $(element) + } + + $.each([ + 'height', + 'off', + 'offset', + 'on', + 'outerHeight', + 'scrollLeft', + 'scrollTop', + 'width' + ], function(i, method) { + JQueryAdapter.prototype[method] = function() { + var args = Array.prototype.slice.call(arguments) + return this.$element[method].apply(this.$element, args) + } + }) + + $.each([ + 'extend', + 'inArray', + 'isEmptyObject' + ], function(i, method) { + JQueryAdapter[method] = $[method] + }) + + window.Waypoint.adapters.push(JQueryAdapter) + window.Waypoint.Adapter = JQueryAdapter +})() diff --git a/src/context.js b/src/context.js index 17c96f6c..4bb0c830 100644 --- a/src/context.js +++ b/src/context.js @@ -4,13 +4,14 @@ var Context = function(element) { this.element = element - this.$element = $(element) + this.Adapter = window.Waypoint.Adapter + this.adapter = new this.Adapter(element) this.key = 'waypoint-context-' + keyCounter this.didScroll = false this.didResize = false this.oldScroll = { - x: this.$element.scrollLeft(), - y: this.$element.scrollTop() + x: this.adapter.scrollLeft(), + y: this.adapter.scrollTop() } this.waypoints = { vertical: {}, @@ -26,55 +27,59 @@ } Context.prototype.createThrottledScrollHandler = function() { - var scrollHandler = $.proxy(function() { - this.handleScroll() - this.didScroll = false - }, this) - - this.$element.on('scroll.waypoints', $.proxy(function() { - if (!this.didScroll || Waypoint.isTouch) { - this.didScroll = true + var self = this + var scrollHandler = function() { + self.handleScroll() + self.didScroll = false + } + + this.adapter.on('scroll.waypoints', function() { + if (!self.didScroll || Waypoint.isTouch) { + self.didScroll = true window.setTimeout(scrollHandler, Waypoint.settings.scrollThrottle) } - }, this)) + }) } Context.prototype.createThrottledResizeHandler = function() { - var resizeHandler = $.proxy(function() { - this.handleResize() - this.didResize = false - }, this) - - this.$element.on('resize.waypoints', $.proxy(function() { - if (!this.didResize) { - this.didResize = true + var self = this + var resizeHandler = function() { + self.handleResize() + self.didResize = false + } + + this.adapter.on('resize.waypoints', function() { + if (!self.didResize) { + self.didResize = true window.setTimeout(resizeHandler, Waypoint.settings.resizeThrottle) } - })) + }) } Context.prototype.handleScroll = function(options) { var triggeredGroups = {} var axes = { horizontal: { - newScroll: this.$element.scrollLeft(), + newScroll: this.adapter.scrollLeft(), oldScroll: this.oldScroll.x, forward: 'right', backward: 'left' }, vertical: { - newScroll: this.$element.scrollTop(), + newScroll: this.adapter.scrollTop(), oldScroll: this.oldScroll.y, forward: 'down', backward: 'up' } } - $.each(axes, $.proxy(function(axisKey, axis) { + for (var axisKey in axes) { + var axis = axes[axisKey] var isForward = axis.newScroll > axis.oldScroll var direction = isForward ? axis.forward : axis.backward - $.each(this.waypoints[axisKey], function(waypointKey, waypoint) { + for (var waypointKey in this.waypoints[axisKey]) { + var waypoint = this.waypoints[axisKey][waypointKey] var wasBeforeTriggerPoint = axis.oldScroll < waypoint.triggerPoint var nowAfterTriggerPoint = axis.newScroll >= waypoint.triggerPoint var crossedForward = wasBeforeTriggerPoint && nowAfterTriggerPoint @@ -83,12 +88,12 @@ waypoint.queueTrigger(direction) triggeredGroups[waypoint.group.id] = waypoint.group } - }) - }, this)) + } + } - $.each(triggeredGroups, function(key, group) { - group.flushTriggers() - }) + for (var groupKey in triggeredGroups) { + triggeredGroups[groupKey].flushTriggers() + } this.oldScroll = { x: axes.horizontal.newScroll, @@ -101,9 +106,9 @@ } Context.prototype.refresh = function() { - var isWindow = $.isWindow(this.element) - var contextOffset = this.$element.offset() - var height = isWindow ? Waypoint.viewportHeight() : this.$element.height() + var isWindow = this.element === this.element.window + var contextOffset = this.adapter.offset() + var height = isWindow ? Waypoint.viewportHeight() : this.adapter.height() var triggeredGroups = {} var axes @@ -112,7 +117,7 @@ horizontal: { contextOffset: isWindow ? 0 : contextOffset.left, contextScroll: isWindow ? 0 : this.oldScroll.x, - contextDimension: this.$element.width(), + contextDimension: this.adapter.width(), oldScroll: this.oldScroll.x, forward: 'right', backward: 'left', @@ -129,8 +134,10 @@ } } - $.each(axes, $.proxy(function(axisKey, axis) { - $.each(this.waypoints[axisKey], function(i, waypoint) { + for (var axisKey in axes) { + var axis = axes[axisKey] + for (var waypointKey in this.waypoints[axisKey]) { + var waypoint = this.waypoints[axisKey][waypointKey] var adjustment = waypoint.options.offset var oldTriggerPoint = waypoint.triggerPoint var elementOffset = 0 @@ -138,8 +145,8 @@ var freshWaypoint = oldTriggerPoint == null var contextModifier - if (!$.isWindow(waypoint.element)) { - elementOffset = waypoint.$element.offset()[axis.offsetProp] + if (waypoint.element !== waypoint.element.window) { + elementOffset = waypoint.adapter.offset()[axis.offsetProp] } if (typeof adjustment === 'function') { @@ -175,12 +182,12 @@ waypoint.queueTrigger(axis.forward) triggeredGroups[waypoint.group.id] = waypoint.group } - }) - }, this)) + } + } - $.each(triggeredGroups, function(key, group) { - group.flushTriggers() - }) + for (var groupKey in triggeredGroups) { + triggeredGroups[groupKey].flushTriggers() + } return this } @@ -200,26 +207,26 @@ /* Internal */ Context.prototype.checkEmpty = function() { - var horizontalEmpty = $.isEmptyObject(this.waypoints.horizontal) - var verticalEmpty = $.isEmptyObject(this.waypoints.vertical) + var horizontalEmpty = this.Adapter.isEmptyObject(this.waypoints.horizontal) + var verticalEmpty = this.Adapter.isEmptyObject(this.waypoints.vertical) if (horizontalEmpty && verticalEmpty) { - this.$element.off('.waypoints') + this.adapter.off('.waypoints') delete contexts[this.key] } } /* Internal */ Context.prototype.height = function() { - if ($.isWindow(this.element)) { + if (this.element === this.element.window) { return Waypoint.viewportHeight() } - return this.$element.height() + return this.adapter.height() } Context.refreshAll = function() { - $.each(contexts, function(contextId, context) { - context.refresh() - }) + for (var contextId in contexts) { + contexts[contextId].refresh() + } } /* Internal */ diff --git a/src/group.js b/src/group.js index 54abbc5c..ef065c25 100644 --- a/src/group.js +++ b/src/group.js @@ -23,13 +23,13 @@ Group.prototype.previous = function(waypoint) { this.sort() - var index = $.inArray(waypoint, this.waypoints) + var index = window.Waypoint.Adapter.inArray(waypoint, this.waypoints) return index ? this.waypoints[index - 1] : null } Group.prototype.next = function(waypoint) { this.sort() - var index = $.inArray(waypoint, this.waypoints) + var index = window.Waypoint.Adapter.inArray(waypoint, this.waypoints) var isLast = index === this.waypoints.length - 1 return isLast ? null : this.waypoints[index + 1] } @@ -49,7 +49,7 @@ /* Internal */ Group.prototype.remove = function(waypoint) { - this.waypoints.splice($.inArray(waypoint), 1) + this.waypoints.splice(window.Waypoint.Adapter.inArray(waypoint), 1) } /* Internal */ @@ -76,15 +76,17 @@ /* Internal */ Group.prototype.flushTriggers = function() { - $.each(this.triggerQueues, function(direction, waypoints) { + for (var direction in this.triggerQueues) { + var waypoints = this.triggerQueues[direction] var reverse = direction === 'up' || direction === 'left' waypoints.sort(reverse ? byReverseTriggerPoint : byTriggerPoint) - $.each(waypoints, function(i, waypoint) { + for (var i = 0, end = waypoints.length; i < end; i += 1) { + var waypoint = waypoints[i] if (waypoint.options.continuous || i === waypoints.length - 1) { waypoint.trigger([direction]) } - }) - }) + } + } this.clearTriggerQueues() } diff --git a/src/waypoint.js b/src/waypoint.js index 4f7a28d4..905e2a8f 100644 --- a/src/waypoint.js +++ b/src/waypoint.js @@ -10,9 +10,9 @@ } this.key = 'waypoint-' + keyCounter - this.options = $.extend({}, Waypoint.defaults, options) + this.options = Waypoint.Adapter.extend({}, Waypoint.defaults, options) this.element = this.options.element - this.$element = $(this.element) + this.adapter = new Waypoint.Adapter(this.element) this.callback = options.handler this.axis = this.options.horizontal ? 'horizontal' : 'vertical' this.enabled = this.options.enabled @@ -70,6 +70,8 @@ this.group.queueTrigger(this, direction) } + Waypoint.adapters = [] + Waypoint.defaults = { context: window, continuous: true, @@ -80,17 +82,17 @@ triggerOnce: false } - Waypoint.settings = { - scrollThrottle: 30, - resizeThrottle: 100 - } - Waypoint.offsetAliases = { 'bottom-in-view': function() { - return this.context.height() - this.$element.outerHeight() + return this.context.height() - this.adapter.outerHeight() } } + Waypoint.settings = { + scrollThrottle: 30, + resizeThrottle: 100 + } + Waypoint.viewportHeight = function() { return window.innerHeight || document.documentElement.clientHeight } diff --git a/test/waypoint-spec.js b/test/waypoint-spec.js index 434d1b63..05afc94f 100644 --- a/test/waypoint-spec.js +++ b/test/waypoint-spec.js @@ -141,7 +141,7 @@ describe('Waypoint', function() { element: $target[0], handler: setHitTrue, offset: function() { - return -this.$element.height() + return -$(this.element).height() } }) $scroller.scrollTop($target.offset().top + $target.height() - 1) @@ -240,7 +240,7 @@ describe('Waypoint', function() { handler: setHitTrue, context: $scroller[0], offset: function() { - return this.$element.height() / 2 + return $(this.element).height() / 2 } }) runs(function() { diff --git a/testem.json b/testem.json index df6de925..82a30499 100644 --- a/testem.json +++ b/testem.json @@ -16,6 +16,7 @@ "src/waypoint.js", "src/context.js", "src/group.js", + "src/adapters/*.js", "src/shortcuts/*.js", "test/settings.js", From a0ecfede0bcf7b5455c38cb7d8180f1e27512277 Mon Sep 17 00:00:00 2001 From: imakewebthings Date: Fri, 13 Jun 2014 13:53:50 -0700 Subject: [PATCH 12/98] Use requestAnimationFrame instead of setTimeout throttle if supported, #242 --- src/context.js | 13 +++++++++++-- src/waypoint.js | 5 ----- 2 files changed, 11 insertions(+), 7 deletions(-) diff --git a/src/context.js b/src/context.js index 4bb0c830..6e33cd70 100644 --- a/src/context.js +++ b/src/context.js @@ -1,7 +1,16 @@ (function() { + function requestAnimationFrameShim(callback) { + window.setTimeout(callback, 1000 / 60) + } + var keyCounter = 0 var contexts = {} + var requestAnimationFrame = window.requestAnimationFrame || + window.mozRequestAnimationFrame || + window.webkitRequestAnimationFrame || + requestAnimationFrameShim + var Context = function(element) { this.element = element this.Adapter = window.Waypoint.Adapter @@ -36,7 +45,7 @@ this.adapter.on('scroll.waypoints', function() { if (!self.didScroll || Waypoint.isTouch) { self.didScroll = true - window.setTimeout(scrollHandler, Waypoint.settings.scrollThrottle) + requestAnimationFrame(scrollHandler) } }) } @@ -51,7 +60,7 @@ this.adapter.on('resize.waypoints', function() { if (!self.didResize) { self.didResize = true - window.setTimeout(resizeHandler, Waypoint.settings.resizeThrottle) + requestAnimationFrame(resizeHandler) } }) } diff --git a/src/waypoint.js b/src/waypoint.js index 905e2a8f..ee534056 100644 --- a/src/waypoint.js +++ b/src/waypoint.js @@ -88,11 +88,6 @@ } } - Waypoint.settings = { - scrollThrottle: 30, - resizeThrottle: 100 - } - Waypoint.viewportHeight = function() { return window.innerHeight || document.documentElement.clientHeight } From 54f41e6501af62a598ab847977b3a8a735319842 Mon Sep 17 00:00:00 2001 From: imakewebthings Date: Sat, 14 Jun 2014 22:48:59 -0700 Subject: [PATCH 13/98] Inview shortcut intermediate checkin --- src/shortcuts/inview.js | 62 +++++++++++++++++ test/inview-spec.js | 144 ++++++++++++++++++++++++++++++++++++++++ 2 files changed, 206 insertions(+) create mode 100644 src/shortcuts/inview.js create mode 100644 test/inview-spec.js diff --git a/src/shortcuts/inview.js b/src/shortcuts/inview.js new file mode 100644 index 00000000..6bf6c1e9 --- /dev/null +++ b/src/shortcuts/inview.js @@ -0,0 +1,62 @@ +(function() { + function noop() {} + + var Inview = function(options) { + this.options = window.Waypoint.Adapter.extend({}, Inview.defaults, options) + this.waypoints = [] + this.createWaypoints() + } + + Inview.prototype.destroy = function() { + for (var i = 0, end = this.waypoints.length; i < end; i++) { + this.waypoints[i].destroy() + } + this.waypoints = [] + } + + /* Internal */ + Inview.prototype.createWaypoints = function() { + var self = this + var configs = [{ + down: 'enter', + up: 'exited', + offset: '100%' + }, { + down: 'entered', + up: 'exit', + offset: 'bottom-in-view' + }, { + down: 'exit', + up: 'entered', + offset: 0 + }, { + down: 'exited', + up: 'enter', + offset: function() { + return -this.adapter.outerHeight() + } + }] + + for (var i = 0, end = configs.length; i < end; i++) { + var config = configs[i] + this.waypoints.push(new Waypoint({ + element: this.options.element, + handler: (function(config) { + return function(direction) { + self.options[config[direction]].call(this, direction) + } + })(config), + offset: config.offset + })) + } + } + + Inview.defaults = { + enter: noop, + entered: noop, + exit: noop, + exited: noop + } + + window.Waypoint.Inview = Inview +})() diff --git a/test/inview-spec.js b/test/inview-spec.js new file mode 100644 index 00000000..7d98d706 --- /dev/null +++ b/test/inview-spec.js @@ -0,0 +1,144 @@ +describe('Waypoints Inview Shortcut', function() { + var standard = 50 + var $scroller = $(window) + var $target, waypoint, hits + + function setsTrue(key) { + return function() { + hits[key] = true + } + } + + function setsEnter() { + hits.enter = true + } + + function setsEntered() { + hits.entered = true + } + + function setsExit() { + hits.exit = true + } + + function setsExited() { + hits.exited = true + } + + function toBeTrue(key) { + return function() { + return hits[key] + } + } + + beforeEach(function() { + loadFixtures('standard.html') + $target = $('#near2') + hits = {} + waypoint = new Waypoint.Inview({ + element: $target[0], + enter: setsTrue('enter'), + entered: setsTrue('entered'), + exit: setsTrue('exit'), + exited: setsTrue('exited') + }) + }) + + afterEach(function() { + waypoint.destroy() + $scroller.scrollTop(0).scrollLeft(0) + waits(standard) + }) + + describe('vertical', function() { + + describe('enter callback', function() { + it('triggers when element starts entering from below', function() { + runs(function() { + $scroller.scrollTop($target.offset().top - Waypoint.viewportHeight()) + }) + waitsFor(toBeTrue('enter'), 'enter to trigger') + }) + + it('triggers when element starts entering from above', function() { + runs(function() { + $scroller.scrollTop($target.offset().top + $target.outerHeight()) + }) + waits(standard) + runs(function() { + hits.enter = false + $scroller.scrollTop($scroller.scrollTop() - 1) + }) + waitsFor(toBeTrue('enter'), 'enter to trigger') + }) + }) + + describe('entered callback', function() { + it('triggers when element finishes entering from below', function() { + runs(function() { + var top = $target.offset().top + var viewportHeight = Waypoint.viewportHeight() + var elementHeight = $target.outerHeight() + $scroller.scrollTop(top - viewportHeight + elementHeight) + }) + waitsFor(toBeTrue('entered'), 'entered to trigger') + }) + + it('triggers when element finishes entering from above', function() { + runs(function() { + $scroller.scrollTop($target.offset().top) + }) + waits(standard) + runs(function() { + hits.entered = false + $scroller.scrollTop($scroller.scrollTop() - 1) + }) + waitsFor(toBeTrue('entered'), 'entered to trigger') + }) + }) + + xdescribe('exit callback', function() { + it('triggers when element starts leaving below', function() { + runs(function() { + var top = $target.offset().top + var viewportHeight = Waypoint.viewportHeight() + var elementHeight = $target.outerHeight() + $scroller.scrollTop(top - viewportHeight + elementHeight) + }) + waits(standard) + runs(function() { + expect(hits.exit).toBeFalsy() + $scroller.scrollTop($scroller.scrollTop() - 1) + }) + waitsFor(toBeTrue('exit'), 'exit to trigger') + }) + + xit('triggers when element starts leaving above', function() { + runs(function() { + $scroller.scrollTop($target.offset().top) + }) + waitsFor(toBeTrue('exit'), 'exit to trigger') + }) + }) + + describe('exited callback', function() { + it('triggers when element finishes exiting below', function() { + runs(function() { + $scroller.scrollTop($target.offset().top - Waypoint.viewportHeight()) + }) + waits(standard) + runs(function() { + $scroller.scrollTop($scroller.scrollTop() - 1) + }) + waitsFor(toBeTrue('exited'), 'exited to trigger') + }) + + it('triggers when element finishes exiting above', function() { + runs(function() { + $scroller.scrollTop($target.offset().top + $target.outerHeight()) + }) + waitsFor(toBeTrue('exited'), 'exited to trigger') + }) + }) + }) +}) From f1b7ddb092eb1379b8c527a746f7e08edfc7b9b1 Mon Sep 17 00:00:00 2001 From: imakewebthings Date: Mon, 16 Jun 2014 17:19:21 -0700 Subject: [PATCH 14/98] Inview intermediate checkin --- src/adapters/jquery.js | 1 + src/shortcuts/inview.js | 92 ++++++++++++++++++++---------- test/inview-spec.js | 123 +++++++++++++++++++++++++++++++++++++--- 3 files changed, 176 insertions(+), 40 deletions(-) diff --git a/src/adapters/jquery.js b/src/adapters/jquery.js index e7e1098b..4d5fc770 100644 --- a/src/adapters/jquery.js +++ b/src/adapters/jquery.js @@ -11,6 +11,7 @@ 'offset', 'on', 'outerHeight', + 'outerWidth', 'scrollLeft', 'scrollTop', 'width' diff --git a/src/shortcuts/inview.js b/src/shortcuts/inview.js index 6bf6c1e9..9cd15b21 100644 --- a/src/shortcuts/inview.js +++ b/src/shortcuts/inview.js @@ -3,6 +3,7 @@ var Inview = function(options) { this.options = window.Waypoint.Adapter.extend({}, Inview.defaults, options) + this.axis = this.options.horizontal ? 'horizontal' : 'vertical' this.waypoints = [] this.createWaypoints() } @@ -16,41 +17,70 @@ /* Internal */ Inview.prototype.createWaypoints = function() { - var self = this - var configs = [{ - down: 'enter', - up: 'exited', - offset: '100%' - }, { - down: 'entered', - up: 'exit', - offset: 'bottom-in-view' - }, { - down: 'exit', - up: 'entered', - offset: 0 - }, { - down: 'exited', - up: 'enter', - offset: function() { - return -this.adapter.outerHeight() - } - }] + var configs = { + vertical: [{ + down: 'enter', + up: 'exited', + offset: '100%' + }, { + down: 'entered', + up: 'exit', + offset: 'bottom-in-view' + }, { + down: 'exit', + up: 'entered', + offset: 0 + }, { + down: 'exited', + up: 'enter', + offset: function() { + return -this.adapter.outerHeight() + } + }], + horizontal: [{ + right: 'enter', + left: 'exited', + offset: '100%' + }, { + right: 'entered', + left: 'exit', + offset: function() { + return this.context.adapter.width() - this.adapter.width() + } + }, { + right: 'exit', + left: 'entered', + offset: 0 + }, { + right: 'exited', + left: 'enter', + offset: function() { + return -this.adapter.outerWidth() + } + }] + } - for (var i = 0, end = configs.length; i < end; i++) { - var config = configs[i] - this.waypoints.push(new Waypoint({ - element: this.options.element, - handler: (function(config) { - return function(direction) { - self.options[config[direction]].call(this, direction) - } - })(config), - offset: config.offset - })) + for (var i = 0, end = configs[this.axis].length; i < end; i++) { + var config = configs[this.axis][i] + this.createWaypoint(config) } } + /* Internal */ + Inview.prototype.createWaypoint = function(config) { + var self = this + this.waypoints.push(new Waypoint({ + element: this.options.element, + handler: (function(config) { + return function(direction) { + self.options[config[direction]].call(this, direction) + } + })(config), + offset: config.offset, + horizontal: this.options.horizontal + })) + } + Inview.defaults = { enter: noop, entered: noop, diff --git a/test/inview-spec.js b/test/inview-spec.js index 7d98d706..47db63f8 100644 --- a/test/inview-spec.js +++ b/test/inview-spec.js @@ -35,13 +35,6 @@ describe('Waypoints Inview Shortcut', function() { loadFixtures('standard.html') $target = $('#near2') hits = {} - waypoint = new Waypoint.Inview({ - element: $target[0], - enter: setsTrue('enter'), - entered: setsTrue('entered'), - exit: setsTrue('exit'), - exited: setsTrue('exited') - }) }) afterEach(function() { @@ -51,6 +44,15 @@ describe('Waypoints Inview Shortcut', function() { }) describe('vertical', function() { + beforeEach(function() { + waypoint = new Waypoint.Inview({ + element: $target[0], + enter: setsTrue('enter'), + entered: setsTrue('entered'), + exit: setsTrue('exit'), + exited: setsTrue('exited') + }) + }) describe('enter callback', function() { it('triggers when element starts entering from below', function() { @@ -97,7 +99,7 @@ describe('Waypoints Inview Shortcut', function() { }) }) - xdescribe('exit callback', function() { + describe('exit callback', function() { it('triggers when element starts leaving below', function() { runs(function() { var top = $target.offset().top @@ -113,7 +115,7 @@ describe('Waypoints Inview Shortcut', function() { waitsFor(toBeTrue('exit'), 'exit to trigger') }) - xit('triggers when element starts leaving above', function() { + it('triggers when element starts leaving above', function() { runs(function() { $scroller.scrollTop($target.offset().top) }) @@ -141,4 +143,107 @@ describe('Waypoints Inview Shortcut', function() { }) }) }) + + describe('horizontal', function() { + beforeEach(function() { + waypoint = new Waypoint.Inview({ + horizontal: true, + element: $target[0], + enter: setsTrue('enter'), + entered: setsTrue('entered'), + exit: setsTrue('exit'), + exited: setsTrue('exited') + }) + }) + + describe('enter callback', function() { + it('triggers when element starts entering from right', function() { + runs(function() { + $scroller.scrollLeft($target.offset().left - $scroller.width()) + }) + waitsFor(toBeTrue('enter'), 'enter to trigger') + }) + + it('triggers when element starts entering from left', function() { + runs(function() { + $scroller.scrollLeft($target.offset().left + $target.outerWidth()) + }) + waits(standard) + runs(function() { + hits.enter = false + $scroller.scrollLeft($scroller.scrollLeft() - 1) + }) + waitsFor(toBeTrue('enter'), 'enter to trigger') + }) + }) + + describe('entered callback', function() { + it('triggers when element finishes entering from right', function() { + runs(function() { + var left = $target.offset().left + var viewportWidth = $scroller.width() + var elementWidth = $target.outerWidth() + $scroller.scrollLeft(left - viewportWidth + elementWidth) + }) + waitsFor(toBeTrue('entered'), 'entered to trigger') + }) + + it('triggers when element finishes entering from left', function() { + runs(function() { + $scroller.scrollLeft($target.offset().left) + }) + waits(standard) + runs(function() { + hits.entered = false + $scroller.scrollLeft($scroller.scrollLeft() - 1) + }) + waitsFor(toBeTrue('entered'), 'entered to trigger') + }) + }) + + describe('exit callback', function() { + it('triggers when element starts leaving on the right', function() { + runs(function() { + var left = $target.offset().left + var viewportWidth = $scroller.width() + var elementWidth = $target.outerWidth() + $scroller.scrollLeft(left - viewportWidth + elementWidth) + }) + waits(standard) + runs(function() { + expect(hits.exit).toBeFalsy() + $scroller.scrollLeft($scroller.scrollLeft() - 1) + }) + waitsFor(toBeTrue('exit'), 'exit to trigger') + }) + + it('triggers when element starts leaving on the left', function() { + runs(function() { + $scroller.scrollLeft($target.offset().left) + }) + waitsFor(toBeTrue('exit'), 'exit to trigger') + }) + }) + + describe('exited callback', function() { + it('triggers when element finishes exiting to the right', function() { + runs(function() { + $scroller.scrollLeft($target.offset().left - $scroller.width()) + }) + waits(standard) + runs(function() { + $scroller.scrollLeft($scroller.scrollLeft() - 1) + }) + waitsFor(toBeTrue('exited'), 'exited to trigger') + }) + + it('triggers when element finishes exiting to the left', function() { + runs(function() { + $scroller.scrollLeft($target.offset().left + $target.outerWidth()) + }) + waitsFor(toBeTrue('exited'), 'exited to trigger') + }) + }) + }) + }) From 68236a5c999d9dcaf3000255800a5770780cca38 Mon Sep 17 00:00:00 2001 From: imakewebthings Date: Tue, 17 Jun 2014 12:18:27 -0700 Subject: [PATCH 15/98] right-in-view alias, polish off Inview, cleanup --- src/context.js | 5 ----- src/shortcuts/inview.js | 4 +--- src/waypoint.js | 8 +++----- 3 files changed, 4 insertions(+), 13 deletions(-) diff --git a/src/context.js b/src/context.js index 6e33cd70..18c4f14b 100644 --- a/src/context.js +++ b/src/context.js @@ -150,7 +150,6 @@ var adjustment = waypoint.options.offset var oldTriggerPoint = waypoint.triggerPoint var elementOffset = 0 - var canTriggerOnRefresh = waypoint.canTriggerOnRefresh() var freshWaypoint = oldTriggerPoint == null var contextModifier @@ -171,10 +170,6 @@ contextModifier = axis.contextScroll - axis.contextOffset waypoint.triggerPoint = elementOffset + contextModifier - adjustment - if (!canTriggerOnRefresh) { - return - } - var wasBeforeScroll = oldTriggerPoint < axis.oldScroll var nowAfterScroll = waypoint.triggerPoint >= axis.oldScroll var triggeredBackward = wasBeforeScroll && nowAfterScroll diff --git a/src/shortcuts/inview.js b/src/shortcuts/inview.js index 9cd15b21..fa8de89d 100644 --- a/src/shortcuts/inview.js +++ b/src/shortcuts/inview.js @@ -44,9 +44,7 @@ }, { right: 'entered', left: 'exit', - offset: function() { - return this.context.adapter.width() - this.adapter.width() - } + offset: 'right-in-view' }, { right: 'exit', left: 'entered', diff --git a/src/waypoint.js b/src/waypoint.js index ee534056..69a152aa 100644 --- a/src/waypoint.js +++ b/src/waypoint.js @@ -47,11 +47,6 @@ this.group.remove(this) } - /* Internal */ - Waypoint.prototype.canTriggerOnRefresh = function() { - return !this.options.onlyOnScroll || this.triggerPoint == null - } - /* Internal */ Waypoint.prototype.trigger = function(args) { if (!this.enabled) { @@ -85,6 +80,9 @@ Waypoint.offsetAliases = { 'bottom-in-view': function() { return this.context.height() - this.adapter.outerHeight() + }, + 'right-in-view': function() { + return this.context.adapter.width() - this.adapter.outerWidth() } } From c1a1aaee2dba952d70132e07b5aa93e8064f4036 Mon Sep 17 00:00:00 2001 From: imakewebthings Date: Wed, 18 Jun 2014 10:05:27 -0700 Subject: [PATCH 16/98] Remove unused old files --- src/shortcuts/infinite-scroll/index.html | 271 ------------------ .../infinite-scroll/waypoints-infinite.coffee | 105 ------- src/shortcuts/sticky-elements/index.html | 205 ------------- .../sticky-elements/waypoints-sticky.coffee | 87 ------ 4 files changed, 668 deletions(-) delete mode 100644 src/shortcuts/infinite-scroll/index.html delete mode 100644 src/shortcuts/infinite-scroll/waypoints-infinite.coffee delete mode 100644 src/shortcuts/sticky-elements/index.html delete mode 100644 src/shortcuts/sticky-elements/waypoints-sticky.coffee diff --git a/src/shortcuts/infinite-scroll/index.html b/src/shortcuts/infinite-scroll/index.html deleted file mode 100644 index 13e31d16..00000000 --- a/src/shortcuts/infinite-scroll/index.html +++ /dev/null @@ -1,271 +0,0 @@ - - - - - - jQuery Waypoints Infinite Shortcut - - - - - - - - -
-

jQuery Waypoints

-

Infinite Scroll

-
- -
-

First include the shortcut script.

- -
<script src="/path/to/waypoints-infinite.min.js"></script>
- -

The Infinite Scroll shortcut is used to transform a traditional "Next Page" navigation into an AJAX-powered infinite scrolling UI pattern. Its default usage looks like this:

- -
$('.infinite-container').waypoint('infinite');
- -

In this example, our shortcut will create a waypoint to be fired when the bottom of .infinite-container comes into view. When that waypoint fires it will go through several steps:

-
- -
-
-
    -
  1. Fire the onBeforePageLoad callback. This callback can be passed to the infinite shortcut in the options object. For our simple example, we have no callback.
  2. -
  3. Add the infinite-loading class to the container. This class gives us a way to style the container during loading. It should be used to give the user a hint that more content is being loaded.
  4. -
  5. Send an AJAX request for the next page. The script will look for a link with a class of infinite-more-link and use its href as the new location to fetch.
  6. -
  7. Append new items from the returned HTML. When the AJAX request returns it looks for any HTML elements with a class of infinite-item and appends them to the container.
  8. -
  9. Replace the "more" link. The newly returned page should also contain a link to its own next page. It looks for the element with class infinite-more-link and replaces the existing one.
  10. -
  11. Remove the infinite-loading class.
  12. -
  13. Fire the onAfterPageLoad callback. As with the first callback, this can be passed in as an option but defaults to a no-op.
  14. -
-
-
- -
-

These steps are repeated every time the user reaches the bottom of the container until the AJAX request does not return a "more" link element, as this indicates we're on the last page. At that point the waypoint is destroyed.

- -

The "infinite" waypoint function accepts a number of options in addition to the usual Waypoints options. Here are the defaults:

-
- -
-
-
$('.infinite-container').waypoint('infinite', {
-  container: 'auto',
-  items: '.infinite-item',
-  more: '.infinite-more-link',
-  offset: 'bottom-in-view',
-  loadingClass: 'infinite-loading',
-  onBeforePageLoad: $.noop,
-  onAfterPageLoad: $.noop
-});
- -
-
container
-
The default value of 'auto' means that the element .waypoint is called on will act as the container. Newly loaded items are appended to this container. This can be set to a different selector, but should only be done when you want the waypoint trigger element to be different from the container of infinite items.
-
items
-
A selector string that matches the items to pull from each AJAX loaded page and append to the container.
-
more
-
A selector string that matches the next-page link.
-
offset
-
The same as the normal Waypoints offset option, but we set the default to 'bottom-in-view' instead of 0.
-
loadingClass
-
The class that is added to the container during page loads and removed after items are appended.
-
onBeforePageLoad
-
A function to execute before the AJAX request is sent off to load a new page.
-
onAfterPageLoad
-
A function to execute after new page items have been loaded and appended to the container.
-
-
-
- -
-

Example

-
-
-
-
-
-
-
-
-
-
-
-
- - More -
- - - - - - - - - \ No newline at end of file diff --git a/src/shortcuts/infinite-scroll/waypoints-infinite.coffee b/src/shortcuts/infinite-scroll/waypoints-infinite.coffee deleted file mode 100644 index 50a81b00..00000000 --- a/src/shortcuts/infinite-scroll/waypoints-infinite.coffee +++ /dev/null @@ -1,105 +0,0 @@ -### -Infinite Scroll Shortcut for jQuery Waypoints - v2.0.5 -Copyright (c) 2011-2014 Caleb Troughton -Licensed under the MIT license. -https://github.com/imakewebthings/jquery-waypoints/blob/master/licenses.txt -### -((root, factory) -> - if typeof define is 'function' and define.amd - define ['jquery', 'waypoints'], factory - else - factory root.jQuery -) window, ($) -> - - # An extension of the waypoint defaults when calling the "infinite" method. - - # - container: Selector that matches a container around the items that are - # infinitely loaded. Newly loaded items will be appended to this container. - # If this value is set to 'auto' as it is by default, the container will be - # the element .waypoint is called on. - - # - items: Selector that matches the items to pull from each AJAX loaded - # page and append to the "container". - - # - more: Selector that matches the next-page link. The href attribute of - # this anchor is AJAX loaded and harvested for new items and a new "more" - # link during each waypoint trigger. - - # - offset: The same as the base waypoint offset. But in this case, we use - # bottom-in-view as the default instead of 0. - - # - loadingClass: This class is added to the container while new items are - # being loaded, and removed once they are loaded and appended. - - # - onBeforePageLoad: A callback function that is executed at the beginning - # of a page load trigger, before the AJAX request is sent. - - # - onAfterPageLoad: A callback function that is executed at the end of a new - # page load, after new items have been appended. - defaults = - container: 'auto' - items: '.infinite-item' - more: '.infinite-more-link' - offset: 'bottom-in-view' - loadingClass: 'infinite-loading' - onBeforePageLoad: $.noop - onAfterPageLoad: $.noop - - # .waypoint('infinite', [object]) - - # The infinite method is a shortcut method for a common UI pattern, infinite - # scrolling. This turns a traditional More/Next-Page style pagination into - # an infinite scrolling page. The recommended usage is to call this method - # on the container holding the items to be loaded. Ex: - - # $('.infinite-container').waypoint('infinite'); - - # Using all of the default options, when the bottom of the infinite container - # comes into view, a new page of items will be loaded. The script will look - # for a link with the class of "infinite-more-link", grab its href attribute, - # and load that page with AJAX. It will then search for all items in this new - # page with a class of "infinite-item" and will append them to the - # "infinite-container". The "infinite-more-link" item is also replaced with - # the more link from the new page, allowing the next trigger to load the next - # page. This continues until no new more link is detected in the loaded page. - - # An options object can optionally be passed in to override any of the - # defaults specified above, as well as the baseline waypoint defaults. - $.waypoints 'extendFn', 'infinite', (options) -> - opts = $.extend {}, $.fn.waypoint.defaults, defaults, options - return @ if $(opts.more).length is 0 - $container = if opts.container is 'auto' then @ else $ opts.container - - opts.handler = (direction) -> - if direction in ['down', 'right'] - $this = $ this - opts.onBeforePageLoad() - - # We disable the waypoint during item loading so that we can't trigger - # it again and cause duplicate loads. - $this.waypoint 'destroy' - - # During loading a class is added to the container, should the user - # wish to style it during this state. - $container.addClass opts.loadingClass - - # Load items from the next page. - $.get $(opts.more).attr('href'), (data) -> - $data = $ $.parseHTML(data) - $more = $ opts.more - $newMore = $data.find opts.more - $container.append $data.find opts.items - $container.removeClass opts.loadingClass - - if $newMore.length - $more.replaceWith $newMore - fn = -> $this.waypoint opts - setTimeout fn, 0 - else - $more.remove() - - opts.onAfterPageLoad() - - # Initialize the waypoint with our built-up options. Returns the original - # jQuery object per normal for chaining. - @.waypoint opts diff --git a/src/shortcuts/sticky-elements/index.html b/src/shortcuts/sticky-elements/index.html deleted file mode 100644 index 43e37545..00000000 --- a/src/shortcuts/sticky-elements/index.html +++ /dev/null @@ -1,205 +0,0 @@ - - - - - - jQuery Waypoints Sticky Shortcut - - - - - - - - -
-

jQuery Waypoints

-

Sticky Elements

-
- -
-

First include the shortcut script.

- -
<script src="/path/to/waypoints-sticky.min.js"></script>
- -

The Sticky Elements shortcut is used to make elements "stick" to the top of the page when the user scrolls past. It packages a few best practices around this pattern into one simple function extension of jQuery Waypoints. The most basic usage looks like this:

- -
$('.my-sticky-element').waypoint('sticky');
-
- -
-
-

What This Shortcut Does

- -
    -
  • Creates a wrapper around the element. This wrapper is what actually becomes the waypoint. It remains statically positioned in your document, acting as a placeholder while the sticky element is free to gain and lose fixed positioning.
  • -
  • Sets that wrapper’s height. When your sticky element gains fixed positioning it will no longer have an effect on the document flow. By giving the static wrapper the same height as the sticky element, we avoid any sudden "jumps" that come with shifting content.
  • -
  • Adds a class to the sticky element when the user reaches it. By default, when the element reaches the top of the viewport it gains the stuck class.
  • -
-
-
- -
-
-

What This Shortcut Does Not

- -
    -
  • Give stuck elements fixed positioning. It is left to you, the author, to give the stuck elements fixed positioning in CSS. With so many design possibilities, the script cannot make any assumptions about how the sticky element should look. The shortcut only goes as far as to add the class to give you a hook for this styling.
  • -
  • Adjust for the wrapper. Besides height, other CSS properties on your sticky element may effect the layout of surrounding content. Margins are one example. You should move any of these styles off of your sticky element and onto the wrapper so that they will persist during the "stuck" state.
  • -
-
-
- -
-

The "sticky" waypoint method may also be passed an options object. This options object can be used to override the class name of the "stuck" state, the direction(s) in which the stuck class should be applied, and the HTML of the wrapper element. Here are the defaults:

- -
$('.my-sticky-element').waypoint('sticky', {
-  direction: 'down right',
-  stuckClass: 'stuck',
-  wrapper: '<div class="sticky-wrapper" />'
-});
- -

This options object is just an extension of the regular Waypoints options object, so you can pass along any traditional options you may want. A common one is the offset option.

- -
$('.my-sticky-element').waypoint('sticky', {
-  offset: 30 // Apply "stuck" when element 30px from top
-});
-
- - - - - - - - - diff --git a/src/shortcuts/sticky-elements/waypoints-sticky.coffee b/src/shortcuts/sticky-elements/waypoints-sticky.coffee deleted file mode 100644 index ad126920..00000000 --- a/src/shortcuts/sticky-elements/waypoints-sticky.coffee +++ /dev/null @@ -1,87 +0,0 @@ -### -Sticky Elements Shortcut for jQuery Waypoints - v2.0.5 -Copyright (c) 2011-2014 Caleb Troughton -Licensed under the MIT license. -https://github.com/imakewebthings/jquery-waypoints/blob/master/licenses.txt -### -((root, factory) -> - if typeof define is 'function' and define.amd - define ['jquery', 'waypoints'], factory - else - factory root.jQuery -) window, ($) -> - - # An extension of the waypoint defaults when calling the "sticky" method. - - # - wrapper: Each sticky element gets wrapped in another element. This - # element acts as the actual waypoint and stays in the document flow, - # leaving the sticky element to gain/lost fixed positioning freely without - # effecting layout. "wrapper" is the HTML for this element. - - # - stuckClass: The class that is added to the sticky element when the - # waypoint is reached. Users should style this class to add fixed - # positioning and whatever other styles are necessary for their - # particular design. - defaults = - wrapper: '
' - stuckClass: 'stuck' - direction: 'down right' - - # Internal: Wraps the sticky elements in the sticky wrapper and returns the - # wrapper elements. - wrap = ($elements, options) -> - $elements.wrap options.wrapper - $parent = $elements.parent() - $parent.data 'isWaypointStickyWrapper', true - - # .waypoint('sticky', [object]) - - # The sticky method is a shortcut method for a common UI pattern, sticky - # elements. In its most common form, this pattern consists of an item that - # is part of the normal document flow until it reaches the top of the - # viewport, where it gains a fixed position state. - - # This shortcut does very little to actually create the sticky state. It only - # adds a class to the element when it reaches the appropriate part of the - # viewport. It is the job of the user to define the styles for this "stuck" - # state in CSS. There are many different ways one could style their sticky - # elements, and trying to implement all of them in JS is futile. Everyone's - # design is different. - - # This shortcut does take care of the most common pitfall in previous - # versions of Waypoints: Using the sticky element as the waypoint. Fixed - # position elements do not work well as waypoints since their position in - # the document is constantly changing as the user scrolls (and their - # position relative to the viewport never does, which is the whole point of - # Waypoints). This shortcut will create a wrapper element around the sticky - # element that acts as the actual waypoint, as well as a placeholder for the - # waypoint in the document flow, as fixed positioning takes an element out - # of flow and would otherwise effect the page layout. Users are recommended - # to define any margins on their sticky elements as margins on this - # wrapper instead. - - $.waypoints 'extendFn', 'sticky', (opt) -> - options = $.extend {}, $.fn.waypoint.defaults, defaults, opt - $wrap = wrap @, options - originalHandler = options.handler - options.handler = (direction) -> - $sticky = $(@).children ':first' - shouldBeStuck = options.direction.indexOf(direction) != -1 - $sticky.toggleClass options.stuckClass, shouldBeStuck - $wrap.height if shouldBeStuck then $sticky.outerHeight() else '' - originalHandler.call @, direction if originalHandler? - $wrap.waypoint options - @data 'stuckClass', options.stuckClass - - # .waypoint('unsticky') - - # Undoes everything done within the sticky shortcut by removing the parent - # sticky wrapper, destroying the waypoint, and removing any stuck class - # that may be applied. - - $.waypoints 'extendFn', 'unsticky', () -> - $parent = @parent() - return @ unless $parent.data('isWaypointStickyWrapper') - $parent.waypoint 'destroy' - @unwrap() - @removeClass @data 'stuckClass' From 0a5ca43152b21cd2e720b7fcf2720158914a1a98 Mon Sep 17 00:00:00 2001 From: imakewebthings Date: Wed, 18 Jun 2014 14:10:53 -0700 Subject: [PATCH 17/98] Zepto adapter: --- bower.json | 3 +- src/adapters/jquery.js | 5 +- src/adapters/zepto.js | 69 +++ test/context-spec.js | 130 +++--- test/fixtures/standard.html | 1 + test/group-spec.js | 124 +++--- test/infinite-spec.js | 1 + test/inview-spec.js | 434 ++++++++++--------- test/sticky-spec.js | 1 + test/waypoint-spec.js | 838 ++++++++++++++++++------------------ testem.json | 4 +- 11 files changed, 856 insertions(+), 754 deletions(-) create mode 100644 src/adapters/zepto.js diff --git a/bower.json b/bower.json index 1b5d872a..d7998f6d 100644 --- a/bower.json +++ b/bower.json @@ -4,6 +4,7 @@ "devDependencies": { "jquery": "~1.11.1", "lodash": "~2.4.1", - "jasmine-jquery": "~1.7.0" + "jasmine-jquery": "~1.7.0", + "zepto": "~1.1.3" } } diff --git a/src/adapters/jquery.js b/src/adapters/jquery.js index 4d5fc770..6b1aeba8 100644 --- a/src/adapters/jquery.js +++ b/src/adapters/jquery.js @@ -30,6 +30,9 @@ JQueryAdapter[method] = $[method] }) - window.Waypoint.adapters.push(JQueryAdapter) + window.Waypoint.adapters.push({ + name: 'jquery', + Adapter: JQueryAdapter + }) window.Waypoint.Adapter = JQueryAdapter })() diff --git a/src/adapters/zepto.js b/src/adapters/zepto.js new file mode 100644 index 00000000..3bee00fc --- /dev/null +++ b/src/adapters/zepto.js @@ -0,0 +1,69 @@ +(function() { + var $ = Zepto + + var ZeptoAdapter = function(element) { + this.element = element + this.$element = $(element) + } + + $.each([ + 'height', + 'off', + 'on', + 'scrollLeft', + 'scrollTop', + 'width' + ], function(i, method) { + ZeptoAdapter.prototype[method] = function() { + var args = Array.prototype.slice.call(arguments) + return this.$element[method].apply(this.$element, args) + } + }) + + ZeptoAdapter.prototype.offset = function() { + if (this.element != this.element.window) { + return this.$element.offset() + } + } + + $.each([ + 'width', + 'height' + ], function(i, dimension) { + var method = $.camelCase('outer-' + dimension) + + ZeptoAdapter.prototype[method] = function(includeMargin) { + var size = this.$element[dimension]() + var sides = { + width: ['left', 'right'], + height: ['top', 'bottom'] + } + if (includeMargin) { + $.each(sides[dimension], $.proxy(function(i, side) { + size += parseInt(this.$element.css('margin-' + side), 10) + }, this)) + } + return size + } + }) + + $.each([ + 'extend', + 'inArray', + ], function(i, method) { + ZeptoAdapter[method] = $[method] + }) + + ZeptoAdapter.isEmptyObject = function(obj) { + for (var name in obj) { + return false + } + return true + } + + window.Waypoint.adapters.push({ + name: 'zepto', + Adapter: ZeptoAdapter + }) + window.Waypoint.Adapter = ZeptoAdapter +})() diff --git a/test/context-spec.js b/test/context-spec.js index 51e5f480..5c94f6b1 100644 --- a/test/context-spec.js +++ b/test/context-spec.js @@ -1,75 +1,81 @@ -describe('Waypoint.Context', function() { - var standard = 50 - var currentDirection, $scroller, waypoint, $target, context +jQuery.each(Waypoint.adapters, function(i, adapter) { + describe(adapter.name + ' adapter:', function() { + describe('Waypoint.Context', function() { + var $ = jQuery + var standard = 50 + var currentDirection, $scroller, waypoint, $target, context - function setDirection(direction) { - currentDirection = direction - } + function setDirection(direction) { + currentDirection = direction + } - function hasDirection() { - return currentDirection != null - } + function hasDirection() { + return currentDirection != null + } - beforeEach(function() { - loadFixtures('standard.html') - $scroller = $(window) - currentDirection = null - $target = $('#same1') - waypoint = new Waypoint({ - element: $target[0], - handler: setDirection - }) - context = waypoint.context - }) - - afterEach(function() { - waypoint.destroy() - $scroller.scrollTop(0).scrollLeft(0) - waits(standard) - }) + beforeEach(function() { + Waypoint.Adapter = adapter.Adapter + loadFixtures('standard.html') + $scroller = $(window) + currentDirection = null + $target = $('#same1') + waypoint = new Waypoint({ + element: $target[0], + handler: setDirection + }) + context = waypoint.context + }) - describe('#refresh', function() { - it('updates trigger point of waypoints', function() { - var top = $target.offset().top - $target.css({ - top: top + 1 + afterEach(function() { + waypoint.destroy() + $scroller.scrollTop(0).scrollLeft(0) + waits(standard) }) - context.refresh() - expect(waypoint.triggerPoint).toEqual(top + 1) - }) - it('triggers down direction if waypoint crosses upwards', function() { - $target.css('top', '-1px') - context.refresh() - expect(currentDirection).toEqual('down') - }) + describe('#refresh', function() { + it('updates trigger point of waypoints', function() { + var top = $target.offset().top + $target.css({ + top: top + 1 + }) + context.refresh() + expect(waypoint.triggerPoint).toEqual(top + 1) + }) - it('triggers up direction if waypoint crosses downwards', function() { - $target.css('top', '-1px') - context.refresh() - $target.css('top', '0px') - context.refresh() - expect(currentDirection).toEqual('up') - }) + it('triggers down direction if waypoint crosses upwards', function() { + $target.css('top', '-1px') + context.refresh() + expect(currentDirection).toEqual('down') + }) - it('returns the same context instance for chaining', function() { - expect(context.refresh()).toEqual(context) - }) - }) + it('triggers up direction if waypoint crosses downwards', function() { + $target.css('top', '-1px') + context.refresh() + $target.css('top', '0px') + context.refresh() + expect(currentDirection).toEqual('up') + }) + + it('returns the same context instance for chaining', function() { + expect(context.refresh()).toEqual(context) + }) + }) - describe('Waypoint.Context.refreshAll()', function() { - it('calls refresh on all contexts', function() { - var secondWaypoint = new Waypoint({ - element: $('#inner3')[0], - context: $('#bottom')[0] + describe('Waypoint.Context.refreshAll()', function() { + it('calls refresh on all contexts', function() { + var secondWaypoint = new Waypoint({ + element: $('#inner3')[0], + context: $('#bottom')[0] + }) + var secondContext = secondWaypoint.context + spyOn(context, 'refresh') + spyOn(secondContext, 'refresh') + Waypoint.Context.refreshAll() + expect(context.refresh).toHaveBeenCalled() + expect(secondContext.refresh).toHaveBeenCalled() + secondWaypoint.destroy() + }) }) - var secondContext = secondWaypoint.context - spyOn(context, 'refresh') - spyOn(secondContext, 'refresh') - Waypoint.Context.refreshAll() - expect(context.refresh).toHaveBeenCalled() - expect(secondContext.refresh).toHaveBeenCalled() - secondWaypoint.destroy() }) }) }) diff --git a/test/fixtures/standard.html b/test/fixtures/standard.html index ec52c039..5faa993a 100644 --- a/test/fixtures/standard.html +++ b/test/fixtures/standard.html @@ -25,6 +25,7 @@ position:absolute; top:0; height:3000px; + width:9000px; } #wp-container div { diff --git a/test/group-spec.js b/test/group-spec.js index 33d85032..08481e2f 100644 --- a/test/group-spec.js +++ b/test/group-spec.js @@ -1,72 +1,78 @@ -describe('Waypoint.Group', function() { - var standard = 50 - var currentDirection, firstWaypoint, secondWaypoint, customGroupWaypoint - var defaultGroup, customGroup +jQuery.each(Waypoint.adapters, function(i, adapter) { + describe(adapter.name + ' adapter:', function() { + describe('Waypoint.Group', function() { + var $ = jQuery + var standard = 50 + var currentDirection, firstWaypoint, secondWaypoint, customGroupWaypoint + var defaultGroup, customGroup - function setDirection(direction) { - currentDirection = direction - } + function setDirection(direction) { + currentDirection = direction + } - function hasDirection() { - return currentDirection != null - } + function hasDirection() { + return currentDirection != null + } - beforeEach(function() { - loadFixtures('standard.html') - currentDirection = null - firstWaypoint = new Waypoint({ - element: $('#same1')[0], - handler: setDirection - }) - secondWaypoint = new Waypoint({ - element: $('#near1')[0], - handler: setDirection - }) - customGroupWaypoint = new Waypoint({ - element: $('#same2')[0], - handler: setDirection, - group: 'custom' - }) - defaultGroup = firstWaypoint.group - customGroup = customGroupWaypoint.group - }) + beforeEach(function() { + Waypoint.Adapter = adapter.Adapter + loadFixtures('standard.html') + currentDirection = null + firstWaypoint = new Waypoint({ + element: $('#same1')[0], + handler: setDirection + }) + secondWaypoint = new Waypoint({ + element: $('#near1')[0], + handler: setDirection + }) + customGroupWaypoint = new Waypoint({ + element: $('#same2')[0], + handler: setDirection, + group: 'custom' + }) + defaultGroup = firstWaypoint.group + customGroup = customGroupWaypoint.group + }) - afterEach(function() { - firstWaypoint.destroy() - secondWaypoint.destroy() - customGroupWaypoint.destroy() - waits(standard) - }) + afterEach(function() { + firstWaypoint.destroy() + secondWaypoint.destroy() + customGroupWaypoint.destroy() + waits(standard) + }) - describe('#previous(waypoint)', function() { - it('returns previous waypoint based on trigger point', function() { - expect(defaultGroup.previous(secondWaypoint)).toEqual(firstWaypoint) - }) + describe('#previous(waypoint)', function() { + it('returns previous waypoint based on trigger point', function() { + expect(defaultGroup.previous(secondWaypoint)).toEqual(firstWaypoint) + }) - it('returns null if on the first waypoint in the group', function() { - expect(defaultGroup.previous(firstWaypoint)).toBeNull() - }) - }) + it('returns null if on the first waypoint in the group', function() { + expect(defaultGroup.previous(firstWaypoint)).toBeNull() + }) + }) - describe('#next(waypoint)', function() { - it('returns next waypoint based on trigger point', function() { - expect(defaultGroup.next(firstWaypoint)).toEqual(secondWaypoint) - }) + describe('#next(waypoint)', function() { + it('returns next waypoint based on trigger point', function() { + expect(defaultGroup.next(firstWaypoint)).toEqual(secondWaypoint) + }) - it('returns null if on the last waypoint in the group', function() { - expect(defaultGroup.next(secondWaypoint)).toBeNull() - }) - }) + it('returns null if on the last waypoint in the group', function() { + expect(defaultGroup.next(secondWaypoint)).toBeNull() + }) + }) - describe('#first()', function() { - it('returns the first waypoint based on trigger point', function() { - expect(defaultGroup.first()).toEqual(firstWaypoint) - }) - }) + describe('#first()', function() { + it('returns the first waypoint based on trigger point', function() { + expect(defaultGroup.first()).toEqual(firstWaypoint) + }) + }) - describe('#last()', function() { - it('returns the first waypoint based on trigger point', function() { - expect(defaultGroup.last()).toEqual(secondWaypoint) + describe('#last()', function() { + it('returns the first waypoint based on trigger point', function() { + expect(defaultGroup.last()).toEqual(secondWaypoint) + }) + }) }) }) }) diff --git a/test/infinite-spec.js b/test/infinite-spec.js index cb9676ac..0177b05d 100644 --- a/test/infinite-spec.js +++ b/test/infinite-spec.js @@ -1,4 +1,5 @@ describe('Waypoint Sticky Shortcut', function() { + var $ = jQuery var standard = 50 var $scroller = $(window) var $container, $items, $more, waypoint, beforeSpy, afterSpy diff --git a/test/inview-spec.js b/test/inview-spec.js index 47db63f8..f255b15d 100644 --- a/test/inview-spec.js +++ b/test/inview-spec.js @@ -1,249 +1,259 @@ -describe('Waypoints Inview Shortcut', function() { - var standard = 50 - var $scroller = $(window) - var $target, waypoint, hits - - function setsTrue(key) { - return function() { - hits[key] = true - } - } - - function setsEnter() { - hits.enter = true - } - - function setsEntered() { - hits.entered = true - } - - function setsExit() { - hits.exit = true - } - - function setsExited() { - hits.exited = true - } - - function toBeTrue(key) { - return function() { - return hits[key] - } - } - - beforeEach(function() { - loadFixtures('standard.html') - $target = $('#near2') - hits = {} - }) +jQuery.each(Waypoint.adapters, function(i, adapter) { + describe(adapter.name + ' adapter:', function() { + describe('Waypoints Inview Shortcut', function() { + var $ = jQuery + var standard = 50 + var $scroller = $(window) + var $target, waypoint, hits - afterEach(function() { - waypoint.destroy() - $scroller.scrollTop(0).scrollLeft(0) - waits(standard) - }) + function setsTrue(key) { + return function() { + hits[key] = true + } + } - describe('vertical', function() { - beforeEach(function() { - waypoint = new Waypoint.Inview({ - element: $target[0], - enter: setsTrue('enter'), - entered: setsTrue('entered'), - exit: setsTrue('exit'), - exited: setsTrue('exited') - }) - }) + function setsEnter() { + hits.enter = true + } - describe('enter callback', function() { - it('triggers when element starts entering from below', function() { - runs(function() { - $scroller.scrollTop($target.offset().top - Waypoint.viewportHeight()) - }) - waitsFor(toBeTrue('enter'), 'enter to trigger') - }) + function setsEntered() { + hits.entered = true + } - it('triggers when element starts entering from above', function() { - runs(function() { - $scroller.scrollTop($target.offset().top + $target.outerHeight()) - }) - waits(standard) - runs(function() { - hits.enter = false - $scroller.scrollTop($scroller.scrollTop() - 1) - }) - waitsFor(toBeTrue('enter'), 'enter to trigger') - }) - }) + function setsExit() { + hits.exit = true + } - describe('entered callback', function() { - it('triggers when element finishes entering from below', function() { - runs(function() { - var top = $target.offset().top - var viewportHeight = Waypoint.viewportHeight() - var elementHeight = $target.outerHeight() - $scroller.scrollTop(top - viewportHeight + elementHeight) - }) - waitsFor(toBeTrue('entered'), 'entered to trigger') - }) + function setsExited() { + hits.exited = true + } - it('triggers when element finishes entering from above', function() { - runs(function() { - $scroller.scrollTop($target.offset().top) - }) - waits(standard) - runs(function() { - hits.entered = false - $scroller.scrollTop($scroller.scrollTop() - 1) - }) - waitsFor(toBeTrue('entered'), 'entered to trigger') + function toBeTrue(key) { + return function() { + return hits[key] + } + } + + beforeEach(function() { + Waypoint.Adapter = adapter.Adapter + loadFixtures('standard.html') + $target = $('#near2') + hits = {} }) - }) - describe('exit callback', function() { - it('triggers when element starts leaving below', function() { - runs(function() { - var top = $target.offset().top - var viewportHeight = Waypoint.viewportHeight() - var elementHeight = $target.outerHeight() - $scroller.scrollTop(top - viewportHeight + elementHeight) - }) + afterEach(function() { + waypoint.destroy() + $scroller.scrollTop(0).scrollLeft(0) waits(standard) - runs(function() { - expect(hits.exit).toBeFalsy() - $scroller.scrollTop($scroller.scrollTop() - 1) - }) - waitsFor(toBeTrue('exit'), 'exit to trigger') }) - it('triggers when element starts leaving above', function() { - runs(function() { - $scroller.scrollTop($target.offset().top) + describe('vertical', function() { + beforeEach(function() { + waypoint = new Waypoint.Inview({ + element: $target[0], + enter: setsTrue('enter'), + entered: setsTrue('entered'), + exit: setsTrue('exit'), + exited: setsTrue('exited') + }) }) - waitsFor(toBeTrue('exit'), 'exit to trigger') - }) - }) - describe('exited callback', function() { - it('triggers when element finishes exiting below', function() { - runs(function() { - $scroller.scrollTop($target.offset().top - Waypoint.viewportHeight()) - }) - waits(standard) - runs(function() { - $scroller.scrollTop($scroller.scrollTop() - 1) - }) - waitsFor(toBeTrue('exited'), 'exited to trigger') - }) + describe('enter callback', function() { + it('triggers when element starts entering from below', function() { + runs(function() { + var top = $target.offset().top + $scroller.scrollTop(top - Waypoint.viewportHeight()) + }) + waitsFor(toBeTrue('enter'), 'enter to trigger') + }) - it('triggers when element finishes exiting above', function() { - runs(function() { - $scroller.scrollTop($target.offset().top + $target.outerHeight()) + it('triggers when element starts entering from above', function() { + runs(function() { + $scroller.scrollTop($target.offset().top + $target.outerHeight()) + }) + waits(standard) + runs(function() { + hits.enter = false + $scroller.scrollTop($scroller.scrollTop() - 1) + }) + waitsFor(toBeTrue('enter'), 'enter to trigger') + }) }) - waitsFor(toBeTrue('exited'), 'exited to trigger') - }) - }) - }) - describe('horizontal', function() { - beforeEach(function() { - waypoint = new Waypoint.Inview({ - horizontal: true, - element: $target[0], - enter: setsTrue('enter'), - entered: setsTrue('entered'), - exit: setsTrue('exit'), - exited: setsTrue('exited') - }) - }) + describe('entered callback', function() { + it('triggers when element finishes entering from below', function() { + runs(function() { + var top = $target.offset().top + var viewportHeight = Waypoint.viewportHeight() + var elementHeight = $target.outerHeight() + $scroller.scrollTop(top - viewportHeight + elementHeight) + }) + waitsFor(toBeTrue('entered'), 'entered to trigger') + }) - describe('enter callback', function() { - it('triggers when element starts entering from right', function() { - runs(function() { - $scroller.scrollLeft($target.offset().left - $scroller.width()) + it('triggers when element finishes entering from above', function() { + runs(function() { + $scroller.scrollTop($target.offset().top) + }) + waits(standard) + runs(function() { + hits.entered = false + $scroller.scrollTop($scroller.scrollTop() - 1) + }) + waitsFor(toBeTrue('entered'), 'entered to trigger') + }) }) - waitsFor(toBeTrue('enter'), 'enter to trigger') - }) - it('triggers when element starts entering from left', function() { - runs(function() { - $scroller.scrollLeft($target.offset().left + $target.outerWidth()) - }) - waits(standard) - runs(function() { - hits.enter = false - $scroller.scrollLeft($scroller.scrollLeft() - 1) - }) - waitsFor(toBeTrue('enter'), 'enter to trigger') - }) - }) + describe('exit callback', function() { + it('triggers when element starts leaving below', function() { + runs(function() { + var top = $target.offset().top + var viewportHeight = Waypoint.viewportHeight() + var elementHeight = $target.outerHeight() + $scroller.scrollTop(top - viewportHeight + elementHeight) + }) + waits(standard) + runs(function() { + expect(hits.exit).toBeFalsy() + $scroller.scrollTop($scroller.scrollTop() - 1) + }) + waitsFor(toBeTrue('exit'), 'exit to trigger') + }) - describe('entered callback', function() { - it('triggers when element finishes entering from right', function() { - runs(function() { - var left = $target.offset().left - var viewportWidth = $scroller.width() - var elementWidth = $target.outerWidth() - $scroller.scrollLeft(left - viewportWidth + elementWidth) + it('triggers when element starts leaving above', function() { + runs(function() { + $scroller.scrollTop($target.offset().top) + }) + waitsFor(toBeTrue('exit'), 'exit to trigger') + }) }) - waitsFor(toBeTrue('entered'), 'entered to trigger') - }) - it('triggers when element finishes entering from left', function() { - runs(function() { - $scroller.scrollLeft($target.offset().left) - }) - waits(standard) - runs(function() { - hits.entered = false - $scroller.scrollLeft($scroller.scrollLeft() - 1) + describe('exited callback', function() { + it('triggers when element finishes exiting below', function() { + runs(function() { + var top = $target.offset().top + $scroller.scrollTop(top - Waypoint.viewportHeight()) + }) + waits(standard) + runs(function() { + $scroller.scrollTop($scroller.scrollTop() - 1) + }) + waitsFor(toBeTrue('exited'), 'exited to trigger') + }) + + it('triggers when element finishes exiting above', function() { + runs(function() { + $scroller.scrollTop($target.offset().top + $target.outerHeight()) + }) + waitsFor(toBeTrue('exited'), 'exited to trigger') + }) }) - waitsFor(toBeTrue('entered'), 'entered to trigger') }) - }) - describe('exit callback', function() { - it('triggers when element starts leaving on the right', function() { - runs(function() { - var left = $target.offset().left - var viewportWidth = $scroller.width() - var elementWidth = $target.outerWidth() - $scroller.scrollLeft(left - viewportWidth + elementWidth) + describe('horizontal', function() { + beforeEach(function() { + waypoint = new Waypoint.Inview({ + horizontal: true, + element: $target[0], + enter: setsTrue('enter'), + entered: setsTrue('entered'), + exit: setsTrue('exit'), + exited: setsTrue('exited') + }) }) - waits(standard) - runs(function() { - expect(hits.exit).toBeFalsy() - $scroller.scrollLeft($scroller.scrollLeft() - 1) - }) - waitsFor(toBeTrue('exit'), 'exit to trigger') - }) - it('triggers when element starts leaving on the left', function() { - runs(function() { - $scroller.scrollLeft($target.offset().left) + describe('enter callback', function() { + it('triggers when element starts entering from right', function() { + runs(function() { + $scroller.scrollLeft($target.offset().left - $scroller.width()) + }) + waitsFor(toBeTrue('enter'), 'enter to trigger') + }) + + it('triggers when element starts entering from left', function() { + runs(function() { + var left = $target.offset().left + $scroller.scrollLeft(left + $target.outerWidth()) + }) + waits(standard) + runs(function() { + hits.enter = false + $scroller.scrollLeft($scroller.scrollLeft() - 1) + }) + waitsFor(toBeTrue('enter'), 'enter to trigger') + }) }) - waitsFor(toBeTrue('exit'), 'exit to trigger') - }) - }) - describe('exited callback', function() { - it('triggers when element finishes exiting to the right', function() { - runs(function() { - $scroller.scrollLeft($target.offset().left - $scroller.width()) + describe('entered callback', function() { + it('triggers when element finishes entering from right', function() { + runs(function() { + var left = $target.offset().left + var viewportWidth = $scroller.width() + var elementWidth = $target.outerWidth() + $scroller.scrollLeft(left - viewportWidth + elementWidth) + }) + waitsFor(toBeTrue('entered'), 'entered to trigger') + }) + + it('triggers when element finishes entering from left', function() { + runs(function() { + $scroller.scrollLeft($target.offset().left) + }) + waits(standard) + runs(function() { + hits.entered = false + $scroller.scrollLeft($scroller.scrollLeft() - 1) + }) + waitsFor(toBeTrue('entered'), 'entered to trigger') + }) }) - waits(standard) - runs(function() { - $scroller.scrollLeft($scroller.scrollLeft() - 1) + + describe('exit callback', function() { + it('triggers when element starts leaving on the right', function() { + runs(function() { + var left = $target.offset().left + var viewportWidth = $scroller.width() + var elementWidth = $target.outerWidth() + $scroller.scrollLeft(left - viewportWidth + elementWidth) + }) + waits(standard) + runs(function() { + expect(hits.exit).toBeFalsy() + $scroller.scrollLeft($scroller.scrollLeft() - 1) + }) + waitsFor(toBeTrue('exit'), 'exit to trigger') + }) + + it('triggers when element starts leaving on the left', function() { + runs(function() { + $scroller.scrollLeft($target.offset().left) + }) + waitsFor(toBeTrue('exit'), 'exit to trigger') + }) }) - waitsFor(toBeTrue('exited'), 'exited to trigger') - }) - it('triggers when element finishes exiting to the left', function() { - runs(function() { - $scroller.scrollLeft($target.offset().left + $target.outerWidth()) + describe('exited callback', function() { + it('triggers when element finishes exiting to the right', function() { + runs(function() { + var left = $target.offset().left + $scroller.scrollLeft(left - $scroller.width()) + }) + waits(standard) + runs(function() { + $scroller.scrollLeft($scroller.scrollLeft() - 1) + }) + waitsFor(toBeTrue('exited'), 'exited to trigger') + }) + + it('triggers when element finishes exiting to the left', function() { + runs(function() { + var left = $target.offset().left + $scroller.scrollLeft(left + $target.outerWidth()) + }) + waitsFor(toBeTrue('exited'), 'exited to trigger') + }) }) - waitsFor(toBeTrue('exited'), 'exited to trigger') }) }) }) - }) diff --git a/test/sticky-spec.js b/test/sticky-spec.js index 47b2a30a..98bb2086 100644 --- a/test/sticky-spec.js +++ b/test/sticky-spec.js @@ -1,4 +1,5 @@ describe('Waypoint Sticky Shortcut', function() { + var $ = jQuery var standard = 50 var $scroller = $(window) var $sticky, waypoint, handlerSpy diff --git a/test/waypoint-spec.js b/test/waypoint-spec.js index 05afc94f..9396fa0f 100644 --- a/test/waypoint-spec.js +++ b/test/waypoint-spec.js @@ -1,474 +1,480 @@ -describe('Waypoint', function() { - var standard = 50 - var hit, $scroller, waypoint, $target, returnValue - - function setHitTrue() { - hit = true - } - - function hitToBeTrue() { - return hit - } - - beforeEach(function() { - loadFixtures('standard.html') - $scroller = $(window) - hit = false - waypoint = null - }) - - afterEach(function() { - if (waypoint) { - waypoint.destroy() - } - $scroller.scrollTop(0).scrollLeft(0) - waits(standard) - }) +jQuery.each(Waypoint.adapters, function(i, adapter) { + describe(adapter.name + ' adapter: ', function() { + describe('Waypoint', function() { + var $ = jQuery + var standard = 50 + var hit, $scroller, waypoint, $target, returnValue + + function setHitTrue() { + hit = true + } - describe('new Waypoint()', function() { - it('errors out', function() { - expect(function() { - new Waypoint() - }).toThrow() - }) - }) + function hitToBeTrue() { + return hit + } - describe('new Waypoint(options)', function() { - it('returns an instance of the Waypoint class', function() { - waypoint = new Waypoint({ - element: document.getElementById('same1') + beforeEach(function() { + Waypoint.Adapter = adapter.Adapter + loadFixtures('standard.html') + $scroller = $(window) + hit = false + waypoint = null }) - expect(waypoint instanceof Waypoint).toBeTruthy() - }) - - it('requires the element option', function() { - expect(function() { - new Waypoint({}) - }).toThrow() - }) - it('triggers down on new already-reached waypoints', function() { - runs(function() { - $target = $('#same2') - $scroller.scrollTop($target.offset().top + 1) + afterEach(function() { + if (waypoint) { + waypoint.destroy() + } + $scroller.scrollTop(0).scrollLeft(0) + waits(standard) }) - waits(standard) - runs(function() { - waypoint = new Waypoint({ - element: $target[0], - handler: function(direction) { - hit = direction === 'down' - } + + describe('new Waypoint()', function() { + it('errors out', function() { + expect(function() { + new Waypoint() + }).toThrow() }) }) - waitsFor(hitToBeTrue, 'callback to trigger') - }) - }) - describe('handler option', function() { - var currentDirection + describe('new Waypoint(options)', function() { + it('returns an instance of the Waypoint class', function() { + waypoint = new Waypoint({ + element: document.getElementById('same1') + }) + expect(waypoint instanceof Waypoint).toBeTruthy() + }) - beforeEach(function() { - $target = $('#same1') - currentDirection = null - waypoint = new Waypoint({ - element: $target[0], - handler: function(direction) { - currentDirection = direction - } - }) - }) + it('requires the element option', function() { + expect(function() { + new Waypoint({}) + }).toThrow() + }) - it('triggers with direction parameter', function() { - runs(function() { - $scroller.scrollTop($target.offset().top) - }) - waitsFor(function() { - return currentDirection === 'down' - }, 'down to trigger') - runs(function() { - $scroller.scrollTop($target.offset().top - 1) + it('triggers down on new already-reached waypoints', function() { + runs(function() { + $target = $('#same2') + $scroller.scrollTop($target.offset().top + 1) + }) + waits(standard) + runs(function() { + waypoint = new Waypoint({ + element: $target[0], + handler: function(direction) { + hit = direction === 'down' + } + }) + }) + waitsFor(hitToBeTrue, 'callback to trigger') + }) }) - waitsFor(function() { - return currentDirection === 'up' - }, 'up to trigger') - }) - }) - describe('offset option', function() { - beforeEach(function() { - $target = $('#same1') - }) + describe('handler option', function() { + var currentDirection - it('takes a px offset', function(){ - runs(function() { - waypoint = new Waypoint({ - element: $target[0], - handler: setHitTrue, - offset: 50 + beforeEach(function() { + $target = $('#same1') + currentDirection = null + waypoint = new Waypoint({ + element: $target[0], + handler: function(direction) { + currentDirection = direction + } + }) }) - $scroller.scrollTop($target.offset().top - 51) - }) - waits(standard) - runs(function() { - expect(hit).toBeFalsy() - $scroller.scrollTop($target.offset().top - 50) - }) - waitsFor(hitToBeTrue, 'callback to trigger') - }) - it('takes a % offset', function() { - var trigger = $target.offset().top - Waypoint.viewportHeight() * .37 - runs(function() { - waypoint = new Waypoint({ - element: $target[0], - handler: setHitTrue, - offset: '37%' + it('triggers with direction parameter', function() { + runs(function() { + $scroller.scrollTop($target.offset().top) + }) + waitsFor(function() { + return currentDirection === 'down' + }, 'down to trigger') + runs(function() { + $scroller.scrollTop($target.offset().top - 1) + }) + waitsFor(function() { + return currentDirection === 'up' + }, 'up to trigger') }) - $scroller.scrollTop(trigger - 1) - }) - waits(standard) - runs(function() { - expect(hit).toBeFalsy() - $scroller.scrollTop(trigger) }) - waitsFor(hitToBeTrue, 'callback to trigger') - }) - it('takes a function offset', function() { - runs(function() { - waypoint = new Waypoint({ - element: $target[0], - handler: setHitTrue, - offset: function() { - return -$(this.element).height() - } + describe('offset option', function() { + beforeEach(function() { + $target = $('#same1') }) - $scroller.scrollTop($target.offset().top + $target.height() - 1) - }) - waits(standard) - runs(function() { - expect(hit).toBeFalsy() - $scroller.scrollTop($target.offset().top + $target.height()) - }) - waitsFor(hitToBeTrue, 'callback to trigger') - }) - it('takes a botton-in-view function alias', function() { - var top = $target.offset().top - var height = $target.outerHeight() - var windowHeight = Waypoint.viewportHeight() - var inview = top + height - windowHeight - runs(function() { - waypoint = new Waypoint({ - element: $target[0], - handler: setHitTrue, - offset: 'bottom-in-view' - }) - $scroller.scrollTop(inview - 1) - }) - waits(standard) - runs(function() { - expect(hit).toBeFalsy() - $scroller.scrollTop(inview) - }) - waitsFor(hitToBeTrue, 'callback to trigger') - }) - }) + it('takes a px offset', function(){ + runs(function() { + waypoint = new Waypoint({ + element: $target[0], + handler: setHitTrue, + offset: 50 + }) + $scroller.scrollTop($target.offset().top - 51) + }) + waits(standard) + runs(function() { + expect(hit).toBeFalsy() + $scroller.scrollTop($target.offset().top - 50) + }) + waitsFor(hitToBeTrue, 'callback to trigger') + }) - describe('triggerOnce option', function() { - it('destroys the waypoint after first trigger', function() { - runs(function() { - $target = $('#same1') - waypoint = new Waypoint({ - element: $target[0], - triggerOnce: true + it('takes a % offset', function() { + var trigger = $target.offset().top - Waypoint.viewportHeight() * .37 + runs(function() { + waypoint = new Waypoint({ + element: $target[0], + handler: setHitTrue, + offset: '37%' + }) + $scroller.scrollTop(trigger - 1) + }) + waits(standard) + runs(function() { + expect(hit).toBeFalsy() + $scroller.scrollTop(trigger) + }) + waitsFor(hitToBeTrue, 'callback to trigger') }) - $scroller.scrollTop($target.offset().top) - }) - waitsFor(function() { - return !waypoint.context.waypoints.vertical[waypoint.key] - }, 'waypoint to be destroyed') - }) - }) - describe('context option', function() { - beforeEach(function() { - $scroller = $('#bottom') - $target = $('#inner3') - }) + it('takes a function offset', function() { + runs(function() { + waypoint = new Waypoint({ + element: $target[0], + handler: setHitTrue, + offset: function() { + return -$(this.element).height() + } + }) + $scroller.scrollTop($target.offset().top + $target.height() - 1) + }) + waits(standard) + runs(function() { + expect(hit).toBeFalsy() + $scroller.scrollTop($target.offset().top + $target.height()) + }) + waitsFor(hitToBeTrue, 'callback to trigger') + }) - it('works with px offset', function() { - waypoint = new Waypoint({ - element: $target[0], - handler: setHitTrue, - context: $scroller[0], - offset: 10 - }) - runs(function() { - $scroller.scrollTop(189) - }) - waits(standard) - runs(function() { - expect(hit).toBeFalsy() - $scroller.scrollTop(190) + it('takes a botton-in-view function alias', function() { + var top = $target.offset().top + var height = $target.outerHeight() + var windowHeight = Waypoint.viewportHeight() + var inview = top + height - windowHeight + runs(function() { + waypoint = new Waypoint({ + element: $target[0], + handler: setHitTrue, + offset: 'bottom-in-view' + }) + $scroller.scrollTop(inview - 1) + }) + waits(standard) + runs(function() { + expect(hit).toBeFalsy() + $scroller.scrollTop(inview) + }) + waitsFor(hitToBeTrue, 'callback to trigger') + }) }) - waitsFor(hitToBeTrue, 'callback to trigger') - }) - it('works with % offset', function() { - waypoint = new Waypoint({ - element: $target[0], - handler: setHitTrue, - context: $scroller[0], - offset: '100%' - }) - runs(function() { - $scroller.scrollTop(149) - }) - waits(standard) - runs(function() { - expect(hit).toBeFalsy() - $scroller.scrollTop(150) + describe('triggerOnce option', function() { + it('destroys the waypoint after first trigger', function() { + runs(function() { + $target = $('#same1') + waypoint = new Waypoint({ + element: $target[0], + triggerOnce: true + }) + $scroller.scrollTop($target.offset().top) + }) + waitsFor(function() { + return !waypoint.context.waypoints.vertical[waypoint.key] + }, 'waypoint to be destroyed') + }) }) - waitsFor(hitToBeTrue, 'callback to trigger') - }) - it('works with function offset', function() { - waypoint = new Waypoint({ - element: $target[0], - handler: setHitTrue, - context: $scroller[0], - offset: function() { - return $(this.element).height() / 2 - } - }) - runs(function() { - $scroller.scrollTop(149) - }) - waits(standard) - runs(function() { - expect(hit).toBeFalsy() - $scroller.scrollTop(150) - }) - waitsFor(hitToBeTrue, 'callback to trigger') - }) + describe('context option', function() { + beforeEach(function() { + $scroller = $('#bottom') + $target = $('#inner3') + }) - it('works with bottom-in-view offset alias', function() { - waypoint = new Waypoint({ - element: $target[0], - handler: setHitTrue, - context: $scroller[0], - offset: 'bottom-in-view' - }) - runs(function() { - $scroller.scrollTop(249) - }) - waits(standard) - runs(function() { - expect(hit).toBeFalsy() - $scroller.scrollTop(250) - }) - waitsFor(hitToBeTrue, 'callback to trigger') - }) - }) + it('works with px offset', function() { + waypoint = new Waypoint({ + element: $target[0], + handler: setHitTrue, + context: $scroller[0], + offset: 10 + }) + runs(function() { + $scroller.scrollTop(189) + }) + waits(standard) + runs(function() { + expect(hit).toBeFalsy() + $scroller.scrollTop(190) + }) + waitsFor(hitToBeTrue, 'callback to trigger') + }) - describe('horizontal option', function() { - var currentDirection - - beforeEach(function() { - currentDirection = null - $target = $('#same1') - waypoint = new Waypoint({ - element: $target[0], - horizontal: true, - handler: function(direction) { - currentDirection = direction - } - }) - }) + it('works with % offset', function() { + waypoint = new Waypoint({ + element: $target[0], + handler: setHitTrue, + context: $scroller[0], + offset: '100%' + }) + runs(function() { + $scroller.scrollTop(149) + }) + waits(standard) + runs(function() { + expect(hit).toBeFalsy() + $scroller.scrollTop(150) + }) + waitsFor(hitToBeTrue, 'callback to trigger') + }) - it('triggers right/left directions', function() { - runs(function() { - $scroller.scrollLeft($target.offset().left) - }) - waitsFor(function() { - return currentDirection === 'right' - }, 'right direction to trigger') - runs(function() { - $scroller.scrollLeft($target.offset().left - 1) - }) - waitsFor(function() { - return currentDirection === 'left' - }) - }) - }) + it('works with function offset', function() { + waypoint = new Waypoint({ + element: $target[0], + handler: setHitTrue, + context: $scroller[0], + offset: function() { + return $(this.element).height() / 2 + } + }) + runs(function() { + $scroller.scrollTop(149) + }) + waits(standard) + runs(function() { + expect(hit).toBeFalsy() + $scroller.scrollTop(150) + }) + waitsFor(hitToBeTrue, 'callback to trigger') + }) - describe('continuous option', function() { - var $later, laterWaypoint, hitCount, hitWaypoint - - function incrementHitCount(direction) { - hitCount += 1 - hitWaypoint = this - } - - beforeEach(function() { - $target = $('#same1') - $later = $('#near1') - hitCount = 0 - waypoint = new Waypoint({ - element: $target[0], - continuous: false, - handler: incrementHitCount - }) - laterWaypoint = new Waypoint({ - element: $later[0], - continuous: false, - handler: incrementHitCount + it('works with bottom-in-view offset alias', function() { + waypoint = new Waypoint({ + element: $target[0], + handler: setHitTrue, + context: $scroller[0], + offset: 'bottom-in-view' + }) + runs(function() { + $scroller.scrollTop(249) + }) + waits(standard) + runs(function() { + expect(hit).toBeFalsy() + $scroller.scrollTop(250) + }) + waitsFor(hitToBeTrue, 'callback to trigger') + }) }) - }) - afterEach(function() { - laterWaypoint.destroy() - }) + describe('horizontal option', function() { + var currentDirection - it('does not trigger the earlier waypoint', function() { - runs(function() { - $scroller.scrollTop($later.offset().top) - }) - waitsFor(function() { - return hitCount - }, 'later callback to trigger') - runs(function() { - expect(hitCount).toEqual(1) - expect(hitWaypoint).toEqual(laterWaypoint) - }) - }) + beforeEach(function() { + currentDirection = null + $target = $('#same1') + waypoint = new Waypoint({ + element: $target[0], + horizontal: true, + handler: function(direction) { + currentDirection = direction + } + }) + }) - it('prevents earlier trigger on refresh', function() { - runs(function() { - $target.css('top', '-1px') - $later.css('top', '-2px') - Waypoint.refresh() - }) - waitsFor(function() { - return hitCount - }, 'later callback to trigger') - runs(function() { - expect(hitCount).toEqual(1) - expect(hitWaypoint).toEqual(waypoint) + it('triggers right/left directions', function() { + runs(function() { + $scroller.scrollLeft($target.offset().left) + }) + waitsFor(function() { + return currentDirection === 'right' + }, 'right direction to trigger') + runs(function() { + $scroller.scrollLeft($target.offset().left - 1) + }) + waitsFor(function() { + return currentDirection === 'left' + }) + }) }) - }) - }) - describe('with window as the waypoint element', function() { - beforeEach(function() { - $target = $(window) - waypoint = new Waypoint({ - element: $target[0], - offset: -$target.height(), - handler: setHitTrue - }) - }) + describe('continuous option', function() { + var $later, laterWaypoint, hitCount, hitWaypoint - it('triggers waypoint', function() { - runs(function() { - $target.scrollTop($target.height() + 1) - }) - waitsFor(hitToBeTrue, 'callback to trigger') - }) - }) + function incrementHitCount(direction) { + hitCount += 1 + hitWaypoint = this + } - describe('#disable()', function() { - beforeEach(function() { - $target = $('#same1') - waypoint = new Waypoint({ - element: $target[0], - handler: setHitTrue - }) - returnValue = waypoint.disable() - }) + beforeEach(function() { + $target = $('#same1') + $later = $('#near1') + hitCount = 0 + waypoint = new Waypoint({ + element: $target[0], + continuous: false, + handler: incrementHitCount + }) + laterWaypoint = new Waypoint({ + element: $later[0], + continuous: false, + handler: incrementHitCount + }) + }) - it('returns the same waypoint object for chaining', function() { - expect(returnValue).toEqual(waypoint) - }) + afterEach(function() { + laterWaypoint.destroy() + }) - it('disables callback triggers', function() { - runs(function() { - $scroller.scrollTop($target.offset().top) - }) - waits(standard) - runs(function() { - expect(hit).toBeFalsy() - }) - }) - }) + it('does not trigger the earlier waypoint', function() { + runs(function() { + $scroller.scrollTop($later.offset().top) + }) + waitsFor(function() { + return hitCount + }, 'later callback to trigger') + runs(function() { + expect(hitCount).toEqual(1) + expect(hitWaypoint).toEqual(laterWaypoint) + }) + }) - describe('#enable()', function() { - beforeEach(function() { - $target = $('#same1') - waypoint = new Waypoint({ - element: $target[0], - handler: setHitTrue + it('prevents earlier trigger on refresh', function() { + runs(function() { + $target.css('top', '-1px') + $later.css('top', '-2px') + Waypoint.refresh() + }) + waitsFor(function() { + return hitCount + }, 'later callback to trigger') + runs(function() { + expect(hitCount).toEqual(1) + expect(hitWaypoint).toEqual(waypoint) + }) + }) }) - waypoint.disable() - returnValue = waypoint.enable() - }) - it('returns the same waypoint instance for chaining', function() { - expect(returnValue).toEqual(waypoint) - }) + describe('with window as the waypoint element', function() { + beforeEach(function() { + $target = $(window) + waypoint = new Waypoint({ + element: $target[0], + offset: -$target.height(), + handler: setHitTrue + }) + }) - it('enables callback triggers', function() { - runs(function() { - $scroller.scrollTop($target.offset().top) + it('triggers waypoint', function() { + runs(function() { + $target.scrollTop($target.height() + 1) + }) + waitsFor(hitToBeTrue, 'callback to trigger') + }) }) - waitsFor(hitToBeTrue, 'callback to trigger') - }) - }) - describe('#destroy()', function() { - beforeEach(function() { - $target = $('#same1') - waypoint = new Waypoint({ - element: $target[0], - handler: setHitTrue + describe('#disable()', function() { + beforeEach(function() { + $target = $('#same1') + waypoint = new Waypoint({ + element: $target[0], + handler: setHitTrue + }) + returnValue = waypoint.disable() + }) + + it('returns the same waypoint object for chaining', function() { + expect(returnValue).toEqual(waypoint) + }) + + it('disables callback triggers', function() { + runs(function() { + $scroller.scrollTop($target.offset().top) + }) + waits(standard) + runs(function() { + expect(hit).toBeFalsy() + }) + }) }) - returnValue = waypoint.destroy() - }) - it('returns undefined', function() { - expect(returnValue).toBeUndefined() - }) + describe('#enable()', function() { + beforeEach(function() { + $target = $('#same1') + waypoint = new Waypoint({ + element: $target[0], + handler: setHitTrue + }) + waypoint.disable() + returnValue = waypoint.enable() + }) - it('no longer triggers callbacks', function() { - runs(function() { - $scroller.scrollTop($target.offset().top) + it('returns the same waypoint instance for chaining', function() { + expect(returnValue).toEqual(waypoint) + }) + + it('enables callback triggers', function() { + runs(function() { + $scroller.scrollTop($target.offset().top) + }) + waitsFor(hitToBeTrue, 'callback to trigger') + }) }) - waits(standard) - runs(function() { - expect(hit).toBeFalsy() + + describe('#destroy()', function() { + beforeEach(function() { + $target = $('#same1') + waypoint = new Waypoint({ + element: $target[0], + handler: setHitTrue + }) + returnValue = waypoint.destroy() + }) + + it('returns undefined', function() { + expect(returnValue).toBeUndefined() + }) + + it('no longer triggers callbacks', function() { + runs(function() { + $scroller.scrollTop($target.offset().top) + }) + waits(standard) + runs(function() { + expect(hit).toBeFalsy() + }) + }) }) - }) - }) - describe('Waypoint.viewportHeight()', function() { - it('returns window innerHeight if it exists', function() { - var height = Waypoint.viewportHeight() - if (window.innerHeight) { - expect(height).toEqual(window.innerHeight) - } - else { - expect(height).toEqual(document.documentElement.clientHeight) - } - }) - }) + describe('Waypoint.viewportHeight()', function() { + it('returns window innerHeight if it exists', function() { + var height = Waypoint.viewportHeight() + if (window.innerHeight) { + expect(height).toEqual(window.innerHeight) + } + else { + expect(height).toEqual(document.documentElement.clientHeight) + } + }) + }) - describe('Waypoint.refresh()', function() { - it('is an alias for Waypoint.Context.refreshAll', function() { - spyOn(Waypoint.Context, 'refreshAll') - Waypoint.refresh() - expect(Waypoint.Context.refreshAll).toHaveBeenCalled() + describe('Waypoint.refresh()', function() { + it('is an alias for Waypoint.Context.refreshAll', function() { + spyOn(Waypoint.Context, 'refreshAll') + Waypoint.refresh() + expect(Waypoint.Context.refreshAll).toHaveBeenCalled() + }) + }) }) }) }) diff --git a/testem.json b/testem.json index 82a30499..9e9ae955 100644 --- a/testem.json +++ b/testem.json @@ -9,9 +9,7 @@ "src_files": [ "bower_components/jquery/dist/jquery.js", "bower_components/jasmine-jquery/lib/jasmine-jquery.js", - "lib/waypoints.js", - "lib/waypoints-infinite.js", - "lib/waypoints-sticky.js", + "bower_components/zepto/zepto.js", "src/waypoint.js", "src/context.js", From afa54c578b1f89b6e5beaacbf88a91b824f22fff Mon Sep 17 00:00:00 2001 From: imakewebthings Date: Thu, 19 Jun 2014 12:35:55 -0700 Subject: [PATCH 18/98] Noframework adapter and jQuery/Zepto fn extension --- src/adapters/jquery-zepto-fn-extension.js | 32 ++++ src/adapters/noframework.js | 169 ++++++++++++++++++++++ test/adapter-fn-spec.js | 49 +++++++ test/waypoint-spec.js | 2 +- 4 files changed, 251 insertions(+), 1 deletion(-) create mode 100644 src/adapters/jquery-zepto-fn-extension.js create mode 100644 src/adapters/noframework.js create mode 100644 test/adapter-fn-spec.js diff --git a/src/adapters/jquery-zepto-fn-extension.js b/src/adapters/jquery-zepto-fn-extension.js new file mode 100644 index 00000000..3aa86527 --- /dev/null +++ b/src/adapters/jquery-zepto-fn-extension.js @@ -0,0 +1,32 @@ +(function() { + function createExtension(framework) { + return function() { + var waypoints = [] + var overrides = arguments[0] + + if (framework.isFunction(arguments[0])) { + overrides = framework.extend({}, arguments[1]) + overrides.handler = arguments[0] + } + + this.each(function() { + var options = framework.extend({}, overrides, { + element: this + }) + if (typeof options.context === 'string') { + options.context = framework(this).closest(options.context)[0] + } + waypoints.push(new Waypoint(options)) + }) + + return waypoints + } + } + + if (window.jQuery) { + window.jQuery.fn.waypoint = createExtension(window.jQuery) + } + if (window.Zepto) { + window.Zepto.fn.waypoint = createExtension(window.Zepto) + } +})() diff --git a/src/adapters/noframework.js b/src/adapters/noframework.js new file mode 100644 index 00000000..ebf49a95 --- /dev/null +++ b/src/adapters/noframework.js @@ -0,0 +1,169 @@ +(function() { + function isWindow(element) { + return element == element.window + } + + function getWindow(element) { + if (isWindow(element)) { + return element + } + return element.defaultView + } + + var eventHandlers = {} + + var NoFrameworkAdapter = function(element) { + this.element = element + } + + NoFrameworkAdapter.prototype.height = function() { + var isWin = isWindow(this.element) + return isWin ? this.element.innerHeight : this.element.offsetHeight + } + + NoFrameworkAdapter.prototype.off = function(event, handler) { + function removeListeners(element, listeners, handler) { + for (var i = 0, end = listeners.length - 1; i < end; i++) { + var listener = listeners[i] + if (!handler || handler === listener) { + element.removeEventListener(listener) + } + } + } + + var eventParts = event.split('.') + var eventType = eventParts[0] + var namespace = eventParts[1] + var element = this.element + + if (namespace && eventHandlers[namespace] && eventType) { + removeListeners(element, eventHandlers[namespace][eventType], handler) + eventHandlers[namespace][eventType] = [] + } + else if (eventType) { + for (var ns in eventHandlers) { + removeListeners(element, eventHandlers[ns][eventType] || [], handler) + eventHandlers[ns][eventType] = [] + } + } + else if (namespace && eventHandlers[namespace]) { + for (var type in eventHandlers[namespace]) { + removeListeners(element, eventHandlers[namespace][type], handler) + } + eventHandlers[namespace] = {} + } + } + + /* Adapted from jQuery 1.x offset() */ + NoFrameworkAdapter.prototype.offset = function() { + if (!this.element.ownerDocument) { + return + } + + var documentElement = this.element.ownerDocument.documentElement + var win = getWindow(this.element.ownerDocument) + var rect = { + top: 0, + left: 0 + } + + if (this.element.getBoundingClientRect) { + rect = this.element.getBoundingClientRect() + } + + return { + top: rect.top + win.pageYOffset - documentElement.clientTop, + left: rect.left + win.pageXOffset - documentElement.clientLeft + } + } + + NoFrameworkAdapter.prototype.on = function(event, handler) { + var eventParts = event.split('.') + var eventType = eventParts[0] + var namespace = eventParts[1] || '__default' + var nsHandlers = eventHandlers[namespace] = eventHandlers[namespace] || {} + var nsTypeList = nsHandlers[eventType] = nsHandlers[eventType] || [] + + nsTypeList.push(handler) + this.element.addEventListener(eventType, handler) + } + + NoFrameworkAdapter.prototype.outerHeight = function(includeMargin) { + var height = this.height() + var computedStyle + + if (includeMargin && !isWindow(this.element)) { + computedStyle = window.getComputedStyle(this.element) + height += parseInt(computedStyle.marginTop, 10) + height += parseInt(computedStyle.marginBottom, 10) + } + + return height + } + + NoFrameworkAdapter.prototype.outerWidth = function(includeMargin) { + var width = this.width() + var computedStyle + + if (includeMargin && !isWindow(this.element)) { + computedStyle = window.getComputedStyle(this.element) + width += parseInt(computedStyle.marginLeft, 10) + width += parseInt(computedStyle.marginRight, 10) + } + + return width + } + + NoFrameworkAdapter.prototype.scrollLeft = function() { + var win = getWindow(this.element) + return win ? win.pageXOffset : this.element.scrollLeft + } + + NoFrameworkAdapter.prototype.scrollTop = function() { + var win = getWindow(this.element) + return win ? win.pageYOffset : this.element.scrollTop + } + + NoFrameworkAdapter.prototype.width = function() { + var isWin = isWindow(this.element) + return isWin ? this.element.innerWidth : this.element.offsetWidth + } + + NoFrameworkAdapter.extend = function() { + var args = Array.prototype.slice.call(arguments) + + function merge(target, obj) { + if (typeof target === 'object' && typeof obj === 'object') { + for (var key in obj) { + if (obj.hasOwnProperty(key)) { + target[key] = obj[key] + } + } + } + + return target + } + + for (var i = 1, end = args.length; i < end; i++) { + merge(args[0], args[i]) + } + return args[0] + } + + NoFrameworkAdapter.inArray = function(element, array, i) { + return array == null ? -1 : array.indexOf(element, i) + } + + NoFrameworkAdapter.isEmptyObject = function(obj) { + for (var name in obj) { + return false + } + return true + } + + window.Waypoint.adapters.push({ + name: 'noframework', + Adapter: NoFrameworkAdapter + }) + window.Waypoint.Adapter = NoFrameworkAdapter +})() diff --git a/test/adapter-fn-spec.js b/test/adapter-fn-spec.js new file mode 100644 index 00000000..b816b536 --- /dev/null +++ b/test/adapter-fn-spec.js @@ -0,0 +1,49 @@ +jQuery.each(jQuery.grep(Waypoint.adapters, function(adapter) { + return "jquery zepto".indexOf(adapter.name) > -1 +}), function(i, adapter) { + describe('$.fn extension for ' + adapter.name + ':', function() { + var $, waypoints + + beforeEach(function() { + $ = adapter.name === 'jquery' ? jQuery : Zepto + Waypoint.Adapter = adapter.Adapter + loadFixtures('standard.html') + }) + + afterEach(function() { + $.each(waypoints, function(i, waypoint) { + waypoint.destroy() + }) + waits(50) + }) + + describe('waypoint initialization', function() { + it('uses the subject elements as the element option', function() { + waypoints = $('.nearsame').waypoint({}) + expect(waypoints[0].element.id).toEqual('near1') + expect(waypoints[1].element.id).toEqual('near2') + }) + + it('returns an array of Waypoint instances', function() { + waypoints = $('.nearsame').waypoint({}) + expect($.isArray(waypoints)).toBeTruthy() + expect(waypoints.length).toEqual(2) + }) + + it('can take the handler as the first parameter', function() { + var handler = function() {} + waypoints = $('#near1').waypoint(handler) + expect(waypoints[0].callback).toBe(handler) + }) + }) + + describe('context option', function() { + it('can be given a string selector', function() { + waypoints = $('#inner3').waypoint({ + context: '#bottom' + }) + expect(waypoints[0].context.element).toBe($('#bottom')[0]) + }) + }) + }) +}) diff --git a/test/waypoint-spec.js b/test/waypoint-spec.js index 9396fa0f..522309aa 100644 --- a/test/waypoint-spec.js +++ b/test/waypoint-spec.js @@ -158,7 +158,7 @@ jQuery.each(Waypoint.adapters, function(i, adapter) { waitsFor(hitToBeTrue, 'callback to trigger') }) - it('takes a botton-in-view function alias', function() { + it('takes a bottom-in-view function alias', function() { var top = $target.offset().top var height = $target.outerHeight() var windowHeight = Waypoint.viewportHeight() From 8efeff6d8b71fe3db5ca91978541a94be6e154e4 Mon Sep 17 00:00:00 2001 From: imakewebthings Date: Thu, 19 Jun 2014 18:45:41 -0700 Subject: [PATCH 19/98] Context destroy and Waypoint destroyAll --- src/context.js | 16 ++++++++++++++++ src/group.js | 5 ++++- src/waypoint.js | 13 +++++++++++++ test/context-spec.js | 27 +++++++++++++++++++++++++-- test/waypoint-spec.js | 17 +++++++++++++++++ 5 files changed, 75 insertions(+), 3 deletions(-) diff --git a/src/context.js b/src/context.js index 18c4f14b..1030017b 100644 --- a/src/context.js +++ b/src/context.js @@ -35,6 +35,7 @@ this.createThrottledResizeHandler() } + /* Internal */ Context.prototype.createThrottledScrollHandler = function() { var self = this var scrollHandler = function() { @@ -50,6 +51,7 @@ }) } + /* Internal */ Context.prototype.createThrottledResizeHandler = function() { var self = this var resizeHandler = function() { @@ -65,6 +67,7 @@ }) } + /* Internal */ Context.prototype.handleScroll = function(options) { var triggeredGroups = {} var axes = { @@ -110,6 +113,7 @@ } } + /* Internal */ Context.prototype.handleResize = function() { Waypoint.Context.refreshAll() } @@ -196,6 +200,18 @@ return this } + Context.prototype.destroy = function() { + var allWaypoints = [] + for (var axis in this.waypoints) { + for (var waypointKey in this.waypoints[axis]) { + allWaypoints.push(this.waypoints[axis][waypointKey]) + } + } + for (var i = 0, end = allWaypoints.length; i < end; i++) { + allWaypoints[i].destroy() + } + } + /* Internal */ Context.prototype.add = function(waypoint) { var axis = waypoint.options.horizontal ? 'horizontal' : 'vertical' diff --git a/src/group.js b/src/group.js index ef065c25..d35f8f96 100644 --- a/src/group.js +++ b/src/group.js @@ -49,7 +49,10 @@ /* Internal */ Group.prototype.remove = function(waypoint) { - this.waypoints.splice(window.Waypoint.Adapter.inArray(waypoint), 1) + var index = window.Waypoint.Adapter.inArray(waypoint, this.waypoints) + if (index > -1) { + this.waypoints.splice(index, 1) + } } /* Internal */ diff --git a/src/waypoint.js b/src/waypoint.js index 69a152aa..d4b50138 100644 --- a/src/waypoint.js +++ b/src/waypoint.js @@ -1,5 +1,6 @@ (function() { var keyCounter = 0 + var allWaypoints = {} var Waypoint = function(options) { if (!options) { @@ -28,6 +29,7 @@ } this.context.add(this) this.group.add(this) + allWaypoints[this.key] = this keyCounter += 1 } @@ -45,6 +47,7 @@ Waypoint.prototype.destroy = function() { this.context.remove(this) this.group.remove(this) + delete allWaypoints[this.key] } /* Internal */ @@ -94,5 +97,15 @@ Waypoint.Context.refreshAll() } + Waypoint.destroyAll = function() { + var allWaypointsArray = [] + for (var waypointKey in allWaypoints) { + allWaypointsArray.push(allWaypoints[waypointKey]) + } + for (var i = 0, end = allWaypointsArray.length; i < end; i++) { + allWaypointsArray[i].destroy() + } + } + window.Waypoint = Waypoint })() diff --git a/test/context-spec.js b/test/context-spec.js index 5c94f6b1..a314dbf5 100644 --- a/test/context-spec.js +++ b/test/context-spec.js @@ -3,7 +3,7 @@ jQuery.each(Waypoint.adapters, function(i, adapter) { describe('Waypoint.Context', function() { var $ = jQuery var standard = 50 - var currentDirection, $scroller, waypoint, $target, context + var currentDirection, $scroller, waypoint, $target, context, skipDestroy function setDirection(direction) { currentDirection = direction @@ -18,6 +18,7 @@ jQuery.each(Waypoint.adapters, function(i, adapter) { loadFixtures('standard.html') $scroller = $(window) currentDirection = null + skipDestroy = false $target = $('#same1') waypoint = new Waypoint({ element: $target[0], @@ -27,7 +28,9 @@ jQuery.each(Waypoint.adapters, function(i, adapter) { }) afterEach(function() { - waypoint.destroy() + if (!skipDestroy) { + waypoint.destroy() + } $scroller.scrollTop(0).scrollLeft(0) waits(standard) }) @@ -61,6 +64,26 @@ jQuery.each(Waypoint.adapters, function(i, adapter) { }) }) + describe('#destroy', function() { + it('prevents further waypoint triggers', function() { + skipDestroy = true + runs(function() { + context.destroy() + $scroller.scrollTop($target.offset().top) + }) + waits(standard) + runs(function() { + expect(currentDirection).toBeNull() + }) + }) + + it('removes context from global lookup', function() { + skipDestroy = true + context.destroy() + expect(Waypoint.Context.findByElement(window)).toBeFalsy() + }) + }) + describe('Waypoint.Context.refreshAll()', function() { it('calls refresh on all contexts', function() { var secondWaypoint = new Waypoint({ diff --git a/test/waypoint-spec.js b/test/waypoint-spec.js index 522309aa..766610a2 100644 --- a/test/waypoint-spec.js +++ b/test/waypoint-spec.js @@ -475,6 +475,23 @@ jQuery.each(Waypoint.adapters, function(i, adapter) { expect(Waypoint.Context.refreshAll).toHaveBeenCalled() }) }) + + describe('Waypoint.destroyAll()', function() { + it('calls destroy on all waypoints', function() { + var secondWaypoint = new Waypoint({ + element: $('#same1')[0] + }) + waypoint = new Waypoint({ + element: $('#same1')[0] + }) + spyOn(secondWaypoint, 'destroy') + spyOn(waypoint, 'destroy') + Waypoint.destroyAll() + expect(secondWaypoint.destroy).toHaveBeenCalled() + expect(waypoint.destroy).toHaveBeenCalled() + waypoint = null + }) + }) }) }) }) From a83c8719f572e108c95f215ddbfef36bc8fb1828 Mon Sep 17 00:00:00 2001 From: imakewebthings Date: Fri, 20 Jun 2014 10:52:11 -0700 Subject: [PATCH 20/98] Clean up unused old test files --- test/AMD.html | 33 -- test/index.html | 44 -- test/infinite.coffee | 55 -- test/sticky.coffee | 67 --- test/waypoints-infinite-xspec.js | 68 --- test/waypoints-sticky-xspec.js | 80 --- test/waypoints-xspec.js | 828 ------------------------------- test/waypoints.coffee | 740 --------------------------- 8 files changed, 1915 deletions(-) delete mode 100644 test/AMD.html delete mode 100644 test/index.html delete mode 100644 test/infinite.coffee delete mode 100644 test/sticky.coffee delete mode 100644 test/waypoints-infinite-xspec.js delete mode 100644 test/waypoints-sticky-xspec.js delete mode 100644 test/waypoints-xspec.js delete mode 100644 test/waypoints.coffee diff --git a/test/AMD.html b/test/AMD.html deleted file mode 100644 index e3f1427e..00000000 --- a/test/AMD.html +++ /dev/null @@ -1,33 +0,0 @@ - - - - Waypoints AMD Test Runner - - - - - - - - - diff --git a/test/index.html b/test/index.html deleted file mode 100644 index 046df371..00000000 --- a/test/index.html +++ /dev/null @@ -1,44 +0,0 @@ - - - - - - -Waypoints Test Runner (Mocha) - - - - - -
- - - - - - - - - - - - - - diff --git a/test/infinite.coffee b/test/infinite.coffee deleted file mode 100644 index 877c8cd2..00000000 --- a/test/infinite.coffee +++ /dev/null @@ -1,55 +0,0 @@ -$.waypoints.settings.scrollThrottle = 10 -$.waypoints.settings.resizeThrottle = 20 -standardWait = 50 - -describe 'Waypoints Infinite Scroll Shortcut', -> - $items = $container = $more = beforeHit = afterHit = null - $win = $ window - - beforeEach -> - loadFixtures 'infinite.html' - $items = $ '.infinite-item' - $container = $ '.infinite-container' - $more = $ '.infinite-more-link' - beforeHit = afterHit = false - - it 'returns the same jQuery object for chaining', -> - expect($container.waypoint('infinite').get()).toEqual $container.get() - - describe 'loading new pages', -> - beforeEach -> - options = - onBeforePageLoad: -> beforeHit = true - onAfterPageLoad: -> afterHit = true - runs -> - $container.waypoint 'infinite', options - scrollVal = $.waypoints('viewportHeight') - $container.height() - $win.scrollTop scrollVal - done = -> $('.infinite-item').length > $items.length - waitsFor done, 2000, 'new items to load' - - it 'appends them to the infinite container', -> - expect($('.infinite-container > .infinite-item').length).toEqual 10 - - it 'replaces the more link with the new more link', -> - expect($more[0]).not.toEqual $('.infinite-more-link')[0] - expect($('.infinite-more-link').length).toEqual 1 - - it 'fires the before callback', -> - expect(beforeHit).toBeTruthy() - - it 'fires the after callback', -> - expect(afterHit).toBeTruthy() - - describe 'when no more link on initialize', -> - beforeEach -> - $more.remove() - $container.waypoint 'infinite' - - it 'does not create the waypoint', -> - expect($.waypoints().vertical.length).toEqual 0 - - afterEach -> - $.waypoints 'destroy' - $win.scrollTop 0 - diff --git a/test/sticky.coffee b/test/sticky.coffee deleted file mode 100644 index 03291cf7..00000000 --- a/test/sticky.coffee +++ /dev/null @@ -1,67 +0,0 @@ -$.waypoints.settings.scrollThrottle = 10 -$.waypoints.settings.resizeThrottle = 20 -standardWait = 50 - -describe 'Waypoints Sticky Elements Shortcut', -> - $sticky = $return = handlerSpy = null - $win = $ window - - beforeEach -> - loadFixtures 'sticky.html' - $sticky = $ '.sticky' - handlerSpy = jasmine.createSpy 'on handler' - $return = $sticky.waypoint 'sticky', - handler: handlerSpy - - it 'returns the same jQuery object for chaining', -> - expect($return.get()).toEqual $sticky.get() - - it 'wraps the sticky element', -> - expect($sticky.parent()).toHaveClass 'sticky-wrapper' - - it 'gives the wrapper the same height as the sticky element', -> - expect($sticky.parent().height()).toEqual $sticky.outerHeight() - - it 'adds stuck class when you reach the element', -> - runs -> - $win.scrollTop $sticky.offset().top - waits standardWait - - runs -> - expect($sticky).toHaveClass 'stuck' - $win.scrollTop $win.scrollTop()-1 - waits standardWait - - runs -> - expect($sticky).not.toHaveClass 'stuck' - - it 'executes handler option after stuck class applied', -> - runs -> - $win.scrollTop $sticky.offset().top - waits standardWait - - runs -> - expect(handlerSpy).toHaveBeenCalled() - - describe '#waypoint("unsticky")', -> - beforeEach -> - $return = $sticky.waypoint 'unsticky' - - it 'returns the same jQuery object for chaining', -> - expect($return.get()).toEqual $sticky.get() - - it 'unwraps the sticky element', -> - expect($sticky.parent()).not.toHaveClass 'sticky-wrapper' - - it 'should not have stuck class', -> - expect($sticky).not.toHaveClass 'stuck' - - it 'does nothing if called on a non-sticky element', -> - $parent = $sticky.parent() - $sticky.waypoint 'unsticky' - expect($parent.closest('body')).toExist() - - afterEach -> - $.waypoints 'destroy' - $win.scrollTop 0 - diff --git a/test/waypoints-infinite-xspec.js b/test/waypoints-infinite-xspec.js deleted file mode 100644 index 2e5ece80..00000000 --- a/test/waypoints-infinite-xspec.js +++ /dev/null @@ -1,68 +0,0 @@ -describe('Waypoints Infinite Scroll Shortcut', function() { - var standard = 50 - var $window = $(window) - var $items, $container, $more, beforeHit, afterHit - - beforeEach(function() { - loadFixtures('infinite.html') - $items = $('.infinite-item') - $container = $('.infinite-container') - $more = $('.infinite-more-link') - beforeHit = afterHit = false - }) - - afterEach(function() { - runs(function() { - $.waypoints('destroy') - $window.scrollTop(0) - }) - waits(standard) - }) - - it('returns the same jQuery object for chaining', function() { - expect($container.waypoint('infinite').get()).toEqual($container.get()) - }) - - describe('loading new pages', function() { - beforeEach(function() { - runs(function() { - var triggerPoint = $.waypoints('viewportHeight') - $container.height() - $container.waypoint('infinite', { - onBeforePageLoad: function() { - beforeHit = true - }, - onAfterPageLoad: function() { - afterHit = true - } - }) - $window.scrollTop(triggerPoint) - }) - waitsFor(function() { - return $('.infinite-container > .infinite-item').length > $items.length - }, 'new items to load') - }) - - it('replaces the more link with the new more link', function() { - expect($more[0]).not.toEqual($('.infinite-more-link')[0]) - }) - - it('fires the before callback', function() { - expect(beforeHit).toBeTruthy() - }) - - it('fires the after callback', function() { - expect(afterHit).toBeTruthy() - }) - }) - - describe('when there is no more link on initialization', function() { - beforeEach(function() { - $more.remove() - $container.waypoint('infinite') - }) - - it('does not create the waypoint', function() { - expect($.waypoints().vertical.length).toEqual(0) - }) - }) -}) diff --git a/test/waypoints-sticky-xspec.js b/test/waypoints-sticky-xspec.js deleted file mode 100644 index fc19ff3b..00000000 --- a/test/waypoints-sticky-xspec.js +++ /dev/null @@ -1,80 +0,0 @@ -describe('Waypoints Sticky Elements Shortcut', function() { - var standard = 50 - var $window = $(window) - var $sticky, $return, handlerSpy - - beforeEach(function() { - loadFixtures('sticky.html') - $sticky = $('.sticky') - handlerSpy = jasmine.createSpy('on handler') - $return = $sticky.waypoint('sticky', { - handler: handlerSpy - }) - }) - - afterEach(function() { - $.waypoints('destroy') - $window.scrollTop(0) - waits(standard) - }) - - it('returns the same jQuery object for chaining', function() { - expect($return.get()).toEqual($sticky.get()) - }) - - it('wraps the sticky element', function() { - expect($sticky.parent()).toHaveClass('sticky-wrapper') - }) - - it('gives the wrapper the same height as the sticky element', function() { - expect($sticky.parent().height()).toEqual($sticky.outerHeight()) - }) - - it('adds stuck class when you scroll to the element', function() { - runs(function() { - $window.scrollTop($sticky.offset().top) - }) - waitsFor(function() { - return $sticky.hasClass('stuck') - }, 'stuck class to apply') - runs(function() { - $window.scrollTop($window.scrollTop() - 1) - }) - waitsFor(function() { - return !$sticky.hasClass('stuck') - }) - }) - - it('executes handler option after stuck class applied', function() { - runs(function() { - $window.scrollTop($sticky.offset().top) - }) - waitsFor(function() { - return handlerSpy.callCount - }, 'callback to trigger') - }) - - describe('#waypoint("unsticky")', function() { - beforeEach(function() { - $return = $sticky.waypoint('unsticky') - }) - - it('returns the same jQuery object for chaining', function() { - expect($return.get()).toEqual($sticky.get()) - }) - - it('unwraps the sticky element', function() { - expect($sticky.parent()).not.toHaveClass('sticky-wrapper') - }) - - it('should not have stuck class', function() { - expect($sticky).not.toHaveClass('stuck') - }) - - it('does nothing if called on a non-sticky element', function() { - $parent = $sticky.parent() - $sticky.waypoint('unsticky') - expect($parent.closest('body')).toExist() - }) - }) -}) diff --git a/test/waypoints-xspec.js b/test/waypoints-xspec.js deleted file mode 100644 index e39d1fe0..00000000 --- a/test/waypoints-xspec.js +++ /dev/null @@ -1,828 +0,0 @@ -describe('jQuery Waypoints', function() { - var standard = 50 - var hit, $scroller, $target, $return - - function setHitTrue() { - hit = true - } - - beforeEach(function() { - loadFixtures('standard.html') - $scroller = $(window) - hit = false - }) - - afterEach(function() { - $.waypoints('destroy') - $scroller.scrollTop(0).scrollLeft(0) - waits(standard) - }) - - describe('#waypoint()', function() { - it ('errors out', function() { - expect(function() { - $('#same1').waypoint() - }).toThrow() - }) - }) - - describe('#waypoint(callback)', function() { - var currentDirection - - beforeEach(function() { - currentDirection = null - $target = $('#same1').waypoint(function(direction) { - currentDirection = direction - hit = true - }) - }) - - it('creates a waypoint', function() { - expect($.waypoints().vertical.length).toEqual(1) - }) - - it('triggers the callback', function() { - runs(function() { - $scroller.scrollTop($target.offset().top) - }) - waitsFor(function() { - return hit - }, 'callback to trigger') - }) - - it('uses the default offset', function(done) { - runs(function() { - $scroller.scrollTop($target.offset().top - 1) - }) - waits(standard) - runs(function() { - expect(hit).toBeFalsy() - $scroller.scrollTop($target.offset().top) - }) - waitsFor(function() { - return hit - }, 'callback to trigger') - }) - - it('passes correct directions', function() { - runs(function() { - $scroller.scrollTop($target.offset().top) - }) - waitsFor(function() { - return currentDirection === 'down' - }, 'down to trigger') - runs(function() { - $scroller.scrollTop($target.offset().top - 1) - }) - waitsFor(function() { - return currentDirection === 'up' - }, 'up to trigger') - }) - }) - - describe('#waypoint(options)', function() { - beforeEach(function() { - $target = $('#same1') - }) - - it('creates a waypoint', function() { - $target.waypoint({ triggerOnce: true }) - expect($.waypoints().vertical.length).toEqual(1) - }) - - it('respects a px offset', function() { - runs(function() { - $target.waypoint({ - offset: 50, - handler: setHitTrue - }) - $scroller.scrollTop($target.offset().top - 51) - }) - waits(standard) - runs(function() { - expect(hit).toBeFalsy() - $scroller.scrollTop($target.offset().top - 50) - }) - waitsFor(function() { - return hit - }, 'callback to trigger') - }) - - it('respects a % offset', function() { - var trigger = $target.offset().top - $.waypoints('viewportHeight') * .37 - runs(function() { - $target.waypoint({ - offset: '37%', - handler: setHitTrue - }) - $scroller.scrollTop(trigger - 1) - }) - waits(standard) - runs(function() { - expect(hit).toBeFalsy() - $scroller.scrollTop(trigger) - }) - waitsFor(function() { - return hit - }, 'callback to trigger') - }) - - it('respects a function offset', function() { - runs(function() { - $target.waypoint({ - offset: function() { - return -$(this).height() - }, - handler: setHitTrue - }) - $scroller.scrollTop($target.offset().top + $target.height() - 1) - }) - waits(standard) - runs(function() { - expect(hit).toBeFalsy() - $scroller.scrollTop($target.offset().top + $target.height()) - }) - waitsFor(function() { - return hit - }, 'callback to trigger') - }) - - it('respects the botton-in-view function alias', function() { - var top = $target.offset().top - var height = $target.outerHeight() - var windowHeight = $.waypoints('viewportHeight') - var inview = top + height - windowHeight - runs(function() { - $target.waypoint({ - offset: 'bottom-in-view', - handler: setHitTrue - }) - $scroller.scrollTop(inview - 1) - }) - waits(standard) - runs(function() { - expect(hit).toBeFalsy() - $scroller.scrollTop(inview) - }) - waitsFor(function() { - return hit - }, 'callback to trigger') - }) - - it('destroys the waypoint if triggerOnce is true', function() { - runs(function() { - $target.waypoint({ - triggerOnce: true - }) - $scroller.scrollTop($target.offset().top) - }) - waitsFor(function() { - return !$.waypoints().vertical.length - }, 'waypoint to be destroyed') - }) - - it('triggers if continuous is true and waypoint is not last', function() { - var $near1 = $('#near1') - var $near2 = $('#near2') - var hitcount = 0 - runs(function() { - $target.add($near1).add($near2).waypoint(function() { - hitcount += 1 - }) - $scroller.scrollTop($near2.offset().top) - }) - waitsFor(function() { - return hitcount === 3 - }, 'all waypoints to trigger') - }) - - it('does not trigger if continuous false, waypoint not last', function() { - var $near1 = $('#near1') - var $near2 = $('#near2') - var hitcount = 0 - runs(function() { - var callback = function() { - hitcount += 1 - } - $target.add($near2).waypoint(callback) - $near1.waypoint(callback, { - continuous: false - }) - $scroller.scrollTop($near2.offset().top) - }) - waitsFor(function() { - return hitcount === 2 - }, 'all waypoints to trigger') - }) - - it('triggers if continuous false, waypoint is last', function() { - var $near1 = $('#near1') - var $near2 = $('#near2') - var hitcount = 0 - runs(function() { - var callback = function() { - hitcount += 1 - } - $target.add($near1).waypoint(callback) - $near2.waypoint(callback, { - continuous: false - }) - $scroller.scrollTop($near2.offset().top) - }) - waitsFor(function() { - return hitcount === 3 - }, 'all waypoints to trigger') - }) - }) - - describe('#waypoint(callback, options)', function() { - beforeEach(function() { - $target = $('#same1').waypoint(setHitTrue, { - offset: -1 - }) - }) - - it('creates a waypoint', function() { - expect($.waypoints().vertical.length).toEqual(1) - }) - - it('respects options', function() { - runs(function() { - $scroller.scrollTop($target.offset().top) - }) - waits(standard) - runs(function() { - expect(hit).toBeFalsy() - $scroller.scrollTop($target.offset().top + 1) - }) - waitsFor(function() { - return hit - }, 'callback to trigger') - }) - }) - - describe('#waypoint("disable")', function() { - beforeEach(function() { - $target = $('#same1').waypoint(setHitTrue) - $return = $target.waypoint('disable') - }) - - it('disables callback triggers', function() { - runs(function() { - $scroller.scrollTop($target.offset().top) - }) - waits(standard) - runs(function() { - expect(hit).toBeFalsy() - }) - }) - - it('returns the same jQuery object for chaining', function() { - expect($return.get()).toEqual($target.get()) - }) - }) - - describe('#waypoint("enable")', function() { - beforeEach(function() { - $target = $('#same1').waypoint(setHitTrue) - $target.waypoint('disable') - $return = $target.waypoint('enable') - }) - - it('enables callback triggers', function() { - runs(function() { - $scroller.scrollTop($target.offset().top) - }) - waitsFor(function() { - return hit - }, 'callback to trigger') - }) - - it('returns the same jQuery object for chaining', function() { - expect($return.get()).toEqual($target.get()) - }) - }) - - describe('#waypoint("destroy")', function() { - beforeEach(function() { - $target = $('#same1').waypoint(setHitTrue) - $return = $target.waypoint('destroy') - }) - - it('removes waypoint from list of waypoints', function() { - expect($.waypoints().vertical.length).toEqual(0) - }) - - it('no longer triggers callback', function() { - runs(function() { - $scroller.scrollTop($target.offset().top) - }) - waits(standard) - runs(function() { - expect(hit).toBeFalsy() - }) - }) - - it('does not preserve callbacks if .waypoint recalled', function() { - runs(function() { - $target.waypoint({}) - $scroller.scrollTop($target.offset().top) - }) - waits(standard) - runs(function() { - expect(hit).toBeFalsy() - }) - }) - - it('returns the same jQuery object for chaining', function() { - expect($return.get()).toEqual($target.get()) - }) - - it('unregisters waypoint even if underlying nodes are removed', function() { - $target.remove() - $target.waypoint('destroy') - expect($.waypoints().vertical.length).toEqual(0) - }) - }) - - describe('#waypoint("prev")', function() { - it('returns jQuery object container previous waypoint', function() { - var $near = $('#near1') - $target = $('#same1') - $target.add($near).waypoint({}) - expect($near.waypoint('prev')[0]).toEqual($target[0]) - }) - - it('can be used in a non-window context', function() { - var $near = $('#inner2') - $target = $('#inner1') - $target.add($near).waypoint({}) - expect($near.waypoint('prev')[0]).toEqual($target[0]) - }) - }) - - describe('#waypoint("next")', function() { - it('returns jQuery object containing next waypoint', function() { - var $near = $('#near1') - $target = $('#same1') - $target.add($near).waypoint({}) - expect($target.waypoint('next')[0]).toEqual($near[0]) - }) - }) - - describe('jQuery#waypoints()', function() { - it('starts as an empty array for each axis', function() { - expect($.waypoints().vertical.length).toEqual(0) - expect($.waypoints().horizontal.length).toEqual(0) - }) - - it('returns waypoint elements', function() { - $target = $('#same1').waypoint({}) - expect($.waypoints().vertical[0]).toEqual($target[0]) - }) - - it('does not blow up with multiple waypoints', function() { - $target = $('.sameposition, #top').waypoint({}) - $target = $target.add($('#near1')).waypoint({}) - expect($.waypoints().vertical.length).toEqual(4) - expect($.waypoints().vertical[0]).toEqual($('#top')[0]) - }) - - it('returns horizontal elements', function() { - $target = $('#same1').waypoint({ - horizontal: true - }) - expect($.waypoints().horizontal[0]).toEqual($target[0]) - }) - - describe('Directional filters', function() { - var $other - - beforeEach(function() { - $target = $('#same1') - $other = $('#near1') - }) - - describe('above', function() { - it('returns only waypoints above current scroll', function() { - runs(function() { - $target.add($other).waypoint({}) - $scroller.scrollTop(1500) - }) - waitsFor(function() { - return $.waypoints('above')[0] === $target[0] - }, 'target to be above') - }) - }) - - describe('below', function() { - it('returns only waypoints below current scroll', function() { - runs(function() { - $target.add($other).waypoint({}) - $scroller.scrollTop(1500) - }) - waitsFor(function() { - return $.waypoints('below')[0] === $other[0] - }, 'other to be below') - }) - }) - - describe('left', function() { - it('returns only waypoints left of current scroll', function() { - runs(function() { - $target.add($other).waypoint({ - horizontal: true - }) - $scroller.scrollLeft(1500) - }) - waitsFor(function() { - return $.waypoints('left')[0] === $target[0] - }, 'target to be left') - }) - }) - - describe('right', function() { - it('returns only waypoints right of current scroll', function() { - runs(function() { - $target.add($other).waypoint({ - horizontal: true - }) - $scroller.scrollLeft(1500) - }) - waitsFor(function() { - return $.waypoints('right')[0] === $other[0] - }, 'other to be right') - }) - }) - }) - }) - - describe('jQuery#waypoints("refresh")', function() { - var currentDirection - - beforeEach(function() { - currentDirection = null - $target = $('#same1').waypoint(function(direction) { - currentDirection = direction - }) - }) - - it('triggers callback if refresh crosses scroll', function() { - var top = $target.offset().top - runs(function() { - $scroller.scrollTop(top - 1) - }) - waits(standard) - runs(function() { - $target.css('top', (top - 50) + 'px') - $.waypoints('refresh') - expect(currentDirection).toEqual('down') - $target.css('top', top + 'px') - $.waypoints('refresh') - expect(currentDirection).toEqual('up') - }) - }) - - it('does not trigger callback if onlyOnScroll true', function() { - var top, $other - runs(function() { - $other = $('#same1').waypoint({ - onlyOnScroll: true, - handler: setHitTrue - }) - top = $other.offset().top - }) - waits(standard) - runs(function() { - $other.css('top', (top - 50) + 'px') - $.waypoints('refresh') - expect(hit).toBeFalsy() - $other.css('top', top + 'px') - $.waypoints('refresh') - expect(hit).toBeFalsy() - }) - }) - - it('updates the offset', function() { - runs(function() { - $scroller.scrollTop($target.offset().top - 51) - $target.css('top', ($target.offset().top - 50) + 'px') - $.waypoints('refresh') - }) - waits(standard) - runs(function() { - expect(currentDirection).toBeFalsy() - $scroller.scrollTop($target.offset().top) - }) - waitsFor(function() { - return currentDirection - }, 'callback to trigger') - }) - }) - - describe('jQuery#waypoints("viewportHeight")', function() { - it('returns window innerHeight if it exists', function() { - if (window.innerHeight) { - expect($.waypoints('viewportHeight')).toEqual(window.innerHeight) - } - else { - expect($.waypoints('viewportHeight')).toEqual($(window).height()) - } - }) - }) - - describe('jQuery#waypoints("disable")', function() { - it('disables all waypoints', function() { - var count = 0 - runs(function() { - $target = $('.sameposition').waypoint(function() { - count += 1 - }) - $.waypoints('disable') - $scroller.scrollTop($target.offset().top + 50) - }) - waits(standard) - runs(function() { - expect(count).toEqual(0) - }) - }) - }) - - describe('jQuery#waypoints("enable")', function() { - it('enables all waypoints', function() { - var count = 0 - runs(function() { - $target = $('.sameposition').waypoint(function() { - count += 1 - }) - $.waypoints('disable') - $.waypoints('enable') - $scroller.scrollTop($target.offset().top + 50) - }) - waits(standard) - runs(function() { - expect(count).toEqual(2) - }) - }) - }) - - describe('jQuery#waypoints("destroy")', function() { - it('destroys all waypoints', function() { - $target = $('.sameposition').waypoint({}) - $.waypoints('destroy') - expect($.waypoints().vertical.length).toEqual(0) - }) - }) - - describe('jQuery#waypoints("extendFn", methodName, function")', function() { - it('adds method to the waypoint namespace', function() { - var currentArg - $.waypoints('extendFn', 'myMethod', function(arg) { - currentArg = arg - }) - $('#same1').waypoint('myMethod', 'test') - expect(currentArg).toEqual('test') - }) - }) - - describe('jQuery.waypoints.settings', function() { - var count, curId - - beforeEach(function() { - count = 0 - $('.sameposition, #near1, #near2').waypoint(function() { - count += 1 - curId = this.id - }) - }) - - it('throttles the scroll check', function() { - runs(function() { - $scroller.scrollTop($('#same1').offset().top) - expect(count).toEqual(0) - }) - waitsFor(function() { - return count === 2 - }, 'callbacks to trigger') - }) - - it('throttles the resize event and calls refresh', function() { - runs(function() { - $('#same1').css('top', '-1000px') - $(window).resize() - expect(count).toEqual(0) - }) - waitsFor(function() { - return count === 1 - }, 'callback to trigger') - }) - }) - - describe('non-window scroll context', function() { - beforeEach(function() { - $scroller = $('#bottom') - }) - - it('triggers the waypoint within its context', function() { - $target = $('#inner3').waypoint({ - context: '#bottom', - handler: setHitTrue - }) - runs(function() { - $scroller.scrollTop(199) - }) - waits(standard) - runs(function() { - expect(hit).toBeFalsy() - $scroller.scrollTop(200) - }) - waitsFor(function() { - return hit - }, 'callback to trigger') - }) - - it('respects a % offset within context', function() { - $target = $('#inner3').waypoint({ - context: '#bottom', - offset: '100%', - handler: setHitTrue - }) - runs(function() { - $scroller.scrollTop(149) - }) - waits(standard) - runs(function() { - expect(hit).toBeFalsy() - $scroller.scrollTop(150) - }) - waitsFor(function() { - return hit - }, 'callback to trigger') - }) - - it('respects function offsets within context', function() { - $target = $('#inner3').waypoint({ - context: '#bottom', - offset: function() { - return $(this).height() / 2 - }, - handler: setHitTrue - }) - runs(function() { - $scroller.scrollTop(149) - }) - waits(standard) - runs(function() { - expect(hit).toBeFalsy() - $scroller.scrollTop(150) - }) - waitsFor(function() { - return hit - }, 'callback to trigger') - }) - - it('respects bottom-in-view alias', function() { - $target = $('#inner3').waypoint({ - context: '#bottom', - offset: 'bottom-in-view', - handler: setHitTrue - }) - runs(function() { - $scroller.scrollTop(249) - }) - waits(standard) - runs(function() { - expect(hit).toBeFalsy() - $scroller.scrollTop(250) - }) - waitsFor(function() { - return hit - }, 'callback to trigger') - }) - }) - - describe('Waypoints added after load, Issue #28, 62, 63', function() { - it('triggers down on new but already reached waypoints', function() { - runs(function() { - $target = $('#same2') - $scroller.scrollTop($target.offset().top + 1) - }) - waits(standard) - runs(function() { - $target.waypoint(function(direction) { - hit = direction === 'down' - }) - }) - waitsFor(function() { - return hit - }, 'callback to trigger') - }) - }) - - describe('Multiple waypoints on the same element', function() { - var hit2 - - beforeEach(function() { - hit2 = false - $target = $('#same1').waypoint(setHitTrue) - $target.waypoint({ - offset: -50, - handler: function() { - hit2 = true - } - }) - }) - - it('triggers all handlers', function() { - runs(function() { - $scroller.scrollTop($target.offset().top + 50) - }) - waitsFor(function() { - return hit && hit2 - }, 'both callbacks to trigger') - }) - - it('uses only one element in $.waypoints array', function() { - expect($.waypoints().vertical.length).toEqual(1) - }) - - it('disables all waypoints on the element with #disable', function() { - runs(function() { - $target.waypoint('disable') - $scroller.scrollTop($target.offset().top + 50) - }) - waits(standard) - runs(function() { - expect(hit || hit2).toBeFalsy() - }) - }) - }) - - describe('Horizontal waypoints', function() { - var currentDirection - - beforeEach(function() { - currentDirection = null - $target = $('#same1').waypoint({ - horizontal: true, - handler: function(direction) { - currentDirection = direction - } - }) - }) - - it('triggers right/left direction', function() { - runs(function() { - $scroller.scrollLeft($target.offset().left) - }) - waitsFor(function() { - return currentDirection === 'right' - }, 'right direction to trigger') - runs(function() { - $scroller.scrollLeft($target.offset().left - 1) - }) - waitsFor(function() { - return currentDirection === 'left' - }, 'left direction to trigger') - }) - }) - - describe('Waypoints attached to window object, PR #86', function() { - $window = $(window) - - beforeEach(function() { - $target = $window.waypoint({ - offset: -$window.height(), - handler: setHitTrue - }) - }) - - it('triggers waypoint', function() { - runs(function() { - $window.scrollTop($window.height() + 1) - }) - waitsFor(function() { - return hit - }, 'callback to trigger') - }) - }) - - describe('Options object reuse, issue #253', function() { - beforeEach(function() { - var options = { - offset: 0 - } - $('#same1').waypoint($.noop, options) - $target = $('#same2').waypoint(setHitTrue, options) - }) - - it('does not override with previous waypoint handler', function() { - runs(function() { - $scroller.scrollTop($target.offset().top) - }) - waitsFor(function() { - return hit - }, 'callback to trigger') - }) - }) -}) diff --git a/test/waypoints.coffee b/test/waypoints.coffee deleted file mode 100644 index 736a3f56..00000000 --- a/test/waypoints.coffee +++ /dev/null @@ -1,740 +0,0 @@ -$.waypoints.settings.scrollThrottle = 10 -$.waypoints.settings.resizeThrottle = 20 -standardWait = 50 - -# Go tests, go - -describe 'jQuery Waypoints', -> - hit = $se = $e = $return = null - - beforeEach -> - loadFixtures 'standard.html' - $se = $ window - hit = false - - describe '#waypoint()', -> - it 'errors out', -> - fn = -> $('#same1').waypoint() - expect(fn).toThrow $.Error - - describe '#waypoint(callback)', -> - currentDirection = null - - beforeEach -> - currentDirection = null - $e = $('#same1').waypoint (direction) -> - currentDirection = direction - hit = true - - it 'creates a waypoint', -> - expect($.waypoints().vertical.length).toEqual 1 - - it 'triggers the callback', -> - runs -> - $se.scrollTop $e.offset().top - waits standardWait - - runs -> - expect(hit).toBeTruthy() - - it 'uses the default offset', -> - runs -> - $se.scrollTop($e.offset().top - 1) - waits standardWait - - runs -> - expect(hit).toBeFalsy() - $se.scrollTop $e.offset().top - waits standardWait - - runs -> - expect(hit).toBeTruthy() - - it 'passes correct directions', -> - runs -> - $se.scrollTop $e.offset().top - waits standardWait - - runs -> - expect(currentDirection).toEqual 'down' - $se.scrollTop($e.offset().top - 1) - waits standardWait - - runs -> - expect(currentDirection).toEqual 'up' - - - - describe '#waypoint(options)', -> - beforeEach -> - $e = $ '#same1' - - it 'creates a waypoint', -> - $e.waypoint - offset: 1 - triggerOnce: true - expect($.waypoints().vertical.length).toEqual 1 - - it 'respects a px offset', -> - runs -> - $e.waypoint - offset: 50 - handler: -> hit = true - $se.scrollTop($e.offset().top - 51) - waits standardWait - - runs -> - expect(hit).toBeFalsy() - $se.scrollTop($e.offset().top - 50) - waits standardWait - - runs -> - expect(hit).toBeTruthy() - - it 'respects a % offset', -> - pos = null - - runs -> - $e.waypoint - offset: '37%' - handler: -> hit = true - pos = $e.offset().top - $.waypoints('viewportHeight') * .37 - 1 - $se.scrollTop pos - waits standardWait - - runs -> - expect(hit).toBeFalsy() - $se.scrollTop pos + 1 - waits standardWait - - runs -> - expect(hit).toBeTruthy() - - it 'respects a function offset', -> - runs -> - $e.waypoint - offset: -> - $(this).height() * -1 - handler: -> hit = true - $se.scrollTop($e.offset().top + $e.height() - 1) - waits standardWait - - runs -> - expect(hit).toBeFalsy() - $se.scrollTop($e.offset().top + $e.height()) - waits standardWait - - runs -> - expect(hit).toBeTruthy() - - it 'respects the bottom-in-view function alias', -> - inview = $e.offset().top \ - - $.waypoints('viewportHeight') \ - + $e.outerHeight() - - runs -> - $e.waypoint - offset: 'bottom-in-view' - handler: -> hit = true - $se.scrollTop(inview - 1) - waits standardWait - - runs -> - expect(hit).toBeFalsy() - $se.scrollTop inview - waits standardWait - - runs -> - expect(hit).toBeTruthy() - - it 'destroys the waypoint if triggerOnce is true', -> - runs -> - $e.waypoint - triggerOnce: true - $se.scrollTop $e.offset().top - waits standardWait - - runs -> - expect($.waypoints().length).toBeFalsy() - - it 'triggers if continuous is true and waypoint is not last', -> - $f = $ '#near1' - $g = $ '#near2' - hitcount = 0 - - runs -> - $e.add($f).add($g).waypoint -> - hitcount++ - $se.scrollTop $g.offset().top - waits standardWait - - runs -> - expect(hitcount).toEqual 3 - - it 'does not trigger if continuous false, waypoint not last', -> - $f = $ '#near1' - $g = $ '#near2' - hitcount = 0 - - runs -> - callback = -> - hitcount++ - options = - continuous: false - $e.add($g).waypoint callback - $f.waypoint callback, options - $se.scrollTop $g.offset().top - waits standardWait - - runs -> - expect(hitcount).toEqual 2 - - it 'triggers if continuous is false, waypoint is last', -> - $f = $ '#near1' - $g = $ '#near2' - hitcount = 0 - - runs -> - callback = -> - hitcount++ - options = - continuous: false - $e.add($f).waypoint callback - $g.waypoint callback, options - $se.scrollTop $g.offset().top - waits standardWait - - runs -> - expect(hitcount).toEqual 3 - - it 'uses the handler option if provided', -> - hitcount = 0 - - runs -> - $e.waypoint - handler: (dir) -> - hitcount++ - $se.scrollTop $e.offset().top - waits standardWait - - runs -> - expect(hitcount).toEqual 1 - - describe '#waypoint(callback, options)', -> - beforeEach -> - callback = -> - hit = true - options = - offset: -1 - $e = $('#same1').waypoint callback, options - - it 'creates a waypoint', -> - expect($.waypoints().vertical.length).toEqual 1 - - it 'respects options', -> - runs -> - $se.scrollTop $e.offset().top - waits standardWait - - runs -> - expect(hit).toBeFalsy() - $se.scrollTop($e.offset().top + 1) - waits standardWait - - runs -> - expect(hit).toBeTruthy() - - it 'fires the callback', -> - runs -> - $se.scrollTop($e.offset().top + 1) - waits standardWait - - runs -> - expect(hit).toBeTruthy() - - describe '#waypoint("disable")', -> - beforeEach -> - $e = $('#same1').waypoint -> - hit = true - $return = $e.waypoint 'disable' - - it 'disables callback triggers', -> - runs -> - $se.scrollTop $e.offset().top - waits standardWait - - runs -> - expect(hit).toBeFalsy() - - it 'returns the same jQuery object for chaining', -> - expect($return.get()).toEqual $e.get() - - describe '.waypoint("enable")', -> - beforeEach -> - $e = $('#same1').waypoint -> - hit = true - $e.waypoint 'disable' - $return = $e.waypoint 'enable' - - it 'enables callback triggers', -> - runs -> - $se.scrollTop $e.offset().top - waits standardWait - - runs -> - expect(hit).toBeTruthy() - - it 'returns the same jQuery object for chaining', -> - expect($return.get()).toEqual $e.get() - - - describe '#waypoint("destroy")', -> - beforeEach -> - $e = $('#same1').waypoint -> - hit = true - $return = $e.waypoint 'destroy' - - it 'removes waypoint from list of waypoints', -> - expect($.waypoints().length).toBeFalsy() - - it 'no longer triggers callback', -> - runs -> - $se.scrollTop $e.offset().top - waits standardWait - - runs -> - expect(hit).toBeFalsy() - - it 'does not preserve callbacks if .waypoint recalled', -> - runs -> - $e.waypoint({}) - $se.scrollTop $e.offset().top - waits standardWait - - runs -> - expect(hit).toBeFalsy() - - it 'returns the same jQuery object for chaining', -> - expect($return.get()).toEqual $e.get() - - it 'unregisters waypoint even if underlying nodes are removed', -> - $e = $('#same2').waypoint -> - hit = true - $e.remove() - $e.waypoint 'destroy' - expect($.waypoints().vertical.length).toEqual(0); - - describe '#waypoint("prev")', -> - it 'returns jQuery object containing previous waypoint', -> - $e = $ '#same1' - $f = $ '#near1' - $e.add($f).waypoint({}) - expect($f.waypoint('prev')[0]).toEqual $e[0] - - it 'can be used in a non-window context', -> - $e = $ '#inner1' - $f = $ '#inner2' - $e.add($f).waypoint - context: '#bottom' - expect($f.waypoint('prev', 'vertical', '#bottom')[0]).toEqual $e[0] - - describe '#waypoint("next")', -> - it 'returns jQuery object containing next waypoint', -> - $e = $ '#same1' - $f = $ '#near1' - $e.add($f).waypoint({}) - expect($e.waypoint('next')[0]).toEqual $f[0] - - describe 'jQuery#waypoints()', -> - it 'starts as an empty array for each axis', -> - expect($.waypoints().vertical.length).toBeFalsy() - expect($.waypoints().horizontal.length).toBeFalsy() - expect($.isPlainObject $.waypoints()).toBeTruthy() - expect($.isArray $.waypoints().horizontal).toBeTruthy() - expect($.isArray $.waypoints().vertical).toBeTruthy() - - it 'returns waypoint elements', -> - $e = $('#same1').waypoint({}) - expect($.waypoints().vertical[0]).toEqual $e[0] - - it 'does not blow up with multiple waypoint', -> - $e = $('.sameposition, #top').waypoint({}) - $e = $e.add $('#near1').waypoint({}) - expect($.waypoints().vertical.length).toEqual 4 - expect($.waypoints().vertical[0]).toEqual $('#top')[0] - - it 'returns horizontal elements', -> - $e = $('#same1').waypoint - horizontal: true - expect($.waypoints().horizontal[0]).toEqual $e[0] - - describe 'Directional filters', -> - $f = null - - beforeEach -> - $e = $ '#same1' - $f = $ '#near1' - - describe 'above', -> - it 'returns waypoints only above the current scroll position', -> - runs -> - $e.add($f).waypoint({}) - $se.scrollTop 1500 - waits standardWait - - runs -> - expect($.waypoints('above')).toEqual [$e[0]] - - describe 'below', -> - it 'returns waypoints only below the current scroll position', -> - runs -> - $e.add($f).waypoint({}) - $se.scrollTop 1500 - waits standardWait - - runs -> - expect($.waypoints('below')).toEqual [$f[0]] - - describe 'left', -> - it 'returns waypoints only left of the current scroll position', -> - runs -> - $e.add($f).waypoint - horizontal: true - $se.scrollLeft 1500 - waits standardWait - - runs -> - expect($.waypoints('left')).toEqual [$e[0]] - - describe 'right', -> - it 'returns waypoints only right of the current scroll position', -> - runs -> - $e.add($f).waypoint - horizontal: true - $se.scrollLeft 1500 - waits standardWait - - runs -> - expect($.waypoints('right')).toEqual [$f[0]] - - - describe 'jQuery#waypoints("refresh")', -> - currentDirection = null - - beforeEach -> - currentDirection = null - $e = $('#same1').waypoint (direction) -> - currentDirection = direction - - it 'triggers callback if refresh crosses scroll', -> - runs -> - $se.scrollTop($e.offset().top - 1) - waits standardWait - - runs -> - $e.css('top', ($e.offset().top - 50) + 'px') - $.waypoints 'refresh' - expect(currentDirection).toEqual 'down' - expect(currentDirection).not.toEqual 'up' - $e.css('top', $e.offset().top + 50 + 'px') - $.waypoints 'refresh' - expect(currentDirection).not.toEqual 'down' - expect(currentDirection).toEqual 'up' - - - it 'does not trigger callback if onlyOnScroll true', -> - $f = null - - runs -> - $f = $('#same2').waypoint - onlyOnScroll: true - handler: -> hit = true - $se.scrollTop($f.offset().top - 1) - waits standardWait - - runs -> - $f.css('top', ($f.offset().top - 50) + 'px') - $.waypoints 'refresh' - expect(hit).toBeFalsy() - $f.css('top', $f.offset().top + 50 + 'px') - $.waypoints 'refresh' - expect(hit).toBeFalsy() - - it 'updates the offset', -> - runs -> - $se.scrollTop($e.offset().top - 51) - $e.css('top', ($e.offset().top - 50) + 'px') - $.waypoints 'refresh' - waits standardWait - - runs -> - expect(currentDirection).toBeFalsy() - $se.scrollTop $e.offset().top - waits standardWait - - runs -> - expect(currentDirection).toBeTruthy() - - describe 'jQuery#waypoints("viewportHeight")', -> - it 'returns window innerheight if it exists', -> - if window.innerHeight - expect($.waypoints 'viewportHeight').toEqual window.innerHeight - else - expect($.waypoints 'viewportHeight').toEqual $(window).height() - - describe 'jQuery#waypoints("disable")', -> - it 'disables all waypoints', -> - count = 0 - - runs -> - $e = $('.sameposition').waypoint -> count++ - $.waypoints 'disable' - $se.scrollTop($e.offset().top + 50) - waits standardWait - - runs -> - expect(count).toEqual 0 - - describe 'jQuery#waypoints("enable")', -> - it 'enables all waypoints', -> - count = 0 - - runs -> - $e = $('.sameposition').waypoint -> count++ - $.waypoints 'disable' - $.waypoints 'enable' - $se.scrollTop($e.offset().top + 50) - waits standardWait - - runs -> - expect(count).toEqual 2 - - describe 'jQuery#waypoints("destroy")', -> - it 'destroys all waypoints', -> - $e = $('.sameposition').waypoint({}) - $.waypoints 'destroy' - expect($.waypoints().vertical.length).toEqual 0 - - describe 'jQuery#waypoints("extendFn", methodName, function)', -> - it 'adds method to the waypoint namespace', -> - currentArg = null - $.waypoints 'extendFn', 'myMethod', (arg) -> - currentArg = arg - $('#same1').waypoint 'myMethod', 'test' - expect(currentArg).toEqual 'test' - - describe 'jQuery#waypoints.settings', -> - count = curID = null - - beforeEach -> - count = 0 - $('.sameposition, #near1, #near2').waypoint -> - count++ - curID = $(this).attr 'id' - - it 'throttles the scroll check', -> - runs -> - $se.scrollTop $('#same1').offset().top - expect(count).toEqual 0 - waits standardWait - - runs -> - expect(count).toEqual 2 - - it 'throttles the resize event and calls refresh', -> - runs -> - $('#same1').css 'top', "-1000px" - $(window).resize() - expect(count).toEqual 0 - waits standardWait - - runs -> - expect(count).toEqual 1 - - describe 'non-window scroll context', -> - $inner = null - - beforeEach -> - $inner = $ '#bottom' - - it 'triggers the waypoint within its context', -> - $e = $('#inner3').waypoint - context: '#bottom' - handler: -> hit = true - - runs -> - $inner.scrollTop 199 - waits standardWait - - runs -> - expect(hit).toBeFalsy() - $inner.scrollTop 200 - waits standardWait - - runs -> - expect(hit).toBeTruthy() - - it 'respects % offsets within contexts', -> - $e = $('#inner3').waypoint - context: '#bottom' - offset: '100%' - handler: -> hit = true - - runs -> - $inner.scrollTop 149 - waits standardWait - - runs -> - expect(hit).toBeFalsy() - $inner.scrollTop 150 - waits standardWait - - runs -> - expect(hit).toBeTruthy() - - it 'respects function offsets within context', -> - $e = $('#inner3').waypoint - context: '#bottom' - offset: -> - $(this).height() / 2 - handler: -> hit = true - - runs -> - $inner.scrollTop 149 - waits standardWait - - runs -> - expect(hit).toBeFalsy() - $inner.scrollTop 150 - waits standardWait - - runs -> - expect(hit).toBeTruthy() - - it 'respects bottom-in-view alias', -> - $e = $('#inner3').waypoint - context: '#bottom' - offset: 'bottom-in-view' - handler: -> hit = true - - runs -> - $inner.scrollTop 249 - waits standardWait - - runs -> - expect(hit).toBeFalsy() - $inner.scrollTop 250 - waits standardWait - - runs -> - expect(hit).toBeTruthy() - - afterEach -> - $inner.scrollTop 0 - - describe 'Waypoints added after load, Issue #28, 62, 63', -> - it 'triggers down on new but already reached waypoints', -> - runs -> - $e = $ '#same2' - $se.scrollTop($e.offset().top + 1) - waits standardWait - - runs -> - $e.waypoint (direction) -> - hit = direction is 'down' - - waitsFor (-> hit), '#same2 to trigger', 1000 - - describe 'Multiple waypoints on the same element', -> - hit2 = false - - beforeEach -> - hit2 = false - $e = $('#same1').waypoint - handler: -> - hit = true - $e.waypoint - handler: -> - hit2 = true - offset: -50 - - it 'triggers all handlers', -> - runs -> - $se.scrollTop($e.offset().top + 50) - waits standardWait - - runs -> - expect(hit and hit2).toBeTruthy() - - it 'uses only one element in $.waypoints() array', -> - expect($.waypoints().vertical.length).toEqual 1 - - it 'disables all waypoints on the element when #disabled called', -> - runs -> - $e.waypoint 'disable' - $se.scrollTop($e.offset().top + 50) - waits standardWait - - runs -> - expect(hit or hit2).toBeFalsy() - - describe 'Horizontal waypoints', -> - currentDirection = null - - beforeEach -> - currentDirection = null - $e = $('#same1').waypoint - horizontal: true - handler: (direction) -> - currentDirection = direction - - it 'triggers right/left direction', -> - runs -> - $se.scrollLeft $e.offset().left - waits standardWait - - runs -> - expect(currentDirection).toEqual 'right' - $se.scrollLeft($e.offset().left - 1) - waits standardWait - - runs -> - expect(currentDirection).toEqual 'left' - - describe 'Waypoints attached to window object, pull request 86', -> - $win = $ window; - - beforeEach -> - $e = $win.waypoint - offset: - -$win.height() - handler: -> hit = true - - it 'triggers waypoint reached', -> - runs -> - $win.scrollTop($win.height() + 1) - waits standardWait - - runs -> - expect(hit).toBeTruthy() - - describe 'Options object reuse, issue #253', -> - beforeEach -> - options = - offset: 0 - fn = -> hit = true - $('#same1').waypoint $.noop, options - $e = $('#same2').waypoint fn, options - - it 'does not override previous waypoint options', -> - runs -> - $se.scrollTop $e.offset().top - waits standardWait - runs -> - expect(hit).toBeTruthy() - - afterEach -> - $.waypoints 'destroy' - $se.scrollTop(0).scrollLeft 0 - hit = false - waits standardWait From 564fe70d756b0818f5eb120c2ecfbdc2ade9396f Mon Sep 17 00:00:00 2001 From: imakewebthings Date: Fri, 20 Jun 2014 14:08:47 -0700 Subject: [PATCH 21/98] Set up lint rules, follow them --- .eslintrc | 25 ++++++++++++++++ gulpfile.js | 14 ++++----- package.json | 4 ++- src/adapters/jquery-zepto-fn-extension.js | 6 +++- src/adapters/jquery.js | 8 +++-- src/adapters/noframework.js | 36 ++++++++++++----------- src/adapters/zepto.js | 13 ++++---- src/context.js | 18 +++++++----- src/group.js | 25 +++++++++------- src/shortcuts/infinite.js | 15 ++++++---- src/shortcuts/inview.js | 14 +++++---- src/shortcuts/sticky.js | 11 +++++-- src/waypoint.js | 6 ++-- test/adapter-fn-spec.js | 14 ++++++--- test/context-spec.js | 14 +++++---- test/group-spec.js | 30 +++++++------------ test/infinite-spec.js | 8 ++++- test/inview-spec.js | 26 +++++----------- test/settings.js | 2 ++ test/sticky-spec.js | 8 ++++- test/waypoint-spec.js | 18 ++++++++---- 21 files changed, 193 insertions(+), 122 deletions(-) create mode 100644 .eslintrc diff --git a/.eslintrc b/.eslintrc new file mode 100644 index 00000000..8e7865fb --- /dev/null +++ b/.eslintrc @@ -0,0 +1,25 @@ +{ + "env": { + "browser": true, + "node": true + }, + + "rules": { + "brace-style": [1, "stroustrup"], + "consistent-this": [1, "self"], + "eqeqeq": [1, "smart"], + "func-style": [1, "declaration"], + "no-else-return": 1, + "no-extra-parens": 1, + "no-floating-decimal": 1, + "no-nested-ternary": 1, + "no-lonely-if": 1, + "quotes": [1, "single", "avoid-escape"], + "radix": 1, + "semi": [1, "never"], + "space-after-keywords": [1, "always"], + "space-in-brackets": [1, "never"], + "space-unary-word-ops": 1, + "wrap-iife": 1 + } +} diff --git a/gulpfile.js b/gulpfile.js index 610b2eaa..4bac03b3 100644 --- a/gulpfile.js +++ b/gulpfile.js @@ -1,12 +1,12 @@ var gulp = require('gulp') -var mochaPhantomJS = require('gulp-mocha-phantomjs') +var eslint = require('gulp-eslint') -gulp.task('test', function() { - return gulp.src('test/index.html').pipe(mochaPhantomJS({ - reporter: 'tap' - })) +var jsFiles = ['src/**/*.js', 'test/**/*.js', '!test/lib/**/*.js'] + +gulp.task('lint', function() { + gulp.src(jsFiles).pipe(eslint('.eslintrc')).pipe(eslint.format()) }) -gulp.task('watch-test', function() { - gulp.watch(['lib/**', 'test/**'], ['test']) +gulp.task('watch', function() { + gulp.watch(jsFiles, ['lint']) }) diff --git a/package.json b/package.json index ead9dd04..4082200d 100644 --- a/package.json +++ b/package.json @@ -16,7 +16,9 @@ "scroll" ], "devDependencies": { - "gulp": "^3.6.2" + "eslint": "^0.6.2", + "gulp": "^3.6.2", + "gulp-eslint": "^0.1.7" }, "license": "MIT" } diff --git a/src/adapters/jquery-zepto-fn-extension.js b/src/adapters/jquery-zepto-fn-extension.js index 3aa86527..88575699 100644 --- a/src/adapters/jquery-zepto-fn-extension.js +++ b/src/adapters/jquery-zepto-fn-extension.js @@ -1,4 +1,8 @@ (function() { + 'use strict' + + var Waypoint = window.Waypoint + function createExtension(framework) { return function() { var waypoints = [] @@ -29,4 +33,4 @@ if (window.Zepto) { window.Zepto.fn.waypoint = createExtension(window.Zepto) } -})() +}()) diff --git a/src/adapters/jquery.js b/src/adapters/jquery.js index 6b1aeba8..712d38d0 100644 --- a/src/adapters/jquery.js +++ b/src/adapters/jquery.js @@ -1,7 +1,9 @@ (function() { - var $ = jQuery + 'use strict' - var JQueryAdapter = function(element) { + var $ = window.jQuery + + function JQueryAdapter(element) { this.$element = $(element) } @@ -35,4 +37,4 @@ Adapter: JQueryAdapter }) window.Waypoint.Adapter = JQueryAdapter -})() +}()) diff --git a/src/adapters/noframework.js b/src/adapters/noframework.js index ebf49a95..23d39963 100644 --- a/src/adapters/noframework.js +++ b/src/adapters/noframework.js @@ -1,6 +1,8 @@ (function() { + 'use strict' + function isWindow(element) { - return element == element.window + return element === element.window } function getWindow(element) { @@ -10,10 +12,9 @@ return element.defaultView } - var eventHandlers = {} - - var NoFrameworkAdapter = function(element) { + function NoFrameworkAdapter(element) { this.element = element + this.handlers = {} } NoFrameworkAdapter.prototype.height = function() { @@ -36,28 +37,28 @@ var namespace = eventParts[1] var element = this.element - if (namespace && eventHandlers[namespace] && eventType) { - removeListeners(element, eventHandlers[namespace][eventType], handler) - eventHandlers[namespace][eventType] = [] + if (namespace && this.handlers[namespace] && eventType) { + removeListeners(element, this.handlers[namespace][eventType], handler) + this.handlers[namespace][eventType] = [] } else if (eventType) { - for (var ns in eventHandlers) { - removeListeners(element, eventHandlers[ns][eventType] || [], handler) - eventHandlers[ns][eventType] = [] + for (var ns in this.handlers) { + removeListeners(element, this.handlers[ns][eventType] || [], handler) + this.handlers[ns][eventType] = [] } } - else if (namespace && eventHandlers[namespace]) { - for (var type in eventHandlers[namespace]) { - removeListeners(element, eventHandlers[namespace][type], handler) + else if (namespace && this.handlers[namespace]) { + for (var type in this.handlers[namespace]) { + removeListeners(element, this.handlers[namespace][type], handler) } - eventHandlers[namespace] = {} + this.handlers[namespace] = {} } } /* Adapted from jQuery 1.x offset() */ NoFrameworkAdapter.prototype.offset = function() { if (!this.element.ownerDocument) { - return + return null } var documentElement = this.element.ownerDocument.documentElement @@ -81,7 +82,7 @@ var eventParts = event.split('.') var eventType = eventParts[0] var namespace = eventParts[1] || '__default' - var nsHandlers = eventHandlers[namespace] = eventHandlers[namespace] || {} + var nsHandlers = this.handlers[namespace] = this.handlers[namespace] || {} var nsTypeList = nsHandlers[eventType] = nsHandlers[eventType] || [] nsTypeList.push(handler) @@ -155,6 +156,7 @@ } NoFrameworkAdapter.isEmptyObject = function(obj) { + /* eslint no-unused-vars: 0 */ for (var name in obj) { return false } @@ -166,4 +168,4 @@ Adapter: NoFrameworkAdapter }) window.Waypoint.Adapter = NoFrameworkAdapter -})() +}()) diff --git a/src/adapters/zepto.js b/src/adapters/zepto.js index 3bee00fc..8546fd29 100644 --- a/src/adapters/zepto.js +++ b/src/adapters/zepto.js @@ -1,7 +1,9 @@ (function() { - var $ = Zepto + 'use strict' - var ZeptoAdapter = function(element) { + var $ = window.Zepto + + function ZeptoAdapter(element) { this.element = element this.$element = $(element) } @@ -21,7 +23,7 @@ }) ZeptoAdapter.prototype.offset = function() { - if (this.element != this.element.window) { + if (this.element !== this.element.window) { return this.$element.offset() } } @@ -49,12 +51,13 @@ $.each([ 'extend', - 'inArray', + 'inArray' ], function(i, method) { ZeptoAdapter[method] = $[method] }) ZeptoAdapter.isEmptyObject = function(obj) { + /* eslint no-unused-vars: 0 */ for (var name in obj) { return false } @@ -66,4 +69,4 @@ Adapter: ZeptoAdapter }) window.Waypoint.Adapter = ZeptoAdapter -})() +}()) diff --git a/src/context.js b/src/context.js index 1030017b..1a049c7f 100644 --- a/src/context.js +++ b/src/context.js @@ -1,19 +1,22 @@ (function() { + 'use strict' + function requestAnimationFrameShim(callback) { window.setTimeout(callback, 1000 / 60) } var keyCounter = 0 var contexts = {} + var Waypoint = window.Waypoint var requestAnimationFrame = window.requestAnimationFrame || window.mozRequestAnimationFrame || window.webkitRequestAnimationFrame || requestAnimationFrameShim - var Context = function(element) { + function Context(element) { this.element = element - this.Adapter = window.Waypoint.Adapter + this.Adapter = Waypoint.Adapter this.adapter = new this.Adapter(element) this.key = 'waypoint-context-' + keyCounter this.didScroll = false @@ -38,7 +41,7 @@ /* Internal */ Context.prototype.createThrottledScrollHandler = function() { var self = this - var scrollHandler = function() { + function scrollHandler() { self.handleScroll() self.didScroll = false } @@ -54,7 +57,8 @@ /* Internal */ Context.prototype.createThrottledResizeHandler = function() { var self = this - var resizeHandler = function() { + + function resizeHandler() { self.handleResize() self.didResize = false } @@ -68,7 +72,7 @@ } /* Internal */ - Context.prototype.handleScroll = function(options) { + Context.prototype.handleScroll = function() { var triggeredGroups = {} var axes = { horizontal: { @@ -259,5 +263,5 @@ return Context.findByElement(element) || new Context(element) } - window.Waypoint.Context = Context -})() + Waypoint.Context = Context +}()) diff --git a/src/group.js b/src/group.js index d35f8f96..5daaa102 100644 --- a/src/group.js +++ b/src/group.js @@ -1,4 +1,12 @@ (function() { + 'use strict' + + var groups = { + vertical: {}, + horizontal: {} + } + var Waypoint = window.Waypoint + function byTriggerPoint(a, b) { return a.triggerPoint - b.triggerPoint } @@ -7,12 +15,7 @@ return b.triggerPoint - a.triggerPoint } - var groups = { - vertical: {}, - horizontal: {} - } - - var Group = function(options) { + function Group(options) { this.name = options.name this.axis = options.axis this.id = this.name + '-' + this.axis @@ -23,13 +26,13 @@ Group.prototype.previous = function(waypoint) { this.sort() - var index = window.Waypoint.Adapter.inArray(waypoint, this.waypoints) + var index = Waypoint.Adapter.inArray(waypoint, this.waypoints) return index ? this.waypoints[index - 1] : null } Group.prototype.next = function(waypoint) { this.sort() - var index = window.Waypoint.Adapter.inArray(waypoint, this.waypoints) + var index = Waypoint.Adapter.inArray(waypoint, this.waypoints) var isLast = index === this.waypoints.length - 1 return isLast ? null : this.waypoints[index + 1] } @@ -49,7 +52,7 @@ /* Internal */ Group.prototype.remove = function(waypoint) { - var index = window.Waypoint.Adapter.inArray(waypoint, this.waypoints) + var index = Waypoint.Adapter.inArray(waypoint, this.waypoints) if (index > -1) { this.waypoints.splice(index, 1) } @@ -98,5 +101,5 @@ return groups[options.axis][options.name] || new Group(options) } - window.Waypoint.Group = Group -})() + Waypoint.Group = Group +}()) diff --git a/src/shortcuts/infinite.js b/src/shortcuts/infinite.js index eeb2332f..1fb517d9 100644 --- a/src/shortcuts/infinite.js +++ b/src/shortcuts/infinite.js @@ -1,5 +1,10 @@ (function() { - var Infinite = function(options) { + 'use strict' + + var $ = window.jQuery + var Waypoint = window.Waypoint + + function Infinite(options) { this.options = $.extend({}, Infinite.defaults, options) this.container = this.options.element if (this.options.container !== 'auto') { @@ -11,7 +16,7 @@ if (this.more) { this.setupHandler() - this.waypoint = new window.Waypoint(this.options) + this.waypoint = new Waypoint(this.options) } } @@ -23,7 +28,7 @@ /* Internal */ Infinite.prototype.setupHandler = function() { - this.options.handler = $.proxy(function(direction) { + this.options.handler = $.proxy(function() { window.setTimeout($.proxy(function() { this.options.onBeforePageLoad() this.destroy() @@ -63,5 +68,5 @@ onAfterPageLoad: $.noop } - window.Waypoint.Infinite = Infinite -})() + Waypoint.Infinite = Infinite +}()) diff --git a/src/shortcuts/inview.js b/src/shortcuts/inview.js index fa8de89d..3bfcac07 100644 --- a/src/shortcuts/inview.js +++ b/src/shortcuts/inview.js @@ -1,8 +1,12 @@ (function() { + 'use strict' + + var Waypoint = window.Waypoint + function noop() {} - var Inview = function(options) { - this.options = window.Waypoint.Adapter.extend({}, Inview.defaults, options) + function Inview(options) { + this.options = Waypoint.Adapter.extend({}, Inview.defaults, options) this.axis = this.options.horizontal ? 'horizontal' : 'vertical' this.waypoints = [] this.createWaypoints() @@ -73,7 +77,7 @@ return function(direction) { self.options[config[direction]].call(this, direction) } - })(config), + }(config)), offset: config.offset, horizontal: this.options.horizontal })) @@ -86,5 +90,5 @@ exited: noop } - window.Waypoint.Inview = Inview -})() + Waypoint.Inview = Inview +}()) diff --git a/src/shortcuts/sticky.js b/src/shortcuts/sticky.js index 763a1b18..665ffd1f 100644 --- a/src/shortcuts/sticky.js +++ b/src/shortcuts/sticky.js @@ -1,5 +1,10 @@ (function() { - var Sticky = function(options) { + 'use strict' + + var $ = window.jQuery + var Waypoint = window.Waypoint + + function Sticky(options) { this.options = $.extend({}, Waypoint.defaults, Sticky.defaults, options) this.element = this.options.element this.$element = $(this.element) @@ -45,5 +50,5 @@ direction: 'down right' } - window.Waypoint.Sticky = Sticky -})() + Waypoint.Sticky = Sticky +}()) diff --git a/src/waypoint.js b/src/waypoint.js index d4b50138..320bad5c 100644 --- a/src/waypoint.js +++ b/src/waypoint.js @@ -1,8 +1,10 @@ (function() { + 'use strict' + var keyCounter = 0 var allWaypoints = {} - var Waypoint = function(options) { + function Waypoint(options) { if (!options) { throw new Error('No options passed to Waypoint constructor') } @@ -108,4 +110,4 @@ } window.Waypoint = Waypoint -})() +}()) diff --git a/test/adapter-fn-spec.js b/test/adapter-fn-spec.js index b816b536..4a5feef5 100644 --- a/test/adapter-fn-spec.js +++ b/test/adapter-fn-spec.js @@ -1,11 +1,17 @@ -jQuery.each(jQuery.grep(Waypoint.adapters, function(adapter) { - return "jquery zepto".indexOf(adapter.name) > -1 +'use strict' +/* global + * describe, it, beforeEach, afterEach, expect, spyOn, waits, runs, + * waitsFor, loadFixtures, Waypoint + */ + +window.jQuery.each(window.jQuery.grep(Waypoint.adapters, function(adapter) { + return 'jquery zepto'.indexOf(adapter.name) > -1 }), function(i, adapter) { describe('$.fn extension for ' + adapter.name + ':', function() { var $, waypoints beforeEach(function() { - $ = adapter.name === 'jquery' ? jQuery : Zepto + $ = adapter.name === 'jquery' ? window.jQuery : window.Zepto Waypoint.Adapter = adapter.Adapter loadFixtures('standard.html') }) @@ -31,7 +37,7 @@ jQuery.each(jQuery.grep(Waypoint.adapters, function(adapter) { }) it('can take the handler as the first parameter', function() { - var handler = function() {} + function handler() {} waypoints = $('#near1').waypoint(handler) expect(waypoints[0].callback).toBe(handler) }) diff --git a/test/context-spec.js b/test/context-spec.js index a314dbf5..292db620 100644 --- a/test/context-spec.js +++ b/test/context-spec.js @@ -1,7 +1,13 @@ -jQuery.each(Waypoint.adapters, function(i, adapter) { +'use strict' +/* global + * describe, it, beforeEach, afterEach, expect, spyOn, waits, runs, + * waitsFor, loadFixtures, Waypoint + */ + +window.jQuery.each(Waypoint.adapters, function(i, adapter) { describe(adapter.name + ' adapter:', function() { describe('Waypoint.Context', function() { - var $ = jQuery + var $ = window.jQuery var standard = 50 var currentDirection, $scroller, waypoint, $target, context, skipDestroy @@ -9,10 +15,6 @@ jQuery.each(Waypoint.adapters, function(i, adapter) { currentDirection = direction } - function hasDirection() { - return currentDirection != null - } - beforeEach(function() { Waypoint.Adapter = adapter.Adapter loadFixtures('standard.html') diff --git a/test/group-spec.js b/test/group-spec.js index 08481e2f..c911e642 100644 --- a/test/group-spec.js +++ b/test/group-spec.js @@ -1,38 +1,30 @@ -jQuery.each(Waypoint.adapters, function(i, adapter) { +'use strict' +/* global + * describe, it, beforeEach, afterEach, expect, spyOn, waits, runs, + * waitsFor, loadFixtures, Waypoint + */ + +window.jQuery.each(Waypoint.adapters, function(i, adapter) { describe(adapter.name + ' adapter:', function() { describe('Waypoint.Group', function() { - var $ = jQuery + var $ = window.jQuery var standard = 50 - var currentDirection, firstWaypoint, secondWaypoint, customGroupWaypoint - var defaultGroup, customGroup - - function setDirection(direction) { - currentDirection = direction - } - - function hasDirection() { - return currentDirection != null - } + var firstWaypoint, secondWaypoint, customGroupWaypoint, defaultGroup beforeEach(function() { Waypoint.Adapter = adapter.Adapter loadFixtures('standard.html') - currentDirection = null firstWaypoint = new Waypoint({ - element: $('#same1')[0], - handler: setDirection + element: $('#same1')[0] }) secondWaypoint = new Waypoint({ - element: $('#near1')[0], - handler: setDirection + element: $('#near1')[0] }) customGroupWaypoint = new Waypoint({ element: $('#same2')[0], - handler: setDirection, group: 'custom' }) defaultGroup = firstWaypoint.group - customGroup = customGroupWaypoint.group }) afterEach(function() { diff --git a/test/infinite-spec.js b/test/infinite-spec.js index 0177b05d..f54c1c08 100644 --- a/test/infinite-spec.js +++ b/test/infinite-spec.js @@ -1,5 +1,11 @@ +'use strict' +/* global + * describe, it, beforeEach, afterEach, expect, spyOn, waits, runs, + * waitsFor, loadFixtures, Waypoint, jasmine + */ + describe('Waypoint Sticky Shortcut', function() { - var $ = jQuery + var $ = window.jQuery var standard = 50 var $scroller = $(window) var $container, $items, $more, waypoint, beforeSpy, afterSpy diff --git a/test/inview-spec.js b/test/inview-spec.js index f255b15d..55e8b999 100644 --- a/test/inview-spec.js +++ b/test/inview-spec.js @@ -1,7 +1,13 @@ -jQuery.each(Waypoint.adapters, function(i, adapter) { +'use strict' +/* global + * describe, it, beforeEach, afterEach, expect, spyOn, waits, runs, + * waitsFor, loadFixtures, Waypoint + */ + +window.jQuery.each(Waypoint.adapters, function(i, adapter) { describe(adapter.name + ' adapter:', function() { describe('Waypoints Inview Shortcut', function() { - var $ = jQuery + var $ = window.jQuery var standard = 50 var $scroller = $(window) var $target, waypoint, hits @@ -12,22 +18,6 @@ jQuery.each(Waypoint.adapters, function(i, adapter) { } } - function setsEnter() { - hits.enter = true - } - - function setsEntered() { - hits.entered = true - } - - function setsExit() { - hits.exit = true - } - - function setsExited() { - hits.exited = true - } - function toBeTrue(key) { return function() { return hits[key] diff --git a/test/settings.js b/test/settings.js index d2ea560c..3fabcd3a 100644 --- a/test/settings.js +++ b/test/settings.js @@ -1,2 +1,4 @@ +/* global jasmine */ + jasmine.getFixtures().fixturesPath = 'test/fixtures' jasmine.getEnv().defaultTimeoutInterval = 1000 diff --git a/test/sticky-spec.js b/test/sticky-spec.js index 98bb2086..5734a1fc 100644 --- a/test/sticky-spec.js +++ b/test/sticky-spec.js @@ -1,5 +1,11 @@ +'use strict' +/* global + * describe, it, beforeEach, afterEach, expect, spyOn, waits, runs, + * waitsFor, loadFixtures, Waypoint, jasmine + */ + describe('Waypoint Sticky Shortcut', function() { - var $ = jQuery + var $ = window.jQuery var standard = 50 var $scroller = $(window) var $sticky, waypoint, handlerSpy diff --git a/test/waypoint-spec.js b/test/waypoint-spec.js index 766610a2..03b7a34c 100644 --- a/test/waypoint-spec.js +++ b/test/waypoint-spec.js @@ -1,7 +1,13 @@ -jQuery.each(Waypoint.adapters, function(i, adapter) { +'use strict' +/* global + * describe, it, beforeEach, afterEach, expect, spyOn, waits, runs, + * waitsFor, loadFixtures, Waypoint + */ + +window.jQuery.each(Waypoint.adapters, function(i, adapter) { describe(adapter.name + ' adapter: ', function() { describe('Waypoint', function() { - var $ = jQuery + var $ = window.jQuery var standard = 50 var hit, $scroller, waypoint, $target, returnValue @@ -32,7 +38,7 @@ jQuery.each(Waypoint.adapters, function(i, adapter) { describe('new Waypoint()', function() { it('errors out', function() { expect(function() { - new Waypoint() + waypoint = new Waypoint() }).toThrow() }) }) @@ -47,7 +53,7 @@ jQuery.each(Waypoint.adapters, function(i, adapter) { it('requires the element option', function() { expect(function() { - new Waypoint({}) + waypoint = new Waypoint({}) }).toThrow() }) @@ -122,7 +128,7 @@ jQuery.each(Waypoint.adapters, function(i, adapter) { }) it('takes a % offset', function() { - var trigger = $target.offset().top - Waypoint.viewportHeight() * .37 + var trigger = $target.offset().top - Waypoint.viewportHeight() * 0.37 runs(function() { waypoint = new Waypoint({ element: $target[0], @@ -311,7 +317,7 @@ jQuery.each(Waypoint.adapters, function(i, adapter) { describe('continuous option', function() { var $later, laterWaypoint, hitCount, hitWaypoint - function incrementHitCount(direction) { + function incrementHitCount() { hitCount += 1 hitWaypoint = this } From a039eb2f548fd63b0ece2a9033ed54012bbf7f11 Mon Sep 17 00:00:00 2001 From: imakewebthings Date: Fri, 20 Jun 2014 15:49:24 -0700 Subject: [PATCH 22/98] Remove old coffee waypoints --- src/waypoints.coffee | 691 ------------------------------------------- 1 file changed, 691 deletions(-) delete mode 100644 src/waypoints.coffee diff --git a/src/waypoints.coffee b/src/waypoints.coffee deleted file mode 100644 index 5135889c..00000000 --- a/src/waypoints.coffee +++ /dev/null @@ -1,691 +0,0 @@ -###! -jQuery Waypoints - v2.0.5 -Copyright (c) 2011-2014 Caleb Troughton -Licensed under the MIT license. -https://github.com/imakewebthings/jquery-waypoints/blob/master/licenses.txt -### -((root, factory) -> - if typeof define is 'function' and define.amd - define 'waypoints', ['jquery'], ($) -> - factory $, root - else - factory root.jQuery, root -) window, ($, window) -> - $w = $ window - - # Touch support feature test - isTouch = 'ontouchstart' in window - - # Internal plugin-wide variables: - - # - allWaypoints: A hash containing two hashes, one for vertical waypoints - # and one for horizontal waypoints. In each hash they value is a Waypoint - # instance and the key is that waypoint's unique ID. - - # - contextCounter: A counter that is incremented with each instantiation - # of the Context class, used in its unique ID. - - # - contexts: A hash of all contexts. The value of each entry is a Context - # instance and the key is that context's unique ID. - - # - contextKey: The DOM element for each context keeps a reference to the - # context's unique ID in the jQuery .data() object. This is the key for - # that data entry. - - # - resizeEvent: The namespaced resize event used by contexts. - - # - scrollEvent: The namespaced scroll event used by contexts. - - # - waypointCounter: A counter that is incremented with each instantiation - # of the Waypoint class, used in its unique ID. - - # - waypointKey: The DOM element for each waypoint keeps a reference to an - # array of the unique IDs of all waypoints attached to that element. This - # array is kept in the jQuery .data() object, and this is the key for - # that entry. - - # - wp: A variable shortcut for the waypoint method name on the $.fn object. - # Using this variable just helps with minification. - - # - wps: A variable shortcut for the waypoints method name on the $ object. - # Using this variable just helps with minification. - - allWaypoints = - horizontal: {} - vertical: {} - contextCounter = 1 - contexts = {} - contextKey = 'waypoints-context-id' - resizeEvent = 'resize.waypoints' - scrollEvent = 'scroll.waypoints' - waypointCounter = 1 - waypointKey = 'waypoints-waypoint-ids' - wp = 'waypoint' - wps = 'waypoints' - - # Context: Represents a single scrolling element in which waypoints live. - # For most users there will only be one Context, the window, but users can - # use other scrollable elements as a context using the "context" option - # when creating waypoints. - - # Properties: - - # - $element: jQuery object containing the context element. - - # - element: The raw HTMLNode of the context element. - - # - didResize: A flag used in throttling the resize event. - - # - didScroll: A flag used in throttling the scroll event. - - # - id: A unique identifier for the context. - - # - oldScroll: A hash containing... - # - x: The context's last known horizontal scroll value. - # - y: The context's last known vertical scroll value. - - # - waypoints: A hash containing two hashes with all waypoints in the context. - # Entries are in the same style as the allWaypoints hashes: - # (key = waypoint.id, value = waypoint) - # - horizontal: A hash of all horizontal waypoints. - # - vertical: A hash of all vertical waypoints. - - class Context - constructor: ($element) -> - @$element = $element - @element = $element[0] - @didResize = no - @didScroll = no - @id = 'context' + contextCounter++ - @oldScroll = - x: $element.scrollLeft() - y: $element.scrollTop() - @waypoints = - horizontal: {} - vertical: {} - - # We need to keep a reference to this Context instance on the DOM node - # so we can look it up later based on the node. - @element[contextKey] = @id - - # To do that look up, we need to have this instance in the global hash. - contexts[@id] = this - - # Run scroll checks on scroll, but throttle it for performance reasons. - $element.bind scrollEvent, => - unless @didScroll or isTouch - @didScroll = yes - scrollHandler = => - @doScroll() - @didScroll = no - window.setTimeout scrollHandler, $[wps].settings.scrollThrottle - - # Run a refresh on resize, but throttle it for performance reasons. - $element.bind resizeEvent, => - unless @didResize - @didResize = yes - resizeHandler = => - $[wps] 'refresh' - @didResize = no - window.setTimeout resizeHandler, $[wps].settings.resizeThrottle - - # doScroll() - - # Looks at the new scroll values for the context, compares them to the old - # scroll values, and checks to see if any waypoints should be triggered - # by that change. - doScroll: -> - - # We use some hashes with common values for each axis so that we can - # just iterate over it rather than write the whole thing twice for - # each axis. - axes = - horizontal: - newScroll: @$element.scrollLeft() - oldScroll: @oldScroll.x - forward: 'right' - backward: 'left' - vertical: - newScroll: @$element.scrollTop() - oldScroll: @oldScroll.y - forward: 'down' - backward: 'up' - - # This is a small "hack" for iOS, needed because scrolls in mobile - # Safari that start or end with the URL bar showing will cause window - # height changes without firing a resize event. - if isTouch and (!axes.vertical.oldScroll or !axes.vertical.newScroll) - $[wps] 'refresh' - - # For each axis, check to see if any waypoints have been crossed. - # Also determine the direction it's being crossed and sort/reverse all - # crossed waypoints accordingly. And, of course, trigger the waypoints. - $.each axes, (aKey, axis) => - triggered = [] - isForward = axis.newScroll > axis.oldScroll - direction = if isForward then axis.forward else axis.backward - $.each @waypoints[aKey], (wKey, waypoint) -> - if axis.oldScroll < waypoint.offset <= axis.newScroll - triggered.push waypoint - else if axis.newScroll < waypoint.offset <= axis.oldScroll - triggered.push waypoint - triggered.sort (a, b) -> a.offset - b.offset - triggered.reverse() unless isForward - $.each triggered, (i, waypoint) -> - if waypoint.options.continuous or i is triggered.length - 1 - waypoint.trigger [direction] - - # Now that we're done with the check, the new scroll values become - # the old scroll values for the next check. - @oldScroll = - x: axes.horizontal.newScroll - y: axes.vertical.newScroll - - # refresh() - # Runs through all of the waypoints in the context and recalculates - # their offsets (the scroll value at which the waypoint is triggered.) - # If a change in offset also happens to cross the context's current - # scroll value, the waypoint will be triggered in the appropriate direction - # unless prevented by the "onlyOnScroll" waypoint option. - refresh: () -> - isWin = $.isWindow @element - cOffset = @$element.offset() - - # Make sure we have the most up-to-date scroll values for our context. - @doScroll() - - # Each axis recalculation needs to know some things: - - # - contextOffset: The distance between the edge of the document and - # the context element. - - # - contextScroll: The scroll value of the context. However, if the - # context is the window this needs to be 0 because this value only - # comes into play when used in adjustment calculations for non-window - # context waypoints. - - # - contextDimension: Width or height of the context. - - # - oldScroll: The scroll value of the context. Unlike "contextScroll", - # this is the same no matter the type of context, and is used when - # determining whether a newly added waypoint should immediately fire - # on its first offset calculation. - - # - forward: Direction string passed to forward waypoint triggers. - - # - backward: Direction string passed to backward waypoint triggers. - - # - offsetProp: Key of the .offset() object for this axis. - axes = - horizontal: - contextOffset: if isWin then 0 else cOffset.left - contextScroll: if isWin then 0 else @oldScroll.x - contextDimension: @$element.width() - oldScroll: @oldScroll.x - forward: 'right' - backward: 'left' - offsetProp: 'left' - vertical: - contextOffset: if isWin then 0 else cOffset.top - contextScroll: if isWin then 0 else @oldScroll.y - contextDimension: if isWin then $[wps]('viewportHeight') else \ - @$element.height() - oldScroll: @oldScroll.y - forward: 'down' - backward: 'up' - offsetProp: 'top' - - # For each axis, run through the waypoints. Store the old offset. - # Recalculate the new offset. Check the difference against the context's - # current scroll value and trigger any crossed waypoints accordingly. - $.each axes, (aKey, axis) => - $.each @waypoints[aKey], (i, waypoint) -> - adjustment = waypoint.options.offset - oldOffset = waypoint.offset - elementOffset = if $.isWindow waypoint.element then 0 else \ - waypoint.$element.offset()[axis.offsetProp] - - # The "offset" waypoint option (which we call "adjustment" here) can - # be a number, percentage string, keyword string (bottom-in-view), - # or a function. So we deal with all of these types here. - if $.isFunction adjustment - adjustment = adjustment.apply waypoint.element - else if typeof adjustment is 'string' - adjustment = parseFloat adjustment - if waypoint.options.offset.indexOf('%') > -1 - adjustment = Math.ceil(axis.contextDimension * adjustment / 100) - - # We've finally calculated all the crazy little adjustments that - # can come from using non-window contexts and the "offset" option. - # Store the damn thing. - waypoint.offset = elementOffset \ - - axis.contextOffset \ - + axis.contextScroll \ - - adjustment - - # "onlyOnScroll" tells us to not even consider triggering waypoints - # during refresh, so we can eject early. - return if (waypoint.options.onlyOnScroll and oldOffset?) or \ - !waypoint.enabled - - # Case where the refresh causes a backward trigger. - if oldOffset isnt null and \ - oldOffset < axis.oldScroll <= waypoint.offset - waypoint.trigger [axis.backward] - - # Now the forward case. - else if oldOffset isnt null and \ - oldOffset > axis.oldScroll >= waypoint.offset - waypoint.trigger [axis.forward] - - # "oldOffset" values of null mean this is the first calculation of - # the waypoint's offset. It's a special time in a waypoint's life. - else if oldOffset is null and axis.oldScroll >= waypoint.offset - waypoint.trigger [axis.forward] - - # checkEmpty() - - # Looks at the waypoints hashes. If they are empty, the context removes - # itself from the global contexts hash. - checkEmpty: -> - if $.isEmptyObject(@waypoints.horizontal) and \ - $.isEmptyObject(@waypoints.vertical) - @$element.unbind [resizeEvent, scrollEvent].join(' ') - delete contexts[@id] - - # Waypoint: Represents a single callback function tied to an element. An - # element can have multiple waypoints with multiple offsets. - - # Properties: - - # - $element: jQuery object containing the waypoint element. - - # - element: The raw HTMLNode of the waypoint element. - - # - axis: 'horizontal' || 'vertical' - The axis on which this waypoint lives. - - # - callback: The function that is fired when the waypoint is triggered. - - # - context: A reference to the context this waypoint belongs to. - - # - enabled: Boolean indicating whether this waypoint is enabled or not. - # Disabled waypoints are still returned in functions that aggregate - # waypoints, but do not fire their callbacks. - - # - id: A unique identifier for the waypoint. - - # - offset: The scroll offset at which the waypoint should trigger. - - # - options: A hash containing the various waypoint options. - # See $.fn.waypoint.defaults for more information on those options. - class Waypoint - constructor: ($element, context, options) -> - if options.offset is 'bottom-in-view' - options.offset = -> - contextHeight = $[wps] 'viewportHeight' - unless $.isWindow context.element - contextHeight = context.$element.height() - contextHeight - $(this).outerHeight() - - @$element = $element - @element = $element[0] - @axis = if options.horizontal then 'horizontal' else 'vertical' - @callback = options.handler - @context = context - @enabled = options.enabled - @id = 'waypoints' + waypointCounter++ - @offset = null - @options = options - - # Add our new waypoint to its context. - context.waypoints[@axis][@id] = this - - # Add it to the global hash. - allWaypoints[@axis][@id] = this - - # Add the waypoint's id to the element's waypoint id list. - idList = @element[waypointKey] ? [] - idList.push @id - @element[waypointKey] = idList - - # trigger(array) - - # Calls the waypoint's callback function, passing to it the arguments - # supplied in the "args" array. - trigger: (args) -> - return unless @enabled - if @callback? - @callback.apply @element, args - if @options.triggerOnce - @destroy() - - # disable() - - # Temporarily disables a waypoint from firing its callback. - disable: -> - @enabled = false - - # enable() - - # Breathe life back into the waypoint. - enable: -> - @context.refresh() - @enabled = true - - # destroy() - - # Kills the waypoint for good. - destroy: -> - delete allWaypoints[@axis][@id] - delete @context.waypoints[@axis][@id] - @context.checkEmpty() - - # Waypoint.getWaypointsByElement(HTMLNode) - - # Returns an array of all Waypoint instances attached to the "element" - # HTMLNode. Returns an empty array if there are no attached waypoints. - @getWaypointsByElement: (element) -> - ids = element[waypointKey] - return [] unless ids - all = $.extend {}, allWaypoints.horizontal, allWaypoints.vertical - $.map ids, (id) -> - all[id] - - # These methods are available on the $.fn object by using the method - # name as the first argument to .waypoint. Ex: $('div').waypoint('destroy') - methods = - - # init(function, object) - - # Creates a new waypoint (and if needed, a new context) using the supplied - # callback function and options. - - # The "f" function and the "options" object are both optional, but at least - # one must be supplied. So acceptable signatures are: - - # - .waypoint(f) - # - .waypoint(options) - # - .waypoint(f, options) - - # This "init" method should never need to be called explicity by the user. - # It is the default method that is delegated to when .waypoint is called - # with one of the above signatures. - - # Ex: $('div').waypoint(function(direction) { - # // Do things - # }, { offset: '100%' }); - init: (f, options) -> - options = $.extend {}, $.fn[wp].defaults, options - options.handler ?= f - - @each -> - $this = $ this - contextElement = options.context ? $.fn[wp].defaults.context - unless $.isWindow contextElement - contextElement = $this.closest contextElement - contextElement = $ contextElement - context = contexts[contextElement[0][contextKey]] - context = new Context contextElement unless context - new Waypoint $this, context, options - $[wps] 'refresh' - this - - # Disable, enable, and destroy all just delegate to the instance methods - # of the waypoints attached to the subject elements. - disable: -> methods._invoke.call this, 'disable' - enable: -> methods._invoke.call this, 'enable' - destroy: -> methods._invoke.call this, 'destroy' - - # .waypoint('prev', string, string|HTMLNode|jQuery) - - # Returns a jQuery object containing previous waypoint elements. This - # creates a new entry in the jQuery object stack just like jQuery's prev - # function. "axis" indicates the axis on which to traverse - # ('horizontal' | 'vertical') and "selector" indicates which context - # element to use. The defaults are 'vertical' and window respectively. - prev: (axis, selector) -> - methods._traverse.call this, axis, selector, (stack, index, waypoints) -> - stack.push waypoints[index-1] if index > 0 - - # .waypoint('next', string, string|HTMLNode|jQuery) - - # Returns a jQuery object containing next waypoint elements. This - # creates a new entry in the jQuery object stack just like jQuery's next - # function. "axis" indicates the axis on which to traverse - # ('horizontal' | 'vertical') and "selector" indicates which context - # element to use. The defaults are 'vertical' and window respectively. - next: (axis, selector) -> - methods._traverse.call this, axis, selector, (stack, index, waypoints) -> - stack.push waypoints[index+1] if index < waypoints.length-1 - - # Internal: Aggregates waypoints on a given axis of a context, and applies - # a "push" callback for each element in the subject jQuery object. This - # callback builds the element array to push to the jQuery stack. - _traverse: (axis = 'vertical', selector = window, push) -> - waypoints = jQMethods.aggregate selector - stack = [] - @each -> - index = $.inArray this, waypoints[axis] - push stack, index, waypoints[axis] - @pushStack stack - - # Internal: Finds all waypoints on a given set of "$elements" and invokes - # "method" on each instance. - _invoke: (method) -> - this.each -> - waypoints = Waypoint.getWaypointsByElement this - $.each waypoints, (i, waypoint) -> - waypoint[method]() - true - this - - # $.fn.waypoint. Let's just hook this guy up to our methods hash and - # add some trivial error reporting for bogus calls. - $.fn[wp] = (method, args...) -> - if methods[method] - methods[method].apply this, args - else if $.isFunction(method) - methods.init.apply this, arguments - else if $.isPlainObject(method) - methods.init.apply this, [null, method] - else if !method - $.error "jQuery Waypoints needs a callback function or handler option." - else - $.error "The #{method} method does not exist in jQuery Waypoints." - - # The default options object for a waypoint. - - # - context: string|HTMLNode|jQuery - The scrollable element that the - # waypoint acts within. The waypoint will look for the closest ancestor - # element that matches this selector or node. - - # - continuous: Multiple waypoints may be triggered by a single scroll check. - # If you would like a waypoint to only trigger if it is the last waypoint - # in a scroll check, set this to false. - - # - enabled: Should this waypoint start enabled (true) or disabled (false)? - - # - handler: This option is not defined by default, but can be used as an - # alternate way to pass the waypoint callback function, rather than as - # the first argument to .waypoint. - - # Ex: $('div').waypoint({ - # handler: function(direction) { ... } - # }); - - # - horizontal: Set this to true if the waypoint is, well, horizontal. - - # - offset: number|string|function - Determines how far from the top (or left - # if the waypoint is horizontal) of the context's viewport to trigger the - # waypoint. The default of 0 means that the waypoint is triggered when the - # top of the waypoint element hits the top of the window/context-element. - # An offset of 50 would mean the waypoint triggers when the top of the - # element is 50 pixels from the top of the window. - - # A % string is translated into a percentage of the width/height of - # the context. - - # If a function is passed, that function should return a number. The "this" - # keyword within this function will be set to the raw HTMLNode of the - # waypoint element. - - # - triggerOnce: If true, the waypoint will destroy itself after - # first trigger. - $.fn[wp].defaults = - context: window - continuous: true - enabled: true - horizontal: false - offset: 0 - triggerOnce: false - - # These methods are available on the $ object by using the method name as - # the first argument to .waypoint. Ex: $.waypoints('refresh') - jQMethods = - - # $.waypoints('refresh') - - # Forces a refresh on all contexts, recalculating all waypoint offsets. - # This is done automatically on waypoint addition and during resize events, - # but if a user does something to change the DOM, CSS, or in some way - # change the layout of a page and its elements, they might need to call - # this method manually. - refresh: -> - $.each contexts, (i, context) -> context.refresh() - - # $.waypoints('viewportHeight') - - # A utility method that returns the window height, but takes into account - # inconsistencies that come with just using jQuery's .height() on iOS. - viewportHeight: -> - window.innerHeight ? $w.height() - - # $.waypoints(['aggregate'], [contextSelector]) - - # Returns an object containing two HTMLNode arrays, one for each axis: - - # { - # horizontal: [ HTMLNode... ] - # vertical: [ HTMLNode... ] - # } - - # This is the default method used when calling $.waypoints(). If - # "contextSelector" is not supplied, it returns all waypoints. If - # "contextSelector" is supplied it only returns waypoints for that context. - - # The array of waypoint elements is returned sorted by calculated offset, - # the order in which they would be triggered on the page. - aggregate: (contextSelector) -> - collection = allWaypoints - if contextSelector - collection = contexts[$(contextSelector)[0][contextKey]]?.waypoints - return [] unless collection - waypoints = - horizontal: [] - vertical: [] - $.each waypoints, (axis, arr) -> - $.each collection[axis], (key, waypoint) -> - arr.push waypoint - arr.sort (a, b) -> a.offset - b.offset - waypoints[axis] = $.map arr, (waypoint) -> waypoint.element - waypoints[axis] = $.unique waypoints[axis] - waypoints - - # $.waypoints('above', [string|HTMLNode|jQuery]) - - # Returns all vertical waypoints that lie above the current scroll position - # of the context specified by "contextSelector". If no "contextSelector" - # is supplied, it defaults to the window. - above: (contextSelector = window) -> - jQMethods._filter contextSelector, 'vertical', (context, waypoint) -> - waypoint.offset <= context.oldScroll.y - - # $.waypoints('below', [string|HTMLNode|jQuery]) - - # Returns all vertical waypoints that lie below the current scroll position - # of the context specified by "contextSelector". If no "contextSelector" - # is supplied, it defaults to the window. - below: (contextSelector = window) -> - jQMethods._filter contextSelector, 'vertical', (context, waypoint) -> - waypoint.offset > context.oldScroll.y - - # $.waypoints('left', [string|HTMLNode|jQuery]) - - # Returns all horizontal waypoints left of the current scroll position - # of the context specified by "contextSelector". If no "contextSelector" - # is supplied, it defaults to the window. - left: (contextSelector = window) -> - jQMethods._filter contextSelector, 'horizontal', (context, waypoint) -> - waypoint.offset <= context.oldScroll.x - - # $.waypoints('right', [string|HTMLNode|jQuery]) - - # Returns all horizontal waypoints right of the current scroll position - # of the context specified by "contextSelector". If no "contextSelector" - # is supplied, it defaults to the window. - right: (contextSelector = window) -> - jQMethods._filter contextSelector, 'horizontal', (context, waypoint) -> - waypoint.offset > context.oldScroll.x - - # $.waypoints('enable/disable/destroy') - - # These methods delegate to the enable/disable/destroy instance methods - # for all waypoints. - enable: -> jQMethods._invoke 'enable' - disable: -> jQMethods._invoke 'disable' - destroy: -> jQMethods._invoke 'destroy' - - # $.waypoints('extendFn', string, function) - - # Extends the $.fn.waypoint method object with a new method, "f". This - # just lets other modules piggyback on the .waypoint namespace. - extendFn: (methodName, f) -> - methods[methodName] = f - - # Internal: Invokes "method" on all waypoints. - _invoke: (method) -> - waypoints = $.extend {}, allWaypoints.vertical, allWaypoints.horizontal - $.each waypoints, (key, waypoint) -> - waypoint[method]() - true - - # Internal: Returns an array of all HTMLNodes for each waypoint that passes - # the "test" function. Only waypoints within the "selector" context on the - # "axis" axis are tested. As with .aggregate, the array is sorted by - # calculated offset (trigger order). - _filter: (selector, axis, test) -> - context = contexts[$(selector)[0][contextKey]] - return [] unless context - waypoints = [] - $.each context.waypoints[axis], (i, waypoint) -> - waypoints.push waypoint if test context, waypoint - waypoints.sort (a, b) -> a.offset - b.offset - $.map waypoints, (waypoint) -> waypoint.element - - # Hook up jQMethods to the $.waypoints namespace. - $[wps] = (method, args...) -> - if jQMethods[method] - jQMethods[method].apply null, args - else - jQMethods.aggregate.call null, method - - # Plugin-wide settings: - - # - resizeThrottle: For performance reasons, the refresh performed during - # resizes is throttled. This value is the rate-limit in milliseconds - # between resize refreshes. For more information on throttling, check out - # Ben Alman’s throttle / debounce plugin. - # http://benalman.com/projects/jquery-throttle-debounce-plugin/ - - # - scrollThrottle: For performance reasons, checking for any crossed - # waypoints during a scroll event is throttled. This value is the - # rate-limit in milliseconds between scroll checks. For more information - # on throttling, check out Ben Alman’s throttle / debounce plugin. - # http://benalman.com/projects/jquery-throttle-debounce-plugin/ - - $[wps].settings = - resizeThrottle: 100 - scrollThrottle: 30 - - # Ensure a refresh on page load. Newly loaded images often shift layout. - $w.on 'load.waypoints', -> $[wps] 'refresh' From c707234ddbddf372ab117df0141884c30861dac0 Mon Sep 17 00:00:00 2001 From: imakewebthings Date: Fri, 20 Jun 2014 18:22:56 -0700 Subject: [PATCH 23/98] Gulp builds to /lib --- gulpfile.js | 73 +++- lib/jquery.waypoints.js | 535 +++++++++++++++++++++++++ lib/jquery.waypoints.min.js | 7 + lib/noframework.waypoints.js | 667 +++++++++++++++++++++++++++++++ lib/noframework.waypoints.min.js | 7 + lib/shortcuts/infinite.js | 78 ++++ lib/shortcuts/infinite.min.js | 7 + lib/shortcuts/inview.js | 100 +++++ lib/shortcuts/inview.min.js | 7 + lib/shortcuts/sticky.js | 60 +++ lib/shortcuts/sticky.min.js | 7 + lib/waypoints.js | 517 ------------------------ lib/zepto.waypoints.js | 567 ++++++++++++++++++++++++++ lib/zepto.waypoints.min.js | 7 + package.json | 8 +- src/adapters/jquery.js | 5 +- src/adapters/noframework.js | 6 +- src/adapters/zepto.js | 5 +- 18 files changed, 2137 insertions(+), 526 deletions(-) create mode 100644 lib/jquery.waypoints.js create mode 100644 lib/jquery.waypoints.min.js create mode 100644 lib/noframework.waypoints.js create mode 100644 lib/noframework.waypoints.min.js create mode 100644 lib/shortcuts/infinite.js create mode 100644 lib/shortcuts/infinite.min.js create mode 100644 lib/shortcuts/inview.js create mode 100644 lib/shortcuts/inview.min.js create mode 100644 lib/shortcuts/sticky.js create mode 100644 lib/shortcuts/sticky.min.js delete mode 100644 lib/waypoints.js create mode 100644 lib/zepto.waypoints.js create mode 100644 lib/zepto.waypoints.min.js diff --git a/gulpfile.js b/gulpfile.js index 4bac03b3..d33ec793 100644 --- a/gulpfile.js +++ b/gulpfile.js @@ -1,12 +1,81 @@ var gulp = require('gulp') var eslint = require('gulp-eslint') +var concat = require('gulp-concat') +var uglify = require('gulp-uglify') +var rename = require('gulp-rename') +var header = require('gulp-header') +var tap = require('gulp-tap') +var merge = require('merge-stream') +var pkg = require('./package.json') +var path = require('path') var jsFiles = ['src/**/*.js', 'test/**/*.js', '!test/lib/**/*.js'] +var shortcutTitles = { + 'infinite': 'Waypoints Infinite Scroll Shortcut', + 'inview': 'Waypoints Inview Shortcut', + 'sticky': 'Waypoints Sticky Element Shortcut' +} + +function fileHeader(title) { + return [ + '/*!', + title + ' - ' + pkg.version, + 'Copyright © 2011-' + new Date().getFullYear() + ' Caleb Troughton', + 'Licensed under the MIT license.', + 'https://github.com/imakewebthings/waypoints/blog/master/licenses.txt', + '*/\n' + ].join('\n') +} gulp.task('lint', function() { - gulp.src(jsFiles).pipe(eslint('.eslintrc')).pipe(eslint.format()) + return gulp.src(jsFiles).pipe(eslint('.eslintrc')).pipe(eslint.format()) +}) + +gulp.task('build-core', function() { + var streams = ['noframework', 'jquery', 'zepto'].map(function(adapter) { + return gulp.src([ + 'src/waypoint.js', + 'src/context.js', + 'src/group.js', + 'src/adapters/' + adapter + '.js' + ]) + .pipe(concat(adapter + '.waypoints.js')) + .pipe(header(fileHeader('Waypoints'))) + .pipe(gulp.dest('lib/')) + .pipe(rename(adapter + '.waypoints.min.js')) + .pipe(uglify({ + preserveComments: 'some' + })) + .pipe(gulp.dest('lib/')) + }) + return merge.apply(null, streams) }) +gulp.task('build-shortcuts', function() { + return gulp.src([ + 'src/shortcuts/*.js' + ]) + .pipe(tap(function(file) { + var title = path.basename(file.path, '.js') + file.contents = Buffer.concat([ + new Buffer(fileHeader(shortcutTitles[title])), + file.contents + ]) + })) + .pipe(gulp.dest('lib/shortcuts/')) + .pipe(rename(function(path) { + path.basename += '.min' + })) + .pipe(uglify({ + preserveComments: 'some' + })) + .pipe(gulp.dest('lib/shortcuts/')) +}) + +gulp.task('build', ['build-core', 'build-shortcuts']) + gulp.task('watch', function() { - gulp.watch(jsFiles, ['lint']) + gulp.watch(jsFiles, ['lint', 'build']) }) + +gulp.task('default', ['lint', 'build', 'watch']) diff --git a/lib/jquery.waypoints.js b/lib/jquery.waypoints.js new file mode 100644 index 00000000..bed9374b --- /dev/null +++ b/lib/jquery.waypoints.js @@ -0,0 +1,535 @@ +/*! +Waypoints - 2.0.5 +Copyright © 2011-2014 Caleb Troughton +Licensed under the MIT license. +https://github.com/imakewebthings/waypoints/blog/master/licenses.txt +*/ +(function() { + 'use strict' + + var keyCounter = 0 + var allWaypoints = {} + + function Waypoint(options) { + if (!options) { + throw new Error('No options passed to Waypoint constructor') + } + if (!options.element) { + throw new Error('No element option passed to Waypoint constructor') + } + + this.key = 'waypoint-' + keyCounter + this.options = Waypoint.Adapter.extend({}, Waypoint.defaults, options) + this.element = this.options.element + this.adapter = new Waypoint.Adapter(this.element) + this.callback = options.handler + this.axis = this.options.horizontal ? 'horizontal' : 'vertical' + this.enabled = this.options.enabled + this.triggerPoint = null + this.group = Waypoint.Group.findOrCreate({ + name: this.options.group, + axis: this.axis + }) + this.context = Waypoint.Context.findOrCreateByElement(this.options.context) + + if (Waypoint.offsetAliases[this.options.offset]) { + this.options.offset = Waypoint.offsetAliases[this.options.offset] + } + this.context.add(this) + this.group.add(this) + allWaypoints[this.key] = this + keyCounter += 1 + } + + Waypoint.prototype.disable = function() { + this.enabled = false + return this + } + + Waypoint.prototype.enable = function() { + this.context.refresh() + this.enabled = true + return this + } + + Waypoint.prototype.destroy = function() { + this.context.remove(this) + this.group.remove(this) + delete allWaypoints[this.key] + } + + /* Internal */ + Waypoint.prototype.trigger = function(args) { + if (!this.enabled) { + return + } + if (this.callback) { + this.callback.apply(this, args) + } + if (this.options.triggerOnce) { + this.destroy() + } + } + + /* Internal */ + Waypoint.prototype.queueTrigger = function(direction) { + this.group.queueTrigger(this, direction) + } + + Waypoint.adapters = [] + + Waypoint.defaults = { + context: window, + continuous: true, + enabled: true, + group: 'default', + horizontal: false, + offset: 0, + triggerOnce: false + } + + Waypoint.offsetAliases = { + 'bottom-in-view': function() { + return this.context.height() - this.adapter.outerHeight() + }, + 'right-in-view': function() { + return this.context.adapter.width() - this.adapter.outerWidth() + } + } + + Waypoint.viewportHeight = function() { + return window.innerHeight || document.documentElement.clientHeight + } + + Waypoint.refresh = function() { + Waypoint.Context.refreshAll() + } + + Waypoint.destroyAll = function() { + var allWaypointsArray = [] + for (var waypointKey in allWaypoints) { + allWaypointsArray.push(allWaypoints[waypointKey]) + } + for (var i = 0, end = allWaypointsArray.length; i < end; i++) { + allWaypointsArray[i].destroy() + } + } + + window.Waypoint = Waypoint +}()) + +(function() { + 'use strict' + + function requestAnimationFrameShim(callback) { + window.setTimeout(callback, 1000 / 60) + } + + var keyCounter = 0 + var contexts = {} + var Waypoint = window.Waypoint + + var requestAnimationFrame = window.requestAnimationFrame || + window.mozRequestAnimationFrame || + window.webkitRequestAnimationFrame || + requestAnimationFrameShim + + function Context(element) { + this.element = element + this.Adapter = Waypoint.Adapter + this.adapter = new this.Adapter(element) + this.key = 'waypoint-context-' + keyCounter + this.didScroll = false + this.didResize = false + this.oldScroll = { + x: this.adapter.scrollLeft(), + y: this.adapter.scrollTop() + } + this.waypoints = { + vertical: {}, + horizontal: {} + } + + element.waypointContextKey = this.key + contexts[element.waypointContextKey] = this + keyCounter += 1 + + this.createThrottledScrollHandler() + this.createThrottledResizeHandler() + } + + /* Internal */ + Context.prototype.createThrottledScrollHandler = function() { + var self = this + function scrollHandler() { + self.handleScroll() + self.didScroll = false + } + + this.adapter.on('scroll.waypoints', function() { + if (!self.didScroll || Waypoint.isTouch) { + self.didScroll = true + requestAnimationFrame(scrollHandler) + } + }) + } + + /* Internal */ + Context.prototype.createThrottledResizeHandler = function() { + var self = this + + function resizeHandler() { + self.handleResize() + self.didResize = false + } + + this.adapter.on('resize.waypoints', function() { + if (!self.didResize) { + self.didResize = true + requestAnimationFrame(resizeHandler) + } + }) + } + + /* Internal */ + Context.prototype.handleScroll = function() { + var triggeredGroups = {} + var axes = { + horizontal: { + newScroll: this.adapter.scrollLeft(), + oldScroll: this.oldScroll.x, + forward: 'right', + backward: 'left' + }, + vertical: { + newScroll: this.adapter.scrollTop(), + oldScroll: this.oldScroll.y, + forward: 'down', + backward: 'up' + } + } + + for (var axisKey in axes) { + var axis = axes[axisKey] + var isForward = axis.newScroll > axis.oldScroll + var direction = isForward ? axis.forward : axis.backward + + for (var waypointKey in this.waypoints[axisKey]) { + var waypoint = this.waypoints[axisKey][waypointKey] + var wasBeforeTriggerPoint = axis.oldScroll < waypoint.triggerPoint + var nowAfterTriggerPoint = axis.newScroll >= waypoint.triggerPoint + var crossedForward = wasBeforeTriggerPoint && nowAfterTriggerPoint + var crossedBackward = !wasBeforeTriggerPoint && !nowAfterTriggerPoint + if (crossedForward || crossedBackward) { + waypoint.queueTrigger(direction) + triggeredGroups[waypoint.group.id] = waypoint.group + } + } + } + + for (var groupKey in triggeredGroups) { + triggeredGroups[groupKey].flushTriggers() + } + + this.oldScroll = { + x: axes.horizontal.newScroll, + y: axes.vertical.newScroll + } + } + + /* Internal */ + Context.prototype.handleResize = function() { + Waypoint.Context.refreshAll() + } + + Context.prototype.refresh = function() { + var isWindow = this.element === this.element.window + var contextOffset = this.adapter.offset() + var height = isWindow ? Waypoint.viewportHeight() : this.adapter.height() + var triggeredGroups = {} + var axes + + this.handleScroll() + axes = { + horizontal: { + contextOffset: isWindow ? 0 : contextOffset.left, + contextScroll: isWindow ? 0 : this.oldScroll.x, + contextDimension: this.adapter.width(), + oldScroll: this.oldScroll.x, + forward: 'right', + backward: 'left', + offsetProp: 'left' + }, + vertical: { + contextOffset: isWindow ? 0 : contextOffset.top, + contextScroll: isWindow ? 0 : this.oldScroll.y, + contextDimension: height, + oldScroll: this.oldScroll.y, + forward: 'down', + backward: 'up', + offsetProp: 'top' + } + } + + for (var axisKey in axes) { + var axis = axes[axisKey] + for (var waypointKey in this.waypoints[axisKey]) { + var waypoint = this.waypoints[axisKey][waypointKey] + var adjustment = waypoint.options.offset + var oldTriggerPoint = waypoint.triggerPoint + var elementOffset = 0 + var freshWaypoint = oldTriggerPoint == null + var contextModifier + + if (waypoint.element !== waypoint.element.window) { + elementOffset = waypoint.adapter.offset()[axis.offsetProp] + } + + if (typeof adjustment === 'function') { + adjustment = adjustment.apply(waypoint) + } + else if (typeof adjustment === 'string') { + adjustment = parseFloat(adjustment) + if (waypoint.options.offset.indexOf('%') > - 1) { + adjustment = Math.ceil(axis.contextDimension * adjustment / 100) + } + } + + contextModifier = axis.contextScroll - axis.contextOffset + waypoint.triggerPoint = elementOffset + contextModifier - adjustment + + var wasBeforeScroll = oldTriggerPoint < axis.oldScroll + var nowAfterScroll = waypoint.triggerPoint >= axis.oldScroll + var triggeredBackward = wasBeforeScroll && nowAfterScroll + var triggeredForward = !wasBeforeScroll && !nowAfterScroll + if (!freshWaypoint && triggeredBackward) { + waypoint.queueTrigger(axis.backward) + triggeredGroups[waypoint.group.id] = waypoint.group + } + else if (!freshWaypoint && triggeredForward) { + waypoint.queueTrigger(axis.forward) + triggeredGroups[waypoint.group.id] = waypoint.group + } + else if (freshWaypoint && axis.oldScroll >= waypoint.triggerPoint) { + waypoint.queueTrigger(axis.forward) + triggeredGroups[waypoint.group.id] = waypoint.group + } + } + } + + for (var groupKey in triggeredGroups) { + triggeredGroups[groupKey].flushTriggers() + } + + return this + } + + Context.prototype.destroy = function() { + var allWaypoints = [] + for (var axis in this.waypoints) { + for (var waypointKey in this.waypoints[axis]) { + allWaypoints.push(this.waypoints[axis][waypointKey]) + } + } + for (var i = 0, end = allWaypoints.length; i < end; i++) { + allWaypoints[i].destroy() + } + } + + /* Internal */ + Context.prototype.add = function(waypoint) { + var axis = waypoint.options.horizontal ? 'horizontal' : 'vertical' + this.waypoints[axis][waypoint.key] = waypoint + this.refresh() + } + + /* Internal */ + Context.prototype.remove = function(waypoint) { + delete this.waypoints[waypoint.axis][waypoint.key] + this.checkEmpty() + } + + /* Internal */ + Context.prototype.checkEmpty = function() { + var horizontalEmpty = this.Adapter.isEmptyObject(this.waypoints.horizontal) + var verticalEmpty = this.Adapter.isEmptyObject(this.waypoints.vertical) + if (horizontalEmpty && verticalEmpty) { + this.adapter.off('.waypoints') + delete contexts[this.key] + } + } + + /* Internal */ + Context.prototype.height = function() { + if (this.element === this.element.window) { + return Waypoint.viewportHeight() + } + return this.adapter.height() + } + + Context.refreshAll = function() { + for (var contextId in contexts) { + contexts[contextId].refresh() + } + } + + /* Internal */ + Context.findByElement = function(element) { + return contexts[element.waypointContextKey] + } + + /* Internal */ + Context.findOrCreateByElement = function(element) { + return Context.findByElement(element) || new Context(element) + } + + Waypoint.Context = Context +}()) + +(function() { + 'use strict' + + var groups = { + vertical: {}, + horizontal: {} + } + var Waypoint = window.Waypoint + + function byTriggerPoint(a, b) { + return a.triggerPoint - b.triggerPoint + } + + function byReverseTriggerPoint(a, b) { + return b.triggerPoint - a.triggerPoint + } + + function Group(options) { + this.name = options.name + this.axis = options.axis + this.id = this.name + '-' + this.axis + this.waypoints = [] + this.clearTriggerQueues() + groups[this.axis][this.name] = this + } + + Group.prototype.previous = function(waypoint) { + this.sort() + var index = Waypoint.Adapter.inArray(waypoint, this.waypoints) + return index ? this.waypoints[index - 1] : null + } + + Group.prototype.next = function(waypoint) { + this.sort() + var index = Waypoint.Adapter.inArray(waypoint, this.waypoints) + var isLast = index === this.waypoints.length - 1 + return isLast ? null : this.waypoints[index + 1] + } + + Group.prototype.first = function() { + return this.waypoints[0] + } + + Group.prototype.last = function() { + return this.waypoints[this.waypoints.length - 1] + } + + /* Internal */ + Group.prototype.add = function(waypoint) { + this.waypoints.push(waypoint) + } + + /* Internal */ + Group.prototype.remove = function(waypoint) { + var index = Waypoint.Adapter.inArray(waypoint, this.waypoints) + if (index > -1) { + this.waypoints.splice(index, 1) + } + } + + /* Internal */ + Group.prototype.sort = function() { + this.waypoints.sort(function(a, b) { + return a.triggerPoint - b.triggerPoint + }) + } + + /* Internal */ + Group.prototype.clearTriggerQueues = function() { + this.triggerQueues = { + up: [], + down: [], + left: [], + right: [] + } + } + + /* Internal */ + Group.prototype.queueTrigger = function(waypoint, direction) { + this.triggerQueues[direction].push(waypoint) + } + + /* Internal */ + Group.prototype.flushTriggers = function() { + for (var direction in this.triggerQueues) { + var waypoints = this.triggerQueues[direction] + var reverse = direction === 'up' || direction === 'left' + waypoints.sort(reverse ? byReverseTriggerPoint : byTriggerPoint) + for (var i = 0, end = waypoints.length; i < end; i += 1) { + var waypoint = waypoints[i] + if (waypoint.options.continuous || i === waypoints.length - 1) { + waypoint.trigger([direction]) + } + } + } + this.clearTriggerQueues() + } + + /* Internal */ + Group.findOrCreate = function(options) { + return groups[options.axis][options.name] || new Group(options) + } + + Waypoint.Group = Group +}()) + +(function() { + 'use strict' + + var $ = window.jQuery + var Waypoint = window.Waypoint + + function JQueryAdapter(element) { + this.$element = $(element) + } + + $.each([ + 'height', + 'off', + 'offset', + 'on', + 'outerHeight', + 'outerWidth', + 'scrollLeft', + 'scrollTop', + 'width' + ], function(i, method) { + JQueryAdapter.prototype[method] = function() { + var args = Array.prototype.slice.call(arguments) + return this.$element[method].apply(this.$element, args) + } + }) + + $.each([ + 'extend', + 'inArray', + 'isEmptyObject' + ], function(i, method) { + JQueryAdapter[method] = $[method] + }) + + Waypoint.adapters.push({ + name: 'jquery', + Adapter: JQueryAdapter + }) + Waypoint.Adapter = JQueryAdapter +}()) diff --git a/lib/jquery.waypoints.min.js b/lib/jquery.waypoints.min.js new file mode 100644 index 00000000..54464c6c --- /dev/null +++ b/lib/jquery.waypoints.min.js @@ -0,0 +1,7 @@ +/*! +Waypoints - 2.0.5 +Copyright © 2011-2014 Caleb Troughton +Licensed under the MIT license. +https://github.com/imakewebthings/waypoints/blog/master/licenses.txt +*/ +!function(){"use strict";function t(o){if(!o)throw new Error("No options passed to Waypoint constructor");if(!o.element)throw new Error("No element option passed to Waypoint constructor");this.key="waypoint-"+e,this.options=t.Adapter.extend({},t.defaults,o),this.element=this.options.element,this.adapter=new t.Adapter(this.element),this.callback=o.handler,this.axis=this.options.horizontal?"horizontal":"vertical",this.enabled=this.options.enabled,this.triggerPoint=null,this.group=t.Group.findOrCreate({name:this.options.group,axis:this.axis}),this.context=t.Context.findOrCreateByElement(this.options.context),t.offsetAliases[this.options.offset]&&(this.options.offset=t.offsetAliases[this.options.offset]),this.context.add(this),this.group.add(this),i[this.key]=this,e+=1}var e=0,i={};t.prototype.disable=function(){return this.enabled=!1,this},t.prototype.enable=function(){return this.context.refresh(),this.enabled=!0,this},t.prototype.destroy=function(){this.context.remove(this),this.group.remove(this),delete i[this.key]},t.prototype.trigger=function(t){this.enabled&&(this.callback&&this.callback.apply(this,t),this.options.triggerOnce&&this.destroy())},t.prototype.queueTrigger=function(t){this.group.queueTrigger(this,t)},t.adapters=[],t.defaults={context:window,continuous:!0,enabled:!0,group:"default",horizontal:!1,offset:0,triggerOnce:!1},t.offsetAliases={"bottom-in-view":function(){return this.context.height()-this.adapter.outerHeight()},"right-in-view":function(){return this.context.adapter.width()-this.adapter.outerWidth()}},t.viewportHeight=function(){return window.innerHeight||document.documentElement.clientHeight},t.refresh=function(){t.Context.refreshAll()},t.destroyAll=function(){var t=[];for(var e in i)t.push(i[e]);for(var o=0,r=t.length;r>o;o++)t[o].destroy()},window.Waypoint=t}()(function(){"use strict";function t(t){window.setTimeout(t,1e3/60)}function e(t){this.element=t,this.Adapter=r.Adapter,this.adapter=new this.Adapter(t),this.key="waypoint-context-"+i,this.didScroll=!1,this.didResize=!1,this.oldScroll={x:this.adapter.scrollLeft(),y:this.adapter.scrollTop()},this.waypoints={vertical:{},horizontal:{}},t.waypointContextKey=this.key,o[t.waypointContextKey]=this,i+=1,this.createThrottledScrollHandler(),this.createThrottledResizeHandler()}var i=0,o={},r=window.Waypoint,n=window.requestAnimationFrame||window.mozRequestAnimationFrame||window.webkitRequestAnimationFrame||t;e.prototype.createThrottledScrollHandler=function(){function t(){e.handleScroll(),e.didScroll=!1}var e=this;this.adapter.on("scroll.waypoints",function(){(!e.didScroll||r.isTouch)&&(e.didScroll=!0,n(t))})},e.prototype.createThrottledResizeHandler=function(){function t(){e.handleResize(),e.didResize=!1}var e=this;this.adapter.on("resize.waypoints",function(){e.didResize||(e.didResize=!0,n(t))})},e.prototype.handleScroll=function(){var t={},e={horizontal:{newScroll:this.adapter.scrollLeft(),oldScroll:this.oldScroll.x,forward:"right",backward:"left"},vertical:{newScroll:this.adapter.scrollTop(),oldScroll:this.oldScroll.y,forward:"down",backward:"up"}};for(var i in e){var o=e[i],r=o.newScroll>o.oldScroll,n=r?o.forward:o.backward;for(var s in this.waypoints[i]){var a=this.waypoints[i][s],l=o.oldScroll=a.triggerPoint,p=l&&h,c=!l&&!h;(p||c)&&(a.queueTrigger(n),t[a.group.id]=a.group)}}for(var u in t)t[u].flushTriggers();this.oldScroll={x:e.horizontal.newScroll,y:e.vertical.newScroll}},e.prototype.handleResize=function(){r.Context.refreshAll()},e.prototype.refresh=function(){var t,e=this.element===this.element.window,i=this.adapter.offset(),o=e?r.viewportHeight():this.adapter.height(),n={};this.handleScroll(),t={horizontal:{contextOffset:e?0:i.left,contextScroll:e?0:this.oldScroll.x,contextDimension:this.adapter.width(),oldScroll:this.oldScroll.x,forward:"right",backward:"left",offsetProp:"left"},vertical:{contextOffset:e?0:i.top,contextScroll:e?0:this.oldScroll.y,contextDimension:o,oldScroll:this.oldScroll.y,forward:"down",backward:"up",offsetProp:"top"}};for(var s in t){var a=t[s];for(var l in this.waypoints[s]){var h,p=this.waypoints[s][l],c=p.options.offset,u=p.triggerPoint,d=0,f=null==u;p.element!==p.element.window&&(d=p.adapter.offset()[a.offsetProp]),"function"==typeof c?c=c.apply(p):"string"==typeof c&&(c=parseFloat(c),p.options.offset.indexOf("%")>-1&&(c=Math.ceil(a.contextDimension*c/100))),h=a.contextScroll-a.contextOffset,p.triggerPoint=d+h-c;var y=u=a.oldScroll,w=y&&g,v=!y&&!g;!f&&w?(p.queueTrigger(a.backward),n[p.group.id]=p.group):!f&&v?(p.queueTrigger(a.forward),n[p.group.id]=p.group):f&&a.oldScroll>=p.triggerPoint&&(p.queueTrigger(a.forward),n[p.group.id]=p.group)}}for(var m in n)n[m].flushTriggers();return this},e.prototype.destroy=function(){var t=[];for(var e in this.waypoints)for(var i in this.waypoints[e])t.push(this.waypoints[e][i]);for(var o=0,r=t.length;r>o;o++)t[o].destroy()},e.prototype.add=function(t){var e=t.options.horizontal?"horizontal":"vertical";this.waypoints[e][t.key]=t,this.refresh()},e.prototype.remove=function(t){delete this.waypoints[t.axis][t.key],this.checkEmpty()},e.prototype.checkEmpty=function(){var t=this.Adapter.isEmptyObject(this.waypoints.horizontal),e=this.Adapter.isEmptyObject(this.waypoints.vertical);t&&e&&(this.adapter.off(".waypoints"),delete o[this.key])},e.prototype.height=function(){return this.element===this.element.window?r.viewportHeight():this.adapter.height()},e.refreshAll=function(){for(var t in o)o[t].refresh()},e.findByElement=function(t){return o[t.waypointContextKey]},e.findOrCreateByElement=function(t){return e.findByElement(t)||new e(t)},r.Context=e}())(function(){"use strict";function t(t,e){return t.triggerPoint-e.triggerPoint}function e(t,e){return e.triggerPoint-t.triggerPoint}function i(t){this.name=t.name,this.axis=t.axis,this.id=this.name+"-"+this.axis,this.waypoints=[],this.clearTriggerQueues(),o[this.axis][this.name]=this}var o={vertical:{},horizontal:{}},r=window.Waypoint;i.prototype.previous=function(t){this.sort();var e=r.Adapter.inArray(t,this.waypoints);return e?this.waypoints[e-1]:null},i.prototype.next=function(t){this.sort();var e=r.Adapter.inArray(t,this.waypoints),i=e===this.waypoints.length-1;return i?null:this.waypoints[e+1]},i.prototype.first=function(){return this.waypoints[0]},i.prototype.last=function(){return this.waypoints[this.waypoints.length-1]},i.prototype.add=function(t){this.waypoints.push(t)},i.prototype.remove=function(t){var e=r.Adapter.inArray(t,this.waypoints);e>-1&&this.waypoints.splice(e,1)},i.prototype.sort=function(){this.waypoints.sort(function(t,e){return t.triggerPoint-e.triggerPoint})},i.prototype.clearTriggerQueues=function(){this.triggerQueues={up:[],down:[],left:[],right:[]}},i.prototype.queueTrigger=function(t,e){this.triggerQueues[e].push(t)},i.prototype.flushTriggers=function(){for(var i in this.triggerQueues){var o=this.triggerQueues[i],r="up"===i||"left"===i;o.sort(r?e:t);for(var n=0,s=o.length;s>n;n+=1){var a=o[n];(a.options.continuous||n===o.length-1)&&a.trigger([i])}}this.clearTriggerQueues()},i.findOrCreate=function(t){return o[t.axis][t.name]||new i(t)},r.Group=i}())(function(){"use strict";function t(t){this.$element=e(t)}var e=window.jQuery,i=window.Waypoint;e.each(["height","off","offset","on","outerHeight","outerWidth","scrollLeft","scrollTop","width"],function(e,i){t.prototype[i]=function(){var t=Array.prototype.slice.call(arguments);return this.$element[i].apply(this.$element,t)}}),e.each(["extend","inArray","isEmptyObject"],function(i,o){t[o]=e[o]}),i.adapters.push({name:"jquery",Adapter:t}),i.Adapter=t}()); \ No newline at end of file diff --git a/lib/noframework.waypoints.js b/lib/noframework.waypoints.js new file mode 100644 index 00000000..2e6fd7a3 --- /dev/null +++ b/lib/noframework.waypoints.js @@ -0,0 +1,667 @@ +/*! +Waypoints - 2.0.5 +Copyright © 2011-2014 Caleb Troughton +Licensed under the MIT license. +https://github.com/imakewebthings/waypoints/blog/master/licenses.txt +*/ +(function() { + 'use strict' + + var keyCounter = 0 + var allWaypoints = {} + + function Waypoint(options) { + if (!options) { + throw new Error('No options passed to Waypoint constructor') + } + if (!options.element) { + throw new Error('No element option passed to Waypoint constructor') + } + + this.key = 'waypoint-' + keyCounter + this.options = Waypoint.Adapter.extend({}, Waypoint.defaults, options) + this.element = this.options.element + this.adapter = new Waypoint.Adapter(this.element) + this.callback = options.handler + this.axis = this.options.horizontal ? 'horizontal' : 'vertical' + this.enabled = this.options.enabled + this.triggerPoint = null + this.group = Waypoint.Group.findOrCreate({ + name: this.options.group, + axis: this.axis + }) + this.context = Waypoint.Context.findOrCreateByElement(this.options.context) + + if (Waypoint.offsetAliases[this.options.offset]) { + this.options.offset = Waypoint.offsetAliases[this.options.offset] + } + this.context.add(this) + this.group.add(this) + allWaypoints[this.key] = this + keyCounter += 1 + } + + Waypoint.prototype.disable = function() { + this.enabled = false + return this + } + + Waypoint.prototype.enable = function() { + this.context.refresh() + this.enabled = true + return this + } + + Waypoint.prototype.destroy = function() { + this.context.remove(this) + this.group.remove(this) + delete allWaypoints[this.key] + } + + /* Internal */ + Waypoint.prototype.trigger = function(args) { + if (!this.enabled) { + return + } + if (this.callback) { + this.callback.apply(this, args) + } + if (this.options.triggerOnce) { + this.destroy() + } + } + + /* Internal */ + Waypoint.prototype.queueTrigger = function(direction) { + this.group.queueTrigger(this, direction) + } + + Waypoint.adapters = [] + + Waypoint.defaults = { + context: window, + continuous: true, + enabled: true, + group: 'default', + horizontal: false, + offset: 0, + triggerOnce: false + } + + Waypoint.offsetAliases = { + 'bottom-in-view': function() { + return this.context.height() - this.adapter.outerHeight() + }, + 'right-in-view': function() { + return this.context.adapter.width() - this.adapter.outerWidth() + } + } + + Waypoint.viewportHeight = function() { + return window.innerHeight || document.documentElement.clientHeight + } + + Waypoint.refresh = function() { + Waypoint.Context.refreshAll() + } + + Waypoint.destroyAll = function() { + var allWaypointsArray = [] + for (var waypointKey in allWaypoints) { + allWaypointsArray.push(allWaypoints[waypointKey]) + } + for (var i = 0, end = allWaypointsArray.length; i < end; i++) { + allWaypointsArray[i].destroy() + } + } + + window.Waypoint = Waypoint +}()) + +(function() { + 'use strict' + + function requestAnimationFrameShim(callback) { + window.setTimeout(callback, 1000 / 60) + } + + var keyCounter = 0 + var contexts = {} + var Waypoint = window.Waypoint + + var requestAnimationFrame = window.requestAnimationFrame || + window.mozRequestAnimationFrame || + window.webkitRequestAnimationFrame || + requestAnimationFrameShim + + function Context(element) { + this.element = element + this.Adapter = Waypoint.Adapter + this.adapter = new this.Adapter(element) + this.key = 'waypoint-context-' + keyCounter + this.didScroll = false + this.didResize = false + this.oldScroll = { + x: this.adapter.scrollLeft(), + y: this.adapter.scrollTop() + } + this.waypoints = { + vertical: {}, + horizontal: {} + } + + element.waypointContextKey = this.key + contexts[element.waypointContextKey] = this + keyCounter += 1 + + this.createThrottledScrollHandler() + this.createThrottledResizeHandler() + } + + /* Internal */ + Context.prototype.createThrottledScrollHandler = function() { + var self = this + function scrollHandler() { + self.handleScroll() + self.didScroll = false + } + + this.adapter.on('scroll.waypoints', function() { + if (!self.didScroll || Waypoint.isTouch) { + self.didScroll = true + requestAnimationFrame(scrollHandler) + } + }) + } + + /* Internal */ + Context.prototype.createThrottledResizeHandler = function() { + var self = this + + function resizeHandler() { + self.handleResize() + self.didResize = false + } + + this.adapter.on('resize.waypoints', function() { + if (!self.didResize) { + self.didResize = true + requestAnimationFrame(resizeHandler) + } + }) + } + + /* Internal */ + Context.prototype.handleScroll = function() { + var triggeredGroups = {} + var axes = { + horizontal: { + newScroll: this.adapter.scrollLeft(), + oldScroll: this.oldScroll.x, + forward: 'right', + backward: 'left' + }, + vertical: { + newScroll: this.adapter.scrollTop(), + oldScroll: this.oldScroll.y, + forward: 'down', + backward: 'up' + } + } + + for (var axisKey in axes) { + var axis = axes[axisKey] + var isForward = axis.newScroll > axis.oldScroll + var direction = isForward ? axis.forward : axis.backward + + for (var waypointKey in this.waypoints[axisKey]) { + var waypoint = this.waypoints[axisKey][waypointKey] + var wasBeforeTriggerPoint = axis.oldScroll < waypoint.triggerPoint + var nowAfterTriggerPoint = axis.newScroll >= waypoint.triggerPoint + var crossedForward = wasBeforeTriggerPoint && nowAfterTriggerPoint + var crossedBackward = !wasBeforeTriggerPoint && !nowAfterTriggerPoint + if (crossedForward || crossedBackward) { + waypoint.queueTrigger(direction) + triggeredGroups[waypoint.group.id] = waypoint.group + } + } + } + + for (var groupKey in triggeredGroups) { + triggeredGroups[groupKey].flushTriggers() + } + + this.oldScroll = { + x: axes.horizontal.newScroll, + y: axes.vertical.newScroll + } + } + + /* Internal */ + Context.prototype.handleResize = function() { + Waypoint.Context.refreshAll() + } + + Context.prototype.refresh = function() { + var isWindow = this.element === this.element.window + var contextOffset = this.adapter.offset() + var height = isWindow ? Waypoint.viewportHeight() : this.adapter.height() + var triggeredGroups = {} + var axes + + this.handleScroll() + axes = { + horizontal: { + contextOffset: isWindow ? 0 : contextOffset.left, + contextScroll: isWindow ? 0 : this.oldScroll.x, + contextDimension: this.adapter.width(), + oldScroll: this.oldScroll.x, + forward: 'right', + backward: 'left', + offsetProp: 'left' + }, + vertical: { + contextOffset: isWindow ? 0 : contextOffset.top, + contextScroll: isWindow ? 0 : this.oldScroll.y, + contextDimension: height, + oldScroll: this.oldScroll.y, + forward: 'down', + backward: 'up', + offsetProp: 'top' + } + } + + for (var axisKey in axes) { + var axis = axes[axisKey] + for (var waypointKey in this.waypoints[axisKey]) { + var waypoint = this.waypoints[axisKey][waypointKey] + var adjustment = waypoint.options.offset + var oldTriggerPoint = waypoint.triggerPoint + var elementOffset = 0 + var freshWaypoint = oldTriggerPoint == null + var contextModifier + + if (waypoint.element !== waypoint.element.window) { + elementOffset = waypoint.adapter.offset()[axis.offsetProp] + } + + if (typeof adjustment === 'function') { + adjustment = adjustment.apply(waypoint) + } + else if (typeof adjustment === 'string') { + adjustment = parseFloat(adjustment) + if (waypoint.options.offset.indexOf('%') > - 1) { + adjustment = Math.ceil(axis.contextDimension * adjustment / 100) + } + } + + contextModifier = axis.contextScroll - axis.contextOffset + waypoint.triggerPoint = elementOffset + contextModifier - adjustment + + var wasBeforeScroll = oldTriggerPoint < axis.oldScroll + var nowAfterScroll = waypoint.triggerPoint >= axis.oldScroll + var triggeredBackward = wasBeforeScroll && nowAfterScroll + var triggeredForward = !wasBeforeScroll && !nowAfterScroll + if (!freshWaypoint && triggeredBackward) { + waypoint.queueTrigger(axis.backward) + triggeredGroups[waypoint.group.id] = waypoint.group + } + else if (!freshWaypoint && triggeredForward) { + waypoint.queueTrigger(axis.forward) + triggeredGroups[waypoint.group.id] = waypoint.group + } + else if (freshWaypoint && axis.oldScroll >= waypoint.triggerPoint) { + waypoint.queueTrigger(axis.forward) + triggeredGroups[waypoint.group.id] = waypoint.group + } + } + } + + for (var groupKey in triggeredGroups) { + triggeredGroups[groupKey].flushTriggers() + } + + return this + } + + Context.prototype.destroy = function() { + var allWaypoints = [] + for (var axis in this.waypoints) { + for (var waypointKey in this.waypoints[axis]) { + allWaypoints.push(this.waypoints[axis][waypointKey]) + } + } + for (var i = 0, end = allWaypoints.length; i < end; i++) { + allWaypoints[i].destroy() + } + } + + /* Internal */ + Context.prototype.add = function(waypoint) { + var axis = waypoint.options.horizontal ? 'horizontal' : 'vertical' + this.waypoints[axis][waypoint.key] = waypoint + this.refresh() + } + + /* Internal */ + Context.prototype.remove = function(waypoint) { + delete this.waypoints[waypoint.axis][waypoint.key] + this.checkEmpty() + } + + /* Internal */ + Context.prototype.checkEmpty = function() { + var horizontalEmpty = this.Adapter.isEmptyObject(this.waypoints.horizontal) + var verticalEmpty = this.Adapter.isEmptyObject(this.waypoints.vertical) + if (horizontalEmpty && verticalEmpty) { + this.adapter.off('.waypoints') + delete contexts[this.key] + } + } + + /* Internal */ + Context.prototype.height = function() { + if (this.element === this.element.window) { + return Waypoint.viewportHeight() + } + return this.adapter.height() + } + + Context.refreshAll = function() { + for (var contextId in contexts) { + contexts[contextId].refresh() + } + } + + /* Internal */ + Context.findByElement = function(element) { + return contexts[element.waypointContextKey] + } + + /* Internal */ + Context.findOrCreateByElement = function(element) { + return Context.findByElement(element) || new Context(element) + } + + Waypoint.Context = Context +}()) + +(function() { + 'use strict' + + var groups = { + vertical: {}, + horizontal: {} + } + var Waypoint = window.Waypoint + + function byTriggerPoint(a, b) { + return a.triggerPoint - b.triggerPoint + } + + function byReverseTriggerPoint(a, b) { + return b.triggerPoint - a.triggerPoint + } + + function Group(options) { + this.name = options.name + this.axis = options.axis + this.id = this.name + '-' + this.axis + this.waypoints = [] + this.clearTriggerQueues() + groups[this.axis][this.name] = this + } + + Group.prototype.previous = function(waypoint) { + this.sort() + var index = Waypoint.Adapter.inArray(waypoint, this.waypoints) + return index ? this.waypoints[index - 1] : null + } + + Group.prototype.next = function(waypoint) { + this.sort() + var index = Waypoint.Adapter.inArray(waypoint, this.waypoints) + var isLast = index === this.waypoints.length - 1 + return isLast ? null : this.waypoints[index + 1] + } + + Group.prototype.first = function() { + return this.waypoints[0] + } + + Group.prototype.last = function() { + return this.waypoints[this.waypoints.length - 1] + } + + /* Internal */ + Group.prototype.add = function(waypoint) { + this.waypoints.push(waypoint) + } + + /* Internal */ + Group.prototype.remove = function(waypoint) { + var index = Waypoint.Adapter.inArray(waypoint, this.waypoints) + if (index > -1) { + this.waypoints.splice(index, 1) + } + } + + /* Internal */ + Group.prototype.sort = function() { + this.waypoints.sort(function(a, b) { + return a.triggerPoint - b.triggerPoint + }) + } + + /* Internal */ + Group.prototype.clearTriggerQueues = function() { + this.triggerQueues = { + up: [], + down: [], + left: [], + right: [] + } + } + + /* Internal */ + Group.prototype.queueTrigger = function(waypoint, direction) { + this.triggerQueues[direction].push(waypoint) + } + + /* Internal */ + Group.prototype.flushTriggers = function() { + for (var direction in this.triggerQueues) { + var waypoints = this.triggerQueues[direction] + var reverse = direction === 'up' || direction === 'left' + waypoints.sort(reverse ? byReverseTriggerPoint : byTriggerPoint) + for (var i = 0, end = waypoints.length; i < end; i += 1) { + var waypoint = waypoints[i] + if (waypoint.options.continuous || i === waypoints.length - 1) { + waypoint.trigger([direction]) + } + } + } + this.clearTriggerQueues() + } + + /* Internal */ + Group.findOrCreate = function(options) { + return groups[options.axis][options.name] || new Group(options) + } + + Waypoint.Group = Group +}()) + +(function() { + 'use strict' + + var Waypoint = window.Waypoint + + function isWindow(element) { + return element === element.window + } + + function getWindow(element) { + if (isWindow(element)) { + return element + } + return element.defaultView + } + + function NoFrameworkAdapter(element) { + this.element = element + this.handlers = {} + } + + NoFrameworkAdapter.prototype.height = function() { + var isWin = isWindow(this.element) + return isWin ? this.element.innerHeight : this.element.offsetHeight + } + + NoFrameworkAdapter.prototype.off = function(event, handler) { + function removeListeners(element, listeners, handler) { + for (var i = 0, end = listeners.length - 1; i < end; i++) { + var listener = listeners[i] + if (!handler || handler === listener) { + element.removeEventListener(listener) + } + } + } + + var eventParts = event.split('.') + var eventType = eventParts[0] + var namespace = eventParts[1] + var element = this.element + + if (namespace && this.handlers[namespace] && eventType) { + removeListeners(element, this.handlers[namespace][eventType], handler) + this.handlers[namespace][eventType] = [] + } + else if (eventType) { + for (var ns in this.handlers) { + removeListeners(element, this.handlers[ns][eventType] || [], handler) + this.handlers[ns][eventType] = [] + } + } + else if (namespace && this.handlers[namespace]) { + for (var type in this.handlers[namespace]) { + removeListeners(element, this.handlers[namespace][type], handler) + } + this.handlers[namespace] = {} + } + } + + /* Adapted from jQuery 1.x offset() */ + NoFrameworkAdapter.prototype.offset = function() { + if (!this.element.ownerDocument) { + return null + } + + var documentElement = this.element.ownerDocument.documentElement + var win = getWindow(this.element.ownerDocument) + var rect = { + top: 0, + left: 0 + } + + if (this.element.getBoundingClientRect) { + rect = this.element.getBoundingClientRect() + } + + return { + top: rect.top + win.pageYOffset - documentElement.clientTop, + left: rect.left + win.pageXOffset - documentElement.clientLeft + } + } + + NoFrameworkAdapter.prototype.on = function(event, handler) { + var eventParts = event.split('.') + var eventType = eventParts[0] + var namespace = eventParts[1] || '__default' + var nsHandlers = this.handlers[namespace] = this.handlers[namespace] || {} + var nsTypeList = nsHandlers[eventType] = nsHandlers[eventType] || [] + + nsTypeList.push(handler) + this.element.addEventListener(eventType, handler) + } + + NoFrameworkAdapter.prototype.outerHeight = function(includeMargin) { + var height = this.height() + var computedStyle + + if (includeMargin && !isWindow(this.element)) { + computedStyle = window.getComputedStyle(this.element) + height += parseInt(computedStyle.marginTop, 10) + height += parseInt(computedStyle.marginBottom, 10) + } + + return height + } + + NoFrameworkAdapter.prototype.outerWidth = function(includeMargin) { + var width = this.width() + var computedStyle + + if (includeMargin && !isWindow(this.element)) { + computedStyle = window.getComputedStyle(this.element) + width += parseInt(computedStyle.marginLeft, 10) + width += parseInt(computedStyle.marginRight, 10) + } + + return width + } + + NoFrameworkAdapter.prototype.scrollLeft = function() { + var win = getWindow(this.element) + return win ? win.pageXOffset : this.element.scrollLeft + } + + NoFrameworkAdapter.prototype.scrollTop = function() { + var win = getWindow(this.element) + return win ? win.pageYOffset : this.element.scrollTop + } + + NoFrameworkAdapter.prototype.width = function() { + var isWin = isWindow(this.element) + return isWin ? this.element.innerWidth : this.element.offsetWidth + } + + NoFrameworkAdapter.extend = function() { + var args = Array.prototype.slice.call(arguments) + + function merge(target, obj) { + if (typeof target === 'object' && typeof obj === 'object') { + for (var key in obj) { + if (obj.hasOwnProperty(key)) { + target[key] = obj[key] + } + } + } + + return target + } + + for (var i = 1, end = args.length; i < end; i++) { + merge(args[0], args[i]) + } + return args[0] + } + + NoFrameworkAdapter.inArray = function(element, array, i) { + return array == null ? -1 : array.indexOf(element, i) + } + + NoFrameworkAdapter.isEmptyObject = function(obj) { + /* eslint no-unused-vars: 0 */ + for (var name in obj) { + return false + } + return true + } + + Waypoint.adapters.push({ + name: 'noframework', + Adapter: NoFrameworkAdapter + }) + Waypoint.Adapter = NoFrameworkAdapter +}()) diff --git a/lib/noframework.waypoints.min.js b/lib/noframework.waypoints.min.js new file mode 100644 index 00000000..3b999e76 --- /dev/null +++ b/lib/noframework.waypoints.min.js @@ -0,0 +1,7 @@ +/*! +Waypoints - 2.0.5 +Copyright © 2011-2014 Caleb Troughton +Licensed under the MIT license. +https://github.com/imakewebthings/waypoints/blog/master/licenses.txt +*/ +!function(){"use strict";function t(r){if(!r)throw new Error("No options passed to Waypoint constructor");if(!r.element)throw new Error("No element option passed to Waypoint constructor");this.key="waypoint-"+e,this.options=t.Adapter.extend({},t.defaults,r),this.element=this.options.element,this.adapter=new t.Adapter(this.element),this.callback=r.handler,this.axis=this.options.horizontal?"horizontal":"vertical",this.enabled=this.options.enabled,this.triggerPoint=null,this.group=t.Group.findOrCreate({name:this.options.group,axis:this.axis}),this.context=t.Context.findOrCreateByElement(this.options.context),t.offsetAliases[this.options.offset]&&(this.options.offset=t.offsetAliases[this.options.offset]),this.context.add(this),this.group.add(this),i[this.key]=this,e+=1}var e=0,i={};t.prototype.disable=function(){return this.enabled=!1,this},t.prototype.enable=function(){return this.context.refresh(),this.enabled=!0,this},t.prototype.destroy=function(){this.context.remove(this),this.group.remove(this),delete i[this.key]},t.prototype.trigger=function(t){this.enabled&&(this.callback&&this.callback.apply(this,t),this.options.triggerOnce&&this.destroy())},t.prototype.queueTrigger=function(t){this.group.queueTrigger(this,t)},t.adapters=[],t.defaults={context:window,continuous:!0,enabled:!0,group:"default",horizontal:!1,offset:0,triggerOnce:!1},t.offsetAliases={"bottom-in-view":function(){return this.context.height()-this.adapter.outerHeight()},"right-in-view":function(){return this.context.adapter.width()-this.adapter.outerWidth()}},t.viewportHeight=function(){return window.innerHeight||document.documentElement.clientHeight},t.refresh=function(){t.Context.refreshAll()},t.destroyAll=function(){var t=[];for(var e in i)t.push(i[e]);for(var r=0,o=t.length;o>r;r++)t[r].destroy()},window.Waypoint=t}()(function(){"use strict";function t(t){window.setTimeout(t,1e3/60)}function e(t){this.element=t,this.Adapter=o.Adapter,this.adapter=new this.Adapter(t),this.key="waypoint-context-"+i,this.didScroll=!1,this.didResize=!1,this.oldScroll={x:this.adapter.scrollLeft(),y:this.adapter.scrollTop()},this.waypoints={vertical:{},horizontal:{}},t.waypointContextKey=this.key,r[t.waypointContextKey]=this,i+=1,this.createThrottledScrollHandler(),this.createThrottledResizeHandler()}var i=0,r={},o=window.Waypoint,n=window.requestAnimationFrame||window.mozRequestAnimationFrame||window.webkitRequestAnimationFrame||t;e.prototype.createThrottledScrollHandler=function(){function t(){e.handleScroll(),e.didScroll=!1}var e=this;this.adapter.on("scroll.waypoints",function(){(!e.didScroll||o.isTouch)&&(e.didScroll=!0,n(t))})},e.prototype.createThrottledResizeHandler=function(){function t(){e.handleResize(),e.didResize=!1}var e=this;this.adapter.on("resize.waypoints",function(){e.didResize||(e.didResize=!0,n(t))})},e.prototype.handleScroll=function(){var t={},e={horizontal:{newScroll:this.adapter.scrollLeft(),oldScroll:this.oldScroll.x,forward:"right",backward:"left"},vertical:{newScroll:this.adapter.scrollTop(),oldScroll:this.oldScroll.y,forward:"down",backward:"up"}};for(var i in e){var r=e[i],o=r.newScroll>r.oldScroll,n=o?r.forward:r.backward;for(var s in this.waypoints[i]){var a=this.waypoints[i][s],l=r.oldScroll=a.triggerPoint,p=l&&h,f=!l&&!h;(p||f)&&(a.queueTrigger(n),t[a.group.id]=a.group)}}for(var u in t)t[u].flushTriggers();this.oldScroll={x:e.horizontal.newScroll,y:e.vertical.newScroll}},e.prototype.handleResize=function(){o.Context.refreshAll()},e.prototype.refresh=function(){var t,e=this.element===this.element.window,i=this.adapter.offset(),r=e?o.viewportHeight():this.adapter.height(),n={};this.handleScroll(),t={horizontal:{contextOffset:e?0:i.left,contextScroll:e?0:this.oldScroll.x,contextDimension:this.adapter.width(),oldScroll:this.oldScroll.x,forward:"right",backward:"left",offsetProp:"left"},vertical:{contextOffset:e?0:i.top,contextScroll:e?0:this.oldScroll.y,contextDimension:r,oldScroll:this.oldScroll.y,forward:"down",backward:"up",offsetProp:"top"}};for(var s in t){var a=t[s];for(var l in this.waypoints[s]){var h,p=this.waypoints[s][l],f=p.options.offset,u=p.triggerPoint,c=0,d=null==u;p.element!==p.element.window&&(c=p.adapter.offset()[a.offsetProp]),"function"==typeof f?f=f.apply(p):"string"==typeof f&&(f=parseFloat(f),p.options.offset.indexOf("%")>-1&&(f=Math.ceil(a.contextDimension*f/100))),h=a.contextScroll-a.contextOffset,p.triggerPoint=c+h-f;var g=u=a.oldScroll,w=g&&y,m=!g&&!y;!d&&w?(p.queueTrigger(a.backward),n[p.group.id]=p.group):!d&&m?(p.queueTrigger(a.forward),n[p.group.id]=p.group):d&&a.oldScroll>=p.triggerPoint&&(p.queueTrigger(a.forward),n[p.group.id]=p.group)}}for(var v in n)n[v].flushTriggers();return this},e.prototype.destroy=function(){var t=[];for(var e in this.waypoints)for(var i in this.waypoints[e])t.push(this.waypoints[e][i]);for(var r=0,o=t.length;o>r;r++)t[r].destroy()},e.prototype.add=function(t){var e=t.options.horizontal?"horizontal":"vertical";this.waypoints[e][t.key]=t,this.refresh()},e.prototype.remove=function(t){delete this.waypoints[t.axis][t.key],this.checkEmpty()},e.prototype.checkEmpty=function(){var t=this.Adapter.isEmptyObject(this.waypoints.horizontal),e=this.Adapter.isEmptyObject(this.waypoints.vertical);t&&e&&(this.adapter.off(".waypoints"),delete r[this.key])},e.prototype.height=function(){return this.element===this.element.window?o.viewportHeight():this.adapter.height()},e.refreshAll=function(){for(var t in r)r[t].refresh()},e.findByElement=function(t){return r[t.waypointContextKey]},e.findOrCreateByElement=function(t){return e.findByElement(t)||new e(t)},o.Context=e}())(function(){"use strict";function t(t,e){return t.triggerPoint-e.triggerPoint}function e(t,e){return e.triggerPoint-t.triggerPoint}function i(t){this.name=t.name,this.axis=t.axis,this.id=this.name+"-"+this.axis,this.waypoints=[],this.clearTriggerQueues(),r[this.axis][this.name]=this}var r={vertical:{},horizontal:{}},o=window.Waypoint;i.prototype.previous=function(t){this.sort();var e=o.Adapter.inArray(t,this.waypoints);return e?this.waypoints[e-1]:null},i.prototype.next=function(t){this.sort();var e=o.Adapter.inArray(t,this.waypoints),i=e===this.waypoints.length-1;return i?null:this.waypoints[e+1]},i.prototype.first=function(){return this.waypoints[0]},i.prototype.last=function(){return this.waypoints[this.waypoints.length-1]},i.prototype.add=function(t){this.waypoints.push(t)},i.prototype.remove=function(t){var e=o.Adapter.inArray(t,this.waypoints);e>-1&&this.waypoints.splice(e,1)},i.prototype.sort=function(){this.waypoints.sort(function(t,e){return t.triggerPoint-e.triggerPoint})},i.prototype.clearTriggerQueues=function(){this.triggerQueues={up:[],down:[],left:[],right:[]}},i.prototype.queueTrigger=function(t,e){this.triggerQueues[e].push(t)},i.prototype.flushTriggers=function(){for(var i in this.triggerQueues){var r=this.triggerQueues[i],o="up"===i||"left"===i;r.sort(o?e:t);for(var n=0,s=r.length;s>n;n+=1){var a=r[n];(a.options.continuous||n===r.length-1)&&a.trigger([i])}}this.clearTriggerQueues()},i.findOrCreate=function(t){return r[t.axis][t.name]||new i(t)},o.Group=i}())(function(){"use strict";function t(t){return t===t.window}function e(e){return t(e)?e:e.defaultView}function i(t){this.element=t,this.handlers={}}var r=window.Waypoint;i.prototype.height=function(){var e=t(this.element);return e?this.element.innerHeight:this.element.offsetHeight},i.prototype.off=function(t,e){function i(t,e,i){for(var r=0,o=e.length-1;o>r;r++){var n=e[r];i&&i!==n||t.removeEventListener(n)}}var r=t.split("."),o=r[0],n=r[1],s=this.element;if(n&&this.handlers[n]&&o)i(s,this.handlers[n][o],e),this.handlers[n][o]=[];else if(o)for(var a in this.handlers)i(s,this.handlers[a][o]||[],e),this.handlers[a][o]=[];else if(n&&this.handlers[n]){for(var l in this.handlers[n])i(s,this.handlers[n][l],e);this.handlers[n]={}}},i.prototype.offset=function(){if(!this.element.ownerDocument)return null;var t=this.element.ownerDocument.documentElement,i=e(this.element.ownerDocument),r={top:0,left:0};return this.element.getBoundingClientRect&&(r=this.element.getBoundingClientRect()),{top:r.top+i.pageYOffset-t.clientTop,left:r.left+i.pageXOffset-t.clientLeft}},i.prototype.on=function(t,e){var i=t.split("."),r=i[0],o=i[1]||"__default",n=this.handlers[o]=this.handlers[o]||{},s=n[r]=n[r]||[];s.push(e),this.element.addEventListener(r,e)},i.prototype.outerHeight=function(e){var i,r=this.height();return e&&!t(this.element)&&(i=window.getComputedStyle(this.element),r+=parseInt(i.marginTop,10),r+=parseInt(i.marginBottom,10)),r},i.prototype.outerWidth=function(e){var i,r=this.width();return e&&!t(this.element)&&(i=window.getComputedStyle(this.element),r+=parseInt(i.marginLeft,10),r+=parseInt(i.marginRight,10)),r},i.prototype.scrollLeft=function(){var t=e(this.element);return t?t.pageXOffset:this.element.scrollLeft},i.prototype.scrollTop=function(){var t=e(this.element);return t?t.pageYOffset:this.element.scrollTop},i.prototype.width=function(){var e=t(this.element);return e?this.element.innerWidth:this.element.offsetWidth},i.extend=function(){function t(t,e){if("object"==typeof t&&"object"==typeof e)for(var i in e)e.hasOwnProperty(i)&&(t[i]=e[i]);return t}for(var e=Array.prototype.slice.call(arguments),i=1,r=e.length;r>i;i++)t(e[0],e[i]);return e[0]},i.inArray=function(t,e,i){return null==e?-1:e.indexOf(t,i)},i.isEmptyObject=function(t){for(var e in t)return!1;return!0},r.adapters.push({name:"noframework",Adapter:i}),r.Adapter=i}()); \ No newline at end of file diff --git a/lib/shortcuts/infinite.js b/lib/shortcuts/infinite.js new file mode 100644 index 00000000..db5da9cc --- /dev/null +++ b/lib/shortcuts/infinite.js @@ -0,0 +1,78 @@ +/*! +Waypoints Infinite Scroll Shortcut - 2.0.5 +Copyright © 2011-2014 Caleb Troughton +Licensed under the MIT license. +https://github.com/imakewebthings/waypoints/blog/master/licenses.txt +*/ +(function() { + 'use strict' + + var $ = window.jQuery + var Waypoint = window.Waypoint + + function Infinite(options) { + this.options = $.extend({}, Infinite.defaults, options) + this.container = this.options.element + if (this.options.container !== 'auto') { + this.container = this.options.container + } + this.$container = $(this.container) + this.$more = $(this.options.more) + this.more = this.$more[0] + + if (this.more) { + this.setupHandler() + this.waypoint = new Waypoint(this.options) + } + } + + Infinite.prototype.destroy = function() { + if (this.waypoint) { + this.waypoint.destroy() + } + } + + /* Internal */ + Infinite.prototype.setupHandler = function() { + this.options.handler = $.proxy(function() { + window.setTimeout($.proxy(function() { + this.options.onBeforePageLoad() + this.destroy() + this.$container.addClass(this.options.loadingClass) + + $.get($(this.options.more).attr('href'), $.proxy(function(data) { + var $data = $($.parseHTML(data)) + var $newMore = $data.find(this.options.more) + + this.$container.append($data.find(this.options.items)) + this.$container.removeClass(this.options.loadingClass) + + if (!$newMore.length) { + $newMore = $data.filter(this.options.more) + } + if ($newMore.length) { + this.$more.replaceWith($newMore) + this.waypoint = new Waypoint(this.options) + } + else { + this.$more.remove() + } + + this.options.onAfterPageLoad() + }, this), 0) + }, this)) + }, this) + } + + Infinite.defaults = { + container: 'auto', + items: '.infinite-item', + more: '.infinite-more-link', + offset: 'bottom-in-view', + loadingClass: 'infinite-loading', + onBeforePageLoad: $.noop, + onAfterPageLoad: $.noop + } + + Waypoint.Infinite = Infinite +}()) diff --git a/lib/shortcuts/infinite.min.js b/lib/shortcuts/infinite.min.js new file mode 100644 index 00000000..708050bf --- /dev/null +++ b/lib/shortcuts/infinite.min.js @@ -0,0 +1,7 @@ +/*! +Waypoints Infinite Scroll Shortcut - 2.0.5 +Copyright © 2011-2014 Caleb Troughton +Licensed under the MIT license. +https://github.com/imakewebthings/waypoints/blog/master/licenses.txt +*/ +!function(){"use strict";function t(n){this.options=i.extend({},t.defaults,n),this.container=this.options.element,"auto"!==this.options.container&&(this.container=this.options.container),this.$container=i(this.container),this.$more=i(this.options.more),this.more=this.$more[0],this.more&&(this.setupHandler(),this.waypoint=new o(this.options))}var i=window.jQuery,o=window.Waypoint;t.prototype.destroy=function(){this.waypoint&&this.waypoint.destroy()},t.prototype.setupHandler=function(){this.options.handler=i.proxy(function(){window.setTimeout(i.proxy(function(){this.options.onBeforePageLoad(),this.destroy(),this.$container.addClass(this.options.loadingClass),i.get(i(this.options.more).attr("href"),i.proxy(function(t){var n=i(i.parseHTML(t)),s=n.find(this.options.more);this.$container.append(n.find(this.options.items)),this.$container.removeClass(this.options.loadingClass),s.length||(s=n.filter(this.options.more)),s.length?(this.$more.replaceWith(s),this.waypoint=new o(this.options)):this.$more.remove(),this.options.onAfterPageLoad()},this),0)},this))},this)},t.defaults={container:"auto",items:".infinite-item",more:".infinite-more-link",offset:"bottom-in-view",loadingClass:"infinite-loading",onBeforePageLoad:i.noop,onAfterPageLoad:i.noop},o.Infinite=t}(); \ No newline at end of file diff --git a/lib/shortcuts/inview.js b/lib/shortcuts/inview.js new file mode 100644 index 00000000..2854f8f4 --- /dev/null +++ b/lib/shortcuts/inview.js @@ -0,0 +1,100 @@ +/*! +Waypoints Inview Shortcut - 2.0.5 +Copyright © 2011-2014 Caleb Troughton +Licensed under the MIT license. +https://github.com/imakewebthings/waypoints/blog/master/licenses.txt +*/ +(function() { + 'use strict' + + var Waypoint = window.Waypoint + + function noop() {} + + function Inview(options) { + this.options = Waypoint.Adapter.extend({}, Inview.defaults, options) + this.axis = this.options.horizontal ? 'horizontal' : 'vertical' + this.waypoints = [] + this.createWaypoints() + } + + Inview.prototype.destroy = function() { + for (var i = 0, end = this.waypoints.length; i < end; i++) { + this.waypoints[i].destroy() + } + this.waypoints = [] + } + + /* Internal */ + Inview.prototype.createWaypoints = function() { + var configs = { + vertical: [{ + down: 'enter', + up: 'exited', + offset: '100%' + }, { + down: 'entered', + up: 'exit', + offset: 'bottom-in-view' + }, { + down: 'exit', + up: 'entered', + offset: 0 + }, { + down: 'exited', + up: 'enter', + offset: function() { + return -this.adapter.outerHeight() + } + }], + horizontal: [{ + right: 'enter', + left: 'exited', + offset: '100%' + }, { + right: 'entered', + left: 'exit', + offset: 'right-in-view' + }, { + right: 'exit', + left: 'entered', + offset: 0 + }, { + right: 'exited', + left: 'enter', + offset: function() { + return -this.adapter.outerWidth() + } + }] + } + + for (var i = 0, end = configs[this.axis].length; i < end; i++) { + var config = configs[this.axis][i] + this.createWaypoint(config) + } + } + + /* Internal */ + Inview.prototype.createWaypoint = function(config) { + var self = this + this.waypoints.push(new Waypoint({ + element: this.options.element, + handler: (function(config) { + return function(direction) { + self.options[config[direction]].call(this, direction) + } + }(config)), + offset: config.offset, + horizontal: this.options.horizontal + })) + } + + Inview.defaults = { + enter: noop, + entered: noop, + exit: noop, + exited: noop + } + + Waypoint.Inview = Inview +}()) diff --git a/lib/shortcuts/inview.min.js b/lib/shortcuts/inview.min.js new file mode 100644 index 00000000..ef84e503 --- /dev/null +++ b/lib/shortcuts/inview.min.js @@ -0,0 +1,7 @@ +/*! +Waypoints Inview Shortcut - 2.0.5 +Copyright © 2011-2014 Caleb Troughton +Licensed under the MIT license. +https://github.com/imakewebthings/waypoints/blog/master/licenses.txt +*/ +!function(){"use strict";function t(){}function e(t){this.options=i.Adapter.extend({},e.defaults,t),this.axis=this.options.horizontal?"horizontal":"vertical",this.waypoints=[],this.createWaypoints()}var i=window.Waypoint;e.prototype.destroy=function(){for(var t=0,e=this.waypoints.length;e>t;t++)this.waypoints[t].destroy();this.waypoints=[]},e.prototype.createWaypoints=function(){for(var t={vertical:[{down:"enter",up:"exited",offset:"100%"},{down:"entered",up:"exit",offset:"bottom-in-view"},{down:"exit",up:"entered",offset:0},{down:"exited",up:"enter",offset:function(){return-this.adapter.outerHeight()}}],horizontal:[{right:"enter",left:"exited",offset:"100%"},{right:"entered",left:"exit",offset:"right-in-view"},{right:"exit",left:"entered",offset:0},{right:"exited",left:"enter",offset:function(){return-this.adapter.outerWidth()}}]},e=0,i=t[this.axis].length;i>e;e++){var o=t[this.axis][e];this.createWaypoint(o)}},e.prototype.createWaypoint=function(t){var e=this;this.waypoints.push(new i({element:this.options.element,handler:function(t){return function(i){e.options[t[i]].call(this,i)}}(t),offset:t.offset,horizontal:this.options.horizontal}))},e.defaults={enter:t,entered:t,exit:t,exited:t},i.Inview=e}(); \ No newline at end of file diff --git a/lib/shortcuts/sticky.js b/lib/shortcuts/sticky.js new file mode 100644 index 00000000..f0142571 --- /dev/null +++ b/lib/shortcuts/sticky.js @@ -0,0 +1,60 @@ +/*! +Waypoints Sticky Element Shortcut - 2.0.5 +Copyright © 2011-2014 Caleb Troughton +Licensed under the MIT license. +https://github.com/imakewebthings/waypoints/blog/master/licenses.txt +*/ +(function() { + 'use strict' + + var $ = window.jQuery + var Waypoint = window.Waypoint + + function Sticky(options) { + this.options = $.extend({}, Waypoint.defaults, Sticky.defaults, options) + this.element = this.options.element + this.$element = $(this.element) + this.createWrapper() + this.createWaypoint() + } + + Sticky.prototype.destroy = function() { + this.waypoint.destroy() + this.$element.removeClass(this.options.stuckClass).unwrap() + } + + /* Internal */ + Sticky.prototype.createWrapper = function() { + this.$element.wrap(this.options.wrapper) + this.$wrapper = this.$element.parent() + this.wrapper = this.$wrapper[0] + } + + /* Internal */ + Sticky.prototype.createWaypoint = function() { + var originalHandler = this.options.handler + + this.waypoint = new Waypoint($.extend({}, this.options, { + element: this.wrapper, + handler: $.proxy(function(direction) { + var shouldBeStuck = this.options.direction.indexOf(direction) > -1 + var wrapperHeight = shouldBeStuck ? this.$element.outerHeight(true) : '' + + this.$element.toggleClass(this.options.stuckClass, shouldBeStuck) + this.$wrapper.height(wrapperHeight) + + if (originalHandler) { + originalHandler.call(this, direction) + } + }, this) + })) + } + + Sticky.defaults = { + wrapper: '
', + stuckClass: 'stuck', + direction: 'down right' + } + + Waypoint.Sticky = Sticky +}()) diff --git a/lib/shortcuts/sticky.min.js b/lib/shortcuts/sticky.min.js new file mode 100644 index 00000000..d9fb0dcc --- /dev/null +++ b/lib/shortcuts/sticky.min.js @@ -0,0 +1,7 @@ +/*! +Waypoints Sticky Element Shortcut - 2.0.5 +Copyright © 2011-2014 Caleb Troughton +Licensed under the MIT license. +https://github.com/imakewebthings/waypoints/blog/master/licenses.txt +*/ +!function(){"use strict";function t(s){this.options=e.extend({},i.defaults,t.defaults,s),this.element=this.options.element,this.$element=e(this.element),this.createWrapper(),this.createWaypoint()}var e=window.jQuery,i=window.Waypoint;t.prototype.destroy=function(){this.waypoint.destroy(),this.$element.removeClass(this.options.stuckClass).unwrap()},t.prototype.createWrapper=function(){this.$element.wrap(this.options.wrapper),this.$wrapper=this.$element.parent(),this.wrapper=this.$wrapper[0]},t.prototype.createWaypoint=function(){var t=this.options.handler;this.waypoint=new i(e.extend({},this.options,{element:this.wrapper,handler:e.proxy(function(e){var i=this.options.direction.indexOf(e)>-1,s=i?this.$element.outerHeight(!0):"";this.$element.toggleClass(this.options.stuckClass,i),this.$wrapper.height(s),t&&t.call(this,e)},this)}))},t.defaults={wrapper:'
',stuckClass:"stuck",direction:"down right"},i.Sticky=t}(); \ No newline at end of file diff --git a/lib/waypoints.js b/lib/waypoints.js deleted file mode 100644 index 4f9a33b2..00000000 --- a/lib/waypoints.js +++ /dev/null @@ -1,517 +0,0 @@ -// Generated by CoffeeScript 1.6.2 -/*! -jQuery Waypoints - v2.0.5 -Copyright (c) 2011-2014 Caleb Troughton -Licensed under the MIT license. -https://github.com/imakewebthings/jquery-waypoints/blob/master/licenses.txt -*/ - - -(function() { - var __indexOf = [].indexOf || function(item) { for (var i = 0, l = this.length; i < l; i++) { if (i in this && this[i] === item) return i; } return -1; }, - __slice = [].slice; - - (function(root, factory) { - if (typeof define === 'function' && define.amd) { - return define('waypoints', ['jquery'], function($) { - return factory($, root); - }); - } else { - return factory(root.jQuery, root); - } - })(window, function($, window) { - var $w, Context, Waypoint, allWaypoints, contextCounter, contextKey, contexts, isTouch, jQMethods, methods, resizeEvent, scrollEvent, waypointCounter, waypointKey, wp, wps; - - $w = $(window); - isTouch = __indexOf.call(window, 'ontouchstart') >= 0; - allWaypoints = { - horizontal: {}, - vertical: {} - }; - contextCounter = 1; - contexts = {}; - contextKey = 'waypoints-context-id'; - resizeEvent = 'resize.waypoints'; - scrollEvent = 'scroll.waypoints'; - waypointCounter = 1; - waypointKey = 'waypoints-waypoint-ids'; - wp = 'waypoint'; - wps = 'waypoints'; - Context = (function() { - function Context($element) { - var _this = this; - - this.$element = $element; - this.element = $element[0]; - this.didResize = false; - this.didScroll = false; - this.id = 'context' + contextCounter++; - this.oldScroll = { - x: $element.scrollLeft(), - y: $element.scrollTop() - }; - this.waypoints = { - horizontal: {}, - vertical: {} - }; - this.element[contextKey] = this.id; - contexts[this.id] = this; - $element.bind(scrollEvent, function() { - var scrollHandler; - - if (!(_this.didScroll || isTouch)) { - _this.didScroll = true; - scrollHandler = function() { - _this.doScroll(); - return _this.didScroll = false; - }; - return window.setTimeout(scrollHandler, $[wps].settings.scrollThrottle); - } - }); - $element.bind(resizeEvent, function() { - var resizeHandler; - - if (!_this.didResize) { - _this.didResize = true; - resizeHandler = function() { - $[wps]('refresh'); - return _this.didResize = false; - }; - return window.setTimeout(resizeHandler, $[wps].settings.resizeThrottle); - } - }); - } - - Context.prototype.doScroll = function() { - var axes, - _this = this; - - axes = { - horizontal: { - newScroll: this.$element.scrollLeft(), - oldScroll: this.oldScroll.x, - forward: 'right', - backward: 'left' - }, - vertical: { - newScroll: this.$element.scrollTop(), - oldScroll: this.oldScroll.y, - forward: 'down', - backward: 'up' - } - }; - if (isTouch && (!axes.vertical.oldScroll || !axes.vertical.newScroll)) { - $[wps]('refresh'); - } - $.each(axes, function(aKey, axis) { - var direction, isForward, triggered; - - triggered = []; - isForward = axis.newScroll > axis.oldScroll; - direction = isForward ? axis.forward : axis.backward; - $.each(_this.waypoints[aKey], function(wKey, waypoint) { - var _ref, _ref1; - - if ((axis.oldScroll < (_ref = waypoint.offset) && _ref <= axis.newScroll)) { - return triggered.push(waypoint); - } else if ((axis.newScroll < (_ref1 = waypoint.offset) && _ref1 <= axis.oldScroll)) { - return triggered.push(waypoint); - } - }); - triggered.sort(function(a, b) { - return a.offset - b.offset; - }); - if (!isForward) { - triggered.reverse(); - } - return $.each(triggered, function(i, waypoint) { - if (waypoint.options.continuous || i === triggered.length - 1) { - return waypoint.trigger([direction]); - } - }); - }); - return this.oldScroll = { - x: axes.horizontal.newScroll, - y: axes.vertical.newScroll - }; - }; - - Context.prototype.refresh = function() { - var axes, cOffset, isWin, - _this = this; - - isWin = $.isWindow(this.element); - cOffset = this.$element.offset(); - this.doScroll(); - axes = { - horizontal: { - contextOffset: isWin ? 0 : cOffset.left, - contextScroll: isWin ? 0 : this.oldScroll.x, - contextDimension: this.$element.width(), - oldScroll: this.oldScroll.x, - forward: 'right', - backward: 'left', - offsetProp: 'left' - }, - vertical: { - contextOffset: isWin ? 0 : cOffset.top, - contextScroll: isWin ? 0 : this.oldScroll.y, - contextDimension: isWin ? $[wps]('viewportHeight') : this.$element.height(), - oldScroll: this.oldScroll.y, - forward: 'down', - backward: 'up', - offsetProp: 'top' - } - }; - return $.each(axes, function(aKey, axis) { - return $.each(_this.waypoints[aKey], function(i, waypoint) { - var adjustment, elementOffset, oldOffset, _ref, _ref1; - - adjustment = waypoint.options.offset; - oldOffset = waypoint.offset; - elementOffset = $.isWindow(waypoint.element) ? 0 : waypoint.$element.offset()[axis.offsetProp]; - if ($.isFunction(adjustment)) { - adjustment = adjustment.apply(waypoint.element); - } else if (typeof adjustment === 'string') { - adjustment = parseFloat(adjustment); - if (waypoint.options.offset.indexOf('%') > -1) { - adjustment = Math.ceil(axis.contextDimension * adjustment / 100); - } - } - waypoint.offset = elementOffset - axis.contextOffset + axis.contextScroll - adjustment; - if ((waypoint.options.onlyOnScroll && (oldOffset != null)) || !waypoint.enabled) { - return; - } - if (oldOffset !== null && (oldOffset < (_ref = axis.oldScroll) && _ref <= waypoint.offset)) { - return waypoint.trigger([axis.backward]); - } else if (oldOffset !== null && (oldOffset > (_ref1 = axis.oldScroll) && _ref1 >= waypoint.offset)) { - return waypoint.trigger([axis.forward]); - } else if (oldOffset === null && axis.oldScroll >= waypoint.offset) { - return waypoint.trigger([axis.forward]); - } - }); - }); - }; - - Context.prototype.checkEmpty = function() { - if ($.isEmptyObject(this.waypoints.horizontal) && $.isEmptyObject(this.waypoints.vertical)) { - this.$element.unbind([resizeEvent, scrollEvent].join(' ')); - return delete contexts[this.id]; - } - }; - - return Context; - - })(); - Waypoint = (function() { - function Waypoint($element, context, options) { - var idList, _ref; - - if (options.offset === 'bottom-in-view') { - options.offset = function() { - var contextHeight; - - contextHeight = $[wps]('viewportHeight'); - if (!$.isWindow(context.element)) { - contextHeight = context.$element.height(); - } - return contextHeight - $(this).outerHeight(); - }; - } - this.$element = $element; - this.element = $element[0]; - this.axis = options.horizontal ? 'horizontal' : 'vertical'; - this.callback = options.handler; - this.context = context; - this.enabled = options.enabled; - this.id = 'waypoints' + waypointCounter++; - this.offset = null; - this.options = options; - context.waypoints[this.axis][this.id] = this; - allWaypoints[this.axis][this.id] = this; - idList = (_ref = this.element[waypointKey]) != null ? _ref : []; - idList.push(this.id); - this.element[waypointKey] = idList; - } - - Waypoint.prototype.trigger = function(args) { - if (!this.enabled) { - return; - } - if (this.callback != null) { - this.callback.apply(this.element, args); - } - if (this.options.triggerOnce) { - return this.destroy(); - } - }; - - Waypoint.prototype.disable = function() { - return this.enabled = false; - }; - - Waypoint.prototype.enable = function() { - this.context.refresh(); - return this.enabled = true; - }; - - Waypoint.prototype.destroy = function() { - delete allWaypoints[this.axis][this.id]; - delete this.context.waypoints[this.axis][this.id]; - return this.context.checkEmpty(); - }; - - Waypoint.getWaypointsByElement = function(element) { - var all, ids; - - ids = element[waypointKey]; - if (!ids) { - return []; - } - all = $.extend({}, allWaypoints.horizontal, allWaypoints.vertical); - return $.map(ids, function(id) { - return all[id]; - }); - }; - - return Waypoint; - - })(); - methods = { - init: function(f, options) { - var _ref; - - options = $.extend({}, $.fn[wp].defaults, options); - if ((_ref = options.handler) == null) { - options.handler = f; - } - this.each(function() { - var $this, context, contextElement, _ref1; - - $this = $(this); - contextElement = (_ref1 = options.context) != null ? _ref1 : $.fn[wp].defaults.context; - if (!$.isWindow(contextElement)) { - contextElement = $this.closest(contextElement); - } - contextElement = $(contextElement); - context = contexts[contextElement[0][contextKey]]; - if (!context) { - context = new Context(contextElement); - } - return new Waypoint($this, context, options); - }); - $[wps]('refresh'); - return this; - }, - disable: function() { - return methods._invoke.call(this, 'disable'); - }, - enable: function() { - return methods._invoke.call(this, 'enable'); - }, - destroy: function() { - return methods._invoke.call(this, 'destroy'); - }, - prev: function(axis, selector) { - return methods._traverse.call(this, axis, selector, function(stack, index, waypoints) { - if (index > 0) { - return stack.push(waypoints[index - 1]); - } - }); - }, - next: function(axis, selector) { - return methods._traverse.call(this, axis, selector, function(stack, index, waypoints) { - if (index < waypoints.length - 1) { - return stack.push(waypoints[index + 1]); - } - }); - }, - _traverse: function(axis, selector, push) { - var stack, waypoints; - - if (axis == null) { - axis = 'vertical'; - } - if (selector == null) { - selector = window; - } - waypoints = jQMethods.aggregate(selector); - stack = []; - this.each(function() { - var index; - - index = $.inArray(this, waypoints[axis]); - return push(stack, index, waypoints[axis]); - }); - return this.pushStack(stack); - }, - _invoke: function(method) { - this.each(function() { - var waypoints; - - waypoints = Waypoint.getWaypointsByElement(this); - return $.each(waypoints, function(i, waypoint) { - waypoint[method](); - return true; - }); - }); - return this; - } - }; - $.fn[wp] = function() { - var args, method; - - method = arguments[0], args = 2 <= arguments.length ? __slice.call(arguments, 1) : []; - if (methods[method]) { - return methods[method].apply(this, args); - } else if ($.isFunction(method)) { - return methods.init.apply(this, arguments); - } else if ($.isPlainObject(method)) { - return methods.init.apply(this, [null, method]); - } else if (!method) { - return $.error("jQuery Waypoints needs a callback function or handler option."); - } else { - return $.error("The " + method + " method does not exist in jQuery Waypoints."); - } - }; - $.fn[wp].defaults = { - context: window, - continuous: true, - enabled: true, - horizontal: false, - offset: 0, - triggerOnce: false - }; - jQMethods = { - refresh: function() { - return $.each(contexts, function(i, context) { - return context.refresh(); - }); - }, - viewportHeight: function() { - var _ref; - - return (_ref = window.innerHeight) != null ? _ref : $w.height(); - }, - aggregate: function(contextSelector) { - var collection, waypoints, _ref; - - collection = allWaypoints; - if (contextSelector) { - collection = (_ref = contexts[$(contextSelector)[0][contextKey]]) != null ? _ref.waypoints : void 0; - } - if (!collection) { - return []; - } - waypoints = { - horizontal: [], - vertical: [] - }; - $.each(waypoints, function(axis, arr) { - $.each(collection[axis], function(key, waypoint) { - return arr.push(waypoint); - }); - arr.sort(function(a, b) { - return a.offset - b.offset; - }); - waypoints[axis] = $.map(arr, function(waypoint) { - return waypoint.element; - }); - return waypoints[axis] = $.unique(waypoints[axis]); - }); - return waypoints; - }, - above: function(contextSelector) { - if (contextSelector == null) { - contextSelector = window; - } - return jQMethods._filter(contextSelector, 'vertical', function(context, waypoint) { - return waypoint.offset <= context.oldScroll.y; - }); - }, - below: function(contextSelector) { - if (contextSelector == null) { - contextSelector = window; - } - return jQMethods._filter(contextSelector, 'vertical', function(context, waypoint) { - return waypoint.offset > context.oldScroll.y; - }); - }, - left: function(contextSelector) { - if (contextSelector == null) { - contextSelector = window; - } - return jQMethods._filter(contextSelector, 'horizontal', function(context, waypoint) { - return waypoint.offset <= context.oldScroll.x; - }); - }, - right: function(contextSelector) { - if (contextSelector == null) { - contextSelector = window; - } - return jQMethods._filter(contextSelector, 'horizontal', function(context, waypoint) { - return waypoint.offset > context.oldScroll.x; - }); - }, - enable: function() { - return jQMethods._invoke('enable'); - }, - disable: function() { - return jQMethods._invoke('disable'); - }, - destroy: function() { - return jQMethods._invoke('destroy'); - }, - extendFn: function(methodName, f) { - return methods[methodName] = f; - }, - _invoke: function(method) { - var waypoints; - - waypoints = $.extend({}, allWaypoints.vertical, allWaypoints.horizontal); - return $.each(waypoints, function(key, waypoint) { - waypoint[method](); - return true; - }); - }, - _filter: function(selector, axis, test) { - var context, waypoints; - - context = contexts[$(selector)[0][contextKey]]; - if (!context) { - return []; - } - waypoints = []; - $.each(context.waypoints[axis], function(i, waypoint) { - if (test(context, waypoint)) { - return waypoints.push(waypoint); - } - }); - waypoints.sort(function(a, b) { - return a.offset - b.offset; - }); - return $.map(waypoints, function(waypoint) { - return waypoint.element; - }); - } - }; - $[wps] = function() { - var args, method; - - method = arguments[0], args = 2 <= arguments.length ? __slice.call(arguments, 1) : []; - if (jQMethods[method]) { - return jQMethods[method].apply(null, args); - } else { - return jQMethods.aggregate.call(null, method); - } - }; - $[wps].settings = { - resizeThrottle: 100, - scrollThrottle: 30 - }; - return $w.on('load.waypoints', function() { - return $[wps]('refresh'); - }); - }); - -}).call(this); diff --git a/lib/zepto.waypoints.js b/lib/zepto.waypoints.js new file mode 100644 index 00000000..a6e0e5c4 --- /dev/null +++ b/lib/zepto.waypoints.js @@ -0,0 +1,567 @@ +/*! +Waypoints - 2.0.5 +Copyright © 2011-2014 Caleb Troughton +Licensed under the MIT license. +https://github.com/imakewebthings/waypoints/blog/master/licenses.txt +*/ +(function() { + 'use strict' + + var keyCounter = 0 + var allWaypoints = {} + + function Waypoint(options) { + if (!options) { + throw new Error('No options passed to Waypoint constructor') + } + if (!options.element) { + throw new Error('No element option passed to Waypoint constructor') + } + + this.key = 'waypoint-' + keyCounter + this.options = Waypoint.Adapter.extend({}, Waypoint.defaults, options) + this.element = this.options.element + this.adapter = new Waypoint.Adapter(this.element) + this.callback = options.handler + this.axis = this.options.horizontal ? 'horizontal' : 'vertical' + this.enabled = this.options.enabled + this.triggerPoint = null + this.group = Waypoint.Group.findOrCreate({ + name: this.options.group, + axis: this.axis + }) + this.context = Waypoint.Context.findOrCreateByElement(this.options.context) + + if (Waypoint.offsetAliases[this.options.offset]) { + this.options.offset = Waypoint.offsetAliases[this.options.offset] + } + this.context.add(this) + this.group.add(this) + allWaypoints[this.key] = this + keyCounter += 1 + } + + Waypoint.prototype.disable = function() { + this.enabled = false + return this + } + + Waypoint.prototype.enable = function() { + this.context.refresh() + this.enabled = true + return this + } + + Waypoint.prototype.destroy = function() { + this.context.remove(this) + this.group.remove(this) + delete allWaypoints[this.key] + } + + /* Internal */ + Waypoint.prototype.trigger = function(args) { + if (!this.enabled) { + return + } + if (this.callback) { + this.callback.apply(this, args) + } + if (this.options.triggerOnce) { + this.destroy() + } + } + + /* Internal */ + Waypoint.prototype.queueTrigger = function(direction) { + this.group.queueTrigger(this, direction) + } + + Waypoint.adapters = [] + + Waypoint.defaults = { + context: window, + continuous: true, + enabled: true, + group: 'default', + horizontal: false, + offset: 0, + triggerOnce: false + } + + Waypoint.offsetAliases = { + 'bottom-in-view': function() { + return this.context.height() - this.adapter.outerHeight() + }, + 'right-in-view': function() { + return this.context.adapter.width() - this.adapter.outerWidth() + } + } + + Waypoint.viewportHeight = function() { + return window.innerHeight || document.documentElement.clientHeight + } + + Waypoint.refresh = function() { + Waypoint.Context.refreshAll() + } + + Waypoint.destroyAll = function() { + var allWaypointsArray = [] + for (var waypointKey in allWaypoints) { + allWaypointsArray.push(allWaypoints[waypointKey]) + } + for (var i = 0, end = allWaypointsArray.length; i < end; i++) { + allWaypointsArray[i].destroy() + } + } + + window.Waypoint = Waypoint +}()) + +(function() { + 'use strict' + + function requestAnimationFrameShim(callback) { + window.setTimeout(callback, 1000 / 60) + } + + var keyCounter = 0 + var contexts = {} + var Waypoint = window.Waypoint + + var requestAnimationFrame = window.requestAnimationFrame || + window.mozRequestAnimationFrame || + window.webkitRequestAnimationFrame || + requestAnimationFrameShim + + function Context(element) { + this.element = element + this.Adapter = Waypoint.Adapter + this.adapter = new this.Adapter(element) + this.key = 'waypoint-context-' + keyCounter + this.didScroll = false + this.didResize = false + this.oldScroll = { + x: this.adapter.scrollLeft(), + y: this.adapter.scrollTop() + } + this.waypoints = { + vertical: {}, + horizontal: {} + } + + element.waypointContextKey = this.key + contexts[element.waypointContextKey] = this + keyCounter += 1 + + this.createThrottledScrollHandler() + this.createThrottledResizeHandler() + } + + /* Internal */ + Context.prototype.createThrottledScrollHandler = function() { + var self = this + function scrollHandler() { + self.handleScroll() + self.didScroll = false + } + + this.adapter.on('scroll.waypoints', function() { + if (!self.didScroll || Waypoint.isTouch) { + self.didScroll = true + requestAnimationFrame(scrollHandler) + } + }) + } + + /* Internal */ + Context.prototype.createThrottledResizeHandler = function() { + var self = this + + function resizeHandler() { + self.handleResize() + self.didResize = false + } + + this.adapter.on('resize.waypoints', function() { + if (!self.didResize) { + self.didResize = true + requestAnimationFrame(resizeHandler) + } + }) + } + + /* Internal */ + Context.prototype.handleScroll = function() { + var triggeredGroups = {} + var axes = { + horizontal: { + newScroll: this.adapter.scrollLeft(), + oldScroll: this.oldScroll.x, + forward: 'right', + backward: 'left' + }, + vertical: { + newScroll: this.adapter.scrollTop(), + oldScroll: this.oldScroll.y, + forward: 'down', + backward: 'up' + } + } + + for (var axisKey in axes) { + var axis = axes[axisKey] + var isForward = axis.newScroll > axis.oldScroll + var direction = isForward ? axis.forward : axis.backward + + for (var waypointKey in this.waypoints[axisKey]) { + var waypoint = this.waypoints[axisKey][waypointKey] + var wasBeforeTriggerPoint = axis.oldScroll < waypoint.triggerPoint + var nowAfterTriggerPoint = axis.newScroll >= waypoint.triggerPoint + var crossedForward = wasBeforeTriggerPoint && nowAfterTriggerPoint + var crossedBackward = !wasBeforeTriggerPoint && !nowAfterTriggerPoint + if (crossedForward || crossedBackward) { + waypoint.queueTrigger(direction) + triggeredGroups[waypoint.group.id] = waypoint.group + } + } + } + + for (var groupKey in triggeredGroups) { + triggeredGroups[groupKey].flushTriggers() + } + + this.oldScroll = { + x: axes.horizontal.newScroll, + y: axes.vertical.newScroll + } + } + + /* Internal */ + Context.prototype.handleResize = function() { + Waypoint.Context.refreshAll() + } + + Context.prototype.refresh = function() { + var isWindow = this.element === this.element.window + var contextOffset = this.adapter.offset() + var height = isWindow ? Waypoint.viewportHeight() : this.adapter.height() + var triggeredGroups = {} + var axes + + this.handleScroll() + axes = { + horizontal: { + contextOffset: isWindow ? 0 : contextOffset.left, + contextScroll: isWindow ? 0 : this.oldScroll.x, + contextDimension: this.adapter.width(), + oldScroll: this.oldScroll.x, + forward: 'right', + backward: 'left', + offsetProp: 'left' + }, + vertical: { + contextOffset: isWindow ? 0 : contextOffset.top, + contextScroll: isWindow ? 0 : this.oldScroll.y, + contextDimension: height, + oldScroll: this.oldScroll.y, + forward: 'down', + backward: 'up', + offsetProp: 'top' + } + } + + for (var axisKey in axes) { + var axis = axes[axisKey] + for (var waypointKey in this.waypoints[axisKey]) { + var waypoint = this.waypoints[axisKey][waypointKey] + var adjustment = waypoint.options.offset + var oldTriggerPoint = waypoint.triggerPoint + var elementOffset = 0 + var freshWaypoint = oldTriggerPoint == null + var contextModifier + + if (waypoint.element !== waypoint.element.window) { + elementOffset = waypoint.adapter.offset()[axis.offsetProp] + } + + if (typeof adjustment === 'function') { + adjustment = adjustment.apply(waypoint) + } + else if (typeof adjustment === 'string') { + adjustment = parseFloat(adjustment) + if (waypoint.options.offset.indexOf('%') > - 1) { + adjustment = Math.ceil(axis.contextDimension * adjustment / 100) + } + } + + contextModifier = axis.contextScroll - axis.contextOffset + waypoint.triggerPoint = elementOffset + contextModifier - adjustment + + var wasBeforeScroll = oldTriggerPoint < axis.oldScroll + var nowAfterScroll = waypoint.triggerPoint >= axis.oldScroll + var triggeredBackward = wasBeforeScroll && nowAfterScroll + var triggeredForward = !wasBeforeScroll && !nowAfterScroll + if (!freshWaypoint && triggeredBackward) { + waypoint.queueTrigger(axis.backward) + triggeredGroups[waypoint.group.id] = waypoint.group + } + else if (!freshWaypoint && triggeredForward) { + waypoint.queueTrigger(axis.forward) + triggeredGroups[waypoint.group.id] = waypoint.group + } + else if (freshWaypoint && axis.oldScroll >= waypoint.triggerPoint) { + waypoint.queueTrigger(axis.forward) + triggeredGroups[waypoint.group.id] = waypoint.group + } + } + } + + for (var groupKey in triggeredGroups) { + triggeredGroups[groupKey].flushTriggers() + } + + return this + } + + Context.prototype.destroy = function() { + var allWaypoints = [] + for (var axis in this.waypoints) { + for (var waypointKey in this.waypoints[axis]) { + allWaypoints.push(this.waypoints[axis][waypointKey]) + } + } + for (var i = 0, end = allWaypoints.length; i < end; i++) { + allWaypoints[i].destroy() + } + } + + /* Internal */ + Context.prototype.add = function(waypoint) { + var axis = waypoint.options.horizontal ? 'horizontal' : 'vertical' + this.waypoints[axis][waypoint.key] = waypoint + this.refresh() + } + + /* Internal */ + Context.prototype.remove = function(waypoint) { + delete this.waypoints[waypoint.axis][waypoint.key] + this.checkEmpty() + } + + /* Internal */ + Context.prototype.checkEmpty = function() { + var horizontalEmpty = this.Adapter.isEmptyObject(this.waypoints.horizontal) + var verticalEmpty = this.Adapter.isEmptyObject(this.waypoints.vertical) + if (horizontalEmpty && verticalEmpty) { + this.adapter.off('.waypoints') + delete contexts[this.key] + } + } + + /* Internal */ + Context.prototype.height = function() { + if (this.element === this.element.window) { + return Waypoint.viewportHeight() + } + return this.adapter.height() + } + + Context.refreshAll = function() { + for (var contextId in contexts) { + contexts[contextId].refresh() + } + } + + /* Internal */ + Context.findByElement = function(element) { + return contexts[element.waypointContextKey] + } + + /* Internal */ + Context.findOrCreateByElement = function(element) { + return Context.findByElement(element) || new Context(element) + } + + Waypoint.Context = Context +}()) + +(function() { + 'use strict' + + var groups = { + vertical: {}, + horizontal: {} + } + var Waypoint = window.Waypoint + + function byTriggerPoint(a, b) { + return a.triggerPoint - b.triggerPoint + } + + function byReverseTriggerPoint(a, b) { + return b.triggerPoint - a.triggerPoint + } + + function Group(options) { + this.name = options.name + this.axis = options.axis + this.id = this.name + '-' + this.axis + this.waypoints = [] + this.clearTriggerQueues() + groups[this.axis][this.name] = this + } + + Group.prototype.previous = function(waypoint) { + this.sort() + var index = Waypoint.Adapter.inArray(waypoint, this.waypoints) + return index ? this.waypoints[index - 1] : null + } + + Group.prototype.next = function(waypoint) { + this.sort() + var index = Waypoint.Adapter.inArray(waypoint, this.waypoints) + var isLast = index === this.waypoints.length - 1 + return isLast ? null : this.waypoints[index + 1] + } + + Group.prototype.first = function() { + return this.waypoints[0] + } + + Group.prototype.last = function() { + return this.waypoints[this.waypoints.length - 1] + } + + /* Internal */ + Group.prototype.add = function(waypoint) { + this.waypoints.push(waypoint) + } + + /* Internal */ + Group.prototype.remove = function(waypoint) { + var index = Waypoint.Adapter.inArray(waypoint, this.waypoints) + if (index > -1) { + this.waypoints.splice(index, 1) + } + } + + /* Internal */ + Group.prototype.sort = function() { + this.waypoints.sort(function(a, b) { + return a.triggerPoint - b.triggerPoint + }) + } + + /* Internal */ + Group.prototype.clearTriggerQueues = function() { + this.triggerQueues = { + up: [], + down: [], + left: [], + right: [] + } + } + + /* Internal */ + Group.prototype.queueTrigger = function(waypoint, direction) { + this.triggerQueues[direction].push(waypoint) + } + + /* Internal */ + Group.prototype.flushTriggers = function() { + for (var direction in this.triggerQueues) { + var waypoints = this.triggerQueues[direction] + var reverse = direction === 'up' || direction === 'left' + waypoints.sort(reverse ? byReverseTriggerPoint : byTriggerPoint) + for (var i = 0, end = waypoints.length; i < end; i += 1) { + var waypoint = waypoints[i] + if (waypoint.options.continuous || i === waypoints.length - 1) { + waypoint.trigger([direction]) + } + } + } + this.clearTriggerQueues() + } + + /* Internal */ + Group.findOrCreate = function(options) { + return groups[options.axis][options.name] || new Group(options) + } + + Waypoint.Group = Group +}()) + +(function() { + 'use strict' + + var $ = window.Zepto + var Waypoint = window.Waypoint + + function ZeptoAdapter(element) { + this.element = element + this.$element = $(element) + } + + $.each([ + 'height', + 'off', + 'on', + 'scrollLeft', + 'scrollTop', + 'width' + ], function(i, method) { + ZeptoAdapter.prototype[method] = function() { + var args = Array.prototype.slice.call(arguments) + return this.$element[method].apply(this.$element, args) + } + }) + + ZeptoAdapter.prototype.offset = function() { + if (this.element !== this.element.window) { + return this.$element.offset() + } + } + + $.each([ + 'width', + 'height' + ], function(i, dimension) { + var method = $.camelCase('outer-' + dimension) + + ZeptoAdapter.prototype[method] = function(includeMargin) { + var size = this.$element[dimension]() + var sides = { + width: ['left', 'right'], + height: ['top', 'bottom'] + } + if (includeMargin) { + $.each(sides[dimension], $.proxy(function(i, side) { + size += parseInt(this.$element.css('margin-' + side), 10) + }, this)) + } + return size + } + }) + + $.each([ + 'extend', + 'inArray' + ], function(i, method) { + ZeptoAdapter[method] = $[method] + }) + + ZeptoAdapter.isEmptyObject = function(obj) { + /* eslint no-unused-vars: 0 */ + for (var name in obj) { + return false + } + return true + } + + Waypoint.adapters.push({ + name: 'zepto', + Adapter: ZeptoAdapter + }) + Waypoint.Adapter = ZeptoAdapter +}()) diff --git a/lib/zepto.waypoints.min.js b/lib/zepto.waypoints.min.js new file mode 100644 index 00000000..fcf8d9b5 --- /dev/null +++ b/lib/zepto.waypoints.min.js @@ -0,0 +1,7 @@ +/*! +Waypoints - 2.0.5 +Copyright © 2011-2014 Caleb Troughton +Licensed under the MIT license. +https://github.com/imakewebthings/waypoints/blog/master/licenses.txt +*/ +!function(){"use strict";function t(o){if(!o)throw new Error("No options passed to Waypoint constructor");if(!o.element)throw new Error("No element option passed to Waypoint constructor");this.key="waypoint-"+e,this.options=t.Adapter.extend({},t.defaults,o),this.element=this.options.element,this.adapter=new t.Adapter(this.element),this.callback=o.handler,this.axis=this.options.horizontal?"horizontal":"vertical",this.enabled=this.options.enabled,this.triggerPoint=null,this.group=t.Group.findOrCreate({name:this.options.group,axis:this.axis}),this.context=t.Context.findOrCreateByElement(this.options.context),t.offsetAliases[this.options.offset]&&(this.options.offset=t.offsetAliases[this.options.offset]),this.context.add(this),this.group.add(this),i[this.key]=this,e+=1}var e=0,i={};t.prototype.disable=function(){return this.enabled=!1,this},t.prototype.enable=function(){return this.context.refresh(),this.enabled=!0,this},t.prototype.destroy=function(){this.context.remove(this),this.group.remove(this),delete i[this.key]},t.prototype.trigger=function(t){this.enabled&&(this.callback&&this.callback.apply(this,t),this.options.triggerOnce&&this.destroy())},t.prototype.queueTrigger=function(t){this.group.queueTrigger(this,t)},t.adapters=[],t.defaults={context:window,continuous:!0,enabled:!0,group:"default",horizontal:!1,offset:0,triggerOnce:!1},t.offsetAliases={"bottom-in-view":function(){return this.context.height()-this.adapter.outerHeight()},"right-in-view":function(){return this.context.adapter.width()-this.adapter.outerWidth()}},t.viewportHeight=function(){return window.innerHeight||document.documentElement.clientHeight},t.refresh=function(){t.Context.refreshAll()},t.destroyAll=function(){var t=[];for(var e in i)t.push(i[e]);for(var o=0,r=t.length;r>o;o++)t[o].destroy()},window.Waypoint=t}()(function(){"use strict";function t(t){window.setTimeout(t,1e3/60)}function e(t){this.element=t,this.Adapter=r.Adapter,this.adapter=new this.Adapter(t),this.key="waypoint-context-"+i,this.didScroll=!1,this.didResize=!1,this.oldScroll={x:this.adapter.scrollLeft(),y:this.adapter.scrollTop()},this.waypoints={vertical:{},horizontal:{}},t.waypointContextKey=this.key,o[t.waypointContextKey]=this,i+=1,this.createThrottledScrollHandler(),this.createThrottledResizeHandler()}var i=0,o={},r=window.Waypoint,n=window.requestAnimationFrame||window.mozRequestAnimationFrame||window.webkitRequestAnimationFrame||t;e.prototype.createThrottledScrollHandler=function(){function t(){e.handleScroll(),e.didScroll=!1}var e=this;this.adapter.on("scroll.waypoints",function(){(!e.didScroll||r.isTouch)&&(e.didScroll=!0,n(t))})},e.prototype.createThrottledResizeHandler=function(){function t(){e.handleResize(),e.didResize=!1}var e=this;this.adapter.on("resize.waypoints",function(){e.didResize||(e.didResize=!0,n(t))})},e.prototype.handleScroll=function(){var t={},e={horizontal:{newScroll:this.adapter.scrollLeft(),oldScroll:this.oldScroll.x,forward:"right",backward:"left"},vertical:{newScroll:this.adapter.scrollTop(),oldScroll:this.oldScroll.y,forward:"down",backward:"up"}};for(var i in e){var o=e[i],r=o.newScroll>o.oldScroll,n=r?o.forward:o.backward;for(var s in this.waypoints[i]){var a=this.waypoints[i][s],l=o.oldScroll=a.triggerPoint,p=l&&h,c=!l&&!h;(p||c)&&(a.queueTrigger(n),t[a.group.id]=a.group)}}for(var u in t)t[u].flushTriggers();this.oldScroll={x:e.horizontal.newScroll,y:e.vertical.newScroll}},e.prototype.handleResize=function(){r.Context.refreshAll()},e.prototype.refresh=function(){var t,e=this.element===this.element.window,i=this.adapter.offset(),o=e?r.viewportHeight():this.adapter.height(),n={};this.handleScroll(),t={horizontal:{contextOffset:e?0:i.left,contextScroll:e?0:this.oldScroll.x,contextDimension:this.adapter.width(),oldScroll:this.oldScroll.x,forward:"right",backward:"left",offsetProp:"left"},vertical:{contextOffset:e?0:i.top,contextScroll:e?0:this.oldScroll.y,contextDimension:o,oldScroll:this.oldScroll.y,forward:"down",backward:"up",offsetProp:"top"}};for(var s in t){var a=t[s];for(var l in this.waypoints[s]){var h,p=this.waypoints[s][l],c=p.options.offset,u=p.triggerPoint,d=0,f=null==u;p.element!==p.element.window&&(d=p.adapter.offset()[a.offsetProp]),"function"==typeof c?c=c.apply(p):"string"==typeof c&&(c=parseFloat(c),p.options.offset.indexOf("%")>-1&&(c=Math.ceil(a.contextDimension*c/100))),h=a.contextScroll-a.contextOffset,p.triggerPoint=d+h-c;var y=u=a.oldScroll,w=y&&g,m=!y&&!g;!f&&w?(p.queueTrigger(a.backward),n[p.group.id]=p.group):!f&&m?(p.queueTrigger(a.forward),n[p.group.id]=p.group):f&&a.oldScroll>=p.triggerPoint&&(p.queueTrigger(a.forward),n[p.group.id]=p.group)}}for(var v in n)n[v].flushTriggers();return this},e.prototype.destroy=function(){var t=[];for(var e in this.waypoints)for(var i in this.waypoints[e])t.push(this.waypoints[e][i]);for(var o=0,r=t.length;r>o;o++)t[o].destroy()},e.prototype.add=function(t){var e=t.options.horizontal?"horizontal":"vertical";this.waypoints[e][t.key]=t,this.refresh()},e.prototype.remove=function(t){delete this.waypoints[t.axis][t.key],this.checkEmpty()},e.prototype.checkEmpty=function(){var t=this.Adapter.isEmptyObject(this.waypoints.horizontal),e=this.Adapter.isEmptyObject(this.waypoints.vertical);t&&e&&(this.adapter.off(".waypoints"),delete o[this.key])},e.prototype.height=function(){return this.element===this.element.window?r.viewportHeight():this.adapter.height()},e.refreshAll=function(){for(var t in o)o[t].refresh()},e.findByElement=function(t){return o[t.waypointContextKey]},e.findOrCreateByElement=function(t){return e.findByElement(t)||new e(t)},r.Context=e}())(function(){"use strict";function t(t,e){return t.triggerPoint-e.triggerPoint}function e(t,e){return e.triggerPoint-t.triggerPoint}function i(t){this.name=t.name,this.axis=t.axis,this.id=this.name+"-"+this.axis,this.waypoints=[],this.clearTriggerQueues(),o[this.axis][this.name]=this}var o={vertical:{},horizontal:{}},r=window.Waypoint;i.prototype.previous=function(t){this.sort();var e=r.Adapter.inArray(t,this.waypoints);return e?this.waypoints[e-1]:null},i.prototype.next=function(t){this.sort();var e=r.Adapter.inArray(t,this.waypoints),i=e===this.waypoints.length-1;return i?null:this.waypoints[e+1]},i.prototype.first=function(){return this.waypoints[0]},i.prototype.last=function(){return this.waypoints[this.waypoints.length-1]},i.prototype.add=function(t){this.waypoints.push(t)},i.prototype.remove=function(t){var e=r.Adapter.inArray(t,this.waypoints);e>-1&&this.waypoints.splice(e,1)},i.prototype.sort=function(){this.waypoints.sort(function(t,e){return t.triggerPoint-e.triggerPoint})},i.prototype.clearTriggerQueues=function(){this.triggerQueues={up:[],down:[],left:[],right:[]}},i.prototype.queueTrigger=function(t,e){this.triggerQueues[e].push(t)},i.prototype.flushTriggers=function(){for(var i in this.triggerQueues){var o=this.triggerQueues[i],r="up"===i||"left"===i;o.sort(r?e:t);for(var n=0,s=o.length;s>n;n+=1){var a=o[n];(a.options.continuous||n===o.length-1)&&a.trigger([i])}}this.clearTriggerQueues()},i.findOrCreate=function(t){return o[t.axis][t.name]||new i(t)},r.Group=i}())(function(){"use strict";function t(t){this.element=t,this.$element=e(t)}var e=window.Zepto,i=window.Waypoint;e.each(["height","off","on","scrollLeft","scrollTop","width"],function(e,i){t.prototype[i]=function(){var t=Array.prototype.slice.call(arguments);return this.$element[i].apply(this.$element,t)}}),t.prototype.offset=function(){return this.element!==this.element.window?this.$element.offset():void 0},e.each(["width","height"],function(i,o){var r=e.camelCase("outer-"+o);t.prototype[r]=function(t){var i=this.$element[o](),r={width:["left","right"],height:["top","bottom"]};return t&&e.each(r[o],e.proxy(function(t,e){i+=parseInt(this.$element.css("margin-"+e),10)},this)),i}}),e.each(["extend","inArray"],function(i,o){t[o]=e[o]}),t.isEmptyObject=function(t){for(var e in t)return!1;return!0},i.adapters.push({name:"zepto",Adapter:t}),i.Adapter=t}()); \ No newline at end of file diff --git a/package.json b/package.json index 4082200d..392e3844 100644 --- a/package.json +++ b/package.json @@ -18,7 +18,13 @@ "devDependencies": { "eslint": "^0.6.2", "gulp": "^3.6.2", - "gulp-eslint": "^0.1.7" + "gulp-concat": "^2.2.0", + "gulp-eslint": "^0.1.7", + "gulp-header": "^1.0.2", + "gulp-rename": "^1.2.0", + "gulp-tap": "^0.1.1", + "gulp-uglify": "^0.3.1", + "merge-stream": "^0.1.1" }, "license": "MIT" } diff --git a/src/adapters/jquery.js b/src/adapters/jquery.js index 712d38d0..a9338f20 100644 --- a/src/adapters/jquery.js +++ b/src/adapters/jquery.js @@ -2,6 +2,7 @@ 'use strict' var $ = window.jQuery + var Waypoint = window.Waypoint function JQueryAdapter(element) { this.$element = $(element) @@ -32,9 +33,9 @@ JQueryAdapter[method] = $[method] }) - window.Waypoint.adapters.push({ + Waypoint.adapters.push({ name: 'jquery', Adapter: JQueryAdapter }) - window.Waypoint.Adapter = JQueryAdapter + Waypoint.Adapter = JQueryAdapter }()) diff --git a/src/adapters/noframework.js b/src/adapters/noframework.js index 23d39963..25b4a40a 100644 --- a/src/adapters/noframework.js +++ b/src/adapters/noframework.js @@ -1,6 +1,8 @@ (function() { 'use strict' + var Waypoint = window.Waypoint + function isWindow(element) { return element === element.window } @@ -163,9 +165,9 @@ return true } - window.Waypoint.adapters.push({ + Waypoint.adapters.push({ name: 'noframework', Adapter: NoFrameworkAdapter }) - window.Waypoint.Adapter = NoFrameworkAdapter + Waypoint.Adapter = NoFrameworkAdapter }()) diff --git a/src/adapters/zepto.js b/src/adapters/zepto.js index 8546fd29..e81f1d45 100644 --- a/src/adapters/zepto.js +++ b/src/adapters/zepto.js @@ -2,6 +2,7 @@ 'use strict' var $ = window.Zepto + var Waypoint = window.Waypoint function ZeptoAdapter(element) { this.element = element @@ -64,9 +65,9 @@ return true } - window.Waypoint.adapters.push({ + Waypoint.adapters.push({ name: 'zepto', Adapter: ZeptoAdapter }) - window.Waypoint.Adapter = ZeptoAdapter + Waypoint.Adapter = ZeptoAdapter }()) From 79609bb27eb87de787c358388ec0fefcde24ddbb Mon Sep 17 00:00:00 2001 From: imakewebthings Date: Sat, 21 Jun 2014 11:19:07 -0700 Subject: [PATCH 24/98] Sort methods by public/private and alphabetically --- lib/jquery.waypoints.js | 322 ++++++++++++++++--------------- lib/jquery.waypoints.min.js | 2 +- lib/noframework.waypoints.js | 322 ++++++++++++++++--------------- lib/noframework.waypoints.min.js | 2 +- lib/shortcuts/infinite.js | 15 +- lib/shortcuts/infinite.min.js | 2 +- lib/shortcuts/inview.js | 23 +-- lib/shortcuts/inview.min.js | 2 +- lib/shortcuts/sticky.js | 27 +-- lib/shortcuts/sticky.min.js | 2 +- lib/zepto.waypoints.js | 322 ++++++++++++++++--------------- lib/zepto.waypoints.min.js | 2 +- src/context.js | 149 +++++++------- src/group.js | 106 +++++----- src/shortcuts/infinite.js | 15 +- src/shortcuts/inview.js | 23 +-- src/shortcuts/sticky.js | 27 +-- src/waypoint.js | 66 ++++--- test/waypoint-spec.js | 6 +- 19 files changed, 748 insertions(+), 687 deletions(-) diff --git a/lib/jquery.waypoints.js b/lib/jquery.waypoints.js index bed9374b..aa809fcf 100644 --- a/lib/jquery.waypoints.js +++ b/lib/jquery.waypoints.js @@ -41,39 +41,63 @@ https://github.com/imakewebthings/waypoints/blog/master/licenses.txt keyCounter += 1 } + /* Private */ + Waypoint.prototype.trigger = function(args) { + if (!this.enabled) { + return + } + if (this.callback) { + this.callback.apply(this, args) + } + if (this.options.triggerOnce) { + this.destroy() + } + } + + /* Private */ + Waypoint.prototype.queueTrigger = function(direction) { + this.group.queueTrigger(this, direction) + } + + /* Public */ Waypoint.prototype.disable = function() { this.enabled = false return this } + /* Public */ Waypoint.prototype.enable = function() { this.context.refresh() this.enabled = true return this } + /* Public */ Waypoint.prototype.destroy = function() { this.context.remove(this) this.group.remove(this) delete allWaypoints[this.key] } - /* Internal */ - Waypoint.prototype.trigger = function(args) { - if (!this.enabled) { - return - } - if (this.callback) { - this.callback.apply(this, args) + /* Public */ + Waypoint.destroyAll = function() { + var allWaypointsArray = [] + for (var waypointKey in allWaypoints) { + allWaypointsArray.push(allWaypoints[waypointKey]) } - if (this.options.triggerOnce) { - this.destroy() + for (var i = 0, end = allWaypointsArray.length; i < end; i++) { + allWaypointsArray[i].destroy() } } - /* Internal */ - Waypoint.prototype.queueTrigger = function(direction) { - this.group.queueTrigger(this, direction) + /* Public */ + Waypoint.refreshAll = function() { + Waypoint.Context.refreshAll() + } + + /* Public */ + Waypoint.viewportHeight = function() { + return window.innerHeight || document.documentElement.clientHeight } Waypoint.adapters = [] @@ -96,24 +120,7 @@ https://github.com/imakewebthings/waypoints/blog/master/licenses.txt return this.context.adapter.width() - this.adapter.outerWidth() } } - - Waypoint.viewportHeight = function() { - return window.innerHeight || document.documentElement.clientHeight - } - - Waypoint.refresh = function() { - Waypoint.Context.refreshAll() - } - - Waypoint.destroyAll = function() { - var allWaypointsArray = [] - for (var waypointKey in allWaypoints) { - allWaypointsArray.push(allWaypoints[waypointKey]) - } - for (var i = 0, end = allWaypointsArray.length; i < end; i++) { - allWaypointsArray[i].destroy() - } - } + } window.Waypoint = Waypoint }()) @@ -128,7 +135,6 @@ https://github.com/imakewebthings/waypoints/blog/master/licenses.txt var keyCounter = 0 var contexts = {} var Waypoint = window.Waypoint - var requestAnimationFrame = window.requestAnimationFrame || window.mozRequestAnimationFrame || window.webkitRequestAnimationFrame || @@ -158,23 +164,24 @@ https://github.com/imakewebthings/waypoints/blog/master/licenses.txt this.createThrottledResizeHandler() } - /* Internal */ - Context.prototype.createThrottledScrollHandler = function() { - var self = this - function scrollHandler() { - self.handleScroll() - self.didScroll = false - } + /* Private */ + Context.prototype.add = function(waypoint) { + var axis = waypoint.options.horizontal ? 'horizontal' : 'vertical' + this.waypoints[axis][waypoint.key] = waypoint + this.refresh() + } - this.adapter.on('scroll.waypoints', function() { - if (!self.didScroll || Waypoint.isTouch) { - self.didScroll = true - requestAnimationFrame(scrollHandler) - } - }) + /* Private */ + Context.prototype.checkEmpty = function() { + var horizontalEmpty = this.Adapter.isEmptyObject(this.waypoints.horizontal) + var verticalEmpty = this.Adapter.isEmptyObject(this.waypoints.vertical) + if (horizontalEmpty && verticalEmpty) { + this.adapter.off('.waypoints') + delete contexts[this.key] + } } - /* Internal */ + /* Private */ Context.prototype.createThrottledResizeHandler = function() { var self = this @@ -191,7 +198,28 @@ https://github.com/imakewebthings/waypoints/blog/master/licenses.txt }) } - /* Internal */ + /* Private */ + Context.prototype.createThrottledScrollHandler = function() { + var self = this + function scrollHandler() { + self.handleScroll() + self.didScroll = false + } + + this.adapter.on('scroll.waypoints', function() { + if (!self.didScroll || Waypoint.isTouch) { + self.didScroll = true + requestAnimationFrame(scrollHandler) + } + }) + } + + /* Private */ + Context.prototype.handleResize = function() { + Waypoint.Context.refreshAll() + } + + /* Private */ Context.prototype.handleScroll = function() { var triggeredGroups = {} var axes = { @@ -237,11 +265,34 @@ https://github.com/imakewebthings/waypoints/blog/master/licenses.txt } } - /* Internal */ - Context.prototype.handleResize = function() { - Waypoint.Context.refreshAll() + /* Private */ + Context.prototype.height = function() { + if (this.element === this.element.window) { + return Waypoint.viewportHeight() + } + return this.adapter.height() + } + + /* Private */ + Context.prototype.remove = function(waypoint) { + delete this.waypoints[waypoint.axis][waypoint.key] + this.checkEmpty() + } + + /* Public */ + Context.prototype.destroy = function() { + var allWaypoints = [] + for (var axis in this.waypoints) { + for (var waypointKey in this.waypoints[axis]) { + allWaypoints.push(this.waypoints[axis][waypointKey]) + } + } + for (var i = 0, end = allWaypoints.length; i < end; i++) { + allWaypoints[i].destroy() + } } + /* Public */ Context.prototype.refresh = function() { var isWindow = this.element === this.element.window var contextOffset = this.adapter.offset() @@ -279,7 +330,8 @@ https://github.com/imakewebthings/waypoints/blog/master/licenses.txt var oldTriggerPoint = waypoint.triggerPoint var elementOffset = 0 var freshWaypoint = oldTriggerPoint == null - var contextModifier + var contextModifier, wasBeforeScroll, nowAfterScroll + var triggeredBackward, triggeredForward if (waypoint.element !== waypoint.element.window) { elementOffset = waypoint.adapter.offset()[axis.offsetProp] @@ -297,11 +349,11 @@ https://github.com/imakewebthings/waypoints/blog/master/licenses.txt contextModifier = axis.contextScroll - axis.contextOffset waypoint.triggerPoint = elementOffset + contextModifier - adjustment + wasBeforeScroll = oldTriggerPoint < axis.oldScroll + nowAfterScroll = waypoint.triggerPoint >= axis.oldScroll + triggeredBackward = wasBeforeScroll && nowAfterScroll + triggeredForward = !wasBeforeScroll && !nowAfterScroll - var wasBeforeScroll = oldTriggerPoint < axis.oldScroll - var nowAfterScroll = waypoint.triggerPoint >= axis.oldScroll - var triggeredBackward = wasBeforeScroll && nowAfterScroll - var triggeredForward = !wasBeforeScroll && !nowAfterScroll if (!freshWaypoint && triggeredBackward) { waypoint.queueTrigger(axis.backward) triggeredGroups[waypoint.group.id] = waypoint.group @@ -324,77 +376,29 @@ https://github.com/imakewebthings/waypoints/blog/master/licenses.txt return this } - Context.prototype.destroy = function() { - var allWaypoints = [] - for (var axis in this.waypoints) { - for (var waypointKey in this.waypoints[axis]) { - allWaypoints.push(this.waypoints[axis][waypointKey]) - } - } - for (var i = 0, end = allWaypoints.length; i < end; i++) { - allWaypoints[i].destroy() - } - } - - /* Internal */ - Context.prototype.add = function(waypoint) { - var axis = waypoint.options.horizontal ? 'horizontal' : 'vertical' - this.waypoints[axis][waypoint.key] = waypoint - this.refresh() - } - - /* Internal */ - Context.prototype.remove = function(waypoint) { - delete this.waypoints[waypoint.axis][waypoint.key] - this.checkEmpty() - } - - /* Internal */ - Context.prototype.checkEmpty = function() { - var horizontalEmpty = this.Adapter.isEmptyObject(this.waypoints.horizontal) - var verticalEmpty = this.Adapter.isEmptyObject(this.waypoints.vertical) - if (horizontalEmpty && verticalEmpty) { - this.adapter.off('.waypoints') - delete contexts[this.key] - } + /* Private */ + Context.findOrCreateByElement = function(element) { + return Context.findByElement(element) || new Context(element) } - /* Internal */ - Context.prototype.height = function() { - if (this.element === this.element.window) { - return Waypoint.viewportHeight() - } - return this.adapter.height() + /* Public */ + Context.findByElement = function(element) { + return contexts[element.waypointContextKey] } + /* Public */ Context.refreshAll = function() { for (var contextId in contexts) { contexts[contextId].refresh() } } - /* Internal */ - Context.findByElement = function(element) { - return contexts[element.waypointContextKey] - } - - /* Internal */ - Context.findOrCreateByElement = function(element) { - return Context.findByElement(element) || new Context(element) - } - Waypoint.Context = Context }()) (function() { 'use strict' - var groups = { - vertical: {}, - horizontal: {} - } - var Waypoint = window.Waypoint - function byTriggerPoint(a, b) { return a.triggerPoint - b.triggerPoint } @@ -403,6 +407,12 @@ https://github.com/imakewebthings/waypoints/blog/master/licenses.txt return b.triggerPoint - a.triggerPoint } + var groups = { + vertical: {}, + horizontal: {} + } + var Waypoint = window.Waypoint + function Group(options) { this.name = options.name this.axis = options.axis @@ -412,48 +422,12 @@ https://github.com/imakewebthings/waypoints/blog/master/licenses.txt groups[this.axis][this.name] = this } - Group.prototype.previous = function(waypoint) { - this.sort() - var index = Waypoint.Adapter.inArray(waypoint, this.waypoints) - return index ? this.waypoints[index - 1] : null - } - - Group.prototype.next = function(waypoint) { - this.sort() - var index = Waypoint.Adapter.inArray(waypoint, this.waypoints) - var isLast = index === this.waypoints.length - 1 - return isLast ? null : this.waypoints[index + 1] - } - - Group.prototype.first = function() { - return this.waypoints[0] - } - - Group.prototype.last = function() { - return this.waypoints[this.waypoints.length - 1] - } - - /* Internal */ + /* Private */ Group.prototype.add = function(waypoint) { this.waypoints.push(waypoint) } - /* Internal */ - Group.prototype.remove = function(waypoint) { - var index = Waypoint.Adapter.inArray(waypoint, this.waypoints) - if (index > -1) { - this.waypoints.splice(index, 1) - } - } - - /* Internal */ - Group.prototype.sort = function() { - this.waypoints.sort(function(a, b) { - return a.triggerPoint - b.triggerPoint - }) - } - - /* Internal */ + /* Private */ Group.prototype.clearTriggerQueues = function() { this.triggerQueues = { up: [], @@ -463,12 +437,7 @@ https://github.com/imakewebthings/waypoints/blog/master/licenses.txt } } - /* Internal */ - Group.prototype.queueTrigger = function(waypoint, direction) { - this.triggerQueues[direction].push(waypoint) - } - - /* Internal */ + /* Private */ Group.prototype.flushTriggers = function() { for (var direction in this.triggerQueues) { var waypoints = this.triggerQueues[direction] @@ -484,7 +453,52 @@ https://github.com/imakewebthings/waypoints/blog/master/licenses.txt this.clearTriggerQueues() } - /* Internal */ + /* Private */ + Group.prototype.queueTrigger = function(waypoint, direction) { + this.triggerQueues[direction].push(waypoint) + } + + /* Private */ + Group.prototype.remove = function(waypoint) { + var index = Waypoint.Adapter.inArray(waypoint, this.waypoints) + if (index > -1) { + this.waypoints.splice(index, 1) + } + } + + /* Private */ + Group.prototype.sort = function() { + this.waypoints.sort(function(a, b) { + return a.triggerPoint - b.triggerPoint + }) + } + + /* Public */ + Group.prototype.first = function() { + return this.waypoints[0] + } + + /* Public */ + Group.prototype.last = function() { + return this.waypoints[this.waypoints.length - 1] + } + + /* Public */ + Group.prototype.next = function(waypoint) { + this.sort() + var index = Waypoint.Adapter.inArray(waypoint, this.waypoints) + var isLast = index === this.waypoints.length - 1 + return isLast ? null : this.waypoints[index + 1] + } + + /* Public */ + Group.prototype.previous = function(waypoint) { + this.sort() + var index = Waypoint.Adapter.inArray(waypoint, this.waypoints) + return index ? this.waypoints[index - 1] : null + } + + /* Private */ Group.findOrCreate = function(options) { return groups[options.axis][options.name] || new Group(options) } diff --git a/lib/jquery.waypoints.min.js b/lib/jquery.waypoints.min.js index 54464c6c..32c6a0e1 100644 --- a/lib/jquery.waypoints.min.js +++ b/lib/jquery.waypoints.min.js @@ -4,4 +4,4 @@ Copyright © 2011-2014 Caleb Troughton Licensed under the MIT license. https://github.com/imakewebthings/waypoints/blog/master/licenses.txt */ -!function(){"use strict";function t(o){if(!o)throw new Error("No options passed to Waypoint constructor");if(!o.element)throw new Error("No element option passed to Waypoint constructor");this.key="waypoint-"+e,this.options=t.Adapter.extend({},t.defaults,o),this.element=this.options.element,this.adapter=new t.Adapter(this.element),this.callback=o.handler,this.axis=this.options.horizontal?"horizontal":"vertical",this.enabled=this.options.enabled,this.triggerPoint=null,this.group=t.Group.findOrCreate({name:this.options.group,axis:this.axis}),this.context=t.Context.findOrCreateByElement(this.options.context),t.offsetAliases[this.options.offset]&&(this.options.offset=t.offsetAliases[this.options.offset]),this.context.add(this),this.group.add(this),i[this.key]=this,e+=1}var e=0,i={};t.prototype.disable=function(){return this.enabled=!1,this},t.prototype.enable=function(){return this.context.refresh(),this.enabled=!0,this},t.prototype.destroy=function(){this.context.remove(this),this.group.remove(this),delete i[this.key]},t.prototype.trigger=function(t){this.enabled&&(this.callback&&this.callback.apply(this,t),this.options.triggerOnce&&this.destroy())},t.prototype.queueTrigger=function(t){this.group.queueTrigger(this,t)},t.adapters=[],t.defaults={context:window,continuous:!0,enabled:!0,group:"default",horizontal:!1,offset:0,triggerOnce:!1},t.offsetAliases={"bottom-in-view":function(){return this.context.height()-this.adapter.outerHeight()},"right-in-view":function(){return this.context.adapter.width()-this.adapter.outerWidth()}},t.viewportHeight=function(){return window.innerHeight||document.documentElement.clientHeight},t.refresh=function(){t.Context.refreshAll()},t.destroyAll=function(){var t=[];for(var e in i)t.push(i[e]);for(var o=0,r=t.length;r>o;o++)t[o].destroy()},window.Waypoint=t}()(function(){"use strict";function t(t){window.setTimeout(t,1e3/60)}function e(t){this.element=t,this.Adapter=r.Adapter,this.adapter=new this.Adapter(t),this.key="waypoint-context-"+i,this.didScroll=!1,this.didResize=!1,this.oldScroll={x:this.adapter.scrollLeft(),y:this.adapter.scrollTop()},this.waypoints={vertical:{},horizontal:{}},t.waypointContextKey=this.key,o[t.waypointContextKey]=this,i+=1,this.createThrottledScrollHandler(),this.createThrottledResizeHandler()}var i=0,o={},r=window.Waypoint,n=window.requestAnimationFrame||window.mozRequestAnimationFrame||window.webkitRequestAnimationFrame||t;e.prototype.createThrottledScrollHandler=function(){function t(){e.handleScroll(),e.didScroll=!1}var e=this;this.adapter.on("scroll.waypoints",function(){(!e.didScroll||r.isTouch)&&(e.didScroll=!0,n(t))})},e.prototype.createThrottledResizeHandler=function(){function t(){e.handleResize(),e.didResize=!1}var e=this;this.adapter.on("resize.waypoints",function(){e.didResize||(e.didResize=!0,n(t))})},e.prototype.handleScroll=function(){var t={},e={horizontal:{newScroll:this.adapter.scrollLeft(),oldScroll:this.oldScroll.x,forward:"right",backward:"left"},vertical:{newScroll:this.adapter.scrollTop(),oldScroll:this.oldScroll.y,forward:"down",backward:"up"}};for(var i in e){var o=e[i],r=o.newScroll>o.oldScroll,n=r?o.forward:o.backward;for(var s in this.waypoints[i]){var a=this.waypoints[i][s],l=o.oldScroll=a.triggerPoint,p=l&&h,c=!l&&!h;(p||c)&&(a.queueTrigger(n),t[a.group.id]=a.group)}}for(var u in t)t[u].flushTriggers();this.oldScroll={x:e.horizontal.newScroll,y:e.vertical.newScroll}},e.prototype.handleResize=function(){r.Context.refreshAll()},e.prototype.refresh=function(){var t,e=this.element===this.element.window,i=this.adapter.offset(),o=e?r.viewportHeight():this.adapter.height(),n={};this.handleScroll(),t={horizontal:{contextOffset:e?0:i.left,contextScroll:e?0:this.oldScroll.x,contextDimension:this.adapter.width(),oldScroll:this.oldScroll.x,forward:"right",backward:"left",offsetProp:"left"},vertical:{contextOffset:e?0:i.top,contextScroll:e?0:this.oldScroll.y,contextDimension:o,oldScroll:this.oldScroll.y,forward:"down",backward:"up",offsetProp:"top"}};for(var s in t){var a=t[s];for(var l in this.waypoints[s]){var h,p=this.waypoints[s][l],c=p.options.offset,u=p.triggerPoint,d=0,f=null==u;p.element!==p.element.window&&(d=p.adapter.offset()[a.offsetProp]),"function"==typeof c?c=c.apply(p):"string"==typeof c&&(c=parseFloat(c),p.options.offset.indexOf("%")>-1&&(c=Math.ceil(a.contextDimension*c/100))),h=a.contextScroll-a.contextOffset,p.triggerPoint=d+h-c;var y=u=a.oldScroll,w=y&&g,v=!y&&!g;!f&&w?(p.queueTrigger(a.backward),n[p.group.id]=p.group):!f&&v?(p.queueTrigger(a.forward),n[p.group.id]=p.group):f&&a.oldScroll>=p.triggerPoint&&(p.queueTrigger(a.forward),n[p.group.id]=p.group)}}for(var m in n)n[m].flushTriggers();return this},e.prototype.destroy=function(){var t=[];for(var e in this.waypoints)for(var i in this.waypoints[e])t.push(this.waypoints[e][i]);for(var o=0,r=t.length;r>o;o++)t[o].destroy()},e.prototype.add=function(t){var e=t.options.horizontal?"horizontal":"vertical";this.waypoints[e][t.key]=t,this.refresh()},e.prototype.remove=function(t){delete this.waypoints[t.axis][t.key],this.checkEmpty()},e.prototype.checkEmpty=function(){var t=this.Adapter.isEmptyObject(this.waypoints.horizontal),e=this.Adapter.isEmptyObject(this.waypoints.vertical);t&&e&&(this.adapter.off(".waypoints"),delete o[this.key])},e.prototype.height=function(){return this.element===this.element.window?r.viewportHeight():this.adapter.height()},e.refreshAll=function(){for(var t in o)o[t].refresh()},e.findByElement=function(t){return o[t.waypointContextKey]},e.findOrCreateByElement=function(t){return e.findByElement(t)||new e(t)},r.Context=e}())(function(){"use strict";function t(t,e){return t.triggerPoint-e.triggerPoint}function e(t,e){return e.triggerPoint-t.triggerPoint}function i(t){this.name=t.name,this.axis=t.axis,this.id=this.name+"-"+this.axis,this.waypoints=[],this.clearTriggerQueues(),o[this.axis][this.name]=this}var o={vertical:{},horizontal:{}},r=window.Waypoint;i.prototype.previous=function(t){this.sort();var e=r.Adapter.inArray(t,this.waypoints);return e?this.waypoints[e-1]:null},i.prototype.next=function(t){this.sort();var e=r.Adapter.inArray(t,this.waypoints),i=e===this.waypoints.length-1;return i?null:this.waypoints[e+1]},i.prototype.first=function(){return this.waypoints[0]},i.prototype.last=function(){return this.waypoints[this.waypoints.length-1]},i.prototype.add=function(t){this.waypoints.push(t)},i.prototype.remove=function(t){var e=r.Adapter.inArray(t,this.waypoints);e>-1&&this.waypoints.splice(e,1)},i.prototype.sort=function(){this.waypoints.sort(function(t,e){return t.triggerPoint-e.triggerPoint})},i.prototype.clearTriggerQueues=function(){this.triggerQueues={up:[],down:[],left:[],right:[]}},i.prototype.queueTrigger=function(t,e){this.triggerQueues[e].push(t)},i.prototype.flushTriggers=function(){for(var i in this.triggerQueues){var o=this.triggerQueues[i],r="up"===i||"left"===i;o.sort(r?e:t);for(var n=0,s=o.length;s>n;n+=1){var a=o[n];(a.options.continuous||n===o.length-1)&&a.trigger([i])}}this.clearTriggerQueues()},i.findOrCreate=function(t){return o[t.axis][t.name]||new i(t)},r.Group=i}())(function(){"use strict";function t(t){this.$element=e(t)}var e=window.jQuery,i=window.Waypoint;e.each(["height","off","offset","on","outerHeight","outerWidth","scrollLeft","scrollTop","width"],function(e,i){t.prototype[i]=function(){var t=Array.prototype.slice.call(arguments);return this.$element[i].apply(this.$element,t)}}),e.each(["extend","inArray","isEmptyObject"],function(i,o){t[o]=e[o]}),i.adapters.push({name:"jquery",Adapter:t}),i.Adapter=t}()); \ No newline at end of file +!function(){"use strict";function t(o){if(!o)throw new Error("No options passed to Waypoint constructor");if(!o.element)throw new Error("No element option passed to Waypoint constructor");this.key="waypoint-"+e,this.options=t.Adapter.extend({},t.defaults,o),this.element=this.options.element,this.adapter=new t.Adapter(this.element),this.callback=o.handler,this.axis=this.options.horizontal?"horizontal":"vertical",this.enabled=this.options.enabled,this.triggerPoint=null,this.group=t.Group.findOrCreate({name:this.options.group,axis:this.axis}),this.context=t.Context.findOrCreateByElement(this.options.context),t.offsetAliases[this.options.offset]&&(this.options.offset=t.offsetAliases[this.options.offset]),this.context.add(this),this.group.add(this),i[this.key]=this,e+=1}var e=0,i={};t.prototype.trigger=function(t){this.enabled&&(this.callback&&this.callback.apply(this,t),this.options.triggerOnce&&this.destroy())},t.prototype.queueTrigger=function(t){this.group.queueTrigger(this,t)},t.prototype.disable=function(){return this.enabled=!1,this},t.prototype.enable=function(){return this.context.refresh(),this.enabled=!0,this},t.prototype.destroy=function(){this.context.remove(this),this.group.remove(this),delete i[this.key]},t.destroyAll=function(){var t=[];for(var e in i)t.push(i[e]);for(var o=0,r=t.length;r>o;o++)t[o].destroy()},t.refreshAll=function(){t.Context.refreshAll()},t.viewportHeight=function(){return window.innerHeight||document.documentElement.clientHeight},window.Waypoint=t}()(function(){"use strict";function t(t){window.setTimeout(t,1e3/60)}function e(t){this.element=t,this.Adapter=r.Adapter,this.adapter=new this.Adapter(t),this.key="waypoint-context-"+i,this.didScroll=!1,this.didResize=!1,this.oldScroll={x:this.adapter.scrollLeft(),y:this.adapter.scrollTop()},this.waypoints={vertical:{},horizontal:{}},t.waypointContextKey=this.key,o[t.waypointContextKey]=this,i+=1,this.createThrottledScrollHandler(),this.createThrottledResizeHandler()}var i=0,o={},r=window.Waypoint,n=window.requestAnimationFrame||window.mozRequestAnimationFrame||window.webkitRequestAnimationFrame||t;e.prototype.add=function(t){var e=t.options.horizontal?"horizontal":"vertical";this.waypoints[e][t.key]=t,this.refresh()},e.prototype.checkEmpty=function(){var t=this.Adapter.isEmptyObject(this.waypoints.horizontal),e=this.Adapter.isEmptyObject(this.waypoints.vertical);t&&e&&(this.adapter.off(".waypoints"),delete o[this.key])},e.prototype.createThrottledResizeHandler=function(){function t(){e.handleResize(),e.didResize=!1}var e=this;this.adapter.on("resize.waypoints",function(){e.didResize||(e.didResize=!0,n(t))})},e.prototype.createThrottledScrollHandler=function(){function t(){e.handleScroll(),e.didScroll=!1}var e=this;this.adapter.on("scroll.waypoints",function(){(!e.didScroll||r.isTouch)&&(e.didScroll=!0,n(t))})},e.prototype.handleResize=function(){r.Context.refreshAll()},e.prototype.handleScroll=function(){var t={},e={horizontal:{newScroll:this.adapter.scrollLeft(),oldScroll:this.oldScroll.x,forward:"right",backward:"left"},vertical:{newScroll:this.adapter.scrollTop(),oldScroll:this.oldScroll.y,forward:"down",backward:"up"}};for(var i in e){var o=e[i],r=o.newScroll>o.oldScroll,n=r?o.forward:o.backward;for(var s in this.waypoints[i]){var a=this.waypoints[i][s],l=o.oldScroll=a.triggerPoint,p=l&&h,c=!l&&!h;(p||c)&&(a.queueTrigger(n),t[a.group.id]=a.group)}}for(var u in t)t[u].flushTriggers();this.oldScroll={x:e.horizontal.newScroll,y:e.vertical.newScroll}},e.prototype.height=function(){return this.element===this.element.window?r.viewportHeight():this.adapter.height()},e.prototype.remove=function(t){delete this.waypoints[t.axis][t.key],this.checkEmpty()},e.prototype.destroy=function(){var t=[];for(var e in this.waypoints)for(var i in this.waypoints[e])t.push(this.waypoints[e][i]);for(var o=0,r=t.length;r>o;o++)t[o].destroy()},e.prototype.refresh=function(){var t,e=this.element===this.element.window,i=this.adapter.offset(),o=e?r.viewportHeight():this.adapter.height(),n={};this.handleScroll(),t={horizontal:{contextOffset:e?0:i.left,contextScroll:e?0:this.oldScroll.x,contextDimension:this.adapter.width(),oldScroll:this.oldScroll.x,forward:"right",backward:"left",offsetProp:"left"},vertical:{contextOffset:e?0:i.top,contextScroll:e?0:this.oldScroll.y,contextDimension:o,oldScroll:this.oldScroll.y,forward:"down",backward:"up",offsetProp:"top"}};for(var s in t){var a=t[s];for(var l in this.waypoints[s]){var h,p,c,u,d,f=this.waypoints[s][l],y=f.options.offset,g=f.triggerPoint,w=0,v=null==g;f.element!==f.element.window&&(w=f.adapter.offset()[a.offsetProp]),"function"==typeof y?y=y.apply(f):"string"==typeof y&&(y=parseFloat(y),f.options.offset.indexOf("%")>-1&&(y=Math.ceil(a.contextDimension*y/100))),h=a.contextScroll-a.contextOffset,f.triggerPoint=w+h-y,p=g=a.oldScroll,u=p&&c,d=!p&&!c,!v&&u?(f.queueTrigger(a.backward),n[f.group.id]=f.group):!v&&d?(f.queueTrigger(a.forward),n[f.group.id]=f.group):v&&a.oldScroll>=f.triggerPoint&&(f.queueTrigger(a.forward),n[f.group.id]=f.group)}}for(var m in n)n[m].flushTriggers();return this},e.findOrCreateByElement=function(t){return e.findByElement(t)||new e(t)},e.findByElement=function(t){return o[t.waypointContextKey]},e.refreshAll=function(){for(var t in o)o[t].refresh()},r.Context=e}())(function(){"use strict";function t(t,e){return t.triggerPoint-e.triggerPoint}function e(t,e){return e.triggerPoint-t.triggerPoint}function i(t){this.name=t.name,this.axis=t.axis,this.id=this.name+"-"+this.axis,this.waypoints=[],this.clearTriggerQueues(),o[this.axis][this.name]=this}var o={vertical:{},horizontal:{}},r=window.Waypoint;i.prototype.add=function(t){this.waypoints.push(t)},i.prototype.clearTriggerQueues=function(){this.triggerQueues={up:[],down:[],left:[],right:[]}},i.prototype.flushTriggers=function(){for(var i in this.triggerQueues){var o=this.triggerQueues[i],r="up"===i||"left"===i;o.sort(r?e:t);for(var n=0,s=o.length;s>n;n+=1){var a=o[n];(a.options.continuous||n===o.length-1)&&a.trigger([i])}}this.clearTriggerQueues()},i.prototype.queueTrigger=function(t,e){this.triggerQueues[e].push(t)},i.prototype.remove=function(t){var e=r.Adapter.inArray(t,this.waypoints);e>-1&&this.waypoints.splice(e,1)},i.prototype.sort=function(){this.waypoints.sort(function(t,e){return t.triggerPoint-e.triggerPoint})},i.prototype.first=function(){return this.waypoints[0]},i.prototype.last=function(){return this.waypoints[this.waypoints.length-1]},i.prototype.next=function(t){this.sort();var e=r.Adapter.inArray(t,this.waypoints),i=e===this.waypoints.length-1;return i?null:this.waypoints[e+1]},i.prototype.previous=function(t){this.sort();var e=r.Adapter.inArray(t,this.waypoints);return e?this.waypoints[e-1]:null},i.findOrCreate=function(t){return o[t.axis][t.name]||new i(t)},r.Group=i}())(function(){"use strict";function t(t){this.$element=e(t)}var e=window.jQuery,i=window.Waypoint;e.each(["height","off","offset","on","outerHeight","outerWidth","scrollLeft","scrollTop","width"],function(e,i){t.prototype[i]=function(){var t=Array.prototype.slice.call(arguments);return this.$element[i].apply(this.$element,t)}}),e.each(["extend","inArray","isEmptyObject"],function(i,o){t[o]=e[o]}),i.adapters.push({name:"jquery",Adapter:t}),i.Adapter=t}()); \ No newline at end of file diff --git a/lib/noframework.waypoints.js b/lib/noframework.waypoints.js index 2e6fd7a3..ef8a9f48 100644 --- a/lib/noframework.waypoints.js +++ b/lib/noframework.waypoints.js @@ -41,39 +41,63 @@ https://github.com/imakewebthings/waypoints/blog/master/licenses.txt keyCounter += 1 } + /* Private */ + Waypoint.prototype.trigger = function(args) { + if (!this.enabled) { + return + } + if (this.callback) { + this.callback.apply(this, args) + } + if (this.options.triggerOnce) { + this.destroy() + } + } + + /* Private */ + Waypoint.prototype.queueTrigger = function(direction) { + this.group.queueTrigger(this, direction) + } + + /* Public */ Waypoint.prototype.disable = function() { this.enabled = false return this } + /* Public */ Waypoint.prototype.enable = function() { this.context.refresh() this.enabled = true return this } + /* Public */ Waypoint.prototype.destroy = function() { this.context.remove(this) this.group.remove(this) delete allWaypoints[this.key] } - /* Internal */ - Waypoint.prototype.trigger = function(args) { - if (!this.enabled) { - return - } - if (this.callback) { - this.callback.apply(this, args) + /* Public */ + Waypoint.destroyAll = function() { + var allWaypointsArray = [] + for (var waypointKey in allWaypoints) { + allWaypointsArray.push(allWaypoints[waypointKey]) } - if (this.options.triggerOnce) { - this.destroy() + for (var i = 0, end = allWaypointsArray.length; i < end; i++) { + allWaypointsArray[i].destroy() } } - /* Internal */ - Waypoint.prototype.queueTrigger = function(direction) { - this.group.queueTrigger(this, direction) + /* Public */ + Waypoint.refreshAll = function() { + Waypoint.Context.refreshAll() + } + + /* Public */ + Waypoint.viewportHeight = function() { + return window.innerHeight || document.documentElement.clientHeight } Waypoint.adapters = [] @@ -96,24 +120,7 @@ https://github.com/imakewebthings/waypoints/blog/master/licenses.txt return this.context.adapter.width() - this.adapter.outerWidth() } } - - Waypoint.viewportHeight = function() { - return window.innerHeight || document.documentElement.clientHeight - } - - Waypoint.refresh = function() { - Waypoint.Context.refreshAll() - } - - Waypoint.destroyAll = function() { - var allWaypointsArray = [] - for (var waypointKey in allWaypoints) { - allWaypointsArray.push(allWaypoints[waypointKey]) - } - for (var i = 0, end = allWaypointsArray.length; i < end; i++) { - allWaypointsArray[i].destroy() - } - } + } window.Waypoint = Waypoint }()) @@ -128,7 +135,6 @@ https://github.com/imakewebthings/waypoints/blog/master/licenses.txt var keyCounter = 0 var contexts = {} var Waypoint = window.Waypoint - var requestAnimationFrame = window.requestAnimationFrame || window.mozRequestAnimationFrame || window.webkitRequestAnimationFrame || @@ -158,23 +164,24 @@ https://github.com/imakewebthings/waypoints/blog/master/licenses.txt this.createThrottledResizeHandler() } - /* Internal */ - Context.prototype.createThrottledScrollHandler = function() { - var self = this - function scrollHandler() { - self.handleScroll() - self.didScroll = false - } + /* Private */ + Context.prototype.add = function(waypoint) { + var axis = waypoint.options.horizontal ? 'horizontal' : 'vertical' + this.waypoints[axis][waypoint.key] = waypoint + this.refresh() + } - this.adapter.on('scroll.waypoints', function() { - if (!self.didScroll || Waypoint.isTouch) { - self.didScroll = true - requestAnimationFrame(scrollHandler) - } - }) + /* Private */ + Context.prototype.checkEmpty = function() { + var horizontalEmpty = this.Adapter.isEmptyObject(this.waypoints.horizontal) + var verticalEmpty = this.Adapter.isEmptyObject(this.waypoints.vertical) + if (horizontalEmpty && verticalEmpty) { + this.adapter.off('.waypoints') + delete contexts[this.key] + } } - /* Internal */ + /* Private */ Context.prototype.createThrottledResizeHandler = function() { var self = this @@ -191,7 +198,28 @@ https://github.com/imakewebthings/waypoints/blog/master/licenses.txt }) } - /* Internal */ + /* Private */ + Context.prototype.createThrottledScrollHandler = function() { + var self = this + function scrollHandler() { + self.handleScroll() + self.didScroll = false + } + + this.adapter.on('scroll.waypoints', function() { + if (!self.didScroll || Waypoint.isTouch) { + self.didScroll = true + requestAnimationFrame(scrollHandler) + } + }) + } + + /* Private */ + Context.prototype.handleResize = function() { + Waypoint.Context.refreshAll() + } + + /* Private */ Context.prototype.handleScroll = function() { var triggeredGroups = {} var axes = { @@ -237,11 +265,34 @@ https://github.com/imakewebthings/waypoints/blog/master/licenses.txt } } - /* Internal */ - Context.prototype.handleResize = function() { - Waypoint.Context.refreshAll() + /* Private */ + Context.prototype.height = function() { + if (this.element === this.element.window) { + return Waypoint.viewportHeight() + } + return this.adapter.height() + } + + /* Private */ + Context.prototype.remove = function(waypoint) { + delete this.waypoints[waypoint.axis][waypoint.key] + this.checkEmpty() + } + + /* Public */ + Context.prototype.destroy = function() { + var allWaypoints = [] + for (var axis in this.waypoints) { + for (var waypointKey in this.waypoints[axis]) { + allWaypoints.push(this.waypoints[axis][waypointKey]) + } + } + for (var i = 0, end = allWaypoints.length; i < end; i++) { + allWaypoints[i].destroy() + } } + /* Public */ Context.prototype.refresh = function() { var isWindow = this.element === this.element.window var contextOffset = this.adapter.offset() @@ -279,7 +330,8 @@ https://github.com/imakewebthings/waypoints/blog/master/licenses.txt var oldTriggerPoint = waypoint.triggerPoint var elementOffset = 0 var freshWaypoint = oldTriggerPoint == null - var contextModifier + var contextModifier, wasBeforeScroll, nowAfterScroll + var triggeredBackward, triggeredForward if (waypoint.element !== waypoint.element.window) { elementOffset = waypoint.adapter.offset()[axis.offsetProp] @@ -297,11 +349,11 @@ https://github.com/imakewebthings/waypoints/blog/master/licenses.txt contextModifier = axis.contextScroll - axis.contextOffset waypoint.triggerPoint = elementOffset + contextModifier - adjustment + wasBeforeScroll = oldTriggerPoint < axis.oldScroll + nowAfterScroll = waypoint.triggerPoint >= axis.oldScroll + triggeredBackward = wasBeforeScroll && nowAfterScroll + triggeredForward = !wasBeforeScroll && !nowAfterScroll - var wasBeforeScroll = oldTriggerPoint < axis.oldScroll - var nowAfterScroll = waypoint.triggerPoint >= axis.oldScroll - var triggeredBackward = wasBeforeScroll && nowAfterScroll - var triggeredForward = !wasBeforeScroll && !nowAfterScroll if (!freshWaypoint && triggeredBackward) { waypoint.queueTrigger(axis.backward) triggeredGroups[waypoint.group.id] = waypoint.group @@ -324,77 +376,29 @@ https://github.com/imakewebthings/waypoints/blog/master/licenses.txt return this } - Context.prototype.destroy = function() { - var allWaypoints = [] - for (var axis in this.waypoints) { - for (var waypointKey in this.waypoints[axis]) { - allWaypoints.push(this.waypoints[axis][waypointKey]) - } - } - for (var i = 0, end = allWaypoints.length; i < end; i++) { - allWaypoints[i].destroy() - } - } - - /* Internal */ - Context.prototype.add = function(waypoint) { - var axis = waypoint.options.horizontal ? 'horizontal' : 'vertical' - this.waypoints[axis][waypoint.key] = waypoint - this.refresh() - } - - /* Internal */ - Context.prototype.remove = function(waypoint) { - delete this.waypoints[waypoint.axis][waypoint.key] - this.checkEmpty() - } - - /* Internal */ - Context.prototype.checkEmpty = function() { - var horizontalEmpty = this.Adapter.isEmptyObject(this.waypoints.horizontal) - var verticalEmpty = this.Adapter.isEmptyObject(this.waypoints.vertical) - if (horizontalEmpty && verticalEmpty) { - this.adapter.off('.waypoints') - delete contexts[this.key] - } + /* Private */ + Context.findOrCreateByElement = function(element) { + return Context.findByElement(element) || new Context(element) } - /* Internal */ - Context.prototype.height = function() { - if (this.element === this.element.window) { - return Waypoint.viewportHeight() - } - return this.adapter.height() + /* Public */ + Context.findByElement = function(element) { + return contexts[element.waypointContextKey] } + /* Public */ Context.refreshAll = function() { for (var contextId in contexts) { contexts[contextId].refresh() } } - /* Internal */ - Context.findByElement = function(element) { - return contexts[element.waypointContextKey] - } - - /* Internal */ - Context.findOrCreateByElement = function(element) { - return Context.findByElement(element) || new Context(element) - } - Waypoint.Context = Context }()) (function() { 'use strict' - var groups = { - vertical: {}, - horizontal: {} - } - var Waypoint = window.Waypoint - function byTriggerPoint(a, b) { return a.triggerPoint - b.triggerPoint } @@ -403,6 +407,12 @@ https://github.com/imakewebthings/waypoints/blog/master/licenses.txt return b.triggerPoint - a.triggerPoint } + var groups = { + vertical: {}, + horizontal: {} + } + var Waypoint = window.Waypoint + function Group(options) { this.name = options.name this.axis = options.axis @@ -412,48 +422,12 @@ https://github.com/imakewebthings/waypoints/blog/master/licenses.txt groups[this.axis][this.name] = this } - Group.prototype.previous = function(waypoint) { - this.sort() - var index = Waypoint.Adapter.inArray(waypoint, this.waypoints) - return index ? this.waypoints[index - 1] : null - } - - Group.prototype.next = function(waypoint) { - this.sort() - var index = Waypoint.Adapter.inArray(waypoint, this.waypoints) - var isLast = index === this.waypoints.length - 1 - return isLast ? null : this.waypoints[index + 1] - } - - Group.prototype.first = function() { - return this.waypoints[0] - } - - Group.prototype.last = function() { - return this.waypoints[this.waypoints.length - 1] - } - - /* Internal */ + /* Private */ Group.prototype.add = function(waypoint) { this.waypoints.push(waypoint) } - /* Internal */ - Group.prototype.remove = function(waypoint) { - var index = Waypoint.Adapter.inArray(waypoint, this.waypoints) - if (index > -1) { - this.waypoints.splice(index, 1) - } - } - - /* Internal */ - Group.prototype.sort = function() { - this.waypoints.sort(function(a, b) { - return a.triggerPoint - b.triggerPoint - }) - } - - /* Internal */ + /* Private */ Group.prototype.clearTriggerQueues = function() { this.triggerQueues = { up: [], @@ -463,12 +437,7 @@ https://github.com/imakewebthings/waypoints/blog/master/licenses.txt } } - /* Internal */ - Group.prototype.queueTrigger = function(waypoint, direction) { - this.triggerQueues[direction].push(waypoint) - } - - /* Internal */ + /* Private */ Group.prototype.flushTriggers = function() { for (var direction in this.triggerQueues) { var waypoints = this.triggerQueues[direction] @@ -484,7 +453,52 @@ https://github.com/imakewebthings/waypoints/blog/master/licenses.txt this.clearTriggerQueues() } - /* Internal */ + /* Private */ + Group.prototype.queueTrigger = function(waypoint, direction) { + this.triggerQueues[direction].push(waypoint) + } + + /* Private */ + Group.prototype.remove = function(waypoint) { + var index = Waypoint.Adapter.inArray(waypoint, this.waypoints) + if (index > -1) { + this.waypoints.splice(index, 1) + } + } + + /* Private */ + Group.prototype.sort = function() { + this.waypoints.sort(function(a, b) { + return a.triggerPoint - b.triggerPoint + }) + } + + /* Public */ + Group.prototype.first = function() { + return this.waypoints[0] + } + + /* Public */ + Group.prototype.last = function() { + return this.waypoints[this.waypoints.length - 1] + } + + /* Public */ + Group.prototype.next = function(waypoint) { + this.sort() + var index = Waypoint.Adapter.inArray(waypoint, this.waypoints) + var isLast = index === this.waypoints.length - 1 + return isLast ? null : this.waypoints[index + 1] + } + + /* Public */ + Group.prototype.previous = function(waypoint) { + this.sort() + var index = Waypoint.Adapter.inArray(waypoint, this.waypoints) + return index ? this.waypoints[index - 1] : null + } + + /* Private */ Group.findOrCreate = function(options) { return groups[options.axis][options.name] || new Group(options) } diff --git a/lib/noframework.waypoints.min.js b/lib/noframework.waypoints.min.js index 3b999e76..c6245e2f 100644 --- a/lib/noframework.waypoints.min.js +++ b/lib/noframework.waypoints.min.js @@ -4,4 +4,4 @@ Copyright © 2011-2014 Caleb Troughton Licensed under the MIT license. https://github.com/imakewebthings/waypoints/blog/master/licenses.txt */ -!function(){"use strict";function t(r){if(!r)throw new Error("No options passed to Waypoint constructor");if(!r.element)throw new Error("No element option passed to Waypoint constructor");this.key="waypoint-"+e,this.options=t.Adapter.extend({},t.defaults,r),this.element=this.options.element,this.adapter=new t.Adapter(this.element),this.callback=r.handler,this.axis=this.options.horizontal?"horizontal":"vertical",this.enabled=this.options.enabled,this.triggerPoint=null,this.group=t.Group.findOrCreate({name:this.options.group,axis:this.axis}),this.context=t.Context.findOrCreateByElement(this.options.context),t.offsetAliases[this.options.offset]&&(this.options.offset=t.offsetAliases[this.options.offset]),this.context.add(this),this.group.add(this),i[this.key]=this,e+=1}var e=0,i={};t.prototype.disable=function(){return this.enabled=!1,this},t.prototype.enable=function(){return this.context.refresh(),this.enabled=!0,this},t.prototype.destroy=function(){this.context.remove(this),this.group.remove(this),delete i[this.key]},t.prototype.trigger=function(t){this.enabled&&(this.callback&&this.callback.apply(this,t),this.options.triggerOnce&&this.destroy())},t.prototype.queueTrigger=function(t){this.group.queueTrigger(this,t)},t.adapters=[],t.defaults={context:window,continuous:!0,enabled:!0,group:"default",horizontal:!1,offset:0,triggerOnce:!1},t.offsetAliases={"bottom-in-view":function(){return this.context.height()-this.adapter.outerHeight()},"right-in-view":function(){return this.context.adapter.width()-this.adapter.outerWidth()}},t.viewportHeight=function(){return window.innerHeight||document.documentElement.clientHeight},t.refresh=function(){t.Context.refreshAll()},t.destroyAll=function(){var t=[];for(var e in i)t.push(i[e]);for(var r=0,o=t.length;o>r;r++)t[r].destroy()},window.Waypoint=t}()(function(){"use strict";function t(t){window.setTimeout(t,1e3/60)}function e(t){this.element=t,this.Adapter=o.Adapter,this.adapter=new this.Adapter(t),this.key="waypoint-context-"+i,this.didScroll=!1,this.didResize=!1,this.oldScroll={x:this.adapter.scrollLeft(),y:this.adapter.scrollTop()},this.waypoints={vertical:{},horizontal:{}},t.waypointContextKey=this.key,r[t.waypointContextKey]=this,i+=1,this.createThrottledScrollHandler(),this.createThrottledResizeHandler()}var i=0,r={},o=window.Waypoint,n=window.requestAnimationFrame||window.mozRequestAnimationFrame||window.webkitRequestAnimationFrame||t;e.prototype.createThrottledScrollHandler=function(){function t(){e.handleScroll(),e.didScroll=!1}var e=this;this.adapter.on("scroll.waypoints",function(){(!e.didScroll||o.isTouch)&&(e.didScroll=!0,n(t))})},e.prototype.createThrottledResizeHandler=function(){function t(){e.handleResize(),e.didResize=!1}var e=this;this.adapter.on("resize.waypoints",function(){e.didResize||(e.didResize=!0,n(t))})},e.prototype.handleScroll=function(){var t={},e={horizontal:{newScroll:this.adapter.scrollLeft(),oldScroll:this.oldScroll.x,forward:"right",backward:"left"},vertical:{newScroll:this.adapter.scrollTop(),oldScroll:this.oldScroll.y,forward:"down",backward:"up"}};for(var i in e){var r=e[i],o=r.newScroll>r.oldScroll,n=o?r.forward:r.backward;for(var s in this.waypoints[i]){var a=this.waypoints[i][s],l=r.oldScroll=a.triggerPoint,p=l&&h,f=!l&&!h;(p||f)&&(a.queueTrigger(n),t[a.group.id]=a.group)}}for(var u in t)t[u].flushTriggers();this.oldScroll={x:e.horizontal.newScroll,y:e.vertical.newScroll}},e.prototype.handleResize=function(){o.Context.refreshAll()},e.prototype.refresh=function(){var t,e=this.element===this.element.window,i=this.adapter.offset(),r=e?o.viewportHeight():this.adapter.height(),n={};this.handleScroll(),t={horizontal:{contextOffset:e?0:i.left,contextScroll:e?0:this.oldScroll.x,contextDimension:this.adapter.width(),oldScroll:this.oldScroll.x,forward:"right",backward:"left",offsetProp:"left"},vertical:{contextOffset:e?0:i.top,contextScroll:e?0:this.oldScroll.y,contextDimension:r,oldScroll:this.oldScroll.y,forward:"down",backward:"up",offsetProp:"top"}};for(var s in t){var a=t[s];for(var l in this.waypoints[s]){var h,p=this.waypoints[s][l],f=p.options.offset,u=p.triggerPoint,c=0,d=null==u;p.element!==p.element.window&&(c=p.adapter.offset()[a.offsetProp]),"function"==typeof f?f=f.apply(p):"string"==typeof f&&(f=parseFloat(f),p.options.offset.indexOf("%")>-1&&(f=Math.ceil(a.contextDimension*f/100))),h=a.contextScroll-a.contextOffset,p.triggerPoint=c+h-f;var g=u=a.oldScroll,w=g&&y,m=!g&&!y;!d&&w?(p.queueTrigger(a.backward),n[p.group.id]=p.group):!d&&m?(p.queueTrigger(a.forward),n[p.group.id]=p.group):d&&a.oldScroll>=p.triggerPoint&&(p.queueTrigger(a.forward),n[p.group.id]=p.group)}}for(var v in n)n[v].flushTriggers();return this},e.prototype.destroy=function(){var t=[];for(var e in this.waypoints)for(var i in this.waypoints[e])t.push(this.waypoints[e][i]);for(var r=0,o=t.length;o>r;r++)t[r].destroy()},e.prototype.add=function(t){var e=t.options.horizontal?"horizontal":"vertical";this.waypoints[e][t.key]=t,this.refresh()},e.prototype.remove=function(t){delete this.waypoints[t.axis][t.key],this.checkEmpty()},e.prototype.checkEmpty=function(){var t=this.Adapter.isEmptyObject(this.waypoints.horizontal),e=this.Adapter.isEmptyObject(this.waypoints.vertical);t&&e&&(this.adapter.off(".waypoints"),delete r[this.key])},e.prototype.height=function(){return this.element===this.element.window?o.viewportHeight():this.adapter.height()},e.refreshAll=function(){for(var t in r)r[t].refresh()},e.findByElement=function(t){return r[t.waypointContextKey]},e.findOrCreateByElement=function(t){return e.findByElement(t)||new e(t)},o.Context=e}())(function(){"use strict";function t(t,e){return t.triggerPoint-e.triggerPoint}function e(t,e){return e.triggerPoint-t.triggerPoint}function i(t){this.name=t.name,this.axis=t.axis,this.id=this.name+"-"+this.axis,this.waypoints=[],this.clearTriggerQueues(),r[this.axis][this.name]=this}var r={vertical:{},horizontal:{}},o=window.Waypoint;i.prototype.previous=function(t){this.sort();var e=o.Adapter.inArray(t,this.waypoints);return e?this.waypoints[e-1]:null},i.prototype.next=function(t){this.sort();var e=o.Adapter.inArray(t,this.waypoints),i=e===this.waypoints.length-1;return i?null:this.waypoints[e+1]},i.prototype.first=function(){return this.waypoints[0]},i.prototype.last=function(){return this.waypoints[this.waypoints.length-1]},i.prototype.add=function(t){this.waypoints.push(t)},i.prototype.remove=function(t){var e=o.Adapter.inArray(t,this.waypoints);e>-1&&this.waypoints.splice(e,1)},i.prototype.sort=function(){this.waypoints.sort(function(t,e){return t.triggerPoint-e.triggerPoint})},i.prototype.clearTriggerQueues=function(){this.triggerQueues={up:[],down:[],left:[],right:[]}},i.prototype.queueTrigger=function(t,e){this.triggerQueues[e].push(t)},i.prototype.flushTriggers=function(){for(var i in this.triggerQueues){var r=this.triggerQueues[i],o="up"===i||"left"===i;r.sort(o?e:t);for(var n=0,s=r.length;s>n;n+=1){var a=r[n];(a.options.continuous||n===r.length-1)&&a.trigger([i])}}this.clearTriggerQueues()},i.findOrCreate=function(t){return r[t.axis][t.name]||new i(t)},o.Group=i}())(function(){"use strict";function t(t){return t===t.window}function e(e){return t(e)?e:e.defaultView}function i(t){this.element=t,this.handlers={}}var r=window.Waypoint;i.prototype.height=function(){var e=t(this.element);return e?this.element.innerHeight:this.element.offsetHeight},i.prototype.off=function(t,e){function i(t,e,i){for(var r=0,o=e.length-1;o>r;r++){var n=e[r];i&&i!==n||t.removeEventListener(n)}}var r=t.split("."),o=r[0],n=r[1],s=this.element;if(n&&this.handlers[n]&&o)i(s,this.handlers[n][o],e),this.handlers[n][o]=[];else if(o)for(var a in this.handlers)i(s,this.handlers[a][o]||[],e),this.handlers[a][o]=[];else if(n&&this.handlers[n]){for(var l in this.handlers[n])i(s,this.handlers[n][l],e);this.handlers[n]={}}},i.prototype.offset=function(){if(!this.element.ownerDocument)return null;var t=this.element.ownerDocument.documentElement,i=e(this.element.ownerDocument),r={top:0,left:0};return this.element.getBoundingClientRect&&(r=this.element.getBoundingClientRect()),{top:r.top+i.pageYOffset-t.clientTop,left:r.left+i.pageXOffset-t.clientLeft}},i.prototype.on=function(t,e){var i=t.split("."),r=i[0],o=i[1]||"__default",n=this.handlers[o]=this.handlers[o]||{},s=n[r]=n[r]||[];s.push(e),this.element.addEventListener(r,e)},i.prototype.outerHeight=function(e){var i,r=this.height();return e&&!t(this.element)&&(i=window.getComputedStyle(this.element),r+=parseInt(i.marginTop,10),r+=parseInt(i.marginBottom,10)),r},i.prototype.outerWidth=function(e){var i,r=this.width();return e&&!t(this.element)&&(i=window.getComputedStyle(this.element),r+=parseInt(i.marginLeft,10),r+=parseInt(i.marginRight,10)),r},i.prototype.scrollLeft=function(){var t=e(this.element);return t?t.pageXOffset:this.element.scrollLeft},i.prototype.scrollTop=function(){var t=e(this.element);return t?t.pageYOffset:this.element.scrollTop},i.prototype.width=function(){var e=t(this.element);return e?this.element.innerWidth:this.element.offsetWidth},i.extend=function(){function t(t,e){if("object"==typeof t&&"object"==typeof e)for(var i in e)e.hasOwnProperty(i)&&(t[i]=e[i]);return t}for(var e=Array.prototype.slice.call(arguments),i=1,r=e.length;r>i;i++)t(e[0],e[i]);return e[0]},i.inArray=function(t,e,i){return null==e?-1:e.indexOf(t,i)},i.isEmptyObject=function(t){for(var e in t)return!1;return!0},r.adapters.push({name:"noframework",Adapter:i}),r.Adapter=i}()); \ No newline at end of file +!function(){"use strict";function t(r){if(!r)throw new Error("No options passed to Waypoint constructor");if(!r.element)throw new Error("No element option passed to Waypoint constructor");this.key="waypoint-"+e,this.options=t.Adapter.extend({},t.defaults,r),this.element=this.options.element,this.adapter=new t.Adapter(this.element),this.callback=r.handler,this.axis=this.options.horizontal?"horizontal":"vertical",this.enabled=this.options.enabled,this.triggerPoint=null,this.group=t.Group.findOrCreate({name:this.options.group,axis:this.axis}),this.context=t.Context.findOrCreateByElement(this.options.context),t.offsetAliases[this.options.offset]&&(this.options.offset=t.offsetAliases[this.options.offset]),this.context.add(this),this.group.add(this),i[this.key]=this,e+=1}var e=0,i={};t.prototype.trigger=function(t){this.enabled&&(this.callback&&this.callback.apply(this,t),this.options.triggerOnce&&this.destroy())},t.prototype.queueTrigger=function(t){this.group.queueTrigger(this,t)},t.prototype.disable=function(){return this.enabled=!1,this},t.prototype.enable=function(){return this.context.refresh(),this.enabled=!0,this},t.prototype.destroy=function(){this.context.remove(this),this.group.remove(this),delete i[this.key]},t.destroyAll=function(){var t=[];for(var e in i)t.push(i[e]);for(var r=0,o=t.length;o>r;r++)t[r].destroy()},t.refreshAll=function(){t.Context.refreshAll()},t.viewportHeight=function(){return window.innerHeight||document.documentElement.clientHeight},window.Waypoint=t}()(function(){"use strict";function t(t){window.setTimeout(t,1e3/60)}function e(t){this.element=t,this.Adapter=o.Adapter,this.adapter=new this.Adapter(t),this.key="waypoint-context-"+i,this.didScroll=!1,this.didResize=!1,this.oldScroll={x:this.adapter.scrollLeft(),y:this.adapter.scrollTop()},this.waypoints={vertical:{},horizontal:{}},t.waypointContextKey=this.key,r[t.waypointContextKey]=this,i+=1,this.createThrottledScrollHandler(),this.createThrottledResizeHandler()}var i=0,r={},o=window.Waypoint,n=window.requestAnimationFrame||window.mozRequestAnimationFrame||window.webkitRequestAnimationFrame||t;e.prototype.add=function(t){var e=t.options.horizontal?"horizontal":"vertical";this.waypoints[e][t.key]=t,this.refresh()},e.prototype.checkEmpty=function(){var t=this.Adapter.isEmptyObject(this.waypoints.horizontal),e=this.Adapter.isEmptyObject(this.waypoints.vertical);t&&e&&(this.adapter.off(".waypoints"),delete r[this.key])},e.prototype.createThrottledResizeHandler=function(){function t(){e.handleResize(),e.didResize=!1}var e=this;this.adapter.on("resize.waypoints",function(){e.didResize||(e.didResize=!0,n(t))})},e.prototype.createThrottledScrollHandler=function(){function t(){e.handleScroll(),e.didScroll=!1}var e=this;this.adapter.on("scroll.waypoints",function(){(!e.didScroll||o.isTouch)&&(e.didScroll=!0,n(t))})},e.prototype.handleResize=function(){o.Context.refreshAll()},e.prototype.handleScroll=function(){var t={},e={horizontal:{newScroll:this.adapter.scrollLeft(),oldScroll:this.oldScroll.x,forward:"right",backward:"left"},vertical:{newScroll:this.adapter.scrollTop(),oldScroll:this.oldScroll.y,forward:"down",backward:"up"}};for(var i in e){var r=e[i],o=r.newScroll>r.oldScroll,n=o?r.forward:r.backward;for(var s in this.waypoints[i]){var a=this.waypoints[i][s],l=r.oldScroll=a.triggerPoint,p=l&&h,f=!l&&!h;(p||f)&&(a.queueTrigger(n),t[a.group.id]=a.group)}}for(var u in t)t[u].flushTriggers();this.oldScroll={x:e.horizontal.newScroll,y:e.vertical.newScroll}},e.prototype.height=function(){return this.element===this.element.window?o.viewportHeight():this.adapter.height()},e.prototype.remove=function(t){delete this.waypoints[t.axis][t.key],this.checkEmpty()},e.prototype.destroy=function(){var t=[];for(var e in this.waypoints)for(var i in this.waypoints[e])t.push(this.waypoints[e][i]);for(var r=0,o=t.length;o>r;r++)t[r].destroy()},e.prototype.refresh=function(){var t,e=this.element===this.element.window,i=this.adapter.offset(),r=e?o.viewportHeight():this.adapter.height(),n={};this.handleScroll(),t={horizontal:{contextOffset:e?0:i.left,contextScroll:e?0:this.oldScroll.x,contextDimension:this.adapter.width(),oldScroll:this.oldScroll.x,forward:"right",backward:"left",offsetProp:"left"},vertical:{contextOffset:e?0:i.top,contextScroll:e?0:this.oldScroll.y,contextDimension:r,oldScroll:this.oldScroll.y,forward:"down",backward:"up",offsetProp:"top"}};for(var s in t){var a=t[s];for(var l in this.waypoints[s]){var h,p,f,u,c,d=this.waypoints[s][l],g=d.options.offset,y=d.triggerPoint,w=0,m=null==y;d.element!==d.element.window&&(w=d.adapter.offset()[a.offsetProp]),"function"==typeof g?g=g.apply(d):"string"==typeof g&&(g=parseFloat(g),d.options.offset.indexOf("%")>-1&&(g=Math.ceil(a.contextDimension*g/100))),h=a.contextScroll-a.contextOffset,d.triggerPoint=w+h-g,p=y=a.oldScroll,u=p&&f,c=!p&&!f,!m&&u?(d.queueTrigger(a.backward),n[d.group.id]=d.group):!m&&c?(d.queueTrigger(a.forward),n[d.group.id]=d.group):m&&a.oldScroll>=d.triggerPoint&&(d.queueTrigger(a.forward),n[d.group.id]=d.group)}}for(var v in n)n[v].flushTriggers();return this},e.findOrCreateByElement=function(t){return e.findByElement(t)||new e(t)},e.findByElement=function(t){return r[t.waypointContextKey]},e.refreshAll=function(){for(var t in r)r[t].refresh()},o.Context=e}())(function(){"use strict";function t(t,e){return t.triggerPoint-e.triggerPoint}function e(t,e){return e.triggerPoint-t.triggerPoint}function i(t){this.name=t.name,this.axis=t.axis,this.id=this.name+"-"+this.axis,this.waypoints=[],this.clearTriggerQueues(),r[this.axis][this.name]=this}var r={vertical:{},horizontal:{}},o=window.Waypoint;i.prototype.add=function(t){this.waypoints.push(t)},i.prototype.clearTriggerQueues=function(){this.triggerQueues={up:[],down:[],left:[],right:[]}},i.prototype.flushTriggers=function(){for(var i in this.triggerQueues){var r=this.triggerQueues[i],o="up"===i||"left"===i;r.sort(o?e:t);for(var n=0,s=r.length;s>n;n+=1){var a=r[n];(a.options.continuous||n===r.length-1)&&a.trigger([i])}}this.clearTriggerQueues()},i.prototype.queueTrigger=function(t,e){this.triggerQueues[e].push(t)},i.prototype.remove=function(t){var e=o.Adapter.inArray(t,this.waypoints);e>-1&&this.waypoints.splice(e,1)},i.prototype.sort=function(){this.waypoints.sort(function(t,e){return t.triggerPoint-e.triggerPoint})},i.prototype.first=function(){return this.waypoints[0]},i.prototype.last=function(){return this.waypoints[this.waypoints.length-1]},i.prototype.next=function(t){this.sort();var e=o.Adapter.inArray(t,this.waypoints),i=e===this.waypoints.length-1;return i?null:this.waypoints[e+1]},i.prototype.previous=function(t){this.sort();var e=o.Adapter.inArray(t,this.waypoints);return e?this.waypoints[e-1]:null},i.findOrCreate=function(t){return r[t.axis][t.name]||new i(t)},o.Group=i}())(function(){"use strict";function t(t){return t===t.window}function e(e){return t(e)?e:e.defaultView}function i(t){this.element=t,this.handlers={}}var r=window.Waypoint;i.prototype.height=function(){var e=t(this.element);return e?this.element.innerHeight:this.element.offsetHeight},i.prototype.off=function(t,e){function i(t,e,i){for(var r=0,o=e.length-1;o>r;r++){var n=e[r];i&&i!==n||t.removeEventListener(n)}}var r=t.split("."),o=r[0],n=r[1],s=this.element;if(n&&this.handlers[n]&&o)i(s,this.handlers[n][o],e),this.handlers[n][o]=[];else if(o)for(var a in this.handlers)i(s,this.handlers[a][o]||[],e),this.handlers[a][o]=[];else if(n&&this.handlers[n]){for(var l in this.handlers[n])i(s,this.handlers[n][l],e);this.handlers[n]={}}},i.prototype.offset=function(){if(!this.element.ownerDocument)return null;var t=this.element.ownerDocument.documentElement,i=e(this.element.ownerDocument),r={top:0,left:0};return this.element.getBoundingClientRect&&(r=this.element.getBoundingClientRect()),{top:r.top+i.pageYOffset-t.clientTop,left:r.left+i.pageXOffset-t.clientLeft}},i.prototype.on=function(t,e){var i=t.split("."),r=i[0],o=i[1]||"__default",n=this.handlers[o]=this.handlers[o]||{},s=n[r]=n[r]||[];s.push(e),this.element.addEventListener(r,e)},i.prototype.outerHeight=function(e){var i,r=this.height();return e&&!t(this.element)&&(i=window.getComputedStyle(this.element),r+=parseInt(i.marginTop,10),r+=parseInt(i.marginBottom,10)),r},i.prototype.outerWidth=function(e){var i,r=this.width();return e&&!t(this.element)&&(i=window.getComputedStyle(this.element),r+=parseInt(i.marginLeft,10),r+=parseInt(i.marginRight,10)),r},i.prototype.scrollLeft=function(){var t=e(this.element);return t?t.pageXOffset:this.element.scrollLeft},i.prototype.scrollTop=function(){var t=e(this.element);return t?t.pageYOffset:this.element.scrollTop},i.prototype.width=function(){var e=t(this.element);return e?this.element.innerWidth:this.element.offsetWidth},i.extend=function(){function t(t,e){if("object"==typeof t&&"object"==typeof e)for(var i in e)e.hasOwnProperty(i)&&(t[i]=e[i]);return t}for(var e=Array.prototype.slice.call(arguments),i=1,r=e.length;r>i;i++)t(e[0],e[i]);return e[0]},i.inArray=function(t,e,i){return null==e?-1:e.indexOf(t,i)},i.isEmptyObject=function(t){for(var e in t)return!1;return!0},r.adapters.push({name:"noframework",Adapter:i}),r.Adapter=i}()); \ No newline at end of file diff --git a/lib/shortcuts/infinite.js b/lib/shortcuts/infinite.js index db5da9cc..350b2ffc 100644 --- a/lib/shortcuts/infinite.js +++ b/lib/shortcuts/infinite.js @@ -26,13 +26,7 @@ https://github.com/imakewebthings/waypoints/blog/master/licenses.txt } } - Infinite.prototype.destroy = function() { - if (this.waypoint) { - this.waypoint.destroy() - } - } - - /* Internal */ + /* Private */ Infinite.prototype.setupHandler = function() { this.options.handler = $.proxy(function() { window.setTimeout($.proxy(function() { @@ -64,6 +58,13 @@ https://github.com/imakewebthings/waypoints/blog/master/licenses.txt }, this) } + /* Public */ + Infinite.prototype.destroy = function() { + if (this.waypoint) { + this.waypoint.destroy() + } + } + Infinite.defaults = { container: 'auto', items: '.infinite-item', diff --git a/lib/shortcuts/infinite.min.js b/lib/shortcuts/infinite.min.js index 708050bf..ee53dc2d 100644 --- a/lib/shortcuts/infinite.min.js +++ b/lib/shortcuts/infinite.min.js @@ -4,4 +4,4 @@ Copyright © 2011-2014 Caleb Troughton Licensed under the MIT license. https://github.com/imakewebthings/waypoints/blog/master/licenses.txt */ -!function(){"use strict";function t(n){this.options=i.extend({},t.defaults,n),this.container=this.options.element,"auto"!==this.options.container&&(this.container=this.options.container),this.$container=i(this.container),this.$more=i(this.options.more),this.more=this.$more[0],this.more&&(this.setupHandler(),this.waypoint=new o(this.options))}var i=window.jQuery,o=window.Waypoint;t.prototype.destroy=function(){this.waypoint&&this.waypoint.destroy()},t.prototype.setupHandler=function(){this.options.handler=i.proxy(function(){window.setTimeout(i.proxy(function(){this.options.onBeforePageLoad(),this.destroy(),this.$container.addClass(this.options.loadingClass),i.get(i(this.options.more).attr("href"),i.proxy(function(t){var n=i(i.parseHTML(t)),s=n.find(this.options.more);this.$container.append(n.find(this.options.items)),this.$container.removeClass(this.options.loadingClass),s.length||(s=n.filter(this.options.more)),s.length?(this.$more.replaceWith(s),this.waypoint=new o(this.options)):this.$more.remove(),this.options.onAfterPageLoad()},this),0)},this))},this)},t.defaults={container:"auto",items:".infinite-item",more:".infinite-more-link",offset:"bottom-in-view",loadingClass:"infinite-loading",onBeforePageLoad:i.noop,onAfterPageLoad:i.noop},o.Infinite=t}(); \ No newline at end of file +!function(){"use strict";function t(n){this.options=i.extend({},t.defaults,n),this.container=this.options.element,"auto"!==this.options.container&&(this.container=this.options.container),this.$container=i(this.container),this.$more=i(this.options.more),this.more=this.$more[0],this.more&&(this.setupHandler(),this.waypoint=new o(this.options))}var i=window.jQuery,o=window.Waypoint;t.prototype.setupHandler=function(){this.options.handler=i.proxy(function(){window.setTimeout(i.proxy(function(){this.options.onBeforePageLoad(),this.destroy(),this.$container.addClass(this.options.loadingClass),i.get(i(this.options.more).attr("href"),i.proxy(function(t){var n=i(i.parseHTML(t)),s=n.find(this.options.more);this.$container.append(n.find(this.options.items)),this.$container.removeClass(this.options.loadingClass),s.length||(s=n.filter(this.options.more)),s.length?(this.$more.replaceWith(s),this.waypoint=new o(this.options)):this.$more.remove(),this.options.onAfterPageLoad()},this),0)},this))},this)},t.prototype.destroy=function(){this.waypoint&&this.waypoint.destroy()},t.defaults={container:"auto",items:".infinite-item",more:".infinite-more-link",offset:"bottom-in-view",loadingClass:"infinite-loading",onBeforePageLoad:i.noop,onAfterPageLoad:i.noop},o.Infinite=t}(); \ No newline at end of file diff --git a/lib/shortcuts/inview.js b/lib/shortcuts/inview.js index 2854f8f4..9d512ccf 100644 --- a/lib/shortcuts/inview.js +++ b/lib/shortcuts/inview.js @@ -7,10 +7,10 @@ https://github.com/imakewebthings/waypoints/blog/master/licenses.txt (function() { 'use strict' - var Waypoint = window.Waypoint - function noop() {} + var Waypoint = window.Waypoint + function Inview(options) { this.options = Waypoint.Adapter.extend({}, Inview.defaults, options) this.axis = this.options.horizontal ? 'horizontal' : 'vertical' @@ -18,14 +18,7 @@ https://github.com/imakewebthings/waypoints/blog/master/licenses.txt this.createWaypoints() } - Inview.prototype.destroy = function() { - for (var i = 0, end = this.waypoints.length; i < end; i++) { - this.waypoints[i].destroy() - } - this.waypoints = [] - } - - /* Internal */ + /* Private */ Inview.prototype.createWaypoints = function() { var configs = { vertical: [{ @@ -74,7 +67,7 @@ https://github.com/imakewebthings/waypoints/blog/master/licenses.txt } } - /* Internal */ + /* Private */ Inview.prototype.createWaypoint = function(config) { var self = this this.waypoints.push(new Waypoint({ @@ -89,6 +82,14 @@ https://github.com/imakewebthings/waypoints/blog/master/licenses.txt })) } + /* Public */ + Inview.prototype.destroy = function() { + for (var i = 0, end = this.waypoints.length; i < end; i++) { + this.waypoints[i].destroy() + } + this.waypoints = [] + } + Inview.defaults = { enter: noop, entered: noop, diff --git a/lib/shortcuts/inview.min.js b/lib/shortcuts/inview.min.js index ef84e503..03156626 100644 --- a/lib/shortcuts/inview.min.js +++ b/lib/shortcuts/inview.min.js @@ -4,4 +4,4 @@ Copyright © 2011-2014 Caleb Troughton Licensed under the MIT license. https://github.com/imakewebthings/waypoints/blog/master/licenses.txt */ -!function(){"use strict";function t(){}function e(t){this.options=i.Adapter.extend({},e.defaults,t),this.axis=this.options.horizontal?"horizontal":"vertical",this.waypoints=[],this.createWaypoints()}var i=window.Waypoint;e.prototype.destroy=function(){for(var t=0,e=this.waypoints.length;e>t;t++)this.waypoints[t].destroy();this.waypoints=[]},e.prototype.createWaypoints=function(){for(var t={vertical:[{down:"enter",up:"exited",offset:"100%"},{down:"entered",up:"exit",offset:"bottom-in-view"},{down:"exit",up:"entered",offset:0},{down:"exited",up:"enter",offset:function(){return-this.adapter.outerHeight()}}],horizontal:[{right:"enter",left:"exited",offset:"100%"},{right:"entered",left:"exit",offset:"right-in-view"},{right:"exit",left:"entered",offset:0},{right:"exited",left:"enter",offset:function(){return-this.adapter.outerWidth()}}]},e=0,i=t[this.axis].length;i>e;e++){var o=t[this.axis][e];this.createWaypoint(o)}},e.prototype.createWaypoint=function(t){var e=this;this.waypoints.push(new i({element:this.options.element,handler:function(t){return function(i){e.options[t[i]].call(this,i)}}(t),offset:t.offset,horizontal:this.options.horizontal}))},e.defaults={enter:t,entered:t,exit:t,exited:t},i.Inview=e}(); \ No newline at end of file +!function(){"use strict";function t(){}function e(t){this.options=i.Adapter.extend({},e.defaults,t),this.axis=this.options.horizontal?"horizontal":"vertical",this.waypoints=[],this.createWaypoints()}var i=window.Waypoint;e.prototype.createWaypoints=function(){for(var t={vertical:[{down:"enter",up:"exited",offset:"100%"},{down:"entered",up:"exit",offset:"bottom-in-view"},{down:"exit",up:"entered",offset:0},{down:"exited",up:"enter",offset:function(){return-this.adapter.outerHeight()}}],horizontal:[{right:"enter",left:"exited",offset:"100%"},{right:"entered",left:"exit",offset:"right-in-view"},{right:"exit",left:"entered",offset:0},{right:"exited",left:"enter",offset:function(){return-this.adapter.outerWidth()}}]},e=0,i=t[this.axis].length;i>e;e++){var o=t[this.axis][e];this.createWaypoint(o)}},e.prototype.createWaypoint=function(t){var e=this;this.waypoints.push(new i({element:this.options.element,handler:function(t){return function(i){e.options[t[i]].call(this,i)}}(t),offset:t.offset,horizontal:this.options.horizontal}))},e.prototype.destroy=function(){for(var t=0,e=this.waypoints.length;e>t;t++)this.waypoints[t].destroy();this.waypoints=[]},e.defaults={enter:t,entered:t,exit:t,exited:t},i.Inview=e}(); \ No newline at end of file diff --git a/lib/shortcuts/sticky.js b/lib/shortcuts/sticky.js index f0142571..8576873c 100644 --- a/lib/shortcuts/sticky.js +++ b/lib/shortcuts/sticky.js @@ -18,19 +18,7 @@ https://github.com/imakewebthings/waypoints/blog/master/licenses.txt this.createWaypoint() } - Sticky.prototype.destroy = function() { - this.waypoint.destroy() - this.$element.removeClass(this.options.stuckClass).unwrap() - } - - /* Internal */ - Sticky.prototype.createWrapper = function() { - this.$element.wrap(this.options.wrapper) - this.$wrapper = this.$element.parent() - this.wrapper = this.$wrapper[0] - } - - /* Internal */ + /* Private */ Sticky.prototype.createWaypoint = function() { var originalHandler = this.options.handler @@ -50,6 +38,19 @@ https://github.com/imakewebthings/waypoints/blog/master/licenses.txt })) } + /* Private */ + Sticky.prototype.createWrapper = function() { + this.$element.wrap(this.options.wrapper) + this.$wrapper = this.$element.parent() + this.wrapper = this.$wrapper[0] + } + + /* Public */ + Sticky.prototype.destroy = function() { + this.waypoint.destroy() + this.$element.removeClass(this.options.stuckClass).unwrap() + } + Sticky.defaults = { wrapper: '
', stuckClass: 'stuck', diff --git a/lib/shortcuts/sticky.min.js b/lib/shortcuts/sticky.min.js index d9fb0dcc..86d4fa2d 100644 --- a/lib/shortcuts/sticky.min.js +++ b/lib/shortcuts/sticky.min.js @@ -4,4 +4,4 @@ Copyright © 2011-2014 Caleb Troughton Licensed under the MIT license. https://github.com/imakewebthings/waypoints/blog/master/licenses.txt */ -!function(){"use strict";function t(s){this.options=e.extend({},i.defaults,t.defaults,s),this.element=this.options.element,this.$element=e(this.element),this.createWrapper(),this.createWaypoint()}var e=window.jQuery,i=window.Waypoint;t.prototype.destroy=function(){this.waypoint.destroy(),this.$element.removeClass(this.options.stuckClass).unwrap()},t.prototype.createWrapper=function(){this.$element.wrap(this.options.wrapper),this.$wrapper=this.$element.parent(),this.wrapper=this.$wrapper[0]},t.prototype.createWaypoint=function(){var t=this.options.handler;this.waypoint=new i(e.extend({},this.options,{element:this.wrapper,handler:e.proxy(function(e){var i=this.options.direction.indexOf(e)>-1,s=i?this.$element.outerHeight(!0):"";this.$element.toggleClass(this.options.stuckClass,i),this.$wrapper.height(s),t&&t.call(this,e)},this)}))},t.defaults={wrapper:'
',stuckClass:"stuck",direction:"down right"},i.Sticky=t}(); \ No newline at end of file +!function(){"use strict";function t(s){this.options=e.extend({},i.defaults,t.defaults,s),this.element=this.options.element,this.$element=e(this.element),this.createWrapper(),this.createWaypoint()}var e=window.jQuery,i=window.Waypoint;t.prototype.createWaypoint=function(){var t=this.options.handler;this.waypoint=new i(e.extend({},this.options,{element:this.wrapper,handler:e.proxy(function(e){var i=this.options.direction.indexOf(e)>-1,s=i?this.$element.outerHeight(!0):"";this.$element.toggleClass(this.options.stuckClass,i),this.$wrapper.height(s),t&&t.call(this,e)},this)}))},t.prototype.createWrapper=function(){this.$element.wrap(this.options.wrapper),this.$wrapper=this.$element.parent(),this.wrapper=this.$wrapper[0]},t.prototype.destroy=function(){this.waypoint.destroy(),this.$element.removeClass(this.options.stuckClass).unwrap()},t.defaults={wrapper:'
',stuckClass:"stuck",direction:"down right"},i.Sticky=t}(); \ No newline at end of file diff --git a/lib/zepto.waypoints.js b/lib/zepto.waypoints.js index a6e0e5c4..e37b0a86 100644 --- a/lib/zepto.waypoints.js +++ b/lib/zepto.waypoints.js @@ -41,39 +41,63 @@ https://github.com/imakewebthings/waypoints/blog/master/licenses.txt keyCounter += 1 } + /* Private */ + Waypoint.prototype.trigger = function(args) { + if (!this.enabled) { + return + } + if (this.callback) { + this.callback.apply(this, args) + } + if (this.options.triggerOnce) { + this.destroy() + } + } + + /* Private */ + Waypoint.prototype.queueTrigger = function(direction) { + this.group.queueTrigger(this, direction) + } + + /* Public */ Waypoint.prototype.disable = function() { this.enabled = false return this } + /* Public */ Waypoint.prototype.enable = function() { this.context.refresh() this.enabled = true return this } + /* Public */ Waypoint.prototype.destroy = function() { this.context.remove(this) this.group.remove(this) delete allWaypoints[this.key] } - /* Internal */ - Waypoint.prototype.trigger = function(args) { - if (!this.enabled) { - return - } - if (this.callback) { - this.callback.apply(this, args) + /* Public */ + Waypoint.destroyAll = function() { + var allWaypointsArray = [] + for (var waypointKey in allWaypoints) { + allWaypointsArray.push(allWaypoints[waypointKey]) } - if (this.options.triggerOnce) { - this.destroy() + for (var i = 0, end = allWaypointsArray.length; i < end; i++) { + allWaypointsArray[i].destroy() } } - /* Internal */ - Waypoint.prototype.queueTrigger = function(direction) { - this.group.queueTrigger(this, direction) + /* Public */ + Waypoint.refreshAll = function() { + Waypoint.Context.refreshAll() + } + + /* Public */ + Waypoint.viewportHeight = function() { + return window.innerHeight || document.documentElement.clientHeight } Waypoint.adapters = [] @@ -96,24 +120,7 @@ https://github.com/imakewebthings/waypoints/blog/master/licenses.txt return this.context.adapter.width() - this.adapter.outerWidth() } } - - Waypoint.viewportHeight = function() { - return window.innerHeight || document.documentElement.clientHeight - } - - Waypoint.refresh = function() { - Waypoint.Context.refreshAll() - } - - Waypoint.destroyAll = function() { - var allWaypointsArray = [] - for (var waypointKey in allWaypoints) { - allWaypointsArray.push(allWaypoints[waypointKey]) - } - for (var i = 0, end = allWaypointsArray.length; i < end; i++) { - allWaypointsArray[i].destroy() - } - } + } window.Waypoint = Waypoint }()) @@ -128,7 +135,6 @@ https://github.com/imakewebthings/waypoints/blog/master/licenses.txt var keyCounter = 0 var contexts = {} var Waypoint = window.Waypoint - var requestAnimationFrame = window.requestAnimationFrame || window.mozRequestAnimationFrame || window.webkitRequestAnimationFrame || @@ -158,23 +164,24 @@ https://github.com/imakewebthings/waypoints/blog/master/licenses.txt this.createThrottledResizeHandler() } - /* Internal */ - Context.prototype.createThrottledScrollHandler = function() { - var self = this - function scrollHandler() { - self.handleScroll() - self.didScroll = false - } + /* Private */ + Context.prototype.add = function(waypoint) { + var axis = waypoint.options.horizontal ? 'horizontal' : 'vertical' + this.waypoints[axis][waypoint.key] = waypoint + this.refresh() + } - this.adapter.on('scroll.waypoints', function() { - if (!self.didScroll || Waypoint.isTouch) { - self.didScroll = true - requestAnimationFrame(scrollHandler) - } - }) + /* Private */ + Context.prototype.checkEmpty = function() { + var horizontalEmpty = this.Adapter.isEmptyObject(this.waypoints.horizontal) + var verticalEmpty = this.Adapter.isEmptyObject(this.waypoints.vertical) + if (horizontalEmpty && verticalEmpty) { + this.adapter.off('.waypoints') + delete contexts[this.key] + } } - /* Internal */ + /* Private */ Context.prototype.createThrottledResizeHandler = function() { var self = this @@ -191,7 +198,28 @@ https://github.com/imakewebthings/waypoints/blog/master/licenses.txt }) } - /* Internal */ + /* Private */ + Context.prototype.createThrottledScrollHandler = function() { + var self = this + function scrollHandler() { + self.handleScroll() + self.didScroll = false + } + + this.adapter.on('scroll.waypoints', function() { + if (!self.didScroll || Waypoint.isTouch) { + self.didScroll = true + requestAnimationFrame(scrollHandler) + } + }) + } + + /* Private */ + Context.prototype.handleResize = function() { + Waypoint.Context.refreshAll() + } + + /* Private */ Context.prototype.handleScroll = function() { var triggeredGroups = {} var axes = { @@ -237,11 +265,34 @@ https://github.com/imakewebthings/waypoints/blog/master/licenses.txt } } - /* Internal */ - Context.prototype.handleResize = function() { - Waypoint.Context.refreshAll() + /* Private */ + Context.prototype.height = function() { + if (this.element === this.element.window) { + return Waypoint.viewportHeight() + } + return this.adapter.height() + } + + /* Private */ + Context.prototype.remove = function(waypoint) { + delete this.waypoints[waypoint.axis][waypoint.key] + this.checkEmpty() + } + + /* Public */ + Context.prototype.destroy = function() { + var allWaypoints = [] + for (var axis in this.waypoints) { + for (var waypointKey in this.waypoints[axis]) { + allWaypoints.push(this.waypoints[axis][waypointKey]) + } + } + for (var i = 0, end = allWaypoints.length; i < end; i++) { + allWaypoints[i].destroy() + } } + /* Public */ Context.prototype.refresh = function() { var isWindow = this.element === this.element.window var contextOffset = this.adapter.offset() @@ -279,7 +330,8 @@ https://github.com/imakewebthings/waypoints/blog/master/licenses.txt var oldTriggerPoint = waypoint.triggerPoint var elementOffset = 0 var freshWaypoint = oldTriggerPoint == null - var contextModifier + var contextModifier, wasBeforeScroll, nowAfterScroll + var triggeredBackward, triggeredForward if (waypoint.element !== waypoint.element.window) { elementOffset = waypoint.adapter.offset()[axis.offsetProp] @@ -297,11 +349,11 @@ https://github.com/imakewebthings/waypoints/blog/master/licenses.txt contextModifier = axis.contextScroll - axis.contextOffset waypoint.triggerPoint = elementOffset + contextModifier - adjustment + wasBeforeScroll = oldTriggerPoint < axis.oldScroll + nowAfterScroll = waypoint.triggerPoint >= axis.oldScroll + triggeredBackward = wasBeforeScroll && nowAfterScroll + triggeredForward = !wasBeforeScroll && !nowAfterScroll - var wasBeforeScroll = oldTriggerPoint < axis.oldScroll - var nowAfterScroll = waypoint.triggerPoint >= axis.oldScroll - var triggeredBackward = wasBeforeScroll && nowAfterScroll - var triggeredForward = !wasBeforeScroll && !nowAfterScroll if (!freshWaypoint && triggeredBackward) { waypoint.queueTrigger(axis.backward) triggeredGroups[waypoint.group.id] = waypoint.group @@ -324,77 +376,29 @@ https://github.com/imakewebthings/waypoints/blog/master/licenses.txt return this } - Context.prototype.destroy = function() { - var allWaypoints = [] - for (var axis in this.waypoints) { - for (var waypointKey in this.waypoints[axis]) { - allWaypoints.push(this.waypoints[axis][waypointKey]) - } - } - for (var i = 0, end = allWaypoints.length; i < end; i++) { - allWaypoints[i].destroy() - } - } - - /* Internal */ - Context.prototype.add = function(waypoint) { - var axis = waypoint.options.horizontal ? 'horizontal' : 'vertical' - this.waypoints[axis][waypoint.key] = waypoint - this.refresh() - } - - /* Internal */ - Context.prototype.remove = function(waypoint) { - delete this.waypoints[waypoint.axis][waypoint.key] - this.checkEmpty() - } - - /* Internal */ - Context.prototype.checkEmpty = function() { - var horizontalEmpty = this.Adapter.isEmptyObject(this.waypoints.horizontal) - var verticalEmpty = this.Adapter.isEmptyObject(this.waypoints.vertical) - if (horizontalEmpty && verticalEmpty) { - this.adapter.off('.waypoints') - delete contexts[this.key] - } + /* Private */ + Context.findOrCreateByElement = function(element) { + return Context.findByElement(element) || new Context(element) } - /* Internal */ - Context.prototype.height = function() { - if (this.element === this.element.window) { - return Waypoint.viewportHeight() - } - return this.adapter.height() + /* Public */ + Context.findByElement = function(element) { + return contexts[element.waypointContextKey] } + /* Public */ Context.refreshAll = function() { for (var contextId in contexts) { contexts[contextId].refresh() } } - /* Internal */ - Context.findByElement = function(element) { - return contexts[element.waypointContextKey] - } - - /* Internal */ - Context.findOrCreateByElement = function(element) { - return Context.findByElement(element) || new Context(element) - } - Waypoint.Context = Context }()) (function() { 'use strict' - var groups = { - vertical: {}, - horizontal: {} - } - var Waypoint = window.Waypoint - function byTriggerPoint(a, b) { return a.triggerPoint - b.triggerPoint } @@ -403,6 +407,12 @@ https://github.com/imakewebthings/waypoints/blog/master/licenses.txt return b.triggerPoint - a.triggerPoint } + var groups = { + vertical: {}, + horizontal: {} + } + var Waypoint = window.Waypoint + function Group(options) { this.name = options.name this.axis = options.axis @@ -412,48 +422,12 @@ https://github.com/imakewebthings/waypoints/blog/master/licenses.txt groups[this.axis][this.name] = this } - Group.prototype.previous = function(waypoint) { - this.sort() - var index = Waypoint.Adapter.inArray(waypoint, this.waypoints) - return index ? this.waypoints[index - 1] : null - } - - Group.prototype.next = function(waypoint) { - this.sort() - var index = Waypoint.Adapter.inArray(waypoint, this.waypoints) - var isLast = index === this.waypoints.length - 1 - return isLast ? null : this.waypoints[index + 1] - } - - Group.prototype.first = function() { - return this.waypoints[0] - } - - Group.prototype.last = function() { - return this.waypoints[this.waypoints.length - 1] - } - - /* Internal */ + /* Private */ Group.prototype.add = function(waypoint) { this.waypoints.push(waypoint) } - /* Internal */ - Group.prototype.remove = function(waypoint) { - var index = Waypoint.Adapter.inArray(waypoint, this.waypoints) - if (index > -1) { - this.waypoints.splice(index, 1) - } - } - - /* Internal */ - Group.prototype.sort = function() { - this.waypoints.sort(function(a, b) { - return a.triggerPoint - b.triggerPoint - }) - } - - /* Internal */ + /* Private */ Group.prototype.clearTriggerQueues = function() { this.triggerQueues = { up: [], @@ -463,12 +437,7 @@ https://github.com/imakewebthings/waypoints/blog/master/licenses.txt } } - /* Internal */ - Group.prototype.queueTrigger = function(waypoint, direction) { - this.triggerQueues[direction].push(waypoint) - } - - /* Internal */ + /* Private */ Group.prototype.flushTriggers = function() { for (var direction in this.triggerQueues) { var waypoints = this.triggerQueues[direction] @@ -484,7 +453,52 @@ https://github.com/imakewebthings/waypoints/blog/master/licenses.txt this.clearTriggerQueues() } - /* Internal */ + /* Private */ + Group.prototype.queueTrigger = function(waypoint, direction) { + this.triggerQueues[direction].push(waypoint) + } + + /* Private */ + Group.prototype.remove = function(waypoint) { + var index = Waypoint.Adapter.inArray(waypoint, this.waypoints) + if (index > -1) { + this.waypoints.splice(index, 1) + } + } + + /* Private */ + Group.prototype.sort = function() { + this.waypoints.sort(function(a, b) { + return a.triggerPoint - b.triggerPoint + }) + } + + /* Public */ + Group.prototype.first = function() { + return this.waypoints[0] + } + + /* Public */ + Group.prototype.last = function() { + return this.waypoints[this.waypoints.length - 1] + } + + /* Public */ + Group.prototype.next = function(waypoint) { + this.sort() + var index = Waypoint.Adapter.inArray(waypoint, this.waypoints) + var isLast = index === this.waypoints.length - 1 + return isLast ? null : this.waypoints[index + 1] + } + + /* Public */ + Group.prototype.previous = function(waypoint) { + this.sort() + var index = Waypoint.Adapter.inArray(waypoint, this.waypoints) + return index ? this.waypoints[index - 1] : null + } + + /* Private */ Group.findOrCreate = function(options) { return groups[options.axis][options.name] || new Group(options) } diff --git a/lib/zepto.waypoints.min.js b/lib/zepto.waypoints.min.js index fcf8d9b5..9f128bc5 100644 --- a/lib/zepto.waypoints.min.js +++ b/lib/zepto.waypoints.min.js @@ -4,4 +4,4 @@ Copyright © 2011-2014 Caleb Troughton Licensed under the MIT license. https://github.com/imakewebthings/waypoints/blog/master/licenses.txt */ -!function(){"use strict";function t(o){if(!o)throw new Error("No options passed to Waypoint constructor");if(!o.element)throw new Error("No element option passed to Waypoint constructor");this.key="waypoint-"+e,this.options=t.Adapter.extend({},t.defaults,o),this.element=this.options.element,this.adapter=new t.Adapter(this.element),this.callback=o.handler,this.axis=this.options.horizontal?"horizontal":"vertical",this.enabled=this.options.enabled,this.triggerPoint=null,this.group=t.Group.findOrCreate({name:this.options.group,axis:this.axis}),this.context=t.Context.findOrCreateByElement(this.options.context),t.offsetAliases[this.options.offset]&&(this.options.offset=t.offsetAliases[this.options.offset]),this.context.add(this),this.group.add(this),i[this.key]=this,e+=1}var e=0,i={};t.prototype.disable=function(){return this.enabled=!1,this},t.prototype.enable=function(){return this.context.refresh(),this.enabled=!0,this},t.prototype.destroy=function(){this.context.remove(this),this.group.remove(this),delete i[this.key]},t.prototype.trigger=function(t){this.enabled&&(this.callback&&this.callback.apply(this,t),this.options.triggerOnce&&this.destroy())},t.prototype.queueTrigger=function(t){this.group.queueTrigger(this,t)},t.adapters=[],t.defaults={context:window,continuous:!0,enabled:!0,group:"default",horizontal:!1,offset:0,triggerOnce:!1},t.offsetAliases={"bottom-in-view":function(){return this.context.height()-this.adapter.outerHeight()},"right-in-view":function(){return this.context.adapter.width()-this.adapter.outerWidth()}},t.viewportHeight=function(){return window.innerHeight||document.documentElement.clientHeight},t.refresh=function(){t.Context.refreshAll()},t.destroyAll=function(){var t=[];for(var e in i)t.push(i[e]);for(var o=0,r=t.length;r>o;o++)t[o].destroy()},window.Waypoint=t}()(function(){"use strict";function t(t){window.setTimeout(t,1e3/60)}function e(t){this.element=t,this.Adapter=r.Adapter,this.adapter=new this.Adapter(t),this.key="waypoint-context-"+i,this.didScroll=!1,this.didResize=!1,this.oldScroll={x:this.adapter.scrollLeft(),y:this.adapter.scrollTop()},this.waypoints={vertical:{},horizontal:{}},t.waypointContextKey=this.key,o[t.waypointContextKey]=this,i+=1,this.createThrottledScrollHandler(),this.createThrottledResizeHandler()}var i=0,o={},r=window.Waypoint,n=window.requestAnimationFrame||window.mozRequestAnimationFrame||window.webkitRequestAnimationFrame||t;e.prototype.createThrottledScrollHandler=function(){function t(){e.handleScroll(),e.didScroll=!1}var e=this;this.adapter.on("scroll.waypoints",function(){(!e.didScroll||r.isTouch)&&(e.didScroll=!0,n(t))})},e.prototype.createThrottledResizeHandler=function(){function t(){e.handleResize(),e.didResize=!1}var e=this;this.adapter.on("resize.waypoints",function(){e.didResize||(e.didResize=!0,n(t))})},e.prototype.handleScroll=function(){var t={},e={horizontal:{newScroll:this.adapter.scrollLeft(),oldScroll:this.oldScroll.x,forward:"right",backward:"left"},vertical:{newScroll:this.adapter.scrollTop(),oldScroll:this.oldScroll.y,forward:"down",backward:"up"}};for(var i in e){var o=e[i],r=o.newScroll>o.oldScroll,n=r?o.forward:o.backward;for(var s in this.waypoints[i]){var a=this.waypoints[i][s],l=o.oldScroll=a.triggerPoint,p=l&&h,c=!l&&!h;(p||c)&&(a.queueTrigger(n),t[a.group.id]=a.group)}}for(var u in t)t[u].flushTriggers();this.oldScroll={x:e.horizontal.newScroll,y:e.vertical.newScroll}},e.prototype.handleResize=function(){r.Context.refreshAll()},e.prototype.refresh=function(){var t,e=this.element===this.element.window,i=this.adapter.offset(),o=e?r.viewportHeight():this.adapter.height(),n={};this.handleScroll(),t={horizontal:{contextOffset:e?0:i.left,contextScroll:e?0:this.oldScroll.x,contextDimension:this.adapter.width(),oldScroll:this.oldScroll.x,forward:"right",backward:"left",offsetProp:"left"},vertical:{contextOffset:e?0:i.top,contextScroll:e?0:this.oldScroll.y,contextDimension:o,oldScroll:this.oldScroll.y,forward:"down",backward:"up",offsetProp:"top"}};for(var s in t){var a=t[s];for(var l in this.waypoints[s]){var h,p=this.waypoints[s][l],c=p.options.offset,u=p.triggerPoint,d=0,f=null==u;p.element!==p.element.window&&(d=p.adapter.offset()[a.offsetProp]),"function"==typeof c?c=c.apply(p):"string"==typeof c&&(c=parseFloat(c),p.options.offset.indexOf("%")>-1&&(c=Math.ceil(a.contextDimension*c/100))),h=a.contextScroll-a.contextOffset,p.triggerPoint=d+h-c;var y=u=a.oldScroll,w=y&&g,m=!y&&!g;!f&&w?(p.queueTrigger(a.backward),n[p.group.id]=p.group):!f&&m?(p.queueTrigger(a.forward),n[p.group.id]=p.group):f&&a.oldScroll>=p.triggerPoint&&(p.queueTrigger(a.forward),n[p.group.id]=p.group)}}for(var v in n)n[v].flushTriggers();return this},e.prototype.destroy=function(){var t=[];for(var e in this.waypoints)for(var i in this.waypoints[e])t.push(this.waypoints[e][i]);for(var o=0,r=t.length;r>o;o++)t[o].destroy()},e.prototype.add=function(t){var e=t.options.horizontal?"horizontal":"vertical";this.waypoints[e][t.key]=t,this.refresh()},e.prototype.remove=function(t){delete this.waypoints[t.axis][t.key],this.checkEmpty()},e.prototype.checkEmpty=function(){var t=this.Adapter.isEmptyObject(this.waypoints.horizontal),e=this.Adapter.isEmptyObject(this.waypoints.vertical);t&&e&&(this.adapter.off(".waypoints"),delete o[this.key])},e.prototype.height=function(){return this.element===this.element.window?r.viewportHeight():this.adapter.height()},e.refreshAll=function(){for(var t in o)o[t].refresh()},e.findByElement=function(t){return o[t.waypointContextKey]},e.findOrCreateByElement=function(t){return e.findByElement(t)||new e(t)},r.Context=e}())(function(){"use strict";function t(t,e){return t.triggerPoint-e.triggerPoint}function e(t,e){return e.triggerPoint-t.triggerPoint}function i(t){this.name=t.name,this.axis=t.axis,this.id=this.name+"-"+this.axis,this.waypoints=[],this.clearTriggerQueues(),o[this.axis][this.name]=this}var o={vertical:{},horizontal:{}},r=window.Waypoint;i.prototype.previous=function(t){this.sort();var e=r.Adapter.inArray(t,this.waypoints);return e?this.waypoints[e-1]:null},i.prototype.next=function(t){this.sort();var e=r.Adapter.inArray(t,this.waypoints),i=e===this.waypoints.length-1;return i?null:this.waypoints[e+1]},i.prototype.first=function(){return this.waypoints[0]},i.prototype.last=function(){return this.waypoints[this.waypoints.length-1]},i.prototype.add=function(t){this.waypoints.push(t)},i.prototype.remove=function(t){var e=r.Adapter.inArray(t,this.waypoints);e>-1&&this.waypoints.splice(e,1)},i.prototype.sort=function(){this.waypoints.sort(function(t,e){return t.triggerPoint-e.triggerPoint})},i.prototype.clearTriggerQueues=function(){this.triggerQueues={up:[],down:[],left:[],right:[]}},i.prototype.queueTrigger=function(t,e){this.triggerQueues[e].push(t)},i.prototype.flushTriggers=function(){for(var i in this.triggerQueues){var o=this.triggerQueues[i],r="up"===i||"left"===i;o.sort(r?e:t);for(var n=0,s=o.length;s>n;n+=1){var a=o[n];(a.options.continuous||n===o.length-1)&&a.trigger([i])}}this.clearTriggerQueues()},i.findOrCreate=function(t){return o[t.axis][t.name]||new i(t)},r.Group=i}())(function(){"use strict";function t(t){this.element=t,this.$element=e(t)}var e=window.Zepto,i=window.Waypoint;e.each(["height","off","on","scrollLeft","scrollTop","width"],function(e,i){t.prototype[i]=function(){var t=Array.prototype.slice.call(arguments);return this.$element[i].apply(this.$element,t)}}),t.prototype.offset=function(){return this.element!==this.element.window?this.$element.offset():void 0},e.each(["width","height"],function(i,o){var r=e.camelCase("outer-"+o);t.prototype[r]=function(t){var i=this.$element[o](),r={width:["left","right"],height:["top","bottom"]};return t&&e.each(r[o],e.proxy(function(t,e){i+=parseInt(this.$element.css("margin-"+e),10)},this)),i}}),e.each(["extend","inArray"],function(i,o){t[o]=e[o]}),t.isEmptyObject=function(t){for(var e in t)return!1;return!0},i.adapters.push({name:"zepto",Adapter:t}),i.Adapter=t}()); \ No newline at end of file +!function(){"use strict";function t(o){if(!o)throw new Error("No options passed to Waypoint constructor");if(!o.element)throw new Error("No element option passed to Waypoint constructor");this.key="waypoint-"+e,this.options=t.Adapter.extend({},t.defaults,o),this.element=this.options.element,this.adapter=new t.Adapter(this.element),this.callback=o.handler,this.axis=this.options.horizontal?"horizontal":"vertical",this.enabled=this.options.enabled,this.triggerPoint=null,this.group=t.Group.findOrCreate({name:this.options.group,axis:this.axis}),this.context=t.Context.findOrCreateByElement(this.options.context),t.offsetAliases[this.options.offset]&&(this.options.offset=t.offsetAliases[this.options.offset]),this.context.add(this),this.group.add(this),i[this.key]=this,e+=1}var e=0,i={};t.prototype.trigger=function(t){this.enabled&&(this.callback&&this.callback.apply(this,t),this.options.triggerOnce&&this.destroy())},t.prototype.queueTrigger=function(t){this.group.queueTrigger(this,t)},t.prototype.disable=function(){return this.enabled=!1,this},t.prototype.enable=function(){return this.context.refresh(),this.enabled=!0,this},t.prototype.destroy=function(){this.context.remove(this),this.group.remove(this),delete i[this.key]},t.destroyAll=function(){var t=[];for(var e in i)t.push(i[e]);for(var o=0,r=t.length;r>o;o++)t[o].destroy()},t.refreshAll=function(){t.Context.refreshAll()},t.viewportHeight=function(){return window.innerHeight||document.documentElement.clientHeight},window.Waypoint=t}()(function(){"use strict";function t(t){window.setTimeout(t,1e3/60)}function e(t){this.element=t,this.Adapter=r.Adapter,this.adapter=new this.Adapter(t),this.key="waypoint-context-"+i,this.didScroll=!1,this.didResize=!1,this.oldScroll={x:this.adapter.scrollLeft(),y:this.adapter.scrollTop()},this.waypoints={vertical:{},horizontal:{}},t.waypointContextKey=this.key,o[t.waypointContextKey]=this,i+=1,this.createThrottledScrollHandler(),this.createThrottledResizeHandler()}var i=0,o={},r=window.Waypoint,n=window.requestAnimationFrame||window.mozRequestAnimationFrame||window.webkitRequestAnimationFrame||t;e.prototype.add=function(t){var e=t.options.horizontal?"horizontal":"vertical";this.waypoints[e][t.key]=t,this.refresh()},e.prototype.checkEmpty=function(){var t=this.Adapter.isEmptyObject(this.waypoints.horizontal),e=this.Adapter.isEmptyObject(this.waypoints.vertical);t&&e&&(this.adapter.off(".waypoints"),delete o[this.key])},e.prototype.createThrottledResizeHandler=function(){function t(){e.handleResize(),e.didResize=!1}var e=this;this.adapter.on("resize.waypoints",function(){e.didResize||(e.didResize=!0,n(t))})},e.prototype.createThrottledScrollHandler=function(){function t(){e.handleScroll(),e.didScroll=!1}var e=this;this.adapter.on("scroll.waypoints",function(){(!e.didScroll||r.isTouch)&&(e.didScroll=!0,n(t))})},e.prototype.handleResize=function(){r.Context.refreshAll()},e.prototype.handleScroll=function(){var t={},e={horizontal:{newScroll:this.adapter.scrollLeft(),oldScroll:this.oldScroll.x,forward:"right",backward:"left"},vertical:{newScroll:this.adapter.scrollTop(),oldScroll:this.oldScroll.y,forward:"down",backward:"up"}};for(var i in e){var o=e[i],r=o.newScroll>o.oldScroll,n=r?o.forward:o.backward;for(var s in this.waypoints[i]){var a=this.waypoints[i][s],l=o.oldScroll=a.triggerPoint,p=l&&h,c=!l&&!h;(p||c)&&(a.queueTrigger(n),t[a.group.id]=a.group)}}for(var u in t)t[u].flushTriggers();this.oldScroll={x:e.horizontal.newScroll,y:e.vertical.newScroll}},e.prototype.height=function(){return this.element===this.element.window?r.viewportHeight():this.adapter.height()},e.prototype.remove=function(t){delete this.waypoints[t.axis][t.key],this.checkEmpty()},e.prototype.destroy=function(){var t=[];for(var e in this.waypoints)for(var i in this.waypoints[e])t.push(this.waypoints[e][i]);for(var o=0,r=t.length;r>o;o++)t[o].destroy()},e.prototype.refresh=function(){var t,e=this.element===this.element.window,i=this.adapter.offset(),o=e?r.viewportHeight():this.adapter.height(),n={};this.handleScroll(),t={horizontal:{contextOffset:e?0:i.left,contextScroll:e?0:this.oldScroll.x,contextDimension:this.adapter.width(),oldScroll:this.oldScroll.x,forward:"right",backward:"left",offsetProp:"left"},vertical:{contextOffset:e?0:i.top,contextScroll:e?0:this.oldScroll.y,contextDimension:o,oldScroll:this.oldScroll.y,forward:"down",backward:"up",offsetProp:"top"}};for(var s in t){var a=t[s];for(var l in this.waypoints[s]){var h,p,c,u,d,f=this.waypoints[s][l],y=f.options.offset,g=f.triggerPoint,w=0,m=null==g;f.element!==f.element.window&&(w=f.adapter.offset()[a.offsetProp]),"function"==typeof y?y=y.apply(f):"string"==typeof y&&(y=parseFloat(y),f.options.offset.indexOf("%")>-1&&(y=Math.ceil(a.contextDimension*y/100))),h=a.contextScroll-a.contextOffset,f.triggerPoint=w+h-y,p=g=a.oldScroll,u=p&&c,d=!p&&!c,!m&&u?(f.queueTrigger(a.backward),n[f.group.id]=f.group):!m&&d?(f.queueTrigger(a.forward),n[f.group.id]=f.group):m&&a.oldScroll>=f.triggerPoint&&(f.queueTrigger(a.forward),n[f.group.id]=f.group)}}for(var v in n)n[v].flushTriggers();return this},e.findOrCreateByElement=function(t){return e.findByElement(t)||new e(t)},e.findByElement=function(t){return o[t.waypointContextKey]},e.refreshAll=function(){for(var t in o)o[t].refresh()},r.Context=e}())(function(){"use strict";function t(t,e){return t.triggerPoint-e.triggerPoint}function e(t,e){return e.triggerPoint-t.triggerPoint}function i(t){this.name=t.name,this.axis=t.axis,this.id=this.name+"-"+this.axis,this.waypoints=[],this.clearTriggerQueues(),o[this.axis][this.name]=this}var o={vertical:{},horizontal:{}},r=window.Waypoint;i.prototype.add=function(t){this.waypoints.push(t)},i.prototype.clearTriggerQueues=function(){this.triggerQueues={up:[],down:[],left:[],right:[]}},i.prototype.flushTriggers=function(){for(var i in this.triggerQueues){var o=this.triggerQueues[i],r="up"===i||"left"===i;o.sort(r?e:t);for(var n=0,s=o.length;s>n;n+=1){var a=o[n];(a.options.continuous||n===o.length-1)&&a.trigger([i])}}this.clearTriggerQueues()},i.prototype.queueTrigger=function(t,e){this.triggerQueues[e].push(t)},i.prototype.remove=function(t){var e=r.Adapter.inArray(t,this.waypoints);e>-1&&this.waypoints.splice(e,1)},i.prototype.sort=function(){this.waypoints.sort(function(t,e){return t.triggerPoint-e.triggerPoint})},i.prototype.first=function(){return this.waypoints[0]},i.prototype.last=function(){return this.waypoints[this.waypoints.length-1]},i.prototype.next=function(t){this.sort();var e=r.Adapter.inArray(t,this.waypoints),i=e===this.waypoints.length-1;return i?null:this.waypoints[e+1]},i.prototype.previous=function(t){this.sort();var e=r.Adapter.inArray(t,this.waypoints);return e?this.waypoints[e-1]:null},i.findOrCreate=function(t){return o[t.axis][t.name]||new i(t)},r.Group=i}())(function(){"use strict";function t(t){this.element=t,this.$element=e(t)}var e=window.Zepto,i=window.Waypoint;e.each(["height","off","on","scrollLeft","scrollTop","width"],function(e,i){t.prototype[i]=function(){var t=Array.prototype.slice.call(arguments);return this.$element[i].apply(this.$element,t)}}),t.prototype.offset=function(){return this.element!==this.element.window?this.$element.offset():void 0},e.each(["width","height"],function(i,o){var r=e.camelCase("outer-"+o);t.prototype[r]=function(t){var i=this.$element[o](),r={width:["left","right"],height:["top","bottom"]};return t&&e.each(r[o],e.proxy(function(t,e){i+=parseInt(this.$element.css("margin-"+e),10)},this)),i}}),e.each(["extend","inArray"],function(i,o){t[o]=e[o]}),t.isEmptyObject=function(t){for(var e in t)return!1;return!0},i.adapters.push({name:"zepto",Adapter:t}),i.Adapter=t}()); \ No newline at end of file diff --git a/src/context.js b/src/context.js index 1a049c7f..a847f3b4 100644 --- a/src/context.js +++ b/src/context.js @@ -8,7 +8,6 @@ var keyCounter = 0 var contexts = {} var Waypoint = window.Waypoint - var requestAnimationFrame = window.requestAnimationFrame || window.mozRequestAnimationFrame || window.webkitRequestAnimationFrame || @@ -38,23 +37,24 @@ this.createThrottledResizeHandler() } - /* Internal */ - Context.prototype.createThrottledScrollHandler = function() { - var self = this - function scrollHandler() { - self.handleScroll() - self.didScroll = false - } + /* Private */ + Context.prototype.add = function(waypoint) { + var axis = waypoint.options.horizontal ? 'horizontal' : 'vertical' + this.waypoints[axis][waypoint.key] = waypoint + this.refresh() + } - this.adapter.on('scroll.waypoints', function() { - if (!self.didScroll || Waypoint.isTouch) { - self.didScroll = true - requestAnimationFrame(scrollHandler) - } - }) + /* Private */ + Context.prototype.checkEmpty = function() { + var horizontalEmpty = this.Adapter.isEmptyObject(this.waypoints.horizontal) + var verticalEmpty = this.Adapter.isEmptyObject(this.waypoints.vertical) + if (horizontalEmpty && verticalEmpty) { + this.adapter.off('.waypoints') + delete contexts[this.key] + } } - /* Internal */ + /* Private */ Context.prototype.createThrottledResizeHandler = function() { var self = this @@ -71,7 +71,28 @@ }) } - /* Internal */ + /* Private */ + Context.prototype.createThrottledScrollHandler = function() { + var self = this + function scrollHandler() { + self.handleScroll() + self.didScroll = false + } + + this.adapter.on('scroll.waypoints', function() { + if (!self.didScroll || Waypoint.isTouch) { + self.didScroll = true + requestAnimationFrame(scrollHandler) + } + }) + } + + /* Private */ + Context.prototype.handleResize = function() { + Waypoint.Context.refreshAll() + } + + /* Private */ Context.prototype.handleScroll = function() { var triggeredGroups = {} var axes = { @@ -117,11 +138,34 @@ } } - /* Internal */ - Context.prototype.handleResize = function() { - Waypoint.Context.refreshAll() + /* Private */ + Context.prototype.height = function() { + if (this.element === this.element.window) { + return Waypoint.viewportHeight() + } + return this.adapter.height() } + /* Private */ + Context.prototype.remove = function(waypoint) { + delete this.waypoints[waypoint.axis][waypoint.key] + this.checkEmpty() + } + + /* Public */ + Context.prototype.destroy = function() { + var allWaypoints = [] + for (var axis in this.waypoints) { + for (var waypointKey in this.waypoints[axis]) { + allWaypoints.push(this.waypoints[axis][waypointKey]) + } + } + for (var i = 0, end = allWaypoints.length; i < end; i++) { + allWaypoints[i].destroy() + } + } + + /* Public */ Context.prototype.refresh = function() { var isWindow = this.element === this.element.window var contextOffset = this.adapter.offset() @@ -159,7 +203,8 @@ var oldTriggerPoint = waypoint.triggerPoint var elementOffset = 0 var freshWaypoint = oldTriggerPoint == null - var contextModifier + var contextModifier, wasBeforeScroll, nowAfterScroll + var triggeredBackward, triggeredForward if (waypoint.element !== waypoint.element.window) { elementOffset = waypoint.adapter.offset()[axis.offsetProp] @@ -177,11 +222,11 @@ contextModifier = axis.contextScroll - axis.contextOffset waypoint.triggerPoint = elementOffset + contextModifier - adjustment + wasBeforeScroll = oldTriggerPoint < axis.oldScroll + nowAfterScroll = waypoint.triggerPoint >= axis.oldScroll + triggeredBackward = wasBeforeScroll && nowAfterScroll + triggeredForward = !wasBeforeScroll && !nowAfterScroll - var wasBeforeScroll = oldTriggerPoint < axis.oldScroll - var nowAfterScroll = waypoint.triggerPoint >= axis.oldScroll - var triggeredBackward = wasBeforeScroll && nowAfterScroll - var triggeredForward = !wasBeforeScroll && !nowAfterScroll if (!freshWaypoint && triggeredBackward) { waypoint.queueTrigger(axis.backward) triggeredGroups[waypoint.group.id] = waypoint.group @@ -204,64 +249,22 @@ return this } - Context.prototype.destroy = function() { - var allWaypoints = [] - for (var axis in this.waypoints) { - for (var waypointKey in this.waypoints[axis]) { - allWaypoints.push(this.waypoints[axis][waypointKey]) - } - } - for (var i = 0, end = allWaypoints.length; i < end; i++) { - allWaypoints[i].destroy() - } - } - - /* Internal */ - Context.prototype.add = function(waypoint) { - var axis = waypoint.options.horizontal ? 'horizontal' : 'vertical' - this.waypoints[axis][waypoint.key] = waypoint - this.refresh() - } - - /* Internal */ - Context.prototype.remove = function(waypoint) { - delete this.waypoints[waypoint.axis][waypoint.key] - this.checkEmpty() - } - - /* Internal */ - Context.prototype.checkEmpty = function() { - var horizontalEmpty = this.Adapter.isEmptyObject(this.waypoints.horizontal) - var verticalEmpty = this.Adapter.isEmptyObject(this.waypoints.vertical) - if (horizontalEmpty && verticalEmpty) { - this.adapter.off('.waypoints') - delete contexts[this.key] - } + /* Private */ + Context.findOrCreateByElement = function(element) { + return Context.findByElement(element) || new Context(element) } - /* Internal */ - Context.prototype.height = function() { - if (this.element === this.element.window) { - return Waypoint.viewportHeight() - } - return this.adapter.height() + /* Public */ + Context.findByElement = function(element) { + return contexts[element.waypointContextKey] } + /* Public */ Context.refreshAll = function() { for (var contextId in contexts) { contexts[contextId].refresh() } } - /* Internal */ - Context.findByElement = function(element) { - return contexts[element.waypointContextKey] - } - - /* Internal */ - Context.findOrCreateByElement = function(element) { - return Context.findByElement(element) || new Context(element) - } - Waypoint.Context = Context }()) diff --git a/src/group.js b/src/group.js index 5daaa102..a7d3a3f9 100644 --- a/src/group.js +++ b/src/group.js @@ -1,12 +1,6 @@ (function() { 'use strict' - var groups = { - vertical: {}, - horizontal: {} - } - var Waypoint = window.Waypoint - function byTriggerPoint(a, b) { return a.triggerPoint - b.triggerPoint } @@ -15,6 +9,12 @@ return b.triggerPoint - a.triggerPoint } + var groups = { + vertical: {}, + horizontal: {} + } + var Waypoint = window.Waypoint + function Group(options) { this.name = options.name this.axis = options.axis @@ -24,48 +24,12 @@ groups[this.axis][this.name] = this } - Group.prototype.previous = function(waypoint) { - this.sort() - var index = Waypoint.Adapter.inArray(waypoint, this.waypoints) - return index ? this.waypoints[index - 1] : null - } - - Group.prototype.next = function(waypoint) { - this.sort() - var index = Waypoint.Adapter.inArray(waypoint, this.waypoints) - var isLast = index === this.waypoints.length - 1 - return isLast ? null : this.waypoints[index + 1] - } - - Group.prototype.first = function() { - return this.waypoints[0] - } - - Group.prototype.last = function() { - return this.waypoints[this.waypoints.length - 1] - } - - /* Internal */ + /* Private */ Group.prototype.add = function(waypoint) { this.waypoints.push(waypoint) } - /* Internal */ - Group.prototype.remove = function(waypoint) { - var index = Waypoint.Adapter.inArray(waypoint, this.waypoints) - if (index > -1) { - this.waypoints.splice(index, 1) - } - } - - /* Internal */ - Group.prototype.sort = function() { - this.waypoints.sort(function(a, b) { - return a.triggerPoint - b.triggerPoint - }) - } - - /* Internal */ + /* Private */ Group.prototype.clearTriggerQueues = function() { this.triggerQueues = { up: [], @@ -75,12 +39,7 @@ } } - /* Internal */ - Group.prototype.queueTrigger = function(waypoint, direction) { - this.triggerQueues[direction].push(waypoint) - } - - /* Internal */ + /* Private */ Group.prototype.flushTriggers = function() { for (var direction in this.triggerQueues) { var waypoints = this.triggerQueues[direction] @@ -96,7 +55,52 @@ this.clearTriggerQueues() } - /* Internal */ + /* Private */ + Group.prototype.queueTrigger = function(waypoint, direction) { + this.triggerQueues[direction].push(waypoint) + } + + /* Private */ + Group.prototype.remove = function(waypoint) { + var index = Waypoint.Adapter.inArray(waypoint, this.waypoints) + if (index > -1) { + this.waypoints.splice(index, 1) + } + } + + /* Private */ + Group.prototype.sort = function() { + this.waypoints.sort(function(a, b) { + return a.triggerPoint - b.triggerPoint + }) + } + + /* Public */ + Group.prototype.first = function() { + return this.waypoints[0] + } + + /* Public */ + Group.prototype.last = function() { + return this.waypoints[this.waypoints.length - 1] + } + + /* Public */ + Group.prototype.next = function(waypoint) { + this.sort() + var index = Waypoint.Adapter.inArray(waypoint, this.waypoints) + var isLast = index === this.waypoints.length - 1 + return isLast ? null : this.waypoints[index + 1] + } + + /* Public */ + Group.prototype.previous = function(waypoint) { + this.sort() + var index = Waypoint.Adapter.inArray(waypoint, this.waypoints) + return index ? this.waypoints[index - 1] : null + } + + /* Private */ Group.findOrCreate = function(options) { return groups[options.axis][options.name] || new Group(options) } diff --git a/src/shortcuts/infinite.js b/src/shortcuts/infinite.js index 1fb517d9..f18b556c 100644 --- a/src/shortcuts/infinite.js +++ b/src/shortcuts/infinite.js @@ -20,13 +20,7 @@ } } - Infinite.prototype.destroy = function() { - if (this.waypoint) { - this.waypoint.destroy() - } - } - - /* Internal */ + /* Private */ Infinite.prototype.setupHandler = function() { this.options.handler = $.proxy(function() { window.setTimeout($.proxy(function() { @@ -58,6 +52,13 @@ }, this) } + /* Public */ + Infinite.prototype.destroy = function() { + if (this.waypoint) { + this.waypoint.destroy() + } + } + Infinite.defaults = { container: 'auto', items: '.infinite-item', diff --git a/src/shortcuts/inview.js b/src/shortcuts/inview.js index 3bfcac07..4b7cd610 100644 --- a/src/shortcuts/inview.js +++ b/src/shortcuts/inview.js @@ -1,10 +1,10 @@ (function() { 'use strict' - var Waypoint = window.Waypoint - function noop() {} + var Waypoint = window.Waypoint + function Inview(options) { this.options = Waypoint.Adapter.extend({}, Inview.defaults, options) this.axis = this.options.horizontal ? 'horizontal' : 'vertical' @@ -12,14 +12,7 @@ this.createWaypoints() } - Inview.prototype.destroy = function() { - for (var i = 0, end = this.waypoints.length; i < end; i++) { - this.waypoints[i].destroy() - } - this.waypoints = [] - } - - /* Internal */ + /* Private */ Inview.prototype.createWaypoints = function() { var configs = { vertical: [{ @@ -68,7 +61,7 @@ } } - /* Internal */ + /* Private */ Inview.prototype.createWaypoint = function(config) { var self = this this.waypoints.push(new Waypoint({ @@ -83,6 +76,14 @@ })) } + /* Public */ + Inview.prototype.destroy = function() { + for (var i = 0, end = this.waypoints.length; i < end; i++) { + this.waypoints[i].destroy() + } + this.waypoints = [] + } + Inview.defaults = { enter: noop, entered: noop, diff --git a/src/shortcuts/sticky.js b/src/shortcuts/sticky.js index 665ffd1f..060bf778 100644 --- a/src/shortcuts/sticky.js +++ b/src/shortcuts/sticky.js @@ -12,19 +12,7 @@ this.createWaypoint() } - Sticky.prototype.destroy = function() { - this.waypoint.destroy() - this.$element.removeClass(this.options.stuckClass).unwrap() - } - - /* Internal */ - Sticky.prototype.createWrapper = function() { - this.$element.wrap(this.options.wrapper) - this.$wrapper = this.$element.parent() - this.wrapper = this.$wrapper[0] - } - - /* Internal */ + /* Private */ Sticky.prototype.createWaypoint = function() { var originalHandler = this.options.handler @@ -44,6 +32,19 @@ })) } + /* Private */ + Sticky.prototype.createWrapper = function() { + this.$element.wrap(this.options.wrapper) + this.$wrapper = this.$element.parent() + this.wrapper = this.$wrapper[0] + } + + /* Public */ + Sticky.prototype.destroy = function() { + this.waypoint.destroy() + this.$element.removeClass(this.options.stuckClass).unwrap() + } + Sticky.defaults = { wrapper: '
', stuckClass: 'stuck', diff --git a/src/waypoint.js b/src/waypoint.js index 320bad5c..aa42b8ac 100644 --- a/src/waypoint.js +++ b/src/waypoint.js @@ -35,39 +35,63 @@ keyCounter += 1 } + /* Private */ + Waypoint.prototype.trigger = function(args) { + if (!this.enabled) { + return + } + if (this.callback) { + this.callback.apply(this, args) + } + if (this.options.triggerOnce) { + this.destroy() + } + } + + /* Private */ + Waypoint.prototype.queueTrigger = function(direction) { + this.group.queueTrigger(this, direction) + } + + /* Public */ Waypoint.prototype.disable = function() { this.enabled = false return this } + /* Public */ Waypoint.prototype.enable = function() { this.context.refresh() this.enabled = true return this } + /* Public */ Waypoint.prototype.destroy = function() { this.context.remove(this) this.group.remove(this) delete allWaypoints[this.key] } - /* Internal */ - Waypoint.prototype.trigger = function(args) { - if (!this.enabled) { - return - } - if (this.callback) { - this.callback.apply(this, args) + /* Public */ + Waypoint.destroyAll = function() { + var allWaypointsArray = [] + for (var waypointKey in allWaypoints) { + allWaypointsArray.push(allWaypoints[waypointKey]) } - if (this.options.triggerOnce) { - this.destroy() + for (var i = 0, end = allWaypointsArray.length; i < end; i++) { + allWaypointsArray[i].destroy() } } - /* Internal */ - Waypoint.prototype.queueTrigger = function(direction) { - this.group.queueTrigger(this, direction) + /* Public */ + Waypoint.refreshAll = function() { + Waypoint.Context.refreshAll() + } + + /* Public */ + Waypoint.viewportHeight = function() { + return window.innerHeight || document.documentElement.clientHeight } Waypoint.adapters = [] @@ -91,23 +115,5 @@ } } - Waypoint.viewportHeight = function() { - return window.innerHeight || document.documentElement.clientHeight - } - - Waypoint.refresh = function() { - Waypoint.Context.refreshAll() - } - - Waypoint.destroyAll = function() { - var allWaypointsArray = [] - for (var waypointKey in allWaypoints) { - allWaypointsArray.push(allWaypoints[waypointKey]) - } - for (var i = 0, end = allWaypointsArray.length; i < end; i++) { - allWaypointsArray[i].destroy() - } - } - window.Waypoint = Waypoint }()) diff --git a/test/waypoint-spec.js b/test/waypoint-spec.js index 03b7a34c..edf579be 100644 --- a/test/waypoint-spec.js +++ b/test/waypoint-spec.js @@ -359,7 +359,7 @@ window.jQuery.each(Waypoint.adapters, function(i, adapter) { runs(function() { $target.css('top', '-1px') $later.css('top', '-2px') - Waypoint.refresh() + Waypoint.refreshAll() }) waitsFor(function() { return hitCount @@ -474,10 +474,10 @@ window.jQuery.each(Waypoint.adapters, function(i, adapter) { }) }) - describe('Waypoint.refresh()', function() { + describe('Waypoint.refreshAll()', function() { it('is an alias for Waypoint.Context.refreshAll', function() { spyOn(Waypoint.Context, 'refreshAll') - Waypoint.refresh() + Waypoint.refreshAll() expect(Waypoint.Context.refreshAll).toHaveBeenCalled() }) }) From 8666b8a5040c86b662d4734ad5fd76e870a0aeed Mon Sep 17 00:00:00 2001 From: imakewebthings Date: Mon, 23 Jun 2014 13:07:56 -0700 Subject: [PATCH 25/98] One more rearrangement --- lib/jquery.waypoints.js | 21 ++++++++++----------- lib/jquery.waypoints.min.js | 2 +- lib/noframework.waypoints.js | 21 ++++++++++----------- lib/noframework.waypoints.min.js | 2 +- lib/zepto.waypoints.js | 21 ++++++++++----------- lib/zepto.waypoints.min.js | 2 +- src/waypoint.js | 20 ++++++++++---------- 7 files changed, 43 insertions(+), 46 deletions(-) diff --git a/lib/jquery.waypoints.js b/lib/jquery.waypoints.js index aa809fcf..ba877fa1 100644 --- a/lib/jquery.waypoints.js +++ b/lib/jquery.waypoints.js @@ -41,6 +41,11 @@ https://github.com/imakewebthings/waypoints/blog/master/licenses.txt keyCounter += 1 } + /* Private */ + Waypoint.prototype.queueTrigger = function(direction) { + this.group.queueTrigger(this, direction) + } + /* Private */ Waypoint.prototype.trigger = function(args) { if (!this.enabled) { @@ -54,9 +59,11 @@ https://github.com/imakewebthings/waypoints/blog/master/licenses.txt } } - /* Private */ - Waypoint.prototype.queueTrigger = function(direction) { - this.group.queueTrigger(this, direction) + /* Public */ + Waypoint.prototype.destroy = function() { + this.context.remove(this) + this.group.remove(this) + delete allWaypoints[this.key] } /* Public */ @@ -72,13 +79,6 @@ https://github.com/imakewebthings/waypoints/blog/master/licenses.txt return this } - /* Public */ - Waypoint.prototype.destroy = function() { - this.context.remove(this) - this.group.remove(this) - delete allWaypoints[this.key] - } - /* Public */ Waypoint.destroyAll = function() { var allWaypointsArray = [] @@ -120,7 +120,6 @@ https://github.com/imakewebthings/waypoints/blog/master/licenses.txt return this.context.adapter.width() - this.adapter.outerWidth() } } - } window.Waypoint = Waypoint }()) diff --git a/lib/jquery.waypoints.min.js b/lib/jquery.waypoints.min.js index 32c6a0e1..c2f3aa38 100644 --- a/lib/jquery.waypoints.min.js +++ b/lib/jquery.waypoints.min.js @@ -4,4 +4,4 @@ Copyright © 2011-2014 Caleb Troughton Licensed under the MIT license. https://github.com/imakewebthings/waypoints/blog/master/licenses.txt */ -!function(){"use strict";function t(o){if(!o)throw new Error("No options passed to Waypoint constructor");if(!o.element)throw new Error("No element option passed to Waypoint constructor");this.key="waypoint-"+e,this.options=t.Adapter.extend({},t.defaults,o),this.element=this.options.element,this.adapter=new t.Adapter(this.element),this.callback=o.handler,this.axis=this.options.horizontal?"horizontal":"vertical",this.enabled=this.options.enabled,this.triggerPoint=null,this.group=t.Group.findOrCreate({name:this.options.group,axis:this.axis}),this.context=t.Context.findOrCreateByElement(this.options.context),t.offsetAliases[this.options.offset]&&(this.options.offset=t.offsetAliases[this.options.offset]),this.context.add(this),this.group.add(this),i[this.key]=this,e+=1}var e=0,i={};t.prototype.trigger=function(t){this.enabled&&(this.callback&&this.callback.apply(this,t),this.options.triggerOnce&&this.destroy())},t.prototype.queueTrigger=function(t){this.group.queueTrigger(this,t)},t.prototype.disable=function(){return this.enabled=!1,this},t.prototype.enable=function(){return this.context.refresh(),this.enabled=!0,this},t.prototype.destroy=function(){this.context.remove(this),this.group.remove(this),delete i[this.key]},t.destroyAll=function(){var t=[];for(var e in i)t.push(i[e]);for(var o=0,r=t.length;r>o;o++)t[o].destroy()},t.refreshAll=function(){t.Context.refreshAll()},t.viewportHeight=function(){return window.innerHeight||document.documentElement.clientHeight},window.Waypoint=t}()(function(){"use strict";function t(t){window.setTimeout(t,1e3/60)}function e(t){this.element=t,this.Adapter=r.Adapter,this.adapter=new this.Adapter(t),this.key="waypoint-context-"+i,this.didScroll=!1,this.didResize=!1,this.oldScroll={x:this.adapter.scrollLeft(),y:this.adapter.scrollTop()},this.waypoints={vertical:{},horizontal:{}},t.waypointContextKey=this.key,o[t.waypointContextKey]=this,i+=1,this.createThrottledScrollHandler(),this.createThrottledResizeHandler()}var i=0,o={},r=window.Waypoint,n=window.requestAnimationFrame||window.mozRequestAnimationFrame||window.webkitRequestAnimationFrame||t;e.prototype.add=function(t){var e=t.options.horizontal?"horizontal":"vertical";this.waypoints[e][t.key]=t,this.refresh()},e.prototype.checkEmpty=function(){var t=this.Adapter.isEmptyObject(this.waypoints.horizontal),e=this.Adapter.isEmptyObject(this.waypoints.vertical);t&&e&&(this.adapter.off(".waypoints"),delete o[this.key])},e.prototype.createThrottledResizeHandler=function(){function t(){e.handleResize(),e.didResize=!1}var e=this;this.adapter.on("resize.waypoints",function(){e.didResize||(e.didResize=!0,n(t))})},e.prototype.createThrottledScrollHandler=function(){function t(){e.handleScroll(),e.didScroll=!1}var e=this;this.adapter.on("scroll.waypoints",function(){(!e.didScroll||r.isTouch)&&(e.didScroll=!0,n(t))})},e.prototype.handleResize=function(){r.Context.refreshAll()},e.prototype.handleScroll=function(){var t={},e={horizontal:{newScroll:this.adapter.scrollLeft(),oldScroll:this.oldScroll.x,forward:"right",backward:"left"},vertical:{newScroll:this.adapter.scrollTop(),oldScroll:this.oldScroll.y,forward:"down",backward:"up"}};for(var i in e){var o=e[i],r=o.newScroll>o.oldScroll,n=r?o.forward:o.backward;for(var s in this.waypoints[i]){var a=this.waypoints[i][s],l=o.oldScroll=a.triggerPoint,p=l&&h,c=!l&&!h;(p||c)&&(a.queueTrigger(n),t[a.group.id]=a.group)}}for(var u in t)t[u].flushTriggers();this.oldScroll={x:e.horizontal.newScroll,y:e.vertical.newScroll}},e.prototype.height=function(){return this.element===this.element.window?r.viewportHeight():this.adapter.height()},e.prototype.remove=function(t){delete this.waypoints[t.axis][t.key],this.checkEmpty()},e.prototype.destroy=function(){var t=[];for(var e in this.waypoints)for(var i in this.waypoints[e])t.push(this.waypoints[e][i]);for(var o=0,r=t.length;r>o;o++)t[o].destroy()},e.prototype.refresh=function(){var t,e=this.element===this.element.window,i=this.adapter.offset(),o=e?r.viewportHeight():this.adapter.height(),n={};this.handleScroll(),t={horizontal:{contextOffset:e?0:i.left,contextScroll:e?0:this.oldScroll.x,contextDimension:this.adapter.width(),oldScroll:this.oldScroll.x,forward:"right",backward:"left",offsetProp:"left"},vertical:{contextOffset:e?0:i.top,contextScroll:e?0:this.oldScroll.y,contextDimension:o,oldScroll:this.oldScroll.y,forward:"down",backward:"up",offsetProp:"top"}};for(var s in t){var a=t[s];for(var l in this.waypoints[s]){var h,p,c,u,d,f=this.waypoints[s][l],y=f.options.offset,g=f.triggerPoint,w=0,v=null==g;f.element!==f.element.window&&(w=f.adapter.offset()[a.offsetProp]),"function"==typeof y?y=y.apply(f):"string"==typeof y&&(y=parseFloat(y),f.options.offset.indexOf("%")>-1&&(y=Math.ceil(a.contextDimension*y/100))),h=a.contextScroll-a.contextOffset,f.triggerPoint=w+h-y,p=g=a.oldScroll,u=p&&c,d=!p&&!c,!v&&u?(f.queueTrigger(a.backward),n[f.group.id]=f.group):!v&&d?(f.queueTrigger(a.forward),n[f.group.id]=f.group):v&&a.oldScroll>=f.triggerPoint&&(f.queueTrigger(a.forward),n[f.group.id]=f.group)}}for(var m in n)n[m].flushTriggers();return this},e.findOrCreateByElement=function(t){return e.findByElement(t)||new e(t)},e.findByElement=function(t){return o[t.waypointContextKey]},e.refreshAll=function(){for(var t in o)o[t].refresh()},r.Context=e}())(function(){"use strict";function t(t,e){return t.triggerPoint-e.triggerPoint}function e(t,e){return e.triggerPoint-t.triggerPoint}function i(t){this.name=t.name,this.axis=t.axis,this.id=this.name+"-"+this.axis,this.waypoints=[],this.clearTriggerQueues(),o[this.axis][this.name]=this}var o={vertical:{},horizontal:{}},r=window.Waypoint;i.prototype.add=function(t){this.waypoints.push(t)},i.prototype.clearTriggerQueues=function(){this.triggerQueues={up:[],down:[],left:[],right:[]}},i.prototype.flushTriggers=function(){for(var i in this.triggerQueues){var o=this.triggerQueues[i],r="up"===i||"left"===i;o.sort(r?e:t);for(var n=0,s=o.length;s>n;n+=1){var a=o[n];(a.options.continuous||n===o.length-1)&&a.trigger([i])}}this.clearTriggerQueues()},i.prototype.queueTrigger=function(t,e){this.triggerQueues[e].push(t)},i.prototype.remove=function(t){var e=r.Adapter.inArray(t,this.waypoints);e>-1&&this.waypoints.splice(e,1)},i.prototype.sort=function(){this.waypoints.sort(function(t,e){return t.triggerPoint-e.triggerPoint})},i.prototype.first=function(){return this.waypoints[0]},i.prototype.last=function(){return this.waypoints[this.waypoints.length-1]},i.prototype.next=function(t){this.sort();var e=r.Adapter.inArray(t,this.waypoints),i=e===this.waypoints.length-1;return i?null:this.waypoints[e+1]},i.prototype.previous=function(t){this.sort();var e=r.Adapter.inArray(t,this.waypoints);return e?this.waypoints[e-1]:null},i.findOrCreate=function(t){return o[t.axis][t.name]||new i(t)},r.Group=i}())(function(){"use strict";function t(t){this.$element=e(t)}var e=window.jQuery,i=window.Waypoint;e.each(["height","off","offset","on","outerHeight","outerWidth","scrollLeft","scrollTop","width"],function(e,i){t.prototype[i]=function(){var t=Array.prototype.slice.call(arguments);return this.$element[i].apply(this.$element,t)}}),e.each(["extend","inArray","isEmptyObject"],function(i,o){t[o]=e[o]}),i.adapters.push({name:"jquery",Adapter:t}),i.Adapter=t}()); \ No newline at end of file +!function(){"use strict";function t(o){if(!o)throw new Error("No options passed to Waypoint constructor");if(!o.element)throw new Error("No element option passed to Waypoint constructor");this.key="waypoint-"+e,this.options=t.Adapter.extend({},t.defaults,o),this.element=this.options.element,this.adapter=new t.Adapter(this.element),this.callback=o.handler,this.axis=this.options.horizontal?"horizontal":"vertical",this.enabled=this.options.enabled,this.triggerPoint=null,this.group=t.Group.findOrCreate({name:this.options.group,axis:this.axis}),this.context=t.Context.findOrCreateByElement(this.options.context),t.offsetAliases[this.options.offset]&&(this.options.offset=t.offsetAliases[this.options.offset]),this.context.add(this),this.group.add(this),i[this.key]=this,e+=1}var e=0,i={};t.prototype.queueTrigger=function(t){this.group.queueTrigger(this,t)},t.prototype.trigger=function(t){this.enabled&&(this.callback&&this.callback.apply(this,t),this.options.triggerOnce&&this.destroy())},t.prototype.destroy=function(){this.context.remove(this),this.group.remove(this),delete i[this.key]},t.prototype.disable=function(){return this.enabled=!1,this},t.prototype.enable=function(){return this.context.refresh(),this.enabled=!0,this},t.destroyAll=function(){var t=[];for(var e in i)t.push(i[e]);for(var o=0,r=t.length;r>o;o++)t[o].destroy()},t.refreshAll=function(){t.Context.refreshAll()},t.viewportHeight=function(){return window.innerHeight||document.documentElement.clientHeight},t.adapters=[],t.defaults={context:window,continuous:!0,enabled:!0,group:"default",horizontal:!1,offset:0,triggerOnce:!1},t.offsetAliases={"bottom-in-view":function(){return this.context.height()-this.adapter.outerHeight()},"right-in-view":function(){return this.context.adapter.width()-this.adapter.outerWidth()}},window.Waypoint=t}()(function(){"use strict";function t(t){window.setTimeout(t,1e3/60)}function e(t){this.element=t,this.Adapter=r.Adapter,this.adapter=new this.Adapter(t),this.key="waypoint-context-"+i,this.didScroll=!1,this.didResize=!1,this.oldScroll={x:this.adapter.scrollLeft(),y:this.adapter.scrollTop()},this.waypoints={vertical:{},horizontal:{}},t.waypointContextKey=this.key,o[t.waypointContextKey]=this,i+=1,this.createThrottledScrollHandler(),this.createThrottledResizeHandler()}var i=0,o={},r=window.Waypoint,n=window.requestAnimationFrame||window.mozRequestAnimationFrame||window.webkitRequestAnimationFrame||t;e.prototype.add=function(t){var e=t.options.horizontal?"horizontal":"vertical";this.waypoints[e][t.key]=t,this.refresh()},e.prototype.checkEmpty=function(){var t=this.Adapter.isEmptyObject(this.waypoints.horizontal),e=this.Adapter.isEmptyObject(this.waypoints.vertical);t&&e&&(this.adapter.off(".waypoints"),delete o[this.key])},e.prototype.createThrottledResizeHandler=function(){function t(){e.handleResize(),e.didResize=!1}var e=this;this.adapter.on("resize.waypoints",function(){e.didResize||(e.didResize=!0,n(t))})},e.prototype.createThrottledScrollHandler=function(){function t(){e.handleScroll(),e.didScroll=!1}var e=this;this.adapter.on("scroll.waypoints",function(){(!e.didScroll||r.isTouch)&&(e.didScroll=!0,n(t))})},e.prototype.handleResize=function(){r.Context.refreshAll()},e.prototype.handleScroll=function(){var t={},e={horizontal:{newScroll:this.adapter.scrollLeft(),oldScroll:this.oldScroll.x,forward:"right",backward:"left"},vertical:{newScroll:this.adapter.scrollTop(),oldScroll:this.oldScroll.y,forward:"down",backward:"up"}};for(var i in e){var o=e[i],r=o.newScroll>o.oldScroll,n=r?o.forward:o.backward;for(var s in this.waypoints[i]){var a=this.waypoints[i][s],l=o.oldScroll=a.triggerPoint,p=l&&h,c=!l&&!h;(p||c)&&(a.queueTrigger(n),t[a.group.id]=a.group)}}for(var u in t)t[u].flushTriggers();this.oldScroll={x:e.horizontal.newScroll,y:e.vertical.newScroll}},e.prototype.height=function(){return this.element===this.element.window?r.viewportHeight():this.adapter.height()},e.prototype.remove=function(t){delete this.waypoints[t.axis][t.key],this.checkEmpty()},e.prototype.destroy=function(){var t=[];for(var e in this.waypoints)for(var i in this.waypoints[e])t.push(this.waypoints[e][i]);for(var o=0,r=t.length;r>o;o++)t[o].destroy()},e.prototype.refresh=function(){var t,e=this.element===this.element.window,i=this.adapter.offset(),o=e?r.viewportHeight():this.adapter.height(),n={};this.handleScroll(),t={horizontal:{contextOffset:e?0:i.left,contextScroll:e?0:this.oldScroll.x,contextDimension:this.adapter.width(),oldScroll:this.oldScroll.x,forward:"right",backward:"left",offsetProp:"left"},vertical:{contextOffset:e?0:i.top,contextScroll:e?0:this.oldScroll.y,contextDimension:o,oldScroll:this.oldScroll.y,forward:"down",backward:"up",offsetProp:"top"}};for(var s in t){var a=t[s];for(var l in this.waypoints[s]){var h,p,c,u,d,f=this.waypoints[s][l],y=f.options.offset,g=f.triggerPoint,w=0,v=null==g;f.element!==f.element.window&&(w=f.adapter.offset()[a.offsetProp]),"function"==typeof y?y=y.apply(f):"string"==typeof y&&(y=parseFloat(y),f.options.offset.indexOf("%")>-1&&(y=Math.ceil(a.contextDimension*y/100))),h=a.contextScroll-a.contextOffset,f.triggerPoint=w+h-y,p=g=a.oldScroll,u=p&&c,d=!p&&!c,!v&&u?(f.queueTrigger(a.backward),n[f.group.id]=f.group):!v&&d?(f.queueTrigger(a.forward),n[f.group.id]=f.group):v&&a.oldScroll>=f.triggerPoint&&(f.queueTrigger(a.forward),n[f.group.id]=f.group)}}for(var m in n)n[m].flushTriggers();return this},e.findOrCreateByElement=function(t){return e.findByElement(t)||new e(t)},e.findByElement=function(t){return o[t.waypointContextKey]},e.refreshAll=function(){for(var t in o)o[t].refresh()},r.Context=e}())(function(){"use strict";function t(t,e){return t.triggerPoint-e.triggerPoint}function e(t,e){return e.triggerPoint-t.triggerPoint}function i(t){this.name=t.name,this.axis=t.axis,this.id=this.name+"-"+this.axis,this.waypoints=[],this.clearTriggerQueues(),o[this.axis][this.name]=this}var o={vertical:{},horizontal:{}},r=window.Waypoint;i.prototype.add=function(t){this.waypoints.push(t)},i.prototype.clearTriggerQueues=function(){this.triggerQueues={up:[],down:[],left:[],right:[]}},i.prototype.flushTriggers=function(){for(var i in this.triggerQueues){var o=this.triggerQueues[i],r="up"===i||"left"===i;o.sort(r?e:t);for(var n=0,s=o.length;s>n;n+=1){var a=o[n];(a.options.continuous||n===o.length-1)&&a.trigger([i])}}this.clearTriggerQueues()},i.prototype.queueTrigger=function(t,e){this.triggerQueues[e].push(t)},i.prototype.remove=function(t){var e=r.Adapter.inArray(t,this.waypoints);e>-1&&this.waypoints.splice(e,1)},i.prototype.sort=function(){this.waypoints.sort(function(t,e){return t.triggerPoint-e.triggerPoint})},i.prototype.first=function(){return this.waypoints[0]},i.prototype.last=function(){return this.waypoints[this.waypoints.length-1]},i.prototype.next=function(t){this.sort();var e=r.Adapter.inArray(t,this.waypoints),i=e===this.waypoints.length-1;return i?null:this.waypoints[e+1]},i.prototype.previous=function(t){this.sort();var e=r.Adapter.inArray(t,this.waypoints);return e?this.waypoints[e-1]:null},i.findOrCreate=function(t){return o[t.axis][t.name]||new i(t)},r.Group=i}())(function(){"use strict";function t(t){this.$element=e(t)}var e=window.jQuery,i=window.Waypoint;e.each(["height","off","offset","on","outerHeight","outerWidth","scrollLeft","scrollTop","width"],function(e,i){t.prototype[i]=function(){var t=Array.prototype.slice.call(arguments);return this.$element[i].apply(this.$element,t)}}),e.each(["extend","inArray","isEmptyObject"],function(i,o){t[o]=e[o]}),i.adapters.push({name:"jquery",Adapter:t}),i.Adapter=t}()); \ No newline at end of file diff --git a/lib/noframework.waypoints.js b/lib/noframework.waypoints.js index ef8a9f48..c3104b28 100644 --- a/lib/noframework.waypoints.js +++ b/lib/noframework.waypoints.js @@ -41,6 +41,11 @@ https://github.com/imakewebthings/waypoints/blog/master/licenses.txt keyCounter += 1 } + /* Private */ + Waypoint.prototype.queueTrigger = function(direction) { + this.group.queueTrigger(this, direction) + } + /* Private */ Waypoint.prototype.trigger = function(args) { if (!this.enabled) { @@ -54,9 +59,11 @@ https://github.com/imakewebthings/waypoints/blog/master/licenses.txt } } - /* Private */ - Waypoint.prototype.queueTrigger = function(direction) { - this.group.queueTrigger(this, direction) + /* Public */ + Waypoint.prototype.destroy = function() { + this.context.remove(this) + this.group.remove(this) + delete allWaypoints[this.key] } /* Public */ @@ -72,13 +79,6 @@ https://github.com/imakewebthings/waypoints/blog/master/licenses.txt return this } - /* Public */ - Waypoint.prototype.destroy = function() { - this.context.remove(this) - this.group.remove(this) - delete allWaypoints[this.key] - } - /* Public */ Waypoint.destroyAll = function() { var allWaypointsArray = [] @@ -120,7 +120,6 @@ https://github.com/imakewebthings/waypoints/blog/master/licenses.txt return this.context.adapter.width() - this.adapter.outerWidth() } } - } window.Waypoint = Waypoint }()) diff --git a/lib/noframework.waypoints.min.js b/lib/noframework.waypoints.min.js index c6245e2f..d613a147 100644 --- a/lib/noframework.waypoints.min.js +++ b/lib/noframework.waypoints.min.js @@ -4,4 +4,4 @@ Copyright © 2011-2014 Caleb Troughton Licensed under the MIT license. https://github.com/imakewebthings/waypoints/blog/master/licenses.txt */ -!function(){"use strict";function t(r){if(!r)throw new Error("No options passed to Waypoint constructor");if(!r.element)throw new Error("No element option passed to Waypoint constructor");this.key="waypoint-"+e,this.options=t.Adapter.extend({},t.defaults,r),this.element=this.options.element,this.adapter=new t.Adapter(this.element),this.callback=r.handler,this.axis=this.options.horizontal?"horizontal":"vertical",this.enabled=this.options.enabled,this.triggerPoint=null,this.group=t.Group.findOrCreate({name:this.options.group,axis:this.axis}),this.context=t.Context.findOrCreateByElement(this.options.context),t.offsetAliases[this.options.offset]&&(this.options.offset=t.offsetAliases[this.options.offset]),this.context.add(this),this.group.add(this),i[this.key]=this,e+=1}var e=0,i={};t.prototype.trigger=function(t){this.enabled&&(this.callback&&this.callback.apply(this,t),this.options.triggerOnce&&this.destroy())},t.prototype.queueTrigger=function(t){this.group.queueTrigger(this,t)},t.prototype.disable=function(){return this.enabled=!1,this},t.prototype.enable=function(){return this.context.refresh(),this.enabled=!0,this},t.prototype.destroy=function(){this.context.remove(this),this.group.remove(this),delete i[this.key]},t.destroyAll=function(){var t=[];for(var e in i)t.push(i[e]);for(var r=0,o=t.length;o>r;r++)t[r].destroy()},t.refreshAll=function(){t.Context.refreshAll()},t.viewportHeight=function(){return window.innerHeight||document.documentElement.clientHeight},window.Waypoint=t}()(function(){"use strict";function t(t){window.setTimeout(t,1e3/60)}function e(t){this.element=t,this.Adapter=o.Adapter,this.adapter=new this.Adapter(t),this.key="waypoint-context-"+i,this.didScroll=!1,this.didResize=!1,this.oldScroll={x:this.adapter.scrollLeft(),y:this.adapter.scrollTop()},this.waypoints={vertical:{},horizontal:{}},t.waypointContextKey=this.key,r[t.waypointContextKey]=this,i+=1,this.createThrottledScrollHandler(),this.createThrottledResizeHandler()}var i=0,r={},o=window.Waypoint,n=window.requestAnimationFrame||window.mozRequestAnimationFrame||window.webkitRequestAnimationFrame||t;e.prototype.add=function(t){var e=t.options.horizontal?"horizontal":"vertical";this.waypoints[e][t.key]=t,this.refresh()},e.prototype.checkEmpty=function(){var t=this.Adapter.isEmptyObject(this.waypoints.horizontal),e=this.Adapter.isEmptyObject(this.waypoints.vertical);t&&e&&(this.adapter.off(".waypoints"),delete r[this.key])},e.prototype.createThrottledResizeHandler=function(){function t(){e.handleResize(),e.didResize=!1}var e=this;this.adapter.on("resize.waypoints",function(){e.didResize||(e.didResize=!0,n(t))})},e.prototype.createThrottledScrollHandler=function(){function t(){e.handleScroll(),e.didScroll=!1}var e=this;this.adapter.on("scroll.waypoints",function(){(!e.didScroll||o.isTouch)&&(e.didScroll=!0,n(t))})},e.prototype.handleResize=function(){o.Context.refreshAll()},e.prototype.handleScroll=function(){var t={},e={horizontal:{newScroll:this.adapter.scrollLeft(),oldScroll:this.oldScroll.x,forward:"right",backward:"left"},vertical:{newScroll:this.adapter.scrollTop(),oldScroll:this.oldScroll.y,forward:"down",backward:"up"}};for(var i in e){var r=e[i],o=r.newScroll>r.oldScroll,n=o?r.forward:r.backward;for(var s in this.waypoints[i]){var a=this.waypoints[i][s],l=r.oldScroll=a.triggerPoint,p=l&&h,f=!l&&!h;(p||f)&&(a.queueTrigger(n),t[a.group.id]=a.group)}}for(var u in t)t[u].flushTriggers();this.oldScroll={x:e.horizontal.newScroll,y:e.vertical.newScroll}},e.prototype.height=function(){return this.element===this.element.window?o.viewportHeight():this.adapter.height()},e.prototype.remove=function(t){delete this.waypoints[t.axis][t.key],this.checkEmpty()},e.prototype.destroy=function(){var t=[];for(var e in this.waypoints)for(var i in this.waypoints[e])t.push(this.waypoints[e][i]);for(var r=0,o=t.length;o>r;r++)t[r].destroy()},e.prototype.refresh=function(){var t,e=this.element===this.element.window,i=this.adapter.offset(),r=e?o.viewportHeight():this.adapter.height(),n={};this.handleScroll(),t={horizontal:{contextOffset:e?0:i.left,contextScroll:e?0:this.oldScroll.x,contextDimension:this.adapter.width(),oldScroll:this.oldScroll.x,forward:"right",backward:"left",offsetProp:"left"},vertical:{contextOffset:e?0:i.top,contextScroll:e?0:this.oldScroll.y,contextDimension:r,oldScroll:this.oldScroll.y,forward:"down",backward:"up",offsetProp:"top"}};for(var s in t){var a=t[s];for(var l in this.waypoints[s]){var h,p,f,u,c,d=this.waypoints[s][l],g=d.options.offset,y=d.triggerPoint,w=0,m=null==y;d.element!==d.element.window&&(w=d.adapter.offset()[a.offsetProp]),"function"==typeof g?g=g.apply(d):"string"==typeof g&&(g=parseFloat(g),d.options.offset.indexOf("%")>-1&&(g=Math.ceil(a.contextDimension*g/100))),h=a.contextScroll-a.contextOffset,d.triggerPoint=w+h-g,p=y=a.oldScroll,u=p&&f,c=!p&&!f,!m&&u?(d.queueTrigger(a.backward),n[d.group.id]=d.group):!m&&c?(d.queueTrigger(a.forward),n[d.group.id]=d.group):m&&a.oldScroll>=d.triggerPoint&&(d.queueTrigger(a.forward),n[d.group.id]=d.group)}}for(var v in n)n[v].flushTriggers();return this},e.findOrCreateByElement=function(t){return e.findByElement(t)||new e(t)},e.findByElement=function(t){return r[t.waypointContextKey]},e.refreshAll=function(){for(var t in r)r[t].refresh()},o.Context=e}())(function(){"use strict";function t(t,e){return t.triggerPoint-e.triggerPoint}function e(t,e){return e.triggerPoint-t.triggerPoint}function i(t){this.name=t.name,this.axis=t.axis,this.id=this.name+"-"+this.axis,this.waypoints=[],this.clearTriggerQueues(),r[this.axis][this.name]=this}var r={vertical:{},horizontal:{}},o=window.Waypoint;i.prototype.add=function(t){this.waypoints.push(t)},i.prototype.clearTriggerQueues=function(){this.triggerQueues={up:[],down:[],left:[],right:[]}},i.prototype.flushTriggers=function(){for(var i in this.triggerQueues){var r=this.triggerQueues[i],o="up"===i||"left"===i;r.sort(o?e:t);for(var n=0,s=r.length;s>n;n+=1){var a=r[n];(a.options.continuous||n===r.length-1)&&a.trigger([i])}}this.clearTriggerQueues()},i.prototype.queueTrigger=function(t,e){this.triggerQueues[e].push(t)},i.prototype.remove=function(t){var e=o.Adapter.inArray(t,this.waypoints);e>-1&&this.waypoints.splice(e,1)},i.prototype.sort=function(){this.waypoints.sort(function(t,e){return t.triggerPoint-e.triggerPoint})},i.prototype.first=function(){return this.waypoints[0]},i.prototype.last=function(){return this.waypoints[this.waypoints.length-1]},i.prototype.next=function(t){this.sort();var e=o.Adapter.inArray(t,this.waypoints),i=e===this.waypoints.length-1;return i?null:this.waypoints[e+1]},i.prototype.previous=function(t){this.sort();var e=o.Adapter.inArray(t,this.waypoints);return e?this.waypoints[e-1]:null},i.findOrCreate=function(t){return r[t.axis][t.name]||new i(t)},o.Group=i}())(function(){"use strict";function t(t){return t===t.window}function e(e){return t(e)?e:e.defaultView}function i(t){this.element=t,this.handlers={}}var r=window.Waypoint;i.prototype.height=function(){var e=t(this.element);return e?this.element.innerHeight:this.element.offsetHeight},i.prototype.off=function(t,e){function i(t,e,i){for(var r=0,o=e.length-1;o>r;r++){var n=e[r];i&&i!==n||t.removeEventListener(n)}}var r=t.split("."),o=r[0],n=r[1],s=this.element;if(n&&this.handlers[n]&&o)i(s,this.handlers[n][o],e),this.handlers[n][o]=[];else if(o)for(var a in this.handlers)i(s,this.handlers[a][o]||[],e),this.handlers[a][o]=[];else if(n&&this.handlers[n]){for(var l in this.handlers[n])i(s,this.handlers[n][l],e);this.handlers[n]={}}},i.prototype.offset=function(){if(!this.element.ownerDocument)return null;var t=this.element.ownerDocument.documentElement,i=e(this.element.ownerDocument),r={top:0,left:0};return this.element.getBoundingClientRect&&(r=this.element.getBoundingClientRect()),{top:r.top+i.pageYOffset-t.clientTop,left:r.left+i.pageXOffset-t.clientLeft}},i.prototype.on=function(t,e){var i=t.split("."),r=i[0],o=i[1]||"__default",n=this.handlers[o]=this.handlers[o]||{},s=n[r]=n[r]||[];s.push(e),this.element.addEventListener(r,e)},i.prototype.outerHeight=function(e){var i,r=this.height();return e&&!t(this.element)&&(i=window.getComputedStyle(this.element),r+=parseInt(i.marginTop,10),r+=parseInt(i.marginBottom,10)),r},i.prototype.outerWidth=function(e){var i,r=this.width();return e&&!t(this.element)&&(i=window.getComputedStyle(this.element),r+=parseInt(i.marginLeft,10),r+=parseInt(i.marginRight,10)),r},i.prototype.scrollLeft=function(){var t=e(this.element);return t?t.pageXOffset:this.element.scrollLeft},i.prototype.scrollTop=function(){var t=e(this.element);return t?t.pageYOffset:this.element.scrollTop},i.prototype.width=function(){var e=t(this.element);return e?this.element.innerWidth:this.element.offsetWidth},i.extend=function(){function t(t,e){if("object"==typeof t&&"object"==typeof e)for(var i in e)e.hasOwnProperty(i)&&(t[i]=e[i]);return t}for(var e=Array.prototype.slice.call(arguments),i=1,r=e.length;r>i;i++)t(e[0],e[i]);return e[0]},i.inArray=function(t,e,i){return null==e?-1:e.indexOf(t,i)},i.isEmptyObject=function(t){for(var e in t)return!1;return!0},r.adapters.push({name:"noframework",Adapter:i}),r.Adapter=i}()); \ No newline at end of file +!function(){"use strict";function t(o){if(!o)throw new Error("No options passed to Waypoint constructor");if(!o.element)throw new Error("No element option passed to Waypoint constructor");this.key="waypoint-"+e,this.options=t.Adapter.extend({},t.defaults,o),this.element=this.options.element,this.adapter=new t.Adapter(this.element),this.callback=o.handler,this.axis=this.options.horizontal?"horizontal":"vertical",this.enabled=this.options.enabled,this.triggerPoint=null,this.group=t.Group.findOrCreate({name:this.options.group,axis:this.axis}),this.context=t.Context.findOrCreateByElement(this.options.context),t.offsetAliases[this.options.offset]&&(this.options.offset=t.offsetAliases[this.options.offset]),this.context.add(this),this.group.add(this),i[this.key]=this,e+=1}var e=0,i={};t.prototype.queueTrigger=function(t){this.group.queueTrigger(this,t)},t.prototype.trigger=function(t){this.enabled&&(this.callback&&this.callback.apply(this,t),this.options.triggerOnce&&this.destroy())},t.prototype.destroy=function(){this.context.remove(this),this.group.remove(this),delete i[this.key]},t.prototype.disable=function(){return this.enabled=!1,this},t.prototype.enable=function(){return this.context.refresh(),this.enabled=!0,this},t.destroyAll=function(){var t=[];for(var e in i)t.push(i[e]);for(var o=0,r=t.length;r>o;o++)t[o].destroy()},t.refreshAll=function(){t.Context.refreshAll()},t.viewportHeight=function(){return window.innerHeight||document.documentElement.clientHeight},t.adapters=[],t.defaults={context:window,continuous:!0,enabled:!0,group:"default",horizontal:!1,offset:0,triggerOnce:!1},t.offsetAliases={"bottom-in-view":function(){return this.context.height()-this.adapter.outerHeight()},"right-in-view":function(){return this.context.adapter.width()-this.adapter.outerWidth()}},window.Waypoint=t}()(function(){"use strict";function t(t){window.setTimeout(t,1e3/60)}function e(t){this.element=t,this.Adapter=r.Adapter,this.adapter=new this.Adapter(t),this.key="waypoint-context-"+i,this.didScroll=!1,this.didResize=!1,this.oldScroll={x:this.adapter.scrollLeft(),y:this.adapter.scrollTop()},this.waypoints={vertical:{},horizontal:{}},t.waypointContextKey=this.key,o[t.waypointContextKey]=this,i+=1,this.createThrottledScrollHandler(),this.createThrottledResizeHandler()}var i=0,o={},r=window.Waypoint,n=window.requestAnimationFrame||window.mozRequestAnimationFrame||window.webkitRequestAnimationFrame||t;e.prototype.add=function(t){var e=t.options.horizontal?"horizontal":"vertical";this.waypoints[e][t.key]=t,this.refresh()},e.prototype.checkEmpty=function(){var t=this.Adapter.isEmptyObject(this.waypoints.horizontal),e=this.Adapter.isEmptyObject(this.waypoints.vertical);t&&e&&(this.adapter.off(".waypoints"),delete o[this.key])},e.prototype.createThrottledResizeHandler=function(){function t(){e.handleResize(),e.didResize=!1}var e=this;this.adapter.on("resize.waypoints",function(){e.didResize||(e.didResize=!0,n(t))})},e.prototype.createThrottledScrollHandler=function(){function t(){e.handleScroll(),e.didScroll=!1}var e=this;this.adapter.on("scroll.waypoints",function(){(!e.didScroll||r.isTouch)&&(e.didScroll=!0,n(t))})},e.prototype.handleResize=function(){r.Context.refreshAll()},e.prototype.handleScroll=function(){var t={},e={horizontal:{newScroll:this.adapter.scrollLeft(),oldScroll:this.oldScroll.x,forward:"right",backward:"left"},vertical:{newScroll:this.adapter.scrollTop(),oldScroll:this.oldScroll.y,forward:"down",backward:"up"}};for(var i in e){var o=e[i],r=o.newScroll>o.oldScroll,n=r?o.forward:o.backward;for(var s in this.waypoints[i]){var a=this.waypoints[i][s],l=o.oldScroll=a.triggerPoint,p=l&&h,f=!l&&!h;(p||f)&&(a.queueTrigger(n),t[a.group.id]=a.group)}}for(var u in t)t[u].flushTriggers();this.oldScroll={x:e.horizontal.newScroll,y:e.vertical.newScroll}},e.prototype.height=function(){return this.element===this.element.window?r.viewportHeight():this.adapter.height()},e.prototype.remove=function(t){delete this.waypoints[t.axis][t.key],this.checkEmpty()},e.prototype.destroy=function(){var t=[];for(var e in this.waypoints)for(var i in this.waypoints[e])t.push(this.waypoints[e][i]);for(var o=0,r=t.length;r>o;o++)t[o].destroy()},e.prototype.refresh=function(){var t,e=this.element===this.element.window,i=this.adapter.offset(),o=e?r.viewportHeight():this.adapter.height(),n={};this.handleScroll(),t={horizontal:{contextOffset:e?0:i.left,contextScroll:e?0:this.oldScroll.x,contextDimension:this.adapter.width(),oldScroll:this.oldScroll.x,forward:"right",backward:"left",offsetProp:"left"},vertical:{contextOffset:e?0:i.top,contextScroll:e?0:this.oldScroll.y,contextDimension:o,oldScroll:this.oldScroll.y,forward:"down",backward:"up",offsetProp:"top"}};for(var s in t){var a=t[s];for(var l in this.waypoints[s]){var h,p,f,u,c,d=this.waypoints[s][l],g=d.options.offset,y=d.triggerPoint,w=0,m=null==y;d.element!==d.element.window&&(w=d.adapter.offset()[a.offsetProp]),"function"==typeof g?g=g.apply(d):"string"==typeof g&&(g=parseFloat(g),d.options.offset.indexOf("%")>-1&&(g=Math.ceil(a.contextDimension*g/100))),h=a.contextScroll-a.contextOffset,d.triggerPoint=w+h-g,p=y=a.oldScroll,u=p&&f,c=!p&&!f,!m&&u?(d.queueTrigger(a.backward),n[d.group.id]=d.group):!m&&c?(d.queueTrigger(a.forward),n[d.group.id]=d.group):m&&a.oldScroll>=d.triggerPoint&&(d.queueTrigger(a.forward),n[d.group.id]=d.group)}}for(var v in n)n[v].flushTriggers();return this},e.findOrCreateByElement=function(t){return e.findByElement(t)||new e(t)},e.findByElement=function(t){return o[t.waypointContextKey]},e.refreshAll=function(){for(var t in o)o[t].refresh()},r.Context=e}())(function(){"use strict";function t(t,e){return t.triggerPoint-e.triggerPoint}function e(t,e){return e.triggerPoint-t.triggerPoint}function i(t){this.name=t.name,this.axis=t.axis,this.id=this.name+"-"+this.axis,this.waypoints=[],this.clearTriggerQueues(),o[this.axis][this.name]=this}var o={vertical:{},horizontal:{}},r=window.Waypoint;i.prototype.add=function(t){this.waypoints.push(t)},i.prototype.clearTriggerQueues=function(){this.triggerQueues={up:[],down:[],left:[],right:[]}},i.prototype.flushTriggers=function(){for(var i in this.triggerQueues){var o=this.triggerQueues[i],r="up"===i||"left"===i;o.sort(r?e:t);for(var n=0,s=o.length;s>n;n+=1){var a=o[n];(a.options.continuous||n===o.length-1)&&a.trigger([i])}}this.clearTriggerQueues()},i.prototype.queueTrigger=function(t,e){this.triggerQueues[e].push(t)},i.prototype.remove=function(t){var e=r.Adapter.inArray(t,this.waypoints);e>-1&&this.waypoints.splice(e,1)},i.prototype.sort=function(){this.waypoints.sort(function(t,e){return t.triggerPoint-e.triggerPoint})},i.prototype.first=function(){return this.waypoints[0]},i.prototype.last=function(){return this.waypoints[this.waypoints.length-1]},i.prototype.next=function(t){this.sort();var e=r.Adapter.inArray(t,this.waypoints),i=e===this.waypoints.length-1;return i?null:this.waypoints[e+1]},i.prototype.previous=function(t){this.sort();var e=r.Adapter.inArray(t,this.waypoints);return e?this.waypoints[e-1]:null},i.findOrCreate=function(t){return o[t.axis][t.name]||new i(t)},r.Group=i}())(function(){"use strict";function t(t){return t===t.window}function e(e){return t(e)?e:e.defaultView}function i(t){this.element=t,this.handlers={}}var o=window.Waypoint;i.prototype.height=function(){var e=t(this.element);return e?this.element.innerHeight:this.element.offsetHeight},i.prototype.off=function(t,e){function i(t,e,i){for(var o=0,r=e.length-1;r>o;o++){var n=e[o];i&&i!==n||t.removeEventListener(n)}}var o=t.split("."),r=o[0],n=o[1],s=this.element;if(n&&this.handlers[n]&&r)i(s,this.handlers[n][r],e),this.handlers[n][r]=[];else if(r)for(var a in this.handlers)i(s,this.handlers[a][r]||[],e),this.handlers[a][r]=[];else if(n&&this.handlers[n]){for(var l in this.handlers[n])i(s,this.handlers[n][l],e);this.handlers[n]={}}},i.prototype.offset=function(){if(!this.element.ownerDocument)return null;var t=this.element.ownerDocument.documentElement,i=e(this.element.ownerDocument),o={top:0,left:0};return this.element.getBoundingClientRect&&(o=this.element.getBoundingClientRect()),{top:o.top+i.pageYOffset-t.clientTop,left:o.left+i.pageXOffset-t.clientLeft}},i.prototype.on=function(t,e){var i=t.split("."),o=i[0],r=i[1]||"__default",n=this.handlers[r]=this.handlers[r]||{},s=n[o]=n[o]||[];s.push(e),this.element.addEventListener(o,e)},i.prototype.outerHeight=function(e){var i,o=this.height();return e&&!t(this.element)&&(i=window.getComputedStyle(this.element),o+=parseInt(i.marginTop,10),o+=parseInt(i.marginBottom,10)),o},i.prototype.outerWidth=function(e){var i,o=this.width();return e&&!t(this.element)&&(i=window.getComputedStyle(this.element),o+=parseInt(i.marginLeft,10),o+=parseInt(i.marginRight,10)),o},i.prototype.scrollLeft=function(){var t=e(this.element);return t?t.pageXOffset:this.element.scrollLeft},i.prototype.scrollTop=function(){var t=e(this.element);return t?t.pageYOffset:this.element.scrollTop},i.prototype.width=function(){var e=t(this.element);return e?this.element.innerWidth:this.element.offsetWidth},i.extend=function(){function t(t,e){if("object"==typeof t&&"object"==typeof e)for(var i in e)e.hasOwnProperty(i)&&(t[i]=e[i]);return t}for(var e=Array.prototype.slice.call(arguments),i=1,o=e.length;o>i;i++)t(e[0],e[i]);return e[0]},i.inArray=function(t,e,i){return null==e?-1:e.indexOf(t,i)},i.isEmptyObject=function(t){for(var e in t)return!1;return!0},o.adapters.push({name:"noframework",Adapter:i}),o.Adapter=i}()); \ No newline at end of file diff --git a/lib/zepto.waypoints.js b/lib/zepto.waypoints.js index e37b0a86..fb435003 100644 --- a/lib/zepto.waypoints.js +++ b/lib/zepto.waypoints.js @@ -41,6 +41,11 @@ https://github.com/imakewebthings/waypoints/blog/master/licenses.txt keyCounter += 1 } + /* Private */ + Waypoint.prototype.queueTrigger = function(direction) { + this.group.queueTrigger(this, direction) + } + /* Private */ Waypoint.prototype.trigger = function(args) { if (!this.enabled) { @@ -54,9 +59,11 @@ https://github.com/imakewebthings/waypoints/blog/master/licenses.txt } } - /* Private */ - Waypoint.prototype.queueTrigger = function(direction) { - this.group.queueTrigger(this, direction) + /* Public */ + Waypoint.prototype.destroy = function() { + this.context.remove(this) + this.group.remove(this) + delete allWaypoints[this.key] } /* Public */ @@ -72,13 +79,6 @@ https://github.com/imakewebthings/waypoints/blog/master/licenses.txt return this } - /* Public */ - Waypoint.prototype.destroy = function() { - this.context.remove(this) - this.group.remove(this) - delete allWaypoints[this.key] - } - /* Public */ Waypoint.destroyAll = function() { var allWaypointsArray = [] @@ -120,7 +120,6 @@ https://github.com/imakewebthings/waypoints/blog/master/licenses.txt return this.context.adapter.width() - this.adapter.outerWidth() } } - } window.Waypoint = Waypoint }()) diff --git a/lib/zepto.waypoints.min.js b/lib/zepto.waypoints.min.js index 9f128bc5..dd1a9e9c 100644 --- a/lib/zepto.waypoints.min.js +++ b/lib/zepto.waypoints.min.js @@ -4,4 +4,4 @@ Copyright © 2011-2014 Caleb Troughton Licensed under the MIT license. https://github.com/imakewebthings/waypoints/blog/master/licenses.txt */ -!function(){"use strict";function t(o){if(!o)throw new Error("No options passed to Waypoint constructor");if(!o.element)throw new Error("No element option passed to Waypoint constructor");this.key="waypoint-"+e,this.options=t.Adapter.extend({},t.defaults,o),this.element=this.options.element,this.adapter=new t.Adapter(this.element),this.callback=o.handler,this.axis=this.options.horizontal?"horizontal":"vertical",this.enabled=this.options.enabled,this.triggerPoint=null,this.group=t.Group.findOrCreate({name:this.options.group,axis:this.axis}),this.context=t.Context.findOrCreateByElement(this.options.context),t.offsetAliases[this.options.offset]&&(this.options.offset=t.offsetAliases[this.options.offset]),this.context.add(this),this.group.add(this),i[this.key]=this,e+=1}var e=0,i={};t.prototype.trigger=function(t){this.enabled&&(this.callback&&this.callback.apply(this,t),this.options.triggerOnce&&this.destroy())},t.prototype.queueTrigger=function(t){this.group.queueTrigger(this,t)},t.prototype.disable=function(){return this.enabled=!1,this},t.prototype.enable=function(){return this.context.refresh(),this.enabled=!0,this},t.prototype.destroy=function(){this.context.remove(this),this.group.remove(this),delete i[this.key]},t.destroyAll=function(){var t=[];for(var e in i)t.push(i[e]);for(var o=0,r=t.length;r>o;o++)t[o].destroy()},t.refreshAll=function(){t.Context.refreshAll()},t.viewportHeight=function(){return window.innerHeight||document.documentElement.clientHeight},window.Waypoint=t}()(function(){"use strict";function t(t){window.setTimeout(t,1e3/60)}function e(t){this.element=t,this.Adapter=r.Adapter,this.adapter=new this.Adapter(t),this.key="waypoint-context-"+i,this.didScroll=!1,this.didResize=!1,this.oldScroll={x:this.adapter.scrollLeft(),y:this.adapter.scrollTop()},this.waypoints={vertical:{},horizontal:{}},t.waypointContextKey=this.key,o[t.waypointContextKey]=this,i+=1,this.createThrottledScrollHandler(),this.createThrottledResizeHandler()}var i=0,o={},r=window.Waypoint,n=window.requestAnimationFrame||window.mozRequestAnimationFrame||window.webkitRequestAnimationFrame||t;e.prototype.add=function(t){var e=t.options.horizontal?"horizontal":"vertical";this.waypoints[e][t.key]=t,this.refresh()},e.prototype.checkEmpty=function(){var t=this.Adapter.isEmptyObject(this.waypoints.horizontal),e=this.Adapter.isEmptyObject(this.waypoints.vertical);t&&e&&(this.adapter.off(".waypoints"),delete o[this.key])},e.prototype.createThrottledResizeHandler=function(){function t(){e.handleResize(),e.didResize=!1}var e=this;this.adapter.on("resize.waypoints",function(){e.didResize||(e.didResize=!0,n(t))})},e.prototype.createThrottledScrollHandler=function(){function t(){e.handleScroll(),e.didScroll=!1}var e=this;this.adapter.on("scroll.waypoints",function(){(!e.didScroll||r.isTouch)&&(e.didScroll=!0,n(t))})},e.prototype.handleResize=function(){r.Context.refreshAll()},e.prototype.handleScroll=function(){var t={},e={horizontal:{newScroll:this.adapter.scrollLeft(),oldScroll:this.oldScroll.x,forward:"right",backward:"left"},vertical:{newScroll:this.adapter.scrollTop(),oldScroll:this.oldScroll.y,forward:"down",backward:"up"}};for(var i in e){var o=e[i],r=o.newScroll>o.oldScroll,n=r?o.forward:o.backward;for(var s in this.waypoints[i]){var a=this.waypoints[i][s],l=o.oldScroll=a.triggerPoint,p=l&&h,c=!l&&!h;(p||c)&&(a.queueTrigger(n),t[a.group.id]=a.group)}}for(var u in t)t[u].flushTriggers();this.oldScroll={x:e.horizontal.newScroll,y:e.vertical.newScroll}},e.prototype.height=function(){return this.element===this.element.window?r.viewportHeight():this.adapter.height()},e.prototype.remove=function(t){delete this.waypoints[t.axis][t.key],this.checkEmpty()},e.prototype.destroy=function(){var t=[];for(var e in this.waypoints)for(var i in this.waypoints[e])t.push(this.waypoints[e][i]);for(var o=0,r=t.length;r>o;o++)t[o].destroy()},e.prototype.refresh=function(){var t,e=this.element===this.element.window,i=this.adapter.offset(),o=e?r.viewportHeight():this.adapter.height(),n={};this.handleScroll(),t={horizontal:{contextOffset:e?0:i.left,contextScroll:e?0:this.oldScroll.x,contextDimension:this.adapter.width(),oldScroll:this.oldScroll.x,forward:"right",backward:"left",offsetProp:"left"},vertical:{contextOffset:e?0:i.top,contextScroll:e?0:this.oldScroll.y,contextDimension:o,oldScroll:this.oldScroll.y,forward:"down",backward:"up",offsetProp:"top"}};for(var s in t){var a=t[s];for(var l in this.waypoints[s]){var h,p,c,u,d,f=this.waypoints[s][l],y=f.options.offset,g=f.triggerPoint,w=0,m=null==g;f.element!==f.element.window&&(w=f.adapter.offset()[a.offsetProp]),"function"==typeof y?y=y.apply(f):"string"==typeof y&&(y=parseFloat(y),f.options.offset.indexOf("%")>-1&&(y=Math.ceil(a.contextDimension*y/100))),h=a.contextScroll-a.contextOffset,f.triggerPoint=w+h-y,p=g=a.oldScroll,u=p&&c,d=!p&&!c,!m&&u?(f.queueTrigger(a.backward),n[f.group.id]=f.group):!m&&d?(f.queueTrigger(a.forward),n[f.group.id]=f.group):m&&a.oldScroll>=f.triggerPoint&&(f.queueTrigger(a.forward),n[f.group.id]=f.group)}}for(var v in n)n[v].flushTriggers();return this},e.findOrCreateByElement=function(t){return e.findByElement(t)||new e(t)},e.findByElement=function(t){return o[t.waypointContextKey]},e.refreshAll=function(){for(var t in o)o[t].refresh()},r.Context=e}())(function(){"use strict";function t(t,e){return t.triggerPoint-e.triggerPoint}function e(t,e){return e.triggerPoint-t.triggerPoint}function i(t){this.name=t.name,this.axis=t.axis,this.id=this.name+"-"+this.axis,this.waypoints=[],this.clearTriggerQueues(),o[this.axis][this.name]=this}var o={vertical:{},horizontal:{}},r=window.Waypoint;i.prototype.add=function(t){this.waypoints.push(t)},i.prototype.clearTriggerQueues=function(){this.triggerQueues={up:[],down:[],left:[],right:[]}},i.prototype.flushTriggers=function(){for(var i in this.triggerQueues){var o=this.triggerQueues[i],r="up"===i||"left"===i;o.sort(r?e:t);for(var n=0,s=o.length;s>n;n+=1){var a=o[n];(a.options.continuous||n===o.length-1)&&a.trigger([i])}}this.clearTriggerQueues()},i.prototype.queueTrigger=function(t,e){this.triggerQueues[e].push(t)},i.prototype.remove=function(t){var e=r.Adapter.inArray(t,this.waypoints);e>-1&&this.waypoints.splice(e,1)},i.prototype.sort=function(){this.waypoints.sort(function(t,e){return t.triggerPoint-e.triggerPoint})},i.prototype.first=function(){return this.waypoints[0]},i.prototype.last=function(){return this.waypoints[this.waypoints.length-1]},i.prototype.next=function(t){this.sort();var e=r.Adapter.inArray(t,this.waypoints),i=e===this.waypoints.length-1;return i?null:this.waypoints[e+1]},i.prototype.previous=function(t){this.sort();var e=r.Adapter.inArray(t,this.waypoints);return e?this.waypoints[e-1]:null},i.findOrCreate=function(t){return o[t.axis][t.name]||new i(t)},r.Group=i}())(function(){"use strict";function t(t){this.element=t,this.$element=e(t)}var e=window.Zepto,i=window.Waypoint;e.each(["height","off","on","scrollLeft","scrollTop","width"],function(e,i){t.prototype[i]=function(){var t=Array.prototype.slice.call(arguments);return this.$element[i].apply(this.$element,t)}}),t.prototype.offset=function(){return this.element!==this.element.window?this.$element.offset():void 0},e.each(["width","height"],function(i,o){var r=e.camelCase("outer-"+o);t.prototype[r]=function(t){var i=this.$element[o](),r={width:["left","right"],height:["top","bottom"]};return t&&e.each(r[o],e.proxy(function(t,e){i+=parseInt(this.$element.css("margin-"+e),10)},this)),i}}),e.each(["extend","inArray"],function(i,o){t[o]=e[o]}),t.isEmptyObject=function(t){for(var e in t)return!1;return!0},i.adapters.push({name:"zepto",Adapter:t}),i.Adapter=t}()); \ No newline at end of file +!function(){"use strict";function t(o){if(!o)throw new Error("No options passed to Waypoint constructor");if(!o.element)throw new Error("No element option passed to Waypoint constructor");this.key="waypoint-"+e,this.options=t.Adapter.extend({},t.defaults,o),this.element=this.options.element,this.adapter=new t.Adapter(this.element),this.callback=o.handler,this.axis=this.options.horizontal?"horizontal":"vertical",this.enabled=this.options.enabled,this.triggerPoint=null,this.group=t.Group.findOrCreate({name:this.options.group,axis:this.axis}),this.context=t.Context.findOrCreateByElement(this.options.context),t.offsetAliases[this.options.offset]&&(this.options.offset=t.offsetAliases[this.options.offset]),this.context.add(this),this.group.add(this),i[this.key]=this,e+=1}var e=0,i={};t.prototype.queueTrigger=function(t){this.group.queueTrigger(this,t)},t.prototype.trigger=function(t){this.enabled&&(this.callback&&this.callback.apply(this,t),this.options.triggerOnce&&this.destroy())},t.prototype.destroy=function(){this.context.remove(this),this.group.remove(this),delete i[this.key]},t.prototype.disable=function(){return this.enabled=!1,this},t.prototype.enable=function(){return this.context.refresh(),this.enabled=!0,this},t.destroyAll=function(){var t=[];for(var e in i)t.push(i[e]);for(var o=0,r=t.length;r>o;o++)t[o].destroy()},t.refreshAll=function(){t.Context.refreshAll()},t.viewportHeight=function(){return window.innerHeight||document.documentElement.clientHeight},t.adapters=[],t.defaults={context:window,continuous:!0,enabled:!0,group:"default",horizontal:!1,offset:0,triggerOnce:!1},t.offsetAliases={"bottom-in-view":function(){return this.context.height()-this.adapter.outerHeight()},"right-in-view":function(){return this.context.adapter.width()-this.adapter.outerWidth()}},window.Waypoint=t}()(function(){"use strict";function t(t){window.setTimeout(t,1e3/60)}function e(t){this.element=t,this.Adapter=r.Adapter,this.adapter=new this.Adapter(t),this.key="waypoint-context-"+i,this.didScroll=!1,this.didResize=!1,this.oldScroll={x:this.adapter.scrollLeft(),y:this.adapter.scrollTop()},this.waypoints={vertical:{},horizontal:{}},t.waypointContextKey=this.key,o[t.waypointContextKey]=this,i+=1,this.createThrottledScrollHandler(),this.createThrottledResizeHandler()}var i=0,o={},r=window.Waypoint,n=window.requestAnimationFrame||window.mozRequestAnimationFrame||window.webkitRequestAnimationFrame||t;e.prototype.add=function(t){var e=t.options.horizontal?"horizontal":"vertical";this.waypoints[e][t.key]=t,this.refresh()},e.prototype.checkEmpty=function(){var t=this.Adapter.isEmptyObject(this.waypoints.horizontal),e=this.Adapter.isEmptyObject(this.waypoints.vertical);t&&e&&(this.adapter.off(".waypoints"),delete o[this.key])},e.prototype.createThrottledResizeHandler=function(){function t(){e.handleResize(),e.didResize=!1}var e=this;this.adapter.on("resize.waypoints",function(){e.didResize||(e.didResize=!0,n(t))})},e.prototype.createThrottledScrollHandler=function(){function t(){e.handleScroll(),e.didScroll=!1}var e=this;this.adapter.on("scroll.waypoints",function(){(!e.didScroll||r.isTouch)&&(e.didScroll=!0,n(t))})},e.prototype.handleResize=function(){r.Context.refreshAll()},e.prototype.handleScroll=function(){var t={},e={horizontal:{newScroll:this.adapter.scrollLeft(),oldScroll:this.oldScroll.x,forward:"right",backward:"left"},vertical:{newScroll:this.adapter.scrollTop(),oldScroll:this.oldScroll.y,forward:"down",backward:"up"}};for(var i in e){var o=e[i],r=o.newScroll>o.oldScroll,n=r?o.forward:o.backward;for(var s in this.waypoints[i]){var a=this.waypoints[i][s],l=o.oldScroll=a.triggerPoint,p=l&&h,c=!l&&!h;(p||c)&&(a.queueTrigger(n),t[a.group.id]=a.group)}}for(var u in t)t[u].flushTriggers();this.oldScroll={x:e.horizontal.newScroll,y:e.vertical.newScroll}},e.prototype.height=function(){return this.element===this.element.window?r.viewportHeight():this.adapter.height()},e.prototype.remove=function(t){delete this.waypoints[t.axis][t.key],this.checkEmpty()},e.prototype.destroy=function(){var t=[];for(var e in this.waypoints)for(var i in this.waypoints[e])t.push(this.waypoints[e][i]);for(var o=0,r=t.length;r>o;o++)t[o].destroy()},e.prototype.refresh=function(){var t,e=this.element===this.element.window,i=this.adapter.offset(),o=e?r.viewportHeight():this.adapter.height(),n={};this.handleScroll(),t={horizontal:{contextOffset:e?0:i.left,contextScroll:e?0:this.oldScroll.x,contextDimension:this.adapter.width(),oldScroll:this.oldScroll.x,forward:"right",backward:"left",offsetProp:"left"},vertical:{contextOffset:e?0:i.top,contextScroll:e?0:this.oldScroll.y,contextDimension:o,oldScroll:this.oldScroll.y,forward:"down",backward:"up",offsetProp:"top"}};for(var s in t){var a=t[s];for(var l in this.waypoints[s]){var h,p,c,u,d,f=this.waypoints[s][l],y=f.options.offset,g=f.triggerPoint,w=0,m=null==g;f.element!==f.element.window&&(w=f.adapter.offset()[a.offsetProp]),"function"==typeof y?y=y.apply(f):"string"==typeof y&&(y=parseFloat(y),f.options.offset.indexOf("%")>-1&&(y=Math.ceil(a.contextDimension*y/100))),h=a.contextScroll-a.contextOffset,f.triggerPoint=w+h-y,p=g=a.oldScroll,u=p&&c,d=!p&&!c,!m&&u?(f.queueTrigger(a.backward),n[f.group.id]=f.group):!m&&d?(f.queueTrigger(a.forward),n[f.group.id]=f.group):m&&a.oldScroll>=f.triggerPoint&&(f.queueTrigger(a.forward),n[f.group.id]=f.group)}}for(var v in n)n[v].flushTriggers();return this},e.findOrCreateByElement=function(t){return e.findByElement(t)||new e(t)},e.findByElement=function(t){return o[t.waypointContextKey]},e.refreshAll=function(){for(var t in o)o[t].refresh()},r.Context=e}())(function(){"use strict";function t(t,e){return t.triggerPoint-e.triggerPoint}function e(t,e){return e.triggerPoint-t.triggerPoint}function i(t){this.name=t.name,this.axis=t.axis,this.id=this.name+"-"+this.axis,this.waypoints=[],this.clearTriggerQueues(),o[this.axis][this.name]=this}var o={vertical:{},horizontal:{}},r=window.Waypoint;i.prototype.add=function(t){this.waypoints.push(t)},i.prototype.clearTriggerQueues=function(){this.triggerQueues={up:[],down:[],left:[],right:[]}},i.prototype.flushTriggers=function(){for(var i in this.triggerQueues){var o=this.triggerQueues[i],r="up"===i||"left"===i;o.sort(r?e:t);for(var n=0,s=o.length;s>n;n+=1){var a=o[n];(a.options.continuous||n===o.length-1)&&a.trigger([i])}}this.clearTriggerQueues()},i.prototype.queueTrigger=function(t,e){this.triggerQueues[e].push(t)},i.prototype.remove=function(t){var e=r.Adapter.inArray(t,this.waypoints);e>-1&&this.waypoints.splice(e,1)},i.prototype.sort=function(){this.waypoints.sort(function(t,e){return t.triggerPoint-e.triggerPoint})},i.prototype.first=function(){return this.waypoints[0]},i.prototype.last=function(){return this.waypoints[this.waypoints.length-1]},i.prototype.next=function(t){this.sort();var e=r.Adapter.inArray(t,this.waypoints),i=e===this.waypoints.length-1;return i?null:this.waypoints[e+1]},i.prototype.previous=function(t){this.sort();var e=r.Adapter.inArray(t,this.waypoints);return e?this.waypoints[e-1]:null},i.findOrCreate=function(t){return o[t.axis][t.name]||new i(t)},r.Group=i}())(function(){"use strict";function t(t){this.element=t,this.$element=e(t)}var e=window.Zepto,i=window.Waypoint;e.each(["height","off","on","scrollLeft","scrollTop","width"],function(e,i){t.prototype[i]=function(){var t=Array.prototype.slice.call(arguments);return this.$element[i].apply(this.$element,t)}}),t.prototype.offset=function(){return this.element!==this.element.window?this.$element.offset():void 0},e.each(["width","height"],function(i,o){var r=e.camelCase("outer-"+o);t.prototype[r]=function(t){var i=this.$element[o](),r={width:["left","right"],height:["top","bottom"]};return t&&e.each(r[o],e.proxy(function(t,e){i+=parseInt(this.$element.css("margin-"+e),10)},this)),i}}),e.each(["extend","inArray"],function(i,o){t[o]=e[o]}),t.isEmptyObject=function(t){for(var e in t)return!1;return!0},i.adapters.push({name:"zepto",Adapter:t}),i.Adapter=t}()); \ No newline at end of file diff --git a/src/waypoint.js b/src/waypoint.js index aa42b8ac..2b50ed3e 100644 --- a/src/waypoint.js +++ b/src/waypoint.js @@ -35,6 +35,11 @@ keyCounter += 1 } + /* Private */ + Waypoint.prototype.queueTrigger = function(direction) { + this.group.queueTrigger(this, direction) + } + /* Private */ Waypoint.prototype.trigger = function(args) { if (!this.enabled) { @@ -48,9 +53,11 @@ } } - /* Private */ - Waypoint.prototype.queueTrigger = function(direction) { - this.group.queueTrigger(this, direction) + /* Public */ + Waypoint.prototype.destroy = function() { + this.context.remove(this) + this.group.remove(this) + delete allWaypoints[this.key] } /* Public */ @@ -66,13 +73,6 @@ return this } - /* Public */ - Waypoint.prototype.destroy = function() { - this.context.remove(this) - this.group.remove(this) - delete allWaypoints[this.key] - } - /* Public */ Waypoint.destroyAll = function() { var allWaypointsArray = [] From 836b0387f3f9e31c29b0db1f7a7378c38c5dd583 Mon Sep 17 00:00:00 2001 From: imakewebthings Date: Mon, 23 Jun 2014 15:34:42 -0700 Subject: [PATCH 26/98] Waypoint prev/next, viewportWidth --- lib/jquery.waypoints.js | 30 +++++++++++++--- lib/jquery.waypoints.min.js | 2 +- lib/noframework.waypoints.js | 30 +++++++++++++--- lib/noframework.waypoints.min.js | 2 +- lib/zepto.waypoints.js | 30 +++++++++++++--- lib/zepto.waypoints.min.js | 2 +- src/context.js | 13 +++++-- src/waypoint.js | 17 ++++++++- test/sticky-spec.js | 3 ++ test/waypoint-spec.js | 59 +++++++++++++++++++++++++++----- testem.json | 2 +- 11 files changed, 161 insertions(+), 29 deletions(-) diff --git a/lib/jquery.waypoints.js b/lib/jquery.waypoints.js index ba877fa1..30f5279f 100644 --- a/lib/jquery.waypoints.js +++ b/lib/jquery.waypoints.js @@ -79,6 +79,16 @@ https://github.com/imakewebthings/waypoints/blog/master/licenses.txt return this } + /* Public */ + Waypoint.prototype.previous = function() { + return this.group.previous(this) + } + + /* Public */ + Waypoint.prototype.next = function() { + return this.group.next(this) + } + /* Public */ Waypoint.destroyAll = function() { var allWaypointsArray = [] @@ -100,6 +110,11 @@ https://github.com/imakewebthings/waypoints/blog/master/licenses.txt return window.innerHeight || document.documentElement.clientHeight } + /* Public */ + Waypoint.viewportWidth = function() { + return document.documentElement.clientWidth + } + Waypoint.adapters = [] Waypoint.defaults = { @@ -117,7 +132,7 @@ https://github.com/imakewebthings/waypoints/blog/master/licenses.txt return this.context.height() - this.adapter.outerHeight() }, 'right-in-view': function() { - return this.context.adapter.width() - this.adapter.outerWidth() + return this.context.width() - this.adapter.outerWidth() } } @@ -278,6 +293,14 @@ https://github.com/imakewebthings/waypoints/blog/master/licenses.txt this.checkEmpty() } + /* Private */ + Context.prototype.width = function() { + if (this.element === this.element.window) { + return Waypoint.viewportWidth() + } + return this.adapter.width() + } + /* Public */ Context.prototype.destroy = function() { var allWaypoints = [] @@ -295,7 +318,6 @@ https://github.com/imakewebthings/waypoints/blog/master/licenses.txt Context.prototype.refresh = function() { var isWindow = this.element === this.element.window var contextOffset = this.adapter.offset() - var height = isWindow ? Waypoint.viewportHeight() : this.adapter.height() var triggeredGroups = {} var axes @@ -304,7 +326,7 @@ https://github.com/imakewebthings/waypoints/blog/master/licenses.txt horizontal: { contextOffset: isWindow ? 0 : contextOffset.left, contextScroll: isWindow ? 0 : this.oldScroll.x, - contextDimension: this.adapter.width(), + contextDimension: this.width(), oldScroll: this.oldScroll.x, forward: 'right', backward: 'left', @@ -313,7 +335,7 @@ https://github.com/imakewebthings/waypoints/blog/master/licenses.txt vertical: { contextOffset: isWindow ? 0 : contextOffset.top, contextScroll: isWindow ? 0 : this.oldScroll.y, - contextDimension: height, + contextDimension: this.height(), oldScroll: this.oldScroll.y, forward: 'down', backward: 'up', diff --git a/lib/jquery.waypoints.min.js b/lib/jquery.waypoints.min.js index c2f3aa38..0163464a 100644 --- a/lib/jquery.waypoints.min.js +++ b/lib/jquery.waypoints.min.js @@ -4,4 +4,4 @@ Copyright © 2011-2014 Caleb Troughton Licensed under the MIT license. https://github.com/imakewebthings/waypoints/blog/master/licenses.txt */ -!function(){"use strict";function t(o){if(!o)throw new Error("No options passed to Waypoint constructor");if(!o.element)throw new Error("No element option passed to Waypoint constructor");this.key="waypoint-"+e,this.options=t.Adapter.extend({},t.defaults,o),this.element=this.options.element,this.adapter=new t.Adapter(this.element),this.callback=o.handler,this.axis=this.options.horizontal?"horizontal":"vertical",this.enabled=this.options.enabled,this.triggerPoint=null,this.group=t.Group.findOrCreate({name:this.options.group,axis:this.axis}),this.context=t.Context.findOrCreateByElement(this.options.context),t.offsetAliases[this.options.offset]&&(this.options.offset=t.offsetAliases[this.options.offset]),this.context.add(this),this.group.add(this),i[this.key]=this,e+=1}var e=0,i={};t.prototype.queueTrigger=function(t){this.group.queueTrigger(this,t)},t.prototype.trigger=function(t){this.enabled&&(this.callback&&this.callback.apply(this,t),this.options.triggerOnce&&this.destroy())},t.prototype.destroy=function(){this.context.remove(this),this.group.remove(this),delete i[this.key]},t.prototype.disable=function(){return this.enabled=!1,this},t.prototype.enable=function(){return this.context.refresh(),this.enabled=!0,this},t.destroyAll=function(){var t=[];for(var e in i)t.push(i[e]);for(var o=0,r=t.length;r>o;o++)t[o].destroy()},t.refreshAll=function(){t.Context.refreshAll()},t.viewportHeight=function(){return window.innerHeight||document.documentElement.clientHeight},t.adapters=[],t.defaults={context:window,continuous:!0,enabled:!0,group:"default",horizontal:!1,offset:0,triggerOnce:!1},t.offsetAliases={"bottom-in-view":function(){return this.context.height()-this.adapter.outerHeight()},"right-in-view":function(){return this.context.adapter.width()-this.adapter.outerWidth()}},window.Waypoint=t}()(function(){"use strict";function t(t){window.setTimeout(t,1e3/60)}function e(t){this.element=t,this.Adapter=r.Adapter,this.adapter=new this.Adapter(t),this.key="waypoint-context-"+i,this.didScroll=!1,this.didResize=!1,this.oldScroll={x:this.adapter.scrollLeft(),y:this.adapter.scrollTop()},this.waypoints={vertical:{},horizontal:{}},t.waypointContextKey=this.key,o[t.waypointContextKey]=this,i+=1,this.createThrottledScrollHandler(),this.createThrottledResizeHandler()}var i=0,o={},r=window.Waypoint,n=window.requestAnimationFrame||window.mozRequestAnimationFrame||window.webkitRequestAnimationFrame||t;e.prototype.add=function(t){var e=t.options.horizontal?"horizontal":"vertical";this.waypoints[e][t.key]=t,this.refresh()},e.prototype.checkEmpty=function(){var t=this.Adapter.isEmptyObject(this.waypoints.horizontal),e=this.Adapter.isEmptyObject(this.waypoints.vertical);t&&e&&(this.adapter.off(".waypoints"),delete o[this.key])},e.prototype.createThrottledResizeHandler=function(){function t(){e.handleResize(),e.didResize=!1}var e=this;this.adapter.on("resize.waypoints",function(){e.didResize||(e.didResize=!0,n(t))})},e.prototype.createThrottledScrollHandler=function(){function t(){e.handleScroll(),e.didScroll=!1}var e=this;this.adapter.on("scroll.waypoints",function(){(!e.didScroll||r.isTouch)&&(e.didScroll=!0,n(t))})},e.prototype.handleResize=function(){r.Context.refreshAll()},e.prototype.handleScroll=function(){var t={},e={horizontal:{newScroll:this.adapter.scrollLeft(),oldScroll:this.oldScroll.x,forward:"right",backward:"left"},vertical:{newScroll:this.adapter.scrollTop(),oldScroll:this.oldScroll.y,forward:"down",backward:"up"}};for(var i in e){var o=e[i],r=o.newScroll>o.oldScroll,n=r?o.forward:o.backward;for(var s in this.waypoints[i]){var a=this.waypoints[i][s],l=o.oldScroll=a.triggerPoint,p=l&&h,c=!l&&!h;(p||c)&&(a.queueTrigger(n),t[a.group.id]=a.group)}}for(var u in t)t[u].flushTriggers();this.oldScroll={x:e.horizontal.newScroll,y:e.vertical.newScroll}},e.prototype.height=function(){return this.element===this.element.window?r.viewportHeight():this.adapter.height()},e.prototype.remove=function(t){delete this.waypoints[t.axis][t.key],this.checkEmpty()},e.prototype.destroy=function(){var t=[];for(var e in this.waypoints)for(var i in this.waypoints[e])t.push(this.waypoints[e][i]);for(var o=0,r=t.length;r>o;o++)t[o].destroy()},e.prototype.refresh=function(){var t,e=this.element===this.element.window,i=this.adapter.offset(),o=e?r.viewportHeight():this.adapter.height(),n={};this.handleScroll(),t={horizontal:{contextOffset:e?0:i.left,contextScroll:e?0:this.oldScroll.x,contextDimension:this.adapter.width(),oldScroll:this.oldScroll.x,forward:"right",backward:"left",offsetProp:"left"},vertical:{contextOffset:e?0:i.top,contextScroll:e?0:this.oldScroll.y,contextDimension:o,oldScroll:this.oldScroll.y,forward:"down",backward:"up",offsetProp:"top"}};for(var s in t){var a=t[s];for(var l in this.waypoints[s]){var h,p,c,u,d,f=this.waypoints[s][l],y=f.options.offset,g=f.triggerPoint,w=0,v=null==g;f.element!==f.element.window&&(w=f.adapter.offset()[a.offsetProp]),"function"==typeof y?y=y.apply(f):"string"==typeof y&&(y=parseFloat(y),f.options.offset.indexOf("%")>-1&&(y=Math.ceil(a.contextDimension*y/100))),h=a.contextScroll-a.contextOffset,f.triggerPoint=w+h-y,p=g=a.oldScroll,u=p&&c,d=!p&&!c,!v&&u?(f.queueTrigger(a.backward),n[f.group.id]=f.group):!v&&d?(f.queueTrigger(a.forward),n[f.group.id]=f.group):v&&a.oldScroll>=f.triggerPoint&&(f.queueTrigger(a.forward),n[f.group.id]=f.group)}}for(var m in n)n[m].flushTriggers();return this},e.findOrCreateByElement=function(t){return e.findByElement(t)||new e(t)},e.findByElement=function(t){return o[t.waypointContextKey]},e.refreshAll=function(){for(var t in o)o[t].refresh()},r.Context=e}())(function(){"use strict";function t(t,e){return t.triggerPoint-e.triggerPoint}function e(t,e){return e.triggerPoint-t.triggerPoint}function i(t){this.name=t.name,this.axis=t.axis,this.id=this.name+"-"+this.axis,this.waypoints=[],this.clearTriggerQueues(),o[this.axis][this.name]=this}var o={vertical:{},horizontal:{}},r=window.Waypoint;i.prototype.add=function(t){this.waypoints.push(t)},i.prototype.clearTriggerQueues=function(){this.triggerQueues={up:[],down:[],left:[],right:[]}},i.prototype.flushTriggers=function(){for(var i in this.triggerQueues){var o=this.triggerQueues[i],r="up"===i||"left"===i;o.sort(r?e:t);for(var n=0,s=o.length;s>n;n+=1){var a=o[n];(a.options.continuous||n===o.length-1)&&a.trigger([i])}}this.clearTriggerQueues()},i.prototype.queueTrigger=function(t,e){this.triggerQueues[e].push(t)},i.prototype.remove=function(t){var e=r.Adapter.inArray(t,this.waypoints);e>-1&&this.waypoints.splice(e,1)},i.prototype.sort=function(){this.waypoints.sort(function(t,e){return t.triggerPoint-e.triggerPoint})},i.prototype.first=function(){return this.waypoints[0]},i.prototype.last=function(){return this.waypoints[this.waypoints.length-1]},i.prototype.next=function(t){this.sort();var e=r.Adapter.inArray(t,this.waypoints),i=e===this.waypoints.length-1;return i?null:this.waypoints[e+1]},i.prototype.previous=function(t){this.sort();var e=r.Adapter.inArray(t,this.waypoints);return e?this.waypoints[e-1]:null},i.findOrCreate=function(t){return o[t.axis][t.name]||new i(t)},r.Group=i}())(function(){"use strict";function t(t){this.$element=e(t)}var e=window.jQuery,i=window.Waypoint;e.each(["height","off","offset","on","outerHeight","outerWidth","scrollLeft","scrollTop","width"],function(e,i){t.prototype[i]=function(){var t=Array.prototype.slice.call(arguments);return this.$element[i].apply(this.$element,t)}}),e.each(["extend","inArray","isEmptyObject"],function(i,o){t[o]=e[o]}),i.adapters.push({name:"jquery",Adapter:t}),i.Adapter=t}()); \ No newline at end of file +!function(){"use strict";function t(o){if(!o)throw new Error("No options passed to Waypoint constructor");if(!o.element)throw new Error("No element option passed to Waypoint constructor");this.key="waypoint-"+e,this.options=t.Adapter.extend({},t.defaults,o),this.element=this.options.element,this.adapter=new t.Adapter(this.element),this.callback=o.handler,this.axis=this.options.horizontal?"horizontal":"vertical",this.enabled=this.options.enabled,this.triggerPoint=null,this.group=t.Group.findOrCreate({name:this.options.group,axis:this.axis}),this.context=t.Context.findOrCreateByElement(this.options.context),t.offsetAliases[this.options.offset]&&(this.options.offset=t.offsetAliases[this.options.offset]),this.context.add(this),this.group.add(this),i[this.key]=this,e+=1}var e=0,i={};t.prototype.queueTrigger=function(t){this.group.queueTrigger(this,t)},t.prototype.trigger=function(t){this.enabled&&(this.callback&&this.callback.apply(this,t),this.options.triggerOnce&&this.destroy())},t.prototype.destroy=function(){this.context.remove(this),this.group.remove(this),delete i[this.key]},t.prototype.disable=function(){return this.enabled=!1,this},t.prototype.enable=function(){return this.context.refresh(),this.enabled=!0,this},t.prototype.previous=function(){return this.group.previous(this)},t.prototype.next=function(){return this.group.next(this)},t.destroyAll=function(){var t=[];for(var e in i)t.push(i[e]);for(var o=0,r=t.length;r>o;o++)t[o].destroy()},t.refreshAll=function(){t.Context.refreshAll()},t.viewportHeight=function(){return window.innerHeight||document.documentElement.clientHeight},t.viewportWidth=function(){return document.documentElement.clientWidth},t.adapters=[],t.defaults={context:window,continuous:!0,enabled:!0,group:"default",horizontal:!1,offset:0,triggerOnce:!1},t.offsetAliases={"bottom-in-view":function(){return this.context.height()-this.adapter.outerHeight()},"right-in-view":function(){return this.context.width()-this.adapter.outerWidth()}},window.Waypoint=t}()(function(){"use strict";function t(t){window.setTimeout(t,1e3/60)}function e(t){this.element=t,this.Adapter=r.Adapter,this.adapter=new this.Adapter(t),this.key="waypoint-context-"+i,this.didScroll=!1,this.didResize=!1,this.oldScroll={x:this.adapter.scrollLeft(),y:this.adapter.scrollTop()},this.waypoints={vertical:{},horizontal:{}},t.waypointContextKey=this.key,o[t.waypointContextKey]=this,i+=1,this.createThrottledScrollHandler(),this.createThrottledResizeHandler()}var i=0,o={},r=window.Waypoint,n=window.requestAnimationFrame||window.mozRequestAnimationFrame||window.webkitRequestAnimationFrame||t;e.prototype.add=function(t){var e=t.options.horizontal?"horizontal":"vertical";this.waypoints[e][t.key]=t,this.refresh()},e.prototype.checkEmpty=function(){var t=this.Adapter.isEmptyObject(this.waypoints.horizontal),e=this.Adapter.isEmptyObject(this.waypoints.vertical);t&&e&&(this.adapter.off(".waypoints"),delete o[this.key])},e.prototype.createThrottledResizeHandler=function(){function t(){e.handleResize(),e.didResize=!1}var e=this;this.adapter.on("resize.waypoints",function(){e.didResize||(e.didResize=!0,n(t))})},e.prototype.createThrottledScrollHandler=function(){function t(){e.handleScroll(),e.didScroll=!1}var e=this;this.adapter.on("scroll.waypoints",function(){(!e.didScroll||r.isTouch)&&(e.didScroll=!0,n(t))})},e.prototype.handleResize=function(){r.Context.refreshAll()},e.prototype.handleScroll=function(){var t={},e={horizontal:{newScroll:this.adapter.scrollLeft(),oldScroll:this.oldScroll.x,forward:"right",backward:"left"},vertical:{newScroll:this.adapter.scrollTop(),oldScroll:this.oldScroll.y,forward:"down",backward:"up"}};for(var i in e){var o=e[i],r=o.newScroll>o.oldScroll,n=r?o.forward:o.backward;for(var s in this.waypoints[i]){var a=this.waypoints[i][s],l=o.oldScroll=a.triggerPoint,p=l&&h,c=!l&&!h;(p||c)&&(a.queueTrigger(n),t[a.group.id]=a.group)}}for(var u in t)t[u].flushTriggers();this.oldScroll={x:e.horizontal.newScroll,y:e.vertical.newScroll}},e.prototype.height=function(){return this.element===this.element.window?r.viewportHeight():this.adapter.height()},e.prototype.remove=function(t){delete this.waypoints[t.axis][t.key],this.checkEmpty()},e.prototype.width=function(){return this.element===this.element.window?r.viewportWidth():this.adapter.width()},e.prototype.destroy=function(){var t=[];for(var e in this.waypoints)for(var i in this.waypoints[e])t.push(this.waypoints[e][i]);for(var o=0,r=t.length;r>o;o++)t[o].destroy()},e.prototype.refresh=function(){var t,e=this.element===this.element.window,i=this.adapter.offset(),o={};this.handleScroll(),t={horizontal:{contextOffset:e?0:i.left,contextScroll:e?0:this.oldScroll.x,contextDimension:this.width(),oldScroll:this.oldScroll.x,forward:"right",backward:"left",offsetProp:"left"},vertical:{contextOffset:e?0:i.top,contextScroll:e?0:this.oldScroll.y,contextDimension:this.height(),oldScroll:this.oldScroll.y,forward:"down",backward:"up",offsetProp:"top"}};for(var r in t){var n=t[r];for(var s in this.waypoints[r]){var a,l,h,p,c,u=this.waypoints[r][s],d=u.options.offset,f=u.triggerPoint,y=0,g=null==f;u.element!==u.element.window&&(y=u.adapter.offset()[n.offsetProp]),"function"==typeof d?d=d.apply(u):"string"==typeof d&&(d=parseFloat(d),u.options.offset.indexOf("%")>-1&&(d=Math.ceil(n.contextDimension*d/100))),a=n.contextScroll-n.contextOffset,u.triggerPoint=y+a-d,l=f=n.oldScroll,p=l&&h,c=!l&&!h,!g&&p?(u.queueTrigger(n.backward),o[u.group.id]=u.group):!g&&c?(u.queueTrigger(n.forward),o[u.group.id]=u.group):g&&n.oldScroll>=u.triggerPoint&&(u.queueTrigger(n.forward),o[u.group.id]=u.group)}}for(var w in o)o[w].flushTriggers();return this},e.findOrCreateByElement=function(t){return e.findByElement(t)||new e(t)},e.findByElement=function(t){return o[t.waypointContextKey]},e.refreshAll=function(){for(var t in o)o[t].refresh()},r.Context=e}())(function(){"use strict";function t(t,e){return t.triggerPoint-e.triggerPoint}function e(t,e){return e.triggerPoint-t.triggerPoint}function i(t){this.name=t.name,this.axis=t.axis,this.id=this.name+"-"+this.axis,this.waypoints=[],this.clearTriggerQueues(),o[this.axis][this.name]=this}var o={vertical:{},horizontal:{}},r=window.Waypoint;i.prototype.add=function(t){this.waypoints.push(t)},i.prototype.clearTriggerQueues=function(){this.triggerQueues={up:[],down:[],left:[],right:[]}},i.prototype.flushTriggers=function(){for(var i in this.triggerQueues){var o=this.triggerQueues[i],r="up"===i||"left"===i;o.sort(r?e:t);for(var n=0,s=o.length;s>n;n+=1){var a=o[n];(a.options.continuous||n===o.length-1)&&a.trigger([i])}}this.clearTriggerQueues()},i.prototype.queueTrigger=function(t,e){this.triggerQueues[e].push(t)},i.prototype.remove=function(t){var e=r.Adapter.inArray(t,this.waypoints);e>-1&&this.waypoints.splice(e,1)},i.prototype.sort=function(){this.waypoints.sort(function(t,e){return t.triggerPoint-e.triggerPoint})},i.prototype.first=function(){return this.waypoints[0]},i.prototype.last=function(){return this.waypoints[this.waypoints.length-1]},i.prototype.next=function(t){this.sort();var e=r.Adapter.inArray(t,this.waypoints),i=e===this.waypoints.length-1;return i?null:this.waypoints[e+1]},i.prototype.previous=function(t){this.sort();var e=r.Adapter.inArray(t,this.waypoints);return e?this.waypoints[e-1]:null},i.findOrCreate=function(t){return o[t.axis][t.name]||new i(t)},r.Group=i}())(function(){"use strict";function t(t){this.$element=e(t)}var e=window.jQuery,i=window.Waypoint;e.each(["height","off","offset","on","outerHeight","outerWidth","scrollLeft","scrollTop","width"],function(e,i){t.prototype[i]=function(){var t=Array.prototype.slice.call(arguments);return this.$element[i].apply(this.$element,t)}}),e.each(["extend","inArray","isEmptyObject"],function(i,o){t[o]=e[o]}),i.adapters.push({name:"jquery",Adapter:t}),i.Adapter=t}()); \ No newline at end of file diff --git a/lib/noframework.waypoints.js b/lib/noframework.waypoints.js index c3104b28..b9f3f6b0 100644 --- a/lib/noframework.waypoints.js +++ b/lib/noframework.waypoints.js @@ -79,6 +79,16 @@ https://github.com/imakewebthings/waypoints/blog/master/licenses.txt return this } + /* Public */ + Waypoint.prototype.previous = function() { + return this.group.previous(this) + } + + /* Public */ + Waypoint.prototype.next = function() { + return this.group.next(this) + } + /* Public */ Waypoint.destroyAll = function() { var allWaypointsArray = [] @@ -100,6 +110,11 @@ https://github.com/imakewebthings/waypoints/blog/master/licenses.txt return window.innerHeight || document.documentElement.clientHeight } + /* Public */ + Waypoint.viewportWidth = function() { + return document.documentElement.clientWidth + } + Waypoint.adapters = [] Waypoint.defaults = { @@ -117,7 +132,7 @@ https://github.com/imakewebthings/waypoints/blog/master/licenses.txt return this.context.height() - this.adapter.outerHeight() }, 'right-in-view': function() { - return this.context.adapter.width() - this.adapter.outerWidth() + return this.context.width() - this.adapter.outerWidth() } } @@ -278,6 +293,14 @@ https://github.com/imakewebthings/waypoints/blog/master/licenses.txt this.checkEmpty() } + /* Private */ + Context.prototype.width = function() { + if (this.element === this.element.window) { + return Waypoint.viewportWidth() + } + return this.adapter.width() + } + /* Public */ Context.prototype.destroy = function() { var allWaypoints = [] @@ -295,7 +318,6 @@ https://github.com/imakewebthings/waypoints/blog/master/licenses.txt Context.prototype.refresh = function() { var isWindow = this.element === this.element.window var contextOffset = this.adapter.offset() - var height = isWindow ? Waypoint.viewportHeight() : this.adapter.height() var triggeredGroups = {} var axes @@ -304,7 +326,7 @@ https://github.com/imakewebthings/waypoints/blog/master/licenses.txt horizontal: { contextOffset: isWindow ? 0 : contextOffset.left, contextScroll: isWindow ? 0 : this.oldScroll.x, - contextDimension: this.adapter.width(), + contextDimension: this.width(), oldScroll: this.oldScroll.x, forward: 'right', backward: 'left', @@ -313,7 +335,7 @@ https://github.com/imakewebthings/waypoints/blog/master/licenses.txt vertical: { contextOffset: isWindow ? 0 : contextOffset.top, contextScroll: isWindow ? 0 : this.oldScroll.y, - contextDimension: height, + contextDimension: this.height(), oldScroll: this.oldScroll.y, forward: 'down', backward: 'up', diff --git a/lib/noframework.waypoints.min.js b/lib/noframework.waypoints.min.js index d613a147..521d5811 100644 --- a/lib/noframework.waypoints.min.js +++ b/lib/noframework.waypoints.min.js @@ -4,4 +4,4 @@ Copyright © 2011-2014 Caleb Troughton Licensed under the MIT license. https://github.com/imakewebthings/waypoints/blog/master/licenses.txt */ -!function(){"use strict";function t(o){if(!o)throw new Error("No options passed to Waypoint constructor");if(!o.element)throw new Error("No element option passed to Waypoint constructor");this.key="waypoint-"+e,this.options=t.Adapter.extend({},t.defaults,o),this.element=this.options.element,this.adapter=new t.Adapter(this.element),this.callback=o.handler,this.axis=this.options.horizontal?"horizontal":"vertical",this.enabled=this.options.enabled,this.triggerPoint=null,this.group=t.Group.findOrCreate({name:this.options.group,axis:this.axis}),this.context=t.Context.findOrCreateByElement(this.options.context),t.offsetAliases[this.options.offset]&&(this.options.offset=t.offsetAliases[this.options.offset]),this.context.add(this),this.group.add(this),i[this.key]=this,e+=1}var e=0,i={};t.prototype.queueTrigger=function(t){this.group.queueTrigger(this,t)},t.prototype.trigger=function(t){this.enabled&&(this.callback&&this.callback.apply(this,t),this.options.triggerOnce&&this.destroy())},t.prototype.destroy=function(){this.context.remove(this),this.group.remove(this),delete i[this.key]},t.prototype.disable=function(){return this.enabled=!1,this},t.prototype.enable=function(){return this.context.refresh(),this.enabled=!0,this},t.destroyAll=function(){var t=[];for(var e in i)t.push(i[e]);for(var o=0,r=t.length;r>o;o++)t[o].destroy()},t.refreshAll=function(){t.Context.refreshAll()},t.viewportHeight=function(){return window.innerHeight||document.documentElement.clientHeight},t.adapters=[],t.defaults={context:window,continuous:!0,enabled:!0,group:"default",horizontal:!1,offset:0,triggerOnce:!1},t.offsetAliases={"bottom-in-view":function(){return this.context.height()-this.adapter.outerHeight()},"right-in-view":function(){return this.context.adapter.width()-this.adapter.outerWidth()}},window.Waypoint=t}()(function(){"use strict";function t(t){window.setTimeout(t,1e3/60)}function e(t){this.element=t,this.Adapter=r.Adapter,this.adapter=new this.Adapter(t),this.key="waypoint-context-"+i,this.didScroll=!1,this.didResize=!1,this.oldScroll={x:this.adapter.scrollLeft(),y:this.adapter.scrollTop()},this.waypoints={vertical:{},horizontal:{}},t.waypointContextKey=this.key,o[t.waypointContextKey]=this,i+=1,this.createThrottledScrollHandler(),this.createThrottledResizeHandler()}var i=0,o={},r=window.Waypoint,n=window.requestAnimationFrame||window.mozRequestAnimationFrame||window.webkitRequestAnimationFrame||t;e.prototype.add=function(t){var e=t.options.horizontal?"horizontal":"vertical";this.waypoints[e][t.key]=t,this.refresh()},e.prototype.checkEmpty=function(){var t=this.Adapter.isEmptyObject(this.waypoints.horizontal),e=this.Adapter.isEmptyObject(this.waypoints.vertical);t&&e&&(this.adapter.off(".waypoints"),delete o[this.key])},e.prototype.createThrottledResizeHandler=function(){function t(){e.handleResize(),e.didResize=!1}var e=this;this.adapter.on("resize.waypoints",function(){e.didResize||(e.didResize=!0,n(t))})},e.prototype.createThrottledScrollHandler=function(){function t(){e.handleScroll(),e.didScroll=!1}var e=this;this.adapter.on("scroll.waypoints",function(){(!e.didScroll||r.isTouch)&&(e.didScroll=!0,n(t))})},e.prototype.handleResize=function(){r.Context.refreshAll()},e.prototype.handleScroll=function(){var t={},e={horizontal:{newScroll:this.adapter.scrollLeft(),oldScroll:this.oldScroll.x,forward:"right",backward:"left"},vertical:{newScroll:this.adapter.scrollTop(),oldScroll:this.oldScroll.y,forward:"down",backward:"up"}};for(var i in e){var o=e[i],r=o.newScroll>o.oldScroll,n=r?o.forward:o.backward;for(var s in this.waypoints[i]){var a=this.waypoints[i][s],l=o.oldScroll=a.triggerPoint,p=l&&h,f=!l&&!h;(p||f)&&(a.queueTrigger(n),t[a.group.id]=a.group)}}for(var u in t)t[u].flushTriggers();this.oldScroll={x:e.horizontal.newScroll,y:e.vertical.newScroll}},e.prototype.height=function(){return this.element===this.element.window?r.viewportHeight():this.adapter.height()},e.prototype.remove=function(t){delete this.waypoints[t.axis][t.key],this.checkEmpty()},e.prototype.destroy=function(){var t=[];for(var e in this.waypoints)for(var i in this.waypoints[e])t.push(this.waypoints[e][i]);for(var o=0,r=t.length;r>o;o++)t[o].destroy()},e.prototype.refresh=function(){var t,e=this.element===this.element.window,i=this.adapter.offset(),o=e?r.viewportHeight():this.adapter.height(),n={};this.handleScroll(),t={horizontal:{contextOffset:e?0:i.left,contextScroll:e?0:this.oldScroll.x,contextDimension:this.adapter.width(),oldScroll:this.oldScroll.x,forward:"right",backward:"left",offsetProp:"left"},vertical:{contextOffset:e?0:i.top,contextScroll:e?0:this.oldScroll.y,contextDimension:o,oldScroll:this.oldScroll.y,forward:"down",backward:"up",offsetProp:"top"}};for(var s in t){var a=t[s];for(var l in this.waypoints[s]){var h,p,f,u,c,d=this.waypoints[s][l],g=d.options.offset,y=d.triggerPoint,w=0,m=null==y;d.element!==d.element.window&&(w=d.adapter.offset()[a.offsetProp]),"function"==typeof g?g=g.apply(d):"string"==typeof g&&(g=parseFloat(g),d.options.offset.indexOf("%")>-1&&(g=Math.ceil(a.contextDimension*g/100))),h=a.contextScroll-a.contextOffset,d.triggerPoint=w+h-g,p=y=a.oldScroll,u=p&&f,c=!p&&!f,!m&&u?(d.queueTrigger(a.backward),n[d.group.id]=d.group):!m&&c?(d.queueTrigger(a.forward),n[d.group.id]=d.group):m&&a.oldScroll>=d.triggerPoint&&(d.queueTrigger(a.forward),n[d.group.id]=d.group)}}for(var v in n)n[v].flushTriggers();return this},e.findOrCreateByElement=function(t){return e.findByElement(t)||new e(t)},e.findByElement=function(t){return o[t.waypointContextKey]},e.refreshAll=function(){for(var t in o)o[t].refresh()},r.Context=e}())(function(){"use strict";function t(t,e){return t.triggerPoint-e.triggerPoint}function e(t,e){return e.triggerPoint-t.triggerPoint}function i(t){this.name=t.name,this.axis=t.axis,this.id=this.name+"-"+this.axis,this.waypoints=[],this.clearTriggerQueues(),o[this.axis][this.name]=this}var o={vertical:{},horizontal:{}},r=window.Waypoint;i.prototype.add=function(t){this.waypoints.push(t)},i.prototype.clearTriggerQueues=function(){this.triggerQueues={up:[],down:[],left:[],right:[]}},i.prototype.flushTriggers=function(){for(var i in this.triggerQueues){var o=this.triggerQueues[i],r="up"===i||"left"===i;o.sort(r?e:t);for(var n=0,s=o.length;s>n;n+=1){var a=o[n];(a.options.continuous||n===o.length-1)&&a.trigger([i])}}this.clearTriggerQueues()},i.prototype.queueTrigger=function(t,e){this.triggerQueues[e].push(t)},i.prototype.remove=function(t){var e=r.Adapter.inArray(t,this.waypoints);e>-1&&this.waypoints.splice(e,1)},i.prototype.sort=function(){this.waypoints.sort(function(t,e){return t.triggerPoint-e.triggerPoint})},i.prototype.first=function(){return this.waypoints[0]},i.prototype.last=function(){return this.waypoints[this.waypoints.length-1]},i.prototype.next=function(t){this.sort();var e=r.Adapter.inArray(t,this.waypoints),i=e===this.waypoints.length-1;return i?null:this.waypoints[e+1]},i.prototype.previous=function(t){this.sort();var e=r.Adapter.inArray(t,this.waypoints);return e?this.waypoints[e-1]:null},i.findOrCreate=function(t){return o[t.axis][t.name]||new i(t)},r.Group=i}())(function(){"use strict";function t(t){return t===t.window}function e(e){return t(e)?e:e.defaultView}function i(t){this.element=t,this.handlers={}}var o=window.Waypoint;i.prototype.height=function(){var e=t(this.element);return e?this.element.innerHeight:this.element.offsetHeight},i.prototype.off=function(t,e){function i(t,e,i){for(var o=0,r=e.length-1;r>o;o++){var n=e[o];i&&i!==n||t.removeEventListener(n)}}var o=t.split("."),r=o[0],n=o[1],s=this.element;if(n&&this.handlers[n]&&r)i(s,this.handlers[n][r],e),this.handlers[n][r]=[];else if(r)for(var a in this.handlers)i(s,this.handlers[a][r]||[],e),this.handlers[a][r]=[];else if(n&&this.handlers[n]){for(var l in this.handlers[n])i(s,this.handlers[n][l],e);this.handlers[n]={}}},i.prototype.offset=function(){if(!this.element.ownerDocument)return null;var t=this.element.ownerDocument.documentElement,i=e(this.element.ownerDocument),o={top:0,left:0};return this.element.getBoundingClientRect&&(o=this.element.getBoundingClientRect()),{top:o.top+i.pageYOffset-t.clientTop,left:o.left+i.pageXOffset-t.clientLeft}},i.prototype.on=function(t,e){var i=t.split("."),o=i[0],r=i[1]||"__default",n=this.handlers[r]=this.handlers[r]||{},s=n[o]=n[o]||[];s.push(e),this.element.addEventListener(o,e)},i.prototype.outerHeight=function(e){var i,o=this.height();return e&&!t(this.element)&&(i=window.getComputedStyle(this.element),o+=parseInt(i.marginTop,10),o+=parseInt(i.marginBottom,10)),o},i.prototype.outerWidth=function(e){var i,o=this.width();return e&&!t(this.element)&&(i=window.getComputedStyle(this.element),o+=parseInt(i.marginLeft,10),o+=parseInt(i.marginRight,10)),o},i.prototype.scrollLeft=function(){var t=e(this.element);return t?t.pageXOffset:this.element.scrollLeft},i.prototype.scrollTop=function(){var t=e(this.element);return t?t.pageYOffset:this.element.scrollTop},i.prototype.width=function(){var e=t(this.element);return e?this.element.innerWidth:this.element.offsetWidth},i.extend=function(){function t(t,e){if("object"==typeof t&&"object"==typeof e)for(var i in e)e.hasOwnProperty(i)&&(t[i]=e[i]);return t}for(var e=Array.prototype.slice.call(arguments),i=1,o=e.length;o>i;i++)t(e[0],e[i]);return e[0]},i.inArray=function(t,e,i){return null==e?-1:e.indexOf(t,i)},i.isEmptyObject=function(t){for(var e in t)return!1;return!0},o.adapters.push({name:"noframework",Adapter:i}),o.Adapter=i}()); \ No newline at end of file +!function(){"use strict";function t(o){if(!o)throw new Error("No options passed to Waypoint constructor");if(!o.element)throw new Error("No element option passed to Waypoint constructor");this.key="waypoint-"+e,this.options=t.Adapter.extend({},t.defaults,o),this.element=this.options.element,this.adapter=new t.Adapter(this.element),this.callback=o.handler,this.axis=this.options.horizontal?"horizontal":"vertical",this.enabled=this.options.enabled,this.triggerPoint=null,this.group=t.Group.findOrCreate({name:this.options.group,axis:this.axis}),this.context=t.Context.findOrCreateByElement(this.options.context),t.offsetAliases[this.options.offset]&&(this.options.offset=t.offsetAliases[this.options.offset]),this.context.add(this),this.group.add(this),i[this.key]=this,e+=1}var e=0,i={};t.prototype.queueTrigger=function(t){this.group.queueTrigger(this,t)},t.prototype.trigger=function(t){this.enabled&&(this.callback&&this.callback.apply(this,t),this.options.triggerOnce&&this.destroy())},t.prototype.destroy=function(){this.context.remove(this),this.group.remove(this),delete i[this.key]},t.prototype.disable=function(){return this.enabled=!1,this},t.prototype.enable=function(){return this.context.refresh(),this.enabled=!0,this},t.prototype.previous=function(){return this.group.previous(this)},t.prototype.next=function(){return this.group.next(this)},t.destroyAll=function(){var t=[];for(var e in i)t.push(i[e]);for(var o=0,r=t.length;r>o;o++)t[o].destroy()},t.refreshAll=function(){t.Context.refreshAll()},t.viewportHeight=function(){return window.innerHeight||document.documentElement.clientHeight},t.viewportWidth=function(){return document.documentElement.clientWidth},t.adapters=[],t.defaults={context:window,continuous:!0,enabled:!0,group:"default",horizontal:!1,offset:0,triggerOnce:!1},t.offsetAliases={"bottom-in-view":function(){return this.context.height()-this.adapter.outerHeight()},"right-in-view":function(){return this.context.width()-this.adapter.outerWidth()}},window.Waypoint=t}()(function(){"use strict";function t(t){window.setTimeout(t,1e3/60)}function e(t){this.element=t,this.Adapter=r.Adapter,this.adapter=new this.Adapter(t),this.key="waypoint-context-"+i,this.didScroll=!1,this.didResize=!1,this.oldScroll={x:this.adapter.scrollLeft(),y:this.adapter.scrollTop()},this.waypoints={vertical:{},horizontal:{}},t.waypointContextKey=this.key,o[t.waypointContextKey]=this,i+=1,this.createThrottledScrollHandler(),this.createThrottledResizeHandler()}var i=0,o={},r=window.Waypoint,n=window.requestAnimationFrame||window.mozRequestAnimationFrame||window.webkitRequestAnimationFrame||t;e.prototype.add=function(t){var e=t.options.horizontal?"horizontal":"vertical";this.waypoints[e][t.key]=t,this.refresh()},e.prototype.checkEmpty=function(){var t=this.Adapter.isEmptyObject(this.waypoints.horizontal),e=this.Adapter.isEmptyObject(this.waypoints.vertical);t&&e&&(this.adapter.off(".waypoints"),delete o[this.key])},e.prototype.createThrottledResizeHandler=function(){function t(){e.handleResize(),e.didResize=!1}var e=this;this.adapter.on("resize.waypoints",function(){e.didResize||(e.didResize=!0,n(t))})},e.prototype.createThrottledScrollHandler=function(){function t(){e.handleScroll(),e.didScroll=!1}var e=this;this.adapter.on("scroll.waypoints",function(){(!e.didScroll||r.isTouch)&&(e.didScroll=!0,n(t))})},e.prototype.handleResize=function(){r.Context.refreshAll()},e.prototype.handleScroll=function(){var t={},e={horizontal:{newScroll:this.adapter.scrollLeft(),oldScroll:this.oldScroll.x,forward:"right",backward:"left"},vertical:{newScroll:this.adapter.scrollTop(),oldScroll:this.oldScroll.y,forward:"down",backward:"up"}};for(var i in e){var o=e[i],r=o.newScroll>o.oldScroll,n=r?o.forward:o.backward;for(var s in this.waypoints[i]){var a=this.waypoints[i][s],l=o.oldScroll=a.triggerPoint,p=l&&h,u=!l&&!h;(p||u)&&(a.queueTrigger(n),t[a.group.id]=a.group)}}for(var f in t)t[f].flushTriggers();this.oldScroll={x:e.horizontal.newScroll,y:e.vertical.newScroll}},e.prototype.height=function(){return this.element===this.element.window?r.viewportHeight():this.adapter.height()},e.prototype.remove=function(t){delete this.waypoints[t.axis][t.key],this.checkEmpty()},e.prototype.width=function(){return this.element===this.element.window?r.viewportWidth():this.adapter.width()},e.prototype.destroy=function(){var t=[];for(var e in this.waypoints)for(var i in this.waypoints[e])t.push(this.waypoints[e][i]);for(var o=0,r=t.length;r>o;o++)t[o].destroy()},e.prototype.refresh=function(){var t,e=this.element===this.element.window,i=this.adapter.offset(),o={};this.handleScroll(),t={horizontal:{contextOffset:e?0:i.left,contextScroll:e?0:this.oldScroll.x,contextDimension:this.width(),oldScroll:this.oldScroll.x,forward:"right",backward:"left",offsetProp:"left"},vertical:{contextOffset:e?0:i.top,contextScroll:e?0:this.oldScroll.y,contextDimension:this.height(),oldScroll:this.oldScroll.y,forward:"down",backward:"up",offsetProp:"top"}};for(var r in t){var n=t[r];for(var s in this.waypoints[r]){var a,l,h,p,u,f=this.waypoints[r][s],c=f.options.offset,d=f.triggerPoint,g=0,y=null==d;f.element!==f.element.window&&(g=f.adapter.offset()[n.offsetProp]),"function"==typeof c?c=c.apply(f):"string"==typeof c&&(c=parseFloat(c),f.options.offset.indexOf("%")>-1&&(c=Math.ceil(n.contextDimension*c/100))),a=n.contextScroll-n.contextOffset,f.triggerPoint=g+a-c,l=d=n.oldScroll,p=l&&h,u=!l&&!h,!y&&p?(f.queueTrigger(n.backward),o[f.group.id]=f.group):!y&&u?(f.queueTrigger(n.forward),o[f.group.id]=f.group):y&&n.oldScroll>=f.triggerPoint&&(f.queueTrigger(n.forward),o[f.group.id]=f.group)}}for(var w in o)o[w].flushTriggers();return this},e.findOrCreateByElement=function(t){return e.findByElement(t)||new e(t)},e.findByElement=function(t){return o[t.waypointContextKey]},e.refreshAll=function(){for(var t in o)o[t].refresh()},r.Context=e}())(function(){"use strict";function t(t,e){return t.triggerPoint-e.triggerPoint}function e(t,e){return e.triggerPoint-t.triggerPoint}function i(t){this.name=t.name,this.axis=t.axis,this.id=this.name+"-"+this.axis,this.waypoints=[],this.clearTriggerQueues(),o[this.axis][this.name]=this}var o={vertical:{},horizontal:{}},r=window.Waypoint;i.prototype.add=function(t){this.waypoints.push(t)},i.prototype.clearTriggerQueues=function(){this.triggerQueues={up:[],down:[],left:[],right:[]}},i.prototype.flushTriggers=function(){for(var i in this.triggerQueues){var o=this.triggerQueues[i],r="up"===i||"left"===i;o.sort(r?e:t);for(var n=0,s=o.length;s>n;n+=1){var a=o[n];(a.options.continuous||n===o.length-1)&&a.trigger([i])}}this.clearTriggerQueues()},i.prototype.queueTrigger=function(t,e){this.triggerQueues[e].push(t)},i.prototype.remove=function(t){var e=r.Adapter.inArray(t,this.waypoints);e>-1&&this.waypoints.splice(e,1)},i.prototype.sort=function(){this.waypoints.sort(function(t,e){return t.triggerPoint-e.triggerPoint})},i.prototype.first=function(){return this.waypoints[0]},i.prototype.last=function(){return this.waypoints[this.waypoints.length-1]},i.prototype.next=function(t){this.sort();var e=r.Adapter.inArray(t,this.waypoints),i=e===this.waypoints.length-1;return i?null:this.waypoints[e+1]},i.prototype.previous=function(t){this.sort();var e=r.Adapter.inArray(t,this.waypoints);return e?this.waypoints[e-1]:null},i.findOrCreate=function(t){return o[t.axis][t.name]||new i(t)},r.Group=i}())(function(){"use strict";function t(t){return t===t.window}function e(e){return t(e)?e:e.defaultView}function i(t){this.element=t,this.handlers={}}var o=window.Waypoint;i.prototype.height=function(){var e=t(this.element);return e?this.element.innerHeight:this.element.offsetHeight},i.prototype.off=function(t,e){function i(t,e,i){for(var o=0,r=e.length-1;r>o;o++){var n=e[o];i&&i!==n||t.removeEventListener(n)}}var o=t.split("."),r=o[0],n=o[1],s=this.element;if(n&&this.handlers[n]&&r)i(s,this.handlers[n][r],e),this.handlers[n][r]=[];else if(r)for(var a in this.handlers)i(s,this.handlers[a][r]||[],e),this.handlers[a][r]=[];else if(n&&this.handlers[n]){for(var l in this.handlers[n])i(s,this.handlers[n][l],e);this.handlers[n]={}}},i.prototype.offset=function(){if(!this.element.ownerDocument)return null;var t=this.element.ownerDocument.documentElement,i=e(this.element.ownerDocument),o={top:0,left:0};return this.element.getBoundingClientRect&&(o=this.element.getBoundingClientRect()),{top:o.top+i.pageYOffset-t.clientTop,left:o.left+i.pageXOffset-t.clientLeft}},i.prototype.on=function(t,e){var i=t.split("."),o=i[0],r=i[1]||"__default",n=this.handlers[r]=this.handlers[r]||{},s=n[o]=n[o]||[];s.push(e),this.element.addEventListener(o,e)},i.prototype.outerHeight=function(e){var i,o=this.height();return e&&!t(this.element)&&(i=window.getComputedStyle(this.element),o+=parseInt(i.marginTop,10),o+=parseInt(i.marginBottom,10)),o},i.prototype.outerWidth=function(e){var i,o=this.width();return e&&!t(this.element)&&(i=window.getComputedStyle(this.element),o+=parseInt(i.marginLeft,10),o+=parseInt(i.marginRight,10)),o},i.prototype.scrollLeft=function(){var t=e(this.element);return t?t.pageXOffset:this.element.scrollLeft},i.prototype.scrollTop=function(){var t=e(this.element);return t?t.pageYOffset:this.element.scrollTop},i.prototype.width=function(){var e=t(this.element);return e?this.element.innerWidth:this.element.offsetWidth},i.extend=function(){function t(t,e){if("object"==typeof t&&"object"==typeof e)for(var i in e)e.hasOwnProperty(i)&&(t[i]=e[i]);return t}for(var e=Array.prototype.slice.call(arguments),i=1,o=e.length;o>i;i++)t(e[0],e[i]);return e[0]},i.inArray=function(t,e,i){return null==e?-1:e.indexOf(t,i)},i.isEmptyObject=function(t){for(var e in t)return!1;return!0},o.adapters.push({name:"noframework",Adapter:i}),o.Adapter=i}()); \ No newline at end of file diff --git a/lib/zepto.waypoints.js b/lib/zepto.waypoints.js index fb435003..0e2f6f94 100644 --- a/lib/zepto.waypoints.js +++ b/lib/zepto.waypoints.js @@ -79,6 +79,16 @@ https://github.com/imakewebthings/waypoints/blog/master/licenses.txt return this } + /* Public */ + Waypoint.prototype.previous = function() { + return this.group.previous(this) + } + + /* Public */ + Waypoint.prototype.next = function() { + return this.group.next(this) + } + /* Public */ Waypoint.destroyAll = function() { var allWaypointsArray = [] @@ -100,6 +110,11 @@ https://github.com/imakewebthings/waypoints/blog/master/licenses.txt return window.innerHeight || document.documentElement.clientHeight } + /* Public */ + Waypoint.viewportWidth = function() { + return document.documentElement.clientWidth + } + Waypoint.adapters = [] Waypoint.defaults = { @@ -117,7 +132,7 @@ https://github.com/imakewebthings/waypoints/blog/master/licenses.txt return this.context.height() - this.adapter.outerHeight() }, 'right-in-view': function() { - return this.context.adapter.width() - this.adapter.outerWidth() + return this.context.width() - this.adapter.outerWidth() } } @@ -278,6 +293,14 @@ https://github.com/imakewebthings/waypoints/blog/master/licenses.txt this.checkEmpty() } + /* Private */ + Context.prototype.width = function() { + if (this.element === this.element.window) { + return Waypoint.viewportWidth() + } + return this.adapter.width() + } + /* Public */ Context.prototype.destroy = function() { var allWaypoints = [] @@ -295,7 +318,6 @@ https://github.com/imakewebthings/waypoints/blog/master/licenses.txt Context.prototype.refresh = function() { var isWindow = this.element === this.element.window var contextOffset = this.adapter.offset() - var height = isWindow ? Waypoint.viewportHeight() : this.adapter.height() var triggeredGroups = {} var axes @@ -304,7 +326,7 @@ https://github.com/imakewebthings/waypoints/blog/master/licenses.txt horizontal: { contextOffset: isWindow ? 0 : contextOffset.left, contextScroll: isWindow ? 0 : this.oldScroll.x, - contextDimension: this.adapter.width(), + contextDimension: this.width(), oldScroll: this.oldScroll.x, forward: 'right', backward: 'left', @@ -313,7 +335,7 @@ https://github.com/imakewebthings/waypoints/blog/master/licenses.txt vertical: { contextOffset: isWindow ? 0 : contextOffset.top, contextScroll: isWindow ? 0 : this.oldScroll.y, - contextDimension: height, + contextDimension: this.height(), oldScroll: this.oldScroll.y, forward: 'down', backward: 'up', diff --git a/lib/zepto.waypoints.min.js b/lib/zepto.waypoints.min.js index dd1a9e9c..47b1395e 100644 --- a/lib/zepto.waypoints.min.js +++ b/lib/zepto.waypoints.min.js @@ -4,4 +4,4 @@ Copyright © 2011-2014 Caleb Troughton Licensed under the MIT license. https://github.com/imakewebthings/waypoints/blog/master/licenses.txt */ -!function(){"use strict";function t(o){if(!o)throw new Error("No options passed to Waypoint constructor");if(!o.element)throw new Error("No element option passed to Waypoint constructor");this.key="waypoint-"+e,this.options=t.Adapter.extend({},t.defaults,o),this.element=this.options.element,this.adapter=new t.Adapter(this.element),this.callback=o.handler,this.axis=this.options.horizontal?"horizontal":"vertical",this.enabled=this.options.enabled,this.triggerPoint=null,this.group=t.Group.findOrCreate({name:this.options.group,axis:this.axis}),this.context=t.Context.findOrCreateByElement(this.options.context),t.offsetAliases[this.options.offset]&&(this.options.offset=t.offsetAliases[this.options.offset]),this.context.add(this),this.group.add(this),i[this.key]=this,e+=1}var e=0,i={};t.prototype.queueTrigger=function(t){this.group.queueTrigger(this,t)},t.prototype.trigger=function(t){this.enabled&&(this.callback&&this.callback.apply(this,t),this.options.triggerOnce&&this.destroy())},t.prototype.destroy=function(){this.context.remove(this),this.group.remove(this),delete i[this.key]},t.prototype.disable=function(){return this.enabled=!1,this},t.prototype.enable=function(){return this.context.refresh(),this.enabled=!0,this},t.destroyAll=function(){var t=[];for(var e in i)t.push(i[e]);for(var o=0,r=t.length;r>o;o++)t[o].destroy()},t.refreshAll=function(){t.Context.refreshAll()},t.viewportHeight=function(){return window.innerHeight||document.documentElement.clientHeight},t.adapters=[],t.defaults={context:window,continuous:!0,enabled:!0,group:"default",horizontal:!1,offset:0,triggerOnce:!1},t.offsetAliases={"bottom-in-view":function(){return this.context.height()-this.adapter.outerHeight()},"right-in-view":function(){return this.context.adapter.width()-this.adapter.outerWidth()}},window.Waypoint=t}()(function(){"use strict";function t(t){window.setTimeout(t,1e3/60)}function e(t){this.element=t,this.Adapter=r.Adapter,this.adapter=new this.Adapter(t),this.key="waypoint-context-"+i,this.didScroll=!1,this.didResize=!1,this.oldScroll={x:this.adapter.scrollLeft(),y:this.adapter.scrollTop()},this.waypoints={vertical:{},horizontal:{}},t.waypointContextKey=this.key,o[t.waypointContextKey]=this,i+=1,this.createThrottledScrollHandler(),this.createThrottledResizeHandler()}var i=0,o={},r=window.Waypoint,n=window.requestAnimationFrame||window.mozRequestAnimationFrame||window.webkitRequestAnimationFrame||t;e.prototype.add=function(t){var e=t.options.horizontal?"horizontal":"vertical";this.waypoints[e][t.key]=t,this.refresh()},e.prototype.checkEmpty=function(){var t=this.Adapter.isEmptyObject(this.waypoints.horizontal),e=this.Adapter.isEmptyObject(this.waypoints.vertical);t&&e&&(this.adapter.off(".waypoints"),delete o[this.key])},e.prototype.createThrottledResizeHandler=function(){function t(){e.handleResize(),e.didResize=!1}var e=this;this.adapter.on("resize.waypoints",function(){e.didResize||(e.didResize=!0,n(t))})},e.prototype.createThrottledScrollHandler=function(){function t(){e.handleScroll(),e.didScroll=!1}var e=this;this.adapter.on("scroll.waypoints",function(){(!e.didScroll||r.isTouch)&&(e.didScroll=!0,n(t))})},e.prototype.handleResize=function(){r.Context.refreshAll()},e.prototype.handleScroll=function(){var t={},e={horizontal:{newScroll:this.adapter.scrollLeft(),oldScroll:this.oldScroll.x,forward:"right",backward:"left"},vertical:{newScroll:this.adapter.scrollTop(),oldScroll:this.oldScroll.y,forward:"down",backward:"up"}};for(var i in e){var o=e[i],r=o.newScroll>o.oldScroll,n=r?o.forward:o.backward;for(var s in this.waypoints[i]){var a=this.waypoints[i][s],l=o.oldScroll=a.triggerPoint,p=l&&h,c=!l&&!h;(p||c)&&(a.queueTrigger(n),t[a.group.id]=a.group)}}for(var u in t)t[u].flushTriggers();this.oldScroll={x:e.horizontal.newScroll,y:e.vertical.newScroll}},e.prototype.height=function(){return this.element===this.element.window?r.viewportHeight():this.adapter.height()},e.prototype.remove=function(t){delete this.waypoints[t.axis][t.key],this.checkEmpty()},e.prototype.destroy=function(){var t=[];for(var e in this.waypoints)for(var i in this.waypoints[e])t.push(this.waypoints[e][i]);for(var o=0,r=t.length;r>o;o++)t[o].destroy()},e.prototype.refresh=function(){var t,e=this.element===this.element.window,i=this.adapter.offset(),o=e?r.viewportHeight():this.adapter.height(),n={};this.handleScroll(),t={horizontal:{contextOffset:e?0:i.left,contextScroll:e?0:this.oldScroll.x,contextDimension:this.adapter.width(),oldScroll:this.oldScroll.x,forward:"right",backward:"left",offsetProp:"left"},vertical:{contextOffset:e?0:i.top,contextScroll:e?0:this.oldScroll.y,contextDimension:o,oldScroll:this.oldScroll.y,forward:"down",backward:"up",offsetProp:"top"}};for(var s in t){var a=t[s];for(var l in this.waypoints[s]){var h,p,c,u,d,f=this.waypoints[s][l],y=f.options.offset,g=f.triggerPoint,w=0,m=null==g;f.element!==f.element.window&&(w=f.adapter.offset()[a.offsetProp]),"function"==typeof y?y=y.apply(f):"string"==typeof y&&(y=parseFloat(y),f.options.offset.indexOf("%")>-1&&(y=Math.ceil(a.contextDimension*y/100))),h=a.contextScroll-a.contextOffset,f.triggerPoint=w+h-y,p=g=a.oldScroll,u=p&&c,d=!p&&!c,!m&&u?(f.queueTrigger(a.backward),n[f.group.id]=f.group):!m&&d?(f.queueTrigger(a.forward),n[f.group.id]=f.group):m&&a.oldScroll>=f.triggerPoint&&(f.queueTrigger(a.forward),n[f.group.id]=f.group)}}for(var v in n)n[v].flushTriggers();return this},e.findOrCreateByElement=function(t){return e.findByElement(t)||new e(t)},e.findByElement=function(t){return o[t.waypointContextKey]},e.refreshAll=function(){for(var t in o)o[t].refresh()},r.Context=e}())(function(){"use strict";function t(t,e){return t.triggerPoint-e.triggerPoint}function e(t,e){return e.triggerPoint-t.triggerPoint}function i(t){this.name=t.name,this.axis=t.axis,this.id=this.name+"-"+this.axis,this.waypoints=[],this.clearTriggerQueues(),o[this.axis][this.name]=this}var o={vertical:{},horizontal:{}},r=window.Waypoint;i.prototype.add=function(t){this.waypoints.push(t)},i.prototype.clearTriggerQueues=function(){this.triggerQueues={up:[],down:[],left:[],right:[]}},i.prototype.flushTriggers=function(){for(var i in this.triggerQueues){var o=this.triggerQueues[i],r="up"===i||"left"===i;o.sort(r?e:t);for(var n=0,s=o.length;s>n;n+=1){var a=o[n];(a.options.continuous||n===o.length-1)&&a.trigger([i])}}this.clearTriggerQueues()},i.prototype.queueTrigger=function(t,e){this.triggerQueues[e].push(t)},i.prototype.remove=function(t){var e=r.Adapter.inArray(t,this.waypoints);e>-1&&this.waypoints.splice(e,1)},i.prototype.sort=function(){this.waypoints.sort(function(t,e){return t.triggerPoint-e.triggerPoint})},i.prototype.first=function(){return this.waypoints[0]},i.prototype.last=function(){return this.waypoints[this.waypoints.length-1]},i.prototype.next=function(t){this.sort();var e=r.Adapter.inArray(t,this.waypoints),i=e===this.waypoints.length-1;return i?null:this.waypoints[e+1]},i.prototype.previous=function(t){this.sort();var e=r.Adapter.inArray(t,this.waypoints);return e?this.waypoints[e-1]:null},i.findOrCreate=function(t){return o[t.axis][t.name]||new i(t)},r.Group=i}())(function(){"use strict";function t(t){this.element=t,this.$element=e(t)}var e=window.Zepto,i=window.Waypoint;e.each(["height","off","on","scrollLeft","scrollTop","width"],function(e,i){t.prototype[i]=function(){var t=Array.prototype.slice.call(arguments);return this.$element[i].apply(this.$element,t)}}),t.prototype.offset=function(){return this.element!==this.element.window?this.$element.offset():void 0},e.each(["width","height"],function(i,o){var r=e.camelCase("outer-"+o);t.prototype[r]=function(t){var i=this.$element[o](),r={width:["left","right"],height:["top","bottom"]};return t&&e.each(r[o],e.proxy(function(t,e){i+=parseInt(this.$element.css("margin-"+e),10)},this)),i}}),e.each(["extend","inArray"],function(i,o){t[o]=e[o]}),t.isEmptyObject=function(t){for(var e in t)return!1;return!0},i.adapters.push({name:"zepto",Adapter:t}),i.Adapter=t}()); \ No newline at end of file +!function(){"use strict";function t(o){if(!o)throw new Error("No options passed to Waypoint constructor");if(!o.element)throw new Error("No element option passed to Waypoint constructor");this.key="waypoint-"+e,this.options=t.Adapter.extend({},t.defaults,o),this.element=this.options.element,this.adapter=new t.Adapter(this.element),this.callback=o.handler,this.axis=this.options.horizontal?"horizontal":"vertical",this.enabled=this.options.enabled,this.triggerPoint=null,this.group=t.Group.findOrCreate({name:this.options.group,axis:this.axis}),this.context=t.Context.findOrCreateByElement(this.options.context),t.offsetAliases[this.options.offset]&&(this.options.offset=t.offsetAliases[this.options.offset]),this.context.add(this),this.group.add(this),i[this.key]=this,e+=1}var e=0,i={};t.prototype.queueTrigger=function(t){this.group.queueTrigger(this,t)},t.prototype.trigger=function(t){this.enabled&&(this.callback&&this.callback.apply(this,t),this.options.triggerOnce&&this.destroy())},t.prototype.destroy=function(){this.context.remove(this),this.group.remove(this),delete i[this.key]},t.prototype.disable=function(){return this.enabled=!1,this},t.prototype.enable=function(){return this.context.refresh(),this.enabled=!0,this},t.prototype.previous=function(){return this.group.previous(this)},t.prototype.next=function(){return this.group.next(this)},t.destroyAll=function(){var t=[];for(var e in i)t.push(i[e]);for(var o=0,r=t.length;r>o;o++)t[o].destroy()},t.refreshAll=function(){t.Context.refreshAll()},t.viewportHeight=function(){return window.innerHeight||document.documentElement.clientHeight},t.viewportWidth=function(){return document.documentElement.clientWidth},t.adapters=[],t.defaults={context:window,continuous:!0,enabled:!0,group:"default",horizontal:!1,offset:0,triggerOnce:!1},t.offsetAliases={"bottom-in-view":function(){return this.context.height()-this.adapter.outerHeight()},"right-in-view":function(){return this.context.width()-this.adapter.outerWidth()}},window.Waypoint=t}()(function(){"use strict";function t(t){window.setTimeout(t,1e3/60)}function e(t){this.element=t,this.Adapter=r.Adapter,this.adapter=new this.Adapter(t),this.key="waypoint-context-"+i,this.didScroll=!1,this.didResize=!1,this.oldScroll={x:this.adapter.scrollLeft(),y:this.adapter.scrollTop()},this.waypoints={vertical:{},horizontal:{}},t.waypointContextKey=this.key,o[t.waypointContextKey]=this,i+=1,this.createThrottledScrollHandler(),this.createThrottledResizeHandler()}var i=0,o={},r=window.Waypoint,n=window.requestAnimationFrame||window.mozRequestAnimationFrame||window.webkitRequestAnimationFrame||t;e.prototype.add=function(t){var e=t.options.horizontal?"horizontal":"vertical";this.waypoints[e][t.key]=t,this.refresh()},e.prototype.checkEmpty=function(){var t=this.Adapter.isEmptyObject(this.waypoints.horizontal),e=this.Adapter.isEmptyObject(this.waypoints.vertical);t&&e&&(this.adapter.off(".waypoints"),delete o[this.key])},e.prototype.createThrottledResizeHandler=function(){function t(){e.handleResize(),e.didResize=!1}var e=this;this.adapter.on("resize.waypoints",function(){e.didResize||(e.didResize=!0,n(t))})},e.prototype.createThrottledScrollHandler=function(){function t(){e.handleScroll(),e.didScroll=!1}var e=this;this.adapter.on("scroll.waypoints",function(){(!e.didScroll||r.isTouch)&&(e.didScroll=!0,n(t))})},e.prototype.handleResize=function(){r.Context.refreshAll()},e.prototype.handleScroll=function(){var t={},e={horizontal:{newScroll:this.adapter.scrollLeft(),oldScroll:this.oldScroll.x,forward:"right",backward:"left"},vertical:{newScroll:this.adapter.scrollTop(),oldScroll:this.oldScroll.y,forward:"down",backward:"up"}};for(var i in e){var o=e[i],r=o.newScroll>o.oldScroll,n=r?o.forward:o.backward;for(var s in this.waypoints[i]){var a=this.waypoints[i][s],h=o.oldScroll=a.triggerPoint,p=h&&l,c=!h&&!l;(p||c)&&(a.queueTrigger(n),t[a.group.id]=a.group)}}for(var u in t)t[u].flushTriggers();this.oldScroll={x:e.horizontal.newScroll,y:e.vertical.newScroll}},e.prototype.height=function(){return this.element===this.element.window?r.viewportHeight():this.adapter.height()},e.prototype.remove=function(t){delete this.waypoints[t.axis][t.key],this.checkEmpty()},e.prototype.width=function(){return this.element===this.element.window?r.viewportWidth():this.adapter.width()},e.prototype.destroy=function(){var t=[];for(var e in this.waypoints)for(var i in this.waypoints[e])t.push(this.waypoints[e][i]);for(var o=0,r=t.length;r>o;o++)t[o].destroy()},e.prototype.refresh=function(){var t,e=this.element===this.element.window,i=this.adapter.offset(),o={};this.handleScroll(),t={horizontal:{contextOffset:e?0:i.left,contextScroll:e?0:this.oldScroll.x,contextDimension:this.width(),oldScroll:this.oldScroll.x,forward:"right",backward:"left",offsetProp:"left"},vertical:{contextOffset:e?0:i.top,contextScroll:e?0:this.oldScroll.y,contextDimension:this.height(),oldScroll:this.oldScroll.y,forward:"down",backward:"up",offsetProp:"top"}};for(var r in t){var n=t[r];for(var s in this.waypoints[r]){var a,h,l,p,c,u=this.waypoints[r][s],d=u.options.offset,f=u.triggerPoint,y=0,g=null==f;u.element!==u.element.window&&(y=u.adapter.offset()[n.offsetProp]),"function"==typeof d?d=d.apply(u):"string"==typeof d&&(d=parseFloat(d),u.options.offset.indexOf("%")>-1&&(d=Math.ceil(n.contextDimension*d/100))),a=n.contextScroll-n.contextOffset,u.triggerPoint=y+a-d,h=f=n.oldScroll,p=h&&l,c=!h&&!l,!g&&p?(u.queueTrigger(n.backward),o[u.group.id]=u.group):!g&&c?(u.queueTrigger(n.forward),o[u.group.id]=u.group):g&&n.oldScroll>=u.triggerPoint&&(u.queueTrigger(n.forward),o[u.group.id]=u.group)}}for(var w in o)o[w].flushTriggers();return this},e.findOrCreateByElement=function(t){return e.findByElement(t)||new e(t)},e.findByElement=function(t){return o[t.waypointContextKey]},e.refreshAll=function(){for(var t in o)o[t].refresh()},r.Context=e}())(function(){"use strict";function t(t,e){return t.triggerPoint-e.triggerPoint}function e(t,e){return e.triggerPoint-t.triggerPoint}function i(t){this.name=t.name,this.axis=t.axis,this.id=this.name+"-"+this.axis,this.waypoints=[],this.clearTriggerQueues(),o[this.axis][this.name]=this}var o={vertical:{},horizontal:{}},r=window.Waypoint;i.prototype.add=function(t){this.waypoints.push(t)},i.prototype.clearTriggerQueues=function(){this.triggerQueues={up:[],down:[],left:[],right:[]}},i.prototype.flushTriggers=function(){for(var i in this.triggerQueues){var o=this.triggerQueues[i],r="up"===i||"left"===i;o.sort(r?e:t);for(var n=0,s=o.length;s>n;n+=1){var a=o[n];(a.options.continuous||n===o.length-1)&&a.trigger([i])}}this.clearTriggerQueues()},i.prototype.queueTrigger=function(t,e){this.triggerQueues[e].push(t)},i.prototype.remove=function(t){var e=r.Adapter.inArray(t,this.waypoints);e>-1&&this.waypoints.splice(e,1)},i.prototype.sort=function(){this.waypoints.sort(function(t,e){return t.triggerPoint-e.triggerPoint})},i.prototype.first=function(){return this.waypoints[0]},i.prototype.last=function(){return this.waypoints[this.waypoints.length-1]},i.prototype.next=function(t){this.sort();var e=r.Adapter.inArray(t,this.waypoints),i=e===this.waypoints.length-1;return i?null:this.waypoints[e+1]},i.prototype.previous=function(t){this.sort();var e=r.Adapter.inArray(t,this.waypoints);return e?this.waypoints[e-1]:null},i.findOrCreate=function(t){return o[t.axis][t.name]||new i(t)},r.Group=i}())(function(){"use strict";function t(t){this.element=t,this.$element=e(t)}var e=window.Zepto,i=window.Waypoint;e.each(["height","off","on","scrollLeft","scrollTop","width"],function(e,i){t.prototype[i]=function(){var t=Array.prototype.slice.call(arguments);return this.$element[i].apply(this.$element,t)}}),t.prototype.offset=function(){return this.element!==this.element.window?this.$element.offset():void 0},e.each(["width","height"],function(i,o){var r=e.camelCase("outer-"+o);t.prototype[r]=function(t){var i=this.$element[o](),r={width:["left","right"],height:["top","bottom"]};return t&&e.each(r[o],e.proxy(function(t,e){i+=parseInt(this.$element.css("margin-"+e),10)},this)),i}}),e.each(["extend","inArray"],function(i,o){t[o]=e[o]}),t.isEmptyObject=function(t){for(var e in t)return!1;return!0},i.adapters.push({name:"zepto",Adapter:t}),i.Adapter=t}()); \ No newline at end of file diff --git a/src/context.js b/src/context.js index a847f3b4..afaef0b7 100644 --- a/src/context.js +++ b/src/context.js @@ -152,6 +152,14 @@ this.checkEmpty() } + /* Private */ + Context.prototype.width = function() { + if (this.element === this.element.window) { + return Waypoint.viewportWidth() + } + return this.adapter.width() + } + /* Public */ Context.prototype.destroy = function() { var allWaypoints = [] @@ -169,7 +177,6 @@ Context.prototype.refresh = function() { var isWindow = this.element === this.element.window var contextOffset = this.adapter.offset() - var height = isWindow ? Waypoint.viewportHeight() : this.adapter.height() var triggeredGroups = {} var axes @@ -178,7 +185,7 @@ horizontal: { contextOffset: isWindow ? 0 : contextOffset.left, contextScroll: isWindow ? 0 : this.oldScroll.x, - contextDimension: this.adapter.width(), + contextDimension: this.width(), oldScroll: this.oldScroll.x, forward: 'right', backward: 'left', @@ -187,7 +194,7 @@ vertical: { contextOffset: isWindow ? 0 : contextOffset.top, contextScroll: isWindow ? 0 : this.oldScroll.y, - contextDimension: height, + contextDimension: this.height(), oldScroll: this.oldScroll.y, forward: 'down', backward: 'up', diff --git a/src/waypoint.js b/src/waypoint.js index 2b50ed3e..a591a49a 100644 --- a/src/waypoint.js +++ b/src/waypoint.js @@ -73,6 +73,16 @@ return this } + /* Public */ + Waypoint.prototype.previous = function() { + return this.group.previous(this) + } + + /* Public */ + Waypoint.prototype.next = function() { + return this.group.next(this) + } + /* Public */ Waypoint.destroyAll = function() { var allWaypointsArray = [] @@ -94,6 +104,11 @@ return window.innerHeight || document.documentElement.clientHeight } + /* Public */ + Waypoint.viewportWidth = function() { + return document.documentElement.clientWidth + } + Waypoint.adapters = [] Waypoint.defaults = { @@ -111,7 +126,7 @@ return this.context.height() - this.adapter.outerHeight() }, 'right-in-view': function() { - return this.context.adapter.width() - this.adapter.outerWidth() + return this.context.width() - this.adapter.outerWidth() } } diff --git a/test/sticky-spec.js b/test/sticky-spec.js index 5734a1fc..53f6bc02 100644 --- a/test/sticky-spec.js +++ b/test/sticky-spec.js @@ -21,6 +21,9 @@ describe('Waypoint Sticky Shortcut', function() { }) afterEach(function() { + if (waypoint) { + waypoint.destroy() + } $scroller.scrollTop(0) waits(standard) }) diff --git a/test/waypoint-spec.js b/test/waypoint-spec.js index edf579be..3ff6c236 100644 --- a/test/waypoint-spec.js +++ b/test/waypoint-spec.js @@ -28,9 +28,7 @@ window.jQuery.each(Waypoint.adapters, function(i, adapter) { }) afterEach(function() { - if (waypoint) { - waypoint.destroy() - } + Waypoint.destroyAll() $scroller.scrollTop(0).scrollLeft(0) waits(standard) }) @@ -338,10 +336,6 @@ window.jQuery.each(Waypoint.adapters, function(i, adapter) { }) }) - afterEach(function() { - laterWaypoint.destroy() - }) - it('does not trigger the earlier waypoint', function() { runs(function() { $scroller.scrollTop($later.offset().top) @@ -462,6 +456,46 @@ window.jQuery.each(Waypoint.adapters, function(i, adapter) { }) }) + describe('#previous', function() { + beforeEach(function() { + $target = $('#same1') + waypoint = new Waypoint({ + element: $target[0], + handler: setHitTrue + }) + }) + + it('calls previous on the waypoint group', function() { + spyOn(waypoint.group, 'previous') + waypoint.previous() + expect(waypoint.group.previous).toHaveBeenCalledWith(waypoint) + }) + + it('returns the group call results', function() { + expect(waypoint.previous()).toBeNull() + }) + }) + + describe('#next', function() { + beforeEach(function() { + $target = $('#same1') + waypoint = new Waypoint({ + element: $target[0], + handler: setHitTrue + }) + }) + + it('calls next on the waypoint group', function() { + spyOn(waypoint.group, 'next') + waypoint.next() + expect(waypoint.group.next).toHaveBeenCalledWith(waypoint) + }) + + it('returns the group call results', function() { + expect(waypoint.next()).toBeNull() + }) + }) + describe('Waypoint.viewportHeight()', function() { it('returns window innerHeight if it exists', function() { var height = Waypoint.viewportHeight() @@ -474,6 +508,13 @@ window.jQuery.each(Waypoint.adapters, function(i, adapter) { }) }) + describe('Waypoint.viewportWidth()', function() { + it('returns client width', function() { + var clientWidth = document.documentElement.clientWidth + expect(Waypoint.viewportWidth()).toEqual(clientWidth) + }) + }) + describe('Waypoint.refreshAll()', function() { it('is an alias for Waypoint.Context.refreshAll', function() { spyOn(Waypoint.Context, 'refreshAll') @@ -490,8 +531,8 @@ window.jQuery.each(Waypoint.adapters, function(i, adapter) { waypoint = new Waypoint({ element: $('#same1')[0] }) - spyOn(secondWaypoint, 'destroy') - spyOn(waypoint, 'destroy') + spyOn(secondWaypoint, 'destroy').andCallThrough() + spyOn(waypoint, 'destroy').andCallThrough() Waypoint.destroyAll() expect(secondWaypoint.destroy).toHaveBeenCalled() expect(waypoint.destroy).toHaveBeenCalled() diff --git a/testem.json b/testem.json index 9e9ae955..afc38921 100644 --- a/testem.json +++ b/testem.json @@ -18,6 +18,6 @@ "src/shortcuts/*.js", "test/settings.js", - "test/*-spec.js" + "test/inview-spec.js" ] } From 1cceec89f19ba4e9903d1ec94db2c28c8ba441d1 Mon Sep 17 00:00:00 2001 From: imakewebthings Date: Mon, 23 Jun 2014 17:18:33 -0700 Subject: [PATCH 27/98] Minor method order tweak --- lib/jquery.waypoints.js | 8 ++++---- lib/jquery.waypoints.min.js | 2 +- lib/noframework.waypoints.js | 8 ++++---- lib/noframework.waypoints.min.js | 2 +- lib/zepto.waypoints.js | 8 ++++---- lib/zepto.waypoints.min.js | 2 +- src/waypoint.js | 8 ++++---- 7 files changed, 19 insertions(+), 19 deletions(-) diff --git a/lib/jquery.waypoints.js b/lib/jquery.waypoints.js index 30f5279f..3f5436a5 100644 --- a/lib/jquery.waypoints.js +++ b/lib/jquery.waypoints.js @@ -80,13 +80,13 @@ https://github.com/imakewebthings/waypoints/blog/master/licenses.txt } /* Public */ - Waypoint.prototype.previous = function() { - return this.group.previous(this) + Waypoint.prototype.next = function() { + return this.group.next(this) } /* Public */ - Waypoint.prototype.next = function() { - return this.group.next(this) + Waypoint.prototype.previous = function() { + return this.group.previous(this) } /* Public */ diff --git a/lib/jquery.waypoints.min.js b/lib/jquery.waypoints.min.js index 0163464a..c528cf5a 100644 --- a/lib/jquery.waypoints.min.js +++ b/lib/jquery.waypoints.min.js @@ -4,4 +4,4 @@ Copyright © 2011-2014 Caleb Troughton Licensed under the MIT license. https://github.com/imakewebthings/waypoints/blog/master/licenses.txt */ -!function(){"use strict";function t(o){if(!o)throw new Error("No options passed to Waypoint constructor");if(!o.element)throw new Error("No element option passed to Waypoint constructor");this.key="waypoint-"+e,this.options=t.Adapter.extend({},t.defaults,o),this.element=this.options.element,this.adapter=new t.Adapter(this.element),this.callback=o.handler,this.axis=this.options.horizontal?"horizontal":"vertical",this.enabled=this.options.enabled,this.triggerPoint=null,this.group=t.Group.findOrCreate({name:this.options.group,axis:this.axis}),this.context=t.Context.findOrCreateByElement(this.options.context),t.offsetAliases[this.options.offset]&&(this.options.offset=t.offsetAliases[this.options.offset]),this.context.add(this),this.group.add(this),i[this.key]=this,e+=1}var e=0,i={};t.prototype.queueTrigger=function(t){this.group.queueTrigger(this,t)},t.prototype.trigger=function(t){this.enabled&&(this.callback&&this.callback.apply(this,t),this.options.triggerOnce&&this.destroy())},t.prototype.destroy=function(){this.context.remove(this),this.group.remove(this),delete i[this.key]},t.prototype.disable=function(){return this.enabled=!1,this},t.prototype.enable=function(){return this.context.refresh(),this.enabled=!0,this},t.prototype.previous=function(){return this.group.previous(this)},t.prototype.next=function(){return this.group.next(this)},t.destroyAll=function(){var t=[];for(var e in i)t.push(i[e]);for(var o=0,r=t.length;r>o;o++)t[o].destroy()},t.refreshAll=function(){t.Context.refreshAll()},t.viewportHeight=function(){return window.innerHeight||document.documentElement.clientHeight},t.viewportWidth=function(){return document.documentElement.clientWidth},t.adapters=[],t.defaults={context:window,continuous:!0,enabled:!0,group:"default",horizontal:!1,offset:0,triggerOnce:!1},t.offsetAliases={"bottom-in-view":function(){return this.context.height()-this.adapter.outerHeight()},"right-in-view":function(){return this.context.width()-this.adapter.outerWidth()}},window.Waypoint=t}()(function(){"use strict";function t(t){window.setTimeout(t,1e3/60)}function e(t){this.element=t,this.Adapter=r.Adapter,this.adapter=new this.Adapter(t),this.key="waypoint-context-"+i,this.didScroll=!1,this.didResize=!1,this.oldScroll={x:this.adapter.scrollLeft(),y:this.adapter.scrollTop()},this.waypoints={vertical:{},horizontal:{}},t.waypointContextKey=this.key,o[t.waypointContextKey]=this,i+=1,this.createThrottledScrollHandler(),this.createThrottledResizeHandler()}var i=0,o={},r=window.Waypoint,n=window.requestAnimationFrame||window.mozRequestAnimationFrame||window.webkitRequestAnimationFrame||t;e.prototype.add=function(t){var e=t.options.horizontal?"horizontal":"vertical";this.waypoints[e][t.key]=t,this.refresh()},e.prototype.checkEmpty=function(){var t=this.Adapter.isEmptyObject(this.waypoints.horizontal),e=this.Adapter.isEmptyObject(this.waypoints.vertical);t&&e&&(this.adapter.off(".waypoints"),delete o[this.key])},e.prototype.createThrottledResizeHandler=function(){function t(){e.handleResize(),e.didResize=!1}var e=this;this.adapter.on("resize.waypoints",function(){e.didResize||(e.didResize=!0,n(t))})},e.prototype.createThrottledScrollHandler=function(){function t(){e.handleScroll(),e.didScroll=!1}var e=this;this.adapter.on("scroll.waypoints",function(){(!e.didScroll||r.isTouch)&&(e.didScroll=!0,n(t))})},e.prototype.handleResize=function(){r.Context.refreshAll()},e.prototype.handleScroll=function(){var t={},e={horizontal:{newScroll:this.adapter.scrollLeft(),oldScroll:this.oldScroll.x,forward:"right",backward:"left"},vertical:{newScroll:this.adapter.scrollTop(),oldScroll:this.oldScroll.y,forward:"down",backward:"up"}};for(var i in e){var o=e[i],r=o.newScroll>o.oldScroll,n=r?o.forward:o.backward;for(var s in this.waypoints[i]){var a=this.waypoints[i][s],l=o.oldScroll=a.triggerPoint,p=l&&h,c=!l&&!h;(p||c)&&(a.queueTrigger(n),t[a.group.id]=a.group)}}for(var u in t)t[u].flushTriggers();this.oldScroll={x:e.horizontal.newScroll,y:e.vertical.newScroll}},e.prototype.height=function(){return this.element===this.element.window?r.viewportHeight():this.adapter.height()},e.prototype.remove=function(t){delete this.waypoints[t.axis][t.key],this.checkEmpty()},e.prototype.width=function(){return this.element===this.element.window?r.viewportWidth():this.adapter.width()},e.prototype.destroy=function(){var t=[];for(var e in this.waypoints)for(var i in this.waypoints[e])t.push(this.waypoints[e][i]);for(var o=0,r=t.length;r>o;o++)t[o].destroy()},e.prototype.refresh=function(){var t,e=this.element===this.element.window,i=this.adapter.offset(),o={};this.handleScroll(),t={horizontal:{contextOffset:e?0:i.left,contextScroll:e?0:this.oldScroll.x,contextDimension:this.width(),oldScroll:this.oldScroll.x,forward:"right",backward:"left",offsetProp:"left"},vertical:{contextOffset:e?0:i.top,contextScroll:e?0:this.oldScroll.y,contextDimension:this.height(),oldScroll:this.oldScroll.y,forward:"down",backward:"up",offsetProp:"top"}};for(var r in t){var n=t[r];for(var s in this.waypoints[r]){var a,l,h,p,c,u=this.waypoints[r][s],d=u.options.offset,f=u.triggerPoint,y=0,g=null==f;u.element!==u.element.window&&(y=u.adapter.offset()[n.offsetProp]),"function"==typeof d?d=d.apply(u):"string"==typeof d&&(d=parseFloat(d),u.options.offset.indexOf("%")>-1&&(d=Math.ceil(n.contextDimension*d/100))),a=n.contextScroll-n.contextOffset,u.triggerPoint=y+a-d,l=f=n.oldScroll,p=l&&h,c=!l&&!h,!g&&p?(u.queueTrigger(n.backward),o[u.group.id]=u.group):!g&&c?(u.queueTrigger(n.forward),o[u.group.id]=u.group):g&&n.oldScroll>=u.triggerPoint&&(u.queueTrigger(n.forward),o[u.group.id]=u.group)}}for(var w in o)o[w].flushTriggers();return this},e.findOrCreateByElement=function(t){return e.findByElement(t)||new e(t)},e.findByElement=function(t){return o[t.waypointContextKey]},e.refreshAll=function(){for(var t in o)o[t].refresh()},r.Context=e}())(function(){"use strict";function t(t,e){return t.triggerPoint-e.triggerPoint}function e(t,e){return e.triggerPoint-t.triggerPoint}function i(t){this.name=t.name,this.axis=t.axis,this.id=this.name+"-"+this.axis,this.waypoints=[],this.clearTriggerQueues(),o[this.axis][this.name]=this}var o={vertical:{},horizontal:{}},r=window.Waypoint;i.prototype.add=function(t){this.waypoints.push(t)},i.prototype.clearTriggerQueues=function(){this.triggerQueues={up:[],down:[],left:[],right:[]}},i.prototype.flushTriggers=function(){for(var i in this.triggerQueues){var o=this.triggerQueues[i],r="up"===i||"left"===i;o.sort(r?e:t);for(var n=0,s=o.length;s>n;n+=1){var a=o[n];(a.options.continuous||n===o.length-1)&&a.trigger([i])}}this.clearTriggerQueues()},i.prototype.queueTrigger=function(t,e){this.triggerQueues[e].push(t)},i.prototype.remove=function(t){var e=r.Adapter.inArray(t,this.waypoints);e>-1&&this.waypoints.splice(e,1)},i.prototype.sort=function(){this.waypoints.sort(function(t,e){return t.triggerPoint-e.triggerPoint})},i.prototype.first=function(){return this.waypoints[0]},i.prototype.last=function(){return this.waypoints[this.waypoints.length-1]},i.prototype.next=function(t){this.sort();var e=r.Adapter.inArray(t,this.waypoints),i=e===this.waypoints.length-1;return i?null:this.waypoints[e+1]},i.prototype.previous=function(t){this.sort();var e=r.Adapter.inArray(t,this.waypoints);return e?this.waypoints[e-1]:null},i.findOrCreate=function(t){return o[t.axis][t.name]||new i(t)},r.Group=i}())(function(){"use strict";function t(t){this.$element=e(t)}var e=window.jQuery,i=window.Waypoint;e.each(["height","off","offset","on","outerHeight","outerWidth","scrollLeft","scrollTop","width"],function(e,i){t.prototype[i]=function(){var t=Array.prototype.slice.call(arguments);return this.$element[i].apply(this.$element,t)}}),e.each(["extend","inArray","isEmptyObject"],function(i,o){t[o]=e[o]}),i.adapters.push({name:"jquery",Adapter:t}),i.Adapter=t}()); \ No newline at end of file +!function(){"use strict";function t(o){if(!o)throw new Error("No options passed to Waypoint constructor");if(!o.element)throw new Error("No element option passed to Waypoint constructor");this.key="waypoint-"+e,this.options=t.Adapter.extend({},t.defaults,o),this.element=this.options.element,this.adapter=new t.Adapter(this.element),this.callback=o.handler,this.axis=this.options.horizontal?"horizontal":"vertical",this.enabled=this.options.enabled,this.triggerPoint=null,this.group=t.Group.findOrCreate({name:this.options.group,axis:this.axis}),this.context=t.Context.findOrCreateByElement(this.options.context),t.offsetAliases[this.options.offset]&&(this.options.offset=t.offsetAliases[this.options.offset]),this.context.add(this),this.group.add(this),i[this.key]=this,e+=1}var e=0,i={};t.prototype.queueTrigger=function(t){this.group.queueTrigger(this,t)},t.prototype.trigger=function(t){this.enabled&&(this.callback&&this.callback.apply(this,t),this.options.triggerOnce&&this.destroy())},t.prototype.destroy=function(){this.context.remove(this),this.group.remove(this),delete i[this.key]},t.prototype.disable=function(){return this.enabled=!1,this},t.prototype.enable=function(){return this.context.refresh(),this.enabled=!0,this},t.prototype.next=function(){return this.group.next(this)},t.prototype.previous=function(){return this.group.previous(this)},t.destroyAll=function(){var t=[];for(var e in i)t.push(i[e]);for(var o=0,r=t.length;r>o;o++)t[o].destroy()},t.refreshAll=function(){t.Context.refreshAll()},t.viewportHeight=function(){return window.innerHeight||document.documentElement.clientHeight},t.viewportWidth=function(){return document.documentElement.clientWidth},t.adapters=[],t.defaults={context:window,continuous:!0,enabled:!0,group:"default",horizontal:!1,offset:0,triggerOnce:!1},t.offsetAliases={"bottom-in-view":function(){return this.context.height()-this.adapter.outerHeight()},"right-in-view":function(){return this.context.width()-this.adapter.outerWidth()}},window.Waypoint=t}()(function(){"use strict";function t(t){window.setTimeout(t,1e3/60)}function e(t){this.element=t,this.Adapter=r.Adapter,this.adapter=new this.Adapter(t),this.key="waypoint-context-"+i,this.didScroll=!1,this.didResize=!1,this.oldScroll={x:this.adapter.scrollLeft(),y:this.adapter.scrollTop()},this.waypoints={vertical:{},horizontal:{}},t.waypointContextKey=this.key,o[t.waypointContextKey]=this,i+=1,this.createThrottledScrollHandler(),this.createThrottledResizeHandler()}var i=0,o={},r=window.Waypoint,n=window.requestAnimationFrame||window.mozRequestAnimationFrame||window.webkitRequestAnimationFrame||t;e.prototype.add=function(t){var e=t.options.horizontal?"horizontal":"vertical";this.waypoints[e][t.key]=t,this.refresh()},e.prototype.checkEmpty=function(){var t=this.Adapter.isEmptyObject(this.waypoints.horizontal),e=this.Adapter.isEmptyObject(this.waypoints.vertical);t&&e&&(this.adapter.off(".waypoints"),delete o[this.key])},e.prototype.createThrottledResizeHandler=function(){function t(){e.handleResize(),e.didResize=!1}var e=this;this.adapter.on("resize.waypoints",function(){e.didResize||(e.didResize=!0,n(t))})},e.prototype.createThrottledScrollHandler=function(){function t(){e.handleScroll(),e.didScroll=!1}var e=this;this.adapter.on("scroll.waypoints",function(){(!e.didScroll||r.isTouch)&&(e.didScroll=!0,n(t))})},e.prototype.handleResize=function(){r.Context.refreshAll()},e.prototype.handleScroll=function(){var t={},e={horizontal:{newScroll:this.adapter.scrollLeft(),oldScroll:this.oldScroll.x,forward:"right",backward:"left"},vertical:{newScroll:this.adapter.scrollTop(),oldScroll:this.oldScroll.y,forward:"down",backward:"up"}};for(var i in e){var o=e[i],r=o.newScroll>o.oldScroll,n=r?o.forward:o.backward;for(var s in this.waypoints[i]){var a=this.waypoints[i][s],l=o.oldScroll=a.triggerPoint,p=l&&h,c=!l&&!h;(p||c)&&(a.queueTrigger(n),t[a.group.id]=a.group)}}for(var u in t)t[u].flushTriggers();this.oldScroll={x:e.horizontal.newScroll,y:e.vertical.newScroll}},e.prototype.height=function(){return this.element===this.element.window?r.viewportHeight():this.adapter.height()},e.prototype.remove=function(t){delete this.waypoints[t.axis][t.key],this.checkEmpty()},e.prototype.width=function(){return this.element===this.element.window?r.viewportWidth():this.adapter.width()},e.prototype.destroy=function(){var t=[];for(var e in this.waypoints)for(var i in this.waypoints[e])t.push(this.waypoints[e][i]);for(var o=0,r=t.length;r>o;o++)t[o].destroy()},e.prototype.refresh=function(){var t,e=this.element===this.element.window,i=this.adapter.offset(),o={};this.handleScroll(),t={horizontal:{contextOffset:e?0:i.left,contextScroll:e?0:this.oldScroll.x,contextDimension:this.width(),oldScroll:this.oldScroll.x,forward:"right",backward:"left",offsetProp:"left"},vertical:{contextOffset:e?0:i.top,contextScroll:e?0:this.oldScroll.y,contextDimension:this.height(),oldScroll:this.oldScroll.y,forward:"down",backward:"up",offsetProp:"top"}};for(var r in t){var n=t[r];for(var s in this.waypoints[r]){var a,l,h,p,c,u=this.waypoints[r][s],d=u.options.offset,f=u.triggerPoint,y=0,g=null==f;u.element!==u.element.window&&(y=u.adapter.offset()[n.offsetProp]),"function"==typeof d?d=d.apply(u):"string"==typeof d&&(d=parseFloat(d),u.options.offset.indexOf("%")>-1&&(d=Math.ceil(n.contextDimension*d/100))),a=n.contextScroll-n.contextOffset,u.triggerPoint=y+a-d,l=f=n.oldScroll,p=l&&h,c=!l&&!h,!g&&p?(u.queueTrigger(n.backward),o[u.group.id]=u.group):!g&&c?(u.queueTrigger(n.forward),o[u.group.id]=u.group):g&&n.oldScroll>=u.triggerPoint&&(u.queueTrigger(n.forward),o[u.group.id]=u.group)}}for(var w in o)o[w].flushTriggers();return this},e.findOrCreateByElement=function(t){return e.findByElement(t)||new e(t)},e.findByElement=function(t){return o[t.waypointContextKey]},e.refreshAll=function(){for(var t in o)o[t].refresh()},r.Context=e}())(function(){"use strict";function t(t,e){return t.triggerPoint-e.triggerPoint}function e(t,e){return e.triggerPoint-t.triggerPoint}function i(t){this.name=t.name,this.axis=t.axis,this.id=this.name+"-"+this.axis,this.waypoints=[],this.clearTriggerQueues(),o[this.axis][this.name]=this}var o={vertical:{},horizontal:{}},r=window.Waypoint;i.prototype.add=function(t){this.waypoints.push(t)},i.prototype.clearTriggerQueues=function(){this.triggerQueues={up:[],down:[],left:[],right:[]}},i.prototype.flushTriggers=function(){for(var i in this.triggerQueues){var o=this.triggerQueues[i],r="up"===i||"left"===i;o.sort(r?e:t);for(var n=0,s=o.length;s>n;n+=1){var a=o[n];(a.options.continuous||n===o.length-1)&&a.trigger([i])}}this.clearTriggerQueues()},i.prototype.queueTrigger=function(t,e){this.triggerQueues[e].push(t)},i.prototype.remove=function(t){var e=r.Adapter.inArray(t,this.waypoints);e>-1&&this.waypoints.splice(e,1)},i.prototype.sort=function(){this.waypoints.sort(function(t,e){return t.triggerPoint-e.triggerPoint})},i.prototype.first=function(){return this.waypoints[0]},i.prototype.last=function(){return this.waypoints[this.waypoints.length-1]},i.prototype.next=function(t){this.sort();var e=r.Adapter.inArray(t,this.waypoints),i=e===this.waypoints.length-1;return i?null:this.waypoints[e+1]},i.prototype.previous=function(t){this.sort();var e=r.Adapter.inArray(t,this.waypoints);return e?this.waypoints[e-1]:null},i.findOrCreate=function(t){return o[t.axis][t.name]||new i(t)},r.Group=i}())(function(){"use strict";function t(t){this.$element=e(t)}var e=window.jQuery,i=window.Waypoint;e.each(["height","off","offset","on","outerHeight","outerWidth","scrollLeft","scrollTop","width"],function(e,i){t.prototype[i]=function(){var t=Array.prototype.slice.call(arguments);return this.$element[i].apply(this.$element,t)}}),e.each(["extend","inArray","isEmptyObject"],function(i,o){t[o]=e[o]}),i.adapters.push({name:"jquery",Adapter:t}),i.Adapter=t}()); \ No newline at end of file diff --git a/lib/noframework.waypoints.js b/lib/noframework.waypoints.js index b9f3f6b0..facdce30 100644 --- a/lib/noframework.waypoints.js +++ b/lib/noframework.waypoints.js @@ -80,13 +80,13 @@ https://github.com/imakewebthings/waypoints/blog/master/licenses.txt } /* Public */ - Waypoint.prototype.previous = function() { - return this.group.previous(this) + Waypoint.prototype.next = function() { + return this.group.next(this) } /* Public */ - Waypoint.prototype.next = function() { - return this.group.next(this) + Waypoint.prototype.previous = function() { + return this.group.previous(this) } /* Public */ diff --git a/lib/noframework.waypoints.min.js b/lib/noframework.waypoints.min.js index 521d5811..d64a1578 100644 --- a/lib/noframework.waypoints.min.js +++ b/lib/noframework.waypoints.min.js @@ -4,4 +4,4 @@ Copyright © 2011-2014 Caleb Troughton Licensed under the MIT license. https://github.com/imakewebthings/waypoints/blog/master/licenses.txt */ -!function(){"use strict";function t(o){if(!o)throw new Error("No options passed to Waypoint constructor");if(!o.element)throw new Error("No element option passed to Waypoint constructor");this.key="waypoint-"+e,this.options=t.Adapter.extend({},t.defaults,o),this.element=this.options.element,this.adapter=new t.Adapter(this.element),this.callback=o.handler,this.axis=this.options.horizontal?"horizontal":"vertical",this.enabled=this.options.enabled,this.triggerPoint=null,this.group=t.Group.findOrCreate({name:this.options.group,axis:this.axis}),this.context=t.Context.findOrCreateByElement(this.options.context),t.offsetAliases[this.options.offset]&&(this.options.offset=t.offsetAliases[this.options.offset]),this.context.add(this),this.group.add(this),i[this.key]=this,e+=1}var e=0,i={};t.prototype.queueTrigger=function(t){this.group.queueTrigger(this,t)},t.prototype.trigger=function(t){this.enabled&&(this.callback&&this.callback.apply(this,t),this.options.triggerOnce&&this.destroy())},t.prototype.destroy=function(){this.context.remove(this),this.group.remove(this),delete i[this.key]},t.prototype.disable=function(){return this.enabled=!1,this},t.prototype.enable=function(){return this.context.refresh(),this.enabled=!0,this},t.prototype.previous=function(){return this.group.previous(this)},t.prototype.next=function(){return this.group.next(this)},t.destroyAll=function(){var t=[];for(var e in i)t.push(i[e]);for(var o=0,r=t.length;r>o;o++)t[o].destroy()},t.refreshAll=function(){t.Context.refreshAll()},t.viewportHeight=function(){return window.innerHeight||document.documentElement.clientHeight},t.viewportWidth=function(){return document.documentElement.clientWidth},t.adapters=[],t.defaults={context:window,continuous:!0,enabled:!0,group:"default",horizontal:!1,offset:0,triggerOnce:!1},t.offsetAliases={"bottom-in-view":function(){return this.context.height()-this.adapter.outerHeight()},"right-in-view":function(){return this.context.width()-this.adapter.outerWidth()}},window.Waypoint=t}()(function(){"use strict";function t(t){window.setTimeout(t,1e3/60)}function e(t){this.element=t,this.Adapter=r.Adapter,this.adapter=new this.Adapter(t),this.key="waypoint-context-"+i,this.didScroll=!1,this.didResize=!1,this.oldScroll={x:this.adapter.scrollLeft(),y:this.adapter.scrollTop()},this.waypoints={vertical:{},horizontal:{}},t.waypointContextKey=this.key,o[t.waypointContextKey]=this,i+=1,this.createThrottledScrollHandler(),this.createThrottledResizeHandler()}var i=0,o={},r=window.Waypoint,n=window.requestAnimationFrame||window.mozRequestAnimationFrame||window.webkitRequestAnimationFrame||t;e.prototype.add=function(t){var e=t.options.horizontal?"horizontal":"vertical";this.waypoints[e][t.key]=t,this.refresh()},e.prototype.checkEmpty=function(){var t=this.Adapter.isEmptyObject(this.waypoints.horizontal),e=this.Adapter.isEmptyObject(this.waypoints.vertical);t&&e&&(this.adapter.off(".waypoints"),delete o[this.key])},e.prototype.createThrottledResizeHandler=function(){function t(){e.handleResize(),e.didResize=!1}var e=this;this.adapter.on("resize.waypoints",function(){e.didResize||(e.didResize=!0,n(t))})},e.prototype.createThrottledScrollHandler=function(){function t(){e.handleScroll(),e.didScroll=!1}var e=this;this.adapter.on("scroll.waypoints",function(){(!e.didScroll||r.isTouch)&&(e.didScroll=!0,n(t))})},e.prototype.handleResize=function(){r.Context.refreshAll()},e.prototype.handleScroll=function(){var t={},e={horizontal:{newScroll:this.adapter.scrollLeft(),oldScroll:this.oldScroll.x,forward:"right",backward:"left"},vertical:{newScroll:this.adapter.scrollTop(),oldScroll:this.oldScroll.y,forward:"down",backward:"up"}};for(var i in e){var o=e[i],r=o.newScroll>o.oldScroll,n=r?o.forward:o.backward;for(var s in this.waypoints[i]){var a=this.waypoints[i][s],l=o.oldScroll=a.triggerPoint,p=l&&h,u=!l&&!h;(p||u)&&(a.queueTrigger(n),t[a.group.id]=a.group)}}for(var f in t)t[f].flushTriggers();this.oldScroll={x:e.horizontal.newScroll,y:e.vertical.newScroll}},e.prototype.height=function(){return this.element===this.element.window?r.viewportHeight():this.adapter.height()},e.prototype.remove=function(t){delete this.waypoints[t.axis][t.key],this.checkEmpty()},e.prototype.width=function(){return this.element===this.element.window?r.viewportWidth():this.adapter.width()},e.prototype.destroy=function(){var t=[];for(var e in this.waypoints)for(var i in this.waypoints[e])t.push(this.waypoints[e][i]);for(var o=0,r=t.length;r>o;o++)t[o].destroy()},e.prototype.refresh=function(){var t,e=this.element===this.element.window,i=this.adapter.offset(),o={};this.handleScroll(),t={horizontal:{contextOffset:e?0:i.left,contextScroll:e?0:this.oldScroll.x,contextDimension:this.width(),oldScroll:this.oldScroll.x,forward:"right",backward:"left",offsetProp:"left"},vertical:{contextOffset:e?0:i.top,contextScroll:e?0:this.oldScroll.y,contextDimension:this.height(),oldScroll:this.oldScroll.y,forward:"down",backward:"up",offsetProp:"top"}};for(var r in t){var n=t[r];for(var s in this.waypoints[r]){var a,l,h,p,u,f=this.waypoints[r][s],c=f.options.offset,d=f.triggerPoint,g=0,y=null==d;f.element!==f.element.window&&(g=f.adapter.offset()[n.offsetProp]),"function"==typeof c?c=c.apply(f):"string"==typeof c&&(c=parseFloat(c),f.options.offset.indexOf("%")>-1&&(c=Math.ceil(n.contextDimension*c/100))),a=n.contextScroll-n.contextOffset,f.triggerPoint=g+a-c,l=d=n.oldScroll,p=l&&h,u=!l&&!h,!y&&p?(f.queueTrigger(n.backward),o[f.group.id]=f.group):!y&&u?(f.queueTrigger(n.forward),o[f.group.id]=f.group):y&&n.oldScroll>=f.triggerPoint&&(f.queueTrigger(n.forward),o[f.group.id]=f.group)}}for(var w in o)o[w].flushTriggers();return this},e.findOrCreateByElement=function(t){return e.findByElement(t)||new e(t)},e.findByElement=function(t){return o[t.waypointContextKey]},e.refreshAll=function(){for(var t in o)o[t].refresh()},r.Context=e}())(function(){"use strict";function t(t,e){return t.triggerPoint-e.triggerPoint}function e(t,e){return e.triggerPoint-t.triggerPoint}function i(t){this.name=t.name,this.axis=t.axis,this.id=this.name+"-"+this.axis,this.waypoints=[],this.clearTriggerQueues(),o[this.axis][this.name]=this}var o={vertical:{},horizontal:{}},r=window.Waypoint;i.prototype.add=function(t){this.waypoints.push(t)},i.prototype.clearTriggerQueues=function(){this.triggerQueues={up:[],down:[],left:[],right:[]}},i.prototype.flushTriggers=function(){for(var i in this.triggerQueues){var o=this.triggerQueues[i],r="up"===i||"left"===i;o.sort(r?e:t);for(var n=0,s=o.length;s>n;n+=1){var a=o[n];(a.options.continuous||n===o.length-1)&&a.trigger([i])}}this.clearTriggerQueues()},i.prototype.queueTrigger=function(t,e){this.triggerQueues[e].push(t)},i.prototype.remove=function(t){var e=r.Adapter.inArray(t,this.waypoints);e>-1&&this.waypoints.splice(e,1)},i.prototype.sort=function(){this.waypoints.sort(function(t,e){return t.triggerPoint-e.triggerPoint})},i.prototype.first=function(){return this.waypoints[0]},i.prototype.last=function(){return this.waypoints[this.waypoints.length-1]},i.prototype.next=function(t){this.sort();var e=r.Adapter.inArray(t,this.waypoints),i=e===this.waypoints.length-1;return i?null:this.waypoints[e+1]},i.prototype.previous=function(t){this.sort();var e=r.Adapter.inArray(t,this.waypoints);return e?this.waypoints[e-1]:null},i.findOrCreate=function(t){return o[t.axis][t.name]||new i(t)},r.Group=i}())(function(){"use strict";function t(t){return t===t.window}function e(e){return t(e)?e:e.defaultView}function i(t){this.element=t,this.handlers={}}var o=window.Waypoint;i.prototype.height=function(){var e=t(this.element);return e?this.element.innerHeight:this.element.offsetHeight},i.prototype.off=function(t,e){function i(t,e,i){for(var o=0,r=e.length-1;r>o;o++){var n=e[o];i&&i!==n||t.removeEventListener(n)}}var o=t.split("."),r=o[0],n=o[1],s=this.element;if(n&&this.handlers[n]&&r)i(s,this.handlers[n][r],e),this.handlers[n][r]=[];else if(r)for(var a in this.handlers)i(s,this.handlers[a][r]||[],e),this.handlers[a][r]=[];else if(n&&this.handlers[n]){for(var l in this.handlers[n])i(s,this.handlers[n][l],e);this.handlers[n]={}}},i.prototype.offset=function(){if(!this.element.ownerDocument)return null;var t=this.element.ownerDocument.documentElement,i=e(this.element.ownerDocument),o={top:0,left:0};return this.element.getBoundingClientRect&&(o=this.element.getBoundingClientRect()),{top:o.top+i.pageYOffset-t.clientTop,left:o.left+i.pageXOffset-t.clientLeft}},i.prototype.on=function(t,e){var i=t.split("."),o=i[0],r=i[1]||"__default",n=this.handlers[r]=this.handlers[r]||{},s=n[o]=n[o]||[];s.push(e),this.element.addEventListener(o,e)},i.prototype.outerHeight=function(e){var i,o=this.height();return e&&!t(this.element)&&(i=window.getComputedStyle(this.element),o+=parseInt(i.marginTop,10),o+=parseInt(i.marginBottom,10)),o},i.prototype.outerWidth=function(e){var i,o=this.width();return e&&!t(this.element)&&(i=window.getComputedStyle(this.element),o+=parseInt(i.marginLeft,10),o+=parseInt(i.marginRight,10)),o},i.prototype.scrollLeft=function(){var t=e(this.element);return t?t.pageXOffset:this.element.scrollLeft},i.prototype.scrollTop=function(){var t=e(this.element);return t?t.pageYOffset:this.element.scrollTop},i.prototype.width=function(){var e=t(this.element);return e?this.element.innerWidth:this.element.offsetWidth},i.extend=function(){function t(t,e){if("object"==typeof t&&"object"==typeof e)for(var i in e)e.hasOwnProperty(i)&&(t[i]=e[i]);return t}for(var e=Array.prototype.slice.call(arguments),i=1,o=e.length;o>i;i++)t(e[0],e[i]);return e[0]},i.inArray=function(t,e,i){return null==e?-1:e.indexOf(t,i)},i.isEmptyObject=function(t){for(var e in t)return!1;return!0},o.adapters.push({name:"noframework",Adapter:i}),o.Adapter=i}()); \ No newline at end of file +!function(){"use strict";function t(o){if(!o)throw new Error("No options passed to Waypoint constructor");if(!o.element)throw new Error("No element option passed to Waypoint constructor");this.key="waypoint-"+e,this.options=t.Adapter.extend({},t.defaults,o),this.element=this.options.element,this.adapter=new t.Adapter(this.element),this.callback=o.handler,this.axis=this.options.horizontal?"horizontal":"vertical",this.enabled=this.options.enabled,this.triggerPoint=null,this.group=t.Group.findOrCreate({name:this.options.group,axis:this.axis}),this.context=t.Context.findOrCreateByElement(this.options.context),t.offsetAliases[this.options.offset]&&(this.options.offset=t.offsetAliases[this.options.offset]),this.context.add(this),this.group.add(this),i[this.key]=this,e+=1}var e=0,i={};t.prototype.queueTrigger=function(t){this.group.queueTrigger(this,t)},t.prototype.trigger=function(t){this.enabled&&(this.callback&&this.callback.apply(this,t),this.options.triggerOnce&&this.destroy())},t.prototype.destroy=function(){this.context.remove(this),this.group.remove(this),delete i[this.key]},t.prototype.disable=function(){return this.enabled=!1,this},t.prototype.enable=function(){return this.context.refresh(),this.enabled=!0,this},t.prototype.next=function(){return this.group.next(this)},t.prototype.previous=function(){return this.group.previous(this)},t.destroyAll=function(){var t=[];for(var e in i)t.push(i[e]);for(var o=0,r=t.length;r>o;o++)t[o].destroy()},t.refreshAll=function(){t.Context.refreshAll()},t.viewportHeight=function(){return window.innerHeight||document.documentElement.clientHeight},t.viewportWidth=function(){return document.documentElement.clientWidth},t.adapters=[],t.defaults={context:window,continuous:!0,enabled:!0,group:"default",horizontal:!1,offset:0,triggerOnce:!1},t.offsetAliases={"bottom-in-view":function(){return this.context.height()-this.adapter.outerHeight()},"right-in-view":function(){return this.context.width()-this.adapter.outerWidth()}},window.Waypoint=t}()(function(){"use strict";function t(t){window.setTimeout(t,1e3/60)}function e(t){this.element=t,this.Adapter=r.Adapter,this.adapter=new this.Adapter(t),this.key="waypoint-context-"+i,this.didScroll=!1,this.didResize=!1,this.oldScroll={x:this.adapter.scrollLeft(),y:this.adapter.scrollTop()},this.waypoints={vertical:{},horizontal:{}},t.waypointContextKey=this.key,o[t.waypointContextKey]=this,i+=1,this.createThrottledScrollHandler(),this.createThrottledResizeHandler()}var i=0,o={},r=window.Waypoint,n=window.requestAnimationFrame||window.mozRequestAnimationFrame||window.webkitRequestAnimationFrame||t;e.prototype.add=function(t){var e=t.options.horizontal?"horizontal":"vertical";this.waypoints[e][t.key]=t,this.refresh()},e.prototype.checkEmpty=function(){var t=this.Adapter.isEmptyObject(this.waypoints.horizontal),e=this.Adapter.isEmptyObject(this.waypoints.vertical);t&&e&&(this.adapter.off(".waypoints"),delete o[this.key])},e.prototype.createThrottledResizeHandler=function(){function t(){e.handleResize(),e.didResize=!1}var e=this;this.adapter.on("resize.waypoints",function(){e.didResize||(e.didResize=!0,n(t))})},e.prototype.createThrottledScrollHandler=function(){function t(){e.handleScroll(),e.didScroll=!1}var e=this;this.adapter.on("scroll.waypoints",function(){(!e.didScroll||r.isTouch)&&(e.didScroll=!0,n(t))})},e.prototype.handleResize=function(){r.Context.refreshAll()},e.prototype.handleScroll=function(){var t={},e={horizontal:{newScroll:this.adapter.scrollLeft(),oldScroll:this.oldScroll.x,forward:"right",backward:"left"},vertical:{newScroll:this.adapter.scrollTop(),oldScroll:this.oldScroll.y,forward:"down",backward:"up"}};for(var i in e){var o=e[i],r=o.newScroll>o.oldScroll,n=r?o.forward:o.backward;for(var s in this.waypoints[i]){var a=this.waypoints[i][s],l=o.oldScroll=a.triggerPoint,p=l&&h,u=!l&&!h;(p||u)&&(a.queueTrigger(n),t[a.group.id]=a.group)}}for(var f in t)t[f].flushTriggers();this.oldScroll={x:e.horizontal.newScroll,y:e.vertical.newScroll}},e.prototype.height=function(){return this.element===this.element.window?r.viewportHeight():this.adapter.height()},e.prototype.remove=function(t){delete this.waypoints[t.axis][t.key],this.checkEmpty()},e.prototype.width=function(){return this.element===this.element.window?r.viewportWidth():this.adapter.width()},e.prototype.destroy=function(){var t=[];for(var e in this.waypoints)for(var i in this.waypoints[e])t.push(this.waypoints[e][i]);for(var o=0,r=t.length;r>o;o++)t[o].destroy()},e.prototype.refresh=function(){var t,e=this.element===this.element.window,i=this.adapter.offset(),o={};this.handleScroll(),t={horizontal:{contextOffset:e?0:i.left,contextScroll:e?0:this.oldScroll.x,contextDimension:this.width(),oldScroll:this.oldScroll.x,forward:"right",backward:"left",offsetProp:"left"},vertical:{contextOffset:e?0:i.top,contextScroll:e?0:this.oldScroll.y,contextDimension:this.height(),oldScroll:this.oldScroll.y,forward:"down",backward:"up",offsetProp:"top"}};for(var r in t){var n=t[r];for(var s in this.waypoints[r]){var a,l,h,p,u,f=this.waypoints[r][s],c=f.options.offset,d=f.triggerPoint,g=0,y=null==d;f.element!==f.element.window&&(g=f.adapter.offset()[n.offsetProp]),"function"==typeof c?c=c.apply(f):"string"==typeof c&&(c=parseFloat(c),f.options.offset.indexOf("%")>-1&&(c=Math.ceil(n.contextDimension*c/100))),a=n.contextScroll-n.contextOffset,f.triggerPoint=g+a-c,l=d=n.oldScroll,p=l&&h,u=!l&&!h,!y&&p?(f.queueTrigger(n.backward),o[f.group.id]=f.group):!y&&u?(f.queueTrigger(n.forward),o[f.group.id]=f.group):y&&n.oldScroll>=f.triggerPoint&&(f.queueTrigger(n.forward),o[f.group.id]=f.group)}}for(var w in o)o[w].flushTriggers();return this},e.findOrCreateByElement=function(t){return e.findByElement(t)||new e(t)},e.findByElement=function(t){return o[t.waypointContextKey]},e.refreshAll=function(){for(var t in o)o[t].refresh()},r.Context=e}())(function(){"use strict";function t(t,e){return t.triggerPoint-e.triggerPoint}function e(t,e){return e.triggerPoint-t.triggerPoint}function i(t){this.name=t.name,this.axis=t.axis,this.id=this.name+"-"+this.axis,this.waypoints=[],this.clearTriggerQueues(),o[this.axis][this.name]=this}var o={vertical:{},horizontal:{}},r=window.Waypoint;i.prototype.add=function(t){this.waypoints.push(t)},i.prototype.clearTriggerQueues=function(){this.triggerQueues={up:[],down:[],left:[],right:[]}},i.prototype.flushTriggers=function(){for(var i in this.triggerQueues){var o=this.triggerQueues[i],r="up"===i||"left"===i;o.sort(r?e:t);for(var n=0,s=o.length;s>n;n+=1){var a=o[n];(a.options.continuous||n===o.length-1)&&a.trigger([i])}}this.clearTriggerQueues()},i.prototype.queueTrigger=function(t,e){this.triggerQueues[e].push(t)},i.prototype.remove=function(t){var e=r.Adapter.inArray(t,this.waypoints);e>-1&&this.waypoints.splice(e,1)},i.prototype.sort=function(){this.waypoints.sort(function(t,e){return t.triggerPoint-e.triggerPoint})},i.prototype.first=function(){return this.waypoints[0]},i.prototype.last=function(){return this.waypoints[this.waypoints.length-1]},i.prototype.next=function(t){this.sort();var e=r.Adapter.inArray(t,this.waypoints),i=e===this.waypoints.length-1;return i?null:this.waypoints[e+1]},i.prototype.previous=function(t){this.sort();var e=r.Adapter.inArray(t,this.waypoints);return e?this.waypoints[e-1]:null},i.findOrCreate=function(t){return o[t.axis][t.name]||new i(t)},r.Group=i}())(function(){"use strict";function t(t){return t===t.window}function e(e){return t(e)?e:e.defaultView}function i(t){this.element=t,this.handlers={}}var o=window.Waypoint;i.prototype.height=function(){var e=t(this.element);return e?this.element.innerHeight:this.element.offsetHeight},i.prototype.off=function(t,e){function i(t,e,i){for(var o=0,r=e.length-1;r>o;o++){var n=e[o];i&&i!==n||t.removeEventListener(n)}}var o=t.split("."),r=o[0],n=o[1],s=this.element;if(n&&this.handlers[n]&&r)i(s,this.handlers[n][r],e),this.handlers[n][r]=[];else if(r)for(var a in this.handlers)i(s,this.handlers[a][r]||[],e),this.handlers[a][r]=[];else if(n&&this.handlers[n]){for(var l in this.handlers[n])i(s,this.handlers[n][l],e);this.handlers[n]={}}},i.prototype.offset=function(){if(!this.element.ownerDocument)return null;var t=this.element.ownerDocument.documentElement,i=e(this.element.ownerDocument),o={top:0,left:0};return this.element.getBoundingClientRect&&(o=this.element.getBoundingClientRect()),{top:o.top+i.pageYOffset-t.clientTop,left:o.left+i.pageXOffset-t.clientLeft}},i.prototype.on=function(t,e){var i=t.split("."),o=i[0],r=i[1]||"__default",n=this.handlers[r]=this.handlers[r]||{},s=n[o]=n[o]||[];s.push(e),this.element.addEventListener(o,e)},i.prototype.outerHeight=function(e){var i,o=this.height();return e&&!t(this.element)&&(i=window.getComputedStyle(this.element),o+=parseInt(i.marginTop,10),o+=parseInt(i.marginBottom,10)),o},i.prototype.outerWidth=function(e){var i,o=this.width();return e&&!t(this.element)&&(i=window.getComputedStyle(this.element),o+=parseInt(i.marginLeft,10),o+=parseInt(i.marginRight,10)),o},i.prototype.scrollLeft=function(){var t=e(this.element);return t?t.pageXOffset:this.element.scrollLeft},i.prototype.scrollTop=function(){var t=e(this.element);return t?t.pageYOffset:this.element.scrollTop},i.prototype.width=function(){var e=t(this.element);return e?this.element.innerWidth:this.element.offsetWidth},i.extend=function(){function t(t,e){if("object"==typeof t&&"object"==typeof e)for(var i in e)e.hasOwnProperty(i)&&(t[i]=e[i]);return t}for(var e=Array.prototype.slice.call(arguments),i=1,o=e.length;o>i;i++)t(e[0],e[i]);return e[0]},i.inArray=function(t,e,i){return null==e?-1:e.indexOf(t,i)},i.isEmptyObject=function(t){for(var e in t)return!1;return!0},o.adapters.push({name:"noframework",Adapter:i}),o.Adapter=i}()); \ No newline at end of file diff --git a/lib/zepto.waypoints.js b/lib/zepto.waypoints.js index 0e2f6f94..196afe59 100644 --- a/lib/zepto.waypoints.js +++ b/lib/zepto.waypoints.js @@ -80,13 +80,13 @@ https://github.com/imakewebthings/waypoints/blog/master/licenses.txt } /* Public */ - Waypoint.prototype.previous = function() { - return this.group.previous(this) + Waypoint.prototype.next = function() { + return this.group.next(this) } /* Public */ - Waypoint.prototype.next = function() { - return this.group.next(this) + Waypoint.prototype.previous = function() { + return this.group.previous(this) } /* Public */ diff --git a/lib/zepto.waypoints.min.js b/lib/zepto.waypoints.min.js index 47b1395e..6b87c4a0 100644 --- a/lib/zepto.waypoints.min.js +++ b/lib/zepto.waypoints.min.js @@ -4,4 +4,4 @@ Copyright © 2011-2014 Caleb Troughton Licensed under the MIT license. https://github.com/imakewebthings/waypoints/blog/master/licenses.txt */ -!function(){"use strict";function t(o){if(!o)throw new Error("No options passed to Waypoint constructor");if(!o.element)throw new Error("No element option passed to Waypoint constructor");this.key="waypoint-"+e,this.options=t.Adapter.extend({},t.defaults,o),this.element=this.options.element,this.adapter=new t.Adapter(this.element),this.callback=o.handler,this.axis=this.options.horizontal?"horizontal":"vertical",this.enabled=this.options.enabled,this.triggerPoint=null,this.group=t.Group.findOrCreate({name:this.options.group,axis:this.axis}),this.context=t.Context.findOrCreateByElement(this.options.context),t.offsetAliases[this.options.offset]&&(this.options.offset=t.offsetAliases[this.options.offset]),this.context.add(this),this.group.add(this),i[this.key]=this,e+=1}var e=0,i={};t.prototype.queueTrigger=function(t){this.group.queueTrigger(this,t)},t.prototype.trigger=function(t){this.enabled&&(this.callback&&this.callback.apply(this,t),this.options.triggerOnce&&this.destroy())},t.prototype.destroy=function(){this.context.remove(this),this.group.remove(this),delete i[this.key]},t.prototype.disable=function(){return this.enabled=!1,this},t.prototype.enable=function(){return this.context.refresh(),this.enabled=!0,this},t.prototype.previous=function(){return this.group.previous(this)},t.prototype.next=function(){return this.group.next(this)},t.destroyAll=function(){var t=[];for(var e in i)t.push(i[e]);for(var o=0,r=t.length;r>o;o++)t[o].destroy()},t.refreshAll=function(){t.Context.refreshAll()},t.viewportHeight=function(){return window.innerHeight||document.documentElement.clientHeight},t.viewportWidth=function(){return document.documentElement.clientWidth},t.adapters=[],t.defaults={context:window,continuous:!0,enabled:!0,group:"default",horizontal:!1,offset:0,triggerOnce:!1},t.offsetAliases={"bottom-in-view":function(){return this.context.height()-this.adapter.outerHeight()},"right-in-view":function(){return this.context.width()-this.adapter.outerWidth()}},window.Waypoint=t}()(function(){"use strict";function t(t){window.setTimeout(t,1e3/60)}function e(t){this.element=t,this.Adapter=r.Adapter,this.adapter=new this.Adapter(t),this.key="waypoint-context-"+i,this.didScroll=!1,this.didResize=!1,this.oldScroll={x:this.adapter.scrollLeft(),y:this.adapter.scrollTop()},this.waypoints={vertical:{},horizontal:{}},t.waypointContextKey=this.key,o[t.waypointContextKey]=this,i+=1,this.createThrottledScrollHandler(),this.createThrottledResizeHandler()}var i=0,o={},r=window.Waypoint,n=window.requestAnimationFrame||window.mozRequestAnimationFrame||window.webkitRequestAnimationFrame||t;e.prototype.add=function(t){var e=t.options.horizontal?"horizontal":"vertical";this.waypoints[e][t.key]=t,this.refresh()},e.prototype.checkEmpty=function(){var t=this.Adapter.isEmptyObject(this.waypoints.horizontal),e=this.Adapter.isEmptyObject(this.waypoints.vertical);t&&e&&(this.adapter.off(".waypoints"),delete o[this.key])},e.prototype.createThrottledResizeHandler=function(){function t(){e.handleResize(),e.didResize=!1}var e=this;this.adapter.on("resize.waypoints",function(){e.didResize||(e.didResize=!0,n(t))})},e.prototype.createThrottledScrollHandler=function(){function t(){e.handleScroll(),e.didScroll=!1}var e=this;this.adapter.on("scroll.waypoints",function(){(!e.didScroll||r.isTouch)&&(e.didScroll=!0,n(t))})},e.prototype.handleResize=function(){r.Context.refreshAll()},e.prototype.handleScroll=function(){var t={},e={horizontal:{newScroll:this.adapter.scrollLeft(),oldScroll:this.oldScroll.x,forward:"right",backward:"left"},vertical:{newScroll:this.adapter.scrollTop(),oldScroll:this.oldScroll.y,forward:"down",backward:"up"}};for(var i in e){var o=e[i],r=o.newScroll>o.oldScroll,n=r?o.forward:o.backward;for(var s in this.waypoints[i]){var a=this.waypoints[i][s],h=o.oldScroll=a.triggerPoint,p=h&&l,c=!h&&!l;(p||c)&&(a.queueTrigger(n),t[a.group.id]=a.group)}}for(var u in t)t[u].flushTriggers();this.oldScroll={x:e.horizontal.newScroll,y:e.vertical.newScroll}},e.prototype.height=function(){return this.element===this.element.window?r.viewportHeight():this.adapter.height()},e.prototype.remove=function(t){delete this.waypoints[t.axis][t.key],this.checkEmpty()},e.prototype.width=function(){return this.element===this.element.window?r.viewportWidth():this.adapter.width()},e.prototype.destroy=function(){var t=[];for(var e in this.waypoints)for(var i in this.waypoints[e])t.push(this.waypoints[e][i]);for(var o=0,r=t.length;r>o;o++)t[o].destroy()},e.prototype.refresh=function(){var t,e=this.element===this.element.window,i=this.adapter.offset(),o={};this.handleScroll(),t={horizontal:{contextOffset:e?0:i.left,contextScroll:e?0:this.oldScroll.x,contextDimension:this.width(),oldScroll:this.oldScroll.x,forward:"right",backward:"left",offsetProp:"left"},vertical:{contextOffset:e?0:i.top,contextScroll:e?0:this.oldScroll.y,contextDimension:this.height(),oldScroll:this.oldScroll.y,forward:"down",backward:"up",offsetProp:"top"}};for(var r in t){var n=t[r];for(var s in this.waypoints[r]){var a,h,l,p,c,u=this.waypoints[r][s],d=u.options.offset,f=u.triggerPoint,y=0,g=null==f;u.element!==u.element.window&&(y=u.adapter.offset()[n.offsetProp]),"function"==typeof d?d=d.apply(u):"string"==typeof d&&(d=parseFloat(d),u.options.offset.indexOf("%")>-1&&(d=Math.ceil(n.contextDimension*d/100))),a=n.contextScroll-n.contextOffset,u.triggerPoint=y+a-d,h=f=n.oldScroll,p=h&&l,c=!h&&!l,!g&&p?(u.queueTrigger(n.backward),o[u.group.id]=u.group):!g&&c?(u.queueTrigger(n.forward),o[u.group.id]=u.group):g&&n.oldScroll>=u.triggerPoint&&(u.queueTrigger(n.forward),o[u.group.id]=u.group)}}for(var w in o)o[w].flushTriggers();return this},e.findOrCreateByElement=function(t){return e.findByElement(t)||new e(t)},e.findByElement=function(t){return o[t.waypointContextKey]},e.refreshAll=function(){for(var t in o)o[t].refresh()},r.Context=e}())(function(){"use strict";function t(t,e){return t.triggerPoint-e.triggerPoint}function e(t,e){return e.triggerPoint-t.triggerPoint}function i(t){this.name=t.name,this.axis=t.axis,this.id=this.name+"-"+this.axis,this.waypoints=[],this.clearTriggerQueues(),o[this.axis][this.name]=this}var o={vertical:{},horizontal:{}},r=window.Waypoint;i.prototype.add=function(t){this.waypoints.push(t)},i.prototype.clearTriggerQueues=function(){this.triggerQueues={up:[],down:[],left:[],right:[]}},i.prototype.flushTriggers=function(){for(var i in this.triggerQueues){var o=this.triggerQueues[i],r="up"===i||"left"===i;o.sort(r?e:t);for(var n=0,s=o.length;s>n;n+=1){var a=o[n];(a.options.continuous||n===o.length-1)&&a.trigger([i])}}this.clearTriggerQueues()},i.prototype.queueTrigger=function(t,e){this.triggerQueues[e].push(t)},i.prototype.remove=function(t){var e=r.Adapter.inArray(t,this.waypoints);e>-1&&this.waypoints.splice(e,1)},i.prototype.sort=function(){this.waypoints.sort(function(t,e){return t.triggerPoint-e.triggerPoint})},i.prototype.first=function(){return this.waypoints[0]},i.prototype.last=function(){return this.waypoints[this.waypoints.length-1]},i.prototype.next=function(t){this.sort();var e=r.Adapter.inArray(t,this.waypoints),i=e===this.waypoints.length-1;return i?null:this.waypoints[e+1]},i.prototype.previous=function(t){this.sort();var e=r.Adapter.inArray(t,this.waypoints);return e?this.waypoints[e-1]:null},i.findOrCreate=function(t){return o[t.axis][t.name]||new i(t)},r.Group=i}())(function(){"use strict";function t(t){this.element=t,this.$element=e(t)}var e=window.Zepto,i=window.Waypoint;e.each(["height","off","on","scrollLeft","scrollTop","width"],function(e,i){t.prototype[i]=function(){var t=Array.prototype.slice.call(arguments);return this.$element[i].apply(this.$element,t)}}),t.prototype.offset=function(){return this.element!==this.element.window?this.$element.offset():void 0},e.each(["width","height"],function(i,o){var r=e.camelCase("outer-"+o);t.prototype[r]=function(t){var i=this.$element[o](),r={width:["left","right"],height:["top","bottom"]};return t&&e.each(r[o],e.proxy(function(t,e){i+=parseInt(this.$element.css("margin-"+e),10)},this)),i}}),e.each(["extend","inArray"],function(i,o){t[o]=e[o]}),t.isEmptyObject=function(t){for(var e in t)return!1;return!0},i.adapters.push({name:"zepto",Adapter:t}),i.Adapter=t}()); \ No newline at end of file +!function(){"use strict";function t(o){if(!o)throw new Error("No options passed to Waypoint constructor");if(!o.element)throw new Error("No element option passed to Waypoint constructor");this.key="waypoint-"+e,this.options=t.Adapter.extend({},t.defaults,o),this.element=this.options.element,this.adapter=new t.Adapter(this.element),this.callback=o.handler,this.axis=this.options.horizontal?"horizontal":"vertical",this.enabled=this.options.enabled,this.triggerPoint=null,this.group=t.Group.findOrCreate({name:this.options.group,axis:this.axis}),this.context=t.Context.findOrCreateByElement(this.options.context),t.offsetAliases[this.options.offset]&&(this.options.offset=t.offsetAliases[this.options.offset]),this.context.add(this),this.group.add(this),i[this.key]=this,e+=1}var e=0,i={};t.prototype.queueTrigger=function(t){this.group.queueTrigger(this,t)},t.prototype.trigger=function(t){this.enabled&&(this.callback&&this.callback.apply(this,t),this.options.triggerOnce&&this.destroy())},t.prototype.destroy=function(){this.context.remove(this),this.group.remove(this),delete i[this.key]},t.prototype.disable=function(){return this.enabled=!1,this},t.prototype.enable=function(){return this.context.refresh(),this.enabled=!0,this},t.prototype.next=function(){return this.group.next(this)},t.prototype.previous=function(){return this.group.previous(this)},t.destroyAll=function(){var t=[];for(var e in i)t.push(i[e]);for(var o=0,r=t.length;r>o;o++)t[o].destroy()},t.refreshAll=function(){t.Context.refreshAll()},t.viewportHeight=function(){return window.innerHeight||document.documentElement.clientHeight},t.viewportWidth=function(){return document.documentElement.clientWidth},t.adapters=[],t.defaults={context:window,continuous:!0,enabled:!0,group:"default",horizontal:!1,offset:0,triggerOnce:!1},t.offsetAliases={"bottom-in-view":function(){return this.context.height()-this.adapter.outerHeight()},"right-in-view":function(){return this.context.width()-this.adapter.outerWidth()}},window.Waypoint=t}()(function(){"use strict";function t(t){window.setTimeout(t,1e3/60)}function e(t){this.element=t,this.Adapter=r.Adapter,this.adapter=new this.Adapter(t),this.key="waypoint-context-"+i,this.didScroll=!1,this.didResize=!1,this.oldScroll={x:this.adapter.scrollLeft(),y:this.adapter.scrollTop()},this.waypoints={vertical:{},horizontal:{}},t.waypointContextKey=this.key,o[t.waypointContextKey]=this,i+=1,this.createThrottledScrollHandler(),this.createThrottledResizeHandler()}var i=0,o={},r=window.Waypoint,n=window.requestAnimationFrame||window.mozRequestAnimationFrame||window.webkitRequestAnimationFrame||t;e.prototype.add=function(t){var e=t.options.horizontal?"horizontal":"vertical";this.waypoints[e][t.key]=t,this.refresh()},e.prototype.checkEmpty=function(){var t=this.Adapter.isEmptyObject(this.waypoints.horizontal),e=this.Adapter.isEmptyObject(this.waypoints.vertical);t&&e&&(this.adapter.off(".waypoints"),delete o[this.key])},e.prototype.createThrottledResizeHandler=function(){function t(){e.handleResize(),e.didResize=!1}var e=this;this.adapter.on("resize.waypoints",function(){e.didResize||(e.didResize=!0,n(t))})},e.prototype.createThrottledScrollHandler=function(){function t(){e.handleScroll(),e.didScroll=!1}var e=this;this.adapter.on("scroll.waypoints",function(){(!e.didScroll||r.isTouch)&&(e.didScroll=!0,n(t))})},e.prototype.handleResize=function(){r.Context.refreshAll()},e.prototype.handleScroll=function(){var t={},e={horizontal:{newScroll:this.adapter.scrollLeft(),oldScroll:this.oldScroll.x,forward:"right",backward:"left"},vertical:{newScroll:this.adapter.scrollTop(),oldScroll:this.oldScroll.y,forward:"down",backward:"up"}};for(var i in e){var o=e[i],r=o.newScroll>o.oldScroll,n=r?o.forward:o.backward;for(var s in this.waypoints[i]){var a=this.waypoints[i][s],h=o.oldScroll=a.triggerPoint,p=h&&l,c=!h&&!l;(p||c)&&(a.queueTrigger(n),t[a.group.id]=a.group)}}for(var u in t)t[u].flushTriggers();this.oldScroll={x:e.horizontal.newScroll,y:e.vertical.newScroll}},e.prototype.height=function(){return this.element===this.element.window?r.viewportHeight():this.adapter.height()},e.prototype.remove=function(t){delete this.waypoints[t.axis][t.key],this.checkEmpty()},e.prototype.width=function(){return this.element===this.element.window?r.viewportWidth():this.adapter.width()},e.prototype.destroy=function(){var t=[];for(var e in this.waypoints)for(var i in this.waypoints[e])t.push(this.waypoints[e][i]);for(var o=0,r=t.length;r>o;o++)t[o].destroy()},e.prototype.refresh=function(){var t,e=this.element===this.element.window,i=this.adapter.offset(),o={};this.handleScroll(),t={horizontal:{contextOffset:e?0:i.left,contextScroll:e?0:this.oldScroll.x,contextDimension:this.width(),oldScroll:this.oldScroll.x,forward:"right",backward:"left",offsetProp:"left"},vertical:{contextOffset:e?0:i.top,contextScroll:e?0:this.oldScroll.y,contextDimension:this.height(),oldScroll:this.oldScroll.y,forward:"down",backward:"up",offsetProp:"top"}};for(var r in t){var n=t[r];for(var s in this.waypoints[r]){var a,h,l,p,c,u=this.waypoints[r][s],d=u.options.offset,f=u.triggerPoint,y=0,g=null==f;u.element!==u.element.window&&(y=u.adapter.offset()[n.offsetProp]),"function"==typeof d?d=d.apply(u):"string"==typeof d&&(d=parseFloat(d),u.options.offset.indexOf("%")>-1&&(d=Math.ceil(n.contextDimension*d/100))),a=n.contextScroll-n.contextOffset,u.triggerPoint=y+a-d,h=f=n.oldScroll,p=h&&l,c=!h&&!l,!g&&p?(u.queueTrigger(n.backward),o[u.group.id]=u.group):!g&&c?(u.queueTrigger(n.forward),o[u.group.id]=u.group):g&&n.oldScroll>=u.triggerPoint&&(u.queueTrigger(n.forward),o[u.group.id]=u.group)}}for(var w in o)o[w].flushTriggers();return this},e.findOrCreateByElement=function(t){return e.findByElement(t)||new e(t)},e.findByElement=function(t){return o[t.waypointContextKey]},e.refreshAll=function(){for(var t in o)o[t].refresh()},r.Context=e}())(function(){"use strict";function t(t,e){return t.triggerPoint-e.triggerPoint}function e(t,e){return e.triggerPoint-t.triggerPoint}function i(t){this.name=t.name,this.axis=t.axis,this.id=this.name+"-"+this.axis,this.waypoints=[],this.clearTriggerQueues(),o[this.axis][this.name]=this}var o={vertical:{},horizontal:{}},r=window.Waypoint;i.prototype.add=function(t){this.waypoints.push(t)},i.prototype.clearTriggerQueues=function(){this.triggerQueues={up:[],down:[],left:[],right:[]}},i.prototype.flushTriggers=function(){for(var i in this.triggerQueues){var o=this.triggerQueues[i],r="up"===i||"left"===i;o.sort(r?e:t);for(var n=0,s=o.length;s>n;n+=1){var a=o[n];(a.options.continuous||n===o.length-1)&&a.trigger([i])}}this.clearTriggerQueues()},i.prototype.queueTrigger=function(t,e){this.triggerQueues[e].push(t)},i.prototype.remove=function(t){var e=r.Adapter.inArray(t,this.waypoints);e>-1&&this.waypoints.splice(e,1)},i.prototype.sort=function(){this.waypoints.sort(function(t,e){return t.triggerPoint-e.triggerPoint})},i.prototype.first=function(){return this.waypoints[0]},i.prototype.last=function(){return this.waypoints[this.waypoints.length-1]},i.prototype.next=function(t){this.sort();var e=r.Adapter.inArray(t,this.waypoints),i=e===this.waypoints.length-1;return i?null:this.waypoints[e+1]},i.prototype.previous=function(t){this.sort();var e=r.Adapter.inArray(t,this.waypoints);return e?this.waypoints[e-1]:null},i.findOrCreate=function(t){return o[t.axis][t.name]||new i(t)},r.Group=i}())(function(){"use strict";function t(t){this.element=t,this.$element=e(t)}var e=window.Zepto,i=window.Waypoint;e.each(["height","off","on","scrollLeft","scrollTop","width"],function(e,i){t.prototype[i]=function(){var t=Array.prototype.slice.call(arguments);return this.$element[i].apply(this.$element,t)}}),t.prototype.offset=function(){return this.element!==this.element.window?this.$element.offset():void 0},e.each(["width","height"],function(i,o){var r=e.camelCase("outer-"+o);t.prototype[r]=function(t){var i=this.$element[o](),r={width:["left","right"],height:["top","bottom"]};return t&&e.each(r[o],e.proxy(function(t,e){i+=parseInt(this.$element.css("margin-"+e),10)},this)),i}}),e.each(["extend","inArray"],function(i,o){t[o]=e[o]}),t.isEmptyObject=function(t){for(var e in t)return!1;return!0},i.adapters.push({name:"zepto",Adapter:t}),i.Adapter=t}()); \ No newline at end of file diff --git a/src/waypoint.js b/src/waypoint.js index a591a49a..01129132 100644 --- a/src/waypoint.js +++ b/src/waypoint.js @@ -74,13 +74,13 @@ } /* Public */ - Waypoint.prototype.previous = function() { - return this.group.previous(this) + Waypoint.prototype.next = function() { + return this.group.next(this) } /* Public */ - Waypoint.prototype.next = function() { - return this.group.next(this) + Waypoint.prototype.previous = function() { + return this.group.previous(this) } /* Public */ From 376425e050ab81621c174b341dc2377f26b8be54 Mon Sep 17 00:00:00 2001 From: imakewebthings Date: Tue, 8 Jul 2014 20:44:10 -0700 Subject: [PATCH 28/98] Privatize group next/prev, context refreshAll --- src/context.js | 12 ++++++------ src/group.js | 30 +++++++++++++++--------------- 2 files changed, 21 insertions(+), 21 deletions(-) diff --git a/src/context.js b/src/context.js index afaef0b7..0610c585 100644 --- a/src/context.js +++ b/src/context.js @@ -261,17 +261,17 @@ return Context.findByElement(element) || new Context(element) } - /* Public */ - Context.findByElement = function(element) { - return contexts[element.waypointContextKey] - } - - /* Public */ + /* Private */ Context.refreshAll = function() { for (var contextId in contexts) { contexts[contextId].refresh() } } + /* Public */ + Context.findByElement = function(element) { + return contexts[element.waypointContextKey] + } + Waypoint.Context = Context }()) diff --git a/src/group.js b/src/group.js index a7d3a3f9..867db0c0 100644 --- a/src/group.js +++ b/src/group.js @@ -55,6 +55,21 @@ this.clearTriggerQueues() } + /* Private */ + Group.prototype.next = function(waypoint) { + this.sort() + var index = Waypoint.Adapter.inArray(waypoint, this.waypoints) + var isLast = index === this.waypoints.length - 1 + return isLast ? null : this.waypoints[index + 1] + } + + /* Private */ + Group.prototype.previous = function(waypoint) { + this.sort() + var index = Waypoint.Adapter.inArray(waypoint, this.waypoints) + return index ? this.waypoints[index - 1] : null + } + /* Private */ Group.prototype.queueTrigger = function(waypoint, direction) { this.triggerQueues[direction].push(waypoint) @@ -85,21 +100,6 @@ return this.waypoints[this.waypoints.length - 1] } - /* Public */ - Group.prototype.next = function(waypoint) { - this.sort() - var index = Waypoint.Adapter.inArray(waypoint, this.waypoints) - var isLast = index === this.waypoints.length - 1 - return isLast ? null : this.waypoints[index + 1] - } - - /* Public */ - Group.prototype.previous = function(waypoint) { - this.sort() - var index = Waypoint.Adapter.inArray(waypoint, this.waypoints) - return index ? this.waypoints[index - 1] : null - } - /* Private */ Group.findOrCreate = function(options) { return groups[options.axis][options.name] || new Group(options) From a5ae0b6b2eb24fbebabff22de55c11995f5845e1 Mon Sep 17 00:00:00 2001 From: imakewebthings Date: Tue, 8 Jul 2014 20:58:38 -0700 Subject: [PATCH 29/98] Add fn extension to jquery and zepto builds --- gulpfile.js | 8 +++- lib/jquery.waypoints.js | 79 +++++++++++++++++++++++--------- lib/jquery.waypoints.min.js | 2 +- lib/noframework.waypoints.js | 42 ++++++++--------- lib/noframework.waypoints.min.js | 2 +- lib/zepto.waypoints.js | 79 +++++++++++++++++++++++--------- lib/zepto.waypoints.min.js | 2 +- 7 files changed, 146 insertions(+), 68 deletions(-) diff --git a/gulpfile.js b/gulpfile.js index d33ec793..8fdf99f5 100644 --- a/gulpfile.js +++ b/gulpfile.js @@ -33,12 +33,16 @@ gulp.task('lint', function() { gulp.task('build-core', function() { var streams = ['noframework', 'jquery', 'zepto'].map(function(adapter) { - return gulp.src([ + var sources = [ 'src/waypoint.js', 'src/context.js', 'src/group.js', 'src/adapters/' + adapter + '.js' - ]) + ] + if (['jquery', 'zepto'].indexOf(adapter) > -1) { + sources.push('src/adapters/jquery-zepto-fn-extension.js') + } + return gulp.src(sources) .pipe(concat(adapter + '.waypoints.js')) .pipe(header(fileHeader('Waypoints'))) .pipe(gulp.dest('lib/')) diff --git a/lib/jquery.waypoints.js b/lib/jquery.waypoints.js index 3f5436a5..875df480 100644 --- a/lib/jquery.waypoints.js +++ b/lib/jquery.waypoints.js @@ -402,18 +402,18 @@ https://github.com/imakewebthings/waypoints/blog/master/licenses.txt return Context.findByElement(element) || new Context(element) } - /* Public */ - Context.findByElement = function(element) { - return contexts[element.waypointContextKey] - } - - /* Public */ + /* Private */ Context.refreshAll = function() { for (var contextId in contexts) { contexts[contextId].refresh() } } + /* Public */ + Context.findByElement = function(element) { + return contexts[element.waypointContextKey] + } + Waypoint.Context = Context }()) @@ -474,6 +474,21 @@ https://github.com/imakewebthings/waypoints/blog/master/licenses.txt this.clearTriggerQueues() } + /* Private */ + Group.prototype.next = function(waypoint) { + this.sort() + var index = Waypoint.Adapter.inArray(waypoint, this.waypoints) + var isLast = index === this.waypoints.length - 1 + return isLast ? null : this.waypoints[index + 1] + } + + /* Private */ + Group.prototype.previous = function(waypoint) { + this.sort() + var index = Waypoint.Adapter.inArray(waypoint, this.waypoints) + return index ? this.waypoints[index - 1] : null + } + /* Private */ Group.prototype.queueTrigger = function(waypoint, direction) { this.triggerQueues[direction].push(waypoint) @@ -504,21 +519,6 @@ https://github.com/imakewebthings/waypoints/blog/master/licenses.txt return this.waypoints[this.waypoints.length - 1] } - /* Public */ - Group.prototype.next = function(waypoint) { - this.sort() - var index = Waypoint.Adapter.inArray(waypoint, this.waypoints) - var isLast = index === this.waypoints.length - 1 - return isLast ? null : this.waypoints[index + 1] - } - - /* Public */ - Group.prototype.previous = function(waypoint) { - this.sort() - var index = Waypoint.Adapter.inArray(waypoint, this.waypoints) - return index ? this.waypoints[index - 1] : null - } - /* Private */ Group.findOrCreate = function(options) { return groups[options.axis][options.name] || new Group(options) @@ -568,3 +568,40 @@ https://github.com/imakewebthings/waypoints/blog/master/licenses.txt }) Waypoint.Adapter = JQueryAdapter }()) + +(function() { + 'use strict' + + var Waypoint = window.Waypoint + + function createExtension(framework) { + return function() { + var waypoints = [] + var overrides = arguments[0] + + if (framework.isFunction(arguments[0])) { + overrides = framework.extend({}, arguments[1]) + overrides.handler = arguments[0] + } + + this.each(function() { + var options = framework.extend({}, overrides, { + element: this + }) + if (typeof options.context === 'string') { + options.context = framework(this).closest(options.context)[0] + } + waypoints.push(new Waypoint(options)) + }) + + return waypoints + } + } + + if (window.jQuery) { + window.jQuery.fn.waypoint = createExtension(window.jQuery) + } + if (window.Zepto) { + window.Zepto.fn.waypoint = createExtension(window.Zepto) + } +}()) diff --git a/lib/jquery.waypoints.min.js b/lib/jquery.waypoints.min.js index c528cf5a..5bb192f1 100644 --- a/lib/jquery.waypoints.min.js +++ b/lib/jquery.waypoints.min.js @@ -4,4 +4,4 @@ Copyright © 2011-2014 Caleb Troughton Licensed under the MIT license. https://github.com/imakewebthings/waypoints/blog/master/licenses.txt */ -!function(){"use strict";function t(o){if(!o)throw new Error("No options passed to Waypoint constructor");if(!o.element)throw new Error("No element option passed to Waypoint constructor");this.key="waypoint-"+e,this.options=t.Adapter.extend({},t.defaults,o),this.element=this.options.element,this.adapter=new t.Adapter(this.element),this.callback=o.handler,this.axis=this.options.horizontal?"horizontal":"vertical",this.enabled=this.options.enabled,this.triggerPoint=null,this.group=t.Group.findOrCreate({name:this.options.group,axis:this.axis}),this.context=t.Context.findOrCreateByElement(this.options.context),t.offsetAliases[this.options.offset]&&(this.options.offset=t.offsetAliases[this.options.offset]),this.context.add(this),this.group.add(this),i[this.key]=this,e+=1}var e=0,i={};t.prototype.queueTrigger=function(t){this.group.queueTrigger(this,t)},t.prototype.trigger=function(t){this.enabled&&(this.callback&&this.callback.apply(this,t),this.options.triggerOnce&&this.destroy())},t.prototype.destroy=function(){this.context.remove(this),this.group.remove(this),delete i[this.key]},t.prototype.disable=function(){return this.enabled=!1,this},t.prototype.enable=function(){return this.context.refresh(),this.enabled=!0,this},t.prototype.next=function(){return this.group.next(this)},t.prototype.previous=function(){return this.group.previous(this)},t.destroyAll=function(){var t=[];for(var e in i)t.push(i[e]);for(var o=0,r=t.length;r>o;o++)t[o].destroy()},t.refreshAll=function(){t.Context.refreshAll()},t.viewportHeight=function(){return window.innerHeight||document.documentElement.clientHeight},t.viewportWidth=function(){return document.documentElement.clientWidth},t.adapters=[],t.defaults={context:window,continuous:!0,enabled:!0,group:"default",horizontal:!1,offset:0,triggerOnce:!1},t.offsetAliases={"bottom-in-view":function(){return this.context.height()-this.adapter.outerHeight()},"right-in-view":function(){return this.context.width()-this.adapter.outerWidth()}},window.Waypoint=t}()(function(){"use strict";function t(t){window.setTimeout(t,1e3/60)}function e(t){this.element=t,this.Adapter=r.Adapter,this.adapter=new this.Adapter(t),this.key="waypoint-context-"+i,this.didScroll=!1,this.didResize=!1,this.oldScroll={x:this.adapter.scrollLeft(),y:this.adapter.scrollTop()},this.waypoints={vertical:{},horizontal:{}},t.waypointContextKey=this.key,o[t.waypointContextKey]=this,i+=1,this.createThrottledScrollHandler(),this.createThrottledResizeHandler()}var i=0,o={},r=window.Waypoint,n=window.requestAnimationFrame||window.mozRequestAnimationFrame||window.webkitRequestAnimationFrame||t;e.prototype.add=function(t){var e=t.options.horizontal?"horizontal":"vertical";this.waypoints[e][t.key]=t,this.refresh()},e.prototype.checkEmpty=function(){var t=this.Adapter.isEmptyObject(this.waypoints.horizontal),e=this.Adapter.isEmptyObject(this.waypoints.vertical);t&&e&&(this.adapter.off(".waypoints"),delete o[this.key])},e.prototype.createThrottledResizeHandler=function(){function t(){e.handleResize(),e.didResize=!1}var e=this;this.adapter.on("resize.waypoints",function(){e.didResize||(e.didResize=!0,n(t))})},e.prototype.createThrottledScrollHandler=function(){function t(){e.handleScroll(),e.didScroll=!1}var e=this;this.adapter.on("scroll.waypoints",function(){(!e.didScroll||r.isTouch)&&(e.didScroll=!0,n(t))})},e.prototype.handleResize=function(){r.Context.refreshAll()},e.prototype.handleScroll=function(){var t={},e={horizontal:{newScroll:this.adapter.scrollLeft(),oldScroll:this.oldScroll.x,forward:"right",backward:"left"},vertical:{newScroll:this.adapter.scrollTop(),oldScroll:this.oldScroll.y,forward:"down",backward:"up"}};for(var i in e){var o=e[i],r=o.newScroll>o.oldScroll,n=r?o.forward:o.backward;for(var s in this.waypoints[i]){var a=this.waypoints[i][s],l=o.oldScroll=a.triggerPoint,p=l&&h,c=!l&&!h;(p||c)&&(a.queueTrigger(n),t[a.group.id]=a.group)}}for(var u in t)t[u].flushTriggers();this.oldScroll={x:e.horizontal.newScroll,y:e.vertical.newScroll}},e.prototype.height=function(){return this.element===this.element.window?r.viewportHeight():this.adapter.height()},e.prototype.remove=function(t){delete this.waypoints[t.axis][t.key],this.checkEmpty()},e.prototype.width=function(){return this.element===this.element.window?r.viewportWidth():this.adapter.width()},e.prototype.destroy=function(){var t=[];for(var e in this.waypoints)for(var i in this.waypoints[e])t.push(this.waypoints[e][i]);for(var o=0,r=t.length;r>o;o++)t[o].destroy()},e.prototype.refresh=function(){var t,e=this.element===this.element.window,i=this.adapter.offset(),o={};this.handleScroll(),t={horizontal:{contextOffset:e?0:i.left,contextScroll:e?0:this.oldScroll.x,contextDimension:this.width(),oldScroll:this.oldScroll.x,forward:"right",backward:"left",offsetProp:"left"},vertical:{contextOffset:e?0:i.top,contextScroll:e?0:this.oldScroll.y,contextDimension:this.height(),oldScroll:this.oldScroll.y,forward:"down",backward:"up",offsetProp:"top"}};for(var r in t){var n=t[r];for(var s in this.waypoints[r]){var a,l,h,p,c,u=this.waypoints[r][s],d=u.options.offset,f=u.triggerPoint,y=0,g=null==f;u.element!==u.element.window&&(y=u.adapter.offset()[n.offsetProp]),"function"==typeof d?d=d.apply(u):"string"==typeof d&&(d=parseFloat(d),u.options.offset.indexOf("%")>-1&&(d=Math.ceil(n.contextDimension*d/100))),a=n.contextScroll-n.contextOffset,u.triggerPoint=y+a-d,l=f=n.oldScroll,p=l&&h,c=!l&&!h,!g&&p?(u.queueTrigger(n.backward),o[u.group.id]=u.group):!g&&c?(u.queueTrigger(n.forward),o[u.group.id]=u.group):g&&n.oldScroll>=u.triggerPoint&&(u.queueTrigger(n.forward),o[u.group.id]=u.group)}}for(var w in o)o[w].flushTriggers();return this},e.findOrCreateByElement=function(t){return e.findByElement(t)||new e(t)},e.findByElement=function(t){return o[t.waypointContextKey]},e.refreshAll=function(){for(var t in o)o[t].refresh()},r.Context=e}())(function(){"use strict";function t(t,e){return t.triggerPoint-e.triggerPoint}function e(t,e){return e.triggerPoint-t.triggerPoint}function i(t){this.name=t.name,this.axis=t.axis,this.id=this.name+"-"+this.axis,this.waypoints=[],this.clearTriggerQueues(),o[this.axis][this.name]=this}var o={vertical:{},horizontal:{}},r=window.Waypoint;i.prototype.add=function(t){this.waypoints.push(t)},i.prototype.clearTriggerQueues=function(){this.triggerQueues={up:[],down:[],left:[],right:[]}},i.prototype.flushTriggers=function(){for(var i in this.triggerQueues){var o=this.triggerQueues[i],r="up"===i||"left"===i;o.sort(r?e:t);for(var n=0,s=o.length;s>n;n+=1){var a=o[n];(a.options.continuous||n===o.length-1)&&a.trigger([i])}}this.clearTriggerQueues()},i.prototype.queueTrigger=function(t,e){this.triggerQueues[e].push(t)},i.prototype.remove=function(t){var e=r.Adapter.inArray(t,this.waypoints);e>-1&&this.waypoints.splice(e,1)},i.prototype.sort=function(){this.waypoints.sort(function(t,e){return t.triggerPoint-e.triggerPoint})},i.prototype.first=function(){return this.waypoints[0]},i.prototype.last=function(){return this.waypoints[this.waypoints.length-1]},i.prototype.next=function(t){this.sort();var e=r.Adapter.inArray(t,this.waypoints),i=e===this.waypoints.length-1;return i?null:this.waypoints[e+1]},i.prototype.previous=function(t){this.sort();var e=r.Adapter.inArray(t,this.waypoints);return e?this.waypoints[e-1]:null},i.findOrCreate=function(t){return o[t.axis][t.name]||new i(t)},r.Group=i}())(function(){"use strict";function t(t){this.$element=e(t)}var e=window.jQuery,i=window.Waypoint;e.each(["height","off","offset","on","outerHeight","outerWidth","scrollLeft","scrollTop","width"],function(e,i){t.prototype[i]=function(){var t=Array.prototype.slice.call(arguments);return this.$element[i].apply(this.$element,t)}}),e.each(["extend","inArray","isEmptyObject"],function(i,o){t[o]=e[o]}),i.adapters.push({name:"jquery",Adapter:t}),i.Adapter=t}()); \ No newline at end of file +!function(){"use strict";function t(o){if(!o)throw new Error("No options passed to Waypoint constructor");if(!o.element)throw new Error("No element option passed to Waypoint constructor");this.key="waypoint-"+e,this.options=t.Adapter.extend({},t.defaults,o),this.element=this.options.element,this.adapter=new t.Adapter(this.element),this.callback=o.handler,this.axis=this.options.horizontal?"horizontal":"vertical",this.enabled=this.options.enabled,this.triggerPoint=null,this.group=t.Group.findOrCreate({name:this.options.group,axis:this.axis}),this.context=t.Context.findOrCreateByElement(this.options.context),t.offsetAliases[this.options.offset]&&(this.options.offset=t.offsetAliases[this.options.offset]),this.context.add(this),this.group.add(this),i[this.key]=this,e+=1}var e=0,i={};t.prototype.queueTrigger=function(t){this.group.queueTrigger(this,t)},t.prototype.trigger=function(t){this.enabled&&(this.callback&&this.callback.apply(this,t),this.options.triggerOnce&&this.destroy())},t.prototype.destroy=function(){this.context.remove(this),this.group.remove(this),delete i[this.key]},t.prototype.disable=function(){return this.enabled=!1,this},t.prototype.enable=function(){return this.context.refresh(),this.enabled=!0,this},t.prototype.next=function(){return this.group.next(this)},t.prototype.previous=function(){return this.group.previous(this)},t.destroyAll=function(){var t=[];for(var e in i)t.push(i[e]);for(var o=0,r=t.length;r>o;o++)t[o].destroy()},t.refreshAll=function(){t.Context.refreshAll()},t.viewportHeight=function(){return window.innerHeight||document.documentElement.clientHeight},t.viewportWidth=function(){return document.documentElement.clientWidth},t.adapters=[],t.defaults={context:window,continuous:!0,enabled:!0,group:"default",horizontal:!1,offset:0,triggerOnce:!1},t.offsetAliases={"bottom-in-view":function(){return this.context.height()-this.adapter.outerHeight()},"right-in-view":function(){return this.context.width()-this.adapter.outerWidth()}},window.Waypoint=t}()(function(){"use strict";function t(t){window.setTimeout(t,1e3/60)}function e(t){this.element=t,this.Adapter=r.Adapter,this.adapter=new this.Adapter(t),this.key="waypoint-context-"+i,this.didScroll=!1,this.didResize=!1,this.oldScroll={x:this.adapter.scrollLeft(),y:this.adapter.scrollTop()},this.waypoints={vertical:{},horizontal:{}},t.waypointContextKey=this.key,o[t.waypointContextKey]=this,i+=1,this.createThrottledScrollHandler(),this.createThrottledResizeHandler()}var i=0,o={},r=window.Waypoint,n=window.requestAnimationFrame||window.mozRequestAnimationFrame||window.webkitRequestAnimationFrame||t;e.prototype.add=function(t){var e=t.options.horizontal?"horizontal":"vertical";this.waypoints[e][t.key]=t,this.refresh()},e.prototype.checkEmpty=function(){var t=this.Adapter.isEmptyObject(this.waypoints.horizontal),e=this.Adapter.isEmptyObject(this.waypoints.vertical);t&&e&&(this.adapter.off(".waypoints"),delete o[this.key])},e.prototype.createThrottledResizeHandler=function(){function t(){e.handleResize(),e.didResize=!1}var e=this;this.adapter.on("resize.waypoints",function(){e.didResize||(e.didResize=!0,n(t))})},e.prototype.createThrottledScrollHandler=function(){function t(){e.handleScroll(),e.didScroll=!1}var e=this;this.adapter.on("scroll.waypoints",function(){(!e.didScroll||r.isTouch)&&(e.didScroll=!0,n(t))})},e.prototype.handleResize=function(){r.Context.refreshAll()},e.prototype.handleScroll=function(){var t={},e={horizontal:{newScroll:this.adapter.scrollLeft(),oldScroll:this.oldScroll.x,forward:"right",backward:"left"},vertical:{newScroll:this.adapter.scrollTop(),oldScroll:this.oldScroll.y,forward:"down",backward:"up"}};for(var i in e){var o=e[i],r=o.newScroll>o.oldScroll,n=r?o.forward:o.backward;for(var s in this.waypoints[i]){var a=this.waypoints[i][s],l=o.oldScroll=a.triggerPoint,p=l&&h,u=!l&&!h;(p||u)&&(a.queueTrigger(n),t[a.group.id]=a.group)}}for(var c in t)t[c].flushTriggers();this.oldScroll={x:e.horizontal.newScroll,y:e.vertical.newScroll}},e.prototype.height=function(){return this.element===this.element.window?r.viewportHeight():this.adapter.height()},e.prototype.remove=function(t){delete this.waypoints[t.axis][t.key],this.checkEmpty()},e.prototype.width=function(){return this.element===this.element.window?r.viewportWidth():this.adapter.width()},e.prototype.destroy=function(){var t=[];for(var e in this.waypoints)for(var i in this.waypoints[e])t.push(this.waypoints[e][i]);for(var o=0,r=t.length;r>o;o++)t[o].destroy()},e.prototype.refresh=function(){var t,e=this.element===this.element.window,i=this.adapter.offset(),o={};this.handleScroll(),t={horizontal:{contextOffset:e?0:i.left,contextScroll:e?0:this.oldScroll.x,contextDimension:this.width(),oldScroll:this.oldScroll.x,forward:"right",backward:"left",offsetProp:"left"},vertical:{contextOffset:e?0:i.top,contextScroll:e?0:this.oldScroll.y,contextDimension:this.height(),oldScroll:this.oldScroll.y,forward:"down",backward:"up",offsetProp:"top"}};for(var r in t){var n=t[r];for(var s in this.waypoints[r]){var a,l,h,p,u,c=this.waypoints[r][s],d=c.options.offset,f=c.triggerPoint,w=0,y=null==f;c.element!==c.element.window&&(w=c.adapter.offset()[n.offsetProp]),"function"==typeof d?d=d.apply(c):"string"==typeof d&&(d=parseFloat(d),c.options.offset.indexOf("%")>-1&&(d=Math.ceil(n.contextDimension*d/100))),a=n.contextScroll-n.contextOffset,c.triggerPoint=w+a-d,l=f=n.oldScroll,p=l&&h,u=!l&&!h,!y&&p?(c.queueTrigger(n.backward),o[c.group.id]=c.group):!y&&u?(c.queueTrigger(n.forward),o[c.group.id]=c.group):y&&n.oldScroll>=c.triggerPoint&&(c.queueTrigger(n.forward),o[c.group.id]=c.group)}}for(var g in o)o[g].flushTriggers();return this},e.findOrCreateByElement=function(t){return e.findByElement(t)||new e(t)},e.refreshAll=function(){for(var t in o)o[t].refresh()},e.findByElement=function(t){return o[t.waypointContextKey]},r.Context=e}())(function(){"use strict";function t(t,e){return t.triggerPoint-e.triggerPoint}function e(t,e){return e.triggerPoint-t.triggerPoint}function i(t){this.name=t.name,this.axis=t.axis,this.id=this.name+"-"+this.axis,this.waypoints=[],this.clearTriggerQueues(),o[this.axis][this.name]=this}var o={vertical:{},horizontal:{}},r=window.Waypoint;i.prototype.add=function(t){this.waypoints.push(t)},i.prototype.clearTriggerQueues=function(){this.triggerQueues={up:[],down:[],left:[],right:[]}},i.prototype.flushTriggers=function(){for(var i in this.triggerQueues){var o=this.triggerQueues[i],r="up"===i||"left"===i;o.sort(r?e:t);for(var n=0,s=o.length;s>n;n+=1){var a=o[n];(a.options.continuous||n===o.length-1)&&a.trigger([i])}}this.clearTriggerQueues()},i.prototype.next=function(t){this.sort();var e=r.Adapter.inArray(t,this.waypoints),i=e===this.waypoints.length-1;return i?null:this.waypoints[e+1]},i.prototype.previous=function(t){this.sort();var e=r.Adapter.inArray(t,this.waypoints);return e?this.waypoints[e-1]:null},i.prototype.queueTrigger=function(t,e){this.triggerQueues[e].push(t)},i.prototype.remove=function(t){var e=r.Adapter.inArray(t,this.waypoints);e>-1&&this.waypoints.splice(e,1)},i.prototype.sort=function(){this.waypoints.sort(function(t,e){return t.triggerPoint-e.triggerPoint})},i.prototype.first=function(){return this.waypoints[0]},i.prototype.last=function(){return this.waypoints[this.waypoints.length-1]},i.findOrCreate=function(t){return o[t.axis][t.name]||new i(t)},r.Group=i}())(function(){"use strict";function t(t){this.$element=e(t)}var e=window.jQuery,i=window.Waypoint;e.each(["height","off","offset","on","outerHeight","outerWidth","scrollLeft","scrollTop","width"],function(e,i){t.prototype[i]=function(){var t=Array.prototype.slice.call(arguments);return this.$element[i].apply(this.$element,t)}}),e.each(["extend","inArray","isEmptyObject"],function(i,o){t[o]=e[o]}),i.adapters.push({name:"jquery",Adapter:t}),i.Adapter=t}())(function(){"use strict";function t(t){return function(){var i=[],o=arguments[0];return t.isFunction(arguments[0])&&(o=t.extend({},arguments[1]),o.handler=arguments[0]),this.each(function(){var r=t.extend({},o,{element:this});"string"==typeof r.context&&(r.context=t(this).closest(r.context)[0]),i.push(new e(r))}),i}}var e=window.Waypoint;window.jQuery&&(window.jQuery.fn.waypoint=t(window.jQuery)),window.Zepto&&(window.Zepto.fn.waypoint=t(window.Zepto))}()); \ No newline at end of file diff --git a/lib/noframework.waypoints.js b/lib/noframework.waypoints.js index facdce30..4e28b739 100644 --- a/lib/noframework.waypoints.js +++ b/lib/noframework.waypoints.js @@ -402,18 +402,18 @@ https://github.com/imakewebthings/waypoints/blog/master/licenses.txt return Context.findByElement(element) || new Context(element) } - /* Public */ - Context.findByElement = function(element) { - return contexts[element.waypointContextKey] - } - - /* Public */ + /* Private */ Context.refreshAll = function() { for (var contextId in contexts) { contexts[contextId].refresh() } } + /* Public */ + Context.findByElement = function(element) { + return contexts[element.waypointContextKey] + } + Waypoint.Context = Context }()) @@ -474,6 +474,21 @@ https://github.com/imakewebthings/waypoints/blog/master/licenses.txt this.clearTriggerQueues() } + /* Private */ + Group.prototype.next = function(waypoint) { + this.sort() + var index = Waypoint.Adapter.inArray(waypoint, this.waypoints) + var isLast = index === this.waypoints.length - 1 + return isLast ? null : this.waypoints[index + 1] + } + + /* Private */ + Group.prototype.previous = function(waypoint) { + this.sort() + var index = Waypoint.Adapter.inArray(waypoint, this.waypoints) + return index ? this.waypoints[index - 1] : null + } + /* Private */ Group.prototype.queueTrigger = function(waypoint, direction) { this.triggerQueues[direction].push(waypoint) @@ -504,21 +519,6 @@ https://github.com/imakewebthings/waypoints/blog/master/licenses.txt return this.waypoints[this.waypoints.length - 1] } - /* Public */ - Group.prototype.next = function(waypoint) { - this.sort() - var index = Waypoint.Adapter.inArray(waypoint, this.waypoints) - var isLast = index === this.waypoints.length - 1 - return isLast ? null : this.waypoints[index + 1] - } - - /* Public */ - Group.prototype.previous = function(waypoint) { - this.sort() - var index = Waypoint.Adapter.inArray(waypoint, this.waypoints) - return index ? this.waypoints[index - 1] : null - } - /* Private */ Group.findOrCreate = function(options) { return groups[options.axis][options.name] || new Group(options) diff --git a/lib/noframework.waypoints.min.js b/lib/noframework.waypoints.min.js index d64a1578..eeaac027 100644 --- a/lib/noframework.waypoints.min.js +++ b/lib/noframework.waypoints.min.js @@ -4,4 +4,4 @@ Copyright © 2011-2014 Caleb Troughton Licensed under the MIT license. https://github.com/imakewebthings/waypoints/blog/master/licenses.txt */ -!function(){"use strict";function t(o){if(!o)throw new Error("No options passed to Waypoint constructor");if(!o.element)throw new Error("No element option passed to Waypoint constructor");this.key="waypoint-"+e,this.options=t.Adapter.extend({},t.defaults,o),this.element=this.options.element,this.adapter=new t.Adapter(this.element),this.callback=o.handler,this.axis=this.options.horizontal?"horizontal":"vertical",this.enabled=this.options.enabled,this.triggerPoint=null,this.group=t.Group.findOrCreate({name:this.options.group,axis:this.axis}),this.context=t.Context.findOrCreateByElement(this.options.context),t.offsetAliases[this.options.offset]&&(this.options.offset=t.offsetAliases[this.options.offset]),this.context.add(this),this.group.add(this),i[this.key]=this,e+=1}var e=0,i={};t.prototype.queueTrigger=function(t){this.group.queueTrigger(this,t)},t.prototype.trigger=function(t){this.enabled&&(this.callback&&this.callback.apply(this,t),this.options.triggerOnce&&this.destroy())},t.prototype.destroy=function(){this.context.remove(this),this.group.remove(this),delete i[this.key]},t.prototype.disable=function(){return this.enabled=!1,this},t.prototype.enable=function(){return this.context.refresh(),this.enabled=!0,this},t.prototype.next=function(){return this.group.next(this)},t.prototype.previous=function(){return this.group.previous(this)},t.destroyAll=function(){var t=[];for(var e in i)t.push(i[e]);for(var o=0,r=t.length;r>o;o++)t[o].destroy()},t.refreshAll=function(){t.Context.refreshAll()},t.viewportHeight=function(){return window.innerHeight||document.documentElement.clientHeight},t.viewportWidth=function(){return document.documentElement.clientWidth},t.adapters=[],t.defaults={context:window,continuous:!0,enabled:!0,group:"default",horizontal:!1,offset:0,triggerOnce:!1},t.offsetAliases={"bottom-in-view":function(){return this.context.height()-this.adapter.outerHeight()},"right-in-view":function(){return this.context.width()-this.adapter.outerWidth()}},window.Waypoint=t}()(function(){"use strict";function t(t){window.setTimeout(t,1e3/60)}function e(t){this.element=t,this.Adapter=r.Adapter,this.adapter=new this.Adapter(t),this.key="waypoint-context-"+i,this.didScroll=!1,this.didResize=!1,this.oldScroll={x:this.adapter.scrollLeft(),y:this.adapter.scrollTop()},this.waypoints={vertical:{},horizontal:{}},t.waypointContextKey=this.key,o[t.waypointContextKey]=this,i+=1,this.createThrottledScrollHandler(),this.createThrottledResizeHandler()}var i=0,o={},r=window.Waypoint,n=window.requestAnimationFrame||window.mozRequestAnimationFrame||window.webkitRequestAnimationFrame||t;e.prototype.add=function(t){var e=t.options.horizontal?"horizontal":"vertical";this.waypoints[e][t.key]=t,this.refresh()},e.prototype.checkEmpty=function(){var t=this.Adapter.isEmptyObject(this.waypoints.horizontal),e=this.Adapter.isEmptyObject(this.waypoints.vertical);t&&e&&(this.adapter.off(".waypoints"),delete o[this.key])},e.prototype.createThrottledResizeHandler=function(){function t(){e.handleResize(),e.didResize=!1}var e=this;this.adapter.on("resize.waypoints",function(){e.didResize||(e.didResize=!0,n(t))})},e.prototype.createThrottledScrollHandler=function(){function t(){e.handleScroll(),e.didScroll=!1}var e=this;this.adapter.on("scroll.waypoints",function(){(!e.didScroll||r.isTouch)&&(e.didScroll=!0,n(t))})},e.prototype.handleResize=function(){r.Context.refreshAll()},e.prototype.handleScroll=function(){var t={},e={horizontal:{newScroll:this.adapter.scrollLeft(),oldScroll:this.oldScroll.x,forward:"right",backward:"left"},vertical:{newScroll:this.adapter.scrollTop(),oldScroll:this.oldScroll.y,forward:"down",backward:"up"}};for(var i in e){var o=e[i],r=o.newScroll>o.oldScroll,n=r?o.forward:o.backward;for(var s in this.waypoints[i]){var a=this.waypoints[i][s],l=o.oldScroll=a.triggerPoint,p=l&&h,u=!l&&!h;(p||u)&&(a.queueTrigger(n),t[a.group.id]=a.group)}}for(var f in t)t[f].flushTriggers();this.oldScroll={x:e.horizontal.newScroll,y:e.vertical.newScroll}},e.prototype.height=function(){return this.element===this.element.window?r.viewportHeight():this.adapter.height()},e.prototype.remove=function(t){delete this.waypoints[t.axis][t.key],this.checkEmpty()},e.prototype.width=function(){return this.element===this.element.window?r.viewportWidth():this.adapter.width()},e.prototype.destroy=function(){var t=[];for(var e in this.waypoints)for(var i in this.waypoints[e])t.push(this.waypoints[e][i]);for(var o=0,r=t.length;r>o;o++)t[o].destroy()},e.prototype.refresh=function(){var t,e=this.element===this.element.window,i=this.adapter.offset(),o={};this.handleScroll(),t={horizontal:{contextOffset:e?0:i.left,contextScroll:e?0:this.oldScroll.x,contextDimension:this.width(),oldScroll:this.oldScroll.x,forward:"right",backward:"left",offsetProp:"left"},vertical:{contextOffset:e?0:i.top,contextScroll:e?0:this.oldScroll.y,contextDimension:this.height(),oldScroll:this.oldScroll.y,forward:"down",backward:"up",offsetProp:"top"}};for(var r in t){var n=t[r];for(var s in this.waypoints[r]){var a,l,h,p,u,f=this.waypoints[r][s],c=f.options.offset,d=f.triggerPoint,g=0,y=null==d;f.element!==f.element.window&&(g=f.adapter.offset()[n.offsetProp]),"function"==typeof c?c=c.apply(f):"string"==typeof c&&(c=parseFloat(c),f.options.offset.indexOf("%")>-1&&(c=Math.ceil(n.contextDimension*c/100))),a=n.contextScroll-n.contextOffset,f.triggerPoint=g+a-c,l=d=n.oldScroll,p=l&&h,u=!l&&!h,!y&&p?(f.queueTrigger(n.backward),o[f.group.id]=f.group):!y&&u?(f.queueTrigger(n.forward),o[f.group.id]=f.group):y&&n.oldScroll>=f.triggerPoint&&(f.queueTrigger(n.forward),o[f.group.id]=f.group)}}for(var w in o)o[w].flushTriggers();return this},e.findOrCreateByElement=function(t){return e.findByElement(t)||new e(t)},e.findByElement=function(t){return o[t.waypointContextKey]},e.refreshAll=function(){for(var t in o)o[t].refresh()},r.Context=e}())(function(){"use strict";function t(t,e){return t.triggerPoint-e.triggerPoint}function e(t,e){return e.triggerPoint-t.triggerPoint}function i(t){this.name=t.name,this.axis=t.axis,this.id=this.name+"-"+this.axis,this.waypoints=[],this.clearTriggerQueues(),o[this.axis][this.name]=this}var o={vertical:{},horizontal:{}},r=window.Waypoint;i.prototype.add=function(t){this.waypoints.push(t)},i.prototype.clearTriggerQueues=function(){this.triggerQueues={up:[],down:[],left:[],right:[]}},i.prototype.flushTriggers=function(){for(var i in this.triggerQueues){var o=this.triggerQueues[i],r="up"===i||"left"===i;o.sort(r?e:t);for(var n=0,s=o.length;s>n;n+=1){var a=o[n];(a.options.continuous||n===o.length-1)&&a.trigger([i])}}this.clearTriggerQueues()},i.prototype.queueTrigger=function(t,e){this.triggerQueues[e].push(t)},i.prototype.remove=function(t){var e=r.Adapter.inArray(t,this.waypoints);e>-1&&this.waypoints.splice(e,1)},i.prototype.sort=function(){this.waypoints.sort(function(t,e){return t.triggerPoint-e.triggerPoint})},i.prototype.first=function(){return this.waypoints[0]},i.prototype.last=function(){return this.waypoints[this.waypoints.length-1]},i.prototype.next=function(t){this.sort();var e=r.Adapter.inArray(t,this.waypoints),i=e===this.waypoints.length-1;return i?null:this.waypoints[e+1]},i.prototype.previous=function(t){this.sort();var e=r.Adapter.inArray(t,this.waypoints);return e?this.waypoints[e-1]:null},i.findOrCreate=function(t){return o[t.axis][t.name]||new i(t)},r.Group=i}())(function(){"use strict";function t(t){return t===t.window}function e(e){return t(e)?e:e.defaultView}function i(t){this.element=t,this.handlers={}}var o=window.Waypoint;i.prototype.height=function(){var e=t(this.element);return e?this.element.innerHeight:this.element.offsetHeight},i.prototype.off=function(t,e){function i(t,e,i){for(var o=0,r=e.length-1;r>o;o++){var n=e[o];i&&i!==n||t.removeEventListener(n)}}var o=t.split("."),r=o[0],n=o[1],s=this.element;if(n&&this.handlers[n]&&r)i(s,this.handlers[n][r],e),this.handlers[n][r]=[];else if(r)for(var a in this.handlers)i(s,this.handlers[a][r]||[],e),this.handlers[a][r]=[];else if(n&&this.handlers[n]){for(var l in this.handlers[n])i(s,this.handlers[n][l],e);this.handlers[n]={}}},i.prototype.offset=function(){if(!this.element.ownerDocument)return null;var t=this.element.ownerDocument.documentElement,i=e(this.element.ownerDocument),o={top:0,left:0};return this.element.getBoundingClientRect&&(o=this.element.getBoundingClientRect()),{top:o.top+i.pageYOffset-t.clientTop,left:o.left+i.pageXOffset-t.clientLeft}},i.prototype.on=function(t,e){var i=t.split("."),o=i[0],r=i[1]||"__default",n=this.handlers[r]=this.handlers[r]||{},s=n[o]=n[o]||[];s.push(e),this.element.addEventListener(o,e)},i.prototype.outerHeight=function(e){var i,o=this.height();return e&&!t(this.element)&&(i=window.getComputedStyle(this.element),o+=parseInt(i.marginTop,10),o+=parseInt(i.marginBottom,10)),o},i.prototype.outerWidth=function(e){var i,o=this.width();return e&&!t(this.element)&&(i=window.getComputedStyle(this.element),o+=parseInt(i.marginLeft,10),o+=parseInt(i.marginRight,10)),o},i.prototype.scrollLeft=function(){var t=e(this.element);return t?t.pageXOffset:this.element.scrollLeft},i.prototype.scrollTop=function(){var t=e(this.element);return t?t.pageYOffset:this.element.scrollTop},i.prototype.width=function(){var e=t(this.element);return e?this.element.innerWidth:this.element.offsetWidth},i.extend=function(){function t(t,e){if("object"==typeof t&&"object"==typeof e)for(var i in e)e.hasOwnProperty(i)&&(t[i]=e[i]);return t}for(var e=Array.prototype.slice.call(arguments),i=1,o=e.length;o>i;i++)t(e[0],e[i]);return e[0]},i.inArray=function(t,e,i){return null==e?-1:e.indexOf(t,i)},i.isEmptyObject=function(t){for(var e in t)return!1;return!0},o.adapters.push({name:"noframework",Adapter:i}),o.Adapter=i}()); \ No newline at end of file +!function(){"use strict";function t(o){if(!o)throw new Error("No options passed to Waypoint constructor");if(!o.element)throw new Error("No element option passed to Waypoint constructor");this.key="waypoint-"+e,this.options=t.Adapter.extend({},t.defaults,o),this.element=this.options.element,this.adapter=new t.Adapter(this.element),this.callback=o.handler,this.axis=this.options.horizontal?"horizontal":"vertical",this.enabled=this.options.enabled,this.triggerPoint=null,this.group=t.Group.findOrCreate({name:this.options.group,axis:this.axis}),this.context=t.Context.findOrCreateByElement(this.options.context),t.offsetAliases[this.options.offset]&&(this.options.offset=t.offsetAliases[this.options.offset]),this.context.add(this),this.group.add(this),i[this.key]=this,e+=1}var e=0,i={};t.prototype.queueTrigger=function(t){this.group.queueTrigger(this,t)},t.prototype.trigger=function(t){this.enabled&&(this.callback&&this.callback.apply(this,t),this.options.triggerOnce&&this.destroy())},t.prototype.destroy=function(){this.context.remove(this),this.group.remove(this),delete i[this.key]},t.prototype.disable=function(){return this.enabled=!1,this},t.prototype.enable=function(){return this.context.refresh(),this.enabled=!0,this},t.prototype.next=function(){return this.group.next(this)},t.prototype.previous=function(){return this.group.previous(this)},t.destroyAll=function(){var t=[];for(var e in i)t.push(i[e]);for(var o=0,r=t.length;r>o;o++)t[o].destroy()},t.refreshAll=function(){t.Context.refreshAll()},t.viewportHeight=function(){return window.innerHeight||document.documentElement.clientHeight},t.viewportWidth=function(){return document.documentElement.clientWidth},t.adapters=[],t.defaults={context:window,continuous:!0,enabled:!0,group:"default",horizontal:!1,offset:0,triggerOnce:!1},t.offsetAliases={"bottom-in-view":function(){return this.context.height()-this.adapter.outerHeight()},"right-in-view":function(){return this.context.width()-this.adapter.outerWidth()}},window.Waypoint=t}()(function(){"use strict";function t(t){window.setTimeout(t,1e3/60)}function e(t){this.element=t,this.Adapter=r.Adapter,this.adapter=new this.Adapter(t),this.key="waypoint-context-"+i,this.didScroll=!1,this.didResize=!1,this.oldScroll={x:this.adapter.scrollLeft(),y:this.adapter.scrollTop()},this.waypoints={vertical:{},horizontal:{}},t.waypointContextKey=this.key,o[t.waypointContextKey]=this,i+=1,this.createThrottledScrollHandler(),this.createThrottledResizeHandler()}var i=0,o={},r=window.Waypoint,n=window.requestAnimationFrame||window.mozRequestAnimationFrame||window.webkitRequestAnimationFrame||t;e.prototype.add=function(t){var e=t.options.horizontal?"horizontal":"vertical";this.waypoints[e][t.key]=t,this.refresh()},e.prototype.checkEmpty=function(){var t=this.Adapter.isEmptyObject(this.waypoints.horizontal),e=this.Adapter.isEmptyObject(this.waypoints.vertical);t&&e&&(this.adapter.off(".waypoints"),delete o[this.key])},e.prototype.createThrottledResizeHandler=function(){function t(){e.handleResize(),e.didResize=!1}var e=this;this.adapter.on("resize.waypoints",function(){e.didResize||(e.didResize=!0,n(t))})},e.prototype.createThrottledScrollHandler=function(){function t(){e.handleScroll(),e.didScroll=!1}var e=this;this.adapter.on("scroll.waypoints",function(){(!e.didScroll||r.isTouch)&&(e.didScroll=!0,n(t))})},e.prototype.handleResize=function(){r.Context.refreshAll()},e.prototype.handleScroll=function(){var t={},e={horizontal:{newScroll:this.adapter.scrollLeft(),oldScroll:this.oldScroll.x,forward:"right",backward:"left"},vertical:{newScroll:this.adapter.scrollTop(),oldScroll:this.oldScroll.y,forward:"down",backward:"up"}};for(var i in e){var o=e[i],r=o.newScroll>o.oldScroll,n=r?o.forward:o.backward;for(var s in this.waypoints[i]){var a=this.waypoints[i][s],l=o.oldScroll=a.triggerPoint,p=l&&h,u=!l&&!h;(p||u)&&(a.queueTrigger(n),t[a.group.id]=a.group)}}for(var f in t)t[f].flushTriggers();this.oldScroll={x:e.horizontal.newScroll,y:e.vertical.newScroll}},e.prototype.height=function(){return this.element===this.element.window?r.viewportHeight():this.adapter.height()},e.prototype.remove=function(t){delete this.waypoints[t.axis][t.key],this.checkEmpty()},e.prototype.width=function(){return this.element===this.element.window?r.viewportWidth():this.adapter.width()},e.prototype.destroy=function(){var t=[];for(var e in this.waypoints)for(var i in this.waypoints[e])t.push(this.waypoints[e][i]);for(var o=0,r=t.length;r>o;o++)t[o].destroy()},e.prototype.refresh=function(){var t,e=this.element===this.element.window,i=this.adapter.offset(),o={};this.handleScroll(),t={horizontal:{contextOffset:e?0:i.left,contextScroll:e?0:this.oldScroll.x,contextDimension:this.width(),oldScroll:this.oldScroll.x,forward:"right",backward:"left",offsetProp:"left"},vertical:{contextOffset:e?0:i.top,contextScroll:e?0:this.oldScroll.y,contextDimension:this.height(),oldScroll:this.oldScroll.y,forward:"down",backward:"up",offsetProp:"top"}};for(var r in t){var n=t[r];for(var s in this.waypoints[r]){var a,l,h,p,u,f=this.waypoints[r][s],c=f.options.offset,d=f.triggerPoint,g=0,y=null==d;f.element!==f.element.window&&(g=f.adapter.offset()[n.offsetProp]),"function"==typeof c?c=c.apply(f):"string"==typeof c&&(c=parseFloat(c),f.options.offset.indexOf("%")>-1&&(c=Math.ceil(n.contextDimension*c/100))),a=n.contextScroll-n.contextOffset,f.triggerPoint=g+a-c,l=d=n.oldScroll,p=l&&h,u=!l&&!h,!y&&p?(f.queueTrigger(n.backward),o[f.group.id]=f.group):!y&&u?(f.queueTrigger(n.forward),o[f.group.id]=f.group):y&&n.oldScroll>=f.triggerPoint&&(f.queueTrigger(n.forward),o[f.group.id]=f.group)}}for(var w in o)o[w].flushTriggers();return this},e.findOrCreateByElement=function(t){return e.findByElement(t)||new e(t)},e.refreshAll=function(){for(var t in o)o[t].refresh()},e.findByElement=function(t){return o[t.waypointContextKey]},r.Context=e}())(function(){"use strict";function t(t,e){return t.triggerPoint-e.triggerPoint}function e(t,e){return e.triggerPoint-t.triggerPoint}function i(t){this.name=t.name,this.axis=t.axis,this.id=this.name+"-"+this.axis,this.waypoints=[],this.clearTriggerQueues(),o[this.axis][this.name]=this}var o={vertical:{},horizontal:{}},r=window.Waypoint;i.prototype.add=function(t){this.waypoints.push(t)},i.prototype.clearTriggerQueues=function(){this.triggerQueues={up:[],down:[],left:[],right:[]}},i.prototype.flushTriggers=function(){for(var i in this.triggerQueues){var o=this.triggerQueues[i],r="up"===i||"left"===i;o.sort(r?e:t);for(var n=0,s=o.length;s>n;n+=1){var a=o[n];(a.options.continuous||n===o.length-1)&&a.trigger([i])}}this.clearTriggerQueues()},i.prototype.next=function(t){this.sort();var e=r.Adapter.inArray(t,this.waypoints),i=e===this.waypoints.length-1;return i?null:this.waypoints[e+1]},i.prototype.previous=function(t){this.sort();var e=r.Adapter.inArray(t,this.waypoints);return e?this.waypoints[e-1]:null},i.prototype.queueTrigger=function(t,e){this.triggerQueues[e].push(t)},i.prototype.remove=function(t){var e=r.Adapter.inArray(t,this.waypoints);e>-1&&this.waypoints.splice(e,1)},i.prototype.sort=function(){this.waypoints.sort(function(t,e){return t.triggerPoint-e.triggerPoint})},i.prototype.first=function(){return this.waypoints[0]},i.prototype.last=function(){return this.waypoints[this.waypoints.length-1]},i.findOrCreate=function(t){return o[t.axis][t.name]||new i(t)},r.Group=i}())(function(){"use strict";function t(t){return t===t.window}function e(e){return t(e)?e:e.defaultView}function i(t){this.element=t,this.handlers={}}var o=window.Waypoint;i.prototype.height=function(){var e=t(this.element);return e?this.element.innerHeight:this.element.offsetHeight},i.prototype.off=function(t,e){function i(t,e,i){for(var o=0,r=e.length-1;r>o;o++){var n=e[o];i&&i!==n||t.removeEventListener(n)}}var o=t.split("."),r=o[0],n=o[1],s=this.element;if(n&&this.handlers[n]&&r)i(s,this.handlers[n][r],e),this.handlers[n][r]=[];else if(r)for(var a in this.handlers)i(s,this.handlers[a][r]||[],e),this.handlers[a][r]=[];else if(n&&this.handlers[n]){for(var l in this.handlers[n])i(s,this.handlers[n][l],e);this.handlers[n]={}}},i.prototype.offset=function(){if(!this.element.ownerDocument)return null;var t=this.element.ownerDocument.documentElement,i=e(this.element.ownerDocument),o={top:0,left:0};return this.element.getBoundingClientRect&&(o=this.element.getBoundingClientRect()),{top:o.top+i.pageYOffset-t.clientTop,left:o.left+i.pageXOffset-t.clientLeft}},i.prototype.on=function(t,e){var i=t.split("."),o=i[0],r=i[1]||"__default",n=this.handlers[r]=this.handlers[r]||{},s=n[o]=n[o]||[];s.push(e),this.element.addEventListener(o,e)},i.prototype.outerHeight=function(e){var i,o=this.height();return e&&!t(this.element)&&(i=window.getComputedStyle(this.element),o+=parseInt(i.marginTop,10),o+=parseInt(i.marginBottom,10)),o},i.prototype.outerWidth=function(e){var i,o=this.width();return e&&!t(this.element)&&(i=window.getComputedStyle(this.element),o+=parseInt(i.marginLeft,10),o+=parseInt(i.marginRight,10)),o},i.prototype.scrollLeft=function(){var t=e(this.element);return t?t.pageXOffset:this.element.scrollLeft},i.prototype.scrollTop=function(){var t=e(this.element);return t?t.pageYOffset:this.element.scrollTop},i.prototype.width=function(){var e=t(this.element);return e?this.element.innerWidth:this.element.offsetWidth},i.extend=function(){function t(t,e){if("object"==typeof t&&"object"==typeof e)for(var i in e)e.hasOwnProperty(i)&&(t[i]=e[i]);return t}for(var e=Array.prototype.slice.call(arguments),i=1,o=e.length;o>i;i++)t(e[0],e[i]);return e[0]},i.inArray=function(t,e,i){return null==e?-1:e.indexOf(t,i)},i.isEmptyObject=function(t){for(var e in t)return!1;return!0},o.adapters.push({name:"noframework",Adapter:i}),o.Adapter=i}()); \ No newline at end of file diff --git a/lib/zepto.waypoints.js b/lib/zepto.waypoints.js index 196afe59..01eed679 100644 --- a/lib/zepto.waypoints.js +++ b/lib/zepto.waypoints.js @@ -402,18 +402,18 @@ https://github.com/imakewebthings/waypoints/blog/master/licenses.txt return Context.findByElement(element) || new Context(element) } - /* Public */ - Context.findByElement = function(element) { - return contexts[element.waypointContextKey] - } - - /* Public */ + /* Private */ Context.refreshAll = function() { for (var contextId in contexts) { contexts[contextId].refresh() } } + /* Public */ + Context.findByElement = function(element) { + return contexts[element.waypointContextKey] + } + Waypoint.Context = Context }()) @@ -474,6 +474,21 @@ https://github.com/imakewebthings/waypoints/blog/master/licenses.txt this.clearTriggerQueues() } + /* Private */ + Group.prototype.next = function(waypoint) { + this.sort() + var index = Waypoint.Adapter.inArray(waypoint, this.waypoints) + var isLast = index === this.waypoints.length - 1 + return isLast ? null : this.waypoints[index + 1] + } + + /* Private */ + Group.prototype.previous = function(waypoint) { + this.sort() + var index = Waypoint.Adapter.inArray(waypoint, this.waypoints) + return index ? this.waypoints[index - 1] : null + } + /* Private */ Group.prototype.queueTrigger = function(waypoint, direction) { this.triggerQueues[direction].push(waypoint) @@ -504,21 +519,6 @@ https://github.com/imakewebthings/waypoints/blog/master/licenses.txt return this.waypoints[this.waypoints.length - 1] } - /* Public */ - Group.prototype.next = function(waypoint) { - this.sort() - var index = Waypoint.Adapter.inArray(waypoint, this.waypoints) - var isLast = index === this.waypoints.length - 1 - return isLast ? null : this.waypoints[index + 1] - } - - /* Public */ - Group.prototype.previous = function(waypoint) { - this.sort() - var index = Waypoint.Adapter.inArray(waypoint, this.waypoints) - return index ? this.waypoints[index - 1] : null - } - /* Private */ Group.findOrCreate = function(options) { return groups[options.axis][options.name] || new Group(options) @@ -600,3 +600,40 @@ https://github.com/imakewebthings/waypoints/blog/master/licenses.txt }) Waypoint.Adapter = ZeptoAdapter }()) + +(function() { + 'use strict' + + var Waypoint = window.Waypoint + + function createExtension(framework) { + return function() { + var waypoints = [] + var overrides = arguments[0] + + if (framework.isFunction(arguments[0])) { + overrides = framework.extend({}, arguments[1]) + overrides.handler = arguments[0] + } + + this.each(function() { + var options = framework.extend({}, overrides, { + element: this + }) + if (typeof options.context === 'string') { + options.context = framework(this).closest(options.context)[0] + } + waypoints.push(new Waypoint(options)) + }) + + return waypoints + } + } + + if (window.jQuery) { + window.jQuery.fn.waypoint = createExtension(window.jQuery) + } + if (window.Zepto) { + window.Zepto.fn.waypoint = createExtension(window.Zepto) + } +}()) diff --git a/lib/zepto.waypoints.min.js b/lib/zepto.waypoints.min.js index 6b87c4a0..0e7895ae 100644 --- a/lib/zepto.waypoints.min.js +++ b/lib/zepto.waypoints.min.js @@ -4,4 +4,4 @@ Copyright © 2011-2014 Caleb Troughton Licensed under the MIT license. https://github.com/imakewebthings/waypoints/blog/master/licenses.txt */ -!function(){"use strict";function t(o){if(!o)throw new Error("No options passed to Waypoint constructor");if(!o.element)throw new Error("No element option passed to Waypoint constructor");this.key="waypoint-"+e,this.options=t.Adapter.extend({},t.defaults,o),this.element=this.options.element,this.adapter=new t.Adapter(this.element),this.callback=o.handler,this.axis=this.options.horizontal?"horizontal":"vertical",this.enabled=this.options.enabled,this.triggerPoint=null,this.group=t.Group.findOrCreate({name:this.options.group,axis:this.axis}),this.context=t.Context.findOrCreateByElement(this.options.context),t.offsetAliases[this.options.offset]&&(this.options.offset=t.offsetAliases[this.options.offset]),this.context.add(this),this.group.add(this),i[this.key]=this,e+=1}var e=0,i={};t.prototype.queueTrigger=function(t){this.group.queueTrigger(this,t)},t.prototype.trigger=function(t){this.enabled&&(this.callback&&this.callback.apply(this,t),this.options.triggerOnce&&this.destroy())},t.prototype.destroy=function(){this.context.remove(this),this.group.remove(this),delete i[this.key]},t.prototype.disable=function(){return this.enabled=!1,this},t.prototype.enable=function(){return this.context.refresh(),this.enabled=!0,this},t.prototype.next=function(){return this.group.next(this)},t.prototype.previous=function(){return this.group.previous(this)},t.destroyAll=function(){var t=[];for(var e in i)t.push(i[e]);for(var o=0,r=t.length;r>o;o++)t[o].destroy()},t.refreshAll=function(){t.Context.refreshAll()},t.viewportHeight=function(){return window.innerHeight||document.documentElement.clientHeight},t.viewportWidth=function(){return document.documentElement.clientWidth},t.adapters=[],t.defaults={context:window,continuous:!0,enabled:!0,group:"default",horizontal:!1,offset:0,triggerOnce:!1},t.offsetAliases={"bottom-in-view":function(){return this.context.height()-this.adapter.outerHeight()},"right-in-view":function(){return this.context.width()-this.adapter.outerWidth()}},window.Waypoint=t}()(function(){"use strict";function t(t){window.setTimeout(t,1e3/60)}function e(t){this.element=t,this.Adapter=r.Adapter,this.adapter=new this.Adapter(t),this.key="waypoint-context-"+i,this.didScroll=!1,this.didResize=!1,this.oldScroll={x:this.adapter.scrollLeft(),y:this.adapter.scrollTop()},this.waypoints={vertical:{},horizontal:{}},t.waypointContextKey=this.key,o[t.waypointContextKey]=this,i+=1,this.createThrottledScrollHandler(),this.createThrottledResizeHandler()}var i=0,o={},r=window.Waypoint,n=window.requestAnimationFrame||window.mozRequestAnimationFrame||window.webkitRequestAnimationFrame||t;e.prototype.add=function(t){var e=t.options.horizontal?"horizontal":"vertical";this.waypoints[e][t.key]=t,this.refresh()},e.prototype.checkEmpty=function(){var t=this.Adapter.isEmptyObject(this.waypoints.horizontal),e=this.Adapter.isEmptyObject(this.waypoints.vertical);t&&e&&(this.adapter.off(".waypoints"),delete o[this.key])},e.prototype.createThrottledResizeHandler=function(){function t(){e.handleResize(),e.didResize=!1}var e=this;this.adapter.on("resize.waypoints",function(){e.didResize||(e.didResize=!0,n(t))})},e.prototype.createThrottledScrollHandler=function(){function t(){e.handleScroll(),e.didScroll=!1}var e=this;this.adapter.on("scroll.waypoints",function(){(!e.didScroll||r.isTouch)&&(e.didScroll=!0,n(t))})},e.prototype.handleResize=function(){r.Context.refreshAll()},e.prototype.handleScroll=function(){var t={},e={horizontal:{newScroll:this.adapter.scrollLeft(),oldScroll:this.oldScroll.x,forward:"right",backward:"left"},vertical:{newScroll:this.adapter.scrollTop(),oldScroll:this.oldScroll.y,forward:"down",backward:"up"}};for(var i in e){var o=e[i],r=o.newScroll>o.oldScroll,n=r?o.forward:o.backward;for(var s in this.waypoints[i]){var a=this.waypoints[i][s],h=o.oldScroll=a.triggerPoint,p=h&&l,c=!h&&!l;(p||c)&&(a.queueTrigger(n),t[a.group.id]=a.group)}}for(var u in t)t[u].flushTriggers();this.oldScroll={x:e.horizontal.newScroll,y:e.vertical.newScroll}},e.prototype.height=function(){return this.element===this.element.window?r.viewportHeight():this.adapter.height()},e.prototype.remove=function(t){delete this.waypoints[t.axis][t.key],this.checkEmpty()},e.prototype.width=function(){return this.element===this.element.window?r.viewportWidth():this.adapter.width()},e.prototype.destroy=function(){var t=[];for(var e in this.waypoints)for(var i in this.waypoints[e])t.push(this.waypoints[e][i]);for(var o=0,r=t.length;r>o;o++)t[o].destroy()},e.prototype.refresh=function(){var t,e=this.element===this.element.window,i=this.adapter.offset(),o={};this.handleScroll(),t={horizontal:{contextOffset:e?0:i.left,contextScroll:e?0:this.oldScroll.x,contextDimension:this.width(),oldScroll:this.oldScroll.x,forward:"right",backward:"left",offsetProp:"left"},vertical:{contextOffset:e?0:i.top,contextScroll:e?0:this.oldScroll.y,contextDimension:this.height(),oldScroll:this.oldScroll.y,forward:"down",backward:"up",offsetProp:"top"}};for(var r in t){var n=t[r];for(var s in this.waypoints[r]){var a,h,l,p,c,u=this.waypoints[r][s],d=u.options.offset,f=u.triggerPoint,y=0,g=null==f;u.element!==u.element.window&&(y=u.adapter.offset()[n.offsetProp]),"function"==typeof d?d=d.apply(u):"string"==typeof d&&(d=parseFloat(d),u.options.offset.indexOf("%")>-1&&(d=Math.ceil(n.contextDimension*d/100))),a=n.contextScroll-n.contextOffset,u.triggerPoint=y+a-d,h=f=n.oldScroll,p=h&&l,c=!h&&!l,!g&&p?(u.queueTrigger(n.backward),o[u.group.id]=u.group):!g&&c?(u.queueTrigger(n.forward),o[u.group.id]=u.group):g&&n.oldScroll>=u.triggerPoint&&(u.queueTrigger(n.forward),o[u.group.id]=u.group)}}for(var w in o)o[w].flushTriggers();return this},e.findOrCreateByElement=function(t){return e.findByElement(t)||new e(t)},e.findByElement=function(t){return o[t.waypointContextKey]},e.refreshAll=function(){for(var t in o)o[t].refresh()},r.Context=e}())(function(){"use strict";function t(t,e){return t.triggerPoint-e.triggerPoint}function e(t,e){return e.triggerPoint-t.triggerPoint}function i(t){this.name=t.name,this.axis=t.axis,this.id=this.name+"-"+this.axis,this.waypoints=[],this.clearTriggerQueues(),o[this.axis][this.name]=this}var o={vertical:{},horizontal:{}},r=window.Waypoint;i.prototype.add=function(t){this.waypoints.push(t)},i.prototype.clearTriggerQueues=function(){this.triggerQueues={up:[],down:[],left:[],right:[]}},i.prototype.flushTriggers=function(){for(var i in this.triggerQueues){var o=this.triggerQueues[i],r="up"===i||"left"===i;o.sort(r?e:t);for(var n=0,s=o.length;s>n;n+=1){var a=o[n];(a.options.continuous||n===o.length-1)&&a.trigger([i])}}this.clearTriggerQueues()},i.prototype.queueTrigger=function(t,e){this.triggerQueues[e].push(t)},i.prototype.remove=function(t){var e=r.Adapter.inArray(t,this.waypoints);e>-1&&this.waypoints.splice(e,1)},i.prototype.sort=function(){this.waypoints.sort(function(t,e){return t.triggerPoint-e.triggerPoint})},i.prototype.first=function(){return this.waypoints[0]},i.prototype.last=function(){return this.waypoints[this.waypoints.length-1]},i.prototype.next=function(t){this.sort();var e=r.Adapter.inArray(t,this.waypoints),i=e===this.waypoints.length-1;return i?null:this.waypoints[e+1]},i.prototype.previous=function(t){this.sort();var e=r.Adapter.inArray(t,this.waypoints);return e?this.waypoints[e-1]:null},i.findOrCreate=function(t){return o[t.axis][t.name]||new i(t)},r.Group=i}())(function(){"use strict";function t(t){this.element=t,this.$element=e(t)}var e=window.Zepto,i=window.Waypoint;e.each(["height","off","on","scrollLeft","scrollTop","width"],function(e,i){t.prototype[i]=function(){var t=Array.prototype.slice.call(arguments);return this.$element[i].apply(this.$element,t)}}),t.prototype.offset=function(){return this.element!==this.element.window?this.$element.offset():void 0},e.each(["width","height"],function(i,o){var r=e.camelCase("outer-"+o);t.prototype[r]=function(t){var i=this.$element[o](),r={width:["left","right"],height:["top","bottom"]};return t&&e.each(r[o],e.proxy(function(t,e){i+=parseInt(this.$element.css("margin-"+e),10)},this)),i}}),e.each(["extend","inArray"],function(i,o){t[o]=e[o]}),t.isEmptyObject=function(t){for(var e in t)return!1;return!0},i.adapters.push({name:"zepto",Adapter:t}),i.Adapter=t}()); \ No newline at end of file +!function(){"use strict";function t(o){if(!o)throw new Error("No options passed to Waypoint constructor");if(!o.element)throw new Error("No element option passed to Waypoint constructor");this.key="waypoint-"+e,this.options=t.Adapter.extend({},t.defaults,o),this.element=this.options.element,this.adapter=new t.Adapter(this.element),this.callback=o.handler,this.axis=this.options.horizontal?"horizontal":"vertical",this.enabled=this.options.enabled,this.triggerPoint=null,this.group=t.Group.findOrCreate({name:this.options.group,axis:this.axis}),this.context=t.Context.findOrCreateByElement(this.options.context),t.offsetAliases[this.options.offset]&&(this.options.offset=t.offsetAliases[this.options.offset]),this.context.add(this),this.group.add(this),i[this.key]=this,e+=1}var e=0,i={};t.prototype.queueTrigger=function(t){this.group.queueTrigger(this,t)},t.prototype.trigger=function(t){this.enabled&&(this.callback&&this.callback.apply(this,t),this.options.triggerOnce&&this.destroy())},t.prototype.destroy=function(){this.context.remove(this),this.group.remove(this),delete i[this.key]},t.prototype.disable=function(){return this.enabled=!1,this},t.prototype.enable=function(){return this.context.refresh(),this.enabled=!0,this},t.prototype.next=function(){return this.group.next(this)},t.prototype.previous=function(){return this.group.previous(this)},t.destroyAll=function(){var t=[];for(var e in i)t.push(i[e]);for(var o=0,r=t.length;r>o;o++)t[o].destroy()},t.refreshAll=function(){t.Context.refreshAll()},t.viewportHeight=function(){return window.innerHeight||document.documentElement.clientHeight},t.viewportWidth=function(){return document.documentElement.clientWidth},t.adapters=[],t.defaults={context:window,continuous:!0,enabled:!0,group:"default",horizontal:!1,offset:0,triggerOnce:!1},t.offsetAliases={"bottom-in-view":function(){return this.context.height()-this.adapter.outerHeight()},"right-in-view":function(){return this.context.width()-this.adapter.outerWidth()}},window.Waypoint=t}()(function(){"use strict";function t(t){window.setTimeout(t,1e3/60)}function e(t){this.element=t,this.Adapter=r.Adapter,this.adapter=new this.Adapter(t),this.key="waypoint-context-"+i,this.didScroll=!1,this.didResize=!1,this.oldScroll={x:this.adapter.scrollLeft(),y:this.adapter.scrollTop()},this.waypoints={vertical:{},horizontal:{}},t.waypointContextKey=this.key,o[t.waypointContextKey]=this,i+=1,this.createThrottledScrollHandler(),this.createThrottledResizeHandler()}var i=0,o={},r=window.Waypoint,n=window.requestAnimationFrame||window.mozRequestAnimationFrame||window.webkitRequestAnimationFrame||t;e.prototype.add=function(t){var e=t.options.horizontal?"horizontal":"vertical";this.waypoints[e][t.key]=t,this.refresh()},e.prototype.checkEmpty=function(){var t=this.Adapter.isEmptyObject(this.waypoints.horizontal),e=this.Adapter.isEmptyObject(this.waypoints.vertical);t&&e&&(this.adapter.off(".waypoints"),delete o[this.key])},e.prototype.createThrottledResizeHandler=function(){function t(){e.handleResize(),e.didResize=!1}var e=this;this.adapter.on("resize.waypoints",function(){e.didResize||(e.didResize=!0,n(t))})},e.prototype.createThrottledScrollHandler=function(){function t(){e.handleScroll(),e.didScroll=!1}var e=this;this.adapter.on("scroll.waypoints",function(){(!e.didScroll||r.isTouch)&&(e.didScroll=!0,n(t))})},e.prototype.handleResize=function(){r.Context.refreshAll()},e.prototype.handleScroll=function(){var t={},e={horizontal:{newScroll:this.adapter.scrollLeft(),oldScroll:this.oldScroll.x,forward:"right",backward:"left"},vertical:{newScroll:this.adapter.scrollTop(),oldScroll:this.oldScroll.y,forward:"down",backward:"up"}};for(var i in e){var o=e[i],r=o.newScroll>o.oldScroll,n=r?o.forward:o.backward;for(var s in this.waypoints[i]){var a=this.waypoints[i][s],h=o.oldScroll=a.triggerPoint,p=h&&l,c=!h&&!l;(p||c)&&(a.queueTrigger(n),t[a.group.id]=a.group)}}for(var u in t)t[u].flushTriggers();this.oldScroll={x:e.horizontal.newScroll,y:e.vertical.newScroll}},e.prototype.height=function(){return this.element===this.element.window?r.viewportHeight():this.adapter.height()},e.prototype.remove=function(t){delete this.waypoints[t.axis][t.key],this.checkEmpty()},e.prototype.width=function(){return this.element===this.element.window?r.viewportWidth():this.adapter.width()},e.prototype.destroy=function(){var t=[];for(var e in this.waypoints)for(var i in this.waypoints[e])t.push(this.waypoints[e][i]);for(var o=0,r=t.length;r>o;o++)t[o].destroy()},e.prototype.refresh=function(){var t,e=this.element===this.element.window,i=this.adapter.offset(),o={};this.handleScroll(),t={horizontal:{contextOffset:e?0:i.left,contextScroll:e?0:this.oldScroll.x,contextDimension:this.width(),oldScroll:this.oldScroll.x,forward:"right",backward:"left",offsetProp:"left"},vertical:{contextOffset:e?0:i.top,contextScroll:e?0:this.oldScroll.y,contextDimension:this.height(),oldScroll:this.oldScroll.y,forward:"down",backward:"up",offsetProp:"top"}};for(var r in t){var n=t[r];for(var s in this.waypoints[r]){var a,h,l,p,c,u=this.waypoints[r][s],d=u.options.offset,f=u.triggerPoint,w=0,y=null==f;u.element!==u.element.window&&(w=u.adapter.offset()[n.offsetProp]),"function"==typeof d?d=d.apply(u):"string"==typeof d&&(d=parseFloat(d),u.options.offset.indexOf("%")>-1&&(d=Math.ceil(n.contextDimension*d/100))),a=n.contextScroll-n.contextOffset,u.triggerPoint=w+a-d,h=f=n.oldScroll,p=h&&l,c=!h&&!l,!y&&p?(u.queueTrigger(n.backward),o[u.group.id]=u.group):!y&&c?(u.queueTrigger(n.forward),o[u.group.id]=u.group):y&&n.oldScroll>=u.triggerPoint&&(u.queueTrigger(n.forward),o[u.group.id]=u.group)}}for(var g in o)o[g].flushTriggers();return this},e.findOrCreateByElement=function(t){return e.findByElement(t)||new e(t)},e.refreshAll=function(){for(var t in o)o[t].refresh()},e.findByElement=function(t){return o[t.waypointContextKey]},r.Context=e}())(function(){"use strict";function t(t,e){return t.triggerPoint-e.triggerPoint}function e(t,e){return e.triggerPoint-t.triggerPoint}function i(t){this.name=t.name,this.axis=t.axis,this.id=this.name+"-"+this.axis,this.waypoints=[],this.clearTriggerQueues(),o[this.axis][this.name]=this}var o={vertical:{},horizontal:{}},r=window.Waypoint;i.prototype.add=function(t){this.waypoints.push(t)},i.prototype.clearTriggerQueues=function(){this.triggerQueues={up:[],down:[],left:[],right:[]}},i.prototype.flushTriggers=function(){for(var i in this.triggerQueues){var o=this.triggerQueues[i],r="up"===i||"left"===i;o.sort(r?e:t);for(var n=0,s=o.length;s>n;n+=1){var a=o[n];(a.options.continuous||n===o.length-1)&&a.trigger([i])}}this.clearTriggerQueues()},i.prototype.next=function(t){this.sort();var e=r.Adapter.inArray(t,this.waypoints),i=e===this.waypoints.length-1;return i?null:this.waypoints[e+1]},i.prototype.previous=function(t){this.sort();var e=r.Adapter.inArray(t,this.waypoints);return e?this.waypoints[e-1]:null},i.prototype.queueTrigger=function(t,e){this.triggerQueues[e].push(t)},i.prototype.remove=function(t){var e=r.Adapter.inArray(t,this.waypoints);e>-1&&this.waypoints.splice(e,1)},i.prototype.sort=function(){this.waypoints.sort(function(t,e){return t.triggerPoint-e.triggerPoint})},i.prototype.first=function(){return this.waypoints[0]},i.prototype.last=function(){return this.waypoints[this.waypoints.length-1]},i.findOrCreate=function(t){return o[t.axis][t.name]||new i(t)},r.Group=i}())(function(){"use strict";function t(t){this.element=t,this.$element=e(t)}var e=window.Zepto,i=window.Waypoint;e.each(["height","off","on","scrollLeft","scrollTop","width"],function(e,i){t.prototype[i]=function(){var t=Array.prototype.slice.call(arguments);return this.$element[i].apply(this.$element,t)}}),t.prototype.offset=function(){return this.element!==this.element.window?this.$element.offset():void 0},e.each(["width","height"],function(i,o){var r=e.camelCase("outer-"+o);t.prototype[r]=function(t){var i=this.$element[o](),r={width:["left","right"],height:["top","bottom"]};return t&&e.each(r[o],e.proxy(function(t,e){i+=parseInt(this.$element.css("margin-"+e),10)},this)),i}}),e.each(["extend","inArray"],function(i,o){t[o]=e[o]}),t.isEmptyObject=function(t){for(var e in t)return!1;return!0},i.adapters.push({name:"zepto",Adapter:t}),i.Adapter=t}())(function(){"use strict";function t(t){return function(){var i=[],o=arguments[0];return t.isFunction(arguments[0])&&(o=t.extend({},arguments[1]),o.handler=arguments[0]),this.each(function(){var r=t.extend({},o,{element:this});"string"==typeof r.context&&(r.context=t(this).closest(r.context)[0]),i.push(new e(r))}),i}}var e=window.Waypoint;window.jQuery&&(window.jQuery.fn.waypoint=t(window.jQuery)),window.Zepto&&(window.Zepto.fn.waypoint=t(window.Zepto))}()); \ No newline at end of file From b1d128f1fd093524dcfe3b35dfc00479ab63ff4d Mon Sep 17 00:00:00 2001 From: imakewebthings Date: Wed, 9 Jul 2014 08:20:46 -0700 Subject: [PATCH 30/98] Remove unneccesary sort method --- src/group.js | 11 ++--------- 1 file changed, 2 insertions(+), 9 deletions(-) diff --git a/src/group.js b/src/group.js index 867db0c0..507206ec 100644 --- a/src/group.js +++ b/src/group.js @@ -57,7 +57,7 @@ /* Private */ Group.prototype.next = function(waypoint) { - this.sort() + this.waypoints.sort(byTriggerPoint) var index = Waypoint.Adapter.inArray(waypoint, this.waypoints) var isLast = index === this.waypoints.length - 1 return isLast ? null : this.waypoints[index + 1] @@ -65,7 +65,7 @@ /* Private */ Group.prototype.previous = function(waypoint) { - this.sort() + this.waypoints.sort(byTriggerPoint) var index = Waypoint.Adapter.inArray(waypoint, this.waypoints) return index ? this.waypoints[index - 1] : null } @@ -83,13 +83,6 @@ } } - /* Private */ - Group.prototype.sort = function() { - this.waypoints.sort(function(a, b) { - return a.triggerPoint - b.triggerPoint - }) - } - /* Public */ Group.prototype.first = function() { return this.waypoints[0] From db4686ca9abef8d4d65415fa245407e41ace25c3 Mon Sep 17 00:00:00 2001 From: imakewebthings Date: Tue, 15 Jul 2014 16:04:28 -0700 Subject: [PATCH 31/98] Builds --- lib/jquery.waypoints.js | 11 ++--------- lib/jquery.waypoints.min.js | 2 +- lib/noframework.waypoints.js | 11 ++--------- lib/noframework.waypoints.min.js | 2 +- lib/zepto.waypoints.js | 11 ++--------- lib/zepto.waypoints.min.js | 2 +- 6 files changed, 9 insertions(+), 30 deletions(-) diff --git a/lib/jquery.waypoints.js b/lib/jquery.waypoints.js index 875df480..a281f292 100644 --- a/lib/jquery.waypoints.js +++ b/lib/jquery.waypoints.js @@ -476,7 +476,7 @@ https://github.com/imakewebthings/waypoints/blog/master/licenses.txt /* Private */ Group.prototype.next = function(waypoint) { - this.sort() + this.waypoints.sort(byTriggerPoint) var index = Waypoint.Adapter.inArray(waypoint, this.waypoints) var isLast = index === this.waypoints.length - 1 return isLast ? null : this.waypoints[index + 1] @@ -484,7 +484,7 @@ https://github.com/imakewebthings/waypoints/blog/master/licenses.txt /* Private */ Group.prototype.previous = function(waypoint) { - this.sort() + this.waypoints.sort(byTriggerPoint) var index = Waypoint.Adapter.inArray(waypoint, this.waypoints) return index ? this.waypoints[index - 1] : null } @@ -502,13 +502,6 @@ https://github.com/imakewebthings/waypoints/blog/master/licenses.txt } } - /* Private */ - Group.prototype.sort = function() { - this.waypoints.sort(function(a, b) { - return a.triggerPoint - b.triggerPoint - }) - } - /* Public */ Group.prototype.first = function() { return this.waypoints[0] diff --git a/lib/jquery.waypoints.min.js b/lib/jquery.waypoints.min.js index 5bb192f1..b4802339 100644 --- a/lib/jquery.waypoints.min.js +++ b/lib/jquery.waypoints.min.js @@ -4,4 +4,4 @@ Copyright © 2011-2014 Caleb Troughton Licensed under the MIT license. https://github.com/imakewebthings/waypoints/blog/master/licenses.txt */ -!function(){"use strict";function t(o){if(!o)throw new Error("No options passed to Waypoint constructor");if(!o.element)throw new Error("No element option passed to Waypoint constructor");this.key="waypoint-"+e,this.options=t.Adapter.extend({},t.defaults,o),this.element=this.options.element,this.adapter=new t.Adapter(this.element),this.callback=o.handler,this.axis=this.options.horizontal?"horizontal":"vertical",this.enabled=this.options.enabled,this.triggerPoint=null,this.group=t.Group.findOrCreate({name:this.options.group,axis:this.axis}),this.context=t.Context.findOrCreateByElement(this.options.context),t.offsetAliases[this.options.offset]&&(this.options.offset=t.offsetAliases[this.options.offset]),this.context.add(this),this.group.add(this),i[this.key]=this,e+=1}var e=0,i={};t.prototype.queueTrigger=function(t){this.group.queueTrigger(this,t)},t.prototype.trigger=function(t){this.enabled&&(this.callback&&this.callback.apply(this,t),this.options.triggerOnce&&this.destroy())},t.prototype.destroy=function(){this.context.remove(this),this.group.remove(this),delete i[this.key]},t.prototype.disable=function(){return this.enabled=!1,this},t.prototype.enable=function(){return this.context.refresh(),this.enabled=!0,this},t.prototype.next=function(){return this.group.next(this)},t.prototype.previous=function(){return this.group.previous(this)},t.destroyAll=function(){var t=[];for(var e in i)t.push(i[e]);for(var o=0,r=t.length;r>o;o++)t[o].destroy()},t.refreshAll=function(){t.Context.refreshAll()},t.viewportHeight=function(){return window.innerHeight||document.documentElement.clientHeight},t.viewportWidth=function(){return document.documentElement.clientWidth},t.adapters=[],t.defaults={context:window,continuous:!0,enabled:!0,group:"default",horizontal:!1,offset:0,triggerOnce:!1},t.offsetAliases={"bottom-in-view":function(){return this.context.height()-this.adapter.outerHeight()},"right-in-view":function(){return this.context.width()-this.adapter.outerWidth()}},window.Waypoint=t}()(function(){"use strict";function t(t){window.setTimeout(t,1e3/60)}function e(t){this.element=t,this.Adapter=r.Adapter,this.adapter=new this.Adapter(t),this.key="waypoint-context-"+i,this.didScroll=!1,this.didResize=!1,this.oldScroll={x:this.adapter.scrollLeft(),y:this.adapter.scrollTop()},this.waypoints={vertical:{},horizontal:{}},t.waypointContextKey=this.key,o[t.waypointContextKey]=this,i+=1,this.createThrottledScrollHandler(),this.createThrottledResizeHandler()}var i=0,o={},r=window.Waypoint,n=window.requestAnimationFrame||window.mozRequestAnimationFrame||window.webkitRequestAnimationFrame||t;e.prototype.add=function(t){var e=t.options.horizontal?"horizontal":"vertical";this.waypoints[e][t.key]=t,this.refresh()},e.prototype.checkEmpty=function(){var t=this.Adapter.isEmptyObject(this.waypoints.horizontal),e=this.Adapter.isEmptyObject(this.waypoints.vertical);t&&e&&(this.adapter.off(".waypoints"),delete o[this.key])},e.prototype.createThrottledResizeHandler=function(){function t(){e.handleResize(),e.didResize=!1}var e=this;this.adapter.on("resize.waypoints",function(){e.didResize||(e.didResize=!0,n(t))})},e.prototype.createThrottledScrollHandler=function(){function t(){e.handleScroll(),e.didScroll=!1}var e=this;this.adapter.on("scroll.waypoints",function(){(!e.didScroll||r.isTouch)&&(e.didScroll=!0,n(t))})},e.prototype.handleResize=function(){r.Context.refreshAll()},e.prototype.handleScroll=function(){var t={},e={horizontal:{newScroll:this.adapter.scrollLeft(),oldScroll:this.oldScroll.x,forward:"right",backward:"left"},vertical:{newScroll:this.adapter.scrollTop(),oldScroll:this.oldScroll.y,forward:"down",backward:"up"}};for(var i in e){var o=e[i],r=o.newScroll>o.oldScroll,n=r?o.forward:o.backward;for(var s in this.waypoints[i]){var a=this.waypoints[i][s],l=o.oldScroll=a.triggerPoint,p=l&&h,u=!l&&!h;(p||u)&&(a.queueTrigger(n),t[a.group.id]=a.group)}}for(var c in t)t[c].flushTriggers();this.oldScroll={x:e.horizontal.newScroll,y:e.vertical.newScroll}},e.prototype.height=function(){return this.element===this.element.window?r.viewportHeight():this.adapter.height()},e.prototype.remove=function(t){delete this.waypoints[t.axis][t.key],this.checkEmpty()},e.prototype.width=function(){return this.element===this.element.window?r.viewportWidth():this.adapter.width()},e.prototype.destroy=function(){var t=[];for(var e in this.waypoints)for(var i in this.waypoints[e])t.push(this.waypoints[e][i]);for(var o=0,r=t.length;r>o;o++)t[o].destroy()},e.prototype.refresh=function(){var t,e=this.element===this.element.window,i=this.adapter.offset(),o={};this.handleScroll(),t={horizontal:{contextOffset:e?0:i.left,contextScroll:e?0:this.oldScroll.x,contextDimension:this.width(),oldScroll:this.oldScroll.x,forward:"right",backward:"left",offsetProp:"left"},vertical:{contextOffset:e?0:i.top,contextScroll:e?0:this.oldScroll.y,contextDimension:this.height(),oldScroll:this.oldScroll.y,forward:"down",backward:"up",offsetProp:"top"}};for(var r in t){var n=t[r];for(var s in this.waypoints[r]){var a,l,h,p,u,c=this.waypoints[r][s],d=c.options.offset,f=c.triggerPoint,w=0,y=null==f;c.element!==c.element.window&&(w=c.adapter.offset()[n.offsetProp]),"function"==typeof d?d=d.apply(c):"string"==typeof d&&(d=parseFloat(d),c.options.offset.indexOf("%")>-1&&(d=Math.ceil(n.contextDimension*d/100))),a=n.contextScroll-n.contextOffset,c.triggerPoint=w+a-d,l=f=n.oldScroll,p=l&&h,u=!l&&!h,!y&&p?(c.queueTrigger(n.backward),o[c.group.id]=c.group):!y&&u?(c.queueTrigger(n.forward),o[c.group.id]=c.group):y&&n.oldScroll>=c.triggerPoint&&(c.queueTrigger(n.forward),o[c.group.id]=c.group)}}for(var g in o)o[g].flushTriggers();return this},e.findOrCreateByElement=function(t){return e.findByElement(t)||new e(t)},e.refreshAll=function(){for(var t in o)o[t].refresh()},e.findByElement=function(t){return o[t.waypointContextKey]},r.Context=e}())(function(){"use strict";function t(t,e){return t.triggerPoint-e.triggerPoint}function e(t,e){return e.triggerPoint-t.triggerPoint}function i(t){this.name=t.name,this.axis=t.axis,this.id=this.name+"-"+this.axis,this.waypoints=[],this.clearTriggerQueues(),o[this.axis][this.name]=this}var o={vertical:{},horizontal:{}},r=window.Waypoint;i.prototype.add=function(t){this.waypoints.push(t)},i.prototype.clearTriggerQueues=function(){this.triggerQueues={up:[],down:[],left:[],right:[]}},i.prototype.flushTriggers=function(){for(var i in this.triggerQueues){var o=this.triggerQueues[i],r="up"===i||"left"===i;o.sort(r?e:t);for(var n=0,s=o.length;s>n;n+=1){var a=o[n];(a.options.continuous||n===o.length-1)&&a.trigger([i])}}this.clearTriggerQueues()},i.prototype.next=function(t){this.sort();var e=r.Adapter.inArray(t,this.waypoints),i=e===this.waypoints.length-1;return i?null:this.waypoints[e+1]},i.prototype.previous=function(t){this.sort();var e=r.Adapter.inArray(t,this.waypoints);return e?this.waypoints[e-1]:null},i.prototype.queueTrigger=function(t,e){this.triggerQueues[e].push(t)},i.prototype.remove=function(t){var e=r.Adapter.inArray(t,this.waypoints);e>-1&&this.waypoints.splice(e,1)},i.prototype.sort=function(){this.waypoints.sort(function(t,e){return t.triggerPoint-e.triggerPoint})},i.prototype.first=function(){return this.waypoints[0]},i.prototype.last=function(){return this.waypoints[this.waypoints.length-1]},i.findOrCreate=function(t){return o[t.axis][t.name]||new i(t)},r.Group=i}())(function(){"use strict";function t(t){this.$element=e(t)}var e=window.jQuery,i=window.Waypoint;e.each(["height","off","offset","on","outerHeight","outerWidth","scrollLeft","scrollTop","width"],function(e,i){t.prototype[i]=function(){var t=Array.prototype.slice.call(arguments);return this.$element[i].apply(this.$element,t)}}),e.each(["extend","inArray","isEmptyObject"],function(i,o){t[o]=e[o]}),i.adapters.push({name:"jquery",Adapter:t}),i.Adapter=t}())(function(){"use strict";function t(t){return function(){var i=[],o=arguments[0];return t.isFunction(arguments[0])&&(o=t.extend({},arguments[1]),o.handler=arguments[0]),this.each(function(){var r=t.extend({},o,{element:this});"string"==typeof r.context&&(r.context=t(this).closest(r.context)[0]),i.push(new e(r))}),i}}var e=window.Waypoint;window.jQuery&&(window.jQuery.fn.waypoint=t(window.jQuery)),window.Zepto&&(window.Zepto.fn.waypoint=t(window.Zepto))}()); \ No newline at end of file +!function(){"use strict";function t(o){if(!o)throw new Error("No options passed to Waypoint constructor");if(!o.element)throw new Error("No element option passed to Waypoint constructor");this.key="waypoint-"+e,this.options=t.Adapter.extend({},t.defaults,o),this.element=this.options.element,this.adapter=new t.Adapter(this.element),this.callback=o.handler,this.axis=this.options.horizontal?"horizontal":"vertical",this.enabled=this.options.enabled,this.triggerPoint=null,this.group=t.Group.findOrCreate({name:this.options.group,axis:this.axis}),this.context=t.Context.findOrCreateByElement(this.options.context),t.offsetAliases[this.options.offset]&&(this.options.offset=t.offsetAliases[this.options.offset]),this.context.add(this),this.group.add(this),i[this.key]=this,e+=1}var e=0,i={};t.prototype.queueTrigger=function(t){this.group.queueTrigger(this,t)},t.prototype.trigger=function(t){this.enabled&&(this.callback&&this.callback.apply(this,t),this.options.triggerOnce&&this.destroy())},t.prototype.destroy=function(){this.context.remove(this),this.group.remove(this),delete i[this.key]},t.prototype.disable=function(){return this.enabled=!1,this},t.prototype.enable=function(){return this.context.refresh(),this.enabled=!0,this},t.prototype.next=function(){return this.group.next(this)},t.prototype.previous=function(){return this.group.previous(this)},t.destroyAll=function(){var t=[];for(var e in i)t.push(i[e]);for(var o=0,r=t.length;r>o;o++)t[o].destroy()},t.refreshAll=function(){t.Context.refreshAll()},t.viewportHeight=function(){return window.innerHeight||document.documentElement.clientHeight},t.viewportWidth=function(){return document.documentElement.clientWidth},t.adapters=[],t.defaults={context:window,continuous:!0,enabled:!0,group:"default",horizontal:!1,offset:0,triggerOnce:!1},t.offsetAliases={"bottom-in-view":function(){return this.context.height()-this.adapter.outerHeight()},"right-in-view":function(){return this.context.width()-this.adapter.outerWidth()}},window.Waypoint=t}()(function(){"use strict";function t(t){window.setTimeout(t,1e3/60)}function e(t){this.element=t,this.Adapter=r.Adapter,this.adapter=new this.Adapter(t),this.key="waypoint-context-"+i,this.didScroll=!1,this.didResize=!1,this.oldScroll={x:this.adapter.scrollLeft(),y:this.adapter.scrollTop()},this.waypoints={vertical:{},horizontal:{}},t.waypointContextKey=this.key,o[t.waypointContextKey]=this,i+=1,this.createThrottledScrollHandler(),this.createThrottledResizeHandler()}var i=0,o={},r=window.Waypoint,n=window.requestAnimationFrame||window.mozRequestAnimationFrame||window.webkitRequestAnimationFrame||t;e.prototype.add=function(t){var e=t.options.horizontal?"horizontal":"vertical";this.waypoints[e][t.key]=t,this.refresh()},e.prototype.checkEmpty=function(){var t=this.Adapter.isEmptyObject(this.waypoints.horizontal),e=this.Adapter.isEmptyObject(this.waypoints.vertical);t&&e&&(this.adapter.off(".waypoints"),delete o[this.key])},e.prototype.createThrottledResizeHandler=function(){function t(){e.handleResize(),e.didResize=!1}var e=this;this.adapter.on("resize.waypoints",function(){e.didResize||(e.didResize=!0,n(t))})},e.prototype.createThrottledScrollHandler=function(){function t(){e.handleScroll(),e.didScroll=!1}var e=this;this.adapter.on("scroll.waypoints",function(){(!e.didScroll||r.isTouch)&&(e.didScroll=!0,n(t))})},e.prototype.handleResize=function(){r.Context.refreshAll()},e.prototype.handleScroll=function(){var t={},e={horizontal:{newScroll:this.adapter.scrollLeft(),oldScroll:this.oldScroll.x,forward:"right",backward:"left"},vertical:{newScroll:this.adapter.scrollTop(),oldScroll:this.oldScroll.y,forward:"down",backward:"up"}};for(var i in e){var o=e[i],r=o.newScroll>o.oldScroll,n=r?o.forward:o.backward;for(var s in this.waypoints[i]){var a=this.waypoints[i][s],l=o.oldScroll=a.triggerPoint,p=l&&h,u=!l&&!h;(p||u)&&(a.queueTrigger(n),t[a.group.id]=a.group)}}for(var c in t)t[c].flushTriggers();this.oldScroll={x:e.horizontal.newScroll,y:e.vertical.newScroll}},e.prototype.height=function(){return this.element===this.element.window?r.viewportHeight():this.adapter.height()},e.prototype.remove=function(t){delete this.waypoints[t.axis][t.key],this.checkEmpty()},e.prototype.width=function(){return this.element===this.element.window?r.viewportWidth():this.adapter.width()},e.prototype.destroy=function(){var t=[];for(var e in this.waypoints)for(var i in this.waypoints[e])t.push(this.waypoints[e][i]);for(var o=0,r=t.length;r>o;o++)t[o].destroy()},e.prototype.refresh=function(){var t,e=this.element===this.element.window,i=this.adapter.offset(),o={};this.handleScroll(),t={horizontal:{contextOffset:e?0:i.left,contextScroll:e?0:this.oldScroll.x,contextDimension:this.width(),oldScroll:this.oldScroll.x,forward:"right",backward:"left",offsetProp:"left"},vertical:{contextOffset:e?0:i.top,contextScroll:e?0:this.oldScroll.y,contextDimension:this.height(),oldScroll:this.oldScroll.y,forward:"down",backward:"up",offsetProp:"top"}};for(var r in t){var n=t[r];for(var s in this.waypoints[r]){var a,l,h,p,u,c=this.waypoints[r][s],d=c.options.offset,f=c.triggerPoint,w=0,y=null==f;c.element!==c.element.window&&(w=c.adapter.offset()[n.offsetProp]),"function"==typeof d?d=d.apply(c):"string"==typeof d&&(d=parseFloat(d),c.options.offset.indexOf("%")>-1&&(d=Math.ceil(n.contextDimension*d/100))),a=n.contextScroll-n.contextOffset,c.triggerPoint=w+a-d,l=f=n.oldScroll,p=l&&h,u=!l&&!h,!y&&p?(c.queueTrigger(n.backward),o[c.group.id]=c.group):!y&&u?(c.queueTrigger(n.forward),o[c.group.id]=c.group):y&&n.oldScroll>=c.triggerPoint&&(c.queueTrigger(n.forward),o[c.group.id]=c.group)}}for(var g in o)o[g].flushTriggers();return this},e.findOrCreateByElement=function(t){return e.findByElement(t)||new e(t)},e.refreshAll=function(){for(var t in o)o[t].refresh()},e.findByElement=function(t){return o[t.waypointContextKey]},r.Context=e}())(function(){"use strict";function t(t,e){return t.triggerPoint-e.triggerPoint}function e(t,e){return e.triggerPoint-t.triggerPoint}function i(t){this.name=t.name,this.axis=t.axis,this.id=this.name+"-"+this.axis,this.waypoints=[],this.clearTriggerQueues(),o[this.axis][this.name]=this}var o={vertical:{},horizontal:{}},r=window.Waypoint;i.prototype.add=function(t){this.waypoints.push(t)},i.prototype.clearTriggerQueues=function(){this.triggerQueues={up:[],down:[],left:[],right:[]}},i.prototype.flushTriggers=function(){for(var i in this.triggerQueues){var o=this.triggerQueues[i],r="up"===i||"left"===i;o.sort(r?e:t);for(var n=0,s=o.length;s>n;n+=1){var a=o[n];(a.options.continuous||n===o.length-1)&&a.trigger([i])}}this.clearTriggerQueues()},i.prototype.next=function(e){this.waypoints.sort(t);var i=r.Adapter.inArray(e,this.waypoints),o=i===this.waypoints.length-1;return o?null:this.waypoints[i+1]},i.prototype.previous=function(e){this.waypoints.sort(t);var i=r.Adapter.inArray(e,this.waypoints);return i?this.waypoints[i-1]:null},i.prototype.queueTrigger=function(t,e){this.triggerQueues[e].push(t)},i.prototype.remove=function(t){var e=r.Adapter.inArray(t,this.waypoints);e>-1&&this.waypoints.splice(e,1)},i.prototype.first=function(){return this.waypoints[0]},i.prototype.last=function(){return this.waypoints[this.waypoints.length-1]},i.findOrCreate=function(t){return o[t.axis][t.name]||new i(t)},r.Group=i}())(function(){"use strict";function t(t){this.$element=e(t)}var e=window.jQuery,i=window.Waypoint;e.each(["height","off","offset","on","outerHeight","outerWidth","scrollLeft","scrollTop","width"],function(e,i){t.prototype[i]=function(){var t=Array.prototype.slice.call(arguments);return this.$element[i].apply(this.$element,t)}}),e.each(["extend","inArray","isEmptyObject"],function(i,o){t[o]=e[o]}),i.adapters.push({name:"jquery",Adapter:t}),i.Adapter=t}())(function(){"use strict";function t(t){return function(){var i=[],o=arguments[0];return t.isFunction(arguments[0])&&(o=t.extend({},arguments[1]),o.handler=arguments[0]),this.each(function(){var r=t.extend({},o,{element:this});"string"==typeof r.context&&(r.context=t(this).closest(r.context)[0]),i.push(new e(r))}),i}}var e=window.Waypoint;window.jQuery&&(window.jQuery.fn.waypoint=t(window.jQuery)),window.Zepto&&(window.Zepto.fn.waypoint=t(window.Zepto))}()); \ No newline at end of file diff --git a/lib/noframework.waypoints.js b/lib/noframework.waypoints.js index 4e28b739..0c89888d 100644 --- a/lib/noframework.waypoints.js +++ b/lib/noframework.waypoints.js @@ -476,7 +476,7 @@ https://github.com/imakewebthings/waypoints/blog/master/licenses.txt /* Private */ Group.prototype.next = function(waypoint) { - this.sort() + this.waypoints.sort(byTriggerPoint) var index = Waypoint.Adapter.inArray(waypoint, this.waypoints) var isLast = index === this.waypoints.length - 1 return isLast ? null : this.waypoints[index + 1] @@ -484,7 +484,7 @@ https://github.com/imakewebthings/waypoints/blog/master/licenses.txt /* Private */ Group.prototype.previous = function(waypoint) { - this.sort() + this.waypoints.sort(byTriggerPoint) var index = Waypoint.Adapter.inArray(waypoint, this.waypoints) return index ? this.waypoints[index - 1] : null } @@ -502,13 +502,6 @@ https://github.com/imakewebthings/waypoints/blog/master/licenses.txt } } - /* Private */ - Group.prototype.sort = function() { - this.waypoints.sort(function(a, b) { - return a.triggerPoint - b.triggerPoint - }) - } - /* Public */ Group.prototype.first = function() { return this.waypoints[0] diff --git a/lib/noframework.waypoints.min.js b/lib/noframework.waypoints.min.js index eeaac027..046e3a3e 100644 --- a/lib/noframework.waypoints.min.js +++ b/lib/noframework.waypoints.min.js @@ -4,4 +4,4 @@ Copyright © 2011-2014 Caleb Troughton Licensed under the MIT license. https://github.com/imakewebthings/waypoints/blog/master/licenses.txt */ -!function(){"use strict";function t(o){if(!o)throw new Error("No options passed to Waypoint constructor");if(!o.element)throw new Error("No element option passed to Waypoint constructor");this.key="waypoint-"+e,this.options=t.Adapter.extend({},t.defaults,o),this.element=this.options.element,this.adapter=new t.Adapter(this.element),this.callback=o.handler,this.axis=this.options.horizontal?"horizontal":"vertical",this.enabled=this.options.enabled,this.triggerPoint=null,this.group=t.Group.findOrCreate({name:this.options.group,axis:this.axis}),this.context=t.Context.findOrCreateByElement(this.options.context),t.offsetAliases[this.options.offset]&&(this.options.offset=t.offsetAliases[this.options.offset]),this.context.add(this),this.group.add(this),i[this.key]=this,e+=1}var e=0,i={};t.prototype.queueTrigger=function(t){this.group.queueTrigger(this,t)},t.prototype.trigger=function(t){this.enabled&&(this.callback&&this.callback.apply(this,t),this.options.triggerOnce&&this.destroy())},t.prototype.destroy=function(){this.context.remove(this),this.group.remove(this),delete i[this.key]},t.prototype.disable=function(){return this.enabled=!1,this},t.prototype.enable=function(){return this.context.refresh(),this.enabled=!0,this},t.prototype.next=function(){return this.group.next(this)},t.prototype.previous=function(){return this.group.previous(this)},t.destroyAll=function(){var t=[];for(var e in i)t.push(i[e]);for(var o=0,r=t.length;r>o;o++)t[o].destroy()},t.refreshAll=function(){t.Context.refreshAll()},t.viewportHeight=function(){return window.innerHeight||document.documentElement.clientHeight},t.viewportWidth=function(){return document.documentElement.clientWidth},t.adapters=[],t.defaults={context:window,continuous:!0,enabled:!0,group:"default",horizontal:!1,offset:0,triggerOnce:!1},t.offsetAliases={"bottom-in-view":function(){return this.context.height()-this.adapter.outerHeight()},"right-in-view":function(){return this.context.width()-this.adapter.outerWidth()}},window.Waypoint=t}()(function(){"use strict";function t(t){window.setTimeout(t,1e3/60)}function e(t){this.element=t,this.Adapter=r.Adapter,this.adapter=new this.Adapter(t),this.key="waypoint-context-"+i,this.didScroll=!1,this.didResize=!1,this.oldScroll={x:this.adapter.scrollLeft(),y:this.adapter.scrollTop()},this.waypoints={vertical:{},horizontal:{}},t.waypointContextKey=this.key,o[t.waypointContextKey]=this,i+=1,this.createThrottledScrollHandler(),this.createThrottledResizeHandler()}var i=0,o={},r=window.Waypoint,n=window.requestAnimationFrame||window.mozRequestAnimationFrame||window.webkitRequestAnimationFrame||t;e.prototype.add=function(t){var e=t.options.horizontal?"horizontal":"vertical";this.waypoints[e][t.key]=t,this.refresh()},e.prototype.checkEmpty=function(){var t=this.Adapter.isEmptyObject(this.waypoints.horizontal),e=this.Adapter.isEmptyObject(this.waypoints.vertical);t&&e&&(this.adapter.off(".waypoints"),delete o[this.key])},e.prototype.createThrottledResizeHandler=function(){function t(){e.handleResize(),e.didResize=!1}var e=this;this.adapter.on("resize.waypoints",function(){e.didResize||(e.didResize=!0,n(t))})},e.prototype.createThrottledScrollHandler=function(){function t(){e.handleScroll(),e.didScroll=!1}var e=this;this.adapter.on("scroll.waypoints",function(){(!e.didScroll||r.isTouch)&&(e.didScroll=!0,n(t))})},e.prototype.handleResize=function(){r.Context.refreshAll()},e.prototype.handleScroll=function(){var t={},e={horizontal:{newScroll:this.adapter.scrollLeft(),oldScroll:this.oldScroll.x,forward:"right",backward:"left"},vertical:{newScroll:this.adapter.scrollTop(),oldScroll:this.oldScroll.y,forward:"down",backward:"up"}};for(var i in e){var o=e[i],r=o.newScroll>o.oldScroll,n=r?o.forward:o.backward;for(var s in this.waypoints[i]){var a=this.waypoints[i][s],l=o.oldScroll=a.triggerPoint,p=l&&h,u=!l&&!h;(p||u)&&(a.queueTrigger(n),t[a.group.id]=a.group)}}for(var f in t)t[f].flushTriggers();this.oldScroll={x:e.horizontal.newScroll,y:e.vertical.newScroll}},e.prototype.height=function(){return this.element===this.element.window?r.viewportHeight():this.adapter.height()},e.prototype.remove=function(t){delete this.waypoints[t.axis][t.key],this.checkEmpty()},e.prototype.width=function(){return this.element===this.element.window?r.viewportWidth():this.adapter.width()},e.prototype.destroy=function(){var t=[];for(var e in this.waypoints)for(var i in this.waypoints[e])t.push(this.waypoints[e][i]);for(var o=0,r=t.length;r>o;o++)t[o].destroy()},e.prototype.refresh=function(){var t,e=this.element===this.element.window,i=this.adapter.offset(),o={};this.handleScroll(),t={horizontal:{contextOffset:e?0:i.left,contextScroll:e?0:this.oldScroll.x,contextDimension:this.width(),oldScroll:this.oldScroll.x,forward:"right",backward:"left",offsetProp:"left"},vertical:{contextOffset:e?0:i.top,contextScroll:e?0:this.oldScroll.y,contextDimension:this.height(),oldScroll:this.oldScroll.y,forward:"down",backward:"up",offsetProp:"top"}};for(var r in t){var n=t[r];for(var s in this.waypoints[r]){var a,l,h,p,u,f=this.waypoints[r][s],c=f.options.offset,d=f.triggerPoint,g=0,y=null==d;f.element!==f.element.window&&(g=f.adapter.offset()[n.offsetProp]),"function"==typeof c?c=c.apply(f):"string"==typeof c&&(c=parseFloat(c),f.options.offset.indexOf("%")>-1&&(c=Math.ceil(n.contextDimension*c/100))),a=n.contextScroll-n.contextOffset,f.triggerPoint=g+a-c,l=d=n.oldScroll,p=l&&h,u=!l&&!h,!y&&p?(f.queueTrigger(n.backward),o[f.group.id]=f.group):!y&&u?(f.queueTrigger(n.forward),o[f.group.id]=f.group):y&&n.oldScroll>=f.triggerPoint&&(f.queueTrigger(n.forward),o[f.group.id]=f.group)}}for(var w in o)o[w].flushTriggers();return this},e.findOrCreateByElement=function(t){return e.findByElement(t)||new e(t)},e.refreshAll=function(){for(var t in o)o[t].refresh()},e.findByElement=function(t){return o[t.waypointContextKey]},r.Context=e}())(function(){"use strict";function t(t,e){return t.triggerPoint-e.triggerPoint}function e(t,e){return e.triggerPoint-t.triggerPoint}function i(t){this.name=t.name,this.axis=t.axis,this.id=this.name+"-"+this.axis,this.waypoints=[],this.clearTriggerQueues(),o[this.axis][this.name]=this}var o={vertical:{},horizontal:{}},r=window.Waypoint;i.prototype.add=function(t){this.waypoints.push(t)},i.prototype.clearTriggerQueues=function(){this.triggerQueues={up:[],down:[],left:[],right:[]}},i.prototype.flushTriggers=function(){for(var i in this.triggerQueues){var o=this.triggerQueues[i],r="up"===i||"left"===i;o.sort(r?e:t);for(var n=0,s=o.length;s>n;n+=1){var a=o[n];(a.options.continuous||n===o.length-1)&&a.trigger([i])}}this.clearTriggerQueues()},i.prototype.next=function(t){this.sort();var e=r.Adapter.inArray(t,this.waypoints),i=e===this.waypoints.length-1;return i?null:this.waypoints[e+1]},i.prototype.previous=function(t){this.sort();var e=r.Adapter.inArray(t,this.waypoints);return e?this.waypoints[e-1]:null},i.prototype.queueTrigger=function(t,e){this.triggerQueues[e].push(t)},i.prototype.remove=function(t){var e=r.Adapter.inArray(t,this.waypoints);e>-1&&this.waypoints.splice(e,1)},i.prototype.sort=function(){this.waypoints.sort(function(t,e){return t.triggerPoint-e.triggerPoint})},i.prototype.first=function(){return this.waypoints[0]},i.prototype.last=function(){return this.waypoints[this.waypoints.length-1]},i.findOrCreate=function(t){return o[t.axis][t.name]||new i(t)},r.Group=i}())(function(){"use strict";function t(t){return t===t.window}function e(e){return t(e)?e:e.defaultView}function i(t){this.element=t,this.handlers={}}var o=window.Waypoint;i.prototype.height=function(){var e=t(this.element);return e?this.element.innerHeight:this.element.offsetHeight},i.prototype.off=function(t,e){function i(t,e,i){for(var o=0,r=e.length-1;r>o;o++){var n=e[o];i&&i!==n||t.removeEventListener(n)}}var o=t.split("."),r=o[0],n=o[1],s=this.element;if(n&&this.handlers[n]&&r)i(s,this.handlers[n][r],e),this.handlers[n][r]=[];else if(r)for(var a in this.handlers)i(s,this.handlers[a][r]||[],e),this.handlers[a][r]=[];else if(n&&this.handlers[n]){for(var l in this.handlers[n])i(s,this.handlers[n][l],e);this.handlers[n]={}}},i.prototype.offset=function(){if(!this.element.ownerDocument)return null;var t=this.element.ownerDocument.documentElement,i=e(this.element.ownerDocument),o={top:0,left:0};return this.element.getBoundingClientRect&&(o=this.element.getBoundingClientRect()),{top:o.top+i.pageYOffset-t.clientTop,left:o.left+i.pageXOffset-t.clientLeft}},i.prototype.on=function(t,e){var i=t.split("."),o=i[0],r=i[1]||"__default",n=this.handlers[r]=this.handlers[r]||{},s=n[o]=n[o]||[];s.push(e),this.element.addEventListener(o,e)},i.prototype.outerHeight=function(e){var i,o=this.height();return e&&!t(this.element)&&(i=window.getComputedStyle(this.element),o+=parseInt(i.marginTop,10),o+=parseInt(i.marginBottom,10)),o},i.prototype.outerWidth=function(e){var i,o=this.width();return e&&!t(this.element)&&(i=window.getComputedStyle(this.element),o+=parseInt(i.marginLeft,10),o+=parseInt(i.marginRight,10)),o},i.prototype.scrollLeft=function(){var t=e(this.element);return t?t.pageXOffset:this.element.scrollLeft},i.prototype.scrollTop=function(){var t=e(this.element);return t?t.pageYOffset:this.element.scrollTop},i.prototype.width=function(){var e=t(this.element);return e?this.element.innerWidth:this.element.offsetWidth},i.extend=function(){function t(t,e){if("object"==typeof t&&"object"==typeof e)for(var i in e)e.hasOwnProperty(i)&&(t[i]=e[i]);return t}for(var e=Array.prototype.slice.call(arguments),i=1,o=e.length;o>i;i++)t(e[0],e[i]);return e[0]},i.inArray=function(t,e,i){return null==e?-1:e.indexOf(t,i)},i.isEmptyObject=function(t){for(var e in t)return!1;return!0},o.adapters.push({name:"noframework",Adapter:i}),o.Adapter=i}()); \ No newline at end of file +!function(){"use strict";function t(o){if(!o)throw new Error("No options passed to Waypoint constructor");if(!o.element)throw new Error("No element option passed to Waypoint constructor");this.key="waypoint-"+e,this.options=t.Adapter.extend({},t.defaults,o),this.element=this.options.element,this.adapter=new t.Adapter(this.element),this.callback=o.handler,this.axis=this.options.horizontal?"horizontal":"vertical",this.enabled=this.options.enabled,this.triggerPoint=null,this.group=t.Group.findOrCreate({name:this.options.group,axis:this.axis}),this.context=t.Context.findOrCreateByElement(this.options.context),t.offsetAliases[this.options.offset]&&(this.options.offset=t.offsetAliases[this.options.offset]),this.context.add(this),this.group.add(this),i[this.key]=this,e+=1}var e=0,i={};t.prototype.queueTrigger=function(t){this.group.queueTrigger(this,t)},t.prototype.trigger=function(t){this.enabled&&(this.callback&&this.callback.apply(this,t),this.options.triggerOnce&&this.destroy())},t.prototype.destroy=function(){this.context.remove(this),this.group.remove(this),delete i[this.key]},t.prototype.disable=function(){return this.enabled=!1,this},t.prototype.enable=function(){return this.context.refresh(),this.enabled=!0,this},t.prototype.next=function(){return this.group.next(this)},t.prototype.previous=function(){return this.group.previous(this)},t.destroyAll=function(){var t=[];for(var e in i)t.push(i[e]);for(var o=0,r=t.length;r>o;o++)t[o].destroy()},t.refreshAll=function(){t.Context.refreshAll()},t.viewportHeight=function(){return window.innerHeight||document.documentElement.clientHeight},t.viewportWidth=function(){return document.documentElement.clientWidth},t.adapters=[],t.defaults={context:window,continuous:!0,enabled:!0,group:"default",horizontal:!1,offset:0,triggerOnce:!1},t.offsetAliases={"bottom-in-view":function(){return this.context.height()-this.adapter.outerHeight()},"right-in-view":function(){return this.context.width()-this.adapter.outerWidth()}},window.Waypoint=t}()(function(){"use strict";function t(t){window.setTimeout(t,1e3/60)}function e(t){this.element=t,this.Adapter=r.Adapter,this.adapter=new this.Adapter(t),this.key="waypoint-context-"+i,this.didScroll=!1,this.didResize=!1,this.oldScroll={x:this.adapter.scrollLeft(),y:this.adapter.scrollTop()},this.waypoints={vertical:{},horizontal:{}},t.waypointContextKey=this.key,o[t.waypointContextKey]=this,i+=1,this.createThrottledScrollHandler(),this.createThrottledResizeHandler()}var i=0,o={},r=window.Waypoint,n=window.requestAnimationFrame||window.mozRequestAnimationFrame||window.webkitRequestAnimationFrame||t;e.prototype.add=function(t){var e=t.options.horizontal?"horizontal":"vertical";this.waypoints[e][t.key]=t,this.refresh()},e.prototype.checkEmpty=function(){var t=this.Adapter.isEmptyObject(this.waypoints.horizontal),e=this.Adapter.isEmptyObject(this.waypoints.vertical);t&&e&&(this.adapter.off(".waypoints"),delete o[this.key])},e.prototype.createThrottledResizeHandler=function(){function t(){e.handleResize(),e.didResize=!1}var e=this;this.adapter.on("resize.waypoints",function(){e.didResize||(e.didResize=!0,n(t))})},e.prototype.createThrottledScrollHandler=function(){function t(){e.handleScroll(),e.didScroll=!1}var e=this;this.adapter.on("scroll.waypoints",function(){(!e.didScroll||r.isTouch)&&(e.didScroll=!0,n(t))})},e.prototype.handleResize=function(){r.Context.refreshAll()},e.prototype.handleScroll=function(){var t={},e={horizontal:{newScroll:this.adapter.scrollLeft(),oldScroll:this.oldScroll.x,forward:"right",backward:"left"},vertical:{newScroll:this.adapter.scrollTop(),oldScroll:this.oldScroll.y,forward:"down",backward:"up"}};for(var i in e){var o=e[i],r=o.newScroll>o.oldScroll,n=r?o.forward:o.backward;for(var s in this.waypoints[i]){var a=this.waypoints[i][s],l=o.oldScroll=a.triggerPoint,p=l&&h,u=!l&&!h;(p||u)&&(a.queueTrigger(n),t[a.group.id]=a.group)}}for(var f in t)t[f].flushTriggers();this.oldScroll={x:e.horizontal.newScroll,y:e.vertical.newScroll}},e.prototype.height=function(){return this.element===this.element.window?r.viewportHeight():this.adapter.height()},e.prototype.remove=function(t){delete this.waypoints[t.axis][t.key],this.checkEmpty()},e.prototype.width=function(){return this.element===this.element.window?r.viewportWidth():this.adapter.width()},e.prototype.destroy=function(){var t=[];for(var e in this.waypoints)for(var i in this.waypoints[e])t.push(this.waypoints[e][i]);for(var o=0,r=t.length;r>o;o++)t[o].destroy()},e.prototype.refresh=function(){var t,e=this.element===this.element.window,i=this.adapter.offset(),o={};this.handleScroll(),t={horizontal:{contextOffset:e?0:i.left,contextScroll:e?0:this.oldScroll.x,contextDimension:this.width(),oldScroll:this.oldScroll.x,forward:"right",backward:"left",offsetProp:"left"},vertical:{contextOffset:e?0:i.top,contextScroll:e?0:this.oldScroll.y,contextDimension:this.height(),oldScroll:this.oldScroll.y,forward:"down",backward:"up",offsetProp:"top"}};for(var r in t){var n=t[r];for(var s in this.waypoints[r]){var a,l,h,p,u,f=this.waypoints[r][s],c=f.options.offset,d=f.triggerPoint,g=0,y=null==d;f.element!==f.element.window&&(g=f.adapter.offset()[n.offsetProp]),"function"==typeof c?c=c.apply(f):"string"==typeof c&&(c=parseFloat(c),f.options.offset.indexOf("%")>-1&&(c=Math.ceil(n.contextDimension*c/100))),a=n.contextScroll-n.contextOffset,f.triggerPoint=g+a-c,l=d=n.oldScroll,p=l&&h,u=!l&&!h,!y&&p?(f.queueTrigger(n.backward),o[f.group.id]=f.group):!y&&u?(f.queueTrigger(n.forward),o[f.group.id]=f.group):y&&n.oldScroll>=f.triggerPoint&&(f.queueTrigger(n.forward),o[f.group.id]=f.group)}}for(var w in o)o[w].flushTriggers();return this},e.findOrCreateByElement=function(t){return e.findByElement(t)||new e(t)},e.refreshAll=function(){for(var t in o)o[t].refresh()},e.findByElement=function(t){return o[t.waypointContextKey]},r.Context=e}())(function(){"use strict";function t(t,e){return t.triggerPoint-e.triggerPoint}function e(t,e){return e.triggerPoint-t.triggerPoint}function i(t){this.name=t.name,this.axis=t.axis,this.id=this.name+"-"+this.axis,this.waypoints=[],this.clearTriggerQueues(),o[this.axis][this.name]=this}var o={vertical:{},horizontal:{}},r=window.Waypoint;i.prototype.add=function(t){this.waypoints.push(t)},i.prototype.clearTriggerQueues=function(){this.triggerQueues={up:[],down:[],left:[],right:[]}},i.prototype.flushTriggers=function(){for(var i in this.triggerQueues){var o=this.triggerQueues[i],r="up"===i||"left"===i;o.sort(r?e:t);for(var n=0,s=o.length;s>n;n+=1){var a=o[n];(a.options.continuous||n===o.length-1)&&a.trigger([i])}}this.clearTriggerQueues()},i.prototype.next=function(e){this.waypoints.sort(t);var i=r.Adapter.inArray(e,this.waypoints),o=i===this.waypoints.length-1;return o?null:this.waypoints[i+1]},i.prototype.previous=function(e){this.waypoints.sort(t);var i=r.Adapter.inArray(e,this.waypoints);return i?this.waypoints[i-1]:null},i.prototype.queueTrigger=function(t,e){this.triggerQueues[e].push(t)},i.prototype.remove=function(t){var e=r.Adapter.inArray(t,this.waypoints);e>-1&&this.waypoints.splice(e,1)},i.prototype.first=function(){return this.waypoints[0]},i.prototype.last=function(){return this.waypoints[this.waypoints.length-1]},i.findOrCreate=function(t){return o[t.axis][t.name]||new i(t)},r.Group=i}())(function(){"use strict";function t(t){return t===t.window}function e(e){return t(e)?e:e.defaultView}function i(t){this.element=t,this.handlers={}}var o=window.Waypoint;i.prototype.height=function(){var e=t(this.element);return e?this.element.innerHeight:this.element.offsetHeight},i.prototype.off=function(t,e){function i(t,e,i){for(var o=0,r=e.length-1;r>o;o++){var n=e[o];i&&i!==n||t.removeEventListener(n)}}var o=t.split("."),r=o[0],n=o[1],s=this.element;if(n&&this.handlers[n]&&r)i(s,this.handlers[n][r],e),this.handlers[n][r]=[];else if(r)for(var a in this.handlers)i(s,this.handlers[a][r]||[],e),this.handlers[a][r]=[];else if(n&&this.handlers[n]){for(var l in this.handlers[n])i(s,this.handlers[n][l],e);this.handlers[n]={}}},i.prototype.offset=function(){if(!this.element.ownerDocument)return null;var t=this.element.ownerDocument.documentElement,i=e(this.element.ownerDocument),o={top:0,left:0};return this.element.getBoundingClientRect&&(o=this.element.getBoundingClientRect()),{top:o.top+i.pageYOffset-t.clientTop,left:o.left+i.pageXOffset-t.clientLeft}},i.prototype.on=function(t,e){var i=t.split("."),o=i[0],r=i[1]||"__default",n=this.handlers[r]=this.handlers[r]||{},s=n[o]=n[o]||[];s.push(e),this.element.addEventListener(o,e)},i.prototype.outerHeight=function(e){var i,o=this.height();return e&&!t(this.element)&&(i=window.getComputedStyle(this.element),o+=parseInt(i.marginTop,10),o+=parseInt(i.marginBottom,10)),o},i.prototype.outerWidth=function(e){var i,o=this.width();return e&&!t(this.element)&&(i=window.getComputedStyle(this.element),o+=parseInt(i.marginLeft,10),o+=parseInt(i.marginRight,10)),o},i.prototype.scrollLeft=function(){var t=e(this.element);return t?t.pageXOffset:this.element.scrollLeft},i.prototype.scrollTop=function(){var t=e(this.element);return t?t.pageYOffset:this.element.scrollTop},i.prototype.width=function(){var e=t(this.element);return e?this.element.innerWidth:this.element.offsetWidth},i.extend=function(){function t(t,e){if("object"==typeof t&&"object"==typeof e)for(var i in e)e.hasOwnProperty(i)&&(t[i]=e[i]);return t}for(var e=Array.prototype.slice.call(arguments),i=1,o=e.length;o>i;i++)t(e[0],e[i]);return e[0]},i.inArray=function(t,e,i){return null==e?-1:e.indexOf(t,i)},i.isEmptyObject=function(t){for(var e in t)return!1;return!0},o.adapters.push({name:"noframework",Adapter:i}),o.Adapter=i}()); \ No newline at end of file diff --git a/lib/zepto.waypoints.js b/lib/zepto.waypoints.js index 01eed679..830ebb18 100644 --- a/lib/zepto.waypoints.js +++ b/lib/zepto.waypoints.js @@ -476,7 +476,7 @@ https://github.com/imakewebthings/waypoints/blog/master/licenses.txt /* Private */ Group.prototype.next = function(waypoint) { - this.sort() + this.waypoints.sort(byTriggerPoint) var index = Waypoint.Adapter.inArray(waypoint, this.waypoints) var isLast = index === this.waypoints.length - 1 return isLast ? null : this.waypoints[index + 1] @@ -484,7 +484,7 @@ https://github.com/imakewebthings/waypoints/blog/master/licenses.txt /* Private */ Group.prototype.previous = function(waypoint) { - this.sort() + this.waypoints.sort(byTriggerPoint) var index = Waypoint.Adapter.inArray(waypoint, this.waypoints) return index ? this.waypoints[index - 1] : null } @@ -502,13 +502,6 @@ https://github.com/imakewebthings/waypoints/blog/master/licenses.txt } } - /* Private */ - Group.prototype.sort = function() { - this.waypoints.sort(function(a, b) { - return a.triggerPoint - b.triggerPoint - }) - } - /* Public */ Group.prototype.first = function() { return this.waypoints[0] diff --git a/lib/zepto.waypoints.min.js b/lib/zepto.waypoints.min.js index 0e7895ae..4cb3856c 100644 --- a/lib/zepto.waypoints.min.js +++ b/lib/zepto.waypoints.min.js @@ -4,4 +4,4 @@ Copyright © 2011-2014 Caleb Troughton Licensed under the MIT license. https://github.com/imakewebthings/waypoints/blog/master/licenses.txt */ -!function(){"use strict";function t(o){if(!o)throw new Error("No options passed to Waypoint constructor");if(!o.element)throw new Error("No element option passed to Waypoint constructor");this.key="waypoint-"+e,this.options=t.Adapter.extend({},t.defaults,o),this.element=this.options.element,this.adapter=new t.Adapter(this.element),this.callback=o.handler,this.axis=this.options.horizontal?"horizontal":"vertical",this.enabled=this.options.enabled,this.triggerPoint=null,this.group=t.Group.findOrCreate({name:this.options.group,axis:this.axis}),this.context=t.Context.findOrCreateByElement(this.options.context),t.offsetAliases[this.options.offset]&&(this.options.offset=t.offsetAliases[this.options.offset]),this.context.add(this),this.group.add(this),i[this.key]=this,e+=1}var e=0,i={};t.prototype.queueTrigger=function(t){this.group.queueTrigger(this,t)},t.prototype.trigger=function(t){this.enabled&&(this.callback&&this.callback.apply(this,t),this.options.triggerOnce&&this.destroy())},t.prototype.destroy=function(){this.context.remove(this),this.group.remove(this),delete i[this.key]},t.prototype.disable=function(){return this.enabled=!1,this},t.prototype.enable=function(){return this.context.refresh(),this.enabled=!0,this},t.prototype.next=function(){return this.group.next(this)},t.prototype.previous=function(){return this.group.previous(this)},t.destroyAll=function(){var t=[];for(var e in i)t.push(i[e]);for(var o=0,r=t.length;r>o;o++)t[o].destroy()},t.refreshAll=function(){t.Context.refreshAll()},t.viewportHeight=function(){return window.innerHeight||document.documentElement.clientHeight},t.viewportWidth=function(){return document.documentElement.clientWidth},t.adapters=[],t.defaults={context:window,continuous:!0,enabled:!0,group:"default",horizontal:!1,offset:0,triggerOnce:!1},t.offsetAliases={"bottom-in-view":function(){return this.context.height()-this.adapter.outerHeight()},"right-in-view":function(){return this.context.width()-this.adapter.outerWidth()}},window.Waypoint=t}()(function(){"use strict";function t(t){window.setTimeout(t,1e3/60)}function e(t){this.element=t,this.Adapter=r.Adapter,this.adapter=new this.Adapter(t),this.key="waypoint-context-"+i,this.didScroll=!1,this.didResize=!1,this.oldScroll={x:this.adapter.scrollLeft(),y:this.adapter.scrollTop()},this.waypoints={vertical:{},horizontal:{}},t.waypointContextKey=this.key,o[t.waypointContextKey]=this,i+=1,this.createThrottledScrollHandler(),this.createThrottledResizeHandler()}var i=0,o={},r=window.Waypoint,n=window.requestAnimationFrame||window.mozRequestAnimationFrame||window.webkitRequestAnimationFrame||t;e.prototype.add=function(t){var e=t.options.horizontal?"horizontal":"vertical";this.waypoints[e][t.key]=t,this.refresh()},e.prototype.checkEmpty=function(){var t=this.Adapter.isEmptyObject(this.waypoints.horizontal),e=this.Adapter.isEmptyObject(this.waypoints.vertical);t&&e&&(this.adapter.off(".waypoints"),delete o[this.key])},e.prototype.createThrottledResizeHandler=function(){function t(){e.handleResize(),e.didResize=!1}var e=this;this.adapter.on("resize.waypoints",function(){e.didResize||(e.didResize=!0,n(t))})},e.prototype.createThrottledScrollHandler=function(){function t(){e.handleScroll(),e.didScroll=!1}var e=this;this.adapter.on("scroll.waypoints",function(){(!e.didScroll||r.isTouch)&&(e.didScroll=!0,n(t))})},e.prototype.handleResize=function(){r.Context.refreshAll()},e.prototype.handleScroll=function(){var t={},e={horizontal:{newScroll:this.adapter.scrollLeft(),oldScroll:this.oldScroll.x,forward:"right",backward:"left"},vertical:{newScroll:this.adapter.scrollTop(),oldScroll:this.oldScroll.y,forward:"down",backward:"up"}};for(var i in e){var o=e[i],r=o.newScroll>o.oldScroll,n=r?o.forward:o.backward;for(var s in this.waypoints[i]){var a=this.waypoints[i][s],h=o.oldScroll=a.triggerPoint,p=h&&l,c=!h&&!l;(p||c)&&(a.queueTrigger(n),t[a.group.id]=a.group)}}for(var u in t)t[u].flushTriggers();this.oldScroll={x:e.horizontal.newScroll,y:e.vertical.newScroll}},e.prototype.height=function(){return this.element===this.element.window?r.viewportHeight():this.adapter.height()},e.prototype.remove=function(t){delete this.waypoints[t.axis][t.key],this.checkEmpty()},e.prototype.width=function(){return this.element===this.element.window?r.viewportWidth():this.adapter.width()},e.prototype.destroy=function(){var t=[];for(var e in this.waypoints)for(var i in this.waypoints[e])t.push(this.waypoints[e][i]);for(var o=0,r=t.length;r>o;o++)t[o].destroy()},e.prototype.refresh=function(){var t,e=this.element===this.element.window,i=this.adapter.offset(),o={};this.handleScroll(),t={horizontal:{contextOffset:e?0:i.left,contextScroll:e?0:this.oldScroll.x,contextDimension:this.width(),oldScroll:this.oldScroll.x,forward:"right",backward:"left",offsetProp:"left"},vertical:{contextOffset:e?0:i.top,contextScroll:e?0:this.oldScroll.y,contextDimension:this.height(),oldScroll:this.oldScroll.y,forward:"down",backward:"up",offsetProp:"top"}};for(var r in t){var n=t[r];for(var s in this.waypoints[r]){var a,h,l,p,c,u=this.waypoints[r][s],d=u.options.offset,f=u.triggerPoint,w=0,y=null==f;u.element!==u.element.window&&(w=u.adapter.offset()[n.offsetProp]),"function"==typeof d?d=d.apply(u):"string"==typeof d&&(d=parseFloat(d),u.options.offset.indexOf("%")>-1&&(d=Math.ceil(n.contextDimension*d/100))),a=n.contextScroll-n.contextOffset,u.triggerPoint=w+a-d,h=f=n.oldScroll,p=h&&l,c=!h&&!l,!y&&p?(u.queueTrigger(n.backward),o[u.group.id]=u.group):!y&&c?(u.queueTrigger(n.forward),o[u.group.id]=u.group):y&&n.oldScroll>=u.triggerPoint&&(u.queueTrigger(n.forward),o[u.group.id]=u.group)}}for(var g in o)o[g].flushTriggers();return this},e.findOrCreateByElement=function(t){return e.findByElement(t)||new e(t)},e.refreshAll=function(){for(var t in o)o[t].refresh()},e.findByElement=function(t){return o[t.waypointContextKey]},r.Context=e}())(function(){"use strict";function t(t,e){return t.triggerPoint-e.triggerPoint}function e(t,e){return e.triggerPoint-t.triggerPoint}function i(t){this.name=t.name,this.axis=t.axis,this.id=this.name+"-"+this.axis,this.waypoints=[],this.clearTriggerQueues(),o[this.axis][this.name]=this}var o={vertical:{},horizontal:{}},r=window.Waypoint;i.prototype.add=function(t){this.waypoints.push(t)},i.prototype.clearTriggerQueues=function(){this.triggerQueues={up:[],down:[],left:[],right:[]}},i.prototype.flushTriggers=function(){for(var i in this.triggerQueues){var o=this.triggerQueues[i],r="up"===i||"left"===i;o.sort(r?e:t);for(var n=0,s=o.length;s>n;n+=1){var a=o[n];(a.options.continuous||n===o.length-1)&&a.trigger([i])}}this.clearTriggerQueues()},i.prototype.next=function(t){this.sort();var e=r.Adapter.inArray(t,this.waypoints),i=e===this.waypoints.length-1;return i?null:this.waypoints[e+1]},i.prototype.previous=function(t){this.sort();var e=r.Adapter.inArray(t,this.waypoints);return e?this.waypoints[e-1]:null},i.prototype.queueTrigger=function(t,e){this.triggerQueues[e].push(t)},i.prototype.remove=function(t){var e=r.Adapter.inArray(t,this.waypoints);e>-1&&this.waypoints.splice(e,1)},i.prototype.sort=function(){this.waypoints.sort(function(t,e){return t.triggerPoint-e.triggerPoint})},i.prototype.first=function(){return this.waypoints[0]},i.prototype.last=function(){return this.waypoints[this.waypoints.length-1]},i.findOrCreate=function(t){return o[t.axis][t.name]||new i(t)},r.Group=i}())(function(){"use strict";function t(t){this.element=t,this.$element=e(t)}var e=window.Zepto,i=window.Waypoint;e.each(["height","off","on","scrollLeft","scrollTop","width"],function(e,i){t.prototype[i]=function(){var t=Array.prototype.slice.call(arguments);return this.$element[i].apply(this.$element,t)}}),t.prototype.offset=function(){return this.element!==this.element.window?this.$element.offset():void 0},e.each(["width","height"],function(i,o){var r=e.camelCase("outer-"+o);t.prototype[r]=function(t){var i=this.$element[o](),r={width:["left","right"],height:["top","bottom"]};return t&&e.each(r[o],e.proxy(function(t,e){i+=parseInt(this.$element.css("margin-"+e),10)},this)),i}}),e.each(["extend","inArray"],function(i,o){t[o]=e[o]}),t.isEmptyObject=function(t){for(var e in t)return!1;return!0},i.adapters.push({name:"zepto",Adapter:t}),i.Adapter=t}())(function(){"use strict";function t(t){return function(){var i=[],o=arguments[0];return t.isFunction(arguments[0])&&(o=t.extend({},arguments[1]),o.handler=arguments[0]),this.each(function(){var r=t.extend({},o,{element:this});"string"==typeof r.context&&(r.context=t(this).closest(r.context)[0]),i.push(new e(r))}),i}}var e=window.Waypoint;window.jQuery&&(window.jQuery.fn.waypoint=t(window.jQuery)),window.Zepto&&(window.Zepto.fn.waypoint=t(window.Zepto))}()); \ No newline at end of file +!function(){"use strict";function t(o){if(!o)throw new Error("No options passed to Waypoint constructor");if(!o.element)throw new Error("No element option passed to Waypoint constructor");this.key="waypoint-"+e,this.options=t.Adapter.extend({},t.defaults,o),this.element=this.options.element,this.adapter=new t.Adapter(this.element),this.callback=o.handler,this.axis=this.options.horizontal?"horizontal":"vertical",this.enabled=this.options.enabled,this.triggerPoint=null,this.group=t.Group.findOrCreate({name:this.options.group,axis:this.axis}),this.context=t.Context.findOrCreateByElement(this.options.context),t.offsetAliases[this.options.offset]&&(this.options.offset=t.offsetAliases[this.options.offset]),this.context.add(this),this.group.add(this),i[this.key]=this,e+=1}var e=0,i={};t.prototype.queueTrigger=function(t){this.group.queueTrigger(this,t)},t.prototype.trigger=function(t){this.enabled&&(this.callback&&this.callback.apply(this,t),this.options.triggerOnce&&this.destroy())},t.prototype.destroy=function(){this.context.remove(this),this.group.remove(this),delete i[this.key]},t.prototype.disable=function(){return this.enabled=!1,this},t.prototype.enable=function(){return this.context.refresh(),this.enabled=!0,this},t.prototype.next=function(){return this.group.next(this)},t.prototype.previous=function(){return this.group.previous(this)},t.destroyAll=function(){var t=[];for(var e in i)t.push(i[e]);for(var o=0,r=t.length;r>o;o++)t[o].destroy()},t.refreshAll=function(){t.Context.refreshAll()},t.viewportHeight=function(){return window.innerHeight||document.documentElement.clientHeight},t.viewportWidth=function(){return document.documentElement.clientWidth},t.adapters=[],t.defaults={context:window,continuous:!0,enabled:!0,group:"default",horizontal:!1,offset:0,triggerOnce:!1},t.offsetAliases={"bottom-in-view":function(){return this.context.height()-this.adapter.outerHeight()},"right-in-view":function(){return this.context.width()-this.adapter.outerWidth()}},window.Waypoint=t}()(function(){"use strict";function t(t){window.setTimeout(t,1e3/60)}function e(t){this.element=t,this.Adapter=r.Adapter,this.adapter=new this.Adapter(t),this.key="waypoint-context-"+i,this.didScroll=!1,this.didResize=!1,this.oldScroll={x:this.adapter.scrollLeft(),y:this.adapter.scrollTop()},this.waypoints={vertical:{},horizontal:{}},t.waypointContextKey=this.key,o[t.waypointContextKey]=this,i+=1,this.createThrottledScrollHandler(),this.createThrottledResizeHandler()}var i=0,o={},r=window.Waypoint,n=window.requestAnimationFrame||window.mozRequestAnimationFrame||window.webkitRequestAnimationFrame||t;e.prototype.add=function(t){var e=t.options.horizontal?"horizontal":"vertical";this.waypoints[e][t.key]=t,this.refresh()},e.prototype.checkEmpty=function(){var t=this.Adapter.isEmptyObject(this.waypoints.horizontal),e=this.Adapter.isEmptyObject(this.waypoints.vertical);t&&e&&(this.adapter.off(".waypoints"),delete o[this.key])},e.prototype.createThrottledResizeHandler=function(){function t(){e.handleResize(),e.didResize=!1}var e=this;this.adapter.on("resize.waypoints",function(){e.didResize||(e.didResize=!0,n(t))})},e.prototype.createThrottledScrollHandler=function(){function t(){e.handleScroll(),e.didScroll=!1}var e=this;this.adapter.on("scroll.waypoints",function(){(!e.didScroll||r.isTouch)&&(e.didScroll=!0,n(t))})},e.prototype.handleResize=function(){r.Context.refreshAll()},e.prototype.handleScroll=function(){var t={},e={horizontal:{newScroll:this.adapter.scrollLeft(),oldScroll:this.oldScroll.x,forward:"right",backward:"left"},vertical:{newScroll:this.adapter.scrollTop(),oldScroll:this.oldScroll.y,forward:"down",backward:"up"}};for(var i in e){var o=e[i],r=o.newScroll>o.oldScroll,n=r?o.forward:o.backward;for(var s in this.waypoints[i]){var a=this.waypoints[i][s],h=o.oldScroll=a.triggerPoint,p=h&&l,c=!h&&!l;(p||c)&&(a.queueTrigger(n),t[a.group.id]=a.group)}}for(var u in t)t[u].flushTriggers();this.oldScroll={x:e.horizontal.newScroll,y:e.vertical.newScroll}},e.prototype.height=function(){return this.element===this.element.window?r.viewportHeight():this.adapter.height()},e.prototype.remove=function(t){delete this.waypoints[t.axis][t.key],this.checkEmpty()},e.prototype.width=function(){return this.element===this.element.window?r.viewportWidth():this.adapter.width()},e.prototype.destroy=function(){var t=[];for(var e in this.waypoints)for(var i in this.waypoints[e])t.push(this.waypoints[e][i]);for(var o=0,r=t.length;r>o;o++)t[o].destroy()},e.prototype.refresh=function(){var t,e=this.element===this.element.window,i=this.adapter.offset(),o={};this.handleScroll(),t={horizontal:{contextOffset:e?0:i.left,contextScroll:e?0:this.oldScroll.x,contextDimension:this.width(),oldScroll:this.oldScroll.x,forward:"right",backward:"left",offsetProp:"left"},vertical:{contextOffset:e?0:i.top,contextScroll:e?0:this.oldScroll.y,contextDimension:this.height(),oldScroll:this.oldScroll.y,forward:"down",backward:"up",offsetProp:"top"}};for(var r in t){var n=t[r];for(var s in this.waypoints[r]){var a,h,l,p,c,u=this.waypoints[r][s],d=u.options.offset,f=u.triggerPoint,w=0,y=null==f;u.element!==u.element.window&&(w=u.adapter.offset()[n.offsetProp]),"function"==typeof d?d=d.apply(u):"string"==typeof d&&(d=parseFloat(d),u.options.offset.indexOf("%")>-1&&(d=Math.ceil(n.contextDimension*d/100))),a=n.contextScroll-n.contextOffset,u.triggerPoint=w+a-d,h=f=n.oldScroll,p=h&&l,c=!h&&!l,!y&&p?(u.queueTrigger(n.backward),o[u.group.id]=u.group):!y&&c?(u.queueTrigger(n.forward),o[u.group.id]=u.group):y&&n.oldScroll>=u.triggerPoint&&(u.queueTrigger(n.forward),o[u.group.id]=u.group)}}for(var g in o)o[g].flushTriggers();return this},e.findOrCreateByElement=function(t){return e.findByElement(t)||new e(t)},e.refreshAll=function(){for(var t in o)o[t].refresh()},e.findByElement=function(t){return o[t.waypointContextKey]},r.Context=e}())(function(){"use strict";function t(t,e){return t.triggerPoint-e.triggerPoint}function e(t,e){return e.triggerPoint-t.triggerPoint}function i(t){this.name=t.name,this.axis=t.axis,this.id=this.name+"-"+this.axis,this.waypoints=[],this.clearTriggerQueues(),o[this.axis][this.name]=this}var o={vertical:{},horizontal:{}},r=window.Waypoint;i.prototype.add=function(t){this.waypoints.push(t)},i.prototype.clearTriggerQueues=function(){this.triggerQueues={up:[],down:[],left:[],right:[]}},i.prototype.flushTriggers=function(){for(var i in this.triggerQueues){var o=this.triggerQueues[i],r="up"===i||"left"===i;o.sort(r?e:t);for(var n=0,s=o.length;s>n;n+=1){var a=o[n];(a.options.continuous||n===o.length-1)&&a.trigger([i])}}this.clearTriggerQueues()},i.prototype.next=function(e){this.waypoints.sort(t);var i=r.Adapter.inArray(e,this.waypoints),o=i===this.waypoints.length-1;return o?null:this.waypoints[i+1]},i.prototype.previous=function(e){this.waypoints.sort(t);var i=r.Adapter.inArray(e,this.waypoints);return i?this.waypoints[i-1]:null},i.prototype.queueTrigger=function(t,e){this.triggerQueues[e].push(t)},i.prototype.remove=function(t){var e=r.Adapter.inArray(t,this.waypoints);e>-1&&this.waypoints.splice(e,1)},i.prototype.first=function(){return this.waypoints[0]},i.prototype.last=function(){return this.waypoints[this.waypoints.length-1]},i.findOrCreate=function(t){return o[t.axis][t.name]||new i(t)},r.Group=i}())(function(){"use strict";function t(t){this.element=t,this.$element=e(t)}var e=window.Zepto,i=window.Waypoint;e.each(["height","off","on","scrollLeft","scrollTop","width"],function(e,i){t.prototype[i]=function(){var t=Array.prototype.slice.call(arguments);return this.$element[i].apply(this.$element,t)}}),t.prototype.offset=function(){return this.element!==this.element.window?this.$element.offset():void 0},e.each(["width","height"],function(i,o){var r=e.camelCase("outer-"+o);t.prototype[r]=function(t){var i=this.$element[o](),r={width:["left","right"],height:["top","bottom"]};return t&&e.each(r[o],e.proxy(function(t,e){i+=parseInt(this.$element.css("margin-"+e),10)},this)),i}}),e.each(["extend","inArray"],function(i,o){t[o]=e[o]}),t.isEmptyObject=function(t){for(var e in t)return!1;return!0},i.adapters.push({name:"zepto",Adapter:t}),i.Adapter=t}())(function(){"use strict";function t(t){return function(){var i=[],o=arguments[0];return t.isFunction(arguments[0])&&(o=t.extend({},arguments[1]),o.handler=arguments[0]),this.each(function(){var r=t.extend({},o,{element:this});"string"==typeof r.context&&(r.context=t(this).closest(r.context)[0]),i.push(new e(r))}),i}}var e=window.Waypoint;window.jQuery&&(window.jQuery.fn.waypoint=t(window.jQuery)),window.Zepto&&(window.Zepto.fn.waypoint=t(window.Zepto))}()); \ No newline at end of file From 922fa1a5b4435e8aba032fadbe009a2647b32239 Mon Sep 17 00:00:00 2001 From: imakewebthings Date: Thu, 7 Aug 2014 17:36:06 -0700 Subject: [PATCH 32/98] Build concats need semicolons separating iifes --- gulpfile.js | 2 +- lib/jquery.waypoints.js | 12 ++++-------- lib/jquery.waypoints.min.js | 2 +- lib/noframework.waypoints.js | 9 +++------ lib/noframework.waypoints.min.js | 2 +- lib/zepto.waypoints.js | 12 ++++-------- lib/zepto.waypoints.min.js | 2 +- 7 files changed, 15 insertions(+), 26 deletions(-) diff --git a/gulpfile.js b/gulpfile.js index 8fdf99f5..4cc82829 100644 --- a/gulpfile.js +++ b/gulpfile.js @@ -43,7 +43,7 @@ gulp.task('build-core', function() { sources.push('src/adapters/jquery-zepto-fn-extension.js') } return gulp.src(sources) - .pipe(concat(adapter + '.waypoints.js')) + .pipe(concat(adapter + '.waypoints.js', { newLine: ';' })) .pipe(header(fileHeader('Waypoints'))) .pipe(gulp.dest('lib/')) .pipe(rename(adapter + '.waypoints.min.js')) diff --git a/lib/jquery.waypoints.js b/lib/jquery.waypoints.js index a281f292..6ee3ccf8 100644 --- a/lib/jquery.waypoints.js +++ b/lib/jquery.waypoints.js @@ -138,8 +138,7 @@ https://github.com/imakewebthings/waypoints/blog/master/licenses.txt window.Waypoint = Waypoint }()) - -(function() { +;(function() { 'use strict' function requestAnimationFrameShim(callback) { @@ -416,8 +415,7 @@ https://github.com/imakewebthings/waypoints/blog/master/licenses.txt Waypoint.Context = Context }()) - -(function() { +;(function() { 'use strict' function byTriggerPoint(a, b) { @@ -519,8 +517,7 @@ https://github.com/imakewebthings/waypoints/blog/master/licenses.txt Waypoint.Group = Group }()) - -(function() { +;(function() { 'use strict' var $ = window.jQuery @@ -561,8 +558,7 @@ https://github.com/imakewebthings/waypoints/blog/master/licenses.txt }) Waypoint.Adapter = JQueryAdapter }()) - -(function() { +;(function() { 'use strict' var Waypoint = window.Waypoint diff --git a/lib/jquery.waypoints.min.js b/lib/jquery.waypoints.min.js index b4802339..74f3d682 100644 --- a/lib/jquery.waypoints.min.js +++ b/lib/jquery.waypoints.min.js @@ -4,4 +4,4 @@ Copyright © 2011-2014 Caleb Troughton Licensed under the MIT license. https://github.com/imakewebthings/waypoints/blog/master/licenses.txt */ -!function(){"use strict";function t(o){if(!o)throw new Error("No options passed to Waypoint constructor");if(!o.element)throw new Error("No element option passed to Waypoint constructor");this.key="waypoint-"+e,this.options=t.Adapter.extend({},t.defaults,o),this.element=this.options.element,this.adapter=new t.Adapter(this.element),this.callback=o.handler,this.axis=this.options.horizontal?"horizontal":"vertical",this.enabled=this.options.enabled,this.triggerPoint=null,this.group=t.Group.findOrCreate({name:this.options.group,axis:this.axis}),this.context=t.Context.findOrCreateByElement(this.options.context),t.offsetAliases[this.options.offset]&&(this.options.offset=t.offsetAliases[this.options.offset]),this.context.add(this),this.group.add(this),i[this.key]=this,e+=1}var e=0,i={};t.prototype.queueTrigger=function(t){this.group.queueTrigger(this,t)},t.prototype.trigger=function(t){this.enabled&&(this.callback&&this.callback.apply(this,t),this.options.triggerOnce&&this.destroy())},t.prototype.destroy=function(){this.context.remove(this),this.group.remove(this),delete i[this.key]},t.prototype.disable=function(){return this.enabled=!1,this},t.prototype.enable=function(){return this.context.refresh(),this.enabled=!0,this},t.prototype.next=function(){return this.group.next(this)},t.prototype.previous=function(){return this.group.previous(this)},t.destroyAll=function(){var t=[];for(var e in i)t.push(i[e]);for(var o=0,r=t.length;r>o;o++)t[o].destroy()},t.refreshAll=function(){t.Context.refreshAll()},t.viewportHeight=function(){return window.innerHeight||document.documentElement.clientHeight},t.viewportWidth=function(){return document.documentElement.clientWidth},t.adapters=[],t.defaults={context:window,continuous:!0,enabled:!0,group:"default",horizontal:!1,offset:0,triggerOnce:!1},t.offsetAliases={"bottom-in-view":function(){return this.context.height()-this.adapter.outerHeight()},"right-in-view":function(){return this.context.width()-this.adapter.outerWidth()}},window.Waypoint=t}()(function(){"use strict";function t(t){window.setTimeout(t,1e3/60)}function e(t){this.element=t,this.Adapter=r.Adapter,this.adapter=new this.Adapter(t),this.key="waypoint-context-"+i,this.didScroll=!1,this.didResize=!1,this.oldScroll={x:this.adapter.scrollLeft(),y:this.adapter.scrollTop()},this.waypoints={vertical:{},horizontal:{}},t.waypointContextKey=this.key,o[t.waypointContextKey]=this,i+=1,this.createThrottledScrollHandler(),this.createThrottledResizeHandler()}var i=0,o={},r=window.Waypoint,n=window.requestAnimationFrame||window.mozRequestAnimationFrame||window.webkitRequestAnimationFrame||t;e.prototype.add=function(t){var e=t.options.horizontal?"horizontal":"vertical";this.waypoints[e][t.key]=t,this.refresh()},e.prototype.checkEmpty=function(){var t=this.Adapter.isEmptyObject(this.waypoints.horizontal),e=this.Adapter.isEmptyObject(this.waypoints.vertical);t&&e&&(this.adapter.off(".waypoints"),delete o[this.key])},e.prototype.createThrottledResizeHandler=function(){function t(){e.handleResize(),e.didResize=!1}var e=this;this.adapter.on("resize.waypoints",function(){e.didResize||(e.didResize=!0,n(t))})},e.prototype.createThrottledScrollHandler=function(){function t(){e.handleScroll(),e.didScroll=!1}var e=this;this.adapter.on("scroll.waypoints",function(){(!e.didScroll||r.isTouch)&&(e.didScroll=!0,n(t))})},e.prototype.handleResize=function(){r.Context.refreshAll()},e.prototype.handleScroll=function(){var t={},e={horizontal:{newScroll:this.adapter.scrollLeft(),oldScroll:this.oldScroll.x,forward:"right",backward:"left"},vertical:{newScroll:this.adapter.scrollTop(),oldScroll:this.oldScroll.y,forward:"down",backward:"up"}};for(var i in e){var o=e[i],r=o.newScroll>o.oldScroll,n=r?o.forward:o.backward;for(var s in this.waypoints[i]){var a=this.waypoints[i][s],l=o.oldScroll=a.triggerPoint,p=l&&h,u=!l&&!h;(p||u)&&(a.queueTrigger(n),t[a.group.id]=a.group)}}for(var c in t)t[c].flushTriggers();this.oldScroll={x:e.horizontal.newScroll,y:e.vertical.newScroll}},e.prototype.height=function(){return this.element===this.element.window?r.viewportHeight():this.adapter.height()},e.prototype.remove=function(t){delete this.waypoints[t.axis][t.key],this.checkEmpty()},e.prototype.width=function(){return this.element===this.element.window?r.viewportWidth():this.adapter.width()},e.prototype.destroy=function(){var t=[];for(var e in this.waypoints)for(var i in this.waypoints[e])t.push(this.waypoints[e][i]);for(var o=0,r=t.length;r>o;o++)t[o].destroy()},e.prototype.refresh=function(){var t,e=this.element===this.element.window,i=this.adapter.offset(),o={};this.handleScroll(),t={horizontal:{contextOffset:e?0:i.left,contextScroll:e?0:this.oldScroll.x,contextDimension:this.width(),oldScroll:this.oldScroll.x,forward:"right",backward:"left",offsetProp:"left"},vertical:{contextOffset:e?0:i.top,contextScroll:e?0:this.oldScroll.y,contextDimension:this.height(),oldScroll:this.oldScroll.y,forward:"down",backward:"up",offsetProp:"top"}};for(var r in t){var n=t[r];for(var s in this.waypoints[r]){var a,l,h,p,u,c=this.waypoints[r][s],d=c.options.offset,f=c.triggerPoint,w=0,y=null==f;c.element!==c.element.window&&(w=c.adapter.offset()[n.offsetProp]),"function"==typeof d?d=d.apply(c):"string"==typeof d&&(d=parseFloat(d),c.options.offset.indexOf("%")>-1&&(d=Math.ceil(n.contextDimension*d/100))),a=n.contextScroll-n.contextOffset,c.triggerPoint=w+a-d,l=f=n.oldScroll,p=l&&h,u=!l&&!h,!y&&p?(c.queueTrigger(n.backward),o[c.group.id]=c.group):!y&&u?(c.queueTrigger(n.forward),o[c.group.id]=c.group):y&&n.oldScroll>=c.triggerPoint&&(c.queueTrigger(n.forward),o[c.group.id]=c.group)}}for(var g in o)o[g].flushTriggers();return this},e.findOrCreateByElement=function(t){return e.findByElement(t)||new e(t)},e.refreshAll=function(){for(var t in o)o[t].refresh()},e.findByElement=function(t){return o[t.waypointContextKey]},r.Context=e}())(function(){"use strict";function t(t,e){return t.triggerPoint-e.triggerPoint}function e(t,e){return e.triggerPoint-t.triggerPoint}function i(t){this.name=t.name,this.axis=t.axis,this.id=this.name+"-"+this.axis,this.waypoints=[],this.clearTriggerQueues(),o[this.axis][this.name]=this}var o={vertical:{},horizontal:{}},r=window.Waypoint;i.prototype.add=function(t){this.waypoints.push(t)},i.prototype.clearTriggerQueues=function(){this.triggerQueues={up:[],down:[],left:[],right:[]}},i.prototype.flushTriggers=function(){for(var i in this.triggerQueues){var o=this.triggerQueues[i],r="up"===i||"left"===i;o.sort(r?e:t);for(var n=0,s=o.length;s>n;n+=1){var a=o[n];(a.options.continuous||n===o.length-1)&&a.trigger([i])}}this.clearTriggerQueues()},i.prototype.next=function(e){this.waypoints.sort(t);var i=r.Adapter.inArray(e,this.waypoints),o=i===this.waypoints.length-1;return o?null:this.waypoints[i+1]},i.prototype.previous=function(e){this.waypoints.sort(t);var i=r.Adapter.inArray(e,this.waypoints);return i?this.waypoints[i-1]:null},i.prototype.queueTrigger=function(t,e){this.triggerQueues[e].push(t)},i.prototype.remove=function(t){var e=r.Adapter.inArray(t,this.waypoints);e>-1&&this.waypoints.splice(e,1)},i.prototype.first=function(){return this.waypoints[0]},i.prototype.last=function(){return this.waypoints[this.waypoints.length-1]},i.findOrCreate=function(t){return o[t.axis][t.name]||new i(t)},r.Group=i}())(function(){"use strict";function t(t){this.$element=e(t)}var e=window.jQuery,i=window.Waypoint;e.each(["height","off","offset","on","outerHeight","outerWidth","scrollLeft","scrollTop","width"],function(e,i){t.prototype[i]=function(){var t=Array.prototype.slice.call(arguments);return this.$element[i].apply(this.$element,t)}}),e.each(["extend","inArray","isEmptyObject"],function(i,o){t[o]=e[o]}),i.adapters.push({name:"jquery",Adapter:t}),i.Adapter=t}())(function(){"use strict";function t(t){return function(){var i=[],o=arguments[0];return t.isFunction(arguments[0])&&(o=t.extend({},arguments[1]),o.handler=arguments[0]),this.each(function(){var r=t.extend({},o,{element:this});"string"==typeof r.context&&(r.context=t(this).closest(r.context)[0]),i.push(new e(r))}),i}}var e=window.Waypoint;window.jQuery&&(window.jQuery.fn.waypoint=t(window.jQuery)),window.Zepto&&(window.Zepto.fn.waypoint=t(window.Zepto))}()); \ No newline at end of file +!function(){"use strict";function t(o){if(!o)throw new Error("No options passed to Waypoint constructor");if(!o.element)throw new Error("No element option passed to Waypoint constructor");this.key="waypoint-"+e,this.options=t.Adapter.extend({},t.defaults,o),this.element=this.options.element,this.adapter=new t.Adapter(this.element),this.callback=o.handler,this.axis=this.options.horizontal?"horizontal":"vertical",this.enabled=this.options.enabled,this.triggerPoint=null,this.group=t.Group.findOrCreate({name:this.options.group,axis:this.axis}),this.context=t.Context.findOrCreateByElement(this.options.context),t.offsetAliases[this.options.offset]&&(this.options.offset=t.offsetAliases[this.options.offset]),this.context.add(this),this.group.add(this),i[this.key]=this,e+=1}var e=0,i={};t.prototype.queueTrigger=function(t){this.group.queueTrigger(this,t)},t.prototype.trigger=function(t){this.enabled&&(this.callback&&this.callback.apply(this,t),this.options.triggerOnce&&this.destroy())},t.prototype.destroy=function(){this.context.remove(this),this.group.remove(this),delete i[this.key]},t.prototype.disable=function(){return this.enabled=!1,this},t.prototype.enable=function(){return this.context.refresh(),this.enabled=!0,this},t.prototype.next=function(){return this.group.next(this)},t.prototype.previous=function(){return this.group.previous(this)},t.destroyAll=function(){var t=[];for(var e in i)t.push(i[e]);for(var o=0,r=t.length;r>o;o++)t[o].destroy()},t.refreshAll=function(){t.Context.refreshAll()},t.viewportHeight=function(){return window.innerHeight||document.documentElement.clientHeight},t.viewportWidth=function(){return document.documentElement.clientWidth},t.adapters=[],t.defaults={context:window,continuous:!0,enabled:!0,group:"default",horizontal:!1,offset:0,triggerOnce:!1},t.offsetAliases={"bottom-in-view":function(){return this.context.height()-this.adapter.outerHeight()},"right-in-view":function(){return this.context.width()-this.adapter.outerWidth()}},window.Waypoint=t}(),function(){"use strict";function t(t){window.setTimeout(t,1e3/60)}function e(t){this.element=t,this.Adapter=r.Adapter,this.adapter=new this.Adapter(t),this.key="waypoint-context-"+i,this.didScroll=!1,this.didResize=!1,this.oldScroll={x:this.adapter.scrollLeft(),y:this.adapter.scrollTop()},this.waypoints={vertical:{},horizontal:{}},t.waypointContextKey=this.key,o[t.waypointContextKey]=this,i+=1,this.createThrottledScrollHandler(),this.createThrottledResizeHandler()}var i=0,o={},r=window.Waypoint,n=window.requestAnimationFrame||window.mozRequestAnimationFrame||window.webkitRequestAnimationFrame||t;e.prototype.add=function(t){var e=t.options.horizontal?"horizontal":"vertical";this.waypoints[e][t.key]=t,this.refresh()},e.prototype.checkEmpty=function(){var t=this.Adapter.isEmptyObject(this.waypoints.horizontal),e=this.Adapter.isEmptyObject(this.waypoints.vertical);t&&e&&(this.adapter.off(".waypoints"),delete o[this.key])},e.prototype.createThrottledResizeHandler=function(){function t(){e.handleResize(),e.didResize=!1}var e=this;this.adapter.on("resize.waypoints",function(){e.didResize||(e.didResize=!0,n(t))})},e.prototype.createThrottledScrollHandler=function(){function t(){e.handleScroll(),e.didScroll=!1}var e=this;this.adapter.on("scroll.waypoints",function(){(!e.didScroll||r.isTouch)&&(e.didScroll=!0,n(t))})},e.prototype.handleResize=function(){r.Context.refreshAll()},e.prototype.handleScroll=function(){var t={},e={horizontal:{newScroll:this.adapter.scrollLeft(),oldScroll:this.oldScroll.x,forward:"right",backward:"left"},vertical:{newScroll:this.adapter.scrollTop(),oldScroll:this.oldScroll.y,forward:"down",backward:"up"}};for(var i in e){var o=e[i],r=o.newScroll>o.oldScroll,n=r?o.forward:o.backward;for(var s in this.waypoints[i]){var a=this.waypoints[i][s],l=o.oldScroll=a.triggerPoint,p=l&&h,u=!l&&!h;(p||u)&&(a.queueTrigger(n),t[a.group.id]=a.group)}}for(var c in t)t[c].flushTriggers();this.oldScroll={x:e.horizontal.newScroll,y:e.vertical.newScroll}},e.prototype.height=function(){return this.element===this.element.window?r.viewportHeight():this.adapter.height()},e.prototype.remove=function(t){delete this.waypoints[t.axis][t.key],this.checkEmpty()},e.prototype.width=function(){return this.element===this.element.window?r.viewportWidth():this.adapter.width()},e.prototype.destroy=function(){var t=[];for(var e in this.waypoints)for(var i in this.waypoints[e])t.push(this.waypoints[e][i]);for(var o=0,r=t.length;r>o;o++)t[o].destroy()},e.prototype.refresh=function(){var t,e=this.element===this.element.window,i=this.adapter.offset(),o={};this.handleScroll(),t={horizontal:{contextOffset:e?0:i.left,contextScroll:e?0:this.oldScroll.x,contextDimension:this.width(),oldScroll:this.oldScroll.x,forward:"right",backward:"left",offsetProp:"left"},vertical:{contextOffset:e?0:i.top,contextScroll:e?0:this.oldScroll.y,contextDimension:this.height(),oldScroll:this.oldScroll.y,forward:"down",backward:"up",offsetProp:"top"}};for(var r in t){var n=t[r];for(var s in this.waypoints[r]){var a,l,h,p,u,c=this.waypoints[r][s],d=c.options.offset,f=c.triggerPoint,w=0,y=null==f;c.element!==c.element.window&&(w=c.adapter.offset()[n.offsetProp]),"function"==typeof d?d=d.apply(c):"string"==typeof d&&(d=parseFloat(d),c.options.offset.indexOf("%")>-1&&(d=Math.ceil(n.contextDimension*d/100))),a=n.contextScroll-n.contextOffset,c.triggerPoint=w+a-d,l=f=n.oldScroll,p=l&&h,u=!l&&!h,!y&&p?(c.queueTrigger(n.backward),o[c.group.id]=c.group):!y&&u?(c.queueTrigger(n.forward),o[c.group.id]=c.group):y&&n.oldScroll>=c.triggerPoint&&(c.queueTrigger(n.forward),o[c.group.id]=c.group)}}for(var g in o)o[g].flushTriggers();return this},e.findOrCreateByElement=function(t){return e.findByElement(t)||new e(t)},e.refreshAll=function(){for(var t in o)o[t].refresh()},e.findByElement=function(t){return o[t.waypointContextKey]},r.Context=e}(),function(){"use strict";function t(t,e){return t.triggerPoint-e.triggerPoint}function e(t,e){return e.triggerPoint-t.triggerPoint}function i(t){this.name=t.name,this.axis=t.axis,this.id=this.name+"-"+this.axis,this.waypoints=[],this.clearTriggerQueues(),o[this.axis][this.name]=this}var o={vertical:{},horizontal:{}},r=window.Waypoint;i.prototype.add=function(t){this.waypoints.push(t)},i.prototype.clearTriggerQueues=function(){this.triggerQueues={up:[],down:[],left:[],right:[]}},i.prototype.flushTriggers=function(){for(var i in this.triggerQueues){var o=this.triggerQueues[i],r="up"===i||"left"===i;o.sort(r?e:t);for(var n=0,s=o.length;s>n;n+=1){var a=o[n];(a.options.continuous||n===o.length-1)&&a.trigger([i])}}this.clearTriggerQueues()},i.prototype.next=function(e){this.waypoints.sort(t);var i=r.Adapter.inArray(e,this.waypoints),o=i===this.waypoints.length-1;return o?null:this.waypoints[i+1]},i.prototype.previous=function(e){this.waypoints.sort(t);var i=r.Adapter.inArray(e,this.waypoints);return i?this.waypoints[i-1]:null},i.prototype.queueTrigger=function(t,e){this.triggerQueues[e].push(t)},i.prototype.remove=function(t){var e=r.Adapter.inArray(t,this.waypoints);e>-1&&this.waypoints.splice(e,1)},i.prototype.first=function(){return this.waypoints[0]},i.prototype.last=function(){return this.waypoints[this.waypoints.length-1]},i.findOrCreate=function(t){return o[t.axis][t.name]||new i(t)},r.Group=i}(),function(){"use strict";function t(t){this.$element=e(t)}var e=window.jQuery,i=window.Waypoint;e.each(["height","off","offset","on","outerHeight","outerWidth","scrollLeft","scrollTop","width"],function(e,i){t.prototype[i]=function(){var t=Array.prototype.slice.call(arguments);return this.$element[i].apply(this.$element,t)}}),e.each(["extend","inArray","isEmptyObject"],function(i,o){t[o]=e[o]}),i.adapters.push({name:"jquery",Adapter:t}),i.Adapter=t}(),function(){"use strict";function t(t){return function(){var i=[],o=arguments[0];return t.isFunction(arguments[0])&&(o=t.extend({},arguments[1]),o.handler=arguments[0]),this.each(function(){var r=t.extend({},o,{element:this});"string"==typeof r.context&&(r.context=t(this).closest(r.context)[0]),i.push(new e(r))}),i}}var e=window.Waypoint;window.jQuery&&(window.jQuery.fn.waypoint=t(window.jQuery)),window.Zepto&&(window.Zepto.fn.waypoint=t(window.Zepto))}(); \ No newline at end of file diff --git a/lib/noframework.waypoints.js b/lib/noframework.waypoints.js index 0c89888d..009003fc 100644 --- a/lib/noframework.waypoints.js +++ b/lib/noframework.waypoints.js @@ -138,8 +138,7 @@ https://github.com/imakewebthings/waypoints/blog/master/licenses.txt window.Waypoint = Waypoint }()) - -(function() { +;(function() { 'use strict' function requestAnimationFrameShim(callback) { @@ -416,8 +415,7 @@ https://github.com/imakewebthings/waypoints/blog/master/licenses.txt Waypoint.Context = Context }()) - -(function() { +;(function() { 'use strict' function byTriggerPoint(a, b) { @@ -519,8 +517,7 @@ https://github.com/imakewebthings/waypoints/blog/master/licenses.txt Waypoint.Group = Group }()) - -(function() { +;(function() { 'use strict' var Waypoint = window.Waypoint diff --git a/lib/noframework.waypoints.min.js b/lib/noframework.waypoints.min.js index 046e3a3e..e1690eb5 100644 --- a/lib/noframework.waypoints.min.js +++ b/lib/noframework.waypoints.min.js @@ -4,4 +4,4 @@ Copyright © 2011-2014 Caleb Troughton Licensed under the MIT license. https://github.com/imakewebthings/waypoints/blog/master/licenses.txt */ -!function(){"use strict";function t(o){if(!o)throw new Error("No options passed to Waypoint constructor");if(!o.element)throw new Error("No element option passed to Waypoint constructor");this.key="waypoint-"+e,this.options=t.Adapter.extend({},t.defaults,o),this.element=this.options.element,this.adapter=new t.Adapter(this.element),this.callback=o.handler,this.axis=this.options.horizontal?"horizontal":"vertical",this.enabled=this.options.enabled,this.triggerPoint=null,this.group=t.Group.findOrCreate({name:this.options.group,axis:this.axis}),this.context=t.Context.findOrCreateByElement(this.options.context),t.offsetAliases[this.options.offset]&&(this.options.offset=t.offsetAliases[this.options.offset]),this.context.add(this),this.group.add(this),i[this.key]=this,e+=1}var e=0,i={};t.prototype.queueTrigger=function(t){this.group.queueTrigger(this,t)},t.prototype.trigger=function(t){this.enabled&&(this.callback&&this.callback.apply(this,t),this.options.triggerOnce&&this.destroy())},t.prototype.destroy=function(){this.context.remove(this),this.group.remove(this),delete i[this.key]},t.prototype.disable=function(){return this.enabled=!1,this},t.prototype.enable=function(){return this.context.refresh(),this.enabled=!0,this},t.prototype.next=function(){return this.group.next(this)},t.prototype.previous=function(){return this.group.previous(this)},t.destroyAll=function(){var t=[];for(var e in i)t.push(i[e]);for(var o=0,r=t.length;r>o;o++)t[o].destroy()},t.refreshAll=function(){t.Context.refreshAll()},t.viewportHeight=function(){return window.innerHeight||document.documentElement.clientHeight},t.viewportWidth=function(){return document.documentElement.clientWidth},t.adapters=[],t.defaults={context:window,continuous:!0,enabled:!0,group:"default",horizontal:!1,offset:0,triggerOnce:!1},t.offsetAliases={"bottom-in-view":function(){return this.context.height()-this.adapter.outerHeight()},"right-in-view":function(){return this.context.width()-this.adapter.outerWidth()}},window.Waypoint=t}()(function(){"use strict";function t(t){window.setTimeout(t,1e3/60)}function e(t){this.element=t,this.Adapter=r.Adapter,this.adapter=new this.Adapter(t),this.key="waypoint-context-"+i,this.didScroll=!1,this.didResize=!1,this.oldScroll={x:this.adapter.scrollLeft(),y:this.adapter.scrollTop()},this.waypoints={vertical:{},horizontal:{}},t.waypointContextKey=this.key,o[t.waypointContextKey]=this,i+=1,this.createThrottledScrollHandler(),this.createThrottledResizeHandler()}var i=0,o={},r=window.Waypoint,n=window.requestAnimationFrame||window.mozRequestAnimationFrame||window.webkitRequestAnimationFrame||t;e.prototype.add=function(t){var e=t.options.horizontal?"horizontal":"vertical";this.waypoints[e][t.key]=t,this.refresh()},e.prototype.checkEmpty=function(){var t=this.Adapter.isEmptyObject(this.waypoints.horizontal),e=this.Adapter.isEmptyObject(this.waypoints.vertical);t&&e&&(this.adapter.off(".waypoints"),delete o[this.key])},e.prototype.createThrottledResizeHandler=function(){function t(){e.handleResize(),e.didResize=!1}var e=this;this.adapter.on("resize.waypoints",function(){e.didResize||(e.didResize=!0,n(t))})},e.prototype.createThrottledScrollHandler=function(){function t(){e.handleScroll(),e.didScroll=!1}var e=this;this.adapter.on("scroll.waypoints",function(){(!e.didScroll||r.isTouch)&&(e.didScroll=!0,n(t))})},e.prototype.handleResize=function(){r.Context.refreshAll()},e.prototype.handleScroll=function(){var t={},e={horizontal:{newScroll:this.adapter.scrollLeft(),oldScroll:this.oldScroll.x,forward:"right",backward:"left"},vertical:{newScroll:this.adapter.scrollTop(),oldScroll:this.oldScroll.y,forward:"down",backward:"up"}};for(var i in e){var o=e[i],r=o.newScroll>o.oldScroll,n=r?o.forward:o.backward;for(var s in this.waypoints[i]){var a=this.waypoints[i][s],l=o.oldScroll=a.triggerPoint,p=l&&h,u=!l&&!h;(p||u)&&(a.queueTrigger(n),t[a.group.id]=a.group)}}for(var f in t)t[f].flushTriggers();this.oldScroll={x:e.horizontal.newScroll,y:e.vertical.newScroll}},e.prototype.height=function(){return this.element===this.element.window?r.viewportHeight():this.adapter.height()},e.prototype.remove=function(t){delete this.waypoints[t.axis][t.key],this.checkEmpty()},e.prototype.width=function(){return this.element===this.element.window?r.viewportWidth():this.adapter.width()},e.prototype.destroy=function(){var t=[];for(var e in this.waypoints)for(var i in this.waypoints[e])t.push(this.waypoints[e][i]);for(var o=0,r=t.length;r>o;o++)t[o].destroy()},e.prototype.refresh=function(){var t,e=this.element===this.element.window,i=this.adapter.offset(),o={};this.handleScroll(),t={horizontal:{contextOffset:e?0:i.left,contextScroll:e?0:this.oldScroll.x,contextDimension:this.width(),oldScroll:this.oldScroll.x,forward:"right",backward:"left",offsetProp:"left"},vertical:{contextOffset:e?0:i.top,contextScroll:e?0:this.oldScroll.y,contextDimension:this.height(),oldScroll:this.oldScroll.y,forward:"down",backward:"up",offsetProp:"top"}};for(var r in t){var n=t[r];for(var s in this.waypoints[r]){var a,l,h,p,u,f=this.waypoints[r][s],c=f.options.offset,d=f.triggerPoint,g=0,y=null==d;f.element!==f.element.window&&(g=f.adapter.offset()[n.offsetProp]),"function"==typeof c?c=c.apply(f):"string"==typeof c&&(c=parseFloat(c),f.options.offset.indexOf("%")>-1&&(c=Math.ceil(n.contextDimension*c/100))),a=n.contextScroll-n.contextOffset,f.triggerPoint=g+a-c,l=d=n.oldScroll,p=l&&h,u=!l&&!h,!y&&p?(f.queueTrigger(n.backward),o[f.group.id]=f.group):!y&&u?(f.queueTrigger(n.forward),o[f.group.id]=f.group):y&&n.oldScroll>=f.triggerPoint&&(f.queueTrigger(n.forward),o[f.group.id]=f.group)}}for(var w in o)o[w].flushTriggers();return this},e.findOrCreateByElement=function(t){return e.findByElement(t)||new e(t)},e.refreshAll=function(){for(var t in o)o[t].refresh()},e.findByElement=function(t){return o[t.waypointContextKey]},r.Context=e}())(function(){"use strict";function t(t,e){return t.triggerPoint-e.triggerPoint}function e(t,e){return e.triggerPoint-t.triggerPoint}function i(t){this.name=t.name,this.axis=t.axis,this.id=this.name+"-"+this.axis,this.waypoints=[],this.clearTriggerQueues(),o[this.axis][this.name]=this}var o={vertical:{},horizontal:{}},r=window.Waypoint;i.prototype.add=function(t){this.waypoints.push(t)},i.prototype.clearTriggerQueues=function(){this.triggerQueues={up:[],down:[],left:[],right:[]}},i.prototype.flushTriggers=function(){for(var i in this.triggerQueues){var o=this.triggerQueues[i],r="up"===i||"left"===i;o.sort(r?e:t);for(var n=0,s=o.length;s>n;n+=1){var a=o[n];(a.options.continuous||n===o.length-1)&&a.trigger([i])}}this.clearTriggerQueues()},i.prototype.next=function(e){this.waypoints.sort(t);var i=r.Adapter.inArray(e,this.waypoints),o=i===this.waypoints.length-1;return o?null:this.waypoints[i+1]},i.prototype.previous=function(e){this.waypoints.sort(t);var i=r.Adapter.inArray(e,this.waypoints);return i?this.waypoints[i-1]:null},i.prototype.queueTrigger=function(t,e){this.triggerQueues[e].push(t)},i.prototype.remove=function(t){var e=r.Adapter.inArray(t,this.waypoints);e>-1&&this.waypoints.splice(e,1)},i.prototype.first=function(){return this.waypoints[0]},i.prototype.last=function(){return this.waypoints[this.waypoints.length-1]},i.findOrCreate=function(t){return o[t.axis][t.name]||new i(t)},r.Group=i}())(function(){"use strict";function t(t){return t===t.window}function e(e){return t(e)?e:e.defaultView}function i(t){this.element=t,this.handlers={}}var o=window.Waypoint;i.prototype.height=function(){var e=t(this.element);return e?this.element.innerHeight:this.element.offsetHeight},i.prototype.off=function(t,e){function i(t,e,i){for(var o=0,r=e.length-1;r>o;o++){var n=e[o];i&&i!==n||t.removeEventListener(n)}}var o=t.split("."),r=o[0],n=o[1],s=this.element;if(n&&this.handlers[n]&&r)i(s,this.handlers[n][r],e),this.handlers[n][r]=[];else if(r)for(var a in this.handlers)i(s,this.handlers[a][r]||[],e),this.handlers[a][r]=[];else if(n&&this.handlers[n]){for(var l in this.handlers[n])i(s,this.handlers[n][l],e);this.handlers[n]={}}},i.prototype.offset=function(){if(!this.element.ownerDocument)return null;var t=this.element.ownerDocument.documentElement,i=e(this.element.ownerDocument),o={top:0,left:0};return this.element.getBoundingClientRect&&(o=this.element.getBoundingClientRect()),{top:o.top+i.pageYOffset-t.clientTop,left:o.left+i.pageXOffset-t.clientLeft}},i.prototype.on=function(t,e){var i=t.split("."),o=i[0],r=i[1]||"__default",n=this.handlers[r]=this.handlers[r]||{},s=n[o]=n[o]||[];s.push(e),this.element.addEventListener(o,e)},i.prototype.outerHeight=function(e){var i,o=this.height();return e&&!t(this.element)&&(i=window.getComputedStyle(this.element),o+=parseInt(i.marginTop,10),o+=parseInt(i.marginBottom,10)),o},i.prototype.outerWidth=function(e){var i,o=this.width();return e&&!t(this.element)&&(i=window.getComputedStyle(this.element),o+=parseInt(i.marginLeft,10),o+=parseInt(i.marginRight,10)),o},i.prototype.scrollLeft=function(){var t=e(this.element);return t?t.pageXOffset:this.element.scrollLeft},i.prototype.scrollTop=function(){var t=e(this.element);return t?t.pageYOffset:this.element.scrollTop},i.prototype.width=function(){var e=t(this.element);return e?this.element.innerWidth:this.element.offsetWidth},i.extend=function(){function t(t,e){if("object"==typeof t&&"object"==typeof e)for(var i in e)e.hasOwnProperty(i)&&(t[i]=e[i]);return t}for(var e=Array.prototype.slice.call(arguments),i=1,o=e.length;o>i;i++)t(e[0],e[i]);return e[0]},i.inArray=function(t,e,i){return null==e?-1:e.indexOf(t,i)},i.isEmptyObject=function(t){for(var e in t)return!1;return!0},o.adapters.push({name:"noframework",Adapter:i}),o.Adapter=i}()); \ No newline at end of file +!function(){"use strict";function t(o){if(!o)throw new Error("No options passed to Waypoint constructor");if(!o.element)throw new Error("No element option passed to Waypoint constructor");this.key="waypoint-"+e,this.options=t.Adapter.extend({},t.defaults,o),this.element=this.options.element,this.adapter=new t.Adapter(this.element),this.callback=o.handler,this.axis=this.options.horizontal?"horizontal":"vertical",this.enabled=this.options.enabled,this.triggerPoint=null,this.group=t.Group.findOrCreate({name:this.options.group,axis:this.axis}),this.context=t.Context.findOrCreateByElement(this.options.context),t.offsetAliases[this.options.offset]&&(this.options.offset=t.offsetAliases[this.options.offset]),this.context.add(this),this.group.add(this),i[this.key]=this,e+=1}var e=0,i={};t.prototype.queueTrigger=function(t){this.group.queueTrigger(this,t)},t.prototype.trigger=function(t){this.enabled&&(this.callback&&this.callback.apply(this,t),this.options.triggerOnce&&this.destroy())},t.prototype.destroy=function(){this.context.remove(this),this.group.remove(this),delete i[this.key]},t.prototype.disable=function(){return this.enabled=!1,this},t.prototype.enable=function(){return this.context.refresh(),this.enabled=!0,this},t.prototype.next=function(){return this.group.next(this)},t.prototype.previous=function(){return this.group.previous(this)},t.destroyAll=function(){var t=[];for(var e in i)t.push(i[e]);for(var o=0,r=t.length;r>o;o++)t[o].destroy()},t.refreshAll=function(){t.Context.refreshAll()},t.viewportHeight=function(){return window.innerHeight||document.documentElement.clientHeight},t.viewportWidth=function(){return document.documentElement.clientWidth},t.adapters=[],t.defaults={context:window,continuous:!0,enabled:!0,group:"default",horizontal:!1,offset:0,triggerOnce:!1},t.offsetAliases={"bottom-in-view":function(){return this.context.height()-this.adapter.outerHeight()},"right-in-view":function(){return this.context.width()-this.adapter.outerWidth()}},window.Waypoint=t}(),function(){"use strict";function t(t){window.setTimeout(t,1e3/60)}function e(t){this.element=t,this.Adapter=r.Adapter,this.adapter=new this.Adapter(t),this.key="waypoint-context-"+i,this.didScroll=!1,this.didResize=!1,this.oldScroll={x:this.adapter.scrollLeft(),y:this.adapter.scrollTop()},this.waypoints={vertical:{},horizontal:{}},t.waypointContextKey=this.key,o[t.waypointContextKey]=this,i+=1,this.createThrottledScrollHandler(),this.createThrottledResizeHandler()}var i=0,o={},r=window.Waypoint,n=window.requestAnimationFrame||window.mozRequestAnimationFrame||window.webkitRequestAnimationFrame||t;e.prototype.add=function(t){var e=t.options.horizontal?"horizontal":"vertical";this.waypoints[e][t.key]=t,this.refresh()},e.prototype.checkEmpty=function(){var t=this.Adapter.isEmptyObject(this.waypoints.horizontal),e=this.Adapter.isEmptyObject(this.waypoints.vertical);t&&e&&(this.adapter.off(".waypoints"),delete o[this.key])},e.prototype.createThrottledResizeHandler=function(){function t(){e.handleResize(),e.didResize=!1}var e=this;this.adapter.on("resize.waypoints",function(){e.didResize||(e.didResize=!0,n(t))})},e.prototype.createThrottledScrollHandler=function(){function t(){e.handleScroll(),e.didScroll=!1}var e=this;this.adapter.on("scroll.waypoints",function(){(!e.didScroll||r.isTouch)&&(e.didScroll=!0,n(t))})},e.prototype.handleResize=function(){r.Context.refreshAll()},e.prototype.handleScroll=function(){var t={},e={horizontal:{newScroll:this.adapter.scrollLeft(),oldScroll:this.oldScroll.x,forward:"right",backward:"left"},vertical:{newScroll:this.adapter.scrollTop(),oldScroll:this.oldScroll.y,forward:"down",backward:"up"}};for(var i in e){var o=e[i],r=o.newScroll>o.oldScroll,n=r?o.forward:o.backward;for(var s in this.waypoints[i]){var a=this.waypoints[i][s],l=o.oldScroll=a.triggerPoint,p=l&&h,u=!l&&!h;(p||u)&&(a.queueTrigger(n),t[a.group.id]=a.group)}}for(var f in t)t[f].flushTriggers();this.oldScroll={x:e.horizontal.newScroll,y:e.vertical.newScroll}},e.prototype.height=function(){return this.element===this.element.window?r.viewportHeight():this.adapter.height()},e.prototype.remove=function(t){delete this.waypoints[t.axis][t.key],this.checkEmpty()},e.prototype.width=function(){return this.element===this.element.window?r.viewportWidth():this.adapter.width()},e.prototype.destroy=function(){var t=[];for(var e in this.waypoints)for(var i in this.waypoints[e])t.push(this.waypoints[e][i]);for(var o=0,r=t.length;r>o;o++)t[o].destroy()},e.prototype.refresh=function(){var t,e=this.element===this.element.window,i=this.adapter.offset(),o={};this.handleScroll(),t={horizontal:{contextOffset:e?0:i.left,contextScroll:e?0:this.oldScroll.x,contextDimension:this.width(),oldScroll:this.oldScroll.x,forward:"right",backward:"left",offsetProp:"left"},vertical:{contextOffset:e?0:i.top,contextScroll:e?0:this.oldScroll.y,contextDimension:this.height(),oldScroll:this.oldScroll.y,forward:"down",backward:"up",offsetProp:"top"}};for(var r in t){var n=t[r];for(var s in this.waypoints[r]){var a,l,h,p,u,f=this.waypoints[r][s],c=f.options.offset,d=f.triggerPoint,g=0,y=null==d;f.element!==f.element.window&&(g=f.adapter.offset()[n.offsetProp]),"function"==typeof c?c=c.apply(f):"string"==typeof c&&(c=parseFloat(c),f.options.offset.indexOf("%")>-1&&(c=Math.ceil(n.contextDimension*c/100))),a=n.contextScroll-n.contextOffset,f.triggerPoint=g+a-c,l=d=n.oldScroll,p=l&&h,u=!l&&!h,!y&&p?(f.queueTrigger(n.backward),o[f.group.id]=f.group):!y&&u?(f.queueTrigger(n.forward),o[f.group.id]=f.group):y&&n.oldScroll>=f.triggerPoint&&(f.queueTrigger(n.forward),o[f.group.id]=f.group)}}for(var w in o)o[w].flushTriggers();return this},e.findOrCreateByElement=function(t){return e.findByElement(t)||new e(t)},e.refreshAll=function(){for(var t in o)o[t].refresh()},e.findByElement=function(t){return o[t.waypointContextKey]},r.Context=e}(),function(){"use strict";function t(t,e){return t.triggerPoint-e.triggerPoint}function e(t,e){return e.triggerPoint-t.triggerPoint}function i(t){this.name=t.name,this.axis=t.axis,this.id=this.name+"-"+this.axis,this.waypoints=[],this.clearTriggerQueues(),o[this.axis][this.name]=this}var o={vertical:{},horizontal:{}},r=window.Waypoint;i.prototype.add=function(t){this.waypoints.push(t)},i.prototype.clearTriggerQueues=function(){this.triggerQueues={up:[],down:[],left:[],right:[]}},i.prototype.flushTriggers=function(){for(var i in this.triggerQueues){var o=this.triggerQueues[i],r="up"===i||"left"===i;o.sort(r?e:t);for(var n=0,s=o.length;s>n;n+=1){var a=o[n];(a.options.continuous||n===o.length-1)&&a.trigger([i])}}this.clearTriggerQueues()},i.prototype.next=function(e){this.waypoints.sort(t);var i=r.Adapter.inArray(e,this.waypoints),o=i===this.waypoints.length-1;return o?null:this.waypoints[i+1]},i.prototype.previous=function(e){this.waypoints.sort(t);var i=r.Adapter.inArray(e,this.waypoints);return i?this.waypoints[i-1]:null},i.prototype.queueTrigger=function(t,e){this.triggerQueues[e].push(t)},i.prototype.remove=function(t){var e=r.Adapter.inArray(t,this.waypoints);e>-1&&this.waypoints.splice(e,1)},i.prototype.first=function(){return this.waypoints[0]},i.prototype.last=function(){return this.waypoints[this.waypoints.length-1]},i.findOrCreate=function(t){return o[t.axis][t.name]||new i(t)},r.Group=i}(),function(){"use strict";function t(t){return t===t.window}function e(e){return t(e)?e:e.defaultView}function i(t){this.element=t,this.handlers={}}var o=window.Waypoint;i.prototype.height=function(){var e=t(this.element);return e?this.element.innerHeight:this.element.offsetHeight},i.prototype.off=function(t,e){function i(t,e,i){for(var o=0,r=e.length-1;r>o;o++){var n=e[o];i&&i!==n||t.removeEventListener(n)}}var o=t.split("."),r=o[0],n=o[1],s=this.element;if(n&&this.handlers[n]&&r)i(s,this.handlers[n][r],e),this.handlers[n][r]=[];else if(r)for(var a in this.handlers)i(s,this.handlers[a][r]||[],e),this.handlers[a][r]=[];else if(n&&this.handlers[n]){for(var l in this.handlers[n])i(s,this.handlers[n][l],e);this.handlers[n]={}}},i.prototype.offset=function(){if(!this.element.ownerDocument)return null;var t=this.element.ownerDocument.documentElement,i=e(this.element.ownerDocument),o={top:0,left:0};return this.element.getBoundingClientRect&&(o=this.element.getBoundingClientRect()),{top:o.top+i.pageYOffset-t.clientTop,left:o.left+i.pageXOffset-t.clientLeft}},i.prototype.on=function(t,e){var i=t.split("."),o=i[0],r=i[1]||"__default",n=this.handlers[r]=this.handlers[r]||{},s=n[o]=n[o]||[];s.push(e),this.element.addEventListener(o,e)},i.prototype.outerHeight=function(e){var i,o=this.height();return e&&!t(this.element)&&(i=window.getComputedStyle(this.element),o+=parseInt(i.marginTop,10),o+=parseInt(i.marginBottom,10)),o},i.prototype.outerWidth=function(e){var i,o=this.width();return e&&!t(this.element)&&(i=window.getComputedStyle(this.element),o+=parseInt(i.marginLeft,10),o+=parseInt(i.marginRight,10)),o},i.prototype.scrollLeft=function(){var t=e(this.element);return t?t.pageXOffset:this.element.scrollLeft},i.prototype.scrollTop=function(){var t=e(this.element);return t?t.pageYOffset:this.element.scrollTop},i.prototype.width=function(){var e=t(this.element);return e?this.element.innerWidth:this.element.offsetWidth},i.extend=function(){function t(t,e){if("object"==typeof t&&"object"==typeof e)for(var i in e)e.hasOwnProperty(i)&&(t[i]=e[i]);return t}for(var e=Array.prototype.slice.call(arguments),i=1,o=e.length;o>i;i++)t(e[0],e[i]);return e[0]},i.inArray=function(t,e,i){return null==e?-1:e.indexOf(t,i)},i.isEmptyObject=function(t){for(var e in t)return!1;return!0},o.adapters.push({name:"noframework",Adapter:i}),o.Adapter=i}(); \ No newline at end of file diff --git a/lib/zepto.waypoints.js b/lib/zepto.waypoints.js index 830ebb18..1d410ccb 100644 --- a/lib/zepto.waypoints.js +++ b/lib/zepto.waypoints.js @@ -138,8 +138,7 @@ https://github.com/imakewebthings/waypoints/blog/master/licenses.txt window.Waypoint = Waypoint }()) - -(function() { +;(function() { 'use strict' function requestAnimationFrameShim(callback) { @@ -416,8 +415,7 @@ https://github.com/imakewebthings/waypoints/blog/master/licenses.txt Waypoint.Context = Context }()) - -(function() { +;(function() { 'use strict' function byTriggerPoint(a, b) { @@ -519,8 +517,7 @@ https://github.com/imakewebthings/waypoints/blog/master/licenses.txt Waypoint.Group = Group }()) - -(function() { +;(function() { 'use strict' var $ = window.Zepto @@ -593,8 +590,7 @@ https://github.com/imakewebthings/waypoints/blog/master/licenses.txt }) Waypoint.Adapter = ZeptoAdapter }()) - -(function() { +;(function() { 'use strict' var Waypoint = window.Waypoint diff --git a/lib/zepto.waypoints.min.js b/lib/zepto.waypoints.min.js index 4cb3856c..2d7d3c4c 100644 --- a/lib/zepto.waypoints.min.js +++ b/lib/zepto.waypoints.min.js @@ -4,4 +4,4 @@ Copyright © 2011-2014 Caleb Troughton Licensed under the MIT license. https://github.com/imakewebthings/waypoints/blog/master/licenses.txt */ -!function(){"use strict";function t(o){if(!o)throw new Error("No options passed to Waypoint constructor");if(!o.element)throw new Error("No element option passed to Waypoint constructor");this.key="waypoint-"+e,this.options=t.Adapter.extend({},t.defaults,o),this.element=this.options.element,this.adapter=new t.Adapter(this.element),this.callback=o.handler,this.axis=this.options.horizontal?"horizontal":"vertical",this.enabled=this.options.enabled,this.triggerPoint=null,this.group=t.Group.findOrCreate({name:this.options.group,axis:this.axis}),this.context=t.Context.findOrCreateByElement(this.options.context),t.offsetAliases[this.options.offset]&&(this.options.offset=t.offsetAliases[this.options.offset]),this.context.add(this),this.group.add(this),i[this.key]=this,e+=1}var e=0,i={};t.prototype.queueTrigger=function(t){this.group.queueTrigger(this,t)},t.prototype.trigger=function(t){this.enabled&&(this.callback&&this.callback.apply(this,t),this.options.triggerOnce&&this.destroy())},t.prototype.destroy=function(){this.context.remove(this),this.group.remove(this),delete i[this.key]},t.prototype.disable=function(){return this.enabled=!1,this},t.prototype.enable=function(){return this.context.refresh(),this.enabled=!0,this},t.prototype.next=function(){return this.group.next(this)},t.prototype.previous=function(){return this.group.previous(this)},t.destroyAll=function(){var t=[];for(var e in i)t.push(i[e]);for(var o=0,r=t.length;r>o;o++)t[o].destroy()},t.refreshAll=function(){t.Context.refreshAll()},t.viewportHeight=function(){return window.innerHeight||document.documentElement.clientHeight},t.viewportWidth=function(){return document.documentElement.clientWidth},t.adapters=[],t.defaults={context:window,continuous:!0,enabled:!0,group:"default",horizontal:!1,offset:0,triggerOnce:!1},t.offsetAliases={"bottom-in-view":function(){return this.context.height()-this.adapter.outerHeight()},"right-in-view":function(){return this.context.width()-this.adapter.outerWidth()}},window.Waypoint=t}()(function(){"use strict";function t(t){window.setTimeout(t,1e3/60)}function e(t){this.element=t,this.Adapter=r.Adapter,this.adapter=new this.Adapter(t),this.key="waypoint-context-"+i,this.didScroll=!1,this.didResize=!1,this.oldScroll={x:this.adapter.scrollLeft(),y:this.adapter.scrollTop()},this.waypoints={vertical:{},horizontal:{}},t.waypointContextKey=this.key,o[t.waypointContextKey]=this,i+=1,this.createThrottledScrollHandler(),this.createThrottledResizeHandler()}var i=0,o={},r=window.Waypoint,n=window.requestAnimationFrame||window.mozRequestAnimationFrame||window.webkitRequestAnimationFrame||t;e.prototype.add=function(t){var e=t.options.horizontal?"horizontal":"vertical";this.waypoints[e][t.key]=t,this.refresh()},e.prototype.checkEmpty=function(){var t=this.Adapter.isEmptyObject(this.waypoints.horizontal),e=this.Adapter.isEmptyObject(this.waypoints.vertical);t&&e&&(this.adapter.off(".waypoints"),delete o[this.key])},e.prototype.createThrottledResizeHandler=function(){function t(){e.handleResize(),e.didResize=!1}var e=this;this.adapter.on("resize.waypoints",function(){e.didResize||(e.didResize=!0,n(t))})},e.prototype.createThrottledScrollHandler=function(){function t(){e.handleScroll(),e.didScroll=!1}var e=this;this.adapter.on("scroll.waypoints",function(){(!e.didScroll||r.isTouch)&&(e.didScroll=!0,n(t))})},e.prototype.handleResize=function(){r.Context.refreshAll()},e.prototype.handleScroll=function(){var t={},e={horizontal:{newScroll:this.adapter.scrollLeft(),oldScroll:this.oldScroll.x,forward:"right",backward:"left"},vertical:{newScroll:this.adapter.scrollTop(),oldScroll:this.oldScroll.y,forward:"down",backward:"up"}};for(var i in e){var o=e[i],r=o.newScroll>o.oldScroll,n=r?o.forward:o.backward;for(var s in this.waypoints[i]){var a=this.waypoints[i][s],h=o.oldScroll=a.triggerPoint,p=h&&l,c=!h&&!l;(p||c)&&(a.queueTrigger(n),t[a.group.id]=a.group)}}for(var u in t)t[u].flushTriggers();this.oldScroll={x:e.horizontal.newScroll,y:e.vertical.newScroll}},e.prototype.height=function(){return this.element===this.element.window?r.viewportHeight():this.adapter.height()},e.prototype.remove=function(t){delete this.waypoints[t.axis][t.key],this.checkEmpty()},e.prototype.width=function(){return this.element===this.element.window?r.viewportWidth():this.adapter.width()},e.prototype.destroy=function(){var t=[];for(var e in this.waypoints)for(var i in this.waypoints[e])t.push(this.waypoints[e][i]);for(var o=0,r=t.length;r>o;o++)t[o].destroy()},e.prototype.refresh=function(){var t,e=this.element===this.element.window,i=this.adapter.offset(),o={};this.handleScroll(),t={horizontal:{contextOffset:e?0:i.left,contextScroll:e?0:this.oldScroll.x,contextDimension:this.width(),oldScroll:this.oldScroll.x,forward:"right",backward:"left",offsetProp:"left"},vertical:{contextOffset:e?0:i.top,contextScroll:e?0:this.oldScroll.y,contextDimension:this.height(),oldScroll:this.oldScroll.y,forward:"down",backward:"up",offsetProp:"top"}};for(var r in t){var n=t[r];for(var s in this.waypoints[r]){var a,h,l,p,c,u=this.waypoints[r][s],d=u.options.offset,f=u.triggerPoint,w=0,y=null==f;u.element!==u.element.window&&(w=u.adapter.offset()[n.offsetProp]),"function"==typeof d?d=d.apply(u):"string"==typeof d&&(d=parseFloat(d),u.options.offset.indexOf("%")>-1&&(d=Math.ceil(n.contextDimension*d/100))),a=n.contextScroll-n.contextOffset,u.triggerPoint=w+a-d,h=f=n.oldScroll,p=h&&l,c=!h&&!l,!y&&p?(u.queueTrigger(n.backward),o[u.group.id]=u.group):!y&&c?(u.queueTrigger(n.forward),o[u.group.id]=u.group):y&&n.oldScroll>=u.triggerPoint&&(u.queueTrigger(n.forward),o[u.group.id]=u.group)}}for(var g in o)o[g].flushTriggers();return this},e.findOrCreateByElement=function(t){return e.findByElement(t)||new e(t)},e.refreshAll=function(){for(var t in o)o[t].refresh()},e.findByElement=function(t){return o[t.waypointContextKey]},r.Context=e}())(function(){"use strict";function t(t,e){return t.triggerPoint-e.triggerPoint}function e(t,e){return e.triggerPoint-t.triggerPoint}function i(t){this.name=t.name,this.axis=t.axis,this.id=this.name+"-"+this.axis,this.waypoints=[],this.clearTriggerQueues(),o[this.axis][this.name]=this}var o={vertical:{},horizontal:{}},r=window.Waypoint;i.prototype.add=function(t){this.waypoints.push(t)},i.prototype.clearTriggerQueues=function(){this.triggerQueues={up:[],down:[],left:[],right:[]}},i.prototype.flushTriggers=function(){for(var i in this.triggerQueues){var o=this.triggerQueues[i],r="up"===i||"left"===i;o.sort(r?e:t);for(var n=0,s=o.length;s>n;n+=1){var a=o[n];(a.options.continuous||n===o.length-1)&&a.trigger([i])}}this.clearTriggerQueues()},i.prototype.next=function(e){this.waypoints.sort(t);var i=r.Adapter.inArray(e,this.waypoints),o=i===this.waypoints.length-1;return o?null:this.waypoints[i+1]},i.prototype.previous=function(e){this.waypoints.sort(t);var i=r.Adapter.inArray(e,this.waypoints);return i?this.waypoints[i-1]:null},i.prototype.queueTrigger=function(t,e){this.triggerQueues[e].push(t)},i.prototype.remove=function(t){var e=r.Adapter.inArray(t,this.waypoints);e>-1&&this.waypoints.splice(e,1)},i.prototype.first=function(){return this.waypoints[0]},i.prototype.last=function(){return this.waypoints[this.waypoints.length-1]},i.findOrCreate=function(t){return o[t.axis][t.name]||new i(t)},r.Group=i}())(function(){"use strict";function t(t){this.element=t,this.$element=e(t)}var e=window.Zepto,i=window.Waypoint;e.each(["height","off","on","scrollLeft","scrollTop","width"],function(e,i){t.prototype[i]=function(){var t=Array.prototype.slice.call(arguments);return this.$element[i].apply(this.$element,t)}}),t.prototype.offset=function(){return this.element!==this.element.window?this.$element.offset():void 0},e.each(["width","height"],function(i,o){var r=e.camelCase("outer-"+o);t.prototype[r]=function(t){var i=this.$element[o](),r={width:["left","right"],height:["top","bottom"]};return t&&e.each(r[o],e.proxy(function(t,e){i+=parseInt(this.$element.css("margin-"+e),10)},this)),i}}),e.each(["extend","inArray"],function(i,o){t[o]=e[o]}),t.isEmptyObject=function(t){for(var e in t)return!1;return!0},i.adapters.push({name:"zepto",Adapter:t}),i.Adapter=t}())(function(){"use strict";function t(t){return function(){var i=[],o=arguments[0];return t.isFunction(arguments[0])&&(o=t.extend({},arguments[1]),o.handler=arguments[0]),this.each(function(){var r=t.extend({},o,{element:this});"string"==typeof r.context&&(r.context=t(this).closest(r.context)[0]),i.push(new e(r))}),i}}var e=window.Waypoint;window.jQuery&&(window.jQuery.fn.waypoint=t(window.jQuery)),window.Zepto&&(window.Zepto.fn.waypoint=t(window.Zepto))}()); \ No newline at end of file +!function(){"use strict";function t(o){if(!o)throw new Error("No options passed to Waypoint constructor");if(!o.element)throw new Error("No element option passed to Waypoint constructor");this.key="waypoint-"+e,this.options=t.Adapter.extend({},t.defaults,o),this.element=this.options.element,this.adapter=new t.Adapter(this.element),this.callback=o.handler,this.axis=this.options.horizontal?"horizontal":"vertical",this.enabled=this.options.enabled,this.triggerPoint=null,this.group=t.Group.findOrCreate({name:this.options.group,axis:this.axis}),this.context=t.Context.findOrCreateByElement(this.options.context),t.offsetAliases[this.options.offset]&&(this.options.offset=t.offsetAliases[this.options.offset]),this.context.add(this),this.group.add(this),i[this.key]=this,e+=1}var e=0,i={};t.prototype.queueTrigger=function(t){this.group.queueTrigger(this,t)},t.prototype.trigger=function(t){this.enabled&&(this.callback&&this.callback.apply(this,t),this.options.triggerOnce&&this.destroy())},t.prototype.destroy=function(){this.context.remove(this),this.group.remove(this),delete i[this.key]},t.prototype.disable=function(){return this.enabled=!1,this},t.prototype.enable=function(){return this.context.refresh(),this.enabled=!0,this},t.prototype.next=function(){return this.group.next(this)},t.prototype.previous=function(){return this.group.previous(this)},t.destroyAll=function(){var t=[];for(var e in i)t.push(i[e]);for(var o=0,r=t.length;r>o;o++)t[o].destroy()},t.refreshAll=function(){t.Context.refreshAll()},t.viewportHeight=function(){return window.innerHeight||document.documentElement.clientHeight},t.viewportWidth=function(){return document.documentElement.clientWidth},t.adapters=[],t.defaults={context:window,continuous:!0,enabled:!0,group:"default",horizontal:!1,offset:0,triggerOnce:!1},t.offsetAliases={"bottom-in-view":function(){return this.context.height()-this.adapter.outerHeight()},"right-in-view":function(){return this.context.width()-this.adapter.outerWidth()}},window.Waypoint=t}(),function(){"use strict";function t(t){window.setTimeout(t,1e3/60)}function e(t){this.element=t,this.Adapter=r.Adapter,this.adapter=new this.Adapter(t),this.key="waypoint-context-"+i,this.didScroll=!1,this.didResize=!1,this.oldScroll={x:this.adapter.scrollLeft(),y:this.adapter.scrollTop()},this.waypoints={vertical:{},horizontal:{}},t.waypointContextKey=this.key,o[t.waypointContextKey]=this,i+=1,this.createThrottledScrollHandler(),this.createThrottledResizeHandler()}var i=0,o={},r=window.Waypoint,n=window.requestAnimationFrame||window.mozRequestAnimationFrame||window.webkitRequestAnimationFrame||t;e.prototype.add=function(t){var e=t.options.horizontal?"horizontal":"vertical";this.waypoints[e][t.key]=t,this.refresh()},e.prototype.checkEmpty=function(){var t=this.Adapter.isEmptyObject(this.waypoints.horizontal),e=this.Adapter.isEmptyObject(this.waypoints.vertical);t&&e&&(this.adapter.off(".waypoints"),delete o[this.key])},e.prototype.createThrottledResizeHandler=function(){function t(){e.handleResize(),e.didResize=!1}var e=this;this.adapter.on("resize.waypoints",function(){e.didResize||(e.didResize=!0,n(t))})},e.prototype.createThrottledScrollHandler=function(){function t(){e.handleScroll(),e.didScroll=!1}var e=this;this.adapter.on("scroll.waypoints",function(){(!e.didScroll||r.isTouch)&&(e.didScroll=!0,n(t))})},e.prototype.handleResize=function(){r.Context.refreshAll()},e.prototype.handleScroll=function(){var t={},e={horizontal:{newScroll:this.adapter.scrollLeft(),oldScroll:this.oldScroll.x,forward:"right",backward:"left"},vertical:{newScroll:this.adapter.scrollTop(),oldScroll:this.oldScroll.y,forward:"down",backward:"up"}};for(var i in e){var o=e[i],r=o.newScroll>o.oldScroll,n=r?o.forward:o.backward;for(var s in this.waypoints[i]){var a=this.waypoints[i][s],h=o.oldScroll=a.triggerPoint,p=h&&l,c=!h&&!l;(p||c)&&(a.queueTrigger(n),t[a.group.id]=a.group)}}for(var u in t)t[u].flushTriggers();this.oldScroll={x:e.horizontal.newScroll,y:e.vertical.newScroll}},e.prototype.height=function(){return this.element===this.element.window?r.viewportHeight():this.adapter.height()},e.prototype.remove=function(t){delete this.waypoints[t.axis][t.key],this.checkEmpty()},e.prototype.width=function(){return this.element===this.element.window?r.viewportWidth():this.adapter.width()},e.prototype.destroy=function(){var t=[];for(var e in this.waypoints)for(var i in this.waypoints[e])t.push(this.waypoints[e][i]);for(var o=0,r=t.length;r>o;o++)t[o].destroy()},e.prototype.refresh=function(){var t,e=this.element===this.element.window,i=this.adapter.offset(),o={};this.handleScroll(),t={horizontal:{contextOffset:e?0:i.left,contextScroll:e?0:this.oldScroll.x,contextDimension:this.width(),oldScroll:this.oldScroll.x,forward:"right",backward:"left",offsetProp:"left"},vertical:{contextOffset:e?0:i.top,contextScroll:e?0:this.oldScroll.y,contextDimension:this.height(),oldScroll:this.oldScroll.y,forward:"down",backward:"up",offsetProp:"top"}};for(var r in t){var n=t[r];for(var s in this.waypoints[r]){var a,h,l,p,c,u=this.waypoints[r][s],d=u.options.offset,f=u.triggerPoint,w=0,y=null==f;u.element!==u.element.window&&(w=u.adapter.offset()[n.offsetProp]),"function"==typeof d?d=d.apply(u):"string"==typeof d&&(d=parseFloat(d),u.options.offset.indexOf("%")>-1&&(d=Math.ceil(n.contextDimension*d/100))),a=n.contextScroll-n.contextOffset,u.triggerPoint=w+a-d,h=f=n.oldScroll,p=h&&l,c=!h&&!l,!y&&p?(u.queueTrigger(n.backward),o[u.group.id]=u.group):!y&&c?(u.queueTrigger(n.forward),o[u.group.id]=u.group):y&&n.oldScroll>=u.triggerPoint&&(u.queueTrigger(n.forward),o[u.group.id]=u.group)}}for(var g in o)o[g].flushTriggers();return this},e.findOrCreateByElement=function(t){return e.findByElement(t)||new e(t)},e.refreshAll=function(){for(var t in o)o[t].refresh()},e.findByElement=function(t){return o[t.waypointContextKey]},r.Context=e}(),function(){"use strict";function t(t,e){return t.triggerPoint-e.triggerPoint}function e(t,e){return e.triggerPoint-t.triggerPoint}function i(t){this.name=t.name,this.axis=t.axis,this.id=this.name+"-"+this.axis,this.waypoints=[],this.clearTriggerQueues(),o[this.axis][this.name]=this}var o={vertical:{},horizontal:{}},r=window.Waypoint;i.prototype.add=function(t){this.waypoints.push(t)},i.prototype.clearTriggerQueues=function(){this.triggerQueues={up:[],down:[],left:[],right:[]}},i.prototype.flushTriggers=function(){for(var i in this.triggerQueues){var o=this.triggerQueues[i],r="up"===i||"left"===i;o.sort(r?e:t);for(var n=0,s=o.length;s>n;n+=1){var a=o[n];(a.options.continuous||n===o.length-1)&&a.trigger([i])}}this.clearTriggerQueues()},i.prototype.next=function(e){this.waypoints.sort(t);var i=r.Adapter.inArray(e,this.waypoints),o=i===this.waypoints.length-1;return o?null:this.waypoints[i+1]},i.prototype.previous=function(e){this.waypoints.sort(t);var i=r.Adapter.inArray(e,this.waypoints);return i?this.waypoints[i-1]:null},i.prototype.queueTrigger=function(t,e){this.triggerQueues[e].push(t)},i.prototype.remove=function(t){var e=r.Adapter.inArray(t,this.waypoints);e>-1&&this.waypoints.splice(e,1)},i.prototype.first=function(){return this.waypoints[0]},i.prototype.last=function(){return this.waypoints[this.waypoints.length-1]},i.findOrCreate=function(t){return o[t.axis][t.name]||new i(t)},r.Group=i}(),function(){"use strict";function t(t){this.element=t,this.$element=e(t)}var e=window.Zepto,i=window.Waypoint;e.each(["height","off","on","scrollLeft","scrollTop","width"],function(e,i){t.prototype[i]=function(){var t=Array.prototype.slice.call(arguments);return this.$element[i].apply(this.$element,t)}}),t.prototype.offset=function(){return this.element!==this.element.window?this.$element.offset():void 0},e.each(["width","height"],function(i,o){var r=e.camelCase("outer-"+o);t.prototype[r]=function(t){var i=this.$element[o](),r={width:["left","right"],height:["top","bottom"]};return t&&e.each(r[o],e.proxy(function(t,e){i+=parseInt(this.$element.css("margin-"+e),10)},this)),i}}),e.each(["extend","inArray"],function(i,o){t[o]=e[o]}),t.isEmptyObject=function(t){for(var e in t)return!1;return!0},i.adapters.push({name:"zepto",Adapter:t}),i.Adapter=t}(),function(){"use strict";function t(t){return function(){var i=[],o=arguments[0];return t.isFunction(arguments[0])&&(o=t.extend({},arguments[1]),o.handler=arguments[0]),this.each(function(){var r=t.extend({},o,{element:this});"string"==typeof r.context&&(r.context=t(this).closest(r.context)[0]),i.push(new e(r))}),i}}var e=window.Waypoint;window.jQuery&&(window.jQuery.fn.waypoint=t(window.jQuery)),window.Zepto&&(window.Zepto.fn.waypoint=t(window.Zepto))}(); \ No newline at end of file From 381258808191a117050ffba2c98e7cda99481a13 Mon Sep 17 00:00:00 2001 From: imakewebthings Date: Wed, 3 Dec 2014 16:17:24 -0800 Subject: [PATCH 33/98] Run all specs --- testem.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/testem.json b/testem.json index afc38921..9e9ae955 100644 --- a/testem.json +++ b/testem.json @@ -18,6 +18,6 @@ "src/shortcuts/*.js", "test/settings.js", - "test/inview-spec.js" + "test/*-spec.js" ] } From a56a3539277da2eda0726138bec18b8bc4261a24 Mon Sep 17 00:00:00 2001 From: imakewebthings Date: Wed, 3 Dec 2014 16:18:49 -0800 Subject: [PATCH 34/98] Add waypoint to group before context on creation --- lib/jquery.waypoints.js | 2 +- lib/jquery.waypoints.min.js | 2 +- lib/noframework.waypoints.js | 2 +- lib/noframework.waypoints.min.js | 2 +- lib/zepto.waypoints.js | 2 +- lib/zepto.waypoints.min.js | 2 +- src/waypoint.js | 2 +- 7 files changed, 7 insertions(+), 7 deletions(-) diff --git a/lib/jquery.waypoints.js b/lib/jquery.waypoints.js index 6ee3ccf8..2b3126d3 100644 --- a/lib/jquery.waypoints.js +++ b/lib/jquery.waypoints.js @@ -35,8 +35,8 @@ https://github.com/imakewebthings/waypoints/blog/master/licenses.txt if (Waypoint.offsetAliases[this.options.offset]) { this.options.offset = Waypoint.offsetAliases[this.options.offset] } - this.context.add(this) this.group.add(this) + this.context.add(this) allWaypoints[this.key] = this keyCounter += 1 } diff --git a/lib/jquery.waypoints.min.js b/lib/jquery.waypoints.min.js index 74f3d682..5b36602b 100644 --- a/lib/jquery.waypoints.min.js +++ b/lib/jquery.waypoints.min.js @@ -4,4 +4,4 @@ Copyright © 2011-2014 Caleb Troughton Licensed under the MIT license. https://github.com/imakewebthings/waypoints/blog/master/licenses.txt */ -!function(){"use strict";function t(o){if(!o)throw new Error("No options passed to Waypoint constructor");if(!o.element)throw new Error("No element option passed to Waypoint constructor");this.key="waypoint-"+e,this.options=t.Adapter.extend({},t.defaults,o),this.element=this.options.element,this.adapter=new t.Adapter(this.element),this.callback=o.handler,this.axis=this.options.horizontal?"horizontal":"vertical",this.enabled=this.options.enabled,this.triggerPoint=null,this.group=t.Group.findOrCreate({name:this.options.group,axis:this.axis}),this.context=t.Context.findOrCreateByElement(this.options.context),t.offsetAliases[this.options.offset]&&(this.options.offset=t.offsetAliases[this.options.offset]),this.context.add(this),this.group.add(this),i[this.key]=this,e+=1}var e=0,i={};t.prototype.queueTrigger=function(t){this.group.queueTrigger(this,t)},t.prototype.trigger=function(t){this.enabled&&(this.callback&&this.callback.apply(this,t),this.options.triggerOnce&&this.destroy())},t.prototype.destroy=function(){this.context.remove(this),this.group.remove(this),delete i[this.key]},t.prototype.disable=function(){return this.enabled=!1,this},t.prototype.enable=function(){return this.context.refresh(),this.enabled=!0,this},t.prototype.next=function(){return this.group.next(this)},t.prototype.previous=function(){return this.group.previous(this)},t.destroyAll=function(){var t=[];for(var e in i)t.push(i[e]);for(var o=0,r=t.length;r>o;o++)t[o].destroy()},t.refreshAll=function(){t.Context.refreshAll()},t.viewportHeight=function(){return window.innerHeight||document.documentElement.clientHeight},t.viewportWidth=function(){return document.documentElement.clientWidth},t.adapters=[],t.defaults={context:window,continuous:!0,enabled:!0,group:"default",horizontal:!1,offset:0,triggerOnce:!1},t.offsetAliases={"bottom-in-view":function(){return this.context.height()-this.adapter.outerHeight()},"right-in-view":function(){return this.context.width()-this.adapter.outerWidth()}},window.Waypoint=t}(),function(){"use strict";function t(t){window.setTimeout(t,1e3/60)}function e(t){this.element=t,this.Adapter=r.Adapter,this.adapter=new this.Adapter(t),this.key="waypoint-context-"+i,this.didScroll=!1,this.didResize=!1,this.oldScroll={x:this.adapter.scrollLeft(),y:this.adapter.scrollTop()},this.waypoints={vertical:{},horizontal:{}},t.waypointContextKey=this.key,o[t.waypointContextKey]=this,i+=1,this.createThrottledScrollHandler(),this.createThrottledResizeHandler()}var i=0,o={},r=window.Waypoint,n=window.requestAnimationFrame||window.mozRequestAnimationFrame||window.webkitRequestAnimationFrame||t;e.prototype.add=function(t){var e=t.options.horizontal?"horizontal":"vertical";this.waypoints[e][t.key]=t,this.refresh()},e.prototype.checkEmpty=function(){var t=this.Adapter.isEmptyObject(this.waypoints.horizontal),e=this.Adapter.isEmptyObject(this.waypoints.vertical);t&&e&&(this.adapter.off(".waypoints"),delete o[this.key])},e.prototype.createThrottledResizeHandler=function(){function t(){e.handleResize(),e.didResize=!1}var e=this;this.adapter.on("resize.waypoints",function(){e.didResize||(e.didResize=!0,n(t))})},e.prototype.createThrottledScrollHandler=function(){function t(){e.handleScroll(),e.didScroll=!1}var e=this;this.adapter.on("scroll.waypoints",function(){(!e.didScroll||r.isTouch)&&(e.didScroll=!0,n(t))})},e.prototype.handleResize=function(){r.Context.refreshAll()},e.prototype.handleScroll=function(){var t={},e={horizontal:{newScroll:this.adapter.scrollLeft(),oldScroll:this.oldScroll.x,forward:"right",backward:"left"},vertical:{newScroll:this.adapter.scrollTop(),oldScroll:this.oldScroll.y,forward:"down",backward:"up"}};for(var i in e){var o=e[i],r=o.newScroll>o.oldScroll,n=r?o.forward:o.backward;for(var s in this.waypoints[i]){var a=this.waypoints[i][s],l=o.oldScroll=a.triggerPoint,p=l&&h,u=!l&&!h;(p||u)&&(a.queueTrigger(n),t[a.group.id]=a.group)}}for(var c in t)t[c].flushTriggers();this.oldScroll={x:e.horizontal.newScroll,y:e.vertical.newScroll}},e.prototype.height=function(){return this.element===this.element.window?r.viewportHeight():this.adapter.height()},e.prototype.remove=function(t){delete this.waypoints[t.axis][t.key],this.checkEmpty()},e.prototype.width=function(){return this.element===this.element.window?r.viewportWidth():this.adapter.width()},e.prototype.destroy=function(){var t=[];for(var e in this.waypoints)for(var i in this.waypoints[e])t.push(this.waypoints[e][i]);for(var o=0,r=t.length;r>o;o++)t[o].destroy()},e.prototype.refresh=function(){var t,e=this.element===this.element.window,i=this.adapter.offset(),o={};this.handleScroll(),t={horizontal:{contextOffset:e?0:i.left,contextScroll:e?0:this.oldScroll.x,contextDimension:this.width(),oldScroll:this.oldScroll.x,forward:"right",backward:"left",offsetProp:"left"},vertical:{contextOffset:e?0:i.top,contextScroll:e?0:this.oldScroll.y,contextDimension:this.height(),oldScroll:this.oldScroll.y,forward:"down",backward:"up",offsetProp:"top"}};for(var r in t){var n=t[r];for(var s in this.waypoints[r]){var a,l,h,p,u,c=this.waypoints[r][s],d=c.options.offset,f=c.triggerPoint,w=0,y=null==f;c.element!==c.element.window&&(w=c.adapter.offset()[n.offsetProp]),"function"==typeof d?d=d.apply(c):"string"==typeof d&&(d=parseFloat(d),c.options.offset.indexOf("%")>-1&&(d=Math.ceil(n.contextDimension*d/100))),a=n.contextScroll-n.contextOffset,c.triggerPoint=w+a-d,l=f=n.oldScroll,p=l&&h,u=!l&&!h,!y&&p?(c.queueTrigger(n.backward),o[c.group.id]=c.group):!y&&u?(c.queueTrigger(n.forward),o[c.group.id]=c.group):y&&n.oldScroll>=c.triggerPoint&&(c.queueTrigger(n.forward),o[c.group.id]=c.group)}}for(var g in o)o[g].flushTriggers();return this},e.findOrCreateByElement=function(t){return e.findByElement(t)||new e(t)},e.refreshAll=function(){for(var t in o)o[t].refresh()},e.findByElement=function(t){return o[t.waypointContextKey]},r.Context=e}(),function(){"use strict";function t(t,e){return t.triggerPoint-e.triggerPoint}function e(t,e){return e.triggerPoint-t.triggerPoint}function i(t){this.name=t.name,this.axis=t.axis,this.id=this.name+"-"+this.axis,this.waypoints=[],this.clearTriggerQueues(),o[this.axis][this.name]=this}var o={vertical:{},horizontal:{}},r=window.Waypoint;i.prototype.add=function(t){this.waypoints.push(t)},i.prototype.clearTriggerQueues=function(){this.triggerQueues={up:[],down:[],left:[],right:[]}},i.prototype.flushTriggers=function(){for(var i in this.triggerQueues){var o=this.triggerQueues[i],r="up"===i||"left"===i;o.sort(r?e:t);for(var n=0,s=o.length;s>n;n+=1){var a=o[n];(a.options.continuous||n===o.length-1)&&a.trigger([i])}}this.clearTriggerQueues()},i.prototype.next=function(e){this.waypoints.sort(t);var i=r.Adapter.inArray(e,this.waypoints),o=i===this.waypoints.length-1;return o?null:this.waypoints[i+1]},i.prototype.previous=function(e){this.waypoints.sort(t);var i=r.Adapter.inArray(e,this.waypoints);return i?this.waypoints[i-1]:null},i.prototype.queueTrigger=function(t,e){this.triggerQueues[e].push(t)},i.prototype.remove=function(t){var e=r.Adapter.inArray(t,this.waypoints);e>-1&&this.waypoints.splice(e,1)},i.prototype.first=function(){return this.waypoints[0]},i.prototype.last=function(){return this.waypoints[this.waypoints.length-1]},i.findOrCreate=function(t){return o[t.axis][t.name]||new i(t)},r.Group=i}(),function(){"use strict";function t(t){this.$element=e(t)}var e=window.jQuery,i=window.Waypoint;e.each(["height","off","offset","on","outerHeight","outerWidth","scrollLeft","scrollTop","width"],function(e,i){t.prototype[i]=function(){var t=Array.prototype.slice.call(arguments);return this.$element[i].apply(this.$element,t)}}),e.each(["extend","inArray","isEmptyObject"],function(i,o){t[o]=e[o]}),i.adapters.push({name:"jquery",Adapter:t}),i.Adapter=t}(),function(){"use strict";function t(t){return function(){var i=[],o=arguments[0];return t.isFunction(arguments[0])&&(o=t.extend({},arguments[1]),o.handler=arguments[0]),this.each(function(){var r=t.extend({},o,{element:this});"string"==typeof r.context&&(r.context=t(this).closest(r.context)[0]),i.push(new e(r))}),i}}var e=window.Waypoint;window.jQuery&&(window.jQuery.fn.waypoint=t(window.jQuery)),window.Zepto&&(window.Zepto.fn.waypoint=t(window.Zepto))}(); \ No newline at end of file +!function(){"use strict";function t(o){if(!o)throw new Error("No options passed to Waypoint constructor");if(!o.element)throw new Error("No element option passed to Waypoint constructor");this.key="waypoint-"+e,this.options=t.Adapter.extend({},t.defaults,o),this.element=this.options.element,this.adapter=new t.Adapter(this.element),this.callback=o.handler,this.axis=this.options.horizontal?"horizontal":"vertical",this.enabled=this.options.enabled,this.triggerPoint=null,this.group=t.Group.findOrCreate({name:this.options.group,axis:this.axis}),this.context=t.Context.findOrCreateByElement(this.options.context),t.offsetAliases[this.options.offset]&&(this.options.offset=t.offsetAliases[this.options.offset]),this.group.add(this),this.context.add(this),i[this.key]=this,e+=1}var e=0,i={};t.prototype.queueTrigger=function(t){this.group.queueTrigger(this,t)},t.prototype.trigger=function(t){this.enabled&&(this.callback&&this.callback.apply(this,t),this.options.triggerOnce&&this.destroy())},t.prototype.destroy=function(){this.context.remove(this),this.group.remove(this),delete i[this.key]},t.prototype.disable=function(){return this.enabled=!1,this},t.prototype.enable=function(){return this.context.refresh(),this.enabled=!0,this},t.prototype.next=function(){return this.group.next(this)},t.prototype.previous=function(){return this.group.previous(this)},t.destroyAll=function(){var t=[];for(var e in i)t.push(i[e]);for(var o=0,r=t.length;r>o;o++)t[o].destroy()},t.refreshAll=function(){t.Context.refreshAll()},t.viewportHeight=function(){return window.innerHeight||document.documentElement.clientHeight},t.viewportWidth=function(){return document.documentElement.clientWidth},t.adapters=[],t.defaults={context:window,continuous:!0,enabled:!0,group:"default",horizontal:!1,offset:0,triggerOnce:!1},t.offsetAliases={"bottom-in-view":function(){return this.context.height()-this.adapter.outerHeight()},"right-in-view":function(){return this.context.width()-this.adapter.outerWidth()}},window.Waypoint=t}(),function(){"use strict";function t(t){window.setTimeout(t,1e3/60)}function e(t){this.element=t,this.Adapter=r.Adapter,this.adapter=new this.Adapter(t),this.key="waypoint-context-"+i,this.didScroll=!1,this.didResize=!1,this.oldScroll={x:this.adapter.scrollLeft(),y:this.adapter.scrollTop()},this.waypoints={vertical:{},horizontal:{}},t.waypointContextKey=this.key,o[t.waypointContextKey]=this,i+=1,this.createThrottledScrollHandler(),this.createThrottledResizeHandler()}var i=0,o={},r=window.Waypoint,n=window.requestAnimationFrame||window.mozRequestAnimationFrame||window.webkitRequestAnimationFrame||t;e.prototype.add=function(t){var e=t.options.horizontal?"horizontal":"vertical";this.waypoints[e][t.key]=t,this.refresh()},e.prototype.checkEmpty=function(){var t=this.Adapter.isEmptyObject(this.waypoints.horizontal),e=this.Adapter.isEmptyObject(this.waypoints.vertical);t&&e&&(this.adapter.off(".waypoints"),delete o[this.key])},e.prototype.createThrottledResizeHandler=function(){function t(){e.handleResize(),e.didResize=!1}var e=this;this.adapter.on("resize.waypoints",function(){e.didResize||(e.didResize=!0,n(t))})},e.prototype.createThrottledScrollHandler=function(){function t(){e.handleScroll(),e.didScroll=!1}var e=this;this.adapter.on("scroll.waypoints",function(){(!e.didScroll||r.isTouch)&&(e.didScroll=!0,n(t))})},e.prototype.handleResize=function(){r.Context.refreshAll()},e.prototype.handleScroll=function(){var t={},e={horizontal:{newScroll:this.adapter.scrollLeft(),oldScroll:this.oldScroll.x,forward:"right",backward:"left"},vertical:{newScroll:this.adapter.scrollTop(),oldScroll:this.oldScroll.y,forward:"down",backward:"up"}};for(var i in e){var o=e[i],r=o.newScroll>o.oldScroll,n=r?o.forward:o.backward;for(var s in this.waypoints[i]){var a=this.waypoints[i][s],l=o.oldScroll=a.triggerPoint,p=l&&h,u=!l&&!h;(p||u)&&(a.queueTrigger(n),t[a.group.id]=a.group)}}for(var c in t)t[c].flushTriggers();this.oldScroll={x:e.horizontal.newScroll,y:e.vertical.newScroll}},e.prototype.height=function(){return this.element===this.element.window?r.viewportHeight():this.adapter.height()},e.prototype.remove=function(t){delete this.waypoints[t.axis][t.key],this.checkEmpty()},e.prototype.width=function(){return this.element===this.element.window?r.viewportWidth():this.adapter.width()},e.prototype.destroy=function(){var t=[];for(var e in this.waypoints)for(var i in this.waypoints[e])t.push(this.waypoints[e][i]);for(var o=0,r=t.length;r>o;o++)t[o].destroy()},e.prototype.refresh=function(){var t,e=this.element===this.element.window,i=this.adapter.offset(),o={};this.handleScroll(),t={horizontal:{contextOffset:e?0:i.left,contextScroll:e?0:this.oldScroll.x,contextDimension:this.width(),oldScroll:this.oldScroll.x,forward:"right",backward:"left",offsetProp:"left"},vertical:{contextOffset:e?0:i.top,contextScroll:e?0:this.oldScroll.y,contextDimension:this.height(),oldScroll:this.oldScroll.y,forward:"down",backward:"up",offsetProp:"top"}};for(var r in t){var n=t[r];for(var s in this.waypoints[r]){var a,l,h,p,u,c=this.waypoints[r][s],d=c.options.offset,f=c.triggerPoint,w=0,y=null==f;c.element!==c.element.window&&(w=c.adapter.offset()[n.offsetProp]),"function"==typeof d?d=d.apply(c):"string"==typeof d&&(d=parseFloat(d),c.options.offset.indexOf("%")>-1&&(d=Math.ceil(n.contextDimension*d/100))),a=n.contextScroll-n.contextOffset,c.triggerPoint=w+a-d,l=f=n.oldScroll,p=l&&h,u=!l&&!h,!y&&p?(c.queueTrigger(n.backward),o[c.group.id]=c.group):!y&&u?(c.queueTrigger(n.forward),o[c.group.id]=c.group):y&&n.oldScroll>=c.triggerPoint&&(c.queueTrigger(n.forward),o[c.group.id]=c.group)}}for(var g in o)o[g].flushTriggers();return this},e.findOrCreateByElement=function(t){return e.findByElement(t)||new e(t)},e.refreshAll=function(){for(var t in o)o[t].refresh()},e.findByElement=function(t){return o[t.waypointContextKey]},r.Context=e}(),function(){"use strict";function t(t,e){return t.triggerPoint-e.triggerPoint}function e(t,e){return e.triggerPoint-t.triggerPoint}function i(t){this.name=t.name,this.axis=t.axis,this.id=this.name+"-"+this.axis,this.waypoints=[],this.clearTriggerQueues(),o[this.axis][this.name]=this}var o={vertical:{},horizontal:{}},r=window.Waypoint;i.prototype.add=function(t){this.waypoints.push(t)},i.prototype.clearTriggerQueues=function(){this.triggerQueues={up:[],down:[],left:[],right:[]}},i.prototype.flushTriggers=function(){for(var i in this.triggerQueues){var o=this.triggerQueues[i],r="up"===i||"left"===i;o.sort(r?e:t);for(var n=0,s=o.length;s>n;n+=1){var a=o[n];(a.options.continuous||n===o.length-1)&&a.trigger([i])}}this.clearTriggerQueues()},i.prototype.next=function(e){this.waypoints.sort(t);var i=r.Adapter.inArray(e,this.waypoints),o=i===this.waypoints.length-1;return o?null:this.waypoints[i+1]},i.prototype.previous=function(e){this.waypoints.sort(t);var i=r.Adapter.inArray(e,this.waypoints);return i?this.waypoints[i-1]:null},i.prototype.queueTrigger=function(t,e){this.triggerQueues[e].push(t)},i.prototype.remove=function(t){var e=r.Adapter.inArray(t,this.waypoints);e>-1&&this.waypoints.splice(e,1)},i.prototype.first=function(){return this.waypoints[0]},i.prototype.last=function(){return this.waypoints[this.waypoints.length-1]},i.findOrCreate=function(t){return o[t.axis][t.name]||new i(t)},r.Group=i}(),function(){"use strict";function t(t){this.$element=e(t)}var e=window.jQuery,i=window.Waypoint;e.each(["height","off","offset","on","outerHeight","outerWidth","scrollLeft","scrollTop","width"],function(e,i){t.prototype[i]=function(){var t=Array.prototype.slice.call(arguments);return this.$element[i].apply(this.$element,t)}}),e.each(["extend","inArray","isEmptyObject"],function(i,o){t[o]=e[o]}),i.adapters.push({name:"jquery",Adapter:t}),i.Adapter=t}(),function(){"use strict";function t(t){return function(){var i=[],o=arguments[0];return t.isFunction(arguments[0])&&(o=t.extend({},arguments[1]),o.handler=arguments[0]),this.each(function(){var r=t.extend({},o,{element:this});"string"==typeof r.context&&(r.context=t(this).closest(r.context)[0]),i.push(new e(r))}),i}}var e=window.Waypoint;window.jQuery&&(window.jQuery.fn.waypoint=t(window.jQuery)),window.Zepto&&(window.Zepto.fn.waypoint=t(window.Zepto))}(); \ No newline at end of file diff --git a/lib/noframework.waypoints.js b/lib/noframework.waypoints.js index 009003fc..01a9f41a 100644 --- a/lib/noframework.waypoints.js +++ b/lib/noframework.waypoints.js @@ -35,8 +35,8 @@ https://github.com/imakewebthings/waypoints/blog/master/licenses.txt if (Waypoint.offsetAliases[this.options.offset]) { this.options.offset = Waypoint.offsetAliases[this.options.offset] } - this.context.add(this) this.group.add(this) + this.context.add(this) allWaypoints[this.key] = this keyCounter += 1 } diff --git a/lib/noframework.waypoints.min.js b/lib/noframework.waypoints.min.js index e1690eb5..7f582084 100644 --- a/lib/noframework.waypoints.min.js +++ b/lib/noframework.waypoints.min.js @@ -4,4 +4,4 @@ Copyright © 2011-2014 Caleb Troughton Licensed under the MIT license. https://github.com/imakewebthings/waypoints/blog/master/licenses.txt */ -!function(){"use strict";function t(o){if(!o)throw new Error("No options passed to Waypoint constructor");if(!o.element)throw new Error("No element option passed to Waypoint constructor");this.key="waypoint-"+e,this.options=t.Adapter.extend({},t.defaults,o),this.element=this.options.element,this.adapter=new t.Adapter(this.element),this.callback=o.handler,this.axis=this.options.horizontal?"horizontal":"vertical",this.enabled=this.options.enabled,this.triggerPoint=null,this.group=t.Group.findOrCreate({name:this.options.group,axis:this.axis}),this.context=t.Context.findOrCreateByElement(this.options.context),t.offsetAliases[this.options.offset]&&(this.options.offset=t.offsetAliases[this.options.offset]),this.context.add(this),this.group.add(this),i[this.key]=this,e+=1}var e=0,i={};t.prototype.queueTrigger=function(t){this.group.queueTrigger(this,t)},t.prototype.trigger=function(t){this.enabled&&(this.callback&&this.callback.apply(this,t),this.options.triggerOnce&&this.destroy())},t.prototype.destroy=function(){this.context.remove(this),this.group.remove(this),delete i[this.key]},t.prototype.disable=function(){return this.enabled=!1,this},t.prototype.enable=function(){return this.context.refresh(),this.enabled=!0,this},t.prototype.next=function(){return this.group.next(this)},t.prototype.previous=function(){return this.group.previous(this)},t.destroyAll=function(){var t=[];for(var e in i)t.push(i[e]);for(var o=0,r=t.length;r>o;o++)t[o].destroy()},t.refreshAll=function(){t.Context.refreshAll()},t.viewportHeight=function(){return window.innerHeight||document.documentElement.clientHeight},t.viewportWidth=function(){return document.documentElement.clientWidth},t.adapters=[],t.defaults={context:window,continuous:!0,enabled:!0,group:"default",horizontal:!1,offset:0,triggerOnce:!1},t.offsetAliases={"bottom-in-view":function(){return this.context.height()-this.adapter.outerHeight()},"right-in-view":function(){return this.context.width()-this.adapter.outerWidth()}},window.Waypoint=t}(),function(){"use strict";function t(t){window.setTimeout(t,1e3/60)}function e(t){this.element=t,this.Adapter=r.Adapter,this.adapter=new this.Adapter(t),this.key="waypoint-context-"+i,this.didScroll=!1,this.didResize=!1,this.oldScroll={x:this.adapter.scrollLeft(),y:this.adapter.scrollTop()},this.waypoints={vertical:{},horizontal:{}},t.waypointContextKey=this.key,o[t.waypointContextKey]=this,i+=1,this.createThrottledScrollHandler(),this.createThrottledResizeHandler()}var i=0,o={},r=window.Waypoint,n=window.requestAnimationFrame||window.mozRequestAnimationFrame||window.webkitRequestAnimationFrame||t;e.prototype.add=function(t){var e=t.options.horizontal?"horizontal":"vertical";this.waypoints[e][t.key]=t,this.refresh()},e.prototype.checkEmpty=function(){var t=this.Adapter.isEmptyObject(this.waypoints.horizontal),e=this.Adapter.isEmptyObject(this.waypoints.vertical);t&&e&&(this.adapter.off(".waypoints"),delete o[this.key])},e.prototype.createThrottledResizeHandler=function(){function t(){e.handleResize(),e.didResize=!1}var e=this;this.adapter.on("resize.waypoints",function(){e.didResize||(e.didResize=!0,n(t))})},e.prototype.createThrottledScrollHandler=function(){function t(){e.handleScroll(),e.didScroll=!1}var e=this;this.adapter.on("scroll.waypoints",function(){(!e.didScroll||r.isTouch)&&(e.didScroll=!0,n(t))})},e.prototype.handleResize=function(){r.Context.refreshAll()},e.prototype.handleScroll=function(){var t={},e={horizontal:{newScroll:this.adapter.scrollLeft(),oldScroll:this.oldScroll.x,forward:"right",backward:"left"},vertical:{newScroll:this.adapter.scrollTop(),oldScroll:this.oldScroll.y,forward:"down",backward:"up"}};for(var i in e){var o=e[i],r=o.newScroll>o.oldScroll,n=r?o.forward:o.backward;for(var s in this.waypoints[i]){var a=this.waypoints[i][s],l=o.oldScroll=a.triggerPoint,p=l&&h,u=!l&&!h;(p||u)&&(a.queueTrigger(n),t[a.group.id]=a.group)}}for(var f in t)t[f].flushTriggers();this.oldScroll={x:e.horizontal.newScroll,y:e.vertical.newScroll}},e.prototype.height=function(){return this.element===this.element.window?r.viewportHeight():this.adapter.height()},e.prototype.remove=function(t){delete this.waypoints[t.axis][t.key],this.checkEmpty()},e.prototype.width=function(){return this.element===this.element.window?r.viewportWidth():this.adapter.width()},e.prototype.destroy=function(){var t=[];for(var e in this.waypoints)for(var i in this.waypoints[e])t.push(this.waypoints[e][i]);for(var o=0,r=t.length;r>o;o++)t[o].destroy()},e.prototype.refresh=function(){var t,e=this.element===this.element.window,i=this.adapter.offset(),o={};this.handleScroll(),t={horizontal:{contextOffset:e?0:i.left,contextScroll:e?0:this.oldScroll.x,contextDimension:this.width(),oldScroll:this.oldScroll.x,forward:"right",backward:"left",offsetProp:"left"},vertical:{contextOffset:e?0:i.top,contextScroll:e?0:this.oldScroll.y,contextDimension:this.height(),oldScroll:this.oldScroll.y,forward:"down",backward:"up",offsetProp:"top"}};for(var r in t){var n=t[r];for(var s in this.waypoints[r]){var a,l,h,p,u,f=this.waypoints[r][s],c=f.options.offset,d=f.triggerPoint,g=0,y=null==d;f.element!==f.element.window&&(g=f.adapter.offset()[n.offsetProp]),"function"==typeof c?c=c.apply(f):"string"==typeof c&&(c=parseFloat(c),f.options.offset.indexOf("%")>-1&&(c=Math.ceil(n.contextDimension*c/100))),a=n.contextScroll-n.contextOffset,f.triggerPoint=g+a-c,l=d=n.oldScroll,p=l&&h,u=!l&&!h,!y&&p?(f.queueTrigger(n.backward),o[f.group.id]=f.group):!y&&u?(f.queueTrigger(n.forward),o[f.group.id]=f.group):y&&n.oldScroll>=f.triggerPoint&&(f.queueTrigger(n.forward),o[f.group.id]=f.group)}}for(var w in o)o[w].flushTriggers();return this},e.findOrCreateByElement=function(t){return e.findByElement(t)||new e(t)},e.refreshAll=function(){for(var t in o)o[t].refresh()},e.findByElement=function(t){return o[t.waypointContextKey]},r.Context=e}(),function(){"use strict";function t(t,e){return t.triggerPoint-e.triggerPoint}function e(t,e){return e.triggerPoint-t.triggerPoint}function i(t){this.name=t.name,this.axis=t.axis,this.id=this.name+"-"+this.axis,this.waypoints=[],this.clearTriggerQueues(),o[this.axis][this.name]=this}var o={vertical:{},horizontal:{}},r=window.Waypoint;i.prototype.add=function(t){this.waypoints.push(t)},i.prototype.clearTriggerQueues=function(){this.triggerQueues={up:[],down:[],left:[],right:[]}},i.prototype.flushTriggers=function(){for(var i in this.triggerQueues){var o=this.triggerQueues[i],r="up"===i||"left"===i;o.sort(r?e:t);for(var n=0,s=o.length;s>n;n+=1){var a=o[n];(a.options.continuous||n===o.length-1)&&a.trigger([i])}}this.clearTriggerQueues()},i.prototype.next=function(e){this.waypoints.sort(t);var i=r.Adapter.inArray(e,this.waypoints),o=i===this.waypoints.length-1;return o?null:this.waypoints[i+1]},i.prototype.previous=function(e){this.waypoints.sort(t);var i=r.Adapter.inArray(e,this.waypoints);return i?this.waypoints[i-1]:null},i.prototype.queueTrigger=function(t,e){this.triggerQueues[e].push(t)},i.prototype.remove=function(t){var e=r.Adapter.inArray(t,this.waypoints);e>-1&&this.waypoints.splice(e,1)},i.prototype.first=function(){return this.waypoints[0]},i.prototype.last=function(){return this.waypoints[this.waypoints.length-1]},i.findOrCreate=function(t){return o[t.axis][t.name]||new i(t)},r.Group=i}(),function(){"use strict";function t(t){return t===t.window}function e(e){return t(e)?e:e.defaultView}function i(t){this.element=t,this.handlers={}}var o=window.Waypoint;i.prototype.height=function(){var e=t(this.element);return e?this.element.innerHeight:this.element.offsetHeight},i.prototype.off=function(t,e){function i(t,e,i){for(var o=0,r=e.length-1;r>o;o++){var n=e[o];i&&i!==n||t.removeEventListener(n)}}var o=t.split("."),r=o[0],n=o[1],s=this.element;if(n&&this.handlers[n]&&r)i(s,this.handlers[n][r],e),this.handlers[n][r]=[];else if(r)for(var a in this.handlers)i(s,this.handlers[a][r]||[],e),this.handlers[a][r]=[];else if(n&&this.handlers[n]){for(var l in this.handlers[n])i(s,this.handlers[n][l],e);this.handlers[n]={}}},i.prototype.offset=function(){if(!this.element.ownerDocument)return null;var t=this.element.ownerDocument.documentElement,i=e(this.element.ownerDocument),o={top:0,left:0};return this.element.getBoundingClientRect&&(o=this.element.getBoundingClientRect()),{top:o.top+i.pageYOffset-t.clientTop,left:o.left+i.pageXOffset-t.clientLeft}},i.prototype.on=function(t,e){var i=t.split("."),o=i[0],r=i[1]||"__default",n=this.handlers[r]=this.handlers[r]||{},s=n[o]=n[o]||[];s.push(e),this.element.addEventListener(o,e)},i.prototype.outerHeight=function(e){var i,o=this.height();return e&&!t(this.element)&&(i=window.getComputedStyle(this.element),o+=parseInt(i.marginTop,10),o+=parseInt(i.marginBottom,10)),o},i.prototype.outerWidth=function(e){var i,o=this.width();return e&&!t(this.element)&&(i=window.getComputedStyle(this.element),o+=parseInt(i.marginLeft,10),o+=parseInt(i.marginRight,10)),o},i.prototype.scrollLeft=function(){var t=e(this.element);return t?t.pageXOffset:this.element.scrollLeft},i.prototype.scrollTop=function(){var t=e(this.element);return t?t.pageYOffset:this.element.scrollTop},i.prototype.width=function(){var e=t(this.element);return e?this.element.innerWidth:this.element.offsetWidth},i.extend=function(){function t(t,e){if("object"==typeof t&&"object"==typeof e)for(var i in e)e.hasOwnProperty(i)&&(t[i]=e[i]);return t}for(var e=Array.prototype.slice.call(arguments),i=1,o=e.length;o>i;i++)t(e[0],e[i]);return e[0]},i.inArray=function(t,e,i){return null==e?-1:e.indexOf(t,i)},i.isEmptyObject=function(t){for(var e in t)return!1;return!0},o.adapters.push({name:"noframework",Adapter:i}),o.Adapter=i}(); \ No newline at end of file +!function(){"use strict";function t(o){if(!o)throw new Error("No options passed to Waypoint constructor");if(!o.element)throw new Error("No element option passed to Waypoint constructor");this.key="waypoint-"+e,this.options=t.Adapter.extend({},t.defaults,o),this.element=this.options.element,this.adapter=new t.Adapter(this.element),this.callback=o.handler,this.axis=this.options.horizontal?"horizontal":"vertical",this.enabled=this.options.enabled,this.triggerPoint=null,this.group=t.Group.findOrCreate({name:this.options.group,axis:this.axis}),this.context=t.Context.findOrCreateByElement(this.options.context),t.offsetAliases[this.options.offset]&&(this.options.offset=t.offsetAliases[this.options.offset]),this.group.add(this),this.context.add(this),i[this.key]=this,e+=1}var e=0,i={};t.prototype.queueTrigger=function(t){this.group.queueTrigger(this,t)},t.prototype.trigger=function(t){this.enabled&&(this.callback&&this.callback.apply(this,t),this.options.triggerOnce&&this.destroy())},t.prototype.destroy=function(){this.context.remove(this),this.group.remove(this),delete i[this.key]},t.prototype.disable=function(){return this.enabled=!1,this},t.prototype.enable=function(){return this.context.refresh(),this.enabled=!0,this},t.prototype.next=function(){return this.group.next(this)},t.prototype.previous=function(){return this.group.previous(this)},t.destroyAll=function(){var t=[];for(var e in i)t.push(i[e]);for(var o=0,r=t.length;r>o;o++)t[o].destroy()},t.refreshAll=function(){t.Context.refreshAll()},t.viewportHeight=function(){return window.innerHeight||document.documentElement.clientHeight},t.viewportWidth=function(){return document.documentElement.clientWidth},t.adapters=[],t.defaults={context:window,continuous:!0,enabled:!0,group:"default",horizontal:!1,offset:0,triggerOnce:!1},t.offsetAliases={"bottom-in-view":function(){return this.context.height()-this.adapter.outerHeight()},"right-in-view":function(){return this.context.width()-this.adapter.outerWidth()}},window.Waypoint=t}(),function(){"use strict";function t(t){window.setTimeout(t,1e3/60)}function e(t){this.element=t,this.Adapter=r.Adapter,this.adapter=new this.Adapter(t),this.key="waypoint-context-"+i,this.didScroll=!1,this.didResize=!1,this.oldScroll={x:this.adapter.scrollLeft(),y:this.adapter.scrollTop()},this.waypoints={vertical:{},horizontal:{}},t.waypointContextKey=this.key,o[t.waypointContextKey]=this,i+=1,this.createThrottledScrollHandler(),this.createThrottledResizeHandler()}var i=0,o={},r=window.Waypoint,n=window.requestAnimationFrame||window.mozRequestAnimationFrame||window.webkitRequestAnimationFrame||t;e.prototype.add=function(t){var e=t.options.horizontal?"horizontal":"vertical";this.waypoints[e][t.key]=t,this.refresh()},e.prototype.checkEmpty=function(){var t=this.Adapter.isEmptyObject(this.waypoints.horizontal),e=this.Adapter.isEmptyObject(this.waypoints.vertical);t&&e&&(this.adapter.off(".waypoints"),delete o[this.key])},e.prototype.createThrottledResizeHandler=function(){function t(){e.handleResize(),e.didResize=!1}var e=this;this.adapter.on("resize.waypoints",function(){e.didResize||(e.didResize=!0,n(t))})},e.prototype.createThrottledScrollHandler=function(){function t(){e.handleScroll(),e.didScroll=!1}var e=this;this.adapter.on("scroll.waypoints",function(){(!e.didScroll||r.isTouch)&&(e.didScroll=!0,n(t))})},e.prototype.handleResize=function(){r.Context.refreshAll()},e.prototype.handleScroll=function(){var t={},e={horizontal:{newScroll:this.adapter.scrollLeft(),oldScroll:this.oldScroll.x,forward:"right",backward:"left"},vertical:{newScroll:this.adapter.scrollTop(),oldScroll:this.oldScroll.y,forward:"down",backward:"up"}};for(var i in e){var o=e[i],r=o.newScroll>o.oldScroll,n=r?o.forward:o.backward;for(var s in this.waypoints[i]){var a=this.waypoints[i][s],l=o.oldScroll=a.triggerPoint,p=l&&h,u=!l&&!h;(p||u)&&(a.queueTrigger(n),t[a.group.id]=a.group)}}for(var f in t)t[f].flushTriggers();this.oldScroll={x:e.horizontal.newScroll,y:e.vertical.newScroll}},e.prototype.height=function(){return this.element===this.element.window?r.viewportHeight():this.adapter.height()},e.prototype.remove=function(t){delete this.waypoints[t.axis][t.key],this.checkEmpty()},e.prototype.width=function(){return this.element===this.element.window?r.viewportWidth():this.adapter.width()},e.prototype.destroy=function(){var t=[];for(var e in this.waypoints)for(var i in this.waypoints[e])t.push(this.waypoints[e][i]);for(var o=0,r=t.length;r>o;o++)t[o].destroy()},e.prototype.refresh=function(){var t,e=this.element===this.element.window,i=this.adapter.offset(),o={};this.handleScroll(),t={horizontal:{contextOffset:e?0:i.left,contextScroll:e?0:this.oldScroll.x,contextDimension:this.width(),oldScroll:this.oldScroll.x,forward:"right",backward:"left",offsetProp:"left"},vertical:{contextOffset:e?0:i.top,contextScroll:e?0:this.oldScroll.y,contextDimension:this.height(),oldScroll:this.oldScroll.y,forward:"down",backward:"up",offsetProp:"top"}};for(var r in t){var n=t[r];for(var s in this.waypoints[r]){var a,l,h,p,u,f=this.waypoints[r][s],c=f.options.offset,d=f.triggerPoint,g=0,y=null==d;f.element!==f.element.window&&(g=f.adapter.offset()[n.offsetProp]),"function"==typeof c?c=c.apply(f):"string"==typeof c&&(c=parseFloat(c),f.options.offset.indexOf("%")>-1&&(c=Math.ceil(n.contextDimension*c/100))),a=n.contextScroll-n.contextOffset,f.triggerPoint=g+a-c,l=d=n.oldScroll,p=l&&h,u=!l&&!h,!y&&p?(f.queueTrigger(n.backward),o[f.group.id]=f.group):!y&&u?(f.queueTrigger(n.forward),o[f.group.id]=f.group):y&&n.oldScroll>=f.triggerPoint&&(f.queueTrigger(n.forward),o[f.group.id]=f.group)}}for(var w in o)o[w].flushTriggers();return this},e.findOrCreateByElement=function(t){return e.findByElement(t)||new e(t)},e.refreshAll=function(){for(var t in o)o[t].refresh()},e.findByElement=function(t){return o[t.waypointContextKey]},r.Context=e}(),function(){"use strict";function t(t,e){return t.triggerPoint-e.triggerPoint}function e(t,e){return e.triggerPoint-t.triggerPoint}function i(t){this.name=t.name,this.axis=t.axis,this.id=this.name+"-"+this.axis,this.waypoints=[],this.clearTriggerQueues(),o[this.axis][this.name]=this}var o={vertical:{},horizontal:{}},r=window.Waypoint;i.prototype.add=function(t){this.waypoints.push(t)},i.prototype.clearTriggerQueues=function(){this.triggerQueues={up:[],down:[],left:[],right:[]}},i.prototype.flushTriggers=function(){for(var i in this.triggerQueues){var o=this.triggerQueues[i],r="up"===i||"left"===i;o.sort(r?e:t);for(var n=0,s=o.length;s>n;n+=1){var a=o[n];(a.options.continuous||n===o.length-1)&&a.trigger([i])}}this.clearTriggerQueues()},i.prototype.next=function(e){this.waypoints.sort(t);var i=r.Adapter.inArray(e,this.waypoints),o=i===this.waypoints.length-1;return o?null:this.waypoints[i+1]},i.prototype.previous=function(e){this.waypoints.sort(t);var i=r.Adapter.inArray(e,this.waypoints);return i?this.waypoints[i-1]:null},i.prototype.queueTrigger=function(t,e){this.triggerQueues[e].push(t)},i.prototype.remove=function(t){var e=r.Adapter.inArray(t,this.waypoints);e>-1&&this.waypoints.splice(e,1)},i.prototype.first=function(){return this.waypoints[0]},i.prototype.last=function(){return this.waypoints[this.waypoints.length-1]},i.findOrCreate=function(t){return o[t.axis][t.name]||new i(t)},r.Group=i}(),function(){"use strict";function t(t){return t===t.window}function e(e){return t(e)?e:e.defaultView}function i(t){this.element=t,this.handlers={}}var o=window.Waypoint;i.prototype.height=function(){var e=t(this.element);return e?this.element.innerHeight:this.element.offsetHeight},i.prototype.off=function(t,e){function i(t,e,i){for(var o=0,r=e.length-1;r>o;o++){var n=e[o];i&&i!==n||t.removeEventListener(n)}}var o=t.split("."),r=o[0],n=o[1],s=this.element;if(n&&this.handlers[n]&&r)i(s,this.handlers[n][r],e),this.handlers[n][r]=[];else if(r)for(var a in this.handlers)i(s,this.handlers[a][r]||[],e),this.handlers[a][r]=[];else if(n&&this.handlers[n]){for(var l in this.handlers[n])i(s,this.handlers[n][l],e);this.handlers[n]={}}},i.prototype.offset=function(){if(!this.element.ownerDocument)return null;var t=this.element.ownerDocument.documentElement,i=e(this.element.ownerDocument),o={top:0,left:0};return this.element.getBoundingClientRect&&(o=this.element.getBoundingClientRect()),{top:o.top+i.pageYOffset-t.clientTop,left:o.left+i.pageXOffset-t.clientLeft}},i.prototype.on=function(t,e){var i=t.split("."),o=i[0],r=i[1]||"__default",n=this.handlers[r]=this.handlers[r]||{},s=n[o]=n[o]||[];s.push(e),this.element.addEventListener(o,e)},i.prototype.outerHeight=function(e){var i,o=this.height();return e&&!t(this.element)&&(i=window.getComputedStyle(this.element),o+=parseInt(i.marginTop,10),o+=parseInt(i.marginBottom,10)),o},i.prototype.outerWidth=function(e){var i,o=this.width();return e&&!t(this.element)&&(i=window.getComputedStyle(this.element),o+=parseInt(i.marginLeft,10),o+=parseInt(i.marginRight,10)),o},i.prototype.scrollLeft=function(){var t=e(this.element);return t?t.pageXOffset:this.element.scrollLeft},i.prototype.scrollTop=function(){var t=e(this.element);return t?t.pageYOffset:this.element.scrollTop},i.prototype.width=function(){var e=t(this.element);return e?this.element.innerWidth:this.element.offsetWidth},i.extend=function(){function t(t,e){if("object"==typeof t&&"object"==typeof e)for(var i in e)e.hasOwnProperty(i)&&(t[i]=e[i]);return t}for(var e=Array.prototype.slice.call(arguments),i=1,o=e.length;o>i;i++)t(e[0],e[i]);return e[0]},i.inArray=function(t,e,i){return null==e?-1:e.indexOf(t,i)},i.isEmptyObject=function(t){for(var e in t)return!1;return!0},o.adapters.push({name:"noframework",Adapter:i}),o.Adapter=i}(); \ No newline at end of file diff --git a/lib/zepto.waypoints.js b/lib/zepto.waypoints.js index 1d410ccb..d1a94829 100644 --- a/lib/zepto.waypoints.js +++ b/lib/zepto.waypoints.js @@ -35,8 +35,8 @@ https://github.com/imakewebthings/waypoints/blog/master/licenses.txt if (Waypoint.offsetAliases[this.options.offset]) { this.options.offset = Waypoint.offsetAliases[this.options.offset] } - this.context.add(this) this.group.add(this) + this.context.add(this) allWaypoints[this.key] = this keyCounter += 1 } diff --git a/lib/zepto.waypoints.min.js b/lib/zepto.waypoints.min.js index 2d7d3c4c..5c033490 100644 --- a/lib/zepto.waypoints.min.js +++ b/lib/zepto.waypoints.min.js @@ -4,4 +4,4 @@ Copyright © 2011-2014 Caleb Troughton Licensed under the MIT license. https://github.com/imakewebthings/waypoints/blog/master/licenses.txt */ -!function(){"use strict";function t(o){if(!o)throw new Error("No options passed to Waypoint constructor");if(!o.element)throw new Error("No element option passed to Waypoint constructor");this.key="waypoint-"+e,this.options=t.Adapter.extend({},t.defaults,o),this.element=this.options.element,this.adapter=new t.Adapter(this.element),this.callback=o.handler,this.axis=this.options.horizontal?"horizontal":"vertical",this.enabled=this.options.enabled,this.triggerPoint=null,this.group=t.Group.findOrCreate({name:this.options.group,axis:this.axis}),this.context=t.Context.findOrCreateByElement(this.options.context),t.offsetAliases[this.options.offset]&&(this.options.offset=t.offsetAliases[this.options.offset]),this.context.add(this),this.group.add(this),i[this.key]=this,e+=1}var e=0,i={};t.prototype.queueTrigger=function(t){this.group.queueTrigger(this,t)},t.prototype.trigger=function(t){this.enabled&&(this.callback&&this.callback.apply(this,t),this.options.triggerOnce&&this.destroy())},t.prototype.destroy=function(){this.context.remove(this),this.group.remove(this),delete i[this.key]},t.prototype.disable=function(){return this.enabled=!1,this},t.prototype.enable=function(){return this.context.refresh(),this.enabled=!0,this},t.prototype.next=function(){return this.group.next(this)},t.prototype.previous=function(){return this.group.previous(this)},t.destroyAll=function(){var t=[];for(var e in i)t.push(i[e]);for(var o=0,r=t.length;r>o;o++)t[o].destroy()},t.refreshAll=function(){t.Context.refreshAll()},t.viewportHeight=function(){return window.innerHeight||document.documentElement.clientHeight},t.viewportWidth=function(){return document.documentElement.clientWidth},t.adapters=[],t.defaults={context:window,continuous:!0,enabled:!0,group:"default",horizontal:!1,offset:0,triggerOnce:!1},t.offsetAliases={"bottom-in-view":function(){return this.context.height()-this.adapter.outerHeight()},"right-in-view":function(){return this.context.width()-this.adapter.outerWidth()}},window.Waypoint=t}(),function(){"use strict";function t(t){window.setTimeout(t,1e3/60)}function e(t){this.element=t,this.Adapter=r.Adapter,this.adapter=new this.Adapter(t),this.key="waypoint-context-"+i,this.didScroll=!1,this.didResize=!1,this.oldScroll={x:this.adapter.scrollLeft(),y:this.adapter.scrollTop()},this.waypoints={vertical:{},horizontal:{}},t.waypointContextKey=this.key,o[t.waypointContextKey]=this,i+=1,this.createThrottledScrollHandler(),this.createThrottledResizeHandler()}var i=0,o={},r=window.Waypoint,n=window.requestAnimationFrame||window.mozRequestAnimationFrame||window.webkitRequestAnimationFrame||t;e.prototype.add=function(t){var e=t.options.horizontal?"horizontal":"vertical";this.waypoints[e][t.key]=t,this.refresh()},e.prototype.checkEmpty=function(){var t=this.Adapter.isEmptyObject(this.waypoints.horizontal),e=this.Adapter.isEmptyObject(this.waypoints.vertical);t&&e&&(this.adapter.off(".waypoints"),delete o[this.key])},e.prototype.createThrottledResizeHandler=function(){function t(){e.handleResize(),e.didResize=!1}var e=this;this.adapter.on("resize.waypoints",function(){e.didResize||(e.didResize=!0,n(t))})},e.prototype.createThrottledScrollHandler=function(){function t(){e.handleScroll(),e.didScroll=!1}var e=this;this.adapter.on("scroll.waypoints",function(){(!e.didScroll||r.isTouch)&&(e.didScroll=!0,n(t))})},e.prototype.handleResize=function(){r.Context.refreshAll()},e.prototype.handleScroll=function(){var t={},e={horizontal:{newScroll:this.adapter.scrollLeft(),oldScroll:this.oldScroll.x,forward:"right",backward:"left"},vertical:{newScroll:this.adapter.scrollTop(),oldScroll:this.oldScroll.y,forward:"down",backward:"up"}};for(var i in e){var o=e[i],r=o.newScroll>o.oldScroll,n=r?o.forward:o.backward;for(var s in this.waypoints[i]){var a=this.waypoints[i][s],h=o.oldScroll=a.triggerPoint,p=h&&l,c=!h&&!l;(p||c)&&(a.queueTrigger(n),t[a.group.id]=a.group)}}for(var u in t)t[u].flushTriggers();this.oldScroll={x:e.horizontal.newScroll,y:e.vertical.newScroll}},e.prototype.height=function(){return this.element===this.element.window?r.viewportHeight():this.adapter.height()},e.prototype.remove=function(t){delete this.waypoints[t.axis][t.key],this.checkEmpty()},e.prototype.width=function(){return this.element===this.element.window?r.viewportWidth():this.adapter.width()},e.prototype.destroy=function(){var t=[];for(var e in this.waypoints)for(var i in this.waypoints[e])t.push(this.waypoints[e][i]);for(var o=0,r=t.length;r>o;o++)t[o].destroy()},e.prototype.refresh=function(){var t,e=this.element===this.element.window,i=this.adapter.offset(),o={};this.handleScroll(),t={horizontal:{contextOffset:e?0:i.left,contextScroll:e?0:this.oldScroll.x,contextDimension:this.width(),oldScroll:this.oldScroll.x,forward:"right",backward:"left",offsetProp:"left"},vertical:{contextOffset:e?0:i.top,contextScroll:e?0:this.oldScroll.y,contextDimension:this.height(),oldScroll:this.oldScroll.y,forward:"down",backward:"up",offsetProp:"top"}};for(var r in t){var n=t[r];for(var s in this.waypoints[r]){var a,h,l,p,c,u=this.waypoints[r][s],d=u.options.offset,f=u.triggerPoint,w=0,y=null==f;u.element!==u.element.window&&(w=u.adapter.offset()[n.offsetProp]),"function"==typeof d?d=d.apply(u):"string"==typeof d&&(d=parseFloat(d),u.options.offset.indexOf("%")>-1&&(d=Math.ceil(n.contextDimension*d/100))),a=n.contextScroll-n.contextOffset,u.triggerPoint=w+a-d,h=f=n.oldScroll,p=h&&l,c=!h&&!l,!y&&p?(u.queueTrigger(n.backward),o[u.group.id]=u.group):!y&&c?(u.queueTrigger(n.forward),o[u.group.id]=u.group):y&&n.oldScroll>=u.triggerPoint&&(u.queueTrigger(n.forward),o[u.group.id]=u.group)}}for(var g in o)o[g].flushTriggers();return this},e.findOrCreateByElement=function(t){return e.findByElement(t)||new e(t)},e.refreshAll=function(){for(var t in o)o[t].refresh()},e.findByElement=function(t){return o[t.waypointContextKey]},r.Context=e}(),function(){"use strict";function t(t,e){return t.triggerPoint-e.triggerPoint}function e(t,e){return e.triggerPoint-t.triggerPoint}function i(t){this.name=t.name,this.axis=t.axis,this.id=this.name+"-"+this.axis,this.waypoints=[],this.clearTriggerQueues(),o[this.axis][this.name]=this}var o={vertical:{},horizontal:{}},r=window.Waypoint;i.prototype.add=function(t){this.waypoints.push(t)},i.prototype.clearTriggerQueues=function(){this.triggerQueues={up:[],down:[],left:[],right:[]}},i.prototype.flushTriggers=function(){for(var i in this.triggerQueues){var o=this.triggerQueues[i],r="up"===i||"left"===i;o.sort(r?e:t);for(var n=0,s=o.length;s>n;n+=1){var a=o[n];(a.options.continuous||n===o.length-1)&&a.trigger([i])}}this.clearTriggerQueues()},i.prototype.next=function(e){this.waypoints.sort(t);var i=r.Adapter.inArray(e,this.waypoints),o=i===this.waypoints.length-1;return o?null:this.waypoints[i+1]},i.prototype.previous=function(e){this.waypoints.sort(t);var i=r.Adapter.inArray(e,this.waypoints);return i?this.waypoints[i-1]:null},i.prototype.queueTrigger=function(t,e){this.triggerQueues[e].push(t)},i.prototype.remove=function(t){var e=r.Adapter.inArray(t,this.waypoints);e>-1&&this.waypoints.splice(e,1)},i.prototype.first=function(){return this.waypoints[0]},i.prototype.last=function(){return this.waypoints[this.waypoints.length-1]},i.findOrCreate=function(t){return o[t.axis][t.name]||new i(t)},r.Group=i}(),function(){"use strict";function t(t){this.element=t,this.$element=e(t)}var e=window.Zepto,i=window.Waypoint;e.each(["height","off","on","scrollLeft","scrollTop","width"],function(e,i){t.prototype[i]=function(){var t=Array.prototype.slice.call(arguments);return this.$element[i].apply(this.$element,t)}}),t.prototype.offset=function(){return this.element!==this.element.window?this.$element.offset():void 0},e.each(["width","height"],function(i,o){var r=e.camelCase("outer-"+o);t.prototype[r]=function(t){var i=this.$element[o](),r={width:["left","right"],height:["top","bottom"]};return t&&e.each(r[o],e.proxy(function(t,e){i+=parseInt(this.$element.css("margin-"+e),10)},this)),i}}),e.each(["extend","inArray"],function(i,o){t[o]=e[o]}),t.isEmptyObject=function(t){for(var e in t)return!1;return!0},i.adapters.push({name:"zepto",Adapter:t}),i.Adapter=t}(),function(){"use strict";function t(t){return function(){var i=[],o=arguments[0];return t.isFunction(arguments[0])&&(o=t.extend({},arguments[1]),o.handler=arguments[0]),this.each(function(){var r=t.extend({},o,{element:this});"string"==typeof r.context&&(r.context=t(this).closest(r.context)[0]),i.push(new e(r))}),i}}var e=window.Waypoint;window.jQuery&&(window.jQuery.fn.waypoint=t(window.jQuery)),window.Zepto&&(window.Zepto.fn.waypoint=t(window.Zepto))}(); \ No newline at end of file +!function(){"use strict";function t(o){if(!o)throw new Error("No options passed to Waypoint constructor");if(!o.element)throw new Error("No element option passed to Waypoint constructor");this.key="waypoint-"+e,this.options=t.Adapter.extend({},t.defaults,o),this.element=this.options.element,this.adapter=new t.Adapter(this.element),this.callback=o.handler,this.axis=this.options.horizontal?"horizontal":"vertical",this.enabled=this.options.enabled,this.triggerPoint=null,this.group=t.Group.findOrCreate({name:this.options.group,axis:this.axis}),this.context=t.Context.findOrCreateByElement(this.options.context),t.offsetAliases[this.options.offset]&&(this.options.offset=t.offsetAliases[this.options.offset]),this.group.add(this),this.context.add(this),i[this.key]=this,e+=1}var e=0,i={};t.prototype.queueTrigger=function(t){this.group.queueTrigger(this,t)},t.prototype.trigger=function(t){this.enabled&&(this.callback&&this.callback.apply(this,t),this.options.triggerOnce&&this.destroy())},t.prototype.destroy=function(){this.context.remove(this),this.group.remove(this),delete i[this.key]},t.prototype.disable=function(){return this.enabled=!1,this},t.prototype.enable=function(){return this.context.refresh(),this.enabled=!0,this},t.prototype.next=function(){return this.group.next(this)},t.prototype.previous=function(){return this.group.previous(this)},t.destroyAll=function(){var t=[];for(var e in i)t.push(i[e]);for(var o=0,r=t.length;r>o;o++)t[o].destroy()},t.refreshAll=function(){t.Context.refreshAll()},t.viewportHeight=function(){return window.innerHeight||document.documentElement.clientHeight},t.viewportWidth=function(){return document.documentElement.clientWidth},t.adapters=[],t.defaults={context:window,continuous:!0,enabled:!0,group:"default",horizontal:!1,offset:0,triggerOnce:!1},t.offsetAliases={"bottom-in-view":function(){return this.context.height()-this.adapter.outerHeight()},"right-in-view":function(){return this.context.width()-this.adapter.outerWidth()}},window.Waypoint=t}(),function(){"use strict";function t(t){window.setTimeout(t,1e3/60)}function e(t){this.element=t,this.Adapter=r.Adapter,this.adapter=new this.Adapter(t),this.key="waypoint-context-"+i,this.didScroll=!1,this.didResize=!1,this.oldScroll={x:this.adapter.scrollLeft(),y:this.adapter.scrollTop()},this.waypoints={vertical:{},horizontal:{}},t.waypointContextKey=this.key,o[t.waypointContextKey]=this,i+=1,this.createThrottledScrollHandler(),this.createThrottledResizeHandler()}var i=0,o={},r=window.Waypoint,n=window.requestAnimationFrame||window.mozRequestAnimationFrame||window.webkitRequestAnimationFrame||t;e.prototype.add=function(t){var e=t.options.horizontal?"horizontal":"vertical";this.waypoints[e][t.key]=t,this.refresh()},e.prototype.checkEmpty=function(){var t=this.Adapter.isEmptyObject(this.waypoints.horizontal),e=this.Adapter.isEmptyObject(this.waypoints.vertical);t&&e&&(this.adapter.off(".waypoints"),delete o[this.key])},e.prototype.createThrottledResizeHandler=function(){function t(){e.handleResize(),e.didResize=!1}var e=this;this.adapter.on("resize.waypoints",function(){e.didResize||(e.didResize=!0,n(t))})},e.prototype.createThrottledScrollHandler=function(){function t(){e.handleScroll(),e.didScroll=!1}var e=this;this.adapter.on("scroll.waypoints",function(){(!e.didScroll||r.isTouch)&&(e.didScroll=!0,n(t))})},e.prototype.handleResize=function(){r.Context.refreshAll()},e.prototype.handleScroll=function(){var t={},e={horizontal:{newScroll:this.adapter.scrollLeft(),oldScroll:this.oldScroll.x,forward:"right",backward:"left"},vertical:{newScroll:this.adapter.scrollTop(),oldScroll:this.oldScroll.y,forward:"down",backward:"up"}};for(var i in e){var o=e[i],r=o.newScroll>o.oldScroll,n=r?o.forward:o.backward;for(var s in this.waypoints[i]){var a=this.waypoints[i][s],h=o.oldScroll=a.triggerPoint,p=h&&l,c=!h&&!l;(p||c)&&(a.queueTrigger(n),t[a.group.id]=a.group)}}for(var u in t)t[u].flushTriggers();this.oldScroll={x:e.horizontal.newScroll,y:e.vertical.newScroll}},e.prototype.height=function(){return this.element===this.element.window?r.viewportHeight():this.adapter.height()},e.prototype.remove=function(t){delete this.waypoints[t.axis][t.key],this.checkEmpty()},e.prototype.width=function(){return this.element===this.element.window?r.viewportWidth():this.adapter.width()},e.prototype.destroy=function(){var t=[];for(var e in this.waypoints)for(var i in this.waypoints[e])t.push(this.waypoints[e][i]);for(var o=0,r=t.length;r>o;o++)t[o].destroy()},e.prototype.refresh=function(){var t,e=this.element===this.element.window,i=this.adapter.offset(),o={};this.handleScroll(),t={horizontal:{contextOffset:e?0:i.left,contextScroll:e?0:this.oldScroll.x,contextDimension:this.width(),oldScroll:this.oldScroll.x,forward:"right",backward:"left",offsetProp:"left"},vertical:{contextOffset:e?0:i.top,contextScroll:e?0:this.oldScroll.y,contextDimension:this.height(),oldScroll:this.oldScroll.y,forward:"down",backward:"up",offsetProp:"top"}};for(var r in t){var n=t[r];for(var s in this.waypoints[r]){var a,h,l,p,c,u=this.waypoints[r][s],d=u.options.offset,f=u.triggerPoint,w=0,y=null==f;u.element!==u.element.window&&(w=u.adapter.offset()[n.offsetProp]),"function"==typeof d?d=d.apply(u):"string"==typeof d&&(d=parseFloat(d),u.options.offset.indexOf("%")>-1&&(d=Math.ceil(n.contextDimension*d/100))),a=n.contextScroll-n.contextOffset,u.triggerPoint=w+a-d,h=f=n.oldScroll,p=h&&l,c=!h&&!l,!y&&p?(u.queueTrigger(n.backward),o[u.group.id]=u.group):!y&&c?(u.queueTrigger(n.forward),o[u.group.id]=u.group):y&&n.oldScroll>=u.triggerPoint&&(u.queueTrigger(n.forward),o[u.group.id]=u.group)}}for(var g in o)o[g].flushTriggers();return this},e.findOrCreateByElement=function(t){return e.findByElement(t)||new e(t)},e.refreshAll=function(){for(var t in o)o[t].refresh()},e.findByElement=function(t){return o[t.waypointContextKey]},r.Context=e}(),function(){"use strict";function t(t,e){return t.triggerPoint-e.triggerPoint}function e(t,e){return e.triggerPoint-t.triggerPoint}function i(t){this.name=t.name,this.axis=t.axis,this.id=this.name+"-"+this.axis,this.waypoints=[],this.clearTriggerQueues(),o[this.axis][this.name]=this}var o={vertical:{},horizontal:{}},r=window.Waypoint;i.prototype.add=function(t){this.waypoints.push(t)},i.prototype.clearTriggerQueues=function(){this.triggerQueues={up:[],down:[],left:[],right:[]}},i.prototype.flushTriggers=function(){for(var i in this.triggerQueues){var o=this.triggerQueues[i],r="up"===i||"left"===i;o.sort(r?e:t);for(var n=0,s=o.length;s>n;n+=1){var a=o[n];(a.options.continuous||n===o.length-1)&&a.trigger([i])}}this.clearTriggerQueues()},i.prototype.next=function(e){this.waypoints.sort(t);var i=r.Adapter.inArray(e,this.waypoints),o=i===this.waypoints.length-1;return o?null:this.waypoints[i+1]},i.prototype.previous=function(e){this.waypoints.sort(t);var i=r.Adapter.inArray(e,this.waypoints);return i?this.waypoints[i-1]:null},i.prototype.queueTrigger=function(t,e){this.triggerQueues[e].push(t)},i.prototype.remove=function(t){var e=r.Adapter.inArray(t,this.waypoints);e>-1&&this.waypoints.splice(e,1)},i.prototype.first=function(){return this.waypoints[0]},i.prototype.last=function(){return this.waypoints[this.waypoints.length-1]},i.findOrCreate=function(t){return o[t.axis][t.name]||new i(t)},r.Group=i}(),function(){"use strict";function t(t){this.element=t,this.$element=e(t)}var e=window.Zepto,i=window.Waypoint;e.each(["height","off","on","scrollLeft","scrollTop","width"],function(e,i){t.prototype[i]=function(){var t=Array.prototype.slice.call(arguments);return this.$element[i].apply(this.$element,t)}}),t.prototype.offset=function(){return this.element!==this.element.window?this.$element.offset():void 0},e.each(["width","height"],function(i,o){var r=e.camelCase("outer-"+o);t.prototype[r]=function(t){var i=this.$element[o](),r={width:["left","right"],height:["top","bottom"]};return t&&e.each(r[o],e.proxy(function(t,e){i+=parseInt(this.$element.css("margin-"+e),10)},this)),i}}),e.each(["extend","inArray"],function(i,o){t[o]=e[o]}),t.isEmptyObject=function(t){for(var e in t)return!1;return!0},i.adapters.push({name:"zepto",Adapter:t}),i.Adapter=t}(),function(){"use strict";function t(t){return function(){var i=[],o=arguments[0];return t.isFunction(arguments[0])&&(o=t.extend({},arguments[1]),o.handler=arguments[0]),this.each(function(){var r=t.extend({},o,{element:this});"string"==typeof r.context&&(r.context=t(this).closest(r.context)[0]),i.push(new e(r))}),i}}var e=window.Waypoint;window.jQuery&&(window.jQuery.fn.waypoint=t(window.jQuery)),window.Zepto&&(window.Zepto.fn.waypoint=t(window.Zepto))}(); \ No newline at end of file diff --git a/src/waypoint.js b/src/waypoint.js index 01129132..8502b266 100644 --- a/src/waypoint.js +++ b/src/waypoint.js @@ -29,8 +29,8 @@ if (Waypoint.offsetAliases[this.options.offset]) { this.options.offset = Waypoint.offsetAliases[this.options.offset] } - this.context.add(this) this.group.add(this) + this.context.add(this) allWaypoints[this.key] = this keyCounter += 1 } From 16c55cffe56f1fc7cbf1404d25c8ee9982dfae26 Mon Sep 17 00:00:00 2001 From: imakewebthings Date: Wed, 3 Dec 2014 16:20:09 -0800 Subject: [PATCH 35/98] Remove triggerOnce option --- lib/jquery.waypoints.js | 6 +----- lib/jquery.waypoints.min.js | 2 +- lib/noframework.waypoints.js | 6 +----- lib/noframework.waypoints.min.js | 2 +- lib/zepto.waypoints.js | 6 +----- lib/zepto.waypoints.min.js | 2 +- src/waypoint.js | 6 +----- test/waypoint-spec.js | 16 ---------------- 8 files changed, 7 insertions(+), 39 deletions(-) diff --git a/lib/jquery.waypoints.js b/lib/jquery.waypoints.js index 2b3126d3..cd725cad 100644 --- a/lib/jquery.waypoints.js +++ b/lib/jquery.waypoints.js @@ -54,9 +54,6 @@ https://github.com/imakewebthings/waypoints/blog/master/licenses.txt if (this.callback) { this.callback.apply(this, args) } - if (this.options.triggerOnce) { - this.destroy() - } } /* Public */ @@ -123,8 +120,7 @@ https://github.com/imakewebthings/waypoints/blog/master/licenses.txt enabled: true, group: 'default', horizontal: false, - offset: 0, - triggerOnce: false + offset: 0 } Waypoint.offsetAliases = { diff --git a/lib/jquery.waypoints.min.js b/lib/jquery.waypoints.min.js index 5b36602b..86f0e419 100644 --- a/lib/jquery.waypoints.min.js +++ b/lib/jquery.waypoints.min.js @@ -4,4 +4,4 @@ Copyright © 2011-2014 Caleb Troughton Licensed under the MIT license. https://github.com/imakewebthings/waypoints/blog/master/licenses.txt */ -!function(){"use strict";function t(o){if(!o)throw new Error("No options passed to Waypoint constructor");if(!o.element)throw new Error("No element option passed to Waypoint constructor");this.key="waypoint-"+e,this.options=t.Adapter.extend({},t.defaults,o),this.element=this.options.element,this.adapter=new t.Adapter(this.element),this.callback=o.handler,this.axis=this.options.horizontal?"horizontal":"vertical",this.enabled=this.options.enabled,this.triggerPoint=null,this.group=t.Group.findOrCreate({name:this.options.group,axis:this.axis}),this.context=t.Context.findOrCreateByElement(this.options.context),t.offsetAliases[this.options.offset]&&(this.options.offset=t.offsetAliases[this.options.offset]),this.group.add(this),this.context.add(this),i[this.key]=this,e+=1}var e=0,i={};t.prototype.queueTrigger=function(t){this.group.queueTrigger(this,t)},t.prototype.trigger=function(t){this.enabled&&(this.callback&&this.callback.apply(this,t),this.options.triggerOnce&&this.destroy())},t.prototype.destroy=function(){this.context.remove(this),this.group.remove(this),delete i[this.key]},t.prototype.disable=function(){return this.enabled=!1,this},t.prototype.enable=function(){return this.context.refresh(),this.enabled=!0,this},t.prototype.next=function(){return this.group.next(this)},t.prototype.previous=function(){return this.group.previous(this)},t.destroyAll=function(){var t=[];for(var e in i)t.push(i[e]);for(var o=0,r=t.length;r>o;o++)t[o].destroy()},t.refreshAll=function(){t.Context.refreshAll()},t.viewportHeight=function(){return window.innerHeight||document.documentElement.clientHeight},t.viewportWidth=function(){return document.documentElement.clientWidth},t.adapters=[],t.defaults={context:window,continuous:!0,enabled:!0,group:"default",horizontal:!1,offset:0,triggerOnce:!1},t.offsetAliases={"bottom-in-view":function(){return this.context.height()-this.adapter.outerHeight()},"right-in-view":function(){return this.context.width()-this.adapter.outerWidth()}},window.Waypoint=t}(),function(){"use strict";function t(t){window.setTimeout(t,1e3/60)}function e(t){this.element=t,this.Adapter=r.Adapter,this.adapter=new this.Adapter(t),this.key="waypoint-context-"+i,this.didScroll=!1,this.didResize=!1,this.oldScroll={x:this.adapter.scrollLeft(),y:this.adapter.scrollTop()},this.waypoints={vertical:{},horizontal:{}},t.waypointContextKey=this.key,o[t.waypointContextKey]=this,i+=1,this.createThrottledScrollHandler(),this.createThrottledResizeHandler()}var i=0,o={},r=window.Waypoint,n=window.requestAnimationFrame||window.mozRequestAnimationFrame||window.webkitRequestAnimationFrame||t;e.prototype.add=function(t){var e=t.options.horizontal?"horizontal":"vertical";this.waypoints[e][t.key]=t,this.refresh()},e.prototype.checkEmpty=function(){var t=this.Adapter.isEmptyObject(this.waypoints.horizontal),e=this.Adapter.isEmptyObject(this.waypoints.vertical);t&&e&&(this.adapter.off(".waypoints"),delete o[this.key])},e.prototype.createThrottledResizeHandler=function(){function t(){e.handleResize(),e.didResize=!1}var e=this;this.adapter.on("resize.waypoints",function(){e.didResize||(e.didResize=!0,n(t))})},e.prototype.createThrottledScrollHandler=function(){function t(){e.handleScroll(),e.didScroll=!1}var e=this;this.adapter.on("scroll.waypoints",function(){(!e.didScroll||r.isTouch)&&(e.didScroll=!0,n(t))})},e.prototype.handleResize=function(){r.Context.refreshAll()},e.prototype.handleScroll=function(){var t={},e={horizontal:{newScroll:this.adapter.scrollLeft(),oldScroll:this.oldScroll.x,forward:"right",backward:"left"},vertical:{newScroll:this.adapter.scrollTop(),oldScroll:this.oldScroll.y,forward:"down",backward:"up"}};for(var i in e){var o=e[i],r=o.newScroll>o.oldScroll,n=r?o.forward:o.backward;for(var s in this.waypoints[i]){var a=this.waypoints[i][s],l=o.oldScroll=a.triggerPoint,p=l&&h,u=!l&&!h;(p||u)&&(a.queueTrigger(n),t[a.group.id]=a.group)}}for(var c in t)t[c].flushTriggers();this.oldScroll={x:e.horizontal.newScroll,y:e.vertical.newScroll}},e.prototype.height=function(){return this.element===this.element.window?r.viewportHeight():this.adapter.height()},e.prototype.remove=function(t){delete this.waypoints[t.axis][t.key],this.checkEmpty()},e.prototype.width=function(){return this.element===this.element.window?r.viewportWidth():this.adapter.width()},e.prototype.destroy=function(){var t=[];for(var e in this.waypoints)for(var i in this.waypoints[e])t.push(this.waypoints[e][i]);for(var o=0,r=t.length;r>o;o++)t[o].destroy()},e.prototype.refresh=function(){var t,e=this.element===this.element.window,i=this.adapter.offset(),o={};this.handleScroll(),t={horizontal:{contextOffset:e?0:i.left,contextScroll:e?0:this.oldScroll.x,contextDimension:this.width(),oldScroll:this.oldScroll.x,forward:"right",backward:"left",offsetProp:"left"},vertical:{contextOffset:e?0:i.top,contextScroll:e?0:this.oldScroll.y,contextDimension:this.height(),oldScroll:this.oldScroll.y,forward:"down",backward:"up",offsetProp:"top"}};for(var r in t){var n=t[r];for(var s in this.waypoints[r]){var a,l,h,p,u,c=this.waypoints[r][s],d=c.options.offset,f=c.triggerPoint,w=0,y=null==f;c.element!==c.element.window&&(w=c.adapter.offset()[n.offsetProp]),"function"==typeof d?d=d.apply(c):"string"==typeof d&&(d=parseFloat(d),c.options.offset.indexOf("%")>-1&&(d=Math.ceil(n.contextDimension*d/100))),a=n.contextScroll-n.contextOffset,c.triggerPoint=w+a-d,l=f=n.oldScroll,p=l&&h,u=!l&&!h,!y&&p?(c.queueTrigger(n.backward),o[c.group.id]=c.group):!y&&u?(c.queueTrigger(n.forward),o[c.group.id]=c.group):y&&n.oldScroll>=c.triggerPoint&&(c.queueTrigger(n.forward),o[c.group.id]=c.group)}}for(var g in o)o[g].flushTriggers();return this},e.findOrCreateByElement=function(t){return e.findByElement(t)||new e(t)},e.refreshAll=function(){for(var t in o)o[t].refresh()},e.findByElement=function(t){return o[t.waypointContextKey]},r.Context=e}(),function(){"use strict";function t(t,e){return t.triggerPoint-e.triggerPoint}function e(t,e){return e.triggerPoint-t.triggerPoint}function i(t){this.name=t.name,this.axis=t.axis,this.id=this.name+"-"+this.axis,this.waypoints=[],this.clearTriggerQueues(),o[this.axis][this.name]=this}var o={vertical:{},horizontal:{}},r=window.Waypoint;i.prototype.add=function(t){this.waypoints.push(t)},i.prototype.clearTriggerQueues=function(){this.triggerQueues={up:[],down:[],left:[],right:[]}},i.prototype.flushTriggers=function(){for(var i in this.triggerQueues){var o=this.triggerQueues[i],r="up"===i||"left"===i;o.sort(r?e:t);for(var n=0,s=o.length;s>n;n+=1){var a=o[n];(a.options.continuous||n===o.length-1)&&a.trigger([i])}}this.clearTriggerQueues()},i.prototype.next=function(e){this.waypoints.sort(t);var i=r.Adapter.inArray(e,this.waypoints),o=i===this.waypoints.length-1;return o?null:this.waypoints[i+1]},i.prototype.previous=function(e){this.waypoints.sort(t);var i=r.Adapter.inArray(e,this.waypoints);return i?this.waypoints[i-1]:null},i.prototype.queueTrigger=function(t,e){this.triggerQueues[e].push(t)},i.prototype.remove=function(t){var e=r.Adapter.inArray(t,this.waypoints);e>-1&&this.waypoints.splice(e,1)},i.prototype.first=function(){return this.waypoints[0]},i.prototype.last=function(){return this.waypoints[this.waypoints.length-1]},i.findOrCreate=function(t){return o[t.axis][t.name]||new i(t)},r.Group=i}(),function(){"use strict";function t(t){this.$element=e(t)}var e=window.jQuery,i=window.Waypoint;e.each(["height","off","offset","on","outerHeight","outerWidth","scrollLeft","scrollTop","width"],function(e,i){t.prototype[i]=function(){var t=Array.prototype.slice.call(arguments);return this.$element[i].apply(this.$element,t)}}),e.each(["extend","inArray","isEmptyObject"],function(i,o){t[o]=e[o]}),i.adapters.push({name:"jquery",Adapter:t}),i.Adapter=t}(),function(){"use strict";function t(t){return function(){var i=[],o=arguments[0];return t.isFunction(arguments[0])&&(o=t.extend({},arguments[1]),o.handler=arguments[0]),this.each(function(){var r=t.extend({},o,{element:this});"string"==typeof r.context&&(r.context=t(this).closest(r.context)[0]),i.push(new e(r))}),i}}var e=window.Waypoint;window.jQuery&&(window.jQuery.fn.waypoint=t(window.jQuery)),window.Zepto&&(window.Zepto.fn.waypoint=t(window.Zepto))}(); \ No newline at end of file +!function(){"use strict";function t(o){if(!o)throw new Error("No options passed to Waypoint constructor");if(!o.element)throw new Error("No element option passed to Waypoint constructor");this.key="waypoint-"+e,this.options=t.Adapter.extend({},t.defaults,o),this.element=this.options.element,this.adapter=new t.Adapter(this.element),this.callback=o.handler,this.axis=this.options.horizontal?"horizontal":"vertical",this.enabled=this.options.enabled,this.triggerPoint=null,this.group=t.Group.findOrCreate({name:this.options.group,axis:this.axis}),this.context=t.Context.findOrCreateByElement(this.options.context),t.offsetAliases[this.options.offset]&&(this.options.offset=t.offsetAliases[this.options.offset]),this.group.add(this),this.context.add(this),i[this.key]=this,e+=1}var e=0,i={};t.prototype.queueTrigger=function(t){this.group.queueTrigger(this,t)},t.prototype.trigger=function(t){this.enabled&&this.callback&&this.callback.apply(this,t)},t.prototype.destroy=function(){this.context.remove(this),this.group.remove(this),delete i[this.key]},t.prototype.disable=function(){return this.enabled=!1,this},t.prototype.enable=function(){return this.context.refresh(),this.enabled=!0,this},t.prototype.next=function(){return this.group.next(this)},t.prototype.previous=function(){return this.group.previous(this)},t.destroyAll=function(){var t=[];for(var e in i)t.push(i[e]);for(var o=0,r=t.length;r>o;o++)t[o].destroy()},t.refreshAll=function(){t.Context.refreshAll()},t.viewportHeight=function(){return window.innerHeight||document.documentElement.clientHeight},t.viewportWidth=function(){return document.documentElement.clientWidth},t.adapters=[],t.defaults={context:window,continuous:!0,enabled:!0,group:"default",horizontal:!1,offset:0},t.offsetAliases={"bottom-in-view":function(){return this.context.height()-this.adapter.outerHeight()},"right-in-view":function(){return this.context.width()-this.adapter.outerWidth()}},window.Waypoint=t}(),function(){"use strict";function t(t){window.setTimeout(t,1e3/60)}function e(t){this.element=t,this.Adapter=r.Adapter,this.adapter=new this.Adapter(t),this.key="waypoint-context-"+i,this.didScroll=!1,this.didResize=!1,this.oldScroll={x:this.adapter.scrollLeft(),y:this.adapter.scrollTop()},this.waypoints={vertical:{},horizontal:{}},t.waypointContextKey=this.key,o[t.waypointContextKey]=this,i+=1,this.createThrottledScrollHandler(),this.createThrottledResizeHandler()}var i=0,o={},r=window.Waypoint,n=window.requestAnimationFrame||window.mozRequestAnimationFrame||window.webkitRequestAnimationFrame||t;e.prototype.add=function(t){var e=t.options.horizontal?"horizontal":"vertical";this.waypoints[e][t.key]=t,this.refresh()},e.prototype.checkEmpty=function(){var t=this.Adapter.isEmptyObject(this.waypoints.horizontal),e=this.Adapter.isEmptyObject(this.waypoints.vertical);t&&e&&(this.adapter.off(".waypoints"),delete o[this.key])},e.prototype.createThrottledResizeHandler=function(){function t(){e.handleResize(),e.didResize=!1}var e=this;this.adapter.on("resize.waypoints",function(){e.didResize||(e.didResize=!0,n(t))})},e.prototype.createThrottledScrollHandler=function(){function t(){e.handleScroll(),e.didScroll=!1}var e=this;this.adapter.on("scroll.waypoints",function(){(!e.didScroll||r.isTouch)&&(e.didScroll=!0,n(t))})},e.prototype.handleResize=function(){r.Context.refreshAll()},e.prototype.handleScroll=function(){var t={},e={horizontal:{newScroll:this.adapter.scrollLeft(),oldScroll:this.oldScroll.x,forward:"right",backward:"left"},vertical:{newScroll:this.adapter.scrollTop(),oldScroll:this.oldScroll.y,forward:"down",backward:"up"}};for(var i in e){var o=e[i],r=o.newScroll>o.oldScroll,n=r?o.forward:o.backward;for(var s in this.waypoints[i]){var a=this.waypoints[i][s],l=o.oldScroll=a.triggerPoint,p=l&&h,u=!l&&!h;(p||u)&&(a.queueTrigger(n),t[a.group.id]=a.group)}}for(var c in t)t[c].flushTriggers();this.oldScroll={x:e.horizontal.newScroll,y:e.vertical.newScroll}},e.prototype.height=function(){return this.element===this.element.window?r.viewportHeight():this.adapter.height()},e.prototype.remove=function(t){delete this.waypoints[t.axis][t.key],this.checkEmpty()},e.prototype.width=function(){return this.element===this.element.window?r.viewportWidth():this.adapter.width()},e.prototype.destroy=function(){var t=[];for(var e in this.waypoints)for(var i in this.waypoints[e])t.push(this.waypoints[e][i]);for(var o=0,r=t.length;r>o;o++)t[o].destroy()},e.prototype.refresh=function(){var t,e=this.element===this.element.window,i=this.adapter.offset(),o={};this.handleScroll(),t={horizontal:{contextOffset:e?0:i.left,contextScroll:e?0:this.oldScroll.x,contextDimension:this.width(),oldScroll:this.oldScroll.x,forward:"right",backward:"left",offsetProp:"left"},vertical:{contextOffset:e?0:i.top,contextScroll:e?0:this.oldScroll.y,contextDimension:this.height(),oldScroll:this.oldScroll.y,forward:"down",backward:"up",offsetProp:"top"}};for(var r in t){var n=t[r];for(var s in this.waypoints[r]){var a,l,h,p,u,c=this.waypoints[r][s],d=c.options.offset,f=c.triggerPoint,w=0,y=null==f;c.element!==c.element.window&&(w=c.adapter.offset()[n.offsetProp]),"function"==typeof d?d=d.apply(c):"string"==typeof d&&(d=parseFloat(d),c.options.offset.indexOf("%")>-1&&(d=Math.ceil(n.contextDimension*d/100))),a=n.contextScroll-n.contextOffset,c.triggerPoint=w+a-d,l=f=n.oldScroll,p=l&&h,u=!l&&!h,!y&&p?(c.queueTrigger(n.backward),o[c.group.id]=c.group):!y&&u?(c.queueTrigger(n.forward),o[c.group.id]=c.group):y&&n.oldScroll>=c.triggerPoint&&(c.queueTrigger(n.forward),o[c.group.id]=c.group)}}for(var g in o)o[g].flushTriggers();return this},e.findOrCreateByElement=function(t){return e.findByElement(t)||new e(t)},e.refreshAll=function(){for(var t in o)o[t].refresh()},e.findByElement=function(t){return o[t.waypointContextKey]},r.Context=e}(),function(){"use strict";function t(t,e){return t.triggerPoint-e.triggerPoint}function e(t,e){return e.triggerPoint-t.triggerPoint}function i(t){this.name=t.name,this.axis=t.axis,this.id=this.name+"-"+this.axis,this.waypoints=[],this.clearTriggerQueues(),o[this.axis][this.name]=this}var o={vertical:{},horizontal:{}},r=window.Waypoint;i.prototype.add=function(t){this.waypoints.push(t)},i.prototype.clearTriggerQueues=function(){this.triggerQueues={up:[],down:[],left:[],right:[]}},i.prototype.flushTriggers=function(){for(var i in this.triggerQueues){var o=this.triggerQueues[i],r="up"===i||"left"===i;o.sort(r?e:t);for(var n=0,s=o.length;s>n;n+=1){var a=o[n];(a.options.continuous||n===o.length-1)&&a.trigger([i])}}this.clearTriggerQueues()},i.prototype.next=function(e){this.waypoints.sort(t);var i=r.Adapter.inArray(e,this.waypoints),o=i===this.waypoints.length-1;return o?null:this.waypoints[i+1]},i.prototype.previous=function(e){this.waypoints.sort(t);var i=r.Adapter.inArray(e,this.waypoints);return i?this.waypoints[i-1]:null},i.prototype.queueTrigger=function(t,e){this.triggerQueues[e].push(t)},i.prototype.remove=function(t){var e=r.Adapter.inArray(t,this.waypoints);e>-1&&this.waypoints.splice(e,1)},i.prototype.first=function(){return this.waypoints[0]},i.prototype.last=function(){return this.waypoints[this.waypoints.length-1]},i.findOrCreate=function(t){return o[t.axis][t.name]||new i(t)},r.Group=i}(),function(){"use strict";function t(t){this.$element=e(t)}var e=window.jQuery,i=window.Waypoint;e.each(["height","off","offset","on","outerHeight","outerWidth","scrollLeft","scrollTop","width"],function(e,i){t.prototype[i]=function(){var t=Array.prototype.slice.call(arguments);return this.$element[i].apply(this.$element,t)}}),e.each(["extend","inArray","isEmptyObject"],function(i,o){t[o]=e[o]}),i.adapters.push({name:"jquery",Adapter:t}),i.Adapter=t}(),function(){"use strict";function t(t){return function(){var i=[],o=arguments[0];return t.isFunction(arguments[0])&&(o=t.extend({},arguments[1]),o.handler=arguments[0]),this.each(function(){var r=t.extend({},o,{element:this});"string"==typeof r.context&&(r.context=t(this).closest(r.context)[0]),i.push(new e(r))}),i}}var e=window.Waypoint;window.jQuery&&(window.jQuery.fn.waypoint=t(window.jQuery)),window.Zepto&&(window.Zepto.fn.waypoint=t(window.Zepto))}(); \ No newline at end of file diff --git a/lib/noframework.waypoints.js b/lib/noframework.waypoints.js index 01a9f41a..82d5f3c9 100644 --- a/lib/noframework.waypoints.js +++ b/lib/noframework.waypoints.js @@ -54,9 +54,6 @@ https://github.com/imakewebthings/waypoints/blog/master/licenses.txt if (this.callback) { this.callback.apply(this, args) } - if (this.options.triggerOnce) { - this.destroy() - } } /* Public */ @@ -123,8 +120,7 @@ https://github.com/imakewebthings/waypoints/blog/master/licenses.txt enabled: true, group: 'default', horizontal: false, - offset: 0, - triggerOnce: false + offset: 0 } Waypoint.offsetAliases = { diff --git a/lib/noframework.waypoints.min.js b/lib/noframework.waypoints.min.js index 7f582084..a8421246 100644 --- a/lib/noframework.waypoints.min.js +++ b/lib/noframework.waypoints.min.js @@ -4,4 +4,4 @@ Copyright © 2011-2014 Caleb Troughton Licensed under the MIT license. https://github.com/imakewebthings/waypoints/blog/master/licenses.txt */ -!function(){"use strict";function t(o){if(!o)throw new Error("No options passed to Waypoint constructor");if(!o.element)throw new Error("No element option passed to Waypoint constructor");this.key="waypoint-"+e,this.options=t.Adapter.extend({},t.defaults,o),this.element=this.options.element,this.adapter=new t.Adapter(this.element),this.callback=o.handler,this.axis=this.options.horizontal?"horizontal":"vertical",this.enabled=this.options.enabled,this.triggerPoint=null,this.group=t.Group.findOrCreate({name:this.options.group,axis:this.axis}),this.context=t.Context.findOrCreateByElement(this.options.context),t.offsetAliases[this.options.offset]&&(this.options.offset=t.offsetAliases[this.options.offset]),this.group.add(this),this.context.add(this),i[this.key]=this,e+=1}var e=0,i={};t.prototype.queueTrigger=function(t){this.group.queueTrigger(this,t)},t.prototype.trigger=function(t){this.enabled&&(this.callback&&this.callback.apply(this,t),this.options.triggerOnce&&this.destroy())},t.prototype.destroy=function(){this.context.remove(this),this.group.remove(this),delete i[this.key]},t.prototype.disable=function(){return this.enabled=!1,this},t.prototype.enable=function(){return this.context.refresh(),this.enabled=!0,this},t.prototype.next=function(){return this.group.next(this)},t.prototype.previous=function(){return this.group.previous(this)},t.destroyAll=function(){var t=[];for(var e in i)t.push(i[e]);for(var o=0,r=t.length;r>o;o++)t[o].destroy()},t.refreshAll=function(){t.Context.refreshAll()},t.viewportHeight=function(){return window.innerHeight||document.documentElement.clientHeight},t.viewportWidth=function(){return document.documentElement.clientWidth},t.adapters=[],t.defaults={context:window,continuous:!0,enabled:!0,group:"default",horizontal:!1,offset:0,triggerOnce:!1},t.offsetAliases={"bottom-in-view":function(){return this.context.height()-this.adapter.outerHeight()},"right-in-view":function(){return this.context.width()-this.adapter.outerWidth()}},window.Waypoint=t}(),function(){"use strict";function t(t){window.setTimeout(t,1e3/60)}function e(t){this.element=t,this.Adapter=r.Adapter,this.adapter=new this.Adapter(t),this.key="waypoint-context-"+i,this.didScroll=!1,this.didResize=!1,this.oldScroll={x:this.adapter.scrollLeft(),y:this.adapter.scrollTop()},this.waypoints={vertical:{},horizontal:{}},t.waypointContextKey=this.key,o[t.waypointContextKey]=this,i+=1,this.createThrottledScrollHandler(),this.createThrottledResizeHandler()}var i=0,o={},r=window.Waypoint,n=window.requestAnimationFrame||window.mozRequestAnimationFrame||window.webkitRequestAnimationFrame||t;e.prototype.add=function(t){var e=t.options.horizontal?"horizontal":"vertical";this.waypoints[e][t.key]=t,this.refresh()},e.prototype.checkEmpty=function(){var t=this.Adapter.isEmptyObject(this.waypoints.horizontal),e=this.Adapter.isEmptyObject(this.waypoints.vertical);t&&e&&(this.adapter.off(".waypoints"),delete o[this.key])},e.prototype.createThrottledResizeHandler=function(){function t(){e.handleResize(),e.didResize=!1}var e=this;this.adapter.on("resize.waypoints",function(){e.didResize||(e.didResize=!0,n(t))})},e.prototype.createThrottledScrollHandler=function(){function t(){e.handleScroll(),e.didScroll=!1}var e=this;this.adapter.on("scroll.waypoints",function(){(!e.didScroll||r.isTouch)&&(e.didScroll=!0,n(t))})},e.prototype.handleResize=function(){r.Context.refreshAll()},e.prototype.handleScroll=function(){var t={},e={horizontal:{newScroll:this.adapter.scrollLeft(),oldScroll:this.oldScroll.x,forward:"right",backward:"left"},vertical:{newScroll:this.adapter.scrollTop(),oldScroll:this.oldScroll.y,forward:"down",backward:"up"}};for(var i in e){var o=e[i],r=o.newScroll>o.oldScroll,n=r?o.forward:o.backward;for(var s in this.waypoints[i]){var a=this.waypoints[i][s],l=o.oldScroll=a.triggerPoint,p=l&&h,u=!l&&!h;(p||u)&&(a.queueTrigger(n),t[a.group.id]=a.group)}}for(var f in t)t[f].flushTriggers();this.oldScroll={x:e.horizontal.newScroll,y:e.vertical.newScroll}},e.prototype.height=function(){return this.element===this.element.window?r.viewportHeight():this.adapter.height()},e.prototype.remove=function(t){delete this.waypoints[t.axis][t.key],this.checkEmpty()},e.prototype.width=function(){return this.element===this.element.window?r.viewportWidth():this.adapter.width()},e.prototype.destroy=function(){var t=[];for(var e in this.waypoints)for(var i in this.waypoints[e])t.push(this.waypoints[e][i]);for(var o=0,r=t.length;r>o;o++)t[o].destroy()},e.prototype.refresh=function(){var t,e=this.element===this.element.window,i=this.adapter.offset(),o={};this.handleScroll(),t={horizontal:{contextOffset:e?0:i.left,contextScroll:e?0:this.oldScroll.x,contextDimension:this.width(),oldScroll:this.oldScroll.x,forward:"right",backward:"left",offsetProp:"left"},vertical:{contextOffset:e?0:i.top,contextScroll:e?0:this.oldScroll.y,contextDimension:this.height(),oldScroll:this.oldScroll.y,forward:"down",backward:"up",offsetProp:"top"}};for(var r in t){var n=t[r];for(var s in this.waypoints[r]){var a,l,h,p,u,f=this.waypoints[r][s],c=f.options.offset,d=f.triggerPoint,g=0,y=null==d;f.element!==f.element.window&&(g=f.adapter.offset()[n.offsetProp]),"function"==typeof c?c=c.apply(f):"string"==typeof c&&(c=parseFloat(c),f.options.offset.indexOf("%")>-1&&(c=Math.ceil(n.contextDimension*c/100))),a=n.contextScroll-n.contextOffset,f.triggerPoint=g+a-c,l=d=n.oldScroll,p=l&&h,u=!l&&!h,!y&&p?(f.queueTrigger(n.backward),o[f.group.id]=f.group):!y&&u?(f.queueTrigger(n.forward),o[f.group.id]=f.group):y&&n.oldScroll>=f.triggerPoint&&(f.queueTrigger(n.forward),o[f.group.id]=f.group)}}for(var w in o)o[w].flushTriggers();return this},e.findOrCreateByElement=function(t){return e.findByElement(t)||new e(t)},e.refreshAll=function(){for(var t in o)o[t].refresh()},e.findByElement=function(t){return o[t.waypointContextKey]},r.Context=e}(),function(){"use strict";function t(t,e){return t.triggerPoint-e.triggerPoint}function e(t,e){return e.triggerPoint-t.triggerPoint}function i(t){this.name=t.name,this.axis=t.axis,this.id=this.name+"-"+this.axis,this.waypoints=[],this.clearTriggerQueues(),o[this.axis][this.name]=this}var o={vertical:{},horizontal:{}},r=window.Waypoint;i.prototype.add=function(t){this.waypoints.push(t)},i.prototype.clearTriggerQueues=function(){this.triggerQueues={up:[],down:[],left:[],right:[]}},i.prototype.flushTriggers=function(){for(var i in this.triggerQueues){var o=this.triggerQueues[i],r="up"===i||"left"===i;o.sort(r?e:t);for(var n=0,s=o.length;s>n;n+=1){var a=o[n];(a.options.continuous||n===o.length-1)&&a.trigger([i])}}this.clearTriggerQueues()},i.prototype.next=function(e){this.waypoints.sort(t);var i=r.Adapter.inArray(e,this.waypoints),o=i===this.waypoints.length-1;return o?null:this.waypoints[i+1]},i.prototype.previous=function(e){this.waypoints.sort(t);var i=r.Adapter.inArray(e,this.waypoints);return i?this.waypoints[i-1]:null},i.prototype.queueTrigger=function(t,e){this.triggerQueues[e].push(t)},i.prototype.remove=function(t){var e=r.Adapter.inArray(t,this.waypoints);e>-1&&this.waypoints.splice(e,1)},i.prototype.first=function(){return this.waypoints[0]},i.prototype.last=function(){return this.waypoints[this.waypoints.length-1]},i.findOrCreate=function(t){return o[t.axis][t.name]||new i(t)},r.Group=i}(),function(){"use strict";function t(t){return t===t.window}function e(e){return t(e)?e:e.defaultView}function i(t){this.element=t,this.handlers={}}var o=window.Waypoint;i.prototype.height=function(){var e=t(this.element);return e?this.element.innerHeight:this.element.offsetHeight},i.prototype.off=function(t,e){function i(t,e,i){for(var o=0,r=e.length-1;r>o;o++){var n=e[o];i&&i!==n||t.removeEventListener(n)}}var o=t.split("."),r=o[0],n=o[1],s=this.element;if(n&&this.handlers[n]&&r)i(s,this.handlers[n][r],e),this.handlers[n][r]=[];else if(r)for(var a in this.handlers)i(s,this.handlers[a][r]||[],e),this.handlers[a][r]=[];else if(n&&this.handlers[n]){for(var l in this.handlers[n])i(s,this.handlers[n][l],e);this.handlers[n]={}}},i.prototype.offset=function(){if(!this.element.ownerDocument)return null;var t=this.element.ownerDocument.documentElement,i=e(this.element.ownerDocument),o={top:0,left:0};return this.element.getBoundingClientRect&&(o=this.element.getBoundingClientRect()),{top:o.top+i.pageYOffset-t.clientTop,left:o.left+i.pageXOffset-t.clientLeft}},i.prototype.on=function(t,e){var i=t.split("."),o=i[0],r=i[1]||"__default",n=this.handlers[r]=this.handlers[r]||{},s=n[o]=n[o]||[];s.push(e),this.element.addEventListener(o,e)},i.prototype.outerHeight=function(e){var i,o=this.height();return e&&!t(this.element)&&(i=window.getComputedStyle(this.element),o+=parseInt(i.marginTop,10),o+=parseInt(i.marginBottom,10)),o},i.prototype.outerWidth=function(e){var i,o=this.width();return e&&!t(this.element)&&(i=window.getComputedStyle(this.element),o+=parseInt(i.marginLeft,10),o+=parseInt(i.marginRight,10)),o},i.prototype.scrollLeft=function(){var t=e(this.element);return t?t.pageXOffset:this.element.scrollLeft},i.prototype.scrollTop=function(){var t=e(this.element);return t?t.pageYOffset:this.element.scrollTop},i.prototype.width=function(){var e=t(this.element);return e?this.element.innerWidth:this.element.offsetWidth},i.extend=function(){function t(t,e){if("object"==typeof t&&"object"==typeof e)for(var i in e)e.hasOwnProperty(i)&&(t[i]=e[i]);return t}for(var e=Array.prototype.slice.call(arguments),i=1,o=e.length;o>i;i++)t(e[0],e[i]);return e[0]},i.inArray=function(t,e,i){return null==e?-1:e.indexOf(t,i)},i.isEmptyObject=function(t){for(var e in t)return!1;return!0},o.adapters.push({name:"noframework",Adapter:i}),o.Adapter=i}(); \ No newline at end of file +!function(){"use strict";function t(o){if(!o)throw new Error("No options passed to Waypoint constructor");if(!o.element)throw new Error("No element option passed to Waypoint constructor");this.key="waypoint-"+e,this.options=t.Adapter.extend({},t.defaults,o),this.element=this.options.element,this.adapter=new t.Adapter(this.element),this.callback=o.handler,this.axis=this.options.horizontal?"horizontal":"vertical",this.enabled=this.options.enabled,this.triggerPoint=null,this.group=t.Group.findOrCreate({name:this.options.group,axis:this.axis}),this.context=t.Context.findOrCreateByElement(this.options.context),t.offsetAliases[this.options.offset]&&(this.options.offset=t.offsetAliases[this.options.offset]),this.group.add(this),this.context.add(this),i[this.key]=this,e+=1}var e=0,i={};t.prototype.queueTrigger=function(t){this.group.queueTrigger(this,t)},t.prototype.trigger=function(t){this.enabled&&this.callback&&this.callback.apply(this,t)},t.prototype.destroy=function(){this.context.remove(this),this.group.remove(this),delete i[this.key]},t.prototype.disable=function(){return this.enabled=!1,this},t.prototype.enable=function(){return this.context.refresh(),this.enabled=!0,this},t.prototype.next=function(){return this.group.next(this)},t.prototype.previous=function(){return this.group.previous(this)},t.destroyAll=function(){var t=[];for(var e in i)t.push(i[e]);for(var o=0,r=t.length;r>o;o++)t[o].destroy()},t.refreshAll=function(){t.Context.refreshAll()},t.viewportHeight=function(){return window.innerHeight||document.documentElement.clientHeight},t.viewportWidth=function(){return document.documentElement.clientWidth},t.adapters=[],t.defaults={context:window,continuous:!0,enabled:!0,group:"default",horizontal:!1,offset:0},t.offsetAliases={"bottom-in-view":function(){return this.context.height()-this.adapter.outerHeight()},"right-in-view":function(){return this.context.width()-this.adapter.outerWidth()}},window.Waypoint=t}(),function(){"use strict";function t(t){window.setTimeout(t,1e3/60)}function e(t){this.element=t,this.Adapter=r.Adapter,this.adapter=new this.Adapter(t),this.key="waypoint-context-"+i,this.didScroll=!1,this.didResize=!1,this.oldScroll={x:this.adapter.scrollLeft(),y:this.adapter.scrollTop()},this.waypoints={vertical:{},horizontal:{}},t.waypointContextKey=this.key,o[t.waypointContextKey]=this,i+=1,this.createThrottledScrollHandler(),this.createThrottledResizeHandler()}var i=0,o={},r=window.Waypoint,n=window.requestAnimationFrame||window.mozRequestAnimationFrame||window.webkitRequestAnimationFrame||t;e.prototype.add=function(t){var e=t.options.horizontal?"horizontal":"vertical";this.waypoints[e][t.key]=t,this.refresh()},e.prototype.checkEmpty=function(){var t=this.Adapter.isEmptyObject(this.waypoints.horizontal),e=this.Adapter.isEmptyObject(this.waypoints.vertical);t&&e&&(this.adapter.off(".waypoints"),delete o[this.key])},e.prototype.createThrottledResizeHandler=function(){function t(){e.handleResize(),e.didResize=!1}var e=this;this.adapter.on("resize.waypoints",function(){e.didResize||(e.didResize=!0,n(t))})},e.prototype.createThrottledScrollHandler=function(){function t(){e.handleScroll(),e.didScroll=!1}var e=this;this.adapter.on("scroll.waypoints",function(){(!e.didScroll||r.isTouch)&&(e.didScroll=!0,n(t))})},e.prototype.handleResize=function(){r.Context.refreshAll()},e.prototype.handleScroll=function(){var t={},e={horizontal:{newScroll:this.adapter.scrollLeft(),oldScroll:this.oldScroll.x,forward:"right",backward:"left"},vertical:{newScroll:this.adapter.scrollTop(),oldScroll:this.oldScroll.y,forward:"down",backward:"up"}};for(var i in e){var o=e[i],r=o.newScroll>o.oldScroll,n=r?o.forward:o.backward;for(var s in this.waypoints[i]){var a=this.waypoints[i][s],l=o.oldScroll=a.triggerPoint,p=l&&h,u=!l&&!h;(p||u)&&(a.queueTrigger(n),t[a.group.id]=a.group)}}for(var f in t)t[f].flushTriggers();this.oldScroll={x:e.horizontal.newScroll,y:e.vertical.newScroll}},e.prototype.height=function(){return this.element===this.element.window?r.viewportHeight():this.adapter.height()},e.prototype.remove=function(t){delete this.waypoints[t.axis][t.key],this.checkEmpty()},e.prototype.width=function(){return this.element===this.element.window?r.viewportWidth():this.adapter.width()},e.prototype.destroy=function(){var t=[];for(var e in this.waypoints)for(var i in this.waypoints[e])t.push(this.waypoints[e][i]);for(var o=0,r=t.length;r>o;o++)t[o].destroy()},e.prototype.refresh=function(){var t,e=this.element===this.element.window,i=this.adapter.offset(),o={};this.handleScroll(),t={horizontal:{contextOffset:e?0:i.left,contextScroll:e?0:this.oldScroll.x,contextDimension:this.width(),oldScroll:this.oldScroll.x,forward:"right",backward:"left",offsetProp:"left"},vertical:{contextOffset:e?0:i.top,contextScroll:e?0:this.oldScroll.y,contextDimension:this.height(),oldScroll:this.oldScroll.y,forward:"down",backward:"up",offsetProp:"top"}};for(var r in t){var n=t[r];for(var s in this.waypoints[r]){var a,l,h,p,u,f=this.waypoints[r][s],c=f.options.offset,d=f.triggerPoint,y=0,g=null==d;f.element!==f.element.window&&(y=f.adapter.offset()[n.offsetProp]),"function"==typeof c?c=c.apply(f):"string"==typeof c&&(c=parseFloat(c),f.options.offset.indexOf("%")>-1&&(c=Math.ceil(n.contextDimension*c/100))),a=n.contextScroll-n.contextOffset,f.triggerPoint=y+a-c,l=d=n.oldScroll,p=l&&h,u=!l&&!h,!g&&p?(f.queueTrigger(n.backward),o[f.group.id]=f.group):!g&&u?(f.queueTrigger(n.forward),o[f.group.id]=f.group):g&&n.oldScroll>=f.triggerPoint&&(f.queueTrigger(n.forward),o[f.group.id]=f.group)}}for(var w in o)o[w].flushTriggers();return this},e.findOrCreateByElement=function(t){return e.findByElement(t)||new e(t)},e.refreshAll=function(){for(var t in o)o[t].refresh()},e.findByElement=function(t){return o[t.waypointContextKey]},r.Context=e}(),function(){"use strict";function t(t,e){return t.triggerPoint-e.triggerPoint}function e(t,e){return e.triggerPoint-t.triggerPoint}function i(t){this.name=t.name,this.axis=t.axis,this.id=this.name+"-"+this.axis,this.waypoints=[],this.clearTriggerQueues(),o[this.axis][this.name]=this}var o={vertical:{},horizontal:{}},r=window.Waypoint;i.prototype.add=function(t){this.waypoints.push(t)},i.prototype.clearTriggerQueues=function(){this.triggerQueues={up:[],down:[],left:[],right:[]}},i.prototype.flushTriggers=function(){for(var i in this.triggerQueues){var o=this.triggerQueues[i],r="up"===i||"left"===i;o.sort(r?e:t);for(var n=0,s=o.length;s>n;n+=1){var a=o[n];(a.options.continuous||n===o.length-1)&&a.trigger([i])}}this.clearTriggerQueues()},i.prototype.next=function(e){this.waypoints.sort(t);var i=r.Adapter.inArray(e,this.waypoints),o=i===this.waypoints.length-1;return o?null:this.waypoints[i+1]},i.prototype.previous=function(e){this.waypoints.sort(t);var i=r.Adapter.inArray(e,this.waypoints);return i?this.waypoints[i-1]:null},i.prototype.queueTrigger=function(t,e){this.triggerQueues[e].push(t)},i.prototype.remove=function(t){var e=r.Adapter.inArray(t,this.waypoints);e>-1&&this.waypoints.splice(e,1)},i.prototype.first=function(){return this.waypoints[0]},i.prototype.last=function(){return this.waypoints[this.waypoints.length-1]},i.findOrCreate=function(t){return o[t.axis][t.name]||new i(t)},r.Group=i}(),function(){"use strict";function t(t){return t===t.window}function e(e){return t(e)?e:e.defaultView}function i(t){this.element=t,this.handlers={}}var o=window.Waypoint;i.prototype.height=function(){var e=t(this.element);return e?this.element.innerHeight:this.element.offsetHeight},i.prototype.off=function(t,e){function i(t,e,i){for(var o=0,r=e.length-1;r>o;o++){var n=e[o];i&&i!==n||t.removeEventListener(n)}}var o=t.split("."),r=o[0],n=o[1],s=this.element;if(n&&this.handlers[n]&&r)i(s,this.handlers[n][r],e),this.handlers[n][r]=[];else if(r)for(var a in this.handlers)i(s,this.handlers[a][r]||[],e),this.handlers[a][r]=[];else if(n&&this.handlers[n]){for(var l in this.handlers[n])i(s,this.handlers[n][l],e);this.handlers[n]={}}},i.prototype.offset=function(){if(!this.element.ownerDocument)return null;var t=this.element.ownerDocument.documentElement,i=e(this.element.ownerDocument),o={top:0,left:0};return this.element.getBoundingClientRect&&(o=this.element.getBoundingClientRect()),{top:o.top+i.pageYOffset-t.clientTop,left:o.left+i.pageXOffset-t.clientLeft}},i.prototype.on=function(t,e){var i=t.split("."),o=i[0],r=i[1]||"__default",n=this.handlers[r]=this.handlers[r]||{},s=n[o]=n[o]||[];s.push(e),this.element.addEventListener(o,e)},i.prototype.outerHeight=function(e){var i,o=this.height();return e&&!t(this.element)&&(i=window.getComputedStyle(this.element),o+=parseInt(i.marginTop,10),o+=parseInt(i.marginBottom,10)),o},i.prototype.outerWidth=function(e){var i,o=this.width();return e&&!t(this.element)&&(i=window.getComputedStyle(this.element),o+=parseInt(i.marginLeft,10),o+=parseInt(i.marginRight,10)),o},i.prototype.scrollLeft=function(){var t=e(this.element);return t?t.pageXOffset:this.element.scrollLeft},i.prototype.scrollTop=function(){var t=e(this.element);return t?t.pageYOffset:this.element.scrollTop},i.prototype.width=function(){var e=t(this.element);return e?this.element.innerWidth:this.element.offsetWidth},i.extend=function(){function t(t,e){if("object"==typeof t&&"object"==typeof e)for(var i in e)e.hasOwnProperty(i)&&(t[i]=e[i]);return t}for(var e=Array.prototype.slice.call(arguments),i=1,o=e.length;o>i;i++)t(e[0],e[i]);return e[0]},i.inArray=function(t,e,i){return null==e?-1:e.indexOf(t,i)},i.isEmptyObject=function(t){for(var e in t)return!1;return!0},o.adapters.push({name:"noframework",Adapter:i}),o.Adapter=i}(); \ No newline at end of file diff --git a/lib/zepto.waypoints.js b/lib/zepto.waypoints.js index d1a94829..8ddd999d 100644 --- a/lib/zepto.waypoints.js +++ b/lib/zepto.waypoints.js @@ -54,9 +54,6 @@ https://github.com/imakewebthings/waypoints/blog/master/licenses.txt if (this.callback) { this.callback.apply(this, args) } - if (this.options.triggerOnce) { - this.destroy() - } } /* Public */ @@ -123,8 +120,7 @@ https://github.com/imakewebthings/waypoints/blog/master/licenses.txt enabled: true, group: 'default', horizontal: false, - offset: 0, - triggerOnce: false + offset: 0 } Waypoint.offsetAliases = { diff --git a/lib/zepto.waypoints.min.js b/lib/zepto.waypoints.min.js index 5c033490..a1ac3e41 100644 --- a/lib/zepto.waypoints.min.js +++ b/lib/zepto.waypoints.min.js @@ -4,4 +4,4 @@ Copyright © 2011-2014 Caleb Troughton Licensed under the MIT license. https://github.com/imakewebthings/waypoints/blog/master/licenses.txt */ -!function(){"use strict";function t(o){if(!o)throw new Error("No options passed to Waypoint constructor");if(!o.element)throw new Error("No element option passed to Waypoint constructor");this.key="waypoint-"+e,this.options=t.Adapter.extend({},t.defaults,o),this.element=this.options.element,this.adapter=new t.Adapter(this.element),this.callback=o.handler,this.axis=this.options.horizontal?"horizontal":"vertical",this.enabled=this.options.enabled,this.triggerPoint=null,this.group=t.Group.findOrCreate({name:this.options.group,axis:this.axis}),this.context=t.Context.findOrCreateByElement(this.options.context),t.offsetAliases[this.options.offset]&&(this.options.offset=t.offsetAliases[this.options.offset]),this.group.add(this),this.context.add(this),i[this.key]=this,e+=1}var e=0,i={};t.prototype.queueTrigger=function(t){this.group.queueTrigger(this,t)},t.prototype.trigger=function(t){this.enabled&&(this.callback&&this.callback.apply(this,t),this.options.triggerOnce&&this.destroy())},t.prototype.destroy=function(){this.context.remove(this),this.group.remove(this),delete i[this.key]},t.prototype.disable=function(){return this.enabled=!1,this},t.prototype.enable=function(){return this.context.refresh(),this.enabled=!0,this},t.prototype.next=function(){return this.group.next(this)},t.prototype.previous=function(){return this.group.previous(this)},t.destroyAll=function(){var t=[];for(var e in i)t.push(i[e]);for(var o=0,r=t.length;r>o;o++)t[o].destroy()},t.refreshAll=function(){t.Context.refreshAll()},t.viewportHeight=function(){return window.innerHeight||document.documentElement.clientHeight},t.viewportWidth=function(){return document.documentElement.clientWidth},t.adapters=[],t.defaults={context:window,continuous:!0,enabled:!0,group:"default",horizontal:!1,offset:0,triggerOnce:!1},t.offsetAliases={"bottom-in-view":function(){return this.context.height()-this.adapter.outerHeight()},"right-in-view":function(){return this.context.width()-this.adapter.outerWidth()}},window.Waypoint=t}(),function(){"use strict";function t(t){window.setTimeout(t,1e3/60)}function e(t){this.element=t,this.Adapter=r.Adapter,this.adapter=new this.Adapter(t),this.key="waypoint-context-"+i,this.didScroll=!1,this.didResize=!1,this.oldScroll={x:this.adapter.scrollLeft(),y:this.adapter.scrollTop()},this.waypoints={vertical:{},horizontal:{}},t.waypointContextKey=this.key,o[t.waypointContextKey]=this,i+=1,this.createThrottledScrollHandler(),this.createThrottledResizeHandler()}var i=0,o={},r=window.Waypoint,n=window.requestAnimationFrame||window.mozRequestAnimationFrame||window.webkitRequestAnimationFrame||t;e.prototype.add=function(t){var e=t.options.horizontal?"horizontal":"vertical";this.waypoints[e][t.key]=t,this.refresh()},e.prototype.checkEmpty=function(){var t=this.Adapter.isEmptyObject(this.waypoints.horizontal),e=this.Adapter.isEmptyObject(this.waypoints.vertical);t&&e&&(this.adapter.off(".waypoints"),delete o[this.key])},e.prototype.createThrottledResizeHandler=function(){function t(){e.handleResize(),e.didResize=!1}var e=this;this.adapter.on("resize.waypoints",function(){e.didResize||(e.didResize=!0,n(t))})},e.prototype.createThrottledScrollHandler=function(){function t(){e.handleScroll(),e.didScroll=!1}var e=this;this.adapter.on("scroll.waypoints",function(){(!e.didScroll||r.isTouch)&&(e.didScroll=!0,n(t))})},e.prototype.handleResize=function(){r.Context.refreshAll()},e.prototype.handleScroll=function(){var t={},e={horizontal:{newScroll:this.adapter.scrollLeft(),oldScroll:this.oldScroll.x,forward:"right",backward:"left"},vertical:{newScroll:this.adapter.scrollTop(),oldScroll:this.oldScroll.y,forward:"down",backward:"up"}};for(var i in e){var o=e[i],r=o.newScroll>o.oldScroll,n=r?o.forward:o.backward;for(var s in this.waypoints[i]){var a=this.waypoints[i][s],h=o.oldScroll=a.triggerPoint,p=h&&l,c=!h&&!l;(p||c)&&(a.queueTrigger(n),t[a.group.id]=a.group)}}for(var u in t)t[u].flushTriggers();this.oldScroll={x:e.horizontal.newScroll,y:e.vertical.newScroll}},e.prototype.height=function(){return this.element===this.element.window?r.viewportHeight():this.adapter.height()},e.prototype.remove=function(t){delete this.waypoints[t.axis][t.key],this.checkEmpty()},e.prototype.width=function(){return this.element===this.element.window?r.viewportWidth():this.adapter.width()},e.prototype.destroy=function(){var t=[];for(var e in this.waypoints)for(var i in this.waypoints[e])t.push(this.waypoints[e][i]);for(var o=0,r=t.length;r>o;o++)t[o].destroy()},e.prototype.refresh=function(){var t,e=this.element===this.element.window,i=this.adapter.offset(),o={};this.handleScroll(),t={horizontal:{contextOffset:e?0:i.left,contextScroll:e?0:this.oldScroll.x,contextDimension:this.width(),oldScroll:this.oldScroll.x,forward:"right",backward:"left",offsetProp:"left"},vertical:{contextOffset:e?0:i.top,contextScroll:e?0:this.oldScroll.y,contextDimension:this.height(),oldScroll:this.oldScroll.y,forward:"down",backward:"up",offsetProp:"top"}};for(var r in t){var n=t[r];for(var s in this.waypoints[r]){var a,h,l,p,c,u=this.waypoints[r][s],d=u.options.offset,f=u.triggerPoint,w=0,y=null==f;u.element!==u.element.window&&(w=u.adapter.offset()[n.offsetProp]),"function"==typeof d?d=d.apply(u):"string"==typeof d&&(d=parseFloat(d),u.options.offset.indexOf("%")>-1&&(d=Math.ceil(n.contextDimension*d/100))),a=n.contextScroll-n.contextOffset,u.triggerPoint=w+a-d,h=f=n.oldScroll,p=h&&l,c=!h&&!l,!y&&p?(u.queueTrigger(n.backward),o[u.group.id]=u.group):!y&&c?(u.queueTrigger(n.forward),o[u.group.id]=u.group):y&&n.oldScroll>=u.triggerPoint&&(u.queueTrigger(n.forward),o[u.group.id]=u.group)}}for(var g in o)o[g].flushTriggers();return this},e.findOrCreateByElement=function(t){return e.findByElement(t)||new e(t)},e.refreshAll=function(){for(var t in o)o[t].refresh()},e.findByElement=function(t){return o[t.waypointContextKey]},r.Context=e}(),function(){"use strict";function t(t,e){return t.triggerPoint-e.triggerPoint}function e(t,e){return e.triggerPoint-t.triggerPoint}function i(t){this.name=t.name,this.axis=t.axis,this.id=this.name+"-"+this.axis,this.waypoints=[],this.clearTriggerQueues(),o[this.axis][this.name]=this}var o={vertical:{},horizontal:{}},r=window.Waypoint;i.prototype.add=function(t){this.waypoints.push(t)},i.prototype.clearTriggerQueues=function(){this.triggerQueues={up:[],down:[],left:[],right:[]}},i.prototype.flushTriggers=function(){for(var i in this.triggerQueues){var o=this.triggerQueues[i],r="up"===i||"left"===i;o.sort(r?e:t);for(var n=0,s=o.length;s>n;n+=1){var a=o[n];(a.options.continuous||n===o.length-1)&&a.trigger([i])}}this.clearTriggerQueues()},i.prototype.next=function(e){this.waypoints.sort(t);var i=r.Adapter.inArray(e,this.waypoints),o=i===this.waypoints.length-1;return o?null:this.waypoints[i+1]},i.prototype.previous=function(e){this.waypoints.sort(t);var i=r.Adapter.inArray(e,this.waypoints);return i?this.waypoints[i-1]:null},i.prototype.queueTrigger=function(t,e){this.triggerQueues[e].push(t)},i.prototype.remove=function(t){var e=r.Adapter.inArray(t,this.waypoints);e>-1&&this.waypoints.splice(e,1)},i.prototype.first=function(){return this.waypoints[0]},i.prototype.last=function(){return this.waypoints[this.waypoints.length-1]},i.findOrCreate=function(t){return o[t.axis][t.name]||new i(t)},r.Group=i}(),function(){"use strict";function t(t){this.element=t,this.$element=e(t)}var e=window.Zepto,i=window.Waypoint;e.each(["height","off","on","scrollLeft","scrollTop","width"],function(e,i){t.prototype[i]=function(){var t=Array.prototype.slice.call(arguments);return this.$element[i].apply(this.$element,t)}}),t.prototype.offset=function(){return this.element!==this.element.window?this.$element.offset():void 0},e.each(["width","height"],function(i,o){var r=e.camelCase("outer-"+o);t.prototype[r]=function(t){var i=this.$element[o](),r={width:["left","right"],height:["top","bottom"]};return t&&e.each(r[o],e.proxy(function(t,e){i+=parseInt(this.$element.css("margin-"+e),10)},this)),i}}),e.each(["extend","inArray"],function(i,o){t[o]=e[o]}),t.isEmptyObject=function(t){for(var e in t)return!1;return!0},i.adapters.push({name:"zepto",Adapter:t}),i.Adapter=t}(),function(){"use strict";function t(t){return function(){var i=[],o=arguments[0];return t.isFunction(arguments[0])&&(o=t.extend({},arguments[1]),o.handler=arguments[0]),this.each(function(){var r=t.extend({},o,{element:this});"string"==typeof r.context&&(r.context=t(this).closest(r.context)[0]),i.push(new e(r))}),i}}var e=window.Waypoint;window.jQuery&&(window.jQuery.fn.waypoint=t(window.jQuery)),window.Zepto&&(window.Zepto.fn.waypoint=t(window.Zepto))}(); \ No newline at end of file +!function(){"use strict";function t(o){if(!o)throw new Error("No options passed to Waypoint constructor");if(!o.element)throw new Error("No element option passed to Waypoint constructor");this.key="waypoint-"+e,this.options=t.Adapter.extend({},t.defaults,o),this.element=this.options.element,this.adapter=new t.Adapter(this.element),this.callback=o.handler,this.axis=this.options.horizontal?"horizontal":"vertical",this.enabled=this.options.enabled,this.triggerPoint=null,this.group=t.Group.findOrCreate({name:this.options.group,axis:this.axis}),this.context=t.Context.findOrCreateByElement(this.options.context),t.offsetAliases[this.options.offset]&&(this.options.offset=t.offsetAliases[this.options.offset]),this.group.add(this),this.context.add(this),i[this.key]=this,e+=1}var e=0,i={};t.prototype.queueTrigger=function(t){this.group.queueTrigger(this,t)},t.prototype.trigger=function(t){this.enabled&&this.callback&&this.callback.apply(this,t)},t.prototype.destroy=function(){this.context.remove(this),this.group.remove(this),delete i[this.key]},t.prototype.disable=function(){return this.enabled=!1,this},t.prototype.enable=function(){return this.context.refresh(),this.enabled=!0,this},t.prototype.next=function(){return this.group.next(this)},t.prototype.previous=function(){return this.group.previous(this)},t.destroyAll=function(){var t=[];for(var e in i)t.push(i[e]);for(var o=0,r=t.length;r>o;o++)t[o].destroy()},t.refreshAll=function(){t.Context.refreshAll()},t.viewportHeight=function(){return window.innerHeight||document.documentElement.clientHeight},t.viewportWidth=function(){return document.documentElement.clientWidth},t.adapters=[],t.defaults={context:window,continuous:!0,enabled:!0,group:"default",horizontal:!1,offset:0},t.offsetAliases={"bottom-in-view":function(){return this.context.height()-this.adapter.outerHeight()},"right-in-view":function(){return this.context.width()-this.adapter.outerWidth()}},window.Waypoint=t}(),function(){"use strict";function t(t){window.setTimeout(t,1e3/60)}function e(t){this.element=t,this.Adapter=r.Adapter,this.adapter=new this.Adapter(t),this.key="waypoint-context-"+i,this.didScroll=!1,this.didResize=!1,this.oldScroll={x:this.adapter.scrollLeft(),y:this.adapter.scrollTop()},this.waypoints={vertical:{},horizontal:{}},t.waypointContextKey=this.key,o[t.waypointContextKey]=this,i+=1,this.createThrottledScrollHandler(),this.createThrottledResizeHandler()}var i=0,o={},r=window.Waypoint,n=window.requestAnimationFrame||window.mozRequestAnimationFrame||window.webkitRequestAnimationFrame||t;e.prototype.add=function(t){var e=t.options.horizontal?"horizontal":"vertical";this.waypoints[e][t.key]=t,this.refresh()},e.prototype.checkEmpty=function(){var t=this.Adapter.isEmptyObject(this.waypoints.horizontal),e=this.Adapter.isEmptyObject(this.waypoints.vertical);t&&e&&(this.adapter.off(".waypoints"),delete o[this.key])},e.prototype.createThrottledResizeHandler=function(){function t(){e.handleResize(),e.didResize=!1}var e=this;this.adapter.on("resize.waypoints",function(){e.didResize||(e.didResize=!0,n(t))})},e.prototype.createThrottledScrollHandler=function(){function t(){e.handleScroll(),e.didScroll=!1}var e=this;this.adapter.on("scroll.waypoints",function(){(!e.didScroll||r.isTouch)&&(e.didScroll=!0,n(t))})},e.prototype.handleResize=function(){r.Context.refreshAll()},e.prototype.handleScroll=function(){var t={},e={horizontal:{newScroll:this.adapter.scrollLeft(),oldScroll:this.oldScroll.x,forward:"right",backward:"left"},vertical:{newScroll:this.adapter.scrollTop(),oldScroll:this.oldScroll.y,forward:"down",backward:"up"}};for(var i in e){var o=e[i],r=o.newScroll>o.oldScroll,n=r?o.forward:o.backward;for(var s in this.waypoints[i]){var a=this.waypoints[i][s],h=o.oldScroll=a.triggerPoint,p=h&&l,c=!h&&!l;(p||c)&&(a.queueTrigger(n),t[a.group.id]=a.group)}}for(var u in t)t[u].flushTriggers();this.oldScroll={x:e.horizontal.newScroll,y:e.vertical.newScroll}},e.prototype.height=function(){return this.element===this.element.window?r.viewportHeight():this.adapter.height()},e.prototype.remove=function(t){delete this.waypoints[t.axis][t.key],this.checkEmpty()},e.prototype.width=function(){return this.element===this.element.window?r.viewportWidth():this.adapter.width()},e.prototype.destroy=function(){var t=[];for(var e in this.waypoints)for(var i in this.waypoints[e])t.push(this.waypoints[e][i]);for(var o=0,r=t.length;r>o;o++)t[o].destroy()},e.prototype.refresh=function(){var t,e=this.element===this.element.window,i=this.adapter.offset(),o={};this.handleScroll(),t={horizontal:{contextOffset:e?0:i.left,contextScroll:e?0:this.oldScroll.x,contextDimension:this.width(),oldScroll:this.oldScroll.x,forward:"right",backward:"left",offsetProp:"left"},vertical:{contextOffset:e?0:i.top,contextScroll:e?0:this.oldScroll.y,contextDimension:this.height(),oldScroll:this.oldScroll.y,forward:"down",backward:"up",offsetProp:"top"}};for(var r in t){var n=t[r];for(var s in this.waypoints[r]){var a,h,l,p,c,u=this.waypoints[r][s],d=u.options.offset,f=u.triggerPoint,w=0,y=null==f;u.element!==u.element.window&&(w=u.adapter.offset()[n.offsetProp]),"function"==typeof d?d=d.apply(u):"string"==typeof d&&(d=parseFloat(d),u.options.offset.indexOf("%")>-1&&(d=Math.ceil(n.contextDimension*d/100))),a=n.contextScroll-n.contextOffset,u.triggerPoint=w+a-d,h=f=n.oldScroll,p=h&&l,c=!h&&!l,!y&&p?(u.queueTrigger(n.backward),o[u.group.id]=u.group):!y&&c?(u.queueTrigger(n.forward),o[u.group.id]=u.group):y&&n.oldScroll>=u.triggerPoint&&(u.queueTrigger(n.forward),o[u.group.id]=u.group)}}for(var g in o)o[g].flushTriggers();return this},e.findOrCreateByElement=function(t){return e.findByElement(t)||new e(t)},e.refreshAll=function(){for(var t in o)o[t].refresh()},e.findByElement=function(t){return o[t.waypointContextKey]},r.Context=e}(),function(){"use strict";function t(t,e){return t.triggerPoint-e.triggerPoint}function e(t,e){return e.triggerPoint-t.triggerPoint}function i(t){this.name=t.name,this.axis=t.axis,this.id=this.name+"-"+this.axis,this.waypoints=[],this.clearTriggerQueues(),o[this.axis][this.name]=this}var o={vertical:{},horizontal:{}},r=window.Waypoint;i.prototype.add=function(t){this.waypoints.push(t)},i.prototype.clearTriggerQueues=function(){this.triggerQueues={up:[],down:[],left:[],right:[]}},i.prototype.flushTriggers=function(){for(var i in this.triggerQueues){var o=this.triggerQueues[i],r="up"===i||"left"===i;o.sort(r?e:t);for(var n=0,s=o.length;s>n;n+=1){var a=o[n];(a.options.continuous||n===o.length-1)&&a.trigger([i])}}this.clearTriggerQueues()},i.prototype.next=function(e){this.waypoints.sort(t);var i=r.Adapter.inArray(e,this.waypoints),o=i===this.waypoints.length-1;return o?null:this.waypoints[i+1]},i.prototype.previous=function(e){this.waypoints.sort(t);var i=r.Adapter.inArray(e,this.waypoints);return i?this.waypoints[i-1]:null},i.prototype.queueTrigger=function(t,e){this.triggerQueues[e].push(t)},i.prototype.remove=function(t){var e=r.Adapter.inArray(t,this.waypoints);e>-1&&this.waypoints.splice(e,1)},i.prototype.first=function(){return this.waypoints[0]},i.prototype.last=function(){return this.waypoints[this.waypoints.length-1]},i.findOrCreate=function(t){return o[t.axis][t.name]||new i(t)},r.Group=i}(),function(){"use strict";function t(t){this.element=t,this.$element=e(t)}var e=window.Zepto,i=window.Waypoint;e.each(["height","off","on","scrollLeft","scrollTop","width"],function(e,i){t.prototype[i]=function(){var t=Array.prototype.slice.call(arguments);return this.$element[i].apply(this.$element,t)}}),t.prototype.offset=function(){return this.element!==this.element.window?this.$element.offset():void 0},e.each(["width","height"],function(i,o){var r=e.camelCase("outer-"+o);t.prototype[r]=function(t){var i=this.$element[o](),r={width:["left","right"],height:["top","bottom"]};return t&&e.each(r[o],e.proxy(function(t,e){i+=parseInt(this.$element.css("margin-"+e),10)},this)),i}}),e.each(["extend","inArray"],function(i,o){t[o]=e[o]}),t.isEmptyObject=function(t){for(var e in t)return!1;return!0},i.adapters.push({name:"zepto",Adapter:t}),i.Adapter=t}(),function(){"use strict";function t(t){return function(){var i=[],o=arguments[0];return t.isFunction(arguments[0])&&(o=t.extend({},arguments[1]),o.handler=arguments[0]),this.each(function(){var r=t.extend({},o,{element:this});"string"==typeof r.context&&(r.context=t(this).closest(r.context)[0]),i.push(new e(r))}),i}}var e=window.Waypoint;window.jQuery&&(window.jQuery.fn.waypoint=t(window.jQuery)),window.Zepto&&(window.Zepto.fn.waypoint=t(window.Zepto))}(); \ No newline at end of file diff --git a/src/waypoint.js b/src/waypoint.js index 8502b266..2ee5dc3a 100644 --- a/src/waypoint.js +++ b/src/waypoint.js @@ -48,9 +48,6 @@ if (this.callback) { this.callback.apply(this, args) } - if (this.options.triggerOnce) { - this.destroy() - } } /* Public */ @@ -117,8 +114,7 @@ enabled: true, group: 'default', horizontal: false, - offset: 0, - triggerOnce: false + offset: 0 } Waypoint.offsetAliases = { diff --git a/test/waypoint-spec.js b/test/waypoint-spec.js index 3ff6c236..790caf18 100644 --- a/test/waypoint-spec.js +++ b/test/waypoint-spec.js @@ -184,22 +184,6 @@ window.jQuery.each(Waypoint.adapters, function(i, adapter) { }) }) - describe('triggerOnce option', function() { - it('destroys the waypoint after first trigger', function() { - runs(function() { - $target = $('#same1') - waypoint = new Waypoint({ - element: $target[0], - triggerOnce: true - }) - $scroller.scrollTop($target.offset().top) - }) - waitsFor(function() { - return !waypoint.context.waypoints.vertical[waypoint.key] - }, 'waypoint to be destroyed') - }) - }) - describe('context option', function() { beforeEach(function() { $scroller = $('#bottom') From 7038e892417371b5d5b38232555809162a478867 Mon Sep 17 00:00:00 2001 From: imakewebthings Date: Wed, 3 Dec 2014 16:31:47 -0800 Subject: [PATCH 36/98] Require the handler option --- lib/jquery.waypoints.js | 3 +++ lib/jquery.waypoints.min.js | 2 +- lib/noframework.waypoints.js | 3 +++ lib/noframework.waypoints.min.js | 2 +- lib/zepto.waypoints.js | 3 +++ lib/zepto.waypoints.min.js | 2 +- src/waypoint.js | 3 +++ test/adapter-fn-spec.js | 7 ++++--- test/context-spec.js | 3 ++- test/group-spec.js | 9 ++++++--- test/waypoint-spec.js | 21 +++++++++++++++++---- 11 files changed, 44 insertions(+), 14 deletions(-) diff --git a/lib/jquery.waypoints.js b/lib/jquery.waypoints.js index cd725cad..0d1e5aae 100644 --- a/lib/jquery.waypoints.js +++ b/lib/jquery.waypoints.js @@ -17,6 +17,9 @@ https://github.com/imakewebthings/waypoints/blog/master/licenses.txt if (!options.element) { throw new Error('No element option passed to Waypoint constructor') } + if (!options.handler) { + throw new Error('No handler option passed to Waypoint constructor') + } this.key = 'waypoint-' + keyCounter this.options = Waypoint.Adapter.extend({}, Waypoint.defaults, options) diff --git a/lib/jquery.waypoints.min.js b/lib/jquery.waypoints.min.js index 86f0e419..f2ac41e3 100644 --- a/lib/jquery.waypoints.min.js +++ b/lib/jquery.waypoints.min.js @@ -4,4 +4,4 @@ Copyright © 2011-2014 Caleb Troughton Licensed under the MIT license. https://github.com/imakewebthings/waypoints/blog/master/licenses.txt */ -!function(){"use strict";function t(o){if(!o)throw new Error("No options passed to Waypoint constructor");if(!o.element)throw new Error("No element option passed to Waypoint constructor");this.key="waypoint-"+e,this.options=t.Adapter.extend({},t.defaults,o),this.element=this.options.element,this.adapter=new t.Adapter(this.element),this.callback=o.handler,this.axis=this.options.horizontal?"horizontal":"vertical",this.enabled=this.options.enabled,this.triggerPoint=null,this.group=t.Group.findOrCreate({name:this.options.group,axis:this.axis}),this.context=t.Context.findOrCreateByElement(this.options.context),t.offsetAliases[this.options.offset]&&(this.options.offset=t.offsetAliases[this.options.offset]),this.group.add(this),this.context.add(this),i[this.key]=this,e+=1}var e=0,i={};t.prototype.queueTrigger=function(t){this.group.queueTrigger(this,t)},t.prototype.trigger=function(t){this.enabled&&this.callback&&this.callback.apply(this,t)},t.prototype.destroy=function(){this.context.remove(this),this.group.remove(this),delete i[this.key]},t.prototype.disable=function(){return this.enabled=!1,this},t.prototype.enable=function(){return this.context.refresh(),this.enabled=!0,this},t.prototype.next=function(){return this.group.next(this)},t.prototype.previous=function(){return this.group.previous(this)},t.destroyAll=function(){var t=[];for(var e in i)t.push(i[e]);for(var o=0,r=t.length;r>o;o++)t[o].destroy()},t.refreshAll=function(){t.Context.refreshAll()},t.viewportHeight=function(){return window.innerHeight||document.documentElement.clientHeight},t.viewportWidth=function(){return document.documentElement.clientWidth},t.adapters=[],t.defaults={context:window,continuous:!0,enabled:!0,group:"default",horizontal:!1,offset:0},t.offsetAliases={"bottom-in-view":function(){return this.context.height()-this.adapter.outerHeight()},"right-in-view":function(){return this.context.width()-this.adapter.outerWidth()}},window.Waypoint=t}(),function(){"use strict";function t(t){window.setTimeout(t,1e3/60)}function e(t){this.element=t,this.Adapter=r.Adapter,this.adapter=new this.Adapter(t),this.key="waypoint-context-"+i,this.didScroll=!1,this.didResize=!1,this.oldScroll={x:this.adapter.scrollLeft(),y:this.adapter.scrollTop()},this.waypoints={vertical:{},horizontal:{}},t.waypointContextKey=this.key,o[t.waypointContextKey]=this,i+=1,this.createThrottledScrollHandler(),this.createThrottledResizeHandler()}var i=0,o={},r=window.Waypoint,n=window.requestAnimationFrame||window.mozRequestAnimationFrame||window.webkitRequestAnimationFrame||t;e.prototype.add=function(t){var e=t.options.horizontal?"horizontal":"vertical";this.waypoints[e][t.key]=t,this.refresh()},e.prototype.checkEmpty=function(){var t=this.Adapter.isEmptyObject(this.waypoints.horizontal),e=this.Adapter.isEmptyObject(this.waypoints.vertical);t&&e&&(this.adapter.off(".waypoints"),delete o[this.key])},e.prototype.createThrottledResizeHandler=function(){function t(){e.handleResize(),e.didResize=!1}var e=this;this.adapter.on("resize.waypoints",function(){e.didResize||(e.didResize=!0,n(t))})},e.prototype.createThrottledScrollHandler=function(){function t(){e.handleScroll(),e.didScroll=!1}var e=this;this.adapter.on("scroll.waypoints",function(){(!e.didScroll||r.isTouch)&&(e.didScroll=!0,n(t))})},e.prototype.handleResize=function(){r.Context.refreshAll()},e.prototype.handleScroll=function(){var t={},e={horizontal:{newScroll:this.adapter.scrollLeft(),oldScroll:this.oldScroll.x,forward:"right",backward:"left"},vertical:{newScroll:this.adapter.scrollTop(),oldScroll:this.oldScroll.y,forward:"down",backward:"up"}};for(var i in e){var o=e[i],r=o.newScroll>o.oldScroll,n=r?o.forward:o.backward;for(var s in this.waypoints[i]){var a=this.waypoints[i][s],l=o.oldScroll=a.triggerPoint,p=l&&h,u=!l&&!h;(p||u)&&(a.queueTrigger(n),t[a.group.id]=a.group)}}for(var c in t)t[c].flushTriggers();this.oldScroll={x:e.horizontal.newScroll,y:e.vertical.newScroll}},e.prototype.height=function(){return this.element===this.element.window?r.viewportHeight():this.adapter.height()},e.prototype.remove=function(t){delete this.waypoints[t.axis][t.key],this.checkEmpty()},e.prototype.width=function(){return this.element===this.element.window?r.viewportWidth():this.adapter.width()},e.prototype.destroy=function(){var t=[];for(var e in this.waypoints)for(var i in this.waypoints[e])t.push(this.waypoints[e][i]);for(var o=0,r=t.length;r>o;o++)t[o].destroy()},e.prototype.refresh=function(){var t,e=this.element===this.element.window,i=this.adapter.offset(),o={};this.handleScroll(),t={horizontal:{contextOffset:e?0:i.left,contextScroll:e?0:this.oldScroll.x,contextDimension:this.width(),oldScroll:this.oldScroll.x,forward:"right",backward:"left",offsetProp:"left"},vertical:{contextOffset:e?0:i.top,contextScroll:e?0:this.oldScroll.y,contextDimension:this.height(),oldScroll:this.oldScroll.y,forward:"down",backward:"up",offsetProp:"top"}};for(var r in t){var n=t[r];for(var s in this.waypoints[r]){var a,l,h,p,u,c=this.waypoints[r][s],d=c.options.offset,f=c.triggerPoint,w=0,y=null==f;c.element!==c.element.window&&(w=c.adapter.offset()[n.offsetProp]),"function"==typeof d?d=d.apply(c):"string"==typeof d&&(d=parseFloat(d),c.options.offset.indexOf("%")>-1&&(d=Math.ceil(n.contextDimension*d/100))),a=n.contextScroll-n.contextOffset,c.triggerPoint=w+a-d,l=f=n.oldScroll,p=l&&h,u=!l&&!h,!y&&p?(c.queueTrigger(n.backward),o[c.group.id]=c.group):!y&&u?(c.queueTrigger(n.forward),o[c.group.id]=c.group):y&&n.oldScroll>=c.triggerPoint&&(c.queueTrigger(n.forward),o[c.group.id]=c.group)}}for(var g in o)o[g].flushTriggers();return this},e.findOrCreateByElement=function(t){return e.findByElement(t)||new e(t)},e.refreshAll=function(){for(var t in o)o[t].refresh()},e.findByElement=function(t){return o[t.waypointContextKey]},r.Context=e}(),function(){"use strict";function t(t,e){return t.triggerPoint-e.triggerPoint}function e(t,e){return e.triggerPoint-t.triggerPoint}function i(t){this.name=t.name,this.axis=t.axis,this.id=this.name+"-"+this.axis,this.waypoints=[],this.clearTriggerQueues(),o[this.axis][this.name]=this}var o={vertical:{},horizontal:{}},r=window.Waypoint;i.prototype.add=function(t){this.waypoints.push(t)},i.prototype.clearTriggerQueues=function(){this.triggerQueues={up:[],down:[],left:[],right:[]}},i.prototype.flushTriggers=function(){for(var i in this.triggerQueues){var o=this.triggerQueues[i],r="up"===i||"left"===i;o.sort(r?e:t);for(var n=0,s=o.length;s>n;n+=1){var a=o[n];(a.options.continuous||n===o.length-1)&&a.trigger([i])}}this.clearTriggerQueues()},i.prototype.next=function(e){this.waypoints.sort(t);var i=r.Adapter.inArray(e,this.waypoints),o=i===this.waypoints.length-1;return o?null:this.waypoints[i+1]},i.prototype.previous=function(e){this.waypoints.sort(t);var i=r.Adapter.inArray(e,this.waypoints);return i?this.waypoints[i-1]:null},i.prototype.queueTrigger=function(t,e){this.triggerQueues[e].push(t)},i.prototype.remove=function(t){var e=r.Adapter.inArray(t,this.waypoints);e>-1&&this.waypoints.splice(e,1)},i.prototype.first=function(){return this.waypoints[0]},i.prototype.last=function(){return this.waypoints[this.waypoints.length-1]},i.findOrCreate=function(t){return o[t.axis][t.name]||new i(t)},r.Group=i}(),function(){"use strict";function t(t){this.$element=e(t)}var e=window.jQuery,i=window.Waypoint;e.each(["height","off","offset","on","outerHeight","outerWidth","scrollLeft","scrollTop","width"],function(e,i){t.prototype[i]=function(){var t=Array.prototype.slice.call(arguments);return this.$element[i].apply(this.$element,t)}}),e.each(["extend","inArray","isEmptyObject"],function(i,o){t[o]=e[o]}),i.adapters.push({name:"jquery",Adapter:t}),i.Adapter=t}(),function(){"use strict";function t(t){return function(){var i=[],o=arguments[0];return t.isFunction(arguments[0])&&(o=t.extend({},arguments[1]),o.handler=arguments[0]),this.each(function(){var r=t.extend({},o,{element:this});"string"==typeof r.context&&(r.context=t(this).closest(r.context)[0]),i.push(new e(r))}),i}}var e=window.Waypoint;window.jQuery&&(window.jQuery.fn.waypoint=t(window.jQuery)),window.Zepto&&(window.Zepto.fn.waypoint=t(window.Zepto))}(); \ No newline at end of file +!function(){"use strict";function t(i){if(!i)throw new Error("No options passed to Waypoint constructor");if(!i.element)throw new Error("No element option passed to Waypoint constructor");if(!i.handler)throw new Error("No handler option passed to Waypoint constructor");this.key="waypoint-"+e,this.options=t.Adapter.extend({},t.defaults,i),this.element=this.options.element,this.adapter=new t.Adapter(this.element),this.callback=i.handler,this.axis=this.options.horizontal?"horizontal":"vertical",this.enabled=this.options.enabled,this.triggerPoint=null,this.group=t.Group.findOrCreate({name:this.options.group,axis:this.axis}),this.context=t.Context.findOrCreateByElement(this.options.context),t.offsetAliases[this.options.offset]&&(this.options.offset=t.offsetAliases[this.options.offset]),this.group.add(this),this.context.add(this),o[this.key]=this,e+=1}var e=0,o={};t.prototype.queueTrigger=function(t){this.group.queueTrigger(this,t)},t.prototype.trigger=function(t){this.enabled&&this.callback&&this.callback.apply(this,t)},t.prototype.destroy=function(){this.context.remove(this),this.group.remove(this),delete o[this.key]},t.prototype.disable=function(){return this.enabled=!1,this},t.prototype.enable=function(){return this.context.refresh(),this.enabled=!0,this},t.prototype.next=function(){return this.group.next(this)},t.prototype.previous=function(){return this.group.previous(this)},t.destroyAll=function(){var t=[];for(var e in o)t.push(o[e]);for(var i=0,r=t.length;r>i;i++)t[i].destroy()},t.refreshAll=function(){t.Context.refreshAll()},t.viewportHeight=function(){return window.innerHeight||document.documentElement.clientHeight},t.viewportWidth=function(){return document.documentElement.clientWidth},t.adapters=[],t.defaults={context:window,continuous:!0,enabled:!0,group:"default",horizontal:!1,offset:0},t.offsetAliases={"bottom-in-view":function(){return this.context.height()-this.adapter.outerHeight()},"right-in-view":function(){return this.context.width()-this.adapter.outerWidth()}},window.Waypoint=t}(),function(){"use strict";function t(t){window.setTimeout(t,1e3/60)}function e(t){this.element=t,this.Adapter=r.Adapter,this.adapter=new this.Adapter(t),this.key="waypoint-context-"+o,this.didScroll=!1,this.didResize=!1,this.oldScroll={x:this.adapter.scrollLeft(),y:this.adapter.scrollTop()},this.waypoints={vertical:{},horizontal:{}},t.waypointContextKey=this.key,i[t.waypointContextKey]=this,o+=1,this.createThrottledScrollHandler(),this.createThrottledResizeHandler()}var o=0,i={},r=window.Waypoint,n=window.requestAnimationFrame||window.mozRequestAnimationFrame||window.webkitRequestAnimationFrame||t;e.prototype.add=function(t){var e=t.options.horizontal?"horizontal":"vertical";this.waypoints[e][t.key]=t,this.refresh()},e.prototype.checkEmpty=function(){var t=this.Adapter.isEmptyObject(this.waypoints.horizontal),e=this.Adapter.isEmptyObject(this.waypoints.vertical);t&&e&&(this.adapter.off(".waypoints"),delete i[this.key])},e.prototype.createThrottledResizeHandler=function(){function t(){e.handleResize(),e.didResize=!1}var e=this;this.adapter.on("resize.waypoints",function(){e.didResize||(e.didResize=!0,n(t))})},e.prototype.createThrottledScrollHandler=function(){function t(){e.handleScroll(),e.didScroll=!1}var e=this;this.adapter.on("scroll.waypoints",function(){(!e.didScroll||r.isTouch)&&(e.didScroll=!0,n(t))})},e.prototype.handleResize=function(){r.Context.refreshAll()},e.prototype.handleScroll=function(){var t={},e={horizontal:{newScroll:this.adapter.scrollLeft(),oldScroll:this.oldScroll.x,forward:"right",backward:"left"},vertical:{newScroll:this.adapter.scrollTop(),oldScroll:this.oldScroll.y,forward:"down",backward:"up"}};for(var o in e){var i=e[o],r=i.newScroll>i.oldScroll,n=r?i.forward:i.backward;for(var s in this.waypoints[o]){var a=this.waypoints[o][s],l=i.oldScroll=a.triggerPoint,p=l&&h,u=!l&&!h;(p||u)&&(a.queueTrigger(n),t[a.group.id]=a.group)}}for(var c in t)t[c].flushTriggers();this.oldScroll={x:e.horizontal.newScroll,y:e.vertical.newScroll}},e.prototype.height=function(){return this.element===this.element.window?r.viewportHeight():this.adapter.height()},e.prototype.remove=function(t){delete this.waypoints[t.axis][t.key],this.checkEmpty()},e.prototype.width=function(){return this.element===this.element.window?r.viewportWidth():this.adapter.width()},e.prototype.destroy=function(){var t=[];for(var e in this.waypoints)for(var o in this.waypoints[e])t.push(this.waypoints[e][o]);for(var i=0,r=t.length;r>i;i++)t[i].destroy()},e.prototype.refresh=function(){var t,e=this.element===this.element.window,o=this.adapter.offset(),i={};this.handleScroll(),t={horizontal:{contextOffset:e?0:o.left,contextScroll:e?0:this.oldScroll.x,contextDimension:this.width(),oldScroll:this.oldScroll.x,forward:"right",backward:"left",offsetProp:"left"},vertical:{contextOffset:e?0:o.top,contextScroll:e?0:this.oldScroll.y,contextDimension:this.height(),oldScroll:this.oldScroll.y,forward:"down",backward:"up",offsetProp:"top"}};for(var r in t){var n=t[r];for(var s in this.waypoints[r]){var a,l,h,p,u,c=this.waypoints[r][s],d=c.options.offset,f=c.triggerPoint,w=0,y=null==f;c.element!==c.element.window&&(w=c.adapter.offset()[n.offsetProp]),"function"==typeof d?d=d.apply(c):"string"==typeof d&&(d=parseFloat(d),c.options.offset.indexOf("%")>-1&&(d=Math.ceil(n.contextDimension*d/100))),a=n.contextScroll-n.contextOffset,c.triggerPoint=w+a-d,l=f=n.oldScroll,p=l&&h,u=!l&&!h,!y&&p?(c.queueTrigger(n.backward),i[c.group.id]=c.group):!y&&u?(c.queueTrigger(n.forward),i[c.group.id]=c.group):y&&n.oldScroll>=c.triggerPoint&&(c.queueTrigger(n.forward),i[c.group.id]=c.group)}}for(var g in i)i[g].flushTriggers();return this},e.findOrCreateByElement=function(t){return e.findByElement(t)||new e(t)},e.refreshAll=function(){for(var t in i)i[t].refresh()},e.findByElement=function(t){return i[t.waypointContextKey]},r.Context=e}(),function(){"use strict";function t(t,e){return t.triggerPoint-e.triggerPoint}function e(t,e){return e.triggerPoint-t.triggerPoint}function o(t){this.name=t.name,this.axis=t.axis,this.id=this.name+"-"+this.axis,this.waypoints=[],this.clearTriggerQueues(),i[this.axis][this.name]=this}var i={vertical:{},horizontal:{}},r=window.Waypoint;o.prototype.add=function(t){this.waypoints.push(t)},o.prototype.clearTriggerQueues=function(){this.triggerQueues={up:[],down:[],left:[],right:[]}},o.prototype.flushTriggers=function(){for(var o in this.triggerQueues){var i=this.triggerQueues[o],r="up"===o||"left"===o;i.sort(r?e:t);for(var n=0,s=i.length;s>n;n+=1){var a=i[n];(a.options.continuous||n===i.length-1)&&a.trigger([o])}}this.clearTriggerQueues()},o.prototype.next=function(e){this.waypoints.sort(t);var o=r.Adapter.inArray(e,this.waypoints),i=o===this.waypoints.length-1;return i?null:this.waypoints[o+1]},o.prototype.previous=function(e){this.waypoints.sort(t);var o=r.Adapter.inArray(e,this.waypoints);return o?this.waypoints[o-1]:null},o.prototype.queueTrigger=function(t,e){this.triggerQueues[e].push(t)},o.prototype.remove=function(t){var e=r.Adapter.inArray(t,this.waypoints);e>-1&&this.waypoints.splice(e,1)},o.prototype.first=function(){return this.waypoints[0]},o.prototype.last=function(){return this.waypoints[this.waypoints.length-1]},o.findOrCreate=function(t){return i[t.axis][t.name]||new o(t)},r.Group=o}(),function(){"use strict";function t(t){this.$element=e(t)}var e=window.jQuery,o=window.Waypoint;e.each(["height","off","offset","on","outerHeight","outerWidth","scrollLeft","scrollTop","width"],function(e,o){t.prototype[o]=function(){var t=Array.prototype.slice.call(arguments);return this.$element[o].apply(this.$element,t)}}),e.each(["extend","inArray","isEmptyObject"],function(o,i){t[i]=e[i]}),o.adapters.push({name:"jquery",Adapter:t}),o.Adapter=t}(),function(){"use strict";function t(t){return function(){var o=[],i=arguments[0];return t.isFunction(arguments[0])&&(i=t.extend({},arguments[1]),i.handler=arguments[0]),this.each(function(){var r=t.extend({},i,{element:this});"string"==typeof r.context&&(r.context=t(this).closest(r.context)[0]),o.push(new e(r))}),o}}var e=window.Waypoint;window.jQuery&&(window.jQuery.fn.waypoint=t(window.jQuery)),window.Zepto&&(window.Zepto.fn.waypoint=t(window.Zepto))}(); \ No newline at end of file diff --git a/lib/noframework.waypoints.js b/lib/noframework.waypoints.js index 82d5f3c9..83ff1522 100644 --- a/lib/noframework.waypoints.js +++ b/lib/noframework.waypoints.js @@ -17,6 +17,9 @@ https://github.com/imakewebthings/waypoints/blog/master/licenses.txt if (!options.element) { throw new Error('No element option passed to Waypoint constructor') } + if (!options.handler) { + throw new Error('No handler option passed to Waypoint constructor') + } this.key = 'waypoint-' + keyCounter this.options = Waypoint.Adapter.extend({}, Waypoint.defaults, options) diff --git a/lib/noframework.waypoints.min.js b/lib/noframework.waypoints.min.js index a8421246..2935047b 100644 --- a/lib/noframework.waypoints.min.js +++ b/lib/noframework.waypoints.min.js @@ -4,4 +4,4 @@ Copyright © 2011-2014 Caleb Troughton Licensed under the MIT license. https://github.com/imakewebthings/waypoints/blog/master/licenses.txt */ -!function(){"use strict";function t(o){if(!o)throw new Error("No options passed to Waypoint constructor");if(!o.element)throw new Error("No element option passed to Waypoint constructor");this.key="waypoint-"+e,this.options=t.Adapter.extend({},t.defaults,o),this.element=this.options.element,this.adapter=new t.Adapter(this.element),this.callback=o.handler,this.axis=this.options.horizontal?"horizontal":"vertical",this.enabled=this.options.enabled,this.triggerPoint=null,this.group=t.Group.findOrCreate({name:this.options.group,axis:this.axis}),this.context=t.Context.findOrCreateByElement(this.options.context),t.offsetAliases[this.options.offset]&&(this.options.offset=t.offsetAliases[this.options.offset]),this.group.add(this),this.context.add(this),i[this.key]=this,e+=1}var e=0,i={};t.prototype.queueTrigger=function(t){this.group.queueTrigger(this,t)},t.prototype.trigger=function(t){this.enabled&&this.callback&&this.callback.apply(this,t)},t.prototype.destroy=function(){this.context.remove(this),this.group.remove(this),delete i[this.key]},t.prototype.disable=function(){return this.enabled=!1,this},t.prototype.enable=function(){return this.context.refresh(),this.enabled=!0,this},t.prototype.next=function(){return this.group.next(this)},t.prototype.previous=function(){return this.group.previous(this)},t.destroyAll=function(){var t=[];for(var e in i)t.push(i[e]);for(var o=0,r=t.length;r>o;o++)t[o].destroy()},t.refreshAll=function(){t.Context.refreshAll()},t.viewportHeight=function(){return window.innerHeight||document.documentElement.clientHeight},t.viewportWidth=function(){return document.documentElement.clientWidth},t.adapters=[],t.defaults={context:window,continuous:!0,enabled:!0,group:"default",horizontal:!1,offset:0},t.offsetAliases={"bottom-in-view":function(){return this.context.height()-this.adapter.outerHeight()},"right-in-view":function(){return this.context.width()-this.adapter.outerWidth()}},window.Waypoint=t}(),function(){"use strict";function t(t){window.setTimeout(t,1e3/60)}function e(t){this.element=t,this.Adapter=r.Adapter,this.adapter=new this.Adapter(t),this.key="waypoint-context-"+i,this.didScroll=!1,this.didResize=!1,this.oldScroll={x:this.adapter.scrollLeft(),y:this.adapter.scrollTop()},this.waypoints={vertical:{},horizontal:{}},t.waypointContextKey=this.key,o[t.waypointContextKey]=this,i+=1,this.createThrottledScrollHandler(),this.createThrottledResizeHandler()}var i=0,o={},r=window.Waypoint,n=window.requestAnimationFrame||window.mozRequestAnimationFrame||window.webkitRequestAnimationFrame||t;e.prototype.add=function(t){var e=t.options.horizontal?"horizontal":"vertical";this.waypoints[e][t.key]=t,this.refresh()},e.prototype.checkEmpty=function(){var t=this.Adapter.isEmptyObject(this.waypoints.horizontal),e=this.Adapter.isEmptyObject(this.waypoints.vertical);t&&e&&(this.adapter.off(".waypoints"),delete o[this.key])},e.prototype.createThrottledResizeHandler=function(){function t(){e.handleResize(),e.didResize=!1}var e=this;this.adapter.on("resize.waypoints",function(){e.didResize||(e.didResize=!0,n(t))})},e.prototype.createThrottledScrollHandler=function(){function t(){e.handleScroll(),e.didScroll=!1}var e=this;this.adapter.on("scroll.waypoints",function(){(!e.didScroll||r.isTouch)&&(e.didScroll=!0,n(t))})},e.prototype.handleResize=function(){r.Context.refreshAll()},e.prototype.handleScroll=function(){var t={},e={horizontal:{newScroll:this.adapter.scrollLeft(),oldScroll:this.oldScroll.x,forward:"right",backward:"left"},vertical:{newScroll:this.adapter.scrollTop(),oldScroll:this.oldScroll.y,forward:"down",backward:"up"}};for(var i in e){var o=e[i],r=o.newScroll>o.oldScroll,n=r?o.forward:o.backward;for(var s in this.waypoints[i]){var a=this.waypoints[i][s],l=o.oldScroll=a.triggerPoint,p=l&&h,u=!l&&!h;(p||u)&&(a.queueTrigger(n),t[a.group.id]=a.group)}}for(var f in t)t[f].flushTriggers();this.oldScroll={x:e.horizontal.newScroll,y:e.vertical.newScroll}},e.prototype.height=function(){return this.element===this.element.window?r.viewportHeight():this.adapter.height()},e.prototype.remove=function(t){delete this.waypoints[t.axis][t.key],this.checkEmpty()},e.prototype.width=function(){return this.element===this.element.window?r.viewportWidth():this.adapter.width()},e.prototype.destroy=function(){var t=[];for(var e in this.waypoints)for(var i in this.waypoints[e])t.push(this.waypoints[e][i]);for(var o=0,r=t.length;r>o;o++)t[o].destroy()},e.prototype.refresh=function(){var t,e=this.element===this.element.window,i=this.adapter.offset(),o={};this.handleScroll(),t={horizontal:{contextOffset:e?0:i.left,contextScroll:e?0:this.oldScroll.x,contextDimension:this.width(),oldScroll:this.oldScroll.x,forward:"right",backward:"left",offsetProp:"left"},vertical:{contextOffset:e?0:i.top,contextScroll:e?0:this.oldScroll.y,contextDimension:this.height(),oldScroll:this.oldScroll.y,forward:"down",backward:"up",offsetProp:"top"}};for(var r in t){var n=t[r];for(var s in this.waypoints[r]){var a,l,h,p,u,f=this.waypoints[r][s],c=f.options.offset,d=f.triggerPoint,y=0,g=null==d;f.element!==f.element.window&&(y=f.adapter.offset()[n.offsetProp]),"function"==typeof c?c=c.apply(f):"string"==typeof c&&(c=parseFloat(c),f.options.offset.indexOf("%")>-1&&(c=Math.ceil(n.contextDimension*c/100))),a=n.contextScroll-n.contextOffset,f.triggerPoint=y+a-c,l=d=n.oldScroll,p=l&&h,u=!l&&!h,!g&&p?(f.queueTrigger(n.backward),o[f.group.id]=f.group):!g&&u?(f.queueTrigger(n.forward),o[f.group.id]=f.group):g&&n.oldScroll>=f.triggerPoint&&(f.queueTrigger(n.forward),o[f.group.id]=f.group)}}for(var w in o)o[w].flushTriggers();return this},e.findOrCreateByElement=function(t){return e.findByElement(t)||new e(t)},e.refreshAll=function(){for(var t in o)o[t].refresh()},e.findByElement=function(t){return o[t.waypointContextKey]},r.Context=e}(),function(){"use strict";function t(t,e){return t.triggerPoint-e.triggerPoint}function e(t,e){return e.triggerPoint-t.triggerPoint}function i(t){this.name=t.name,this.axis=t.axis,this.id=this.name+"-"+this.axis,this.waypoints=[],this.clearTriggerQueues(),o[this.axis][this.name]=this}var o={vertical:{},horizontal:{}},r=window.Waypoint;i.prototype.add=function(t){this.waypoints.push(t)},i.prototype.clearTriggerQueues=function(){this.triggerQueues={up:[],down:[],left:[],right:[]}},i.prototype.flushTriggers=function(){for(var i in this.triggerQueues){var o=this.triggerQueues[i],r="up"===i||"left"===i;o.sort(r?e:t);for(var n=0,s=o.length;s>n;n+=1){var a=o[n];(a.options.continuous||n===o.length-1)&&a.trigger([i])}}this.clearTriggerQueues()},i.prototype.next=function(e){this.waypoints.sort(t);var i=r.Adapter.inArray(e,this.waypoints),o=i===this.waypoints.length-1;return o?null:this.waypoints[i+1]},i.prototype.previous=function(e){this.waypoints.sort(t);var i=r.Adapter.inArray(e,this.waypoints);return i?this.waypoints[i-1]:null},i.prototype.queueTrigger=function(t,e){this.triggerQueues[e].push(t)},i.prototype.remove=function(t){var e=r.Adapter.inArray(t,this.waypoints);e>-1&&this.waypoints.splice(e,1)},i.prototype.first=function(){return this.waypoints[0]},i.prototype.last=function(){return this.waypoints[this.waypoints.length-1]},i.findOrCreate=function(t){return o[t.axis][t.name]||new i(t)},r.Group=i}(),function(){"use strict";function t(t){return t===t.window}function e(e){return t(e)?e:e.defaultView}function i(t){this.element=t,this.handlers={}}var o=window.Waypoint;i.prototype.height=function(){var e=t(this.element);return e?this.element.innerHeight:this.element.offsetHeight},i.prototype.off=function(t,e){function i(t,e,i){for(var o=0,r=e.length-1;r>o;o++){var n=e[o];i&&i!==n||t.removeEventListener(n)}}var o=t.split("."),r=o[0],n=o[1],s=this.element;if(n&&this.handlers[n]&&r)i(s,this.handlers[n][r],e),this.handlers[n][r]=[];else if(r)for(var a in this.handlers)i(s,this.handlers[a][r]||[],e),this.handlers[a][r]=[];else if(n&&this.handlers[n]){for(var l in this.handlers[n])i(s,this.handlers[n][l],e);this.handlers[n]={}}},i.prototype.offset=function(){if(!this.element.ownerDocument)return null;var t=this.element.ownerDocument.documentElement,i=e(this.element.ownerDocument),o={top:0,left:0};return this.element.getBoundingClientRect&&(o=this.element.getBoundingClientRect()),{top:o.top+i.pageYOffset-t.clientTop,left:o.left+i.pageXOffset-t.clientLeft}},i.prototype.on=function(t,e){var i=t.split("."),o=i[0],r=i[1]||"__default",n=this.handlers[r]=this.handlers[r]||{},s=n[o]=n[o]||[];s.push(e),this.element.addEventListener(o,e)},i.prototype.outerHeight=function(e){var i,o=this.height();return e&&!t(this.element)&&(i=window.getComputedStyle(this.element),o+=parseInt(i.marginTop,10),o+=parseInt(i.marginBottom,10)),o},i.prototype.outerWidth=function(e){var i,o=this.width();return e&&!t(this.element)&&(i=window.getComputedStyle(this.element),o+=parseInt(i.marginLeft,10),o+=parseInt(i.marginRight,10)),o},i.prototype.scrollLeft=function(){var t=e(this.element);return t?t.pageXOffset:this.element.scrollLeft},i.prototype.scrollTop=function(){var t=e(this.element);return t?t.pageYOffset:this.element.scrollTop},i.prototype.width=function(){var e=t(this.element);return e?this.element.innerWidth:this.element.offsetWidth},i.extend=function(){function t(t,e){if("object"==typeof t&&"object"==typeof e)for(var i in e)e.hasOwnProperty(i)&&(t[i]=e[i]);return t}for(var e=Array.prototype.slice.call(arguments),i=1,o=e.length;o>i;i++)t(e[0],e[i]);return e[0]},i.inArray=function(t,e,i){return null==e?-1:e.indexOf(t,i)},i.isEmptyObject=function(t){for(var e in t)return!1;return!0},o.adapters.push({name:"noframework",Adapter:i}),o.Adapter=i}(); \ No newline at end of file +!function(){"use strict";function t(o){if(!o)throw new Error("No options passed to Waypoint constructor");if(!o.element)throw new Error("No element option passed to Waypoint constructor");if(!o.handler)throw new Error("No handler option passed to Waypoint constructor");this.key="waypoint-"+e,this.options=t.Adapter.extend({},t.defaults,o),this.element=this.options.element,this.adapter=new t.Adapter(this.element),this.callback=o.handler,this.axis=this.options.horizontal?"horizontal":"vertical",this.enabled=this.options.enabled,this.triggerPoint=null,this.group=t.Group.findOrCreate({name:this.options.group,axis:this.axis}),this.context=t.Context.findOrCreateByElement(this.options.context),t.offsetAliases[this.options.offset]&&(this.options.offset=t.offsetAliases[this.options.offset]),this.group.add(this),this.context.add(this),i[this.key]=this,e+=1}var e=0,i={};t.prototype.queueTrigger=function(t){this.group.queueTrigger(this,t)},t.prototype.trigger=function(t){this.enabled&&this.callback&&this.callback.apply(this,t)},t.prototype.destroy=function(){this.context.remove(this),this.group.remove(this),delete i[this.key]},t.prototype.disable=function(){return this.enabled=!1,this},t.prototype.enable=function(){return this.context.refresh(),this.enabled=!0,this},t.prototype.next=function(){return this.group.next(this)},t.prototype.previous=function(){return this.group.previous(this)},t.destroyAll=function(){var t=[];for(var e in i)t.push(i[e]);for(var o=0,r=t.length;r>o;o++)t[o].destroy()},t.refreshAll=function(){t.Context.refreshAll()},t.viewportHeight=function(){return window.innerHeight||document.documentElement.clientHeight},t.viewportWidth=function(){return document.documentElement.clientWidth},t.adapters=[],t.defaults={context:window,continuous:!0,enabled:!0,group:"default",horizontal:!1,offset:0},t.offsetAliases={"bottom-in-view":function(){return this.context.height()-this.adapter.outerHeight()},"right-in-view":function(){return this.context.width()-this.adapter.outerWidth()}},window.Waypoint=t}(),function(){"use strict";function t(t){window.setTimeout(t,1e3/60)}function e(t){this.element=t,this.Adapter=r.Adapter,this.adapter=new this.Adapter(t),this.key="waypoint-context-"+i,this.didScroll=!1,this.didResize=!1,this.oldScroll={x:this.adapter.scrollLeft(),y:this.adapter.scrollTop()},this.waypoints={vertical:{},horizontal:{}},t.waypointContextKey=this.key,o[t.waypointContextKey]=this,i+=1,this.createThrottledScrollHandler(),this.createThrottledResizeHandler()}var i=0,o={},r=window.Waypoint,n=window.requestAnimationFrame||window.mozRequestAnimationFrame||window.webkitRequestAnimationFrame||t;e.prototype.add=function(t){var e=t.options.horizontal?"horizontal":"vertical";this.waypoints[e][t.key]=t,this.refresh()},e.prototype.checkEmpty=function(){var t=this.Adapter.isEmptyObject(this.waypoints.horizontal),e=this.Adapter.isEmptyObject(this.waypoints.vertical);t&&e&&(this.adapter.off(".waypoints"),delete o[this.key])},e.prototype.createThrottledResizeHandler=function(){function t(){e.handleResize(),e.didResize=!1}var e=this;this.adapter.on("resize.waypoints",function(){e.didResize||(e.didResize=!0,n(t))})},e.prototype.createThrottledScrollHandler=function(){function t(){e.handleScroll(),e.didScroll=!1}var e=this;this.adapter.on("scroll.waypoints",function(){(!e.didScroll||r.isTouch)&&(e.didScroll=!0,n(t))})},e.prototype.handleResize=function(){r.Context.refreshAll()},e.prototype.handleScroll=function(){var t={},e={horizontal:{newScroll:this.adapter.scrollLeft(),oldScroll:this.oldScroll.x,forward:"right",backward:"left"},vertical:{newScroll:this.adapter.scrollTop(),oldScroll:this.oldScroll.y,forward:"down",backward:"up"}};for(var i in e){var o=e[i],r=o.newScroll>o.oldScroll,n=r?o.forward:o.backward;for(var s in this.waypoints[i]){var a=this.waypoints[i][s],l=o.oldScroll=a.triggerPoint,p=l&&h,u=!l&&!h;(p||u)&&(a.queueTrigger(n),t[a.group.id]=a.group)}}for(var f in t)t[f].flushTriggers();this.oldScroll={x:e.horizontal.newScroll,y:e.vertical.newScroll}},e.prototype.height=function(){return this.element===this.element.window?r.viewportHeight():this.adapter.height()},e.prototype.remove=function(t){delete this.waypoints[t.axis][t.key],this.checkEmpty()},e.prototype.width=function(){return this.element===this.element.window?r.viewportWidth():this.adapter.width()},e.prototype.destroy=function(){var t=[];for(var e in this.waypoints)for(var i in this.waypoints[e])t.push(this.waypoints[e][i]);for(var o=0,r=t.length;r>o;o++)t[o].destroy()},e.prototype.refresh=function(){var t,e=this.element===this.element.window,i=this.adapter.offset(),o={};this.handleScroll(),t={horizontal:{contextOffset:e?0:i.left,contextScroll:e?0:this.oldScroll.x,contextDimension:this.width(),oldScroll:this.oldScroll.x,forward:"right",backward:"left",offsetProp:"left"},vertical:{contextOffset:e?0:i.top,contextScroll:e?0:this.oldScroll.y,contextDimension:this.height(),oldScroll:this.oldScroll.y,forward:"down",backward:"up",offsetProp:"top"}};for(var r in t){var n=t[r];for(var s in this.waypoints[r]){var a,l,h,p,u,f=this.waypoints[r][s],c=f.options.offset,d=f.triggerPoint,y=0,g=null==d;f.element!==f.element.window&&(y=f.adapter.offset()[n.offsetProp]),"function"==typeof c?c=c.apply(f):"string"==typeof c&&(c=parseFloat(c),f.options.offset.indexOf("%")>-1&&(c=Math.ceil(n.contextDimension*c/100))),a=n.contextScroll-n.contextOffset,f.triggerPoint=y+a-c,l=d=n.oldScroll,p=l&&h,u=!l&&!h,!g&&p?(f.queueTrigger(n.backward),o[f.group.id]=f.group):!g&&u?(f.queueTrigger(n.forward),o[f.group.id]=f.group):g&&n.oldScroll>=f.triggerPoint&&(f.queueTrigger(n.forward),o[f.group.id]=f.group)}}for(var w in o)o[w].flushTriggers();return this},e.findOrCreateByElement=function(t){return e.findByElement(t)||new e(t)},e.refreshAll=function(){for(var t in o)o[t].refresh()},e.findByElement=function(t){return o[t.waypointContextKey]},r.Context=e}(),function(){"use strict";function t(t,e){return t.triggerPoint-e.triggerPoint}function e(t,e){return e.triggerPoint-t.triggerPoint}function i(t){this.name=t.name,this.axis=t.axis,this.id=this.name+"-"+this.axis,this.waypoints=[],this.clearTriggerQueues(),o[this.axis][this.name]=this}var o={vertical:{},horizontal:{}},r=window.Waypoint;i.prototype.add=function(t){this.waypoints.push(t)},i.prototype.clearTriggerQueues=function(){this.triggerQueues={up:[],down:[],left:[],right:[]}},i.prototype.flushTriggers=function(){for(var i in this.triggerQueues){var o=this.triggerQueues[i],r="up"===i||"left"===i;o.sort(r?e:t);for(var n=0,s=o.length;s>n;n+=1){var a=o[n];(a.options.continuous||n===o.length-1)&&a.trigger([i])}}this.clearTriggerQueues()},i.prototype.next=function(e){this.waypoints.sort(t);var i=r.Adapter.inArray(e,this.waypoints),o=i===this.waypoints.length-1;return o?null:this.waypoints[i+1]},i.prototype.previous=function(e){this.waypoints.sort(t);var i=r.Adapter.inArray(e,this.waypoints);return i?this.waypoints[i-1]:null},i.prototype.queueTrigger=function(t,e){this.triggerQueues[e].push(t)},i.prototype.remove=function(t){var e=r.Adapter.inArray(t,this.waypoints);e>-1&&this.waypoints.splice(e,1)},i.prototype.first=function(){return this.waypoints[0]},i.prototype.last=function(){return this.waypoints[this.waypoints.length-1]},i.findOrCreate=function(t){return o[t.axis][t.name]||new i(t)},r.Group=i}(),function(){"use strict";function t(t){return t===t.window}function e(e){return t(e)?e:e.defaultView}function i(t){this.element=t,this.handlers={}}var o=window.Waypoint;i.prototype.height=function(){var e=t(this.element);return e?this.element.innerHeight:this.element.offsetHeight},i.prototype.off=function(t,e){function i(t,e,i){for(var o=0,r=e.length-1;r>o;o++){var n=e[o];i&&i!==n||t.removeEventListener(n)}}var o=t.split("."),r=o[0],n=o[1],s=this.element;if(n&&this.handlers[n]&&r)i(s,this.handlers[n][r],e),this.handlers[n][r]=[];else if(r)for(var a in this.handlers)i(s,this.handlers[a][r]||[],e),this.handlers[a][r]=[];else if(n&&this.handlers[n]){for(var l in this.handlers[n])i(s,this.handlers[n][l],e);this.handlers[n]={}}},i.prototype.offset=function(){if(!this.element.ownerDocument)return null;var t=this.element.ownerDocument.documentElement,i=e(this.element.ownerDocument),o={top:0,left:0};return this.element.getBoundingClientRect&&(o=this.element.getBoundingClientRect()),{top:o.top+i.pageYOffset-t.clientTop,left:o.left+i.pageXOffset-t.clientLeft}},i.prototype.on=function(t,e){var i=t.split("."),o=i[0],r=i[1]||"__default",n=this.handlers[r]=this.handlers[r]||{},s=n[o]=n[o]||[];s.push(e),this.element.addEventListener(o,e)},i.prototype.outerHeight=function(e){var i,o=this.height();return e&&!t(this.element)&&(i=window.getComputedStyle(this.element),o+=parseInt(i.marginTop,10),o+=parseInt(i.marginBottom,10)),o},i.prototype.outerWidth=function(e){var i,o=this.width();return e&&!t(this.element)&&(i=window.getComputedStyle(this.element),o+=parseInt(i.marginLeft,10),o+=parseInt(i.marginRight,10)),o},i.prototype.scrollLeft=function(){var t=e(this.element);return t?t.pageXOffset:this.element.scrollLeft},i.prototype.scrollTop=function(){var t=e(this.element);return t?t.pageYOffset:this.element.scrollTop},i.prototype.width=function(){var e=t(this.element);return e?this.element.innerWidth:this.element.offsetWidth},i.extend=function(){function t(t,e){if("object"==typeof t&&"object"==typeof e)for(var i in e)e.hasOwnProperty(i)&&(t[i]=e[i]);return t}for(var e=Array.prototype.slice.call(arguments),i=1,o=e.length;o>i;i++)t(e[0],e[i]);return e[0]},i.inArray=function(t,e,i){return null==e?-1:e.indexOf(t,i)},i.isEmptyObject=function(t){for(var e in t)return!1;return!0},o.adapters.push({name:"noframework",Adapter:i}),o.Adapter=i}(); \ No newline at end of file diff --git a/lib/zepto.waypoints.js b/lib/zepto.waypoints.js index 8ddd999d..45c5f5f8 100644 --- a/lib/zepto.waypoints.js +++ b/lib/zepto.waypoints.js @@ -17,6 +17,9 @@ https://github.com/imakewebthings/waypoints/blog/master/licenses.txt if (!options.element) { throw new Error('No element option passed to Waypoint constructor') } + if (!options.handler) { + throw new Error('No handler option passed to Waypoint constructor') + } this.key = 'waypoint-' + keyCounter this.options = Waypoint.Adapter.extend({}, Waypoint.defaults, options) diff --git a/lib/zepto.waypoints.min.js b/lib/zepto.waypoints.min.js index a1ac3e41..f4272581 100644 --- a/lib/zepto.waypoints.min.js +++ b/lib/zepto.waypoints.min.js @@ -4,4 +4,4 @@ Copyright © 2011-2014 Caleb Troughton Licensed under the MIT license. https://github.com/imakewebthings/waypoints/blog/master/licenses.txt */ -!function(){"use strict";function t(o){if(!o)throw new Error("No options passed to Waypoint constructor");if(!o.element)throw new Error("No element option passed to Waypoint constructor");this.key="waypoint-"+e,this.options=t.Adapter.extend({},t.defaults,o),this.element=this.options.element,this.adapter=new t.Adapter(this.element),this.callback=o.handler,this.axis=this.options.horizontal?"horizontal":"vertical",this.enabled=this.options.enabled,this.triggerPoint=null,this.group=t.Group.findOrCreate({name:this.options.group,axis:this.axis}),this.context=t.Context.findOrCreateByElement(this.options.context),t.offsetAliases[this.options.offset]&&(this.options.offset=t.offsetAliases[this.options.offset]),this.group.add(this),this.context.add(this),i[this.key]=this,e+=1}var e=0,i={};t.prototype.queueTrigger=function(t){this.group.queueTrigger(this,t)},t.prototype.trigger=function(t){this.enabled&&this.callback&&this.callback.apply(this,t)},t.prototype.destroy=function(){this.context.remove(this),this.group.remove(this),delete i[this.key]},t.prototype.disable=function(){return this.enabled=!1,this},t.prototype.enable=function(){return this.context.refresh(),this.enabled=!0,this},t.prototype.next=function(){return this.group.next(this)},t.prototype.previous=function(){return this.group.previous(this)},t.destroyAll=function(){var t=[];for(var e in i)t.push(i[e]);for(var o=0,r=t.length;r>o;o++)t[o].destroy()},t.refreshAll=function(){t.Context.refreshAll()},t.viewportHeight=function(){return window.innerHeight||document.documentElement.clientHeight},t.viewportWidth=function(){return document.documentElement.clientWidth},t.adapters=[],t.defaults={context:window,continuous:!0,enabled:!0,group:"default",horizontal:!1,offset:0},t.offsetAliases={"bottom-in-view":function(){return this.context.height()-this.adapter.outerHeight()},"right-in-view":function(){return this.context.width()-this.adapter.outerWidth()}},window.Waypoint=t}(),function(){"use strict";function t(t){window.setTimeout(t,1e3/60)}function e(t){this.element=t,this.Adapter=r.Adapter,this.adapter=new this.Adapter(t),this.key="waypoint-context-"+i,this.didScroll=!1,this.didResize=!1,this.oldScroll={x:this.adapter.scrollLeft(),y:this.adapter.scrollTop()},this.waypoints={vertical:{},horizontal:{}},t.waypointContextKey=this.key,o[t.waypointContextKey]=this,i+=1,this.createThrottledScrollHandler(),this.createThrottledResizeHandler()}var i=0,o={},r=window.Waypoint,n=window.requestAnimationFrame||window.mozRequestAnimationFrame||window.webkitRequestAnimationFrame||t;e.prototype.add=function(t){var e=t.options.horizontal?"horizontal":"vertical";this.waypoints[e][t.key]=t,this.refresh()},e.prototype.checkEmpty=function(){var t=this.Adapter.isEmptyObject(this.waypoints.horizontal),e=this.Adapter.isEmptyObject(this.waypoints.vertical);t&&e&&(this.adapter.off(".waypoints"),delete o[this.key])},e.prototype.createThrottledResizeHandler=function(){function t(){e.handleResize(),e.didResize=!1}var e=this;this.adapter.on("resize.waypoints",function(){e.didResize||(e.didResize=!0,n(t))})},e.prototype.createThrottledScrollHandler=function(){function t(){e.handleScroll(),e.didScroll=!1}var e=this;this.adapter.on("scroll.waypoints",function(){(!e.didScroll||r.isTouch)&&(e.didScroll=!0,n(t))})},e.prototype.handleResize=function(){r.Context.refreshAll()},e.prototype.handleScroll=function(){var t={},e={horizontal:{newScroll:this.adapter.scrollLeft(),oldScroll:this.oldScroll.x,forward:"right",backward:"left"},vertical:{newScroll:this.adapter.scrollTop(),oldScroll:this.oldScroll.y,forward:"down",backward:"up"}};for(var i in e){var o=e[i],r=o.newScroll>o.oldScroll,n=r?o.forward:o.backward;for(var s in this.waypoints[i]){var a=this.waypoints[i][s],h=o.oldScroll=a.triggerPoint,p=h&&l,c=!h&&!l;(p||c)&&(a.queueTrigger(n),t[a.group.id]=a.group)}}for(var u in t)t[u].flushTriggers();this.oldScroll={x:e.horizontal.newScroll,y:e.vertical.newScroll}},e.prototype.height=function(){return this.element===this.element.window?r.viewportHeight():this.adapter.height()},e.prototype.remove=function(t){delete this.waypoints[t.axis][t.key],this.checkEmpty()},e.prototype.width=function(){return this.element===this.element.window?r.viewportWidth():this.adapter.width()},e.prototype.destroy=function(){var t=[];for(var e in this.waypoints)for(var i in this.waypoints[e])t.push(this.waypoints[e][i]);for(var o=0,r=t.length;r>o;o++)t[o].destroy()},e.prototype.refresh=function(){var t,e=this.element===this.element.window,i=this.adapter.offset(),o={};this.handleScroll(),t={horizontal:{contextOffset:e?0:i.left,contextScroll:e?0:this.oldScroll.x,contextDimension:this.width(),oldScroll:this.oldScroll.x,forward:"right",backward:"left",offsetProp:"left"},vertical:{contextOffset:e?0:i.top,contextScroll:e?0:this.oldScroll.y,contextDimension:this.height(),oldScroll:this.oldScroll.y,forward:"down",backward:"up",offsetProp:"top"}};for(var r in t){var n=t[r];for(var s in this.waypoints[r]){var a,h,l,p,c,u=this.waypoints[r][s],d=u.options.offset,f=u.triggerPoint,w=0,y=null==f;u.element!==u.element.window&&(w=u.adapter.offset()[n.offsetProp]),"function"==typeof d?d=d.apply(u):"string"==typeof d&&(d=parseFloat(d),u.options.offset.indexOf("%")>-1&&(d=Math.ceil(n.contextDimension*d/100))),a=n.contextScroll-n.contextOffset,u.triggerPoint=w+a-d,h=f=n.oldScroll,p=h&&l,c=!h&&!l,!y&&p?(u.queueTrigger(n.backward),o[u.group.id]=u.group):!y&&c?(u.queueTrigger(n.forward),o[u.group.id]=u.group):y&&n.oldScroll>=u.triggerPoint&&(u.queueTrigger(n.forward),o[u.group.id]=u.group)}}for(var g in o)o[g].flushTriggers();return this},e.findOrCreateByElement=function(t){return e.findByElement(t)||new e(t)},e.refreshAll=function(){for(var t in o)o[t].refresh()},e.findByElement=function(t){return o[t.waypointContextKey]},r.Context=e}(),function(){"use strict";function t(t,e){return t.triggerPoint-e.triggerPoint}function e(t,e){return e.triggerPoint-t.triggerPoint}function i(t){this.name=t.name,this.axis=t.axis,this.id=this.name+"-"+this.axis,this.waypoints=[],this.clearTriggerQueues(),o[this.axis][this.name]=this}var o={vertical:{},horizontal:{}},r=window.Waypoint;i.prototype.add=function(t){this.waypoints.push(t)},i.prototype.clearTriggerQueues=function(){this.triggerQueues={up:[],down:[],left:[],right:[]}},i.prototype.flushTriggers=function(){for(var i in this.triggerQueues){var o=this.triggerQueues[i],r="up"===i||"left"===i;o.sort(r?e:t);for(var n=0,s=o.length;s>n;n+=1){var a=o[n];(a.options.continuous||n===o.length-1)&&a.trigger([i])}}this.clearTriggerQueues()},i.prototype.next=function(e){this.waypoints.sort(t);var i=r.Adapter.inArray(e,this.waypoints),o=i===this.waypoints.length-1;return o?null:this.waypoints[i+1]},i.prototype.previous=function(e){this.waypoints.sort(t);var i=r.Adapter.inArray(e,this.waypoints);return i?this.waypoints[i-1]:null},i.prototype.queueTrigger=function(t,e){this.triggerQueues[e].push(t)},i.prototype.remove=function(t){var e=r.Adapter.inArray(t,this.waypoints);e>-1&&this.waypoints.splice(e,1)},i.prototype.first=function(){return this.waypoints[0]},i.prototype.last=function(){return this.waypoints[this.waypoints.length-1]},i.findOrCreate=function(t){return o[t.axis][t.name]||new i(t)},r.Group=i}(),function(){"use strict";function t(t){this.element=t,this.$element=e(t)}var e=window.Zepto,i=window.Waypoint;e.each(["height","off","on","scrollLeft","scrollTop","width"],function(e,i){t.prototype[i]=function(){var t=Array.prototype.slice.call(arguments);return this.$element[i].apply(this.$element,t)}}),t.prototype.offset=function(){return this.element!==this.element.window?this.$element.offset():void 0},e.each(["width","height"],function(i,o){var r=e.camelCase("outer-"+o);t.prototype[r]=function(t){var i=this.$element[o](),r={width:["left","right"],height:["top","bottom"]};return t&&e.each(r[o],e.proxy(function(t,e){i+=parseInt(this.$element.css("margin-"+e),10)},this)),i}}),e.each(["extend","inArray"],function(i,o){t[o]=e[o]}),t.isEmptyObject=function(t){for(var e in t)return!1;return!0},i.adapters.push({name:"zepto",Adapter:t}),i.Adapter=t}(),function(){"use strict";function t(t){return function(){var i=[],o=arguments[0];return t.isFunction(arguments[0])&&(o=t.extend({},arguments[1]),o.handler=arguments[0]),this.each(function(){var r=t.extend({},o,{element:this});"string"==typeof r.context&&(r.context=t(this).closest(r.context)[0]),i.push(new e(r))}),i}}var e=window.Waypoint;window.jQuery&&(window.jQuery.fn.waypoint=t(window.jQuery)),window.Zepto&&(window.Zepto.fn.waypoint=t(window.Zepto))}(); \ No newline at end of file +!function(){"use strict";function t(i){if(!i)throw new Error("No options passed to Waypoint constructor");if(!i.element)throw new Error("No element option passed to Waypoint constructor");if(!i.handler)throw new Error("No handler option passed to Waypoint constructor");this.key="waypoint-"+e,this.options=t.Adapter.extend({},t.defaults,i),this.element=this.options.element,this.adapter=new t.Adapter(this.element),this.callback=i.handler,this.axis=this.options.horizontal?"horizontal":"vertical",this.enabled=this.options.enabled,this.triggerPoint=null,this.group=t.Group.findOrCreate({name:this.options.group,axis:this.axis}),this.context=t.Context.findOrCreateByElement(this.options.context),t.offsetAliases[this.options.offset]&&(this.options.offset=t.offsetAliases[this.options.offset]),this.group.add(this),this.context.add(this),o[this.key]=this,e+=1}var e=0,o={};t.prototype.queueTrigger=function(t){this.group.queueTrigger(this,t)},t.prototype.trigger=function(t){this.enabled&&this.callback&&this.callback.apply(this,t)},t.prototype.destroy=function(){this.context.remove(this),this.group.remove(this),delete o[this.key]},t.prototype.disable=function(){return this.enabled=!1,this},t.prototype.enable=function(){return this.context.refresh(),this.enabled=!0,this},t.prototype.next=function(){return this.group.next(this)},t.prototype.previous=function(){return this.group.previous(this)},t.destroyAll=function(){var t=[];for(var e in o)t.push(o[e]);for(var i=0,r=t.length;r>i;i++)t[i].destroy()},t.refreshAll=function(){t.Context.refreshAll()},t.viewportHeight=function(){return window.innerHeight||document.documentElement.clientHeight},t.viewportWidth=function(){return document.documentElement.clientWidth},t.adapters=[],t.defaults={context:window,continuous:!0,enabled:!0,group:"default",horizontal:!1,offset:0},t.offsetAliases={"bottom-in-view":function(){return this.context.height()-this.adapter.outerHeight()},"right-in-view":function(){return this.context.width()-this.adapter.outerWidth()}},window.Waypoint=t}(),function(){"use strict";function t(t){window.setTimeout(t,1e3/60)}function e(t){this.element=t,this.Adapter=r.Adapter,this.adapter=new this.Adapter(t),this.key="waypoint-context-"+o,this.didScroll=!1,this.didResize=!1,this.oldScroll={x:this.adapter.scrollLeft(),y:this.adapter.scrollTop()},this.waypoints={vertical:{},horizontal:{}},t.waypointContextKey=this.key,i[t.waypointContextKey]=this,o+=1,this.createThrottledScrollHandler(),this.createThrottledResizeHandler()}var o=0,i={},r=window.Waypoint,n=window.requestAnimationFrame||window.mozRequestAnimationFrame||window.webkitRequestAnimationFrame||t;e.prototype.add=function(t){var e=t.options.horizontal?"horizontal":"vertical";this.waypoints[e][t.key]=t,this.refresh()},e.prototype.checkEmpty=function(){var t=this.Adapter.isEmptyObject(this.waypoints.horizontal),e=this.Adapter.isEmptyObject(this.waypoints.vertical);t&&e&&(this.adapter.off(".waypoints"),delete i[this.key])},e.prototype.createThrottledResizeHandler=function(){function t(){e.handleResize(),e.didResize=!1}var e=this;this.adapter.on("resize.waypoints",function(){e.didResize||(e.didResize=!0,n(t))})},e.prototype.createThrottledScrollHandler=function(){function t(){e.handleScroll(),e.didScroll=!1}var e=this;this.adapter.on("scroll.waypoints",function(){(!e.didScroll||r.isTouch)&&(e.didScroll=!0,n(t))})},e.prototype.handleResize=function(){r.Context.refreshAll()},e.prototype.handleScroll=function(){var t={},e={horizontal:{newScroll:this.adapter.scrollLeft(),oldScroll:this.oldScroll.x,forward:"right",backward:"left"},vertical:{newScroll:this.adapter.scrollTop(),oldScroll:this.oldScroll.y,forward:"down",backward:"up"}};for(var o in e){var i=e[o],r=i.newScroll>i.oldScroll,n=r?i.forward:i.backward;for(var s in this.waypoints[o]){var a=this.waypoints[o][s],h=i.oldScroll=a.triggerPoint,p=h&&l,c=!h&&!l;(p||c)&&(a.queueTrigger(n),t[a.group.id]=a.group)}}for(var u in t)t[u].flushTriggers();this.oldScroll={x:e.horizontal.newScroll,y:e.vertical.newScroll}},e.prototype.height=function(){return this.element===this.element.window?r.viewportHeight():this.adapter.height()},e.prototype.remove=function(t){delete this.waypoints[t.axis][t.key],this.checkEmpty()},e.prototype.width=function(){return this.element===this.element.window?r.viewportWidth():this.adapter.width()},e.prototype.destroy=function(){var t=[];for(var e in this.waypoints)for(var o in this.waypoints[e])t.push(this.waypoints[e][o]);for(var i=0,r=t.length;r>i;i++)t[i].destroy()},e.prototype.refresh=function(){var t,e=this.element===this.element.window,o=this.adapter.offset(),i={};this.handleScroll(),t={horizontal:{contextOffset:e?0:o.left,contextScroll:e?0:this.oldScroll.x,contextDimension:this.width(),oldScroll:this.oldScroll.x,forward:"right",backward:"left",offsetProp:"left"},vertical:{contextOffset:e?0:o.top,contextScroll:e?0:this.oldScroll.y,contextDimension:this.height(),oldScroll:this.oldScroll.y,forward:"down",backward:"up",offsetProp:"top"}};for(var r in t){var n=t[r];for(var s in this.waypoints[r]){var a,h,l,p,c,u=this.waypoints[r][s],d=u.options.offset,f=u.triggerPoint,w=0,y=null==f;u.element!==u.element.window&&(w=u.adapter.offset()[n.offsetProp]),"function"==typeof d?d=d.apply(u):"string"==typeof d&&(d=parseFloat(d),u.options.offset.indexOf("%")>-1&&(d=Math.ceil(n.contextDimension*d/100))),a=n.contextScroll-n.contextOffset,u.triggerPoint=w+a-d,h=f=n.oldScroll,p=h&&l,c=!h&&!l,!y&&p?(u.queueTrigger(n.backward),i[u.group.id]=u.group):!y&&c?(u.queueTrigger(n.forward),i[u.group.id]=u.group):y&&n.oldScroll>=u.triggerPoint&&(u.queueTrigger(n.forward),i[u.group.id]=u.group)}}for(var g in i)i[g].flushTriggers();return this},e.findOrCreateByElement=function(t){return e.findByElement(t)||new e(t)},e.refreshAll=function(){for(var t in i)i[t].refresh()},e.findByElement=function(t){return i[t.waypointContextKey]},r.Context=e}(),function(){"use strict";function t(t,e){return t.triggerPoint-e.triggerPoint}function e(t,e){return e.triggerPoint-t.triggerPoint}function o(t){this.name=t.name,this.axis=t.axis,this.id=this.name+"-"+this.axis,this.waypoints=[],this.clearTriggerQueues(),i[this.axis][this.name]=this}var i={vertical:{},horizontal:{}},r=window.Waypoint;o.prototype.add=function(t){this.waypoints.push(t)},o.prototype.clearTriggerQueues=function(){this.triggerQueues={up:[],down:[],left:[],right:[]}},o.prototype.flushTriggers=function(){for(var o in this.triggerQueues){var i=this.triggerQueues[o],r="up"===o||"left"===o;i.sort(r?e:t);for(var n=0,s=i.length;s>n;n+=1){var a=i[n];(a.options.continuous||n===i.length-1)&&a.trigger([o])}}this.clearTriggerQueues()},o.prototype.next=function(e){this.waypoints.sort(t);var o=r.Adapter.inArray(e,this.waypoints),i=o===this.waypoints.length-1;return i?null:this.waypoints[o+1]},o.prototype.previous=function(e){this.waypoints.sort(t);var o=r.Adapter.inArray(e,this.waypoints);return o?this.waypoints[o-1]:null},o.prototype.queueTrigger=function(t,e){this.triggerQueues[e].push(t)},o.prototype.remove=function(t){var e=r.Adapter.inArray(t,this.waypoints);e>-1&&this.waypoints.splice(e,1)},o.prototype.first=function(){return this.waypoints[0]},o.prototype.last=function(){return this.waypoints[this.waypoints.length-1]},o.findOrCreate=function(t){return i[t.axis][t.name]||new o(t)},r.Group=o}(),function(){"use strict";function t(t){this.element=t,this.$element=e(t)}var e=window.Zepto,o=window.Waypoint;e.each(["height","off","on","scrollLeft","scrollTop","width"],function(e,o){t.prototype[o]=function(){var t=Array.prototype.slice.call(arguments);return this.$element[o].apply(this.$element,t)}}),t.prototype.offset=function(){return this.element!==this.element.window?this.$element.offset():void 0},e.each(["width","height"],function(o,i){var r=e.camelCase("outer-"+i);t.prototype[r]=function(t){var o=this.$element[i](),r={width:["left","right"],height:["top","bottom"]};return t&&e.each(r[i],e.proxy(function(t,e){o+=parseInt(this.$element.css("margin-"+e),10)},this)),o}}),e.each(["extend","inArray"],function(o,i){t[i]=e[i]}),t.isEmptyObject=function(t){for(var e in t)return!1;return!0},o.adapters.push({name:"zepto",Adapter:t}),o.Adapter=t}(),function(){"use strict";function t(t){return function(){var o=[],i=arguments[0];return t.isFunction(arguments[0])&&(i=t.extend({},arguments[1]),i.handler=arguments[0]),this.each(function(){var r=t.extend({},i,{element:this});"string"==typeof r.context&&(r.context=t(this).closest(r.context)[0]),o.push(new e(r))}),o}}var e=window.Waypoint;window.jQuery&&(window.jQuery.fn.waypoint=t(window.jQuery)),window.Zepto&&(window.Zepto.fn.waypoint=t(window.Zepto))}(); \ No newline at end of file diff --git a/src/waypoint.js b/src/waypoint.js index 2ee5dc3a..0c9b250e 100644 --- a/src/waypoint.js +++ b/src/waypoint.js @@ -11,6 +11,9 @@ if (!options.element) { throw new Error('No element option passed to Waypoint constructor') } + if (!options.handler) { + throw new Error('No handler option passed to Waypoint constructor') + } this.key = 'waypoint-' + keyCounter this.options = Waypoint.Adapter.extend({}, Waypoint.defaults, options) diff --git a/test/adapter-fn-spec.js b/test/adapter-fn-spec.js index 4a5feef5..eca92b9e 100644 --- a/test/adapter-fn-spec.js +++ b/test/adapter-fn-spec.js @@ -25,13 +25,13 @@ window.jQuery.each(window.jQuery.grep(Waypoint.adapters, function(adapter) { describe('waypoint initialization', function() { it('uses the subject elements as the element option', function() { - waypoints = $('.nearsame').waypoint({}) + waypoints = $('.nearsame').waypoint(function() {}) expect(waypoints[0].element.id).toEqual('near1') expect(waypoints[1].element.id).toEqual('near2') }) it('returns an array of Waypoint instances', function() { - waypoints = $('.nearsame').waypoint({}) + waypoints = $('.nearsame').waypoint(function() {}) expect($.isArray(waypoints)).toBeTruthy() expect(waypoints.length).toEqual(2) }) @@ -46,7 +46,8 @@ window.jQuery.each(window.jQuery.grep(Waypoint.adapters, function(adapter) { describe('context option', function() { it('can be given a string selector', function() { waypoints = $('#inner3').waypoint({ - context: '#bottom' + context: '#bottom', + handler: function() {} }) expect(waypoints[0].context.element).toBe($('#bottom')[0]) }) diff --git a/test/context-spec.js b/test/context-spec.js index 292db620..8593c978 100644 --- a/test/context-spec.js +++ b/test/context-spec.js @@ -90,7 +90,8 @@ window.jQuery.each(Waypoint.adapters, function(i, adapter) { it('calls refresh on all contexts', function() { var secondWaypoint = new Waypoint({ element: $('#inner3')[0], - context: $('#bottom')[0] + context: $('#bottom')[0], + handler: function() {} }) var secondContext = secondWaypoint.context spyOn(context, 'refresh') diff --git a/test/group-spec.js b/test/group-spec.js index c911e642..613f7be1 100644 --- a/test/group-spec.js +++ b/test/group-spec.js @@ -15,14 +15,17 @@ window.jQuery.each(Waypoint.adapters, function(i, adapter) { Waypoint.Adapter = adapter.Adapter loadFixtures('standard.html') firstWaypoint = new Waypoint({ - element: $('#same1')[0] + element: $('#same1')[0], + handler: function() {} }) secondWaypoint = new Waypoint({ - element: $('#near1')[0] + element: $('#near1')[0], + handler: function() {} }) customGroupWaypoint = new Waypoint({ element: $('#same2')[0], - group: 'custom' + group: 'custom', + handler: function() {} }) defaultGroup = firstWaypoint.group }) diff --git a/test/waypoint-spec.js b/test/waypoint-spec.js index 790caf18..e4519ec1 100644 --- a/test/waypoint-spec.js +++ b/test/waypoint-spec.js @@ -44,14 +44,25 @@ window.jQuery.each(Waypoint.adapters, function(i, adapter) { describe('new Waypoint(options)', function() { it('returns an instance of the Waypoint class', function() { waypoint = new Waypoint({ - element: document.getElementById('same1') + element: document.getElementById('same1'), + handler: function() {} }) expect(waypoint instanceof Waypoint).toBeTruthy() }) it('requires the element option', function() { expect(function() { - waypoint = new Waypoint({}) + waypoint = new Waypoint({ + handler: function() {} + }) + }).toThrow() + }) + + it('requires the handler option', function() { + expect(function() { + waypoint = new Waypoint({ + element: document.getElementById('same1') + }) }).toThrow() }) @@ -510,10 +521,12 @@ window.jQuery.each(Waypoint.adapters, function(i, adapter) { describe('Waypoint.destroyAll()', function() { it('calls destroy on all waypoints', function() { var secondWaypoint = new Waypoint({ - element: $('#same1')[0] + element: $('#same1')[0], + handler: function() {} }) waypoint = new Waypoint({ - element: $('#same1')[0] + element: $('#same1')[0], + handler: function() {} }) spyOn(secondWaypoint, 'destroy').andCallThrough() spyOn(waypoint, 'destroy').andCallThrough() From aebf467e66babc0d2e09be6f26a09de88d6a17a3 Mon Sep 17 00:00:00 2001 From: imakewebthings Date: Wed, 3 Dec 2014 16:35:13 -0800 Subject: [PATCH 37/98] Make sticky destroy resistant to multiple calls --- lib/shortcuts/sticky.js | 6 ++++-- lib/shortcuts/sticky.min.js | 2 +- src/shortcuts/sticky.js | 6 ++++-- 3 files changed, 9 insertions(+), 5 deletions(-) diff --git a/lib/shortcuts/sticky.js b/lib/shortcuts/sticky.js index 8576873c..fef6ea59 100644 --- a/lib/shortcuts/sticky.js +++ b/lib/shortcuts/sticky.js @@ -47,8 +47,10 @@ https://github.com/imakewebthings/waypoints/blog/master/licenses.txt /* Public */ Sticky.prototype.destroy = function() { - this.waypoint.destroy() - this.$element.removeClass(this.options.stuckClass).unwrap() + if (this.$element.parent()[0] === this.wrapper) { + this.waypoint.destroy() + this.$element.removeClass(this.options.stuckClass).unwrap() + } } Sticky.defaults = { diff --git a/lib/shortcuts/sticky.min.js b/lib/shortcuts/sticky.min.js index 86d4fa2d..bf998bfa 100644 --- a/lib/shortcuts/sticky.min.js +++ b/lib/shortcuts/sticky.min.js @@ -4,4 +4,4 @@ Copyright © 2011-2014 Caleb Troughton Licensed under the MIT license. https://github.com/imakewebthings/waypoints/blog/master/licenses.txt */ -!function(){"use strict";function t(s){this.options=e.extend({},i.defaults,t.defaults,s),this.element=this.options.element,this.$element=e(this.element),this.createWrapper(),this.createWaypoint()}var e=window.jQuery,i=window.Waypoint;t.prototype.createWaypoint=function(){var t=this.options.handler;this.waypoint=new i(e.extend({},this.options,{element:this.wrapper,handler:e.proxy(function(e){var i=this.options.direction.indexOf(e)>-1,s=i?this.$element.outerHeight(!0):"";this.$element.toggleClass(this.options.stuckClass,i),this.$wrapper.height(s),t&&t.call(this,e)},this)}))},t.prototype.createWrapper=function(){this.$element.wrap(this.options.wrapper),this.$wrapper=this.$element.parent(),this.wrapper=this.$wrapper[0]},t.prototype.destroy=function(){this.waypoint.destroy(),this.$element.removeClass(this.options.stuckClass).unwrap()},t.defaults={wrapper:'
',stuckClass:"stuck",direction:"down right"},i.Sticky=t}(); \ No newline at end of file +!function(){"use strict";function t(s){this.options=e.extend({},i.defaults,t.defaults,s),this.element=this.options.element,this.$element=e(this.element),this.createWrapper(),this.createWaypoint()}var e=window.jQuery,i=window.Waypoint;t.prototype.createWaypoint=function(){var t=this.options.handler;this.waypoint=new i(e.extend({},this.options,{element:this.wrapper,handler:e.proxy(function(e){var i=this.options.direction.indexOf(e)>-1,s=i?this.$element.outerHeight(!0):"";this.$element.toggleClass(this.options.stuckClass,i),this.$wrapper.height(s),t&&t.call(this,e)},this)}))},t.prototype.createWrapper=function(){this.$element.wrap(this.options.wrapper),this.$wrapper=this.$element.parent(),this.wrapper=this.$wrapper[0]},t.prototype.destroy=function(){this.$element.parent()[0]===this.wrapper&&(this.waypoint.destroy(),this.$element.removeClass(this.options.stuckClass).unwrap())},t.defaults={wrapper:'
',stuckClass:"stuck",direction:"down right"},i.Sticky=t}(); \ No newline at end of file diff --git a/src/shortcuts/sticky.js b/src/shortcuts/sticky.js index 060bf778..8e7c86c2 100644 --- a/src/shortcuts/sticky.js +++ b/src/shortcuts/sticky.js @@ -41,8 +41,10 @@ /* Public */ Sticky.prototype.destroy = function() { - this.waypoint.destroy() - this.$element.removeClass(this.options.stuckClass).unwrap() + if (this.$element.parent()[0] === this.wrapper) { + this.waypoint.destroy() + this.$element.removeClass(this.options.stuckClass).unwrap() + } } Sticky.defaults = { From 5059429edecdf7b1f7bc457d26482e26849955de Mon Sep 17 00:00:00 2001 From: imakewebthings Date: Wed, 3 Dec 2014 16:37:36 -0800 Subject: [PATCH 38/98] Fix infinite more-link replacement after page 2 --- lib/shortcuts/infinite.js | 4 ++-- lib/shortcuts/infinite.min.js | 2 +- src/shortcuts/infinite.js | 4 ++-- 3 files changed, 5 insertions(+), 5 deletions(-) diff --git a/lib/shortcuts/infinite.js b/lib/shortcuts/infinite.js index 350b2ffc..283a208a 100644 --- a/lib/shortcuts/infinite.js +++ b/lib/shortcuts/infinite.js @@ -18,9 +18,8 @@ https://github.com/imakewebthings/waypoints/blog/master/licenses.txt } this.$container = $(this.container) this.$more = $(this.options.more) - this.more = this.$more[0] - if (this.more) { + if (this.$more.length) { this.setupHandler() this.waypoint = new Waypoint(this.options) } @@ -46,6 +45,7 @@ https://github.com/imakewebthings/waypoints/blog/master/licenses.txt } if ($newMore.length) { this.$more.replaceWith($newMore) + this.$more = $newMore this.waypoint = new Waypoint(this.options) } else { diff --git a/lib/shortcuts/infinite.min.js b/lib/shortcuts/infinite.min.js index ee53dc2d..688a700c 100644 --- a/lib/shortcuts/infinite.min.js +++ b/lib/shortcuts/infinite.min.js @@ -4,4 +4,4 @@ Copyright © 2011-2014 Caleb Troughton Licensed under the MIT license. https://github.com/imakewebthings/waypoints/blog/master/licenses.txt */ -!function(){"use strict";function t(n){this.options=i.extend({},t.defaults,n),this.container=this.options.element,"auto"!==this.options.container&&(this.container=this.options.container),this.$container=i(this.container),this.$more=i(this.options.more),this.more=this.$more[0],this.more&&(this.setupHandler(),this.waypoint=new o(this.options))}var i=window.jQuery,o=window.Waypoint;t.prototype.setupHandler=function(){this.options.handler=i.proxy(function(){window.setTimeout(i.proxy(function(){this.options.onBeforePageLoad(),this.destroy(),this.$container.addClass(this.options.loadingClass),i.get(i(this.options.more).attr("href"),i.proxy(function(t){var n=i(i.parseHTML(t)),s=n.find(this.options.more);this.$container.append(n.find(this.options.items)),this.$container.removeClass(this.options.loadingClass),s.length||(s=n.filter(this.options.more)),s.length?(this.$more.replaceWith(s),this.waypoint=new o(this.options)):this.$more.remove(),this.options.onAfterPageLoad()},this),0)},this))},this)},t.prototype.destroy=function(){this.waypoint&&this.waypoint.destroy()},t.defaults={container:"auto",items:".infinite-item",more:".infinite-more-link",offset:"bottom-in-view",loadingClass:"infinite-loading",onBeforePageLoad:i.noop,onAfterPageLoad:i.noop},o.Infinite=t}(); \ No newline at end of file +!function(){"use strict";function t(n){this.options=i.extend({},t.defaults,n),this.container=this.options.element,"auto"!==this.options.container&&(this.container=this.options.container),this.$container=i(this.container),this.$more=i(this.options.more),this.$more.length&&(this.setupHandler(),this.waypoint=new o(this.options))}var i=window.jQuery,o=window.Waypoint;t.prototype.setupHandler=function(){this.options.handler=i.proxy(function(){window.setTimeout(i.proxy(function(){this.options.onBeforePageLoad(),this.destroy(),this.$container.addClass(this.options.loadingClass),i.get(i(this.options.more).attr("href"),i.proxy(function(t){var n=i(i.parseHTML(t)),e=n.find(this.options.more);this.$container.append(n.find(this.options.items)),this.$container.removeClass(this.options.loadingClass),e.length||(e=n.filter(this.options.more)),e.length?(this.$more.replaceWith(e),this.$more=e,this.waypoint=new o(this.options)):this.$more.remove(),this.options.onAfterPageLoad()},this),0)},this))},this)},t.prototype.destroy=function(){this.waypoint&&this.waypoint.destroy()},t.defaults={container:"auto",items:".infinite-item",more:".infinite-more-link",offset:"bottom-in-view",loadingClass:"infinite-loading",onBeforePageLoad:i.noop,onAfterPageLoad:i.noop},o.Infinite=t}(); \ No newline at end of file diff --git a/src/shortcuts/infinite.js b/src/shortcuts/infinite.js index f18b556c..8775d340 100644 --- a/src/shortcuts/infinite.js +++ b/src/shortcuts/infinite.js @@ -12,9 +12,8 @@ } this.$container = $(this.container) this.$more = $(this.options.more) - this.more = this.$more[0] - if (this.more) { + if (this.$more.length) { this.setupHandler() this.waypoint = new Waypoint(this.options) } @@ -40,6 +39,7 @@ } if ($newMore.length) { this.$more.replaceWith($newMore) + this.$more = $newMore this.waypoint = new Waypoint(this.options) } else { From 7bd9d9f980b8aa236001aeade280f8371c7480fc Mon Sep 17 00:00:00 2001 From: imakewebthings Date: Thu, 11 Dec 2014 17:46:09 -0800 Subject: [PATCH 39/98] Debug script --- gulpfile.js | 11 +++++++- lib/waypoints.debug.js | 41 ++++++++++++++++++++++++++++++ src/debug.js | 35 ++++++++++++++++++++++++++ test/debug-spec.js | 57 ++++++++++++++++++++++++++++++++++++++++++ testem.json | 1 + 5 files changed, 144 insertions(+), 1 deletion(-) create mode 100644 lib/waypoints.debug.js create mode 100644 src/debug.js create mode 100644 test/debug-spec.js diff --git a/gulpfile.js b/gulpfile.js index 4cc82829..33d35d31 100644 --- a/gulpfile.js +++ b/gulpfile.js @@ -76,7 +76,16 @@ gulp.task('build-shortcuts', function() { .pipe(gulp.dest('lib/shortcuts/')) }) -gulp.task('build', ['build-core', 'build-shortcuts']) +gulp.task('build-debug', function() { + return gulp.src([ + 'src/debug.js' + ]) + .pipe(rename('waypoints.debug.js')) + .pipe(header(fileHeader('Waypoints Debug'))) + .pipe(gulp.dest('lib/')) +}) + +gulp.task('build', ['build-core', 'build-shortcuts', 'build-debug']) gulp.task('watch', function() { gulp.watch(jsFiles, ['lint', 'build']) diff --git a/lib/waypoints.debug.js b/lib/waypoints.debug.js new file mode 100644 index 00000000..bb9f330a --- /dev/null +++ b/lib/waypoints.debug.js @@ -0,0 +1,41 @@ +/*! +Waypoints Debug - 2.0.5 +Copyright © 2011-2014 Caleb Troughton +Licensed under the MIT license. +https://github.com/imakewebthings/waypoints/blog/master/licenses.txt +*/ +(function() { + 'use strict' + + var displayNoneMessage = [ + 'You have a Waypoint element with display none. For more information on ', + 'why this is a bad idea read ', + 'http://imakewebthings.com/waypoints/guides/debugging/#display-none' + ].join('') + var fixedMessage = [ + 'You have a Waypoint element with fixed positioning. For more ', + 'information on why this is a bad idea read ', + 'http://imakewebthings.com/waypoints/guides/debugging/#fixed-position' + ].join('') + + function checkWaypointStyles() { + var originalRefresh = window.Waypoint.Context.prototype.refresh + + window.Waypoint.Context.prototype.refresh = function() { + for (var axis in this.waypoints) { + for (var key in this.waypoints[axis]) { + var style = this.waypoints[axis][key].element.style + if (style && style.display === 'none') { + console.error(displayNoneMessage) + } + if (style && style.position === 'fixed') { + console.error(fixedMessage) + } + } + } + return originalRefresh.call(this) + } + } + + checkWaypointStyles() +}()) diff --git a/src/debug.js b/src/debug.js new file mode 100644 index 00000000..b598c700 --- /dev/null +++ b/src/debug.js @@ -0,0 +1,35 @@ +(function() { + 'use strict' + + var displayNoneMessage = [ + 'You have a Waypoint element with display none. For more information on ', + 'why this is a bad idea read ', + 'http://imakewebthings.com/waypoints/guides/debugging/#display-none' + ].join('') + var fixedMessage = [ + 'You have a Waypoint element with fixed positioning. For more ', + 'information on why this is a bad idea read ', + 'http://imakewebthings.com/waypoints/guides/debugging/#fixed-position' + ].join('') + + function checkWaypointStyles() { + var originalRefresh = window.Waypoint.Context.prototype.refresh + + window.Waypoint.Context.prototype.refresh = function() { + for (var axis in this.waypoints) { + for (var key in this.waypoints[axis]) { + var style = this.waypoints[axis][key].element.style + if (style && style.display === 'none') { + console.error(displayNoneMessage) + } + if (style && style.position === 'fixed') { + console.error(fixedMessage) + } + } + } + return originalRefresh.call(this) + } + } + + checkWaypointStyles() +}()) diff --git a/test/debug-spec.js b/test/debug-spec.js new file mode 100644 index 00000000..b791dbbb --- /dev/null +++ b/test/debug-spec.js @@ -0,0 +1,57 @@ +'use strict' + +/* global + * describe, it, beforeEach, afterEach, expect, spyOn, waits, runs, + * waitsFor, loadFixtures, Waypoint + */ + +describe('Waypoints debug script', function() { + var waypoint, element + + beforeEach(function() { + loadFixtures('standard.html') + }) + + afterEach(function() { + waypoint.destroy() + }) + + describe('display none detection', function() { + beforeEach(function() { + element = document.getElementById('same1') + waypoint = new Waypoint({ + element: element, + handler: function() {} + }) + element.style.display = 'none' + }) + + it('logs a console error', function() { + spyOn(console, 'error') + waypoint.context.refresh() + expect(console.error).toHaveBeenCalled() + }) + }) + + describe('display fixed positioning detection', function() { + beforeEach(function() { + element = document.getElementById('same1') + waypoint = new Waypoint({ + element: element, + handler: function() {} + }) + element.style.position = 'fixed' + }) + + it('logs a console error', function() { + spyOn(console, 'error') + waypoint.context.refresh() + expect(console.error).toHaveBeenCalled() + }) + }) + + + describe('fixed position detection', function() { + + }) +}) diff --git a/testem.json b/testem.json index 9e9ae955..21f89a03 100644 --- a/testem.json +++ b/testem.json @@ -14,6 +14,7 @@ "src/waypoint.js", "src/context.js", "src/group.js", + "src/debug.js", "src/adapters/*.js", "src/shortcuts/*.js", From 0020cc74b380a5a6f8604e161c5d24131305333b Mon Sep 17 00:00:00 2001 From: imakewebthings Date: Thu, 11 Dec 2014 17:54:14 -0800 Subject: [PATCH 40/98] Set sticky wrapper height before class toggle --- src/shortcuts/sticky.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/shortcuts/sticky.js b/src/shortcuts/sticky.js index 8e7c86c2..4e3bb083 100644 --- a/src/shortcuts/sticky.js +++ b/src/shortcuts/sticky.js @@ -22,8 +22,8 @@ var shouldBeStuck = this.options.direction.indexOf(direction) > -1 var wrapperHeight = shouldBeStuck ? this.$element.outerHeight(true) : '' - this.$element.toggleClass(this.options.stuckClass, shouldBeStuck) this.$wrapper.height(wrapperHeight) + this.$element.toggleClass(this.options.stuckClass, shouldBeStuck) if (originalHandler) { originalHandler.call(this, direction) From 254f177f3e4dddc9f9e8a23da654d2a2c549cb48 Mon Sep 17 00:00:00 2001 From: imakewebthings Date: Thu, 11 Dec 2014 18:29:18 -0800 Subject: [PATCH 41/98] Refresh on page load --- lib/jquery.waypoints.js | 5 +++++ lib/jquery.waypoints.min.js | 2 +- lib/noframework.waypoints.js | 5 +++++ lib/noframework.waypoints.min.js | 2 +- lib/shortcuts/sticky.js | 2 +- lib/shortcuts/sticky.min.js | 2 +- lib/zepto.waypoints.js | 5 +++++ lib/zepto.waypoints.min.js | 2 +- src/context.js | 5 +++++ 9 files changed, 25 insertions(+), 5 deletions(-) diff --git a/lib/jquery.waypoints.js b/lib/jquery.waypoints.js index 0d1e5aae..dc2bcc21 100644 --- a/lib/jquery.waypoints.js +++ b/lib/jquery.waypoints.js @@ -151,6 +151,7 @@ https://github.com/imakewebthings/waypoints/blog/master/licenses.txt window.mozRequestAnimationFrame || window.webkitRequestAnimationFrame || requestAnimationFrameShim + var oldWindowLoad = window.onload function Context(element) { this.element = element @@ -412,6 +413,10 @@ https://github.com/imakewebthings/waypoints/blog/master/licenses.txt return contexts[element.waypointContextKey] } + window.onload = function() { + oldWindowLoad() + Context.refreshAll() + } Waypoint.Context = Context }()) ;(function() { diff --git a/lib/jquery.waypoints.min.js b/lib/jquery.waypoints.min.js index f2ac41e3..e6019da9 100644 --- a/lib/jquery.waypoints.min.js +++ b/lib/jquery.waypoints.min.js @@ -4,4 +4,4 @@ Copyright © 2011-2014 Caleb Troughton Licensed under the MIT license. https://github.com/imakewebthings/waypoints/blog/master/licenses.txt */ -!function(){"use strict";function t(i){if(!i)throw new Error("No options passed to Waypoint constructor");if(!i.element)throw new Error("No element option passed to Waypoint constructor");if(!i.handler)throw new Error("No handler option passed to Waypoint constructor");this.key="waypoint-"+e,this.options=t.Adapter.extend({},t.defaults,i),this.element=this.options.element,this.adapter=new t.Adapter(this.element),this.callback=i.handler,this.axis=this.options.horizontal?"horizontal":"vertical",this.enabled=this.options.enabled,this.triggerPoint=null,this.group=t.Group.findOrCreate({name:this.options.group,axis:this.axis}),this.context=t.Context.findOrCreateByElement(this.options.context),t.offsetAliases[this.options.offset]&&(this.options.offset=t.offsetAliases[this.options.offset]),this.group.add(this),this.context.add(this),o[this.key]=this,e+=1}var e=0,o={};t.prototype.queueTrigger=function(t){this.group.queueTrigger(this,t)},t.prototype.trigger=function(t){this.enabled&&this.callback&&this.callback.apply(this,t)},t.prototype.destroy=function(){this.context.remove(this),this.group.remove(this),delete o[this.key]},t.prototype.disable=function(){return this.enabled=!1,this},t.prototype.enable=function(){return this.context.refresh(),this.enabled=!0,this},t.prototype.next=function(){return this.group.next(this)},t.prototype.previous=function(){return this.group.previous(this)},t.destroyAll=function(){var t=[];for(var e in o)t.push(o[e]);for(var i=0,r=t.length;r>i;i++)t[i].destroy()},t.refreshAll=function(){t.Context.refreshAll()},t.viewportHeight=function(){return window.innerHeight||document.documentElement.clientHeight},t.viewportWidth=function(){return document.documentElement.clientWidth},t.adapters=[],t.defaults={context:window,continuous:!0,enabled:!0,group:"default",horizontal:!1,offset:0},t.offsetAliases={"bottom-in-view":function(){return this.context.height()-this.adapter.outerHeight()},"right-in-view":function(){return this.context.width()-this.adapter.outerWidth()}},window.Waypoint=t}(),function(){"use strict";function t(t){window.setTimeout(t,1e3/60)}function e(t){this.element=t,this.Adapter=r.Adapter,this.adapter=new this.Adapter(t),this.key="waypoint-context-"+o,this.didScroll=!1,this.didResize=!1,this.oldScroll={x:this.adapter.scrollLeft(),y:this.adapter.scrollTop()},this.waypoints={vertical:{},horizontal:{}},t.waypointContextKey=this.key,i[t.waypointContextKey]=this,o+=1,this.createThrottledScrollHandler(),this.createThrottledResizeHandler()}var o=0,i={},r=window.Waypoint,n=window.requestAnimationFrame||window.mozRequestAnimationFrame||window.webkitRequestAnimationFrame||t;e.prototype.add=function(t){var e=t.options.horizontal?"horizontal":"vertical";this.waypoints[e][t.key]=t,this.refresh()},e.prototype.checkEmpty=function(){var t=this.Adapter.isEmptyObject(this.waypoints.horizontal),e=this.Adapter.isEmptyObject(this.waypoints.vertical);t&&e&&(this.adapter.off(".waypoints"),delete i[this.key])},e.prototype.createThrottledResizeHandler=function(){function t(){e.handleResize(),e.didResize=!1}var e=this;this.adapter.on("resize.waypoints",function(){e.didResize||(e.didResize=!0,n(t))})},e.prototype.createThrottledScrollHandler=function(){function t(){e.handleScroll(),e.didScroll=!1}var e=this;this.adapter.on("scroll.waypoints",function(){(!e.didScroll||r.isTouch)&&(e.didScroll=!0,n(t))})},e.prototype.handleResize=function(){r.Context.refreshAll()},e.prototype.handleScroll=function(){var t={},e={horizontal:{newScroll:this.adapter.scrollLeft(),oldScroll:this.oldScroll.x,forward:"right",backward:"left"},vertical:{newScroll:this.adapter.scrollTop(),oldScroll:this.oldScroll.y,forward:"down",backward:"up"}};for(var o in e){var i=e[o],r=i.newScroll>i.oldScroll,n=r?i.forward:i.backward;for(var s in this.waypoints[o]){var a=this.waypoints[o][s],l=i.oldScroll=a.triggerPoint,p=l&&h,u=!l&&!h;(p||u)&&(a.queueTrigger(n),t[a.group.id]=a.group)}}for(var c in t)t[c].flushTriggers();this.oldScroll={x:e.horizontal.newScroll,y:e.vertical.newScroll}},e.prototype.height=function(){return this.element===this.element.window?r.viewportHeight():this.adapter.height()},e.prototype.remove=function(t){delete this.waypoints[t.axis][t.key],this.checkEmpty()},e.prototype.width=function(){return this.element===this.element.window?r.viewportWidth():this.adapter.width()},e.prototype.destroy=function(){var t=[];for(var e in this.waypoints)for(var o in this.waypoints[e])t.push(this.waypoints[e][o]);for(var i=0,r=t.length;r>i;i++)t[i].destroy()},e.prototype.refresh=function(){var t,e=this.element===this.element.window,o=this.adapter.offset(),i={};this.handleScroll(),t={horizontal:{contextOffset:e?0:o.left,contextScroll:e?0:this.oldScroll.x,contextDimension:this.width(),oldScroll:this.oldScroll.x,forward:"right",backward:"left",offsetProp:"left"},vertical:{contextOffset:e?0:o.top,contextScroll:e?0:this.oldScroll.y,contextDimension:this.height(),oldScroll:this.oldScroll.y,forward:"down",backward:"up",offsetProp:"top"}};for(var r in t){var n=t[r];for(var s in this.waypoints[r]){var a,l,h,p,u,c=this.waypoints[r][s],d=c.options.offset,f=c.triggerPoint,w=0,y=null==f;c.element!==c.element.window&&(w=c.adapter.offset()[n.offsetProp]),"function"==typeof d?d=d.apply(c):"string"==typeof d&&(d=parseFloat(d),c.options.offset.indexOf("%")>-1&&(d=Math.ceil(n.contextDimension*d/100))),a=n.contextScroll-n.contextOffset,c.triggerPoint=w+a-d,l=f=n.oldScroll,p=l&&h,u=!l&&!h,!y&&p?(c.queueTrigger(n.backward),i[c.group.id]=c.group):!y&&u?(c.queueTrigger(n.forward),i[c.group.id]=c.group):y&&n.oldScroll>=c.triggerPoint&&(c.queueTrigger(n.forward),i[c.group.id]=c.group)}}for(var g in i)i[g].flushTriggers();return this},e.findOrCreateByElement=function(t){return e.findByElement(t)||new e(t)},e.refreshAll=function(){for(var t in i)i[t].refresh()},e.findByElement=function(t){return i[t.waypointContextKey]},r.Context=e}(),function(){"use strict";function t(t,e){return t.triggerPoint-e.triggerPoint}function e(t,e){return e.triggerPoint-t.triggerPoint}function o(t){this.name=t.name,this.axis=t.axis,this.id=this.name+"-"+this.axis,this.waypoints=[],this.clearTriggerQueues(),i[this.axis][this.name]=this}var i={vertical:{},horizontal:{}},r=window.Waypoint;o.prototype.add=function(t){this.waypoints.push(t)},o.prototype.clearTriggerQueues=function(){this.triggerQueues={up:[],down:[],left:[],right:[]}},o.prototype.flushTriggers=function(){for(var o in this.triggerQueues){var i=this.triggerQueues[o],r="up"===o||"left"===o;i.sort(r?e:t);for(var n=0,s=i.length;s>n;n+=1){var a=i[n];(a.options.continuous||n===i.length-1)&&a.trigger([o])}}this.clearTriggerQueues()},o.prototype.next=function(e){this.waypoints.sort(t);var o=r.Adapter.inArray(e,this.waypoints),i=o===this.waypoints.length-1;return i?null:this.waypoints[o+1]},o.prototype.previous=function(e){this.waypoints.sort(t);var o=r.Adapter.inArray(e,this.waypoints);return o?this.waypoints[o-1]:null},o.prototype.queueTrigger=function(t,e){this.triggerQueues[e].push(t)},o.prototype.remove=function(t){var e=r.Adapter.inArray(t,this.waypoints);e>-1&&this.waypoints.splice(e,1)},o.prototype.first=function(){return this.waypoints[0]},o.prototype.last=function(){return this.waypoints[this.waypoints.length-1]},o.findOrCreate=function(t){return i[t.axis][t.name]||new o(t)},r.Group=o}(),function(){"use strict";function t(t){this.$element=e(t)}var e=window.jQuery,o=window.Waypoint;e.each(["height","off","offset","on","outerHeight","outerWidth","scrollLeft","scrollTop","width"],function(e,o){t.prototype[o]=function(){var t=Array.prototype.slice.call(arguments);return this.$element[o].apply(this.$element,t)}}),e.each(["extend","inArray","isEmptyObject"],function(o,i){t[i]=e[i]}),o.adapters.push({name:"jquery",Adapter:t}),o.Adapter=t}(),function(){"use strict";function t(t){return function(){var o=[],i=arguments[0];return t.isFunction(arguments[0])&&(i=t.extend({},arguments[1]),i.handler=arguments[0]),this.each(function(){var r=t.extend({},i,{element:this});"string"==typeof r.context&&(r.context=t(this).closest(r.context)[0]),o.push(new e(r))}),o}}var e=window.Waypoint;window.jQuery&&(window.jQuery.fn.waypoint=t(window.jQuery)),window.Zepto&&(window.Zepto.fn.waypoint=t(window.Zepto))}(); \ No newline at end of file +!function(){"use strict";function t(i){if(!i)throw new Error("No options passed to Waypoint constructor");if(!i.element)throw new Error("No element option passed to Waypoint constructor");if(!i.handler)throw new Error("No handler option passed to Waypoint constructor");this.key="waypoint-"+e,this.options=t.Adapter.extend({},t.defaults,i),this.element=this.options.element,this.adapter=new t.Adapter(this.element),this.callback=i.handler,this.axis=this.options.horizontal?"horizontal":"vertical",this.enabled=this.options.enabled,this.triggerPoint=null,this.group=t.Group.findOrCreate({name:this.options.group,axis:this.axis}),this.context=t.Context.findOrCreateByElement(this.options.context),t.offsetAliases[this.options.offset]&&(this.options.offset=t.offsetAliases[this.options.offset]),this.group.add(this),this.context.add(this),o[this.key]=this,e+=1}var e=0,o={};t.prototype.queueTrigger=function(t){this.group.queueTrigger(this,t)},t.prototype.trigger=function(t){this.enabled&&this.callback&&this.callback.apply(this,t)},t.prototype.destroy=function(){this.context.remove(this),this.group.remove(this),delete o[this.key]},t.prototype.disable=function(){return this.enabled=!1,this},t.prototype.enable=function(){return this.context.refresh(),this.enabled=!0,this},t.prototype.next=function(){return this.group.next(this)},t.prototype.previous=function(){return this.group.previous(this)},t.destroyAll=function(){var t=[];for(var e in o)t.push(o[e]);for(var i=0,r=t.length;r>i;i++)t[i].destroy()},t.refreshAll=function(){t.Context.refreshAll()},t.viewportHeight=function(){return window.innerHeight||document.documentElement.clientHeight},t.viewportWidth=function(){return document.documentElement.clientWidth},t.adapters=[],t.defaults={context:window,continuous:!0,enabled:!0,group:"default",horizontal:!1,offset:0},t.offsetAliases={"bottom-in-view":function(){return this.context.height()-this.adapter.outerHeight()},"right-in-view":function(){return this.context.width()-this.adapter.outerWidth()}},window.Waypoint=t}(),function(){"use strict";function t(t){window.setTimeout(t,1e3/60)}function e(t){this.element=t,this.Adapter=r.Adapter,this.adapter=new this.Adapter(t),this.key="waypoint-context-"+o,this.didScroll=!1,this.didResize=!1,this.oldScroll={x:this.adapter.scrollLeft(),y:this.adapter.scrollTop()},this.waypoints={vertical:{},horizontal:{}},t.waypointContextKey=this.key,i[t.waypointContextKey]=this,o+=1,this.createThrottledScrollHandler(),this.createThrottledResizeHandler()}var o=0,i={},r=window.Waypoint,n=window.requestAnimationFrame||window.mozRequestAnimationFrame||window.webkitRequestAnimationFrame||t,s=window.onload;e.prototype.add=function(t){var e=t.options.horizontal?"horizontal":"vertical";this.waypoints[e][t.key]=t,this.refresh()},e.prototype.checkEmpty=function(){var t=this.Adapter.isEmptyObject(this.waypoints.horizontal),e=this.Adapter.isEmptyObject(this.waypoints.vertical);t&&e&&(this.adapter.off(".waypoints"),delete i[this.key])},e.prototype.createThrottledResizeHandler=function(){function t(){e.handleResize(),e.didResize=!1}var e=this;this.adapter.on("resize.waypoints",function(){e.didResize||(e.didResize=!0,n(t))})},e.prototype.createThrottledScrollHandler=function(){function t(){e.handleScroll(),e.didScroll=!1}var e=this;this.adapter.on("scroll.waypoints",function(){(!e.didScroll||r.isTouch)&&(e.didScroll=!0,n(t))})},e.prototype.handleResize=function(){r.Context.refreshAll()},e.prototype.handleScroll=function(){var t={},e={horizontal:{newScroll:this.adapter.scrollLeft(),oldScroll:this.oldScroll.x,forward:"right",backward:"left"},vertical:{newScroll:this.adapter.scrollTop(),oldScroll:this.oldScroll.y,forward:"down",backward:"up"}};for(var o in e){var i=e[o],r=i.newScroll>i.oldScroll,n=r?i.forward:i.backward;for(var s in this.waypoints[o]){var a=this.waypoints[o][s],l=i.oldScroll=a.triggerPoint,p=l&&h,u=!l&&!h;(p||u)&&(a.queueTrigger(n),t[a.group.id]=a.group)}}for(var c in t)t[c].flushTriggers();this.oldScroll={x:e.horizontal.newScroll,y:e.vertical.newScroll}},e.prototype.height=function(){return this.element===this.element.window?r.viewportHeight():this.adapter.height()},e.prototype.remove=function(t){delete this.waypoints[t.axis][t.key],this.checkEmpty()},e.prototype.width=function(){return this.element===this.element.window?r.viewportWidth():this.adapter.width()},e.prototype.destroy=function(){var t=[];for(var e in this.waypoints)for(var o in this.waypoints[e])t.push(this.waypoints[e][o]);for(var i=0,r=t.length;r>i;i++)t[i].destroy()},e.prototype.refresh=function(){var t,e=this.element===this.element.window,o=this.adapter.offset(),i={};this.handleScroll(),t={horizontal:{contextOffset:e?0:o.left,contextScroll:e?0:this.oldScroll.x,contextDimension:this.width(),oldScroll:this.oldScroll.x,forward:"right",backward:"left",offsetProp:"left"},vertical:{contextOffset:e?0:o.top,contextScroll:e?0:this.oldScroll.y,contextDimension:this.height(),oldScroll:this.oldScroll.y,forward:"down",backward:"up",offsetProp:"top"}};for(var r in t){var n=t[r];for(var s in this.waypoints[r]){var a,l,h,p,u,c=this.waypoints[r][s],d=c.options.offset,f=c.triggerPoint,w=0,y=null==f;c.element!==c.element.window&&(w=c.adapter.offset()[n.offsetProp]),"function"==typeof d?d=d.apply(c):"string"==typeof d&&(d=parseFloat(d),c.options.offset.indexOf("%")>-1&&(d=Math.ceil(n.contextDimension*d/100))),a=n.contextScroll-n.contextOffset,c.triggerPoint=w+a-d,l=f=n.oldScroll,p=l&&h,u=!l&&!h,!y&&p?(c.queueTrigger(n.backward),i[c.group.id]=c.group):!y&&u?(c.queueTrigger(n.forward),i[c.group.id]=c.group):y&&n.oldScroll>=c.triggerPoint&&(c.queueTrigger(n.forward),i[c.group.id]=c.group)}}for(var g in i)i[g].flushTriggers();return this},e.findOrCreateByElement=function(t){return e.findByElement(t)||new e(t)},e.refreshAll=function(){for(var t in i)i[t].refresh()},e.findByElement=function(t){return i[t.waypointContextKey]},window.onload=function(){s(),e.refreshAll()},r.Context=e}(),function(){"use strict";function t(t,e){return t.triggerPoint-e.triggerPoint}function e(t,e){return e.triggerPoint-t.triggerPoint}function o(t){this.name=t.name,this.axis=t.axis,this.id=this.name+"-"+this.axis,this.waypoints=[],this.clearTriggerQueues(),i[this.axis][this.name]=this}var i={vertical:{},horizontal:{}},r=window.Waypoint;o.prototype.add=function(t){this.waypoints.push(t)},o.prototype.clearTriggerQueues=function(){this.triggerQueues={up:[],down:[],left:[],right:[]}},o.prototype.flushTriggers=function(){for(var o in this.triggerQueues){var i=this.triggerQueues[o],r="up"===o||"left"===o;i.sort(r?e:t);for(var n=0,s=i.length;s>n;n+=1){var a=i[n];(a.options.continuous||n===i.length-1)&&a.trigger([o])}}this.clearTriggerQueues()},o.prototype.next=function(e){this.waypoints.sort(t);var o=r.Adapter.inArray(e,this.waypoints),i=o===this.waypoints.length-1;return i?null:this.waypoints[o+1]},o.prototype.previous=function(e){this.waypoints.sort(t);var o=r.Adapter.inArray(e,this.waypoints);return o?this.waypoints[o-1]:null},o.prototype.queueTrigger=function(t,e){this.triggerQueues[e].push(t)},o.prototype.remove=function(t){var e=r.Adapter.inArray(t,this.waypoints);e>-1&&this.waypoints.splice(e,1)},o.prototype.first=function(){return this.waypoints[0]},o.prototype.last=function(){return this.waypoints[this.waypoints.length-1]},o.findOrCreate=function(t){return i[t.axis][t.name]||new o(t)},r.Group=o}(),function(){"use strict";function t(t){this.$element=e(t)}var e=window.jQuery,o=window.Waypoint;e.each(["height","off","offset","on","outerHeight","outerWidth","scrollLeft","scrollTop","width"],function(e,o){t.prototype[o]=function(){var t=Array.prototype.slice.call(arguments);return this.$element[o].apply(this.$element,t)}}),e.each(["extend","inArray","isEmptyObject"],function(o,i){t[i]=e[i]}),o.adapters.push({name:"jquery",Adapter:t}),o.Adapter=t}(),function(){"use strict";function t(t){return function(){var o=[],i=arguments[0];return t.isFunction(arguments[0])&&(i=t.extend({},arguments[1]),i.handler=arguments[0]),this.each(function(){var r=t.extend({},i,{element:this});"string"==typeof r.context&&(r.context=t(this).closest(r.context)[0]),o.push(new e(r))}),o}}var e=window.Waypoint;window.jQuery&&(window.jQuery.fn.waypoint=t(window.jQuery)),window.Zepto&&(window.Zepto.fn.waypoint=t(window.Zepto))}(); \ No newline at end of file diff --git a/lib/noframework.waypoints.js b/lib/noframework.waypoints.js index 83ff1522..46c4a3da 100644 --- a/lib/noframework.waypoints.js +++ b/lib/noframework.waypoints.js @@ -151,6 +151,7 @@ https://github.com/imakewebthings/waypoints/blog/master/licenses.txt window.mozRequestAnimationFrame || window.webkitRequestAnimationFrame || requestAnimationFrameShim + var oldWindowLoad = window.onload function Context(element) { this.element = element @@ -412,6 +413,10 @@ https://github.com/imakewebthings/waypoints/blog/master/licenses.txt return contexts[element.waypointContextKey] } + window.onload = function() { + oldWindowLoad() + Context.refreshAll() + } Waypoint.Context = Context }()) ;(function() { diff --git a/lib/noframework.waypoints.min.js b/lib/noframework.waypoints.min.js index 2935047b..b68cb327 100644 --- a/lib/noframework.waypoints.min.js +++ b/lib/noframework.waypoints.min.js @@ -4,4 +4,4 @@ Copyright © 2011-2014 Caleb Troughton Licensed under the MIT license. https://github.com/imakewebthings/waypoints/blog/master/licenses.txt */ -!function(){"use strict";function t(o){if(!o)throw new Error("No options passed to Waypoint constructor");if(!o.element)throw new Error("No element option passed to Waypoint constructor");if(!o.handler)throw new Error("No handler option passed to Waypoint constructor");this.key="waypoint-"+e,this.options=t.Adapter.extend({},t.defaults,o),this.element=this.options.element,this.adapter=new t.Adapter(this.element),this.callback=o.handler,this.axis=this.options.horizontal?"horizontal":"vertical",this.enabled=this.options.enabled,this.triggerPoint=null,this.group=t.Group.findOrCreate({name:this.options.group,axis:this.axis}),this.context=t.Context.findOrCreateByElement(this.options.context),t.offsetAliases[this.options.offset]&&(this.options.offset=t.offsetAliases[this.options.offset]),this.group.add(this),this.context.add(this),i[this.key]=this,e+=1}var e=0,i={};t.prototype.queueTrigger=function(t){this.group.queueTrigger(this,t)},t.prototype.trigger=function(t){this.enabled&&this.callback&&this.callback.apply(this,t)},t.prototype.destroy=function(){this.context.remove(this),this.group.remove(this),delete i[this.key]},t.prototype.disable=function(){return this.enabled=!1,this},t.prototype.enable=function(){return this.context.refresh(),this.enabled=!0,this},t.prototype.next=function(){return this.group.next(this)},t.prototype.previous=function(){return this.group.previous(this)},t.destroyAll=function(){var t=[];for(var e in i)t.push(i[e]);for(var o=0,r=t.length;r>o;o++)t[o].destroy()},t.refreshAll=function(){t.Context.refreshAll()},t.viewportHeight=function(){return window.innerHeight||document.documentElement.clientHeight},t.viewportWidth=function(){return document.documentElement.clientWidth},t.adapters=[],t.defaults={context:window,continuous:!0,enabled:!0,group:"default",horizontal:!1,offset:0},t.offsetAliases={"bottom-in-view":function(){return this.context.height()-this.adapter.outerHeight()},"right-in-view":function(){return this.context.width()-this.adapter.outerWidth()}},window.Waypoint=t}(),function(){"use strict";function t(t){window.setTimeout(t,1e3/60)}function e(t){this.element=t,this.Adapter=r.Adapter,this.adapter=new this.Adapter(t),this.key="waypoint-context-"+i,this.didScroll=!1,this.didResize=!1,this.oldScroll={x:this.adapter.scrollLeft(),y:this.adapter.scrollTop()},this.waypoints={vertical:{},horizontal:{}},t.waypointContextKey=this.key,o[t.waypointContextKey]=this,i+=1,this.createThrottledScrollHandler(),this.createThrottledResizeHandler()}var i=0,o={},r=window.Waypoint,n=window.requestAnimationFrame||window.mozRequestAnimationFrame||window.webkitRequestAnimationFrame||t;e.prototype.add=function(t){var e=t.options.horizontal?"horizontal":"vertical";this.waypoints[e][t.key]=t,this.refresh()},e.prototype.checkEmpty=function(){var t=this.Adapter.isEmptyObject(this.waypoints.horizontal),e=this.Adapter.isEmptyObject(this.waypoints.vertical);t&&e&&(this.adapter.off(".waypoints"),delete o[this.key])},e.prototype.createThrottledResizeHandler=function(){function t(){e.handleResize(),e.didResize=!1}var e=this;this.adapter.on("resize.waypoints",function(){e.didResize||(e.didResize=!0,n(t))})},e.prototype.createThrottledScrollHandler=function(){function t(){e.handleScroll(),e.didScroll=!1}var e=this;this.adapter.on("scroll.waypoints",function(){(!e.didScroll||r.isTouch)&&(e.didScroll=!0,n(t))})},e.prototype.handleResize=function(){r.Context.refreshAll()},e.prototype.handleScroll=function(){var t={},e={horizontal:{newScroll:this.adapter.scrollLeft(),oldScroll:this.oldScroll.x,forward:"right",backward:"left"},vertical:{newScroll:this.adapter.scrollTop(),oldScroll:this.oldScroll.y,forward:"down",backward:"up"}};for(var i in e){var o=e[i],r=o.newScroll>o.oldScroll,n=r?o.forward:o.backward;for(var s in this.waypoints[i]){var a=this.waypoints[i][s],l=o.oldScroll=a.triggerPoint,p=l&&h,u=!l&&!h;(p||u)&&(a.queueTrigger(n),t[a.group.id]=a.group)}}for(var f in t)t[f].flushTriggers();this.oldScroll={x:e.horizontal.newScroll,y:e.vertical.newScroll}},e.prototype.height=function(){return this.element===this.element.window?r.viewportHeight():this.adapter.height()},e.prototype.remove=function(t){delete this.waypoints[t.axis][t.key],this.checkEmpty()},e.prototype.width=function(){return this.element===this.element.window?r.viewportWidth():this.adapter.width()},e.prototype.destroy=function(){var t=[];for(var e in this.waypoints)for(var i in this.waypoints[e])t.push(this.waypoints[e][i]);for(var o=0,r=t.length;r>o;o++)t[o].destroy()},e.prototype.refresh=function(){var t,e=this.element===this.element.window,i=this.adapter.offset(),o={};this.handleScroll(),t={horizontal:{contextOffset:e?0:i.left,contextScroll:e?0:this.oldScroll.x,contextDimension:this.width(),oldScroll:this.oldScroll.x,forward:"right",backward:"left",offsetProp:"left"},vertical:{contextOffset:e?0:i.top,contextScroll:e?0:this.oldScroll.y,contextDimension:this.height(),oldScroll:this.oldScroll.y,forward:"down",backward:"up",offsetProp:"top"}};for(var r in t){var n=t[r];for(var s in this.waypoints[r]){var a,l,h,p,u,f=this.waypoints[r][s],c=f.options.offset,d=f.triggerPoint,y=0,g=null==d;f.element!==f.element.window&&(y=f.adapter.offset()[n.offsetProp]),"function"==typeof c?c=c.apply(f):"string"==typeof c&&(c=parseFloat(c),f.options.offset.indexOf("%")>-1&&(c=Math.ceil(n.contextDimension*c/100))),a=n.contextScroll-n.contextOffset,f.triggerPoint=y+a-c,l=d=n.oldScroll,p=l&&h,u=!l&&!h,!g&&p?(f.queueTrigger(n.backward),o[f.group.id]=f.group):!g&&u?(f.queueTrigger(n.forward),o[f.group.id]=f.group):g&&n.oldScroll>=f.triggerPoint&&(f.queueTrigger(n.forward),o[f.group.id]=f.group)}}for(var w in o)o[w].flushTriggers();return this},e.findOrCreateByElement=function(t){return e.findByElement(t)||new e(t)},e.refreshAll=function(){for(var t in o)o[t].refresh()},e.findByElement=function(t){return o[t.waypointContextKey]},r.Context=e}(),function(){"use strict";function t(t,e){return t.triggerPoint-e.triggerPoint}function e(t,e){return e.triggerPoint-t.triggerPoint}function i(t){this.name=t.name,this.axis=t.axis,this.id=this.name+"-"+this.axis,this.waypoints=[],this.clearTriggerQueues(),o[this.axis][this.name]=this}var o={vertical:{},horizontal:{}},r=window.Waypoint;i.prototype.add=function(t){this.waypoints.push(t)},i.prototype.clearTriggerQueues=function(){this.triggerQueues={up:[],down:[],left:[],right:[]}},i.prototype.flushTriggers=function(){for(var i in this.triggerQueues){var o=this.triggerQueues[i],r="up"===i||"left"===i;o.sort(r?e:t);for(var n=0,s=o.length;s>n;n+=1){var a=o[n];(a.options.continuous||n===o.length-1)&&a.trigger([i])}}this.clearTriggerQueues()},i.prototype.next=function(e){this.waypoints.sort(t);var i=r.Adapter.inArray(e,this.waypoints),o=i===this.waypoints.length-1;return o?null:this.waypoints[i+1]},i.prototype.previous=function(e){this.waypoints.sort(t);var i=r.Adapter.inArray(e,this.waypoints);return i?this.waypoints[i-1]:null},i.prototype.queueTrigger=function(t,e){this.triggerQueues[e].push(t)},i.prototype.remove=function(t){var e=r.Adapter.inArray(t,this.waypoints);e>-1&&this.waypoints.splice(e,1)},i.prototype.first=function(){return this.waypoints[0]},i.prototype.last=function(){return this.waypoints[this.waypoints.length-1]},i.findOrCreate=function(t){return o[t.axis][t.name]||new i(t)},r.Group=i}(),function(){"use strict";function t(t){return t===t.window}function e(e){return t(e)?e:e.defaultView}function i(t){this.element=t,this.handlers={}}var o=window.Waypoint;i.prototype.height=function(){var e=t(this.element);return e?this.element.innerHeight:this.element.offsetHeight},i.prototype.off=function(t,e){function i(t,e,i){for(var o=0,r=e.length-1;r>o;o++){var n=e[o];i&&i!==n||t.removeEventListener(n)}}var o=t.split("."),r=o[0],n=o[1],s=this.element;if(n&&this.handlers[n]&&r)i(s,this.handlers[n][r],e),this.handlers[n][r]=[];else if(r)for(var a in this.handlers)i(s,this.handlers[a][r]||[],e),this.handlers[a][r]=[];else if(n&&this.handlers[n]){for(var l in this.handlers[n])i(s,this.handlers[n][l],e);this.handlers[n]={}}},i.prototype.offset=function(){if(!this.element.ownerDocument)return null;var t=this.element.ownerDocument.documentElement,i=e(this.element.ownerDocument),o={top:0,left:0};return this.element.getBoundingClientRect&&(o=this.element.getBoundingClientRect()),{top:o.top+i.pageYOffset-t.clientTop,left:o.left+i.pageXOffset-t.clientLeft}},i.prototype.on=function(t,e){var i=t.split("."),o=i[0],r=i[1]||"__default",n=this.handlers[r]=this.handlers[r]||{},s=n[o]=n[o]||[];s.push(e),this.element.addEventListener(o,e)},i.prototype.outerHeight=function(e){var i,o=this.height();return e&&!t(this.element)&&(i=window.getComputedStyle(this.element),o+=parseInt(i.marginTop,10),o+=parseInt(i.marginBottom,10)),o},i.prototype.outerWidth=function(e){var i,o=this.width();return e&&!t(this.element)&&(i=window.getComputedStyle(this.element),o+=parseInt(i.marginLeft,10),o+=parseInt(i.marginRight,10)),o},i.prototype.scrollLeft=function(){var t=e(this.element);return t?t.pageXOffset:this.element.scrollLeft},i.prototype.scrollTop=function(){var t=e(this.element);return t?t.pageYOffset:this.element.scrollTop},i.prototype.width=function(){var e=t(this.element);return e?this.element.innerWidth:this.element.offsetWidth},i.extend=function(){function t(t,e){if("object"==typeof t&&"object"==typeof e)for(var i in e)e.hasOwnProperty(i)&&(t[i]=e[i]);return t}for(var e=Array.prototype.slice.call(arguments),i=1,o=e.length;o>i;i++)t(e[0],e[i]);return e[0]},i.inArray=function(t,e,i){return null==e?-1:e.indexOf(t,i)},i.isEmptyObject=function(t){for(var e in t)return!1;return!0},o.adapters.push({name:"noframework",Adapter:i}),o.Adapter=i}(); \ No newline at end of file +!function(){"use strict";function t(o){if(!o)throw new Error("No options passed to Waypoint constructor");if(!o.element)throw new Error("No element option passed to Waypoint constructor");if(!o.handler)throw new Error("No handler option passed to Waypoint constructor");this.key="waypoint-"+e,this.options=t.Adapter.extend({},t.defaults,o),this.element=this.options.element,this.adapter=new t.Adapter(this.element),this.callback=o.handler,this.axis=this.options.horizontal?"horizontal":"vertical",this.enabled=this.options.enabled,this.triggerPoint=null,this.group=t.Group.findOrCreate({name:this.options.group,axis:this.axis}),this.context=t.Context.findOrCreateByElement(this.options.context),t.offsetAliases[this.options.offset]&&(this.options.offset=t.offsetAliases[this.options.offset]),this.group.add(this),this.context.add(this),i[this.key]=this,e+=1}var e=0,i={};t.prototype.queueTrigger=function(t){this.group.queueTrigger(this,t)},t.prototype.trigger=function(t){this.enabled&&this.callback&&this.callback.apply(this,t)},t.prototype.destroy=function(){this.context.remove(this),this.group.remove(this),delete i[this.key]},t.prototype.disable=function(){return this.enabled=!1,this},t.prototype.enable=function(){return this.context.refresh(),this.enabled=!0,this},t.prototype.next=function(){return this.group.next(this)},t.prototype.previous=function(){return this.group.previous(this)},t.destroyAll=function(){var t=[];for(var e in i)t.push(i[e]);for(var o=0,r=t.length;r>o;o++)t[o].destroy()},t.refreshAll=function(){t.Context.refreshAll()},t.viewportHeight=function(){return window.innerHeight||document.documentElement.clientHeight},t.viewportWidth=function(){return document.documentElement.clientWidth},t.adapters=[],t.defaults={context:window,continuous:!0,enabled:!0,group:"default",horizontal:!1,offset:0},t.offsetAliases={"bottom-in-view":function(){return this.context.height()-this.adapter.outerHeight()},"right-in-view":function(){return this.context.width()-this.adapter.outerWidth()}},window.Waypoint=t}(),function(){"use strict";function t(t){window.setTimeout(t,1e3/60)}function e(t){this.element=t,this.Adapter=r.Adapter,this.adapter=new this.Adapter(t),this.key="waypoint-context-"+i,this.didScroll=!1,this.didResize=!1,this.oldScroll={x:this.adapter.scrollLeft(),y:this.adapter.scrollTop()},this.waypoints={vertical:{},horizontal:{}},t.waypointContextKey=this.key,o[t.waypointContextKey]=this,i+=1,this.createThrottledScrollHandler(),this.createThrottledResizeHandler()}var i=0,o={},r=window.Waypoint,n=window.requestAnimationFrame||window.mozRequestAnimationFrame||window.webkitRequestAnimationFrame||t,s=window.onload;e.prototype.add=function(t){var e=t.options.horizontal?"horizontal":"vertical";this.waypoints[e][t.key]=t,this.refresh()},e.prototype.checkEmpty=function(){var t=this.Adapter.isEmptyObject(this.waypoints.horizontal),e=this.Adapter.isEmptyObject(this.waypoints.vertical);t&&e&&(this.adapter.off(".waypoints"),delete o[this.key])},e.prototype.createThrottledResizeHandler=function(){function t(){e.handleResize(),e.didResize=!1}var e=this;this.adapter.on("resize.waypoints",function(){e.didResize||(e.didResize=!0,n(t))})},e.prototype.createThrottledScrollHandler=function(){function t(){e.handleScroll(),e.didScroll=!1}var e=this;this.adapter.on("scroll.waypoints",function(){(!e.didScroll||r.isTouch)&&(e.didScroll=!0,n(t))})},e.prototype.handleResize=function(){r.Context.refreshAll()},e.prototype.handleScroll=function(){var t={},e={horizontal:{newScroll:this.adapter.scrollLeft(),oldScroll:this.oldScroll.x,forward:"right",backward:"left"},vertical:{newScroll:this.adapter.scrollTop(),oldScroll:this.oldScroll.y,forward:"down",backward:"up"}};for(var i in e){var o=e[i],r=o.newScroll>o.oldScroll,n=r?o.forward:o.backward;for(var s in this.waypoints[i]){var a=this.waypoints[i][s],l=o.oldScroll=a.triggerPoint,p=l&&h,u=!l&&!h;(p||u)&&(a.queueTrigger(n),t[a.group.id]=a.group)}}for(var f in t)t[f].flushTriggers();this.oldScroll={x:e.horizontal.newScroll,y:e.vertical.newScroll}},e.prototype.height=function(){return this.element===this.element.window?r.viewportHeight():this.adapter.height()},e.prototype.remove=function(t){delete this.waypoints[t.axis][t.key],this.checkEmpty()},e.prototype.width=function(){return this.element===this.element.window?r.viewportWidth():this.adapter.width()},e.prototype.destroy=function(){var t=[];for(var e in this.waypoints)for(var i in this.waypoints[e])t.push(this.waypoints[e][i]);for(var o=0,r=t.length;r>o;o++)t[o].destroy()},e.prototype.refresh=function(){var t,e=this.element===this.element.window,i=this.adapter.offset(),o={};this.handleScroll(),t={horizontal:{contextOffset:e?0:i.left,contextScroll:e?0:this.oldScroll.x,contextDimension:this.width(),oldScroll:this.oldScroll.x,forward:"right",backward:"left",offsetProp:"left"},vertical:{contextOffset:e?0:i.top,contextScroll:e?0:this.oldScroll.y,contextDimension:this.height(),oldScroll:this.oldScroll.y,forward:"down",backward:"up",offsetProp:"top"}};for(var r in t){var n=t[r];for(var s in this.waypoints[r]){var a,l,h,p,u,f=this.waypoints[r][s],c=f.options.offset,d=f.triggerPoint,w=0,y=null==d;f.element!==f.element.window&&(w=f.adapter.offset()[n.offsetProp]),"function"==typeof c?c=c.apply(f):"string"==typeof c&&(c=parseFloat(c),f.options.offset.indexOf("%")>-1&&(c=Math.ceil(n.contextDimension*c/100))),a=n.contextScroll-n.contextOffset,f.triggerPoint=w+a-c,l=d=n.oldScroll,p=l&&h,u=!l&&!h,!y&&p?(f.queueTrigger(n.backward),o[f.group.id]=f.group):!y&&u?(f.queueTrigger(n.forward),o[f.group.id]=f.group):y&&n.oldScroll>=f.triggerPoint&&(f.queueTrigger(n.forward),o[f.group.id]=f.group)}}for(var g in o)o[g].flushTriggers();return this},e.findOrCreateByElement=function(t){return e.findByElement(t)||new e(t)},e.refreshAll=function(){for(var t in o)o[t].refresh()},e.findByElement=function(t){return o[t.waypointContextKey]},window.onload=function(){s(),e.refreshAll()},r.Context=e}(),function(){"use strict";function t(t,e){return t.triggerPoint-e.triggerPoint}function e(t,e){return e.triggerPoint-t.triggerPoint}function i(t){this.name=t.name,this.axis=t.axis,this.id=this.name+"-"+this.axis,this.waypoints=[],this.clearTriggerQueues(),o[this.axis][this.name]=this}var o={vertical:{},horizontal:{}},r=window.Waypoint;i.prototype.add=function(t){this.waypoints.push(t)},i.prototype.clearTriggerQueues=function(){this.triggerQueues={up:[],down:[],left:[],right:[]}},i.prototype.flushTriggers=function(){for(var i in this.triggerQueues){var o=this.triggerQueues[i],r="up"===i||"left"===i;o.sort(r?e:t);for(var n=0,s=o.length;s>n;n+=1){var a=o[n];(a.options.continuous||n===o.length-1)&&a.trigger([i])}}this.clearTriggerQueues()},i.prototype.next=function(e){this.waypoints.sort(t);var i=r.Adapter.inArray(e,this.waypoints),o=i===this.waypoints.length-1;return o?null:this.waypoints[i+1]},i.prototype.previous=function(e){this.waypoints.sort(t);var i=r.Adapter.inArray(e,this.waypoints);return i?this.waypoints[i-1]:null},i.prototype.queueTrigger=function(t,e){this.triggerQueues[e].push(t)},i.prototype.remove=function(t){var e=r.Adapter.inArray(t,this.waypoints);e>-1&&this.waypoints.splice(e,1)},i.prototype.first=function(){return this.waypoints[0]},i.prototype.last=function(){return this.waypoints[this.waypoints.length-1]},i.findOrCreate=function(t){return o[t.axis][t.name]||new i(t)},r.Group=i}(),function(){"use strict";function t(t){return t===t.window}function e(e){return t(e)?e:e.defaultView}function i(t){this.element=t,this.handlers={}}var o=window.Waypoint;i.prototype.height=function(){var e=t(this.element);return e?this.element.innerHeight:this.element.offsetHeight},i.prototype.off=function(t,e){function i(t,e,i){for(var o=0,r=e.length-1;r>o;o++){var n=e[o];i&&i!==n||t.removeEventListener(n)}}var o=t.split("."),r=o[0],n=o[1],s=this.element;if(n&&this.handlers[n]&&r)i(s,this.handlers[n][r],e),this.handlers[n][r]=[];else if(r)for(var a in this.handlers)i(s,this.handlers[a][r]||[],e),this.handlers[a][r]=[];else if(n&&this.handlers[n]){for(var l in this.handlers[n])i(s,this.handlers[n][l],e);this.handlers[n]={}}},i.prototype.offset=function(){if(!this.element.ownerDocument)return null;var t=this.element.ownerDocument.documentElement,i=e(this.element.ownerDocument),o={top:0,left:0};return this.element.getBoundingClientRect&&(o=this.element.getBoundingClientRect()),{top:o.top+i.pageYOffset-t.clientTop,left:o.left+i.pageXOffset-t.clientLeft}},i.prototype.on=function(t,e){var i=t.split("."),o=i[0],r=i[1]||"__default",n=this.handlers[r]=this.handlers[r]||{},s=n[o]=n[o]||[];s.push(e),this.element.addEventListener(o,e)},i.prototype.outerHeight=function(e){var i,o=this.height();return e&&!t(this.element)&&(i=window.getComputedStyle(this.element),o+=parseInt(i.marginTop,10),o+=parseInt(i.marginBottom,10)),o},i.prototype.outerWidth=function(e){var i,o=this.width();return e&&!t(this.element)&&(i=window.getComputedStyle(this.element),o+=parseInt(i.marginLeft,10),o+=parseInt(i.marginRight,10)),o},i.prototype.scrollLeft=function(){var t=e(this.element);return t?t.pageXOffset:this.element.scrollLeft},i.prototype.scrollTop=function(){var t=e(this.element);return t?t.pageYOffset:this.element.scrollTop},i.prototype.width=function(){var e=t(this.element);return e?this.element.innerWidth:this.element.offsetWidth},i.extend=function(){function t(t,e){if("object"==typeof t&&"object"==typeof e)for(var i in e)e.hasOwnProperty(i)&&(t[i]=e[i]);return t}for(var e=Array.prototype.slice.call(arguments),i=1,o=e.length;o>i;i++)t(e[0],e[i]);return e[0]},i.inArray=function(t,e,i){return null==e?-1:e.indexOf(t,i)},i.isEmptyObject=function(t){for(var e in t)return!1;return!0},o.adapters.push({name:"noframework",Adapter:i}),o.Adapter=i}(); \ No newline at end of file diff --git a/lib/shortcuts/sticky.js b/lib/shortcuts/sticky.js index fef6ea59..4bc9ac5a 100644 --- a/lib/shortcuts/sticky.js +++ b/lib/shortcuts/sticky.js @@ -28,8 +28,8 @@ https://github.com/imakewebthings/waypoints/blog/master/licenses.txt var shouldBeStuck = this.options.direction.indexOf(direction) > -1 var wrapperHeight = shouldBeStuck ? this.$element.outerHeight(true) : '' - this.$element.toggleClass(this.options.stuckClass, shouldBeStuck) this.$wrapper.height(wrapperHeight) + this.$element.toggleClass(this.options.stuckClass, shouldBeStuck) if (originalHandler) { originalHandler.call(this, direction) diff --git a/lib/shortcuts/sticky.min.js b/lib/shortcuts/sticky.min.js index bf998bfa..e7664e9a 100644 --- a/lib/shortcuts/sticky.min.js +++ b/lib/shortcuts/sticky.min.js @@ -4,4 +4,4 @@ Copyright © 2011-2014 Caleb Troughton Licensed under the MIT license. https://github.com/imakewebthings/waypoints/blog/master/licenses.txt */ -!function(){"use strict";function t(s){this.options=e.extend({},i.defaults,t.defaults,s),this.element=this.options.element,this.$element=e(this.element),this.createWrapper(),this.createWaypoint()}var e=window.jQuery,i=window.Waypoint;t.prototype.createWaypoint=function(){var t=this.options.handler;this.waypoint=new i(e.extend({},this.options,{element:this.wrapper,handler:e.proxy(function(e){var i=this.options.direction.indexOf(e)>-1,s=i?this.$element.outerHeight(!0):"";this.$element.toggleClass(this.options.stuckClass,i),this.$wrapper.height(s),t&&t.call(this,e)},this)}))},t.prototype.createWrapper=function(){this.$element.wrap(this.options.wrapper),this.$wrapper=this.$element.parent(),this.wrapper=this.$wrapper[0]},t.prototype.destroy=function(){this.$element.parent()[0]===this.wrapper&&(this.waypoint.destroy(),this.$element.removeClass(this.options.stuckClass).unwrap())},t.defaults={wrapper:'
',stuckClass:"stuck",direction:"down right"},i.Sticky=t}(); \ No newline at end of file +!function(){"use strict";function t(s){this.options=e.extend({},i.defaults,t.defaults,s),this.element=this.options.element,this.$element=e(this.element),this.createWrapper(),this.createWaypoint()}var e=window.jQuery,i=window.Waypoint;t.prototype.createWaypoint=function(){var t=this.options.handler;this.waypoint=new i(e.extend({},this.options,{element:this.wrapper,handler:e.proxy(function(e){var i=this.options.direction.indexOf(e)>-1,s=i?this.$element.outerHeight(!0):"";this.$wrapper.height(s),this.$element.toggleClass(this.options.stuckClass,i),t&&t.call(this,e)},this)}))},t.prototype.createWrapper=function(){this.$element.wrap(this.options.wrapper),this.$wrapper=this.$element.parent(),this.wrapper=this.$wrapper[0]},t.prototype.destroy=function(){this.$element.parent()[0]===this.wrapper&&(this.waypoint.destroy(),this.$element.removeClass(this.options.stuckClass).unwrap())},t.defaults={wrapper:'
',stuckClass:"stuck",direction:"down right"},i.Sticky=t}(); \ No newline at end of file diff --git a/lib/zepto.waypoints.js b/lib/zepto.waypoints.js index 45c5f5f8..5eb682a4 100644 --- a/lib/zepto.waypoints.js +++ b/lib/zepto.waypoints.js @@ -151,6 +151,7 @@ https://github.com/imakewebthings/waypoints/blog/master/licenses.txt window.mozRequestAnimationFrame || window.webkitRequestAnimationFrame || requestAnimationFrameShim + var oldWindowLoad = window.onload function Context(element) { this.element = element @@ -412,6 +413,10 @@ https://github.com/imakewebthings/waypoints/blog/master/licenses.txt return contexts[element.waypointContextKey] } + window.onload = function() { + oldWindowLoad() + Context.refreshAll() + } Waypoint.Context = Context }()) ;(function() { diff --git a/lib/zepto.waypoints.min.js b/lib/zepto.waypoints.min.js index f4272581..764e3b18 100644 --- a/lib/zepto.waypoints.min.js +++ b/lib/zepto.waypoints.min.js @@ -4,4 +4,4 @@ Copyright © 2011-2014 Caleb Troughton Licensed under the MIT license. https://github.com/imakewebthings/waypoints/blog/master/licenses.txt */ -!function(){"use strict";function t(i){if(!i)throw new Error("No options passed to Waypoint constructor");if(!i.element)throw new Error("No element option passed to Waypoint constructor");if(!i.handler)throw new Error("No handler option passed to Waypoint constructor");this.key="waypoint-"+e,this.options=t.Adapter.extend({},t.defaults,i),this.element=this.options.element,this.adapter=new t.Adapter(this.element),this.callback=i.handler,this.axis=this.options.horizontal?"horizontal":"vertical",this.enabled=this.options.enabled,this.triggerPoint=null,this.group=t.Group.findOrCreate({name:this.options.group,axis:this.axis}),this.context=t.Context.findOrCreateByElement(this.options.context),t.offsetAliases[this.options.offset]&&(this.options.offset=t.offsetAliases[this.options.offset]),this.group.add(this),this.context.add(this),o[this.key]=this,e+=1}var e=0,o={};t.prototype.queueTrigger=function(t){this.group.queueTrigger(this,t)},t.prototype.trigger=function(t){this.enabled&&this.callback&&this.callback.apply(this,t)},t.prototype.destroy=function(){this.context.remove(this),this.group.remove(this),delete o[this.key]},t.prototype.disable=function(){return this.enabled=!1,this},t.prototype.enable=function(){return this.context.refresh(),this.enabled=!0,this},t.prototype.next=function(){return this.group.next(this)},t.prototype.previous=function(){return this.group.previous(this)},t.destroyAll=function(){var t=[];for(var e in o)t.push(o[e]);for(var i=0,r=t.length;r>i;i++)t[i].destroy()},t.refreshAll=function(){t.Context.refreshAll()},t.viewportHeight=function(){return window.innerHeight||document.documentElement.clientHeight},t.viewportWidth=function(){return document.documentElement.clientWidth},t.adapters=[],t.defaults={context:window,continuous:!0,enabled:!0,group:"default",horizontal:!1,offset:0},t.offsetAliases={"bottom-in-view":function(){return this.context.height()-this.adapter.outerHeight()},"right-in-view":function(){return this.context.width()-this.adapter.outerWidth()}},window.Waypoint=t}(),function(){"use strict";function t(t){window.setTimeout(t,1e3/60)}function e(t){this.element=t,this.Adapter=r.Adapter,this.adapter=new this.Adapter(t),this.key="waypoint-context-"+o,this.didScroll=!1,this.didResize=!1,this.oldScroll={x:this.adapter.scrollLeft(),y:this.adapter.scrollTop()},this.waypoints={vertical:{},horizontal:{}},t.waypointContextKey=this.key,i[t.waypointContextKey]=this,o+=1,this.createThrottledScrollHandler(),this.createThrottledResizeHandler()}var o=0,i={},r=window.Waypoint,n=window.requestAnimationFrame||window.mozRequestAnimationFrame||window.webkitRequestAnimationFrame||t;e.prototype.add=function(t){var e=t.options.horizontal?"horizontal":"vertical";this.waypoints[e][t.key]=t,this.refresh()},e.prototype.checkEmpty=function(){var t=this.Adapter.isEmptyObject(this.waypoints.horizontal),e=this.Adapter.isEmptyObject(this.waypoints.vertical);t&&e&&(this.adapter.off(".waypoints"),delete i[this.key])},e.prototype.createThrottledResizeHandler=function(){function t(){e.handleResize(),e.didResize=!1}var e=this;this.adapter.on("resize.waypoints",function(){e.didResize||(e.didResize=!0,n(t))})},e.prototype.createThrottledScrollHandler=function(){function t(){e.handleScroll(),e.didScroll=!1}var e=this;this.adapter.on("scroll.waypoints",function(){(!e.didScroll||r.isTouch)&&(e.didScroll=!0,n(t))})},e.prototype.handleResize=function(){r.Context.refreshAll()},e.prototype.handleScroll=function(){var t={},e={horizontal:{newScroll:this.adapter.scrollLeft(),oldScroll:this.oldScroll.x,forward:"right",backward:"left"},vertical:{newScroll:this.adapter.scrollTop(),oldScroll:this.oldScroll.y,forward:"down",backward:"up"}};for(var o in e){var i=e[o],r=i.newScroll>i.oldScroll,n=r?i.forward:i.backward;for(var s in this.waypoints[o]){var a=this.waypoints[o][s],h=i.oldScroll=a.triggerPoint,p=h&&l,c=!h&&!l;(p||c)&&(a.queueTrigger(n),t[a.group.id]=a.group)}}for(var u in t)t[u].flushTriggers();this.oldScroll={x:e.horizontal.newScroll,y:e.vertical.newScroll}},e.prototype.height=function(){return this.element===this.element.window?r.viewportHeight():this.adapter.height()},e.prototype.remove=function(t){delete this.waypoints[t.axis][t.key],this.checkEmpty()},e.prototype.width=function(){return this.element===this.element.window?r.viewportWidth():this.adapter.width()},e.prototype.destroy=function(){var t=[];for(var e in this.waypoints)for(var o in this.waypoints[e])t.push(this.waypoints[e][o]);for(var i=0,r=t.length;r>i;i++)t[i].destroy()},e.prototype.refresh=function(){var t,e=this.element===this.element.window,o=this.adapter.offset(),i={};this.handleScroll(),t={horizontal:{contextOffset:e?0:o.left,contextScroll:e?0:this.oldScroll.x,contextDimension:this.width(),oldScroll:this.oldScroll.x,forward:"right",backward:"left",offsetProp:"left"},vertical:{contextOffset:e?0:o.top,contextScroll:e?0:this.oldScroll.y,contextDimension:this.height(),oldScroll:this.oldScroll.y,forward:"down",backward:"up",offsetProp:"top"}};for(var r in t){var n=t[r];for(var s in this.waypoints[r]){var a,h,l,p,c,u=this.waypoints[r][s],d=u.options.offset,f=u.triggerPoint,w=0,y=null==f;u.element!==u.element.window&&(w=u.adapter.offset()[n.offsetProp]),"function"==typeof d?d=d.apply(u):"string"==typeof d&&(d=parseFloat(d),u.options.offset.indexOf("%")>-1&&(d=Math.ceil(n.contextDimension*d/100))),a=n.contextScroll-n.contextOffset,u.triggerPoint=w+a-d,h=f=n.oldScroll,p=h&&l,c=!h&&!l,!y&&p?(u.queueTrigger(n.backward),i[u.group.id]=u.group):!y&&c?(u.queueTrigger(n.forward),i[u.group.id]=u.group):y&&n.oldScroll>=u.triggerPoint&&(u.queueTrigger(n.forward),i[u.group.id]=u.group)}}for(var g in i)i[g].flushTriggers();return this},e.findOrCreateByElement=function(t){return e.findByElement(t)||new e(t)},e.refreshAll=function(){for(var t in i)i[t].refresh()},e.findByElement=function(t){return i[t.waypointContextKey]},r.Context=e}(),function(){"use strict";function t(t,e){return t.triggerPoint-e.triggerPoint}function e(t,e){return e.triggerPoint-t.triggerPoint}function o(t){this.name=t.name,this.axis=t.axis,this.id=this.name+"-"+this.axis,this.waypoints=[],this.clearTriggerQueues(),i[this.axis][this.name]=this}var i={vertical:{},horizontal:{}},r=window.Waypoint;o.prototype.add=function(t){this.waypoints.push(t)},o.prototype.clearTriggerQueues=function(){this.triggerQueues={up:[],down:[],left:[],right:[]}},o.prototype.flushTriggers=function(){for(var o in this.triggerQueues){var i=this.triggerQueues[o],r="up"===o||"left"===o;i.sort(r?e:t);for(var n=0,s=i.length;s>n;n+=1){var a=i[n];(a.options.continuous||n===i.length-1)&&a.trigger([o])}}this.clearTriggerQueues()},o.prototype.next=function(e){this.waypoints.sort(t);var o=r.Adapter.inArray(e,this.waypoints),i=o===this.waypoints.length-1;return i?null:this.waypoints[o+1]},o.prototype.previous=function(e){this.waypoints.sort(t);var o=r.Adapter.inArray(e,this.waypoints);return o?this.waypoints[o-1]:null},o.prototype.queueTrigger=function(t,e){this.triggerQueues[e].push(t)},o.prototype.remove=function(t){var e=r.Adapter.inArray(t,this.waypoints);e>-1&&this.waypoints.splice(e,1)},o.prototype.first=function(){return this.waypoints[0]},o.prototype.last=function(){return this.waypoints[this.waypoints.length-1]},o.findOrCreate=function(t){return i[t.axis][t.name]||new o(t)},r.Group=o}(),function(){"use strict";function t(t){this.element=t,this.$element=e(t)}var e=window.Zepto,o=window.Waypoint;e.each(["height","off","on","scrollLeft","scrollTop","width"],function(e,o){t.prototype[o]=function(){var t=Array.prototype.slice.call(arguments);return this.$element[o].apply(this.$element,t)}}),t.prototype.offset=function(){return this.element!==this.element.window?this.$element.offset():void 0},e.each(["width","height"],function(o,i){var r=e.camelCase("outer-"+i);t.prototype[r]=function(t){var o=this.$element[i](),r={width:["left","right"],height:["top","bottom"]};return t&&e.each(r[i],e.proxy(function(t,e){o+=parseInt(this.$element.css("margin-"+e),10)},this)),o}}),e.each(["extend","inArray"],function(o,i){t[i]=e[i]}),t.isEmptyObject=function(t){for(var e in t)return!1;return!0},o.adapters.push({name:"zepto",Adapter:t}),o.Adapter=t}(),function(){"use strict";function t(t){return function(){var o=[],i=arguments[0];return t.isFunction(arguments[0])&&(i=t.extend({},arguments[1]),i.handler=arguments[0]),this.each(function(){var r=t.extend({},i,{element:this});"string"==typeof r.context&&(r.context=t(this).closest(r.context)[0]),o.push(new e(r))}),o}}var e=window.Waypoint;window.jQuery&&(window.jQuery.fn.waypoint=t(window.jQuery)),window.Zepto&&(window.Zepto.fn.waypoint=t(window.Zepto))}(); \ No newline at end of file +!function(){"use strict";function t(i){if(!i)throw new Error("No options passed to Waypoint constructor");if(!i.element)throw new Error("No element option passed to Waypoint constructor");if(!i.handler)throw new Error("No handler option passed to Waypoint constructor");this.key="waypoint-"+e,this.options=t.Adapter.extend({},t.defaults,i),this.element=this.options.element,this.adapter=new t.Adapter(this.element),this.callback=i.handler,this.axis=this.options.horizontal?"horizontal":"vertical",this.enabled=this.options.enabled,this.triggerPoint=null,this.group=t.Group.findOrCreate({name:this.options.group,axis:this.axis}),this.context=t.Context.findOrCreateByElement(this.options.context),t.offsetAliases[this.options.offset]&&(this.options.offset=t.offsetAliases[this.options.offset]),this.group.add(this),this.context.add(this),o[this.key]=this,e+=1}var e=0,o={};t.prototype.queueTrigger=function(t){this.group.queueTrigger(this,t)},t.prototype.trigger=function(t){this.enabled&&this.callback&&this.callback.apply(this,t)},t.prototype.destroy=function(){this.context.remove(this),this.group.remove(this),delete o[this.key]},t.prototype.disable=function(){return this.enabled=!1,this},t.prototype.enable=function(){return this.context.refresh(),this.enabled=!0,this},t.prototype.next=function(){return this.group.next(this)},t.prototype.previous=function(){return this.group.previous(this)},t.destroyAll=function(){var t=[];for(var e in o)t.push(o[e]);for(var i=0,r=t.length;r>i;i++)t[i].destroy()},t.refreshAll=function(){t.Context.refreshAll()},t.viewportHeight=function(){return window.innerHeight||document.documentElement.clientHeight},t.viewportWidth=function(){return document.documentElement.clientWidth},t.adapters=[],t.defaults={context:window,continuous:!0,enabled:!0,group:"default",horizontal:!1,offset:0},t.offsetAliases={"bottom-in-view":function(){return this.context.height()-this.adapter.outerHeight()},"right-in-view":function(){return this.context.width()-this.adapter.outerWidth()}},window.Waypoint=t}(),function(){"use strict";function t(t){window.setTimeout(t,1e3/60)}function e(t){this.element=t,this.Adapter=r.Adapter,this.adapter=new this.Adapter(t),this.key="waypoint-context-"+o,this.didScroll=!1,this.didResize=!1,this.oldScroll={x:this.adapter.scrollLeft(),y:this.adapter.scrollTop()},this.waypoints={vertical:{},horizontal:{}},t.waypointContextKey=this.key,i[t.waypointContextKey]=this,o+=1,this.createThrottledScrollHandler(),this.createThrottledResizeHandler()}var o=0,i={},r=window.Waypoint,n=window.requestAnimationFrame||window.mozRequestAnimationFrame||window.webkitRequestAnimationFrame||t,s=window.onload;e.prototype.add=function(t){var e=t.options.horizontal?"horizontal":"vertical";this.waypoints[e][t.key]=t,this.refresh()},e.prototype.checkEmpty=function(){var t=this.Adapter.isEmptyObject(this.waypoints.horizontal),e=this.Adapter.isEmptyObject(this.waypoints.vertical);t&&e&&(this.adapter.off(".waypoints"),delete i[this.key])},e.prototype.createThrottledResizeHandler=function(){function t(){e.handleResize(),e.didResize=!1}var e=this;this.adapter.on("resize.waypoints",function(){e.didResize||(e.didResize=!0,n(t))})},e.prototype.createThrottledScrollHandler=function(){function t(){e.handleScroll(),e.didScroll=!1}var e=this;this.adapter.on("scroll.waypoints",function(){(!e.didScroll||r.isTouch)&&(e.didScroll=!0,n(t))})},e.prototype.handleResize=function(){r.Context.refreshAll()},e.prototype.handleScroll=function(){var t={},e={horizontal:{newScroll:this.adapter.scrollLeft(),oldScroll:this.oldScroll.x,forward:"right",backward:"left"},vertical:{newScroll:this.adapter.scrollTop(),oldScroll:this.oldScroll.y,forward:"down",backward:"up"}};for(var o in e){var i=e[o],r=i.newScroll>i.oldScroll,n=r?i.forward:i.backward;for(var s in this.waypoints[o]){var a=this.waypoints[o][s],l=i.oldScroll=a.triggerPoint,p=l&&h,c=!l&&!h;(p||c)&&(a.queueTrigger(n),t[a.group.id]=a.group)}}for(var u in t)t[u].flushTriggers();this.oldScroll={x:e.horizontal.newScroll,y:e.vertical.newScroll}},e.prototype.height=function(){return this.element===this.element.window?r.viewportHeight():this.adapter.height()},e.prototype.remove=function(t){delete this.waypoints[t.axis][t.key],this.checkEmpty()},e.prototype.width=function(){return this.element===this.element.window?r.viewportWidth():this.adapter.width()},e.prototype.destroy=function(){var t=[];for(var e in this.waypoints)for(var o in this.waypoints[e])t.push(this.waypoints[e][o]);for(var i=0,r=t.length;r>i;i++)t[i].destroy()},e.prototype.refresh=function(){var t,e=this.element===this.element.window,o=this.adapter.offset(),i={};this.handleScroll(),t={horizontal:{contextOffset:e?0:o.left,contextScroll:e?0:this.oldScroll.x,contextDimension:this.width(),oldScroll:this.oldScroll.x,forward:"right",backward:"left",offsetProp:"left"},vertical:{contextOffset:e?0:o.top,contextScroll:e?0:this.oldScroll.y,contextDimension:this.height(),oldScroll:this.oldScroll.y,forward:"down",backward:"up",offsetProp:"top"}};for(var r in t){var n=t[r];for(var s in this.waypoints[r]){var a,l,h,p,c,u=this.waypoints[r][s],d=u.options.offset,f=u.triggerPoint,w=0,y=null==f;u.element!==u.element.window&&(w=u.adapter.offset()[n.offsetProp]),"function"==typeof d?d=d.apply(u):"string"==typeof d&&(d=parseFloat(d),u.options.offset.indexOf("%")>-1&&(d=Math.ceil(n.contextDimension*d/100))),a=n.contextScroll-n.contextOffset,u.triggerPoint=w+a-d,l=f=n.oldScroll,p=l&&h,c=!l&&!h,!y&&p?(u.queueTrigger(n.backward),i[u.group.id]=u.group):!y&&c?(u.queueTrigger(n.forward),i[u.group.id]=u.group):y&&n.oldScroll>=u.triggerPoint&&(u.queueTrigger(n.forward),i[u.group.id]=u.group)}}for(var g in i)i[g].flushTriggers();return this},e.findOrCreateByElement=function(t){return e.findByElement(t)||new e(t)},e.refreshAll=function(){for(var t in i)i[t].refresh()},e.findByElement=function(t){return i[t.waypointContextKey]},window.onload=function(){s(),e.refreshAll()},r.Context=e}(),function(){"use strict";function t(t,e){return t.triggerPoint-e.triggerPoint}function e(t,e){return e.triggerPoint-t.triggerPoint}function o(t){this.name=t.name,this.axis=t.axis,this.id=this.name+"-"+this.axis,this.waypoints=[],this.clearTriggerQueues(),i[this.axis][this.name]=this}var i={vertical:{},horizontal:{}},r=window.Waypoint;o.prototype.add=function(t){this.waypoints.push(t)},o.prototype.clearTriggerQueues=function(){this.triggerQueues={up:[],down:[],left:[],right:[]}},o.prototype.flushTriggers=function(){for(var o in this.triggerQueues){var i=this.triggerQueues[o],r="up"===o||"left"===o;i.sort(r?e:t);for(var n=0,s=i.length;s>n;n+=1){var a=i[n];(a.options.continuous||n===i.length-1)&&a.trigger([o])}}this.clearTriggerQueues()},o.prototype.next=function(e){this.waypoints.sort(t);var o=r.Adapter.inArray(e,this.waypoints),i=o===this.waypoints.length-1;return i?null:this.waypoints[o+1]},o.prototype.previous=function(e){this.waypoints.sort(t);var o=r.Adapter.inArray(e,this.waypoints);return o?this.waypoints[o-1]:null},o.prototype.queueTrigger=function(t,e){this.triggerQueues[e].push(t)},o.prototype.remove=function(t){var e=r.Adapter.inArray(t,this.waypoints);e>-1&&this.waypoints.splice(e,1)},o.prototype.first=function(){return this.waypoints[0]},o.prototype.last=function(){return this.waypoints[this.waypoints.length-1]},o.findOrCreate=function(t){return i[t.axis][t.name]||new o(t)},r.Group=o}(),function(){"use strict";function t(t){this.element=t,this.$element=e(t)}var e=window.Zepto,o=window.Waypoint;e.each(["height","off","on","scrollLeft","scrollTop","width"],function(e,o){t.prototype[o]=function(){var t=Array.prototype.slice.call(arguments);return this.$element[o].apply(this.$element,t)}}),t.prototype.offset=function(){return this.element!==this.element.window?this.$element.offset():void 0},e.each(["width","height"],function(o,i){var r=e.camelCase("outer-"+i);t.prototype[r]=function(t){var o=this.$element[i](),r={width:["left","right"],height:["top","bottom"]};return t&&e.each(r[i],e.proxy(function(t,e){o+=parseInt(this.$element.css("margin-"+e),10)},this)),o}}),e.each(["extend","inArray"],function(o,i){t[i]=e[i]}),t.isEmptyObject=function(t){for(var e in t)return!1;return!0},o.adapters.push({name:"zepto",Adapter:t}),o.Adapter=t}(),function(){"use strict";function t(t){return function(){var o=[],i=arguments[0];return t.isFunction(arguments[0])&&(i=t.extend({},arguments[1]),i.handler=arguments[0]),this.each(function(){var r=t.extend({},i,{element:this});"string"==typeof r.context&&(r.context=t(this).closest(r.context)[0]),o.push(new e(r))}),o}}var e=window.Waypoint;window.jQuery&&(window.jQuery.fn.waypoint=t(window.jQuery)),window.Zepto&&(window.Zepto.fn.waypoint=t(window.Zepto))}(); \ No newline at end of file diff --git a/src/context.js b/src/context.js index 0610c585..d6bba8b3 100644 --- a/src/context.js +++ b/src/context.js @@ -12,6 +12,7 @@ window.mozRequestAnimationFrame || window.webkitRequestAnimationFrame || requestAnimationFrameShim + var oldWindowLoad = window.onload function Context(element) { this.element = element @@ -273,5 +274,9 @@ return contexts[element.waypointContextKey] } + window.onload = function() { + oldWindowLoad() + Context.refreshAll() + } Waypoint.Context = Context }()) From 2628c9077598fcf66030890f51831d88be1a3f78 Mon Sep 17 00:00:00 2001 From: imakewebthings Date: Tue, 16 Dec 2014 23:54:03 -0800 Subject: [PATCH 42/98] Change from height/width to innerHeight/Width --- lib/jquery.waypoints.js | 22 ++++++------ lib/jquery.waypoints.min.js | 2 +- lib/noframework.waypoints.js | 34 +++++++++---------- lib/noframework.waypoints.min.js | 2 +- lib/zepto.waypoints.js | 57 +++++++++++++++++++------------- lib/zepto.waypoints.min.js | 2 +- src/adapters/jquery.js | 6 ++-- src/adapters/noframework.js | 18 +++++----- src/adapters/zepto.js | 41 ++++++++++++++--------- src/context.js | 12 +++---- src/waypoint.js | 4 +-- 11 files changed, 111 insertions(+), 89 deletions(-) diff --git a/lib/jquery.waypoints.js b/lib/jquery.waypoints.js index dc2bcc21..ac35e3ab 100644 --- a/lib/jquery.waypoints.js +++ b/lib/jquery.waypoints.js @@ -128,10 +128,10 @@ https://github.com/imakewebthings/waypoints/blog/master/licenses.txt Waypoint.offsetAliases = { 'bottom-in-view': function() { - return this.context.height() - this.adapter.outerHeight() + return this.context.innerHeight() - this.adapter.outerHeight() }, 'right-in-view': function() { - return this.context.width() - this.adapter.outerWidth() + return this.context.innerWidth() - this.adapter.outerWidth() } } @@ -279,11 +279,11 @@ https://github.com/imakewebthings/waypoints/blog/master/licenses.txt } /* Private */ - Context.prototype.height = function() { + Context.prototype.innerHeight = function() { if (this.element === this.element.window) { return Waypoint.viewportHeight() } - return this.adapter.height() + return this.adapter.innerHeight() } /* Private */ @@ -293,11 +293,11 @@ https://github.com/imakewebthings/waypoints/blog/master/licenses.txt } /* Private */ - Context.prototype.width = function() { + Context.prototype.innerWidth = function() { if (this.element === this.element.window) { return Waypoint.viewportWidth() } - return this.adapter.width() + return this.adapter.innerWidth() } /* Public */ @@ -325,7 +325,7 @@ https://github.com/imakewebthings/waypoints/blog/master/licenses.txt horizontal: { contextOffset: isWindow ? 0 : contextOffset.left, contextScroll: isWindow ? 0 : this.oldScroll.x, - contextDimension: this.width(), + contextDimension: this.innerWidth(), oldScroll: this.oldScroll.x, forward: 'right', backward: 'left', @@ -334,7 +334,7 @@ https://github.com/imakewebthings/waypoints/blog/master/licenses.txt vertical: { contextOffset: isWindow ? 0 : contextOffset.top, contextScroll: isWindow ? 0 : this.oldScroll.y, - contextDimension: this.height(), + contextDimension: this.innerHeight(), oldScroll: this.oldScroll.y, forward: 'down', backward: 'up', @@ -532,15 +532,15 @@ https://github.com/imakewebthings/waypoints/blog/master/licenses.txt } $.each([ - 'height', + 'innerHeight', + 'innerWidth', 'off', 'offset', 'on', 'outerHeight', 'outerWidth', 'scrollLeft', - 'scrollTop', - 'width' + 'scrollTop' ], function(i, method) { JQueryAdapter.prototype[method] = function() { var args = Array.prototype.slice.call(arguments) diff --git a/lib/jquery.waypoints.min.js b/lib/jquery.waypoints.min.js index e6019da9..97c9252a 100644 --- a/lib/jquery.waypoints.min.js +++ b/lib/jquery.waypoints.min.js @@ -4,4 +4,4 @@ Copyright © 2011-2014 Caleb Troughton Licensed under the MIT license. https://github.com/imakewebthings/waypoints/blog/master/licenses.txt */ -!function(){"use strict";function t(i){if(!i)throw new Error("No options passed to Waypoint constructor");if(!i.element)throw new Error("No element option passed to Waypoint constructor");if(!i.handler)throw new Error("No handler option passed to Waypoint constructor");this.key="waypoint-"+e,this.options=t.Adapter.extend({},t.defaults,i),this.element=this.options.element,this.adapter=new t.Adapter(this.element),this.callback=i.handler,this.axis=this.options.horizontal?"horizontal":"vertical",this.enabled=this.options.enabled,this.triggerPoint=null,this.group=t.Group.findOrCreate({name:this.options.group,axis:this.axis}),this.context=t.Context.findOrCreateByElement(this.options.context),t.offsetAliases[this.options.offset]&&(this.options.offset=t.offsetAliases[this.options.offset]),this.group.add(this),this.context.add(this),o[this.key]=this,e+=1}var e=0,o={};t.prototype.queueTrigger=function(t){this.group.queueTrigger(this,t)},t.prototype.trigger=function(t){this.enabled&&this.callback&&this.callback.apply(this,t)},t.prototype.destroy=function(){this.context.remove(this),this.group.remove(this),delete o[this.key]},t.prototype.disable=function(){return this.enabled=!1,this},t.prototype.enable=function(){return this.context.refresh(),this.enabled=!0,this},t.prototype.next=function(){return this.group.next(this)},t.prototype.previous=function(){return this.group.previous(this)},t.destroyAll=function(){var t=[];for(var e in o)t.push(o[e]);for(var i=0,r=t.length;r>i;i++)t[i].destroy()},t.refreshAll=function(){t.Context.refreshAll()},t.viewportHeight=function(){return window.innerHeight||document.documentElement.clientHeight},t.viewportWidth=function(){return document.documentElement.clientWidth},t.adapters=[],t.defaults={context:window,continuous:!0,enabled:!0,group:"default",horizontal:!1,offset:0},t.offsetAliases={"bottom-in-view":function(){return this.context.height()-this.adapter.outerHeight()},"right-in-view":function(){return this.context.width()-this.adapter.outerWidth()}},window.Waypoint=t}(),function(){"use strict";function t(t){window.setTimeout(t,1e3/60)}function e(t){this.element=t,this.Adapter=r.Adapter,this.adapter=new this.Adapter(t),this.key="waypoint-context-"+o,this.didScroll=!1,this.didResize=!1,this.oldScroll={x:this.adapter.scrollLeft(),y:this.adapter.scrollTop()},this.waypoints={vertical:{},horizontal:{}},t.waypointContextKey=this.key,i[t.waypointContextKey]=this,o+=1,this.createThrottledScrollHandler(),this.createThrottledResizeHandler()}var o=0,i={},r=window.Waypoint,n=window.requestAnimationFrame||window.mozRequestAnimationFrame||window.webkitRequestAnimationFrame||t,s=window.onload;e.prototype.add=function(t){var e=t.options.horizontal?"horizontal":"vertical";this.waypoints[e][t.key]=t,this.refresh()},e.prototype.checkEmpty=function(){var t=this.Adapter.isEmptyObject(this.waypoints.horizontal),e=this.Adapter.isEmptyObject(this.waypoints.vertical);t&&e&&(this.adapter.off(".waypoints"),delete i[this.key])},e.prototype.createThrottledResizeHandler=function(){function t(){e.handleResize(),e.didResize=!1}var e=this;this.adapter.on("resize.waypoints",function(){e.didResize||(e.didResize=!0,n(t))})},e.prototype.createThrottledScrollHandler=function(){function t(){e.handleScroll(),e.didScroll=!1}var e=this;this.adapter.on("scroll.waypoints",function(){(!e.didScroll||r.isTouch)&&(e.didScroll=!0,n(t))})},e.prototype.handleResize=function(){r.Context.refreshAll()},e.prototype.handleScroll=function(){var t={},e={horizontal:{newScroll:this.adapter.scrollLeft(),oldScroll:this.oldScroll.x,forward:"right",backward:"left"},vertical:{newScroll:this.adapter.scrollTop(),oldScroll:this.oldScroll.y,forward:"down",backward:"up"}};for(var o in e){var i=e[o],r=i.newScroll>i.oldScroll,n=r?i.forward:i.backward;for(var s in this.waypoints[o]){var a=this.waypoints[o][s],l=i.oldScroll=a.triggerPoint,p=l&&h,u=!l&&!h;(p||u)&&(a.queueTrigger(n),t[a.group.id]=a.group)}}for(var c in t)t[c].flushTriggers();this.oldScroll={x:e.horizontal.newScroll,y:e.vertical.newScroll}},e.prototype.height=function(){return this.element===this.element.window?r.viewportHeight():this.adapter.height()},e.prototype.remove=function(t){delete this.waypoints[t.axis][t.key],this.checkEmpty()},e.prototype.width=function(){return this.element===this.element.window?r.viewportWidth():this.adapter.width()},e.prototype.destroy=function(){var t=[];for(var e in this.waypoints)for(var o in this.waypoints[e])t.push(this.waypoints[e][o]);for(var i=0,r=t.length;r>i;i++)t[i].destroy()},e.prototype.refresh=function(){var t,e=this.element===this.element.window,o=this.adapter.offset(),i={};this.handleScroll(),t={horizontal:{contextOffset:e?0:o.left,contextScroll:e?0:this.oldScroll.x,contextDimension:this.width(),oldScroll:this.oldScroll.x,forward:"right",backward:"left",offsetProp:"left"},vertical:{contextOffset:e?0:o.top,contextScroll:e?0:this.oldScroll.y,contextDimension:this.height(),oldScroll:this.oldScroll.y,forward:"down",backward:"up",offsetProp:"top"}};for(var r in t){var n=t[r];for(var s in this.waypoints[r]){var a,l,h,p,u,c=this.waypoints[r][s],d=c.options.offset,f=c.triggerPoint,w=0,y=null==f;c.element!==c.element.window&&(w=c.adapter.offset()[n.offsetProp]),"function"==typeof d?d=d.apply(c):"string"==typeof d&&(d=parseFloat(d),c.options.offset.indexOf("%")>-1&&(d=Math.ceil(n.contextDimension*d/100))),a=n.contextScroll-n.contextOffset,c.triggerPoint=w+a-d,l=f=n.oldScroll,p=l&&h,u=!l&&!h,!y&&p?(c.queueTrigger(n.backward),i[c.group.id]=c.group):!y&&u?(c.queueTrigger(n.forward),i[c.group.id]=c.group):y&&n.oldScroll>=c.triggerPoint&&(c.queueTrigger(n.forward),i[c.group.id]=c.group)}}for(var g in i)i[g].flushTriggers();return this},e.findOrCreateByElement=function(t){return e.findByElement(t)||new e(t)},e.refreshAll=function(){for(var t in i)i[t].refresh()},e.findByElement=function(t){return i[t.waypointContextKey]},window.onload=function(){s(),e.refreshAll()},r.Context=e}(),function(){"use strict";function t(t,e){return t.triggerPoint-e.triggerPoint}function e(t,e){return e.triggerPoint-t.triggerPoint}function o(t){this.name=t.name,this.axis=t.axis,this.id=this.name+"-"+this.axis,this.waypoints=[],this.clearTriggerQueues(),i[this.axis][this.name]=this}var i={vertical:{},horizontal:{}},r=window.Waypoint;o.prototype.add=function(t){this.waypoints.push(t)},o.prototype.clearTriggerQueues=function(){this.triggerQueues={up:[],down:[],left:[],right:[]}},o.prototype.flushTriggers=function(){for(var o in this.triggerQueues){var i=this.triggerQueues[o],r="up"===o||"left"===o;i.sort(r?e:t);for(var n=0,s=i.length;s>n;n+=1){var a=i[n];(a.options.continuous||n===i.length-1)&&a.trigger([o])}}this.clearTriggerQueues()},o.prototype.next=function(e){this.waypoints.sort(t);var o=r.Adapter.inArray(e,this.waypoints),i=o===this.waypoints.length-1;return i?null:this.waypoints[o+1]},o.prototype.previous=function(e){this.waypoints.sort(t);var o=r.Adapter.inArray(e,this.waypoints);return o?this.waypoints[o-1]:null},o.prototype.queueTrigger=function(t,e){this.triggerQueues[e].push(t)},o.prototype.remove=function(t){var e=r.Adapter.inArray(t,this.waypoints);e>-1&&this.waypoints.splice(e,1)},o.prototype.first=function(){return this.waypoints[0]},o.prototype.last=function(){return this.waypoints[this.waypoints.length-1]},o.findOrCreate=function(t){return i[t.axis][t.name]||new o(t)},r.Group=o}(),function(){"use strict";function t(t){this.$element=e(t)}var e=window.jQuery,o=window.Waypoint;e.each(["height","off","offset","on","outerHeight","outerWidth","scrollLeft","scrollTop","width"],function(e,o){t.prototype[o]=function(){var t=Array.prototype.slice.call(arguments);return this.$element[o].apply(this.$element,t)}}),e.each(["extend","inArray","isEmptyObject"],function(o,i){t[i]=e[i]}),o.adapters.push({name:"jquery",Adapter:t}),o.Adapter=t}(),function(){"use strict";function t(t){return function(){var o=[],i=arguments[0];return t.isFunction(arguments[0])&&(i=t.extend({},arguments[1]),i.handler=arguments[0]),this.each(function(){var r=t.extend({},i,{element:this});"string"==typeof r.context&&(r.context=t(this).closest(r.context)[0]),o.push(new e(r))}),o}}var e=window.Waypoint;window.jQuery&&(window.jQuery.fn.waypoint=t(window.jQuery)),window.Zepto&&(window.Zepto.fn.waypoint=t(window.Zepto))}(); \ No newline at end of file +!function(){"use strict";function t(o){if(!o)throw new Error("No options passed to Waypoint constructor");if(!o.element)throw new Error("No element option passed to Waypoint constructor");if(!o.handler)throw new Error("No handler option passed to Waypoint constructor");this.key="waypoint-"+e,this.options=t.Adapter.extend({},t.defaults,o),this.element=this.options.element,this.adapter=new t.Adapter(this.element),this.callback=o.handler,this.axis=this.options.horizontal?"horizontal":"vertical",this.enabled=this.options.enabled,this.triggerPoint=null,this.group=t.Group.findOrCreate({name:this.options.group,axis:this.axis}),this.context=t.Context.findOrCreateByElement(this.options.context),t.offsetAliases[this.options.offset]&&(this.options.offset=t.offsetAliases[this.options.offset]),this.group.add(this),this.context.add(this),i[this.key]=this,e+=1}var e=0,i={};t.prototype.queueTrigger=function(t){this.group.queueTrigger(this,t)},t.prototype.trigger=function(t){this.enabled&&this.callback&&this.callback.apply(this,t)},t.prototype.destroy=function(){this.context.remove(this),this.group.remove(this),delete i[this.key]},t.prototype.disable=function(){return this.enabled=!1,this},t.prototype.enable=function(){return this.context.refresh(),this.enabled=!0,this},t.prototype.next=function(){return this.group.next(this)},t.prototype.previous=function(){return this.group.previous(this)},t.destroyAll=function(){var t=[];for(var e in i)t.push(i[e]);for(var o=0,r=t.length;r>o;o++)t[o].destroy()},t.refreshAll=function(){t.Context.refreshAll()},t.viewportHeight=function(){return window.innerHeight||document.documentElement.clientHeight},t.viewportWidth=function(){return document.documentElement.clientWidth},t.adapters=[],t.defaults={context:window,continuous:!0,enabled:!0,group:"default",horizontal:!1,offset:0},t.offsetAliases={"bottom-in-view":function(){return this.context.innerHeight()-this.adapter.outerHeight()},"right-in-view":function(){return this.context.innerWidth()-this.adapter.outerWidth()}},window.Waypoint=t}(),function(){"use strict";function t(t){window.setTimeout(t,1e3/60)}function e(t){this.element=t,this.Adapter=r.Adapter,this.adapter=new this.Adapter(t),this.key="waypoint-context-"+i,this.didScroll=!1,this.didResize=!1,this.oldScroll={x:this.adapter.scrollLeft(),y:this.adapter.scrollTop()},this.waypoints={vertical:{},horizontal:{}},t.waypointContextKey=this.key,o[t.waypointContextKey]=this,i+=1,this.createThrottledScrollHandler(),this.createThrottledResizeHandler()}var i=0,o={},r=window.Waypoint,n=window.requestAnimationFrame||window.mozRequestAnimationFrame||window.webkitRequestAnimationFrame||t,s=window.onload;e.prototype.add=function(t){var e=t.options.horizontal?"horizontal":"vertical";this.waypoints[e][t.key]=t,this.refresh()},e.prototype.checkEmpty=function(){var t=this.Adapter.isEmptyObject(this.waypoints.horizontal),e=this.Adapter.isEmptyObject(this.waypoints.vertical);t&&e&&(this.adapter.off(".waypoints"),delete o[this.key])},e.prototype.createThrottledResizeHandler=function(){function t(){e.handleResize(),e.didResize=!1}var e=this;this.adapter.on("resize.waypoints",function(){e.didResize||(e.didResize=!0,n(t))})},e.prototype.createThrottledScrollHandler=function(){function t(){e.handleScroll(),e.didScroll=!1}var e=this;this.adapter.on("scroll.waypoints",function(){(!e.didScroll||r.isTouch)&&(e.didScroll=!0,n(t))})},e.prototype.handleResize=function(){r.Context.refreshAll()},e.prototype.handleScroll=function(){var t={},e={horizontal:{newScroll:this.adapter.scrollLeft(),oldScroll:this.oldScroll.x,forward:"right",backward:"left"},vertical:{newScroll:this.adapter.scrollTop(),oldScroll:this.oldScroll.y,forward:"down",backward:"up"}};for(var i in e){var o=e[i],r=o.newScroll>o.oldScroll,n=r?o.forward:o.backward;for(var s in this.waypoints[i]){var a=this.waypoints[i][s],l=o.oldScroll=a.triggerPoint,p=l&&h,u=!l&&!h;(p||u)&&(a.queueTrigger(n),t[a.group.id]=a.group)}}for(var c in t)t[c].flushTriggers();this.oldScroll={x:e.horizontal.newScroll,y:e.vertical.newScroll}},e.prototype.innerHeight=function(){return this.element===this.element.window?r.viewportHeight():this.adapter.innerHeight()},e.prototype.remove=function(t){delete this.waypoints[t.axis][t.key],this.checkEmpty()},e.prototype.innerWidth=function(){return this.element===this.element.window?r.viewportWidth():this.adapter.innerWidth()},e.prototype.destroy=function(){var t=[];for(var e in this.waypoints)for(var i in this.waypoints[e])t.push(this.waypoints[e][i]);for(var o=0,r=t.length;r>o;o++)t[o].destroy()},e.prototype.refresh=function(){var t,e=this.element===this.element.window,i=this.adapter.offset(),o={};this.handleScroll(),t={horizontal:{contextOffset:e?0:i.left,contextScroll:e?0:this.oldScroll.x,contextDimension:this.innerWidth(),oldScroll:this.oldScroll.x,forward:"right",backward:"left",offsetProp:"left"},vertical:{contextOffset:e?0:i.top,contextScroll:e?0:this.oldScroll.y,contextDimension:this.innerHeight(),oldScroll:this.oldScroll.y,forward:"down",backward:"up",offsetProp:"top"}};for(var r in t){var n=t[r];for(var s in this.waypoints[r]){var a,l,h,p,u,c=this.waypoints[r][s],d=c.options.offset,f=c.triggerPoint,w=0,y=null==f;c.element!==c.element.window&&(w=c.adapter.offset()[n.offsetProp]),"function"==typeof d?d=d.apply(c):"string"==typeof d&&(d=parseFloat(d),c.options.offset.indexOf("%")>-1&&(d=Math.ceil(n.contextDimension*d/100))),a=n.contextScroll-n.contextOffset,c.triggerPoint=w+a-d,l=f=n.oldScroll,p=l&&h,u=!l&&!h,!y&&p?(c.queueTrigger(n.backward),o[c.group.id]=c.group):!y&&u?(c.queueTrigger(n.forward),o[c.group.id]=c.group):y&&n.oldScroll>=c.triggerPoint&&(c.queueTrigger(n.forward),o[c.group.id]=c.group)}}for(var g in o)o[g].flushTriggers();return this},e.findOrCreateByElement=function(t){return e.findByElement(t)||new e(t)},e.refreshAll=function(){for(var t in o)o[t].refresh()},e.findByElement=function(t){return o[t.waypointContextKey]},window.onload=function(){s(),e.refreshAll()},r.Context=e}(),function(){"use strict";function t(t,e){return t.triggerPoint-e.triggerPoint}function e(t,e){return e.triggerPoint-t.triggerPoint}function i(t){this.name=t.name,this.axis=t.axis,this.id=this.name+"-"+this.axis,this.waypoints=[],this.clearTriggerQueues(),o[this.axis][this.name]=this}var o={vertical:{},horizontal:{}},r=window.Waypoint;i.prototype.add=function(t){this.waypoints.push(t)},i.prototype.clearTriggerQueues=function(){this.triggerQueues={up:[],down:[],left:[],right:[]}},i.prototype.flushTriggers=function(){for(var i in this.triggerQueues){var o=this.triggerQueues[i],r="up"===i||"left"===i;o.sort(r?e:t);for(var n=0,s=o.length;s>n;n+=1){var a=o[n];(a.options.continuous||n===o.length-1)&&a.trigger([i])}}this.clearTriggerQueues()},i.prototype.next=function(e){this.waypoints.sort(t);var i=r.Adapter.inArray(e,this.waypoints),o=i===this.waypoints.length-1;return o?null:this.waypoints[i+1]},i.prototype.previous=function(e){this.waypoints.sort(t);var i=r.Adapter.inArray(e,this.waypoints);return i?this.waypoints[i-1]:null},i.prototype.queueTrigger=function(t,e){this.triggerQueues[e].push(t)},i.prototype.remove=function(t){var e=r.Adapter.inArray(t,this.waypoints);e>-1&&this.waypoints.splice(e,1)},i.prototype.first=function(){return this.waypoints[0]},i.prototype.last=function(){return this.waypoints[this.waypoints.length-1]},i.findOrCreate=function(t){return o[t.axis][t.name]||new i(t)},r.Group=i}(),function(){"use strict";function t(t){this.$element=e(t)}var e=window.jQuery,i=window.Waypoint;e.each(["innerHeight","innerWidth","off","offset","on","outerHeight","outerWidth","scrollLeft","scrollTop"],function(e,i){t.prototype[i]=function(){var t=Array.prototype.slice.call(arguments);return this.$element[i].apply(this.$element,t)}}),e.each(["extend","inArray","isEmptyObject"],function(i,o){t[o]=e[o]}),i.adapters.push({name:"jquery",Adapter:t}),i.Adapter=t}(),function(){"use strict";function t(t){return function(){var i=[],o=arguments[0];return t.isFunction(arguments[0])&&(o=t.extend({},arguments[1]),o.handler=arguments[0]),this.each(function(){var r=t.extend({},o,{element:this});"string"==typeof r.context&&(r.context=t(this).closest(r.context)[0]),i.push(new e(r))}),i}}var e=window.Waypoint;window.jQuery&&(window.jQuery.fn.waypoint=t(window.jQuery)),window.Zepto&&(window.Zepto.fn.waypoint=t(window.Zepto))}(); \ No newline at end of file diff --git a/lib/noframework.waypoints.js b/lib/noframework.waypoints.js index 46c4a3da..4108f2ef 100644 --- a/lib/noframework.waypoints.js +++ b/lib/noframework.waypoints.js @@ -128,10 +128,10 @@ https://github.com/imakewebthings/waypoints/blog/master/licenses.txt Waypoint.offsetAliases = { 'bottom-in-view': function() { - return this.context.height() - this.adapter.outerHeight() + return this.context.innerHeight() - this.adapter.outerHeight() }, 'right-in-view': function() { - return this.context.width() - this.adapter.outerWidth() + return this.context.innerWidth() - this.adapter.outerWidth() } } @@ -279,11 +279,11 @@ https://github.com/imakewebthings/waypoints/blog/master/licenses.txt } /* Private */ - Context.prototype.height = function() { + Context.prototype.innerHeight = function() { if (this.element === this.element.window) { return Waypoint.viewportHeight() } - return this.adapter.height() + return this.adapter.innerHeight() } /* Private */ @@ -293,11 +293,11 @@ https://github.com/imakewebthings/waypoints/blog/master/licenses.txt } /* Private */ - Context.prototype.width = function() { + Context.prototype.innerWidth = function() { if (this.element === this.element.window) { return Waypoint.viewportWidth() } - return this.adapter.width() + return this.adapter.innerWidth() } /* Public */ @@ -325,7 +325,7 @@ https://github.com/imakewebthings/waypoints/blog/master/licenses.txt horizontal: { contextOffset: isWindow ? 0 : contextOffset.left, contextScroll: isWindow ? 0 : this.oldScroll.x, - contextDimension: this.width(), + contextDimension: this.innerWidth(), oldScroll: this.oldScroll.x, forward: 'right', backward: 'left', @@ -334,7 +334,7 @@ https://github.com/imakewebthings/waypoints/blog/master/licenses.txt vertical: { contextOffset: isWindow ? 0 : contextOffset.top, contextScroll: isWindow ? 0 : this.oldScroll.y, - contextDimension: this.height(), + contextDimension: this.innerHeight(), oldScroll: this.oldScroll.y, forward: 'down', backward: 'up', @@ -542,9 +542,14 @@ https://github.com/imakewebthings/waypoints/blog/master/licenses.txt this.handlers = {} } - NoFrameworkAdapter.prototype.height = function() { + NoFrameworkAdapter.prototype.innerHeight = function() { var isWin = isWindow(this.element) - return isWin ? this.element.innerHeight : this.element.offsetHeight + return isWin ? this.element.innerHeight : this.element.clientHeight + } + + NoFrameworkAdapter.prototype.innerWidth = function() { + var isWin = isWindow(this.element) + return isWin ? this.element.innerWidth : this.element.clientWidth } NoFrameworkAdapter.prototype.off = function(event, handler) { @@ -615,7 +620,7 @@ https://github.com/imakewebthings/waypoints/blog/master/licenses.txt } NoFrameworkAdapter.prototype.outerHeight = function(includeMargin) { - var height = this.height() + var height = this.innerHeight() var computedStyle if (includeMargin && !isWindow(this.element)) { @@ -628,7 +633,7 @@ https://github.com/imakewebthings/waypoints/blog/master/licenses.txt } NoFrameworkAdapter.prototype.outerWidth = function(includeMargin) { - var width = this.width() + var width = this.innerWidth() var computedStyle if (includeMargin && !isWindow(this.element)) { @@ -650,11 +655,6 @@ https://github.com/imakewebthings/waypoints/blog/master/licenses.txt return win ? win.pageYOffset : this.element.scrollTop } - NoFrameworkAdapter.prototype.width = function() { - var isWin = isWindow(this.element) - return isWin ? this.element.innerWidth : this.element.offsetWidth - } - NoFrameworkAdapter.extend = function() { var args = Array.prototype.slice.call(arguments) diff --git a/lib/noframework.waypoints.min.js b/lib/noframework.waypoints.min.js index b68cb327..7335d087 100644 --- a/lib/noframework.waypoints.min.js +++ b/lib/noframework.waypoints.min.js @@ -4,4 +4,4 @@ Copyright © 2011-2014 Caleb Troughton Licensed under the MIT license. https://github.com/imakewebthings/waypoints/blog/master/licenses.txt */ -!function(){"use strict";function t(o){if(!o)throw new Error("No options passed to Waypoint constructor");if(!o.element)throw new Error("No element option passed to Waypoint constructor");if(!o.handler)throw new Error("No handler option passed to Waypoint constructor");this.key="waypoint-"+e,this.options=t.Adapter.extend({},t.defaults,o),this.element=this.options.element,this.adapter=new t.Adapter(this.element),this.callback=o.handler,this.axis=this.options.horizontal?"horizontal":"vertical",this.enabled=this.options.enabled,this.triggerPoint=null,this.group=t.Group.findOrCreate({name:this.options.group,axis:this.axis}),this.context=t.Context.findOrCreateByElement(this.options.context),t.offsetAliases[this.options.offset]&&(this.options.offset=t.offsetAliases[this.options.offset]),this.group.add(this),this.context.add(this),i[this.key]=this,e+=1}var e=0,i={};t.prototype.queueTrigger=function(t){this.group.queueTrigger(this,t)},t.prototype.trigger=function(t){this.enabled&&this.callback&&this.callback.apply(this,t)},t.prototype.destroy=function(){this.context.remove(this),this.group.remove(this),delete i[this.key]},t.prototype.disable=function(){return this.enabled=!1,this},t.prototype.enable=function(){return this.context.refresh(),this.enabled=!0,this},t.prototype.next=function(){return this.group.next(this)},t.prototype.previous=function(){return this.group.previous(this)},t.destroyAll=function(){var t=[];for(var e in i)t.push(i[e]);for(var o=0,r=t.length;r>o;o++)t[o].destroy()},t.refreshAll=function(){t.Context.refreshAll()},t.viewportHeight=function(){return window.innerHeight||document.documentElement.clientHeight},t.viewportWidth=function(){return document.documentElement.clientWidth},t.adapters=[],t.defaults={context:window,continuous:!0,enabled:!0,group:"default",horizontal:!1,offset:0},t.offsetAliases={"bottom-in-view":function(){return this.context.height()-this.adapter.outerHeight()},"right-in-view":function(){return this.context.width()-this.adapter.outerWidth()}},window.Waypoint=t}(),function(){"use strict";function t(t){window.setTimeout(t,1e3/60)}function e(t){this.element=t,this.Adapter=r.Adapter,this.adapter=new this.Adapter(t),this.key="waypoint-context-"+i,this.didScroll=!1,this.didResize=!1,this.oldScroll={x:this.adapter.scrollLeft(),y:this.adapter.scrollTop()},this.waypoints={vertical:{},horizontal:{}},t.waypointContextKey=this.key,o[t.waypointContextKey]=this,i+=1,this.createThrottledScrollHandler(),this.createThrottledResizeHandler()}var i=0,o={},r=window.Waypoint,n=window.requestAnimationFrame||window.mozRequestAnimationFrame||window.webkitRequestAnimationFrame||t,s=window.onload;e.prototype.add=function(t){var e=t.options.horizontal?"horizontal":"vertical";this.waypoints[e][t.key]=t,this.refresh()},e.prototype.checkEmpty=function(){var t=this.Adapter.isEmptyObject(this.waypoints.horizontal),e=this.Adapter.isEmptyObject(this.waypoints.vertical);t&&e&&(this.adapter.off(".waypoints"),delete o[this.key])},e.prototype.createThrottledResizeHandler=function(){function t(){e.handleResize(),e.didResize=!1}var e=this;this.adapter.on("resize.waypoints",function(){e.didResize||(e.didResize=!0,n(t))})},e.prototype.createThrottledScrollHandler=function(){function t(){e.handleScroll(),e.didScroll=!1}var e=this;this.adapter.on("scroll.waypoints",function(){(!e.didScroll||r.isTouch)&&(e.didScroll=!0,n(t))})},e.prototype.handleResize=function(){r.Context.refreshAll()},e.prototype.handleScroll=function(){var t={},e={horizontal:{newScroll:this.adapter.scrollLeft(),oldScroll:this.oldScroll.x,forward:"right",backward:"left"},vertical:{newScroll:this.adapter.scrollTop(),oldScroll:this.oldScroll.y,forward:"down",backward:"up"}};for(var i in e){var o=e[i],r=o.newScroll>o.oldScroll,n=r?o.forward:o.backward;for(var s in this.waypoints[i]){var a=this.waypoints[i][s],l=o.oldScroll=a.triggerPoint,p=l&&h,u=!l&&!h;(p||u)&&(a.queueTrigger(n),t[a.group.id]=a.group)}}for(var f in t)t[f].flushTriggers();this.oldScroll={x:e.horizontal.newScroll,y:e.vertical.newScroll}},e.prototype.height=function(){return this.element===this.element.window?r.viewportHeight():this.adapter.height()},e.prototype.remove=function(t){delete this.waypoints[t.axis][t.key],this.checkEmpty()},e.prototype.width=function(){return this.element===this.element.window?r.viewportWidth():this.adapter.width()},e.prototype.destroy=function(){var t=[];for(var e in this.waypoints)for(var i in this.waypoints[e])t.push(this.waypoints[e][i]);for(var o=0,r=t.length;r>o;o++)t[o].destroy()},e.prototype.refresh=function(){var t,e=this.element===this.element.window,i=this.adapter.offset(),o={};this.handleScroll(),t={horizontal:{contextOffset:e?0:i.left,contextScroll:e?0:this.oldScroll.x,contextDimension:this.width(),oldScroll:this.oldScroll.x,forward:"right",backward:"left",offsetProp:"left"},vertical:{contextOffset:e?0:i.top,contextScroll:e?0:this.oldScroll.y,contextDimension:this.height(),oldScroll:this.oldScroll.y,forward:"down",backward:"up",offsetProp:"top"}};for(var r in t){var n=t[r];for(var s in this.waypoints[r]){var a,l,h,p,u,f=this.waypoints[r][s],c=f.options.offset,d=f.triggerPoint,w=0,y=null==d;f.element!==f.element.window&&(w=f.adapter.offset()[n.offsetProp]),"function"==typeof c?c=c.apply(f):"string"==typeof c&&(c=parseFloat(c),f.options.offset.indexOf("%")>-1&&(c=Math.ceil(n.contextDimension*c/100))),a=n.contextScroll-n.contextOffset,f.triggerPoint=w+a-c,l=d=n.oldScroll,p=l&&h,u=!l&&!h,!y&&p?(f.queueTrigger(n.backward),o[f.group.id]=f.group):!y&&u?(f.queueTrigger(n.forward),o[f.group.id]=f.group):y&&n.oldScroll>=f.triggerPoint&&(f.queueTrigger(n.forward),o[f.group.id]=f.group)}}for(var g in o)o[g].flushTriggers();return this},e.findOrCreateByElement=function(t){return e.findByElement(t)||new e(t)},e.refreshAll=function(){for(var t in o)o[t].refresh()},e.findByElement=function(t){return o[t.waypointContextKey]},window.onload=function(){s(),e.refreshAll()},r.Context=e}(),function(){"use strict";function t(t,e){return t.triggerPoint-e.triggerPoint}function e(t,e){return e.triggerPoint-t.triggerPoint}function i(t){this.name=t.name,this.axis=t.axis,this.id=this.name+"-"+this.axis,this.waypoints=[],this.clearTriggerQueues(),o[this.axis][this.name]=this}var o={vertical:{},horizontal:{}},r=window.Waypoint;i.prototype.add=function(t){this.waypoints.push(t)},i.prototype.clearTriggerQueues=function(){this.triggerQueues={up:[],down:[],left:[],right:[]}},i.prototype.flushTriggers=function(){for(var i in this.triggerQueues){var o=this.triggerQueues[i],r="up"===i||"left"===i;o.sort(r?e:t);for(var n=0,s=o.length;s>n;n+=1){var a=o[n];(a.options.continuous||n===o.length-1)&&a.trigger([i])}}this.clearTriggerQueues()},i.prototype.next=function(e){this.waypoints.sort(t);var i=r.Adapter.inArray(e,this.waypoints),o=i===this.waypoints.length-1;return o?null:this.waypoints[i+1]},i.prototype.previous=function(e){this.waypoints.sort(t);var i=r.Adapter.inArray(e,this.waypoints);return i?this.waypoints[i-1]:null},i.prototype.queueTrigger=function(t,e){this.triggerQueues[e].push(t)},i.prototype.remove=function(t){var e=r.Adapter.inArray(t,this.waypoints);e>-1&&this.waypoints.splice(e,1)},i.prototype.first=function(){return this.waypoints[0]},i.prototype.last=function(){return this.waypoints[this.waypoints.length-1]},i.findOrCreate=function(t){return o[t.axis][t.name]||new i(t)},r.Group=i}(),function(){"use strict";function t(t){return t===t.window}function e(e){return t(e)?e:e.defaultView}function i(t){this.element=t,this.handlers={}}var o=window.Waypoint;i.prototype.height=function(){var e=t(this.element);return e?this.element.innerHeight:this.element.offsetHeight},i.prototype.off=function(t,e){function i(t,e,i){for(var o=0,r=e.length-1;r>o;o++){var n=e[o];i&&i!==n||t.removeEventListener(n)}}var o=t.split("."),r=o[0],n=o[1],s=this.element;if(n&&this.handlers[n]&&r)i(s,this.handlers[n][r],e),this.handlers[n][r]=[];else if(r)for(var a in this.handlers)i(s,this.handlers[a][r]||[],e),this.handlers[a][r]=[];else if(n&&this.handlers[n]){for(var l in this.handlers[n])i(s,this.handlers[n][l],e);this.handlers[n]={}}},i.prototype.offset=function(){if(!this.element.ownerDocument)return null;var t=this.element.ownerDocument.documentElement,i=e(this.element.ownerDocument),o={top:0,left:0};return this.element.getBoundingClientRect&&(o=this.element.getBoundingClientRect()),{top:o.top+i.pageYOffset-t.clientTop,left:o.left+i.pageXOffset-t.clientLeft}},i.prototype.on=function(t,e){var i=t.split("."),o=i[0],r=i[1]||"__default",n=this.handlers[r]=this.handlers[r]||{},s=n[o]=n[o]||[];s.push(e),this.element.addEventListener(o,e)},i.prototype.outerHeight=function(e){var i,o=this.height();return e&&!t(this.element)&&(i=window.getComputedStyle(this.element),o+=parseInt(i.marginTop,10),o+=parseInt(i.marginBottom,10)),o},i.prototype.outerWidth=function(e){var i,o=this.width();return e&&!t(this.element)&&(i=window.getComputedStyle(this.element),o+=parseInt(i.marginLeft,10),o+=parseInt(i.marginRight,10)),o},i.prototype.scrollLeft=function(){var t=e(this.element);return t?t.pageXOffset:this.element.scrollLeft},i.prototype.scrollTop=function(){var t=e(this.element);return t?t.pageYOffset:this.element.scrollTop},i.prototype.width=function(){var e=t(this.element);return e?this.element.innerWidth:this.element.offsetWidth},i.extend=function(){function t(t,e){if("object"==typeof t&&"object"==typeof e)for(var i in e)e.hasOwnProperty(i)&&(t[i]=e[i]);return t}for(var e=Array.prototype.slice.call(arguments),i=1,o=e.length;o>i;i++)t(e[0],e[i]);return e[0]},i.inArray=function(t,e,i){return null==e?-1:e.indexOf(t,i)},i.isEmptyObject=function(t){for(var e in t)return!1;return!0},o.adapters.push({name:"noframework",Adapter:i}),o.Adapter=i}(); \ No newline at end of file +!function(){"use strict";function t(n){if(!n)throw new Error("No options passed to Waypoint constructor");if(!n.element)throw new Error("No element option passed to Waypoint constructor");if(!n.handler)throw new Error("No handler option passed to Waypoint constructor");this.key="waypoint-"+e,this.options=t.Adapter.extend({},t.defaults,n),this.element=this.options.element,this.adapter=new t.Adapter(this.element),this.callback=n.handler,this.axis=this.options.horizontal?"horizontal":"vertical",this.enabled=this.options.enabled,this.triggerPoint=null,this.group=t.Group.findOrCreate({name:this.options.group,axis:this.axis}),this.context=t.Context.findOrCreateByElement(this.options.context),t.offsetAliases[this.options.offset]&&(this.options.offset=t.offsetAliases[this.options.offset]),this.group.add(this),this.context.add(this),i[this.key]=this,e+=1}var e=0,i={};t.prototype.queueTrigger=function(t){this.group.queueTrigger(this,t)},t.prototype.trigger=function(t){this.enabled&&this.callback&&this.callback.apply(this,t)},t.prototype.destroy=function(){this.context.remove(this),this.group.remove(this),delete i[this.key]},t.prototype.disable=function(){return this.enabled=!1,this},t.prototype.enable=function(){return this.context.refresh(),this.enabled=!0,this},t.prototype.next=function(){return this.group.next(this)},t.prototype.previous=function(){return this.group.previous(this)},t.destroyAll=function(){var t=[];for(var e in i)t.push(i[e]);for(var n=0,o=t.length;o>n;n++)t[n].destroy()},t.refreshAll=function(){t.Context.refreshAll()},t.viewportHeight=function(){return window.innerHeight||document.documentElement.clientHeight},t.viewportWidth=function(){return document.documentElement.clientWidth},t.adapters=[],t.defaults={context:window,continuous:!0,enabled:!0,group:"default",horizontal:!1,offset:0},t.offsetAliases={"bottom-in-view":function(){return this.context.innerHeight()-this.adapter.outerHeight()},"right-in-view":function(){return this.context.innerWidth()-this.adapter.outerWidth()}},window.Waypoint=t}(),function(){"use strict";function t(t){window.setTimeout(t,1e3/60)}function e(t){this.element=t,this.Adapter=o.Adapter,this.adapter=new this.Adapter(t),this.key="waypoint-context-"+i,this.didScroll=!1,this.didResize=!1,this.oldScroll={x:this.adapter.scrollLeft(),y:this.adapter.scrollTop()},this.waypoints={vertical:{},horizontal:{}},t.waypointContextKey=this.key,n[t.waypointContextKey]=this,i+=1,this.createThrottledScrollHandler(),this.createThrottledResizeHandler()}var i=0,n={},o=window.Waypoint,r=window.requestAnimationFrame||window.mozRequestAnimationFrame||window.webkitRequestAnimationFrame||t,s=window.onload;e.prototype.add=function(t){var e=t.options.horizontal?"horizontal":"vertical";this.waypoints[e][t.key]=t,this.refresh()},e.prototype.checkEmpty=function(){var t=this.Adapter.isEmptyObject(this.waypoints.horizontal),e=this.Adapter.isEmptyObject(this.waypoints.vertical);t&&e&&(this.adapter.off(".waypoints"),delete n[this.key])},e.prototype.createThrottledResizeHandler=function(){function t(){e.handleResize(),e.didResize=!1}var e=this;this.adapter.on("resize.waypoints",function(){e.didResize||(e.didResize=!0,r(t))})},e.prototype.createThrottledScrollHandler=function(){function t(){e.handleScroll(),e.didScroll=!1}var e=this;this.adapter.on("scroll.waypoints",function(){(!e.didScroll||o.isTouch)&&(e.didScroll=!0,r(t))})},e.prototype.handleResize=function(){o.Context.refreshAll()},e.prototype.handleScroll=function(){var t={},e={horizontal:{newScroll:this.adapter.scrollLeft(),oldScroll:this.oldScroll.x,forward:"right",backward:"left"},vertical:{newScroll:this.adapter.scrollTop(),oldScroll:this.oldScroll.y,forward:"down",backward:"up"}};for(var i in e){var n=e[i],o=n.newScroll>n.oldScroll,r=o?n.forward:n.backward;for(var s in this.waypoints[i]){var a=this.waypoints[i][s],l=n.oldScroll=a.triggerPoint,p=l&&h,u=!l&&!h;(p||u)&&(a.queueTrigger(r),t[a.group.id]=a.group)}}for(var c in t)t[c].flushTriggers();this.oldScroll={x:e.horizontal.newScroll,y:e.vertical.newScroll}},e.prototype.innerHeight=function(){return this.element===this.element.window?o.viewportHeight():this.adapter.innerHeight()},e.prototype.remove=function(t){delete this.waypoints[t.axis][t.key],this.checkEmpty()},e.prototype.innerWidth=function(){return this.element===this.element.window?o.viewportWidth():this.adapter.innerWidth()},e.prototype.destroy=function(){var t=[];for(var e in this.waypoints)for(var i in this.waypoints[e])t.push(this.waypoints[e][i]);for(var n=0,o=t.length;o>n;n++)t[n].destroy()},e.prototype.refresh=function(){var t,e=this.element===this.element.window,i=this.adapter.offset(),n={};this.handleScroll(),t={horizontal:{contextOffset:e?0:i.left,contextScroll:e?0:this.oldScroll.x,contextDimension:this.innerWidth(),oldScroll:this.oldScroll.x,forward:"right",backward:"left",offsetProp:"left"},vertical:{contextOffset:e?0:i.top,contextScroll:e?0:this.oldScroll.y,contextDimension:this.innerHeight(),oldScroll:this.oldScroll.y,forward:"down",backward:"up",offsetProp:"top"}};for(var o in t){var r=t[o];for(var s in this.waypoints[o]){var a,l,h,p,u,c=this.waypoints[o][s],f=c.options.offset,d=c.triggerPoint,y=0,g=null==d;c.element!==c.element.window&&(y=c.adapter.offset()[r.offsetProp]),"function"==typeof f?f=f.apply(c):"string"==typeof f&&(f=parseFloat(f),c.options.offset.indexOf("%")>-1&&(f=Math.ceil(r.contextDimension*f/100))),a=r.contextScroll-r.contextOffset,c.triggerPoint=y+a-f,l=d=r.oldScroll,p=l&&h,u=!l&&!h,!g&&p?(c.queueTrigger(r.backward),n[c.group.id]=c.group):!g&&u?(c.queueTrigger(r.forward),n[c.group.id]=c.group):g&&r.oldScroll>=c.triggerPoint&&(c.queueTrigger(r.forward),n[c.group.id]=c.group)}}for(var w in n)n[w].flushTriggers();return this},e.findOrCreateByElement=function(t){return e.findByElement(t)||new e(t)},e.refreshAll=function(){for(var t in n)n[t].refresh()},e.findByElement=function(t){return n[t.waypointContextKey]},window.onload=function(){s(),e.refreshAll()},o.Context=e}(),function(){"use strict";function t(t,e){return t.triggerPoint-e.triggerPoint}function e(t,e){return e.triggerPoint-t.triggerPoint}function i(t){this.name=t.name,this.axis=t.axis,this.id=this.name+"-"+this.axis,this.waypoints=[],this.clearTriggerQueues(),n[this.axis][this.name]=this}var n={vertical:{},horizontal:{}},o=window.Waypoint;i.prototype.add=function(t){this.waypoints.push(t)},i.prototype.clearTriggerQueues=function(){this.triggerQueues={up:[],down:[],left:[],right:[]}},i.prototype.flushTriggers=function(){for(var i in this.triggerQueues){var n=this.triggerQueues[i],o="up"===i||"left"===i;n.sort(o?e:t);for(var r=0,s=n.length;s>r;r+=1){var a=n[r];(a.options.continuous||r===n.length-1)&&a.trigger([i])}}this.clearTriggerQueues()},i.prototype.next=function(e){this.waypoints.sort(t);var i=o.Adapter.inArray(e,this.waypoints),n=i===this.waypoints.length-1;return n?null:this.waypoints[i+1]},i.prototype.previous=function(e){this.waypoints.sort(t);var i=o.Adapter.inArray(e,this.waypoints);return i?this.waypoints[i-1]:null},i.prototype.queueTrigger=function(t,e){this.triggerQueues[e].push(t)},i.prototype.remove=function(t){var e=o.Adapter.inArray(t,this.waypoints);e>-1&&this.waypoints.splice(e,1)},i.prototype.first=function(){return this.waypoints[0]},i.prototype.last=function(){return this.waypoints[this.waypoints.length-1]},i.findOrCreate=function(t){return n[t.axis][t.name]||new i(t)},o.Group=i}(),function(){"use strict";function t(t){return t===t.window}function e(e){return t(e)?e:e.defaultView}function i(t){this.element=t,this.handlers={}}var n=window.Waypoint;i.prototype.innerHeight=function(){var e=t(this.element);return e?this.element.innerHeight:this.element.clientHeight},i.prototype.innerWidth=function(){var e=t(this.element);return e?this.element.innerWidth:this.element.clientWidth},i.prototype.off=function(t,e){function i(t,e,i){for(var n=0,o=e.length-1;o>n;n++){var r=e[n];i&&i!==r||t.removeEventListener(r)}}var n=t.split("."),o=n[0],r=n[1],s=this.element;if(r&&this.handlers[r]&&o)i(s,this.handlers[r][o],e),this.handlers[r][o]=[];else if(o)for(var a in this.handlers)i(s,this.handlers[a][o]||[],e),this.handlers[a][o]=[];else if(r&&this.handlers[r]){for(var l in this.handlers[r])i(s,this.handlers[r][l],e);this.handlers[r]={}}},i.prototype.offset=function(){if(!this.element.ownerDocument)return null;var t=this.element.ownerDocument.documentElement,i=e(this.element.ownerDocument),n={top:0,left:0};return this.element.getBoundingClientRect&&(n=this.element.getBoundingClientRect()),{top:n.top+i.pageYOffset-t.clientTop,left:n.left+i.pageXOffset-t.clientLeft}},i.prototype.on=function(t,e){var i=t.split("."),n=i[0],o=i[1]||"__default",r=this.handlers[o]=this.handlers[o]||{},s=r[n]=r[n]||[];s.push(e),this.element.addEventListener(n,e)},i.prototype.outerHeight=function(e){var i,n=this.innerHeight();return e&&!t(this.element)&&(i=window.getComputedStyle(this.element),n+=parseInt(i.marginTop,10),n+=parseInt(i.marginBottom,10)),n},i.prototype.outerWidth=function(e){var i,n=this.innerWidth();return e&&!t(this.element)&&(i=window.getComputedStyle(this.element),n+=parseInt(i.marginLeft,10),n+=parseInt(i.marginRight,10)),n},i.prototype.scrollLeft=function(){var t=e(this.element);return t?t.pageXOffset:this.element.scrollLeft},i.prototype.scrollTop=function(){var t=e(this.element);return t?t.pageYOffset:this.element.scrollTop},i.extend=function(){function t(t,e){if("object"==typeof t&&"object"==typeof e)for(var i in e)e.hasOwnProperty(i)&&(t[i]=e[i]);return t}for(var e=Array.prototype.slice.call(arguments),i=1,n=e.length;n>i;i++)t(e[0],e[i]);return e[0]},i.inArray=function(t,e,i){return null==e?-1:e.indexOf(t,i)},i.isEmptyObject=function(t){for(var e in t)return!1;return!0},n.adapters.push({name:"noframework",Adapter:i}),n.Adapter=i}(); \ No newline at end of file diff --git a/lib/zepto.waypoints.js b/lib/zepto.waypoints.js index 5eb682a4..20c2b341 100644 --- a/lib/zepto.waypoints.js +++ b/lib/zepto.waypoints.js @@ -128,10 +128,10 @@ https://github.com/imakewebthings/waypoints/blog/master/licenses.txt Waypoint.offsetAliases = { 'bottom-in-view': function() { - return this.context.height() - this.adapter.outerHeight() + return this.context.innerHeight() - this.adapter.outerHeight() }, 'right-in-view': function() { - return this.context.width() - this.adapter.outerWidth() + return this.context.innerWidth() - this.adapter.outerWidth() } } @@ -279,11 +279,11 @@ https://github.com/imakewebthings/waypoints/blog/master/licenses.txt } /* Private */ - Context.prototype.height = function() { + Context.prototype.innerHeight = function() { if (this.element === this.element.window) { return Waypoint.viewportHeight() } - return this.adapter.height() + return this.adapter.innerHeight() } /* Private */ @@ -293,11 +293,11 @@ https://github.com/imakewebthings/waypoints/blog/master/licenses.txt } /* Private */ - Context.prototype.width = function() { + Context.prototype.innerWidth = function() { if (this.element === this.element.window) { return Waypoint.viewportWidth() } - return this.adapter.width() + return this.adapter.innerWidth() } /* Public */ @@ -325,7 +325,7 @@ https://github.com/imakewebthings/waypoints/blog/master/licenses.txt horizontal: { contextOffset: isWindow ? 0 : contextOffset.left, contextScroll: isWindow ? 0 : this.oldScroll.x, - contextDimension: this.width(), + contextDimension: this.innerWidth(), oldScroll: this.oldScroll.x, forward: 'right', backward: 'left', @@ -334,7 +334,7 @@ https://github.com/imakewebthings/waypoints/blog/master/licenses.txt vertical: { contextOffset: isWindow ? 0 : contextOffset.top, contextScroll: isWindow ? 0 : this.oldScroll.y, - contextDimension: this.height(), + contextDimension: this.innerHeight(), oldScroll: this.oldScroll.y, forward: 'down', backward: 'up', @@ -533,12 +533,10 @@ https://github.com/imakewebthings/waypoints/blog/master/licenses.txt } $.each([ - 'height', 'off', 'on', 'scrollLeft', - 'scrollTop', - 'width' + 'scrollTop' ], function(i, method) { ZeptoAdapter.prototype[method] = function() { var args = Array.prototype.slice.call(arguments) @@ -552,25 +550,38 @@ https://github.com/imakewebthings/waypoints/blog/master/licenses.txt } } + // Adapted from https://gist.github.com/wheresrhys/5823198 $.each([ 'width', 'height' ], function(i, dimension) { - var method = $.camelCase('outer-' + dimension) + function createDimensionMethod($element, includeBorder) { + return function(includeMargin) { + var $element = this.$element + var size = $element[dimension]() + var sides = { + width: ['left', 'right'], + height: ['top', 'bottom'] + } - ZeptoAdapter.prototype[method] = function(includeMargin) { - var size = this.$element[dimension]() - var sides = { - width: ['left', 'right'], - height: ['top', 'bottom'] - } - if (includeMargin) { - $.each(sides[dimension], $.proxy(function(i, side) { - size += parseInt(this.$element.css('margin-' + side), 10) - }, this)) + $.each(sides[dimension], function(i, side) { + size += parseInt($element.css('padding-' + side), 10) + if (includeBorder) { + size += parseInt($element.css('border-' + side + '-width'), 10) + } + if (includeMargin) { + size += parseInt($element.css('margin-' + side), 10) + } + }) + return size } - return size } + + var innerMethod = $.camelCase('inner-' + dimension) + var outerMethod = $.camelCase('outer-' + dimension) + + ZeptoAdapter.prototype[innerMethod] = createDimensionMethod(false) + ZeptoAdapter.prototype[outerMethod] = createDimensionMethod(true) }) $.each([ diff --git a/lib/zepto.waypoints.min.js b/lib/zepto.waypoints.min.js index 764e3b18..b5c4f81c 100644 --- a/lib/zepto.waypoints.min.js +++ b/lib/zepto.waypoints.min.js @@ -4,4 +4,4 @@ Copyright © 2011-2014 Caleb Troughton Licensed under the MIT license. https://github.com/imakewebthings/waypoints/blog/master/licenses.txt */ -!function(){"use strict";function t(i){if(!i)throw new Error("No options passed to Waypoint constructor");if(!i.element)throw new Error("No element option passed to Waypoint constructor");if(!i.handler)throw new Error("No handler option passed to Waypoint constructor");this.key="waypoint-"+e,this.options=t.Adapter.extend({},t.defaults,i),this.element=this.options.element,this.adapter=new t.Adapter(this.element),this.callback=i.handler,this.axis=this.options.horizontal?"horizontal":"vertical",this.enabled=this.options.enabled,this.triggerPoint=null,this.group=t.Group.findOrCreate({name:this.options.group,axis:this.axis}),this.context=t.Context.findOrCreateByElement(this.options.context),t.offsetAliases[this.options.offset]&&(this.options.offset=t.offsetAliases[this.options.offset]),this.group.add(this),this.context.add(this),o[this.key]=this,e+=1}var e=0,o={};t.prototype.queueTrigger=function(t){this.group.queueTrigger(this,t)},t.prototype.trigger=function(t){this.enabled&&this.callback&&this.callback.apply(this,t)},t.prototype.destroy=function(){this.context.remove(this),this.group.remove(this),delete o[this.key]},t.prototype.disable=function(){return this.enabled=!1,this},t.prototype.enable=function(){return this.context.refresh(),this.enabled=!0,this},t.prototype.next=function(){return this.group.next(this)},t.prototype.previous=function(){return this.group.previous(this)},t.destroyAll=function(){var t=[];for(var e in o)t.push(o[e]);for(var i=0,r=t.length;r>i;i++)t[i].destroy()},t.refreshAll=function(){t.Context.refreshAll()},t.viewportHeight=function(){return window.innerHeight||document.documentElement.clientHeight},t.viewportWidth=function(){return document.documentElement.clientWidth},t.adapters=[],t.defaults={context:window,continuous:!0,enabled:!0,group:"default",horizontal:!1,offset:0},t.offsetAliases={"bottom-in-view":function(){return this.context.height()-this.adapter.outerHeight()},"right-in-view":function(){return this.context.width()-this.adapter.outerWidth()}},window.Waypoint=t}(),function(){"use strict";function t(t){window.setTimeout(t,1e3/60)}function e(t){this.element=t,this.Adapter=r.Adapter,this.adapter=new this.Adapter(t),this.key="waypoint-context-"+o,this.didScroll=!1,this.didResize=!1,this.oldScroll={x:this.adapter.scrollLeft(),y:this.adapter.scrollTop()},this.waypoints={vertical:{},horizontal:{}},t.waypointContextKey=this.key,i[t.waypointContextKey]=this,o+=1,this.createThrottledScrollHandler(),this.createThrottledResizeHandler()}var o=0,i={},r=window.Waypoint,n=window.requestAnimationFrame||window.mozRequestAnimationFrame||window.webkitRequestAnimationFrame||t,s=window.onload;e.prototype.add=function(t){var e=t.options.horizontal?"horizontal":"vertical";this.waypoints[e][t.key]=t,this.refresh()},e.prototype.checkEmpty=function(){var t=this.Adapter.isEmptyObject(this.waypoints.horizontal),e=this.Adapter.isEmptyObject(this.waypoints.vertical);t&&e&&(this.adapter.off(".waypoints"),delete i[this.key])},e.prototype.createThrottledResizeHandler=function(){function t(){e.handleResize(),e.didResize=!1}var e=this;this.adapter.on("resize.waypoints",function(){e.didResize||(e.didResize=!0,n(t))})},e.prototype.createThrottledScrollHandler=function(){function t(){e.handleScroll(),e.didScroll=!1}var e=this;this.adapter.on("scroll.waypoints",function(){(!e.didScroll||r.isTouch)&&(e.didScroll=!0,n(t))})},e.prototype.handleResize=function(){r.Context.refreshAll()},e.prototype.handleScroll=function(){var t={},e={horizontal:{newScroll:this.adapter.scrollLeft(),oldScroll:this.oldScroll.x,forward:"right",backward:"left"},vertical:{newScroll:this.adapter.scrollTop(),oldScroll:this.oldScroll.y,forward:"down",backward:"up"}};for(var o in e){var i=e[o],r=i.newScroll>i.oldScroll,n=r?i.forward:i.backward;for(var s in this.waypoints[o]){var a=this.waypoints[o][s],l=i.oldScroll=a.triggerPoint,p=l&&h,c=!l&&!h;(p||c)&&(a.queueTrigger(n),t[a.group.id]=a.group)}}for(var u in t)t[u].flushTriggers();this.oldScroll={x:e.horizontal.newScroll,y:e.vertical.newScroll}},e.prototype.height=function(){return this.element===this.element.window?r.viewportHeight():this.adapter.height()},e.prototype.remove=function(t){delete this.waypoints[t.axis][t.key],this.checkEmpty()},e.prototype.width=function(){return this.element===this.element.window?r.viewportWidth():this.adapter.width()},e.prototype.destroy=function(){var t=[];for(var e in this.waypoints)for(var o in this.waypoints[e])t.push(this.waypoints[e][o]);for(var i=0,r=t.length;r>i;i++)t[i].destroy()},e.prototype.refresh=function(){var t,e=this.element===this.element.window,o=this.adapter.offset(),i={};this.handleScroll(),t={horizontal:{contextOffset:e?0:o.left,contextScroll:e?0:this.oldScroll.x,contextDimension:this.width(),oldScroll:this.oldScroll.x,forward:"right",backward:"left",offsetProp:"left"},vertical:{contextOffset:e?0:o.top,contextScroll:e?0:this.oldScroll.y,contextDimension:this.height(),oldScroll:this.oldScroll.y,forward:"down",backward:"up",offsetProp:"top"}};for(var r in t){var n=t[r];for(var s in this.waypoints[r]){var a,l,h,p,c,u=this.waypoints[r][s],d=u.options.offset,f=u.triggerPoint,w=0,y=null==f;u.element!==u.element.window&&(w=u.adapter.offset()[n.offsetProp]),"function"==typeof d?d=d.apply(u):"string"==typeof d&&(d=parseFloat(d),u.options.offset.indexOf("%")>-1&&(d=Math.ceil(n.contextDimension*d/100))),a=n.contextScroll-n.contextOffset,u.triggerPoint=w+a-d,l=f=n.oldScroll,p=l&&h,c=!l&&!h,!y&&p?(u.queueTrigger(n.backward),i[u.group.id]=u.group):!y&&c?(u.queueTrigger(n.forward),i[u.group.id]=u.group):y&&n.oldScroll>=u.triggerPoint&&(u.queueTrigger(n.forward),i[u.group.id]=u.group)}}for(var g in i)i[g].flushTriggers();return this},e.findOrCreateByElement=function(t){return e.findByElement(t)||new e(t)},e.refreshAll=function(){for(var t in i)i[t].refresh()},e.findByElement=function(t){return i[t.waypointContextKey]},window.onload=function(){s(),e.refreshAll()},r.Context=e}(),function(){"use strict";function t(t,e){return t.triggerPoint-e.triggerPoint}function e(t,e){return e.triggerPoint-t.triggerPoint}function o(t){this.name=t.name,this.axis=t.axis,this.id=this.name+"-"+this.axis,this.waypoints=[],this.clearTriggerQueues(),i[this.axis][this.name]=this}var i={vertical:{},horizontal:{}},r=window.Waypoint;o.prototype.add=function(t){this.waypoints.push(t)},o.prototype.clearTriggerQueues=function(){this.triggerQueues={up:[],down:[],left:[],right:[]}},o.prototype.flushTriggers=function(){for(var o in this.triggerQueues){var i=this.triggerQueues[o],r="up"===o||"left"===o;i.sort(r?e:t);for(var n=0,s=i.length;s>n;n+=1){var a=i[n];(a.options.continuous||n===i.length-1)&&a.trigger([o])}}this.clearTriggerQueues()},o.prototype.next=function(e){this.waypoints.sort(t);var o=r.Adapter.inArray(e,this.waypoints),i=o===this.waypoints.length-1;return i?null:this.waypoints[o+1]},o.prototype.previous=function(e){this.waypoints.sort(t);var o=r.Adapter.inArray(e,this.waypoints);return o?this.waypoints[o-1]:null},o.prototype.queueTrigger=function(t,e){this.triggerQueues[e].push(t)},o.prototype.remove=function(t){var e=r.Adapter.inArray(t,this.waypoints);e>-1&&this.waypoints.splice(e,1)},o.prototype.first=function(){return this.waypoints[0]},o.prototype.last=function(){return this.waypoints[this.waypoints.length-1]},o.findOrCreate=function(t){return i[t.axis][t.name]||new o(t)},r.Group=o}(),function(){"use strict";function t(t){this.element=t,this.$element=e(t)}var e=window.Zepto,o=window.Waypoint;e.each(["height","off","on","scrollLeft","scrollTop","width"],function(e,o){t.prototype[o]=function(){var t=Array.prototype.slice.call(arguments);return this.$element[o].apply(this.$element,t)}}),t.prototype.offset=function(){return this.element!==this.element.window?this.$element.offset():void 0},e.each(["width","height"],function(o,i){var r=e.camelCase("outer-"+i);t.prototype[r]=function(t){var o=this.$element[i](),r={width:["left","right"],height:["top","bottom"]};return t&&e.each(r[i],e.proxy(function(t,e){o+=parseInt(this.$element.css("margin-"+e),10)},this)),o}}),e.each(["extend","inArray"],function(o,i){t[i]=e[i]}),t.isEmptyObject=function(t){for(var e in t)return!1;return!0},o.adapters.push({name:"zepto",Adapter:t}),o.Adapter=t}(),function(){"use strict";function t(t){return function(){var o=[],i=arguments[0];return t.isFunction(arguments[0])&&(i=t.extend({},arguments[1]),i.handler=arguments[0]),this.each(function(){var r=t.extend({},i,{element:this});"string"==typeof r.context&&(r.context=t(this).closest(r.context)[0]),o.push(new e(r))}),o}}var e=window.Waypoint;window.jQuery&&(window.jQuery.fn.waypoint=t(window.jQuery)),window.Zepto&&(window.Zepto.fn.waypoint=t(window.Zepto))}(); \ No newline at end of file +!function(){"use strict";function t(i){if(!i)throw new Error("No options passed to Waypoint constructor");if(!i.element)throw new Error("No element option passed to Waypoint constructor");if(!i.handler)throw new Error("No handler option passed to Waypoint constructor");this.key="waypoint-"+e,this.options=t.Adapter.extend({},t.defaults,i),this.element=this.options.element,this.adapter=new t.Adapter(this.element),this.callback=i.handler,this.axis=this.options.horizontal?"horizontal":"vertical",this.enabled=this.options.enabled,this.triggerPoint=null,this.group=t.Group.findOrCreate({name:this.options.group,axis:this.axis}),this.context=t.Context.findOrCreateByElement(this.options.context),t.offsetAliases[this.options.offset]&&(this.options.offset=t.offsetAliases[this.options.offset]),this.group.add(this),this.context.add(this),o[this.key]=this,e+=1}var e=0,o={};t.prototype.queueTrigger=function(t){this.group.queueTrigger(this,t)},t.prototype.trigger=function(t){this.enabled&&this.callback&&this.callback.apply(this,t)},t.prototype.destroy=function(){this.context.remove(this),this.group.remove(this),delete o[this.key]},t.prototype.disable=function(){return this.enabled=!1,this},t.prototype.enable=function(){return this.context.refresh(),this.enabled=!0,this},t.prototype.next=function(){return this.group.next(this)},t.prototype.previous=function(){return this.group.previous(this)},t.destroyAll=function(){var t=[];for(var e in o)t.push(o[e]);for(var i=0,n=t.length;n>i;i++)t[i].destroy()},t.refreshAll=function(){t.Context.refreshAll()},t.viewportHeight=function(){return window.innerHeight||document.documentElement.clientHeight},t.viewportWidth=function(){return document.documentElement.clientWidth},t.adapters=[],t.defaults={context:window,continuous:!0,enabled:!0,group:"default",horizontal:!1,offset:0},t.offsetAliases={"bottom-in-view":function(){return this.context.innerHeight()-this.adapter.outerHeight()},"right-in-view":function(){return this.context.innerWidth()-this.adapter.outerWidth()}},window.Waypoint=t}(),function(){"use strict";function t(t){window.setTimeout(t,1e3/60)}function e(t){this.element=t,this.Adapter=n.Adapter,this.adapter=new this.Adapter(t),this.key="waypoint-context-"+o,this.didScroll=!1,this.didResize=!1,this.oldScroll={x:this.adapter.scrollLeft(),y:this.adapter.scrollTop()},this.waypoints={vertical:{},horizontal:{}},t.waypointContextKey=this.key,i[t.waypointContextKey]=this,o+=1,this.createThrottledScrollHandler(),this.createThrottledResizeHandler()}var o=0,i={},n=window.Waypoint,r=window.requestAnimationFrame||window.mozRequestAnimationFrame||window.webkitRequestAnimationFrame||t,s=window.onload;e.prototype.add=function(t){var e=t.options.horizontal?"horizontal":"vertical";this.waypoints[e][t.key]=t,this.refresh()},e.prototype.checkEmpty=function(){var t=this.Adapter.isEmptyObject(this.waypoints.horizontal),e=this.Adapter.isEmptyObject(this.waypoints.vertical);t&&e&&(this.adapter.off(".waypoints"),delete i[this.key])},e.prototype.createThrottledResizeHandler=function(){function t(){e.handleResize(),e.didResize=!1}var e=this;this.adapter.on("resize.waypoints",function(){e.didResize||(e.didResize=!0,r(t))})},e.prototype.createThrottledScrollHandler=function(){function t(){e.handleScroll(),e.didScroll=!1}var e=this;this.adapter.on("scroll.waypoints",function(){(!e.didScroll||n.isTouch)&&(e.didScroll=!0,r(t))})},e.prototype.handleResize=function(){n.Context.refreshAll()},e.prototype.handleScroll=function(){var t={},e={horizontal:{newScroll:this.adapter.scrollLeft(),oldScroll:this.oldScroll.x,forward:"right",backward:"left"},vertical:{newScroll:this.adapter.scrollTop(),oldScroll:this.oldScroll.y,forward:"down",backward:"up"}};for(var o in e){var i=e[o],n=i.newScroll>i.oldScroll,r=n?i.forward:i.backward;for(var s in this.waypoints[o]){var a=this.waypoints[o][s],l=i.oldScroll=a.triggerPoint,p=l&&h,c=!l&&!h;(p||c)&&(a.queueTrigger(r),t[a.group.id]=a.group)}}for(var u in t)t[u].flushTriggers();this.oldScroll={x:e.horizontal.newScroll,y:e.vertical.newScroll}},e.prototype.innerHeight=function(){return this.element===this.element.window?n.viewportHeight():this.adapter.innerHeight()},e.prototype.remove=function(t){delete this.waypoints[t.axis][t.key],this.checkEmpty()},e.prototype.innerWidth=function(){return this.element===this.element.window?n.viewportWidth():this.adapter.innerWidth()},e.prototype.destroy=function(){var t=[];for(var e in this.waypoints)for(var o in this.waypoints[e])t.push(this.waypoints[e][o]);for(var i=0,n=t.length;n>i;i++)t[i].destroy()},e.prototype.refresh=function(){var t,e=this.element===this.element.window,o=this.adapter.offset(),i={};this.handleScroll(),t={horizontal:{contextOffset:e?0:o.left,contextScroll:e?0:this.oldScroll.x,contextDimension:this.innerWidth(),oldScroll:this.oldScroll.x,forward:"right",backward:"left",offsetProp:"left"},vertical:{contextOffset:e?0:o.top,contextScroll:e?0:this.oldScroll.y,contextDimension:this.innerHeight(),oldScroll:this.oldScroll.y,forward:"down",backward:"up",offsetProp:"top"}};for(var n in t){var r=t[n];for(var s in this.waypoints[n]){var a,l,h,p,c,u=this.waypoints[n][s],d=u.options.offset,f=u.triggerPoint,w=0,y=null==f;u.element!==u.element.window&&(w=u.adapter.offset()[r.offsetProp]),"function"==typeof d?d=d.apply(u):"string"==typeof d&&(d=parseFloat(d),u.options.offset.indexOf("%")>-1&&(d=Math.ceil(r.contextDimension*d/100))),a=r.contextScroll-r.contextOffset,u.triggerPoint=w+a-d,l=f=r.oldScroll,p=l&&h,c=!l&&!h,!y&&p?(u.queueTrigger(r.backward),i[u.group.id]=u.group):!y&&c?(u.queueTrigger(r.forward),i[u.group.id]=u.group):y&&r.oldScroll>=u.triggerPoint&&(u.queueTrigger(r.forward),i[u.group.id]=u.group)}}for(var g in i)i[g].flushTriggers();return this},e.findOrCreateByElement=function(t){return e.findByElement(t)||new e(t)},e.refreshAll=function(){for(var t in i)i[t].refresh()},e.findByElement=function(t){return i[t.waypointContextKey]},window.onload=function(){s(),e.refreshAll()},n.Context=e}(),function(){"use strict";function t(t,e){return t.triggerPoint-e.triggerPoint}function e(t,e){return e.triggerPoint-t.triggerPoint}function o(t){this.name=t.name,this.axis=t.axis,this.id=this.name+"-"+this.axis,this.waypoints=[],this.clearTriggerQueues(),i[this.axis][this.name]=this}var i={vertical:{},horizontal:{}},n=window.Waypoint;o.prototype.add=function(t){this.waypoints.push(t)},o.prototype.clearTriggerQueues=function(){this.triggerQueues={up:[],down:[],left:[],right:[]}},o.prototype.flushTriggers=function(){for(var o in this.triggerQueues){var i=this.triggerQueues[o],n="up"===o||"left"===o;i.sort(n?e:t);for(var r=0,s=i.length;s>r;r+=1){var a=i[r];(a.options.continuous||r===i.length-1)&&a.trigger([o])}}this.clearTriggerQueues()},o.prototype.next=function(e){this.waypoints.sort(t);var o=n.Adapter.inArray(e,this.waypoints),i=o===this.waypoints.length-1;return i?null:this.waypoints[o+1]},o.prototype.previous=function(e){this.waypoints.sort(t);var o=n.Adapter.inArray(e,this.waypoints);return o?this.waypoints[o-1]:null},o.prototype.queueTrigger=function(t,e){this.triggerQueues[e].push(t)},o.prototype.remove=function(t){var e=n.Adapter.inArray(t,this.waypoints);e>-1&&this.waypoints.splice(e,1)},o.prototype.first=function(){return this.waypoints[0]},o.prototype.last=function(){return this.waypoints[this.waypoints.length-1]},o.findOrCreate=function(t){return i[t.axis][t.name]||new o(t)},n.Group=o}(),function(){"use strict";function t(t){this.element=t,this.$element=e(t)}var e=window.Zepto,o=window.Waypoint;e.each(["off","on","scrollLeft","scrollTop"],function(e,o){t.prototype[o]=function(){var t=Array.prototype.slice.call(arguments);return this.$element[o].apply(this.$element,t)}}),t.prototype.offset=function(){return this.element!==this.element.window?this.$element.offset():void 0},e.each(["width","height"],function(o,i){function n(t,o){return function(t){var n=this.$element,r=n[i](),s={width:["left","right"],height:["top","bottom"]};return e.each(s[i],function(e,i){r+=parseInt(n.css("padding-"+i),10),o&&(r+=parseInt(n.css("border-"+i+"-width"),10)),t&&(r+=parseInt(n.css("margin-"+i),10))}),r}}var r=e.camelCase("inner-"+i),s=e.camelCase("outer-"+i);t.prototype[r]=n(!1),t.prototype[s]=n(!0)}),e.each(["extend","inArray"],function(o,i){t[i]=e[i]}),t.isEmptyObject=function(t){for(var e in t)return!1;return!0},o.adapters.push({name:"zepto",Adapter:t}),o.Adapter=t}(),function(){"use strict";function t(t){return function(){var o=[],i=arguments[0];return t.isFunction(arguments[0])&&(i=t.extend({},arguments[1]),i.handler=arguments[0]),this.each(function(){var n=t.extend({},i,{element:this});"string"==typeof n.context&&(n.context=t(this).closest(n.context)[0]),o.push(new e(n))}),o}}var e=window.Waypoint;window.jQuery&&(window.jQuery.fn.waypoint=t(window.jQuery)),window.Zepto&&(window.Zepto.fn.waypoint=t(window.Zepto))}(); \ No newline at end of file diff --git a/src/adapters/jquery.js b/src/adapters/jquery.js index a9338f20..ac712364 100644 --- a/src/adapters/jquery.js +++ b/src/adapters/jquery.js @@ -9,15 +9,15 @@ } $.each([ - 'height', + 'innerHeight', + 'innerWidth', 'off', 'offset', 'on', 'outerHeight', 'outerWidth', 'scrollLeft', - 'scrollTop', - 'width' + 'scrollTop' ], function(i, method) { JQueryAdapter.prototype[method] = function() { var args = Array.prototype.slice.call(arguments) diff --git a/src/adapters/noframework.js b/src/adapters/noframework.js index 25b4a40a..bac75ead 100644 --- a/src/adapters/noframework.js +++ b/src/adapters/noframework.js @@ -19,9 +19,14 @@ this.handlers = {} } - NoFrameworkAdapter.prototype.height = function() { + NoFrameworkAdapter.prototype.innerHeight = function() { var isWin = isWindow(this.element) - return isWin ? this.element.innerHeight : this.element.offsetHeight + return isWin ? this.element.innerHeight : this.element.clientHeight + } + + NoFrameworkAdapter.prototype.innerWidth = function() { + var isWin = isWindow(this.element) + return isWin ? this.element.innerWidth : this.element.clientWidth } NoFrameworkAdapter.prototype.off = function(event, handler) { @@ -92,7 +97,7 @@ } NoFrameworkAdapter.prototype.outerHeight = function(includeMargin) { - var height = this.height() + var height = this.innerHeight() var computedStyle if (includeMargin && !isWindow(this.element)) { @@ -105,7 +110,7 @@ } NoFrameworkAdapter.prototype.outerWidth = function(includeMargin) { - var width = this.width() + var width = this.innerWidth() var computedStyle if (includeMargin && !isWindow(this.element)) { @@ -127,11 +132,6 @@ return win ? win.pageYOffset : this.element.scrollTop } - NoFrameworkAdapter.prototype.width = function() { - var isWin = isWindow(this.element) - return isWin ? this.element.innerWidth : this.element.offsetWidth - } - NoFrameworkAdapter.extend = function() { var args = Array.prototype.slice.call(arguments) diff --git a/src/adapters/zepto.js b/src/adapters/zepto.js index e81f1d45..203e40e1 100644 --- a/src/adapters/zepto.js +++ b/src/adapters/zepto.js @@ -10,12 +10,10 @@ } $.each([ - 'height', 'off', 'on', 'scrollLeft', - 'scrollTop', - 'width' + 'scrollTop' ], function(i, method) { ZeptoAdapter.prototype[method] = function() { var args = Array.prototype.slice.call(arguments) @@ -29,25 +27,38 @@ } } + // Adapted from https://gist.github.com/wheresrhys/5823198 $.each([ 'width', 'height' ], function(i, dimension) { - var method = $.camelCase('outer-' + dimension) + function createDimensionMethod($element, includeBorder) { + return function(includeMargin) { + var $element = this.$element + var size = $element[dimension]() + var sides = { + width: ['left', 'right'], + height: ['top', 'bottom'] + } - ZeptoAdapter.prototype[method] = function(includeMargin) { - var size = this.$element[dimension]() - var sides = { - width: ['left', 'right'], - height: ['top', 'bottom'] + $.each(sides[dimension], function(i, side) { + size += parseInt($element.css('padding-' + side), 10) + if (includeBorder) { + size += parseInt($element.css('border-' + side + '-width'), 10) + } + if (includeMargin) { + size += parseInt($element.css('margin-' + side), 10) + } + }) + return size } - if (includeMargin) { - $.each(sides[dimension], $.proxy(function(i, side) { - size += parseInt(this.$element.css('margin-' + side), 10) - }, this)) - } - return size } + + var innerMethod = $.camelCase('inner-' + dimension) + var outerMethod = $.camelCase('outer-' + dimension) + + ZeptoAdapter.prototype[innerMethod] = createDimensionMethod(false) + ZeptoAdapter.prototype[outerMethod] = createDimensionMethod(true) }) $.each([ diff --git a/src/context.js b/src/context.js index d6bba8b3..27632c00 100644 --- a/src/context.js +++ b/src/context.js @@ -140,11 +140,11 @@ } /* Private */ - Context.prototype.height = function() { + Context.prototype.innerHeight = function() { if (this.element === this.element.window) { return Waypoint.viewportHeight() } - return this.adapter.height() + return this.adapter.innerHeight() } /* Private */ @@ -154,11 +154,11 @@ } /* Private */ - Context.prototype.width = function() { + Context.prototype.innerWidth = function() { if (this.element === this.element.window) { return Waypoint.viewportWidth() } - return this.adapter.width() + return this.adapter.innerWidth() } /* Public */ @@ -186,7 +186,7 @@ horizontal: { contextOffset: isWindow ? 0 : contextOffset.left, contextScroll: isWindow ? 0 : this.oldScroll.x, - contextDimension: this.width(), + contextDimension: this.innerWidth(), oldScroll: this.oldScroll.x, forward: 'right', backward: 'left', @@ -195,7 +195,7 @@ vertical: { contextOffset: isWindow ? 0 : contextOffset.top, contextScroll: isWindow ? 0 : this.oldScroll.y, - contextDimension: this.height(), + contextDimension: this.innerHeight(), oldScroll: this.oldScroll.y, forward: 'down', backward: 'up', diff --git a/src/waypoint.js b/src/waypoint.js index 0c9b250e..53896b6a 100644 --- a/src/waypoint.js +++ b/src/waypoint.js @@ -122,10 +122,10 @@ Waypoint.offsetAliases = { 'bottom-in-view': function() { - return this.context.height() - this.adapter.outerHeight() + return this.context.innerHeight() - this.adapter.outerHeight() }, 'right-in-view': function() { - return this.context.width() - this.adapter.outerWidth() + return this.context.innerWidth() - this.adapter.outerWidth() } } From 89c23ba41a2bab9fe36a24bb4004a3b868043c3d Mon Sep 17 00:00:00 2001 From: imakewebthings Date: Wed, 17 Dec 2014 15:13:50 -0800 Subject: [PATCH 43/98] Ignore leftover pages builds --- .gitignore | 1 + 1 file changed, 1 insertion(+) diff --git a/.gitignore b/.gitignore index 9e539ac7..7f0e595b 100644 --- a/.gitignore +++ b/.gitignore @@ -1,3 +1,4 @@ +_site .sass-cache .DS_Store /style.scss From 92027f2db0fe491ab670be30273ba7b9ce4e3af7 Mon Sep 17 00:00:00 2001 From: imakewebthings Date: Wed, 17 Dec 2014 15:21:28 -0800 Subject: [PATCH 44/98] Add API urls as comments --- lib/jquery.waypoints.js | 17 +++++++++++++++++ lib/noframework.waypoints.js | 17 +++++++++++++++++ lib/shortcuts/infinite.js | 1 + lib/shortcuts/inview.js | 1 + lib/shortcuts/sticky.js | 1 + lib/zepto.waypoints.js | 17 +++++++++++++++++ src/context.js | 4 ++++ src/group.js | 3 +++ src/shortcuts/infinite.js | 1 + src/shortcuts/inview.js | 1 + src/shortcuts/sticky.js | 1 + src/waypoint.js | 10 ++++++++++ 12 files changed, 74 insertions(+) diff --git a/lib/jquery.waypoints.js b/lib/jquery.waypoints.js index ac35e3ab..067e1472 100644 --- a/lib/jquery.waypoints.js +++ b/lib/jquery.waypoints.js @@ -10,6 +10,7 @@ https://github.com/imakewebthings/waypoints/blog/master/licenses.txt var keyCounter = 0 var allWaypoints = {} + /* http://imakewebthings.com/waypoints/api/waypoint */ function Waypoint(options) { if (!options) { throw new Error('No options passed to Waypoint constructor') @@ -60,6 +61,7 @@ https://github.com/imakewebthings/waypoints/blog/master/licenses.txt } /* Public */ + /* http://imakewebthings.com/waypoints/api/destroy */ Waypoint.prototype.destroy = function() { this.context.remove(this) this.group.remove(this) @@ -67,12 +69,14 @@ https://github.com/imakewebthings/waypoints/blog/master/licenses.txt } /* Public */ + /* http://imakewebthings.com/waypoints/api/disable */ Waypoint.prototype.disable = function() { this.enabled = false return this } /* Public */ + /* http://imakewebthings.com/waypoints/api/enable */ Waypoint.prototype.enable = function() { this.context.refresh() this.enabled = true @@ -80,16 +84,19 @@ https://github.com/imakewebthings/waypoints/blog/master/licenses.txt } /* Public */ + /* http://imakewebthings.com/waypoints/api/next */ Waypoint.prototype.next = function() { return this.group.next(this) } /* Public */ + /* http://imakewebthings.com/waypoints/api/previous */ Waypoint.prototype.previous = function() { return this.group.previous(this) } /* Public */ + /* http://imakewebthings.com/waypoints/api/destroy-all */ Waypoint.destroyAll = function() { var allWaypointsArray = [] for (var waypointKey in allWaypoints) { @@ -101,16 +108,19 @@ https://github.com/imakewebthings/waypoints/blog/master/licenses.txt } /* Public */ + /* http://imakewebthings.com/waypoints/api/refresh-all */ Waypoint.refreshAll = function() { Waypoint.Context.refreshAll() } /* Public */ + /* http://imakewebthings.com/waypoints/api/viewport-height */ Waypoint.viewportHeight = function() { return window.innerHeight || document.documentElement.clientHeight } /* Public */ + /* http://imakewebthings.com/waypoints/api/viewport-width */ Waypoint.viewportWidth = function() { return document.documentElement.clientWidth } @@ -153,6 +163,7 @@ https://github.com/imakewebthings/waypoints/blog/master/licenses.txt requestAnimationFrameShim var oldWindowLoad = window.onload + /* http://imakewebthings.com/waypoints/api/context */ function Context(element) { this.element = element this.Adapter = Waypoint.Adapter @@ -301,6 +312,7 @@ https://github.com/imakewebthings/waypoints/blog/master/licenses.txt } /* Public */ + /* http://imakewebthings.com/waypoints/api/context-destroy */ Context.prototype.destroy = function() { var allWaypoints = [] for (var axis in this.waypoints) { @@ -314,6 +326,7 @@ https://github.com/imakewebthings/waypoints/blog/master/licenses.txt } /* Public */ + /* http://imakewebthings.com/waypoints/api/context-refresh */ Context.prototype.refresh = function() { var isWindow = this.element === this.element.window var contextOffset = this.adapter.offset() @@ -409,6 +422,7 @@ https://github.com/imakewebthings/waypoints/blog/master/licenses.txt } /* Public */ + /* http://imakewebthings.com/waypoints/api/context-find-by-element */ Context.findByElement = function(element) { return contexts[element.waypointContextKey] } @@ -436,6 +450,7 @@ https://github.com/imakewebthings/waypoints/blog/master/licenses.txt } var Waypoint = window.Waypoint + /* http://imakewebthings.com/waypoints/api/group */ function Group(options) { this.name = options.name this.axis = options.axis @@ -505,11 +520,13 @@ https://github.com/imakewebthings/waypoints/blog/master/licenses.txt } /* Public */ + /* http://imakewebthings.com/waypoints/api/first */ Group.prototype.first = function() { return this.waypoints[0] } /* Public */ + /* http://imakewebthings.com/waypoints/api/last */ Group.prototype.last = function() { return this.waypoints[this.waypoints.length - 1] } diff --git a/lib/noframework.waypoints.js b/lib/noframework.waypoints.js index 4108f2ef..938d32aa 100644 --- a/lib/noframework.waypoints.js +++ b/lib/noframework.waypoints.js @@ -10,6 +10,7 @@ https://github.com/imakewebthings/waypoints/blog/master/licenses.txt var keyCounter = 0 var allWaypoints = {} + /* http://imakewebthings.com/waypoints/api/waypoint */ function Waypoint(options) { if (!options) { throw new Error('No options passed to Waypoint constructor') @@ -60,6 +61,7 @@ https://github.com/imakewebthings/waypoints/blog/master/licenses.txt } /* Public */ + /* http://imakewebthings.com/waypoints/api/destroy */ Waypoint.prototype.destroy = function() { this.context.remove(this) this.group.remove(this) @@ -67,12 +69,14 @@ https://github.com/imakewebthings/waypoints/blog/master/licenses.txt } /* Public */ + /* http://imakewebthings.com/waypoints/api/disable */ Waypoint.prototype.disable = function() { this.enabled = false return this } /* Public */ + /* http://imakewebthings.com/waypoints/api/enable */ Waypoint.prototype.enable = function() { this.context.refresh() this.enabled = true @@ -80,16 +84,19 @@ https://github.com/imakewebthings/waypoints/blog/master/licenses.txt } /* Public */ + /* http://imakewebthings.com/waypoints/api/next */ Waypoint.prototype.next = function() { return this.group.next(this) } /* Public */ + /* http://imakewebthings.com/waypoints/api/previous */ Waypoint.prototype.previous = function() { return this.group.previous(this) } /* Public */ + /* http://imakewebthings.com/waypoints/api/destroy-all */ Waypoint.destroyAll = function() { var allWaypointsArray = [] for (var waypointKey in allWaypoints) { @@ -101,16 +108,19 @@ https://github.com/imakewebthings/waypoints/blog/master/licenses.txt } /* Public */ + /* http://imakewebthings.com/waypoints/api/refresh-all */ Waypoint.refreshAll = function() { Waypoint.Context.refreshAll() } /* Public */ + /* http://imakewebthings.com/waypoints/api/viewport-height */ Waypoint.viewportHeight = function() { return window.innerHeight || document.documentElement.clientHeight } /* Public */ + /* http://imakewebthings.com/waypoints/api/viewport-width */ Waypoint.viewportWidth = function() { return document.documentElement.clientWidth } @@ -153,6 +163,7 @@ https://github.com/imakewebthings/waypoints/blog/master/licenses.txt requestAnimationFrameShim var oldWindowLoad = window.onload + /* http://imakewebthings.com/waypoints/api/context */ function Context(element) { this.element = element this.Adapter = Waypoint.Adapter @@ -301,6 +312,7 @@ https://github.com/imakewebthings/waypoints/blog/master/licenses.txt } /* Public */ + /* http://imakewebthings.com/waypoints/api/context-destroy */ Context.prototype.destroy = function() { var allWaypoints = [] for (var axis in this.waypoints) { @@ -314,6 +326,7 @@ https://github.com/imakewebthings/waypoints/blog/master/licenses.txt } /* Public */ + /* http://imakewebthings.com/waypoints/api/context-refresh */ Context.prototype.refresh = function() { var isWindow = this.element === this.element.window var contextOffset = this.adapter.offset() @@ -409,6 +422,7 @@ https://github.com/imakewebthings/waypoints/blog/master/licenses.txt } /* Public */ + /* http://imakewebthings.com/waypoints/api/context-find-by-element */ Context.findByElement = function(element) { return contexts[element.waypointContextKey] } @@ -436,6 +450,7 @@ https://github.com/imakewebthings/waypoints/blog/master/licenses.txt } var Waypoint = window.Waypoint + /* http://imakewebthings.com/waypoints/api/group */ function Group(options) { this.name = options.name this.axis = options.axis @@ -505,11 +520,13 @@ https://github.com/imakewebthings/waypoints/blog/master/licenses.txt } /* Public */ + /* http://imakewebthings.com/waypoints/api/first */ Group.prototype.first = function() { return this.waypoints[0] } /* Public */ + /* http://imakewebthings.com/waypoints/api/last */ Group.prototype.last = function() { return this.waypoints[this.waypoints.length - 1] } diff --git a/lib/shortcuts/infinite.js b/lib/shortcuts/infinite.js index 283a208a..0a3c37c5 100644 --- a/lib/shortcuts/infinite.js +++ b/lib/shortcuts/infinite.js @@ -10,6 +10,7 @@ https://github.com/imakewebthings/waypoints/blog/master/licenses.txt var $ = window.jQuery var Waypoint = window.Waypoint + /* http://imakewebthings.com/waypoints/shortcuts/infinite-scroll */ function Infinite(options) { this.options = $.extend({}, Infinite.defaults, options) this.container = this.options.element diff --git a/lib/shortcuts/inview.js b/lib/shortcuts/inview.js index 9d512ccf..b068c795 100644 --- a/lib/shortcuts/inview.js +++ b/lib/shortcuts/inview.js @@ -11,6 +11,7 @@ https://github.com/imakewebthings/waypoints/blog/master/licenses.txt var Waypoint = window.Waypoint + /* http://imakewebthings.com/waypoints/shortcuts/inview */ function Inview(options) { this.options = Waypoint.Adapter.extend({}, Inview.defaults, options) this.axis = this.options.horizontal ? 'horizontal' : 'vertical' diff --git a/lib/shortcuts/sticky.js b/lib/shortcuts/sticky.js index 4bc9ac5a..7805dc7b 100644 --- a/lib/shortcuts/sticky.js +++ b/lib/shortcuts/sticky.js @@ -10,6 +10,7 @@ https://github.com/imakewebthings/waypoints/blog/master/licenses.txt var $ = window.jQuery var Waypoint = window.Waypoint + /* http://imakewebthings.com/waypoints/shortcuts/sticky-elements */ function Sticky(options) { this.options = $.extend({}, Waypoint.defaults, Sticky.defaults, options) this.element = this.options.element diff --git a/lib/zepto.waypoints.js b/lib/zepto.waypoints.js index 20c2b341..c399da9f 100644 --- a/lib/zepto.waypoints.js +++ b/lib/zepto.waypoints.js @@ -10,6 +10,7 @@ https://github.com/imakewebthings/waypoints/blog/master/licenses.txt var keyCounter = 0 var allWaypoints = {} + /* http://imakewebthings.com/waypoints/api/waypoint */ function Waypoint(options) { if (!options) { throw new Error('No options passed to Waypoint constructor') @@ -60,6 +61,7 @@ https://github.com/imakewebthings/waypoints/blog/master/licenses.txt } /* Public */ + /* http://imakewebthings.com/waypoints/api/destroy */ Waypoint.prototype.destroy = function() { this.context.remove(this) this.group.remove(this) @@ -67,12 +69,14 @@ https://github.com/imakewebthings/waypoints/blog/master/licenses.txt } /* Public */ + /* http://imakewebthings.com/waypoints/api/disable */ Waypoint.prototype.disable = function() { this.enabled = false return this } /* Public */ + /* http://imakewebthings.com/waypoints/api/enable */ Waypoint.prototype.enable = function() { this.context.refresh() this.enabled = true @@ -80,16 +84,19 @@ https://github.com/imakewebthings/waypoints/blog/master/licenses.txt } /* Public */ + /* http://imakewebthings.com/waypoints/api/next */ Waypoint.prototype.next = function() { return this.group.next(this) } /* Public */ + /* http://imakewebthings.com/waypoints/api/previous */ Waypoint.prototype.previous = function() { return this.group.previous(this) } /* Public */ + /* http://imakewebthings.com/waypoints/api/destroy-all */ Waypoint.destroyAll = function() { var allWaypointsArray = [] for (var waypointKey in allWaypoints) { @@ -101,16 +108,19 @@ https://github.com/imakewebthings/waypoints/blog/master/licenses.txt } /* Public */ + /* http://imakewebthings.com/waypoints/api/refresh-all */ Waypoint.refreshAll = function() { Waypoint.Context.refreshAll() } /* Public */ + /* http://imakewebthings.com/waypoints/api/viewport-height */ Waypoint.viewportHeight = function() { return window.innerHeight || document.documentElement.clientHeight } /* Public */ + /* http://imakewebthings.com/waypoints/api/viewport-width */ Waypoint.viewportWidth = function() { return document.documentElement.clientWidth } @@ -153,6 +163,7 @@ https://github.com/imakewebthings/waypoints/blog/master/licenses.txt requestAnimationFrameShim var oldWindowLoad = window.onload + /* http://imakewebthings.com/waypoints/api/context */ function Context(element) { this.element = element this.Adapter = Waypoint.Adapter @@ -301,6 +312,7 @@ https://github.com/imakewebthings/waypoints/blog/master/licenses.txt } /* Public */ + /* http://imakewebthings.com/waypoints/api/context-destroy */ Context.prototype.destroy = function() { var allWaypoints = [] for (var axis in this.waypoints) { @@ -314,6 +326,7 @@ https://github.com/imakewebthings/waypoints/blog/master/licenses.txt } /* Public */ + /* http://imakewebthings.com/waypoints/api/context-refresh */ Context.prototype.refresh = function() { var isWindow = this.element === this.element.window var contextOffset = this.adapter.offset() @@ -409,6 +422,7 @@ https://github.com/imakewebthings/waypoints/blog/master/licenses.txt } /* Public */ + /* http://imakewebthings.com/waypoints/api/context-find-by-element */ Context.findByElement = function(element) { return contexts[element.waypointContextKey] } @@ -436,6 +450,7 @@ https://github.com/imakewebthings/waypoints/blog/master/licenses.txt } var Waypoint = window.Waypoint + /* http://imakewebthings.com/waypoints/api/group */ function Group(options) { this.name = options.name this.axis = options.axis @@ -505,11 +520,13 @@ https://github.com/imakewebthings/waypoints/blog/master/licenses.txt } /* Public */ + /* http://imakewebthings.com/waypoints/api/first */ Group.prototype.first = function() { return this.waypoints[0] } /* Public */ + /* http://imakewebthings.com/waypoints/api/last */ Group.prototype.last = function() { return this.waypoints[this.waypoints.length - 1] } diff --git a/src/context.js b/src/context.js index 27632c00..61614aaf 100644 --- a/src/context.js +++ b/src/context.js @@ -14,6 +14,7 @@ requestAnimationFrameShim var oldWindowLoad = window.onload + /* http://imakewebthings.com/waypoints/api/context */ function Context(element) { this.element = element this.Adapter = Waypoint.Adapter @@ -162,6 +163,7 @@ } /* Public */ + /* http://imakewebthings.com/waypoints/api/context-destroy */ Context.prototype.destroy = function() { var allWaypoints = [] for (var axis in this.waypoints) { @@ -175,6 +177,7 @@ } /* Public */ + /* http://imakewebthings.com/waypoints/api/context-refresh */ Context.prototype.refresh = function() { var isWindow = this.element === this.element.window var contextOffset = this.adapter.offset() @@ -270,6 +273,7 @@ } /* Public */ + /* http://imakewebthings.com/waypoints/api/context-find-by-element */ Context.findByElement = function(element) { return contexts[element.waypointContextKey] } diff --git a/src/group.js b/src/group.js index 507206ec..57c30387 100644 --- a/src/group.js +++ b/src/group.js @@ -15,6 +15,7 @@ } var Waypoint = window.Waypoint + /* http://imakewebthings.com/waypoints/api/group */ function Group(options) { this.name = options.name this.axis = options.axis @@ -84,11 +85,13 @@ } /* Public */ + /* http://imakewebthings.com/waypoints/api/first */ Group.prototype.first = function() { return this.waypoints[0] } /* Public */ + /* http://imakewebthings.com/waypoints/api/last */ Group.prototype.last = function() { return this.waypoints[this.waypoints.length - 1] } diff --git a/src/shortcuts/infinite.js b/src/shortcuts/infinite.js index 8775d340..66751143 100644 --- a/src/shortcuts/infinite.js +++ b/src/shortcuts/infinite.js @@ -4,6 +4,7 @@ var $ = window.jQuery var Waypoint = window.Waypoint + /* http://imakewebthings.com/waypoints/shortcuts/infinite-scroll */ function Infinite(options) { this.options = $.extend({}, Infinite.defaults, options) this.container = this.options.element diff --git a/src/shortcuts/inview.js b/src/shortcuts/inview.js index 4b7cd610..45d18c99 100644 --- a/src/shortcuts/inview.js +++ b/src/shortcuts/inview.js @@ -5,6 +5,7 @@ var Waypoint = window.Waypoint + /* http://imakewebthings.com/waypoints/shortcuts/inview */ function Inview(options) { this.options = Waypoint.Adapter.extend({}, Inview.defaults, options) this.axis = this.options.horizontal ? 'horizontal' : 'vertical' diff --git a/src/shortcuts/sticky.js b/src/shortcuts/sticky.js index 4e3bb083..17dfc2f2 100644 --- a/src/shortcuts/sticky.js +++ b/src/shortcuts/sticky.js @@ -4,6 +4,7 @@ var $ = window.jQuery var Waypoint = window.Waypoint + /* http://imakewebthings.com/waypoints/shortcuts/sticky-elements */ function Sticky(options) { this.options = $.extend({}, Waypoint.defaults, Sticky.defaults, options) this.element = this.options.element diff --git a/src/waypoint.js b/src/waypoint.js index 53896b6a..8405b69d 100644 --- a/src/waypoint.js +++ b/src/waypoint.js @@ -4,6 +4,7 @@ var keyCounter = 0 var allWaypoints = {} + /* http://imakewebthings.com/waypoints/api/waypoint */ function Waypoint(options) { if (!options) { throw new Error('No options passed to Waypoint constructor') @@ -54,6 +55,7 @@ } /* Public */ + /* http://imakewebthings.com/waypoints/api/destroy */ Waypoint.prototype.destroy = function() { this.context.remove(this) this.group.remove(this) @@ -61,12 +63,14 @@ } /* Public */ + /* http://imakewebthings.com/waypoints/api/disable */ Waypoint.prototype.disable = function() { this.enabled = false return this } /* Public */ + /* http://imakewebthings.com/waypoints/api/enable */ Waypoint.prototype.enable = function() { this.context.refresh() this.enabled = true @@ -74,16 +78,19 @@ } /* Public */ + /* http://imakewebthings.com/waypoints/api/next */ Waypoint.prototype.next = function() { return this.group.next(this) } /* Public */ + /* http://imakewebthings.com/waypoints/api/previous */ Waypoint.prototype.previous = function() { return this.group.previous(this) } /* Public */ + /* http://imakewebthings.com/waypoints/api/destroy-all */ Waypoint.destroyAll = function() { var allWaypointsArray = [] for (var waypointKey in allWaypoints) { @@ -95,16 +102,19 @@ } /* Public */ + /* http://imakewebthings.com/waypoints/api/refresh-all */ Waypoint.refreshAll = function() { Waypoint.Context.refreshAll() } /* Public */ + /* http://imakewebthings.com/waypoints/api/viewport-height */ Waypoint.viewportHeight = function() { return window.innerHeight || document.documentElement.clientHeight } /* Public */ + /* http://imakewebthings.com/waypoints/api/viewport-width */ Waypoint.viewportWidth = function() { return document.documentElement.clientWidth } From c04d36ea0a6d4393797241373a6488dd0f2a726a Mon Sep 17 00:00:00 2001 From: imakewebthings Date: Wed, 17 Dec 2014 15:28:59 -0800 Subject: [PATCH 45/98] Don't die if no old windowload --- lib/jquery.waypoints.js | 4 +++- lib/jquery.waypoints.min.js | 2 +- lib/noframework.waypoints.js | 4 +++- lib/noframework.waypoints.min.js | 2 +- lib/zepto.waypoints.js | 4 +++- lib/zepto.waypoints.min.js | 2 +- src/context.js | 4 +++- 7 files changed, 15 insertions(+), 7 deletions(-) diff --git a/lib/jquery.waypoints.js b/lib/jquery.waypoints.js index 067e1472..9e4fe8d2 100644 --- a/lib/jquery.waypoints.js +++ b/lib/jquery.waypoints.js @@ -428,7 +428,9 @@ https://github.com/imakewebthings/waypoints/blog/master/licenses.txt } window.onload = function() { - oldWindowLoad() + if (oldWindowOnLoad) { + oldWindowLoad() + } Context.refreshAll() } Waypoint.Context = Context diff --git a/lib/jquery.waypoints.min.js b/lib/jquery.waypoints.min.js index 97c9252a..8e9f8ee4 100644 --- a/lib/jquery.waypoints.min.js +++ b/lib/jquery.waypoints.min.js @@ -4,4 +4,4 @@ Copyright © 2011-2014 Caleb Troughton Licensed under the MIT license. https://github.com/imakewebthings/waypoints/blog/master/licenses.txt */ -!function(){"use strict";function t(o){if(!o)throw new Error("No options passed to Waypoint constructor");if(!o.element)throw new Error("No element option passed to Waypoint constructor");if(!o.handler)throw new Error("No handler option passed to Waypoint constructor");this.key="waypoint-"+e,this.options=t.Adapter.extend({},t.defaults,o),this.element=this.options.element,this.adapter=new t.Adapter(this.element),this.callback=o.handler,this.axis=this.options.horizontal?"horizontal":"vertical",this.enabled=this.options.enabled,this.triggerPoint=null,this.group=t.Group.findOrCreate({name:this.options.group,axis:this.axis}),this.context=t.Context.findOrCreateByElement(this.options.context),t.offsetAliases[this.options.offset]&&(this.options.offset=t.offsetAliases[this.options.offset]),this.group.add(this),this.context.add(this),i[this.key]=this,e+=1}var e=0,i={};t.prototype.queueTrigger=function(t){this.group.queueTrigger(this,t)},t.prototype.trigger=function(t){this.enabled&&this.callback&&this.callback.apply(this,t)},t.prototype.destroy=function(){this.context.remove(this),this.group.remove(this),delete i[this.key]},t.prototype.disable=function(){return this.enabled=!1,this},t.prototype.enable=function(){return this.context.refresh(),this.enabled=!0,this},t.prototype.next=function(){return this.group.next(this)},t.prototype.previous=function(){return this.group.previous(this)},t.destroyAll=function(){var t=[];for(var e in i)t.push(i[e]);for(var o=0,r=t.length;r>o;o++)t[o].destroy()},t.refreshAll=function(){t.Context.refreshAll()},t.viewportHeight=function(){return window.innerHeight||document.documentElement.clientHeight},t.viewportWidth=function(){return document.documentElement.clientWidth},t.adapters=[],t.defaults={context:window,continuous:!0,enabled:!0,group:"default",horizontal:!1,offset:0},t.offsetAliases={"bottom-in-view":function(){return this.context.innerHeight()-this.adapter.outerHeight()},"right-in-view":function(){return this.context.innerWidth()-this.adapter.outerWidth()}},window.Waypoint=t}(),function(){"use strict";function t(t){window.setTimeout(t,1e3/60)}function e(t){this.element=t,this.Adapter=r.Adapter,this.adapter=new this.Adapter(t),this.key="waypoint-context-"+i,this.didScroll=!1,this.didResize=!1,this.oldScroll={x:this.adapter.scrollLeft(),y:this.adapter.scrollTop()},this.waypoints={vertical:{},horizontal:{}},t.waypointContextKey=this.key,o[t.waypointContextKey]=this,i+=1,this.createThrottledScrollHandler(),this.createThrottledResizeHandler()}var i=0,o={},r=window.Waypoint,n=window.requestAnimationFrame||window.mozRequestAnimationFrame||window.webkitRequestAnimationFrame||t,s=window.onload;e.prototype.add=function(t){var e=t.options.horizontal?"horizontal":"vertical";this.waypoints[e][t.key]=t,this.refresh()},e.prototype.checkEmpty=function(){var t=this.Adapter.isEmptyObject(this.waypoints.horizontal),e=this.Adapter.isEmptyObject(this.waypoints.vertical);t&&e&&(this.adapter.off(".waypoints"),delete o[this.key])},e.prototype.createThrottledResizeHandler=function(){function t(){e.handleResize(),e.didResize=!1}var e=this;this.adapter.on("resize.waypoints",function(){e.didResize||(e.didResize=!0,n(t))})},e.prototype.createThrottledScrollHandler=function(){function t(){e.handleScroll(),e.didScroll=!1}var e=this;this.adapter.on("scroll.waypoints",function(){(!e.didScroll||r.isTouch)&&(e.didScroll=!0,n(t))})},e.prototype.handleResize=function(){r.Context.refreshAll()},e.prototype.handleScroll=function(){var t={},e={horizontal:{newScroll:this.adapter.scrollLeft(),oldScroll:this.oldScroll.x,forward:"right",backward:"left"},vertical:{newScroll:this.adapter.scrollTop(),oldScroll:this.oldScroll.y,forward:"down",backward:"up"}};for(var i in e){var o=e[i],r=o.newScroll>o.oldScroll,n=r?o.forward:o.backward;for(var s in this.waypoints[i]){var a=this.waypoints[i][s],l=o.oldScroll=a.triggerPoint,p=l&&h,u=!l&&!h;(p||u)&&(a.queueTrigger(n),t[a.group.id]=a.group)}}for(var c in t)t[c].flushTriggers();this.oldScroll={x:e.horizontal.newScroll,y:e.vertical.newScroll}},e.prototype.innerHeight=function(){return this.element===this.element.window?r.viewportHeight():this.adapter.innerHeight()},e.prototype.remove=function(t){delete this.waypoints[t.axis][t.key],this.checkEmpty()},e.prototype.innerWidth=function(){return this.element===this.element.window?r.viewportWidth():this.adapter.innerWidth()},e.prototype.destroy=function(){var t=[];for(var e in this.waypoints)for(var i in this.waypoints[e])t.push(this.waypoints[e][i]);for(var o=0,r=t.length;r>o;o++)t[o].destroy()},e.prototype.refresh=function(){var t,e=this.element===this.element.window,i=this.adapter.offset(),o={};this.handleScroll(),t={horizontal:{contextOffset:e?0:i.left,contextScroll:e?0:this.oldScroll.x,contextDimension:this.innerWidth(),oldScroll:this.oldScroll.x,forward:"right",backward:"left",offsetProp:"left"},vertical:{contextOffset:e?0:i.top,contextScroll:e?0:this.oldScroll.y,contextDimension:this.innerHeight(),oldScroll:this.oldScroll.y,forward:"down",backward:"up",offsetProp:"top"}};for(var r in t){var n=t[r];for(var s in this.waypoints[r]){var a,l,h,p,u,c=this.waypoints[r][s],d=c.options.offset,f=c.triggerPoint,w=0,y=null==f;c.element!==c.element.window&&(w=c.adapter.offset()[n.offsetProp]),"function"==typeof d?d=d.apply(c):"string"==typeof d&&(d=parseFloat(d),c.options.offset.indexOf("%")>-1&&(d=Math.ceil(n.contextDimension*d/100))),a=n.contextScroll-n.contextOffset,c.triggerPoint=w+a-d,l=f=n.oldScroll,p=l&&h,u=!l&&!h,!y&&p?(c.queueTrigger(n.backward),o[c.group.id]=c.group):!y&&u?(c.queueTrigger(n.forward),o[c.group.id]=c.group):y&&n.oldScroll>=c.triggerPoint&&(c.queueTrigger(n.forward),o[c.group.id]=c.group)}}for(var g in o)o[g].flushTriggers();return this},e.findOrCreateByElement=function(t){return e.findByElement(t)||new e(t)},e.refreshAll=function(){for(var t in o)o[t].refresh()},e.findByElement=function(t){return o[t.waypointContextKey]},window.onload=function(){s(),e.refreshAll()},r.Context=e}(),function(){"use strict";function t(t,e){return t.triggerPoint-e.triggerPoint}function e(t,e){return e.triggerPoint-t.triggerPoint}function i(t){this.name=t.name,this.axis=t.axis,this.id=this.name+"-"+this.axis,this.waypoints=[],this.clearTriggerQueues(),o[this.axis][this.name]=this}var o={vertical:{},horizontal:{}},r=window.Waypoint;i.prototype.add=function(t){this.waypoints.push(t)},i.prototype.clearTriggerQueues=function(){this.triggerQueues={up:[],down:[],left:[],right:[]}},i.prototype.flushTriggers=function(){for(var i in this.triggerQueues){var o=this.triggerQueues[i],r="up"===i||"left"===i;o.sort(r?e:t);for(var n=0,s=o.length;s>n;n+=1){var a=o[n];(a.options.continuous||n===o.length-1)&&a.trigger([i])}}this.clearTriggerQueues()},i.prototype.next=function(e){this.waypoints.sort(t);var i=r.Adapter.inArray(e,this.waypoints),o=i===this.waypoints.length-1;return o?null:this.waypoints[i+1]},i.prototype.previous=function(e){this.waypoints.sort(t);var i=r.Adapter.inArray(e,this.waypoints);return i?this.waypoints[i-1]:null},i.prototype.queueTrigger=function(t,e){this.triggerQueues[e].push(t)},i.prototype.remove=function(t){var e=r.Adapter.inArray(t,this.waypoints);e>-1&&this.waypoints.splice(e,1)},i.prototype.first=function(){return this.waypoints[0]},i.prototype.last=function(){return this.waypoints[this.waypoints.length-1]},i.findOrCreate=function(t){return o[t.axis][t.name]||new i(t)},r.Group=i}(),function(){"use strict";function t(t){this.$element=e(t)}var e=window.jQuery,i=window.Waypoint;e.each(["innerHeight","innerWidth","off","offset","on","outerHeight","outerWidth","scrollLeft","scrollTop"],function(e,i){t.prototype[i]=function(){var t=Array.prototype.slice.call(arguments);return this.$element[i].apply(this.$element,t)}}),e.each(["extend","inArray","isEmptyObject"],function(i,o){t[o]=e[o]}),i.adapters.push({name:"jquery",Adapter:t}),i.Adapter=t}(),function(){"use strict";function t(t){return function(){var i=[],o=arguments[0];return t.isFunction(arguments[0])&&(o=t.extend({},arguments[1]),o.handler=arguments[0]),this.each(function(){var r=t.extend({},o,{element:this});"string"==typeof r.context&&(r.context=t(this).closest(r.context)[0]),i.push(new e(r))}),i}}var e=window.Waypoint;window.jQuery&&(window.jQuery.fn.waypoint=t(window.jQuery)),window.Zepto&&(window.Zepto.fn.waypoint=t(window.Zepto))}(); \ No newline at end of file +!function(){"use strict";function t(o){if(!o)throw new Error("No options passed to Waypoint constructor");if(!o.element)throw new Error("No element option passed to Waypoint constructor");if(!o.handler)throw new Error("No handler option passed to Waypoint constructor");this.key="waypoint-"+e,this.options=t.Adapter.extend({},t.defaults,o),this.element=this.options.element,this.adapter=new t.Adapter(this.element),this.callback=o.handler,this.axis=this.options.horizontal?"horizontal":"vertical",this.enabled=this.options.enabled,this.triggerPoint=null,this.group=t.Group.findOrCreate({name:this.options.group,axis:this.axis}),this.context=t.Context.findOrCreateByElement(this.options.context),t.offsetAliases[this.options.offset]&&(this.options.offset=t.offsetAliases[this.options.offset]),this.group.add(this),this.context.add(this),i[this.key]=this,e+=1}var e=0,i={};t.prototype.queueTrigger=function(t){this.group.queueTrigger(this,t)},t.prototype.trigger=function(t){this.enabled&&this.callback&&this.callback.apply(this,t)},t.prototype.destroy=function(){this.context.remove(this),this.group.remove(this),delete i[this.key]},t.prototype.disable=function(){return this.enabled=!1,this},t.prototype.enable=function(){return this.context.refresh(),this.enabled=!0,this},t.prototype.next=function(){return this.group.next(this)},t.prototype.previous=function(){return this.group.previous(this)},t.destroyAll=function(){var t=[];for(var e in i)t.push(i[e]);for(var o=0,r=t.length;r>o;o++)t[o].destroy()},t.refreshAll=function(){t.Context.refreshAll()},t.viewportHeight=function(){return window.innerHeight||document.documentElement.clientHeight},t.viewportWidth=function(){return document.documentElement.clientWidth},t.adapters=[],t.defaults={context:window,continuous:!0,enabled:!0,group:"default",horizontal:!1,offset:0},t.offsetAliases={"bottom-in-view":function(){return this.context.innerHeight()-this.adapter.outerHeight()},"right-in-view":function(){return this.context.innerWidth()-this.adapter.outerWidth()}},window.Waypoint=t}(),function(){"use strict";function t(t){window.setTimeout(t,1e3/60)}function e(t){this.element=t,this.Adapter=r.Adapter,this.adapter=new this.Adapter(t),this.key="waypoint-context-"+i,this.didScroll=!1,this.didResize=!1,this.oldScroll={x:this.adapter.scrollLeft(),y:this.adapter.scrollTop()},this.waypoints={vertical:{},horizontal:{}},t.waypointContextKey=this.key,o[t.waypointContextKey]=this,i+=1,this.createThrottledScrollHandler(),this.createThrottledResizeHandler()}var i=0,o={},r=window.Waypoint,n=window.requestAnimationFrame||window.mozRequestAnimationFrame||window.webkitRequestAnimationFrame||t,s=window.onload;e.prototype.add=function(t){var e=t.options.horizontal?"horizontal":"vertical";this.waypoints[e][t.key]=t,this.refresh()},e.prototype.checkEmpty=function(){var t=this.Adapter.isEmptyObject(this.waypoints.horizontal),e=this.Adapter.isEmptyObject(this.waypoints.vertical);t&&e&&(this.adapter.off(".waypoints"),delete o[this.key])},e.prototype.createThrottledResizeHandler=function(){function t(){e.handleResize(),e.didResize=!1}var e=this;this.adapter.on("resize.waypoints",function(){e.didResize||(e.didResize=!0,n(t))})},e.prototype.createThrottledScrollHandler=function(){function t(){e.handleScroll(),e.didScroll=!1}var e=this;this.adapter.on("scroll.waypoints",function(){(!e.didScroll||r.isTouch)&&(e.didScroll=!0,n(t))})},e.prototype.handleResize=function(){r.Context.refreshAll()},e.prototype.handleScroll=function(){var t={},e={horizontal:{newScroll:this.adapter.scrollLeft(),oldScroll:this.oldScroll.x,forward:"right",backward:"left"},vertical:{newScroll:this.adapter.scrollTop(),oldScroll:this.oldScroll.y,forward:"down",backward:"up"}};for(var i in e){var o=e[i],r=o.newScroll>o.oldScroll,n=r?o.forward:o.backward;for(var s in this.waypoints[i]){var a=this.waypoints[i][s],l=o.oldScroll=a.triggerPoint,p=l&&h,u=!l&&!h;(p||u)&&(a.queueTrigger(n),t[a.group.id]=a.group)}}for(var c in t)t[c].flushTriggers();this.oldScroll={x:e.horizontal.newScroll,y:e.vertical.newScroll}},e.prototype.innerHeight=function(){return this.element===this.element.window?r.viewportHeight():this.adapter.innerHeight()},e.prototype.remove=function(t){delete this.waypoints[t.axis][t.key],this.checkEmpty()},e.prototype.innerWidth=function(){return this.element===this.element.window?r.viewportWidth():this.adapter.innerWidth()},e.prototype.destroy=function(){var t=[];for(var e in this.waypoints)for(var i in this.waypoints[e])t.push(this.waypoints[e][i]);for(var o=0,r=t.length;r>o;o++)t[o].destroy()},e.prototype.refresh=function(){var t,e=this.element===this.element.window,i=this.adapter.offset(),o={};this.handleScroll(),t={horizontal:{contextOffset:e?0:i.left,contextScroll:e?0:this.oldScroll.x,contextDimension:this.innerWidth(),oldScroll:this.oldScroll.x,forward:"right",backward:"left",offsetProp:"left"},vertical:{contextOffset:e?0:i.top,contextScroll:e?0:this.oldScroll.y,contextDimension:this.innerHeight(),oldScroll:this.oldScroll.y,forward:"down",backward:"up",offsetProp:"top"}};for(var r in t){var n=t[r];for(var s in this.waypoints[r]){var a,l,h,p,u,c=this.waypoints[r][s],d=c.options.offset,f=c.triggerPoint,w=0,y=null==f;c.element!==c.element.window&&(w=c.adapter.offset()[n.offsetProp]),"function"==typeof d?d=d.apply(c):"string"==typeof d&&(d=parseFloat(d),c.options.offset.indexOf("%")>-1&&(d=Math.ceil(n.contextDimension*d/100))),a=n.contextScroll-n.contextOffset,c.triggerPoint=w+a-d,l=f=n.oldScroll,p=l&&h,u=!l&&!h,!y&&p?(c.queueTrigger(n.backward),o[c.group.id]=c.group):!y&&u?(c.queueTrigger(n.forward),o[c.group.id]=c.group):y&&n.oldScroll>=c.triggerPoint&&(c.queueTrigger(n.forward),o[c.group.id]=c.group)}}for(var g in o)o[g].flushTriggers();return this},e.findOrCreateByElement=function(t){return e.findByElement(t)||new e(t)},e.refreshAll=function(){for(var t in o)o[t].refresh()},e.findByElement=function(t){return o[t.waypointContextKey]},window.onload=function(){oldWindowOnLoad&&s(),e.refreshAll()},r.Context=e}(),function(){"use strict";function t(t,e){return t.triggerPoint-e.triggerPoint}function e(t,e){return e.triggerPoint-t.triggerPoint}function i(t){this.name=t.name,this.axis=t.axis,this.id=this.name+"-"+this.axis,this.waypoints=[],this.clearTriggerQueues(),o[this.axis][this.name]=this}var o={vertical:{},horizontal:{}},r=window.Waypoint;i.prototype.add=function(t){this.waypoints.push(t)},i.prototype.clearTriggerQueues=function(){this.triggerQueues={up:[],down:[],left:[],right:[]}},i.prototype.flushTriggers=function(){for(var i in this.triggerQueues){var o=this.triggerQueues[i],r="up"===i||"left"===i;o.sort(r?e:t);for(var n=0,s=o.length;s>n;n+=1){var a=o[n];(a.options.continuous||n===o.length-1)&&a.trigger([i])}}this.clearTriggerQueues()},i.prototype.next=function(e){this.waypoints.sort(t);var i=r.Adapter.inArray(e,this.waypoints),o=i===this.waypoints.length-1;return o?null:this.waypoints[i+1]},i.prototype.previous=function(e){this.waypoints.sort(t);var i=r.Adapter.inArray(e,this.waypoints);return i?this.waypoints[i-1]:null},i.prototype.queueTrigger=function(t,e){this.triggerQueues[e].push(t)},i.prototype.remove=function(t){var e=r.Adapter.inArray(t,this.waypoints);e>-1&&this.waypoints.splice(e,1)},i.prototype.first=function(){return this.waypoints[0]},i.prototype.last=function(){return this.waypoints[this.waypoints.length-1]},i.findOrCreate=function(t){return o[t.axis][t.name]||new i(t)},r.Group=i}(),function(){"use strict";function t(t){this.$element=e(t)}var e=window.jQuery,i=window.Waypoint;e.each(["innerHeight","innerWidth","off","offset","on","outerHeight","outerWidth","scrollLeft","scrollTop"],function(e,i){t.prototype[i]=function(){var t=Array.prototype.slice.call(arguments);return this.$element[i].apply(this.$element,t)}}),e.each(["extend","inArray","isEmptyObject"],function(i,o){t[o]=e[o]}),i.adapters.push({name:"jquery",Adapter:t}),i.Adapter=t}(),function(){"use strict";function t(t){return function(){var i=[],o=arguments[0];return t.isFunction(arguments[0])&&(o=t.extend({},arguments[1]),o.handler=arguments[0]),this.each(function(){var r=t.extend({},o,{element:this});"string"==typeof r.context&&(r.context=t(this).closest(r.context)[0]),i.push(new e(r))}),i}}var e=window.Waypoint;window.jQuery&&(window.jQuery.fn.waypoint=t(window.jQuery)),window.Zepto&&(window.Zepto.fn.waypoint=t(window.Zepto))}(); \ No newline at end of file diff --git a/lib/noframework.waypoints.js b/lib/noframework.waypoints.js index 938d32aa..ed7f3e0e 100644 --- a/lib/noframework.waypoints.js +++ b/lib/noframework.waypoints.js @@ -428,7 +428,9 @@ https://github.com/imakewebthings/waypoints/blog/master/licenses.txt } window.onload = function() { - oldWindowLoad() + if (oldWindowOnLoad) { + oldWindowLoad() + } Context.refreshAll() } Waypoint.Context = Context diff --git a/lib/noframework.waypoints.min.js b/lib/noframework.waypoints.min.js index 7335d087..847319a5 100644 --- a/lib/noframework.waypoints.min.js +++ b/lib/noframework.waypoints.min.js @@ -4,4 +4,4 @@ Copyright © 2011-2014 Caleb Troughton Licensed under the MIT license. https://github.com/imakewebthings/waypoints/blog/master/licenses.txt */ -!function(){"use strict";function t(n){if(!n)throw new Error("No options passed to Waypoint constructor");if(!n.element)throw new Error("No element option passed to Waypoint constructor");if(!n.handler)throw new Error("No handler option passed to Waypoint constructor");this.key="waypoint-"+e,this.options=t.Adapter.extend({},t.defaults,n),this.element=this.options.element,this.adapter=new t.Adapter(this.element),this.callback=n.handler,this.axis=this.options.horizontal?"horizontal":"vertical",this.enabled=this.options.enabled,this.triggerPoint=null,this.group=t.Group.findOrCreate({name:this.options.group,axis:this.axis}),this.context=t.Context.findOrCreateByElement(this.options.context),t.offsetAliases[this.options.offset]&&(this.options.offset=t.offsetAliases[this.options.offset]),this.group.add(this),this.context.add(this),i[this.key]=this,e+=1}var e=0,i={};t.prototype.queueTrigger=function(t){this.group.queueTrigger(this,t)},t.prototype.trigger=function(t){this.enabled&&this.callback&&this.callback.apply(this,t)},t.prototype.destroy=function(){this.context.remove(this),this.group.remove(this),delete i[this.key]},t.prototype.disable=function(){return this.enabled=!1,this},t.prototype.enable=function(){return this.context.refresh(),this.enabled=!0,this},t.prototype.next=function(){return this.group.next(this)},t.prototype.previous=function(){return this.group.previous(this)},t.destroyAll=function(){var t=[];for(var e in i)t.push(i[e]);for(var n=0,o=t.length;o>n;n++)t[n].destroy()},t.refreshAll=function(){t.Context.refreshAll()},t.viewportHeight=function(){return window.innerHeight||document.documentElement.clientHeight},t.viewportWidth=function(){return document.documentElement.clientWidth},t.adapters=[],t.defaults={context:window,continuous:!0,enabled:!0,group:"default",horizontal:!1,offset:0},t.offsetAliases={"bottom-in-view":function(){return this.context.innerHeight()-this.adapter.outerHeight()},"right-in-view":function(){return this.context.innerWidth()-this.adapter.outerWidth()}},window.Waypoint=t}(),function(){"use strict";function t(t){window.setTimeout(t,1e3/60)}function e(t){this.element=t,this.Adapter=o.Adapter,this.adapter=new this.Adapter(t),this.key="waypoint-context-"+i,this.didScroll=!1,this.didResize=!1,this.oldScroll={x:this.adapter.scrollLeft(),y:this.adapter.scrollTop()},this.waypoints={vertical:{},horizontal:{}},t.waypointContextKey=this.key,n[t.waypointContextKey]=this,i+=1,this.createThrottledScrollHandler(),this.createThrottledResizeHandler()}var i=0,n={},o=window.Waypoint,r=window.requestAnimationFrame||window.mozRequestAnimationFrame||window.webkitRequestAnimationFrame||t,s=window.onload;e.prototype.add=function(t){var e=t.options.horizontal?"horizontal":"vertical";this.waypoints[e][t.key]=t,this.refresh()},e.prototype.checkEmpty=function(){var t=this.Adapter.isEmptyObject(this.waypoints.horizontal),e=this.Adapter.isEmptyObject(this.waypoints.vertical);t&&e&&(this.adapter.off(".waypoints"),delete n[this.key])},e.prototype.createThrottledResizeHandler=function(){function t(){e.handleResize(),e.didResize=!1}var e=this;this.adapter.on("resize.waypoints",function(){e.didResize||(e.didResize=!0,r(t))})},e.prototype.createThrottledScrollHandler=function(){function t(){e.handleScroll(),e.didScroll=!1}var e=this;this.adapter.on("scroll.waypoints",function(){(!e.didScroll||o.isTouch)&&(e.didScroll=!0,r(t))})},e.prototype.handleResize=function(){o.Context.refreshAll()},e.prototype.handleScroll=function(){var t={},e={horizontal:{newScroll:this.adapter.scrollLeft(),oldScroll:this.oldScroll.x,forward:"right",backward:"left"},vertical:{newScroll:this.adapter.scrollTop(),oldScroll:this.oldScroll.y,forward:"down",backward:"up"}};for(var i in e){var n=e[i],o=n.newScroll>n.oldScroll,r=o?n.forward:n.backward;for(var s in this.waypoints[i]){var a=this.waypoints[i][s],l=n.oldScroll=a.triggerPoint,p=l&&h,u=!l&&!h;(p||u)&&(a.queueTrigger(r),t[a.group.id]=a.group)}}for(var c in t)t[c].flushTriggers();this.oldScroll={x:e.horizontal.newScroll,y:e.vertical.newScroll}},e.prototype.innerHeight=function(){return this.element===this.element.window?o.viewportHeight():this.adapter.innerHeight()},e.prototype.remove=function(t){delete this.waypoints[t.axis][t.key],this.checkEmpty()},e.prototype.innerWidth=function(){return this.element===this.element.window?o.viewportWidth():this.adapter.innerWidth()},e.prototype.destroy=function(){var t=[];for(var e in this.waypoints)for(var i in this.waypoints[e])t.push(this.waypoints[e][i]);for(var n=0,o=t.length;o>n;n++)t[n].destroy()},e.prototype.refresh=function(){var t,e=this.element===this.element.window,i=this.adapter.offset(),n={};this.handleScroll(),t={horizontal:{contextOffset:e?0:i.left,contextScroll:e?0:this.oldScroll.x,contextDimension:this.innerWidth(),oldScroll:this.oldScroll.x,forward:"right",backward:"left",offsetProp:"left"},vertical:{contextOffset:e?0:i.top,contextScroll:e?0:this.oldScroll.y,contextDimension:this.innerHeight(),oldScroll:this.oldScroll.y,forward:"down",backward:"up",offsetProp:"top"}};for(var o in t){var r=t[o];for(var s in this.waypoints[o]){var a,l,h,p,u,c=this.waypoints[o][s],f=c.options.offset,d=c.triggerPoint,y=0,g=null==d;c.element!==c.element.window&&(y=c.adapter.offset()[r.offsetProp]),"function"==typeof f?f=f.apply(c):"string"==typeof f&&(f=parseFloat(f),c.options.offset.indexOf("%")>-1&&(f=Math.ceil(r.contextDimension*f/100))),a=r.contextScroll-r.contextOffset,c.triggerPoint=y+a-f,l=d=r.oldScroll,p=l&&h,u=!l&&!h,!g&&p?(c.queueTrigger(r.backward),n[c.group.id]=c.group):!g&&u?(c.queueTrigger(r.forward),n[c.group.id]=c.group):g&&r.oldScroll>=c.triggerPoint&&(c.queueTrigger(r.forward),n[c.group.id]=c.group)}}for(var w in n)n[w].flushTriggers();return this},e.findOrCreateByElement=function(t){return e.findByElement(t)||new e(t)},e.refreshAll=function(){for(var t in n)n[t].refresh()},e.findByElement=function(t){return n[t.waypointContextKey]},window.onload=function(){s(),e.refreshAll()},o.Context=e}(),function(){"use strict";function t(t,e){return t.triggerPoint-e.triggerPoint}function e(t,e){return e.triggerPoint-t.triggerPoint}function i(t){this.name=t.name,this.axis=t.axis,this.id=this.name+"-"+this.axis,this.waypoints=[],this.clearTriggerQueues(),n[this.axis][this.name]=this}var n={vertical:{},horizontal:{}},o=window.Waypoint;i.prototype.add=function(t){this.waypoints.push(t)},i.prototype.clearTriggerQueues=function(){this.triggerQueues={up:[],down:[],left:[],right:[]}},i.prototype.flushTriggers=function(){for(var i in this.triggerQueues){var n=this.triggerQueues[i],o="up"===i||"left"===i;n.sort(o?e:t);for(var r=0,s=n.length;s>r;r+=1){var a=n[r];(a.options.continuous||r===n.length-1)&&a.trigger([i])}}this.clearTriggerQueues()},i.prototype.next=function(e){this.waypoints.sort(t);var i=o.Adapter.inArray(e,this.waypoints),n=i===this.waypoints.length-1;return n?null:this.waypoints[i+1]},i.prototype.previous=function(e){this.waypoints.sort(t);var i=o.Adapter.inArray(e,this.waypoints);return i?this.waypoints[i-1]:null},i.prototype.queueTrigger=function(t,e){this.triggerQueues[e].push(t)},i.prototype.remove=function(t){var e=o.Adapter.inArray(t,this.waypoints);e>-1&&this.waypoints.splice(e,1)},i.prototype.first=function(){return this.waypoints[0]},i.prototype.last=function(){return this.waypoints[this.waypoints.length-1]},i.findOrCreate=function(t){return n[t.axis][t.name]||new i(t)},o.Group=i}(),function(){"use strict";function t(t){return t===t.window}function e(e){return t(e)?e:e.defaultView}function i(t){this.element=t,this.handlers={}}var n=window.Waypoint;i.prototype.innerHeight=function(){var e=t(this.element);return e?this.element.innerHeight:this.element.clientHeight},i.prototype.innerWidth=function(){var e=t(this.element);return e?this.element.innerWidth:this.element.clientWidth},i.prototype.off=function(t,e){function i(t,e,i){for(var n=0,o=e.length-1;o>n;n++){var r=e[n];i&&i!==r||t.removeEventListener(r)}}var n=t.split("."),o=n[0],r=n[1],s=this.element;if(r&&this.handlers[r]&&o)i(s,this.handlers[r][o],e),this.handlers[r][o]=[];else if(o)for(var a in this.handlers)i(s,this.handlers[a][o]||[],e),this.handlers[a][o]=[];else if(r&&this.handlers[r]){for(var l in this.handlers[r])i(s,this.handlers[r][l],e);this.handlers[r]={}}},i.prototype.offset=function(){if(!this.element.ownerDocument)return null;var t=this.element.ownerDocument.documentElement,i=e(this.element.ownerDocument),n={top:0,left:0};return this.element.getBoundingClientRect&&(n=this.element.getBoundingClientRect()),{top:n.top+i.pageYOffset-t.clientTop,left:n.left+i.pageXOffset-t.clientLeft}},i.prototype.on=function(t,e){var i=t.split("."),n=i[0],o=i[1]||"__default",r=this.handlers[o]=this.handlers[o]||{},s=r[n]=r[n]||[];s.push(e),this.element.addEventListener(n,e)},i.prototype.outerHeight=function(e){var i,n=this.innerHeight();return e&&!t(this.element)&&(i=window.getComputedStyle(this.element),n+=parseInt(i.marginTop,10),n+=parseInt(i.marginBottom,10)),n},i.prototype.outerWidth=function(e){var i,n=this.innerWidth();return e&&!t(this.element)&&(i=window.getComputedStyle(this.element),n+=parseInt(i.marginLeft,10),n+=parseInt(i.marginRight,10)),n},i.prototype.scrollLeft=function(){var t=e(this.element);return t?t.pageXOffset:this.element.scrollLeft},i.prototype.scrollTop=function(){var t=e(this.element);return t?t.pageYOffset:this.element.scrollTop},i.extend=function(){function t(t,e){if("object"==typeof t&&"object"==typeof e)for(var i in e)e.hasOwnProperty(i)&&(t[i]=e[i]);return t}for(var e=Array.prototype.slice.call(arguments),i=1,n=e.length;n>i;i++)t(e[0],e[i]);return e[0]},i.inArray=function(t,e,i){return null==e?-1:e.indexOf(t,i)},i.isEmptyObject=function(t){for(var e in t)return!1;return!0},n.adapters.push({name:"noframework",Adapter:i}),n.Adapter=i}(); \ No newline at end of file +!function(){"use strict";function t(n){if(!n)throw new Error("No options passed to Waypoint constructor");if(!n.element)throw new Error("No element option passed to Waypoint constructor");if(!n.handler)throw new Error("No handler option passed to Waypoint constructor");this.key="waypoint-"+e,this.options=t.Adapter.extend({},t.defaults,n),this.element=this.options.element,this.adapter=new t.Adapter(this.element),this.callback=n.handler,this.axis=this.options.horizontal?"horizontal":"vertical",this.enabled=this.options.enabled,this.triggerPoint=null,this.group=t.Group.findOrCreate({name:this.options.group,axis:this.axis}),this.context=t.Context.findOrCreateByElement(this.options.context),t.offsetAliases[this.options.offset]&&(this.options.offset=t.offsetAliases[this.options.offset]),this.group.add(this),this.context.add(this),i[this.key]=this,e+=1}var e=0,i={};t.prototype.queueTrigger=function(t){this.group.queueTrigger(this,t)},t.prototype.trigger=function(t){this.enabled&&this.callback&&this.callback.apply(this,t)},t.prototype.destroy=function(){this.context.remove(this),this.group.remove(this),delete i[this.key]},t.prototype.disable=function(){return this.enabled=!1,this},t.prototype.enable=function(){return this.context.refresh(),this.enabled=!0,this},t.prototype.next=function(){return this.group.next(this)},t.prototype.previous=function(){return this.group.previous(this)},t.destroyAll=function(){var t=[];for(var e in i)t.push(i[e]);for(var n=0,o=t.length;o>n;n++)t[n].destroy()},t.refreshAll=function(){t.Context.refreshAll()},t.viewportHeight=function(){return window.innerHeight||document.documentElement.clientHeight},t.viewportWidth=function(){return document.documentElement.clientWidth},t.adapters=[],t.defaults={context:window,continuous:!0,enabled:!0,group:"default",horizontal:!1,offset:0},t.offsetAliases={"bottom-in-view":function(){return this.context.innerHeight()-this.adapter.outerHeight()},"right-in-view":function(){return this.context.innerWidth()-this.adapter.outerWidth()}},window.Waypoint=t}(),function(){"use strict";function t(t){window.setTimeout(t,1e3/60)}function e(t){this.element=t,this.Adapter=o.Adapter,this.adapter=new this.Adapter(t),this.key="waypoint-context-"+i,this.didScroll=!1,this.didResize=!1,this.oldScroll={x:this.adapter.scrollLeft(),y:this.adapter.scrollTop()},this.waypoints={vertical:{},horizontal:{}},t.waypointContextKey=this.key,n[t.waypointContextKey]=this,i+=1,this.createThrottledScrollHandler(),this.createThrottledResizeHandler()}var i=0,n={},o=window.Waypoint,r=window.requestAnimationFrame||window.mozRequestAnimationFrame||window.webkitRequestAnimationFrame||t,s=window.onload;e.prototype.add=function(t){var e=t.options.horizontal?"horizontal":"vertical";this.waypoints[e][t.key]=t,this.refresh()},e.prototype.checkEmpty=function(){var t=this.Adapter.isEmptyObject(this.waypoints.horizontal),e=this.Adapter.isEmptyObject(this.waypoints.vertical);t&&e&&(this.adapter.off(".waypoints"),delete n[this.key])},e.prototype.createThrottledResizeHandler=function(){function t(){e.handleResize(),e.didResize=!1}var e=this;this.adapter.on("resize.waypoints",function(){e.didResize||(e.didResize=!0,r(t))})},e.prototype.createThrottledScrollHandler=function(){function t(){e.handleScroll(),e.didScroll=!1}var e=this;this.adapter.on("scroll.waypoints",function(){(!e.didScroll||o.isTouch)&&(e.didScroll=!0,r(t))})},e.prototype.handleResize=function(){o.Context.refreshAll()},e.prototype.handleScroll=function(){var t={},e={horizontal:{newScroll:this.adapter.scrollLeft(),oldScroll:this.oldScroll.x,forward:"right",backward:"left"},vertical:{newScroll:this.adapter.scrollTop(),oldScroll:this.oldScroll.y,forward:"down",backward:"up"}};for(var i in e){var n=e[i],o=n.newScroll>n.oldScroll,r=o?n.forward:n.backward;for(var s in this.waypoints[i]){var a=this.waypoints[i][s],l=n.oldScroll=a.triggerPoint,p=l&&h,u=!l&&!h;(p||u)&&(a.queueTrigger(r),t[a.group.id]=a.group)}}for(var c in t)t[c].flushTriggers();this.oldScroll={x:e.horizontal.newScroll,y:e.vertical.newScroll}},e.prototype.innerHeight=function(){return this.element===this.element.window?o.viewportHeight():this.adapter.innerHeight()},e.prototype.remove=function(t){delete this.waypoints[t.axis][t.key],this.checkEmpty()},e.prototype.innerWidth=function(){return this.element===this.element.window?o.viewportWidth():this.adapter.innerWidth()},e.prototype.destroy=function(){var t=[];for(var e in this.waypoints)for(var i in this.waypoints[e])t.push(this.waypoints[e][i]);for(var n=0,o=t.length;o>n;n++)t[n].destroy()},e.prototype.refresh=function(){var t,e=this.element===this.element.window,i=this.adapter.offset(),n={};this.handleScroll(),t={horizontal:{contextOffset:e?0:i.left,contextScroll:e?0:this.oldScroll.x,contextDimension:this.innerWidth(),oldScroll:this.oldScroll.x,forward:"right",backward:"left",offsetProp:"left"},vertical:{contextOffset:e?0:i.top,contextScroll:e?0:this.oldScroll.y,contextDimension:this.innerHeight(),oldScroll:this.oldScroll.y,forward:"down",backward:"up",offsetProp:"top"}};for(var o in t){var r=t[o];for(var s in this.waypoints[o]){var a,l,h,p,u,c=this.waypoints[o][s],d=c.options.offset,f=c.triggerPoint,y=0,g=null==f;c.element!==c.element.window&&(y=c.adapter.offset()[r.offsetProp]),"function"==typeof d?d=d.apply(c):"string"==typeof d&&(d=parseFloat(d),c.options.offset.indexOf("%")>-1&&(d=Math.ceil(r.contextDimension*d/100))),a=r.contextScroll-r.contextOffset,c.triggerPoint=y+a-d,l=f=r.oldScroll,p=l&&h,u=!l&&!h,!g&&p?(c.queueTrigger(r.backward),n[c.group.id]=c.group):!g&&u?(c.queueTrigger(r.forward),n[c.group.id]=c.group):g&&r.oldScroll>=c.triggerPoint&&(c.queueTrigger(r.forward),n[c.group.id]=c.group)}}for(var w in n)n[w].flushTriggers();return this},e.findOrCreateByElement=function(t){return e.findByElement(t)||new e(t)},e.refreshAll=function(){for(var t in n)n[t].refresh()},e.findByElement=function(t){return n[t.waypointContextKey]},window.onload=function(){oldWindowOnLoad&&s(),e.refreshAll()},o.Context=e}(),function(){"use strict";function t(t,e){return t.triggerPoint-e.triggerPoint}function e(t,e){return e.triggerPoint-t.triggerPoint}function i(t){this.name=t.name,this.axis=t.axis,this.id=this.name+"-"+this.axis,this.waypoints=[],this.clearTriggerQueues(),n[this.axis][this.name]=this}var n={vertical:{},horizontal:{}},o=window.Waypoint;i.prototype.add=function(t){this.waypoints.push(t)},i.prototype.clearTriggerQueues=function(){this.triggerQueues={up:[],down:[],left:[],right:[]}},i.prototype.flushTriggers=function(){for(var i in this.triggerQueues){var n=this.triggerQueues[i],o="up"===i||"left"===i;n.sort(o?e:t);for(var r=0,s=n.length;s>r;r+=1){var a=n[r];(a.options.continuous||r===n.length-1)&&a.trigger([i])}}this.clearTriggerQueues()},i.prototype.next=function(e){this.waypoints.sort(t);var i=o.Adapter.inArray(e,this.waypoints),n=i===this.waypoints.length-1;return n?null:this.waypoints[i+1]},i.prototype.previous=function(e){this.waypoints.sort(t);var i=o.Adapter.inArray(e,this.waypoints);return i?this.waypoints[i-1]:null},i.prototype.queueTrigger=function(t,e){this.triggerQueues[e].push(t)},i.prototype.remove=function(t){var e=o.Adapter.inArray(t,this.waypoints);e>-1&&this.waypoints.splice(e,1)},i.prototype.first=function(){return this.waypoints[0]},i.prototype.last=function(){return this.waypoints[this.waypoints.length-1]},i.findOrCreate=function(t){return n[t.axis][t.name]||new i(t)},o.Group=i}(),function(){"use strict";function t(t){return t===t.window}function e(e){return t(e)?e:e.defaultView}function i(t){this.element=t,this.handlers={}}var n=window.Waypoint;i.prototype.innerHeight=function(){var e=t(this.element);return e?this.element.innerHeight:this.element.clientHeight},i.prototype.innerWidth=function(){var e=t(this.element);return e?this.element.innerWidth:this.element.clientWidth},i.prototype.off=function(t,e){function i(t,e,i){for(var n=0,o=e.length-1;o>n;n++){var r=e[n];i&&i!==r||t.removeEventListener(r)}}var n=t.split("."),o=n[0],r=n[1],s=this.element;if(r&&this.handlers[r]&&o)i(s,this.handlers[r][o],e),this.handlers[r][o]=[];else if(o)for(var a in this.handlers)i(s,this.handlers[a][o]||[],e),this.handlers[a][o]=[];else if(r&&this.handlers[r]){for(var l in this.handlers[r])i(s,this.handlers[r][l],e);this.handlers[r]={}}},i.prototype.offset=function(){if(!this.element.ownerDocument)return null;var t=this.element.ownerDocument.documentElement,i=e(this.element.ownerDocument),n={top:0,left:0};return this.element.getBoundingClientRect&&(n=this.element.getBoundingClientRect()),{top:n.top+i.pageYOffset-t.clientTop,left:n.left+i.pageXOffset-t.clientLeft}},i.prototype.on=function(t,e){var i=t.split("."),n=i[0],o=i[1]||"__default",r=this.handlers[o]=this.handlers[o]||{},s=r[n]=r[n]||[];s.push(e),this.element.addEventListener(n,e)},i.prototype.outerHeight=function(e){var i,n=this.innerHeight();return e&&!t(this.element)&&(i=window.getComputedStyle(this.element),n+=parseInt(i.marginTop,10),n+=parseInt(i.marginBottom,10)),n},i.prototype.outerWidth=function(e){var i,n=this.innerWidth();return e&&!t(this.element)&&(i=window.getComputedStyle(this.element),n+=parseInt(i.marginLeft,10),n+=parseInt(i.marginRight,10)),n},i.prototype.scrollLeft=function(){var t=e(this.element);return t?t.pageXOffset:this.element.scrollLeft},i.prototype.scrollTop=function(){var t=e(this.element);return t?t.pageYOffset:this.element.scrollTop},i.extend=function(){function t(t,e){if("object"==typeof t&&"object"==typeof e)for(var i in e)e.hasOwnProperty(i)&&(t[i]=e[i]);return t}for(var e=Array.prototype.slice.call(arguments),i=1,n=e.length;n>i;i++)t(e[0],e[i]);return e[0]},i.inArray=function(t,e,i){return null==e?-1:e.indexOf(t,i)},i.isEmptyObject=function(t){for(var e in t)return!1;return!0},n.adapters.push({name:"noframework",Adapter:i}),n.Adapter=i}(); \ No newline at end of file diff --git a/lib/zepto.waypoints.js b/lib/zepto.waypoints.js index c399da9f..5213f2cc 100644 --- a/lib/zepto.waypoints.js +++ b/lib/zepto.waypoints.js @@ -428,7 +428,9 @@ https://github.com/imakewebthings/waypoints/blog/master/licenses.txt } window.onload = function() { - oldWindowLoad() + if (oldWindowOnLoad) { + oldWindowLoad() + } Context.refreshAll() } Waypoint.Context = Context diff --git a/lib/zepto.waypoints.min.js b/lib/zepto.waypoints.min.js index b5c4f81c..4f6e3ce1 100644 --- a/lib/zepto.waypoints.min.js +++ b/lib/zepto.waypoints.min.js @@ -4,4 +4,4 @@ Copyright © 2011-2014 Caleb Troughton Licensed under the MIT license. https://github.com/imakewebthings/waypoints/blog/master/licenses.txt */ -!function(){"use strict";function t(i){if(!i)throw new Error("No options passed to Waypoint constructor");if(!i.element)throw new Error("No element option passed to Waypoint constructor");if(!i.handler)throw new Error("No handler option passed to Waypoint constructor");this.key="waypoint-"+e,this.options=t.Adapter.extend({},t.defaults,i),this.element=this.options.element,this.adapter=new t.Adapter(this.element),this.callback=i.handler,this.axis=this.options.horizontal?"horizontal":"vertical",this.enabled=this.options.enabled,this.triggerPoint=null,this.group=t.Group.findOrCreate({name:this.options.group,axis:this.axis}),this.context=t.Context.findOrCreateByElement(this.options.context),t.offsetAliases[this.options.offset]&&(this.options.offset=t.offsetAliases[this.options.offset]),this.group.add(this),this.context.add(this),o[this.key]=this,e+=1}var e=0,o={};t.prototype.queueTrigger=function(t){this.group.queueTrigger(this,t)},t.prototype.trigger=function(t){this.enabled&&this.callback&&this.callback.apply(this,t)},t.prototype.destroy=function(){this.context.remove(this),this.group.remove(this),delete o[this.key]},t.prototype.disable=function(){return this.enabled=!1,this},t.prototype.enable=function(){return this.context.refresh(),this.enabled=!0,this},t.prototype.next=function(){return this.group.next(this)},t.prototype.previous=function(){return this.group.previous(this)},t.destroyAll=function(){var t=[];for(var e in o)t.push(o[e]);for(var i=0,n=t.length;n>i;i++)t[i].destroy()},t.refreshAll=function(){t.Context.refreshAll()},t.viewportHeight=function(){return window.innerHeight||document.documentElement.clientHeight},t.viewportWidth=function(){return document.documentElement.clientWidth},t.adapters=[],t.defaults={context:window,continuous:!0,enabled:!0,group:"default",horizontal:!1,offset:0},t.offsetAliases={"bottom-in-view":function(){return this.context.innerHeight()-this.adapter.outerHeight()},"right-in-view":function(){return this.context.innerWidth()-this.adapter.outerWidth()}},window.Waypoint=t}(),function(){"use strict";function t(t){window.setTimeout(t,1e3/60)}function e(t){this.element=t,this.Adapter=n.Adapter,this.adapter=new this.Adapter(t),this.key="waypoint-context-"+o,this.didScroll=!1,this.didResize=!1,this.oldScroll={x:this.adapter.scrollLeft(),y:this.adapter.scrollTop()},this.waypoints={vertical:{},horizontal:{}},t.waypointContextKey=this.key,i[t.waypointContextKey]=this,o+=1,this.createThrottledScrollHandler(),this.createThrottledResizeHandler()}var o=0,i={},n=window.Waypoint,r=window.requestAnimationFrame||window.mozRequestAnimationFrame||window.webkitRequestAnimationFrame||t,s=window.onload;e.prototype.add=function(t){var e=t.options.horizontal?"horizontal":"vertical";this.waypoints[e][t.key]=t,this.refresh()},e.prototype.checkEmpty=function(){var t=this.Adapter.isEmptyObject(this.waypoints.horizontal),e=this.Adapter.isEmptyObject(this.waypoints.vertical);t&&e&&(this.adapter.off(".waypoints"),delete i[this.key])},e.prototype.createThrottledResizeHandler=function(){function t(){e.handleResize(),e.didResize=!1}var e=this;this.adapter.on("resize.waypoints",function(){e.didResize||(e.didResize=!0,r(t))})},e.prototype.createThrottledScrollHandler=function(){function t(){e.handleScroll(),e.didScroll=!1}var e=this;this.adapter.on("scroll.waypoints",function(){(!e.didScroll||n.isTouch)&&(e.didScroll=!0,r(t))})},e.prototype.handleResize=function(){n.Context.refreshAll()},e.prototype.handleScroll=function(){var t={},e={horizontal:{newScroll:this.adapter.scrollLeft(),oldScroll:this.oldScroll.x,forward:"right",backward:"left"},vertical:{newScroll:this.adapter.scrollTop(),oldScroll:this.oldScroll.y,forward:"down",backward:"up"}};for(var o in e){var i=e[o],n=i.newScroll>i.oldScroll,r=n?i.forward:i.backward;for(var s in this.waypoints[o]){var a=this.waypoints[o][s],l=i.oldScroll=a.triggerPoint,p=l&&h,c=!l&&!h;(p||c)&&(a.queueTrigger(r),t[a.group.id]=a.group)}}for(var u in t)t[u].flushTriggers();this.oldScroll={x:e.horizontal.newScroll,y:e.vertical.newScroll}},e.prototype.innerHeight=function(){return this.element===this.element.window?n.viewportHeight():this.adapter.innerHeight()},e.prototype.remove=function(t){delete this.waypoints[t.axis][t.key],this.checkEmpty()},e.prototype.innerWidth=function(){return this.element===this.element.window?n.viewportWidth():this.adapter.innerWidth()},e.prototype.destroy=function(){var t=[];for(var e in this.waypoints)for(var o in this.waypoints[e])t.push(this.waypoints[e][o]);for(var i=0,n=t.length;n>i;i++)t[i].destroy()},e.prototype.refresh=function(){var t,e=this.element===this.element.window,o=this.adapter.offset(),i={};this.handleScroll(),t={horizontal:{contextOffset:e?0:o.left,contextScroll:e?0:this.oldScroll.x,contextDimension:this.innerWidth(),oldScroll:this.oldScroll.x,forward:"right",backward:"left",offsetProp:"left"},vertical:{contextOffset:e?0:o.top,contextScroll:e?0:this.oldScroll.y,contextDimension:this.innerHeight(),oldScroll:this.oldScroll.y,forward:"down",backward:"up",offsetProp:"top"}};for(var n in t){var r=t[n];for(var s in this.waypoints[n]){var a,l,h,p,c,u=this.waypoints[n][s],d=u.options.offset,f=u.triggerPoint,w=0,y=null==f;u.element!==u.element.window&&(w=u.adapter.offset()[r.offsetProp]),"function"==typeof d?d=d.apply(u):"string"==typeof d&&(d=parseFloat(d),u.options.offset.indexOf("%")>-1&&(d=Math.ceil(r.contextDimension*d/100))),a=r.contextScroll-r.contextOffset,u.triggerPoint=w+a-d,l=f=r.oldScroll,p=l&&h,c=!l&&!h,!y&&p?(u.queueTrigger(r.backward),i[u.group.id]=u.group):!y&&c?(u.queueTrigger(r.forward),i[u.group.id]=u.group):y&&r.oldScroll>=u.triggerPoint&&(u.queueTrigger(r.forward),i[u.group.id]=u.group)}}for(var g in i)i[g].flushTriggers();return this},e.findOrCreateByElement=function(t){return e.findByElement(t)||new e(t)},e.refreshAll=function(){for(var t in i)i[t].refresh()},e.findByElement=function(t){return i[t.waypointContextKey]},window.onload=function(){s(),e.refreshAll()},n.Context=e}(),function(){"use strict";function t(t,e){return t.triggerPoint-e.triggerPoint}function e(t,e){return e.triggerPoint-t.triggerPoint}function o(t){this.name=t.name,this.axis=t.axis,this.id=this.name+"-"+this.axis,this.waypoints=[],this.clearTriggerQueues(),i[this.axis][this.name]=this}var i={vertical:{},horizontal:{}},n=window.Waypoint;o.prototype.add=function(t){this.waypoints.push(t)},o.prototype.clearTriggerQueues=function(){this.triggerQueues={up:[],down:[],left:[],right:[]}},o.prototype.flushTriggers=function(){for(var o in this.triggerQueues){var i=this.triggerQueues[o],n="up"===o||"left"===o;i.sort(n?e:t);for(var r=0,s=i.length;s>r;r+=1){var a=i[r];(a.options.continuous||r===i.length-1)&&a.trigger([o])}}this.clearTriggerQueues()},o.prototype.next=function(e){this.waypoints.sort(t);var o=n.Adapter.inArray(e,this.waypoints),i=o===this.waypoints.length-1;return i?null:this.waypoints[o+1]},o.prototype.previous=function(e){this.waypoints.sort(t);var o=n.Adapter.inArray(e,this.waypoints);return o?this.waypoints[o-1]:null},o.prototype.queueTrigger=function(t,e){this.triggerQueues[e].push(t)},o.prototype.remove=function(t){var e=n.Adapter.inArray(t,this.waypoints);e>-1&&this.waypoints.splice(e,1)},o.prototype.first=function(){return this.waypoints[0]},o.prototype.last=function(){return this.waypoints[this.waypoints.length-1]},o.findOrCreate=function(t){return i[t.axis][t.name]||new o(t)},n.Group=o}(),function(){"use strict";function t(t){this.element=t,this.$element=e(t)}var e=window.Zepto,o=window.Waypoint;e.each(["off","on","scrollLeft","scrollTop"],function(e,o){t.prototype[o]=function(){var t=Array.prototype.slice.call(arguments);return this.$element[o].apply(this.$element,t)}}),t.prototype.offset=function(){return this.element!==this.element.window?this.$element.offset():void 0},e.each(["width","height"],function(o,i){function n(t,o){return function(t){var n=this.$element,r=n[i](),s={width:["left","right"],height:["top","bottom"]};return e.each(s[i],function(e,i){r+=parseInt(n.css("padding-"+i),10),o&&(r+=parseInt(n.css("border-"+i+"-width"),10)),t&&(r+=parseInt(n.css("margin-"+i),10))}),r}}var r=e.camelCase("inner-"+i),s=e.camelCase("outer-"+i);t.prototype[r]=n(!1),t.prototype[s]=n(!0)}),e.each(["extend","inArray"],function(o,i){t[i]=e[i]}),t.isEmptyObject=function(t){for(var e in t)return!1;return!0},o.adapters.push({name:"zepto",Adapter:t}),o.Adapter=t}(),function(){"use strict";function t(t){return function(){var o=[],i=arguments[0];return t.isFunction(arguments[0])&&(i=t.extend({},arguments[1]),i.handler=arguments[0]),this.each(function(){var n=t.extend({},i,{element:this});"string"==typeof n.context&&(n.context=t(this).closest(n.context)[0]),o.push(new e(n))}),o}}var e=window.Waypoint;window.jQuery&&(window.jQuery.fn.waypoint=t(window.jQuery)),window.Zepto&&(window.Zepto.fn.waypoint=t(window.Zepto))}(); \ No newline at end of file +!function(){"use strict";function t(i){if(!i)throw new Error("No options passed to Waypoint constructor");if(!i.element)throw new Error("No element option passed to Waypoint constructor");if(!i.handler)throw new Error("No handler option passed to Waypoint constructor");this.key="waypoint-"+e,this.options=t.Adapter.extend({},t.defaults,i),this.element=this.options.element,this.adapter=new t.Adapter(this.element),this.callback=i.handler,this.axis=this.options.horizontal?"horizontal":"vertical",this.enabled=this.options.enabled,this.triggerPoint=null,this.group=t.Group.findOrCreate({name:this.options.group,axis:this.axis}),this.context=t.Context.findOrCreateByElement(this.options.context),t.offsetAliases[this.options.offset]&&(this.options.offset=t.offsetAliases[this.options.offset]),this.group.add(this),this.context.add(this),o[this.key]=this,e+=1}var e=0,o={};t.prototype.queueTrigger=function(t){this.group.queueTrigger(this,t)},t.prototype.trigger=function(t){this.enabled&&this.callback&&this.callback.apply(this,t)},t.prototype.destroy=function(){this.context.remove(this),this.group.remove(this),delete o[this.key]},t.prototype.disable=function(){return this.enabled=!1,this},t.prototype.enable=function(){return this.context.refresh(),this.enabled=!0,this},t.prototype.next=function(){return this.group.next(this)},t.prototype.previous=function(){return this.group.previous(this)},t.destroyAll=function(){var t=[];for(var e in o)t.push(o[e]);for(var i=0,n=t.length;n>i;i++)t[i].destroy()},t.refreshAll=function(){t.Context.refreshAll()},t.viewportHeight=function(){return window.innerHeight||document.documentElement.clientHeight},t.viewportWidth=function(){return document.documentElement.clientWidth},t.adapters=[],t.defaults={context:window,continuous:!0,enabled:!0,group:"default",horizontal:!1,offset:0},t.offsetAliases={"bottom-in-view":function(){return this.context.innerHeight()-this.adapter.outerHeight()},"right-in-view":function(){return this.context.innerWidth()-this.adapter.outerWidth()}},window.Waypoint=t}(),function(){"use strict";function t(t){window.setTimeout(t,1e3/60)}function e(t){this.element=t,this.Adapter=n.Adapter,this.adapter=new this.Adapter(t),this.key="waypoint-context-"+o,this.didScroll=!1,this.didResize=!1,this.oldScroll={x:this.adapter.scrollLeft(),y:this.adapter.scrollTop()},this.waypoints={vertical:{},horizontal:{}},t.waypointContextKey=this.key,i[t.waypointContextKey]=this,o+=1,this.createThrottledScrollHandler(),this.createThrottledResizeHandler()}var o=0,i={},n=window.Waypoint,r=window.requestAnimationFrame||window.mozRequestAnimationFrame||window.webkitRequestAnimationFrame||t,s=window.onload;e.prototype.add=function(t){var e=t.options.horizontal?"horizontal":"vertical";this.waypoints[e][t.key]=t,this.refresh()},e.prototype.checkEmpty=function(){var t=this.Adapter.isEmptyObject(this.waypoints.horizontal),e=this.Adapter.isEmptyObject(this.waypoints.vertical);t&&e&&(this.adapter.off(".waypoints"),delete i[this.key])},e.prototype.createThrottledResizeHandler=function(){function t(){e.handleResize(),e.didResize=!1}var e=this;this.adapter.on("resize.waypoints",function(){e.didResize||(e.didResize=!0,r(t))})},e.prototype.createThrottledScrollHandler=function(){function t(){e.handleScroll(),e.didScroll=!1}var e=this;this.adapter.on("scroll.waypoints",function(){(!e.didScroll||n.isTouch)&&(e.didScroll=!0,r(t))})},e.prototype.handleResize=function(){n.Context.refreshAll()},e.prototype.handleScroll=function(){var t={},e={horizontal:{newScroll:this.adapter.scrollLeft(),oldScroll:this.oldScroll.x,forward:"right",backward:"left"},vertical:{newScroll:this.adapter.scrollTop(),oldScroll:this.oldScroll.y,forward:"down",backward:"up"}};for(var o in e){var i=e[o],n=i.newScroll>i.oldScroll,r=n?i.forward:i.backward;for(var s in this.waypoints[o]){var a=this.waypoints[o][s],l=i.oldScroll=a.triggerPoint,p=l&&h,c=!l&&!h;(p||c)&&(a.queueTrigger(r),t[a.group.id]=a.group)}}for(var u in t)t[u].flushTriggers();this.oldScroll={x:e.horizontal.newScroll,y:e.vertical.newScroll}},e.prototype.innerHeight=function(){return this.element===this.element.window?n.viewportHeight():this.adapter.innerHeight()},e.prototype.remove=function(t){delete this.waypoints[t.axis][t.key],this.checkEmpty()},e.prototype.innerWidth=function(){return this.element===this.element.window?n.viewportWidth():this.adapter.innerWidth()},e.prototype.destroy=function(){var t=[];for(var e in this.waypoints)for(var o in this.waypoints[e])t.push(this.waypoints[e][o]);for(var i=0,n=t.length;n>i;i++)t[i].destroy()},e.prototype.refresh=function(){var t,e=this.element===this.element.window,o=this.adapter.offset(),i={};this.handleScroll(),t={horizontal:{contextOffset:e?0:o.left,contextScroll:e?0:this.oldScroll.x,contextDimension:this.innerWidth(),oldScroll:this.oldScroll.x,forward:"right",backward:"left",offsetProp:"left"},vertical:{contextOffset:e?0:o.top,contextScroll:e?0:this.oldScroll.y,contextDimension:this.innerHeight(),oldScroll:this.oldScroll.y,forward:"down",backward:"up",offsetProp:"top"}};for(var n in t){var r=t[n];for(var s in this.waypoints[n]){var a,l,h,p,c,u=this.waypoints[n][s],d=u.options.offset,f=u.triggerPoint,w=0,y=null==f;u.element!==u.element.window&&(w=u.adapter.offset()[r.offsetProp]),"function"==typeof d?d=d.apply(u):"string"==typeof d&&(d=parseFloat(d),u.options.offset.indexOf("%")>-1&&(d=Math.ceil(r.contextDimension*d/100))),a=r.contextScroll-r.contextOffset,u.triggerPoint=w+a-d,l=f=r.oldScroll,p=l&&h,c=!l&&!h,!y&&p?(u.queueTrigger(r.backward),i[u.group.id]=u.group):!y&&c?(u.queueTrigger(r.forward),i[u.group.id]=u.group):y&&r.oldScroll>=u.triggerPoint&&(u.queueTrigger(r.forward),i[u.group.id]=u.group)}}for(var g in i)i[g].flushTriggers();return this},e.findOrCreateByElement=function(t){return e.findByElement(t)||new e(t)},e.refreshAll=function(){for(var t in i)i[t].refresh()},e.findByElement=function(t){return i[t.waypointContextKey]},window.onload=function(){oldWindowOnLoad&&s(),e.refreshAll()},n.Context=e}(),function(){"use strict";function t(t,e){return t.triggerPoint-e.triggerPoint}function e(t,e){return e.triggerPoint-t.triggerPoint}function o(t){this.name=t.name,this.axis=t.axis,this.id=this.name+"-"+this.axis,this.waypoints=[],this.clearTriggerQueues(),i[this.axis][this.name]=this}var i={vertical:{},horizontal:{}},n=window.Waypoint;o.prototype.add=function(t){this.waypoints.push(t)},o.prototype.clearTriggerQueues=function(){this.triggerQueues={up:[],down:[],left:[],right:[]}},o.prototype.flushTriggers=function(){for(var o in this.triggerQueues){var i=this.triggerQueues[o],n="up"===o||"left"===o;i.sort(n?e:t);for(var r=0,s=i.length;s>r;r+=1){var a=i[r];(a.options.continuous||r===i.length-1)&&a.trigger([o])}}this.clearTriggerQueues()},o.prototype.next=function(e){this.waypoints.sort(t);var o=n.Adapter.inArray(e,this.waypoints),i=o===this.waypoints.length-1;return i?null:this.waypoints[o+1]},o.prototype.previous=function(e){this.waypoints.sort(t);var o=n.Adapter.inArray(e,this.waypoints);return o?this.waypoints[o-1]:null},o.prototype.queueTrigger=function(t,e){this.triggerQueues[e].push(t)},o.prototype.remove=function(t){var e=n.Adapter.inArray(t,this.waypoints);e>-1&&this.waypoints.splice(e,1)},o.prototype.first=function(){return this.waypoints[0]},o.prototype.last=function(){return this.waypoints[this.waypoints.length-1]},o.findOrCreate=function(t){return i[t.axis][t.name]||new o(t)},n.Group=o}(),function(){"use strict";function t(t){this.element=t,this.$element=e(t)}var e=window.Zepto,o=window.Waypoint;e.each(["off","on","scrollLeft","scrollTop"],function(e,o){t.prototype[o]=function(){var t=Array.prototype.slice.call(arguments);return this.$element[o].apply(this.$element,t)}}),t.prototype.offset=function(){return this.element!==this.element.window?this.$element.offset():void 0},e.each(["width","height"],function(o,i){function n(t,o){return function(t){var n=this.$element,r=n[i](),s={width:["left","right"],height:["top","bottom"]};return e.each(s[i],function(e,i){r+=parseInt(n.css("padding-"+i),10),o&&(r+=parseInt(n.css("border-"+i+"-width"),10)),t&&(r+=parseInt(n.css("margin-"+i),10))}),r}}var r=e.camelCase("inner-"+i),s=e.camelCase("outer-"+i);t.prototype[r]=n(!1),t.prototype[s]=n(!0)}),e.each(["extend","inArray"],function(o,i){t[i]=e[i]}),t.isEmptyObject=function(t){for(var e in t)return!1;return!0},o.adapters.push({name:"zepto",Adapter:t}),o.Adapter=t}(),function(){"use strict";function t(t){return function(){var o=[],i=arguments[0];return t.isFunction(arguments[0])&&(i=t.extend({},arguments[1]),i.handler=arguments[0]),this.each(function(){var n=t.extend({},i,{element:this});"string"==typeof n.context&&(n.context=t(this).closest(n.context)[0]),o.push(new e(n))}),o}}var e=window.Waypoint;window.jQuery&&(window.jQuery.fn.waypoint=t(window.jQuery)),window.Zepto&&(window.Zepto.fn.waypoint=t(window.Zepto))}(); \ No newline at end of file diff --git a/src/context.js b/src/context.js index 61614aaf..81e18292 100644 --- a/src/context.js +++ b/src/context.js @@ -279,7 +279,9 @@ } window.onload = function() { - oldWindowLoad() + if (oldWindowOnLoad) { + oldWindowLoad() + } Context.refreshAll() } Waypoint.Context = Context From f97c055797b81c57e8246fe44a0fc39ff238ad98 Mon Sep 17 00:00:00 2001 From: imakewebthings Date: Thu, 18 Dec 2014 19:35:32 -0800 Subject: [PATCH 46/98] Update README, bump version number --- README.md | 48 +++++++++++--------------------- bower.json | 11 +++++++- lib/jquery.waypoints.js | 4 +-- lib/jquery.waypoints.min.js | 4 +-- lib/noframework.waypoints.js | 4 +-- lib/noframework.waypoints.min.js | 4 +-- lib/shortcuts/infinite.js | 2 +- lib/shortcuts/infinite.min.js | 2 +- lib/shortcuts/inview.js | 2 +- lib/shortcuts/inview.min.js | 2 +- lib/shortcuts/sticky.js | 2 +- lib/shortcuts/sticky.min.js | 2 +- lib/waypoints.debug.js | 2 +- lib/zepto.waypoints.js | 4 +-- lib/zepto.waypoints.min.js | 4 +-- package.json | 7 +++-- src/context.js | 2 +- 17 files changed, 52 insertions(+), 54 deletions(-) diff --git a/README.md b/README.md index 09adba92..c494f75b 100644 --- a/README.md +++ b/README.md @@ -1,47 +1,33 @@ -# jQuery Waypoints +# Waypoints -Waypoints is a jQuery plugin that makes it easy to execute a function whenever you scroll to an element. +Waypoints is a library that makes it easy to execute a function whenever you scroll to an element. ```js -$('.thing').waypoint(function() { - alert('You have scrolled to a thing.'); -}); +var waypoint = new Waypoint({ + element: document.getElementById('thing'), + handler: function(direction) { + alert('You have scroll to a thing') + } +}) ``` -If you're new to Waypoints, check out the [Get Started](http://imakewebthings.github.com/jquery-waypoints/#get-started) section. -[Read the full documentation](http://imakewebthings.github.com/jquery-waypoints/#docs) for more details on usage and customization. +If you're new to Waypoints, check out the [Getting Started](http://imakewebthings.com/guides/get-started) guide. + +[Read the full documentation](http://imakewebthings.com/waypoints/api/waypoint) for more details on usage and customization. ## Shortcuts In addition to the normal Waypoints script, extensions exist to make common UI patterns just a little easier to implement: -- [Infinite Scrolling](http://imakewebthings.github.com/jquery-waypoints/shortcuts/infinite-scroll) -- [Sticky Elements](http://imakewebthings.github.com/jquery-waypoints/shortcuts/sticky-elements) - -## Examples - -Waypoints can also be used as a base for your own custom UI patterns. Here are a few examples: - -- [Scroll Analytics](http://imakewebthings.github.com/jquery-waypoints/examples/scroll-analytics) -- [Dial Controls](http://imakewebthings.github.com/jquery-waypoints/examples/dial-controls) - -## AMD Module Loader Support +- [Infinite Scrolling](http://imakewebthings.com/waypoints/shortcuts/infinite-scroll) +- [Sticky Elements](http://imakewebthings.com/waypoints/shortcuts/sticky-elements) +- [Inview Detection](http://imakewebthings.com/waypoints/shortcuts/inview) -If you're using an AMD loader like [RequireJS](http://requirejs.org/), Waypoints registers itself as a named module, `'waypoints'`. Shortcut scripts are anonymous modules. -## Development Environment +## Contributing -If you want to contribute to Waypoints, I love pull requests that include changes to the source `coffee` files as well as the compiled JS and minified files. You can set up the same environment by running `make setup` (which just aliases to `npm install`). This will install the version of CoffeeScript and UglifyJS that I'm using. From there, running `make build` will compile and minify all the necessary files. Test coffee files are compiled on the fly, so compile and minify do not apply to those files. +If you want to report a Waypoints bug or contribute code to the library, please read the [Contributing Guidelines](https://github.com/imakewebthings/waypoints/blob/master/CONRIBUTING.md). If you need help *using* Waypoints, please do not open an issue. Instead, ask the question on [Stack Overflow](http://stackoverflow.com)and tag it with #jquery-waypoints. Be sure to follow the guidelines for [asking a good question](http://stackoverflow.com/help/how-to-ask). ## License -Copyright (c) 2011-2014 Caleb Troughton -Licensed under the [MIT license](https://github.com/imakewebthings/jquery-waypoints/blob/master/licenses.txt). - -## Support - -Unit tests for Waypoints are written with [Jasmine](http://pivotal.github.com/jasmine/) and [jasmine-jquery](https://github.com/velesin/jasmine-jquery). You can [run them here](http://imakewebthings.github.com/jquery-waypoints/test/). If any of the tests fail, please open an issue and include the browser used, operating system, and description of the failed test. - -## Donations - -[![Gittip donate button](http://img.shields.io/gittip/imakewebthings.png)](https://www.gittip.com/imakewebthings/ "Donate weekly to this project using Gittip") +Copyright (c) 2011-2014 Caleb Troughton. Licensed under the [MIT license](https://github.com/imakewebthings/waypoints/blob/master/licenses.txt). diff --git a/bower.json b/bower.json index d7998f6d..ec514e75 100644 --- a/bower.json +++ b/bower.json @@ -1,6 +1,15 @@ { "name": "waypoints", - "private": true, + "version": "3.0.0", + "main": "lib/noframework.waypoints.min.js", + "description": "Easily execute a function when you scroll to an element.", + "ignore": [ + "gulpfile.js", + "package.json", + "src", + "test", + "testem.json" + ], "devDependencies": { "jquery": "~1.11.1", "lodash": "~2.4.1", diff --git a/lib/jquery.waypoints.js b/lib/jquery.waypoints.js index 9e4fe8d2..106a8eb3 100644 --- a/lib/jquery.waypoints.js +++ b/lib/jquery.waypoints.js @@ -1,5 +1,5 @@ /*! -Waypoints - 2.0.5 +Waypoints - 3.0.0 Copyright © 2011-2014 Caleb Troughton Licensed under the MIT license. https://github.com/imakewebthings/waypoints/blog/master/licenses.txt @@ -428,7 +428,7 @@ https://github.com/imakewebthings/waypoints/blog/master/licenses.txt } window.onload = function() { - if (oldWindowOnLoad) { + if (oldWindowLoad) { oldWindowLoad() } Context.refreshAll() diff --git a/lib/jquery.waypoints.min.js b/lib/jquery.waypoints.min.js index 8e9f8ee4..2309fc40 100644 --- a/lib/jquery.waypoints.min.js +++ b/lib/jquery.waypoints.min.js @@ -1,7 +1,7 @@ /*! -Waypoints - 2.0.5 +Waypoints - 3.0.0 Copyright © 2011-2014 Caleb Troughton Licensed under the MIT license. https://github.com/imakewebthings/waypoints/blog/master/licenses.txt */ -!function(){"use strict";function t(o){if(!o)throw new Error("No options passed to Waypoint constructor");if(!o.element)throw new Error("No element option passed to Waypoint constructor");if(!o.handler)throw new Error("No handler option passed to Waypoint constructor");this.key="waypoint-"+e,this.options=t.Adapter.extend({},t.defaults,o),this.element=this.options.element,this.adapter=new t.Adapter(this.element),this.callback=o.handler,this.axis=this.options.horizontal?"horizontal":"vertical",this.enabled=this.options.enabled,this.triggerPoint=null,this.group=t.Group.findOrCreate({name:this.options.group,axis:this.axis}),this.context=t.Context.findOrCreateByElement(this.options.context),t.offsetAliases[this.options.offset]&&(this.options.offset=t.offsetAliases[this.options.offset]),this.group.add(this),this.context.add(this),i[this.key]=this,e+=1}var e=0,i={};t.prototype.queueTrigger=function(t){this.group.queueTrigger(this,t)},t.prototype.trigger=function(t){this.enabled&&this.callback&&this.callback.apply(this,t)},t.prototype.destroy=function(){this.context.remove(this),this.group.remove(this),delete i[this.key]},t.prototype.disable=function(){return this.enabled=!1,this},t.prototype.enable=function(){return this.context.refresh(),this.enabled=!0,this},t.prototype.next=function(){return this.group.next(this)},t.prototype.previous=function(){return this.group.previous(this)},t.destroyAll=function(){var t=[];for(var e in i)t.push(i[e]);for(var o=0,r=t.length;r>o;o++)t[o].destroy()},t.refreshAll=function(){t.Context.refreshAll()},t.viewportHeight=function(){return window.innerHeight||document.documentElement.clientHeight},t.viewportWidth=function(){return document.documentElement.clientWidth},t.adapters=[],t.defaults={context:window,continuous:!0,enabled:!0,group:"default",horizontal:!1,offset:0},t.offsetAliases={"bottom-in-view":function(){return this.context.innerHeight()-this.adapter.outerHeight()},"right-in-view":function(){return this.context.innerWidth()-this.adapter.outerWidth()}},window.Waypoint=t}(),function(){"use strict";function t(t){window.setTimeout(t,1e3/60)}function e(t){this.element=t,this.Adapter=r.Adapter,this.adapter=new this.Adapter(t),this.key="waypoint-context-"+i,this.didScroll=!1,this.didResize=!1,this.oldScroll={x:this.adapter.scrollLeft(),y:this.adapter.scrollTop()},this.waypoints={vertical:{},horizontal:{}},t.waypointContextKey=this.key,o[t.waypointContextKey]=this,i+=1,this.createThrottledScrollHandler(),this.createThrottledResizeHandler()}var i=0,o={},r=window.Waypoint,n=window.requestAnimationFrame||window.mozRequestAnimationFrame||window.webkitRequestAnimationFrame||t,s=window.onload;e.prototype.add=function(t){var e=t.options.horizontal?"horizontal":"vertical";this.waypoints[e][t.key]=t,this.refresh()},e.prototype.checkEmpty=function(){var t=this.Adapter.isEmptyObject(this.waypoints.horizontal),e=this.Adapter.isEmptyObject(this.waypoints.vertical);t&&e&&(this.adapter.off(".waypoints"),delete o[this.key])},e.prototype.createThrottledResizeHandler=function(){function t(){e.handleResize(),e.didResize=!1}var e=this;this.adapter.on("resize.waypoints",function(){e.didResize||(e.didResize=!0,n(t))})},e.prototype.createThrottledScrollHandler=function(){function t(){e.handleScroll(),e.didScroll=!1}var e=this;this.adapter.on("scroll.waypoints",function(){(!e.didScroll||r.isTouch)&&(e.didScroll=!0,n(t))})},e.prototype.handleResize=function(){r.Context.refreshAll()},e.prototype.handleScroll=function(){var t={},e={horizontal:{newScroll:this.adapter.scrollLeft(),oldScroll:this.oldScroll.x,forward:"right",backward:"left"},vertical:{newScroll:this.adapter.scrollTop(),oldScroll:this.oldScroll.y,forward:"down",backward:"up"}};for(var i in e){var o=e[i],r=o.newScroll>o.oldScroll,n=r?o.forward:o.backward;for(var s in this.waypoints[i]){var a=this.waypoints[i][s],l=o.oldScroll=a.triggerPoint,p=l&&h,u=!l&&!h;(p||u)&&(a.queueTrigger(n),t[a.group.id]=a.group)}}for(var c in t)t[c].flushTriggers();this.oldScroll={x:e.horizontal.newScroll,y:e.vertical.newScroll}},e.prototype.innerHeight=function(){return this.element===this.element.window?r.viewportHeight():this.adapter.innerHeight()},e.prototype.remove=function(t){delete this.waypoints[t.axis][t.key],this.checkEmpty()},e.prototype.innerWidth=function(){return this.element===this.element.window?r.viewportWidth():this.adapter.innerWidth()},e.prototype.destroy=function(){var t=[];for(var e in this.waypoints)for(var i in this.waypoints[e])t.push(this.waypoints[e][i]);for(var o=0,r=t.length;r>o;o++)t[o].destroy()},e.prototype.refresh=function(){var t,e=this.element===this.element.window,i=this.adapter.offset(),o={};this.handleScroll(),t={horizontal:{contextOffset:e?0:i.left,contextScroll:e?0:this.oldScroll.x,contextDimension:this.innerWidth(),oldScroll:this.oldScroll.x,forward:"right",backward:"left",offsetProp:"left"},vertical:{contextOffset:e?0:i.top,contextScroll:e?0:this.oldScroll.y,contextDimension:this.innerHeight(),oldScroll:this.oldScroll.y,forward:"down",backward:"up",offsetProp:"top"}};for(var r in t){var n=t[r];for(var s in this.waypoints[r]){var a,l,h,p,u,c=this.waypoints[r][s],d=c.options.offset,f=c.triggerPoint,w=0,y=null==f;c.element!==c.element.window&&(w=c.adapter.offset()[n.offsetProp]),"function"==typeof d?d=d.apply(c):"string"==typeof d&&(d=parseFloat(d),c.options.offset.indexOf("%")>-1&&(d=Math.ceil(n.contextDimension*d/100))),a=n.contextScroll-n.contextOffset,c.triggerPoint=w+a-d,l=f=n.oldScroll,p=l&&h,u=!l&&!h,!y&&p?(c.queueTrigger(n.backward),o[c.group.id]=c.group):!y&&u?(c.queueTrigger(n.forward),o[c.group.id]=c.group):y&&n.oldScroll>=c.triggerPoint&&(c.queueTrigger(n.forward),o[c.group.id]=c.group)}}for(var g in o)o[g].flushTriggers();return this},e.findOrCreateByElement=function(t){return e.findByElement(t)||new e(t)},e.refreshAll=function(){for(var t in o)o[t].refresh()},e.findByElement=function(t){return o[t.waypointContextKey]},window.onload=function(){oldWindowOnLoad&&s(),e.refreshAll()},r.Context=e}(),function(){"use strict";function t(t,e){return t.triggerPoint-e.triggerPoint}function e(t,e){return e.triggerPoint-t.triggerPoint}function i(t){this.name=t.name,this.axis=t.axis,this.id=this.name+"-"+this.axis,this.waypoints=[],this.clearTriggerQueues(),o[this.axis][this.name]=this}var o={vertical:{},horizontal:{}},r=window.Waypoint;i.prototype.add=function(t){this.waypoints.push(t)},i.prototype.clearTriggerQueues=function(){this.triggerQueues={up:[],down:[],left:[],right:[]}},i.prototype.flushTriggers=function(){for(var i in this.triggerQueues){var o=this.triggerQueues[i],r="up"===i||"left"===i;o.sort(r?e:t);for(var n=0,s=o.length;s>n;n+=1){var a=o[n];(a.options.continuous||n===o.length-1)&&a.trigger([i])}}this.clearTriggerQueues()},i.prototype.next=function(e){this.waypoints.sort(t);var i=r.Adapter.inArray(e,this.waypoints),o=i===this.waypoints.length-1;return o?null:this.waypoints[i+1]},i.prototype.previous=function(e){this.waypoints.sort(t);var i=r.Adapter.inArray(e,this.waypoints);return i?this.waypoints[i-1]:null},i.prototype.queueTrigger=function(t,e){this.triggerQueues[e].push(t)},i.prototype.remove=function(t){var e=r.Adapter.inArray(t,this.waypoints);e>-1&&this.waypoints.splice(e,1)},i.prototype.first=function(){return this.waypoints[0]},i.prototype.last=function(){return this.waypoints[this.waypoints.length-1]},i.findOrCreate=function(t){return o[t.axis][t.name]||new i(t)},r.Group=i}(),function(){"use strict";function t(t){this.$element=e(t)}var e=window.jQuery,i=window.Waypoint;e.each(["innerHeight","innerWidth","off","offset","on","outerHeight","outerWidth","scrollLeft","scrollTop"],function(e,i){t.prototype[i]=function(){var t=Array.prototype.slice.call(arguments);return this.$element[i].apply(this.$element,t)}}),e.each(["extend","inArray","isEmptyObject"],function(i,o){t[o]=e[o]}),i.adapters.push({name:"jquery",Adapter:t}),i.Adapter=t}(),function(){"use strict";function t(t){return function(){var i=[],o=arguments[0];return t.isFunction(arguments[0])&&(o=t.extend({},arguments[1]),o.handler=arguments[0]),this.each(function(){var r=t.extend({},o,{element:this});"string"==typeof r.context&&(r.context=t(this).closest(r.context)[0]),i.push(new e(r))}),i}}var e=window.Waypoint;window.jQuery&&(window.jQuery.fn.waypoint=t(window.jQuery)),window.Zepto&&(window.Zepto.fn.waypoint=t(window.Zepto))}(); \ No newline at end of file +!function(){"use strict";function t(o){if(!o)throw new Error("No options passed to Waypoint constructor");if(!o.element)throw new Error("No element option passed to Waypoint constructor");if(!o.handler)throw new Error("No handler option passed to Waypoint constructor");this.key="waypoint-"+e,this.options=t.Adapter.extend({},t.defaults,o),this.element=this.options.element,this.adapter=new t.Adapter(this.element),this.callback=o.handler,this.axis=this.options.horizontal?"horizontal":"vertical",this.enabled=this.options.enabled,this.triggerPoint=null,this.group=t.Group.findOrCreate({name:this.options.group,axis:this.axis}),this.context=t.Context.findOrCreateByElement(this.options.context),t.offsetAliases[this.options.offset]&&(this.options.offset=t.offsetAliases[this.options.offset]),this.group.add(this),this.context.add(this),i[this.key]=this,e+=1}var e=0,i={};t.prototype.queueTrigger=function(t){this.group.queueTrigger(this,t)},t.prototype.trigger=function(t){this.enabled&&this.callback&&this.callback.apply(this,t)},t.prototype.destroy=function(){this.context.remove(this),this.group.remove(this),delete i[this.key]},t.prototype.disable=function(){return this.enabled=!1,this},t.prototype.enable=function(){return this.context.refresh(),this.enabled=!0,this},t.prototype.next=function(){return this.group.next(this)},t.prototype.previous=function(){return this.group.previous(this)},t.destroyAll=function(){var t=[];for(var e in i)t.push(i[e]);for(var o=0,r=t.length;r>o;o++)t[o].destroy()},t.refreshAll=function(){t.Context.refreshAll()},t.viewportHeight=function(){return window.innerHeight||document.documentElement.clientHeight},t.viewportWidth=function(){return document.documentElement.clientWidth},t.adapters=[],t.defaults={context:window,continuous:!0,enabled:!0,group:"default",horizontal:!1,offset:0},t.offsetAliases={"bottom-in-view":function(){return this.context.innerHeight()-this.adapter.outerHeight()},"right-in-view":function(){return this.context.innerWidth()-this.adapter.outerWidth()}},window.Waypoint=t}(),function(){"use strict";function t(t){window.setTimeout(t,1e3/60)}function e(t){this.element=t,this.Adapter=r.Adapter,this.adapter=new this.Adapter(t),this.key="waypoint-context-"+i,this.didScroll=!1,this.didResize=!1,this.oldScroll={x:this.adapter.scrollLeft(),y:this.adapter.scrollTop()},this.waypoints={vertical:{},horizontal:{}},t.waypointContextKey=this.key,o[t.waypointContextKey]=this,i+=1,this.createThrottledScrollHandler(),this.createThrottledResizeHandler()}var i=0,o={},r=window.Waypoint,n=window.requestAnimationFrame||window.mozRequestAnimationFrame||window.webkitRequestAnimationFrame||t,s=window.onload;e.prototype.add=function(t){var e=t.options.horizontal?"horizontal":"vertical";this.waypoints[e][t.key]=t,this.refresh()},e.prototype.checkEmpty=function(){var t=this.Adapter.isEmptyObject(this.waypoints.horizontal),e=this.Adapter.isEmptyObject(this.waypoints.vertical);t&&e&&(this.adapter.off(".waypoints"),delete o[this.key])},e.prototype.createThrottledResizeHandler=function(){function t(){e.handleResize(),e.didResize=!1}var e=this;this.adapter.on("resize.waypoints",function(){e.didResize||(e.didResize=!0,n(t))})},e.prototype.createThrottledScrollHandler=function(){function t(){e.handleScroll(),e.didScroll=!1}var e=this;this.adapter.on("scroll.waypoints",function(){(!e.didScroll||r.isTouch)&&(e.didScroll=!0,n(t))})},e.prototype.handleResize=function(){r.Context.refreshAll()},e.prototype.handleScroll=function(){var t={},e={horizontal:{newScroll:this.adapter.scrollLeft(),oldScroll:this.oldScroll.x,forward:"right",backward:"left"},vertical:{newScroll:this.adapter.scrollTop(),oldScroll:this.oldScroll.y,forward:"down",backward:"up"}};for(var i in e){var o=e[i],r=o.newScroll>o.oldScroll,n=r?o.forward:o.backward;for(var s in this.waypoints[i]){var a=this.waypoints[i][s],l=o.oldScroll=a.triggerPoint,p=l&&h,u=!l&&!h;(p||u)&&(a.queueTrigger(n),t[a.group.id]=a.group)}}for(var c in t)t[c].flushTriggers();this.oldScroll={x:e.horizontal.newScroll,y:e.vertical.newScroll}},e.prototype.innerHeight=function(){return this.element===this.element.window?r.viewportHeight():this.adapter.innerHeight()},e.prototype.remove=function(t){delete this.waypoints[t.axis][t.key],this.checkEmpty()},e.prototype.innerWidth=function(){return this.element===this.element.window?r.viewportWidth():this.adapter.innerWidth()},e.prototype.destroy=function(){var t=[];for(var e in this.waypoints)for(var i in this.waypoints[e])t.push(this.waypoints[e][i]);for(var o=0,r=t.length;r>o;o++)t[o].destroy()},e.prototype.refresh=function(){var t,e=this.element===this.element.window,i=this.adapter.offset(),o={};this.handleScroll(),t={horizontal:{contextOffset:e?0:i.left,contextScroll:e?0:this.oldScroll.x,contextDimension:this.innerWidth(),oldScroll:this.oldScroll.x,forward:"right",backward:"left",offsetProp:"left"},vertical:{contextOffset:e?0:i.top,contextScroll:e?0:this.oldScroll.y,contextDimension:this.innerHeight(),oldScroll:this.oldScroll.y,forward:"down",backward:"up",offsetProp:"top"}};for(var r in t){var n=t[r];for(var s in this.waypoints[r]){var a,l,h,p,u,c=this.waypoints[r][s],d=c.options.offset,f=c.triggerPoint,w=0,y=null==f;c.element!==c.element.window&&(w=c.adapter.offset()[n.offsetProp]),"function"==typeof d?d=d.apply(c):"string"==typeof d&&(d=parseFloat(d),c.options.offset.indexOf("%")>-1&&(d=Math.ceil(n.contextDimension*d/100))),a=n.contextScroll-n.contextOffset,c.triggerPoint=w+a-d,l=f=n.oldScroll,p=l&&h,u=!l&&!h,!y&&p?(c.queueTrigger(n.backward),o[c.group.id]=c.group):!y&&u?(c.queueTrigger(n.forward),o[c.group.id]=c.group):y&&n.oldScroll>=c.triggerPoint&&(c.queueTrigger(n.forward),o[c.group.id]=c.group)}}for(var g in o)o[g].flushTriggers();return this},e.findOrCreateByElement=function(t){return e.findByElement(t)||new e(t)},e.refreshAll=function(){for(var t in o)o[t].refresh()},e.findByElement=function(t){return o[t.waypointContextKey]},window.onload=function(){s&&s(),e.refreshAll()},r.Context=e}(),function(){"use strict";function t(t,e){return t.triggerPoint-e.triggerPoint}function e(t,e){return e.triggerPoint-t.triggerPoint}function i(t){this.name=t.name,this.axis=t.axis,this.id=this.name+"-"+this.axis,this.waypoints=[],this.clearTriggerQueues(),o[this.axis][this.name]=this}var o={vertical:{},horizontal:{}},r=window.Waypoint;i.prototype.add=function(t){this.waypoints.push(t)},i.prototype.clearTriggerQueues=function(){this.triggerQueues={up:[],down:[],left:[],right:[]}},i.prototype.flushTriggers=function(){for(var i in this.triggerQueues){var o=this.triggerQueues[i],r="up"===i||"left"===i;o.sort(r?e:t);for(var n=0,s=o.length;s>n;n+=1){var a=o[n];(a.options.continuous||n===o.length-1)&&a.trigger([i])}}this.clearTriggerQueues()},i.prototype.next=function(e){this.waypoints.sort(t);var i=r.Adapter.inArray(e,this.waypoints),o=i===this.waypoints.length-1;return o?null:this.waypoints[i+1]},i.prototype.previous=function(e){this.waypoints.sort(t);var i=r.Adapter.inArray(e,this.waypoints);return i?this.waypoints[i-1]:null},i.prototype.queueTrigger=function(t,e){this.triggerQueues[e].push(t)},i.prototype.remove=function(t){var e=r.Adapter.inArray(t,this.waypoints);e>-1&&this.waypoints.splice(e,1)},i.prototype.first=function(){return this.waypoints[0]},i.prototype.last=function(){return this.waypoints[this.waypoints.length-1]},i.findOrCreate=function(t){return o[t.axis][t.name]||new i(t)},r.Group=i}(),function(){"use strict";function t(t){this.$element=e(t)}var e=window.jQuery,i=window.Waypoint;e.each(["innerHeight","innerWidth","off","offset","on","outerHeight","outerWidth","scrollLeft","scrollTop"],function(e,i){t.prototype[i]=function(){var t=Array.prototype.slice.call(arguments);return this.$element[i].apply(this.$element,t)}}),e.each(["extend","inArray","isEmptyObject"],function(i,o){t[o]=e[o]}),i.adapters.push({name:"jquery",Adapter:t}),i.Adapter=t}(),function(){"use strict";function t(t){return function(){var i=[],o=arguments[0];return t.isFunction(arguments[0])&&(o=t.extend({},arguments[1]),o.handler=arguments[0]),this.each(function(){var r=t.extend({},o,{element:this});"string"==typeof r.context&&(r.context=t(this).closest(r.context)[0]),i.push(new e(r))}),i}}var e=window.Waypoint;window.jQuery&&(window.jQuery.fn.waypoint=t(window.jQuery)),window.Zepto&&(window.Zepto.fn.waypoint=t(window.Zepto))}(); \ No newline at end of file diff --git a/lib/noframework.waypoints.js b/lib/noframework.waypoints.js index ed7f3e0e..90cf14bf 100644 --- a/lib/noframework.waypoints.js +++ b/lib/noframework.waypoints.js @@ -1,5 +1,5 @@ /*! -Waypoints - 2.0.5 +Waypoints - 3.0.0 Copyright © 2011-2014 Caleb Troughton Licensed under the MIT license. https://github.com/imakewebthings/waypoints/blog/master/licenses.txt @@ -428,7 +428,7 @@ https://github.com/imakewebthings/waypoints/blog/master/licenses.txt } window.onload = function() { - if (oldWindowOnLoad) { + if (oldWindowLoad) { oldWindowLoad() } Context.refreshAll() diff --git a/lib/noframework.waypoints.min.js b/lib/noframework.waypoints.min.js index 847319a5..4c570872 100644 --- a/lib/noframework.waypoints.min.js +++ b/lib/noframework.waypoints.min.js @@ -1,7 +1,7 @@ /*! -Waypoints - 2.0.5 +Waypoints - 3.0.0 Copyright © 2011-2014 Caleb Troughton Licensed under the MIT license. https://github.com/imakewebthings/waypoints/blog/master/licenses.txt */ -!function(){"use strict";function t(n){if(!n)throw new Error("No options passed to Waypoint constructor");if(!n.element)throw new Error("No element option passed to Waypoint constructor");if(!n.handler)throw new Error("No handler option passed to Waypoint constructor");this.key="waypoint-"+e,this.options=t.Adapter.extend({},t.defaults,n),this.element=this.options.element,this.adapter=new t.Adapter(this.element),this.callback=n.handler,this.axis=this.options.horizontal?"horizontal":"vertical",this.enabled=this.options.enabled,this.triggerPoint=null,this.group=t.Group.findOrCreate({name:this.options.group,axis:this.axis}),this.context=t.Context.findOrCreateByElement(this.options.context),t.offsetAliases[this.options.offset]&&(this.options.offset=t.offsetAliases[this.options.offset]),this.group.add(this),this.context.add(this),i[this.key]=this,e+=1}var e=0,i={};t.prototype.queueTrigger=function(t){this.group.queueTrigger(this,t)},t.prototype.trigger=function(t){this.enabled&&this.callback&&this.callback.apply(this,t)},t.prototype.destroy=function(){this.context.remove(this),this.group.remove(this),delete i[this.key]},t.prototype.disable=function(){return this.enabled=!1,this},t.prototype.enable=function(){return this.context.refresh(),this.enabled=!0,this},t.prototype.next=function(){return this.group.next(this)},t.prototype.previous=function(){return this.group.previous(this)},t.destroyAll=function(){var t=[];for(var e in i)t.push(i[e]);for(var n=0,o=t.length;o>n;n++)t[n].destroy()},t.refreshAll=function(){t.Context.refreshAll()},t.viewportHeight=function(){return window.innerHeight||document.documentElement.clientHeight},t.viewportWidth=function(){return document.documentElement.clientWidth},t.adapters=[],t.defaults={context:window,continuous:!0,enabled:!0,group:"default",horizontal:!1,offset:0},t.offsetAliases={"bottom-in-view":function(){return this.context.innerHeight()-this.adapter.outerHeight()},"right-in-view":function(){return this.context.innerWidth()-this.adapter.outerWidth()}},window.Waypoint=t}(),function(){"use strict";function t(t){window.setTimeout(t,1e3/60)}function e(t){this.element=t,this.Adapter=o.Adapter,this.adapter=new this.Adapter(t),this.key="waypoint-context-"+i,this.didScroll=!1,this.didResize=!1,this.oldScroll={x:this.adapter.scrollLeft(),y:this.adapter.scrollTop()},this.waypoints={vertical:{},horizontal:{}},t.waypointContextKey=this.key,n[t.waypointContextKey]=this,i+=1,this.createThrottledScrollHandler(),this.createThrottledResizeHandler()}var i=0,n={},o=window.Waypoint,r=window.requestAnimationFrame||window.mozRequestAnimationFrame||window.webkitRequestAnimationFrame||t,s=window.onload;e.prototype.add=function(t){var e=t.options.horizontal?"horizontal":"vertical";this.waypoints[e][t.key]=t,this.refresh()},e.prototype.checkEmpty=function(){var t=this.Adapter.isEmptyObject(this.waypoints.horizontal),e=this.Adapter.isEmptyObject(this.waypoints.vertical);t&&e&&(this.adapter.off(".waypoints"),delete n[this.key])},e.prototype.createThrottledResizeHandler=function(){function t(){e.handleResize(),e.didResize=!1}var e=this;this.adapter.on("resize.waypoints",function(){e.didResize||(e.didResize=!0,r(t))})},e.prototype.createThrottledScrollHandler=function(){function t(){e.handleScroll(),e.didScroll=!1}var e=this;this.adapter.on("scroll.waypoints",function(){(!e.didScroll||o.isTouch)&&(e.didScroll=!0,r(t))})},e.prototype.handleResize=function(){o.Context.refreshAll()},e.prototype.handleScroll=function(){var t={},e={horizontal:{newScroll:this.adapter.scrollLeft(),oldScroll:this.oldScroll.x,forward:"right",backward:"left"},vertical:{newScroll:this.adapter.scrollTop(),oldScroll:this.oldScroll.y,forward:"down",backward:"up"}};for(var i in e){var n=e[i],o=n.newScroll>n.oldScroll,r=o?n.forward:n.backward;for(var s in this.waypoints[i]){var a=this.waypoints[i][s],l=n.oldScroll=a.triggerPoint,p=l&&h,u=!l&&!h;(p||u)&&(a.queueTrigger(r),t[a.group.id]=a.group)}}for(var c in t)t[c].flushTriggers();this.oldScroll={x:e.horizontal.newScroll,y:e.vertical.newScroll}},e.prototype.innerHeight=function(){return this.element===this.element.window?o.viewportHeight():this.adapter.innerHeight()},e.prototype.remove=function(t){delete this.waypoints[t.axis][t.key],this.checkEmpty()},e.prototype.innerWidth=function(){return this.element===this.element.window?o.viewportWidth():this.adapter.innerWidth()},e.prototype.destroy=function(){var t=[];for(var e in this.waypoints)for(var i in this.waypoints[e])t.push(this.waypoints[e][i]);for(var n=0,o=t.length;o>n;n++)t[n].destroy()},e.prototype.refresh=function(){var t,e=this.element===this.element.window,i=this.adapter.offset(),n={};this.handleScroll(),t={horizontal:{contextOffset:e?0:i.left,contextScroll:e?0:this.oldScroll.x,contextDimension:this.innerWidth(),oldScroll:this.oldScroll.x,forward:"right",backward:"left",offsetProp:"left"},vertical:{contextOffset:e?0:i.top,contextScroll:e?0:this.oldScroll.y,contextDimension:this.innerHeight(),oldScroll:this.oldScroll.y,forward:"down",backward:"up",offsetProp:"top"}};for(var o in t){var r=t[o];for(var s in this.waypoints[o]){var a,l,h,p,u,c=this.waypoints[o][s],d=c.options.offset,f=c.triggerPoint,y=0,g=null==f;c.element!==c.element.window&&(y=c.adapter.offset()[r.offsetProp]),"function"==typeof d?d=d.apply(c):"string"==typeof d&&(d=parseFloat(d),c.options.offset.indexOf("%")>-1&&(d=Math.ceil(r.contextDimension*d/100))),a=r.contextScroll-r.contextOffset,c.triggerPoint=y+a-d,l=f=r.oldScroll,p=l&&h,u=!l&&!h,!g&&p?(c.queueTrigger(r.backward),n[c.group.id]=c.group):!g&&u?(c.queueTrigger(r.forward),n[c.group.id]=c.group):g&&r.oldScroll>=c.triggerPoint&&(c.queueTrigger(r.forward),n[c.group.id]=c.group)}}for(var w in n)n[w].flushTriggers();return this},e.findOrCreateByElement=function(t){return e.findByElement(t)||new e(t)},e.refreshAll=function(){for(var t in n)n[t].refresh()},e.findByElement=function(t){return n[t.waypointContextKey]},window.onload=function(){oldWindowOnLoad&&s(),e.refreshAll()},o.Context=e}(),function(){"use strict";function t(t,e){return t.triggerPoint-e.triggerPoint}function e(t,e){return e.triggerPoint-t.triggerPoint}function i(t){this.name=t.name,this.axis=t.axis,this.id=this.name+"-"+this.axis,this.waypoints=[],this.clearTriggerQueues(),n[this.axis][this.name]=this}var n={vertical:{},horizontal:{}},o=window.Waypoint;i.prototype.add=function(t){this.waypoints.push(t)},i.prototype.clearTriggerQueues=function(){this.triggerQueues={up:[],down:[],left:[],right:[]}},i.prototype.flushTriggers=function(){for(var i in this.triggerQueues){var n=this.triggerQueues[i],o="up"===i||"left"===i;n.sort(o?e:t);for(var r=0,s=n.length;s>r;r+=1){var a=n[r];(a.options.continuous||r===n.length-1)&&a.trigger([i])}}this.clearTriggerQueues()},i.prototype.next=function(e){this.waypoints.sort(t);var i=o.Adapter.inArray(e,this.waypoints),n=i===this.waypoints.length-1;return n?null:this.waypoints[i+1]},i.prototype.previous=function(e){this.waypoints.sort(t);var i=o.Adapter.inArray(e,this.waypoints);return i?this.waypoints[i-1]:null},i.prototype.queueTrigger=function(t,e){this.triggerQueues[e].push(t)},i.prototype.remove=function(t){var e=o.Adapter.inArray(t,this.waypoints);e>-1&&this.waypoints.splice(e,1)},i.prototype.first=function(){return this.waypoints[0]},i.prototype.last=function(){return this.waypoints[this.waypoints.length-1]},i.findOrCreate=function(t){return n[t.axis][t.name]||new i(t)},o.Group=i}(),function(){"use strict";function t(t){return t===t.window}function e(e){return t(e)?e:e.defaultView}function i(t){this.element=t,this.handlers={}}var n=window.Waypoint;i.prototype.innerHeight=function(){var e=t(this.element);return e?this.element.innerHeight:this.element.clientHeight},i.prototype.innerWidth=function(){var e=t(this.element);return e?this.element.innerWidth:this.element.clientWidth},i.prototype.off=function(t,e){function i(t,e,i){for(var n=0,o=e.length-1;o>n;n++){var r=e[n];i&&i!==r||t.removeEventListener(r)}}var n=t.split("."),o=n[0],r=n[1],s=this.element;if(r&&this.handlers[r]&&o)i(s,this.handlers[r][o],e),this.handlers[r][o]=[];else if(o)for(var a in this.handlers)i(s,this.handlers[a][o]||[],e),this.handlers[a][o]=[];else if(r&&this.handlers[r]){for(var l in this.handlers[r])i(s,this.handlers[r][l],e);this.handlers[r]={}}},i.prototype.offset=function(){if(!this.element.ownerDocument)return null;var t=this.element.ownerDocument.documentElement,i=e(this.element.ownerDocument),n={top:0,left:0};return this.element.getBoundingClientRect&&(n=this.element.getBoundingClientRect()),{top:n.top+i.pageYOffset-t.clientTop,left:n.left+i.pageXOffset-t.clientLeft}},i.prototype.on=function(t,e){var i=t.split("."),n=i[0],o=i[1]||"__default",r=this.handlers[o]=this.handlers[o]||{},s=r[n]=r[n]||[];s.push(e),this.element.addEventListener(n,e)},i.prototype.outerHeight=function(e){var i,n=this.innerHeight();return e&&!t(this.element)&&(i=window.getComputedStyle(this.element),n+=parseInt(i.marginTop,10),n+=parseInt(i.marginBottom,10)),n},i.prototype.outerWidth=function(e){var i,n=this.innerWidth();return e&&!t(this.element)&&(i=window.getComputedStyle(this.element),n+=parseInt(i.marginLeft,10),n+=parseInt(i.marginRight,10)),n},i.prototype.scrollLeft=function(){var t=e(this.element);return t?t.pageXOffset:this.element.scrollLeft},i.prototype.scrollTop=function(){var t=e(this.element);return t?t.pageYOffset:this.element.scrollTop},i.extend=function(){function t(t,e){if("object"==typeof t&&"object"==typeof e)for(var i in e)e.hasOwnProperty(i)&&(t[i]=e[i]);return t}for(var e=Array.prototype.slice.call(arguments),i=1,n=e.length;n>i;i++)t(e[0],e[i]);return e[0]},i.inArray=function(t,e,i){return null==e?-1:e.indexOf(t,i)},i.isEmptyObject=function(t){for(var e in t)return!1;return!0},n.adapters.push({name:"noframework",Adapter:i}),n.Adapter=i}(); \ No newline at end of file +!function(){"use strict";function t(n){if(!n)throw new Error("No options passed to Waypoint constructor");if(!n.element)throw new Error("No element option passed to Waypoint constructor");if(!n.handler)throw new Error("No handler option passed to Waypoint constructor");this.key="waypoint-"+e,this.options=t.Adapter.extend({},t.defaults,n),this.element=this.options.element,this.adapter=new t.Adapter(this.element),this.callback=n.handler,this.axis=this.options.horizontal?"horizontal":"vertical",this.enabled=this.options.enabled,this.triggerPoint=null,this.group=t.Group.findOrCreate({name:this.options.group,axis:this.axis}),this.context=t.Context.findOrCreateByElement(this.options.context),t.offsetAliases[this.options.offset]&&(this.options.offset=t.offsetAliases[this.options.offset]),this.group.add(this),this.context.add(this),i[this.key]=this,e+=1}var e=0,i={};t.prototype.queueTrigger=function(t){this.group.queueTrigger(this,t)},t.prototype.trigger=function(t){this.enabled&&this.callback&&this.callback.apply(this,t)},t.prototype.destroy=function(){this.context.remove(this),this.group.remove(this),delete i[this.key]},t.prototype.disable=function(){return this.enabled=!1,this},t.prototype.enable=function(){return this.context.refresh(),this.enabled=!0,this},t.prototype.next=function(){return this.group.next(this)},t.prototype.previous=function(){return this.group.previous(this)},t.destroyAll=function(){var t=[];for(var e in i)t.push(i[e]);for(var n=0,o=t.length;o>n;n++)t[n].destroy()},t.refreshAll=function(){t.Context.refreshAll()},t.viewportHeight=function(){return window.innerHeight||document.documentElement.clientHeight},t.viewportWidth=function(){return document.documentElement.clientWidth},t.adapters=[],t.defaults={context:window,continuous:!0,enabled:!0,group:"default",horizontal:!1,offset:0},t.offsetAliases={"bottom-in-view":function(){return this.context.innerHeight()-this.adapter.outerHeight()},"right-in-view":function(){return this.context.innerWidth()-this.adapter.outerWidth()}},window.Waypoint=t}(),function(){"use strict";function t(t){window.setTimeout(t,1e3/60)}function e(t){this.element=t,this.Adapter=o.Adapter,this.adapter=new this.Adapter(t),this.key="waypoint-context-"+i,this.didScroll=!1,this.didResize=!1,this.oldScroll={x:this.adapter.scrollLeft(),y:this.adapter.scrollTop()},this.waypoints={vertical:{},horizontal:{}},t.waypointContextKey=this.key,n[t.waypointContextKey]=this,i+=1,this.createThrottledScrollHandler(),this.createThrottledResizeHandler()}var i=0,n={},o=window.Waypoint,r=window.requestAnimationFrame||window.mozRequestAnimationFrame||window.webkitRequestAnimationFrame||t,s=window.onload;e.prototype.add=function(t){var e=t.options.horizontal?"horizontal":"vertical";this.waypoints[e][t.key]=t,this.refresh()},e.prototype.checkEmpty=function(){var t=this.Adapter.isEmptyObject(this.waypoints.horizontal),e=this.Adapter.isEmptyObject(this.waypoints.vertical);t&&e&&(this.adapter.off(".waypoints"),delete n[this.key])},e.prototype.createThrottledResizeHandler=function(){function t(){e.handleResize(),e.didResize=!1}var e=this;this.adapter.on("resize.waypoints",function(){e.didResize||(e.didResize=!0,r(t))})},e.prototype.createThrottledScrollHandler=function(){function t(){e.handleScroll(),e.didScroll=!1}var e=this;this.adapter.on("scroll.waypoints",function(){(!e.didScroll||o.isTouch)&&(e.didScroll=!0,r(t))})},e.prototype.handleResize=function(){o.Context.refreshAll()},e.prototype.handleScroll=function(){var t={},e={horizontal:{newScroll:this.adapter.scrollLeft(),oldScroll:this.oldScroll.x,forward:"right",backward:"left"},vertical:{newScroll:this.adapter.scrollTop(),oldScroll:this.oldScroll.y,forward:"down",backward:"up"}};for(var i in e){var n=e[i],o=n.newScroll>n.oldScroll,r=o?n.forward:n.backward;for(var s in this.waypoints[i]){var a=this.waypoints[i][s],l=n.oldScroll=a.triggerPoint,p=l&&h,u=!l&&!h;(p||u)&&(a.queueTrigger(r),t[a.group.id]=a.group)}}for(var c in t)t[c].flushTriggers();this.oldScroll={x:e.horizontal.newScroll,y:e.vertical.newScroll}},e.prototype.innerHeight=function(){return this.element===this.element.window?o.viewportHeight():this.adapter.innerHeight()},e.prototype.remove=function(t){delete this.waypoints[t.axis][t.key],this.checkEmpty()},e.prototype.innerWidth=function(){return this.element===this.element.window?o.viewportWidth():this.adapter.innerWidth()},e.prototype.destroy=function(){var t=[];for(var e in this.waypoints)for(var i in this.waypoints[e])t.push(this.waypoints[e][i]);for(var n=0,o=t.length;o>n;n++)t[n].destroy()},e.prototype.refresh=function(){var t,e=this.element===this.element.window,i=this.adapter.offset(),n={};this.handleScroll(),t={horizontal:{contextOffset:e?0:i.left,contextScroll:e?0:this.oldScroll.x,contextDimension:this.innerWidth(),oldScroll:this.oldScroll.x,forward:"right",backward:"left",offsetProp:"left"},vertical:{contextOffset:e?0:i.top,contextScroll:e?0:this.oldScroll.y,contextDimension:this.innerHeight(),oldScroll:this.oldScroll.y,forward:"down",backward:"up",offsetProp:"top"}};for(var o in t){var r=t[o];for(var s in this.waypoints[o]){var a,l,h,p,u,c=this.waypoints[o][s],f=c.options.offset,d=c.triggerPoint,y=0,g=null==d;c.element!==c.element.window&&(y=c.adapter.offset()[r.offsetProp]),"function"==typeof f?f=f.apply(c):"string"==typeof f&&(f=parseFloat(f),c.options.offset.indexOf("%")>-1&&(f=Math.ceil(r.contextDimension*f/100))),a=r.contextScroll-r.contextOffset,c.triggerPoint=y+a-f,l=d=r.oldScroll,p=l&&h,u=!l&&!h,!g&&p?(c.queueTrigger(r.backward),n[c.group.id]=c.group):!g&&u?(c.queueTrigger(r.forward),n[c.group.id]=c.group):g&&r.oldScroll>=c.triggerPoint&&(c.queueTrigger(r.forward),n[c.group.id]=c.group)}}for(var w in n)n[w].flushTriggers();return this},e.findOrCreateByElement=function(t){return e.findByElement(t)||new e(t)},e.refreshAll=function(){for(var t in n)n[t].refresh()},e.findByElement=function(t){return n[t.waypointContextKey]},window.onload=function(){s&&s(),e.refreshAll()},o.Context=e}(),function(){"use strict";function t(t,e){return t.triggerPoint-e.triggerPoint}function e(t,e){return e.triggerPoint-t.triggerPoint}function i(t){this.name=t.name,this.axis=t.axis,this.id=this.name+"-"+this.axis,this.waypoints=[],this.clearTriggerQueues(),n[this.axis][this.name]=this}var n={vertical:{},horizontal:{}},o=window.Waypoint;i.prototype.add=function(t){this.waypoints.push(t)},i.prototype.clearTriggerQueues=function(){this.triggerQueues={up:[],down:[],left:[],right:[]}},i.prototype.flushTriggers=function(){for(var i in this.triggerQueues){var n=this.triggerQueues[i],o="up"===i||"left"===i;n.sort(o?e:t);for(var r=0,s=n.length;s>r;r+=1){var a=n[r];(a.options.continuous||r===n.length-1)&&a.trigger([i])}}this.clearTriggerQueues()},i.prototype.next=function(e){this.waypoints.sort(t);var i=o.Adapter.inArray(e,this.waypoints),n=i===this.waypoints.length-1;return n?null:this.waypoints[i+1]},i.prototype.previous=function(e){this.waypoints.sort(t);var i=o.Adapter.inArray(e,this.waypoints);return i?this.waypoints[i-1]:null},i.prototype.queueTrigger=function(t,e){this.triggerQueues[e].push(t)},i.prototype.remove=function(t){var e=o.Adapter.inArray(t,this.waypoints);e>-1&&this.waypoints.splice(e,1)},i.prototype.first=function(){return this.waypoints[0]},i.prototype.last=function(){return this.waypoints[this.waypoints.length-1]},i.findOrCreate=function(t){return n[t.axis][t.name]||new i(t)},o.Group=i}(),function(){"use strict";function t(t){return t===t.window}function e(e){return t(e)?e:e.defaultView}function i(t){this.element=t,this.handlers={}}var n=window.Waypoint;i.prototype.innerHeight=function(){var e=t(this.element);return e?this.element.innerHeight:this.element.clientHeight},i.prototype.innerWidth=function(){var e=t(this.element);return e?this.element.innerWidth:this.element.clientWidth},i.prototype.off=function(t,e){function i(t,e,i){for(var n=0,o=e.length-1;o>n;n++){var r=e[n];i&&i!==r||t.removeEventListener(r)}}var n=t.split("."),o=n[0],r=n[1],s=this.element;if(r&&this.handlers[r]&&o)i(s,this.handlers[r][o],e),this.handlers[r][o]=[];else if(o)for(var a in this.handlers)i(s,this.handlers[a][o]||[],e),this.handlers[a][o]=[];else if(r&&this.handlers[r]){for(var l in this.handlers[r])i(s,this.handlers[r][l],e);this.handlers[r]={}}},i.prototype.offset=function(){if(!this.element.ownerDocument)return null;var t=this.element.ownerDocument.documentElement,i=e(this.element.ownerDocument),n={top:0,left:0};return this.element.getBoundingClientRect&&(n=this.element.getBoundingClientRect()),{top:n.top+i.pageYOffset-t.clientTop,left:n.left+i.pageXOffset-t.clientLeft}},i.prototype.on=function(t,e){var i=t.split("."),n=i[0],o=i[1]||"__default",r=this.handlers[o]=this.handlers[o]||{},s=r[n]=r[n]||[];s.push(e),this.element.addEventListener(n,e)},i.prototype.outerHeight=function(e){var i,n=this.innerHeight();return e&&!t(this.element)&&(i=window.getComputedStyle(this.element),n+=parseInt(i.marginTop,10),n+=parseInt(i.marginBottom,10)),n},i.prototype.outerWidth=function(e){var i,n=this.innerWidth();return e&&!t(this.element)&&(i=window.getComputedStyle(this.element),n+=parseInt(i.marginLeft,10),n+=parseInt(i.marginRight,10)),n},i.prototype.scrollLeft=function(){var t=e(this.element);return t?t.pageXOffset:this.element.scrollLeft},i.prototype.scrollTop=function(){var t=e(this.element);return t?t.pageYOffset:this.element.scrollTop},i.extend=function(){function t(t,e){if("object"==typeof t&&"object"==typeof e)for(var i in e)e.hasOwnProperty(i)&&(t[i]=e[i]);return t}for(var e=Array.prototype.slice.call(arguments),i=1,n=e.length;n>i;i++)t(e[0],e[i]);return e[0]},i.inArray=function(t,e,i){return null==e?-1:e.indexOf(t,i)},i.isEmptyObject=function(t){for(var e in t)return!1;return!0},n.adapters.push({name:"noframework",Adapter:i}),n.Adapter=i}(); \ No newline at end of file diff --git a/lib/shortcuts/infinite.js b/lib/shortcuts/infinite.js index 0a3c37c5..1e05ae84 100644 --- a/lib/shortcuts/infinite.js +++ b/lib/shortcuts/infinite.js @@ -1,5 +1,5 @@ /*! -Waypoints Infinite Scroll Shortcut - 2.0.5 +Waypoints Infinite Scroll Shortcut - 3.0.0 Copyright © 2011-2014 Caleb Troughton Licensed under the MIT license. https://github.com/imakewebthings/waypoints/blog/master/licenses.txt diff --git a/lib/shortcuts/infinite.min.js b/lib/shortcuts/infinite.min.js index 688a700c..d75dc286 100644 --- a/lib/shortcuts/infinite.min.js +++ b/lib/shortcuts/infinite.min.js @@ -1,5 +1,5 @@ /*! -Waypoints Infinite Scroll Shortcut - 2.0.5 +Waypoints Infinite Scroll Shortcut - 3.0.0 Copyright © 2011-2014 Caleb Troughton Licensed under the MIT license. https://github.com/imakewebthings/waypoints/blog/master/licenses.txt diff --git a/lib/shortcuts/inview.js b/lib/shortcuts/inview.js index b068c795..87635fe7 100644 --- a/lib/shortcuts/inview.js +++ b/lib/shortcuts/inview.js @@ -1,5 +1,5 @@ /*! -Waypoints Inview Shortcut - 2.0.5 +Waypoints Inview Shortcut - 3.0.0 Copyright © 2011-2014 Caleb Troughton Licensed under the MIT license. https://github.com/imakewebthings/waypoints/blog/master/licenses.txt diff --git a/lib/shortcuts/inview.min.js b/lib/shortcuts/inview.min.js index 03156626..029741c2 100644 --- a/lib/shortcuts/inview.min.js +++ b/lib/shortcuts/inview.min.js @@ -1,5 +1,5 @@ /*! -Waypoints Inview Shortcut - 2.0.5 +Waypoints Inview Shortcut - 3.0.0 Copyright © 2011-2014 Caleb Troughton Licensed under the MIT license. https://github.com/imakewebthings/waypoints/blog/master/licenses.txt diff --git a/lib/shortcuts/sticky.js b/lib/shortcuts/sticky.js index 7805dc7b..759132b1 100644 --- a/lib/shortcuts/sticky.js +++ b/lib/shortcuts/sticky.js @@ -1,5 +1,5 @@ /*! -Waypoints Sticky Element Shortcut - 2.0.5 +Waypoints Sticky Element Shortcut - 3.0.0 Copyright © 2011-2014 Caleb Troughton Licensed under the MIT license. https://github.com/imakewebthings/waypoints/blog/master/licenses.txt diff --git a/lib/shortcuts/sticky.min.js b/lib/shortcuts/sticky.min.js index e7664e9a..d728d36e 100644 --- a/lib/shortcuts/sticky.min.js +++ b/lib/shortcuts/sticky.min.js @@ -1,5 +1,5 @@ /*! -Waypoints Sticky Element Shortcut - 2.0.5 +Waypoints Sticky Element Shortcut - 3.0.0 Copyright © 2011-2014 Caleb Troughton Licensed under the MIT license. https://github.com/imakewebthings/waypoints/blog/master/licenses.txt diff --git a/lib/waypoints.debug.js b/lib/waypoints.debug.js index bb9f330a..1c1f9865 100644 --- a/lib/waypoints.debug.js +++ b/lib/waypoints.debug.js @@ -1,5 +1,5 @@ /*! -Waypoints Debug - 2.0.5 +Waypoints Debug - 3.0.0 Copyright © 2011-2014 Caleb Troughton Licensed under the MIT license. https://github.com/imakewebthings/waypoints/blog/master/licenses.txt diff --git a/lib/zepto.waypoints.js b/lib/zepto.waypoints.js index 5213f2cc..1ba79fc3 100644 --- a/lib/zepto.waypoints.js +++ b/lib/zepto.waypoints.js @@ -1,5 +1,5 @@ /*! -Waypoints - 2.0.5 +Waypoints - 3.0.0 Copyright © 2011-2014 Caleb Troughton Licensed under the MIT license. https://github.com/imakewebthings/waypoints/blog/master/licenses.txt @@ -428,7 +428,7 @@ https://github.com/imakewebthings/waypoints/blog/master/licenses.txt } window.onload = function() { - if (oldWindowOnLoad) { + if (oldWindowLoad) { oldWindowLoad() } Context.refreshAll() diff --git a/lib/zepto.waypoints.min.js b/lib/zepto.waypoints.min.js index 4f6e3ce1..afdae20f 100644 --- a/lib/zepto.waypoints.min.js +++ b/lib/zepto.waypoints.min.js @@ -1,7 +1,7 @@ /*! -Waypoints - 2.0.5 +Waypoints - 3.0.0 Copyright © 2011-2014 Caleb Troughton Licensed under the MIT license. https://github.com/imakewebthings/waypoints/blog/master/licenses.txt */ -!function(){"use strict";function t(i){if(!i)throw new Error("No options passed to Waypoint constructor");if(!i.element)throw new Error("No element option passed to Waypoint constructor");if(!i.handler)throw new Error("No handler option passed to Waypoint constructor");this.key="waypoint-"+e,this.options=t.Adapter.extend({},t.defaults,i),this.element=this.options.element,this.adapter=new t.Adapter(this.element),this.callback=i.handler,this.axis=this.options.horizontal?"horizontal":"vertical",this.enabled=this.options.enabled,this.triggerPoint=null,this.group=t.Group.findOrCreate({name:this.options.group,axis:this.axis}),this.context=t.Context.findOrCreateByElement(this.options.context),t.offsetAliases[this.options.offset]&&(this.options.offset=t.offsetAliases[this.options.offset]),this.group.add(this),this.context.add(this),o[this.key]=this,e+=1}var e=0,o={};t.prototype.queueTrigger=function(t){this.group.queueTrigger(this,t)},t.prototype.trigger=function(t){this.enabled&&this.callback&&this.callback.apply(this,t)},t.prototype.destroy=function(){this.context.remove(this),this.group.remove(this),delete o[this.key]},t.prototype.disable=function(){return this.enabled=!1,this},t.prototype.enable=function(){return this.context.refresh(),this.enabled=!0,this},t.prototype.next=function(){return this.group.next(this)},t.prototype.previous=function(){return this.group.previous(this)},t.destroyAll=function(){var t=[];for(var e in o)t.push(o[e]);for(var i=0,n=t.length;n>i;i++)t[i].destroy()},t.refreshAll=function(){t.Context.refreshAll()},t.viewportHeight=function(){return window.innerHeight||document.documentElement.clientHeight},t.viewportWidth=function(){return document.documentElement.clientWidth},t.adapters=[],t.defaults={context:window,continuous:!0,enabled:!0,group:"default",horizontal:!1,offset:0},t.offsetAliases={"bottom-in-view":function(){return this.context.innerHeight()-this.adapter.outerHeight()},"right-in-view":function(){return this.context.innerWidth()-this.adapter.outerWidth()}},window.Waypoint=t}(),function(){"use strict";function t(t){window.setTimeout(t,1e3/60)}function e(t){this.element=t,this.Adapter=n.Adapter,this.adapter=new this.Adapter(t),this.key="waypoint-context-"+o,this.didScroll=!1,this.didResize=!1,this.oldScroll={x:this.adapter.scrollLeft(),y:this.adapter.scrollTop()},this.waypoints={vertical:{},horizontal:{}},t.waypointContextKey=this.key,i[t.waypointContextKey]=this,o+=1,this.createThrottledScrollHandler(),this.createThrottledResizeHandler()}var o=0,i={},n=window.Waypoint,r=window.requestAnimationFrame||window.mozRequestAnimationFrame||window.webkitRequestAnimationFrame||t,s=window.onload;e.prototype.add=function(t){var e=t.options.horizontal?"horizontal":"vertical";this.waypoints[e][t.key]=t,this.refresh()},e.prototype.checkEmpty=function(){var t=this.Adapter.isEmptyObject(this.waypoints.horizontal),e=this.Adapter.isEmptyObject(this.waypoints.vertical);t&&e&&(this.adapter.off(".waypoints"),delete i[this.key])},e.prototype.createThrottledResizeHandler=function(){function t(){e.handleResize(),e.didResize=!1}var e=this;this.adapter.on("resize.waypoints",function(){e.didResize||(e.didResize=!0,r(t))})},e.prototype.createThrottledScrollHandler=function(){function t(){e.handleScroll(),e.didScroll=!1}var e=this;this.adapter.on("scroll.waypoints",function(){(!e.didScroll||n.isTouch)&&(e.didScroll=!0,r(t))})},e.prototype.handleResize=function(){n.Context.refreshAll()},e.prototype.handleScroll=function(){var t={},e={horizontal:{newScroll:this.adapter.scrollLeft(),oldScroll:this.oldScroll.x,forward:"right",backward:"left"},vertical:{newScroll:this.adapter.scrollTop(),oldScroll:this.oldScroll.y,forward:"down",backward:"up"}};for(var o in e){var i=e[o],n=i.newScroll>i.oldScroll,r=n?i.forward:i.backward;for(var s in this.waypoints[o]){var a=this.waypoints[o][s],l=i.oldScroll=a.triggerPoint,p=l&&h,c=!l&&!h;(p||c)&&(a.queueTrigger(r),t[a.group.id]=a.group)}}for(var u in t)t[u].flushTriggers();this.oldScroll={x:e.horizontal.newScroll,y:e.vertical.newScroll}},e.prototype.innerHeight=function(){return this.element===this.element.window?n.viewportHeight():this.adapter.innerHeight()},e.prototype.remove=function(t){delete this.waypoints[t.axis][t.key],this.checkEmpty()},e.prototype.innerWidth=function(){return this.element===this.element.window?n.viewportWidth():this.adapter.innerWidth()},e.prototype.destroy=function(){var t=[];for(var e in this.waypoints)for(var o in this.waypoints[e])t.push(this.waypoints[e][o]);for(var i=0,n=t.length;n>i;i++)t[i].destroy()},e.prototype.refresh=function(){var t,e=this.element===this.element.window,o=this.adapter.offset(),i={};this.handleScroll(),t={horizontal:{contextOffset:e?0:o.left,contextScroll:e?0:this.oldScroll.x,contextDimension:this.innerWidth(),oldScroll:this.oldScroll.x,forward:"right",backward:"left",offsetProp:"left"},vertical:{contextOffset:e?0:o.top,contextScroll:e?0:this.oldScroll.y,contextDimension:this.innerHeight(),oldScroll:this.oldScroll.y,forward:"down",backward:"up",offsetProp:"top"}};for(var n in t){var r=t[n];for(var s in this.waypoints[n]){var a,l,h,p,c,u=this.waypoints[n][s],d=u.options.offset,f=u.triggerPoint,w=0,y=null==f;u.element!==u.element.window&&(w=u.adapter.offset()[r.offsetProp]),"function"==typeof d?d=d.apply(u):"string"==typeof d&&(d=parseFloat(d),u.options.offset.indexOf("%")>-1&&(d=Math.ceil(r.contextDimension*d/100))),a=r.contextScroll-r.contextOffset,u.triggerPoint=w+a-d,l=f=r.oldScroll,p=l&&h,c=!l&&!h,!y&&p?(u.queueTrigger(r.backward),i[u.group.id]=u.group):!y&&c?(u.queueTrigger(r.forward),i[u.group.id]=u.group):y&&r.oldScroll>=u.triggerPoint&&(u.queueTrigger(r.forward),i[u.group.id]=u.group)}}for(var g in i)i[g].flushTriggers();return this},e.findOrCreateByElement=function(t){return e.findByElement(t)||new e(t)},e.refreshAll=function(){for(var t in i)i[t].refresh()},e.findByElement=function(t){return i[t.waypointContextKey]},window.onload=function(){oldWindowOnLoad&&s(),e.refreshAll()},n.Context=e}(),function(){"use strict";function t(t,e){return t.triggerPoint-e.triggerPoint}function e(t,e){return e.triggerPoint-t.triggerPoint}function o(t){this.name=t.name,this.axis=t.axis,this.id=this.name+"-"+this.axis,this.waypoints=[],this.clearTriggerQueues(),i[this.axis][this.name]=this}var i={vertical:{},horizontal:{}},n=window.Waypoint;o.prototype.add=function(t){this.waypoints.push(t)},o.prototype.clearTriggerQueues=function(){this.triggerQueues={up:[],down:[],left:[],right:[]}},o.prototype.flushTriggers=function(){for(var o in this.triggerQueues){var i=this.triggerQueues[o],n="up"===o||"left"===o;i.sort(n?e:t);for(var r=0,s=i.length;s>r;r+=1){var a=i[r];(a.options.continuous||r===i.length-1)&&a.trigger([o])}}this.clearTriggerQueues()},o.prototype.next=function(e){this.waypoints.sort(t);var o=n.Adapter.inArray(e,this.waypoints),i=o===this.waypoints.length-1;return i?null:this.waypoints[o+1]},o.prototype.previous=function(e){this.waypoints.sort(t);var o=n.Adapter.inArray(e,this.waypoints);return o?this.waypoints[o-1]:null},o.prototype.queueTrigger=function(t,e){this.triggerQueues[e].push(t)},o.prototype.remove=function(t){var e=n.Adapter.inArray(t,this.waypoints);e>-1&&this.waypoints.splice(e,1)},o.prototype.first=function(){return this.waypoints[0]},o.prototype.last=function(){return this.waypoints[this.waypoints.length-1]},o.findOrCreate=function(t){return i[t.axis][t.name]||new o(t)},n.Group=o}(),function(){"use strict";function t(t){this.element=t,this.$element=e(t)}var e=window.Zepto,o=window.Waypoint;e.each(["off","on","scrollLeft","scrollTop"],function(e,o){t.prototype[o]=function(){var t=Array.prototype.slice.call(arguments);return this.$element[o].apply(this.$element,t)}}),t.prototype.offset=function(){return this.element!==this.element.window?this.$element.offset():void 0},e.each(["width","height"],function(o,i){function n(t,o){return function(t){var n=this.$element,r=n[i](),s={width:["left","right"],height:["top","bottom"]};return e.each(s[i],function(e,i){r+=parseInt(n.css("padding-"+i),10),o&&(r+=parseInt(n.css("border-"+i+"-width"),10)),t&&(r+=parseInt(n.css("margin-"+i),10))}),r}}var r=e.camelCase("inner-"+i),s=e.camelCase("outer-"+i);t.prototype[r]=n(!1),t.prototype[s]=n(!0)}),e.each(["extend","inArray"],function(o,i){t[i]=e[i]}),t.isEmptyObject=function(t){for(var e in t)return!1;return!0},o.adapters.push({name:"zepto",Adapter:t}),o.Adapter=t}(),function(){"use strict";function t(t){return function(){var o=[],i=arguments[0];return t.isFunction(arguments[0])&&(i=t.extend({},arguments[1]),i.handler=arguments[0]),this.each(function(){var n=t.extend({},i,{element:this});"string"==typeof n.context&&(n.context=t(this).closest(n.context)[0]),o.push(new e(n))}),o}}var e=window.Waypoint;window.jQuery&&(window.jQuery.fn.waypoint=t(window.jQuery)),window.Zepto&&(window.Zepto.fn.waypoint=t(window.Zepto))}(); \ No newline at end of file +!function(){"use strict";function t(i){if(!i)throw new Error("No options passed to Waypoint constructor");if(!i.element)throw new Error("No element option passed to Waypoint constructor");if(!i.handler)throw new Error("No handler option passed to Waypoint constructor");this.key="waypoint-"+e,this.options=t.Adapter.extend({},t.defaults,i),this.element=this.options.element,this.adapter=new t.Adapter(this.element),this.callback=i.handler,this.axis=this.options.horizontal?"horizontal":"vertical",this.enabled=this.options.enabled,this.triggerPoint=null,this.group=t.Group.findOrCreate({name:this.options.group,axis:this.axis}),this.context=t.Context.findOrCreateByElement(this.options.context),t.offsetAliases[this.options.offset]&&(this.options.offset=t.offsetAliases[this.options.offset]),this.group.add(this),this.context.add(this),o[this.key]=this,e+=1}var e=0,o={};t.prototype.queueTrigger=function(t){this.group.queueTrigger(this,t)},t.prototype.trigger=function(t){this.enabled&&this.callback&&this.callback.apply(this,t)},t.prototype.destroy=function(){this.context.remove(this),this.group.remove(this),delete o[this.key]},t.prototype.disable=function(){return this.enabled=!1,this},t.prototype.enable=function(){return this.context.refresh(),this.enabled=!0,this},t.prototype.next=function(){return this.group.next(this)},t.prototype.previous=function(){return this.group.previous(this)},t.destroyAll=function(){var t=[];for(var e in o)t.push(o[e]);for(var i=0,n=t.length;n>i;i++)t[i].destroy()},t.refreshAll=function(){t.Context.refreshAll()},t.viewportHeight=function(){return window.innerHeight||document.documentElement.clientHeight},t.viewportWidth=function(){return document.documentElement.clientWidth},t.adapters=[],t.defaults={context:window,continuous:!0,enabled:!0,group:"default",horizontal:!1,offset:0},t.offsetAliases={"bottom-in-view":function(){return this.context.innerHeight()-this.adapter.outerHeight()},"right-in-view":function(){return this.context.innerWidth()-this.adapter.outerWidth()}},window.Waypoint=t}(),function(){"use strict";function t(t){window.setTimeout(t,1e3/60)}function e(t){this.element=t,this.Adapter=n.Adapter,this.adapter=new this.Adapter(t),this.key="waypoint-context-"+o,this.didScroll=!1,this.didResize=!1,this.oldScroll={x:this.adapter.scrollLeft(),y:this.adapter.scrollTop()},this.waypoints={vertical:{},horizontal:{}},t.waypointContextKey=this.key,i[t.waypointContextKey]=this,o+=1,this.createThrottledScrollHandler(),this.createThrottledResizeHandler()}var o=0,i={},n=window.Waypoint,r=window.requestAnimationFrame||window.mozRequestAnimationFrame||window.webkitRequestAnimationFrame||t,s=window.onload;e.prototype.add=function(t){var e=t.options.horizontal?"horizontal":"vertical";this.waypoints[e][t.key]=t,this.refresh()},e.prototype.checkEmpty=function(){var t=this.Adapter.isEmptyObject(this.waypoints.horizontal),e=this.Adapter.isEmptyObject(this.waypoints.vertical);t&&e&&(this.adapter.off(".waypoints"),delete i[this.key])},e.prototype.createThrottledResizeHandler=function(){function t(){e.handleResize(),e.didResize=!1}var e=this;this.adapter.on("resize.waypoints",function(){e.didResize||(e.didResize=!0,r(t))})},e.prototype.createThrottledScrollHandler=function(){function t(){e.handleScroll(),e.didScroll=!1}var e=this;this.adapter.on("scroll.waypoints",function(){(!e.didScroll||n.isTouch)&&(e.didScroll=!0,r(t))})},e.prototype.handleResize=function(){n.Context.refreshAll()},e.prototype.handleScroll=function(){var t={},e={horizontal:{newScroll:this.adapter.scrollLeft(),oldScroll:this.oldScroll.x,forward:"right",backward:"left"},vertical:{newScroll:this.adapter.scrollTop(),oldScroll:this.oldScroll.y,forward:"down",backward:"up"}};for(var o in e){var i=e[o],n=i.newScroll>i.oldScroll,r=n?i.forward:i.backward;for(var s in this.waypoints[o]){var a=this.waypoints[o][s],l=i.oldScroll=a.triggerPoint,p=l&&h,c=!l&&!h;(p||c)&&(a.queueTrigger(r),t[a.group.id]=a.group)}}for(var u in t)t[u].flushTriggers();this.oldScroll={x:e.horizontal.newScroll,y:e.vertical.newScroll}},e.prototype.innerHeight=function(){return this.element===this.element.window?n.viewportHeight():this.adapter.innerHeight()},e.prototype.remove=function(t){delete this.waypoints[t.axis][t.key],this.checkEmpty()},e.prototype.innerWidth=function(){return this.element===this.element.window?n.viewportWidth():this.adapter.innerWidth()},e.prototype.destroy=function(){var t=[];for(var e in this.waypoints)for(var o in this.waypoints[e])t.push(this.waypoints[e][o]);for(var i=0,n=t.length;n>i;i++)t[i].destroy()},e.prototype.refresh=function(){var t,e=this.element===this.element.window,o=this.adapter.offset(),i={};this.handleScroll(),t={horizontal:{contextOffset:e?0:o.left,contextScroll:e?0:this.oldScroll.x,contextDimension:this.innerWidth(),oldScroll:this.oldScroll.x,forward:"right",backward:"left",offsetProp:"left"},vertical:{contextOffset:e?0:o.top,contextScroll:e?0:this.oldScroll.y,contextDimension:this.innerHeight(),oldScroll:this.oldScroll.y,forward:"down",backward:"up",offsetProp:"top"}};for(var n in t){var r=t[n];for(var s in this.waypoints[n]){var a,l,h,p,c,u=this.waypoints[n][s],d=u.options.offset,f=u.triggerPoint,w=0,y=null==f;u.element!==u.element.window&&(w=u.adapter.offset()[r.offsetProp]),"function"==typeof d?d=d.apply(u):"string"==typeof d&&(d=parseFloat(d),u.options.offset.indexOf("%")>-1&&(d=Math.ceil(r.contextDimension*d/100))),a=r.contextScroll-r.contextOffset,u.triggerPoint=w+a-d,l=f=r.oldScroll,p=l&&h,c=!l&&!h,!y&&p?(u.queueTrigger(r.backward),i[u.group.id]=u.group):!y&&c?(u.queueTrigger(r.forward),i[u.group.id]=u.group):y&&r.oldScroll>=u.triggerPoint&&(u.queueTrigger(r.forward),i[u.group.id]=u.group)}}for(var g in i)i[g].flushTriggers();return this},e.findOrCreateByElement=function(t){return e.findByElement(t)||new e(t)},e.refreshAll=function(){for(var t in i)i[t].refresh()},e.findByElement=function(t){return i[t.waypointContextKey]},window.onload=function(){s&&s(),e.refreshAll()},n.Context=e}(),function(){"use strict";function t(t,e){return t.triggerPoint-e.triggerPoint}function e(t,e){return e.triggerPoint-t.triggerPoint}function o(t){this.name=t.name,this.axis=t.axis,this.id=this.name+"-"+this.axis,this.waypoints=[],this.clearTriggerQueues(),i[this.axis][this.name]=this}var i={vertical:{},horizontal:{}},n=window.Waypoint;o.prototype.add=function(t){this.waypoints.push(t)},o.prototype.clearTriggerQueues=function(){this.triggerQueues={up:[],down:[],left:[],right:[]}},o.prototype.flushTriggers=function(){for(var o in this.triggerQueues){var i=this.triggerQueues[o],n="up"===o||"left"===o;i.sort(n?e:t);for(var r=0,s=i.length;s>r;r+=1){var a=i[r];(a.options.continuous||r===i.length-1)&&a.trigger([o])}}this.clearTriggerQueues()},o.prototype.next=function(e){this.waypoints.sort(t);var o=n.Adapter.inArray(e,this.waypoints),i=o===this.waypoints.length-1;return i?null:this.waypoints[o+1]},o.prototype.previous=function(e){this.waypoints.sort(t);var o=n.Adapter.inArray(e,this.waypoints);return o?this.waypoints[o-1]:null},o.prototype.queueTrigger=function(t,e){this.triggerQueues[e].push(t)},o.prototype.remove=function(t){var e=n.Adapter.inArray(t,this.waypoints);e>-1&&this.waypoints.splice(e,1)},o.prototype.first=function(){return this.waypoints[0]},o.prototype.last=function(){return this.waypoints[this.waypoints.length-1]},o.findOrCreate=function(t){return i[t.axis][t.name]||new o(t)},n.Group=o}(),function(){"use strict";function t(t){this.element=t,this.$element=e(t)}var e=window.Zepto,o=window.Waypoint;e.each(["off","on","scrollLeft","scrollTop"],function(e,o){t.prototype[o]=function(){var t=Array.prototype.slice.call(arguments);return this.$element[o].apply(this.$element,t)}}),t.prototype.offset=function(){return this.element!==this.element.window?this.$element.offset():void 0},e.each(["width","height"],function(o,i){function n(t,o){return function(t){var n=this.$element,r=n[i](),s={width:["left","right"],height:["top","bottom"]};return e.each(s[i],function(e,i){r+=parseInt(n.css("padding-"+i),10),o&&(r+=parseInt(n.css("border-"+i+"-width"),10)),t&&(r+=parseInt(n.css("margin-"+i),10))}),r}}var r=e.camelCase("inner-"+i),s=e.camelCase("outer-"+i);t.prototype[r]=n(!1),t.prototype[s]=n(!0)}),e.each(["extend","inArray"],function(o,i){t[i]=e[i]}),t.isEmptyObject=function(t){for(var e in t)return!1;return!0},o.adapters.push({name:"zepto",Adapter:t}),o.Adapter=t}(),function(){"use strict";function t(t){return function(){var o=[],i=arguments[0];return t.isFunction(arguments[0])&&(i=t.extend({},arguments[1]),i.handler=arguments[0]),this.each(function(){var n=t.extend({},i,{element:this});"string"==typeof n.context&&(n.context=t(this).closest(n.context)[0]),o.push(new e(n))}),o}}var e=window.Waypoint;window.jQuery&&(window.jQuery.fn.waypoint=t(window.jQuery)),window.Zepto&&(window.Zepto.fn.waypoint=t(window.Zepto))}(); \ No newline at end of file diff --git a/package.json b/package.json index 392e3844..37424513 100644 --- a/package.json +++ b/package.json @@ -1,11 +1,14 @@ { "name": "jquery-waypoints", - "version": "2.0.5", + "version": "3.0.0", "author": "Caleb Troughton ", "description": "A jQuery plugin that makes it easy to execute a function whenever you scroll to an element.", "scripts": { + "build": "gulp build", + "gulp": "gulp", "test": "testem ci", - "tdd": "testem" + "tdd": "testem", + "watch": "gulp watch" }, "repository": { "type": "git", diff --git a/src/context.js b/src/context.js index 81e18292..2695cf65 100644 --- a/src/context.js +++ b/src/context.js @@ -279,7 +279,7 @@ } window.onload = function() { - if (oldWindowOnLoad) { + if (oldWindowLoad) { oldWindowLoad() } Context.refreshAll() From 1b64b7eb3c42ac51d5305b9b26c7e70a9a3fdceb Mon Sep 17 00:00:00 2001 From: imakewebthings Date: Thu, 18 Dec 2014 19:41:17 -0800 Subject: [PATCH 47/98] README typo --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index c494f75b..f45c65dc 100644 --- a/README.md +++ b/README.md @@ -26,7 +26,7 @@ In addition to the normal Waypoints script, extensions exist to make common UI p ## Contributing -If you want to report a Waypoints bug or contribute code to the library, please read the [Contributing Guidelines](https://github.com/imakewebthings/waypoints/blob/master/CONRIBUTING.md). If you need help *using* Waypoints, please do not open an issue. Instead, ask the question on [Stack Overflow](http://stackoverflow.com)and tag it with #jquery-waypoints. Be sure to follow the guidelines for [asking a good question](http://stackoverflow.com/help/how-to-ask). +If you want to report a Waypoints bug or contribute code to the library, please read the [Contributing Guidelines](https://github.com/imakewebthings/waypoints/blob/master/CONRIBUTING.md). If you need help *using* Waypoints, please do not open an issue. Instead, ask the question on [Stack Overflow](http://stackoverflow.com) and tag it with #jquery-waypoints. Be sure to follow the guidelines for [asking a good question](http://stackoverflow.com/help/how-to-ask). ## License From a054e2fa0510f704a184b235354c5b031265f133 Mon Sep 17 00:00:00 2001 From: imakewebthings Date: Thu, 18 Dec 2014 19:53:55 -0800 Subject: [PATCH 48/98] Update changelog for 3.0.0 --- CHANGELOG.md | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 53b206a5..e2e5bb6f 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,15 @@ # Changelog +## v3.0.0 + +- Remove hard jQuery dependency. Create builds for jQuery, Zepto, and no DOM framework. (Issue #282) +- Expose Waypoint and Context classes to instantiation. (Issue #281) +- Add Group class and group option for grouping waypoints. Make continuous option work within these groups. (Issue #264) +- Add Inview shortcut. (Issue #131) +- Extend continuous option to cover refreshes. (Issue #166) +- Throttle resize and scroll handlers using requestAnimationFrame instead of a set millisecond timeout. Fallback to the old 60 FPS setTimeout throttle for unsupported browsers. (Issue #242) +- Remove all traces of CoffeeScript. + ## v2.0.5 - Allow sticky users to define which direction the stuck class shold be applied. (Issue #192) From 528bc3367c92531ae8bcc2c7bc532b139cb1a015 Mon Sep 17 00:00:00 2001 From: imakewebthings Date: Thu, 18 Dec 2014 20:17:14 -0800 Subject: [PATCH 49/98] Contribution guidelines --- CONTRIBUTING.md | 31 +++++++++++++++++++++++++++++++ 1 file changed, 31 insertions(+) create mode 100644 CONTRIBUTING.md diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md new file mode 100644 index 00000000..8e6e9b18 --- /dev/null +++ b/CONTRIBUTING.md @@ -0,0 +1,31 @@ +# Opening an Issue + +The GitHub issue tracker is exclusively for opening demonstrable bugs with the library or for discussing/implementing enhancements. If you need general help with Waypoints try searching through existing closed tickets, searching through the [#jquery-waypoints](http://stackoverflow.com/questions/tagged/jquery-waypoints) tag on StackOverflow, or asking your question there using that tag. If you do ask a question on StackOverflow, please follow the guidelines for [asking a good question](http://stackoverflow.com/help/how-to-ask). + +If you're opening a ticket for a bug: + +- Give a clear explanation of the bug. +- Try to provide a link to a [JSFiddle](http://jsfiddle.net/) or [CodePen](http://codepen.io/) or similar reduced test case. +- If you cannot provide a reduced test case, please provide a link to a live site demonstrating your bug and include in the ticket the relevant Waypoints code. + +If you're interested in discussing a possible new feature: + +- Search closed tickets for discussions that may have already occurred. +- Open a ticket and let's talk! + +# Pull Requests + +- Please send the pull request against the master branch. +- Note any tickets that the pull request addresses. +- Add any necessary tests (see below). +- Follow the coding style of the current codebase. + +# Tests + +Tests are written in [Jasmine](http://jasmine.github.io/) and run through the [testem](https://github.com/airportyh/testem) test runner. To run them locally you'll need to: + +- Install, if you haven't already: [PhantomJS](http://phantomjs.org/), node, and [Bower](bower.io). +- `npm install` +- `bower install` + +You can then run the tests one time by running `npm test`, or enter TDD mode by running `npm run tdd`. From bb7a75047066901ffe964e21a482697412f2f254 Mon Sep 17 00:00:00 2001 From: imakewebthings Date: Thu, 18 Dec 2014 21:41:10 -0800 Subject: [PATCH 50/98] More changes logged --- CHANGELOG.md | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index e2e5bb6f..f64693f7 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -3,11 +3,14 @@ ## v3.0.0 - Remove hard jQuery dependency. Create builds for jQuery, Zepto, and no DOM framework. (Issue #282) -- Expose Waypoint and Context classes to instantiation. (Issue #281) -- Add Group class and group option for grouping waypoints. Make continuous option work within these groups. (Issue #264) +- Expose `Waypoint` and `Context` classes. (Issue #281) +- Add `Group` class and `group` option for grouping waypoints. Make `continuous` option work within these groups. (Issue #264) - Add Inview shortcut. (Issue #131) -- Extend continuous option to cover refreshes. (Issue #166) -- Throttle resize and scroll handlers using requestAnimationFrame instead of a set millisecond timeout. Fallback to the old 60 FPS setTimeout throttle for unsupported browsers. (Issue #242) +- Extend `continuous` option to cover refreshes. (Issue #166) +- Throttle resize and scroll handlers using `requestAnimationFrame` instead of a set millisecond timeout. Fallback to the old 60 FPS `setTimeout` throttle for unsupported browsers. (Issue #242) +- Add debugging script for diagnosing common problems. +- Remove `triggerOnce` option. +- Add `viewportWidth` utility method. - Remove all traces of CoffeeScript. ## v2.0.5 From 26d20aa0dcb166231ed3beefd18584c43ca46414 Mon Sep 17 00:00:00 2001 From: imakewebthings Date: Fri, 19 Dec 2014 10:16:03 -0800 Subject: [PATCH 51/98] Remove old shortcut scripts --- lib/waypoints-infinite.js | 70 --------------------------------------- lib/waypoints-sticky.js | 65 ------------------------------------ 2 files changed, 135 deletions(-) delete mode 100644 lib/waypoints-infinite.js delete mode 100644 lib/waypoints-sticky.js diff --git a/lib/waypoints-infinite.js b/lib/waypoints-infinite.js deleted file mode 100644 index 9b5b3f42..00000000 --- a/lib/waypoints-infinite.js +++ /dev/null @@ -1,70 +0,0 @@ -// Generated by CoffeeScript 1.6.2 -/* -Infinite Scroll Shortcut for jQuery Waypoints - v2.0.5 -Copyright (c) 2011-2014 Caleb Troughton -Licensed under the MIT license. -https://github.com/imakewebthings/jquery-waypoints/blob/master/licenses.txt -*/ - - -(function() { - (function(root, factory) { - if (typeof define === 'function' && define.amd) { - return define(['jquery', 'waypoints'], factory); - } else { - return factory(root.jQuery); - } - })(window, function($) { - var defaults; - - defaults = { - container: 'auto', - items: '.infinite-item', - more: '.infinite-more-link', - offset: 'bottom-in-view', - loadingClass: 'infinite-loading', - onBeforePageLoad: $.noop, - onAfterPageLoad: $.noop - }; - return $.waypoints('extendFn', 'infinite', function(options) { - var $container, opts; - - opts = $.extend({}, $.fn.waypoint.defaults, defaults, options); - if ($(opts.more).length === 0) { - return this; - } - $container = opts.container === 'auto' ? this : $(opts.container); - opts.handler = function(direction) { - var $this; - - if (direction === 'down' || direction === 'right') { - $this = $(this); - opts.onBeforePageLoad(); - $this.waypoint('destroy'); - $container.addClass(opts.loadingClass); - return $.get($(opts.more).attr('href'), function(data) { - var $data, $more, $newMore, fn; - - $data = $($.parseHTML(data)); - $more = $(opts.more); - $newMore = $data.find(opts.more); - $container.append($data.find(opts.items)); - $container.removeClass(opts.loadingClass); - if ($newMore.length) { - $more.replaceWith($newMore); - fn = function() { - return $this.waypoint(opts); - }; - setTimeout(fn, 0); - } else { - $more.remove(); - } - return opts.onAfterPageLoad(); - }); - } - }; - return this.waypoint(opts); - }); - }); - -}).call(this); diff --git a/lib/waypoints-sticky.js b/lib/waypoints-sticky.js deleted file mode 100644 index 1befd723..00000000 --- a/lib/waypoints-sticky.js +++ /dev/null @@ -1,65 +0,0 @@ -// Generated by CoffeeScript 1.6.2 -/* -Sticky Elements Shortcut for jQuery Waypoints - v2.0.5 -Copyright (c) 2011-2014 Caleb Troughton -Licensed under the MIT license. -https://github.com/imakewebthings/jquery-waypoints/blob/master/licenses.txt -*/ - - -(function() { - (function(root, factory) { - if (typeof define === 'function' && define.amd) { - return define(['jquery', 'waypoints'], factory); - } else { - return factory(root.jQuery); - } - })(window, function($) { - var defaults, wrap; - - defaults = { - wrapper: '
', - stuckClass: 'stuck', - direction: 'down right' - }; - wrap = function($elements, options) { - var $parent; - - $elements.wrap(options.wrapper); - $parent = $elements.parent(); - return $parent.data('isWaypointStickyWrapper', true); - }; - $.waypoints('extendFn', 'sticky', function(opt) { - var $wrap, options, originalHandler; - - options = $.extend({}, $.fn.waypoint.defaults, defaults, opt); - $wrap = wrap(this, options); - originalHandler = options.handler; - options.handler = function(direction) { - var $sticky, shouldBeStuck; - - $sticky = $(this).children(':first'); - shouldBeStuck = options.direction.indexOf(direction) !== -1; - $sticky.toggleClass(options.stuckClass, shouldBeStuck); - $wrap.height(shouldBeStuck ? $sticky.outerHeight() : ''); - if (originalHandler != null) { - return originalHandler.call(this, direction); - } - }; - $wrap.waypoint(options); - return this.data('stuckClass', options.stuckClass); - }); - return $.waypoints('extendFn', 'unsticky', function() { - var $parent; - - $parent = this.parent(); - if (!$parent.data('isWaypointStickyWrapper')) { - return this; - } - $parent.waypoint('destroy'); - this.unwrap(); - return this.removeClass(this.data('stuckClass')); - }); - }); - -}).call(this); From d21e1690bb5f407de4bf0bd9f08d967cf2027424 Mon Sep 17 00:00:00 2001 From: imakewebthings Date: Sat, 20 Dec 2014 12:52:29 -0800 Subject: [PATCH 52/98] Add semicolon to end of built files, #353 --- bower.json | 2 +- gulpfile.js | 4 ++++ lib/jquery.waypoints.js | 1 + lib/noframework.waypoints.js | 1 + lib/shortcuts/infinite.js | 1 + lib/shortcuts/inview.js | 1 + lib/shortcuts/sticky.js | 1 + lib/waypoints.debug.js | 1 + lib/zepto.waypoints.js | 1 + package.json | 5 +++-- 10 files changed, 15 insertions(+), 3 deletions(-) diff --git a/bower.json b/bower.json index ec514e75..cc40623f 100644 --- a/bower.json +++ b/bower.json @@ -1,6 +1,6 @@ { "name": "waypoints", - "version": "3.0.0", + "version": "3.0.1", "main": "lib/noframework.waypoints.min.js", "description": "Easily execute a function when you scroll to an element.", "ignore": [ diff --git a/gulpfile.js b/gulpfile.js index 33d35d31..36944665 100644 --- a/gulpfile.js +++ b/gulpfile.js @@ -4,6 +4,7 @@ var concat = require('gulp-concat') var uglify = require('gulp-uglify') var rename = require('gulp-rename') var header = require('gulp-header') +var footer = require('gulp-footer') var tap = require('gulp-tap') var merge = require('merge-stream') var pkg = require('./package.json') @@ -45,6 +46,7 @@ gulp.task('build-core', function() { return gulp.src(sources) .pipe(concat(adapter + '.waypoints.js', { newLine: ';' })) .pipe(header(fileHeader('Waypoints'))) + .pipe(footer(';')) .pipe(gulp.dest('lib/')) .pipe(rename(adapter + '.waypoints.min.js')) .pipe(uglify({ @@ -66,6 +68,7 @@ gulp.task('build-shortcuts', function() { file.contents ]) })) + .pipe(footer(';')) .pipe(gulp.dest('lib/shortcuts/')) .pipe(rename(function(path) { path.basename += '.min' @@ -82,6 +85,7 @@ gulp.task('build-debug', function() { ]) .pipe(rename('waypoints.debug.js')) .pipe(header(fileHeader('Waypoints Debug'))) + .pipe(footer(';')) .pipe(gulp.dest('lib/')) }) diff --git a/lib/jquery.waypoints.js b/lib/jquery.waypoints.js index 106a8eb3..5487c82b 100644 --- a/lib/jquery.waypoints.js +++ b/lib/jquery.waypoints.js @@ -617,3 +617,4 @@ https://github.com/imakewebthings/waypoints/blog/master/licenses.txt window.Zepto.fn.waypoint = createExtension(window.Zepto) } }()) +; \ No newline at end of file diff --git a/lib/noframework.waypoints.js b/lib/noframework.waypoints.js index 90cf14bf..502379c1 100644 --- a/lib/noframework.waypoints.js +++ b/lib/noframework.waypoints.js @@ -713,3 +713,4 @@ https://github.com/imakewebthings/waypoints/blog/master/licenses.txt }) Waypoint.Adapter = NoFrameworkAdapter }()) +; \ No newline at end of file diff --git a/lib/shortcuts/infinite.js b/lib/shortcuts/infinite.js index 1e05ae84..c1470e11 100644 --- a/lib/shortcuts/infinite.js +++ b/lib/shortcuts/infinite.js @@ -78,3 +78,4 @@ https://github.com/imakewebthings/waypoints/blog/master/licenses.txt Waypoint.Infinite = Infinite }()) +; \ No newline at end of file diff --git a/lib/shortcuts/inview.js b/lib/shortcuts/inview.js index 87635fe7..cd707e5e 100644 --- a/lib/shortcuts/inview.js +++ b/lib/shortcuts/inview.js @@ -100,3 +100,4 @@ https://github.com/imakewebthings/waypoints/blog/master/licenses.txt Waypoint.Inview = Inview }()) +; \ No newline at end of file diff --git a/lib/shortcuts/sticky.js b/lib/shortcuts/sticky.js index 759132b1..96a43134 100644 --- a/lib/shortcuts/sticky.js +++ b/lib/shortcuts/sticky.js @@ -62,3 +62,4 @@ https://github.com/imakewebthings/waypoints/blog/master/licenses.txt Waypoint.Sticky = Sticky }()) +; \ No newline at end of file diff --git a/lib/waypoints.debug.js b/lib/waypoints.debug.js index 1c1f9865..2f89f370 100644 --- a/lib/waypoints.debug.js +++ b/lib/waypoints.debug.js @@ -39,3 +39,4 @@ https://github.com/imakewebthings/waypoints/blog/master/licenses.txt checkWaypointStyles() }()) +; \ No newline at end of file diff --git a/lib/zepto.waypoints.js b/lib/zepto.waypoints.js index 1ba79fc3..59918448 100644 --- a/lib/zepto.waypoints.js +++ b/lib/zepto.waypoints.js @@ -660,3 +660,4 @@ https://github.com/imakewebthings/waypoints/blog/master/licenses.txt window.Zepto.fn.waypoint = createExtension(window.Zepto) } }()) +; \ No newline at end of file diff --git a/package.json b/package.json index 37424513..8144716c 100644 --- a/package.json +++ b/package.json @@ -1,11 +1,11 @@ { "name": "jquery-waypoints", - "version": "3.0.0", + "version": "3.0.1", "author": "Caleb Troughton ", "description": "A jQuery plugin that makes it easy to execute a function whenever you scroll to an element.", "scripts": { "build": "gulp build", - "gulp": "gulp", + "start": "gulp", "test": "testem ci", "tdd": "testem", "watch": "gulp watch" @@ -23,6 +23,7 @@ "gulp": "^3.6.2", "gulp-concat": "^2.2.0", "gulp-eslint": "^0.1.7", + "gulp-footer": "^1.0.5", "gulp-header": "^1.0.2", "gulp-rename": "^1.2.0", "gulp-tap": "^0.1.1", From 79903c88ed2564b6df6fb850e8430f1f68fa7f1e Mon Sep 17 00:00:00 2001 From: imakewebthings Date: Sat, 20 Dec 2014 12:59:37 -0800 Subject: [PATCH 53/98] 3.0.1 changelog --- CHANGELOG.md | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index f64693f7..28a19da4 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,9 @@ # Changelog +## v3.0.1 + +- Add semicolons to the end of built files to aid in clean concatenation. (Issue #353) + ## v3.0.0 - Remove hard jQuery dependency. Create builds for jQuery, Zepto, and no DOM framework. (Issue #282) From 815ccb10dad4b309246174908ac1c0bea04f8aa2 Mon Sep 17 00:00:00 2001 From: imakewebthings Date: Mon, 29 Dec 2014 12:31:20 -0800 Subject: [PATCH 54/98] Fix getting started link in README --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index f45c65dc..fb88ab58 100644 --- a/README.md +++ b/README.md @@ -11,7 +11,7 @@ var waypoint = new Waypoint({ }) ``` -If you're new to Waypoints, check out the [Getting Started](http://imakewebthings.com/guides/get-started) guide. +If you're new to Waypoints, check out the [Getting Started](http://imakewebthings.com/waypoints/guides/getting-started) guide. [Read the full documentation](http://imakewebthings.com/waypoints/api/waypoint) for more details on usage and customization. From 7871409f57e84b8e03e9f76230185d808dd98058 Mon Sep 17 00:00:00 2001 From: imakewebthings Date: Mon, 29 Dec 2014 12:34:23 -0800 Subject: [PATCH 55/98] Fix contribution guidelines link typo in README --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index fb88ab58..af573f44 100644 --- a/README.md +++ b/README.md @@ -26,7 +26,7 @@ In addition to the normal Waypoints script, extensions exist to make common UI p ## Contributing -If you want to report a Waypoints bug or contribute code to the library, please read the [Contributing Guidelines](https://github.com/imakewebthings/waypoints/blob/master/CONRIBUTING.md). If you need help *using* Waypoints, please do not open an issue. Instead, ask the question on [Stack Overflow](http://stackoverflow.com) and tag it with #jquery-waypoints. Be sure to follow the guidelines for [asking a good question](http://stackoverflow.com/help/how-to-ask). +If you want to report a Waypoints bug or contribute code to the library, please read the [Contributing Guidelines](https://github.com/imakewebthings/waypoints/blob/master/CONTRIBUTING.md). If you need help *using* Waypoints, please do not open an issue. Instead, ask the question on [Stack Overflow](http://stackoverflow.com) and tag it with #jquery-waypoints. Be sure to follow the guidelines for [asking a good question](http://stackoverflow.com/help/how-to-ask). ## License From 40b4dcba9006e23285879a56243438a675698a65 Mon Sep 17 00:00:00 2001 From: imakewebthings Date: Mon, 29 Dec 2014 14:01:25 -0800 Subject: [PATCH 56/98] Travis CI + unclog an infinite test --- .travis.yml | 3 +++ src/shortcuts/infinite.js | 44 +++++++++++++++++++-------------------- 2 files changed, 24 insertions(+), 23 deletions(-) create mode 100644 .travis.yml diff --git a/.travis.yml b/.travis.yml new file mode 100644 index 00000000..6e5919de --- /dev/null +++ b/.travis.yml @@ -0,0 +1,3 @@ +language: node_js +node_js: + - "0.10" diff --git a/src/shortcuts/infinite.js b/src/shortcuts/infinite.js index 66751143..73277ec1 100644 --- a/src/shortcuts/infinite.js +++ b/src/shortcuts/infinite.js @@ -22,33 +22,31 @@ /* Private */ Infinite.prototype.setupHandler = function() { - this.options.handler = $.proxy(function() { - window.setTimeout($.proxy(function() { - this.options.onBeforePageLoad() - this.destroy() - this.$container.addClass(this.options.loadingClass) + this.options.handler = $.proxy(function(direction) { + this.options.onBeforePageLoad() + this.destroy() + this.$container.addClass(this.options.loadingClass) - $.get($(this.options.more).attr('href'), $.proxy(function(data) { - var $data = $($.parseHTML(data)) - var $newMore = $data.find(this.options.more) + $.get($(this.options.more).attr('href'), $.proxy(function(data) { + var $data = $($.parseHTML(data)) + var $newMore = $data.find(this.options.more) - this.$container.append($data.find(this.options.items)) - this.$container.removeClass(this.options.loadingClass) + this.$container.append($data.find(this.options.items)) + this.$container.removeClass(this.options.loadingClass) - if (!$newMore.length) { - $newMore = $data.filter(this.options.more) - } - if ($newMore.length) { - this.$more.replaceWith($newMore) - this.$more = $newMore - this.waypoint = new Waypoint(this.options) - } - else { - this.$more.remove() - } + if (!$newMore.length) { + $newMore = $data.filter(this.options.more) + } + if ($newMore.length) { + this.$more.replaceWith($newMore) + this.$more = $newMore + this.waypoint = new Waypoint(this.options) + } + else { + this.$more.remove() + } - this.options.onAfterPageLoad() - }, this), 0) + this.options.onAfterPageLoad() }, this)) }, this) } From 85b7b77c09dca852746d19c50b9d339560cfd8fe Mon Sep 17 00:00:00 2001 From: imakewebthings Date: Mon, 29 Dec 2014 14:05:13 -0800 Subject: [PATCH 57/98] Add Travis badge --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index af573f44..1ed12866 100644 --- a/README.md +++ b/README.md @@ -1,6 +1,6 @@ # Waypoints -Waypoints is a library that makes it easy to execute a function whenever you scroll to an element. +Waypoints is a library that makes it easy to execute a function whenever you scroll to an element. ~[Build Status](https://travis-ci.org/imakewebthings/waypoints.svg) ```js var waypoint = new Waypoint({ From ba80ff442f0e66b3a40a06abb36af268872b4118 Mon Sep 17 00:00:00 2001 From: imakewebthings Date: Mon, 29 Dec 2014 14:08:00 -0800 Subject: [PATCH 58/98] Add testem as dev dependency for travis ci --- package.json | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/package.json b/package.json index 8144716c..dd85f2f7 100644 --- a/package.json +++ b/package.json @@ -28,7 +28,8 @@ "gulp-rename": "^1.2.0", "gulp-tap": "^0.1.1", "gulp-uglify": "^0.3.1", - "merge-stream": "^0.1.1" + "merge-stream": "^0.1.1", + "testem": "^0.6.24" }, "license": "MIT" } From 1accdee2c6493fd8a648a6077bfa694c7a662f96 Mon Sep 17 00:00:00 2001 From: imakewebthings Date: Mon, 29 Dec 2014 14:12:28 -0800 Subject: [PATCH 59/98] Bower install in travis before_script --- .travis.yml | 3 +++ 1 file changed, 3 insertions(+) diff --git a/.travis.yml b/.travis.yml index 6e5919de..a094d1a2 100644 --- a/.travis.yml +++ b/.travis.yml @@ -1,3 +1,6 @@ language: node_js node_js: - "0.10" +before_script: + - npm install -g bower + - bower install From 308f1cc6d385ab3e8b465aef2f59a196e99b58d8 Mon Sep 17 00:00:00 2001 From: imakewebthings Date: Mon, 29 Dec 2014 14:51:55 -0800 Subject: [PATCH 60/98] Fix build status typo --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 1ed12866..8c440549 100644 --- a/README.md +++ b/README.md @@ -1,6 +1,6 @@ # Waypoints -Waypoints is a library that makes it easy to execute a function whenever you scroll to an element. ~[Build Status](https://travis-ci.org/imakewebthings/waypoints.svg) +Waypoints is a library that makes it easy to execute a function whenever you scroll to an element. ![Build Status](https://travis-ci.org/imakewebthings/waypoints.svg) ```js var waypoint = new Waypoint({ From 4d694099a3a1ec0b9640ce0638bc08288dd0f0c9 Mon Sep 17 00:00:00 2001 From: sw_double Date: Fri, 9 Jan 2015 18:54:56 +0300 Subject: [PATCH 61/98] Add ability to filter infinite items from data --- src/shortcuts/infinite.js | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/src/shortcuts/infinite.js b/src/shortcuts/infinite.js index 73277ec1..d444a013 100644 --- a/src/shortcuts/infinite.js +++ b/src/shortcuts/infinite.js @@ -31,7 +31,12 @@ var $data = $($.parseHTML(data)) var $newMore = $data.find(this.options.more) - this.$container.append($data.find(this.options.items)) + var $items = $data.find(this.options.items) + if (!$items.length) { + $items = $data.filter(this.options.items) + } + + this.$container.append($items) this.$container.removeClass(this.options.loadingClass) if (!$newMore.length) { From eaff42bf0de9de5a1067947f5d07656a207d98a5 Mon Sep 17 00:00:00 2001 From: imakewebthings Date: Tue, 13 Jan 2015 15:46:16 -0800 Subject: [PATCH 62/98] Remove unused parameter in infinite shortcut --- src/shortcuts/infinite.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/shortcuts/infinite.js b/src/shortcuts/infinite.js index 73277ec1..31e9fe4e 100644 --- a/src/shortcuts/infinite.js +++ b/src/shortcuts/infinite.js @@ -22,7 +22,7 @@ /* Private */ Infinite.prototype.setupHandler = function() { - this.options.handler = $.proxy(function(direction) { + this.options.handler = $.proxy(function() { this.options.onBeforePageLoad() this.destroy() this.$container.addClass(this.options.loadingClass) From 18d0af4f93707488241a7a064f1a59d7e4b5ae0f Mon Sep 17 00:00:00 2001 From: imakewebthings Date: Tue, 13 Jan 2015 17:10:35 -0800 Subject: [PATCH 63/98] Speed up and green tests by removing most waits calls --- lib/jquery.waypoints.js | 17 ++++++------ lib/jquery.waypoints.min.js | 6 ++--- lib/noframework.waypoints.js | 17 ++++++------ lib/noframework.waypoints.min.js | 6 ++--- lib/shortcuts/infinite.js | 46 +++++++++++++++----------------- lib/shortcuts/infinite.min.js | 6 ++--- lib/shortcuts/inview.js | 4 +-- lib/shortcuts/inview.min.js | 4 +-- lib/shortcuts/sticky.js | 4 +-- lib/shortcuts/sticky.min.js | 4 +-- lib/waypoints.debug.js | 4 +-- lib/zepto.waypoints.js | 17 ++++++------ lib/zepto.waypoints.min.js | 6 ++--- src/context.js | 13 ++++----- test/adapter-fn-spec.js | 1 - test/context-spec.js | 17 ++++-------- test/debug-spec.js | 4 +-- test/group-spec.js | 6 ++--- test/infinite-spec.js | 4 +-- test/inview-spec.js | 3 +-- test/settings.js | 7 ++++- test/sticky-spec.js | 6 +---- test/waypoint-spec.js | 28 ------------------- 23 files changed, 96 insertions(+), 134 deletions(-) diff --git a/lib/jquery.waypoints.js b/lib/jquery.waypoints.js index 5487c82b..1f0e0631 100644 --- a/lib/jquery.waypoints.js +++ b/lib/jquery.waypoints.js @@ -1,6 +1,6 @@ /*! -Waypoints - 3.0.0 -Copyright © 2011-2014 Caleb Troughton +Waypoints - 3.0.1 +Copyright © 2011-2015 Caleb Troughton Licensed under the MIT license. https://github.com/imakewebthings/waypoints/blog/master/licenses.txt */ @@ -157,10 +157,6 @@ https://github.com/imakewebthings/waypoints/blog/master/licenses.txt var keyCounter = 0 var contexts = {} var Waypoint = window.Waypoint - var requestAnimationFrame = window.requestAnimationFrame || - window.mozRequestAnimationFrame || - window.webkitRequestAnimationFrame || - requestAnimationFrameShim var oldWindowLoad = window.onload /* http://imakewebthings.com/waypoints/api/context */ @@ -217,7 +213,7 @@ https://github.com/imakewebthings/waypoints/blog/master/licenses.txt this.adapter.on('resize.waypoints', function() { if (!self.didResize) { self.didResize = true - requestAnimationFrame(resizeHandler) + Waypoint.requestAnimationFrame(resizeHandler) } }) } @@ -233,7 +229,7 @@ https://github.com/imakewebthings/waypoints/blog/master/licenses.txt this.adapter.on('scroll.waypoints', function() { if (!self.didScroll || Waypoint.isTouch) { self.didScroll = true - requestAnimationFrame(scrollHandler) + Waypoint.requestAnimationFrame(scrollHandler) } }) } @@ -433,6 +429,11 @@ https://github.com/imakewebthings/waypoints/blog/master/licenses.txt } Context.refreshAll() } + + Waypoint.requestAnimationFrame = window.requestAnimationFrame || + window.mozRequestAnimationFrame || + window.webkitRequestAnimationFrame || + requestAnimationFrameShim Waypoint.Context = Context }()) ;(function() { diff --git a/lib/jquery.waypoints.min.js b/lib/jquery.waypoints.min.js index 2309fc40..4bbeaa61 100644 --- a/lib/jquery.waypoints.min.js +++ b/lib/jquery.waypoints.min.js @@ -1,7 +1,7 @@ /*! -Waypoints - 3.0.0 -Copyright © 2011-2014 Caleb Troughton +Waypoints - 3.0.1 +Copyright © 2011-2015 Caleb Troughton Licensed under the MIT license. https://github.com/imakewebthings/waypoints/blog/master/licenses.txt */ -!function(){"use strict";function t(o){if(!o)throw new Error("No options passed to Waypoint constructor");if(!o.element)throw new Error("No element option passed to Waypoint constructor");if(!o.handler)throw new Error("No handler option passed to Waypoint constructor");this.key="waypoint-"+e,this.options=t.Adapter.extend({},t.defaults,o),this.element=this.options.element,this.adapter=new t.Adapter(this.element),this.callback=o.handler,this.axis=this.options.horizontal?"horizontal":"vertical",this.enabled=this.options.enabled,this.triggerPoint=null,this.group=t.Group.findOrCreate({name:this.options.group,axis:this.axis}),this.context=t.Context.findOrCreateByElement(this.options.context),t.offsetAliases[this.options.offset]&&(this.options.offset=t.offsetAliases[this.options.offset]),this.group.add(this),this.context.add(this),i[this.key]=this,e+=1}var e=0,i={};t.prototype.queueTrigger=function(t){this.group.queueTrigger(this,t)},t.prototype.trigger=function(t){this.enabled&&this.callback&&this.callback.apply(this,t)},t.prototype.destroy=function(){this.context.remove(this),this.group.remove(this),delete i[this.key]},t.prototype.disable=function(){return this.enabled=!1,this},t.prototype.enable=function(){return this.context.refresh(),this.enabled=!0,this},t.prototype.next=function(){return this.group.next(this)},t.prototype.previous=function(){return this.group.previous(this)},t.destroyAll=function(){var t=[];for(var e in i)t.push(i[e]);for(var o=0,r=t.length;r>o;o++)t[o].destroy()},t.refreshAll=function(){t.Context.refreshAll()},t.viewportHeight=function(){return window.innerHeight||document.documentElement.clientHeight},t.viewportWidth=function(){return document.documentElement.clientWidth},t.adapters=[],t.defaults={context:window,continuous:!0,enabled:!0,group:"default",horizontal:!1,offset:0},t.offsetAliases={"bottom-in-view":function(){return this.context.innerHeight()-this.adapter.outerHeight()},"right-in-view":function(){return this.context.innerWidth()-this.adapter.outerWidth()}},window.Waypoint=t}(),function(){"use strict";function t(t){window.setTimeout(t,1e3/60)}function e(t){this.element=t,this.Adapter=r.Adapter,this.adapter=new this.Adapter(t),this.key="waypoint-context-"+i,this.didScroll=!1,this.didResize=!1,this.oldScroll={x:this.adapter.scrollLeft(),y:this.adapter.scrollTop()},this.waypoints={vertical:{},horizontal:{}},t.waypointContextKey=this.key,o[t.waypointContextKey]=this,i+=1,this.createThrottledScrollHandler(),this.createThrottledResizeHandler()}var i=0,o={},r=window.Waypoint,n=window.requestAnimationFrame||window.mozRequestAnimationFrame||window.webkitRequestAnimationFrame||t,s=window.onload;e.prototype.add=function(t){var e=t.options.horizontal?"horizontal":"vertical";this.waypoints[e][t.key]=t,this.refresh()},e.prototype.checkEmpty=function(){var t=this.Adapter.isEmptyObject(this.waypoints.horizontal),e=this.Adapter.isEmptyObject(this.waypoints.vertical);t&&e&&(this.adapter.off(".waypoints"),delete o[this.key])},e.prototype.createThrottledResizeHandler=function(){function t(){e.handleResize(),e.didResize=!1}var e=this;this.adapter.on("resize.waypoints",function(){e.didResize||(e.didResize=!0,n(t))})},e.prototype.createThrottledScrollHandler=function(){function t(){e.handleScroll(),e.didScroll=!1}var e=this;this.adapter.on("scroll.waypoints",function(){(!e.didScroll||r.isTouch)&&(e.didScroll=!0,n(t))})},e.prototype.handleResize=function(){r.Context.refreshAll()},e.prototype.handleScroll=function(){var t={},e={horizontal:{newScroll:this.adapter.scrollLeft(),oldScroll:this.oldScroll.x,forward:"right",backward:"left"},vertical:{newScroll:this.adapter.scrollTop(),oldScroll:this.oldScroll.y,forward:"down",backward:"up"}};for(var i in e){var o=e[i],r=o.newScroll>o.oldScroll,n=r?o.forward:o.backward;for(var s in this.waypoints[i]){var a=this.waypoints[i][s],l=o.oldScroll=a.triggerPoint,p=l&&h,u=!l&&!h;(p||u)&&(a.queueTrigger(n),t[a.group.id]=a.group)}}for(var c in t)t[c].flushTriggers();this.oldScroll={x:e.horizontal.newScroll,y:e.vertical.newScroll}},e.prototype.innerHeight=function(){return this.element===this.element.window?r.viewportHeight():this.adapter.innerHeight()},e.prototype.remove=function(t){delete this.waypoints[t.axis][t.key],this.checkEmpty()},e.prototype.innerWidth=function(){return this.element===this.element.window?r.viewportWidth():this.adapter.innerWidth()},e.prototype.destroy=function(){var t=[];for(var e in this.waypoints)for(var i in this.waypoints[e])t.push(this.waypoints[e][i]);for(var o=0,r=t.length;r>o;o++)t[o].destroy()},e.prototype.refresh=function(){var t,e=this.element===this.element.window,i=this.adapter.offset(),o={};this.handleScroll(),t={horizontal:{contextOffset:e?0:i.left,contextScroll:e?0:this.oldScroll.x,contextDimension:this.innerWidth(),oldScroll:this.oldScroll.x,forward:"right",backward:"left",offsetProp:"left"},vertical:{contextOffset:e?0:i.top,contextScroll:e?0:this.oldScroll.y,contextDimension:this.innerHeight(),oldScroll:this.oldScroll.y,forward:"down",backward:"up",offsetProp:"top"}};for(var r in t){var n=t[r];for(var s in this.waypoints[r]){var a,l,h,p,u,c=this.waypoints[r][s],d=c.options.offset,f=c.triggerPoint,w=0,y=null==f;c.element!==c.element.window&&(w=c.adapter.offset()[n.offsetProp]),"function"==typeof d?d=d.apply(c):"string"==typeof d&&(d=parseFloat(d),c.options.offset.indexOf("%")>-1&&(d=Math.ceil(n.contextDimension*d/100))),a=n.contextScroll-n.contextOffset,c.triggerPoint=w+a-d,l=f=n.oldScroll,p=l&&h,u=!l&&!h,!y&&p?(c.queueTrigger(n.backward),o[c.group.id]=c.group):!y&&u?(c.queueTrigger(n.forward),o[c.group.id]=c.group):y&&n.oldScroll>=c.triggerPoint&&(c.queueTrigger(n.forward),o[c.group.id]=c.group)}}for(var g in o)o[g].flushTriggers();return this},e.findOrCreateByElement=function(t){return e.findByElement(t)||new e(t)},e.refreshAll=function(){for(var t in o)o[t].refresh()},e.findByElement=function(t){return o[t.waypointContextKey]},window.onload=function(){s&&s(),e.refreshAll()},r.Context=e}(),function(){"use strict";function t(t,e){return t.triggerPoint-e.triggerPoint}function e(t,e){return e.triggerPoint-t.triggerPoint}function i(t){this.name=t.name,this.axis=t.axis,this.id=this.name+"-"+this.axis,this.waypoints=[],this.clearTriggerQueues(),o[this.axis][this.name]=this}var o={vertical:{},horizontal:{}},r=window.Waypoint;i.prototype.add=function(t){this.waypoints.push(t)},i.prototype.clearTriggerQueues=function(){this.triggerQueues={up:[],down:[],left:[],right:[]}},i.prototype.flushTriggers=function(){for(var i in this.triggerQueues){var o=this.triggerQueues[i],r="up"===i||"left"===i;o.sort(r?e:t);for(var n=0,s=o.length;s>n;n+=1){var a=o[n];(a.options.continuous||n===o.length-1)&&a.trigger([i])}}this.clearTriggerQueues()},i.prototype.next=function(e){this.waypoints.sort(t);var i=r.Adapter.inArray(e,this.waypoints),o=i===this.waypoints.length-1;return o?null:this.waypoints[i+1]},i.prototype.previous=function(e){this.waypoints.sort(t);var i=r.Adapter.inArray(e,this.waypoints);return i?this.waypoints[i-1]:null},i.prototype.queueTrigger=function(t,e){this.triggerQueues[e].push(t)},i.prototype.remove=function(t){var e=r.Adapter.inArray(t,this.waypoints);e>-1&&this.waypoints.splice(e,1)},i.prototype.first=function(){return this.waypoints[0]},i.prototype.last=function(){return this.waypoints[this.waypoints.length-1]},i.findOrCreate=function(t){return o[t.axis][t.name]||new i(t)},r.Group=i}(),function(){"use strict";function t(t){this.$element=e(t)}var e=window.jQuery,i=window.Waypoint;e.each(["innerHeight","innerWidth","off","offset","on","outerHeight","outerWidth","scrollLeft","scrollTop"],function(e,i){t.prototype[i]=function(){var t=Array.prototype.slice.call(arguments);return this.$element[i].apply(this.$element,t)}}),e.each(["extend","inArray","isEmptyObject"],function(i,o){t[o]=e[o]}),i.adapters.push({name:"jquery",Adapter:t}),i.Adapter=t}(),function(){"use strict";function t(t){return function(){var i=[],o=arguments[0];return t.isFunction(arguments[0])&&(o=t.extend({},arguments[1]),o.handler=arguments[0]),this.each(function(){var r=t.extend({},o,{element:this});"string"==typeof r.context&&(r.context=t(this).closest(r.context)[0]),i.push(new e(r))}),i}}var e=window.Waypoint;window.jQuery&&(window.jQuery.fn.waypoint=t(window.jQuery)),window.Zepto&&(window.Zepto.fn.waypoint=t(window.Zepto))}(); \ No newline at end of file +!function(){"use strict";function t(o){if(!o)throw new Error("No options passed to Waypoint constructor");if(!o.element)throw new Error("No element option passed to Waypoint constructor");if(!o.handler)throw new Error("No handler option passed to Waypoint constructor");this.key="waypoint-"+e,this.options=t.Adapter.extend({},t.defaults,o),this.element=this.options.element,this.adapter=new t.Adapter(this.element),this.callback=o.handler,this.axis=this.options.horizontal?"horizontal":"vertical",this.enabled=this.options.enabled,this.triggerPoint=null,this.group=t.Group.findOrCreate({name:this.options.group,axis:this.axis}),this.context=t.Context.findOrCreateByElement(this.options.context),t.offsetAliases[this.options.offset]&&(this.options.offset=t.offsetAliases[this.options.offset]),this.group.add(this),this.context.add(this),i[this.key]=this,e+=1}var e=0,i={};t.prototype.queueTrigger=function(t){this.group.queueTrigger(this,t)},t.prototype.trigger=function(t){this.enabled&&this.callback&&this.callback.apply(this,t)},t.prototype.destroy=function(){this.context.remove(this),this.group.remove(this),delete i[this.key]},t.prototype.disable=function(){return this.enabled=!1,this},t.prototype.enable=function(){return this.context.refresh(),this.enabled=!0,this},t.prototype.next=function(){return this.group.next(this)},t.prototype.previous=function(){return this.group.previous(this)},t.destroyAll=function(){var t=[];for(var e in i)t.push(i[e]);for(var o=0,r=t.length;r>o;o++)t[o].destroy()},t.refreshAll=function(){t.Context.refreshAll()},t.viewportHeight=function(){return window.innerHeight||document.documentElement.clientHeight},t.viewportWidth=function(){return document.documentElement.clientWidth},t.adapters=[],t.defaults={context:window,continuous:!0,enabled:!0,group:"default",horizontal:!1,offset:0},t.offsetAliases={"bottom-in-view":function(){return this.context.innerHeight()-this.adapter.outerHeight()},"right-in-view":function(){return this.context.innerWidth()-this.adapter.outerWidth()}},window.Waypoint=t}(),function(){"use strict";function t(t){window.setTimeout(t,1e3/60)}function e(t){this.element=t,this.Adapter=r.Adapter,this.adapter=new this.Adapter(t),this.key="waypoint-context-"+i,this.didScroll=!1,this.didResize=!1,this.oldScroll={x:this.adapter.scrollLeft(),y:this.adapter.scrollTop()},this.waypoints={vertical:{},horizontal:{}},t.waypointContextKey=this.key,o[t.waypointContextKey]=this,i+=1,this.createThrottledScrollHandler(),this.createThrottledResizeHandler()}var i=0,o={},r=window.Waypoint,n=window.onload;e.prototype.add=function(t){var e=t.options.horizontal?"horizontal":"vertical";this.waypoints[e][t.key]=t,this.refresh()},e.prototype.checkEmpty=function(){var t=this.Adapter.isEmptyObject(this.waypoints.horizontal),e=this.Adapter.isEmptyObject(this.waypoints.vertical);t&&e&&(this.adapter.off(".waypoints"),delete o[this.key])},e.prototype.createThrottledResizeHandler=function(){function t(){e.handleResize(),e.didResize=!1}var e=this;this.adapter.on("resize.waypoints",function(){e.didResize||(e.didResize=!0,r.requestAnimationFrame(t))})},e.prototype.createThrottledScrollHandler=function(){function t(){e.handleScroll(),e.didScroll=!1}var e=this;this.adapter.on("scroll.waypoints",function(){(!e.didScroll||r.isTouch)&&(e.didScroll=!0,r.requestAnimationFrame(t))})},e.prototype.handleResize=function(){r.Context.refreshAll()},e.prototype.handleScroll=function(){var t={},e={horizontal:{newScroll:this.adapter.scrollLeft(),oldScroll:this.oldScroll.x,forward:"right",backward:"left"},vertical:{newScroll:this.adapter.scrollTop(),oldScroll:this.oldScroll.y,forward:"down",backward:"up"}};for(var i in e){var o=e[i],r=o.newScroll>o.oldScroll,n=r?o.forward:o.backward;for(var s in this.waypoints[i]){var a=this.waypoints[i][s],l=o.oldScroll=a.triggerPoint,p=l&&h,u=!l&&!h;(p||u)&&(a.queueTrigger(n),t[a.group.id]=a.group)}}for(var c in t)t[c].flushTriggers();this.oldScroll={x:e.horizontal.newScroll,y:e.vertical.newScroll}},e.prototype.innerHeight=function(){return this.element===this.element.window?r.viewportHeight():this.adapter.innerHeight()},e.prototype.remove=function(t){delete this.waypoints[t.axis][t.key],this.checkEmpty()},e.prototype.innerWidth=function(){return this.element===this.element.window?r.viewportWidth():this.adapter.innerWidth()},e.prototype.destroy=function(){var t=[];for(var e in this.waypoints)for(var i in this.waypoints[e])t.push(this.waypoints[e][i]);for(var o=0,r=t.length;r>o;o++)t[o].destroy()},e.prototype.refresh=function(){var t,e=this.element===this.element.window,i=this.adapter.offset(),o={};this.handleScroll(),t={horizontal:{contextOffset:e?0:i.left,contextScroll:e?0:this.oldScroll.x,contextDimension:this.innerWidth(),oldScroll:this.oldScroll.x,forward:"right",backward:"left",offsetProp:"left"},vertical:{contextOffset:e?0:i.top,contextScroll:e?0:this.oldScroll.y,contextDimension:this.innerHeight(),oldScroll:this.oldScroll.y,forward:"down",backward:"up",offsetProp:"top"}};for(var r in t){var n=t[r];for(var s in this.waypoints[r]){var a,l,h,p,u,c=this.waypoints[r][s],d=c.options.offset,f=c.triggerPoint,w=0,y=null==f;c.element!==c.element.window&&(w=c.adapter.offset()[n.offsetProp]),"function"==typeof d?d=d.apply(c):"string"==typeof d&&(d=parseFloat(d),c.options.offset.indexOf("%")>-1&&(d=Math.ceil(n.contextDimension*d/100))),a=n.contextScroll-n.contextOffset,c.triggerPoint=w+a-d,l=f=n.oldScroll,p=l&&h,u=!l&&!h,!y&&p?(c.queueTrigger(n.backward),o[c.group.id]=c.group):!y&&u?(c.queueTrigger(n.forward),o[c.group.id]=c.group):y&&n.oldScroll>=c.triggerPoint&&(c.queueTrigger(n.forward),o[c.group.id]=c.group)}}for(var g in o)o[g].flushTriggers();return this},e.findOrCreateByElement=function(t){return e.findByElement(t)||new e(t)},e.refreshAll=function(){for(var t in o)o[t].refresh()},e.findByElement=function(t){return o[t.waypointContextKey]},window.onload=function(){n&&n(),e.refreshAll()},r.requestAnimationFrame=window.requestAnimationFrame||window.mozRequestAnimationFrame||window.webkitRequestAnimationFrame||t,r.Context=e}(),function(){"use strict";function t(t,e){return t.triggerPoint-e.triggerPoint}function e(t,e){return e.triggerPoint-t.triggerPoint}function i(t){this.name=t.name,this.axis=t.axis,this.id=this.name+"-"+this.axis,this.waypoints=[],this.clearTriggerQueues(),o[this.axis][this.name]=this}var o={vertical:{},horizontal:{}},r=window.Waypoint;i.prototype.add=function(t){this.waypoints.push(t)},i.prototype.clearTriggerQueues=function(){this.triggerQueues={up:[],down:[],left:[],right:[]}},i.prototype.flushTriggers=function(){for(var i in this.triggerQueues){var o=this.triggerQueues[i],r="up"===i||"left"===i;o.sort(r?e:t);for(var n=0,s=o.length;s>n;n+=1){var a=o[n];(a.options.continuous||n===o.length-1)&&a.trigger([i])}}this.clearTriggerQueues()},i.prototype.next=function(e){this.waypoints.sort(t);var i=r.Adapter.inArray(e,this.waypoints),o=i===this.waypoints.length-1;return o?null:this.waypoints[i+1]},i.prototype.previous=function(e){this.waypoints.sort(t);var i=r.Adapter.inArray(e,this.waypoints);return i?this.waypoints[i-1]:null},i.prototype.queueTrigger=function(t,e){this.triggerQueues[e].push(t)},i.prototype.remove=function(t){var e=r.Adapter.inArray(t,this.waypoints);e>-1&&this.waypoints.splice(e,1)},i.prototype.first=function(){return this.waypoints[0]},i.prototype.last=function(){return this.waypoints[this.waypoints.length-1]},i.findOrCreate=function(t){return o[t.axis][t.name]||new i(t)},r.Group=i}(),function(){"use strict";function t(t){this.$element=e(t)}var e=window.jQuery,i=window.Waypoint;e.each(["innerHeight","innerWidth","off","offset","on","outerHeight","outerWidth","scrollLeft","scrollTop"],function(e,i){t.prototype[i]=function(){var t=Array.prototype.slice.call(arguments);return this.$element[i].apply(this.$element,t)}}),e.each(["extend","inArray","isEmptyObject"],function(i,o){t[o]=e[o]}),i.adapters.push({name:"jquery",Adapter:t}),i.Adapter=t}(),function(){"use strict";function t(t){return function(){var i=[],o=arguments[0];return t.isFunction(arguments[0])&&(o=t.extend({},arguments[1]),o.handler=arguments[0]),this.each(function(){var r=t.extend({},o,{element:this});"string"==typeof r.context&&(r.context=t(this).closest(r.context)[0]),i.push(new e(r))}),i}}var e=window.Waypoint;window.jQuery&&(window.jQuery.fn.waypoint=t(window.jQuery)),window.Zepto&&(window.Zepto.fn.waypoint=t(window.Zepto))}(); \ No newline at end of file diff --git a/lib/noframework.waypoints.js b/lib/noframework.waypoints.js index 502379c1..5ccfdb04 100644 --- a/lib/noframework.waypoints.js +++ b/lib/noframework.waypoints.js @@ -1,6 +1,6 @@ /*! -Waypoints - 3.0.0 -Copyright © 2011-2014 Caleb Troughton +Waypoints - 3.0.1 +Copyright © 2011-2015 Caleb Troughton Licensed under the MIT license. https://github.com/imakewebthings/waypoints/blog/master/licenses.txt */ @@ -157,10 +157,6 @@ https://github.com/imakewebthings/waypoints/blog/master/licenses.txt var keyCounter = 0 var contexts = {} var Waypoint = window.Waypoint - var requestAnimationFrame = window.requestAnimationFrame || - window.mozRequestAnimationFrame || - window.webkitRequestAnimationFrame || - requestAnimationFrameShim var oldWindowLoad = window.onload /* http://imakewebthings.com/waypoints/api/context */ @@ -217,7 +213,7 @@ https://github.com/imakewebthings/waypoints/blog/master/licenses.txt this.adapter.on('resize.waypoints', function() { if (!self.didResize) { self.didResize = true - requestAnimationFrame(resizeHandler) + Waypoint.requestAnimationFrame(resizeHandler) } }) } @@ -233,7 +229,7 @@ https://github.com/imakewebthings/waypoints/blog/master/licenses.txt this.adapter.on('scroll.waypoints', function() { if (!self.didScroll || Waypoint.isTouch) { self.didScroll = true - requestAnimationFrame(scrollHandler) + Waypoint.requestAnimationFrame(scrollHandler) } }) } @@ -433,6 +429,11 @@ https://github.com/imakewebthings/waypoints/blog/master/licenses.txt } Context.refreshAll() } + + Waypoint.requestAnimationFrame = window.requestAnimationFrame || + window.mozRequestAnimationFrame || + window.webkitRequestAnimationFrame || + requestAnimationFrameShim Waypoint.Context = Context }()) ;(function() { diff --git a/lib/noframework.waypoints.min.js b/lib/noframework.waypoints.min.js index 4c570872..b45074df 100644 --- a/lib/noframework.waypoints.min.js +++ b/lib/noframework.waypoints.min.js @@ -1,7 +1,7 @@ /*! -Waypoints - 3.0.0 -Copyright © 2011-2014 Caleb Troughton +Waypoints - 3.0.1 +Copyright © 2011-2015 Caleb Troughton Licensed under the MIT license. https://github.com/imakewebthings/waypoints/blog/master/licenses.txt */ -!function(){"use strict";function t(n){if(!n)throw new Error("No options passed to Waypoint constructor");if(!n.element)throw new Error("No element option passed to Waypoint constructor");if(!n.handler)throw new Error("No handler option passed to Waypoint constructor");this.key="waypoint-"+e,this.options=t.Adapter.extend({},t.defaults,n),this.element=this.options.element,this.adapter=new t.Adapter(this.element),this.callback=n.handler,this.axis=this.options.horizontal?"horizontal":"vertical",this.enabled=this.options.enabled,this.triggerPoint=null,this.group=t.Group.findOrCreate({name:this.options.group,axis:this.axis}),this.context=t.Context.findOrCreateByElement(this.options.context),t.offsetAliases[this.options.offset]&&(this.options.offset=t.offsetAliases[this.options.offset]),this.group.add(this),this.context.add(this),i[this.key]=this,e+=1}var e=0,i={};t.prototype.queueTrigger=function(t){this.group.queueTrigger(this,t)},t.prototype.trigger=function(t){this.enabled&&this.callback&&this.callback.apply(this,t)},t.prototype.destroy=function(){this.context.remove(this),this.group.remove(this),delete i[this.key]},t.prototype.disable=function(){return this.enabled=!1,this},t.prototype.enable=function(){return this.context.refresh(),this.enabled=!0,this},t.prototype.next=function(){return this.group.next(this)},t.prototype.previous=function(){return this.group.previous(this)},t.destroyAll=function(){var t=[];for(var e in i)t.push(i[e]);for(var n=0,o=t.length;o>n;n++)t[n].destroy()},t.refreshAll=function(){t.Context.refreshAll()},t.viewportHeight=function(){return window.innerHeight||document.documentElement.clientHeight},t.viewportWidth=function(){return document.documentElement.clientWidth},t.adapters=[],t.defaults={context:window,continuous:!0,enabled:!0,group:"default",horizontal:!1,offset:0},t.offsetAliases={"bottom-in-view":function(){return this.context.innerHeight()-this.adapter.outerHeight()},"right-in-view":function(){return this.context.innerWidth()-this.adapter.outerWidth()}},window.Waypoint=t}(),function(){"use strict";function t(t){window.setTimeout(t,1e3/60)}function e(t){this.element=t,this.Adapter=o.Adapter,this.adapter=new this.Adapter(t),this.key="waypoint-context-"+i,this.didScroll=!1,this.didResize=!1,this.oldScroll={x:this.adapter.scrollLeft(),y:this.adapter.scrollTop()},this.waypoints={vertical:{},horizontal:{}},t.waypointContextKey=this.key,n[t.waypointContextKey]=this,i+=1,this.createThrottledScrollHandler(),this.createThrottledResizeHandler()}var i=0,n={},o=window.Waypoint,r=window.requestAnimationFrame||window.mozRequestAnimationFrame||window.webkitRequestAnimationFrame||t,s=window.onload;e.prototype.add=function(t){var e=t.options.horizontal?"horizontal":"vertical";this.waypoints[e][t.key]=t,this.refresh()},e.prototype.checkEmpty=function(){var t=this.Adapter.isEmptyObject(this.waypoints.horizontal),e=this.Adapter.isEmptyObject(this.waypoints.vertical);t&&e&&(this.adapter.off(".waypoints"),delete n[this.key])},e.prototype.createThrottledResizeHandler=function(){function t(){e.handleResize(),e.didResize=!1}var e=this;this.adapter.on("resize.waypoints",function(){e.didResize||(e.didResize=!0,r(t))})},e.prototype.createThrottledScrollHandler=function(){function t(){e.handleScroll(),e.didScroll=!1}var e=this;this.adapter.on("scroll.waypoints",function(){(!e.didScroll||o.isTouch)&&(e.didScroll=!0,r(t))})},e.prototype.handleResize=function(){o.Context.refreshAll()},e.prototype.handleScroll=function(){var t={},e={horizontal:{newScroll:this.adapter.scrollLeft(),oldScroll:this.oldScroll.x,forward:"right",backward:"left"},vertical:{newScroll:this.adapter.scrollTop(),oldScroll:this.oldScroll.y,forward:"down",backward:"up"}};for(var i in e){var n=e[i],o=n.newScroll>n.oldScroll,r=o?n.forward:n.backward;for(var s in this.waypoints[i]){var a=this.waypoints[i][s],l=n.oldScroll=a.triggerPoint,p=l&&h,u=!l&&!h;(p||u)&&(a.queueTrigger(r),t[a.group.id]=a.group)}}for(var c in t)t[c].flushTriggers();this.oldScroll={x:e.horizontal.newScroll,y:e.vertical.newScroll}},e.prototype.innerHeight=function(){return this.element===this.element.window?o.viewportHeight():this.adapter.innerHeight()},e.prototype.remove=function(t){delete this.waypoints[t.axis][t.key],this.checkEmpty()},e.prototype.innerWidth=function(){return this.element===this.element.window?o.viewportWidth():this.adapter.innerWidth()},e.prototype.destroy=function(){var t=[];for(var e in this.waypoints)for(var i in this.waypoints[e])t.push(this.waypoints[e][i]);for(var n=0,o=t.length;o>n;n++)t[n].destroy()},e.prototype.refresh=function(){var t,e=this.element===this.element.window,i=this.adapter.offset(),n={};this.handleScroll(),t={horizontal:{contextOffset:e?0:i.left,contextScroll:e?0:this.oldScroll.x,contextDimension:this.innerWidth(),oldScroll:this.oldScroll.x,forward:"right",backward:"left",offsetProp:"left"},vertical:{contextOffset:e?0:i.top,contextScroll:e?0:this.oldScroll.y,contextDimension:this.innerHeight(),oldScroll:this.oldScroll.y,forward:"down",backward:"up",offsetProp:"top"}};for(var o in t){var r=t[o];for(var s in this.waypoints[o]){var a,l,h,p,u,c=this.waypoints[o][s],f=c.options.offset,d=c.triggerPoint,y=0,g=null==d;c.element!==c.element.window&&(y=c.adapter.offset()[r.offsetProp]),"function"==typeof f?f=f.apply(c):"string"==typeof f&&(f=parseFloat(f),c.options.offset.indexOf("%")>-1&&(f=Math.ceil(r.contextDimension*f/100))),a=r.contextScroll-r.contextOffset,c.triggerPoint=y+a-f,l=d=r.oldScroll,p=l&&h,u=!l&&!h,!g&&p?(c.queueTrigger(r.backward),n[c.group.id]=c.group):!g&&u?(c.queueTrigger(r.forward),n[c.group.id]=c.group):g&&r.oldScroll>=c.triggerPoint&&(c.queueTrigger(r.forward),n[c.group.id]=c.group)}}for(var w in n)n[w].flushTriggers();return this},e.findOrCreateByElement=function(t){return e.findByElement(t)||new e(t)},e.refreshAll=function(){for(var t in n)n[t].refresh()},e.findByElement=function(t){return n[t.waypointContextKey]},window.onload=function(){s&&s(),e.refreshAll()},o.Context=e}(),function(){"use strict";function t(t,e){return t.triggerPoint-e.triggerPoint}function e(t,e){return e.triggerPoint-t.triggerPoint}function i(t){this.name=t.name,this.axis=t.axis,this.id=this.name+"-"+this.axis,this.waypoints=[],this.clearTriggerQueues(),n[this.axis][this.name]=this}var n={vertical:{},horizontal:{}},o=window.Waypoint;i.prototype.add=function(t){this.waypoints.push(t)},i.prototype.clearTriggerQueues=function(){this.triggerQueues={up:[],down:[],left:[],right:[]}},i.prototype.flushTriggers=function(){for(var i in this.triggerQueues){var n=this.triggerQueues[i],o="up"===i||"left"===i;n.sort(o?e:t);for(var r=0,s=n.length;s>r;r+=1){var a=n[r];(a.options.continuous||r===n.length-1)&&a.trigger([i])}}this.clearTriggerQueues()},i.prototype.next=function(e){this.waypoints.sort(t);var i=o.Adapter.inArray(e,this.waypoints),n=i===this.waypoints.length-1;return n?null:this.waypoints[i+1]},i.prototype.previous=function(e){this.waypoints.sort(t);var i=o.Adapter.inArray(e,this.waypoints);return i?this.waypoints[i-1]:null},i.prototype.queueTrigger=function(t,e){this.triggerQueues[e].push(t)},i.prototype.remove=function(t){var e=o.Adapter.inArray(t,this.waypoints);e>-1&&this.waypoints.splice(e,1)},i.prototype.first=function(){return this.waypoints[0]},i.prototype.last=function(){return this.waypoints[this.waypoints.length-1]},i.findOrCreate=function(t){return n[t.axis][t.name]||new i(t)},o.Group=i}(),function(){"use strict";function t(t){return t===t.window}function e(e){return t(e)?e:e.defaultView}function i(t){this.element=t,this.handlers={}}var n=window.Waypoint;i.prototype.innerHeight=function(){var e=t(this.element);return e?this.element.innerHeight:this.element.clientHeight},i.prototype.innerWidth=function(){var e=t(this.element);return e?this.element.innerWidth:this.element.clientWidth},i.prototype.off=function(t,e){function i(t,e,i){for(var n=0,o=e.length-1;o>n;n++){var r=e[n];i&&i!==r||t.removeEventListener(r)}}var n=t.split("."),o=n[0],r=n[1],s=this.element;if(r&&this.handlers[r]&&o)i(s,this.handlers[r][o],e),this.handlers[r][o]=[];else if(o)for(var a in this.handlers)i(s,this.handlers[a][o]||[],e),this.handlers[a][o]=[];else if(r&&this.handlers[r]){for(var l in this.handlers[r])i(s,this.handlers[r][l],e);this.handlers[r]={}}},i.prototype.offset=function(){if(!this.element.ownerDocument)return null;var t=this.element.ownerDocument.documentElement,i=e(this.element.ownerDocument),n={top:0,left:0};return this.element.getBoundingClientRect&&(n=this.element.getBoundingClientRect()),{top:n.top+i.pageYOffset-t.clientTop,left:n.left+i.pageXOffset-t.clientLeft}},i.prototype.on=function(t,e){var i=t.split("."),n=i[0],o=i[1]||"__default",r=this.handlers[o]=this.handlers[o]||{},s=r[n]=r[n]||[];s.push(e),this.element.addEventListener(n,e)},i.prototype.outerHeight=function(e){var i,n=this.innerHeight();return e&&!t(this.element)&&(i=window.getComputedStyle(this.element),n+=parseInt(i.marginTop,10),n+=parseInt(i.marginBottom,10)),n},i.prototype.outerWidth=function(e){var i,n=this.innerWidth();return e&&!t(this.element)&&(i=window.getComputedStyle(this.element),n+=parseInt(i.marginLeft,10),n+=parseInt(i.marginRight,10)),n},i.prototype.scrollLeft=function(){var t=e(this.element);return t?t.pageXOffset:this.element.scrollLeft},i.prototype.scrollTop=function(){var t=e(this.element);return t?t.pageYOffset:this.element.scrollTop},i.extend=function(){function t(t,e){if("object"==typeof t&&"object"==typeof e)for(var i in e)e.hasOwnProperty(i)&&(t[i]=e[i]);return t}for(var e=Array.prototype.slice.call(arguments),i=1,n=e.length;n>i;i++)t(e[0],e[i]);return e[0]},i.inArray=function(t,e,i){return null==e?-1:e.indexOf(t,i)},i.isEmptyObject=function(t){for(var e in t)return!1;return!0},n.adapters.push({name:"noframework",Adapter:i}),n.Adapter=i}(); \ No newline at end of file +!function(){"use strict";function t(n){if(!n)throw new Error("No options passed to Waypoint constructor");if(!n.element)throw new Error("No element option passed to Waypoint constructor");if(!n.handler)throw new Error("No handler option passed to Waypoint constructor");this.key="waypoint-"+e,this.options=t.Adapter.extend({},t.defaults,n),this.element=this.options.element,this.adapter=new t.Adapter(this.element),this.callback=n.handler,this.axis=this.options.horizontal?"horizontal":"vertical",this.enabled=this.options.enabled,this.triggerPoint=null,this.group=t.Group.findOrCreate({name:this.options.group,axis:this.axis}),this.context=t.Context.findOrCreateByElement(this.options.context),t.offsetAliases[this.options.offset]&&(this.options.offset=t.offsetAliases[this.options.offset]),this.group.add(this),this.context.add(this),i[this.key]=this,e+=1}var e=0,i={};t.prototype.queueTrigger=function(t){this.group.queueTrigger(this,t)},t.prototype.trigger=function(t){this.enabled&&this.callback&&this.callback.apply(this,t)},t.prototype.destroy=function(){this.context.remove(this),this.group.remove(this),delete i[this.key]},t.prototype.disable=function(){return this.enabled=!1,this},t.prototype.enable=function(){return this.context.refresh(),this.enabled=!0,this},t.prototype.next=function(){return this.group.next(this)},t.prototype.previous=function(){return this.group.previous(this)},t.destroyAll=function(){var t=[];for(var e in i)t.push(i[e]);for(var n=0,r=t.length;r>n;n++)t[n].destroy()},t.refreshAll=function(){t.Context.refreshAll()},t.viewportHeight=function(){return window.innerHeight||document.documentElement.clientHeight},t.viewportWidth=function(){return document.documentElement.clientWidth},t.adapters=[],t.defaults={context:window,continuous:!0,enabled:!0,group:"default",horizontal:!1,offset:0},t.offsetAliases={"bottom-in-view":function(){return this.context.innerHeight()-this.adapter.outerHeight()},"right-in-view":function(){return this.context.innerWidth()-this.adapter.outerWidth()}},window.Waypoint=t}(),function(){"use strict";function t(t){window.setTimeout(t,1e3/60)}function e(t){this.element=t,this.Adapter=r.Adapter,this.adapter=new this.Adapter(t),this.key="waypoint-context-"+i,this.didScroll=!1,this.didResize=!1,this.oldScroll={x:this.adapter.scrollLeft(),y:this.adapter.scrollTop()},this.waypoints={vertical:{},horizontal:{}},t.waypointContextKey=this.key,n[t.waypointContextKey]=this,i+=1,this.createThrottledScrollHandler(),this.createThrottledResizeHandler()}var i=0,n={},r=window.Waypoint,o=window.onload;e.prototype.add=function(t){var e=t.options.horizontal?"horizontal":"vertical";this.waypoints[e][t.key]=t,this.refresh()},e.prototype.checkEmpty=function(){var t=this.Adapter.isEmptyObject(this.waypoints.horizontal),e=this.Adapter.isEmptyObject(this.waypoints.vertical);t&&e&&(this.adapter.off(".waypoints"),delete n[this.key])},e.prototype.createThrottledResizeHandler=function(){function t(){e.handleResize(),e.didResize=!1}var e=this;this.adapter.on("resize.waypoints",function(){e.didResize||(e.didResize=!0,r.requestAnimationFrame(t))})},e.prototype.createThrottledScrollHandler=function(){function t(){e.handleScroll(),e.didScroll=!1}var e=this;this.adapter.on("scroll.waypoints",function(){(!e.didScroll||r.isTouch)&&(e.didScroll=!0,r.requestAnimationFrame(t))})},e.prototype.handleResize=function(){r.Context.refreshAll()},e.prototype.handleScroll=function(){var t={},e={horizontal:{newScroll:this.adapter.scrollLeft(),oldScroll:this.oldScroll.x,forward:"right",backward:"left"},vertical:{newScroll:this.adapter.scrollTop(),oldScroll:this.oldScroll.y,forward:"down",backward:"up"}};for(var i in e){var n=e[i],r=n.newScroll>n.oldScroll,o=r?n.forward:n.backward;for(var s in this.waypoints[i]){var a=this.waypoints[i][s],l=n.oldScroll=a.triggerPoint,p=l&&h,u=!l&&!h;(p||u)&&(a.queueTrigger(o),t[a.group.id]=a.group)}}for(var c in t)t[c].flushTriggers();this.oldScroll={x:e.horizontal.newScroll,y:e.vertical.newScroll}},e.prototype.innerHeight=function(){return this.element===this.element.window?r.viewportHeight():this.adapter.innerHeight()},e.prototype.remove=function(t){delete this.waypoints[t.axis][t.key],this.checkEmpty()},e.prototype.innerWidth=function(){return this.element===this.element.window?r.viewportWidth():this.adapter.innerWidth()},e.prototype.destroy=function(){var t=[];for(var e in this.waypoints)for(var i in this.waypoints[e])t.push(this.waypoints[e][i]);for(var n=0,r=t.length;r>n;n++)t[n].destroy()},e.prototype.refresh=function(){var t,e=this.element===this.element.window,i=this.adapter.offset(),n={};this.handleScroll(),t={horizontal:{contextOffset:e?0:i.left,contextScroll:e?0:this.oldScroll.x,contextDimension:this.innerWidth(),oldScroll:this.oldScroll.x,forward:"right",backward:"left",offsetProp:"left"},vertical:{contextOffset:e?0:i.top,contextScroll:e?0:this.oldScroll.y,contextDimension:this.innerHeight(),oldScroll:this.oldScroll.y,forward:"down",backward:"up",offsetProp:"top"}};for(var r in t){var o=t[r];for(var s in this.waypoints[r]){var a,l,h,p,u,c=this.waypoints[r][s],f=c.options.offset,d=c.triggerPoint,y=0,g=null==d;c.element!==c.element.window&&(y=c.adapter.offset()[o.offsetProp]),"function"==typeof f?f=f.apply(c):"string"==typeof f&&(f=parseFloat(f),c.options.offset.indexOf("%")>-1&&(f=Math.ceil(o.contextDimension*f/100))),a=o.contextScroll-o.contextOffset,c.triggerPoint=y+a-f,l=d=o.oldScroll,p=l&&h,u=!l&&!h,!g&&p?(c.queueTrigger(o.backward),n[c.group.id]=c.group):!g&&u?(c.queueTrigger(o.forward),n[c.group.id]=c.group):g&&o.oldScroll>=c.triggerPoint&&(c.queueTrigger(o.forward),n[c.group.id]=c.group)}}for(var w in n)n[w].flushTriggers();return this},e.findOrCreateByElement=function(t){return e.findByElement(t)||new e(t)},e.refreshAll=function(){for(var t in n)n[t].refresh()},e.findByElement=function(t){return n[t.waypointContextKey]},window.onload=function(){o&&o(),e.refreshAll()},r.requestAnimationFrame=window.requestAnimationFrame||window.mozRequestAnimationFrame||window.webkitRequestAnimationFrame||t,r.Context=e}(),function(){"use strict";function t(t,e){return t.triggerPoint-e.triggerPoint}function e(t,e){return e.triggerPoint-t.triggerPoint}function i(t){this.name=t.name,this.axis=t.axis,this.id=this.name+"-"+this.axis,this.waypoints=[],this.clearTriggerQueues(),n[this.axis][this.name]=this}var n={vertical:{},horizontal:{}},r=window.Waypoint;i.prototype.add=function(t){this.waypoints.push(t)},i.prototype.clearTriggerQueues=function(){this.triggerQueues={up:[],down:[],left:[],right:[]}},i.prototype.flushTriggers=function(){for(var i in this.triggerQueues){var n=this.triggerQueues[i],r="up"===i||"left"===i;n.sort(r?e:t);for(var o=0,s=n.length;s>o;o+=1){var a=n[o];(a.options.continuous||o===n.length-1)&&a.trigger([i])}}this.clearTriggerQueues()},i.prototype.next=function(e){this.waypoints.sort(t);var i=r.Adapter.inArray(e,this.waypoints),n=i===this.waypoints.length-1;return n?null:this.waypoints[i+1]},i.prototype.previous=function(e){this.waypoints.sort(t);var i=r.Adapter.inArray(e,this.waypoints);return i?this.waypoints[i-1]:null},i.prototype.queueTrigger=function(t,e){this.triggerQueues[e].push(t)},i.prototype.remove=function(t){var e=r.Adapter.inArray(t,this.waypoints);e>-1&&this.waypoints.splice(e,1)},i.prototype.first=function(){return this.waypoints[0]},i.prototype.last=function(){return this.waypoints[this.waypoints.length-1]},i.findOrCreate=function(t){return n[t.axis][t.name]||new i(t)},r.Group=i}(),function(){"use strict";function t(t){return t===t.window}function e(e){return t(e)?e:e.defaultView}function i(t){this.element=t,this.handlers={}}var n=window.Waypoint;i.prototype.innerHeight=function(){var e=t(this.element);return e?this.element.innerHeight:this.element.clientHeight},i.prototype.innerWidth=function(){var e=t(this.element);return e?this.element.innerWidth:this.element.clientWidth},i.prototype.off=function(t,e){function i(t,e,i){for(var n=0,r=e.length-1;r>n;n++){var o=e[n];i&&i!==o||t.removeEventListener(o)}}var n=t.split("."),r=n[0],o=n[1],s=this.element;if(o&&this.handlers[o]&&r)i(s,this.handlers[o][r],e),this.handlers[o][r]=[];else if(r)for(var a in this.handlers)i(s,this.handlers[a][r]||[],e),this.handlers[a][r]=[];else if(o&&this.handlers[o]){for(var l in this.handlers[o])i(s,this.handlers[o][l],e);this.handlers[o]={}}},i.prototype.offset=function(){if(!this.element.ownerDocument)return null;var t=this.element.ownerDocument.documentElement,i=e(this.element.ownerDocument),n={top:0,left:0};return this.element.getBoundingClientRect&&(n=this.element.getBoundingClientRect()),{top:n.top+i.pageYOffset-t.clientTop,left:n.left+i.pageXOffset-t.clientLeft}},i.prototype.on=function(t,e){var i=t.split("."),n=i[0],r=i[1]||"__default",o=this.handlers[r]=this.handlers[r]||{},s=o[n]=o[n]||[];s.push(e),this.element.addEventListener(n,e)},i.prototype.outerHeight=function(e){var i,n=this.innerHeight();return e&&!t(this.element)&&(i=window.getComputedStyle(this.element),n+=parseInt(i.marginTop,10),n+=parseInt(i.marginBottom,10)),n},i.prototype.outerWidth=function(e){var i,n=this.innerWidth();return e&&!t(this.element)&&(i=window.getComputedStyle(this.element),n+=parseInt(i.marginLeft,10),n+=parseInt(i.marginRight,10)),n},i.prototype.scrollLeft=function(){var t=e(this.element);return t?t.pageXOffset:this.element.scrollLeft},i.prototype.scrollTop=function(){var t=e(this.element);return t?t.pageYOffset:this.element.scrollTop},i.extend=function(){function t(t,e){if("object"==typeof t&&"object"==typeof e)for(var i in e)e.hasOwnProperty(i)&&(t[i]=e[i]);return t}for(var e=Array.prototype.slice.call(arguments),i=1,n=e.length;n>i;i++)t(e[0],e[i]);return e[0]},i.inArray=function(t,e,i){return null==e?-1:e.indexOf(t,i)},i.isEmptyObject=function(t){for(var e in t)return!1;return!0},n.adapters.push({name:"noframework",Adapter:i}),n.Adapter=i}(); \ No newline at end of file diff --git a/lib/shortcuts/infinite.js b/lib/shortcuts/infinite.js index c1470e11..5bf62fc9 100644 --- a/lib/shortcuts/infinite.js +++ b/lib/shortcuts/infinite.js @@ -1,6 +1,6 @@ /*! -Waypoints Infinite Scroll Shortcut - 3.0.0 -Copyright © 2011-2014 Caleb Troughton +Waypoints Infinite Scroll Shortcut - 3.0.1 +Copyright © 2011-2015 Caleb Troughton Licensed under the MIT license. https://github.com/imakewebthings/waypoints/blog/master/licenses.txt */ @@ -29,32 +29,30 @@ https://github.com/imakewebthings/waypoints/blog/master/licenses.txt /* Private */ Infinite.prototype.setupHandler = function() { this.options.handler = $.proxy(function() { - window.setTimeout($.proxy(function() { - this.options.onBeforePageLoad() - this.destroy() - this.$container.addClass(this.options.loadingClass) + this.options.onBeforePageLoad() + this.destroy() + this.$container.addClass(this.options.loadingClass) - $.get($(this.options.more).attr('href'), $.proxy(function(data) { - var $data = $($.parseHTML(data)) - var $newMore = $data.find(this.options.more) + $.get($(this.options.more).attr('href'), $.proxy(function(data) { + var $data = $($.parseHTML(data)) + var $newMore = $data.find(this.options.more) - this.$container.append($data.find(this.options.items)) - this.$container.removeClass(this.options.loadingClass) + this.$container.append($data.find(this.options.items)) + this.$container.removeClass(this.options.loadingClass) - if (!$newMore.length) { - $newMore = $data.filter(this.options.more) - } - if ($newMore.length) { - this.$more.replaceWith($newMore) - this.$more = $newMore - this.waypoint = new Waypoint(this.options) - } - else { - this.$more.remove() - } + if (!$newMore.length) { + $newMore = $data.filter(this.options.more) + } + if ($newMore.length) { + this.$more.replaceWith($newMore) + this.$more = $newMore + this.waypoint = new Waypoint(this.options) + } + else { + this.$more.remove() + } - this.options.onAfterPageLoad() - }, this), 0) + this.options.onAfterPageLoad() }, this)) }, this) } diff --git a/lib/shortcuts/infinite.min.js b/lib/shortcuts/infinite.min.js index d75dc286..2c1ae9f0 100644 --- a/lib/shortcuts/infinite.min.js +++ b/lib/shortcuts/infinite.min.js @@ -1,7 +1,7 @@ /*! -Waypoints Infinite Scroll Shortcut - 3.0.0 -Copyright © 2011-2014 Caleb Troughton +Waypoints Infinite Scroll Shortcut - 3.0.1 +Copyright © 2011-2015 Caleb Troughton Licensed under the MIT license. https://github.com/imakewebthings/waypoints/blog/master/licenses.txt */ -!function(){"use strict";function t(n){this.options=i.extend({},t.defaults,n),this.container=this.options.element,"auto"!==this.options.container&&(this.container=this.options.container),this.$container=i(this.container),this.$more=i(this.options.more),this.$more.length&&(this.setupHandler(),this.waypoint=new o(this.options))}var i=window.jQuery,o=window.Waypoint;t.prototype.setupHandler=function(){this.options.handler=i.proxy(function(){window.setTimeout(i.proxy(function(){this.options.onBeforePageLoad(),this.destroy(),this.$container.addClass(this.options.loadingClass),i.get(i(this.options.more).attr("href"),i.proxy(function(t){var n=i(i.parseHTML(t)),e=n.find(this.options.more);this.$container.append(n.find(this.options.items)),this.$container.removeClass(this.options.loadingClass),e.length||(e=n.filter(this.options.more)),e.length?(this.$more.replaceWith(e),this.$more=e,this.waypoint=new o(this.options)):this.$more.remove(),this.options.onAfterPageLoad()},this),0)},this))},this)},t.prototype.destroy=function(){this.waypoint&&this.waypoint.destroy()},t.defaults={container:"auto",items:".infinite-item",more:".infinite-more-link",offset:"bottom-in-view",loadingClass:"infinite-loading",onBeforePageLoad:i.noop,onAfterPageLoad:i.noop},o.Infinite=t}(); \ No newline at end of file +!function(){"use strict";function t(n){this.options=i.extend({},t.defaults,n),this.container=this.options.element,"auto"!==this.options.container&&(this.container=this.options.container),this.$container=i(this.container),this.$more=i(this.options.more),this.$more.length&&(this.setupHandler(),this.waypoint=new o(this.options))}var i=window.jQuery,o=window.Waypoint;t.prototype.setupHandler=function(){this.options.handler=i.proxy(function(){this.options.onBeforePageLoad(),this.destroy(),this.$container.addClass(this.options.loadingClass),i.get(i(this.options.more).attr("href"),i.proxy(function(t){var n=i(i.parseHTML(t)),e=n.find(this.options.more);this.$container.append(n.find(this.options.items)),this.$container.removeClass(this.options.loadingClass),e.length||(e=n.filter(this.options.more)),e.length?(this.$more.replaceWith(e),this.$more=e,this.waypoint=new o(this.options)):this.$more.remove(),this.options.onAfterPageLoad()},this))},this)},t.prototype.destroy=function(){this.waypoint&&this.waypoint.destroy()},t.defaults={container:"auto",items:".infinite-item",more:".infinite-more-link",offset:"bottom-in-view",loadingClass:"infinite-loading",onBeforePageLoad:i.noop,onAfterPageLoad:i.noop},o.Infinite=t}(); \ No newline at end of file diff --git a/lib/shortcuts/inview.js b/lib/shortcuts/inview.js index cd707e5e..e5009c48 100644 --- a/lib/shortcuts/inview.js +++ b/lib/shortcuts/inview.js @@ -1,6 +1,6 @@ /*! -Waypoints Inview Shortcut - 3.0.0 -Copyright © 2011-2014 Caleb Troughton +Waypoints Inview Shortcut - 3.0.1 +Copyright © 2011-2015 Caleb Troughton Licensed under the MIT license. https://github.com/imakewebthings/waypoints/blog/master/licenses.txt */ diff --git a/lib/shortcuts/inview.min.js b/lib/shortcuts/inview.min.js index 029741c2..c8837186 100644 --- a/lib/shortcuts/inview.min.js +++ b/lib/shortcuts/inview.min.js @@ -1,6 +1,6 @@ /*! -Waypoints Inview Shortcut - 3.0.0 -Copyright © 2011-2014 Caleb Troughton +Waypoints Inview Shortcut - 3.0.1 +Copyright © 2011-2015 Caleb Troughton Licensed under the MIT license. https://github.com/imakewebthings/waypoints/blog/master/licenses.txt */ diff --git a/lib/shortcuts/sticky.js b/lib/shortcuts/sticky.js index 96a43134..4492cfbf 100644 --- a/lib/shortcuts/sticky.js +++ b/lib/shortcuts/sticky.js @@ -1,6 +1,6 @@ /*! -Waypoints Sticky Element Shortcut - 3.0.0 -Copyright © 2011-2014 Caleb Troughton +Waypoints Sticky Element Shortcut - 3.0.1 +Copyright © 2011-2015 Caleb Troughton Licensed under the MIT license. https://github.com/imakewebthings/waypoints/blog/master/licenses.txt */ diff --git a/lib/shortcuts/sticky.min.js b/lib/shortcuts/sticky.min.js index d728d36e..65de4c41 100644 --- a/lib/shortcuts/sticky.min.js +++ b/lib/shortcuts/sticky.min.js @@ -1,6 +1,6 @@ /*! -Waypoints Sticky Element Shortcut - 3.0.0 -Copyright © 2011-2014 Caleb Troughton +Waypoints Sticky Element Shortcut - 3.0.1 +Copyright © 2011-2015 Caleb Troughton Licensed under the MIT license. https://github.com/imakewebthings/waypoints/blog/master/licenses.txt */ diff --git a/lib/waypoints.debug.js b/lib/waypoints.debug.js index 2f89f370..83dc01d0 100644 --- a/lib/waypoints.debug.js +++ b/lib/waypoints.debug.js @@ -1,6 +1,6 @@ /*! -Waypoints Debug - 3.0.0 -Copyright © 2011-2014 Caleb Troughton +Waypoints Debug - 3.0.1 +Copyright © 2011-2015 Caleb Troughton Licensed under the MIT license. https://github.com/imakewebthings/waypoints/blog/master/licenses.txt */ diff --git a/lib/zepto.waypoints.js b/lib/zepto.waypoints.js index 59918448..f747ba2a 100644 --- a/lib/zepto.waypoints.js +++ b/lib/zepto.waypoints.js @@ -1,6 +1,6 @@ /*! -Waypoints - 3.0.0 -Copyright © 2011-2014 Caleb Troughton +Waypoints - 3.0.1 +Copyright © 2011-2015 Caleb Troughton Licensed under the MIT license. https://github.com/imakewebthings/waypoints/blog/master/licenses.txt */ @@ -157,10 +157,6 @@ https://github.com/imakewebthings/waypoints/blog/master/licenses.txt var keyCounter = 0 var contexts = {} var Waypoint = window.Waypoint - var requestAnimationFrame = window.requestAnimationFrame || - window.mozRequestAnimationFrame || - window.webkitRequestAnimationFrame || - requestAnimationFrameShim var oldWindowLoad = window.onload /* http://imakewebthings.com/waypoints/api/context */ @@ -217,7 +213,7 @@ https://github.com/imakewebthings/waypoints/blog/master/licenses.txt this.adapter.on('resize.waypoints', function() { if (!self.didResize) { self.didResize = true - requestAnimationFrame(resizeHandler) + Waypoint.requestAnimationFrame(resizeHandler) } }) } @@ -233,7 +229,7 @@ https://github.com/imakewebthings/waypoints/blog/master/licenses.txt this.adapter.on('scroll.waypoints', function() { if (!self.didScroll || Waypoint.isTouch) { self.didScroll = true - requestAnimationFrame(scrollHandler) + Waypoint.requestAnimationFrame(scrollHandler) } }) } @@ -433,6 +429,11 @@ https://github.com/imakewebthings/waypoints/blog/master/licenses.txt } Context.refreshAll() } + + Waypoint.requestAnimationFrame = window.requestAnimationFrame || + window.mozRequestAnimationFrame || + window.webkitRequestAnimationFrame || + requestAnimationFrameShim Waypoint.Context = Context }()) ;(function() { diff --git a/lib/zepto.waypoints.min.js b/lib/zepto.waypoints.min.js index afdae20f..d9a3c062 100644 --- a/lib/zepto.waypoints.min.js +++ b/lib/zepto.waypoints.min.js @@ -1,7 +1,7 @@ /*! -Waypoints - 3.0.0 -Copyright © 2011-2014 Caleb Troughton +Waypoints - 3.0.1 +Copyright © 2011-2015 Caleb Troughton Licensed under the MIT license. https://github.com/imakewebthings/waypoints/blog/master/licenses.txt */ -!function(){"use strict";function t(i){if(!i)throw new Error("No options passed to Waypoint constructor");if(!i.element)throw new Error("No element option passed to Waypoint constructor");if(!i.handler)throw new Error("No handler option passed to Waypoint constructor");this.key="waypoint-"+e,this.options=t.Adapter.extend({},t.defaults,i),this.element=this.options.element,this.adapter=new t.Adapter(this.element),this.callback=i.handler,this.axis=this.options.horizontal?"horizontal":"vertical",this.enabled=this.options.enabled,this.triggerPoint=null,this.group=t.Group.findOrCreate({name:this.options.group,axis:this.axis}),this.context=t.Context.findOrCreateByElement(this.options.context),t.offsetAliases[this.options.offset]&&(this.options.offset=t.offsetAliases[this.options.offset]),this.group.add(this),this.context.add(this),o[this.key]=this,e+=1}var e=0,o={};t.prototype.queueTrigger=function(t){this.group.queueTrigger(this,t)},t.prototype.trigger=function(t){this.enabled&&this.callback&&this.callback.apply(this,t)},t.prototype.destroy=function(){this.context.remove(this),this.group.remove(this),delete o[this.key]},t.prototype.disable=function(){return this.enabled=!1,this},t.prototype.enable=function(){return this.context.refresh(),this.enabled=!0,this},t.prototype.next=function(){return this.group.next(this)},t.prototype.previous=function(){return this.group.previous(this)},t.destroyAll=function(){var t=[];for(var e in o)t.push(o[e]);for(var i=0,n=t.length;n>i;i++)t[i].destroy()},t.refreshAll=function(){t.Context.refreshAll()},t.viewportHeight=function(){return window.innerHeight||document.documentElement.clientHeight},t.viewportWidth=function(){return document.documentElement.clientWidth},t.adapters=[],t.defaults={context:window,continuous:!0,enabled:!0,group:"default",horizontal:!1,offset:0},t.offsetAliases={"bottom-in-view":function(){return this.context.innerHeight()-this.adapter.outerHeight()},"right-in-view":function(){return this.context.innerWidth()-this.adapter.outerWidth()}},window.Waypoint=t}(),function(){"use strict";function t(t){window.setTimeout(t,1e3/60)}function e(t){this.element=t,this.Adapter=n.Adapter,this.adapter=new this.Adapter(t),this.key="waypoint-context-"+o,this.didScroll=!1,this.didResize=!1,this.oldScroll={x:this.adapter.scrollLeft(),y:this.adapter.scrollTop()},this.waypoints={vertical:{},horizontal:{}},t.waypointContextKey=this.key,i[t.waypointContextKey]=this,o+=1,this.createThrottledScrollHandler(),this.createThrottledResizeHandler()}var o=0,i={},n=window.Waypoint,r=window.requestAnimationFrame||window.mozRequestAnimationFrame||window.webkitRequestAnimationFrame||t,s=window.onload;e.prototype.add=function(t){var e=t.options.horizontal?"horizontal":"vertical";this.waypoints[e][t.key]=t,this.refresh()},e.prototype.checkEmpty=function(){var t=this.Adapter.isEmptyObject(this.waypoints.horizontal),e=this.Adapter.isEmptyObject(this.waypoints.vertical);t&&e&&(this.adapter.off(".waypoints"),delete i[this.key])},e.prototype.createThrottledResizeHandler=function(){function t(){e.handleResize(),e.didResize=!1}var e=this;this.adapter.on("resize.waypoints",function(){e.didResize||(e.didResize=!0,r(t))})},e.prototype.createThrottledScrollHandler=function(){function t(){e.handleScroll(),e.didScroll=!1}var e=this;this.adapter.on("scroll.waypoints",function(){(!e.didScroll||n.isTouch)&&(e.didScroll=!0,r(t))})},e.prototype.handleResize=function(){n.Context.refreshAll()},e.prototype.handleScroll=function(){var t={},e={horizontal:{newScroll:this.adapter.scrollLeft(),oldScroll:this.oldScroll.x,forward:"right",backward:"left"},vertical:{newScroll:this.adapter.scrollTop(),oldScroll:this.oldScroll.y,forward:"down",backward:"up"}};for(var o in e){var i=e[o],n=i.newScroll>i.oldScroll,r=n?i.forward:i.backward;for(var s in this.waypoints[o]){var a=this.waypoints[o][s],l=i.oldScroll=a.triggerPoint,p=l&&h,c=!l&&!h;(p||c)&&(a.queueTrigger(r),t[a.group.id]=a.group)}}for(var u in t)t[u].flushTriggers();this.oldScroll={x:e.horizontal.newScroll,y:e.vertical.newScroll}},e.prototype.innerHeight=function(){return this.element===this.element.window?n.viewportHeight():this.adapter.innerHeight()},e.prototype.remove=function(t){delete this.waypoints[t.axis][t.key],this.checkEmpty()},e.prototype.innerWidth=function(){return this.element===this.element.window?n.viewportWidth():this.adapter.innerWidth()},e.prototype.destroy=function(){var t=[];for(var e in this.waypoints)for(var o in this.waypoints[e])t.push(this.waypoints[e][o]);for(var i=0,n=t.length;n>i;i++)t[i].destroy()},e.prototype.refresh=function(){var t,e=this.element===this.element.window,o=this.adapter.offset(),i={};this.handleScroll(),t={horizontal:{contextOffset:e?0:o.left,contextScroll:e?0:this.oldScroll.x,contextDimension:this.innerWidth(),oldScroll:this.oldScroll.x,forward:"right",backward:"left",offsetProp:"left"},vertical:{contextOffset:e?0:o.top,contextScroll:e?0:this.oldScroll.y,contextDimension:this.innerHeight(),oldScroll:this.oldScroll.y,forward:"down",backward:"up",offsetProp:"top"}};for(var n in t){var r=t[n];for(var s in this.waypoints[n]){var a,l,h,p,c,u=this.waypoints[n][s],d=u.options.offset,f=u.triggerPoint,w=0,y=null==f;u.element!==u.element.window&&(w=u.adapter.offset()[r.offsetProp]),"function"==typeof d?d=d.apply(u):"string"==typeof d&&(d=parseFloat(d),u.options.offset.indexOf("%")>-1&&(d=Math.ceil(r.contextDimension*d/100))),a=r.contextScroll-r.contextOffset,u.triggerPoint=w+a-d,l=f=r.oldScroll,p=l&&h,c=!l&&!h,!y&&p?(u.queueTrigger(r.backward),i[u.group.id]=u.group):!y&&c?(u.queueTrigger(r.forward),i[u.group.id]=u.group):y&&r.oldScroll>=u.triggerPoint&&(u.queueTrigger(r.forward),i[u.group.id]=u.group)}}for(var g in i)i[g].flushTriggers();return this},e.findOrCreateByElement=function(t){return e.findByElement(t)||new e(t)},e.refreshAll=function(){for(var t in i)i[t].refresh()},e.findByElement=function(t){return i[t.waypointContextKey]},window.onload=function(){s&&s(),e.refreshAll()},n.Context=e}(),function(){"use strict";function t(t,e){return t.triggerPoint-e.triggerPoint}function e(t,e){return e.triggerPoint-t.triggerPoint}function o(t){this.name=t.name,this.axis=t.axis,this.id=this.name+"-"+this.axis,this.waypoints=[],this.clearTriggerQueues(),i[this.axis][this.name]=this}var i={vertical:{},horizontal:{}},n=window.Waypoint;o.prototype.add=function(t){this.waypoints.push(t)},o.prototype.clearTriggerQueues=function(){this.triggerQueues={up:[],down:[],left:[],right:[]}},o.prototype.flushTriggers=function(){for(var o in this.triggerQueues){var i=this.triggerQueues[o],n="up"===o||"left"===o;i.sort(n?e:t);for(var r=0,s=i.length;s>r;r+=1){var a=i[r];(a.options.continuous||r===i.length-1)&&a.trigger([o])}}this.clearTriggerQueues()},o.prototype.next=function(e){this.waypoints.sort(t);var o=n.Adapter.inArray(e,this.waypoints),i=o===this.waypoints.length-1;return i?null:this.waypoints[o+1]},o.prototype.previous=function(e){this.waypoints.sort(t);var o=n.Adapter.inArray(e,this.waypoints);return o?this.waypoints[o-1]:null},o.prototype.queueTrigger=function(t,e){this.triggerQueues[e].push(t)},o.prototype.remove=function(t){var e=n.Adapter.inArray(t,this.waypoints);e>-1&&this.waypoints.splice(e,1)},o.prototype.first=function(){return this.waypoints[0]},o.prototype.last=function(){return this.waypoints[this.waypoints.length-1]},o.findOrCreate=function(t){return i[t.axis][t.name]||new o(t)},n.Group=o}(),function(){"use strict";function t(t){this.element=t,this.$element=e(t)}var e=window.Zepto,o=window.Waypoint;e.each(["off","on","scrollLeft","scrollTop"],function(e,o){t.prototype[o]=function(){var t=Array.prototype.slice.call(arguments);return this.$element[o].apply(this.$element,t)}}),t.prototype.offset=function(){return this.element!==this.element.window?this.$element.offset():void 0},e.each(["width","height"],function(o,i){function n(t,o){return function(t){var n=this.$element,r=n[i](),s={width:["left","right"],height:["top","bottom"]};return e.each(s[i],function(e,i){r+=parseInt(n.css("padding-"+i),10),o&&(r+=parseInt(n.css("border-"+i+"-width"),10)),t&&(r+=parseInt(n.css("margin-"+i),10))}),r}}var r=e.camelCase("inner-"+i),s=e.camelCase("outer-"+i);t.prototype[r]=n(!1),t.prototype[s]=n(!0)}),e.each(["extend","inArray"],function(o,i){t[i]=e[i]}),t.isEmptyObject=function(t){for(var e in t)return!1;return!0},o.adapters.push({name:"zepto",Adapter:t}),o.Adapter=t}(),function(){"use strict";function t(t){return function(){var o=[],i=arguments[0];return t.isFunction(arguments[0])&&(i=t.extend({},arguments[1]),i.handler=arguments[0]),this.each(function(){var n=t.extend({},i,{element:this});"string"==typeof n.context&&(n.context=t(this).closest(n.context)[0]),o.push(new e(n))}),o}}var e=window.Waypoint;window.jQuery&&(window.jQuery.fn.waypoint=t(window.jQuery)),window.Zepto&&(window.Zepto.fn.waypoint=t(window.Zepto))}(); \ No newline at end of file +!function(){"use strict";function t(o){if(!o)throw new Error("No options passed to Waypoint constructor");if(!o.element)throw new Error("No element option passed to Waypoint constructor");if(!o.handler)throw new Error("No handler option passed to Waypoint constructor");this.key="waypoint-"+e,this.options=t.Adapter.extend({},t.defaults,o),this.element=this.options.element,this.adapter=new t.Adapter(this.element),this.callback=o.handler,this.axis=this.options.horizontal?"horizontal":"vertical",this.enabled=this.options.enabled,this.triggerPoint=null,this.group=t.Group.findOrCreate({name:this.options.group,axis:this.axis}),this.context=t.Context.findOrCreateByElement(this.options.context),t.offsetAliases[this.options.offset]&&(this.options.offset=t.offsetAliases[this.options.offset]),this.group.add(this),this.context.add(this),i[this.key]=this,e+=1}var e=0,i={};t.prototype.queueTrigger=function(t){this.group.queueTrigger(this,t)},t.prototype.trigger=function(t){this.enabled&&this.callback&&this.callback.apply(this,t)},t.prototype.destroy=function(){this.context.remove(this),this.group.remove(this),delete i[this.key]},t.prototype.disable=function(){return this.enabled=!1,this},t.prototype.enable=function(){return this.context.refresh(),this.enabled=!0,this},t.prototype.next=function(){return this.group.next(this)},t.prototype.previous=function(){return this.group.previous(this)},t.destroyAll=function(){var t=[];for(var e in i)t.push(i[e]);for(var o=0,n=t.length;n>o;o++)t[o].destroy()},t.refreshAll=function(){t.Context.refreshAll()},t.viewportHeight=function(){return window.innerHeight||document.documentElement.clientHeight},t.viewportWidth=function(){return document.documentElement.clientWidth},t.adapters=[],t.defaults={context:window,continuous:!0,enabled:!0,group:"default",horizontal:!1,offset:0},t.offsetAliases={"bottom-in-view":function(){return this.context.innerHeight()-this.adapter.outerHeight()},"right-in-view":function(){return this.context.innerWidth()-this.adapter.outerWidth()}},window.Waypoint=t}(),function(){"use strict";function t(t){window.setTimeout(t,1e3/60)}function e(t){this.element=t,this.Adapter=n.Adapter,this.adapter=new this.Adapter(t),this.key="waypoint-context-"+i,this.didScroll=!1,this.didResize=!1,this.oldScroll={x:this.adapter.scrollLeft(),y:this.adapter.scrollTop()},this.waypoints={vertical:{},horizontal:{}},t.waypointContextKey=this.key,o[t.waypointContextKey]=this,i+=1,this.createThrottledScrollHandler(),this.createThrottledResizeHandler()}var i=0,o={},n=window.Waypoint,r=window.onload;e.prototype.add=function(t){var e=t.options.horizontal?"horizontal":"vertical";this.waypoints[e][t.key]=t,this.refresh()},e.prototype.checkEmpty=function(){var t=this.Adapter.isEmptyObject(this.waypoints.horizontal),e=this.Adapter.isEmptyObject(this.waypoints.vertical);t&&e&&(this.adapter.off(".waypoints"),delete o[this.key])},e.prototype.createThrottledResizeHandler=function(){function t(){e.handleResize(),e.didResize=!1}var e=this;this.adapter.on("resize.waypoints",function(){e.didResize||(e.didResize=!0,n.requestAnimationFrame(t))})},e.prototype.createThrottledScrollHandler=function(){function t(){e.handleScroll(),e.didScroll=!1}var e=this;this.adapter.on("scroll.waypoints",function(){(!e.didScroll||n.isTouch)&&(e.didScroll=!0,n.requestAnimationFrame(t))})},e.prototype.handleResize=function(){n.Context.refreshAll()},e.prototype.handleScroll=function(){var t={},e={horizontal:{newScroll:this.adapter.scrollLeft(),oldScroll:this.oldScroll.x,forward:"right",backward:"left"},vertical:{newScroll:this.adapter.scrollTop(),oldScroll:this.oldScroll.y,forward:"down",backward:"up"}};for(var i in e){var o=e[i],n=o.newScroll>o.oldScroll,r=n?o.forward:o.backward;for(var s in this.waypoints[i]){var a=this.waypoints[i][s],l=o.oldScroll=a.triggerPoint,p=l&&h,c=!l&&!h;(p||c)&&(a.queueTrigger(r),t[a.group.id]=a.group)}}for(var u in t)t[u].flushTriggers();this.oldScroll={x:e.horizontal.newScroll,y:e.vertical.newScroll}},e.prototype.innerHeight=function(){return this.element===this.element.window?n.viewportHeight():this.adapter.innerHeight()},e.prototype.remove=function(t){delete this.waypoints[t.axis][t.key],this.checkEmpty()},e.prototype.innerWidth=function(){return this.element===this.element.window?n.viewportWidth():this.adapter.innerWidth()},e.prototype.destroy=function(){var t=[];for(var e in this.waypoints)for(var i in this.waypoints[e])t.push(this.waypoints[e][i]);for(var o=0,n=t.length;n>o;o++)t[o].destroy()},e.prototype.refresh=function(){var t,e=this.element===this.element.window,i=this.adapter.offset(),o={};this.handleScroll(),t={horizontal:{contextOffset:e?0:i.left,contextScroll:e?0:this.oldScroll.x,contextDimension:this.innerWidth(),oldScroll:this.oldScroll.x,forward:"right",backward:"left",offsetProp:"left"},vertical:{contextOffset:e?0:i.top,contextScroll:e?0:this.oldScroll.y,contextDimension:this.innerHeight(),oldScroll:this.oldScroll.y,forward:"down",backward:"up",offsetProp:"top"}};for(var n in t){var r=t[n];for(var s in this.waypoints[n]){var a,l,h,p,c,u=this.waypoints[n][s],d=u.options.offset,f=u.triggerPoint,w=0,y=null==f;u.element!==u.element.window&&(w=u.adapter.offset()[r.offsetProp]),"function"==typeof d?d=d.apply(u):"string"==typeof d&&(d=parseFloat(d),u.options.offset.indexOf("%")>-1&&(d=Math.ceil(r.contextDimension*d/100))),a=r.contextScroll-r.contextOffset,u.triggerPoint=w+a-d,l=f=r.oldScroll,p=l&&h,c=!l&&!h,!y&&p?(u.queueTrigger(r.backward),o[u.group.id]=u.group):!y&&c?(u.queueTrigger(r.forward),o[u.group.id]=u.group):y&&r.oldScroll>=u.triggerPoint&&(u.queueTrigger(r.forward),o[u.group.id]=u.group)}}for(var g in o)o[g].flushTriggers();return this},e.findOrCreateByElement=function(t){return e.findByElement(t)||new e(t)},e.refreshAll=function(){for(var t in o)o[t].refresh()},e.findByElement=function(t){return o[t.waypointContextKey]},window.onload=function(){r&&r(),e.refreshAll()},n.requestAnimationFrame=window.requestAnimationFrame||window.mozRequestAnimationFrame||window.webkitRequestAnimationFrame||t,n.Context=e}(),function(){"use strict";function t(t,e){return t.triggerPoint-e.triggerPoint}function e(t,e){return e.triggerPoint-t.triggerPoint}function i(t){this.name=t.name,this.axis=t.axis,this.id=this.name+"-"+this.axis,this.waypoints=[],this.clearTriggerQueues(),o[this.axis][this.name]=this}var o={vertical:{},horizontal:{}},n=window.Waypoint;i.prototype.add=function(t){this.waypoints.push(t)},i.prototype.clearTriggerQueues=function(){this.triggerQueues={up:[],down:[],left:[],right:[]}},i.prototype.flushTriggers=function(){for(var i in this.triggerQueues){var o=this.triggerQueues[i],n="up"===i||"left"===i;o.sort(n?e:t);for(var r=0,s=o.length;s>r;r+=1){var a=o[r];(a.options.continuous||r===o.length-1)&&a.trigger([i])}}this.clearTriggerQueues()},i.prototype.next=function(e){this.waypoints.sort(t);var i=n.Adapter.inArray(e,this.waypoints),o=i===this.waypoints.length-1;return o?null:this.waypoints[i+1]},i.prototype.previous=function(e){this.waypoints.sort(t);var i=n.Adapter.inArray(e,this.waypoints);return i?this.waypoints[i-1]:null},i.prototype.queueTrigger=function(t,e){this.triggerQueues[e].push(t)},i.prototype.remove=function(t){var e=n.Adapter.inArray(t,this.waypoints);e>-1&&this.waypoints.splice(e,1)},i.prototype.first=function(){return this.waypoints[0]},i.prototype.last=function(){return this.waypoints[this.waypoints.length-1]},i.findOrCreate=function(t){return o[t.axis][t.name]||new i(t)},n.Group=i}(),function(){"use strict";function t(t){this.element=t,this.$element=e(t)}var e=window.Zepto,i=window.Waypoint;e.each(["off","on","scrollLeft","scrollTop"],function(e,i){t.prototype[i]=function(){var t=Array.prototype.slice.call(arguments);return this.$element[i].apply(this.$element,t)}}),t.prototype.offset=function(){return this.element!==this.element.window?this.$element.offset():void 0},e.each(["width","height"],function(i,o){function n(t,i){return function(t){var n=this.$element,r=n[o](),s={width:["left","right"],height:["top","bottom"]};return e.each(s[o],function(e,o){r+=parseInt(n.css("padding-"+o),10),i&&(r+=parseInt(n.css("border-"+o+"-width"),10)),t&&(r+=parseInt(n.css("margin-"+o),10))}),r}}var r=e.camelCase("inner-"+o),s=e.camelCase("outer-"+o);t.prototype[r]=n(!1),t.prototype[s]=n(!0)}),e.each(["extend","inArray"],function(i,o){t[o]=e[o]}),t.isEmptyObject=function(t){for(var e in t)return!1;return!0},i.adapters.push({name:"zepto",Adapter:t}),i.Adapter=t}(),function(){"use strict";function t(t){return function(){var i=[],o=arguments[0];return t.isFunction(arguments[0])&&(o=t.extend({},arguments[1]),o.handler=arguments[0]),this.each(function(){var n=t.extend({},o,{element:this});"string"==typeof n.context&&(n.context=t(this).closest(n.context)[0]),i.push(new e(n))}),i}}var e=window.Waypoint;window.jQuery&&(window.jQuery.fn.waypoint=t(window.jQuery)),window.Zepto&&(window.Zepto.fn.waypoint=t(window.Zepto))}(); \ No newline at end of file diff --git a/src/context.js b/src/context.js index 2695cf65..48259d7f 100644 --- a/src/context.js +++ b/src/context.js @@ -8,10 +8,6 @@ var keyCounter = 0 var contexts = {} var Waypoint = window.Waypoint - var requestAnimationFrame = window.requestAnimationFrame || - window.mozRequestAnimationFrame || - window.webkitRequestAnimationFrame || - requestAnimationFrameShim var oldWindowLoad = window.onload /* http://imakewebthings.com/waypoints/api/context */ @@ -68,7 +64,7 @@ this.adapter.on('resize.waypoints', function() { if (!self.didResize) { self.didResize = true - requestAnimationFrame(resizeHandler) + Waypoint.requestAnimationFrame(resizeHandler) } }) } @@ -84,7 +80,7 @@ this.adapter.on('scroll.waypoints', function() { if (!self.didScroll || Waypoint.isTouch) { self.didScroll = true - requestAnimationFrame(scrollHandler) + Waypoint.requestAnimationFrame(scrollHandler) } }) } @@ -284,5 +280,10 @@ } Context.refreshAll() } + + Waypoint.requestAnimationFrame = window.requestAnimationFrame || + window.mozRequestAnimationFrame || + window.webkitRequestAnimationFrame || + requestAnimationFrameShim Waypoint.Context = Context }()) diff --git a/test/adapter-fn-spec.js b/test/adapter-fn-spec.js index eca92b9e..cd171ed6 100644 --- a/test/adapter-fn-spec.js +++ b/test/adapter-fn-spec.js @@ -20,7 +20,6 @@ window.jQuery.each(window.jQuery.grep(Waypoint.adapters, function(adapter) { $.each(waypoints, function(i, waypoint) { waypoint.destroy() }) - waits(50) }) describe('waypoint initialization', function() { diff --git a/test/context-spec.js b/test/context-spec.js index 8593c978..c4c904d4 100644 --- a/test/context-spec.js +++ b/test/context-spec.js @@ -1,14 +1,13 @@ 'use strict' /* global - * describe, it, beforeEach, afterEach, expect, spyOn, waits, runs, - * waitsFor, loadFixtures, Waypoint + * describe, it, beforeEach, afterEach, expect, spyOn, runs, + * loadFixtures, Waypoint */ window.jQuery.each(Waypoint.adapters, function(i, adapter) { describe(adapter.name + ' adapter:', function() { describe('Waypoint.Context', function() { var $ = window.jQuery - var standard = 50 var currentDirection, $scroller, waypoint, $target, context, skipDestroy function setDirection(direction) { @@ -34,7 +33,6 @@ window.jQuery.each(Waypoint.adapters, function(i, adapter) { waypoint.destroy() } $scroller.scrollTop(0).scrollLeft(0) - waits(standard) }) describe('#refresh', function() { @@ -69,14 +67,9 @@ window.jQuery.each(Waypoint.adapters, function(i, adapter) { describe('#destroy', function() { it('prevents further waypoint triggers', function() { skipDestroy = true - runs(function() { - context.destroy() - $scroller.scrollTop($target.offset().top) - }) - waits(standard) - runs(function() { - expect(currentDirection).toBeNull() - }) + context.destroy() + $scroller.scrollTop($target.offset().top) + expect(currentDirection).toBeNull() }) it('removes context from global lookup', function() { diff --git a/test/debug-spec.js b/test/debug-spec.js index b791dbbb..54833834 100644 --- a/test/debug-spec.js +++ b/test/debug-spec.js @@ -1,8 +1,8 @@ 'use strict' /* global - * describe, it, beforeEach, afterEach, expect, spyOn, waits, runs, - * waitsFor, loadFixtures, Waypoint + * describe, it, beforeEach, afterEach, expect, spyOn, + * loadFixtures, Waypoint */ describe('Waypoints debug script', function() { diff --git a/test/group-spec.js b/test/group-spec.js index 613f7be1..4930d984 100644 --- a/test/group-spec.js +++ b/test/group-spec.js @@ -1,14 +1,13 @@ 'use strict' /* global - * describe, it, beforeEach, afterEach, expect, spyOn, waits, runs, - * waitsFor, loadFixtures, Waypoint + * describe, it, beforeEach, afterEach, expect, spyOn, + * loadFixtures, Waypoint */ window.jQuery.each(Waypoint.adapters, function(i, adapter) { describe(adapter.name + ' adapter:', function() { describe('Waypoint.Group', function() { var $ = window.jQuery - var standard = 50 var firstWaypoint, secondWaypoint, customGroupWaypoint, defaultGroup beforeEach(function() { @@ -34,7 +33,6 @@ window.jQuery.each(Waypoint.adapters, function(i, adapter) { firstWaypoint.destroy() secondWaypoint.destroy() customGroupWaypoint.destroy() - waits(standard) }) describe('#previous(waypoint)', function() { diff --git a/test/infinite-spec.js b/test/infinite-spec.js index f54c1c08..0571e674 100644 --- a/test/infinite-spec.js +++ b/test/infinite-spec.js @@ -1,12 +1,11 @@ 'use strict' /* global - * describe, it, beforeEach, afterEach, expect, spyOn, waits, runs, + * describe, it, beforeEach, afterEach, expect, spyOn, runs, * waitsFor, loadFixtures, Waypoint, jasmine */ describe('Waypoint Sticky Shortcut', function() { var $ = window.jQuery - var standard = 50 var $scroller = $(window) var $container, $items, $more, waypoint, beforeSpy, afterSpy @@ -22,7 +21,6 @@ describe('Waypoint Sticky Shortcut', function() { afterEach(function() { waypoint.destroy() $scroller.scrollTop(0) - waits(standard) }) it('returns an instance of the Waypoint.Infinite class', function() { diff --git a/test/inview-spec.js b/test/inview-spec.js index 55e8b999..5bd94160 100644 --- a/test/inview-spec.js +++ b/test/inview-spec.js @@ -34,7 +34,6 @@ window.jQuery.each(Waypoint.adapters, function(i, adapter) { afterEach(function() { waypoint.destroy() $scroller.scrollTop(0).scrollLeft(0) - waits(standard) }) describe('vertical', function() { @@ -228,7 +227,7 @@ window.jQuery.each(Waypoint.adapters, function(i, adapter) { var left = $target.offset().left $scroller.scrollLeft(left - $scroller.width()) }) - waits(standard) + waitsFor(toBeTrue('enter'), 'enter to trigger') runs(function() { $scroller.scrollLeft($scroller.scrollLeft() - 1) }) diff --git a/test/settings.js b/test/settings.js index 3fabcd3a..0cdda718 100644 --- a/test/settings.js +++ b/test/settings.js @@ -1,4 +1,9 @@ -/* global jasmine */ +/* global jasmine, Waypoint */ + +'use strict' jasmine.getFixtures().fixturesPath = 'test/fixtures' jasmine.getEnv().defaultTimeoutInterval = 1000 +Waypoint.requestAnimationFrame = function(callback) { + callback() +} diff --git a/test/sticky-spec.js b/test/sticky-spec.js index 53f6bc02..447b8eee 100644 --- a/test/sticky-spec.js +++ b/test/sticky-spec.js @@ -6,7 +6,6 @@ describe('Waypoint Sticky Shortcut', function() { var $ = window.jQuery - var standard = 50 var $scroller = $(window) var $sticky, waypoint, handlerSpy @@ -25,7 +24,6 @@ describe('Waypoint Sticky Shortcut', function() { waypoint.destroy() } $scroller.scrollTop(0) - waits(standard) }) describe('on init', function() { @@ -65,9 +63,7 @@ describe('Waypoint Sticky Shortcut', function() { }) it('executes handler option after stuck class applied', function() { - waitsFor(function() { - return handlerSpy.callCount - }, 'callback to trigger') + expect(handlerSpy).toHaveBeenCalled() }) }) }) diff --git a/test/waypoint-spec.js b/test/waypoint-spec.js index e4519ec1..bb4c38a3 100644 --- a/test/waypoint-spec.js +++ b/test/waypoint-spec.js @@ -30,7 +30,6 @@ window.jQuery.each(Waypoint.adapters, function(i, adapter) { afterEach(function() { Waypoint.destroyAll() $scroller.scrollTop(0).scrollLeft(0) - waits(standard) }) describe('new Waypoint()', function() { @@ -70,9 +69,6 @@ window.jQuery.each(Waypoint.adapters, function(i, adapter) { runs(function() { $target = $('#same2') $scroller.scrollTop($target.offset().top + 1) - }) - waits(standard) - runs(function() { waypoint = new Waypoint({ element: $target[0], handler: function(direction) { @@ -127,9 +123,6 @@ window.jQuery.each(Waypoint.adapters, function(i, adapter) { offset: 50 }) $scroller.scrollTop($target.offset().top - 51) - }) - waits(standard) - runs(function() { expect(hit).toBeFalsy() $scroller.scrollTop($target.offset().top - 50) }) @@ -145,9 +138,6 @@ window.jQuery.each(Waypoint.adapters, function(i, adapter) { offset: '37%' }) $scroller.scrollTop(trigger - 1) - }) - waits(standard) - runs(function() { expect(hit).toBeFalsy() $scroller.scrollTop(trigger) }) @@ -164,9 +154,6 @@ window.jQuery.each(Waypoint.adapters, function(i, adapter) { } }) $scroller.scrollTop($target.offset().top + $target.height() - 1) - }) - waits(standard) - runs(function() { expect(hit).toBeFalsy() $scroller.scrollTop($target.offset().top + $target.height()) }) @@ -185,9 +172,6 @@ window.jQuery.each(Waypoint.adapters, function(i, adapter) { offset: 'bottom-in-view' }) $scroller.scrollTop(inview - 1) - }) - waits(standard) - runs(function() { expect(hit).toBeFalsy() $scroller.scrollTop(inview) }) @@ -210,9 +194,6 @@ window.jQuery.each(Waypoint.adapters, function(i, adapter) { }) runs(function() { $scroller.scrollTop(189) - }) - waits(standard) - runs(function() { expect(hit).toBeFalsy() $scroller.scrollTop(190) }) @@ -228,9 +209,6 @@ window.jQuery.each(Waypoint.adapters, function(i, adapter) { }) runs(function() { $scroller.scrollTop(149) - }) - waits(standard) - runs(function() { expect(hit).toBeFalsy() $scroller.scrollTop(150) }) @@ -248,9 +226,6 @@ window.jQuery.each(Waypoint.adapters, function(i, adapter) { }) runs(function() { $scroller.scrollTop(149) - }) - waits(standard) - runs(function() { expect(hit).toBeFalsy() $scroller.scrollTop(150) }) @@ -266,9 +241,6 @@ window.jQuery.each(Waypoint.adapters, function(i, adapter) { }) runs(function() { $scroller.scrollTop(249) - }) - waits(standard) - runs(function() { expect(hit).toBeFalsy() $scroller.scrollTop(250) }) From 6b72b7898e5d3d15c5587416248193b799aea253 Mon Sep 17 00:00:00 2001 From: imakewebthings Date: Wed, 14 Jan 2015 14:04:40 -0800 Subject: [PATCH 64/98] Add enableAll and disableAll methods --- lib/jquery.waypoints.js | 25 +++++++++++++++++---- lib/jquery.waypoints.min.js | 2 +- lib/noframework.waypoints.js | 25 +++++++++++++++++---- lib/noframework.waypoints.min.js | 2 +- lib/shortcuts/infinite.js | 7 +++++- lib/shortcuts/infinite.min.js | 2 +- lib/zepto.waypoints.js | 25 +++++++++++++++++---- lib/zepto.waypoints.min.js | 2 +- src/waypoint.js | 25 +++++++++++++++++---- test/waypoint-spec.js | 37 +++++++++++++++++++++++++++++++- 10 files changed, 130 insertions(+), 22 deletions(-) diff --git a/lib/jquery.waypoints.js b/lib/jquery.waypoints.js index 1f0e0631..ddf4ddc4 100644 --- a/lib/jquery.waypoints.js +++ b/lib/jquery.waypoints.js @@ -95,18 +95,35 @@ https://github.com/imakewebthings/waypoints/blog/master/licenses.txt return this.group.previous(this) } - /* Public */ - /* http://imakewebthings.com/waypoints/api/destroy-all */ - Waypoint.destroyAll = function() { + /* Private */ + Waypoint.invokeAll = function(method) { var allWaypointsArray = [] for (var waypointKey in allWaypoints) { allWaypointsArray.push(allWaypoints[waypointKey]) } for (var i = 0, end = allWaypointsArray.length; i < end; i++) { - allWaypointsArray[i].destroy() + allWaypointsArray[i][method]() } } + /* Public */ + /* http://imakewebthings.com/waypoints/api/destroy-all */ + Waypoint.destroyAll = function() { + Waypoint.invokeAll('destroy') + } + + /* Public */ + /* http://imakewebthings.com/waypoints/api/disable-all */ + Waypoint.disableAll = function() { + Waypoint.invokeAll('disable') + } + + /* Public */ + /* http://imakewebthings.com/waypoints/api/enable-all */ + Waypoint.enableAll = function() { + Waypoint.invokeAll('enable') + } + /* Public */ /* http://imakewebthings.com/waypoints/api/refresh-all */ Waypoint.refreshAll = function() { diff --git a/lib/jquery.waypoints.min.js b/lib/jquery.waypoints.min.js index 4bbeaa61..f4a3168b 100644 --- a/lib/jquery.waypoints.min.js +++ b/lib/jquery.waypoints.min.js @@ -4,4 +4,4 @@ Copyright © 2011-2015 Caleb Troughton Licensed under the MIT license. https://github.com/imakewebthings/waypoints/blog/master/licenses.txt */ -!function(){"use strict";function t(o){if(!o)throw new Error("No options passed to Waypoint constructor");if(!o.element)throw new Error("No element option passed to Waypoint constructor");if(!o.handler)throw new Error("No handler option passed to Waypoint constructor");this.key="waypoint-"+e,this.options=t.Adapter.extend({},t.defaults,o),this.element=this.options.element,this.adapter=new t.Adapter(this.element),this.callback=o.handler,this.axis=this.options.horizontal?"horizontal":"vertical",this.enabled=this.options.enabled,this.triggerPoint=null,this.group=t.Group.findOrCreate({name:this.options.group,axis:this.axis}),this.context=t.Context.findOrCreateByElement(this.options.context),t.offsetAliases[this.options.offset]&&(this.options.offset=t.offsetAliases[this.options.offset]),this.group.add(this),this.context.add(this),i[this.key]=this,e+=1}var e=0,i={};t.prototype.queueTrigger=function(t){this.group.queueTrigger(this,t)},t.prototype.trigger=function(t){this.enabled&&this.callback&&this.callback.apply(this,t)},t.prototype.destroy=function(){this.context.remove(this),this.group.remove(this),delete i[this.key]},t.prototype.disable=function(){return this.enabled=!1,this},t.prototype.enable=function(){return this.context.refresh(),this.enabled=!0,this},t.prototype.next=function(){return this.group.next(this)},t.prototype.previous=function(){return this.group.previous(this)},t.destroyAll=function(){var t=[];for(var e in i)t.push(i[e]);for(var o=0,r=t.length;r>o;o++)t[o].destroy()},t.refreshAll=function(){t.Context.refreshAll()},t.viewportHeight=function(){return window.innerHeight||document.documentElement.clientHeight},t.viewportWidth=function(){return document.documentElement.clientWidth},t.adapters=[],t.defaults={context:window,continuous:!0,enabled:!0,group:"default",horizontal:!1,offset:0},t.offsetAliases={"bottom-in-view":function(){return this.context.innerHeight()-this.adapter.outerHeight()},"right-in-view":function(){return this.context.innerWidth()-this.adapter.outerWidth()}},window.Waypoint=t}(),function(){"use strict";function t(t){window.setTimeout(t,1e3/60)}function e(t){this.element=t,this.Adapter=r.Adapter,this.adapter=new this.Adapter(t),this.key="waypoint-context-"+i,this.didScroll=!1,this.didResize=!1,this.oldScroll={x:this.adapter.scrollLeft(),y:this.adapter.scrollTop()},this.waypoints={vertical:{},horizontal:{}},t.waypointContextKey=this.key,o[t.waypointContextKey]=this,i+=1,this.createThrottledScrollHandler(),this.createThrottledResizeHandler()}var i=0,o={},r=window.Waypoint,n=window.onload;e.prototype.add=function(t){var e=t.options.horizontal?"horizontal":"vertical";this.waypoints[e][t.key]=t,this.refresh()},e.prototype.checkEmpty=function(){var t=this.Adapter.isEmptyObject(this.waypoints.horizontal),e=this.Adapter.isEmptyObject(this.waypoints.vertical);t&&e&&(this.adapter.off(".waypoints"),delete o[this.key])},e.prototype.createThrottledResizeHandler=function(){function t(){e.handleResize(),e.didResize=!1}var e=this;this.adapter.on("resize.waypoints",function(){e.didResize||(e.didResize=!0,r.requestAnimationFrame(t))})},e.prototype.createThrottledScrollHandler=function(){function t(){e.handleScroll(),e.didScroll=!1}var e=this;this.adapter.on("scroll.waypoints",function(){(!e.didScroll||r.isTouch)&&(e.didScroll=!0,r.requestAnimationFrame(t))})},e.prototype.handleResize=function(){r.Context.refreshAll()},e.prototype.handleScroll=function(){var t={},e={horizontal:{newScroll:this.adapter.scrollLeft(),oldScroll:this.oldScroll.x,forward:"right",backward:"left"},vertical:{newScroll:this.adapter.scrollTop(),oldScroll:this.oldScroll.y,forward:"down",backward:"up"}};for(var i in e){var o=e[i],r=o.newScroll>o.oldScroll,n=r?o.forward:o.backward;for(var s in this.waypoints[i]){var a=this.waypoints[i][s],l=o.oldScroll=a.triggerPoint,p=l&&h,u=!l&&!h;(p||u)&&(a.queueTrigger(n),t[a.group.id]=a.group)}}for(var c in t)t[c].flushTriggers();this.oldScroll={x:e.horizontal.newScroll,y:e.vertical.newScroll}},e.prototype.innerHeight=function(){return this.element===this.element.window?r.viewportHeight():this.adapter.innerHeight()},e.prototype.remove=function(t){delete this.waypoints[t.axis][t.key],this.checkEmpty()},e.prototype.innerWidth=function(){return this.element===this.element.window?r.viewportWidth():this.adapter.innerWidth()},e.prototype.destroy=function(){var t=[];for(var e in this.waypoints)for(var i in this.waypoints[e])t.push(this.waypoints[e][i]);for(var o=0,r=t.length;r>o;o++)t[o].destroy()},e.prototype.refresh=function(){var t,e=this.element===this.element.window,i=this.adapter.offset(),o={};this.handleScroll(),t={horizontal:{contextOffset:e?0:i.left,contextScroll:e?0:this.oldScroll.x,contextDimension:this.innerWidth(),oldScroll:this.oldScroll.x,forward:"right",backward:"left",offsetProp:"left"},vertical:{contextOffset:e?0:i.top,contextScroll:e?0:this.oldScroll.y,contextDimension:this.innerHeight(),oldScroll:this.oldScroll.y,forward:"down",backward:"up",offsetProp:"top"}};for(var r in t){var n=t[r];for(var s in this.waypoints[r]){var a,l,h,p,u,c=this.waypoints[r][s],d=c.options.offset,f=c.triggerPoint,w=0,y=null==f;c.element!==c.element.window&&(w=c.adapter.offset()[n.offsetProp]),"function"==typeof d?d=d.apply(c):"string"==typeof d&&(d=parseFloat(d),c.options.offset.indexOf("%")>-1&&(d=Math.ceil(n.contextDimension*d/100))),a=n.contextScroll-n.contextOffset,c.triggerPoint=w+a-d,l=f=n.oldScroll,p=l&&h,u=!l&&!h,!y&&p?(c.queueTrigger(n.backward),o[c.group.id]=c.group):!y&&u?(c.queueTrigger(n.forward),o[c.group.id]=c.group):y&&n.oldScroll>=c.triggerPoint&&(c.queueTrigger(n.forward),o[c.group.id]=c.group)}}for(var g in o)o[g].flushTriggers();return this},e.findOrCreateByElement=function(t){return e.findByElement(t)||new e(t)},e.refreshAll=function(){for(var t in o)o[t].refresh()},e.findByElement=function(t){return o[t.waypointContextKey]},window.onload=function(){n&&n(),e.refreshAll()},r.requestAnimationFrame=window.requestAnimationFrame||window.mozRequestAnimationFrame||window.webkitRequestAnimationFrame||t,r.Context=e}(),function(){"use strict";function t(t,e){return t.triggerPoint-e.triggerPoint}function e(t,e){return e.triggerPoint-t.triggerPoint}function i(t){this.name=t.name,this.axis=t.axis,this.id=this.name+"-"+this.axis,this.waypoints=[],this.clearTriggerQueues(),o[this.axis][this.name]=this}var o={vertical:{},horizontal:{}},r=window.Waypoint;i.prototype.add=function(t){this.waypoints.push(t)},i.prototype.clearTriggerQueues=function(){this.triggerQueues={up:[],down:[],left:[],right:[]}},i.prototype.flushTriggers=function(){for(var i in this.triggerQueues){var o=this.triggerQueues[i],r="up"===i||"left"===i;o.sort(r?e:t);for(var n=0,s=o.length;s>n;n+=1){var a=o[n];(a.options.continuous||n===o.length-1)&&a.trigger([i])}}this.clearTriggerQueues()},i.prototype.next=function(e){this.waypoints.sort(t);var i=r.Adapter.inArray(e,this.waypoints),o=i===this.waypoints.length-1;return o?null:this.waypoints[i+1]},i.prototype.previous=function(e){this.waypoints.sort(t);var i=r.Adapter.inArray(e,this.waypoints);return i?this.waypoints[i-1]:null},i.prototype.queueTrigger=function(t,e){this.triggerQueues[e].push(t)},i.prototype.remove=function(t){var e=r.Adapter.inArray(t,this.waypoints);e>-1&&this.waypoints.splice(e,1)},i.prototype.first=function(){return this.waypoints[0]},i.prototype.last=function(){return this.waypoints[this.waypoints.length-1]},i.findOrCreate=function(t){return o[t.axis][t.name]||new i(t)},r.Group=i}(),function(){"use strict";function t(t){this.$element=e(t)}var e=window.jQuery,i=window.Waypoint;e.each(["innerHeight","innerWidth","off","offset","on","outerHeight","outerWidth","scrollLeft","scrollTop"],function(e,i){t.prototype[i]=function(){var t=Array.prototype.slice.call(arguments);return this.$element[i].apply(this.$element,t)}}),e.each(["extend","inArray","isEmptyObject"],function(i,o){t[o]=e[o]}),i.adapters.push({name:"jquery",Adapter:t}),i.Adapter=t}(),function(){"use strict";function t(t){return function(){var i=[],o=arguments[0];return t.isFunction(arguments[0])&&(o=t.extend({},arguments[1]),o.handler=arguments[0]),this.each(function(){var r=t.extend({},o,{element:this});"string"==typeof r.context&&(r.context=t(this).closest(r.context)[0]),i.push(new e(r))}),i}}var e=window.Waypoint;window.jQuery&&(window.jQuery.fn.waypoint=t(window.jQuery)),window.Zepto&&(window.Zepto.fn.waypoint=t(window.Zepto))}(); \ No newline at end of file +!function(){"use strict";function t(o){if(!o)throw new Error("No options passed to Waypoint constructor");if(!o.element)throw new Error("No element option passed to Waypoint constructor");if(!o.handler)throw new Error("No handler option passed to Waypoint constructor");this.key="waypoint-"+e,this.options=t.Adapter.extend({},t.defaults,o),this.element=this.options.element,this.adapter=new t.Adapter(this.element),this.callback=o.handler,this.axis=this.options.horizontal?"horizontal":"vertical",this.enabled=this.options.enabled,this.triggerPoint=null,this.group=t.Group.findOrCreate({name:this.options.group,axis:this.axis}),this.context=t.Context.findOrCreateByElement(this.options.context),t.offsetAliases[this.options.offset]&&(this.options.offset=t.offsetAliases[this.options.offset]),this.group.add(this),this.context.add(this),i[this.key]=this,e+=1}var e=0,i={};t.prototype.queueTrigger=function(t){this.group.queueTrigger(this,t)},t.prototype.trigger=function(t){this.enabled&&this.callback&&this.callback.apply(this,t)},t.prototype.destroy=function(){this.context.remove(this),this.group.remove(this),delete i[this.key]},t.prototype.disable=function(){return this.enabled=!1,this},t.prototype.enable=function(){return this.context.refresh(),this.enabled=!0,this},t.prototype.next=function(){return this.group.next(this)},t.prototype.previous=function(){return this.group.previous(this)},t.invokeAll=function(t){var e=[];for(var o in i)e.push(i[o]);for(var n=0,r=e.length;r>n;n++)e[n][t]()},t.destroyAll=function(){t.invokeAll("destroy")},t.disableAll=function(){t.invokeAll("disable")},t.enableAll=function(){t.invokeAll("enable")},t.refreshAll=function(){t.Context.refreshAll()},t.viewportHeight=function(){return window.innerHeight||document.documentElement.clientHeight},t.viewportWidth=function(){return document.documentElement.clientWidth},t.adapters=[],t.defaults={context:window,continuous:!0,enabled:!0,group:"default",horizontal:!1,offset:0},t.offsetAliases={"bottom-in-view":function(){return this.context.innerHeight()-this.adapter.outerHeight()},"right-in-view":function(){return this.context.innerWidth()-this.adapter.outerWidth()}},window.Waypoint=t}(),function(){"use strict";function t(t){window.setTimeout(t,1e3/60)}function e(t){this.element=t,this.Adapter=n.Adapter,this.adapter=new this.Adapter(t),this.key="waypoint-context-"+i,this.didScroll=!1,this.didResize=!1,this.oldScroll={x:this.adapter.scrollLeft(),y:this.adapter.scrollTop()},this.waypoints={vertical:{},horizontal:{}},t.waypointContextKey=this.key,o[t.waypointContextKey]=this,i+=1,this.createThrottledScrollHandler(),this.createThrottledResizeHandler()}var i=0,o={},n=window.Waypoint,r=window.onload;e.prototype.add=function(t){var e=t.options.horizontal?"horizontal":"vertical";this.waypoints[e][t.key]=t,this.refresh()},e.prototype.checkEmpty=function(){var t=this.Adapter.isEmptyObject(this.waypoints.horizontal),e=this.Adapter.isEmptyObject(this.waypoints.vertical);t&&e&&(this.adapter.off(".waypoints"),delete o[this.key])},e.prototype.createThrottledResizeHandler=function(){function t(){e.handleResize(),e.didResize=!1}var e=this;this.adapter.on("resize.waypoints",function(){e.didResize||(e.didResize=!0,n.requestAnimationFrame(t))})},e.prototype.createThrottledScrollHandler=function(){function t(){e.handleScroll(),e.didScroll=!1}var e=this;this.adapter.on("scroll.waypoints",function(){(!e.didScroll||n.isTouch)&&(e.didScroll=!0,n.requestAnimationFrame(t))})},e.prototype.handleResize=function(){n.Context.refreshAll()},e.prototype.handleScroll=function(){var t={},e={horizontal:{newScroll:this.adapter.scrollLeft(),oldScroll:this.oldScroll.x,forward:"right",backward:"left"},vertical:{newScroll:this.adapter.scrollTop(),oldScroll:this.oldScroll.y,forward:"down",backward:"up"}};for(var i in e){var o=e[i],n=o.newScroll>o.oldScroll,r=n?o.forward:o.backward;for(var s in this.waypoints[i]){var a=this.waypoints[i][s],l=o.oldScroll=a.triggerPoint,p=l&&h,u=!l&&!h;(p||u)&&(a.queueTrigger(r),t[a.group.id]=a.group)}}for(var c in t)t[c].flushTriggers();this.oldScroll={x:e.horizontal.newScroll,y:e.vertical.newScroll}},e.prototype.innerHeight=function(){return this.element===this.element.window?n.viewportHeight():this.adapter.innerHeight()},e.prototype.remove=function(t){delete this.waypoints[t.axis][t.key],this.checkEmpty()},e.prototype.innerWidth=function(){return this.element===this.element.window?n.viewportWidth():this.adapter.innerWidth()},e.prototype.destroy=function(){var t=[];for(var e in this.waypoints)for(var i in this.waypoints[e])t.push(this.waypoints[e][i]);for(var o=0,n=t.length;n>o;o++)t[o].destroy()},e.prototype.refresh=function(){var t,e=this.element===this.element.window,i=this.adapter.offset(),o={};this.handleScroll(),t={horizontal:{contextOffset:e?0:i.left,contextScroll:e?0:this.oldScroll.x,contextDimension:this.innerWidth(),oldScroll:this.oldScroll.x,forward:"right",backward:"left",offsetProp:"left"},vertical:{contextOffset:e?0:i.top,contextScroll:e?0:this.oldScroll.y,contextDimension:this.innerHeight(),oldScroll:this.oldScroll.y,forward:"down",backward:"up",offsetProp:"top"}};for(var n in t){var r=t[n];for(var s in this.waypoints[n]){var a,l,h,p,u,c=this.waypoints[n][s],d=c.options.offset,f=c.triggerPoint,w=0,y=null==f;c.element!==c.element.window&&(w=c.adapter.offset()[r.offsetProp]),"function"==typeof d?d=d.apply(c):"string"==typeof d&&(d=parseFloat(d),c.options.offset.indexOf("%")>-1&&(d=Math.ceil(r.contextDimension*d/100))),a=r.contextScroll-r.contextOffset,c.triggerPoint=w+a-d,l=f=r.oldScroll,p=l&&h,u=!l&&!h,!y&&p?(c.queueTrigger(r.backward),o[c.group.id]=c.group):!y&&u?(c.queueTrigger(r.forward),o[c.group.id]=c.group):y&&r.oldScroll>=c.triggerPoint&&(c.queueTrigger(r.forward),o[c.group.id]=c.group)}}for(var g in o)o[g].flushTriggers();return this},e.findOrCreateByElement=function(t){return e.findByElement(t)||new e(t)},e.refreshAll=function(){for(var t in o)o[t].refresh()},e.findByElement=function(t){return o[t.waypointContextKey]},window.onload=function(){r&&r(),e.refreshAll()},n.requestAnimationFrame=window.requestAnimationFrame||window.mozRequestAnimationFrame||window.webkitRequestAnimationFrame||t,n.Context=e}(),function(){"use strict";function t(t,e){return t.triggerPoint-e.triggerPoint}function e(t,e){return e.triggerPoint-t.triggerPoint}function i(t){this.name=t.name,this.axis=t.axis,this.id=this.name+"-"+this.axis,this.waypoints=[],this.clearTriggerQueues(),o[this.axis][this.name]=this}var o={vertical:{},horizontal:{}},n=window.Waypoint;i.prototype.add=function(t){this.waypoints.push(t)},i.prototype.clearTriggerQueues=function(){this.triggerQueues={up:[],down:[],left:[],right:[]}},i.prototype.flushTriggers=function(){for(var i in this.triggerQueues){var o=this.triggerQueues[i],n="up"===i||"left"===i;o.sort(n?e:t);for(var r=0,s=o.length;s>r;r+=1){var a=o[r];(a.options.continuous||r===o.length-1)&&a.trigger([i])}}this.clearTriggerQueues()},i.prototype.next=function(e){this.waypoints.sort(t);var i=n.Adapter.inArray(e,this.waypoints),o=i===this.waypoints.length-1;return o?null:this.waypoints[i+1]},i.prototype.previous=function(e){this.waypoints.sort(t);var i=n.Adapter.inArray(e,this.waypoints);return i?this.waypoints[i-1]:null},i.prototype.queueTrigger=function(t,e){this.triggerQueues[e].push(t)},i.prototype.remove=function(t){var e=n.Adapter.inArray(t,this.waypoints);e>-1&&this.waypoints.splice(e,1)},i.prototype.first=function(){return this.waypoints[0]},i.prototype.last=function(){return this.waypoints[this.waypoints.length-1]},i.findOrCreate=function(t){return o[t.axis][t.name]||new i(t)},n.Group=i}(),function(){"use strict";function t(t){this.$element=e(t)}var e=window.jQuery,i=window.Waypoint;e.each(["innerHeight","innerWidth","off","offset","on","outerHeight","outerWidth","scrollLeft","scrollTop"],function(e,i){t.prototype[i]=function(){var t=Array.prototype.slice.call(arguments);return this.$element[i].apply(this.$element,t)}}),e.each(["extend","inArray","isEmptyObject"],function(i,o){t[o]=e[o]}),i.adapters.push({name:"jquery",Adapter:t}),i.Adapter=t}(),function(){"use strict";function t(t){return function(){var i=[],o=arguments[0];return t.isFunction(arguments[0])&&(o=t.extend({},arguments[1]),o.handler=arguments[0]),this.each(function(){var n=t.extend({},o,{element:this});"string"==typeof n.context&&(n.context=t(this).closest(n.context)[0]),i.push(new e(n))}),i}}var e=window.Waypoint;window.jQuery&&(window.jQuery.fn.waypoint=t(window.jQuery)),window.Zepto&&(window.Zepto.fn.waypoint=t(window.Zepto))}(); \ No newline at end of file diff --git a/lib/noframework.waypoints.js b/lib/noframework.waypoints.js index 5ccfdb04..3bd7e361 100644 --- a/lib/noframework.waypoints.js +++ b/lib/noframework.waypoints.js @@ -95,18 +95,35 @@ https://github.com/imakewebthings/waypoints/blog/master/licenses.txt return this.group.previous(this) } - /* Public */ - /* http://imakewebthings.com/waypoints/api/destroy-all */ - Waypoint.destroyAll = function() { + /* Private */ + Waypoint.invokeAll = function(method) { var allWaypointsArray = [] for (var waypointKey in allWaypoints) { allWaypointsArray.push(allWaypoints[waypointKey]) } for (var i = 0, end = allWaypointsArray.length; i < end; i++) { - allWaypointsArray[i].destroy() + allWaypointsArray[i][method]() } } + /* Public */ + /* http://imakewebthings.com/waypoints/api/destroy-all */ + Waypoint.destroyAll = function() { + Waypoint.invokeAll('destroy') + } + + /* Public */ + /* http://imakewebthings.com/waypoints/api/disable-all */ + Waypoint.disableAll = function() { + Waypoint.invokeAll('disable') + } + + /* Public */ + /* http://imakewebthings.com/waypoints/api/enable-all */ + Waypoint.enableAll = function() { + Waypoint.invokeAll('enable') + } + /* Public */ /* http://imakewebthings.com/waypoints/api/refresh-all */ Waypoint.refreshAll = function() { diff --git a/lib/noframework.waypoints.min.js b/lib/noframework.waypoints.min.js index b45074df..d270ad7c 100644 --- a/lib/noframework.waypoints.min.js +++ b/lib/noframework.waypoints.min.js @@ -4,4 +4,4 @@ Copyright © 2011-2015 Caleb Troughton Licensed under the MIT license. https://github.com/imakewebthings/waypoints/blog/master/licenses.txt */ -!function(){"use strict";function t(n){if(!n)throw new Error("No options passed to Waypoint constructor");if(!n.element)throw new Error("No element option passed to Waypoint constructor");if(!n.handler)throw new Error("No handler option passed to Waypoint constructor");this.key="waypoint-"+e,this.options=t.Adapter.extend({},t.defaults,n),this.element=this.options.element,this.adapter=new t.Adapter(this.element),this.callback=n.handler,this.axis=this.options.horizontal?"horizontal":"vertical",this.enabled=this.options.enabled,this.triggerPoint=null,this.group=t.Group.findOrCreate({name:this.options.group,axis:this.axis}),this.context=t.Context.findOrCreateByElement(this.options.context),t.offsetAliases[this.options.offset]&&(this.options.offset=t.offsetAliases[this.options.offset]),this.group.add(this),this.context.add(this),i[this.key]=this,e+=1}var e=0,i={};t.prototype.queueTrigger=function(t){this.group.queueTrigger(this,t)},t.prototype.trigger=function(t){this.enabled&&this.callback&&this.callback.apply(this,t)},t.prototype.destroy=function(){this.context.remove(this),this.group.remove(this),delete i[this.key]},t.prototype.disable=function(){return this.enabled=!1,this},t.prototype.enable=function(){return this.context.refresh(),this.enabled=!0,this},t.prototype.next=function(){return this.group.next(this)},t.prototype.previous=function(){return this.group.previous(this)},t.destroyAll=function(){var t=[];for(var e in i)t.push(i[e]);for(var n=0,r=t.length;r>n;n++)t[n].destroy()},t.refreshAll=function(){t.Context.refreshAll()},t.viewportHeight=function(){return window.innerHeight||document.documentElement.clientHeight},t.viewportWidth=function(){return document.documentElement.clientWidth},t.adapters=[],t.defaults={context:window,continuous:!0,enabled:!0,group:"default",horizontal:!1,offset:0},t.offsetAliases={"bottom-in-view":function(){return this.context.innerHeight()-this.adapter.outerHeight()},"right-in-view":function(){return this.context.innerWidth()-this.adapter.outerWidth()}},window.Waypoint=t}(),function(){"use strict";function t(t){window.setTimeout(t,1e3/60)}function e(t){this.element=t,this.Adapter=r.Adapter,this.adapter=new this.Adapter(t),this.key="waypoint-context-"+i,this.didScroll=!1,this.didResize=!1,this.oldScroll={x:this.adapter.scrollLeft(),y:this.adapter.scrollTop()},this.waypoints={vertical:{},horizontal:{}},t.waypointContextKey=this.key,n[t.waypointContextKey]=this,i+=1,this.createThrottledScrollHandler(),this.createThrottledResizeHandler()}var i=0,n={},r=window.Waypoint,o=window.onload;e.prototype.add=function(t){var e=t.options.horizontal?"horizontal":"vertical";this.waypoints[e][t.key]=t,this.refresh()},e.prototype.checkEmpty=function(){var t=this.Adapter.isEmptyObject(this.waypoints.horizontal),e=this.Adapter.isEmptyObject(this.waypoints.vertical);t&&e&&(this.adapter.off(".waypoints"),delete n[this.key])},e.prototype.createThrottledResizeHandler=function(){function t(){e.handleResize(),e.didResize=!1}var e=this;this.adapter.on("resize.waypoints",function(){e.didResize||(e.didResize=!0,r.requestAnimationFrame(t))})},e.prototype.createThrottledScrollHandler=function(){function t(){e.handleScroll(),e.didScroll=!1}var e=this;this.adapter.on("scroll.waypoints",function(){(!e.didScroll||r.isTouch)&&(e.didScroll=!0,r.requestAnimationFrame(t))})},e.prototype.handleResize=function(){r.Context.refreshAll()},e.prototype.handleScroll=function(){var t={},e={horizontal:{newScroll:this.adapter.scrollLeft(),oldScroll:this.oldScroll.x,forward:"right",backward:"left"},vertical:{newScroll:this.adapter.scrollTop(),oldScroll:this.oldScroll.y,forward:"down",backward:"up"}};for(var i in e){var n=e[i],r=n.newScroll>n.oldScroll,o=r?n.forward:n.backward;for(var s in this.waypoints[i]){var a=this.waypoints[i][s],l=n.oldScroll=a.triggerPoint,p=l&&h,u=!l&&!h;(p||u)&&(a.queueTrigger(o),t[a.group.id]=a.group)}}for(var c in t)t[c].flushTriggers();this.oldScroll={x:e.horizontal.newScroll,y:e.vertical.newScroll}},e.prototype.innerHeight=function(){return this.element===this.element.window?r.viewportHeight():this.adapter.innerHeight()},e.prototype.remove=function(t){delete this.waypoints[t.axis][t.key],this.checkEmpty()},e.prototype.innerWidth=function(){return this.element===this.element.window?r.viewportWidth():this.adapter.innerWidth()},e.prototype.destroy=function(){var t=[];for(var e in this.waypoints)for(var i in this.waypoints[e])t.push(this.waypoints[e][i]);for(var n=0,r=t.length;r>n;n++)t[n].destroy()},e.prototype.refresh=function(){var t,e=this.element===this.element.window,i=this.adapter.offset(),n={};this.handleScroll(),t={horizontal:{contextOffset:e?0:i.left,contextScroll:e?0:this.oldScroll.x,contextDimension:this.innerWidth(),oldScroll:this.oldScroll.x,forward:"right",backward:"left",offsetProp:"left"},vertical:{contextOffset:e?0:i.top,contextScroll:e?0:this.oldScroll.y,contextDimension:this.innerHeight(),oldScroll:this.oldScroll.y,forward:"down",backward:"up",offsetProp:"top"}};for(var r in t){var o=t[r];for(var s in this.waypoints[r]){var a,l,h,p,u,c=this.waypoints[r][s],f=c.options.offset,d=c.triggerPoint,y=0,g=null==d;c.element!==c.element.window&&(y=c.adapter.offset()[o.offsetProp]),"function"==typeof f?f=f.apply(c):"string"==typeof f&&(f=parseFloat(f),c.options.offset.indexOf("%")>-1&&(f=Math.ceil(o.contextDimension*f/100))),a=o.contextScroll-o.contextOffset,c.triggerPoint=y+a-f,l=d=o.oldScroll,p=l&&h,u=!l&&!h,!g&&p?(c.queueTrigger(o.backward),n[c.group.id]=c.group):!g&&u?(c.queueTrigger(o.forward),n[c.group.id]=c.group):g&&o.oldScroll>=c.triggerPoint&&(c.queueTrigger(o.forward),n[c.group.id]=c.group)}}for(var w in n)n[w].flushTriggers();return this},e.findOrCreateByElement=function(t){return e.findByElement(t)||new e(t)},e.refreshAll=function(){for(var t in n)n[t].refresh()},e.findByElement=function(t){return n[t.waypointContextKey]},window.onload=function(){o&&o(),e.refreshAll()},r.requestAnimationFrame=window.requestAnimationFrame||window.mozRequestAnimationFrame||window.webkitRequestAnimationFrame||t,r.Context=e}(),function(){"use strict";function t(t,e){return t.triggerPoint-e.triggerPoint}function e(t,e){return e.triggerPoint-t.triggerPoint}function i(t){this.name=t.name,this.axis=t.axis,this.id=this.name+"-"+this.axis,this.waypoints=[],this.clearTriggerQueues(),n[this.axis][this.name]=this}var n={vertical:{},horizontal:{}},r=window.Waypoint;i.prototype.add=function(t){this.waypoints.push(t)},i.prototype.clearTriggerQueues=function(){this.triggerQueues={up:[],down:[],left:[],right:[]}},i.prototype.flushTriggers=function(){for(var i in this.triggerQueues){var n=this.triggerQueues[i],r="up"===i||"left"===i;n.sort(r?e:t);for(var o=0,s=n.length;s>o;o+=1){var a=n[o];(a.options.continuous||o===n.length-1)&&a.trigger([i])}}this.clearTriggerQueues()},i.prototype.next=function(e){this.waypoints.sort(t);var i=r.Adapter.inArray(e,this.waypoints),n=i===this.waypoints.length-1;return n?null:this.waypoints[i+1]},i.prototype.previous=function(e){this.waypoints.sort(t);var i=r.Adapter.inArray(e,this.waypoints);return i?this.waypoints[i-1]:null},i.prototype.queueTrigger=function(t,e){this.triggerQueues[e].push(t)},i.prototype.remove=function(t){var e=r.Adapter.inArray(t,this.waypoints);e>-1&&this.waypoints.splice(e,1)},i.prototype.first=function(){return this.waypoints[0]},i.prototype.last=function(){return this.waypoints[this.waypoints.length-1]},i.findOrCreate=function(t){return n[t.axis][t.name]||new i(t)},r.Group=i}(),function(){"use strict";function t(t){return t===t.window}function e(e){return t(e)?e:e.defaultView}function i(t){this.element=t,this.handlers={}}var n=window.Waypoint;i.prototype.innerHeight=function(){var e=t(this.element);return e?this.element.innerHeight:this.element.clientHeight},i.prototype.innerWidth=function(){var e=t(this.element);return e?this.element.innerWidth:this.element.clientWidth},i.prototype.off=function(t,e){function i(t,e,i){for(var n=0,r=e.length-1;r>n;n++){var o=e[n];i&&i!==o||t.removeEventListener(o)}}var n=t.split("."),r=n[0],o=n[1],s=this.element;if(o&&this.handlers[o]&&r)i(s,this.handlers[o][r],e),this.handlers[o][r]=[];else if(r)for(var a in this.handlers)i(s,this.handlers[a][r]||[],e),this.handlers[a][r]=[];else if(o&&this.handlers[o]){for(var l in this.handlers[o])i(s,this.handlers[o][l],e);this.handlers[o]={}}},i.prototype.offset=function(){if(!this.element.ownerDocument)return null;var t=this.element.ownerDocument.documentElement,i=e(this.element.ownerDocument),n={top:0,left:0};return this.element.getBoundingClientRect&&(n=this.element.getBoundingClientRect()),{top:n.top+i.pageYOffset-t.clientTop,left:n.left+i.pageXOffset-t.clientLeft}},i.prototype.on=function(t,e){var i=t.split("."),n=i[0],r=i[1]||"__default",o=this.handlers[r]=this.handlers[r]||{},s=o[n]=o[n]||[];s.push(e),this.element.addEventListener(n,e)},i.prototype.outerHeight=function(e){var i,n=this.innerHeight();return e&&!t(this.element)&&(i=window.getComputedStyle(this.element),n+=parseInt(i.marginTop,10),n+=parseInt(i.marginBottom,10)),n},i.prototype.outerWidth=function(e){var i,n=this.innerWidth();return e&&!t(this.element)&&(i=window.getComputedStyle(this.element),n+=parseInt(i.marginLeft,10),n+=parseInt(i.marginRight,10)),n},i.prototype.scrollLeft=function(){var t=e(this.element);return t?t.pageXOffset:this.element.scrollLeft},i.prototype.scrollTop=function(){var t=e(this.element);return t?t.pageYOffset:this.element.scrollTop},i.extend=function(){function t(t,e){if("object"==typeof t&&"object"==typeof e)for(var i in e)e.hasOwnProperty(i)&&(t[i]=e[i]);return t}for(var e=Array.prototype.slice.call(arguments),i=1,n=e.length;n>i;i++)t(e[0],e[i]);return e[0]},i.inArray=function(t,e,i){return null==e?-1:e.indexOf(t,i)},i.isEmptyObject=function(t){for(var e in t)return!1;return!0},n.adapters.push({name:"noframework",Adapter:i}),n.Adapter=i}(); \ No newline at end of file +!function(){"use strict";function t(n){if(!n)throw new Error("No options passed to Waypoint constructor");if(!n.element)throw new Error("No element option passed to Waypoint constructor");if(!n.handler)throw new Error("No handler option passed to Waypoint constructor");this.key="waypoint-"+e,this.options=t.Adapter.extend({},t.defaults,n),this.element=this.options.element,this.adapter=new t.Adapter(this.element),this.callback=n.handler,this.axis=this.options.horizontal?"horizontal":"vertical",this.enabled=this.options.enabled,this.triggerPoint=null,this.group=t.Group.findOrCreate({name:this.options.group,axis:this.axis}),this.context=t.Context.findOrCreateByElement(this.options.context),t.offsetAliases[this.options.offset]&&(this.options.offset=t.offsetAliases[this.options.offset]),this.group.add(this),this.context.add(this),i[this.key]=this,e+=1}var e=0,i={};t.prototype.queueTrigger=function(t){this.group.queueTrigger(this,t)},t.prototype.trigger=function(t){this.enabled&&this.callback&&this.callback.apply(this,t)},t.prototype.destroy=function(){this.context.remove(this),this.group.remove(this),delete i[this.key]},t.prototype.disable=function(){return this.enabled=!1,this},t.prototype.enable=function(){return this.context.refresh(),this.enabled=!0,this},t.prototype.next=function(){return this.group.next(this)},t.prototype.previous=function(){return this.group.previous(this)},t.invokeAll=function(t){var e=[];for(var n in i)e.push(i[n]);for(var o=0,r=e.length;r>o;o++)e[o][t]()},t.destroyAll=function(){t.invokeAll("destroy")},t.disableAll=function(){t.invokeAll("disable")},t.enableAll=function(){t.invokeAll("enable")},t.refreshAll=function(){t.Context.refreshAll()},t.viewportHeight=function(){return window.innerHeight||document.documentElement.clientHeight},t.viewportWidth=function(){return document.documentElement.clientWidth},t.adapters=[],t.defaults={context:window,continuous:!0,enabled:!0,group:"default",horizontal:!1,offset:0},t.offsetAliases={"bottom-in-view":function(){return this.context.innerHeight()-this.adapter.outerHeight()},"right-in-view":function(){return this.context.innerWidth()-this.adapter.outerWidth()}},window.Waypoint=t}(),function(){"use strict";function t(t){window.setTimeout(t,1e3/60)}function e(t){this.element=t,this.Adapter=o.Adapter,this.adapter=new this.Adapter(t),this.key="waypoint-context-"+i,this.didScroll=!1,this.didResize=!1,this.oldScroll={x:this.adapter.scrollLeft(),y:this.adapter.scrollTop()},this.waypoints={vertical:{},horizontal:{}},t.waypointContextKey=this.key,n[t.waypointContextKey]=this,i+=1,this.createThrottledScrollHandler(),this.createThrottledResizeHandler()}var i=0,n={},o=window.Waypoint,r=window.onload;e.prototype.add=function(t){var e=t.options.horizontal?"horizontal":"vertical";this.waypoints[e][t.key]=t,this.refresh()},e.prototype.checkEmpty=function(){var t=this.Adapter.isEmptyObject(this.waypoints.horizontal),e=this.Adapter.isEmptyObject(this.waypoints.vertical);t&&e&&(this.adapter.off(".waypoints"),delete n[this.key])},e.prototype.createThrottledResizeHandler=function(){function t(){e.handleResize(),e.didResize=!1}var e=this;this.adapter.on("resize.waypoints",function(){e.didResize||(e.didResize=!0,o.requestAnimationFrame(t))})},e.prototype.createThrottledScrollHandler=function(){function t(){e.handleScroll(),e.didScroll=!1}var e=this;this.adapter.on("scroll.waypoints",function(){(!e.didScroll||o.isTouch)&&(e.didScroll=!0,o.requestAnimationFrame(t))})},e.prototype.handleResize=function(){o.Context.refreshAll()},e.prototype.handleScroll=function(){var t={},e={horizontal:{newScroll:this.adapter.scrollLeft(),oldScroll:this.oldScroll.x,forward:"right",backward:"left"},vertical:{newScroll:this.adapter.scrollTop(),oldScroll:this.oldScroll.y,forward:"down",backward:"up"}};for(var i in e){var n=e[i],o=n.newScroll>n.oldScroll,r=o?n.forward:n.backward;for(var s in this.waypoints[i]){var l=this.waypoints[i][s],a=n.oldScroll=l.triggerPoint,p=a&&h,u=!a&&!h;(p||u)&&(l.queueTrigger(r),t[l.group.id]=l.group)}}for(var c in t)t[c].flushTriggers();this.oldScroll={x:e.horizontal.newScroll,y:e.vertical.newScroll}},e.prototype.innerHeight=function(){return this.element===this.element.window?o.viewportHeight():this.adapter.innerHeight()},e.prototype.remove=function(t){delete this.waypoints[t.axis][t.key],this.checkEmpty()},e.prototype.innerWidth=function(){return this.element===this.element.window?o.viewportWidth():this.adapter.innerWidth()},e.prototype.destroy=function(){var t=[];for(var e in this.waypoints)for(var i in this.waypoints[e])t.push(this.waypoints[e][i]);for(var n=0,o=t.length;o>n;n++)t[n].destroy()},e.prototype.refresh=function(){var t,e=this.element===this.element.window,i=this.adapter.offset(),n={};this.handleScroll(),t={horizontal:{contextOffset:e?0:i.left,contextScroll:e?0:this.oldScroll.x,contextDimension:this.innerWidth(),oldScroll:this.oldScroll.x,forward:"right",backward:"left",offsetProp:"left"},vertical:{contextOffset:e?0:i.top,contextScroll:e?0:this.oldScroll.y,contextDimension:this.innerHeight(),oldScroll:this.oldScroll.y,forward:"down",backward:"up",offsetProp:"top"}};for(var o in t){var r=t[o];for(var s in this.waypoints[o]){var l,a,h,p,u,c=this.waypoints[o][s],f=c.options.offset,d=c.triggerPoint,y=0,g=null==d;c.element!==c.element.window&&(y=c.adapter.offset()[r.offsetProp]),"function"==typeof f?f=f.apply(c):"string"==typeof f&&(f=parseFloat(f),c.options.offset.indexOf("%")>-1&&(f=Math.ceil(r.contextDimension*f/100))),l=r.contextScroll-r.contextOffset,c.triggerPoint=y+l-f,a=d=r.oldScroll,p=a&&h,u=!a&&!h,!g&&p?(c.queueTrigger(r.backward),n[c.group.id]=c.group):!g&&u?(c.queueTrigger(r.forward),n[c.group.id]=c.group):g&&r.oldScroll>=c.triggerPoint&&(c.queueTrigger(r.forward),n[c.group.id]=c.group)}}for(var w in n)n[w].flushTriggers();return this},e.findOrCreateByElement=function(t){return e.findByElement(t)||new e(t)},e.refreshAll=function(){for(var t in n)n[t].refresh()},e.findByElement=function(t){return n[t.waypointContextKey]},window.onload=function(){r&&r(),e.refreshAll()},o.requestAnimationFrame=window.requestAnimationFrame||window.mozRequestAnimationFrame||window.webkitRequestAnimationFrame||t,o.Context=e}(),function(){"use strict";function t(t,e){return t.triggerPoint-e.triggerPoint}function e(t,e){return e.triggerPoint-t.triggerPoint}function i(t){this.name=t.name,this.axis=t.axis,this.id=this.name+"-"+this.axis,this.waypoints=[],this.clearTriggerQueues(),n[this.axis][this.name]=this}var n={vertical:{},horizontal:{}},o=window.Waypoint;i.prototype.add=function(t){this.waypoints.push(t)},i.prototype.clearTriggerQueues=function(){this.triggerQueues={up:[],down:[],left:[],right:[]}},i.prototype.flushTriggers=function(){for(var i in this.triggerQueues){var n=this.triggerQueues[i],o="up"===i||"left"===i;n.sort(o?e:t);for(var r=0,s=n.length;s>r;r+=1){var l=n[r];(l.options.continuous||r===n.length-1)&&l.trigger([i])}}this.clearTriggerQueues()},i.prototype.next=function(e){this.waypoints.sort(t);var i=o.Adapter.inArray(e,this.waypoints),n=i===this.waypoints.length-1;return n?null:this.waypoints[i+1]},i.prototype.previous=function(e){this.waypoints.sort(t);var i=o.Adapter.inArray(e,this.waypoints);return i?this.waypoints[i-1]:null},i.prototype.queueTrigger=function(t,e){this.triggerQueues[e].push(t)},i.prototype.remove=function(t){var e=o.Adapter.inArray(t,this.waypoints);e>-1&&this.waypoints.splice(e,1)},i.prototype.first=function(){return this.waypoints[0]},i.prototype.last=function(){return this.waypoints[this.waypoints.length-1]},i.findOrCreate=function(t){return n[t.axis][t.name]||new i(t)},o.Group=i}(),function(){"use strict";function t(t){return t===t.window}function e(e){return t(e)?e:e.defaultView}function i(t){this.element=t,this.handlers={}}var n=window.Waypoint;i.prototype.innerHeight=function(){var e=t(this.element);return e?this.element.innerHeight:this.element.clientHeight},i.prototype.innerWidth=function(){var e=t(this.element);return e?this.element.innerWidth:this.element.clientWidth},i.prototype.off=function(t,e){function i(t,e,i){for(var n=0,o=e.length-1;o>n;n++){var r=e[n];i&&i!==r||t.removeEventListener(r)}}var n=t.split("."),o=n[0],r=n[1],s=this.element;if(r&&this.handlers[r]&&o)i(s,this.handlers[r][o],e),this.handlers[r][o]=[];else if(o)for(var l in this.handlers)i(s,this.handlers[l][o]||[],e),this.handlers[l][o]=[];else if(r&&this.handlers[r]){for(var a in this.handlers[r])i(s,this.handlers[r][a],e);this.handlers[r]={}}},i.prototype.offset=function(){if(!this.element.ownerDocument)return null;var t=this.element.ownerDocument.documentElement,i=e(this.element.ownerDocument),n={top:0,left:0};return this.element.getBoundingClientRect&&(n=this.element.getBoundingClientRect()),{top:n.top+i.pageYOffset-t.clientTop,left:n.left+i.pageXOffset-t.clientLeft}},i.prototype.on=function(t,e){var i=t.split("."),n=i[0],o=i[1]||"__default",r=this.handlers[o]=this.handlers[o]||{},s=r[n]=r[n]||[];s.push(e),this.element.addEventListener(n,e)},i.prototype.outerHeight=function(e){var i,n=this.innerHeight();return e&&!t(this.element)&&(i=window.getComputedStyle(this.element),n+=parseInt(i.marginTop,10),n+=parseInt(i.marginBottom,10)),n},i.prototype.outerWidth=function(e){var i,n=this.innerWidth();return e&&!t(this.element)&&(i=window.getComputedStyle(this.element),n+=parseInt(i.marginLeft,10),n+=parseInt(i.marginRight,10)),n},i.prototype.scrollLeft=function(){var t=e(this.element);return t?t.pageXOffset:this.element.scrollLeft},i.prototype.scrollTop=function(){var t=e(this.element);return t?t.pageYOffset:this.element.scrollTop},i.extend=function(){function t(t,e){if("object"==typeof t&&"object"==typeof e)for(var i in e)e.hasOwnProperty(i)&&(t[i]=e[i]);return t}for(var e=Array.prototype.slice.call(arguments),i=1,n=e.length;n>i;i++)t(e[0],e[i]);return e[0]},i.inArray=function(t,e,i){return null==e?-1:e.indexOf(t,i)},i.isEmptyObject=function(t){for(var e in t)return!1;return!0},n.adapters.push({name:"noframework",Adapter:i}),n.Adapter=i}(); \ No newline at end of file diff --git a/lib/shortcuts/infinite.js b/lib/shortcuts/infinite.js index 5bf62fc9..537f0ecc 100644 --- a/lib/shortcuts/infinite.js +++ b/lib/shortcuts/infinite.js @@ -37,7 +37,12 @@ https://github.com/imakewebthings/waypoints/blog/master/licenses.txt var $data = $($.parseHTML(data)) var $newMore = $data.find(this.options.more) - this.$container.append($data.find(this.options.items)) + var $items = $data.find(this.options.items) + if (!$items.length) { + $items = $data.filter(this.options.items) + } + + this.$container.append($items) this.$container.removeClass(this.options.loadingClass) if (!$newMore.length) { diff --git a/lib/shortcuts/infinite.min.js b/lib/shortcuts/infinite.min.js index 2c1ae9f0..39cb1696 100644 --- a/lib/shortcuts/infinite.min.js +++ b/lib/shortcuts/infinite.min.js @@ -4,4 +4,4 @@ Copyright © 2011-2015 Caleb Troughton Licensed under the MIT license. https://github.com/imakewebthings/waypoints/blog/master/licenses.txt */ -!function(){"use strict";function t(n){this.options=i.extend({},t.defaults,n),this.container=this.options.element,"auto"!==this.options.container&&(this.container=this.options.container),this.$container=i(this.container),this.$more=i(this.options.more),this.$more.length&&(this.setupHandler(),this.waypoint=new o(this.options))}var i=window.jQuery,o=window.Waypoint;t.prototype.setupHandler=function(){this.options.handler=i.proxy(function(){this.options.onBeforePageLoad(),this.destroy(),this.$container.addClass(this.options.loadingClass),i.get(i(this.options.more).attr("href"),i.proxy(function(t){var n=i(i.parseHTML(t)),e=n.find(this.options.more);this.$container.append(n.find(this.options.items)),this.$container.removeClass(this.options.loadingClass),e.length||(e=n.filter(this.options.more)),e.length?(this.$more.replaceWith(e),this.$more=e,this.waypoint=new o(this.options)):this.$more.remove(),this.options.onAfterPageLoad()},this))},this)},t.prototype.destroy=function(){this.waypoint&&this.waypoint.destroy()},t.defaults={container:"auto",items:".infinite-item",more:".infinite-more-link",offset:"bottom-in-view",loadingClass:"infinite-loading",onBeforePageLoad:i.noop,onAfterPageLoad:i.noop},o.Infinite=t}(); \ No newline at end of file +!function(){"use strict";function t(n){this.options=i.extend({},t.defaults,n),this.container=this.options.element,"auto"!==this.options.container&&(this.container=this.options.container),this.$container=i(this.container),this.$more=i(this.options.more),this.$more.length&&(this.setupHandler(),this.waypoint=new o(this.options))}var i=window.jQuery,o=window.Waypoint;t.prototype.setupHandler=function(){this.options.handler=i.proxy(function(){this.options.onBeforePageLoad(),this.destroy(),this.$container.addClass(this.options.loadingClass),i.get(i(this.options.more).attr("href"),i.proxy(function(t){var n=i(i.parseHTML(t)),e=n.find(this.options.more),s=n.find(this.options.items);s.length||(s=n.filter(this.options.items)),this.$container.append(s),this.$container.removeClass(this.options.loadingClass),e.length||(e=n.filter(this.options.more)),e.length?(this.$more.replaceWith(e),this.$more=e,this.waypoint=new o(this.options)):this.$more.remove(),this.options.onAfterPageLoad()},this))},this)},t.prototype.destroy=function(){this.waypoint&&this.waypoint.destroy()},t.defaults={container:"auto",items:".infinite-item",more:".infinite-more-link",offset:"bottom-in-view",loadingClass:"infinite-loading",onBeforePageLoad:i.noop,onAfterPageLoad:i.noop},o.Infinite=t}(); \ No newline at end of file diff --git a/lib/zepto.waypoints.js b/lib/zepto.waypoints.js index f747ba2a..b179aeee 100644 --- a/lib/zepto.waypoints.js +++ b/lib/zepto.waypoints.js @@ -95,18 +95,35 @@ https://github.com/imakewebthings/waypoints/blog/master/licenses.txt return this.group.previous(this) } - /* Public */ - /* http://imakewebthings.com/waypoints/api/destroy-all */ - Waypoint.destroyAll = function() { + /* Private */ + Waypoint.invokeAll = function(method) { var allWaypointsArray = [] for (var waypointKey in allWaypoints) { allWaypointsArray.push(allWaypoints[waypointKey]) } for (var i = 0, end = allWaypointsArray.length; i < end; i++) { - allWaypointsArray[i].destroy() + allWaypointsArray[i][method]() } } + /* Public */ + /* http://imakewebthings.com/waypoints/api/destroy-all */ + Waypoint.destroyAll = function() { + Waypoint.invokeAll('destroy') + } + + /* Public */ + /* http://imakewebthings.com/waypoints/api/disable-all */ + Waypoint.disableAll = function() { + Waypoint.invokeAll('disable') + } + + /* Public */ + /* http://imakewebthings.com/waypoints/api/enable-all */ + Waypoint.enableAll = function() { + Waypoint.invokeAll('enable') + } + /* Public */ /* http://imakewebthings.com/waypoints/api/refresh-all */ Waypoint.refreshAll = function() { diff --git a/lib/zepto.waypoints.min.js b/lib/zepto.waypoints.min.js index d9a3c062..dbe09040 100644 --- a/lib/zepto.waypoints.min.js +++ b/lib/zepto.waypoints.min.js @@ -4,4 +4,4 @@ Copyright © 2011-2015 Caleb Troughton Licensed under the MIT license. https://github.com/imakewebthings/waypoints/blog/master/licenses.txt */ -!function(){"use strict";function t(o){if(!o)throw new Error("No options passed to Waypoint constructor");if(!o.element)throw new Error("No element option passed to Waypoint constructor");if(!o.handler)throw new Error("No handler option passed to Waypoint constructor");this.key="waypoint-"+e,this.options=t.Adapter.extend({},t.defaults,o),this.element=this.options.element,this.adapter=new t.Adapter(this.element),this.callback=o.handler,this.axis=this.options.horizontal?"horizontal":"vertical",this.enabled=this.options.enabled,this.triggerPoint=null,this.group=t.Group.findOrCreate({name:this.options.group,axis:this.axis}),this.context=t.Context.findOrCreateByElement(this.options.context),t.offsetAliases[this.options.offset]&&(this.options.offset=t.offsetAliases[this.options.offset]),this.group.add(this),this.context.add(this),i[this.key]=this,e+=1}var e=0,i={};t.prototype.queueTrigger=function(t){this.group.queueTrigger(this,t)},t.prototype.trigger=function(t){this.enabled&&this.callback&&this.callback.apply(this,t)},t.prototype.destroy=function(){this.context.remove(this),this.group.remove(this),delete i[this.key]},t.prototype.disable=function(){return this.enabled=!1,this},t.prototype.enable=function(){return this.context.refresh(),this.enabled=!0,this},t.prototype.next=function(){return this.group.next(this)},t.prototype.previous=function(){return this.group.previous(this)},t.destroyAll=function(){var t=[];for(var e in i)t.push(i[e]);for(var o=0,n=t.length;n>o;o++)t[o].destroy()},t.refreshAll=function(){t.Context.refreshAll()},t.viewportHeight=function(){return window.innerHeight||document.documentElement.clientHeight},t.viewportWidth=function(){return document.documentElement.clientWidth},t.adapters=[],t.defaults={context:window,continuous:!0,enabled:!0,group:"default",horizontal:!1,offset:0},t.offsetAliases={"bottom-in-view":function(){return this.context.innerHeight()-this.adapter.outerHeight()},"right-in-view":function(){return this.context.innerWidth()-this.adapter.outerWidth()}},window.Waypoint=t}(),function(){"use strict";function t(t){window.setTimeout(t,1e3/60)}function e(t){this.element=t,this.Adapter=n.Adapter,this.adapter=new this.Adapter(t),this.key="waypoint-context-"+i,this.didScroll=!1,this.didResize=!1,this.oldScroll={x:this.adapter.scrollLeft(),y:this.adapter.scrollTop()},this.waypoints={vertical:{},horizontal:{}},t.waypointContextKey=this.key,o[t.waypointContextKey]=this,i+=1,this.createThrottledScrollHandler(),this.createThrottledResizeHandler()}var i=0,o={},n=window.Waypoint,r=window.onload;e.prototype.add=function(t){var e=t.options.horizontal?"horizontal":"vertical";this.waypoints[e][t.key]=t,this.refresh()},e.prototype.checkEmpty=function(){var t=this.Adapter.isEmptyObject(this.waypoints.horizontal),e=this.Adapter.isEmptyObject(this.waypoints.vertical);t&&e&&(this.adapter.off(".waypoints"),delete o[this.key])},e.prototype.createThrottledResizeHandler=function(){function t(){e.handleResize(),e.didResize=!1}var e=this;this.adapter.on("resize.waypoints",function(){e.didResize||(e.didResize=!0,n.requestAnimationFrame(t))})},e.prototype.createThrottledScrollHandler=function(){function t(){e.handleScroll(),e.didScroll=!1}var e=this;this.adapter.on("scroll.waypoints",function(){(!e.didScroll||n.isTouch)&&(e.didScroll=!0,n.requestAnimationFrame(t))})},e.prototype.handleResize=function(){n.Context.refreshAll()},e.prototype.handleScroll=function(){var t={},e={horizontal:{newScroll:this.adapter.scrollLeft(),oldScroll:this.oldScroll.x,forward:"right",backward:"left"},vertical:{newScroll:this.adapter.scrollTop(),oldScroll:this.oldScroll.y,forward:"down",backward:"up"}};for(var i in e){var o=e[i],n=o.newScroll>o.oldScroll,r=n?o.forward:o.backward;for(var s in this.waypoints[i]){var a=this.waypoints[i][s],l=o.oldScroll=a.triggerPoint,p=l&&h,c=!l&&!h;(p||c)&&(a.queueTrigger(r),t[a.group.id]=a.group)}}for(var u in t)t[u].flushTriggers();this.oldScroll={x:e.horizontal.newScroll,y:e.vertical.newScroll}},e.prototype.innerHeight=function(){return this.element===this.element.window?n.viewportHeight():this.adapter.innerHeight()},e.prototype.remove=function(t){delete this.waypoints[t.axis][t.key],this.checkEmpty()},e.prototype.innerWidth=function(){return this.element===this.element.window?n.viewportWidth():this.adapter.innerWidth()},e.prototype.destroy=function(){var t=[];for(var e in this.waypoints)for(var i in this.waypoints[e])t.push(this.waypoints[e][i]);for(var o=0,n=t.length;n>o;o++)t[o].destroy()},e.prototype.refresh=function(){var t,e=this.element===this.element.window,i=this.adapter.offset(),o={};this.handleScroll(),t={horizontal:{contextOffset:e?0:i.left,contextScroll:e?0:this.oldScroll.x,contextDimension:this.innerWidth(),oldScroll:this.oldScroll.x,forward:"right",backward:"left",offsetProp:"left"},vertical:{contextOffset:e?0:i.top,contextScroll:e?0:this.oldScroll.y,contextDimension:this.innerHeight(),oldScroll:this.oldScroll.y,forward:"down",backward:"up",offsetProp:"top"}};for(var n in t){var r=t[n];for(var s in this.waypoints[n]){var a,l,h,p,c,u=this.waypoints[n][s],d=u.options.offset,f=u.triggerPoint,w=0,y=null==f;u.element!==u.element.window&&(w=u.adapter.offset()[r.offsetProp]),"function"==typeof d?d=d.apply(u):"string"==typeof d&&(d=parseFloat(d),u.options.offset.indexOf("%")>-1&&(d=Math.ceil(r.contextDimension*d/100))),a=r.contextScroll-r.contextOffset,u.triggerPoint=w+a-d,l=f=r.oldScroll,p=l&&h,c=!l&&!h,!y&&p?(u.queueTrigger(r.backward),o[u.group.id]=u.group):!y&&c?(u.queueTrigger(r.forward),o[u.group.id]=u.group):y&&r.oldScroll>=u.triggerPoint&&(u.queueTrigger(r.forward),o[u.group.id]=u.group)}}for(var g in o)o[g].flushTriggers();return this},e.findOrCreateByElement=function(t){return e.findByElement(t)||new e(t)},e.refreshAll=function(){for(var t in o)o[t].refresh()},e.findByElement=function(t){return o[t.waypointContextKey]},window.onload=function(){r&&r(),e.refreshAll()},n.requestAnimationFrame=window.requestAnimationFrame||window.mozRequestAnimationFrame||window.webkitRequestAnimationFrame||t,n.Context=e}(),function(){"use strict";function t(t,e){return t.triggerPoint-e.triggerPoint}function e(t,e){return e.triggerPoint-t.triggerPoint}function i(t){this.name=t.name,this.axis=t.axis,this.id=this.name+"-"+this.axis,this.waypoints=[],this.clearTriggerQueues(),o[this.axis][this.name]=this}var o={vertical:{},horizontal:{}},n=window.Waypoint;i.prototype.add=function(t){this.waypoints.push(t)},i.prototype.clearTriggerQueues=function(){this.triggerQueues={up:[],down:[],left:[],right:[]}},i.prototype.flushTriggers=function(){for(var i in this.triggerQueues){var o=this.triggerQueues[i],n="up"===i||"left"===i;o.sort(n?e:t);for(var r=0,s=o.length;s>r;r+=1){var a=o[r];(a.options.continuous||r===o.length-1)&&a.trigger([i])}}this.clearTriggerQueues()},i.prototype.next=function(e){this.waypoints.sort(t);var i=n.Adapter.inArray(e,this.waypoints),o=i===this.waypoints.length-1;return o?null:this.waypoints[i+1]},i.prototype.previous=function(e){this.waypoints.sort(t);var i=n.Adapter.inArray(e,this.waypoints);return i?this.waypoints[i-1]:null},i.prototype.queueTrigger=function(t,e){this.triggerQueues[e].push(t)},i.prototype.remove=function(t){var e=n.Adapter.inArray(t,this.waypoints);e>-1&&this.waypoints.splice(e,1)},i.prototype.first=function(){return this.waypoints[0]},i.prototype.last=function(){return this.waypoints[this.waypoints.length-1]},i.findOrCreate=function(t){return o[t.axis][t.name]||new i(t)},n.Group=i}(),function(){"use strict";function t(t){this.element=t,this.$element=e(t)}var e=window.Zepto,i=window.Waypoint;e.each(["off","on","scrollLeft","scrollTop"],function(e,i){t.prototype[i]=function(){var t=Array.prototype.slice.call(arguments);return this.$element[i].apply(this.$element,t)}}),t.prototype.offset=function(){return this.element!==this.element.window?this.$element.offset():void 0},e.each(["width","height"],function(i,o){function n(t,i){return function(t){var n=this.$element,r=n[o](),s={width:["left","right"],height:["top","bottom"]};return e.each(s[o],function(e,o){r+=parseInt(n.css("padding-"+o),10),i&&(r+=parseInt(n.css("border-"+o+"-width"),10)),t&&(r+=parseInt(n.css("margin-"+o),10))}),r}}var r=e.camelCase("inner-"+o),s=e.camelCase("outer-"+o);t.prototype[r]=n(!1),t.prototype[s]=n(!0)}),e.each(["extend","inArray"],function(i,o){t[o]=e[o]}),t.isEmptyObject=function(t){for(var e in t)return!1;return!0},i.adapters.push({name:"zepto",Adapter:t}),i.Adapter=t}(),function(){"use strict";function t(t){return function(){var i=[],o=arguments[0];return t.isFunction(arguments[0])&&(o=t.extend({},arguments[1]),o.handler=arguments[0]),this.each(function(){var n=t.extend({},o,{element:this});"string"==typeof n.context&&(n.context=t(this).closest(n.context)[0]),i.push(new e(n))}),i}}var e=window.Waypoint;window.jQuery&&(window.jQuery.fn.waypoint=t(window.jQuery)),window.Zepto&&(window.Zepto.fn.waypoint=t(window.Zepto))}(); \ No newline at end of file +!function(){"use strict";function t(o){if(!o)throw new Error("No options passed to Waypoint constructor");if(!o.element)throw new Error("No element option passed to Waypoint constructor");if(!o.handler)throw new Error("No handler option passed to Waypoint constructor");this.key="waypoint-"+e,this.options=t.Adapter.extend({},t.defaults,o),this.element=this.options.element,this.adapter=new t.Adapter(this.element),this.callback=o.handler,this.axis=this.options.horizontal?"horizontal":"vertical",this.enabled=this.options.enabled,this.triggerPoint=null,this.group=t.Group.findOrCreate({name:this.options.group,axis:this.axis}),this.context=t.Context.findOrCreateByElement(this.options.context),t.offsetAliases[this.options.offset]&&(this.options.offset=t.offsetAliases[this.options.offset]),this.group.add(this),this.context.add(this),i[this.key]=this,e+=1}var e=0,i={};t.prototype.queueTrigger=function(t){this.group.queueTrigger(this,t)},t.prototype.trigger=function(t){this.enabled&&this.callback&&this.callback.apply(this,t)},t.prototype.destroy=function(){this.context.remove(this),this.group.remove(this),delete i[this.key]},t.prototype.disable=function(){return this.enabled=!1,this},t.prototype.enable=function(){return this.context.refresh(),this.enabled=!0,this},t.prototype.next=function(){return this.group.next(this)},t.prototype.previous=function(){return this.group.previous(this)},t.invokeAll=function(t){var e=[];for(var o in i)e.push(i[o]);for(var n=0,r=e.length;r>n;n++)e[n][t]()},t.destroyAll=function(){t.invokeAll("destroy")},t.disableAll=function(){t.invokeAll("disable")},t.enableAll=function(){t.invokeAll("enable")},t.refreshAll=function(){t.Context.refreshAll()},t.viewportHeight=function(){return window.innerHeight||document.documentElement.clientHeight},t.viewportWidth=function(){return document.documentElement.clientWidth},t.adapters=[],t.defaults={context:window,continuous:!0,enabled:!0,group:"default",horizontal:!1,offset:0},t.offsetAliases={"bottom-in-view":function(){return this.context.innerHeight()-this.adapter.outerHeight()},"right-in-view":function(){return this.context.innerWidth()-this.adapter.outerWidth()}},window.Waypoint=t}(),function(){"use strict";function t(t){window.setTimeout(t,1e3/60)}function e(t){this.element=t,this.Adapter=n.Adapter,this.adapter=new this.Adapter(t),this.key="waypoint-context-"+i,this.didScroll=!1,this.didResize=!1,this.oldScroll={x:this.adapter.scrollLeft(),y:this.adapter.scrollTop()},this.waypoints={vertical:{},horizontal:{}},t.waypointContextKey=this.key,o[t.waypointContextKey]=this,i+=1,this.createThrottledScrollHandler(),this.createThrottledResizeHandler()}var i=0,o={},n=window.Waypoint,r=window.onload;e.prototype.add=function(t){var e=t.options.horizontal?"horizontal":"vertical";this.waypoints[e][t.key]=t,this.refresh()},e.prototype.checkEmpty=function(){var t=this.Adapter.isEmptyObject(this.waypoints.horizontal),e=this.Adapter.isEmptyObject(this.waypoints.vertical);t&&e&&(this.adapter.off(".waypoints"),delete o[this.key])},e.prototype.createThrottledResizeHandler=function(){function t(){e.handleResize(),e.didResize=!1}var e=this;this.adapter.on("resize.waypoints",function(){e.didResize||(e.didResize=!0,n.requestAnimationFrame(t))})},e.prototype.createThrottledScrollHandler=function(){function t(){e.handleScroll(),e.didScroll=!1}var e=this;this.adapter.on("scroll.waypoints",function(){(!e.didScroll||n.isTouch)&&(e.didScroll=!0,n.requestAnimationFrame(t))})},e.prototype.handleResize=function(){n.Context.refreshAll()},e.prototype.handleScroll=function(){var t={},e={horizontal:{newScroll:this.adapter.scrollLeft(),oldScroll:this.oldScroll.x,forward:"right",backward:"left"},vertical:{newScroll:this.adapter.scrollTop(),oldScroll:this.oldScroll.y,forward:"down",backward:"up"}};for(var i in e){var o=e[i],n=o.newScroll>o.oldScroll,r=n?o.forward:o.backward;for(var s in this.waypoints[i]){var a=this.waypoints[i][s],l=o.oldScroll=a.triggerPoint,p=l&&h,c=!l&&!h;(p||c)&&(a.queueTrigger(r),t[a.group.id]=a.group)}}for(var u in t)t[u].flushTriggers();this.oldScroll={x:e.horizontal.newScroll,y:e.vertical.newScroll}},e.prototype.innerHeight=function(){return this.element===this.element.window?n.viewportHeight():this.adapter.innerHeight()},e.prototype.remove=function(t){delete this.waypoints[t.axis][t.key],this.checkEmpty()},e.prototype.innerWidth=function(){return this.element===this.element.window?n.viewportWidth():this.adapter.innerWidth()},e.prototype.destroy=function(){var t=[];for(var e in this.waypoints)for(var i in this.waypoints[e])t.push(this.waypoints[e][i]);for(var o=0,n=t.length;n>o;o++)t[o].destroy()},e.prototype.refresh=function(){var t,e=this.element===this.element.window,i=this.adapter.offset(),o={};this.handleScroll(),t={horizontal:{contextOffset:e?0:i.left,contextScroll:e?0:this.oldScroll.x,contextDimension:this.innerWidth(),oldScroll:this.oldScroll.x,forward:"right",backward:"left",offsetProp:"left"},vertical:{contextOffset:e?0:i.top,contextScroll:e?0:this.oldScroll.y,contextDimension:this.innerHeight(),oldScroll:this.oldScroll.y,forward:"down",backward:"up",offsetProp:"top"}};for(var n in t){var r=t[n];for(var s in this.waypoints[n]){var a,l,h,p,c,u=this.waypoints[n][s],d=u.options.offset,f=u.triggerPoint,w=0,y=null==f;u.element!==u.element.window&&(w=u.adapter.offset()[r.offsetProp]),"function"==typeof d?d=d.apply(u):"string"==typeof d&&(d=parseFloat(d),u.options.offset.indexOf("%")>-1&&(d=Math.ceil(r.contextDimension*d/100))),a=r.contextScroll-r.contextOffset,u.triggerPoint=w+a-d,l=f=r.oldScroll,p=l&&h,c=!l&&!h,!y&&p?(u.queueTrigger(r.backward),o[u.group.id]=u.group):!y&&c?(u.queueTrigger(r.forward),o[u.group.id]=u.group):y&&r.oldScroll>=u.triggerPoint&&(u.queueTrigger(r.forward),o[u.group.id]=u.group)}}for(var g in o)o[g].flushTriggers();return this},e.findOrCreateByElement=function(t){return e.findByElement(t)||new e(t)},e.refreshAll=function(){for(var t in o)o[t].refresh()},e.findByElement=function(t){return o[t.waypointContextKey]},window.onload=function(){r&&r(),e.refreshAll()},n.requestAnimationFrame=window.requestAnimationFrame||window.mozRequestAnimationFrame||window.webkitRequestAnimationFrame||t,n.Context=e}(),function(){"use strict";function t(t,e){return t.triggerPoint-e.triggerPoint}function e(t,e){return e.triggerPoint-t.triggerPoint}function i(t){this.name=t.name,this.axis=t.axis,this.id=this.name+"-"+this.axis,this.waypoints=[],this.clearTriggerQueues(),o[this.axis][this.name]=this}var o={vertical:{},horizontal:{}},n=window.Waypoint;i.prototype.add=function(t){this.waypoints.push(t)},i.prototype.clearTriggerQueues=function(){this.triggerQueues={up:[],down:[],left:[],right:[]}},i.prototype.flushTriggers=function(){for(var i in this.triggerQueues){var o=this.triggerQueues[i],n="up"===i||"left"===i;o.sort(n?e:t);for(var r=0,s=o.length;s>r;r+=1){var a=o[r];(a.options.continuous||r===o.length-1)&&a.trigger([i])}}this.clearTriggerQueues()},i.prototype.next=function(e){this.waypoints.sort(t);var i=n.Adapter.inArray(e,this.waypoints),o=i===this.waypoints.length-1;return o?null:this.waypoints[i+1]},i.prototype.previous=function(e){this.waypoints.sort(t);var i=n.Adapter.inArray(e,this.waypoints);return i?this.waypoints[i-1]:null},i.prototype.queueTrigger=function(t,e){this.triggerQueues[e].push(t)},i.prototype.remove=function(t){var e=n.Adapter.inArray(t,this.waypoints);e>-1&&this.waypoints.splice(e,1)},i.prototype.first=function(){return this.waypoints[0]},i.prototype.last=function(){return this.waypoints[this.waypoints.length-1]},i.findOrCreate=function(t){return o[t.axis][t.name]||new i(t)},n.Group=i}(),function(){"use strict";function t(t){this.element=t,this.$element=e(t)}var e=window.Zepto,i=window.Waypoint;e.each(["off","on","scrollLeft","scrollTop"],function(e,i){t.prototype[i]=function(){var t=Array.prototype.slice.call(arguments);return this.$element[i].apply(this.$element,t)}}),t.prototype.offset=function(){return this.element!==this.element.window?this.$element.offset():void 0},e.each(["width","height"],function(i,o){function n(t,i){return function(t){var n=this.$element,r=n[o](),s={width:["left","right"],height:["top","bottom"]};return e.each(s[o],function(e,o){r+=parseInt(n.css("padding-"+o),10),i&&(r+=parseInt(n.css("border-"+o+"-width"),10)),t&&(r+=parseInt(n.css("margin-"+o),10))}),r}}var r=e.camelCase("inner-"+o),s=e.camelCase("outer-"+o);t.prototype[r]=n(!1),t.prototype[s]=n(!0)}),e.each(["extend","inArray"],function(i,o){t[o]=e[o]}),t.isEmptyObject=function(t){for(var e in t)return!1;return!0},i.adapters.push({name:"zepto",Adapter:t}),i.Adapter=t}(),function(){"use strict";function t(t){return function(){var i=[],o=arguments[0];return t.isFunction(arguments[0])&&(o=t.extend({},arguments[1]),o.handler=arguments[0]),this.each(function(){var n=t.extend({},o,{element:this});"string"==typeof n.context&&(n.context=t(this).closest(n.context)[0]),i.push(new e(n))}),i}}var e=window.Waypoint;window.jQuery&&(window.jQuery.fn.waypoint=t(window.jQuery)),window.Zepto&&(window.Zepto.fn.waypoint=t(window.Zepto))}(); \ No newline at end of file diff --git a/src/waypoint.js b/src/waypoint.js index 8405b69d..7f76f1d8 100644 --- a/src/waypoint.js +++ b/src/waypoint.js @@ -89,18 +89,35 @@ return this.group.previous(this) } - /* Public */ - /* http://imakewebthings.com/waypoints/api/destroy-all */ - Waypoint.destroyAll = function() { + /* Private */ + Waypoint.invokeAll = function(method) { var allWaypointsArray = [] for (var waypointKey in allWaypoints) { allWaypointsArray.push(allWaypoints[waypointKey]) } for (var i = 0, end = allWaypointsArray.length; i < end; i++) { - allWaypointsArray[i].destroy() + allWaypointsArray[i][method]() } } + /* Public */ + /* http://imakewebthings.com/waypoints/api/destroy-all */ + Waypoint.destroyAll = function() { + Waypoint.invokeAll('destroy') + } + + /* Public */ + /* http://imakewebthings.com/waypoints/api/disable-all */ + Waypoint.disableAll = function() { + Waypoint.invokeAll('disable') + } + + /* Public */ + /* http://imakewebthings.com/waypoints/api/enable-all */ + Waypoint.enableAll = function() { + Waypoint.invokeAll('enable') + } + /* Public */ /* http://imakewebthings.com/waypoints/api/refresh-all */ Waypoint.refreshAll = function() { diff --git a/test/waypoint-spec.js b/test/waypoint-spec.js index bb4c38a3..53670b5a 100644 --- a/test/waypoint-spec.js +++ b/test/waypoint-spec.js @@ -505,7 +505,42 @@ window.jQuery.each(Waypoint.adapters, function(i, adapter) { Waypoint.destroyAll() expect(secondWaypoint.destroy).toHaveBeenCalled() expect(waypoint.destroy).toHaveBeenCalled() - waypoint = null + }) + }) + + describe('Waypoint.disableAll()', function() { + it('calls disable on all waypoints', function() { + var secondWaypoint = new Waypoint({ + element: $('#same1')[0], + handler: function() {} + }) + waypoint = new Waypoint({ + element: $('#same1')[0], + handler: function() {} + }) + spyOn(secondWaypoint, 'disable').andCallThrough() + spyOn(waypoint, 'disable').andCallThrough() + Waypoint.disableAll() + expect(secondWaypoint.disable).toHaveBeenCalled() + expect(waypoint.disable).toHaveBeenCalled() + }) + }) + + describe('Waypoint.enableAll()', function() { + it('calls enable on all waypoints', function() { + var secondWaypoint = new Waypoint({ + element: $('#same1')[0], + handler: function() {} + }) + waypoint = new Waypoint({ + element: $('#same1')[0], + handler: function() {} + }) + spyOn(secondWaypoint, 'enable').andCallThrough() + spyOn(waypoint, 'enable').andCallThrough() + Waypoint.enableAll() + expect(secondWaypoint.enable).toHaveBeenCalled() + expect(waypoint.enable).toHaveBeenCalled() }) }) }) From 587538dd3a13b10272da50c4d43c0f7e21637e94 Mon Sep 17 00:00:00 2001 From: lsthornt Date: Sat, 17 Jan 2015 16:01:33 -0800 Subject: [PATCH 65/98] Prevents console warnings from disabled waypoints --- src/debug.js | 4 +++- test/debug-spec.js | 18 ++++++++++++++++++ 2 files changed, 21 insertions(+), 1 deletion(-) diff --git a/src/debug.js b/src/debug.js index b598c700..415e5b83 100644 --- a/src/debug.js +++ b/src/debug.js @@ -18,7 +18,9 @@ window.Waypoint.Context.prototype.refresh = function() { for (var axis in this.waypoints) { for (var key in this.waypoints[axis]) { - var style = this.waypoints[axis][key].element.style + var waypoint = this.waypoints[axis][key] + var style = waypoint.element.style + if (!waypoint.enabled) { continue } if (style && style.display === 'none') { console.error(displayNoneMessage) } diff --git a/test/debug-spec.js b/test/debug-spec.js index 54833834..fd618147 100644 --- a/test/debug-spec.js +++ b/test/debug-spec.js @@ -54,4 +54,22 @@ describe('Waypoints debug script', function() { describe('fixed position detection', function() { }) + + describe('respect waypoint disabling', function() { + beforeEach(function() { + element = document.getElementById('same1') + waypoint = new Waypoint({ + element: element, + handler: function() {} + }) + element.style.display = 'none' + waypoint.disable() + }) + + it('does not log a console error', function() { + spyOn(console, 'error') + waypoint.context.refresh() + expect(console.error.calls.length).toEqual(0) + }) + }) }) From f6c85070e10458b3a62e07609a9d4d540e082ef2 Mon Sep 17 00:00:00 2001 From: lsthornt Date: Sat, 17 Jan 2015 16:22:34 -0800 Subject: [PATCH 66/98] Build lib and fix styling --- lib/waypoints.debug.js | 6 +++++- src/debug.js | 4 +++- 2 files changed, 8 insertions(+), 2 deletions(-) diff --git a/lib/waypoints.debug.js b/lib/waypoints.debug.js index 83dc01d0..745401b9 100644 --- a/lib/waypoints.debug.js +++ b/lib/waypoints.debug.js @@ -24,7 +24,11 @@ https://github.com/imakewebthings/waypoints/blog/master/licenses.txt window.Waypoint.Context.prototype.refresh = function() { for (var axis in this.waypoints) { for (var key in this.waypoints[axis]) { - var style = this.waypoints[axis][key].element.style + var waypoint = this.waypoints[axis][key] + var style = waypoint.element.style + if (!waypoint.enabled) { + continue + } if (style && style.display === 'none') { console.error(displayNoneMessage) } diff --git a/src/debug.js b/src/debug.js index 415e5b83..4461e732 100644 --- a/src/debug.js +++ b/src/debug.js @@ -20,7 +20,9 @@ for (var key in this.waypoints[axis]) { var waypoint = this.waypoints[axis][key] var style = waypoint.element.style - if (!waypoint.enabled) { continue } + if (!waypoint.enabled) { + continue + } if (style && style.display === 'none') { console.error(displayNoneMessage) } From f5a602525c9afe1941c1766de04ef4ef320605f5 Mon Sep 17 00:00:00 2001 From: lsthornt Date: Sat, 17 Jan 2015 18:54:33 -0800 Subject: [PATCH 67/98] Prevent console errors from requestAnimationFrame invocation --- lib/jquery.waypoints.js | 11 +++++++---- lib/jquery.waypoints.min.js | 2 +- lib/noframework.waypoints.js | 11 +++++++---- lib/noframework.waypoints.min.js | 2 +- lib/zepto.waypoints.js | 11 +++++++---- lib/zepto.waypoints.min.js | 2 +- src/context.js | 11 +++++++---- 7 files changed, 31 insertions(+), 19 deletions(-) diff --git a/lib/jquery.waypoints.js b/lib/jquery.waypoints.js index ddf4ddc4..7f8d1ae3 100644 --- a/lib/jquery.waypoints.js +++ b/lib/jquery.waypoints.js @@ -447,10 +447,13 @@ https://github.com/imakewebthings/waypoints/blog/master/licenses.txt Context.refreshAll() } - Waypoint.requestAnimationFrame = window.requestAnimationFrame || - window.mozRequestAnimationFrame || - window.webkitRequestAnimationFrame || - requestAnimationFrameShim + Waypoint.requestAnimationFrame = function(callback) { + var requestFn = window.requestAnimationFrame || + window.mozRequestAnimationFrame || + window.webkitRequestAnimationFrame || + requestAnimationFrameShim + requestFn.call(window, callback) + } Waypoint.Context = Context }()) ;(function() { diff --git a/lib/jquery.waypoints.min.js b/lib/jquery.waypoints.min.js index f4a3168b..70cbcf4a 100644 --- a/lib/jquery.waypoints.min.js +++ b/lib/jquery.waypoints.min.js @@ -4,4 +4,4 @@ Copyright © 2011-2015 Caleb Troughton Licensed under the MIT license. https://github.com/imakewebthings/waypoints/blog/master/licenses.txt */ -!function(){"use strict";function t(o){if(!o)throw new Error("No options passed to Waypoint constructor");if(!o.element)throw new Error("No element option passed to Waypoint constructor");if(!o.handler)throw new Error("No handler option passed to Waypoint constructor");this.key="waypoint-"+e,this.options=t.Adapter.extend({},t.defaults,o),this.element=this.options.element,this.adapter=new t.Adapter(this.element),this.callback=o.handler,this.axis=this.options.horizontal?"horizontal":"vertical",this.enabled=this.options.enabled,this.triggerPoint=null,this.group=t.Group.findOrCreate({name:this.options.group,axis:this.axis}),this.context=t.Context.findOrCreateByElement(this.options.context),t.offsetAliases[this.options.offset]&&(this.options.offset=t.offsetAliases[this.options.offset]),this.group.add(this),this.context.add(this),i[this.key]=this,e+=1}var e=0,i={};t.prototype.queueTrigger=function(t){this.group.queueTrigger(this,t)},t.prototype.trigger=function(t){this.enabled&&this.callback&&this.callback.apply(this,t)},t.prototype.destroy=function(){this.context.remove(this),this.group.remove(this),delete i[this.key]},t.prototype.disable=function(){return this.enabled=!1,this},t.prototype.enable=function(){return this.context.refresh(),this.enabled=!0,this},t.prototype.next=function(){return this.group.next(this)},t.prototype.previous=function(){return this.group.previous(this)},t.invokeAll=function(t){var e=[];for(var o in i)e.push(i[o]);for(var n=0,r=e.length;r>n;n++)e[n][t]()},t.destroyAll=function(){t.invokeAll("destroy")},t.disableAll=function(){t.invokeAll("disable")},t.enableAll=function(){t.invokeAll("enable")},t.refreshAll=function(){t.Context.refreshAll()},t.viewportHeight=function(){return window.innerHeight||document.documentElement.clientHeight},t.viewportWidth=function(){return document.documentElement.clientWidth},t.adapters=[],t.defaults={context:window,continuous:!0,enabled:!0,group:"default",horizontal:!1,offset:0},t.offsetAliases={"bottom-in-view":function(){return this.context.innerHeight()-this.adapter.outerHeight()},"right-in-view":function(){return this.context.innerWidth()-this.adapter.outerWidth()}},window.Waypoint=t}(),function(){"use strict";function t(t){window.setTimeout(t,1e3/60)}function e(t){this.element=t,this.Adapter=n.Adapter,this.adapter=new this.Adapter(t),this.key="waypoint-context-"+i,this.didScroll=!1,this.didResize=!1,this.oldScroll={x:this.adapter.scrollLeft(),y:this.adapter.scrollTop()},this.waypoints={vertical:{},horizontal:{}},t.waypointContextKey=this.key,o[t.waypointContextKey]=this,i+=1,this.createThrottledScrollHandler(),this.createThrottledResizeHandler()}var i=0,o={},n=window.Waypoint,r=window.onload;e.prototype.add=function(t){var e=t.options.horizontal?"horizontal":"vertical";this.waypoints[e][t.key]=t,this.refresh()},e.prototype.checkEmpty=function(){var t=this.Adapter.isEmptyObject(this.waypoints.horizontal),e=this.Adapter.isEmptyObject(this.waypoints.vertical);t&&e&&(this.adapter.off(".waypoints"),delete o[this.key])},e.prototype.createThrottledResizeHandler=function(){function t(){e.handleResize(),e.didResize=!1}var e=this;this.adapter.on("resize.waypoints",function(){e.didResize||(e.didResize=!0,n.requestAnimationFrame(t))})},e.prototype.createThrottledScrollHandler=function(){function t(){e.handleScroll(),e.didScroll=!1}var e=this;this.adapter.on("scroll.waypoints",function(){(!e.didScroll||n.isTouch)&&(e.didScroll=!0,n.requestAnimationFrame(t))})},e.prototype.handleResize=function(){n.Context.refreshAll()},e.prototype.handleScroll=function(){var t={},e={horizontal:{newScroll:this.adapter.scrollLeft(),oldScroll:this.oldScroll.x,forward:"right",backward:"left"},vertical:{newScroll:this.adapter.scrollTop(),oldScroll:this.oldScroll.y,forward:"down",backward:"up"}};for(var i in e){var o=e[i],n=o.newScroll>o.oldScroll,r=n?o.forward:o.backward;for(var s in this.waypoints[i]){var a=this.waypoints[i][s],l=o.oldScroll=a.triggerPoint,p=l&&h,u=!l&&!h;(p||u)&&(a.queueTrigger(r),t[a.group.id]=a.group)}}for(var c in t)t[c].flushTriggers();this.oldScroll={x:e.horizontal.newScroll,y:e.vertical.newScroll}},e.prototype.innerHeight=function(){return this.element===this.element.window?n.viewportHeight():this.adapter.innerHeight()},e.prototype.remove=function(t){delete this.waypoints[t.axis][t.key],this.checkEmpty()},e.prototype.innerWidth=function(){return this.element===this.element.window?n.viewportWidth():this.adapter.innerWidth()},e.prototype.destroy=function(){var t=[];for(var e in this.waypoints)for(var i in this.waypoints[e])t.push(this.waypoints[e][i]);for(var o=0,n=t.length;n>o;o++)t[o].destroy()},e.prototype.refresh=function(){var t,e=this.element===this.element.window,i=this.adapter.offset(),o={};this.handleScroll(),t={horizontal:{contextOffset:e?0:i.left,contextScroll:e?0:this.oldScroll.x,contextDimension:this.innerWidth(),oldScroll:this.oldScroll.x,forward:"right",backward:"left",offsetProp:"left"},vertical:{contextOffset:e?0:i.top,contextScroll:e?0:this.oldScroll.y,contextDimension:this.innerHeight(),oldScroll:this.oldScroll.y,forward:"down",backward:"up",offsetProp:"top"}};for(var n in t){var r=t[n];for(var s in this.waypoints[n]){var a,l,h,p,u,c=this.waypoints[n][s],d=c.options.offset,f=c.triggerPoint,w=0,y=null==f;c.element!==c.element.window&&(w=c.adapter.offset()[r.offsetProp]),"function"==typeof d?d=d.apply(c):"string"==typeof d&&(d=parseFloat(d),c.options.offset.indexOf("%")>-1&&(d=Math.ceil(r.contextDimension*d/100))),a=r.contextScroll-r.contextOffset,c.triggerPoint=w+a-d,l=f=r.oldScroll,p=l&&h,u=!l&&!h,!y&&p?(c.queueTrigger(r.backward),o[c.group.id]=c.group):!y&&u?(c.queueTrigger(r.forward),o[c.group.id]=c.group):y&&r.oldScroll>=c.triggerPoint&&(c.queueTrigger(r.forward),o[c.group.id]=c.group)}}for(var g in o)o[g].flushTriggers();return this},e.findOrCreateByElement=function(t){return e.findByElement(t)||new e(t)},e.refreshAll=function(){for(var t in o)o[t].refresh()},e.findByElement=function(t){return o[t.waypointContextKey]},window.onload=function(){r&&r(),e.refreshAll()},n.requestAnimationFrame=window.requestAnimationFrame||window.mozRequestAnimationFrame||window.webkitRequestAnimationFrame||t,n.Context=e}(),function(){"use strict";function t(t,e){return t.triggerPoint-e.triggerPoint}function e(t,e){return e.triggerPoint-t.triggerPoint}function i(t){this.name=t.name,this.axis=t.axis,this.id=this.name+"-"+this.axis,this.waypoints=[],this.clearTriggerQueues(),o[this.axis][this.name]=this}var o={vertical:{},horizontal:{}},n=window.Waypoint;i.prototype.add=function(t){this.waypoints.push(t)},i.prototype.clearTriggerQueues=function(){this.triggerQueues={up:[],down:[],left:[],right:[]}},i.prototype.flushTriggers=function(){for(var i in this.triggerQueues){var o=this.triggerQueues[i],n="up"===i||"left"===i;o.sort(n?e:t);for(var r=0,s=o.length;s>r;r+=1){var a=o[r];(a.options.continuous||r===o.length-1)&&a.trigger([i])}}this.clearTriggerQueues()},i.prototype.next=function(e){this.waypoints.sort(t);var i=n.Adapter.inArray(e,this.waypoints),o=i===this.waypoints.length-1;return o?null:this.waypoints[i+1]},i.prototype.previous=function(e){this.waypoints.sort(t);var i=n.Adapter.inArray(e,this.waypoints);return i?this.waypoints[i-1]:null},i.prototype.queueTrigger=function(t,e){this.triggerQueues[e].push(t)},i.prototype.remove=function(t){var e=n.Adapter.inArray(t,this.waypoints);e>-1&&this.waypoints.splice(e,1)},i.prototype.first=function(){return this.waypoints[0]},i.prototype.last=function(){return this.waypoints[this.waypoints.length-1]},i.findOrCreate=function(t){return o[t.axis][t.name]||new i(t)},n.Group=i}(),function(){"use strict";function t(t){this.$element=e(t)}var e=window.jQuery,i=window.Waypoint;e.each(["innerHeight","innerWidth","off","offset","on","outerHeight","outerWidth","scrollLeft","scrollTop"],function(e,i){t.prototype[i]=function(){var t=Array.prototype.slice.call(arguments);return this.$element[i].apply(this.$element,t)}}),e.each(["extend","inArray","isEmptyObject"],function(i,o){t[o]=e[o]}),i.adapters.push({name:"jquery",Adapter:t}),i.Adapter=t}(),function(){"use strict";function t(t){return function(){var i=[],o=arguments[0];return t.isFunction(arguments[0])&&(o=t.extend({},arguments[1]),o.handler=arguments[0]),this.each(function(){var n=t.extend({},o,{element:this});"string"==typeof n.context&&(n.context=t(this).closest(n.context)[0]),i.push(new e(n))}),i}}var e=window.Waypoint;window.jQuery&&(window.jQuery.fn.waypoint=t(window.jQuery)),window.Zepto&&(window.Zepto.fn.waypoint=t(window.Zepto))}(); \ No newline at end of file +!function(){"use strict";function t(o){if(!o)throw new Error("No options passed to Waypoint constructor");if(!o.element)throw new Error("No element option passed to Waypoint constructor");if(!o.handler)throw new Error("No handler option passed to Waypoint constructor");this.key="waypoint-"+e,this.options=t.Adapter.extend({},t.defaults,o),this.element=this.options.element,this.adapter=new t.Adapter(this.element),this.callback=o.handler,this.axis=this.options.horizontal?"horizontal":"vertical",this.enabled=this.options.enabled,this.triggerPoint=null,this.group=t.Group.findOrCreate({name:this.options.group,axis:this.axis}),this.context=t.Context.findOrCreateByElement(this.options.context),t.offsetAliases[this.options.offset]&&(this.options.offset=t.offsetAliases[this.options.offset]),this.group.add(this),this.context.add(this),i[this.key]=this,e+=1}var e=0,i={};t.prototype.queueTrigger=function(t){this.group.queueTrigger(this,t)},t.prototype.trigger=function(t){this.enabled&&this.callback&&this.callback.apply(this,t)},t.prototype.destroy=function(){this.context.remove(this),this.group.remove(this),delete i[this.key]},t.prototype.disable=function(){return this.enabled=!1,this},t.prototype.enable=function(){return this.context.refresh(),this.enabled=!0,this},t.prototype.next=function(){return this.group.next(this)},t.prototype.previous=function(){return this.group.previous(this)},t.invokeAll=function(t){var e=[];for(var o in i)e.push(i[o]);for(var n=0,r=e.length;r>n;n++)e[n][t]()},t.destroyAll=function(){t.invokeAll("destroy")},t.disableAll=function(){t.invokeAll("disable")},t.enableAll=function(){t.invokeAll("enable")},t.refreshAll=function(){t.Context.refreshAll()},t.viewportHeight=function(){return window.innerHeight||document.documentElement.clientHeight},t.viewportWidth=function(){return document.documentElement.clientWidth},t.adapters=[],t.defaults={context:window,continuous:!0,enabled:!0,group:"default",horizontal:!1,offset:0},t.offsetAliases={"bottom-in-view":function(){return this.context.innerHeight()-this.adapter.outerHeight()},"right-in-view":function(){return this.context.innerWidth()-this.adapter.outerWidth()}},window.Waypoint=t}(),function(){"use strict";function t(t){window.setTimeout(t,1e3/60)}function e(t){this.element=t,this.Adapter=n.Adapter,this.adapter=new this.Adapter(t),this.key="waypoint-context-"+i,this.didScroll=!1,this.didResize=!1,this.oldScroll={x:this.adapter.scrollLeft(),y:this.adapter.scrollTop()},this.waypoints={vertical:{},horizontal:{}},t.waypointContextKey=this.key,o[t.waypointContextKey]=this,i+=1,this.createThrottledScrollHandler(),this.createThrottledResizeHandler()}var i=0,o={},n=window.Waypoint,r=window.onload;e.prototype.add=function(t){var e=t.options.horizontal?"horizontal":"vertical";this.waypoints[e][t.key]=t,this.refresh()},e.prototype.checkEmpty=function(){var t=this.Adapter.isEmptyObject(this.waypoints.horizontal),e=this.Adapter.isEmptyObject(this.waypoints.vertical);t&&e&&(this.adapter.off(".waypoints"),delete o[this.key])},e.prototype.createThrottledResizeHandler=function(){function t(){e.handleResize(),e.didResize=!1}var e=this;this.adapter.on("resize.waypoints",function(){e.didResize||(e.didResize=!0,n.requestAnimationFrame(t))})},e.prototype.createThrottledScrollHandler=function(){function t(){e.handleScroll(),e.didScroll=!1}var e=this;this.adapter.on("scroll.waypoints",function(){(!e.didScroll||n.isTouch)&&(e.didScroll=!0,n.requestAnimationFrame(t))})},e.prototype.handleResize=function(){n.Context.refreshAll()},e.prototype.handleScroll=function(){var t={},e={horizontal:{newScroll:this.adapter.scrollLeft(),oldScroll:this.oldScroll.x,forward:"right",backward:"left"},vertical:{newScroll:this.adapter.scrollTop(),oldScroll:this.oldScroll.y,forward:"down",backward:"up"}};for(var i in e){var o=e[i],n=o.newScroll>o.oldScroll,r=n?o.forward:o.backward;for(var s in this.waypoints[i]){var a=this.waypoints[i][s],l=o.oldScroll=a.triggerPoint,p=l&&h,u=!l&&!h;(p||u)&&(a.queueTrigger(r),t[a.group.id]=a.group)}}for(var c in t)t[c].flushTriggers();this.oldScroll={x:e.horizontal.newScroll,y:e.vertical.newScroll}},e.prototype.innerHeight=function(){return this.element===this.element.window?n.viewportHeight():this.adapter.innerHeight()},e.prototype.remove=function(t){delete this.waypoints[t.axis][t.key],this.checkEmpty()},e.prototype.innerWidth=function(){return this.element===this.element.window?n.viewportWidth():this.adapter.innerWidth()},e.prototype.destroy=function(){var t=[];for(var e in this.waypoints)for(var i in this.waypoints[e])t.push(this.waypoints[e][i]);for(var o=0,n=t.length;n>o;o++)t[o].destroy()},e.prototype.refresh=function(){var t,e=this.element===this.element.window,i=this.adapter.offset(),o={};this.handleScroll(),t={horizontal:{contextOffset:e?0:i.left,contextScroll:e?0:this.oldScroll.x,contextDimension:this.innerWidth(),oldScroll:this.oldScroll.x,forward:"right",backward:"left",offsetProp:"left"},vertical:{contextOffset:e?0:i.top,contextScroll:e?0:this.oldScroll.y,contextDimension:this.innerHeight(),oldScroll:this.oldScroll.y,forward:"down",backward:"up",offsetProp:"top"}};for(var n in t){var r=t[n];for(var s in this.waypoints[n]){var a,l,h,p,u,c=this.waypoints[n][s],d=c.options.offset,f=c.triggerPoint,w=0,y=null==f;c.element!==c.element.window&&(w=c.adapter.offset()[r.offsetProp]),"function"==typeof d?d=d.apply(c):"string"==typeof d&&(d=parseFloat(d),c.options.offset.indexOf("%")>-1&&(d=Math.ceil(r.contextDimension*d/100))),a=r.contextScroll-r.contextOffset,c.triggerPoint=w+a-d,l=f=r.oldScroll,p=l&&h,u=!l&&!h,!y&&p?(c.queueTrigger(r.backward),o[c.group.id]=c.group):!y&&u?(c.queueTrigger(r.forward),o[c.group.id]=c.group):y&&r.oldScroll>=c.triggerPoint&&(c.queueTrigger(r.forward),o[c.group.id]=c.group)}}for(var g in o)o[g].flushTriggers();return this},e.findOrCreateByElement=function(t){return e.findByElement(t)||new e(t)},e.refreshAll=function(){for(var t in o)o[t].refresh()},e.findByElement=function(t){return o[t.waypointContextKey]},window.onload=function(){r&&r(),e.refreshAll()},n.requestAnimationFrame=function(e){var i=window.requestAnimationFrame||window.mozRequestAnimationFrame||window.webkitRequestAnimationFrame||t;i.call(window,e)},n.Context=e}(),function(){"use strict";function t(t,e){return t.triggerPoint-e.triggerPoint}function e(t,e){return e.triggerPoint-t.triggerPoint}function i(t){this.name=t.name,this.axis=t.axis,this.id=this.name+"-"+this.axis,this.waypoints=[],this.clearTriggerQueues(),o[this.axis][this.name]=this}var o={vertical:{},horizontal:{}},n=window.Waypoint;i.prototype.add=function(t){this.waypoints.push(t)},i.prototype.clearTriggerQueues=function(){this.triggerQueues={up:[],down:[],left:[],right:[]}},i.prototype.flushTriggers=function(){for(var i in this.triggerQueues){var o=this.triggerQueues[i],n="up"===i||"left"===i;o.sort(n?e:t);for(var r=0,s=o.length;s>r;r+=1){var a=o[r];(a.options.continuous||r===o.length-1)&&a.trigger([i])}}this.clearTriggerQueues()},i.prototype.next=function(e){this.waypoints.sort(t);var i=n.Adapter.inArray(e,this.waypoints),o=i===this.waypoints.length-1;return o?null:this.waypoints[i+1]},i.prototype.previous=function(e){this.waypoints.sort(t);var i=n.Adapter.inArray(e,this.waypoints);return i?this.waypoints[i-1]:null},i.prototype.queueTrigger=function(t,e){this.triggerQueues[e].push(t)},i.prototype.remove=function(t){var e=n.Adapter.inArray(t,this.waypoints);e>-1&&this.waypoints.splice(e,1)},i.prototype.first=function(){return this.waypoints[0]},i.prototype.last=function(){return this.waypoints[this.waypoints.length-1]},i.findOrCreate=function(t){return o[t.axis][t.name]||new i(t)},n.Group=i}(),function(){"use strict";function t(t){this.$element=e(t)}var e=window.jQuery,i=window.Waypoint;e.each(["innerHeight","innerWidth","off","offset","on","outerHeight","outerWidth","scrollLeft","scrollTop"],function(e,i){t.prototype[i]=function(){var t=Array.prototype.slice.call(arguments);return this.$element[i].apply(this.$element,t)}}),e.each(["extend","inArray","isEmptyObject"],function(i,o){t[o]=e[o]}),i.adapters.push({name:"jquery",Adapter:t}),i.Adapter=t}(),function(){"use strict";function t(t){return function(){var i=[],o=arguments[0];return t.isFunction(arguments[0])&&(o=t.extend({},arguments[1]),o.handler=arguments[0]),this.each(function(){var n=t.extend({},o,{element:this});"string"==typeof n.context&&(n.context=t(this).closest(n.context)[0]),i.push(new e(n))}),i}}var e=window.Waypoint;window.jQuery&&(window.jQuery.fn.waypoint=t(window.jQuery)),window.Zepto&&(window.Zepto.fn.waypoint=t(window.Zepto))}(); \ No newline at end of file diff --git a/lib/noframework.waypoints.js b/lib/noframework.waypoints.js index 3bd7e361..ef3bac41 100644 --- a/lib/noframework.waypoints.js +++ b/lib/noframework.waypoints.js @@ -447,10 +447,13 @@ https://github.com/imakewebthings/waypoints/blog/master/licenses.txt Context.refreshAll() } - Waypoint.requestAnimationFrame = window.requestAnimationFrame || - window.mozRequestAnimationFrame || - window.webkitRequestAnimationFrame || - requestAnimationFrameShim + Waypoint.requestAnimationFrame = function(callback) { + var requestFn = window.requestAnimationFrame || + window.mozRequestAnimationFrame || + window.webkitRequestAnimationFrame || + requestAnimationFrameShim + requestFn.call(window, callback) + } Waypoint.Context = Context }()) ;(function() { diff --git a/lib/noframework.waypoints.min.js b/lib/noframework.waypoints.min.js index d270ad7c..359f58f6 100644 --- a/lib/noframework.waypoints.min.js +++ b/lib/noframework.waypoints.min.js @@ -4,4 +4,4 @@ Copyright © 2011-2015 Caleb Troughton Licensed under the MIT license. https://github.com/imakewebthings/waypoints/blog/master/licenses.txt */ -!function(){"use strict";function t(n){if(!n)throw new Error("No options passed to Waypoint constructor");if(!n.element)throw new Error("No element option passed to Waypoint constructor");if(!n.handler)throw new Error("No handler option passed to Waypoint constructor");this.key="waypoint-"+e,this.options=t.Adapter.extend({},t.defaults,n),this.element=this.options.element,this.adapter=new t.Adapter(this.element),this.callback=n.handler,this.axis=this.options.horizontal?"horizontal":"vertical",this.enabled=this.options.enabled,this.triggerPoint=null,this.group=t.Group.findOrCreate({name:this.options.group,axis:this.axis}),this.context=t.Context.findOrCreateByElement(this.options.context),t.offsetAliases[this.options.offset]&&(this.options.offset=t.offsetAliases[this.options.offset]),this.group.add(this),this.context.add(this),i[this.key]=this,e+=1}var e=0,i={};t.prototype.queueTrigger=function(t){this.group.queueTrigger(this,t)},t.prototype.trigger=function(t){this.enabled&&this.callback&&this.callback.apply(this,t)},t.prototype.destroy=function(){this.context.remove(this),this.group.remove(this),delete i[this.key]},t.prototype.disable=function(){return this.enabled=!1,this},t.prototype.enable=function(){return this.context.refresh(),this.enabled=!0,this},t.prototype.next=function(){return this.group.next(this)},t.prototype.previous=function(){return this.group.previous(this)},t.invokeAll=function(t){var e=[];for(var n in i)e.push(i[n]);for(var o=0,r=e.length;r>o;o++)e[o][t]()},t.destroyAll=function(){t.invokeAll("destroy")},t.disableAll=function(){t.invokeAll("disable")},t.enableAll=function(){t.invokeAll("enable")},t.refreshAll=function(){t.Context.refreshAll()},t.viewportHeight=function(){return window.innerHeight||document.documentElement.clientHeight},t.viewportWidth=function(){return document.documentElement.clientWidth},t.adapters=[],t.defaults={context:window,continuous:!0,enabled:!0,group:"default",horizontal:!1,offset:0},t.offsetAliases={"bottom-in-view":function(){return this.context.innerHeight()-this.adapter.outerHeight()},"right-in-view":function(){return this.context.innerWidth()-this.adapter.outerWidth()}},window.Waypoint=t}(),function(){"use strict";function t(t){window.setTimeout(t,1e3/60)}function e(t){this.element=t,this.Adapter=o.Adapter,this.adapter=new this.Adapter(t),this.key="waypoint-context-"+i,this.didScroll=!1,this.didResize=!1,this.oldScroll={x:this.adapter.scrollLeft(),y:this.adapter.scrollTop()},this.waypoints={vertical:{},horizontal:{}},t.waypointContextKey=this.key,n[t.waypointContextKey]=this,i+=1,this.createThrottledScrollHandler(),this.createThrottledResizeHandler()}var i=0,n={},o=window.Waypoint,r=window.onload;e.prototype.add=function(t){var e=t.options.horizontal?"horizontal":"vertical";this.waypoints[e][t.key]=t,this.refresh()},e.prototype.checkEmpty=function(){var t=this.Adapter.isEmptyObject(this.waypoints.horizontal),e=this.Adapter.isEmptyObject(this.waypoints.vertical);t&&e&&(this.adapter.off(".waypoints"),delete n[this.key])},e.prototype.createThrottledResizeHandler=function(){function t(){e.handleResize(),e.didResize=!1}var e=this;this.adapter.on("resize.waypoints",function(){e.didResize||(e.didResize=!0,o.requestAnimationFrame(t))})},e.prototype.createThrottledScrollHandler=function(){function t(){e.handleScroll(),e.didScroll=!1}var e=this;this.adapter.on("scroll.waypoints",function(){(!e.didScroll||o.isTouch)&&(e.didScroll=!0,o.requestAnimationFrame(t))})},e.prototype.handleResize=function(){o.Context.refreshAll()},e.prototype.handleScroll=function(){var t={},e={horizontal:{newScroll:this.adapter.scrollLeft(),oldScroll:this.oldScroll.x,forward:"right",backward:"left"},vertical:{newScroll:this.adapter.scrollTop(),oldScroll:this.oldScroll.y,forward:"down",backward:"up"}};for(var i in e){var n=e[i],o=n.newScroll>n.oldScroll,r=o?n.forward:n.backward;for(var s in this.waypoints[i]){var l=this.waypoints[i][s],a=n.oldScroll=l.triggerPoint,p=a&&h,u=!a&&!h;(p||u)&&(l.queueTrigger(r),t[l.group.id]=l.group)}}for(var c in t)t[c].flushTriggers();this.oldScroll={x:e.horizontal.newScroll,y:e.vertical.newScroll}},e.prototype.innerHeight=function(){return this.element===this.element.window?o.viewportHeight():this.adapter.innerHeight()},e.prototype.remove=function(t){delete this.waypoints[t.axis][t.key],this.checkEmpty()},e.prototype.innerWidth=function(){return this.element===this.element.window?o.viewportWidth():this.adapter.innerWidth()},e.prototype.destroy=function(){var t=[];for(var e in this.waypoints)for(var i in this.waypoints[e])t.push(this.waypoints[e][i]);for(var n=0,o=t.length;o>n;n++)t[n].destroy()},e.prototype.refresh=function(){var t,e=this.element===this.element.window,i=this.adapter.offset(),n={};this.handleScroll(),t={horizontal:{contextOffset:e?0:i.left,contextScroll:e?0:this.oldScroll.x,contextDimension:this.innerWidth(),oldScroll:this.oldScroll.x,forward:"right",backward:"left",offsetProp:"left"},vertical:{contextOffset:e?0:i.top,contextScroll:e?0:this.oldScroll.y,contextDimension:this.innerHeight(),oldScroll:this.oldScroll.y,forward:"down",backward:"up",offsetProp:"top"}};for(var o in t){var r=t[o];for(var s in this.waypoints[o]){var l,a,h,p,u,c=this.waypoints[o][s],f=c.options.offset,d=c.triggerPoint,y=0,g=null==d;c.element!==c.element.window&&(y=c.adapter.offset()[r.offsetProp]),"function"==typeof f?f=f.apply(c):"string"==typeof f&&(f=parseFloat(f),c.options.offset.indexOf("%")>-1&&(f=Math.ceil(r.contextDimension*f/100))),l=r.contextScroll-r.contextOffset,c.triggerPoint=y+l-f,a=d=r.oldScroll,p=a&&h,u=!a&&!h,!g&&p?(c.queueTrigger(r.backward),n[c.group.id]=c.group):!g&&u?(c.queueTrigger(r.forward),n[c.group.id]=c.group):g&&r.oldScroll>=c.triggerPoint&&(c.queueTrigger(r.forward),n[c.group.id]=c.group)}}for(var w in n)n[w].flushTriggers();return this},e.findOrCreateByElement=function(t){return e.findByElement(t)||new e(t)},e.refreshAll=function(){for(var t in n)n[t].refresh()},e.findByElement=function(t){return n[t.waypointContextKey]},window.onload=function(){r&&r(),e.refreshAll()},o.requestAnimationFrame=window.requestAnimationFrame||window.mozRequestAnimationFrame||window.webkitRequestAnimationFrame||t,o.Context=e}(),function(){"use strict";function t(t,e){return t.triggerPoint-e.triggerPoint}function e(t,e){return e.triggerPoint-t.triggerPoint}function i(t){this.name=t.name,this.axis=t.axis,this.id=this.name+"-"+this.axis,this.waypoints=[],this.clearTriggerQueues(),n[this.axis][this.name]=this}var n={vertical:{},horizontal:{}},o=window.Waypoint;i.prototype.add=function(t){this.waypoints.push(t)},i.prototype.clearTriggerQueues=function(){this.triggerQueues={up:[],down:[],left:[],right:[]}},i.prototype.flushTriggers=function(){for(var i in this.triggerQueues){var n=this.triggerQueues[i],o="up"===i||"left"===i;n.sort(o?e:t);for(var r=0,s=n.length;s>r;r+=1){var l=n[r];(l.options.continuous||r===n.length-1)&&l.trigger([i])}}this.clearTriggerQueues()},i.prototype.next=function(e){this.waypoints.sort(t);var i=o.Adapter.inArray(e,this.waypoints),n=i===this.waypoints.length-1;return n?null:this.waypoints[i+1]},i.prototype.previous=function(e){this.waypoints.sort(t);var i=o.Adapter.inArray(e,this.waypoints);return i?this.waypoints[i-1]:null},i.prototype.queueTrigger=function(t,e){this.triggerQueues[e].push(t)},i.prototype.remove=function(t){var e=o.Adapter.inArray(t,this.waypoints);e>-1&&this.waypoints.splice(e,1)},i.prototype.first=function(){return this.waypoints[0]},i.prototype.last=function(){return this.waypoints[this.waypoints.length-1]},i.findOrCreate=function(t){return n[t.axis][t.name]||new i(t)},o.Group=i}(),function(){"use strict";function t(t){return t===t.window}function e(e){return t(e)?e:e.defaultView}function i(t){this.element=t,this.handlers={}}var n=window.Waypoint;i.prototype.innerHeight=function(){var e=t(this.element);return e?this.element.innerHeight:this.element.clientHeight},i.prototype.innerWidth=function(){var e=t(this.element);return e?this.element.innerWidth:this.element.clientWidth},i.prototype.off=function(t,e){function i(t,e,i){for(var n=0,o=e.length-1;o>n;n++){var r=e[n];i&&i!==r||t.removeEventListener(r)}}var n=t.split("."),o=n[0],r=n[1],s=this.element;if(r&&this.handlers[r]&&o)i(s,this.handlers[r][o],e),this.handlers[r][o]=[];else if(o)for(var l in this.handlers)i(s,this.handlers[l][o]||[],e),this.handlers[l][o]=[];else if(r&&this.handlers[r]){for(var a in this.handlers[r])i(s,this.handlers[r][a],e);this.handlers[r]={}}},i.prototype.offset=function(){if(!this.element.ownerDocument)return null;var t=this.element.ownerDocument.documentElement,i=e(this.element.ownerDocument),n={top:0,left:0};return this.element.getBoundingClientRect&&(n=this.element.getBoundingClientRect()),{top:n.top+i.pageYOffset-t.clientTop,left:n.left+i.pageXOffset-t.clientLeft}},i.prototype.on=function(t,e){var i=t.split("."),n=i[0],o=i[1]||"__default",r=this.handlers[o]=this.handlers[o]||{},s=r[n]=r[n]||[];s.push(e),this.element.addEventListener(n,e)},i.prototype.outerHeight=function(e){var i,n=this.innerHeight();return e&&!t(this.element)&&(i=window.getComputedStyle(this.element),n+=parseInt(i.marginTop,10),n+=parseInt(i.marginBottom,10)),n},i.prototype.outerWidth=function(e){var i,n=this.innerWidth();return e&&!t(this.element)&&(i=window.getComputedStyle(this.element),n+=parseInt(i.marginLeft,10),n+=parseInt(i.marginRight,10)),n},i.prototype.scrollLeft=function(){var t=e(this.element);return t?t.pageXOffset:this.element.scrollLeft},i.prototype.scrollTop=function(){var t=e(this.element);return t?t.pageYOffset:this.element.scrollTop},i.extend=function(){function t(t,e){if("object"==typeof t&&"object"==typeof e)for(var i in e)e.hasOwnProperty(i)&&(t[i]=e[i]);return t}for(var e=Array.prototype.slice.call(arguments),i=1,n=e.length;n>i;i++)t(e[0],e[i]);return e[0]},i.inArray=function(t,e,i){return null==e?-1:e.indexOf(t,i)},i.isEmptyObject=function(t){for(var e in t)return!1;return!0},n.adapters.push({name:"noframework",Adapter:i}),n.Adapter=i}(); \ No newline at end of file +!function(){"use strict";function t(n){if(!n)throw new Error("No options passed to Waypoint constructor");if(!n.element)throw new Error("No element option passed to Waypoint constructor");if(!n.handler)throw new Error("No handler option passed to Waypoint constructor");this.key="waypoint-"+e,this.options=t.Adapter.extend({},t.defaults,n),this.element=this.options.element,this.adapter=new t.Adapter(this.element),this.callback=n.handler,this.axis=this.options.horizontal?"horizontal":"vertical",this.enabled=this.options.enabled,this.triggerPoint=null,this.group=t.Group.findOrCreate({name:this.options.group,axis:this.axis}),this.context=t.Context.findOrCreateByElement(this.options.context),t.offsetAliases[this.options.offset]&&(this.options.offset=t.offsetAliases[this.options.offset]),this.group.add(this),this.context.add(this),i[this.key]=this,e+=1}var e=0,i={};t.prototype.queueTrigger=function(t){this.group.queueTrigger(this,t)},t.prototype.trigger=function(t){this.enabled&&this.callback&&this.callback.apply(this,t)},t.prototype.destroy=function(){this.context.remove(this),this.group.remove(this),delete i[this.key]},t.prototype.disable=function(){return this.enabled=!1,this},t.prototype.enable=function(){return this.context.refresh(),this.enabled=!0,this},t.prototype.next=function(){return this.group.next(this)},t.prototype.previous=function(){return this.group.previous(this)},t.invokeAll=function(t){var e=[];for(var n in i)e.push(i[n]);for(var o=0,r=e.length;r>o;o++)e[o][t]()},t.destroyAll=function(){t.invokeAll("destroy")},t.disableAll=function(){t.invokeAll("disable")},t.enableAll=function(){t.invokeAll("enable")},t.refreshAll=function(){t.Context.refreshAll()},t.viewportHeight=function(){return window.innerHeight||document.documentElement.clientHeight},t.viewportWidth=function(){return document.documentElement.clientWidth},t.adapters=[],t.defaults={context:window,continuous:!0,enabled:!0,group:"default",horizontal:!1,offset:0},t.offsetAliases={"bottom-in-view":function(){return this.context.innerHeight()-this.adapter.outerHeight()},"right-in-view":function(){return this.context.innerWidth()-this.adapter.outerWidth()}},window.Waypoint=t}(),function(){"use strict";function t(t){window.setTimeout(t,1e3/60)}function e(t){this.element=t,this.Adapter=o.Adapter,this.adapter=new this.Adapter(t),this.key="waypoint-context-"+i,this.didScroll=!1,this.didResize=!1,this.oldScroll={x:this.adapter.scrollLeft(),y:this.adapter.scrollTop()},this.waypoints={vertical:{},horizontal:{}},t.waypointContextKey=this.key,n[t.waypointContextKey]=this,i+=1,this.createThrottledScrollHandler(),this.createThrottledResizeHandler()}var i=0,n={},o=window.Waypoint,r=window.onload;e.prototype.add=function(t){var e=t.options.horizontal?"horizontal":"vertical";this.waypoints[e][t.key]=t,this.refresh()},e.prototype.checkEmpty=function(){var t=this.Adapter.isEmptyObject(this.waypoints.horizontal),e=this.Adapter.isEmptyObject(this.waypoints.vertical);t&&e&&(this.adapter.off(".waypoints"),delete n[this.key])},e.prototype.createThrottledResizeHandler=function(){function t(){e.handleResize(),e.didResize=!1}var e=this;this.adapter.on("resize.waypoints",function(){e.didResize||(e.didResize=!0,o.requestAnimationFrame(t))})},e.prototype.createThrottledScrollHandler=function(){function t(){e.handleScroll(),e.didScroll=!1}var e=this;this.adapter.on("scroll.waypoints",function(){(!e.didScroll||o.isTouch)&&(e.didScroll=!0,o.requestAnimationFrame(t))})},e.prototype.handleResize=function(){o.Context.refreshAll()},e.prototype.handleScroll=function(){var t={},e={horizontal:{newScroll:this.adapter.scrollLeft(),oldScroll:this.oldScroll.x,forward:"right",backward:"left"},vertical:{newScroll:this.adapter.scrollTop(),oldScroll:this.oldScroll.y,forward:"down",backward:"up"}};for(var i in e){var n=e[i],o=n.newScroll>n.oldScroll,r=o?n.forward:n.backward;for(var s in this.waypoints[i]){var l=this.waypoints[i][s],a=n.oldScroll=l.triggerPoint,p=a&&h,u=!a&&!h;(p||u)&&(l.queueTrigger(r),t[l.group.id]=l.group)}}for(var c in t)t[c].flushTriggers();this.oldScroll={x:e.horizontal.newScroll,y:e.vertical.newScroll}},e.prototype.innerHeight=function(){return this.element===this.element.window?o.viewportHeight():this.adapter.innerHeight()},e.prototype.remove=function(t){delete this.waypoints[t.axis][t.key],this.checkEmpty()},e.prototype.innerWidth=function(){return this.element===this.element.window?o.viewportWidth():this.adapter.innerWidth()},e.prototype.destroy=function(){var t=[];for(var e in this.waypoints)for(var i in this.waypoints[e])t.push(this.waypoints[e][i]);for(var n=0,o=t.length;o>n;n++)t[n].destroy()},e.prototype.refresh=function(){var t,e=this.element===this.element.window,i=this.adapter.offset(),n={};this.handleScroll(),t={horizontal:{contextOffset:e?0:i.left,contextScroll:e?0:this.oldScroll.x,contextDimension:this.innerWidth(),oldScroll:this.oldScroll.x,forward:"right",backward:"left",offsetProp:"left"},vertical:{contextOffset:e?0:i.top,contextScroll:e?0:this.oldScroll.y,contextDimension:this.innerHeight(),oldScroll:this.oldScroll.y,forward:"down",backward:"up",offsetProp:"top"}};for(var o in t){var r=t[o];for(var s in this.waypoints[o]){var l,a,h,p,u,c=this.waypoints[o][s],f=c.options.offset,d=c.triggerPoint,y=0,g=null==d;c.element!==c.element.window&&(y=c.adapter.offset()[r.offsetProp]),"function"==typeof f?f=f.apply(c):"string"==typeof f&&(f=parseFloat(f),c.options.offset.indexOf("%")>-1&&(f=Math.ceil(r.contextDimension*f/100))),l=r.contextScroll-r.contextOffset,c.triggerPoint=y+l-f,a=d=r.oldScroll,p=a&&h,u=!a&&!h,!g&&p?(c.queueTrigger(r.backward),n[c.group.id]=c.group):!g&&u?(c.queueTrigger(r.forward),n[c.group.id]=c.group):g&&r.oldScroll>=c.triggerPoint&&(c.queueTrigger(r.forward),n[c.group.id]=c.group)}}for(var w in n)n[w].flushTriggers();return this},e.findOrCreateByElement=function(t){return e.findByElement(t)||new e(t)},e.refreshAll=function(){for(var t in n)n[t].refresh()},e.findByElement=function(t){return n[t.waypointContextKey]},window.onload=function(){r&&r(),e.refreshAll()},o.requestAnimationFrame=function(e){var i=window.requestAnimationFrame||window.mozRequestAnimationFrame||window.webkitRequestAnimationFrame||t;i.call(window,e)},o.Context=e}(),function(){"use strict";function t(t,e){return t.triggerPoint-e.triggerPoint}function e(t,e){return e.triggerPoint-t.triggerPoint}function i(t){this.name=t.name,this.axis=t.axis,this.id=this.name+"-"+this.axis,this.waypoints=[],this.clearTriggerQueues(),n[this.axis][this.name]=this}var n={vertical:{},horizontal:{}},o=window.Waypoint;i.prototype.add=function(t){this.waypoints.push(t)},i.prototype.clearTriggerQueues=function(){this.triggerQueues={up:[],down:[],left:[],right:[]}},i.prototype.flushTriggers=function(){for(var i in this.triggerQueues){var n=this.triggerQueues[i],o="up"===i||"left"===i;n.sort(o?e:t);for(var r=0,s=n.length;s>r;r+=1){var l=n[r];(l.options.continuous||r===n.length-1)&&l.trigger([i])}}this.clearTriggerQueues()},i.prototype.next=function(e){this.waypoints.sort(t);var i=o.Adapter.inArray(e,this.waypoints),n=i===this.waypoints.length-1;return n?null:this.waypoints[i+1]},i.prototype.previous=function(e){this.waypoints.sort(t);var i=o.Adapter.inArray(e,this.waypoints);return i?this.waypoints[i-1]:null},i.prototype.queueTrigger=function(t,e){this.triggerQueues[e].push(t)},i.prototype.remove=function(t){var e=o.Adapter.inArray(t,this.waypoints);e>-1&&this.waypoints.splice(e,1)},i.prototype.first=function(){return this.waypoints[0]},i.prototype.last=function(){return this.waypoints[this.waypoints.length-1]},i.findOrCreate=function(t){return n[t.axis][t.name]||new i(t)},o.Group=i}(),function(){"use strict";function t(t){return t===t.window}function e(e){return t(e)?e:e.defaultView}function i(t){this.element=t,this.handlers={}}var n=window.Waypoint;i.prototype.innerHeight=function(){var e=t(this.element);return e?this.element.innerHeight:this.element.clientHeight},i.prototype.innerWidth=function(){var e=t(this.element);return e?this.element.innerWidth:this.element.clientWidth},i.prototype.off=function(t,e){function i(t,e,i){for(var n=0,o=e.length-1;o>n;n++){var r=e[n];i&&i!==r||t.removeEventListener(r)}}var n=t.split("."),o=n[0],r=n[1],s=this.element;if(r&&this.handlers[r]&&o)i(s,this.handlers[r][o],e),this.handlers[r][o]=[];else if(o)for(var l in this.handlers)i(s,this.handlers[l][o]||[],e),this.handlers[l][o]=[];else if(r&&this.handlers[r]){for(var a in this.handlers[r])i(s,this.handlers[r][a],e);this.handlers[r]={}}},i.prototype.offset=function(){if(!this.element.ownerDocument)return null;var t=this.element.ownerDocument.documentElement,i=e(this.element.ownerDocument),n={top:0,left:0};return this.element.getBoundingClientRect&&(n=this.element.getBoundingClientRect()),{top:n.top+i.pageYOffset-t.clientTop,left:n.left+i.pageXOffset-t.clientLeft}},i.prototype.on=function(t,e){var i=t.split("."),n=i[0],o=i[1]||"__default",r=this.handlers[o]=this.handlers[o]||{},s=r[n]=r[n]||[];s.push(e),this.element.addEventListener(n,e)},i.prototype.outerHeight=function(e){var i,n=this.innerHeight();return e&&!t(this.element)&&(i=window.getComputedStyle(this.element),n+=parseInt(i.marginTop,10),n+=parseInt(i.marginBottom,10)),n},i.prototype.outerWidth=function(e){var i,n=this.innerWidth();return e&&!t(this.element)&&(i=window.getComputedStyle(this.element),n+=parseInt(i.marginLeft,10),n+=parseInt(i.marginRight,10)),n},i.prototype.scrollLeft=function(){var t=e(this.element);return t?t.pageXOffset:this.element.scrollLeft},i.prototype.scrollTop=function(){var t=e(this.element);return t?t.pageYOffset:this.element.scrollTop},i.extend=function(){function t(t,e){if("object"==typeof t&&"object"==typeof e)for(var i in e)e.hasOwnProperty(i)&&(t[i]=e[i]);return t}for(var e=Array.prototype.slice.call(arguments),i=1,n=e.length;n>i;i++)t(e[0],e[i]);return e[0]},i.inArray=function(t,e,i){return null==e?-1:e.indexOf(t,i)},i.isEmptyObject=function(t){for(var e in t)return!1;return!0},n.adapters.push({name:"noframework",Adapter:i}),n.Adapter=i}(); \ No newline at end of file diff --git a/lib/zepto.waypoints.js b/lib/zepto.waypoints.js index b179aeee..2733e54f 100644 --- a/lib/zepto.waypoints.js +++ b/lib/zepto.waypoints.js @@ -447,10 +447,13 @@ https://github.com/imakewebthings/waypoints/blog/master/licenses.txt Context.refreshAll() } - Waypoint.requestAnimationFrame = window.requestAnimationFrame || - window.mozRequestAnimationFrame || - window.webkitRequestAnimationFrame || - requestAnimationFrameShim + Waypoint.requestAnimationFrame = function(callback) { + var requestFn = window.requestAnimationFrame || + window.mozRequestAnimationFrame || + window.webkitRequestAnimationFrame || + requestAnimationFrameShim + requestFn.call(window, callback) + } Waypoint.Context = Context }()) ;(function() { diff --git a/lib/zepto.waypoints.min.js b/lib/zepto.waypoints.min.js index dbe09040..c289fef4 100644 --- a/lib/zepto.waypoints.min.js +++ b/lib/zepto.waypoints.min.js @@ -4,4 +4,4 @@ Copyright © 2011-2015 Caleb Troughton Licensed under the MIT license. https://github.com/imakewebthings/waypoints/blog/master/licenses.txt */ -!function(){"use strict";function t(o){if(!o)throw new Error("No options passed to Waypoint constructor");if(!o.element)throw new Error("No element option passed to Waypoint constructor");if(!o.handler)throw new Error("No handler option passed to Waypoint constructor");this.key="waypoint-"+e,this.options=t.Adapter.extend({},t.defaults,o),this.element=this.options.element,this.adapter=new t.Adapter(this.element),this.callback=o.handler,this.axis=this.options.horizontal?"horizontal":"vertical",this.enabled=this.options.enabled,this.triggerPoint=null,this.group=t.Group.findOrCreate({name:this.options.group,axis:this.axis}),this.context=t.Context.findOrCreateByElement(this.options.context),t.offsetAliases[this.options.offset]&&(this.options.offset=t.offsetAliases[this.options.offset]),this.group.add(this),this.context.add(this),i[this.key]=this,e+=1}var e=0,i={};t.prototype.queueTrigger=function(t){this.group.queueTrigger(this,t)},t.prototype.trigger=function(t){this.enabled&&this.callback&&this.callback.apply(this,t)},t.prototype.destroy=function(){this.context.remove(this),this.group.remove(this),delete i[this.key]},t.prototype.disable=function(){return this.enabled=!1,this},t.prototype.enable=function(){return this.context.refresh(),this.enabled=!0,this},t.prototype.next=function(){return this.group.next(this)},t.prototype.previous=function(){return this.group.previous(this)},t.invokeAll=function(t){var e=[];for(var o in i)e.push(i[o]);for(var n=0,r=e.length;r>n;n++)e[n][t]()},t.destroyAll=function(){t.invokeAll("destroy")},t.disableAll=function(){t.invokeAll("disable")},t.enableAll=function(){t.invokeAll("enable")},t.refreshAll=function(){t.Context.refreshAll()},t.viewportHeight=function(){return window.innerHeight||document.documentElement.clientHeight},t.viewportWidth=function(){return document.documentElement.clientWidth},t.adapters=[],t.defaults={context:window,continuous:!0,enabled:!0,group:"default",horizontal:!1,offset:0},t.offsetAliases={"bottom-in-view":function(){return this.context.innerHeight()-this.adapter.outerHeight()},"right-in-view":function(){return this.context.innerWidth()-this.adapter.outerWidth()}},window.Waypoint=t}(),function(){"use strict";function t(t){window.setTimeout(t,1e3/60)}function e(t){this.element=t,this.Adapter=n.Adapter,this.adapter=new this.Adapter(t),this.key="waypoint-context-"+i,this.didScroll=!1,this.didResize=!1,this.oldScroll={x:this.adapter.scrollLeft(),y:this.adapter.scrollTop()},this.waypoints={vertical:{},horizontal:{}},t.waypointContextKey=this.key,o[t.waypointContextKey]=this,i+=1,this.createThrottledScrollHandler(),this.createThrottledResizeHandler()}var i=0,o={},n=window.Waypoint,r=window.onload;e.prototype.add=function(t){var e=t.options.horizontal?"horizontal":"vertical";this.waypoints[e][t.key]=t,this.refresh()},e.prototype.checkEmpty=function(){var t=this.Adapter.isEmptyObject(this.waypoints.horizontal),e=this.Adapter.isEmptyObject(this.waypoints.vertical);t&&e&&(this.adapter.off(".waypoints"),delete o[this.key])},e.prototype.createThrottledResizeHandler=function(){function t(){e.handleResize(),e.didResize=!1}var e=this;this.adapter.on("resize.waypoints",function(){e.didResize||(e.didResize=!0,n.requestAnimationFrame(t))})},e.prototype.createThrottledScrollHandler=function(){function t(){e.handleScroll(),e.didScroll=!1}var e=this;this.adapter.on("scroll.waypoints",function(){(!e.didScroll||n.isTouch)&&(e.didScroll=!0,n.requestAnimationFrame(t))})},e.prototype.handleResize=function(){n.Context.refreshAll()},e.prototype.handleScroll=function(){var t={},e={horizontal:{newScroll:this.adapter.scrollLeft(),oldScroll:this.oldScroll.x,forward:"right",backward:"left"},vertical:{newScroll:this.adapter.scrollTop(),oldScroll:this.oldScroll.y,forward:"down",backward:"up"}};for(var i in e){var o=e[i],n=o.newScroll>o.oldScroll,r=n?o.forward:o.backward;for(var s in this.waypoints[i]){var a=this.waypoints[i][s],l=o.oldScroll=a.triggerPoint,p=l&&h,c=!l&&!h;(p||c)&&(a.queueTrigger(r),t[a.group.id]=a.group)}}for(var u in t)t[u].flushTriggers();this.oldScroll={x:e.horizontal.newScroll,y:e.vertical.newScroll}},e.prototype.innerHeight=function(){return this.element===this.element.window?n.viewportHeight():this.adapter.innerHeight()},e.prototype.remove=function(t){delete this.waypoints[t.axis][t.key],this.checkEmpty()},e.prototype.innerWidth=function(){return this.element===this.element.window?n.viewportWidth():this.adapter.innerWidth()},e.prototype.destroy=function(){var t=[];for(var e in this.waypoints)for(var i in this.waypoints[e])t.push(this.waypoints[e][i]);for(var o=0,n=t.length;n>o;o++)t[o].destroy()},e.prototype.refresh=function(){var t,e=this.element===this.element.window,i=this.adapter.offset(),o={};this.handleScroll(),t={horizontal:{contextOffset:e?0:i.left,contextScroll:e?0:this.oldScroll.x,contextDimension:this.innerWidth(),oldScroll:this.oldScroll.x,forward:"right",backward:"left",offsetProp:"left"},vertical:{contextOffset:e?0:i.top,contextScroll:e?0:this.oldScroll.y,contextDimension:this.innerHeight(),oldScroll:this.oldScroll.y,forward:"down",backward:"up",offsetProp:"top"}};for(var n in t){var r=t[n];for(var s in this.waypoints[n]){var a,l,h,p,c,u=this.waypoints[n][s],d=u.options.offset,f=u.triggerPoint,w=0,y=null==f;u.element!==u.element.window&&(w=u.adapter.offset()[r.offsetProp]),"function"==typeof d?d=d.apply(u):"string"==typeof d&&(d=parseFloat(d),u.options.offset.indexOf("%")>-1&&(d=Math.ceil(r.contextDimension*d/100))),a=r.contextScroll-r.contextOffset,u.triggerPoint=w+a-d,l=f=r.oldScroll,p=l&&h,c=!l&&!h,!y&&p?(u.queueTrigger(r.backward),o[u.group.id]=u.group):!y&&c?(u.queueTrigger(r.forward),o[u.group.id]=u.group):y&&r.oldScroll>=u.triggerPoint&&(u.queueTrigger(r.forward),o[u.group.id]=u.group)}}for(var g in o)o[g].flushTriggers();return this},e.findOrCreateByElement=function(t){return e.findByElement(t)||new e(t)},e.refreshAll=function(){for(var t in o)o[t].refresh()},e.findByElement=function(t){return o[t.waypointContextKey]},window.onload=function(){r&&r(),e.refreshAll()},n.requestAnimationFrame=window.requestAnimationFrame||window.mozRequestAnimationFrame||window.webkitRequestAnimationFrame||t,n.Context=e}(),function(){"use strict";function t(t,e){return t.triggerPoint-e.triggerPoint}function e(t,e){return e.triggerPoint-t.triggerPoint}function i(t){this.name=t.name,this.axis=t.axis,this.id=this.name+"-"+this.axis,this.waypoints=[],this.clearTriggerQueues(),o[this.axis][this.name]=this}var o={vertical:{},horizontal:{}},n=window.Waypoint;i.prototype.add=function(t){this.waypoints.push(t)},i.prototype.clearTriggerQueues=function(){this.triggerQueues={up:[],down:[],left:[],right:[]}},i.prototype.flushTriggers=function(){for(var i in this.triggerQueues){var o=this.triggerQueues[i],n="up"===i||"left"===i;o.sort(n?e:t);for(var r=0,s=o.length;s>r;r+=1){var a=o[r];(a.options.continuous||r===o.length-1)&&a.trigger([i])}}this.clearTriggerQueues()},i.prototype.next=function(e){this.waypoints.sort(t);var i=n.Adapter.inArray(e,this.waypoints),o=i===this.waypoints.length-1;return o?null:this.waypoints[i+1]},i.prototype.previous=function(e){this.waypoints.sort(t);var i=n.Adapter.inArray(e,this.waypoints);return i?this.waypoints[i-1]:null},i.prototype.queueTrigger=function(t,e){this.triggerQueues[e].push(t)},i.prototype.remove=function(t){var e=n.Adapter.inArray(t,this.waypoints);e>-1&&this.waypoints.splice(e,1)},i.prototype.first=function(){return this.waypoints[0]},i.prototype.last=function(){return this.waypoints[this.waypoints.length-1]},i.findOrCreate=function(t){return o[t.axis][t.name]||new i(t)},n.Group=i}(),function(){"use strict";function t(t){this.element=t,this.$element=e(t)}var e=window.Zepto,i=window.Waypoint;e.each(["off","on","scrollLeft","scrollTop"],function(e,i){t.prototype[i]=function(){var t=Array.prototype.slice.call(arguments);return this.$element[i].apply(this.$element,t)}}),t.prototype.offset=function(){return this.element!==this.element.window?this.$element.offset():void 0},e.each(["width","height"],function(i,o){function n(t,i){return function(t){var n=this.$element,r=n[o](),s={width:["left","right"],height:["top","bottom"]};return e.each(s[o],function(e,o){r+=parseInt(n.css("padding-"+o),10),i&&(r+=parseInt(n.css("border-"+o+"-width"),10)),t&&(r+=parseInt(n.css("margin-"+o),10))}),r}}var r=e.camelCase("inner-"+o),s=e.camelCase("outer-"+o);t.prototype[r]=n(!1),t.prototype[s]=n(!0)}),e.each(["extend","inArray"],function(i,o){t[o]=e[o]}),t.isEmptyObject=function(t){for(var e in t)return!1;return!0},i.adapters.push({name:"zepto",Adapter:t}),i.Adapter=t}(),function(){"use strict";function t(t){return function(){var i=[],o=arguments[0];return t.isFunction(arguments[0])&&(o=t.extend({},arguments[1]),o.handler=arguments[0]),this.each(function(){var n=t.extend({},o,{element:this});"string"==typeof n.context&&(n.context=t(this).closest(n.context)[0]),i.push(new e(n))}),i}}var e=window.Waypoint;window.jQuery&&(window.jQuery.fn.waypoint=t(window.jQuery)),window.Zepto&&(window.Zepto.fn.waypoint=t(window.Zepto))}(); \ No newline at end of file +!function(){"use strict";function t(o){if(!o)throw new Error("No options passed to Waypoint constructor");if(!o.element)throw new Error("No element option passed to Waypoint constructor");if(!o.handler)throw new Error("No handler option passed to Waypoint constructor");this.key="waypoint-"+e,this.options=t.Adapter.extend({},t.defaults,o),this.element=this.options.element,this.adapter=new t.Adapter(this.element),this.callback=o.handler,this.axis=this.options.horizontal?"horizontal":"vertical",this.enabled=this.options.enabled,this.triggerPoint=null,this.group=t.Group.findOrCreate({name:this.options.group,axis:this.axis}),this.context=t.Context.findOrCreateByElement(this.options.context),t.offsetAliases[this.options.offset]&&(this.options.offset=t.offsetAliases[this.options.offset]),this.group.add(this),this.context.add(this),i[this.key]=this,e+=1}var e=0,i={};t.prototype.queueTrigger=function(t){this.group.queueTrigger(this,t)},t.prototype.trigger=function(t){this.enabled&&this.callback&&this.callback.apply(this,t)},t.prototype.destroy=function(){this.context.remove(this),this.group.remove(this),delete i[this.key]},t.prototype.disable=function(){return this.enabled=!1,this},t.prototype.enable=function(){return this.context.refresh(),this.enabled=!0,this},t.prototype.next=function(){return this.group.next(this)},t.prototype.previous=function(){return this.group.previous(this)},t.invokeAll=function(t){var e=[];for(var o in i)e.push(i[o]);for(var n=0,r=e.length;r>n;n++)e[n][t]()},t.destroyAll=function(){t.invokeAll("destroy")},t.disableAll=function(){t.invokeAll("disable")},t.enableAll=function(){t.invokeAll("enable")},t.refreshAll=function(){t.Context.refreshAll()},t.viewportHeight=function(){return window.innerHeight||document.documentElement.clientHeight},t.viewportWidth=function(){return document.documentElement.clientWidth},t.adapters=[],t.defaults={context:window,continuous:!0,enabled:!0,group:"default",horizontal:!1,offset:0},t.offsetAliases={"bottom-in-view":function(){return this.context.innerHeight()-this.adapter.outerHeight()},"right-in-view":function(){return this.context.innerWidth()-this.adapter.outerWidth()}},window.Waypoint=t}(),function(){"use strict";function t(t){window.setTimeout(t,1e3/60)}function e(t){this.element=t,this.Adapter=n.Adapter,this.adapter=new this.Adapter(t),this.key="waypoint-context-"+i,this.didScroll=!1,this.didResize=!1,this.oldScroll={x:this.adapter.scrollLeft(),y:this.adapter.scrollTop()},this.waypoints={vertical:{},horizontal:{}},t.waypointContextKey=this.key,o[t.waypointContextKey]=this,i+=1,this.createThrottledScrollHandler(),this.createThrottledResizeHandler()}var i=0,o={},n=window.Waypoint,r=window.onload;e.prototype.add=function(t){var e=t.options.horizontal?"horizontal":"vertical";this.waypoints[e][t.key]=t,this.refresh()},e.prototype.checkEmpty=function(){var t=this.Adapter.isEmptyObject(this.waypoints.horizontal),e=this.Adapter.isEmptyObject(this.waypoints.vertical);t&&e&&(this.adapter.off(".waypoints"),delete o[this.key])},e.prototype.createThrottledResizeHandler=function(){function t(){e.handleResize(),e.didResize=!1}var e=this;this.adapter.on("resize.waypoints",function(){e.didResize||(e.didResize=!0,n.requestAnimationFrame(t))})},e.prototype.createThrottledScrollHandler=function(){function t(){e.handleScroll(),e.didScroll=!1}var e=this;this.adapter.on("scroll.waypoints",function(){(!e.didScroll||n.isTouch)&&(e.didScroll=!0,n.requestAnimationFrame(t))})},e.prototype.handleResize=function(){n.Context.refreshAll()},e.prototype.handleScroll=function(){var t={},e={horizontal:{newScroll:this.adapter.scrollLeft(),oldScroll:this.oldScroll.x,forward:"right",backward:"left"},vertical:{newScroll:this.adapter.scrollTop(),oldScroll:this.oldScroll.y,forward:"down",backward:"up"}};for(var i in e){var o=e[i],n=o.newScroll>o.oldScroll,r=n?o.forward:o.backward;for(var s in this.waypoints[i]){var a=this.waypoints[i][s],l=o.oldScroll=a.triggerPoint,p=l&&h,c=!l&&!h;(p||c)&&(a.queueTrigger(r),t[a.group.id]=a.group)}}for(var u in t)t[u].flushTriggers();this.oldScroll={x:e.horizontal.newScroll,y:e.vertical.newScroll}},e.prototype.innerHeight=function(){return this.element===this.element.window?n.viewportHeight():this.adapter.innerHeight()},e.prototype.remove=function(t){delete this.waypoints[t.axis][t.key],this.checkEmpty()},e.prototype.innerWidth=function(){return this.element===this.element.window?n.viewportWidth():this.adapter.innerWidth()},e.prototype.destroy=function(){var t=[];for(var e in this.waypoints)for(var i in this.waypoints[e])t.push(this.waypoints[e][i]);for(var o=0,n=t.length;n>o;o++)t[o].destroy()},e.prototype.refresh=function(){var t,e=this.element===this.element.window,i=this.adapter.offset(),o={};this.handleScroll(),t={horizontal:{contextOffset:e?0:i.left,contextScroll:e?0:this.oldScroll.x,contextDimension:this.innerWidth(),oldScroll:this.oldScroll.x,forward:"right",backward:"left",offsetProp:"left"},vertical:{contextOffset:e?0:i.top,contextScroll:e?0:this.oldScroll.y,contextDimension:this.innerHeight(),oldScroll:this.oldScroll.y,forward:"down",backward:"up",offsetProp:"top"}};for(var n in t){var r=t[n];for(var s in this.waypoints[n]){var a,l,h,p,c,u=this.waypoints[n][s],d=u.options.offset,f=u.triggerPoint,w=0,y=null==f;u.element!==u.element.window&&(w=u.adapter.offset()[r.offsetProp]),"function"==typeof d?d=d.apply(u):"string"==typeof d&&(d=parseFloat(d),u.options.offset.indexOf("%")>-1&&(d=Math.ceil(r.contextDimension*d/100))),a=r.contextScroll-r.contextOffset,u.triggerPoint=w+a-d,l=f=r.oldScroll,p=l&&h,c=!l&&!h,!y&&p?(u.queueTrigger(r.backward),o[u.group.id]=u.group):!y&&c?(u.queueTrigger(r.forward),o[u.group.id]=u.group):y&&r.oldScroll>=u.triggerPoint&&(u.queueTrigger(r.forward),o[u.group.id]=u.group)}}for(var g in o)o[g].flushTriggers();return this},e.findOrCreateByElement=function(t){return e.findByElement(t)||new e(t)},e.refreshAll=function(){for(var t in o)o[t].refresh()},e.findByElement=function(t){return o[t.waypointContextKey]},window.onload=function(){r&&r(),e.refreshAll()},n.requestAnimationFrame=function(e){var i=window.requestAnimationFrame||window.mozRequestAnimationFrame||window.webkitRequestAnimationFrame||t;i.call(window,e)},n.Context=e}(),function(){"use strict";function t(t,e){return t.triggerPoint-e.triggerPoint}function e(t,e){return e.triggerPoint-t.triggerPoint}function i(t){this.name=t.name,this.axis=t.axis,this.id=this.name+"-"+this.axis,this.waypoints=[],this.clearTriggerQueues(),o[this.axis][this.name]=this}var o={vertical:{},horizontal:{}},n=window.Waypoint;i.prototype.add=function(t){this.waypoints.push(t)},i.prototype.clearTriggerQueues=function(){this.triggerQueues={up:[],down:[],left:[],right:[]}},i.prototype.flushTriggers=function(){for(var i in this.triggerQueues){var o=this.triggerQueues[i],n="up"===i||"left"===i;o.sort(n?e:t);for(var r=0,s=o.length;s>r;r+=1){var a=o[r];(a.options.continuous||r===o.length-1)&&a.trigger([i])}}this.clearTriggerQueues()},i.prototype.next=function(e){this.waypoints.sort(t);var i=n.Adapter.inArray(e,this.waypoints),o=i===this.waypoints.length-1;return o?null:this.waypoints[i+1]},i.prototype.previous=function(e){this.waypoints.sort(t);var i=n.Adapter.inArray(e,this.waypoints);return i?this.waypoints[i-1]:null},i.prototype.queueTrigger=function(t,e){this.triggerQueues[e].push(t)},i.prototype.remove=function(t){var e=n.Adapter.inArray(t,this.waypoints);e>-1&&this.waypoints.splice(e,1)},i.prototype.first=function(){return this.waypoints[0]},i.prototype.last=function(){return this.waypoints[this.waypoints.length-1]},i.findOrCreate=function(t){return o[t.axis][t.name]||new i(t)},n.Group=i}(),function(){"use strict";function t(t){this.element=t,this.$element=e(t)}var e=window.Zepto,i=window.Waypoint;e.each(["off","on","scrollLeft","scrollTop"],function(e,i){t.prototype[i]=function(){var t=Array.prototype.slice.call(arguments);return this.$element[i].apply(this.$element,t)}}),t.prototype.offset=function(){return this.element!==this.element.window?this.$element.offset():void 0},e.each(["width","height"],function(i,o){function n(t,i){return function(t){var n=this.$element,r=n[o](),s={width:["left","right"],height:["top","bottom"]};return e.each(s[o],function(e,o){r+=parseInt(n.css("padding-"+o),10),i&&(r+=parseInt(n.css("border-"+o+"-width"),10)),t&&(r+=parseInt(n.css("margin-"+o),10))}),r}}var r=e.camelCase("inner-"+o),s=e.camelCase("outer-"+o);t.prototype[r]=n(!1),t.prototype[s]=n(!0)}),e.each(["extend","inArray"],function(i,o){t[o]=e[o]}),t.isEmptyObject=function(t){for(var e in t)return!1;return!0},i.adapters.push({name:"zepto",Adapter:t}),i.Adapter=t}(),function(){"use strict";function t(t){return function(){var i=[],o=arguments[0];return t.isFunction(arguments[0])&&(o=t.extend({},arguments[1]),o.handler=arguments[0]),this.each(function(){var n=t.extend({},o,{element:this});"string"==typeof n.context&&(n.context=t(this).closest(n.context)[0]),i.push(new e(n))}),i}}var e=window.Waypoint;window.jQuery&&(window.jQuery.fn.waypoint=t(window.jQuery)),window.Zepto&&(window.Zepto.fn.waypoint=t(window.Zepto))}(); \ No newline at end of file diff --git a/src/context.js b/src/context.js index 48259d7f..996da39e 100644 --- a/src/context.js +++ b/src/context.js @@ -281,9 +281,12 @@ Context.refreshAll() } - Waypoint.requestAnimationFrame = window.requestAnimationFrame || - window.mozRequestAnimationFrame || - window.webkitRequestAnimationFrame || - requestAnimationFrameShim + Waypoint.requestAnimationFrame = function(callback) { + var requestFn = window.requestAnimationFrame || + window.mozRequestAnimationFrame || + window.webkitRequestAnimationFrame || + requestAnimationFrameShim + requestFn.call(window, callback) + } Waypoint.Context = Context }()) From f4488a0cfb3b9b0349caeb42c84a881fd4ef2273 Mon Sep 17 00:00:00 2001 From: imakewebthings Date: Mon, 19 Jan 2015 12:24:20 -0800 Subject: [PATCH 68/98] Use getComputedStyle in debug to catch CSS definitions --- lib/waypoints.debug.js | 2 +- src/debug.js | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/lib/waypoints.debug.js b/lib/waypoints.debug.js index 745401b9..f9f4c2f9 100644 --- a/lib/waypoints.debug.js +++ b/lib/waypoints.debug.js @@ -25,7 +25,7 @@ https://github.com/imakewebthings/waypoints/blog/master/licenses.txt for (var axis in this.waypoints) { for (var key in this.waypoints[axis]) { var waypoint = this.waypoints[axis][key] - var style = waypoint.element.style + var style = window.getComputedStyle(waypoint.element) if (!waypoint.enabled) { continue } diff --git a/src/debug.js b/src/debug.js index 4461e732..be9510bf 100644 --- a/src/debug.js +++ b/src/debug.js @@ -19,7 +19,7 @@ for (var axis in this.waypoints) { for (var key in this.waypoints[axis]) { var waypoint = this.waypoints[axis][key] - var style = waypoint.element.style + var style = window.getComputedStyle(waypoint.element) if (!waypoint.enabled) { continue } From 8b23d3688ea00712e735587ca47b8ceeccd17456 Mon Sep 17 00:00:00 2001 From: imakewebthings Date: Mon, 19 Jan 2015 12:41:51 -0800 Subject: [PATCH 69/98] Release 3.1.0 --- bower.json | 2 +- lib/jquery.waypoints.js | 2 +- lib/jquery.waypoints.min.js | 2 +- lib/noframework.waypoints.js | 2 +- lib/noframework.waypoints.min.js | 2 +- lib/shortcuts/infinite.js | 2 +- lib/shortcuts/infinite.min.js | 2 +- lib/shortcuts/inview.js | 2 +- lib/shortcuts/inview.min.js | 2 +- lib/shortcuts/sticky.js | 2 +- lib/shortcuts/sticky.min.js | 2 +- lib/waypoints.debug.js | 2 +- lib/zepto.waypoints.js | 2 +- lib/zepto.waypoints.min.js | 2 +- package.json | 4 ++-- 15 files changed, 16 insertions(+), 16 deletions(-) diff --git a/bower.json b/bower.json index cc40623f..91a18291 100644 --- a/bower.json +++ b/bower.json @@ -1,6 +1,6 @@ { "name": "waypoints", - "version": "3.0.1", + "version": "3.1.0", "main": "lib/noframework.waypoints.min.js", "description": "Easily execute a function when you scroll to an element.", "ignore": [ diff --git a/lib/jquery.waypoints.js b/lib/jquery.waypoints.js index 7f8d1ae3..9037e9d4 100644 --- a/lib/jquery.waypoints.js +++ b/lib/jquery.waypoints.js @@ -1,5 +1,5 @@ /*! -Waypoints - 3.0.1 +Waypoints - 3.1.0 Copyright © 2011-2015 Caleb Troughton Licensed under the MIT license. https://github.com/imakewebthings/waypoints/blog/master/licenses.txt diff --git a/lib/jquery.waypoints.min.js b/lib/jquery.waypoints.min.js index 70cbcf4a..f39a42fd 100644 --- a/lib/jquery.waypoints.min.js +++ b/lib/jquery.waypoints.min.js @@ -1,5 +1,5 @@ /*! -Waypoints - 3.0.1 +Waypoints - 3.1.0 Copyright © 2011-2015 Caleb Troughton Licensed under the MIT license. https://github.com/imakewebthings/waypoints/blog/master/licenses.txt diff --git a/lib/noframework.waypoints.js b/lib/noframework.waypoints.js index ef3bac41..027cb450 100644 --- a/lib/noframework.waypoints.js +++ b/lib/noframework.waypoints.js @@ -1,5 +1,5 @@ /*! -Waypoints - 3.0.1 +Waypoints - 3.1.0 Copyright © 2011-2015 Caleb Troughton Licensed under the MIT license. https://github.com/imakewebthings/waypoints/blog/master/licenses.txt diff --git a/lib/noframework.waypoints.min.js b/lib/noframework.waypoints.min.js index 359f58f6..37081970 100644 --- a/lib/noframework.waypoints.min.js +++ b/lib/noframework.waypoints.min.js @@ -1,5 +1,5 @@ /*! -Waypoints - 3.0.1 +Waypoints - 3.1.0 Copyright © 2011-2015 Caleb Troughton Licensed under the MIT license. https://github.com/imakewebthings/waypoints/blog/master/licenses.txt diff --git a/lib/shortcuts/infinite.js b/lib/shortcuts/infinite.js index 537f0ecc..2c86cceb 100644 --- a/lib/shortcuts/infinite.js +++ b/lib/shortcuts/infinite.js @@ -1,5 +1,5 @@ /*! -Waypoints Infinite Scroll Shortcut - 3.0.1 +Waypoints Infinite Scroll Shortcut - 3.1.0 Copyright © 2011-2015 Caleb Troughton Licensed under the MIT license. https://github.com/imakewebthings/waypoints/blog/master/licenses.txt diff --git a/lib/shortcuts/infinite.min.js b/lib/shortcuts/infinite.min.js index 39cb1696..aca4c90f 100644 --- a/lib/shortcuts/infinite.min.js +++ b/lib/shortcuts/infinite.min.js @@ -1,5 +1,5 @@ /*! -Waypoints Infinite Scroll Shortcut - 3.0.1 +Waypoints Infinite Scroll Shortcut - 3.1.0 Copyright © 2011-2015 Caleb Troughton Licensed under the MIT license. https://github.com/imakewebthings/waypoints/blog/master/licenses.txt diff --git a/lib/shortcuts/inview.js b/lib/shortcuts/inview.js index e5009c48..09948baa 100644 --- a/lib/shortcuts/inview.js +++ b/lib/shortcuts/inview.js @@ -1,5 +1,5 @@ /*! -Waypoints Inview Shortcut - 3.0.1 +Waypoints Inview Shortcut - 3.1.0 Copyright © 2011-2015 Caleb Troughton Licensed under the MIT license. https://github.com/imakewebthings/waypoints/blog/master/licenses.txt diff --git a/lib/shortcuts/inview.min.js b/lib/shortcuts/inview.min.js index c8837186..9843b2b0 100644 --- a/lib/shortcuts/inview.min.js +++ b/lib/shortcuts/inview.min.js @@ -1,5 +1,5 @@ /*! -Waypoints Inview Shortcut - 3.0.1 +Waypoints Inview Shortcut - 3.1.0 Copyright © 2011-2015 Caleb Troughton Licensed under the MIT license. https://github.com/imakewebthings/waypoints/blog/master/licenses.txt diff --git a/lib/shortcuts/sticky.js b/lib/shortcuts/sticky.js index 4492cfbf..a9823833 100644 --- a/lib/shortcuts/sticky.js +++ b/lib/shortcuts/sticky.js @@ -1,5 +1,5 @@ /*! -Waypoints Sticky Element Shortcut - 3.0.1 +Waypoints Sticky Element Shortcut - 3.1.0 Copyright © 2011-2015 Caleb Troughton Licensed under the MIT license. https://github.com/imakewebthings/waypoints/blog/master/licenses.txt diff --git a/lib/shortcuts/sticky.min.js b/lib/shortcuts/sticky.min.js index 65de4c41..0fd1ab3e 100644 --- a/lib/shortcuts/sticky.min.js +++ b/lib/shortcuts/sticky.min.js @@ -1,5 +1,5 @@ /*! -Waypoints Sticky Element Shortcut - 3.0.1 +Waypoints Sticky Element Shortcut - 3.1.0 Copyright © 2011-2015 Caleb Troughton Licensed under the MIT license. https://github.com/imakewebthings/waypoints/blog/master/licenses.txt diff --git a/lib/waypoints.debug.js b/lib/waypoints.debug.js index f9f4c2f9..bf117160 100644 --- a/lib/waypoints.debug.js +++ b/lib/waypoints.debug.js @@ -1,5 +1,5 @@ /*! -Waypoints Debug - 3.0.1 +Waypoints Debug - 3.1.0 Copyright © 2011-2015 Caleb Troughton Licensed under the MIT license. https://github.com/imakewebthings/waypoints/blog/master/licenses.txt diff --git a/lib/zepto.waypoints.js b/lib/zepto.waypoints.js index 2733e54f..f580076a 100644 --- a/lib/zepto.waypoints.js +++ b/lib/zepto.waypoints.js @@ -1,5 +1,5 @@ /*! -Waypoints - 3.0.1 +Waypoints - 3.1.0 Copyright © 2011-2015 Caleb Troughton Licensed under the MIT license. https://github.com/imakewebthings/waypoints/blog/master/licenses.txt diff --git a/lib/zepto.waypoints.min.js b/lib/zepto.waypoints.min.js index c289fef4..97a34d61 100644 --- a/lib/zepto.waypoints.min.js +++ b/lib/zepto.waypoints.min.js @@ -1,5 +1,5 @@ /*! -Waypoints - 3.0.1 +Waypoints - 3.1.0 Copyright © 2011-2015 Caleb Troughton Licensed under the MIT license. https://github.com/imakewebthings/waypoints/blog/master/licenses.txt diff --git a/package.json b/package.json index dd85f2f7..1d67cb49 100644 --- a/package.json +++ b/package.json @@ -1,7 +1,7 @@ { "name": "jquery-waypoints", - "version": "3.0.1", - "author": "Caleb Troughton ", + "version": "3.1.0", + "author": "Caleb Troughton (http://imakewebthings.com)", "description": "A jQuery plugin that makes it easy to execute a function whenever you scroll to an element.", "scripts": { "build": "gulp build", From 747f0a843a88dd8aba2de4f761ad44dd0dc8d9e1 Mon Sep 17 00:00:00 2001 From: imakewebthings Date: Mon, 19 Jan 2015 14:50:57 -0800 Subject: [PATCH 70/98] Changelog for 3.1.0 --- CHANGELOG.md | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 28a19da4..87ffdf64 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,13 @@ # Changelog +## v3.1.0 + +- Add `Waypoint.disableAll` and `Waypoint.enableAll` methods. +- Fix Illegal Invocation errors stemming from non-window context use of `requestAnimationFrame`. (Pull #366) +- Keep disabled waypoints from triggering debug script errors. (Pull #365) +- Allow Infinite Scroll items to be root elements in the AJAX response. (Pull #361) +- In debug script, detect display none and fixed positioning defined in CSS. + ## v3.0.1 - Add semicolons to the end of built files to aid in clean concatenation. (Issue #353) From 705399cee37a0a209890c36d6ce574ed06bb3cce Mon Sep 17 00:00:00 2001 From: Matthew Harris Date: Wed, 21 Jan 2015 15:23:20 +0000 Subject: [PATCH 71/98] Update README.md --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 8c440549..af686851 100644 --- a/README.md +++ b/README.md @@ -6,7 +6,7 @@ Waypoints is a library that makes it easy to execute a function whenever you scr var waypoint = new Waypoint({ element: document.getElementById('thing'), handler: function(direction) { - alert('You have scroll to a thing') + alert('You have scrolled to a thing') } }) ``` From 78cf2950aae9cc7e8553e6c1c59dc45e0c977f06 Mon Sep 17 00:00:00 2001 From: imakewebthings Date: Thu, 29 Jan 2015 13:27:50 -0800 Subject: [PATCH 72/98] isWindow check should not use strict equality --- src/context.js | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/context.js b/src/context.js index 996da39e..42e539bc 100644 --- a/src/context.js +++ b/src/context.js @@ -138,7 +138,7 @@ /* Private */ Context.prototype.innerHeight = function() { - if (this.element === this.element.window) { + if (this.element == this.element.window) { return Waypoint.viewportHeight() } return this.adapter.innerHeight() @@ -152,7 +152,7 @@ /* Private */ Context.prototype.innerWidth = function() { - if (this.element === this.element.window) { + if (this.element == this.element.window) { return Waypoint.viewportWidth() } return this.adapter.innerWidth() @@ -175,7 +175,7 @@ /* Public */ /* http://imakewebthings.com/waypoints/api/context-refresh */ Context.prototype.refresh = function() { - var isWindow = this.element === this.element.window + var isWindow = this.element == this.element.window var contextOffset = this.adapter.offset() var triggeredGroups = {} var axes From 13ae054b649b5e0df9a549abb4a0420eac67bea8 Mon Sep 17 00:00:00 2001 From: imakewebthings Date: Thu, 29 Jan 2015 13:40:12 -0800 Subject: [PATCH 73/98] Build and prepare for 3.1.1 release --- CHANGELOG.md | 4 ++++ bower.json | 2 +- lib/jquery.waypoints.js | 14 ++++++++++---- lib/jquery.waypoints.min.js | 4 ++-- lib/noframework.waypoints.js | 14 ++++++++++---- lib/noframework.waypoints.min.js | 4 ++-- lib/shortcuts/infinite.js | 2 +- lib/shortcuts/infinite.min.js | 2 +- lib/shortcuts/inview.js | 2 +- lib/shortcuts/inview.min.js | 2 +- lib/shortcuts/sticky.js | 2 +- lib/shortcuts/sticky.min.js | 2 +- lib/waypoints.debug.js | 2 +- lib/zepto.waypoints.js | 14 ++++++++++---- lib/zepto.waypoints.min.js | 4 ++-- package.json | 9 ++++----- src/context.js | 6 ++++++ 17 files changed, 58 insertions(+), 31 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 87ffdf64..d9a7918b 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,9 @@ # Changelog +## v3.1.1 + +- Fix bad `isWindow` checks causing errors in IE8-. (Issue #372) + ## v3.1.0 - Add `Waypoint.disableAll` and `Waypoint.enableAll` methods. diff --git a/bower.json b/bower.json index 91a18291..348993c3 100644 --- a/bower.json +++ b/bower.json @@ -1,6 +1,6 @@ { "name": "waypoints", - "version": "3.1.0", + "version": "3.1.1", "main": "lib/noframework.waypoints.min.js", "description": "Easily execute a function when you scroll to an element.", "ignore": [ diff --git a/lib/jquery.waypoints.js b/lib/jquery.waypoints.js index 9037e9d4..536d5d48 100644 --- a/lib/jquery.waypoints.js +++ b/lib/jquery.waypoints.js @@ -1,5 +1,5 @@ /*! -Waypoints - 3.1.0 +Waypoints - 3.1.1 Copyright © 2011-2015 Caleb Troughton Licensed under the MIT license. https://github.com/imakewebthings/waypoints/blog/master/licenses.txt @@ -304,9 +304,11 @@ https://github.com/imakewebthings/waypoints/blog/master/licenses.txt /* Private */ Context.prototype.innerHeight = function() { - if (this.element === this.element.window) { + /*eslint-disable eqeqeq */ + if (this.element == this.element.window) { return Waypoint.viewportHeight() } + /*eslint-enable eqeqeq */ return this.adapter.innerHeight() } @@ -318,9 +320,11 @@ https://github.com/imakewebthings/waypoints/blog/master/licenses.txt /* Private */ Context.prototype.innerWidth = function() { - if (this.element === this.element.window) { + /*eslint-disable eqeqeq */ + if (this.element == this.element.window) { return Waypoint.viewportWidth() } + /*eslint-enable eqeqeq */ return this.adapter.innerWidth() } @@ -341,7 +345,9 @@ https://github.com/imakewebthings/waypoints/blog/master/licenses.txt /* Public */ /* http://imakewebthings.com/waypoints/api/context-refresh */ Context.prototype.refresh = function() { - var isWindow = this.element === this.element.window + /*eslint-disable eqeqeq */ + var isWindow = this.element == this.element.window + /*eslint-enable eqeqeq */ var contextOffset = this.adapter.offset() var triggeredGroups = {} var axes diff --git a/lib/jquery.waypoints.min.js b/lib/jquery.waypoints.min.js index f39a42fd..44a1d323 100644 --- a/lib/jquery.waypoints.min.js +++ b/lib/jquery.waypoints.min.js @@ -1,7 +1,7 @@ /*! -Waypoints - 3.1.0 +Waypoints - 3.1.1 Copyright © 2011-2015 Caleb Troughton Licensed under the MIT license. https://github.com/imakewebthings/waypoints/blog/master/licenses.txt */ -!function(){"use strict";function t(o){if(!o)throw new Error("No options passed to Waypoint constructor");if(!o.element)throw new Error("No element option passed to Waypoint constructor");if(!o.handler)throw new Error("No handler option passed to Waypoint constructor");this.key="waypoint-"+e,this.options=t.Adapter.extend({},t.defaults,o),this.element=this.options.element,this.adapter=new t.Adapter(this.element),this.callback=o.handler,this.axis=this.options.horizontal?"horizontal":"vertical",this.enabled=this.options.enabled,this.triggerPoint=null,this.group=t.Group.findOrCreate({name:this.options.group,axis:this.axis}),this.context=t.Context.findOrCreateByElement(this.options.context),t.offsetAliases[this.options.offset]&&(this.options.offset=t.offsetAliases[this.options.offset]),this.group.add(this),this.context.add(this),i[this.key]=this,e+=1}var e=0,i={};t.prototype.queueTrigger=function(t){this.group.queueTrigger(this,t)},t.prototype.trigger=function(t){this.enabled&&this.callback&&this.callback.apply(this,t)},t.prototype.destroy=function(){this.context.remove(this),this.group.remove(this),delete i[this.key]},t.prototype.disable=function(){return this.enabled=!1,this},t.prototype.enable=function(){return this.context.refresh(),this.enabled=!0,this},t.prototype.next=function(){return this.group.next(this)},t.prototype.previous=function(){return this.group.previous(this)},t.invokeAll=function(t){var e=[];for(var o in i)e.push(i[o]);for(var n=0,r=e.length;r>n;n++)e[n][t]()},t.destroyAll=function(){t.invokeAll("destroy")},t.disableAll=function(){t.invokeAll("disable")},t.enableAll=function(){t.invokeAll("enable")},t.refreshAll=function(){t.Context.refreshAll()},t.viewportHeight=function(){return window.innerHeight||document.documentElement.clientHeight},t.viewportWidth=function(){return document.documentElement.clientWidth},t.adapters=[],t.defaults={context:window,continuous:!0,enabled:!0,group:"default",horizontal:!1,offset:0},t.offsetAliases={"bottom-in-view":function(){return this.context.innerHeight()-this.adapter.outerHeight()},"right-in-view":function(){return this.context.innerWidth()-this.adapter.outerWidth()}},window.Waypoint=t}(),function(){"use strict";function t(t){window.setTimeout(t,1e3/60)}function e(t){this.element=t,this.Adapter=n.Adapter,this.adapter=new this.Adapter(t),this.key="waypoint-context-"+i,this.didScroll=!1,this.didResize=!1,this.oldScroll={x:this.adapter.scrollLeft(),y:this.adapter.scrollTop()},this.waypoints={vertical:{},horizontal:{}},t.waypointContextKey=this.key,o[t.waypointContextKey]=this,i+=1,this.createThrottledScrollHandler(),this.createThrottledResizeHandler()}var i=0,o={},n=window.Waypoint,r=window.onload;e.prototype.add=function(t){var e=t.options.horizontal?"horizontal":"vertical";this.waypoints[e][t.key]=t,this.refresh()},e.prototype.checkEmpty=function(){var t=this.Adapter.isEmptyObject(this.waypoints.horizontal),e=this.Adapter.isEmptyObject(this.waypoints.vertical);t&&e&&(this.adapter.off(".waypoints"),delete o[this.key])},e.prototype.createThrottledResizeHandler=function(){function t(){e.handleResize(),e.didResize=!1}var e=this;this.adapter.on("resize.waypoints",function(){e.didResize||(e.didResize=!0,n.requestAnimationFrame(t))})},e.prototype.createThrottledScrollHandler=function(){function t(){e.handleScroll(),e.didScroll=!1}var e=this;this.adapter.on("scroll.waypoints",function(){(!e.didScroll||n.isTouch)&&(e.didScroll=!0,n.requestAnimationFrame(t))})},e.prototype.handleResize=function(){n.Context.refreshAll()},e.prototype.handleScroll=function(){var t={},e={horizontal:{newScroll:this.adapter.scrollLeft(),oldScroll:this.oldScroll.x,forward:"right",backward:"left"},vertical:{newScroll:this.adapter.scrollTop(),oldScroll:this.oldScroll.y,forward:"down",backward:"up"}};for(var i in e){var o=e[i],n=o.newScroll>o.oldScroll,r=n?o.forward:o.backward;for(var s in this.waypoints[i]){var a=this.waypoints[i][s],l=o.oldScroll=a.triggerPoint,p=l&&h,u=!l&&!h;(p||u)&&(a.queueTrigger(r),t[a.group.id]=a.group)}}for(var c in t)t[c].flushTriggers();this.oldScroll={x:e.horizontal.newScroll,y:e.vertical.newScroll}},e.prototype.innerHeight=function(){return this.element===this.element.window?n.viewportHeight():this.adapter.innerHeight()},e.prototype.remove=function(t){delete this.waypoints[t.axis][t.key],this.checkEmpty()},e.prototype.innerWidth=function(){return this.element===this.element.window?n.viewportWidth():this.adapter.innerWidth()},e.prototype.destroy=function(){var t=[];for(var e in this.waypoints)for(var i in this.waypoints[e])t.push(this.waypoints[e][i]);for(var o=0,n=t.length;n>o;o++)t[o].destroy()},e.prototype.refresh=function(){var t,e=this.element===this.element.window,i=this.adapter.offset(),o={};this.handleScroll(),t={horizontal:{contextOffset:e?0:i.left,contextScroll:e?0:this.oldScroll.x,contextDimension:this.innerWidth(),oldScroll:this.oldScroll.x,forward:"right",backward:"left",offsetProp:"left"},vertical:{contextOffset:e?0:i.top,contextScroll:e?0:this.oldScroll.y,contextDimension:this.innerHeight(),oldScroll:this.oldScroll.y,forward:"down",backward:"up",offsetProp:"top"}};for(var n in t){var r=t[n];for(var s in this.waypoints[n]){var a,l,h,p,u,c=this.waypoints[n][s],d=c.options.offset,f=c.triggerPoint,w=0,y=null==f;c.element!==c.element.window&&(w=c.adapter.offset()[r.offsetProp]),"function"==typeof d?d=d.apply(c):"string"==typeof d&&(d=parseFloat(d),c.options.offset.indexOf("%")>-1&&(d=Math.ceil(r.contextDimension*d/100))),a=r.contextScroll-r.contextOffset,c.triggerPoint=w+a-d,l=f=r.oldScroll,p=l&&h,u=!l&&!h,!y&&p?(c.queueTrigger(r.backward),o[c.group.id]=c.group):!y&&u?(c.queueTrigger(r.forward),o[c.group.id]=c.group):y&&r.oldScroll>=c.triggerPoint&&(c.queueTrigger(r.forward),o[c.group.id]=c.group)}}for(var g in o)o[g].flushTriggers();return this},e.findOrCreateByElement=function(t){return e.findByElement(t)||new e(t)},e.refreshAll=function(){for(var t in o)o[t].refresh()},e.findByElement=function(t){return o[t.waypointContextKey]},window.onload=function(){r&&r(),e.refreshAll()},n.requestAnimationFrame=function(e){var i=window.requestAnimationFrame||window.mozRequestAnimationFrame||window.webkitRequestAnimationFrame||t;i.call(window,e)},n.Context=e}(),function(){"use strict";function t(t,e){return t.triggerPoint-e.triggerPoint}function e(t,e){return e.triggerPoint-t.triggerPoint}function i(t){this.name=t.name,this.axis=t.axis,this.id=this.name+"-"+this.axis,this.waypoints=[],this.clearTriggerQueues(),o[this.axis][this.name]=this}var o={vertical:{},horizontal:{}},n=window.Waypoint;i.prototype.add=function(t){this.waypoints.push(t)},i.prototype.clearTriggerQueues=function(){this.triggerQueues={up:[],down:[],left:[],right:[]}},i.prototype.flushTriggers=function(){for(var i in this.triggerQueues){var o=this.triggerQueues[i],n="up"===i||"left"===i;o.sort(n?e:t);for(var r=0,s=o.length;s>r;r+=1){var a=o[r];(a.options.continuous||r===o.length-1)&&a.trigger([i])}}this.clearTriggerQueues()},i.prototype.next=function(e){this.waypoints.sort(t);var i=n.Adapter.inArray(e,this.waypoints),o=i===this.waypoints.length-1;return o?null:this.waypoints[i+1]},i.prototype.previous=function(e){this.waypoints.sort(t);var i=n.Adapter.inArray(e,this.waypoints);return i?this.waypoints[i-1]:null},i.prototype.queueTrigger=function(t,e){this.triggerQueues[e].push(t)},i.prototype.remove=function(t){var e=n.Adapter.inArray(t,this.waypoints);e>-1&&this.waypoints.splice(e,1)},i.prototype.first=function(){return this.waypoints[0]},i.prototype.last=function(){return this.waypoints[this.waypoints.length-1]},i.findOrCreate=function(t){return o[t.axis][t.name]||new i(t)},n.Group=i}(),function(){"use strict";function t(t){this.$element=e(t)}var e=window.jQuery,i=window.Waypoint;e.each(["innerHeight","innerWidth","off","offset","on","outerHeight","outerWidth","scrollLeft","scrollTop"],function(e,i){t.prototype[i]=function(){var t=Array.prototype.slice.call(arguments);return this.$element[i].apply(this.$element,t)}}),e.each(["extend","inArray","isEmptyObject"],function(i,o){t[o]=e[o]}),i.adapters.push({name:"jquery",Adapter:t}),i.Adapter=t}(),function(){"use strict";function t(t){return function(){var i=[],o=arguments[0];return t.isFunction(arguments[0])&&(o=t.extend({},arguments[1]),o.handler=arguments[0]),this.each(function(){var n=t.extend({},o,{element:this});"string"==typeof n.context&&(n.context=t(this).closest(n.context)[0]),i.push(new e(n))}),i}}var e=window.Waypoint;window.jQuery&&(window.jQuery.fn.waypoint=t(window.jQuery)),window.Zepto&&(window.Zepto.fn.waypoint=t(window.Zepto))}(); \ No newline at end of file +!function(){"use strict";function t(o){if(!o)throw new Error("No options passed to Waypoint constructor");if(!o.element)throw new Error("No element option passed to Waypoint constructor");if(!o.handler)throw new Error("No handler option passed to Waypoint constructor");this.key="waypoint-"+e,this.options=t.Adapter.extend({},t.defaults,o),this.element=this.options.element,this.adapter=new t.Adapter(this.element),this.callback=o.handler,this.axis=this.options.horizontal?"horizontal":"vertical",this.enabled=this.options.enabled,this.triggerPoint=null,this.group=t.Group.findOrCreate({name:this.options.group,axis:this.axis}),this.context=t.Context.findOrCreateByElement(this.options.context),t.offsetAliases[this.options.offset]&&(this.options.offset=t.offsetAliases[this.options.offset]),this.group.add(this),this.context.add(this),i[this.key]=this,e+=1}var e=0,i={};t.prototype.queueTrigger=function(t){this.group.queueTrigger(this,t)},t.prototype.trigger=function(t){this.enabled&&this.callback&&this.callback.apply(this,t)},t.prototype.destroy=function(){this.context.remove(this),this.group.remove(this),delete i[this.key]},t.prototype.disable=function(){return this.enabled=!1,this},t.prototype.enable=function(){return this.context.refresh(),this.enabled=!0,this},t.prototype.next=function(){return this.group.next(this)},t.prototype.previous=function(){return this.group.previous(this)},t.invokeAll=function(t){var e=[];for(var o in i)e.push(i[o]);for(var n=0,r=e.length;r>n;n++)e[n][t]()},t.destroyAll=function(){t.invokeAll("destroy")},t.disableAll=function(){t.invokeAll("disable")},t.enableAll=function(){t.invokeAll("enable")},t.refreshAll=function(){t.Context.refreshAll()},t.viewportHeight=function(){return window.innerHeight||document.documentElement.clientHeight},t.viewportWidth=function(){return document.documentElement.clientWidth},t.adapters=[],t.defaults={context:window,continuous:!0,enabled:!0,group:"default",horizontal:!1,offset:0},t.offsetAliases={"bottom-in-view":function(){return this.context.innerHeight()-this.adapter.outerHeight()},"right-in-view":function(){return this.context.innerWidth()-this.adapter.outerWidth()}},window.Waypoint=t}(),function(){"use strict";function t(t){window.setTimeout(t,1e3/60)}function e(t){this.element=t,this.Adapter=n.Adapter,this.adapter=new this.Adapter(t),this.key="waypoint-context-"+i,this.didScroll=!1,this.didResize=!1,this.oldScroll={x:this.adapter.scrollLeft(),y:this.adapter.scrollTop()},this.waypoints={vertical:{},horizontal:{}},t.waypointContextKey=this.key,o[t.waypointContextKey]=this,i+=1,this.createThrottledScrollHandler(),this.createThrottledResizeHandler()}var i=0,o={},n=window.Waypoint,r=window.onload;e.prototype.add=function(t){var e=t.options.horizontal?"horizontal":"vertical";this.waypoints[e][t.key]=t,this.refresh()},e.prototype.checkEmpty=function(){var t=this.Adapter.isEmptyObject(this.waypoints.horizontal),e=this.Adapter.isEmptyObject(this.waypoints.vertical);t&&e&&(this.adapter.off(".waypoints"),delete o[this.key])},e.prototype.createThrottledResizeHandler=function(){function t(){e.handleResize(),e.didResize=!1}var e=this;this.adapter.on("resize.waypoints",function(){e.didResize||(e.didResize=!0,n.requestAnimationFrame(t))})},e.prototype.createThrottledScrollHandler=function(){function t(){e.handleScroll(),e.didScroll=!1}var e=this;this.adapter.on("scroll.waypoints",function(){(!e.didScroll||n.isTouch)&&(e.didScroll=!0,n.requestAnimationFrame(t))})},e.prototype.handleResize=function(){n.Context.refreshAll()},e.prototype.handleScroll=function(){var t={},e={horizontal:{newScroll:this.adapter.scrollLeft(),oldScroll:this.oldScroll.x,forward:"right",backward:"left"},vertical:{newScroll:this.adapter.scrollTop(),oldScroll:this.oldScroll.y,forward:"down",backward:"up"}};for(var i in e){var o=e[i],n=o.newScroll>o.oldScroll,r=n?o.forward:o.backward;for(var s in this.waypoints[i]){var a=this.waypoints[i][s],l=o.oldScroll=a.triggerPoint,p=l&&h,u=!l&&!h;(p||u)&&(a.queueTrigger(r),t[a.group.id]=a.group)}}for(var c in t)t[c].flushTriggers();this.oldScroll={x:e.horizontal.newScroll,y:e.vertical.newScroll}},e.prototype.innerHeight=function(){return this.element==this.element.window?n.viewportHeight():this.adapter.innerHeight()},e.prototype.remove=function(t){delete this.waypoints[t.axis][t.key],this.checkEmpty()},e.prototype.innerWidth=function(){return this.element==this.element.window?n.viewportWidth():this.adapter.innerWidth()},e.prototype.destroy=function(){var t=[];for(var e in this.waypoints)for(var i in this.waypoints[e])t.push(this.waypoints[e][i]);for(var o=0,n=t.length;n>o;o++)t[o].destroy()},e.prototype.refresh=function(){var t,e=this.element==this.element.window,i=this.adapter.offset(),o={};this.handleScroll(),t={horizontal:{contextOffset:e?0:i.left,contextScroll:e?0:this.oldScroll.x,contextDimension:this.innerWidth(),oldScroll:this.oldScroll.x,forward:"right",backward:"left",offsetProp:"left"},vertical:{contextOffset:e?0:i.top,contextScroll:e?0:this.oldScroll.y,contextDimension:this.innerHeight(),oldScroll:this.oldScroll.y,forward:"down",backward:"up",offsetProp:"top"}};for(var n in t){var r=t[n];for(var s in this.waypoints[n]){var a,l,h,p,u,c=this.waypoints[n][s],d=c.options.offset,f=c.triggerPoint,w=0,y=null==f;c.element!==c.element.window&&(w=c.adapter.offset()[r.offsetProp]),"function"==typeof d?d=d.apply(c):"string"==typeof d&&(d=parseFloat(d),c.options.offset.indexOf("%")>-1&&(d=Math.ceil(r.contextDimension*d/100))),a=r.contextScroll-r.contextOffset,c.triggerPoint=w+a-d,l=f=r.oldScroll,p=l&&h,u=!l&&!h,!y&&p?(c.queueTrigger(r.backward),o[c.group.id]=c.group):!y&&u?(c.queueTrigger(r.forward),o[c.group.id]=c.group):y&&r.oldScroll>=c.triggerPoint&&(c.queueTrigger(r.forward),o[c.group.id]=c.group)}}for(var g in o)o[g].flushTriggers();return this},e.findOrCreateByElement=function(t){return e.findByElement(t)||new e(t)},e.refreshAll=function(){for(var t in o)o[t].refresh()},e.findByElement=function(t){return o[t.waypointContextKey]},window.onload=function(){r&&r(),e.refreshAll()},n.requestAnimationFrame=function(e){var i=window.requestAnimationFrame||window.mozRequestAnimationFrame||window.webkitRequestAnimationFrame||t;i.call(window,e)},n.Context=e}(),function(){"use strict";function t(t,e){return t.triggerPoint-e.triggerPoint}function e(t,e){return e.triggerPoint-t.triggerPoint}function i(t){this.name=t.name,this.axis=t.axis,this.id=this.name+"-"+this.axis,this.waypoints=[],this.clearTriggerQueues(),o[this.axis][this.name]=this}var o={vertical:{},horizontal:{}},n=window.Waypoint;i.prototype.add=function(t){this.waypoints.push(t)},i.prototype.clearTriggerQueues=function(){this.triggerQueues={up:[],down:[],left:[],right:[]}},i.prototype.flushTriggers=function(){for(var i in this.triggerQueues){var o=this.triggerQueues[i],n="up"===i||"left"===i;o.sort(n?e:t);for(var r=0,s=o.length;s>r;r+=1){var a=o[r];(a.options.continuous||r===o.length-1)&&a.trigger([i])}}this.clearTriggerQueues()},i.prototype.next=function(e){this.waypoints.sort(t);var i=n.Adapter.inArray(e,this.waypoints),o=i===this.waypoints.length-1;return o?null:this.waypoints[i+1]},i.prototype.previous=function(e){this.waypoints.sort(t);var i=n.Adapter.inArray(e,this.waypoints);return i?this.waypoints[i-1]:null},i.prototype.queueTrigger=function(t,e){this.triggerQueues[e].push(t)},i.prototype.remove=function(t){var e=n.Adapter.inArray(t,this.waypoints);e>-1&&this.waypoints.splice(e,1)},i.prototype.first=function(){return this.waypoints[0]},i.prototype.last=function(){return this.waypoints[this.waypoints.length-1]},i.findOrCreate=function(t){return o[t.axis][t.name]||new i(t)},n.Group=i}(),function(){"use strict";function t(t){this.$element=e(t)}var e=window.jQuery,i=window.Waypoint;e.each(["innerHeight","innerWidth","off","offset","on","outerHeight","outerWidth","scrollLeft","scrollTop"],function(e,i){t.prototype[i]=function(){var t=Array.prototype.slice.call(arguments);return this.$element[i].apply(this.$element,t)}}),e.each(["extend","inArray","isEmptyObject"],function(i,o){t[o]=e[o]}),i.adapters.push({name:"jquery",Adapter:t}),i.Adapter=t}(),function(){"use strict";function t(t){return function(){var i=[],o=arguments[0];return t.isFunction(arguments[0])&&(o=t.extend({},arguments[1]),o.handler=arguments[0]),this.each(function(){var n=t.extend({},o,{element:this});"string"==typeof n.context&&(n.context=t(this).closest(n.context)[0]),i.push(new e(n))}),i}}var e=window.Waypoint;window.jQuery&&(window.jQuery.fn.waypoint=t(window.jQuery)),window.Zepto&&(window.Zepto.fn.waypoint=t(window.Zepto))}(); \ No newline at end of file diff --git a/lib/noframework.waypoints.js b/lib/noframework.waypoints.js index 027cb450..431551ce 100644 --- a/lib/noframework.waypoints.js +++ b/lib/noframework.waypoints.js @@ -1,5 +1,5 @@ /*! -Waypoints - 3.1.0 +Waypoints - 3.1.1 Copyright © 2011-2015 Caleb Troughton Licensed under the MIT license. https://github.com/imakewebthings/waypoints/blog/master/licenses.txt @@ -304,9 +304,11 @@ https://github.com/imakewebthings/waypoints/blog/master/licenses.txt /* Private */ Context.prototype.innerHeight = function() { - if (this.element === this.element.window) { + /*eslint-disable eqeqeq */ + if (this.element == this.element.window) { return Waypoint.viewportHeight() } + /*eslint-enable eqeqeq */ return this.adapter.innerHeight() } @@ -318,9 +320,11 @@ https://github.com/imakewebthings/waypoints/blog/master/licenses.txt /* Private */ Context.prototype.innerWidth = function() { - if (this.element === this.element.window) { + /*eslint-disable eqeqeq */ + if (this.element == this.element.window) { return Waypoint.viewportWidth() } + /*eslint-enable eqeqeq */ return this.adapter.innerWidth() } @@ -341,7 +345,9 @@ https://github.com/imakewebthings/waypoints/blog/master/licenses.txt /* Public */ /* http://imakewebthings.com/waypoints/api/context-refresh */ Context.prototype.refresh = function() { - var isWindow = this.element === this.element.window + /*eslint-disable eqeqeq */ + var isWindow = this.element == this.element.window + /*eslint-enable eqeqeq */ var contextOffset = this.adapter.offset() var triggeredGroups = {} var axes diff --git a/lib/noframework.waypoints.min.js b/lib/noframework.waypoints.min.js index 37081970..0367c93a 100644 --- a/lib/noframework.waypoints.min.js +++ b/lib/noframework.waypoints.min.js @@ -1,7 +1,7 @@ /*! -Waypoints - 3.1.0 +Waypoints - 3.1.1 Copyright © 2011-2015 Caleb Troughton Licensed under the MIT license. https://github.com/imakewebthings/waypoints/blog/master/licenses.txt */ -!function(){"use strict";function t(n){if(!n)throw new Error("No options passed to Waypoint constructor");if(!n.element)throw new Error("No element option passed to Waypoint constructor");if(!n.handler)throw new Error("No handler option passed to Waypoint constructor");this.key="waypoint-"+e,this.options=t.Adapter.extend({},t.defaults,n),this.element=this.options.element,this.adapter=new t.Adapter(this.element),this.callback=n.handler,this.axis=this.options.horizontal?"horizontal":"vertical",this.enabled=this.options.enabled,this.triggerPoint=null,this.group=t.Group.findOrCreate({name:this.options.group,axis:this.axis}),this.context=t.Context.findOrCreateByElement(this.options.context),t.offsetAliases[this.options.offset]&&(this.options.offset=t.offsetAliases[this.options.offset]),this.group.add(this),this.context.add(this),i[this.key]=this,e+=1}var e=0,i={};t.prototype.queueTrigger=function(t){this.group.queueTrigger(this,t)},t.prototype.trigger=function(t){this.enabled&&this.callback&&this.callback.apply(this,t)},t.prototype.destroy=function(){this.context.remove(this),this.group.remove(this),delete i[this.key]},t.prototype.disable=function(){return this.enabled=!1,this},t.prototype.enable=function(){return this.context.refresh(),this.enabled=!0,this},t.prototype.next=function(){return this.group.next(this)},t.prototype.previous=function(){return this.group.previous(this)},t.invokeAll=function(t){var e=[];for(var n in i)e.push(i[n]);for(var o=0,r=e.length;r>o;o++)e[o][t]()},t.destroyAll=function(){t.invokeAll("destroy")},t.disableAll=function(){t.invokeAll("disable")},t.enableAll=function(){t.invokeAll("enable")},t.refreshAll=function(){t.Context.refreshAll()},t.viewportHeight=function(){return window.innerHeight||document.documentElement.clientHeight},t.viewportWidth=function(){return document.documentElement.clientWidth},t.adapters=[],t.defaults={context:window,continuous:!0,enabled:!0,group:"default",horizontal:!1,offset:0},t.offsetAliases={"bottom-in-view":function(){return this.context.innerHeight()-this.adapter.outerHeight()},"right-in-view":function(){return this.context.innerWidth()-this.adapter.outerWidth()}},window.Waypoint=t}(),function(){"use strict";function t(t){window.setTimeout(t,1e3/60)}function e(t){this.element=t,this.Adapter=o.Adapter,this.adapter=new this.Adapter(t),this.key="waypoint-context-"+i,this.didScroll=!1,this.didResize=!1,this.oldScroll={x:this.adapter.scrollLeft(),y:this.adapter.scrollTop()},this.waypoints={vertical:{},horizontal:{}},t.waypointContextKey=this.key,n[t.waypointContextKey]=this,i+=1,this.createThrottledScrollHandler(),this.createThrottledResizeHandler()}var i=0,n={},o=window.Waypoint,r=window.onload;e.prototype.add=function(t){var e=t.options.horizontal?"horizontal":"vertical";this.waypoints[e][t.key]=t,this.refresh()},e.prototype.checkEmpty=function(){var t=this.Adapter.isEmptyObject(this.waypoints.horizontal),e=this.Adapter.isEmptyObject(this.waypoints.vertical);t&&e&&(this.adapter.off(".waypoints"),delete n[this.key])},e.prototype.createThrottledResizeHandler=function(){function t(){e.handleResize(),e.didResize=!1}var e=this;this.adapter.on("resize.waypoints",function(){e.didResize||(e.didResize=!0,o.requestAnimationFrame(t))})},e.prototype.createThrottledScrollHandler=function(){function t(){e.handleScroll(),e.didScroll=!1}var e=this;this.adapter.on("scroll.waypoints",function(){(!e.didScroll||o.isTouch)&&(e.didScroll=!0,o.requestAnimationFrame(t))})},e.prototype.handleResize=function(){o.Context.refreshAll()},e.prototype.handleScroll=function(){var t={},e={horizontal:{newScroll:this.adapter.scrollLeft(),oldScroll:this.oldScroll.x,forward:"right",backward:"left"},vertical:{newScroll:this.adapter.scrollTop(),oldScroll:this.oldScroll.y,forward:"down",backward:"up"}};for(var i in e){var n=e[i],o=n.newScroll>n.oldScroll,r=o?n.forward:n.backward;for(var s in this.waypoints[i]){var l=this.waypoints[i][s],a=n.oldScroll=l.triggerPoint,p=a&&h,u=!a&&!h;(p||u)&&(l.queueTrigger(r),t[l.group.id]=l.group)}}for(var c in t)t[c].flushTriggers();this.oldScroll={x:e.horizontal.newScroll,y:e.vertical.newScroll}},e.prototype.innerHeight=function(){return this.element===this.element.window?o.viewportHeight():this.adapter.innerHeight()},e.prototype.remove=function(t){delete this.waypoints[t.axis][t.key],this.checkEmpty()},e.prototype.innerWidth=function(){return this.element===this.element.window?o.viewportWidth():this.adapter.innerWidth()},e.prototype.destroy=function(){var t=[];for(var e in this.waypoints)for(var i in this.waypoints[e])t.push(this.waypoints[e][i]);for(var n=0,o=t.length;o>n;n++)t[n].destroy()},e.prototype.refresh=function(){var t,e=this.element===this.element.window,i=this.adapter.offset(),n={};this.handleScroll(),t={horizontal:{contextOffset:e?0:i.left,contextScroll:e?0:this.oldScroll.x,contextDimension:this.innerWidth(),oldScroll:this.oldScroll.x,forward:"right",backward:"left",offsetProp:"left"},vertical:{contextOffset:e?0:i.top,contextScroll:e?0:this.oldScroll.y,contextDimension:this.innerHeight(),oldScroll:this.oldScroll.y,forward:"down",backward:"up",offsetProp:"top"}};for(var o in t){var r=t[o];for(var s in this.waypoints[o]){var l,a,h,p,u,c=this.waypoints[o][s],f=c.options.offset,d=c.triggerPoint,y=0,g=null==d;c.element!==c.element.window&&(y=c.adapter.offset()[r.offsetProp]),"function"==typeof f?f=f.apply(c):"string"==typeof f&&(f=parseFloat(f),c.options.offset.indexOf("%")>-1&&(f=Math.ceil(r.contextDimension*f/100))),l=r.contextScroll-r.contextOffset,c.triggerPoint=y+l-f,a=d=r.oldScroll,p=a&&h,u=!a&&!h,!g&&p?(c.queueTrigger(r.backward),n[c.group.id]=c.group):!g&&u?(c.queueTrigger(r.forward),n[c.group.id]=c.group):g&&r.oldScroll>=c.triggerPoint&&(c.queueTrigger(r.forward),n[c.group.id]=c.group)}}for(var w in n)n[w].flushTriggers();return this},e.findOrCreateByElement=function(t){return e.findByElement(t)||new e(t)},e.refreshAll=function(){for(var t in n)n[t].refresh()},e.findByElement=function(t){return n[t.waypointContextKey]},window.onload=function(){r&&r(),e.refreshAll()},o.requestAnimationFrame=function(e){var i=window.requestAnimationFrame||window.mozRequestAnimationFrame||window.webkitRequestAnimationFrame||t;i.call(window,e)},o.Context=e}(),function(){"use strict";function t(t,e){return t.triggerPoint-e.triggerPoint}function e(t,e){return e.triggerPoint-t.triggerPoint}function i(t){this.name=t.name,this.axis=t.axis,this.id=this.name+"-"+this.axis,this.waypoints=[],this.clearTriggerQueues(),n[this.axis][this.name]=this}var n={vertical:{},horizontal:{}},o=window.Waypoint;i.prototype.add=function(t){this.waypoints.push(t)},i.prototype.clearTriggerQueues=function(){this.triggerQueues={up:[],down:[],left:[],right:[]}},i.prototype.flushTriggers=function(){for(var i in this.triggerQueues){var n=this.triggerQueues[i],o="up"===i||"left"===i;n.sort(o?e:t);for(var r=0,s=n.length;s>r;r+=1){var l=n[r];(l.options.continuous||r===n.length-1)&&l.trigger([i])}}this.clearTriggerQueues()},i.prototype.next=function(e){this.waypoints.sort(t);var i=o.Adapter.inArray(e,this.waypoints),n=i===this.waypoints.length-1;return n?null:this.waypoints[i+1]},i.prototype.previous=function(e){this.waypoints.sort(t);var i=o.Adapter.inArray(e,this.waypoints);return i?this.waypoints[i-1]:null},i.prototype.queueTrigger=function(t,e){this.triggerQueues[e].push(t)},i.prototype.remove=function(t){var e=o.Adapter.inArray(t,this.waypoints);e>-1&&this.waypoints.splice(e,1)},i.prototype.first=function(){return this.waypoints[0]},i.prototype.last=function(){return this.waypoints[this.waypoints.length-1]},i.findOrCreate=function(t){return n[t.axis][t.name]||new i(t)},o.Group=i}(),function(){"use strict";function t(t){return t===t.window}function e(e){return t(e)?e:e.defaultView}function i(t){this.element=t,this.handlers={}}var n=window.Waypoint;i.prototype.innerHeight=function(){var e=t(this.element);return e?this.element.innerHeight:this.element.clientHeight},i.prototype.innerWidth=function(){var e=t(this.element);return e?this.element.innerWidth:this.element.clientWidth},i.prototype.off=function(t,e){function i(t,e,i){for(var n=0,o=e.length-1;o>n;n++){var r=e[n];i&&i!==r||t.removeEventListener(r)}}var n=t.split("."),o=n[0],r=n[1],s=this.element;if(r&&this.handlers[r]&&o)i(s,this.handlers[r][o],e),this.handlers[r][o]=[];else if(o)for(var l in this.handlers)i(s,this.handlers[l][o]||[],e),this.handlers[l][o]=[];else if(r&&this.handlers[r]){for(var a in this.handlers[r])i(s,this.handlers[r][a],e);this.handlers[r]={}}},i.prototype.offset=function(){if(!this.element.ownerDocument)return null;var t=this.element.ownerDocument.documentElement,i=e(this.element.ownerDocument),n={top:0,left:0};return this.element.getBoundingClientRect&&(n=this.element.getBoundingClientRect()),{top:n.top+i.pageYOffset-t.clientTop,left:n.left+i.pageXOffset-t.clientLeft}},i.prototype.on=function(t,e){var i=t.split("."),n=i[0],o=i[1]||"__default",r=this.handlers[o]=this.handlers[o]||{},s=r[n]=r[n]||[];s.push(e),this.element.addEventListener(n,e)},i.prototype.outerHeight=function(e){var i,n=this.innerHeight();return e&&!t(this.element)&&(i=window.getComputedStyle(this.element),n+=parseInt(i.marginTop,10),n+=parseInt(i.marginBottom,10)),n},i.prototype.outerWidth=function(e){var i,n=this.innerWidth();return e&&!t(this.element)&&(i=window.getComputedStyle(this.element),n+=parseInt(i.marginLeft,10),n+=parseInt(i.marginRight,10)),n},i.prototype.scrollLeft=function(){var t=e(this.element);return t?t.pageXOffset:this.element.scrollLeft},i.prototype.scrollTop=function(){var t=e(this.element);return t?t.pageYOffset:this.element.scrollTop},i.extend=function(){function t(t,e){if("object"==typeof t&&"object"==typeof e)for(var i in e)e.hasOwnProperty(i)&&(t[i]=e[i]);return t}for(var e=Array.prototype.slice.call(arguments),i=1,n=e.length;n>i;i++)t(e[0],e[i]);return e[0]},i.inArray=function(t,e,i){return null==e?-1:e.indexOf(t,i)},i.isEmptyObject=function(t){for(var e in t)return!1;return!0},n.adapters.push({name:"noframework",Adapter:i}),n.Adapter=i}(); \ No newline at end of file +!function(){"use strict";function t(n){if(!n)throw new Error("No options passed to Waypoint constructor");if(!n.element)throw new Error("No element option passed to Waypoint constructor");if(!n.handler)throw new Error("No handler option passed to Waypoint constructor");this.key="waypoint-"+e,this.options=t.Adapter.extend({},t.defaults,n),this.element=this.options.element,this.adapter=new t.Adapter(this.element),this.callback=n.handler,this.axis=this.options.horizontal?"horizontal":"vertical",this.enabled=this.options.enabled,this.triggerPoint=null,this.group=t.Group.findOrCreate({name:this.options.group,axis:this.axis}),this.context=t.Context.findOrCreateByElement(this.options.context),t.offsetAliases[this.options.offset]&&(this.options.offset=t.offsetAliases[this.options.offset]),this.group.add(this),this.context.add(this),i[this.key]=this,e+=1}var e=0,i={};t.prototype.queueTrigger=function(t){this.group.queueTrigger(this,t)},t.prototype.trigger=function(t){this.enabled&&this.callback&&this.callback.apply(this,t)},t.prototype.destroy=function(){this.context.remove(this),this.group.remove(this),delete i[this.key]},t.prototype.disable=function(){return this.enabled=!1,this},t.prototype.enable=function(){return this.context.refresh(),this.enabled=!0,this},t.prototype.next=function(){return this.group.next(this)},t.prototype.previous=function(){return this.group.previous(this)},t.invokeAll=function(t){var e=[];for(var n in i)e.push(i[n]);for(var o=0,r=e.length;r>o;o++)e[o][t]()},t.destroyAll=function(){t.invokeAll("destroy")},t.disableAll=function(){t.invokeAll("disable")},t.enableAll=function(){t.invokeAll("enable")},t.refreshAll=function(){t.Context.refreshAll()},t.viewportHeight=function(){return window.innerHeight||document.documentElement.clientHeight},t.viewportWidth=function(){return document.documentElement.clientWidth},t.adapters=[],t.defaults={context:window,continuous:!0,enabled:!0,group:"default",horizontal:!1,offset:0},t.offsetAliases={"bottom-in-view":function(){return this.context.innerHeight()-this.adapter.outerHeight()},"right-in-view":function(){return this.context.innerWidth()-this.adapter.outerWidth()}},window.Waypoint=t}(),function(){"use strict";function t(t){window.setTimeout(t,1e3/60)}function e(t){this.element=t,this.Adapter=o.Adapter,this.adapter=new this.Adapter(t),this.key="waypoint-context-"+i,this.didScroll=!1,this.didResize=!1,this.oldScroll={x:this.adapter.scrollLeft(),y:this.adapter.scrollTop()},this.waypoints={vertical:{},horizontal:{}},t.waypointContextKey=this.key,n[t.waypointContextKey]=this,i+=1,this.createThrottledScrollHandler(),this.createThrottledResizeHandler()}var i=0,n={},o=window.Waypoint,r=window.onload;e.prototype.add=function(t){var e=t.options.horizontal?"horizontal":"vertical";this.waypoints[e][t.key]=t,this.refresh()},e.prototype.checkEmpty=function(){var t=this.Adapter.isEmptyObject(this.waypoints.horizontal),e=this.Adapter.isEmptyObject(this.waypoints.vertical);t&&e&&(this.adapter.off(".waypoints"),delete n[this.key])},e.prototype.createThrottledResizeHandler=function(){function t(){e.handleResize(),e.didResize=!1}var e=this;this.adapter.on("resize.waypoints",function(){e.didResize||(e.didResize=!0,o.requestAnimationFrame(t))})},e.prototype.createThrottledScrollHandler=function(){function t(){e.handleScroll(),e.didScroll=!1}var e=this;this.adapter.on("scroll.waypoints",function(){(!e.didScroll||o.isTouch)&&(e.didScroll=!0,o.requestAnimationFrame(t))})},e.prototype.handleResize=function(){o.Context.refreshAll()},e.prototype.handleScroll=function(){var t={},e={horizontal:{newScroll:this.adapter.scrollLeft(),oldScroll:this.oldScroll.x,forward:"right",backward:"left"},vertical:{newScroll:this.adapter.scrollTop(),oldScroll:this.oldScroll.y,forward:"down",backward:"up"}};for(var i in e){var n=e[i],o=n.newScroll>n.oldScroll,r=o?n.forward:n.backward;for(var s in this.waypoints[i]){var l=this.waypoints[i][s],a=n.oldScroll=l.triggerPoint,p=a&&h,u=!a&&!h;(p||u)&&(l.queueTrigger(r),t[l.group.id]=l.group)}}for(var c in t)t[c].flushTriggers();this.oldScroll={x:e.horizontal.newScroll,y:e.vertical.newScroll}},e.prototype.innerHeight=function(){return this.element==this.element.window?o.viewportHeight():this.adapter.innerHeight()},e.prototype.remove=function(t){delete this.waypoints[t.axis][t.key],this.checkEmpty()},e.prototype.innerWidth=function(){return this.element==this.element.window?o.viewportWidth():this.adapter.innerWidth()},e.prototype.destroy=function(){var t=[];for(var e in this.waypoints)for(var i in this.waypoints[e])t.push(this.waypoints[e][i]);for(var n=0,o=t.length;o>n;n++)t[n].destroy()},e.prototype.refresh=function(){var t,e=this.element==this.element.window,i=this.adapter.offset(),n={};this.handleScroll(),t={horizontal:{contextOffset:e?0:i.left,contextScroll:e?0:this.oldScroll.x,contextDimension:this.innerWidth(),oldScroll:this.oldScroll.x,forward:"right",backward:"left",offsetProp:"left"},vertical:{contextOffset:e?0:i.top,contextScroll:e?0:this.oldScroll.y,contextDimension:this.innerHeight(),oldScroll:this.oldScroll.y,forward:"down",backward:"up",offsetProp:"top"}};for(var o in t){var r=t[o];for(var s in this.waypoints[o]){var l,a,h,p,u,c=this.waypoints[o][s],f=c.options.offset,d=c.triggerPoint,y=0,g=null==d;c.element!==c.element.window&&(y=c.adapter.offset()[r.offsetProp]),"function"==typeof f?f=f.apply(c):"string"==typeof f&&(f=parseFloat(f),c.options.offset.indexOf("%")>-1&&(f=Math.ceil(r.contextDimension*f/100))),l=r.contextScroll-r.contextOffset,c.triggerPoint=y+l-f,a=d=r.oldScroll,p=a&&h,u=!a&&!h,!g&&p?(c.queueTrigger(r.backward),n[c.group.id]=c.group):!g&&u?(c.queueTrigger(r.forward),n[c.group.id]=c.group):g&&r.oldScroll>=c.triggerPoint&&(c.queueTrigger(r.forward),n[c.group.id]=c.group)}}for(var w in n)n[w].flushTriggers();return this},e.findOrCreateByElement=function(t){return e.findByElement(t)||new e(t)},e.refreshAll=function(){for(var t in n)n[t].refresh()},e.findByElement=function(t){return n[t.waypointContextKey]},window.onload=function(){r&&r(),e.refreshAll()},o.requestAnimationFrame=function(e){var i=window.requestAnimationFrame||window.mozRequestAnimationFrame||window.webkitRequestAnimationFrame||t;i.call(window,e)},o.Context=e}(),function(){"use strict";function t(t,e){return t.triggerPoint-e.triggerPoint}function e(t,e){return e.triggerPoint-t.triggerPoint}function i(t){this.name=t.name,this.axis=t.axis,this.id=this.name+"-"+this.axis,this.waypoints=[],this.clearTriggerQueues(),n[this.axis][this.name]=this}var n={vertical:{},horizontal:{}},o=window.Waypoint;i.prototype.add=function(t){this.waypoints.push(t)},i.prototype.clearTriggerQueues=function(){this.triggerQueues={up:[],down:[],left:[],right:[]}},i.prototype.flushTriggers=function(){for(var i in this.triggerQueues){var n=this.triggerQueues[i],o="up"===i||"left"===i;n.sort(o?e:t);for(var r=0,s=n.length;s>r;r+=1){var l=n[r];(l.options.continuous||r===n.length-1)&&l.trigger([i])}}this.clearTriggerQueues()},i.prototype.next=function(e){this.waypoints.sort(t);var i=o.Adapter.inArray(e,this.waypoints),n=i===this.waypoints.length-1;return n?null:this.waypoints[i+1]},i.prototype.previous=function(e){this.waypoints.sort(t);var i=o.Adapter.inArray(e,this.waypoints);return i?this.waypoints[i-1]:null},i.prototype.queueTrigger=function(t,e){this.triggerQueues[e].push(t)},i.prototype.remove=function(t){var e=o.Adapter.inArray(t,this.waypoints);e>-1&&this.waypoints.splice(e,1)},i.prototype.first=function(){return this.waypoints[0]},i.prototype.last=function(){return this.waypoints[this.waypoints.length-1]},i.findOrCreate=function(t){return n[t.axis][t.name]||new i(t)},o.Group=i}(),function(){"use strict";function t(t){return t===t.window}function e(e){return t(e)?e:e.defaultView}function i(t){this.element=t,this.handlers={}}var n=window.Waypoint;i.prototype.innerHeight=function(){var e=t(this.element);return e?this.element.innerHeight:this.element.clientHeight},i.prototype.innerWidth=function(){var e=t(this.element);return e?this.element.innerWidth:this.element.clientWidth},i.prototype.off=function(t,e){function i(t,e,i){for(var n=0,o=e.length-1;o>n;n++){var r=e[n];i&&i!==r||t.removeEventListener(r)}}var n=t.split("."),o=n[0],r=n[1],s=this.element;if(r&&this.handlers[r]&&o)i(s,this.handlers[r][o],e),this.handlers[r][o]=[];else if(o)for(var l in this.handlers)i(s,this.handlers[l][o]||[],e),this.handlers[l][o]=[];else if(r&&this.handlers[r]){for(var a in this.handlers[r])i(s,this.handlers[r][a],e);this.handlers[r]={}}},i.prototype.offset=function(){if(!this.element.ownerDocument)return null;var t=this.element.ownerDocument.documentElement,i=e(this.element.ownerDocument),n={top:0,left:0};return this.element.getBoundingClientRect&&(n=this.element.getBoundingClientRect()),{top:n.top+i.pageYOffset-t.clientTop,left:n.left+i.pageXOffset-t.clientLeft}},i.prototype.on=function(t,e){var i=t.split("."),n=i[0],o=i[1]||"__default",r=this.handlers[o]=this.handlers[o]||{},s=r[n]=r[n]||[];s.push(e),this.element.addEventListener(n,e)},i.prototype.outerHeight=function(e){var i,n=this.innerHeight();return e&&!t(this.element)&&(i=window.getComputedStyle(this.element),n+=parseInt(i.marginTop,10),n+=parseInt(i.marginBottom,10)),n},i.prototype.outerWidth=function(e){var i,n=this.innerWidth();return e&&!t(this.element)&&(i=window.getComputedStyle(this.element),n+=parseInt(i.marginLeft,10),n+=parseInt(i.marginRight,10)),n},i.prototype.scrollLeft=function(){var t=e(this.element);return t?t.pageXOffset:this.element.scrollLeft},i.prototype.scrollTop=function(){var t=e(this.element);return t?t.pageYOffset:this.element.scrollTop},i.extend=function(){function t(t,e){if("object"==typeof t&&"object"==typeof e)for(var i in e)e.hasOwnProperty(i)&&(t[i]=e[i]);return t}for(var e=Array.prototype.slice.call(arguments),i=1,n=e.length;n>i;i++)t(e[0],e[i]);return e[0]},i.inArray=function(t,e,i){return null==e?-1:e.indexOf(t,i)},i.isEmptyObject=function(t){for(var e in t)return!1;return!0},n.adapters.push({name:"noframework",Adapter:i}),n.Adapter=i}(); \ No newline at end of file diff --git a/lib/shortcuts/infinite.js b/lib/shortcuts/infinite.js index 2c86cceb..72db624e 100644 --- a/lib/shortcuts/infinite.js +++ b/lib/shortcuts/infinite.js @@ -1,5 +1,5 @@ /*! -Waypoints Infinite Scroll Shortcut - 3.1.0 +Waypoints Infinite Scroll Shortcut - 3.1.1 Copyright © 2011-2015 Caleb Troughton Licensed under the MIT license. https://github.com/imakewebthings/waypoints/blog/master/licenses.txt diff --git a/lib/shortcuts/infinite.min.js b/lib/shortcuts/infinite.min.js index aca4c90f..47031158 100644 --- a/lib/shortcuts/infinite.min.js +++ b/lib/shortcuts/infinite.min.js @@ -1,5 +1,5 @@ /*! -Waypoints Infinite Scroll Shortcut - 3.1.0 +Waypoints Infinite Scroll Shortcut - 3.1.1 Copyright © 2011-2015 Caleb Troughton Licensed under the MIT license. https://github.com/imakewebthings/waypoints/blog/master/licenses.txt diff --git a/lib/shortcuts/inview.js b/lib/shortcuts/inview.js index 09948baa..3b5bedc9 100644 --- a/lib/shortcuts/inview.js +++ b/lib/shortcuts/inview.js @@ -1,5 +1,5 @@ /*! -Waypoints Inview Shortcut - 3.1.0 +Waypoints Inview Shortcut - 3.1.1 Copyright © 2011-2015 Caleb Troughton Licensed under the MIT license. https://github.com/imakewebthings/waypoints/blog/master/licenses.txt diff --git a/lib/shortcuts/inview.min.js b/lib/shortcuts/inview.min.js index 9843b2b0..41d2ea45 100644 --- a/lib/shortcuts/inview.min.js +++ b/lib/shortcuts/inview.min.js @@ -1,5 +1,5 @@ /*! -Waypoints Inview Shortcut - 3.1.0 +Waypoints Inview Shortcut - 3.1.1 Copyright © 2011-2015 Caleb Troughton Licensed under the MIT license. https://github.com/imakewebthings/waypoints/blog/master/licenses.txt diff --git a/lib/shortcuts/sticky.js b/lib/shortcuts/sticky.js index a9823833..81f0e27d 100644 --- a/lib/shortcuts/sticky.js +++ b/lib/shortcuts/sticky.js @@ -1,5 +1,5 @@ /*! -Waypoints Sticky Element Shortcut - 3.1.0 +Waypoints Sticky Element Shortcut - 3.1.1 Copyright © 2011-2015 Caleb Troughton Licensed under the MIT license. https://github.com/imakewebthings/waypoints/blog/master/licenses.txt diff --git a/lib/shortcuts/sticky.min.js b/lib/shortcuts/sticky.min.js index 0fd1ab3e..545a9c7c 100644 --- a/lib/shortcuts/sticky.min.js +++ b/lib/shortcuts/sticky.min.js @@ -1,5 +1,5 @@ /*! -Waypoints Sticky Element Shortcut - 3.1.0 +Waypoints Sticky Element Shortcut - 3.1.1 Copyright © 2011-2015 Caleb Troughton Licensed under the MIT license. https://github.com/imakewebthings/waypoints/blog/master/licenses.txt diff --git a/lib/waypoints.debug.js b/lib/waypoints.debug.js index bf117160..6e7dc8d5 100644 --- a/lib/waypoints.debug.js +++ b/lib/waypoints.debug.js @@ -1,5 +1,5 @@ /*! -Waypoints Debug - 3.1.0 +Waypoints Debug - 3.1.1 Copyright © 2011-2015 Caleb Troughton Licensed under the MIT license. https://github.com/imakewebthings/waypoints/blog/master/licenses.txt diff --git a/lib/zepto.waypoints.js b/lib/zepto.waypoints.js index f580076a..76eefbee 100644 --- a/lib/zepto.waypoints.js +++ b/lib/zepto.waypoints.js @@ -1,5 +1,5 @@ /*! -Waypoints - 3.1.0 +Waypoints - 3.1.1 Copyright © 2011-2015 Caleb Troughton Licensed under the MIT license. https://github.com/imakewebthings/waypoints/blog/master/licenses.txt @@ -304,9 +304,11 @@ https://github.com/imakewebthings/waypoints/blog/master/licenses.txt /* Private */ Context.prototype.innerHeight = function() { - if (this.element === this.element.window) { + /*eslint-disable eqeqeq */ + if (this.element == this.element.window) { return Waypoint.viewportHeight() } + /*eslint-enable eqeqeq */ return this.adapter.innerHeight() } @@ -318,9 +320,11 @@ https://github.com/imakewebthings/waypoints/blog/master/licenses.txt /* Private */ Context.prototype.innerWidth = function() { - if (this.element === this.element.window) { + /*eslint-disable eqeqeq */ + if (this.element == this.element.window) { return Waypoint.viewportWidth() } + /*eslint-enable eqeqeq */ return this.adapter.innerWidth() } @@ -341,7 +345,9 @@ https://github.com/imakewebthings/waypoints/blog/master/licenses.txt /* Public */ /* http://imakewebthings.com/waypoints/api/context-refresh */ Context.prototype.refresh = function() { - var isWindow = this.element === this.element.window + /*eslint-disable eqeqeq */ + var isWindow = this.element == this.element.window + /*eslint-enable eqeqeq */ var contextOffset = this.adapter.offset() var triggeredGroups = {} var axes diff --git a/lib/zepto.waypoints.min.js b/lib/zepto.waypoints.min.js index 97a34d61..fc8f7721 100644 --- a/lib/zepto.waypoints.min.js +++ b/lib/zepto.waypoints.min.js @@ -1,7 +1,7 @@ /*! -Waypoints - 3.1.0 +Waypoints - 3.1.1 Copyright © 2011-2015 Caleb Troughton Licensed under the MIT license. https://github.com/imakewebthings/waypoints/blog/master/licenses.txt */ -!function(){"use strict";function t(o){if(!o)throw new Error("No options passed to Waypoint constructor");if(!o.element)throw new Error("No element option passed to Waypoint constructor");if(!o.handler)throw new Error("No handler option passed to Waypoint constructor");this.key="waypoint-"+e,this.options=t.Adapter.extend({},t.defaults,o),this.element=this.options.element,this.adapter=new t.Adapter(this.element),this.callback=o.handler,this.axis=this.options.horizontal?"horizontal":"vertical",this.enabled=this.options.enabled,this.triggerPoint=null,this.group=t.Group.findOrCreate({name:this.options.group,axis:this.axis}),this.context=t.Context.findOrCreateByElement(this.options.context),t.offsetAliases[this.options.offset]&&(this.options.offset=t.offsetAliases[this.options.offset]),this.group.add(this),this.context.add(this),i[this.key]=this,e+=1}var e=0,i={};t.prototype.queueTrigger=function(t){this.group.queueTrigger(this,t)},t.prototype.trigger=function(t){this.enabled&&this.callback&&this.callback.apply(this,t)},t.prototype.destroy=function(){this.context.remove(this),this.group.remove(this),delete i[this.key]},t.prototype.disable=function(){return this.enabled=!1,this},t.prototype.enable=function(){return this.context.refresh(),this.enabled=!0,this},t.prototype.next=function(){return this.group.next(this)},t.prototype.previous=function(){return this.group.previous(this)},t.invokeAll=function(t){var e=[];for(var o in i)e.push(i[o]);for(var n=0,r=e.length;r>n;n++)e[n][t]()},t.destroyAll=function(){t.invokeAll("destroy")},t.disableAll=function(){t.invokeAll("disable")},t.enableAll=function(){t.invokeAll("enable")},t.refreshAll=function(){t.Context.refreshAll()},t.viewportHeight=function(){return window.innerHeight||document.documentElement.clientHeight},t.viewportWidth=function(){return document.documentElement.clientWidth},t.adapters=[],t.defaults={context:window,continuous:!0,enabled:!0,group:"default",horizontal:!1,offset:0},t.offsetAliases={"bottom-in-view":function(){return this.context.innerHeight()-this.adapter.outerHeight()},"right-in-view":function(){return this.context.innerWidth()-this.adapter.outerWidth()}},window.Waypoint=t}(),function(){"use strict";function t(t){window.setTimeout(t,1e3/60)}function e(t){this.element=t,this.Adapter=n.Adapter,this.adapter=new this.Adapter(t),this.key="waypoint-context-"+i,this.didScroll=!1,this.didResize=!1,this.oldScroll={x:this.adapter.scrollLeft(),y:this.adapter.scrollTop()},this.waypoints={vertical:{},horizontal:{}},t.waypointContextKey=this.key,o[t.waypointContextKey]=this,i+=1,this.createThrottledScrollHandler(),this.createThrottledResizeHandler()}var i=0,o={},n=window.Waypoint,r=window.onload;e.prototype.add=function(t){var e=t.options.horizontal?"horizontal":"vertical";this.waypoints[e][t.key]=t,this.refresh()},e.prototype.checkEmpty=function(){var t=this.Adapter.isEmptyObject(this.waypoints.horizontal),e=this.Adapter.isEmptyObject(this.waypoints.vertical);t&&e&&(this.adapter.off(".waypoints"),delete o[this.key])},e.prototype.createThrottledResizeHandler=function(){function t(){e.handleResize(),e.didResize=!1}var e=this;this.adapter.on("resize.waypoints",function(){e.didResize||(e.didResize=!0,n.requestAnimationFrame(t))})},e.prototype.createThrottledScrollHandler=function(){function t(){e.handleScroll(),e.didScroll=!1}var e=this;this.adapter.on("scroll.waypoints",function(){(!e.didScroll||n.isTouch)&&(e.didScroll=!0,n.requestAnimationFrame(t))})},e.prototype.handleResize=function(){n.Context.refreshAll()},e.prototype.handleScroll=function(){var t={},e={horizontal:{newScroll:this.adapter.scrollLeft(),oldScroll:this.oldScroll.x,forward:"right",backward:"left"},vertical:{newScroll:this.adapter.scrollTop(),oldScroll:this.oldScroll.y,forward:"down",backward:"up"}};for(var i in e){var o=e[i],n=o.newScroll>o.oldScroll,r=n?o.forward:o.backward;for(var s in this.waypoints[i]){var a=this.waypoints[i][s],l=o.oldScroll=a.triggerPoint,p=l&&h,c=!l&&!h;(p||c)&&(a.queueTrigger(r),t[a.group.id]=a.group)}}for(var u in t)t[u].flushTriggers();this.oldScroll={x:e.horizontal.newScroll,y:e.vertical.newScroll}},e.prototype.innerHeight=function(){return this.element===this.element.window?n.viewportHeight():this.adapter.innerHeight()},e.prototype.remove=function(t){delete this.waypoints[t.axis][t.key],this.checkEmpty()},e.prototype.innerWidth=function(){return this.element===this.element.window?n.viewportWidth():this.adapter.innerWidth()},e.prototype.destroy=function(){var t=[];for(var e in this.waypoints)for(var i in this.waypoints[e])t.push(this.waypoints[e][i]);for(var o=0,n=t.length;n>o;o++)t[o].destroy()},e.prototype.refresh=function(){var t,e=this.element===this.element.window,i=this.adapter.offset(),o={};this.handleScroll(),t={horizontal:{contextOffset:e?0:i.left,contextScroll:e?0:this.oldScroll.x,contextDimension:this.innerWidth(),oldScroll:this.oldScroll.x,forward:"right",backward:"left",offsetProp:"left"},vertical:{contextOffset:e?0:i.top,contextScroll:e?0:this.oldScroll.y,contextDimension:this.innerHeight(),oldScroll:this.oldScroll.y,forward:"down",backward:"up",offsetProp:"top"}};for(var n in t){var r=t[n];for(var s in this.waypoints[n]){var a,l,h,p,c,u=this.waypoints[n][s],d=u.options.offset,f=u.triggerPoint,w=0,y=null==f;u.element!==u.element.window&&(w=u.adapter.offset()[r.offsetProp]),"function"==typeof d?d=d.apply(u):"string"==typeof d&&(d=parseFloat(d),u.options.offset.indexOf("%")>-1&&(d=Math.ceil(r.contextDimension*d/100))),a=r.contextScroll-r.contextOffset,u.triggerPoint=w+a-d,l=f=r.oldScroll,p=l&&h,c=!l&&!h,!y&&p?(u.queueTrigger(r.backward),o[u.group.id]=u.group):!y&&c?(u.queueTrigger(r.forward),o[u.group.id]=u.group):y&&r.oldScroll>=u.triggerPoint&&(u.queueTrigger(r.forward),o[u.group.id]=u.group)}}for(var g in o)o[g].flushTriggers();return this},e.findOrCreateByElement=function(t){return e.findByElement(t)||new e(t)},e.refreshAll=function(){for(var t in o)o[t].refresh()},e.findByElement=function(t){return o[t.waypointContextKey]},window.onload=function(){r&&r(),e.refreshAll()},n.requestAnimationFrame=function(e){var i=window.requestAnimationFrame||window.mozRequestAnimationFrame||window.webkitRequestAnimationFrame||t;i.call(window,e)},n.Context=e}(),function(){"use strict";function t(t,e){return t.triggerPoint-e.triggerPoint}function e(t,e){return e.triggerPoint-t.triggerPoint}function i(t){this.name=t.name,this.axis=t.axis,this.id=this.name+"-"+this.axis,this.waypoints=[],this.clearTriggerQueues(),o[this.axis][this.name]=this}var o={vertical:{},horizontal:{}},n=window.Waypoint;i.prototype.add=function(t){this.waypoints.push(t)},i.prototype.clearTriggerQueues=function(){this.triggerQueues={up:[],down:[],left:[],right:[]}},i.prototype.flushTriggers=function(){for(var i in this.triggerQueues){var o=this.triggerQueues[i],n="up"===i||"left"===i;o.sort(n?e:t);for(var r=0,s=o.length;s>r;r+=1){var a=o[r];(a.options.continuous||r===o.length-1)&&a.trigger([i])}}this.clearTriggerQueues()},i.prototype.next=function(e){this.waypoints.sort(t);var i=n.Adapter.inArray(e,this.waypoints),o=i===this.waypoints.length-1;return o?null:this.waypoints[i+1]},i.prototype.previous=function(e){this.waypoints.sort(t);var i=n.Adapter.inArray(e,this.waypoints);return i?this.waypoints[i-1]:null},i.prototype.queueTrigger=function(t,e){this.triggerQueues[e].push(t)},i.prototype.remove=function(t){var e=n.Adapter.inArray(t,this.waypoints);e>-1&&this.waypoints.splice(e,1)},i.prototype.first=function(){return this.waypoints[0]},i.prototype.last=function(){return this.waypoints[this.waypoints.length-1]},i.findOrCreate=function(t){return o[t.axis][t.name]||new i(t)},n.Group=i}(),function(){"use strict";function t(t){this.element=t,this.$element=e(t)}var e=window.Zepto,i=window.Waypoint;e.each(["off","on","scrollLeft","scrollTop"],function(e,i){t.prototype[i]=function(){var t=Array.prototype.slice.call(arguments);return this.$element[i].apply(this.$element,t)}}),t.prototype.offset=function(){return this.element!==this.element.window?this.$element.offset():void 0},e.each(["width","height"],function(i,o){function n(t,i){return function(t){var n=this.$element,r=n[o](),s={width:["left","right"],height:["top","bottom"]};return e.each(s[o],function(e,o){r+=parseInt(n.css("padding-"+o),10),i&&(r+=parseInt(n.css("border-"+o+"-width"),10)),t&&(r+=parseInt(n.css("margin-"+o),10))}),r}}var r=e.camelCase("inner-"+o),s=e.camelCase("outer-"+o);t.prototype[r]=n(!1),t.prototype[s]=n(!0)}),e.each(["extend","inArray"],function(i,o){t[o]=e[o]}),t.isEmptyObject=function(t){for(var e in t)return!1;return!0},i.adapters.push({name:"zepto",Adapter:t}),i.Adapter=t}(),function(){"use strict";function t(t){return function(){var i=[],o=arguments[0];return t.isFunction(arguments[0])&&(o=t.extend({},arguments[1]),o.handler=arguments[0]),this.each(function(){var n=t.extend({},o,{element:this});"string"==typeof n.context&&(n.context=t(this).closest(n.context)[0]),i.push(new e(n))}),i}}var e=window.Waypoint;window.jQuery&&(window.jQuery.fn.waypoint=t(window.jQuery)),window.Zepto&&(window.Zepto.fn.waypoint=t(window.Zepto))}(); \ No newline at end of file +!function(){"use strict";function t(o){if(!o)throw new Error("No options passed to Waypoint constructor");if(!o.element)throw new Error("No element option passed to Waypoint constructor");if(!o.handler)throw new Error("No handler option passed to Waypoint constructor");this.key="waypoint-"+e,this.options=t.Adapter.extend({},t.defaults,o),this.element=this.options.element,this.adapter=new t.Adapter(this.element),this.callback=o.handler,this.axis=this.options.horizontal?"horizontal":"vertical",this.enabled=this.options.enabled,this.triggerPoint=null,this.group=t.Group.findOrCreate({name:this.options.group,axis:this.axis}),this.context=t.Context.findOrCreateByElement(this.options.context),t.offsetAliases[this.options.offset]&&(this.options.offset=t.offsetAliases[this.options.offset]),this.group.add(this),this.context.add(this),i[this.key]=this,e+=1}var e=0,i={};t.prototype.queueTrigger=function(t){this.group.queueTrigger(this,t)},t.prototype.trigger=function(t){this.enabled&&this.callback&&this.callback.apply(this,t)},t.prototype.destroy=function(){this.context.remove(this),this.group.remove(this),delete i[this.key]},t.prototype.disable=function(){return this.enabled=!1,this},t.prototype.enable=function(){return this.context.refresh(),this.enabled=!0,this},t.prototype.next=function(){return this.group.next(this)},t.prototype.previous=function(){return this.group.previous(this)},t.invokeAll=function(t){var e=[];for(var o in i)e.push(i[o]);for(var n=0,r=e.length;r>n;n++)e[n][t]()},t.destroyAll=function(){t.invokeAll("destroy")},t.disableAll=function(){t.invokeAll("disable")},t.enableAll=function(){t.invokeAll("enable")},t.refreshAll=function(){t.Context.refreshAll()},t.viewportHeight=function(){return window.innerHeight||document.documentElement.clientHeight},t.viewportWidth=function(){return document.documentElement.clientWidth},t.adapters=[],t.defaults={context:window,continuous:!0,enabled:!0,group:"default",horizontal:!1,offset:0},t.offsetAliases={"bottom-in-view":function(){return this.context.innerHeight()-this.adapter.outerHeight()},"right-in-view":function(){return this.context.innerWidth()-this.adapter.outerWidth()}},window.Waypoint=t}(),function(){"use strict";function t(t){window.setTimeout(t,1e3/60)}function e(t){this.element=t,this.Adapter=n.Adapter,this.adapter=new this.Adapter(t),this.key="waypoint-context-"+i,this.didScroll=!1,this.didResize=!1,this.oldScroll={x:this.adapter.scrollLeft(),y:this.adapter.scrollTop()},this.waypoints={vertical:{},horizontal:{}},t.waypointContextKey=this.key,o[t.waypointContextKey]=this,i+=1,this.createThrottledScrollHandler(),this.createThrottledResizeHandler()}var i=0,o={},n=window.Waypoint,r=window.onload;e.prototype.add=function(t){var e=t.options.horizontal?"horizontal":"vertical";this.waypoints[e][t.key]=t,this.refresh()},e.prototype.checkEmpty=function(){var t=this.Adapter.isEmptyObject(this.waypoints.horizontal),e=this.Adapter.isEmptyObject(this.waypoints.vertical);t&&e&&(this.adapter.off(".waypoints"),delete o[this.key])},e.prototype.createThrottledResizeHandler=function(){function t(){e.handleResize(),e.didResize=!1}var e=this;this.adapter.on("resize.waypoints",function(){e.didResize||(e.didResize=!0,n.requestAnimationFrame(t))})},e.prototype.createThrottledScrollHandler=function(){function t(){e.handleScroll(),e.didScroll=!1}var e=this;this.adapter.on("scroll.waypoints",function(){(!e.didScroll||n.isTouch)&&(e.didScroll=!0,n.requestAnimationFrame(t))})},e.prototype.handleResize=function(){n.Context.refreshAll()},e.prototype.handleScroll=function(){var t={},e={horizontal:{newScroll:this.adapter.scrollLeft(),oldScroll:this.oldScroll.x,forward:"right",backward:"left"},vertical:{newScroll:this.adapter.scrollTop(),oldScroll:this.oldScroll.y,forward:"down",backward:"up"}};for(var i in e){var o=e[i],n=o.newScroll>o.oldScroll,r=n?o.forward:o.backward;for(var s in this.waypoints[i]){var a=this.waypoints[i][s],l=o.oldScroll=a.triggerPoint,p=l&&h,c=!l&&!h;(p||c)&&(a.queueTrigger(r),t[a.group.id]=a.group)}}for(var u in t)t[u].flushTriggers();this.oldScroll={x:e.horizontal.newScroll,y:e.vertical.newScroll}},e.prototype.innerHeight=function(){return this.element==this.element.window?n.viewportHeight():this.adapter.innerHeight()},e.prototype.remove=function(t){delete this.waypoints[t.axis][t.key],this.checkEmpty()},e.prototype.innerWidth=function(){return this.element==this.element.window?n.viewportWidth():this.adapter.innerWidth()},e.prototype.destroy=function(){var t=[];for(var e in this.waypoints)for(var i in this.waypoints[e])t.push(this.waypoints[e][i]);for(var o=0,n=t.length;n>o;o++)t[o].destroy()},e.prototype.refresh=function(){var t,e=this.element==this.element.window,i=this.adapter.offset(),o={};this.handleScroll(),t={horizontal:{contextOffset:e?0:i.left,contextScroll:e?0:this.oldScroll.x,contextDimension:this.innerWidth(),oldScroll:this.oldScroll.x,forward:"right",backward:"left",offsetProp:"left"},vertical:{contextOffset:e?0:i.top,contextScroll:e?0:this.oldScroll.y,contextDimension:this.innerHeight(),oldScroll:this.oldScroll.y,forward:"down",backward:"up",offsetProp:"top"}};for(var n in t){var r=t[n];for(var s in this.waypoints[n]){var a,l,h,p,c,u=this.waypoints[n][s],d=u.options.offset,f=u.triggerPoint,w=0,y=null==f;u.element!==u.element.window&&(w=u.adapter.offset()[r.offsetProp]),"function"==typeof d?d=d.apply(u):"string"==typeof d&&(d=parseFloat(d),u.options.offset.indexOf("%")>-1&&(d=Math.ceil(r.contextDimension*d/100))),a=r.contextScroll-r.contextOffset,u.triggerPoint=w+a-d,l=f=r.oldScroll,p=l&&h,c=!l&&!h,!y&&p?(u.queueTrigger(r.backward),o[u.group.id]=u.group):!y&&c?(u.queueTrigger(r.forward),o[u.group.id]=u.group):y&&r.oldScroll>=u.triggerPoint&&(u.queueTrigger(r.forward),o[u.group.id]=u.group)}}for(var g in o)o[g].flushTriggers();return this},e.findOrCreateByElement=function(t){return e.findByElement(t)||new e(t)},e.refreshAll=function(){for(var t in o)o[t].refresh()},e.findByElement=function(t){return o[t.waypointContextKey]},window.onload=function(){r&&r(),e.refreshAll()},n.requestAnimationFrame=function(e){var i=window.requestAnimationFrame||window.mozRequestAnimationFrame||window.webkitRequestAnimationFrame||t;i.call(window,e)},n.Context=e}(),function(){"use strict";function t(t,e){return t.triggerPoint-e.triggerPoint}function e(t,e){return e.triggerPoint-t.triggerPoint}function i(t){this.name=t.name,this.axis=t.axis,this.id=this.name+"-"+this.axis,this.waypoints=[],this.clearTriggerQueues(),o[this.axis][this.name]=this}var o={vertical:{},horizontal:{}},n=window.Waypoint;i.prototype.add=function(t){this.waypoints.push(t)},i.prototype.clearTriggerQueues=function(){this.triggerQueues={up:[],down:[],left:[],right:[]}},i.prototype.flushTriggers=function(){for(var i in this.triggerQueues){var o=this.triggerQueues[i],n="up"===i||"left"===i;o.sort(n?e:t);for(var r=0,s=o.length;s>r;r+=1){var a=o[r];(a.options.continuous||r===o.length-1)&&a.trigger([i])}}this.clearTriggerQueues()},i.prototype.next=function(e){this.waypoints.sort(t);var i=n.Adapter.inArray(e,this.waypoints),o=i===this.waypoints.length-1;return o?null:this.waypoints[i+1]},i.prototype.previous=function(e){this.waypoints.sort(t);var i=n.Adapter.inArray(e,this.waypoints);return i?this.waypoints[i-1]:null},i.prototype.queueTrigger=function(t,e){this.triggerQueues[e].push(t)},i.prototype.remove=function(t){var e=n.Adapter.inArray(t,this.waypoints);e>-1&&this.waypoints.splice(e,1)},i.prototype.first=function(){return this.waypoints[0]},i.prototype.last=function(){return this.waypoints[this.waypoints.length-1]},i.findOrCreate=function(t){return o[t.axis][t.name]||new i(t)},n.Group=i}(),function(){"use strict";function t(t){this.element=t,this.$element=e(t)}var e=window.Zepto,i=window.Waypoint;e.each(["off","on","scrollLeft","scrollTop"],function(e,i){t.prototype[i]=function(){var t=Array.prototype.slice.call(arguments);return this.$element[i].apply(this.$element,t)}}),t.prototype.offset=function(){return this.element!==this.element.window?this.$element.offset():void 0},e.each(["width","height"],function(i,o){function n(t,i){return function(t){var n=this.$element,r=n[o](),s={width:["left","right"],height:["top","bottom"]};return e.each(s[o],function(e,o){r+=parseInt(n.css("padding-"+o),10),i&&(r+=parseInt(n.css("border-"+o+"-width"),10)),t&&(r+=parseInt(n.css("margin-"+o),10))}),r}}var r=e.camelCase("inner-"+o),s=e.camelCase("outer-"+o);t.prototype[r]=n(!1),t.prototype[s]=n(!0)}),e.each(["extend","inArray"],function(i,o){t[o]=e[o]}),t.isEmptyObject=function(t){for(var e in t)return!1;return!0},i.adapters.push({name:"zepto",Adapter:t}),i.Adapter=t}(),function(){"use strict";function t(t){return function(){var i=[],o=arguments[0];return t.isFunction(arguments[0])&&(o=t.extend({},arguments[1]),o.handler=arguments[0]),this.each(function(){var n=t.extend({},o,{element:this});"string"==typeof n.context&&(n.context=t(this).closest(n.context)[0]),i.push(new e(n))}),i}}var e=window.Waypoint;window.jQuery&&(window.jQuery.fn.waypoint=t(window.jQuery)),window.Zepto&&(window.Zepto.fn.waypoint=t(window.Zepto))}(); \ No newline at end of file diff --git a/package.json b/package.json index 1d67cb49..88270b9c 100644 --- a/package.json +++ b/package.json @@ -1,8 +1,8 @@ { - "name": "jquery-waypoints", - "version": "3.1.0", + "name": "waypoints", + "version": "3.1.1", "author": "Caleb Troughton (http://imakewebthings.com)", - "description": "A jQuery plugin that makes it easy to execute a function whenever you scroll to an element.", + "description": "Easily execute a function when you scroll to an element", "scripts": { "build": "gulp build", "start": "gulp", @@ -12,10 +12,9 @@ }, "repository": { "type": "git", - "url": "https://github.com/imakewebthings/jquery-waypoints.git" + "url": "https://github.com/imakewebthings/waypoints.git" }, "keywords": [ - "jquery", "scroll" ], "devDependencies": { diff --git a/src/context.js b/src/context.js index 42e539bc..185efae3 100644 --- a/src/context.js +++ b/src/context.js @@ -138,9 +138,11 @@ /* Private */ Context.prototype.innerHeight = function() { + /*eslint-disable eqeqeq */ if (this.element == this.element.window) { return Waypoint.viewportHeight() } + /*eslint-enable eqeqeq */ return this.adapter.innerHeight() } @@ -152,9 +154,11 @@ /* Private */ Context.prototype.innerWidth = function() { + /*eslint-disable eqeqeq */ if (this.element == this.element.window) { return Waypoint.viewportWidth() } + /*eslint-enable eqeqeq */ return this.adapter.innerWidth() } @@ -175,7 +179,9 @@ /* Public */ /* http://imakewebthings.com/waypoints/api/context-refresh */ Context.prototype.refresh = function() { + /*eslint-disable eqeqeq */ var isWindow = this.element == this.element.window + /*eslint-enable eqeqeq */ var contextOffset = this.adapter.offset() var triggeredGroups = {} var axes From 963829aba6d363b574ff5e15d11809a4bff6753c Mon Sep 17 00:00:00 2001 From: Tim Kelty Date: Mon, 16 Feb 2015 14:38:43 -0500 Subject: [PATCH 74/98] Allow for pre-existing wrapper --- src/shortcuts/sticky.js | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/shortcuts/sticky.js b/src/shortcuts/sticky.js index 17dfc2f2..14de0c9b 100644 --- a/src/shortcuts/sticky.js +++ b/src/shortcuts/sticky.js @@ -35,7 +35,9 @@ /* Private */ Sticky.prototype.createWrapper = function() { - this.$element.wrap(this.options.wrapper) + if (this.options.wrapper !== false) { + this.$element.wrap(this.options.wrapper) + } this.$wrapper = this.$element.parent() this.wrapper = this.$wrapper[0] } From 3f16647db1eb10cbf9ab001a1fed04ac56f8dac1 Mon Sep 17 00:00:00 2001 From: Tim Kelty Date: Mon, 16 Feb 2015 16:46:39 -0500 Subject: [PATCH 75/98] Update sticky.js --- src/shortcuts/sticky.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/shortcuts/sticky.js b/src/shortcuts/sticky.js index 14de0c9b..5cf03ae0 100644 --- a/src/shortcuts/sticky.js +++ b/src/shortcuts/sticky.js @@ -35,7 +35,7 @@ /* Private */ Sticky.prototype.createWrapper = function() { - if (this.options.wrapper !== false) { + if (this.options.wrapper) { this.$element.wrap(this.options.wrapper) } this.$wrapper = this.$element.parent() From 63148e32db10dbdd77d657a8c93b9a0cd7529fd5 Mon Sep 17 00:00:00 2001 From: Oskar Rough Mosumgaard Date: Wed, 18 Feb 2015 17:58:37 +0100 Subject: [PATCH 76/98] Update bower to include the non-minified version See See https://github.com/bower/bower.json-spec#main --- bower.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/bower.json b/bower.json index 348993c3..3a1e9462 100644 --- a/bower.json +++ b/bower.json @@ -1,7 +1,7 @@ { "name": "waypoints", "version": "3.1.1", - "main": "lib/noframework.waypoints.min.js", + "main": "lib/noframework.waypoints.js", "description": "Easily execute a function when you scroll to an element.", "ignore": [ "gulpfile.js", From b7c9276b3ff5ce1af90c11a429d8a2380274a419 Mon Sep 17 00:00:00 2001 From: Christoph Hochstrasser Date: Wed, 8 Apr 2015 11:48:59 +0200 Subject: [PATCH 77/98] Pass items to onAfterPageLoad When using masonry or isotope it's necessary to know the items which have to be relayouted. This change passes the items that were extracted of the response to the `onAfterPageLoad` callback. Using that, efficient relayouting can be accomplished by using isotope's `appended` method with the passed items. --- src/shortcuts/infinite.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/shortcuts/infinite.js b/src/shortcuts/infinite.js index ddebefd3..a904dabc 100644 --- a/src/shortcuts/infinite.js +++ b/src/shortcuts/infinite.js @@ -51,7 +51,7 @@ this.$more.remove() } - this.options.onAfterPageLoad() + this.options.onAfterPageLoad($items) }, this)) }, this) } From 2ecfb753a781ceb7c7385df1daf7fe0c3b87d113 Mon Sep 17 00:00:00 2001 From: Christoph Hochstrasser Date: Fri, 17 Apr 2015 14:40:40 +0200 Subject: [PATCH 78/98] Add testcase, run gulp --- lib/shortcuts/infinite.js | 2 +- lib/shortcuts/infinite.min.js | 2 +- test/infinite-spec.js | 2 ++ 3 files changed, 4 insertions(+), 2 deletions(-) diff --git a/lib/shortcuts/infinite.js b/lib/shortcuts/infinite.js index 72db624e..9d136711 100644 --- a/lib/shortcuts/infinite.js +++ b/lib/shortcuts/infinite.js @@ -57,7 +57,7 @@ https://github.com/imakewebthings/waypoints/blog/master/licenses.txt this.$more.remove() } - this.options.onAfterPageLoad() + this.options.onAfterPageLoad($items) }, this)) }, this) } diff --git a/lib/shortcuts/infinite.min.js b/lib/shortcuts/infinite.min.js index 47031158..015d7679 100644 --- a/lib/shortcuts/infinite.min.js +++ b/lib/shortcuts/infinite.min.js @@ -4,4 +4,4 @@ Copyright © 2011-2015 Caleb Troughton Licensed under the MIT license. https://github.com/imakewebthings/waypoints/blog/master/licenses.txt */ -!function(){"use strict";function t(n){this.options=i.extend({},t.defaults,n),this.container=this.options.element,"auto"!==this.options.container&&(this.container=this.options.container),this.$container=i(this.container),this.$more=i(this.options.more),this.$more.length&&(this.setupHandler(),this.waypoint=new o(this.options))}var i=window.jQuery,o=window.Waypoint;t.prototype.setupHandler=function(){this.options.handler=i.proxy(function(){this.options.onBeforePageLoad(),this.destroy(),this.$container.addClass(this.options.loadingClass),i.get(i(this.options.more).attr("href"),i.proxy(function(t){var n=i(i.parseHTML(t)),e=n.find(this.options.more),s=n.find(this.options.items);s.length||(s=n.filter(this.options.items)),this.$container.append(s),this.$container.removeClass(this.options.loadingClass),e.length||(e=n.filter(this.options.more)),e.length?(this.$more.replaceWith(e),this.$more=e,this.waypoint=new o(this.options)):this.$more.remove(),this.options.onAfterPageLoad()},this))},this)},t.prototype.destroy=function(){this.waypoint&&this.waypoint.destroy()},t.defaults={container:"auto",items:".infinite-item",more:".infinite-more-link",offset:"bottom-in-view",loadingClass:"infinite-loading",onBeforePageLoad:i.noop,onAfterPageLoad:i.noop},o.Infinite=t}(); \ No newline at end of file +!function(){"use strict";function t(n){this.options=i.extend({},t.defaults,n),this.container=this.options.element,"auto"!==this.options.container&&(this.container=this.options.container),this.$container=i(this.container),this.$more=i(this.options.more),this.$more.length&&(this.setupHandler(),this.waypoint=new o(this.options))}var i=window.jQuery,o=window.Waypoint;t.prototype.setupHandler=function(){this.options.handler=i.proxy(function(){this.options.onBeforePageLoad(),this.destroy(),this.$container.addClass(this.options.loadingClass),i.get(i(this.options.more).attr("href"),i.proxy(function(t){var n=i(i.parseHTML(t)),e=n.find(this.options.more),s=n.find(this.options.items);s.length||(s=n.filter(this.options.items)),this.$container.append(s),this.$container.removeClass(this.options.loadingClass),e.length||(e=n.filter(this.options.more)),e.length?(this.$more.replaceWith(e),this.$more=e,this.waypoint=new o(this.options)):this.$more.remove(),this.options.onAfterPageLoad(s)},this))},this)},t.prototype.destroy=function(){this.waypoint&&this.waypoint.destroy()},t.defaults={container:"auto",items:".infinite-item",more:".infinite-more-link",offset:"bottom-in-view",loadingClass:"infinite-loading",onBeforePageLoad:i.noop,onAfterPageLoad:i.noop},o.Infinite=t}(); \ No newline at end of file diff --git a/test/infinite-spec.js b/test/infinite-spec.js index 0571e674..5c54208d 100644 --- a/test/infinite-spec.js +++ b/test/infinite-spec.js @@ -55,6 +55,8 @@ describe('Waypoint Sticky Shortcut', function() { it('fires the after callback', function() { expect(afterSpy.callCount).toBeTruthy() + expect(afterSpy.mostRecentCall.args.length).toEqual(1); + expect(afterSpy).toHaveBeenCalledWith(jasmine.any(Object)) }) }) From feef32ee75a85cf2821a14b61853f3d9bfbbf91c Mon Sep 17 00:00:00 2001 From: Lukas Appelhans Date: Wed, 13 May 2015 23:37:44 +0200 Subject: [PATCH 79/98] Give enable/disable functions and enabled property to waypoints --- lib/shortcuts/inview.js | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) diff --git a/lib/shortcuts/inview.js b/lib/shortcuts/inview.js index 3b5bedc9..78f1e7ac 100644 --- a/lib/shortcuts/inview.js +++ b/lib/shortcuts/inview.js @@ -79,7 +79,8 @@ https://github.com/imakewebthings/waypoints/blog/master/licenses.txt } }(config)), offset: config.offset, - horizontal: this.options.horizontal + horizontal: this.options.horizontal, + enabled: this.options.enabled })) } @@ -90,6 +91,18 @@ https://github.com/imakewebthings/waypoints/blog/master/licenses.txt } this.waypoints = [] } + + Inview.prototype.disable = function() { + for (var i = 0, end = this.waypoints.length; i < end; i++) { + this.waypoints[i].disable() + } + } + + Inview.prototype.enable = function() { + for (var i = 0, end = this.waypoints.length; i < end; i++) { + this.waypoints[i].enable() + } + } Inview.defaults = { enter: noop, From c92423268898f06b6abc50068274d9d35a746697 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mart=C3=ADn=20Gonz=C3=A1lez?= Date: Thu, 14 May 2015 00:01:57 +0200 Subject: [PATCH 80/98] minify inview --- lib/shortcuts/inview.min.js | 8 +------- 1 file changed, 1 insertion(+), 7 deletions(-) diff --git a/lib/shortcuts/inview.min.js b/lib/shortcuts/inview.min.js index 41d2ea45..aad0f34c 100644 --- a/lib/shortcuts/inview.min.js +++ b/lib/shortcuts/inview.min.js @@ -1,7 +1 @@ -/*! -Waypoints Inview Shortcut - 3.1.1 -Copyright © 2011-2015 Caleb Troughton -Licensed under the MIT license. -https://github.com/imakewebthings/waypoints/blog/master/licenses.txt -*/ -!function(){"use strict";function t(){}function e(t){this.options=i.Adapter.extend({},e.defaults,t),this.axis=this.options.horizontal?"horizontal":"vertical",this.waypoints=[],this.createWaypoints()}var i=window.Waypoint;e.prototype.createWaypoints=function(){for(var t={vertical:[{down:"enter",up:"exited",offset:"100%"},{down:"entered",up:"exit",offset:"bottom-in-view"},{down:"exit",up:"entered",offset:0},{down:"exited",up:"enter",offset:function(){return-this.adapter.outerHeight()}}],horizontal:[{right:"enter",left:"exited",offset:"100%"},{right:"entered",left:"exit",offset:"right-in-view"},{right:"exit",left:"entered",offset:0},{right:"exited",left:"enter",offset:function(){return-this.adapter.outerWidth()}}]},e=0,i=t[this.axis].length;i>e;e++){var o=t[this.axis][e];this.createWaypoint(o)}},e.prototype.createWaypoint=function(t){var e=this;this.waypoints.push(new i({element:this.options.element,handler:function(t){return function(i){e.options[t[i]].call(this,i)}}(t),offset:t.offset,horizontal:this.options.horizontal}))},e.prototype.destroy=function(){for(var t=0,e=this.waypoints.length;e>t;t++)this.waypoints[t].destroy();this.waypoints=[]},e.defaults={enter:t,entered:t,exit:t,exited:t},i.Inview=e}(); \ No newline at end of file +!function(){"use strict";function t(){}function e(t){this.options=i.Adapter.extend({},e.defaults,t),this.axis=this.options.horizontal?"horizontal":"vertical",this.waypoints=[],this.createWaypoints()}var i=window.Waypoint;e.prototype.createWaypoints=function(){for(var t={vertical:[{down:"enter",up:"exited",offset:"100%"},{down:"entered",up:"exit",offset:"bottom-in-view"},{down:"exit",up:"entered",offset:0},{down:"exited",up:"enter",offset:function(){return-this.adapter.outerHeight()}}],horizontal:[{right:"enter",left:"exited",offset:"100%"},{right:"entered",left:"exit",offset:"right-in-view"},{right:"exit",left:"entered",offset:0},{right:"exited",left:"enter",offset:function(){return-this.adapter.outerWidth()}}]},e=0,i=t[this.axis].length;i>e;e++){var n=t[this.axis][e];this.createWaypoint(n)}},e.prototype.createWaypoint=function(t){var e=this;this.waypoints.push(new i({element:this.options.element,handler:function(t){return function(i){e.options[t[i]].call(this,i)}}(t),offset:t.offset,horizontal:this.options.horizontal,enabled:this.options.enabled}))},e.prototype.destroy=function(){for(var t=0,e=this.waypoints.length;e>t;t++)this.waypoints[t].destroy();this.waypoints=[]},e.prototype.disable=function(){for(var t=0,e=this.waypoints.length;e>t;t++)this.waypoints[t].disable()},e.prototype.enable=function(){for(var t=0,e=this.waypoints.length;e>t;t++)this.waypoints[t].enable()},e.defaults={enter:t,entered:t,exit:t,exited:t},i.Inview=e}(); From b6ac4994811d58923d75b8ba30646ce26fdd9eec Mon Sep 17 00:00:00 2001 From: Kevin Kirsche Date: Wed, 10 Jun 2015 18:58:48 -0400 Subject: [PATCH 81/98] Remove moot `version` property from bower.json Per bower/bower.json-spec@a325da3 --- bower.json | 1 - 1 file changed, 1 deletion(-) diff --git a/bower.json b/bower.json index 3a1e9462..01f3cde6 100644 --- a/bower.json +++ b/bower.json @@ -1,6 +1,5 @@ { "name": "waypoints", - "version": "3.1.1", "main": "lib/noframework.waypoints.js", "description": "Easily execute a function when you scroll to an element.", "ignore": [ From 3762d4cc6c19d2f733f017dc2f6115e4129a9cbc Mon Sep 17 00:00:00 2001 From: Brent Dearth Date: Thu, 16 Jul 2015 15:18:29 -0400 Subject: [PATCH 82/98] Account for breaking change in jQuery 3 offset() --- src/context.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/context.js b/src/context.js index 185efae3..f3e13a3e 100644 --- a/src/context.js +++ b/src/context.js @@ -182,7 +182,7 @@ /*eslint-disable eqeqeq */ var isWindow = this.element == this.element.window /*eslint-enable eqeqeq */ - var contextOffset = this.adapter.offset() + var contextOffset = isWindow ? undefined : this.adapter.offset() var triggeredGroups = {} var axes From 720217ffe27642f78ef26b94929b151dc6694168 Mon Sep 17 00:00:00 2001 From: imakewebthings Date: Mon, 17 Aug 2015 21:34:08 -0700 Subject: [PATCH 83/98] Only unwrap sticky element on destroy if wrapper option is truthy --- src/shortcuts/sticky.js | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/src/shortcuts/sticky.js b/src/shortcuts/sticky.js index 5cf03ae0..7dc7054a 100644 --- a/src/shortcuts/sticky.js +++ b/src/shortcuts/sticky.js @@ -46,7 +46,10 @@ Sticky.prototype.destroy = function() { if (this.$element.parent()[0] === this.wrapper) { this.waypoint.destroy() - this.$element.removeClass(this.options.stuckClass).unwrap() + this.$element.removeClass(this.options.stuckClass) + if (this.options.wrapper) { + this.$element.unwrap() + } } } From f8f4865e4877315c825c96ebe8f74ceaef29ac1f Mon Sep 17 00:00:00 2001 From: imakewebthings Date: Mon, 17 Aug 2015 21:43:32 -0700 Subject: [PATCH 84/98] Test wrapper false sticky addition --- test/sticky-spec.js | 113 +++++++++++++++++++++++++++----------------- 1 file changed, 69 insertions(+), 44 deletions(-) diff --git a/test/sticky-spec.js b/test/sticky-spec.js index 447b8eee..b6128a0b 100644 --- a/test/sticky-spec.js +++ b/test/sticky-spec.js @@ -12,81 +12,106 @@ describe('Waypoint Sticky Shortcut', function() { beforeEach(function() { loadFixtures('sticky.html') $sticky = $('.sticky') - handlerSpy = jasmine.createSpy('on handler') - waypoint = new Waypoint.Sticky({ - element: $sticky[0], - handler: handlerSpy - }) }) - afterEach(function() { - if (waypoint) { - waypoint.destroy() - } - $scroller.scrollTop(0) - }) + describe('with default options', function() { + beforeEach(function() { + handlerSpy = jasmine.createSpy('on handler') + waypoint = new Waypoint.Sticky({ + element: $sticky[0], + handler: handlerSpy + }) + }) - describe('on init', function() { afterEach(function() { - waypoint.destroy() + if (waypoint) { + waypoint.destroy() + } + $scroller.scrollTop(0) }) - it('returns an instance of the Waypoint.Sticky class', function() { - expect(waypoint instanceof Waypoint.Sticky).toBeTruthy() - }) + describe('on init', function() { + afterEach(function() { + waypoint.destroy() + }) + + it('returns an instance of the Waypoint.Sticky class', function() { + expect(waypoint instanceof Waypoint.Sticky).toBeTruthy() + }) + + it('wraps the sticky element on init', function() { + expect($sticky.parent()).toHaveClass('sticky-wrapper') + }) + + describe('when sticky element is scrolled to', function() { + beforeEach(function() { + runs(function() { + $scroller.scrollTop($sticky.offset().top) + }) + waitsFor(function() { + return $sticky.hasClass('stuck') + }, 'stuck class to apply') + }) + + it('adds/removes stuck class', function() { + runs(function() { + $scroller.scrollTop($scroller.scrollTop() - 1) + }) + waitsFor(function() { + return !$sticky.hasClass('stuck') + }) + }) + + it('gives the wrapper the same height as the sticky element', function() { + expect($sticky.parent().height()).toEqual($sticky.outerHeight()) + }) - it('wraps the sticky element on init', function() { - expect($sticky.parent()).toHaveClass('sticky-wrapper') + it('executes handler option after stuck class applied', function() { + expect(handlerSpy).toHaveBeenCalled() + }) + }) }) - describe('when sticky element is scrolled to', function() { + describe('#destroy', function() { beforeEach(function() { runs(function() { $scroller.scrollTop($sticky.offset().top) }) waitsFor(function() { - return $sticky.hasClass('stuck') - }, 'stuck class to apply') - }) - - it('adds/removes stuck class', function() { - runs(function() { - $scroller.scrollTop($scroller.scrollTop() - 1) + return handlerSpy.callCount }) - waitsFor(function() { - return !$sticky.hasClass('stuck') + runs(function() { + waypoint.destroy() }) }) - it('gives the wrapper the same height as the sticky element', function() { - expect($sticky.parent().height()).toEqual($sticky.outerHeight()) + it('unwraps the sticky element', function() { + expect($sticky.parent()).not.toHaveClass('sticky-wrapper') }) - it('executes handler option after stuck class applied', function() { - expect(handlerSpy).toHaveBeenCalled() + it('removes the stuck class', function() { + expect($sticky).not.toHaveClass('stuck') }) }) }) - describe('#destroy', function() { + describe('with wrapper false', function() { beforeEach(function() { - runs(function() { - $scroller.scrollTop($sticky.offset().top) - }) - waitsFor(function() { - return handlerSpy.callCount - }) - runs(function() { - waypoint.destroy() + waypoint = new Waypoint.Sticky({ + element: $sticky[0], + handler: handlerSpy, + wrapper: false }) }) - it('unwraps the sticky element', function() { + it('does not wrap the sticky element', function() { expect($sticky.parent()).not.toHaveClass('sticky-wrapper') }) - it('removes the stuck class', function() { - expect($sticky).not.toHaveClass('stuck') + it('does not unwrap on destroy', function() { + var parent = waypoint.wrapper + waypoint.destroy() + expect(parent).toBe(waypoint.wrapper) }) }) }) From 6207df2b76ba608a2fcdead1429465d1f04474d4 Mon Sep 17 00:00:00 2001 From: imakewebthings Date: Mon, 17 Aug 2015 21:50:02 -0700 Subject: [PATCH 85/98] Run fresh waypoint triggers on next animation frame, fixes #384 --- CHANGELOG.md | 4 ++++ lib/jquery.waypoints.js | 8 +++++--- lib/jquery.waypoints.min.js | 2 +- lib/noframework.waypoints.js | 8 +++++--- lib/noframework.waypoints.min.js | 2 +- lib/shortcuts/sticky.js | 9 +++++++-- lib/shortcuts/sticky.min.js | 2 +- lib/zepto.waypoints.js | 8 +++++--- lib/zepto.waypoints.min.js | 2 +- src/context.js | 8 +++++--- 10 files changed, 35 insertions(+), 18 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index d9a7918b..b90b9c81 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,9 @@ # Changelog +## v4.0.0 + +- Allow Sticky option `wrapper` to accept false, which will not create a wrapper and instead use the preexisting parent element. (Pull #416) + ## v3.1.1 - Fix bad `isWindow` checks causing errors in IE8-. (Issue #372) diff --git a/lib/jquery.waypoints.js b/lib/jquery.waypoints.js index 536d5d48..27d39b22 100644 --- a/lib/jquery.waypoints.js +++ b/lib/jquery.waypoints.js @@ -421,9 +421,11 @@ https://github.com/imakewebthings/waypoints/blog/master/licenses.txt } } - for (var groupKey in triggeredGroups) { - triggeredGroups[groupKey].flushTriggers() - } + Waypoint.requestAnimationFrame(function() { + for (var groupKey in triggeredGroups) { + triggeredGroups[groupKey].flushTriggers() + } + }) return this } diff --git a/lib/jquery.waypoints.min.js b/lib/jquery.waypoints.min.js index 44a1d323..fc8e2885 100644 --- a/lib/jquery.waypoints.min.js +++ b/lib/jquery.waypoints.min.js @@ -4,4 +4,4 @@ Copyright © 2011-2015 Caleb Troughton Licensed under the MIT license. https://github.com/imakewebthings/waypoints/blog/master/licenses.txt */ -!function(){"use strict";function t(o){if(!o)throw new Error("No options passed to Waypoint constructor");if(!o.element)throw new Error("No element option passed to Waypoint constructor");if(!o.handler)throw new Error("No handler option passed to Waypoint constructor");this.key="waypoint-"+e,this.options=t.Adapter.extend({},t.defaults,o),this.element=this.options.element,this.adapter=new t.Adapter(this.element),this.callback=o.handler,this.axis=this.options.horizontal?"horizontal":"vertical",this.enabled=this.options.enabled,this.triggerPoint=null,this.group=t.Group.findOrCreate({name:this.options.group,axis:this.axis}),this.context=t.Context.findOrCreateByElement(this.options.context),t.offsetAliases[this.options.offset]&&(this.options.offset=t.offsetAliases[this.options.offset]),this.group.add(this),this.context.add(this),i[this.key]=this,e+=1}var e=0,i={};t.prototype.queueTrigger=function(t){this.group.queueTrigger(this,t)},t.prototype.trigger=function(t){this.enabled&&this.callback&&this.callback.apply(this,t)},t.prototype.destroy=function(){this.context.remove(this),this.group.remove(this),delete i[this.key]},t.prototype.disable=function(){return this.enabled=!1,this},t.prototype.enable=function(){return this.context.refresh(),this.enabled=!0,this},t.prototype.next=function(){return this.group.next(this)},t.prototype.previous=function(){return this.group.previous(this)},t.invokeAll=function(t){var e=[];for(var o in i)e.push(i[o]);for(var n=0,r=e.length;r>n;n++)e[n][t]()},t.destroyAll=function(){t.invokeAll("destroy")},t.disableAll=function(){t.invokeAll("disable")},t.enableAll=function(){t.invokeAll("enable")},t.refreshAll=function(){t.Context.refreshAll()},t.viewportHeight=function(){return window.innerHeight||document.documentElement.clientHeight},t.viewportWidth=function(){return document.documentElement.clientWidth},t.adapters=[],t.defaults={context:window,continuous:!0,enabled:!0,group:"default",horizontal:!1,offset:0},t.offsetAliases={"bottom-in-view":function(){return this.context.innerHeight()-this.adapter.outerHeight()},"right-in-view":function(){return this.context.innerWidth()-this.adapter.outerWidth()}},window.Waypoint=t}(),function(){"use strict";function t(t){window.setTimeout(t,1e3/60)}function e(t){this.element=t,this.Adapter=n.Adapter,this.adapter=new this.Adapter(t),this.key="waypoint-context-"+i,this.didScroll=!1,this.didResize=!1,this.oldScroll={x:this.adapter.scrollLeft(),y:this.adapter.scrollTop()},this.waypoints={vertical:{},horizontal:{}},t.waypointContextKey=this.key,o[t.waypointContextKey]=this,i+=1,this.createThrottledScrollHandler(),this.createThrottledResizeHandler()}var i=0,o={},n=window.Waypoint,r=window.onload;e.prototype.add=function(t){var e=t.options.horizontal?"horizontal":"vertical";this.waypoints[e][t.key]=t,this.refresh()},e.prototype.checkEmpty=function(){var t=this.Adapter.isEmptyObject(this.waypoints.horizontal),e=this.Adapter.isEmptyObject(this.waypoints.vertical);t&&e&&(this.adapter.off(".waypoints"),delete o[this.key])},e.prototype.createThrottledResizeHandler=function(){function t(){e.handleResize(),e.didResize=!1}var e=this;this.adapter.on("resize.waypoints",function(){e.didResize||(e.didResize=!0,n.requestAnimationFrame(t))})},e.prototype.createThrottledScrollHandler=function(){function t(){e.handleScroll(),e.didScroll=!1}var e=this;this.adapter.on("scroll.waypoints",function(){(!e.didScroll||n.isTouch)&&(e.didScroll=!0,n.requestAnimationFrame(t))})},e.prototype.handleResize=function(){n.Context.refreshAll()},e.prototype.handleScroll=function(){var t={},e={horizontal:{newScroll:this.adapter.scrollLeft(),oldScroll:this.oldScroll.x,forward:"right",backward:"left"},vertical:{newScroll:this.adapter.scrollTop(),oldScroll:this.oldScroll.y,forward:"down",backward:"up"}};for(var i in e){var o=e[i],n=o.newScroll>o.oldScroll,r=n?o.forward:o.backward;for(var s in this.waypoints[i]){var a=this.waypoints[i][s],l=o.oldScroll=a.triggerPoint,p=l&&h,u=!l&&!h;(p||u)&&(a.queueTrigger(r),t[a.group.id]=a.group)}}for(var c in t)t[c].flushTriggers();this.oldScroll={x:e.horizontal.newScroll,y:e.vertical.newScroll}},e.prototype.innerHeight=function(){return this.element==this.element.window?n.viewportHeight():this.adapter.innerHeight()},e.prototype.remove=function(t){delete this.waypoints[t.axis][t.key],this.checkEmpty()},e.prototype.innerWidth=function(){return this.element==this.element.window?n.viewportWidth():this.adapter.innerWidth()},e.prototype.destroy=function(){var t=[];for(var e in this.waypoints)for(var i in this.waypoints[e])t.push(this.waypoints[e][i]);for(var o=0,n=t.length;n>o;o++)t[o].destroy()},e.prototype.refresh=function(){var t,e=this.element==this.element.window,i=this.adapter.offset(),o={};this.handleScroll(),t={horizontal:{contextOffset:e?0:i.left,contextScroll:e?0:this.oldScroll.x,contextDimension:this.innerWidth(),oldScroll:this.oldScroll.x,forward:"right",backward:"left",offsetProp:"left"},vertical:{contextOffset:e?0:i.top,contextScroll:e?0:this.oldScroll.y,contextDimension:this.innerHeight(),oldScroll:this.oldScroll.y,forward:"down",backward:"up",offsetProp:"top"}};for(var n in t){var r=t[n];for(var s in this.waypoints[n]){var a,l,h,p,u,c=this.waypoints[n][s],d=c.options.offset,f=c.triggerPoint,w=0,y=null==f;c.element!==c.element.window&&(w=c.adapter.offset()[r.offsetProp]),"function"==typeof d?d=d.apply(c):"string"==typeof d&&(d=parseFloat(d),c.options.offset.indexOf("%")>-1&&(d=Math.ceil(r.contextDimension*d/100))),a=r.contextScroll-r.contextOffset,c.triggerPoint=w+a-d,l=f=r.oldScroll,p=l&&h,u=!l&&!h,!y&&p?(c.queueTrigger(r.backward),o[c.group.id]=c.group):!y&&u?(c.queueTrigger(r.forward),o[c.group.id]=c.group):y&&r.oldScroll>=c.triggerPoint&&(c.queueTrigger(r.forward),o[c.group.id]=c.group)}}for(var g in o)o[g].flushTriggers();return this},e.findOrCreateByElement=function(t){return e.findByElement(t)||new e(t)},e.refreshAll=function(){for(var t in o)o[t].refresh()},e.findByElement=function(t){return o[t.waypointContextKey]},window.onload=function(){r&&r(),e.refreshAll()},n.requestAnimationFrame=function(e){var i=window.requestAnimationFrame||window.mozRequestAnimationFrame||window.webkitRequestAnimationFrame||t;i.call(window,e)},n.Context=e}(),function(){"use strict";function t(t,e){return t.triggerPoint-e.triggerPoint}function e(t,e){return e.triggerPoint-t.triggerPoint}function i(t){this.name=t.name,this.axis=t.axis,this.id=this.name+"-"+this.axis,this.waypoints=[],this.clearTriggerQueues(),o[this.axis][this.name]=this}var o={vertical:{},horizontal:{}},n=window.Waypoint;i.prototype.add=function(t){this.waypoints.push(t)},i.prototype.clearTriggerQueues=function(){this.triggerQueues={up:[],down:[],left:[],right:[]}},i.prototype.flushTriggers=function(){for(var i in this.triggerQueues){var o=this.triggerQueues[i],n="up"===i||"left"===i;o.sort(n?e:t);for(var r=0,s=o.length;s>r;r+=1){var a=o[r];(a.options.continuous||r===o.length-1)&&a.trigger([i])}}this.clearTriggerQueues()},i.prototype.next=function(e){this.waypoints.sort(t);var i=n.Adapter.inArray(e,this.waypoints),o=i===this.waypoints.length-1;return o?null:this.waypoints[i+1]},i.prototype.previous=function(e){this.waypoints.sort(t);var i=n.Adapter.inArray(e,this.waypoints);return i?this.waypoints[i-1]:null},i.prototype.queueTrigger=function(t,e){this.triggerQueues[e].push(t)},i.prototype.remove=function(t){var e=n.Adapter.inArray(t,this.waypoints);e>-1&&this.waypoints.splice(e,1)},i.prototype.first=function(){return this.waypoints[0]},i.prototype.last=function(){return this.waypoints[this.waypoints.length-1]},i.findOrCreate=function(t){return o[t.axis][t.name]||new i(t)},n.Group=i}(),function(){"use strict";function t(t){this.$element=e(t)}var e=window.jQuery,i=window.Waypoint;e.each(["innerHeight","innerWidth","off","offset","on","outerHeight","outerWidth","scrollLeft","scrollTop"],function(e,i){t.prototype[i]=function(){var t=Array.prototype.slice.call(arguments);return this.$element[i].apply(this.$element,t)}}),e.each(["extend","inArray","isEmptyObject"],function(i,o){t[o]=e[o]}),i.adapters.push({name:"jquery",Adapter:t}),i.Adapter=t}(),function(){"use strict";function t(t){return function(){var i=[],o=arguments[0];return t.isFunction(arguments[0])&&(o=t.extend({},arguments[1]),o.handler=arguments[0]),this.each(function(){var n=t.extend({},o,{element:this});"string"==typeof n.context&&(n.context=t(this).closest(n.context)[0]),i.push(new e(n))}),i}}var e=window.Waypoint;window.jQuery&&(window.jQuery.fn.waypoint=t(window.jQuery)),window.Zepto&&(window.Zepto.fn.waypoint=t(window.Zepto))}(); \ No newline at end of file +!function(){"use strict";function t(o){if(!o)throw new Error("No options passed to Waypoint constructor");if(!o.element)throw new Error("No element option passed to Waypoint constructor");if(!o.handler)throw new Error("No handler option passed to Waypoint constructor");this.key="waypoint-"+e,this.options=t.Adapter.extend({},t.defaults,o),this.element=this.options.element,this.adapter=new t.Adapter(this.element),this.callback=o.handler,this.axis=this.options.horizontal?"horizontal":"vertical",this.enabled=this.options.enabled,this.triggerPoint=null,this.group=t.Group.findOrCreate({name:this.options.group,axis:this.axis}),this.context=t.Context.findOrCreateByElement(this.options.context),t.offsetAliases[this.options.offset]&&(this.options.offset=t.offsetAliases[this.options.offset]),this.group.add(this),this.context.add(this),i[this.key]=this,e+=1}var e=0,i={};t.prototype.queueTrigger=function(t){this.group.queueTrigger(this,t)},t.prototype.trigger=function(t){this.enabled&&this.callback&&this.callback.apply(this,t)},t.prototype.destroy=function(){this.context.remove(this),this.group.remove(this),delete i[this.key]},t.prototype.disable=function(){return this.enabled=!1,this},t.prototype.enable=function(){return this.context.refresh(),this.enabled=!0,this},t.prototype.next=function(){return this.group.next(this)},t.prototype.previous=function(){return this.group.previous(this)},t.invokeAll=function(t){var e=[];for(var o in i)e.push(i[o]);for(var n=0,r=e.length;r>n;n++)e[n][t]()},t.destroyAll=function(){t.invokeAll("destroy")},t.disableAll=function(){t.invokeAll("disable")},t.enableAll=function(){t.invokeAll("enable")},t.refreshAll=function(){t.Context.refreshAll()},t.viewportHeight=function(){return window.innerHeight||document.documentElement.clientHeight},t.viewportWidth=function(){return document.documentElement.clientWidth},t.adapters=[],t.defaults={context:window,continuous:!0,enabled:!0,group:"default",horizontal:!1,offset:0},t.offsetAliases={"bottom-in-view":function(){return this.context.innerHeight()-this.adapter.outerHeight()},"right-in-view":function(){return this.context.innerWidth()-this.adapter.outerWidth()}},window.Waypoint=t}(),function(){"use strict";function t(t){window.setTimeout(t,1e3/60)}function e(t){this.element=t,this.Adapter=n.Adapter,this.adapter=new this.Adapter(t),this.key="waypoint-context-"+i,this.didScroll=!1,this.didResize=!1,this.oldScroll={x:this.adapter.scrollLeft(),y:this.adapter.scrollTop()},this.waypoints={vertical:{},horizontal:{}},t.waypointContextKey=this.key,o[t.waypointContextKey]=this,i+=1,this.createThrottledScrollHandler(),this.createThrottledResizeHandler()}var i=0,o={},n=window.Waypoint,r=window.onload;e.prototype.add=function(t){var e=t.options.horizontal?"horizontal":"vertical";this.waypoints[e][t.key]=t,this.refresh()},e.prototype.checkEmpty=function(){var t=this.Adapter.isEmptyObject(this.waypoints.horizontal),e=this.Adapter.isEmptyObject(this.waypoints.vertical);t&&e&&(this.adapter.off(".waypoints"),delete o[this.key])},e.prototype.createThrottledResizeHandler=function(){function t(){e.handleResize(),e.didResize=!1}var e=this;this.adapter.on("resize.waypoints",function(){e.didResize||(e.didResize=!0,n.requestAnimationFrame(t))})},e.prototype.createThrottledScrollHandler=function(){function t(){e.handleScroll(),e.didScroll=!1}var e=this;this.adapter.on("scroll.waypoints",function(){(!e.didScroll||n.isTouch)&&(e.didScroll=!0,n.requestAnimationFrame(t))})},e.prototype.handleResize=function(){n.Context.refreshAll()},e.prototype.handleScroll=function(){var t={},e={horizontal:{newScroll:this.adapter.scrollLeft(),oldScroll:this.oldScroll.x,forward:"right",backward:"left"},vertical:{newScroll:this.adapter.scrollTop(),oldScroll:this.oldScroll.y,forward:"down",backward:"up"}};for(var i in e){var o=e[i],n=o.newScroll>o.oldScroll,r=n?o.forward:o.backward;for(var s in this.waypoints[i]){var a=this.waypoints[i][s],l=o.oldScroll=a.triggerPoint,p=l&&h,u=!l&&!h;(p||u)&&(a.queueTrigger(r),t[a.group.id]=a.group)}}for(var c in t)t[c].flushTriggers();this.oldScroll={x:e.horizontal.newScroll,y:e.vertical.newScroll}},e.prototype.innerHeight=function(){return this.element==this.element.window?n.viewportHeight():this.adapter.innerHeight()},e.prototype.remove=function(t){delete this.waypoints[t.axis][t.key],this.checkEmpty()},e.prototype.innerWidth=function(){return this.element==this.element.window?n.viewportWidth():this.adapter.innerWidth()},e.prototype.destroy=function(){var t=[];for(var e in this.waypoints)for(var i in this.waypoints[e])t.push(this.waypoints[e][i]);for(var o=0,n=t.length;n>o;o++)t[o].destroy()},e.prototype.refresh=function(){var t,e=this.element==this.element.window,i=this.adapter.offset(),o={};this.handleScroll(),t={horizontal:{contextOffset:e?0:i.left,contextScroll:e?0:this.oldScroll.x,contextDimension:this.innerWidth(),oldScroll:this.oldScroll.x,forward:"right",backward:"left",offsetProp:"left"},vertical:{contextOffset:e?0:i.top,contextScroll:e?0:this.oldScroll.y,contextDimension:this.innerHeight(),oldScroll:this.oldScroll.y,forward:"down",backward:"up",offsetProp:"top"}};for(var r in t){var s=t[r];for(var a in this.waypoints[r]){var l,h,p,u,c,d=this.waypoints[r][a],f=d.options.offset,w=d.triggerPoint,y=0,g=null==w;d.element!==d.element.window&&(y=d.adapter.offset()[s.offsetProp]),"function"==typeof f?f=f.apply(d):"string"==typeof f&&(f=parseFloat(f),d.options.offset.indexOf("%")>-1&&(f=Math.ceil(s.contextDimension*f/100))),l=s.contextScroll-s.contextOffset,d.triggerPoint=y+l-f,h=w=s.oldScroll,u=h&&p,c=!h&&!p,!g&&u?(d.queueTrigger(s.backward),o[d.group.id]=d.group):!g&&c?(d.queueTrigger(s.forward),o[d.group.id]=d.group):g&&s.oldScroll>=d.triggerPoint&&(d.queueTrigger(s.forward),o[d.group.id]=d.group)}}return n.requestAnimationFrame(function(){for(var t in o)o[t].flushTriggers()}),this},e.findOrCreateByElement=function(t){return e.findByElement(t)||new e(t)},e.refreshAll=function(){for(var t in o)o[t].refresh()},e.findByElement=function(t){return o[t.waypointContextKey]},window.onload=function(){r&&r(),e.refreshAll()},n.requestAnimationFrame=function(e){var i=window.requestAnimationFrame||window.mozRequestAnimationFrame||window.webkitRequestAnimationFrame||t;i.call(window,e)},n.Context=e}(),function(){"use strict";function t(t,e){return t.triggerPoint-e.triggerPoint}function e(t,e){return e.triggerPoint-t.triggerPoint}function i(t){this.name=t.name,this.axis=t.axis,this.id=this.name+"-"+this.axis,this.waypoints=[],this.clearTriggerQueues(),o[this.axis][this.name]=this}var o={vertical:{},horizontal:{}},n=window.Waypoint;i.prototype.add=function(t){this.waypoints.push(t)},i.prototype.clearTriggerQueues=function(){this.triggerQueues={up:[],down:[],left:[],right:[]}},i.prototype.flushTriggers=function(){for(var i in this.triggerQueues){var o=this.triggerQueues[i],n="up"===i||"left"===i;o.sort(n?e:t);for(var r=0,s=o.length;s>r;r+=1){var a=o[r];(a.options.continuous||r===o.length-1)&&a.trigger([i])}}this.clearTriggerQueues()},i.prototype.next=function(e){this.waypoints.sort(t);var i=n.Adapter.inArray(e,this.waypoints),o=i===this.waypoints.length-1;return o?null:this.waypoints[i+1]},i.prototype.previous=function(e){this.waypoints.sort(t);var i=n.Adapter.inArray(e,this.waypoints);return i?this.waypoints[i-1]:null},i.prototype.queueTrigger=function(t,e){this.triggerQueues[e].push(t)},i.prototype.remove=function(t){var e=n.Adapter.inArray(t,this.waypoints);e>-1&&this.waypoints.splice(e,1)},i.prototype.first=function(){return this.waypoints[0]},i.prototype.last=function(){return this.waypoints[this.waypoints.length-1]},i.findOrCreate=function(t){return o[t.axis][t.name]||new i(t)},n.Group=i}(),function(){"use strict";function t(t){this.$element=e(t)}var e=window.jQuery,i=window.Waypoint;e.each(["innerHeight","innerWidth","off","offset","on","outerHeight","outerWidth","scrollLeft","scrollTop"],function(e,i){t.prototype[i]=function(){var t=Array.prototype.slice.call(arguments);return this.$element[i].apply(this.$element,t)}}),e.each(["extend","inArray","isEmptyObject"],function(i,o){t[o]=e[o]}),i.adapters.push({name:"jquery",Adapter:t}),i.Adapter=t}(),function(){"use strict";function t(t){return function(){var i=[],o=arguments[0];return t.isFunction(arguments[0])&&(o=t.extend({},arguments[1]),o.handler=arguments[0]),this.each(function(){var n=t.extend({},o,{element:this});"string"==typeof n.context&&(n.context=t(this).closest(n.context)[0]),i.push(new e(n))}),i}}var e=window.Waypoint;window.jQuery&&(window.jQuery.fn.waypoint=t(window.jQuery)),window.Zepto&&(window.Zepto.fn.waypoint=t(window.Zepto))}(); \ No newline at end of file diff --git a/lib/noframework.waypoints.js b/lib/noframework.waypoints.js index 431551ce..9cfaf936 100644 --- a/lib/noframework.waypoints.js +++ b/lib/noframework.waypoints.js @@ -421,9 +421,11 @@ https://github.com/imakewebthings/waypoints/blog/master/licenses.txt } } - for (var groupKey in triggeredGroups) { - triggeredGroups[groupKey].flushTriggers() - } + Waypoint.requestAnimationFrame(function() { + for (var groupKey in triggeredGroups) { + triggeredGroups[groupKey].flushTriggers() + } + }) return this } diff --git a/lib/noframework.waypoints.min.js b/lib/noframework.waypoints.min.js index 0367c93a..5f320c34 100644 --- a/lib/noframework.waypoints.min.js +++ b/lib/noframework.waypoints.min.js @@ -4,4 +4,4 @@ Copyright © 2011-2015 Caleb Troughton Licensed under the MIT license. https://github.com/imakewebthings/waypoints/blog/master/licenses.txt */ -!function(){"use strict";function t(n){if(!n)throw new Error("No options passed to Waypoint constructor");if(!n.element)throw new Error("No element option passed to Waypoint constructor");if(!n.handler)throw new Error("No handler option passed to Waypoint constructor");this.key="waypoint-"+e,this.options=t.Adapter.extend({},t.defaults,n),this.element=this.options.element,this.adapter=new t.Adapter(this.element),this.callback=n.handler,this.axis=this.options.horizontal?"horizontal":"vertical",this.enabled=this.options.enabled,this.triggerPoint=null,this.group=t.Group.findOrCreate({name:this.options.group,axis:this.axis}),this.context=t.Context.findOrCreateByElement(this.options.context),t.offsetAliases[this.options.offset]&&(this.options.offset=t.offsetAliases[this.options.offset]),this.group.add(this),this.context.add(this),i[this.key]=this,e+=1}var e=0,i={};t.prototype.queueTrigger=function(t){this.group.queueTrigger(this,t)},t.prototype.trigger=function(t){this.enabled&&this.callback&&this.callback.apply(this,t)},t.prototype.destroy=function(){this.context.remove(this),this.group.remove(this),delete i[this.key]},t.prototype.disable=function(){return this.enabled=!1,this},t.prototype.enable=function(){return this.context.refresh(),this.enabled=!0,this},t.prototype.next=function(){return this.group.next(this)},t.prototype.previous=function(){return this.group.previous(this)},t.invokeAll=function(t){var e=[];for(var n in i)e.push(i[n]);for(var o=0,r=e.length;r>o;o++)e[o][t]()},t.destroyAll=function(){t.invokeAll("destroy")},t.disableAll=function(){t.invokeAll("disable")},t.enableAll=function(){t.invokeAll("enable")},t.refreshAll=function(){t.Context.refreshAll()},t.viewportHeight=function(){return window.innerHeight||document.documentElement.clientHeight},t.viewportWidth=function(){return document.documentElement.clientWidth},t.adapters=[],t.defaults={context:window,continuous:!0,enabled:!0,group:"default",horizontal:!1,offset:0},t.offsetAliases={"bottom-in-view":function(){return this.context.innerHeight()-this.adapter.outerHeight()},"right-in-view":function(){return this.context.innerWidth()-this.adapter.outerWidth()}},window.Waypoint=t}(),function(){"use strict";function t(t){window.setTimeout(t,1e3/60)}function e(t){this.element=t,this.Adapter=o.Adapter,this.adapter=new this.Adapter(t),this.key="waypoint-context-"+i,this.didScroll=!1,this.didResize=!1,this.oldScroll={x:this.adapter.scrollLeft(),y:this.adapter.scrollTop()},this.waypoints={vertical:{},horizontal:{}},t.waypointContextKey=this.key,n[t.waypointContextKey]=this,i+=1,this.createThrottledScrollHandler(),this.createThrottledResizeHandler()}var i=0,n={},o=window.Waypoint,r=window.onload;e.prototype.add=function(t){var e=t.options.horizontal?"horizontal":"vertical";this.waypoints[e][t.key]=t,this.refresh()},e.prototype.checkEmpty=function(){var t=this.Adapter.isEmptyObject(this.waypoints.horizontal),e=this.Adapter.isEmptyObject(this.waypoints.vertical);t&&e&&(this.adapter.off(".waypoints"),delete n[this.key])},e.prototype.createThrottledResizeHandler=function(){function t(){e.handleResize(),e.didResize=!1}var e=this;this.adapter.on("resize.waypoints",function(){e.didResize||(e.didResize=!0,o.requestAnimationFrame(t))})},e.prototype.createThrottledScrollHandler=function(){function t(){e.handleScroll(),e.didScroll=!1}var e=this;this.adapter.on("scroll.waypoints",function(){(!e.didScroll||o.isTouch)&&(e.didScroll=!0,o.requestAnimationFrame(t))})},e.prototype.handleResize=function(){o.Context.refreshAll()},e.prototype.handleScroll=function(){var t={},e={horizontal:{newScroll:this.adapter.scrollLeft(),oldScroll:this.oldScroll.x,forward:"right",backward:"left"},vertical:{newScroll:this.adapter.scrollTop(),oldScroll:this.oldScroll.y,forward:"down",backward:"up"}};for(var i in e){var n=e[i],o=n.newScroll>n.oldScroll,r=o?n.forward:n.backward;for(var s in this.waypoints[i]){var l=this.waypoints[i][s],a=n.oldScroll=l.triggerPoint,p=a&&h,u=!a&&!h;(p||u)&&(l.queueTrigger(r),t[l.group.id]=l.group)}}for(var c in t)t[c].flushTriggers();this.oldScroll={x:e.horizontal.newScroll,y:e.vertical.newScroll}},e.prototype.innerHeight=function(){return this.element==this.element.window?o.viewportHeight():this.adapter.innerHeight()},e.prototype.remove=function(t){delete this.waypoints[t.axis][t.key],this.checkEmpty()},e.prototype.innerWidth=function(){return this.element==this.element.window?o.viewportWidth():this.adapter.innerWidth()},e.prototype.destroy=function(){var t=[];for(var e in this.waypoints)for(var i in this.waypoints[e])t.push(this.waypoints[e][i]);for(var n=0,o=t.length;o>n;n++)t[n].destroy()},e.prototype.refresh=function(){var t,e=this.element==this.element.window,i=this.adapter.offset(),n={};this.handleScroll(),t={horizontal:{contextOffset:e?0:i.left,contextScroll:e?0:this.oldScroll.x,contextDimension:this.innerWidth(),oldScroll:this.oldScroll.x,forward:"right",backward:"left",offsetProp:"left"},vertical:{contextOffset:e?0:i.top,contextScroll:e?0:this.oldScroll.y,contextDimension:this.innerHeight(),oldScroll:this.oldScroll.y,forward:"down",backward:"up",offsetProp:"top"}};for(var o in t){var r=t[o];for(var s in this.waypoints[o]){var l,a,h,p,u,c=this.waypoints[o][s],f=c.options.offset,d=c.triggerPoint,y=0,g=null==d;c.element!==c.element.window&&(y=c.adapter.offset()[r.offsetProp]),"function"==typeof f?f=f.apply(c):"string"==typeof f&&(f=parseFloat(f),c.options.offset.indexOf("%")>-1&&(f=Math.ceil(r.contextDimension*f/100))),l=r.contextScroll-r.contextOffset,c.triggerPoint=y+l-f,a=d=r.oldScroll,p=a&&h,u=!a&&!h,!g&&p?(c.queueTrigger(r.backward),n[c.group.id]=c.group):!g&&u?(c.queueTrigger(r.forward),n[c.group.id]=c.group):g&&r.oldScroll>=c.triggerPoint&&(c.queueTrigger(r.forward),n[c.group.id]=c.group)}}for(var w in n)n[w].flushTriggers();return this},e.findOrCreateByElement=function(t){return e.findByElement(t)||new e(t)},e.refreshAll=function(){for(var t in n)n[t].refresh()},e.findByElement=function(t){return n[t.waypointContextKey]},window.onload=function(){r&&r(),e.refreshAll()},o.requestAnimationFrame=function(e){var i=window.requestAnimationFrame||window.mozRequestAnimationFrame||window.webkitRequestAnimationFrame||t;i.call(window,e)},o.Context=e}(),function(){"use strict";function t(t,e){return t.triggerPoint-e.triggerPoint}function e(t,e){return e.triggerPoint-t.triggerPoint}function i(t){this.name=t.name,this.axis=t.axis,this.id=this.name+"-"+this.axis,this.waypoints=[],this.clearTriggerQueues(),n[this.axis][this.name]=this}var n={vertical:{},horizontal:{}},o=window.Waypoint;i.prototype.add=function(t){this.waypoints.push(t)},i.prototype.clearTriggerQueues=function(){this.triggerQueues={up:[],down:[],left:[],right:[]}},i.prototype.flushTriggers=function(){for(var i in this.triggerQueues){var n=this.triggerQueues[i],o="up"===i||"left"===i;n.sort(o?e:t);for(var r=0,s=n.length;s>r;r+=1){var l=n[r];(l.options.continuous||r===n.length-1)&&l.trigger([i])}}this.clearTriggerQueues()},i.prototype.next=function(e){this.waypoints.sort(t);var i=o.Adapter.inArray(e,this.waypoints),n=i===this.waypoints.length-1;return n?null:this.waypoints[i+1]},i.prototype.previous=function(e){this.waypoints.sort(t);var i=o.Adapter.inArray(e,this.waypoints);return i?this.waypoints[i-1]:null},i.prototype.queueTrigger=function(t,e){this.triggerQueues[e].push(t)},i.prototype.remove=function(t){var e=o.Adapter.inArray(t,this.waypoints);e>-1&&this.waypoints.splice(e,1)},i.prototype.first=function(){return this.waypoints[0]},i.prototype.last=function(){return this.waypoints[this.waypoints.length-1]},i.findOrCreate=function(t){return n[t.axis][t.name]||new i(t)},o.Group=i}(),function(){"use strict";function t(t){return t===t.window}function e(e){return t(e)?e:e.defaultView}function i(t){this.element=t,this.handlers={}}var n=window.Waypoint;i.prototype.innerHeight=function(){var e=t(this.element);return e?this.element.innerHeight:this.element.clientHeight},i.prototype.innerWidth=function(){var e=t(this.element);return e?this.element.innerWidth:this.element.clientWidth},i.prototype.off=function(t,e){function i(t,e,i){for(var n=0,o=e.length-1;o>n;n++){var r=e[n];i&&i!==r||t.removeEventListener(r)}}var n=t.split("."),o=n[0],r=n[1],s=this.element;if(r&&this.handlers[r]&&o)i(s,this.handlers[r][o],e),this.handlers[r][o]=[];else if(o)for(var l in this.handlers)i(s,this.handlers[l][o]||[],e),this.handlers[l][o]=[];else if(r&&this.handlers[r]){for(var a in this.handlers[r])i(s,this.handlers[r][a],e);this.handlers[r]={}}},i.prototype.offset=function(){if(!this.element.ownerDocument)return null;var t=this.element.ownerDocument.documentElement,i=e(this.element.ownerDocument),n={top:0,left:0};return this.element.getBoundingClientRect&&(n=this.element.getBoundingClientRect()),{top:n.top+i.pageYOffset-t.clientTop,left:n.left+i.pageXOffset-t.clientLeft}},i.prototype.on=function(t,e){var i=t.split("."),n=i[0],o=i[1]||"__default",r=this.handlers[o]=this.handlers[o]||{},s=r[n]=r[n]||[];s.push(e),this.element.addEventListener(n,e)},i.prototype.outerHeight=function(e){var i,n=this.innerHeight();return e&&!t(this.element)&&(i=window.getComputedStyle(this.element),n+=parseInt(i.marginTop,10),n+=parseInt(i.marginBottom,10)),n},i.prototype.outerWidth=function(e){var i,n=this.innerWidth();return e&&!t(this.element)&&(i=window.getComputedStyle(this.element),n+=parseInt(i.marginLeft,10),n+=parseInt(i.marginRight,10)),n},i.prototype.scrollLeft=function(){var t=e(this.element);return t?t.pageXOffset:this.element.scrollLeft},i.prototype.scrollTop=function(){var t=e(this.element);return t?t.pageYOffset:this.element.scrollTop},i.extend=function(){function t(t,e){if("object"==typeof t&&"object"==typeof e)for(var i in e)e.hasOwnProperty(i)&&(t[i]=e[i]);return t}for(var e=Array.prototype.slice.call(arguments),i=1,n=e.length;n>i;i++)t(e[0],e[i]);return e[0]},i.inArray=function(t,e,i){return null==e?-1:e.indexOf(t,i)},i.isEmptyObject=function(t){for(var e in t)return!1;return!0},n.adapters.push({name:"noframework",Adapter:i}),n.Adapter=i}(); \ No newline at end of file +!function(){"use strict";function t(n){if(!n)throw new Error("No options passed to Waypoint constructor");if(!n.element)throw new Error("No element option passed to Waypoint constructor");if(!n.handler)throw new Error("No handler option passed to Waypoint constructor");this.key="waypoint-"+e,this.options=t.Adapter.extend({},t.defaults,n),this.element=this.options.element,this.adapter=new t.Adapter(this.element),this.callback=n.handler,this.axis=this.options.horizontal?"horizontal":"vertical",this.enabled=this.options.enabled,this.triggerPoint=null,this.group=t.Group.findOrCreate({name:this.options.group,axis:this.axis}),this.context=t.Context.findOrCreateByElement(this.options.context),t.offsetAliases[this.options.offset]&&(this.options.offset=t.offsetAliases[this.options.offset]),this.group.add(this),this.context.add(this),i[this.key]=this,e+=1}var e=0,i={};t.prototype.queueTrigger=function(t){this.group.queueTrigger(this,t)},t.prototype.trigger=function(t){this.enabled&&this.callback&&this.callback.apply(this,t)},t.prototype.destroy=function(){this.context.remove(this),this.group.remove(this),delete i[this.key]},t.prototype.disable=function(){return this.enabled=!1,this},t.prototype.enable=function(){return this.context.refresh(),this.enabled=!0,this},t.prototype.next=function(){return this.group.next(this)},t.prototype.previous=function(){return this.group.previous(this)},t.invokeAll=function(t){var e=[];for(var n in i)e.push(i[n]);for(var o=0,r=e.length;r>o;o++)e[o][t]()},t.destroyAll=function(){t.invokeAll("destroy")},t.disableAll=function(){t.invokeAll("disable")},t.enableAll=function(){t.invokeAll("enable")},t.refreshAll=function(){t.Context.refreshAll()},t.viewportHeight=function(){return window.innerHeight||document.documentElement.clientHeight},t.viewportWidth=function(){return document.documentElement.clientWidth},t.adapters=[],t.defaults={context:window,continuous:!0,enabled:!0,group:"default",horizontal:!1,offset:0},t.offsetAliases={"bottom-in-view":function(){return this.context.innerHeight()-this.adapter.outerHeight()},"right-in-view":function(){return this.context.innerWidth()-this.adapter.outerWidth()}},window.Waypoint=t}(),function(){"use strict";function t(t){window.setTimeout(t,1e3/60)}function e(t){this.element=t,this.Adapter=o.Adapter,this.adapter=new this.Adapter(t),this.key="waypoint-context-"+i,this.didScroll=!1,this.didResize=!1,this.oldScroll={x:this.adapter.scrollLeft(),y:this.adapter.scrollTop()},this.waypoints={vertical:{},horizontal:{}},t.waypointContextKey=this.key,n[t.waypointContextKey]=this,i+=1,this.createThrottledScrollHandler(),this.createThrottledResizeHandler()}var i=0,n={},o=window.Waypoint,r=window.onload;e.prototype.add=function(t){var e=t.options.horizontal?"horizontal":"vertical";this.waypoints[e][t.key]=t,this.refresh()},e.prototype.checkEmpty=function(){var t=this.Adapter.isEmptyObject(this.waypoints.horizontal),e=this.Adapter.isEmptyObject(this.waypoints.vertical);t&&e&&(this.adapter.off(".waypoints"),delete n[this.key])},e.prototype.createThrottledResizeHandler=function(){function t(){e.handleResize(),e.didResize=!1}var e=this;this.adapter.on("resize.waypoints",function(){e.didResize||(e.didResize=!0,o.requestAnimationFrame(t))})},e.prototype.createThrottledScrollHandler=function(){function t(){e.handleScroll(),e.didScroll=!1}var e=this;this.adapter.on("scroll.waypoints",function(){(!e.didScroll||o.isTouch)&&(e.didScroll=!0,o.requestAnimationFrame(t))})},e.prototype.handleResize=function(){o.Context.refreshAll()},e.prototype.handleScroll=function(){var t={},e={horizontal:{newScroll:this.adapter.scrollLeft(),oldScroll:this.oldScroll.x,forward:"right",backward:"left"},vertical:{newScroll:this.adapter.scrollTop(),oldScroll:this.oldScroll.y,forward:"down",backward:"up"}};for(var i in e){var n=e[i],o=n.newScroll>n.oldScroll,r=o?n.forward:n.backward;for(var s in this.waypoints[i]){var l=this.waypoints[i][s],a=n.oldScroll=l.triggerPoint,p=a&&h,u=!a&&!h;(p||u)&&(l.queueTrigger(r),t[l.group.id]=l.group)}}for(var c in t)t[c].flushTriggers();this.oldScroll={x:e.horizontal.newScroll,y:e.vertical.newScroll}},e.prototype.innerHeight=function(){return this.element==this.element.window?o.viewportHeight():this.adapter.innerHeight()},e.prototype.remove=function(t){delete this.waypoints[t.axis][t.key],this.checkEmpty()},e.prototype.innerWidth=function(){return this.element==this.element.window?o.viewportWidth():this.adapter.innerWidth()},e.prototype.destroy=function(){var t=[];for(var e in this.waypoints)for(var i in this.waypoints[e])t.push(this.waypoints[e][i]);for(var n=0,o=t.length;o>n;n++)t[n].destroy()},e.prototype.refresh=function(){var t,e=this.element==this.element.window,i=this.adapter.offset(),n={};this.handleScroll(),t={horizontal:{contextOffset:e?0:i.left,contextScroll:e?0:this.oldScroll.x,contextDimension:this.innerWidth(),oldScroll:this.oldScroll.x,forward:"right",backward:"left",offsetProp:"left"},vertical:{contextOffset:e?0:i.top,contextScroll:e?0:this.oldScroll.y,contextDimension:this.innerHeight(),oldScroll:this.oldScroll.y,forward:"down",backward:"up",offsetProp:"top"}};for(var r in t){var s=t[r];for(var l in this.waypoints[r]){var a,h,p,u,c,f=this.waypoints[r][l],d=f.options.offset,y=f.triggerPoint,g=0,w=null==y;f.element!==f.element.window&&(g=f.adapter.offset()[s.offsetProp]),"function"==typeof d?d=d.apply(f):"string"==typeof d&&(d=parseFloat(d),f.options.offset.indexOf("%")>-1&&(d=Math.ceil(s.contextDimension*d/100))),a=s.contextScroll-s.contextOffset,f.triggerPoint=g+a-d,h=y=s.oldScroll,u=h&&p,c=!h&&!p,!w&&u?(f.queueTrigger(s.backward),n[f.group.id]=f.group):!w&&c?(f.queueTrigger(s.forward),n[f.group.id]=f.group):w&&s.oldScroll>=f.triggerPoint&&(f.queueTrigger(s.forward),n[f.group.id]=f.group)}}return o.requestAnimationFrame(function(){for(var t in n)n[t].flushTriggers()}),this},e.findOrCreateByElement=function(t){return e.findByElement(t)||new e(t)},e.refreshAll=function(){for(var t in n)n[t].refresh()},e.findByElement=function(t){return n[t.waypointContextKey]},window.onload=function(){r&&r(),e.refreshAll()},o.requestAnimationFrame=function(e){var i=window.requestAnimationFrame||window.mozRequestAnimationFrame||window.webkitRequestAnimationFrame||t;i.call(window,e)},o.Context=e}(),function(){"use strict";function t(t,e){return t.triggerPoint-e.triggerPoint}function e(t,e){return e.triggerPoint-t.triggerPoint}function i(t){this.name=t.name,this.axis=t.axis,this.id=this.name+"-"+this.axis,this.waypoints=[],this.clearTriggerQueues(),n[this.axis][this.name]=this}var n={vertical:{},horizontal:{}},o=window.Waypoint;i.prototype.add=function(t){this.waypoints.push(t)},i.prototype.clearTriggerQueues=function(){this.triggerQueues={up:[],down:[],left:[],right:[]}},i.prototype.flushTriggers=function(){for(var i in this.triggerQueues){var n=this.triggerQueues[i],o="up"===i||"left"===i;n.sort(o?e:t);for(var r=0,s=n.length;s>r;r+=1){var l=n[r];(l.options.continuous||r===n.length-1)&&l.trigger([i])}}this.clearTriggerQueues()},i.prototype.next=function(e){this.waypoints.sort(t);var i=o.Adapter.inArray(e,this.waypoints),n=i===this.waypoints.length-1;return n?null:this.waypoints[i+1]},i.prototype.previous=function(e){this.waypoints.sort(t);var i=o.Adapter.inArray(e,this.waypoints);return i?this.waypoints[i-1]:null},i.prototype.queueTrigger=function(t,e){this.triggerQueues[e].push(t)},i.prototype.remove=function(t){var e=o.Adapter.inArray(t,this.waypoints);e>-1&&this.waypoints.splice(e,1)},i.prototype.first=function(){return this.waypoints[0]},i.prototype.last=function(){return this.waypoints[this.waypoints.length-1]},i.findOrCreate=function(t){return n[t.axis][t.name]||new i(t)},o.Group=i}(),function(){"use strict";function t(t){return t===t.window}function e(e){return t(e)?e:e.defaultView}function i(t){this.element=t,this.handlers={}}var n=window.Waypoint;i.prototype.innerHeight=function(){var e=t(this.element);return e?this.element.innerHeight:this.element.clientHeight},i.prototype.innerWidth=function(){var e=t(this.element);return e?this.element.innerWidth:this.element.clientWidth},i.prototype.off=function(t,e){function i(t,e,i){for(var n=0,o=e.length-1;o>n;n++){var r=e[n];i&&i!==r||t.removeEventListener(r)}}var n=t.split("."),o=n[0],r=n[1],s=this.element;if(r&&this.handlers[r]&&o)i(s,this.handlers[r][o],e),this.handlers[r][o]=[];else if(o)for(var l in this.handlers)i(s,this.handlers[l][o]||[],e),this.handlers[l][o]=[];else if(r&&this.handlers[r]){for(var a in this.handlers[r])i(s,this.handlers[r][a],e);this.handlers[r]={}}},i.prototype.offset=function(){if(!this.element.ownerDocument)return null;var t=this.element.ownerDocument.documentElement,i=e(this.element.ownerDocument),n={top:0,left:0};return this.element.getBoundingClientRect&&(n=this.element.getBoundingClientRect()),{top:n.top+i.pageYOffset-t.clientTop,left:n.left+i.pageXOffset-t.clientLeft}},i.prototype.on=function(t,e){var i=t.split("."),n=i[0],o=i[1]||"__default",r=this.handlers[o]=this.handlers[o]||{},s=r[n]=r[n]||[];s.push(e),this.element.addEventListener(n,e)},i.prototype.outerHeight=function(e){var i,n=this.innerHeight();return e&&!t(this.element)&&(i=window.getComputedStyle(this.element),n+=parseInt(i.marginTop,10),n+=parseInt(i.marginBottom,10)),n},i.prototype.outerWidth=function(e){var i,n=this.innerWidth();return e&&!t(this.element)&&(i=window.getComputedStyle(this.element),n+=parseInt(i.marginLeft,10),n+=parseInt(i.marginRight,10)),n},i.prototype.scrollLeft=function(){var t=e(this.element);return t?t.pageXOffset:this.element.scrollLeft},i.prototype.scrollTop=function(){var t=e(this.element);return t?t.pageYOffset:this.element.scrollTop},i.extend=function(){function t(t,e){if("object"==typeof t&&"object"==typeof e)for(var i in e)e.hasOwnProperty(i)&&(t[i]=e[i]);return t}for(var e=Array.prototype.slice.call(arguments),i=1,n=e.length;n>i;i++)t(e[0],e[i]);return e[0]},i.inArray=function(t,e,i){return null==e?-1:e.indexOf(t,i)},i.isEmptyObject=function(t){for(var e in t)return!1;return!0},n.adapters.push({name:"noframework",Adapter:i}),n.Adapter=i}(); \ No newline at end of file diff --git a/lib/shortcuts/sticky.js b/lib/shortcuts/sticky.js index 81f0e27d..8a74c2a2 100644 --- a/lib/shortcuts/sticky.js +++ b/lib/shortcuts/sticky.js @@ -41,7 +41,9 @@ https://github.com/imakewebthings/waypoints/blog/master/licenses.txt /* Private */ Sticky.prototype.createWrapper = function() { - this.$element.wrap(this.options.wrapper) + if (this.options.wrapper) { + this.$element.wrap(this.options.wrapper) + } this.$wrapper = this.$element.parent() this.wrapper = this.$wrapper[0] } @@ -50,7 +52,10 @@ https://github.com/imakewebthings/waypoints/blog/master/licenses.txt Sticky.prototype.destroy = function() { if (this.$element.parent()[0] === this.wrapper) { this.waypoint.destroy() - this.$element.removeClass(this.options.stuckClass).unwrap() + this.$element.removeClass(this.options.stuckClass) + if (this.options.wrapper) { + this.$element.unwrap() + } } } diff --git a/lib/shortcuts/sticky.min.js b/lib/shortcuts/sticky.min.js index 545a9c7c..9173935c 100644 --- a/lib/shortcuts/sticky.min.js +++ b/lib/shortcuts/sticky.min.js @@ -4,4 +4,4 @@ Copyright © 2011-2015 Caleb Troughton Licensed under the MIT license. https://github.com/imakewebthings/waypoints/blog/master/licenses.txt */ -!function(){"use strict";function t(s){this.options=e.extend({},i.defaults,t.defaults,s),this.element=this.options.element,this.$element=e(this.element),this.createWrapper(),this.createWaypoint()}var e=window.jQuery,i=window.Waypoint;t.prototype.createWaypoint=function(){var t=this.options.handler;this.waypoint=new i(e.extend({},this.options,{element:this.wrapper,handler:e.proxy(function(e){var i=this.options.direction.indexOf(e)>-1,s=i?this.$element.outerHeight(!0):"";this.$wrapper.height(s),this.$element.toggleClass(this.options.stuckClass,i),t&&t.call(this,e)},this)}))},t.prototype.createWrapper=function(){this.$element.wrap(this.options.wrapper),this.$wrapper=this.$element.parent(),this.wrapper=this.$wrapper[0]},t.prototype.destroy=function(){this.$element.parent()[0]===this.wrapper&&(this.waypoint.destroy(),this.$element.removeClass(this.options.stuckClass).unwrap())},t.defaults={wrapper:'
',stuckClass:"stuck",direction:"down right"},i.Sticky=t}(); \ No newline at end of file +!function(){"use strict";function t(s){this.options=e.extend({},i.defaults,t.defaults,s),this.element=this.options.element,this.$element=e(this.element),this.createWrapper(),this.createWaypoint()}var e=window.jQuery,i=window.Waypoint;t.prototype.createWaypoint=function(){var t=this.options.handler;this.waypoint=new i(e.extend({},this.options,{element:this.wrapper,handler:e.proxy(function(e){var i=this.options.direction.indexOf(e)>-1,s=i?this.$element.outerHeight(!0):"";this.$wrapper.height(s),this.$element.toggleClass(this.options.stuckClass,i),t&&t.call(this,e)},this)}))},t.prototype.createWrapper=function(){this.options.wrapper&&this.$element.wrap(this.options.wrapper),this.$wrapper=this.$element.parent(),this.wrapper=this.$wrapper[0]},t.prototype.destroy=function(){this.$element.parent()[0]===this.wrapper&&(this.waypoint.destroy(),this.$element.removeClass(this.options.stuckClass),this.options.wrapper&&this.$element.unwrap())},t.defaults={wrapper:'
',stuckClass:"stuck",direction:"down right"},i.Sticky=t}(); \ No newline at end of file diff --git a/lib/zepto.waypoints.js b/lib/zepto.waypoints.js index 76eefbee..7ba59d9d 100644 --- a/lib/zepto.waypoints.js +++ b/lib/zepto.waypoints.js @@ -421,9 +421,11 @@ https://github.com/imakewebthings/waypoints/blog/master/licenses.txt } } - for (var groupKey in triggeredGroups) { - triggeredGroups[groupKey].flushTriggers() - } + Waypoint.requestAnimationFrame(function() { + for (var groupKey in triggeredGroups) { + triggeredGroups[groupKey].flushTriggers() + } + }) return this } diff --git a/lib/zepto.waypoints.min.js b/lib/zepto.waypoints.min.js index fc8f7721..55c68527 100644 --- a/lib/zepto.waypoints.min.js +++ b/lib/zepto.waypoints.min.js @@ -4,4 +4,4 @@ Copyright © 2011-2015 Caleb Troughton Licensed under the MIT license. https://github.com/imakewebthings/waypoints/blog/master/licenses.txt */ -!function(){"use strict";function t(o){if(!o)throw new Error("No options passed to Waypoint constructor");if(!o.element)throw new Error("No element option passed to Waypoint constructor");if(!o.handler)throw new Error("No handler option passed to Waypoint constructor");this.key="waypoint-"+e,this.options=t.Adapter.extend({},t.defaults,o),this.element=this.options.element,this.adapter=new t.Adapter(this.element),this.callback=o.handler,this.axis=this.options.horizontal?"horizontal":"vertical",this.enabled=this.options.enabled,this.triggerPoint=null,this.group=t.Group.findOrCreate({name:this.options.group,axis:this.axis}),this.context=t.Context.findOrCreateByElement(this.options.context),t.offsetAliases[this.options.offset]&&(this.options.offset=t.offsetAliases[this.options.offset]),this.group.add(this),this.context.add(this),i[this.key]=this,e+=1}var e=0,i={};t.prototype.queueTrigger=function(t){this.group.queueTrigger(this,t)},t.prototype.trigger=function(t){this.enabled&&this.callback&&this.callback.apply(this,t)},t.prototype.destroy=function(){this.context.remove(this),this.group.remove(this),delete i[this.key]},t.prototype.disable=function(){return this.enabled=!1,this},t.prototype.enable=function(){return this.context.refresh(),this.enabled=!0,this},t.prototype.next=function(){return this.group.next(this)},t.prototype.previous=function(){return this.group.previous(this)},t.invokeAll=function(t){var e=[];for(var o in i)e.push(i[o]);for(var n=0,r=e.length;r>n;n++)e[n][t]()},t.destroyAll=function(){t.invokeAll("destroy")},t.disableAll=function(){t.invokeAll("disable")},t.enableAll=function(){t.invokeAll("enable")},t.refreshAll=function(){t.Context.refreshAll()},t.viewportHeight=function(){return window.innerHeight||document.documentElement.clientHeight},t.viewportWidth=function(){return document.documentElement.clientWidth},t.adapters=[],t.defaults={context:window,continuous:!0,enabled:!0,group:"default",horizontal:!1,offset:0},t.offsetAliases={"bottom-in-view":function(){return this.context.innerHeight()-this.adapter.outerHeight()},"right-in-view":function(){return this.context.innerWidth()-this.adapter.outerWidth()}},window.Waypoint=t}(),function(){"use strict";function t(t){window.setTimeout(t,1e3/60)}function e(t){this.element=t,this.Adapter=n.Adapter,this.adapter=new this.Adapter(t),this.key="waypoint-context-"+i,this.didScroll=!1,this.didResize=!1,this.oldScroll={x:this.adapter.scrollLeft(),y:this.adapter.scrollTop()},this.waypoints={vertical:{},horizontal:{}},t.waypointContextKey=this.key,o[t.waypointContextKey]=this,i+=1,this.createThrottledScrollHandler(),this.createThrottledResizeHandler()}var i=0,o={},n=window.Waypoint,r=window.onload;e.prototype.add=function(t){var e=t.options.horizontal?"horizontal":"vertical";this.waypoints[e][t.key]=t,this.refresh()},e.prototype.checkEmpty=function(){var t=this.Adapter.isEmptyObject(this.waypoints.horizontal),e=this.Adapter.isEmptyObject(this.waypoints.vertical);t&&e&&(this.adapter.off(".waypoints"),delete o[this.key])},e.prototype.createThrottledResizeHandler=function(){function t(){e.handleResize(),e.didResize=!1}var e=this;this.adapter.on("resize.waypoints",function(){e.didResize||(e.didResize=!0,n.requestAnimationFrame(t))})},e.prototype.createThrottledScrollHandler=function(){function t(){e.handleScroll(),e.didScroll=!1}var e=this;this.adapter.on("scroll.waypoints",function(){(!e.didScroll||n.isTouch)&&(e.didScroll=!0,n.requestAnimationFrame(t))})},e.prototype.handleResize=function(){n.Context.refreshAll()},e.prototype.handleScroll=function(){var t={},e={horizontal:{newScroll:this.adapter.scrollLeft(),oldScroll:this.oldScroll.x,forward:"right",backward:"left"},vertical:{newScroll:this.adapter.scrollTop(),oldScroll:this.oldScroll.y,forward:"down",backward:"up"}};for(var i in e){var o=e[i],n=o.newScroll>o.oldScroll,r=n?o.forward:o.backward;for(var s in this.waypoints[i]){var a=this.waypoints[i][s],l=o.oldScroll=a.triggerPoint,p=l&&h,c=!l&&!h;(p||c)&&(a.queueTrigger(r),t[a.group.id]=a.group)}}for(var u in t)t[u].flushTriggers();this.oldScroll={x:e.horizontal.newScroll,y:e.vertical.newScroll}},e.prototype.innerHeight=function(){return this.element==this.element.window?n.viewportHeight():this.adapter.innerHeight()},e.prototype.remove=function(t){delete this.waypoints[t.axis][t.key],this.checkEmpty()},e.prototype.innerWidth=function(){return this.element==this.element.window?n.viewportWidth():this.adapter.innerWidth()},e.prototype.destroy=function(){var t=[];for(var e in this.waypoints)for(var i in this.waypoints[e])t.push(this.waypoints[e][i]);for(var o=0,n=t.length;n>o;o++)t[o].destroy()},e.prototype.refresh=function(){var t,e=this.element==this.element.window,i=this.adapter.offset(),o={};this.handleScroll(),t={horizontal:{contextOffset:e?0:i.left,contextScroll:e?0:this.oldScroll.x,contextDimension:this.innerWidth(),oldScroll:this.oldScroll.x,forward:"right",backward:"left",offsetProp:"left"},vertical:{contextOffset:e?0:i.top,contextScroll:e?0:this.oldScroll.y,contextDimension:this.innerHeight(),oldScroll:this.oldScroll.y,forward:"down",backward:"up",offsetProp:"top"}};for(var n in t){var r=t[n];for(var s in this.waypoints[n]){var a,l,h,p,c,u=this.waypoints[n][s],d=u.options.offset,f=u.triggerPoint,w=0,y=null==f;u.element!==u.element.window&&(w=u.adapter.offset()[r.offsetProp]),"function"==typeof d?d=d.apply(u):"string"==typeof d&&(d=parseFloat(d),u.options.offset.indexOf("%")>-1&&(d=Math.ceil(r.contextDimension*d/100))),a=r.contextScroll-r.contextOffset,u.triggerPoint=w+a-d,l=f=r.oldScroll,p=l&&h,c=!l&&!h,!y&&p?(u.queueTrigger(r.backward),o[u.group.id]=u.group):!y&&c?(u.queueTrigger(r.forward),o[u.group.id]=u.group):y&&r.oldScroll>=u.triggerPoint&&(u.queueTrigger(r.forward),o[u.group.id]=u.group)}}for(var g in o)o[g].flushTriggers();return this},e.findOrCreateByElement=function(t){return e.findByElement(t)||new e(t)},e.refreshAll=function(){for(var t in o)o[t].refresh()},e.findByElement=function(t){return o[t.waypointContextKey]},window.onload=function(){r&&r(),e.refreshAll()},n.requestAnimationFrame=function(e){var i=window.requestAnimationFrame||window.mozRequestAnimationFrame||window.webkitRequestAnimationFrame||t;i.call(window,e)},n.Context=e}(),function(){"use strict";function t(t,e){return t.triggerPoint-e.triggerPoint}function e(t,e){return e.triggerPoint-t.triggerPoint}function i(t){this.name=t.name,this.axis=t.axis,this.id=this.name+"-"+this.axis,this.waypoints=[],this.clearTriggerQueues(),o[this.axis][this.name]=this}var o={vertical:{},horizontal:{}},n=window.Waypoint;i.prototype.add=function(t){this.waypoints.push(t)},i.prototype.clearTriggerQueues=function(){this.triggerQueues={up:[],down:[],left:[],right:[]}},i.prototype.flushTriggers=function(){for(var i in this.triggerQueues){var o=this.triggerQueues[i],n="up"===i||"left"===i;o.sort(n?e:t);for(var r=0,s=o.length;s>r;r+=1){var a=o[r];(a.options.continuous||r===o.length-1)&&a.trigger([i])}}this.clearTriggerQueues()},i.prototype.next=function(e){this.waypoints.sort(t);var i=n.Adapter.inArray(e,this.waypoints),o=i===this.waypoints.length-1;return o?null:this.waypoints[i+1]},i.prototype.previous=function(e){this.waypoints.sort(t);var i=n.Adapter.inArray(e,this.waypoints);return i?this.waypoints[i-1]:null},i.prototype.queueTrigger=function(t,e){this.triggerQueues[e].push(t)},i.prototype.remove=function(t){var e=n.Adapter.inArray(t,this.waypoints);e>-1&&this.waypoints.splice(e,1)},i.prototype.first=function(){return this.waypoints[0]},i.prototype.last=function(){return this.waypoints[this.waypoints.length-1]},i.findOrCreate=function(t){return o[t.axis][t.name]||new i(t)},n.Group=i}(),function(){"use strict";function t(t){this.element=t,this.$element=e(t)}var e=window.Zepto,i=window.Waypoint;e.each(["off","on","scrollLeft","scrollTop"],function(e,i){t.prototype[i]=function(){var t=Array.prototype.slice.call(arguments);return this.$element[i].apply(this.$element,t)}}),t.prototype.offset=function(){return this.element!==this.element.window?this.$element.offset():void 0},e.each(["width","height"],function(i,o){function n(t,i){return function(t){var n=this.$element,r=n[o](),s={width:["left","right"],height:["top","bottom"]};return e.each(s[o],function(e,o){r+=parseInt(n.css("padding-"+o),10),i&&(r+=parseInt(n.css("border-"+o+"-width"),10)),t&&(r+=parseInt(n.css("margin-"+o),10))}),r}}var r=e.camelCase("inner-"+o),s=e.camelCase("outer-"+o);t.prototype[r]=n(!1),t.prototype[s]=n(!0)}),e.each(["extend","inArray"],function(i,o){t[o]=e[o]}),t.isEmptyObject=function(t){for(var e in t)return!1;return!0},i.adapters.push({name:"zepto",Adapter:t}),i.Adapter=t}(),function(){"use strict";function t(t){return function(){var i=[],o=arguments[0];return t.isFunction(arguments[0])&&(o=t.extend({},arguments[1]),o.handler=arguments[0]),this.each(function(){var n=t.extend({},o,{element:this});"string"==typeof n.context&&(n.context=t(this).closest(n.context)[0]),i.push(new e(n))}),i}}var e=window.Waypoint;window.jQuery&&(window.jQuery.fn.waypoint=t(window.jQuery)),window.Zepto&&(window.Zepto.fn.waypoint=t(window.Zepto))}(); \ No newline at end of file +!function(){"use strict";function t(o){if(!o)throw new Error("No options passed to Waypoint constructor");if(!o.element)throw new Error("No element option passed to Waypoint constructor");if(!o.handler)throw new Error("No handler option passed to Waypoint constructor");this.key="waypoint-"+e,this.options=t.Adapter.extend({},t.defaults,o),this.element=this.options.element,this.adapter=new t.Adapter(this.element),this.callback=o.handler,this.axis=this.options.horizontal?"horizontal":"vertical",this.enabled=this.options.enabled,this.triggerPoint=null,this.group=t.Group.findOrCreate({name:this.options.group,axis:this.axis}),this.context=t.Context.findOrCreateByElement(this.options.context),t.offsetAliases[this.options.offset]&&(this.options.offset=t.offsetAliases[this.options.offset]),this.group.add(this),this.context.add(this),i[this.key]=this,e+=1}var e=0,i={};t.prototype.queueTrigger=function(t){this.group.queueTrigger(this,t)},t.prototype.trigger=function(t){this.enabled&&this.callback&&this.callback.apply(this,t)},t.prototype.destroy=function(){this.context.remove(this),this.group.remove(this),delete i[this.key]},t.prototype.disable=function(){return this.enabled=!1,this},t.prototype.enable=function(){return this.context.refresh(),this.enabled=!0,this},t.prototype.next=function(){return this.group.next(this)},t.prototype.previous=function(){return this.group.previous(this)},t.invokeAll=function(t){var e=[];for(var o in i)e.push(i[o]);for(var n=0,r=e.length;r>n;n++)e[n][t]()},t.destroyAll=function(){t.invokeAll("destroy")},t.disableAll=function(){t.invokeAll("disable")},t.enableAll=function(){t.invokeAll("enable")},t.refreshAll=function(){t.Context.refreshAll()},t.viewportHeight=function(){return window.innerHeight||document.documentElement.clientHeight},t.viewportWidth=function(){return document.documentElement.clientWidth},t.adapters=[],t.defaults={context:window,continuous:!0,enabled:!0,group:"default",horizontal:!1,offset:0},t.offsetAliases={"bottom-in-view":function(){return this.context.innerHeight()-this.adapter.outerHeight()},"right-in-view":function(){return this.context.innerWidth()-this.adapter.outerWidth()}},window.Waypoint=t}(),function(){"use strict";function t(t){window.setTimeout(t,1e3/60)}function e(t){this.element=t,this.Adapter=n.Adapter,this.adapter=new this.Adapter(t),this.key="waypoint-context-"+i,this.didScroll=!1,this.didResize=!1,this.oldScroll={x:this.adapter.scrollLeft(),y:this.adapter.scrollTop()},this.waypoints={vertical:{},horizontal:{}},t.waypointContextKey=this.key,o[t.waypointContextKey]=this,i+=1,this.createThrottledScrollHandler(),this.createThrottledResizeHandler()}var i=0,o={},n=window.Waypoint,r=window.onload;e.prototype.add=function(t){var e=t.options.horizontal?"horizontal":"vertical";this.waypoints[e][t.key]=t,this.refresh()},e.prototype.checkEmpty=function(){var t=this.Adapter.isEmptyObject(this.waypoints.horizontal),e=this.Adapter.isEmptyObject(this.waypoints.vertical);t&&e&&(this.adapter.off(".waypoints"),delete o[this.key])},e.prototype.createThrottledResizeHandler=function(){function t(){e.handleResize(),e.didResize=!1}var e=this;this.adapter.on("resize.waypoints",function(){e.didResize||(e.didResize=!0,n.requestAnimationFrame(t))})},e.prototype.createThrottledScrollHandler=function(){function t(){e.handleScroll(),e.didScroll=!1}var e=this;this.adapter.on("scroll.waypoints",function(){(!e.didScroll||n.isTouch)&&(e.didScroll=!0,n.requestAnimationFrame(t))})},e.prototype.handleResize=function(){n.Context.refreshAll()},e.prototype.handleScroll=function(){var t={},e={horizontal:{newScroll:this.adapter.scrollLeft(),oldScroll:this.oldScroll.x,forward:"right",backward:"left"},vertical:{newScroll:this.adapter.scrollTop(),oldScroll:this.oldScroll.y,forward:"down",backward:"up"}};for(var i in e){var o=e[i],n=o.newScroll>o.oldScroll,r=n?o.forward:o.backward;for(var s in this.waypoints[i]){var a=this.waypoints[i][s],l=o.oldScroll=a.triggerPoint,p=l&&h,c=!l&&!h;(p||c)&&(a.queueTrigger(r),t[a.group.id]=a.group)}}for(var u in t)t[u].flushTriggers();this.oldScroll={x:e.horizontal.newScroll,y:e.vertical.newScroll}},e.prototype.innerHeight=function(){return this.element==this.element.window?n.viewportHeight():this.adapter.innerHeight()},e.prototype.remove=function(t){delete this.waypoints[t.axis][t.key],this.checkEmpty()},e.prototype.innerWidth=function(){return this.element==this.element.window?n.viewportWidth():this.adapter.innerWidth()},e.prototype.destroy=function(){var t=[];for(var e in this.waypoints)for(var i in this.waypoints[e])t.push(this.waypoints[e][i]);for(var o=0,n=t.length;n>o;o++)t[o].destroy()},e.prototype.refresh=function(){var t,e=this.element==this.element.window,i=this.adapter.offset(),o={};this.handleScroll(),t={horizontal:{contextOffset:e?0:i.left,contextScroll:e?0:this.oldScroll.x,contextDimension:this.innerWidth(),oldScroll:this.oldScroll.x,forward:"right",backward:"left",offsetProp:"left"},vertical:{contextOffset:e?0:i.top,contextScroll:e?0:this.oldScroll.y,contextDimension:this.innerHeight(),oldScroll:this.oldScroll.y,forward:"down",backward:"up",offsetProp:"top"}};for(var r in t){var s=t[r];for(var a in this.waypoints[r]){var l,h,p,c,u,d=this.waypoints[r][a],f=d.options.offset,w=d.triggerPoint,y=0,g=null==w;d.element!==d.element.window&&(y=d.adapter.offset()[s.offsetProp]),"function"==typeof f?f=f.apply(d):"string"==typeof f&&(f=parseFloat(f),d.options.offset.indexOf("%")>-1&&(f=Math.ceil(s.contextDimension*f/100))),l=s.contextScroll-s.contextOffset,d.triggerPoint=y+l-f,h=w=s.oldScroll,c=h&&p,u=!h&&!p,!g&&c?(d.queueTrigger(s.backward),o[d.group.id]=d.group):!g&&u?(d.queueTrigger(s.forward),o[d.group.id]=d.group):g&&s.oldScroll>=d.triggerPoint&&(d.queueTrigger(s.forward),o[d.group.id]=d.group)}}return n.requestAnimationFrame(function(){for(var t in o)o[t].flushTriggers()}),this},e.findOrCreateByElement=function(t){return e.findByElement(t)||new e(t)},e.refreshAll=function(){for(var t in o)o[t].refresh()},e.findByElement=function(t){return o[t.waypointContextKey]},window.onload=function(){r&&r(),e.refreshAll()},n.requestAnimationFrame=function(e){var i=window.requestAnimationFrame||window.mozRequestAnimationFrame||window.webkitRequestAnimationFrame||t;i.call(window,e)},n.Context=e}(),function(){"use strict";function t(t,e){return t.triggerPoint-e.triggerPoint}function e(t,e){return e.triggerPoint-t.triggerPoint}function i(t){this.name=t.name,this.axis=t.axis,this.id=this.name+"-"+this.axis,this.waypoints=[],this.clearTriggerQueues(),o[this.axis][this.name]=this}var o={vertical:{},horizontal:{}},n=window.Waypoint;i.prototype.add=function(t){this.waypoints.push(t)},i.prototype.clearTriggerQueues=function(){this.triggerQueues={up:[],down:[],left:[],right:[]}},i.prototype.flushTriggers=function(){for(var i in this.triggerQueues){var o=this.triggerQueues[i],n="up"===i||"left"===i;o.sort(n?e:t);for(var r=0,s=o.length;s>r;r+=1){var a=o[r];(a.options.continuous||r===o.length-1)&&a.trigger([i])}}this.clearTriggerQueues()},i.prototype.next=function(e){this.waypoints.sort(t);var i=n.Adapter.inArray(e,this.waypoints),o=i===this.waypoints.length-1;return o?null:this.waypoints[i+1]},i.prototype.previous=function(e){this.waypoints.sort(t);var i=n.Adapter.inArray(e,this.waypoints);return i?this.waypoints[i-1]:null},i.prototype.queueTrigger=function(t,e){this.triggerQueues[e].push(t)},i.prototype.remove=function(t){var e=n.Adapter.inArray(t,this.waypoints);e>-1&&this.waypoints.splice(e,1)},i.prototype.first=function(){return this.waypoints[0]},i.prototype.last=function(){return this.waypoints[this.waypoints.length-1]},i.findOrCreate=function(t){return o[t.axis][t.name]||new i(t)},n.Group=i}(),function(){"use strict";function t(t){this.element=t,this.$element=e(t)}var e=window.Zepto,i=window.Waypoint;e.each(["off","on","scrollLeft","scrollTop"],function(e,i){t.prototype[i]=function(){var t=Array.prototype.slice.call(arguments);return this.$element[i].apply(this.$element,t)}}),t.prototype.offset=function(){return this.element!==this.element.window?this.$element.offset():void 0},e.each(["width","height"],function(i,o){function n(t,i){return function(t){var n=this.$element,r=n[o](),s={width:["left","right"],height:["top","bottom"]};return e.each(s[o],function(e,o){r+=parseInt(n.css("padding-"+o),10),i&&(r+=parseInt(n.css("border-"+o+"-width"),10)),t&&(r+=parseInt(n.css("margin-"+o),10))}),r}}var r=e.camelCase("inner-"+o),s=e.camelCase("outer-"+o);t.prototype[r]=n(!1),t.prototype[s]=n(!0)}),e.each(["extend","inArray"],function(i,o){t[o]=e[o]}),t.isEmptyObject=function(t){for(var e in t)return!1;return!0},i.adapters.push({name:"zepto",Adapter:t}),i.Adapter=t}(),function(){"use strict";function t(t){return function(){var i=[],o=arguments[0];return t.isFunction(arguments[0])&&(o=t.extend({},arguments[1]),o.handler=arguments[0]),this.each(function(){var n=t.extend({},o,{element:this});"string"==typeof n.context&&(n.context=t(this).closest(n.context)[0]),i.push(new e(n))}),i}}var e=window.Waypoint;window.jQuery&&(window.jQuery.fn.waypoint=t(window.jQuery)),window.Zepto&&(window.Zepto.fn.waypoint=t(window.Zepto))}(); \ No newline at end of file diff --git a/src/context.js b/src/context.js index 185efae3..b7276c6b 100644 --- a/src/context.js +++ b/src/context.js @@ -255,9 +255,11 @@ } } - for (var groupKey in triggeredGroups) { - triggeredGroups[groupKey].flushTriggers() - } + Waypoint.requestAnimationFrame(function() { + for (var groupKey in triggeredGroups) { + triggeredGroups[groupKey].flushTriggers() + } + }) return this } From 5ed938b5de4da0f5929a5b2f7b33b4816118b4f0 Mon Sep 17 00:00:00 2001 From: imakewebthings Date: Mon, 17 Aug 2015 22:08:45 -0700 Subject: [PATCH 86/98] Cleanup infinite test suite from pull #398 --- CHANGELOG.md | 2 ++ test/infinite-spec.js | 1 - 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index b90b9c81..f373884c 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -3,6 +3,8 @@ ## v4.0.0 - Allow Sticky option `wrapper` to accept false, which will not create a wrapper and instead use the preexisting parent element. (Pull #416) +- Waypoints that are immediately triggered on creation because they've already passed their trigger point now run their handlers on the next animation frame. This contains Zalgo. +- Pass the jQuery object of items added during an Infinite page load to the `onAfterPageLoad` callback. (Pull #398) ## v3.1.1 diff --git a/test/infinite-spec.js b/test/infinite-spec.js index 5c54208d..1cc92aa5 100644 --- a/test/infinite-spec.js +++ b/test/infinite-spec.js @@ -55,7 +55,6 @@ describe('Waypoint Sticky Shortcut', function() { it('fires the after callback', function() { expect(afterSpy.callCount).toBeTruthy() - expect(afterSpy.mostRecentCall.args.length).toEqual(1); expect(afterSpy).toHaveBeenCalledWith(jasmine.any(Object)) }) }) From e91cb6328349e9881e4f7f6f79d14acf6279b09b Mon Sep 17 00:00:00 2001 From: imakewebthings Date: Mon, 17 Aug 2015 22:46:04 -0700 Subject: [PATCH 87/98] Cleanup pull #406 --- lib/shortcuts/inview.js | 9 +++++---- lib/shortcuts/inview.min.js | 8 +++++++- src/shortcuts/inview.js | 14 ++++++++++++++ test/inview-spec.js | 38 +++++++++++++++++++++++++++++++++++++ 4 files changed, 64 insertions(+), 5 deletions(-) diff --git a/lib/shortcuts/inview.js b/lib/shortcuts/inview.js index 78f1e7ac..c4488c2a 100644 --- a/lib/shortcuts/inview.js +++ b/lib/shortcuts/inview.js @@ -73,14 +73,14 @@ https://github.com/imakewebthings/waypoints/blog/master/licenses.txt var self = this this.waypoints.push(new Waypoint({ element: this.options.element, + enabled: this.options.enabled, handler: (function(config) { return function(direction) { self.options[config[direction]].call(this, direction) } }(config)), offset: config.offset, - horizontal: this.options.horizontal, - enabled: this.options.enabled + horizontal: this.options.horizontal })) } @@ -91,13 +91,13 @@ https://github.com/imakewebthings/waypoints/blog/master/licenses.txt } this.waypoints = [] } - + Inview.prototype.disable = function() { for (var i = 0, end = this.waypoints.length; i < end; i++) { this.waypoints[i].disable() } } - + Inview.prototype.enable = function() { for (var i = 0, end = this.waypoints.length; i < end; i++) { this.waypoints[i].enable() @@ -105,6 +105,7 @@ https://github.com/imakewebthings/waypoints/blog/master/licenses.txt } Inview.defaults = { + enabled: true, enter: noop, entered: noop, exit: noop, diff --git a/lib/shortcuts/inview.min.js b/lib/shortcuts/inview.min.js index aad0f34c..3ea656fe 100644 --- a/lib/shortcuts/inview.min.js +++ b/lib/shortcuts/inview.min.js @@ -1 +1,7 @@ -!function(){"use strict";function t(){}function e(t){this.options=i.Adapter.extend({},e.defaults,t),this.axis=this.options.horizontal?"horizontal":"vertical",this.waypoints=[],this.createWaypoints()}var i=window.Waypoint;e.prototype.createWaypoints=function(){for(var t={vertical:[{down:"enter",up:"exited",offset:"100%"},{down:"entered",up:"exit",offset:"bottom-in-view"},{down:"exit",up:"entered",offset:0},{down:"exited",up:"enter",offset:function(){return-this.adapter.outerHeight()}}],horizontal:[{right:"enter",left:"exited",offset:"100%"},{right:"entered",left:"exit",offset:"right-in-view"},{right:"exit",left:"entered",offset:0},{right:"exited",left:"enter",offset:function(){return-this.adapter.outerWidth()}}]},e=0,i=t[this.axis].length;i>e;e++){var n=t[this.axis][e];this.createWaypoint(n)}},e.prototype.createWaypoint=function(t){var e=this;this.waypoints.push(new i({element:this.options.element,handler:function(t){return function(i){e.options[t[i]].call(this,i)}}(t),offset:t.offset,horizontal:this.options.horizontal,enabled:this.options.enabled}))},e.prototype.destroy=function(){for(var t=0,e=this.waypoints.length;e>t;t++)this.waypoints[t].destroy();this.waypoints=[]},e.prototype.disable=function(){for(var t=0,e=this.waypoints.length;e>t;t++)this.waypoints[t].disable()},e.prototype.enable=function(){for(var t=0,e=this.waypoints.length;e>t;t++)this.waypoints[t].enable()},e.defaults={enter:t,entered:t,exit:t,exited:t},i.Inview=e}(); +/*! +Waypoints Inview Shortcut - 3.1.1 +Copyright © 2011-2015 Caleb Troughton +Licensed under the MIT license. +https://github.com/imakewebthings/waypoints/blog/master/licenses.txt +*/ +!function(){"use strict";function t(){}function e(t){this.options=i.Adapter.extend({},e.defaults,t),this.axis=this.options.horizontal?"horizontal":"vertical",this.waypoints=[],this.createWaypoints()}var i=window.Waypoint;e.prototype.createWaypoints=function(){for(var t={vertical:[{down:"enter",up:"exited",offset:"100%"},{down:"entered",up:"exit",offset:"bottom-in-view"},{down:"exit",up:"entered",offset:0},{down:"exited",up:"enter",offset:function(){return-this.adapter.outerHeight()}}],horizontal:[{right:"enter",left:"exited",offset:"100%"},{right:"entered",left:"exit",offset:"right-in-view"},{right:"exit",left:"entered",offset:0},{right:"exited",left:"enter",offset:function(){return-this.adapter.outerWidth()}}]},e=0,i=t[this.axis].length;i>e;e++){var n=t[this.axis][e];this.createWaypoint(n)}},e.prototype.createWaypoint=function(t){var e=this;this.waypoints.push(new i({element:this.options.element,enabled:this.options.enabled,handler:function(t){return function(i){e.options[t[i]].call(this,i)}}(t),offset:t.offset,horizontal:this.options.horizontal}))},e.prototype.destroy=function(){for(var t=0,e=this.waypoints.length;e>t;t++)this.waypoints[t].destroy();this.waypoints=[]},e.prototype.disable=function(){for(var t=0,e=this.waypoints.length;e>t;t++)this.waypoints[t].disable()},e.prototype.enable=function(){for(var t=0,e=this.waypoints.length;e>t;t++)this.waypoints[t].enable()},e.defaults={enabled:!0,enter:t,entered:t,exit:t,exited:t},i.Inview=e}(); \ No newline at end of file diff --git a/src/shortcuts/inview.js b/src/shortcuts/inview.js index 45d18c99..5e25ee3d 100644 --- a/src/shortcuts/inview.js +++ b/src/shortcuts/inview.js @@ -67,6 +67,7 @@ var self = this this.waypoints.push(new Waypoint({ element: this.options.element, + enabled: this.options.enabled, handler: (function(config) { return function(direction) { self.options[config[direction]].call(this, direction) @@ -85,7 +86,20 @@ this.waypoints = [] } + Inview.prototype.disable = function() { + for (var i = 0, end = this.waypoints.length; i < end; i++) { + this.waypoints[i].disable() + } + } + + Inview.prototype.enable = function() { + for (var i = 0, end = this.waypoints.length; i < end; i++) { + this.waypoints[i].enable() + } + } + Inview.defaults = { + enabled: true, enter: noop, entered: noop, exit: noop, diff --git a/test/inview-spec.js b/test/inview-spec.js index 5bd94160..889703c8 100644 --- a/test/inview-spec.js +++ b/test/inview-spec.js @@ -243,6 +243,44 @@ window.jQuery.each(Waypoint.adapters, function(i, adapter) { }) }) }) + + describe('disabled', function() { + beforeEach(function() { + waypoint = new Waypoint.Inview({ + element: $target[0], + enabled: false, + enter: setsTrue('enter'), + entered: setsTrue('entered'), + exit: setsTrue('exit'), + exited: setsTrue('exited') + }) + }) + + it('starts disabled', function() { + $.each(waypoint.waypoints, function(i, wp) { + expect(wp.enabled).toEqual(false) + }) + }) + + describe('#enable', function() { + it('enables all waypoints', function() { + waypoint.enable() + $.each(waypoint.waypoints, function(i, wp) { + expect(wp.enabled).toEqual(true) + }) + }) + }) + + describe('#disable', function() { + it('disables all waypoints', function() { + waypoint.enable() + waypoint.disable() + $.each(waypoint.waypoints, function(i, wp) { + expect(wp.enabled).toEqual(false) + }) + }) + }) + }) }) }) }) From 0589259ebbb64778580be9ebec311256895ac616 Mon Sep 17 00:00:00 2001 From: imakewebthings Date: Mon, 17 Aug 2015 22:56:46 -0700 Subject: [PATCH 88/98] Make Inview instance this within callbacks, fixes #412 --- CHANGELOG.md | 4 +++- lib/shortcuts/inview.js | 2 +- lib/shortcuts/inview.min.js | 2 +- src/shortcuts/inview.js | 2 +- test/inview-spec.js | 15 ++++++++++++++- 5 files changed, 20 insertions(+), 5 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index f373884c..78781a53 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -3,8 +3,10 @@ ## v4.0.0 - Allow Sticky option `wrapper` to accept false, which will not create a wrapper and instead use the preexisting parent element. (Pull #416) -- Waypoints that are immediately triggered on creation because they've already passed their trigger point now run their handlers on the next animation frame. This contains Zalgo. +- Waypoints that are immediately triggered on creation because they've already passed their trigger point now run their handlers on the next animation frame. This contains Zalgo. (Issue #384) - Pass the jQuery object of items added during an Infinite page load to the `onAfterPageLoad` callback. (Pull #398) +- Add `enabled` option, `enable` and `disable` methods to the Inview shortcut (Pull #406) +- Make the Inview instance `this` within the callbacks, rather than the invdividual underlying waypoints. (Issue #412) ## v3.1.1 diff --git a/lib/shortcuts/inview.js b/lib/shortcuts/inview.js index c4488c2a..da963b48 100644 --- a/lib/shortcuts/inview.js +++ b/lib/shortcuts/inview.js @@ -76,7 +76,7 @@ https://github.com/imakewebthings/waypoints/blog/master/licenses.txt enabled: this.options.enabled, handler: (function(config) { return function(direction) { - self.options[config[direction]].call(this, direction) + self.options[config[direction]].call(self, direction) } }(config)), offset: config.offset, diff --git a/lib/shortcuts/inview.min.js b/lib/shortcuts/inview.min.js index 3ea656fe..b6d5c33e 100644 --- a/lib/shortcuts/inview.min.js +++ b/lib/shortcuts/inview.min.js @@ -4,4 +4,4 @@ Copyright © 2011-2015 Caleb Troughton Licensed under the MIT license. https://github.com/imakewebthings/waypoints/blog/master/licenses.txt */ -!function(){"use strict";function t(){}function e(t){this.options=i.Adapter.extend({},e.defaults,t),this.axis=this.options.horizontal?"horizontal":"vertical",this.waypoints=[],this.createWaypoints()}var i=window.Waypoint;e.prototype.createWaypoints=function(){for(var t={vertical:[{down:"enter",up:"exited",offset:"100%"},{down:"entered",up:"exit",offset:"bottom-in-view"},{down:"exit",up:"entered",offset:0},{down:"exited",up:"enter",offset:function(){return-this.adapter.outerHeight()}}],horizontal:[{right:"enter",left:"exited",offset:"100%"},{right:"entered",left:"exit",offset:"right-in-view"},{right:"exit",left:"entered",offset:0},{right:"exited",left:"enter",offset:function(){return-this.adapter.outerWidth()}}]},e=0,i=t[this.axis].length;i>e;e++){var n=t[this.axis][e];this.createWaypoint(n)}},e.prototype.createWaypoint=function(t){var e=this;this.waypoints.push(new i({element:this.options.element,enabled:this.options.enabled,handler:function(t){return function(i){e.options[t[i]].call(this,i)}}(t),offset:t.offset,horizontal:this.options.horizontal}))},e.prototype.destroy=function(){for(var t=0,e=this.waypoints.length;e>t;t++)this.waypoints[t].destroy();this.waypoints=[]},e.prototype.disable=function(){for(var t=0,e=this.waypoints.length;e>t;t++)this.waypoints[t].disable()},e.prototype.enable=function(){for(var t=0,e=this.waypoints.length;e>t;t++)this.waypoints[t].enable()},e.defaults={enabled:!0,enter:t,entered:t,exit:t,exited:t},i.Inview=e}(); \ No newline at end of file +!function(){"use strict";function t(){}function e(t){this.options=i.Adapter.extend({},e.defaults,t),this.axis=this.options.horizontal?"horizontal":"vertical",this.waypoints=[],this.createWaypoints()}var i=window.Waypoint;e.prototype.createWaypoints=function(){for(var t={vertical:[{down:"enter",up:"exited",offset:"100%"},{down:"entered",up:"exit",offset:"bottom-in-view"},{down:"exit",up:"entered",offset:0},{down:"exited",up:"enter",offset:function(){return-this.adapter.outerHeight()}}],horizontal:[{right:"enter",left:"exited",offset:"100%"},{right:"entered",left:"exit",offset:"right-in-view"},{right:"exit",left:"entered",offset:0},{right:"exited",left:"enter",offset:function(){return-this.adapter.outerWidth()}}]},e=0,i=t[this.axis].length;i>e;e++){var n=t[this.axis][e];this.createWaypoint(n)}},e.prototype.createWaypoint=function(t){var e=this;this.waypoints.push(new i({element:this.options.element,enabled:this.options.enabled,handler:function(t){return function(i){e.options[t[i]].call(e,i)}}(t),offset:t.offset,horizontal:this.options.horizontal}))},e.prototype.destroy=function(){for(var t=0,e=this.waypoints.length;e>t;t++)this.waypoints[t].destroy();this.waypoints=[]},e.prototype.disable=function(){for(var t=0,e=this.waypoints.length;e>t;t++)this.waypoints[t].disable()},e.prototype.enable=function(){for(var t=0,e=this.waypoints.length;e>t;t++)this.waypoints[t].enable()},e.defaults={enabled:!0,enter:t,entered:t,exit:t,exited:t},i.Inview=e}(); \ No newline at end of file diff --git a/src/shortcuts/inview.js b/src/shortcuts/inview.js index 5e25ee3d..b1b540b1 100644 --- a/src/shortcuts/inview.js +++ b/src/shortcuts/inview.js @@ -70,7 +70,7 @@ enabled: this.options.enabled, handler: (function(config) { return function(direction) { - self.options[config[direction]].call(this, direction) + self.options[config[direction]].call(self, direction) } }(config)), offset: config.offset, diff --git a/test/inview-spec.js b/test/inview-spec.js index 889703c8..c08c85c9 100644 --- a/test/inview-spec.js +++ b/test/inview-spec.js @@ -10,10 +10,11 @@ window.jQuery.each(Waypoint.adapters, function(i, adapter) { var $ = window.jQuery var standard = 50 var $scroller = $(window) - var $target, waypoint, hits + var $target, waypoint, hits, callbackContext function setsTrue(key) { return function() { + callbackContext = this hits[key] = true } } @@ -54,6 +55,9 @@ window.jQuery.each(Waypoint.adapters, function(i, adapter) { $scroller.scrollTop(top - Waypoint.viewportHeight()) }) waitsFor(toBeTrue('enter'), 'enter to trigger') + runs(function() { + expect(callbackContext).toEqual(waypoint) + }) }) it('triggers when element starts entering from above', function() { @@ -78,6 +82,9 @@ window.jQuery.each(Waypoint.adapters, function(i, adapter) { $scroller.scrollTop(top - viewportHeight + elementHeight) }) waitsFor(toBeTrue('entered'), 'entered to trigger') + runs(function() { + expect(callbackContext).toEqual(waypoint) + }) }) it('triggers when element finishes entering from above', function() { @@ -114,6 +121,9 @@ window.jQuery.each(Waypoint.adapters, function(i, adapter) { $scroller.scrollTop($target.offset().top) }) waitsFor(toBeTrue('exit'), 'exit to trigger') + runs(function() { + expect(callbackContext).toEqual(waypoint) + }) }) }) @@ -135,6 +145,9 @@ window.jQuery.each(Waypoint.adapters, function(i, adapter) { $scroller.scrollTop($target.offset().top + $target.outerHeight()) }) waitsFor(toBeTrue('exited'), 'exited to trigger') + runs(function() { + expect(callbackContext).toEqual(waypoint) + }) }) }) }) From 9e6465c243c2f68e1ad911a14358b709631d8d98 Mon Sep 17 00:00:00 2001 From: imakewebthings Date: Mon, 17 Aug 2015 23:15:13 -0700 Subject: [PATCH 89/98] Add context option to Inview, fixes #433 --- CHANGELOG.md | 2 ++ lib/jquery.waypoints.js | 2 +- lib/jquery.waypoints.min.js | 2 +- lib/noframework.waypoints.js | 2 +- lib/noframework.waypoints.min.js | 2 +- lib/shortcuts/inview.js | 2 ++ lib/shortcuts/inview.min.js | 2 +- lib/zepto.waypoints.js | 2 +- lib/zepto.waypoints.min.js | 2 +- src/shortcuts/inview.js | 2 ++ 10 files changed, 13 insertions(+), 7 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 78781a53..f35c9789 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -7,6 +7,8 @@ - Pass the jQuery object of items added during an Infinite page load to the `onAfterPageLoad` callback. (Pull #398) - Add `enabled` option, `enable` and `disable` methods to the Inview shortcut (Pull #406) - Make the Inview instance `this` within the callbacks, rather than the invdividual underlying waypoints. (Issue #412) +- Account for changes to jQuery 3 around calling `offset` on the window. (Pull #430) +- Add `context` option to Inview. (Issue #433) ## v3.1.1 diff --git a/lib/jquery.waypoints.js b/lib/jquery.waypoints.js index 27d39b22..f89a374f 100644 --- a/lib/jquery.waypoints.js +++ b/lib/jquery.waypoints.js @@ -348,7 +348,7 @@ https://github.com/imakewebthings/waypoints/blog/master/licenses.txt /*eslint-disable eqeqeq */ var isWindow = this.element == this.element.window /*eslint-enable eqeqeq */ - var contextOffset = this.adapter.offset() + var contextOffset = isWindow ? undefined : this.adapter.offset() var triggeredGroups = {} var axes diff --git a/lib/jquery.waypoints.min.js b/lib/jquery.waypoints.min.js index fc8e2885..4b8c85cd 100644 --- a/lib/jquery.waypoints.min.js +++ b/lib/jquery.waypoints.min.js @@ -4,4 +4,4 @@ Copyright © 2011-2015 Caleb Troughton Licensed under the MIT license. https://github.com/imakewebthings/waypoints/blog/master/licenses.txt */ -!function(){"use strict";function t(o){if(!o)throw new Error("No options passed to Waypoint constructor");if(!o.element)throw new Error("No element option passed to Waypoint constructor");if(!o.handler)throw new Error("No handler option passed to Waypoint constructor");this.key="waypoint-"+e,this.options=t.Adapter.extend({},t.defaults,o),this.element=this.options.element,this.adapter=new t.Adapter(this.element),this.callback=o.handler,this.axis=this.options.horizontal?"horizontal":"vertical",this.enabled=this.options.enabled,this.triggerPoint=null,this.group=t.Group.findOrCreate({name:this.options.group,axis:this.axis}),this.context=t.Context.findOrCreateByElement(this.options.context),t.offsetAliases[this.options.offset]&&(this.options.offset=t.offsetAliases[this.options.offset]),this.group.add(this),this.context.add(this),i[this.key]=this,e+=1}var e=0,i={};t.prototype.queueTrigger=function(t){this.group.queueTrigger(this,t)},t.prototype.trigger=function(t){this.enabled&&this.callback&&this.callback.apply(this,t)},t.prototype.destroy=function(){this.context.remove(this),this.group.remove(this),delete i[this.key]},t.prototype.disable=function(){return this.enabled=!1,this},t.prototype.enable=function(){return this.context.refresh(),this.enabled=!0,this},t.prototype.next=function(){return this.group.next(this)},t.prototype.previous=function(){return this.group.previous(this)},t.invokeAll=function(t){var e=[];for(var o in i)e.push(i[o]);for(var n=0,r=e.length;r>n;n++)e[n][t]()},t.destroyAll=function(){t.invokeAll("destroy")},t.disableAll=function(){t.invokeAll("disable")},t.enableAll=function(){t.invokeAll("enable")},t.refreshAll=function(){t.Context.refreshAll()},t.viewportHeight=function(){return window.innerHeight||document.documentElement.clientHeight},t.viewportWidth=function(){return document.documentElement.clientWidth},t.adapters=[],t.defaults={context:window,continuous:!0,enabled:!0,group:"default",horizontal:!1,offset:0},t.offsetAliases={"bottom-in-view":function(){return this.context.innerHeight()-this.adapter.outerHeight()},"right-in-view":function(){return this.context.innerWidth()-this.adapter.outerWidth()}},window.Waypoint=t}(),function(){"use strict";function t(t){window.setTimeout(t,1e3/60)}function e(t){this.element=t,this.Adapter=n.Adapter,this.adapter=new this.Adapter(t),this.key="waypoint-context-"+i,this.didScroll=!1,this.didResize=!1,this.oldScroll={x:this.adapter.scrollLeft(),y:this.adapter.scrollTop()},this.waypoints={vertical:{},horizontal:{}},t.waypointContextKey=this.key,o[t.waypointContextKey]=this,i+=1,this.createThrottledScrollHandler(),this.createThrottledResizeHandler()}var i=0,o={},n=window.Waypoint,r=window.onload;e.prototype.add=function(t){var e=t.options.horizontal?"horizontal":"vertical";this.waypoints[e][t.key]=t,this.refresh()},e.prototype.checkEmpty=function(){var t=this.Adapter.isEmptyObject(this.waypoints.horizontal),e=this.Adapter.isEmptyObject(this.waypoints.vertical);t&&e&&(this.adapter.off(".waypoints"),delete o[this.key])},e.prototype.createThrottledResizeHandler=function(){function t(){e.handleResize(),e.didResize=!1}var e=this;this.adapter.on("resize.waypoints",function(){e.didResize||(e.didResize=!0,n.requestAnimationFrame(t))})},e.prototype.createThrottledScrollHandler=function(){function t(){e.handleScroll(),e.didScroll=!1}var e=this;this.adapter.on("scroll.waypoints",function(){(!e.didScroll||n.isTouch)&&(e.didScroll=!0,n.requestAnimationFrame(t))})},e.prototype.handleResize=function(){n.Context.refreshAll()},e.prototype.handleScroll=function(){var t={},e={horizontal:{newScroll:this.adapter.scrollLeft(),oldScroll:this.oldScroll.x,forward:"right",backward:"left"},vertical:{newScroll:this.adapter.scrollTop(),oldScroll:this.oldScroll.y,forward:"down",backward:"up"}};for(var i in e){var o=e[i],n=o.newScroll>o.oldScroll,r=n?o.forward:o.backward;for(var s in this.waypoints[i]){var a=this.waypoints[i][s],l=o.oldScroll=a.triggerPoint,p=l&&h,u=!l&&!h;(p||u)&&(a.queueTrigger(r),t[a.group.id]=a.group)}}for(var c in t)t[c].flushTriggers();this.oldScroll={x:e.horizontal.newScroll,y:e.vertical.newScroll}},e.prototype.innerHeight=function(){return this.element==this.element.window?n.viewportHeight():this.adapter.innerHeight()},e.prototype.remove=function(t){delete this.waypoints[t.axis][t.key],this.checkEmpty()},e.prototype.innerWidth=function(){return this.element==this.element.window?n.viewportWidth():this.adapter.innerWidth()},e.prototype.destroy=function(){var t=[];for(var e in this.waypoints)for(var i in this.waypoints[e])t.push(this.waypoints[e][i]);for(var o=0,n=t.length;n>o;o++)t[o].destroy()},e.prototype.refresh=function(){var t,e=this.element==this.element.window,i=this.adapter.offset(),o={};this.handleScroll(),t={horizontal:{contextOffset:e?0:i.left,contextScroll:e?0:this.oldScroll.x,contextDimension:this.innerWidth(),oldScroll:this.oldScroll.x,forward:"right",backward:"left",offsetProp:"left"},vertical:{contextOffset:e?0:i.top,contextScroll:e?0:this.oldScroll.y,contextDimension:this.innerHeight(),oldScroll:this.oldScroll.y,forward:"down",backward:"up",offsetProp:"top"}};for(var r in t){var s=t[r];for(var a in this.waypoints[r]){var l,h,p,u,c,d=this.waypoints[r][a],f=d.options.offset,w=d.triggerPoint,y=0,g=null==w;d.element!==d.element.window&&(y=d.adapter.offset()[s.offsetProp]),"function"==typeof f?f=f.apply(d):"string"==typeof f&&(f=parseFloat(f),d.options.offset.indexOf("%")>-1&&(f=Math.ceil(s.contextDimension*f/100))),l=s.contextScroll-s.contextOffset,d.triggerPoint=y+l-f,h=w=s.oldScroll,u=h&&p,c=!h&&!p,!g&&u?(d.queueTrigger(s.backward),o[d.group.id]=d.group):!g&&c?(d.queueTrigger(s.forward),o[d.group.id]=d.group):g&&s.oldScroll>=d.triggerPoint&&(d.queueTrigger(s.forward),o[d.group.id]=d.group)}}return n.requestAnimationFrame(function(){for(var t in o)o[t].flushTriggers()}),this},e.findOrCreateByElement=function(t){return e.findByElement(t)||new e(t)},e.refreshAll=function(){for(var t in o)o[t].refresh()},e.findByElement=function(t){return o[t.waypointContextKey]},window.onload=function(){r&&r(),e.refreshAll()},n.requestAnimationFrame=function(e){var i=window.requestAnimationFrame||window.mozRequestAnimationFrame||window.webkitRequestAnimationFrame||t;i.call(window,e)},n.Context=e}(),function(){"use strict";function t(t,e){return t.triggerPoint-e.triggerPoint}function e(t,e){return e.triggerPoint-t.triggerPoint}function i(t){this.name=t.name,this.axis=t.axis,this.id=this.name+"-"+this.axis,this.waypoints=[],this.clearTriggerQueues(),o[this.axis][this.name]=this}var o={vertical:{},horizontal:{}},n=window.Waypoint;i.prototype.add=function(t){this.waypoints.push(t)},i.prototype.clearTriggerQueues=function(){this.triggerQueues={up:[],down:[],left:[],right:[]}},i.prototype.flushTriggers=function(){for(var i in this.triggerQueues){var o=this.triggerQueues[i],n="up"===i||"left"===i;o.sort(n?e:t);for(var r=0,s=o.length;s>r;r+=1){var a=o[r];(a.options.continuous||r===o.length-1)&&a.trigger([i])}}this.clearTriggerQueues()},i.prototype.next=function(e){this.waypoints.sort(t);var i=n.Adapter.inArray(e,this.waypoints),o=i===this.waypoints.length-1;return o?null:this.waypoints[i+1]},i.prototype.previous=function(e){this.waypoints.sort(t);var i=n.Adapter.inArray(e,this.waypoints);return i?this.waypoints[i-1]:null},i.prototype.queueTrigger=function(t,e){this.triggerQueues[e].push(t)},i.prototype.remove=function(t){var e=n.Adapter.inArray(t,this.waypoints);e>-1&&this.waypoints.splice(e,1)},i.prototype.first=function(){return this.waypoints[0]},i.prototype.last=function(){return this.waypoints[this.waypoints.length-1]},i.findOrCreate=function(t){return o[t.axis][t.name]||new i(t)},n.Group=i}(),function(){"use strict";function t(t){this.$element=e(t)}var e=window.jQuery,i=window.Waypoint;e.each(["innerHeight","innerWidth","off","offset","on","outerHeight","outerWidth","scrollLeft","scrollTop"],function(e,i){t.prototype[i]=function(){var t=Array.prototype.slice.call(arguments);return this.$element[i].apply(this.$element,t)}}),e.each(["extend","inArray","isEmptyObject"],function(i,o){t[o]=e[o]}),i.adapters.push({name:"jquery",Adapter:t}),i.Adapter=t}(),function(){"use strict";function t(t){return function(){var i=[],o=arguments[0];return t.isFunction(arguments[0])&&(o=t.extend({},arguments[1]),o.handler=arguments[0]),this.each(function(){var n=t.extend({},o,{element:this});"string"==typeof n.context&&(n.context=t(this).closest(n.context)[0]),i.push(new e(n))}),i}}var e=window.Waypoint;window.jQuery&&(window.jQuery.fn.waypoint=t(window.jQuery)),window.Zepto&&(window.Zepto.fn.waypoint=t(window.Zepto))}(); \ No newline at end of file +!function(){"use strict";function t(o){if(!o)throw new Error("No options passed to Waypoint constructor");if(!o.element)throw new Error("No element option passed to Waypoint constructor");if(!o.handler)throw new Error("No handler option passed to Waypoint constructor");this.key="waypoint-"+e,this.options=t.Adapter.extend({},t.defaults,o),this.element=this.options.element,this.adapter=new t.Adapter(this.element),this.callback=o.handler,this.axis=this.options.horizontal?"horizontal":"vertical",this.enabled=this.options.enabled,this.triggerPoint=null,this.group=t.Group.findOrCreate({name:this.options.group,axis:this.axis}),this.context=t.Context.findOrCreateByElement(this.options.context),t.offsetAliases[this.options.offset]&&(this.options.offset=t.offsetAliases[this.options.offset]),this.group.add(this),this.context.add(this),i[this.key]=this,e+=1}var e=0,i={};t.prototype.queueTrigger=function(t){this.group.queueTrigger(this,t)},t.prototype.trigger=function(t){this.enabled&&this.callback&&this.callback.apply(this,t)},t.prototype.destroy=function(){this.context.remove(this),this.group.remove(this),delete i[this.key]},t.prototype.disable=function(){return this.enabled=!1,this},t.prototype.enable=function(){return this.context.refresh(),this.enabled=!0,this},t.prototype.next=function(){return this.group.next(this)},t.prototype.previous=function(){return this.group.previous(this)},t.invokeAll=function(t){var e=[];for(var o in i)e.push(i[o]);for(var n=0,r=e.length;r>n;n++)e[n][t]()},t.destroyAll=function(){t.invokeAll("destroy")},t.disableAll=function(){t.invokeAll("disable")},t.enableAll=function(){t.invokeAll("enable")},t.refreshAll=function(){t.Context.refreshAll()},t.viewportHeight=function(){return window.innerHeight||document.documentElement.clientHeight},t.viewportWidth=function(){return document.documentElement.clientWidth},t.adapters=[],t.defaults={context:window,continuous:!0,enabled:!0,group:"default",horizontal:!1,offset:0},t.offsetAliases={"bottom-in-view":function(){return this.context.innerHeight()-this.adapter.outerHeight()},"right-in-view":function(){return this.context.innerWidth()-this.adapter.outerWidth()}},window.Waypoint=t}(),function(){"use strict";function t(t){window.setTimeout(t,1e3/60)}function e(t){this.element=t,this.Adapter=n.Adapter,this.adapter=new this.Adapter(t),this.key="waypoint-context-"+i,this.didScroll=!1,this.didResize=!1,this.oldScroll={x:this.adapter.scrollLeft(),y:this.adapter.scrollTop()},this.waypoints={vertical:{},horizontal:{}},t.waypointContextKey=this.key,o[t.waypointContextKey]=this,i+=1,this.createThrottledScrollHandler(),this.createThrottledResizeHandler()}var i=0,o={},n=window.Waypoint,r=window.onload;e.prototype.add=function(t){var e=t.options.horizontal?"horizontal":"vertical";this.waypoints[e][t.key]=t,this.refresh()},e.prototype.checkEmpty=function(){var t=this.Adapter.isEmptyObject(this.waypoints.horizontal),e=this.Adapter.isEmptyObject(this.waypoints.vertical);t&&e&&(this.adapter.off(".waypoints"),delete o[this.key])},e.prototype.createThrottledResizeHandler=function(){function t(){e.handleResize(),e.didResize=!1}var e=this;this.adapter.on("resize.waypoints",function(){e.didResize||(e.didResize=!0,n.requestAnimationFrame(t))})},e.prototype.createThrottledScrollHandler=function(){function t(){e.handleScroll(),e.didScroll=!1}var e=this;this.adapter.on("scroll.waypoints",function(){(!e.didScroll||n.isTouch)&&(e.didScroll=!0,n.requestAnimationFrame(t))})},e.prototype.handleResize=function(){n.Context.refreshAll()},e.prototype.handleScroll=function(){var t={},e={horizontal:{newScroll:this.adapter.scrollLeft(),oldScroll:this.oldScroll.x,forward:"right",backward:"left"},vertical:{newScroll:this.adapter.scrollTop(),oldScroll:this.oldScroll.y,forward:"down",backward:"up"}};for(var i in e){var o=e[i],n=o.newScroll>o.oldScroll,r=n?o.forward:o.backward;for(var s in this.waypoints[i]){var a=this.waypoints[i][s],l=o.oldScroll=a.triggerPoint,p=l&&h,u=!l&&!h;(p||u)&&(a.queueTrigger(r),t[a.group.id]=a.group)}}for(var c in t)t[c].flushTriggers();this.oldScroll={x:e.horizontal.newScroll,y:e.vertical.newScroll}},e.prototype.innerHeight=function(){return this.element==this.element.window?n.viewportHeight():this.adapter.innerHeight()},e.prototype.remove=function(t){delete this.waypoints[t.axis][t.key],this.checkEmpty()},e.prototype.innerWidth=function(){return this.element==this.element.window?n.viewportWidth():this.adapter.innerWidth()},e.prototype.destroy=function(){var t=[];for(var e in this.waypoints)for(var i in this.waypoints[e])t.push(this.waypoints[e][i]);for(var o=0,n=t.length;n>o;o++)t[o].destroy()},e.prototype.refresh=function(){var t,e=this.element==this.element.window,i=e?void 0:this.adapter.offset(),o={};this.handleScroll(),t={horizontal:{contextOffset:e?0:i.left,contextScroll:e?0:this.oldScroll.x,contextDimension:this.innerWidth(),oldScroll:this.oldScroll.x,forward:"right",backward:"left",offsetProp:"left"},vertical:{contextOffset:e?0:i.top,contextScroll:e?0:this.oldScroll.y,contextDimension:this.innerHeight(),oldScroll:this.oldScroll.y,forward:"down",backward:"up",offsetProp:"top"}};for(var r in t){var s=t[r];for(var a in this.waypoints[r]){var l,h,p,u,c,d=this.waypoints[r][a],f=d.options.offset,w=d.triggerPoint,y=0,g=null==w;d.element!==d.element.window&&(y=d.adapter.offset()[s.offsetProp]),"function"==typeof f?f=f.apply(d):"string"==typeof f&&(f=parseFloat(f),d.options.offset.indexOf("%")>-1&&(f=Math.ceil(s.contextDimension*f/100))),l=s.contextScroll-s.contextOffset,d.triggerPoint=y+l-f,h=w=s.oldScroll,u=h&&p,c=!h&&!p,!g&&u?(d.queueTrigger(s.backward),o[d.group.id]=d.group):!g&&c?(d.queueTrigger(s.forward),o[d.group.id]=d.group):g&&s.oldScroll>=d.triggerPoint&&(d.queueTrigger(s.forward),o[d.group.id]=d.group)}}return n.requestAnimationFrame(function(){for(var t in o)o[t].flushTriggers()}),this},e.findOrCreateByElement=function(t){return e.findByElement(t)||new e(t)},e.refreshAll=function(){for(var t in o)o[t].refresh()},e.findByElement=function(t){return o[t.waypointContextKey]},window.onload=function(){r&&r(),e.refreshAll()},n.requestAnimationFrame=function(e){var i=window.requestAnimationFrame||window.mozRequestAnimationFrame||window.webkitRequestAnimationFrame||t;i.call(window,e)},n.Context=e}(),function(){"use strict";function t(t,e){return t.triggerPoint-e.triggerPoint}function e(t,e){return e.triggerPoint-t.triggerPoint}function i(t){this.name=t.name,this.axis=t.axis,this.id=this.name+"-"+this.axis,this.waypoints=[],this.clearTriggerQueues(),o[this.axis][this.name]=this}var o={vertical:{},horizontal:{}},n=window.Waypoint;i.prototype.add=function(t){this.waypoints.push(t)},i.prototype.clearTriggerQueues=function(){this.triggerQueues={up:[],down:[],left:[],right:[]}},i.prototype.flushTriggers=function(){for(var i in this.triggerQueues){var o=this.triggerQueues[i],n="up"===i||"left"===i;o.sort(n?e:t);for(var r=0,s=o.length;s>r;r+=1){var a=o[r];(a.options.continuous||r===o.length-1)&&a.trigger([i])}}this.clearTriggerQueues()},i.prototype.next=function(e){this.waypoints.sort(t);var i=n.Adapter.inArray(e,this.waypoints),o=i===this.waypoints.length-1;return o?null:this.waypoints[i+1]},i.prototype.previous=function(e){this.waypoints.sort(t);var i=n.Adapter.inArray(e,this.waypoints);return i?this.waypoints[i-1]:null},i.prototype.queueTrigger=function(t,e){this.triggerQueues[e].push(t)},i.prototype.remove=function(t){var e=n.Adapter.inArray(t,this.waypoints);e>-1&&this.waypoints.splice(e,1)},i.prototype.first=function(){return this.waypoints[0]},i.prototype.last=function(){return this.waypoints[this.waypoints.length-1]},i.findOrCreate=function(t){return o[t.axis][t.name]||new i(t)},n.Group=i}(),function(){"use strict";function t(t){this.$element=e(t)}var e=window.jQuery,i=window.Waypoint;e.each(["innerHeight","innerWidth","off","offset","on","outerHeight","outerWidth","scrollLeft","scrollTop"],function(e,i){t.prototype[i]=function(){var t=Array.prototype.slice.call(arguments);return this.$element[i].apply(this.$element,t)}}),e.each(["extend","inArray","isEmptyObject"],function(i,o){t[o]=e[o]}),i.adapters.push({name:"jquery",Adapter:t}),i.Adapter=t}(),function(){"use strict";function t(t){return function(){var i=[],o=arguments[0];return t.isFunction(arguments[0])&&(o=t.extend({},arguments[1]),o.handler=arguments[0]),this.each(function(){var n=t.extend({},o,{element:this});"string"==typeof n.context&&(n.context=t(this).closest(n.context)[0]),i.push(new e(n))}),i}}var e=window.Waypoint;window.jQuery&&(window.jQuery.fn.waypoint=t(window.jQuery)),window.Zepto&&(window.Zepto.fn.waypoint=t(window.Zepto))}(); \ No newline at end of file diff --git a/lib/noframework.waypoints.js b/lib/noframework.waypoints.js index 9cfaf936..a3ad9228 100644 --- a/lib/noframework.waypoints.js +++ b/lib/noframework.waypoints.js @@ -348,7 +348,7 @@ https://github.com/imakewebthings/waypoints/blog/master/licenses.txt /*eslint-disable eqeqeq */ var isWindow = this.element == this.element.window /*eslint-enable eqeqeq */ - var contextOffset = this.adapter.offset() + var contextOffset = isWindow ? undefined : this.adapter.offset() var triggeredGroups = {} var axes diff --git a/lib/noframework.waypoints.min.js b/lib/noframework.waypoints.min.js index 5f320c34..ed4a5999 100644 --- a/lib/noframework.waypoints.min.js +++ b/lib/noframework.waypoints.min.js @@ -4,4 +4,4 @@ Copyright © 2011-2015 Caleb Troughton Licensed under the MIT license. https://github.com/imakewebthings/waypoints/blog/master/licenses.txt */ -!function(){"use strict";function t(n){if(!n)throw new Error("No options passed to Waypoint constructor");if(!n.element)throw new Error("No element option passed to Waypoint constructor");if(!n.handler)throw new Error("No handler option passed to Waypoint constructor");this.key="waypoint-"+e,this.options=t.Adapter.extend({},t.defaults,n),this.element=this.options.element,this.adapter=new t.Adapter(this.element),this.callback=n.handler,this.axis=this.options.horizontal?"horizontal":"vertical",this.enabled=this.options.enabled,this.triggerPoint=null,this.group=t.Group.findOrCreate({name:this.options.group,axis:this.axis}),this.context=t.Context.findOrCreateByElement(this.options.context),t.offsetAliases[this.options.offset]&&(this.options.offset=t.offsetAliases[this.options.offset]),this.group.add(this),this.context.add(this),i[this.key]=this,e+=1}var e=0,i={};t.prototype.queueTrigger=function(t){this.group.queueTrigger(this,t)},t.prototype.trigger=function(t){this.enabled&&this.callback&&this.callback.apply(this,t)},t.prototype.destroy=function(){this.context.remove(this),this.group.remove(this),delete i[this.key]},t.prototype.disable=function(){return this.enabled=!1,this},t.prototype.enable=function(){return this.context.refresh(),this.enabled=!0,this},t.prototype.next=function(){return this.group.next(this)},t.prototype.previous=function(){return this.group.previous(this)},t.invokeAll=function(t){var e=[];for(var n in i)e.push(i[n]);for(var o=0,r=e.length;r>o;o++)e[o][t]()},t.destroyAll=function(){t.invokeAll("destroy")},t.disableAll=function(){t.invokeAll("disable")},t.enableAll=function(){t.invokeAll("enable")},t.refreshAll=function(){t.Context.refreshAll()},t.viewportHeight=function(){return window.innerHeight||document.documentElement.clientHeight},t.viewportWidth=function(){return document.documentElement.clientWidth},t.adapters=[],t.defaults={context:window,continuous:!0,enabled:!0,group:"default",horizontal:!1,offset:0},t.offsetAliases={"bottom-in-view":function(){return this.context.innerHeight()-this.adapter.outerHeight()},"right-in-view":function(){return this.context.innerWidth()-this.adapter.outerWidth()}},window.Waypoint=t}(),function(){"use strict";function t(t){window.setTimeout(t,1e3/60)}function e(t){this.element=t,this.Adapter=o.Adapter,this.adapter=new this.Adapter(t),this.key="waypoint-context-"+i,this.didScroll=!1,this.didResize=!1,this.oldScroll={x:this.adapter.scrollLeft(),y:this.adapter.scrollTop()},this.waypoints={vertical:{},horizontal:{}},t.waypointContextKey=this.key,n[t.waypointContextKey]=this,i+=1,this.createThrottledScrollHandler(),this.createThrottledResizeHandler()}var i=0,n={},o=window.Waypoint,r=window.onload;e.prototype.add=function(t){var e=t.options.horizontal?"horizontal":"vertical";this.waypoints[e][t.key]=t,this.refresh()},e.prototype.checkEmpty=function(){var t=this.Adapter.isEmptyObject(this.waypoints.horizontal),e=this.Adapter.isEmptyObject(this.waypoints.vertical);t&&e&&(this.adapter.off(".waypoints"),delete n[this.key])},e.prototype.createThrottledResizeHandler=function(){function t(){e.handleResize(),e.didResize=!1}var e=this;this.adapter.on("resize.waypoints",function(){e.didResize||(e.didResize=!0,o.requestAnimationFrame(t))})},e.prototype.createThrottledScrollHandler=function(){function t(){e.handleScroll(),e.didScroll=!1}var e=this;this.adapter.on("scroll.waypoints",function(){(!e.didScroll||o.isTouch)&&(e.didScroll=!0,o.requestAnimationFrame(t))})},e.prototype.handleResize=function(){o.Context.refreshAll()},e.prototype.handleScroll=function(){var t={},e={horizontal:{newScroll:this.adapter.scrollLeft(),oldScroll:this.oldScroll.x,forward:"right",backward:"left"},vertical:{newScroll:this.adapter.scrollTop(),oldScroll:this.oldScroll.y,forward:"down",backward:"up"}};for(var i in e){var n=e[i],o=n.newScroll>n.oldScroll,r=o?n.forward:n.backward;for(var s in this.waypoints[i]){var l=this.waypoints[i][s],a=n.oldScroll=l.triggerPoint,p=a&&h,u=!a&&!h;(p||u)&&(l.queueTrigger(r),t[l.group.id]=l.group)}}for(var c in t)t[c].flushTriggers();this.oldScroll={x:e.horizontal.newScroll,y:e.vertical.newScroll}},e.prototype.innerHeight=function(){return this.element==this.element.window?o.viewportHeight():this.adapter.innerHeight()},e.prototype.remove=function(t){delete this.waypoints[t.axis][t.key],this.checkEmpty()},e.prototype.innerWidth=function(){return this.element==this.element.window?o.viewportWidth():this.adapter.innerWidth()},e.prototype.destroy=function(){var t=[];for(var e in this.waypoints)for(var i in this.waypoints[e])t.push(this.waypoints[e][i]);for(var n=0,o=t.length;o>n;n++)t[n].destroy()},e.prototype.refresh=function(){var t,e=this.element==this.element.window,i=this.adapter.offset(),n={};this.handleScroll(),t={horizontal:{contextOffset:e?0:i.left,contextScroll:e?0:this.oldScroll.x,contextDimension:this.innerWidth(),oldScroll:this.oldScroll.x,forward:"right",backward:"left",offsetProp:"left"},vertical:{contextOffset:e?0:i.top,contextScroll:e?0:this.oldScroll.y,contextDimension:this.innerHeight(),oldScroll:this.oldScroll.y,forward:"down",backward:"up",offsetProp:"top"}};for(var r in t){var s=t[r];for(var l in this.waypoints[r]){var a,h,p,u,c,f=this.waypoints[r][l],d=f.options.offset,y=f.triggerPoint,g=0,w=null==y;f.element!==f.element.window&&(g=f.adapter.offset()[s.offsetProp]),"function"==typeof d?d=d.apply(f):"string"==typeof d&&(d=parseFloat(d),f.options.offset.indexOf("%")>-1&&(d=Math.ceil(s.contextDimension*d/100))),a=s.contextScroll-s.contextOffset,f.triggerPoint=g+a-d,h=y=s.oldScroll,u=h&&p,c=!h&&!p,!w&&u?(f.queueTrigger(s.backward),n[f.group.id]=f.group):!w&&c?(f.queueTrigger(s.forward),n[f.group.id]=f.group):w&&s.oldScroll>=f.triggerPoint&&(f.queueTrigger(s.forward),n[f.group.id]=f.group)}}return o.requestAnimationFrame(function(){for(var t in n)n[t].flushTriggers()}),this},e.findOrCreateByElement=function(t){return e.findByElement(t)||new e(t)},e.refreshAll=function(){for(var t in n)n[t].refresh()},e.findByElement=function(t){return n[t.waypointContextKey]},window.onload=function(){r&&r(),e.refreshAll()},o.requestAnimationFrame=function(e){var i=window.requestAnimationFrame||window.mozRequestAnimationFrame||window.webkitRequestAnimationFrame||t;i.call(window,e)},o.Context=e}(),function(){"use strict";function t(t,e){return t.triggerPoint-e.triggerPoint}function e(t,e){return e.triggerPoint-t.triggerPoint}function i(t){this.name=t.name,this.axis=t.axis,this.id=this.name+"-"+this.axis,this.waypoints=[],this.clearTriggerQueues(),n[this.axis][this.name]=this}var n={vertical:{},horizontal:{}},o=window.Waypoint;i.prototype.add=function(t){this.waypoints.push(t)},i.prototype.clearTriggerQueues=function(){this.triggerQueues={up:[],down:[],left:[],right:[]}},i.prototype.flushTriggers=function(){for(var i in this.triggerQueues){var n=this.triggerQueues[i],o="up"===i||"left"===i;n.sort(o?e:t);for(var r=0,s=n.length;s>r;r+=1){var l=n[r];(l.options.continuous||r===n.length-1)&&l.trigger([i])}}this.clearTriggerQueues()},i.prototype.next=function(e){this.waypoints.sort(t);var i=o.Adapter.inArray(e,this.waypoints),n=i===this.waypoints.length-1;return n?null:this.waypoints[i+1]},i.prototype.previous=function(e){this.waypoints.sort(t);var i=o.Adapter.inArray(e,this.waypoints);return i?this.waypoints[i-1]:null},i.prototype.queueTrigger=function(t,e){this.triggerQueues[e].push(t)},i.prototype.remove=function(t){var e=o.Adapter.inArray(t,this.waypoints);e>-1&&this.waypoints.splice(e,1)},i.prototype.first=function(){return this.waypoints[0]},i.prototype.last=function(){return this.waypoints[this.waypoints.length-1]},i.findOrCreate=function(t){return n[t.axis][t.name]||new i(t)},o.Group=i}(),function(){"use strict";function t(t){return t===t.window}function e(e){return t(e)?e:e.defaultView}function i(t){this.element=t,this.handlers={}}var n=window.Waypoint;i.prototype.innerHeight=function(){var e=t(this.element);return e?this.element.innerHeight:this.element.clientHeight},i.prototype.innerWidth=function(){var e=t(this.element);return e?this.element.innerWidth:this.element.clientWidth},i.prototype.off=function(t,e){function i(t,e,i){for(var n=0,o=e.length-1;o>n;n++){var r=e[n];i&&i!==r||t.removeEventListener(r)}}var n=t.split("."),o=n[0],r=n[1],s=this.element;if(r&&this.handlers[r]&&o)i(s,this.handlers[r][o],e),this.handlers[r][o]=[];else if(o)for(var l in this.handlers)i(s,this.handlers[l][o]||[],e),this.handlers[l][o]=[];else if(r&&this.handlers[r]){for(var a in this.handlers[r])i(s,this.handlers[r][a],e);this.handlers[r]={}}},i.prototype.offset=function(){if(!this.element.ownerDocument)return null;var t=this.element.ownerDocument.documentElement,i=e(this.element.ownerDocument),n={top:0,left:0};return this.element.getBoundingClientRect&&(n=this.element.getBoundingClientRect()),{top:n.top+i.pageYOffset-t.clientTop,left:n.left+i.pageXOffset-t.clientLeft}},i.prototype.on=function(t,e){var i=t.split("."),n=i[0],o=i[1]||"__default",r=this.handlers[o]=this.handlers[o]||{},s=r[n]=r[n]||[];s.push(e),this.element.addEventListener(n,e)},i.prototype.outerHeight=function(e){var i,n=this.innerHeight();return e&&!t(this.element)&&(i=window.getComputedStyle(this.element),n+=parseInt(i.marginTop,10),n+=parseInt(i.marginBottom,10)),n},i.prototype.outerWidth=function(e){var i,n=this.innerWidth();return e&&!t(this.element)&&(i=window.getComputedStyle(this.element),n+=parseInt(i.marginLeft,10),n+=parseInt(i.marginRight,10)),n},i.prototype.scrollLeft=function(){var t=e(this.element);return t?t.pageXOffset:this.element.scrollLeft},i.prototype.scrollTop=function(){var t=e(this.element);return t?t.pageYOffset:this.element.scrollTop},i.extend=function(){function t(t,e){if("object"==typeof t&&"object"==typeof e)for(var i in e)e.hasOwnProperty(i)&&(t[i]=e[i]);return t}for(var e=Array.prototype.slice.call(arguments),i=1,n=e.length;n>i;i++)t(e[0],e[i]);return e[0]},i.inArray=function(t,e,i){return null==e?-1:e.indexOf(t,i)},i.isEmptyObject=function(t){for(var e in t)return!1;return!0},n.adapters.push({name:"noframework",Adapter:i}),n.Adapter=i}(); \ No newline at end of file +!function(){"use strict";function t(n){if(!n)throw new Error("No options passed to Waypoint constructor");if(!n.element)throw new Error("No element option passed to Waypoint constructor");if(!n.handler)throw new Error("No handler option passed to Waypoint constructor");this.key="waypoint-"+e,this.options=t.Adapter.extend({},t.defaults,n),this.element=this.options.element,this.adapter=new t.Adapter(this.element),this.callback=n.handler,this.axis=this.options.horizontal?"horizontal":"vertical",this.enabled=this.options.enabled,this.triggerPoint=null,this.group=t.Group.findOrCreate({name:this.options.group,axis:this.axis}),this.context=t.Context.findOrCreateByElement(this.options.context),t.offsetAliases[this.options.offset]&&(this.options.offset=t.offsetAliases[this.options.offset]),this.group.add(this),this.context.add(this),i[this.key]=this,e+=1}var e=0,i={};t.prototype.queueTrigger=function(t){this.group.queueTrigger(this,t)},t.prototype.trigger=function(t){this.enabled&&this.callback&&this.callback.apply(this,t)},t.prototype.destroy=function(){this.context.remove(this),this.group.remove(this),delete i[this.key]},t.prototype.disable=function(){return this.enabled=!1,this},t.prototype.enable=function(){return this.context.refresh(),this.enabled=!0,this},t.prototype.next=function(){return this.group.next(this)},t.prototype.previous=function(){return this.group.previous(this)},t.invokeAll=function(t){var e=[];for(var n in i)e.push(i[n]);for(var o=0,r=e.length;r>o;o++)e[o][t]()},t.destroyAll=function(){t.invokeAll("destroy")},t.disableAll=function(){t.invokeAll("disable")},t.enableAll=function(){t.invokeAll("enable")},t.refreshAll=function(){t.Context.refreshAll()},t.viewportHeight=function(){return window.innerHeight||document.documentElement.clientHeight},t.viewportWidth=function(){return document.documentElement.clientWidth},t.adapters=[],t.defaults={context:window,continuous:!0,enabled:!0,group:"default",horizontal:!1,offset:0},t.offsetAliases={"bottom-in-view":function(){return this.context.innerHeight()-this.adapter.outerHeight()},"right-in-view":function(){return this.context.innerWidth()-this.adapter.outerWidth()}},window.Waypoint=t}(),function(){"use strict";function t(t){window.setTimeout(t,1e3/60)}function e(t){this.element=t,this.Adapter=o.Adapter,this.adapter=new this.Adapter(t),this.key="waypoint-context-"+i,this.didScroll=!1,this.didResize=!1,this.oldScroll={x:this.adapter.scrollLeft(),y:this.adapter.scrollTop()},this.waypoints={vertical:{},horizontal:{}},t.waypointContextKey=this.key,n[t.waypointContextKey]=this,i+=1,this.createThrottledScrollHandler(),this.createThrottledResizeHandler()}var i=0,n={},o=window.Waypoint,r=window.onload;e.prototype.add=function(t){var e=t.options.horizontal?"horizontal":"vertical";this.waypoints[e][t.key]=t,this.refresh()},e.prototype.checkEmpty=function(){var t=this.Adapter.isEmptyObject(this.waypoints.horizontal),e=this.Adapter.isEmptyObject(this.waypoints.vertical);t&&e&&(this.adapter.off(".waypoints"),delete n[this.key])},e.prototype.createThrottledResizeHandler=function(){function t(){e.handleResize(),e.didResize=!1}var e=this;this.adapter.on("resize.waypoints",function(){e.didResize||(e.didResize=!0,o.requestAnimationFrame(t))})},e.prototype.createThrottledScrollHandler=function(){function t(){e.handleScroll(),e.didScroll=!1}var e=this;this.adapter.on("scroll.waypoints",function(){(!e.didScroll||o.isTouch)&&(e.didScroll=!0,o.requestAnimationFrame(t))})},e.prototype.handleResize=function(){o.Context.refreshAll()},e.prototype.handleScroll=function(){var t={},e={horizontal:{newScroll:this.adapter.scrollLeft(),oldScroll:this.oldScroll.x,forward:"right",backward:"left"},vertical:{newScroll:this.adapter.scrollTop(),oldScroll:this.oldScroll.y,forward:"down",backward:"up"}};for(var i in e){var n=e[i],o=n.newScroll>n.oldScroll,r=o?n.forward:n.backward;for(var s in this.waypoints[i]){var l=this.waypoints[i][s],a=n.oldScroll=l.triggerPoint,p=a&&h,u=!a&&!h;(p||u)&&(l.queueTrigger(r),t[l.group.id]=l.group)}}for(var c in t)t[c].flushTriggers();this.oldScroll={x:e.horizontal.newScroll,y:e.vertical.newScroll}},e.prototype.innerHeight=function(){return this.element==this.element.window?o.viewportHeight():this.adapter.innerHeight()},e.prototype.remove=function(t){delete this.waypoints[t.axis][t.key],this.checkEmpty()},e.prototype.innerWidth=function(){return this.element==this.element.window?o.viewportWidth():this.adapter.innerWidth()},e.prototype.destroy=function(){var t=[];for(var e in this.waypoints)for(var i in this.waypoints[e])t.push(this.waypoints[e][i]);for(var n=0,o=t.length;o>n;n++)t[n].destroy()},e.prototype.refresh=function(){var t,e=this.element==this.element.window,i=e?void 0:this.adapter.offset(),n={};this.handleScroll(),t={horizontal:{contextOffset:e?0:i.left,contextScroll:e?0:this.oldScroll.x,contextDimension:this.innerWidth(),oldScroll:this.oldScroll.x,forward:"right",backward:"left",offsetProp:"left"},vertical:{contextOffset:e?0:i.top,contextScroll:e?0:this.oldScroll.y,contextDimension:this.innerHeight(),oldScroll:this.oldScroll.y,forward:"down",backward:"up",offsetProp:"top"}};for(var r in t){var s=t[r];for(var l in this.waypoints[r]){var a,h,p,u,c,f=this.waypoints[r][l],d=f.options.offset,y=f.triggerPoint,g=0,w=null==y;f.element!==f.element.window&&(g=f.adapter.offset()[s.offsetProp]),"function"==typeof d?d=d.apply(f):"string"==typeof d&&(d=parseFloat(d),f.options.offset.indexOf("%")>-1&&(d=Math.ceil(s.contextDimension*d/100))),a=s.contextScroll-s.contextOffset,f.triggerPoint=g+a-d,h=y=s.oldScroll,u=h&&p,c=!h&&!p,!w&&u?(f.queueTrigger(s.backward),n[f.group.id]=f.group):!w&&c?(f.queueTrigger(s.forward),n[f.group.id]=f.group):w&&s.oldScroll>=f.triggerPoint&&(f.queueTrigger(s.forward),n[f.group.id]=f.group)}}return o.requestAnimationFrame(function(){for(var t in n)n[t].flushTriggers()}),this},e.findOrCreateByElement=function(t){return e.findByElement(t)||new e(t)},e.refreshAll=function(){for(var t in n)n[t].refresh()},e.findByElement=function(t){return n[t.waypointContextKey]},window.onload=function(){r&&r(),e.refreshAll()},o.requestAnimationFrame=function(e){var i=window.requestAnimationFrame||window.mozRequestAnimationFrame||window.webkitRequestAnimationFrame||t;i.call(window,e)},o.Context=e}(),function(){"use strict";function t(t,e){return t.triggerPoint-e.triggerPoint}function e(t,e){return e.triggerPoint-t.triggerPoint}function i(t){this.name=t.name,this.axis=t.axis,this.id=this.name+"-"+this.axis,this.waypoints=[],this.clearTriggerQueues(),n[this.axis][this.name]=this}var n={vertical:{},horizontal:{}},o=window.Waypoint;i.prototype.add=function(t){this.waypoints.push(t)},i.prototype.clearTriggerQueues=function(){this.triggerQueues={up:[],down:[],left:[],right:[]}},i.prototype.flushTriggers=function(){for(var i in this.triggerQueues){var n=this.triggerQueues[i],o="up"===i||"left"===i;n.sort(o?e:t);for(var r=0,s=n.length;s>r;r+=1){var l=n[r];(l.options.continuous||r===n.length-1)&&l.trigger([i])}}this.clearTriggerQueues()},i.prototype.next=function(e){this.waypoints.sort(t);var i=o.Adapter.inArray(e,this.waypoints),n=i===this.waypoints.length-1;return n?null:this.waypoints[i+1]},i.prototype.previous=function(e){this.waypoints.sort(t);var i=o.Adapter.inArray(e,this.waypoints);return i?this.waypoints[i-1]:null},i.prototype.queueTrigger=function(t,e){this.triggerQueues[e].push(t)},i.prototype.remove=function(t){var e=o.Adapter.inArray(t,this.waypoints);e>-1&&this.waypoints.splice(e,1)},i.prototype.first=function(){return this.waypoints[0]},i.prototype.last=function(){return this.waypoints[this.waypoints.length-1]},i.findOrCreate=function(t){return n[t.axis][t.name]||new i(t)},o.Group=i}(),function(){"use strict";function t(t){return t===t.window}function e(e){return t(e)?e:e.defaultView}function i(t){this.element=t,this.handlers={}}var n=window.Waypoint;i.prototype.innerHeight=function(){var e=t(this.element);return e?this.element.innerHeight:this.element.clientHeight},i.prototype.innerWidth=function(){var e=t(this.element);return e?this.element.innerWidth:this.element.clientWidth},i.prototype.off=function(t,e){function i(t,e,i){for(var n=0,o=e.length-1;o>n;n++){var r=e[n];i&&i!==r||t.removeEventListener(r)}}var n=t.split("."),o=n[0],r=n[1],s=this.element;if(r&&this.handlers[r]&&o)i(s,this.handlers[r][o],e),this.handlers[r][o]=[];else if(o)for(var l in this.handlers)i(s,this.handlers[l][o]||[],e),this.handlers[l][o]=[];else if(r&&this.handlers[r]){for(var a in this.handlers[r])i(s,this.handlers[r][a],e);this.handlers[r]={}}},i.prototype.offset=function(){if(!this.element.ownerDocument)return null;var t=this.element.ownerDocument.documentElement,i=e(this.element.ownerDocument),n={top:0,left:0};return this.element.getBoundingClientRect&&(n=this.element.getBoundingClientRect()),{top:n.top+i.pageYOffset-t.clientTop,left:n.left+i.pageXOffset-t.clientLeft}},i.prototype.on=function(t,e){var i=t.split("."),n=i[0],o=i[1]||"__default",r=this.handlers[o]=this.handlers[o]||{},s=r[n]=r[n]||[];s.push(e),this.element.addEventListener(n,e)},i.prototype.outerHeight=function(e){var i,n=this.innerHeight();return e&&!t(this.element)&&(i=window.getComputedStyle(this.element),n+=parseInt(i.marginTop,10),n+=parseInt(i.marginBottom,10)),n},i.prototype.outerWidth=function(e){var i,n=this.innerWidth();return e&&!t(this.element)&&(i=window.getComputedStyle(this.element),n+=parseInt(i.marginLeft,10),n+=parseInt(i.marginRight,10)),n},i.prototype.scrollLeft=function(){var t=e(this.element);return t?t.pageXOffset:this.element.scrollLeft},i.prototype.scrollTop=function(){var t=e(this.element);return t?t.pageYOffset:this.element.scrollTop},i.extend=function(){function t(t,e){if("object"==typeof t&&"object"==typeof e)for(var i in e)e.hasOwnProperty(i)&&(t[i]=e[i]);return t}for(var e=Array.prototype.slice.call(arguments),i=1,n=e.length;n>i;i++)t(e[0],e[i]);return e[0]},i.inArray=function(t,e,i){return null==e?-1:e.indexOf(t,i)},i.isEmptyObject=function(t){for(var e in t)return!1;return!0},n.adapters.push({name:"noframework",Adapter:i}),n.Adapter=i}(); \ No newline at end of file diff --git a/lib/shortcuts/inview.js b/lib/shortcuts/inview.js index da963b48..a4a591c1 100644 --- a/lib/shortcuts/inview.js +++ b/lib/shortcuts/inview.js @@ -72,6 +72,7 @@ https://github.com/imakewebthings/waypoints/blog/master/licenses.txt Inview.prototype.createWaypoint = function(config) { var self = this this.waypoints.push(new Waypoint({ + context: this.options.context, element: this.options.element, enabled: this.options.enabled, handler: (function(config) { @@ -105,6 +106,7 @@ https://github.com/imakewebthings/waypoints/blog/master/licenses.txt } Inview.defaults = { + context: window, enabled: true, enter: noop, entered: noop, diff --git a/lib/shortcuts/inview.min.js b/lib/shortcuts/inview.min.js index b6d5c33e..674df63b 100644 --- a/lib/shortcuts/inview.min.js +++ b/lib/shortcuts/inview.min.js @@ -4,4 +4,4 @@ Copyright © 2011-2015 Caleb Troughton Licensed under the MIT license. https://github.com/imakewebthings/waypoints/blog/master/licenses.txt */ -!function(){"use strict";function t(){}function e(t){this.options=i.Adapter.extend({},e.defaults,t),this.axis=this.options.horizontal?"horizontal":"vertical",this.waypoints=[],this.createWaypoints()}var i=window.Waypoint;e.prototype.createWaypoints=function(){for(var t={vertical:[{down:"enter",up:"exited",offset:"100%"},{down:"entered",up:"exit",offset:"bottom-in-view"},{down:"exit",up:"entered",offset:0},{down:"exited",up:"enter",offset:function(){return-this.adapter.outerHeight()}}],horizontal:[{right:"enter",left:"exited",offset:"100%"},{right:"entered",left:"exit",offset:"right-in-view"},{right:"exit",left:"entered",offset:0},{right:"exited",left:"enter",offset:function(){return-this.adapter.outerWidth()}}]},e=0,i=t[this.axis].length;i>e;e++){var n=t[this.axis][e];this.createWaypoint(n)}},e.prototype.createWaypoint=function(t){var e=this;this.waypoints.push(new i({element:this.options.element,enabled:this.options.enabled,handler:function(t){return function(i){e.options[t[i]].call(e,i)}}(t),offset:t.offset,horizontal:this.options.horizontal}))},e.prototype.destroy=function(){for(var t=0,e=this.waypoints.length;e>t;t++)this.waypoints[t].destroy();this.waypoints=[]},e.prototype.disable=function(){for(var t=0,e=this.waypoints.length;e>t;t++)this.waypoints[t].disable()},e.prototype.enable=function(){for(var t=0,e=this.waypoints.length;e>t;t++)this.waypoints[t].enable()},e.defaults={enabled:!0,enter:t,entered:t,exit:t,exited:t},i.Inview=e}(); \ No newline at end of file +!function(){"use strict";function t(){}function e(t){this.options=i.Adapter.extend({},e.defaults,t),this.axis=this.options.horizontal?"horizontal":"vertical",this.waypoints=[],this.createWaypoints()}var i=window.Waypoint;e.prototype.createWaypoints=function(){for(var t={vertical:[{down:"enter",up:"exited",offset:"100%"},{down:"entered",up:"exit",offset:"bottom-in-view"},{down:"exit",up:"entered",offset:0},{down:"exited",up:"enter",offset:function(){return-this.adapter.outerHeight()}}],horizontal:[{right:"enter",left:"exited",offset:"100%"},{right:"entered",left:"exit",offset:"right-in-view"},{right:"exit",left:"entered",offset:0},{right:"exited",left:"enter",offset:function(){return-this.adapter.outerWidth()}}]},e=0,i=t[this.axis].length;i>e;e++){var n=t[this.axis][e];this.createWaypoint(n)}},e.prototype.createWaypoint=function(t){var e=this;this.waypoints.push(new i({context:this.options.context,element:this.options.element,enabled:this.options.enabled,handler:function(t){return function(i){e.options[t[i]].call(e,i)}}(t),offset:t.offset,horizontal:this.options.horizontal}))},e.prototype.destroy=function(){for(var t=0,e=this.waypoints.length;e>t;t++)this.waypoints[t].destroy();this.waypoints=[]},e.prototype.disable=function(){for(var t=0,e=this.waypoints.length;e>t;t++)this.waypoints[t].disable()},e.prototype.enable=function(){for(var t=0,e=this.waypoints.length;e>t;t++)this.waypoints[t].enable()},e.defaults={context:window,enabled:!0,enter:t,entered:t,exit:t,exited:t},i.Inview=e}(); \ No newline at end of file diff --git a/lib/zepto.waypoints.js b/lib/zepto.waypoints.js index 7ba59d9d..be4b02c7 100644 --- a/lib/zepto.waypoints.js +++ b/lib/zepto.waypoints.js @@ -348,7 +348,7 @@ https://github.com/imakewebthings/waypoints/blog/master/licenses.txt /*eslint-disable eqeqeq */ var isWindow = this.element == this.element.window /*eslint-enable eqeqeq */ - var contextOffset = this.adapter.offset() + var contextOffset = isWindow ? undefined : this.adapter.offset() var triggeredGroups = {} var axes diff --git a/lib/zepto.waypoints.min.js b/lib/zepto.waypoints.min.js index 55c68527..e429af44 100644 --- a/lib/zepto.waypoints.min.js +++ b/lib/zepto.waypoints.min.js @@ -4,4 +4,4 @@ Copyright © 2011-2015 Caleb Troughton Licensed under the MIT license. https://github.com/imakewebthings/waypoints/blog/master/licenses.txt */ -!function(){"use strict";function t(o){if(!o)throw new Error("No options passed to Waypoint constructor");if(!o.element)throw new Error("No element option passed to Waypoint constructor");if(!o.handler)throw new Error("No handler option passed to Waypoint constructor");this.key="waypoint-"+e,this.options=t.Adapter.extend({},t.defaults,o),this.element=this.options.element,this.adapter=new t.Adapter(this.element),this.callback=o.handler,this.axis=this.options.horizontal?"horizontal":"vertical",this.enabled=this.options.enabled,this.triggerPoint=null,this.group=t.Group.findOrCreate({name:this.options.group,axis:this.axis}),this.context=t.Context.findOrCreateByElement(this.options.context),t.offsetAliases[this.options.offset]&&(this.options.offset=t.offsetAliases[this.options.offset]),this.group.add(this),this.context.add(this),i[this.key]=this,e+=1}var e=0,i={};t.prototype.queueTrigger=function(t){this.group.queueTrigger(this,t)},t.prototype.trigger=function(t){this.enabled&&this.callback&&this.callback.apply(this,t)},t.prototype.destroy=function(){this.context.remove(this),this.group.remove(this),delete i[this.key]},t.prototype.disable=function(){return this.enabled=!1,this},t.prototype.enable=function(){return this.context.refresh(),this.enabled=!0,this},t.prototype.next=function(){return this.group.next(this)},t.prototype.previous=function(){return this.group.previous(this)},t.invokeAll=function(t){var e=[];for(var o in i)e.push(i[o]);for(var n=0,r=e.length;r>n;n++)e[n][t]()},t.destroyAll=function(){t.invokeAll("destroy")},t.disableAll=function(){t.invokeAll("disable")},t.enableAll=function(){t.invokeAll("enable")},t.refreshAll=function(){t.Context.refreshAll()},t.viewportHeight=function(){return window.innerHeight||document.documentElement.clientHeight},t.viewportWidth=function(){return document.documentElement.clientWidth},t.adapters=[],t.defaults={context:window,continuous:!0,enabled:!0,group:"default",horizontal:!1,offset:0},t.offsetAliases={"bottom-in-view":function(){return this.context.innerHeight()-this.adapter.outerHeight()},"right-in-view":function(){return this.context.innerWidth()-this.adapter.outerWidth()}},window.Waypoint=t}(),function(){"use strict";function t(t){window.setTimeout(t,1e3/60)}function e(t){this.element=t,this.Adapter=n.Adapter,this.adapter=new this.Adapter(t),this.key="waypoint-context-"+i,this.didScroll=!1,this.didResize=!1,this.oldScroll={x:this.adapter.scrollLeft(),y:this.adapter.scrollTop()},this.waypoints={vertical:{},horizontal:{}},t.waypointContextKey=this.key,o[t.waypointContextKey]=this,i+=1,this.createThrottledScrollHandler(),this.createThrottledResizeHandler()}var i=0,o={},n=window.Waypoint,r=window.onload;e.prototype.add=function(t){var e=t.options.horizontal?"horizontal":"vertical";this.waypoints[e][t.key]=t,this.refresh()},e.prototype.checkEmpty=function(){var t=this.Adapter.isEmptyObject(this.waypoints.horizontal),e=this.Adapter.isEmptyObject(this.waypoints.vertical);t&&e&&(this.adapter.off(".waypoints"),delete o[this.key])},e.prototype.createThrottledResizeHandler=function(){function t(){e.handleResize(),e.didResize=!1}var e=this;this.adapter.on("resize.waypoints",function(){e.didResize||(e.didResize=!0,n.requestAnimationFrame(t))})},e.prototype.createThrottledScrollHandler=function(){function t(){e.handleScroll(),e.didScroll=!1}var e=this;this.adapter.on("scroll.waypoints",function(){(!e.didScroll||n.isTouch)&&(e.didScroll=!0,n.requestAnimationFrame(t))})},e.prototype.handleResize=function(){n.Context.refreshAll()},e.prototype.handleScroll=function(){var t={},e={horizontal:{newScroll:this.adapter.scrollLeft(),oldScroll:this.oldScroll.x,forward:"right",backward:"left"},vertical:{newScroll:this.adapter.scrollTop(),oldScroll:this.oldScroll.y,forward:"down",backward:"up"}};for(var i in e){var o=e[i],n=o.newScroll>o.oldScroll,r=n?o.forward:o.backward;for(var s in this.waypoints[i]){var a=this.waypoints[i][s],l=o.oldScroll=a.triggerPoint,p=l&&h,c=!l&&!h;(p||c)&&(a.queueTrigger(r),t[a.group.id]=a.group)}}for(var u in t)t[u].flushTriggers();this.oldScroll={x:e.horizontal.newScroll,y:e.vertical.newScroll}},e.prototype.innerHeight=function(){return this.element==this.element.window?n.viewportHeight():this.adapter.innerHeight()},e.prototype.remove=function(t){delete this.waypoints[t.axis][t.key],this.checkEmpty()},e.prototype.innerWidth=function(){return this.element==this.element.window?n.viewportWidth():this.adapter.innerWidth()},e.prototype.destroy=function(){var t=[];for(var e in this.waypoints)for(var i in this.waypoints[e])t.push(this.waypoints[e][i]);for(var o=0,n=t.length;n>o;o++)t[o].destroy()},e.prototype.refresh=function(){var t,e=this.element==this.element.window,i=this.adapter.offset(),o={};this.handleScroll(),t={horizontal:{contextOffset:e?0:i.left,contextScroll:e?0:this.oldScroll.x,contextDimension:this.innerWidth(),oldScroll:this.oldScroll.x,forward:"right",backward:"left",offsetProp:"left"},vertical:{contextOffset:e?0:i.top,contextScroll:e?0:this.oldScroll.y,contextDimension:this.innerHeight(),oldScroll:this.oldScroll.y,forward:"down",backward:"up",offsetProp:"top"}};for(var r in t){var s=t[r];for(var a in this.waypoints[r]){var l,h,p,c,u,d=this.waypoints[r][a],f=d.options.offset,w=d.triggerPoint,y=0,g=null==w;d.element!==d.element.window&&(y=d.adapter.offset()[s.offsetProp]),"function"==typeof f?f=f.apply(d):"string"==typeof f&&(f=parseFloat(f),d.options.offset.indexOf("%")>-1&&(f=Math.ceil(s.contextDimension*f/100))),l=s.contextScroll-s.contextOffset,d.triggerPoint=y+l-f,h=w=s.oldScroll,c=h&&p,u=!h&&!p,!g&&c?(d.queueTrigger(s.backward),o[d.group.id]=d.group):!g&&u?(d.queueTrigger(s.forward),o[d.group.id]=d.group):g&&s.oldScroll>=d.triggerPoint&&(d.queueTrigger(s.forward),o[d.group.id]=d.group)}}return n.requestAnimationFrame(function(){for(var t in o)o[t].flushTriggers()}),this},e.findOrCreateByElement=function(t){return e.findByElement(t)||new e(t)},e.refreshAll=function(){for(var t in o)o[t].refresh()},e.findByElement=function(t){return o[t.waypointContextKey]},window.onload=function(){r&&r(),e.refreshAll()},n.requestAnimationFrame=function(e){var i=window.requestAnimationFrame||window.mozRequestAnimationFrame||window.webkitRequestAnimationFrame||t;i.call(window,e)},n.Context=e}(),function(){"use strict";function t(t,e){return t.triggerPoint-e.triggerPoint}function e(t,e){return e.triggerPoint-t.triggerPoint}function i(t){this.name=t.name,this.axis=t.axis,this.id=this.name+"-"+this.axis,this.waypoints=[],this.clearTriggerQueues(),o[this.axis][this.name]=this}var o={vertical:{},horizontal:{}},n=window.Waypoint;i.prototype.add=function(t){this.waypoints.push(t)},i.prototype.clearTriggerQueues=function(){this.triggerQueues={up:[],down:[],left:[],right:[]}},i.prototype.flushTriggers=function(){for(var i in this.triggerQueues){var o=this.triggerQueues[i],n="up"===i||"left"===i;o.sort(n?e:t);for(var r=0,s=o.length;s>r;r+=1){var a=o[r];(a.options.continuous||r===o.length-1)&&a.trigger([i])}}this.clearTriggerQueues()},i.prototype.next=function(e){this.waypoints.sort(t);var i=n.Adapter.inArray(e,this.waypoints),o=i===this.waypoints.length-1;return o?null:this.waypoints[i+1]},i.prototype.previous=function(e){this.waypoints.sort(t);var i=n.Adapter.inArray(e,this.waypoints);return i?this.waypoints[i-1]:null},i.prototype.queueTrigger=function(t,e){this.triggerQueues[e].push(t)},i.prototype.remove=function(t){var e=n.Adapter.inArray(t,this.waypoints);e>-1&&this.waypoints.splice(e,1)},i.prototype.first=function(){return this.waypoints[0]},i.prototype.last=function(){return this.waypoints[this.waypoints.length-1]},i.findOrCreate=function(t){return o[t.axis][t.name]||new i(t)},n.Group=i}(),function(){"use strict";function t(t){this.element=t,this.$element=e(t)}var e=window.Zepto,i=window.Waypoint;e.each(["off","on","scrollLeft","scrollTop"],function(e,i){t.prototype[i]=function(){var t=Array.prototype.slice.call(arguments);return this.$element[i].apply(this.$element,t)}}),t.prototype.offset=function(){return this.element!==this.element.window?this.$element.offset():void 0},e.each(["width","height"],function(i,o){function n(t,i){return function(t){var n=this.$element,r=n[o](),s={width:["left","right"],height:["top","bottom"]};return e.each(s[o],function(e,o){r+=parseInt(n.css("padding-"+o),10),i&&(r+=parseInt(n.css("border-"+o+"-width"),10)),t&&(r+=parseInt(n.css("margin-"+o),10))}),r}}var r=e.camelCase("inner-"+o),s=e.camelCase("outer-"+o);t.prototype[r]=n(!1),t.prototype[s]=n(!0)}),e.each(["extend","inArray"],function(i,o){t[o]=e[o]}),t.isEmptyObject=function(t){for(var e in t)return!1;return!0},i.adapters.push({name:"zepto",Adapter:t}),i.Adapter=t}(),function(){"use strict";function t(t){return function(){var i=[],o=arguments[0];return t.isFunction(arguments[0])&&(o=t.extend({},arguments[1]),o.handler=arguments[0]),this.each(function(){var n=t.extend({},o,{element:this});"string"==typeof n.context&&(n.context=t(this).closest(n.context)[0]),i.push(new e(n))}),i}}var e=window.Waypoint;window.jQuery&&(window.jQuery.fn.waypoint=t(window.jQuery)),window.Zepto&&(window.Zepto.fn.waypoint=t(window.Zepto))}(); \ No newline at end of file +!function(){"use strict";function t(o){if(!o)throw new Error("No options passed to Waypoint constructor");if(!o.element)throw new Error("No element option passed to Waypoint constructor");if(!o.handler)throw new Error("No handler option passed to Waypoint constructor");this.key="waypoint-"+e,this.options=t.Adapter.extend({},t.defaults,o),this.element=this.options.element,this.adapter=new t.Adapter(this.element),this.callback=o.handler,this.axis=this.options.horizontal?"horizontal":"vertical",this.enabled=this.options.enabled,this.triggerPoint=null,this.group=t.Group.findOrCreate({name:this.options.group,axis:this.axis}),this.context=t.Context.findOrCreateByElement(this.options.context),t.offsetAliases[this.options.offset]&&(this.options.offset=t.offsetAliases[this.options.offset]),this.group.add(this),this.context.add(this),i[this.key]=this,e+=1}var e=0,i={};t.prototype.queueTrigger=function(t){this.group.queueTrigger(this,t)},t.prototype.trigger=function(t){this.enabled&&this.callback&&this.callback.apply(this,t)},t.prototype.destroy=function(){this.context.remove(this),this.group.remove(this),delete i[this.key]},t.prototype.disable=function(){return this.enabled=!1,this},t.prototype.enable=function(){return this.context.refresh(),this.enabled=!0,this},t.prototype.next=function(){return this.group.next(this)},t.prototype.previous=function(){return this.group.previous(this)},t.invokeAll=function(t){var e=[];for(var o in i)e.push(i[o]);for(var n=0,r=e.length;r>n;n++)e[n][t]()},t.destroyAll=function(){t.invokeAll("destroy")},t.disableAll=function(){t.invokeAll("disable")},t.enableAll=function(){t.invokeAll("enable")},t.refreshAll=function(){t.Context.refreshAll()},t.viewportHeight=function(){return window.innerHeight||document.documentElement.clientHeight},t.viewportWidth=function(){return document.documentElement.clientWidth},t.adapters=[],t.defaults={context:window,continuous:!0,enabled:!0,group:"default",horizontal:!1,offset:0},t.offsetAliases={"bottom-in-view":function(){return this.context.innerHeight()-this.adapter.outerHeight()},"right-in-view":function(){return this.context.innerWidth()-this.adapter.outerWidth()}},window.Waypoint=t}(),function(){"use strict";function t(t){window.setTimeout(t,1e3/60)}function e(t){this.element=t,this.Adapter=n.Adapter,this.adapter=new this.Adapter(t),this.key="waypoint-context-"+i,this.didScroll=!1,this.didResize=!1,this.oldScroll={x:this.adapter.scrollLeft(),y:this.adapter.scrollTop()},this.waypoints={vertical:{},horizontal:{}},t.waypointContextKey=this.key,o[t.waypointContextKey]=this,i+=1,this.createThrottledScrollHandler(),this.createThrottledResizeHandler()}var i=0,o={},n=window.Waypoint,r=window.onload;e.prototype.add=function(t){var e=t.options.horizontal?"horizontal":"vertical";this.waypoints[e][t.key]=t,this.refresh()},e.prototype.checkEmpty=function(){var t=this.Adapter.isEmptyObject(this.waypoints.horizontal),e=this.Adapter.isEmptyObject(this.waypoints.vertical);t&&e&&(this.adapter.off(".waypoints"),delete o[this.key])},e.prototype.createThrottledResizeHandler=function(){function t(){e.handleResize(),e.didResize=!1}var e=this;this.adapter.on("resize.waypoints",function(){e.didResize||(e.didResize=!0,n.requestAnimationFrame(t))})},e.prototype.createThrottledScrollHandler=function(){function t(){e.handleScroll(),e.didScroll=!1}var e=this;this.adapter.on("scroll.waypoints",function(){(!e.didScroll||n.isTouch)&&(e.didScroll=!0,n.requestAnimationFrame(t))})},e.prototype.handleResize=function(){n.Context.refreshAll()},e.prototype.handleScroll=function(){var t={},e={horizontal:{newScroll:this.adapter.scrollLeft(),oldScroll:this.oldScroll.x,forward:"right",backward:"left"},vertical:{newScroll:this.adapter.scrollTop(),oldScroll:this.oldScroll.y,forward:"down",backward:"up"}};for(var i in e){var o=e[i],n=o.newScroll>o.oldScroll,r=n?o.forward:o.backward;for(var s in this.waypoints[i]){var a=this.waypoints[i][s],l=o.oldScroll=a.triggerPoint,p=l&&h,c=!l&&!h;(p||c)&&(a.queueTrigger(r),t[a.group.id]=a.group)}}for(var u in t)t[u].flushTriggers();this.oldScroll={x:e.horizontal.newScroll,y:e.vertical.newScroll}},e.prototype.innerHeight=function(){return this.element==this.element.window?n.viewportHeight():this.adapter.innerHeight()},e.prototype.remove=function(t){delete this.waypoints[t.axis][t.key],this.checkEmpty()},e.prototype.innerWidth=function(){return this.element==this.element.window?n.viewportWidth():this.adapter.innerWidth()},e.prototype.destroy=function(){var t=[];for(var e in this.waypoints)for(var i in this.waypoints[e])t.push(this.waypoints[e][i]);for(var o=0,n=t.length;n>o;o++)t[o].destroy()},e.prototype.refresh=function(){var t,e=this.element==this.element.window,i=e?void 0:this.adapter.offset(),o={};this.handleScroll(),t={horizontal:{contextOffset:e?0:i.left,contextScroll:e?0:this.oldScroll.x,contextDimension:this.innerWidth(),oldScroll:this.oldScroll.x,forward:"right",backward:"left",offsetProp:"left"},vertical:{contextOffset:e?0:i.top,contextScroll:e?0:this.oldScroll.y,contextDimension:this.innerHeight(),oldScroll:this.oldScroll.y,forward:"down",backward:"up",offsetProp:"top"}};for(var r in t){var s=t[r];for(var a in this.waypoints[r]){var l,h,p,c,u,d=this.waypoints[r][a],f=d.options.offset,w=d.triggerPoint,y=0,g=null==w;d.element!==d.element.window&&(y=d.adapter.offset()[s.offsetProp]),"function"==typeof f?f=f.apply(d):"string"==typeof f&&(f=parseFloat(f),d.options.offset.indexOf("%")>-1&&(f=Math.ceil(s.contextDimension*f/100))),l=s.contextScroll-s.contextOffset,d.triggerPoint=y+l-f,h=w=s.oldScroll,c=h&&p,u=!h&&!p,!g&&c?(d.queueTrigger(s.backward),o[d.group.id]=d.group):!g&&u?(d.queueTrigger(s.forward),o[d.group.id]=d.group):g&&s.oldScroll>=d.triggerPoint&&(d.queueTrigger(s.forward),o[d.group.id]=d.group)}}return n.requestAnimationFrame(function(){for(var t in o)o[t].flushTriggers()}),this},e.findOrCreateByElement=function(t){return e.findByElement(t)||new e(t)},e.refreshAll=function(){for(var t in o)o[t].refresh()},e.findByElement=function(t){return o[t.waypointContextKey]},window.onload=function(){r&&r(),e.refreshAll()},n.requestAnimationFrame=function(e){var i=window.requestAnimationFrame||window.mozRequestAnimationFrame||window.webkitRequestAnimationFrame||t;i.call(window,e)},n.Context=e}(),function(){"use strict";function t(t,e){return t.triggerPoint-e.triggerPoint}function e(t,e){return e.triggerPoint-t.triggerPoint}function i(t){this.name=t.name,this.axis=t.axis,this.id=this.name+"-"+this.axis,this.waypoints=[],this.clearTriggerQueues(),o[this.axis][this.name]=this}var o={vertical:{},horizontal:{}},n=window.Waypoint;i.prototype.add=function(t){this.waypoints.push(t)},i.prototype.clearTriggerQueues=function(){this.triggerQueues={up:[],down:[],left:[],right:[]}},i.prototype.flushTriggers=function(){for(var i in this.triggerQueues){var o=this.triggerQueues[i],n="up"===i||"left"===i;o.sort(n?e:t);for(var r=0,s=o.length;s>r;r+=1){var a=o[r];(a.options.continuous||r===o.length-1)&&a.trigger([i])}}this.clearTriggerQueues()},i.prototype.next=function(e){this.waypoints.sort(t);var i=n.Adapter.inArray(e,this.waypoints),o=i===this.waypoints.length-1;return o?null:this.waypoints[i+1]},i.prototype.previous=function(e){this.waypoints.sort(t);var i=n.Adapter.inArray(e,this.waypoints);return i?this.waypoints[i-1]:null},i.prototype.queueTrigger=function(t,e){this.triggerQueues[e].push(t)},i.prototype.remove=function(t){var e=n.Adapter.inArray(t,this.waypoints);e>-1&&this.waypoints.splice(e,1)},i.prototype.first=function(){return this.waypoints[0]},i.prototype.last=function(){return this.waypoints[this.waypoints.length-1]},i.findOrCreate=function(t){return o[t.axis][t.name]||new i(t)},n.Group=i}(),function(){"use strict";function t(t){this.element=t,this.$element=e(t)}var e=window.Zepto,i=window.Waypoint;e.each(["off","on","scrollLeft","scrollTop"],function(e,i){t.prototype[i]=function(){var t=Array.prototype.slice.call(arguments);return this.$element[i].apply(this.$element,t)}}),t.prototype.offset=function(){return this.element!==this.element.window?this.$element.offset():void 0},e.each(["width","height"],function(i,o){function n(t,i){return function(t){var n=this.$element,r=n[o](),s={width:["left","right"],height:["top","bottom"]};return e.each(s[o],function(e,o){r+=parseInt(n.css("padding-"+o),10),i&&(r+=parseInt(n.css("border-"+o+"-width"),10)),t&&(r+=parseInt(n.css("margin-"+o),10))}),r}}var r=e.camelCase("inner-"+o),s=e.camelCase("outer-"+o);t.prototype[r]=n(!1),t.prototype[s]=n(!0)}),e.each(["extend","inArray"],function(i,o){t[o]=e[o]}),t.isEmptyObject=function(t){for(var e in t)return!1;return!0},i.adapters.push({name:"zepto",Adapter:t}),i.Adapter=t}(),function(){"use strict";function t(t){return function(){var i=[],o=arguments[0];return t.isFunction(arguments[0])&&(o=t.extend({},arguments[1]),o.handler=arguments[0]),this.each(function(){var n=t.extend({},o,{element:this});"string"==typeof n.context&&(n.context=t(this).closest(n.context)[0]),i.push(new e(n))}),i}}var e=window.Waypoint;window.jQuery&&(window.jQuery.fn.waypoint=t(window.jQuery)),window.Zepto&&(window.Zepto.fn.waypoint=t(window.Zepto))}(); \ No newline at end of file diff --git a/src/shortcuts/inview.js b/src/shortcuts/inview.js index b1b540b1..34c587dd 100644 --- a/src/shortcuts/inview.js +++ b/src/shortcuts/inview.js @@ -66,6 +66,7 @@ Inview.prototype.createWaypoint = function(config) { var self = this this.waypoints.push(new Waypoint({ + context: this.options.context, element: this.options.element, enabled: this.options.enabled, handler: (function(config) { @@ -99,6 +100,7 @@ } Inview.defaults = { + context: window, enabled: true, enter: noop, entered: noop, From 8651a2548eba949ce4eecb49577f0ded3bdd2152 Mon Sep 17 00:00:00 2001 From: imakewebthings Date: Mon, 17 Aug 2015 23:22:25 -0700 Subject: [PATCH 90/98] Travis container config --- .travis.yml | 1 + 1 file changed, 1 insertion(+) diff --git a/.travis.yml b/.travis.yml index a094d1a2..f4910ba7 100644 --- a/.travis.yml +++ b/.travis.yml @@ -1,4 +1,5 @@ language: node_js +sudo: false node_js: - "0.10" before_script: From 1336d1aedc8ddf7520c97284b46d7d81792c3a44 Mon Sep 17 00:00:00 2001 From: imakewebthings Date: Tue, 18 Aug 2015 22:24:24 -0700 Subject: [PATCH 91/98] Add element to Inview instance properties --- lib/shortcuts/inview.js | 1 + lib/shortcuts/inview.min.js | 2 +- src/shortcuts/inview.js | 1 + 3 files changed, 3 insertions(+), 1 deletion(-) diff --git a/lib/shortcuts/inview.js b/lib/shortcuts/inview.js index a4a591c1..fbea2c8c 100644 --- a/lib/shortcuts/inview.js +++ b/lib/shortcuts/inview.js @@ -16,6 +16,7 @@ https://github.com/imakewebthings/waypoints/blog/master/licenses.txt this.options = Waypoint.Adapter.extend({}, Inview.defaults, options) this.axis = this.options.horizontal ? 'horizontal' : 'vertical' this.waypoints = [] + this.element = this.options.element this.createWaypoints() } diff --git a/lib/shortcuts/inview.min.js b/lib/shortcuts/inview.min.js index 674df63b..c7c57f70 100644 --- a/lib/shortcuts/inview.min.js +++ b/lib/shortcuts/inview.min.js @@ -4,4 +4,4 @@ Copyright © 2011-2015 Caleb Troughton Licensed under the MIT license. https://github.com/imakewebthings/waypoints/blog/master/licenses.txt */ -!function(){"use strict";function t(){}function e(t){this.options=i.Adapter.extend({},e.defaults,t),this.axis=this.options.horizontal?"horizontal":"vertical",this.waypoints=[],this.createWaypoints()}var i=window.Waypoint;e.prototype.createWaypoints=function(){for(var t={vertical:[{down:"enter",up:"exited",offset:"100%"},{down:"entered",up:"exit",offset:"bottom-in-view"},{down:"exit",up:"entered",offset:0},{down:"exited",up:"enter",offset:function(){return-this.adapter.outerHeight()}}],horizontal:[{right:"enter",left:"exited",offset:"100%"},{right:"entered",left:"exit",offset:"right-in-view"},{right:"exit",left:"entered",offset:0},{right:"exited",left:"enter",offset:function(){return-this.adapter.outerWidth()}}]},e=0,i=t[this.axis].length;i>e;e++){var n=t[this.axis][e];this.createWaypoint(n)}},e.prototype.createWaypoint=function(t){var e=this;this.waypoints.push(new i({context:this.options.context,element:this.options.element,enabled:this.options.enabled,handler:function(t){return function(i){e.options[t[i]].call(e,i)}}(t),offset:t.offset,horizontal:this.options.horizontal}))},e.prototype.destroy=function(){for(var t=0,e=this.waypoints.length;e>t;t++)this.waypoints[t].destroy();this.waypoints=[]},e.prototype.disable=function(){for(var t=0,e=this.waypoints.length;e>t;t++)this.waypoints[t].disable()},e.prototype.enable=function(){for(var t=0,e=this.waypoints.length;e>t;t++)this.waypoints[t].enable()},e.defaults={context:window,enabled:!0,enter:t,entered:t,exit:t,exited:t},i.Inview=e}(); \ No newline at end of file +!function(){"use strict";function t(){}function e(t){this.options=i.Adapter.extend({},e.defaults,t),this.axis=this.options.horizontal?"horizontal":"vertical",this.waypoints=[],this.element=this.options.element,this.createWaypoints()}var i=window.Waypoint;e.prototype.createWaypoints=function(){for(var t={vertical:[{down:"enter",up:"exited",offset:"100%"},{down:"entered",up:"exit",offset:"bottom-in-view"},{down:"exit",up:"entered",offset:0},{down:"exited",up:"enter",offset:function(){return-this.adapter.outerHeight()}}],horizontal:[{right:"enter",left:"exited",offset:"100%"},{right:"entered",left:"exit",offset:"right-in-view"},{right:"exit",left:"entered",offset:0},{right:"exited",left:"enter",offset:function(){return-this.adapter.outerWidth()}}]},e=0,i=t[this.axis].length;i>e;e++){var n=t[this.axis][e];this.createWaypoint(n)}},e.prototype.createWaypoint=function(t){var e=this;this.waypoints.push(new i({context:this.options.context,element:this.options.element,enabled:this.options.enabled,handler:function(t){return function(i){e.options[t[i]].call(e,i)}}(t),offset:t.offset,horizontal:this.options.horizontal}))},e.prototype.destroy=function(){for(var t=0,e=this.waypoints.length;e>t;t++)this.waypoints[t].destroy();this.waypoints=[]},e.prototype.disable=function(){for(var t=0,e=this.waypoints.length;e>t;t++)this.waypoints[t].disable()},e.prototype.enable=function(){for(var t=0,e=this.waypoints.length;e>t;t++)this.waypoints[t].enable()},e.defaults={context:window,enabled:!0,enter:t,entered:t,exit:t,exited:t},i.Inview=e}(); \ No newline at end of file diff --git a/src/shortcuts/inview.js b/src/shortcuts/inview.js index 34c587dd..cda4b1f0 100644 --- a/src/shortcuts/inview.js +++ b/src/shortcuts/inview.js @@ -10,6 +10,7 @@ this.options = Waypoint.Adapter.extend({}, Inview.defaults, options) this.axis = this.options.horizontal ? 'horizontal' : 'vertical' this.waypoints = [] + this.element = this.options.element this.createWaypoints() } From 0944e1569dd46a05494c3c056e4328884a739a4f Mon Sep 17 00:00:00 2001 From: imakewebthings Date: Tue, 18 Aug 2015 22:40:13 -0700 Subject: [PATCH 92/98] 4.0.0 --- lib/jquery.waypoints.js | 2 +- lib/jquery.waypoints.min.js | 2 +- lib/noframework.waypoints.js | 2 +- lib/noframework.waypoints.min.js | 2 +- lib/shortcuts/infinite.js | 2 +- lib/shortcuts/infinite.min.js | 2 +- lib/shortcuts/inview.js | 2 +- lib/shortcuts/inview.min.js | 2 +- lib/shortcuts/sticky.js | 2 +- lib/shortcuts/sticky.min.js | 2 +- lib/waypoints.debug.js | 2 +- lib/zepto.waypoints.js | 2 +- lib/zepto.waypoints.min.js | 2 +- package.json | 2 +- 14 files changed, 14 insertions(+), 14 deletions(-) diff --git a/lib/jquery.waypoints.js b/lib/jquery.waypoints.js index f89a374f..650f681b 100644 --- a/lib/jquery.waypoints.js +++ b/lib/jquery.waypoints.js @@ -1,5 +1,5 @@ /*! -Waypoints - 3.1.1 +Waypoints - 4.0.0 Copyright © 2011-2015 Caleb Troughton Licensed under the MIT license. https://github.com/imakewebthings/waypoints/blog/master/licenses.txt diff --git a/lib/jquery.waypoints.min.js b/lib/jquery.waypoints.min.js index 4b8c85cd..39955396 100644 --- a/lib/jquery.waypoints.min.js +++ b/lib/jquery.waypoints.min.js @@ -1,5 +1,5 @@ /*! -Waypoints - 3.1.1 +Waypoints - 4.0.0 Copyright © 2011-2015 Caleb Troughton Licensed under the MIT license. https://github.com/imakewebthings/waypoints/blog/master/licenses.txt diff --git a/lib/noframework.waypoints.js b/lib/noframework.waypoints.js index a3ad9228..f05275d6 100644 --- a/lib/noframework.waypoints.js +++ b/lib/noframework.waypoints.js @@ -1,5 +1,5 @@ /*! -Waypoints - 3.1.1 +Waypoints - 4.0.0 Copyright © 2011-2015 Caleb Troughton Licensed under the MIT license. https://github.com/imakewebthings/waypoints/blog/master/licenses.txt diff --git a/lib/noframework.waypoints.min.js b/lib/noframework.waypoints.min.js index ed4a5999..e153e630 100644 --- a/lib/noframework.waypoints.min.js +++ b/lib/noframework.waypoints.min.js @@ -1,5 +1,5 @@ /*! -Waypoints - 3.1.1 +Waypoints - 4.0.0 Copyright © 2011-2015 Caleb Troughton Licensed under the MIT license. https://github.com/imakewebthings/waypoints/blog/master/licenses.txt diff --git a/lib/shortcuts/infinite.js b/lib/shortcuts/infinite.js index 9d136711..61f72cd8 100644 --- a/lib/shortcuts/infinite.js +++ b/lib/shortcuts/infinite.js @@ -1,5 +1,5 @@ /*! -Waypoints Infinite Scroll Shortcut - 3.1.1 +Waypoints Infinite Scroll Shortcut - 4.0.0 Copyright © 2011-2015 Caleb Troughton Licensed under the MIT license. https://github.com/imakewebthings/waypoints/blog/master/licenses.txt diff --git a/lib/shortcuts/infinite.min.js b/lib/shortcuts/infinite.min.js index 015d7679..50d1134d 100644 --- a/lib/shortcuts/infinite.min.js +++ b/lib/shortcuts/infinite.min.js @@ -1,5 +1,5 @@ /*! -Waypoints Infinite Scroll Shortcut - 3.1.1 +Waypoints Infinite Scroll Shortcut - 4.0.0 Copyright © 2011-2015 Caleb Troughton Licensed under the MIT license. https://github.com/imakewebthings/waypoints/blog/master/licenses.txt diff --git a/lib/shortcuts/inview.js b/lib/shortcuts/inview.js index fbea2c8c..20aa59b8 100644 --- a/lib/shortcuts/inview.js +++ b/lib/shortcuts/inview.js @@ -1,5 +1,5 @@ /*! -Waypoints Inview Shortcut - 3.1.1 +Waypoints Inview Shortcut - 4.0.0 Copyright © 2011-2015 Caleb Troughton Licensed under the MIT license. https://github.com/imakewebthings/waypoints/blog/master/licenses.txt diff --git a/lib/shortcuts/inview.min.js b/lib/shortcuts/inview.min.js index c7c57f70..5a07530b 100644 --- a/lib/shortcuts/inview.min.js +++ b/lib/shortcuts/inview.min.js @@ -1,5 +1,5 @@ /*! -Waypoints Inview Shortcut - 3.1.1 +Waypoints Inview Shortcut - 4.0.0 Copyright © 2011-2015 Caleb Troughton Licensed under the MIT license. https://github.com/imakewebthings/waypoints/blog/master/licenses.txt diff --git a/lib/shortcuts/sticky.js b/lib/shortcuts/sticky.js index 8a74c2a2..4e07cb7e 100644 --- a/lib/shortcuts/sticky.js +++ b/lib/shortcuts/sticky.js @@ -1,5 +1,5 @@ /*! -Waypoints Sticky Element Shortcut - 3.1.1 +Waypoints Sticky Element Shortcut - 4.0.0 Copyright © 2011-2015 Caleb Troughton Licensed under the MIT license. https://github.com/imakewebthings/waypoints/blog/master/licenses.txt diff --git a/lib/shortcuts/sticky.min.js b/lib/shortcuts/sticky.min.js index 9173935c..fd8dcc13 100644 --- a/lib/shortcuts/sticky.min.js +++ b/lib/shortcuts/sticky.min.js @@ -1,5 +1,5 @@ /*! -Waypoints Sticky Element Shortcut - 3.1.1 +Waypoints Sticky Element Shortcut - 4.0.0 Copyright © 2011-2015 Caleb Troughton Licensed under the MIT license. https://github.com/imakewebthings/waypoints/blog/master/licenses.txt diff --git a/lib/waypoints.debug.js b/lib/waypoints.debug.js index 6e7dc8d5..f60a9592 100644 --- a/lib/waypoints.debug.js +++ b/lib/waypoints.debug.js @@ -1,5 +1,5 @@ /*! -Waypoints Debug - 3.1.1 +Waypoints Debug - 4.0.0 Copyright © 2011-2015 Caleb Troughton Licensed under the MIT license. https://github.com/imakewebthings/waypoints/blog/master/licenses.txt diff --git a/lib/zepto.waypoints.js b/lib/zepto.waypoints.js index be4b02c7..0409af6d 100644 --- a/lib/zepto.waypoints.js +++ b/lib/zepto.waypoints.js @@ -1,5 +1,5 @@ /*! -Waypoints - 3.1.1 +Waypoints - 4.0.0 Copyright © 2011-2015 Caleb Troughton Licensed under the MIT license. https://github.com/imakewebthings/waypoints/blog/master/licenses.txt diff --git a/lib/zepto.waypoints.min.js b/lib/zepto.waypoints.min.js index e429af44..7062bc97 100644 --- a/lib/zepto.waypoints.min.js +++ b/lib/zepto.waypoints.min.js @@ -1,5 +1,5 @@ /*! -Waypoints - 3.1.1 +Waypoints - 4.0.0 Copyright © 2011-2015 Caleb Troughton Licensed under the MIT license. https://github.com/imakewebthings/waypoints/blog/master/licenses.txt diff --git a/package.json b/package.json index 88270b9c..22a85166 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "waypoints", - "version": "3.1.1", + "version": "4.0.0", "author": "Caleb Troughton (http://imakewebthings.com)", "description": "Easily execute a function when you scroll to an element", "scripts": { From 9bdcb2c982102eec2508f3c4964395171f325515 Mon Sep 17 00:00:00 2001 From: rochefort Date: Fri, 11 Sep 2015 02:11:29 +0900 Subject: [PATCH 93/98] Fix typos --- gulpfile.js | 2 +- lib/jquery.waypoints.js | 2 +- lib/jquery.waypoints.min.js | 2 +- lib/noframework.waypoints.js | 2 +- lib/noframework.waypoints.min.js | 2 +- lib/shortcuts/infinite.js | 2 +- lib/shortcuts/infinite.min.js | 2 +- lib/shortcuts/inview.js | 2 +- lib/shortcuts/inview.min.js | 2 +- lib/shortcuts/sticky.js | 2 +- lib/shortcuts/sticky.min.js | 2 +- lib/waypoints.debug.js | 2 +- lib/zepto.waypoints.js | 2 +- lib/zepto.waypoints.min.js | 2 +- 14 files changed, 14 insertions(+), 14 deletions(-) diff --git a/gulpfile.js b/gulpfile.js index 36944665..2eb60bc1 100644 --- a/gulpfile.js +++ b/gulpfile.js @@ -23,7 +23,7 @@ function fileHeader(title) { title + ' - ' + pkg.version, 'Copyright © 2011-' + new Date().getFullYear() + ' Caleb Troughton', 'Licensed under the MIT license.', - 'https://github.com/imakewebthings/waypoints/blog/master/licenses.txt', + 'https://github.com/imakewebthings/waypoints/blob/master/licenses.txt', '*/\n' ].join('\n') } diff --git a/lib/jquery.waypoints.js b/lib/jquery.waypoints.js index 650f681b..90372dd8 100644 --- a/lib/jquery.waypoints.js +++ b/lib/jquery.waypoints.js @@ -2,7 +2,7 @@ Waypoints - 4.0.0 Copyright © 2011-2015 Caleb Troughton Licensed under the MIT license. -https://github.com/imakewebthings/waypoints/blog/master/licenses.txt +https://github.com/imakewebthings/waypoints/blob/master/licenses.txt */ (function() { 'use strict' diff --git a/lib/jquery.waypoints.min.js b/lib/jquery.waypoints.min.js index 39955396..20e6f625 100644 --- a/lib/jquery.waypoints.min.js +++ b/lib/jquery.waypoints.min.js @@ -2,6 +2,6 @@ Waypoints - 4.0.0 Copyright © 2011-2015 Caleb Troughton Licensed under the MIT license. -https://github.com/imakewebthings/waypoints/blog/master/licenses.txt +https://github.com/imakewebthings/waypoints/blob/master/licenses.txt */ !function(){"use strict";function t(o){if(!o)throw new Error("No options passed to Waypoint constructor");if(!o.element)throw new Error("No element option passed to Waypoint constructor");if(!o.handler)throw new Error("No handler option passed to Waypoint constructor");this.key="waypoint-"+e,this.options=t.Adapter.extend({},t.defaults,o),this.element=this.options.element,this.adapter=new t.Adapter(this.element),this.callback=o.handler,this.axis=this.options.horizontal?"horizontal":"vertical",this.enabled=this.options.enabled,this.triggerPoint=null,this.group=t.Group.findOrCreate({name:this.options.group,axis:this.axis}),this.context=t.Context.findOrCreateByElement(this.options.context),t.offsetAliases[this.options.offset]&&(this.options.offset=t.offsetAliases[this.options.offset]),this.group.add(this),this.context.add(this),i[this.key]=this,e+=1}var e=0,i={};t.prototype.queueTrigger=function(t){this.group.queueTrigger(this,t)},t.prototype.trigger=function(t){this.enabled&&this.callback&&this.callback.apply(this,t)},t.prototype.destroy=function(){this.context.remove(this),this.group.remove(this),delete i[this.key]},t.prototype.disable=function(){return this.enabled=!1,this},t.prototype.enable=function(){return this.context.refresh(),this.enabled=!0,this},t.prototype.next=function(){return this.group.next(this)},t.prototype.previous=function(){return this.group.previous(this)},t.invokeAll=function(t){var e=[];for(var o in i)e.push(i[o]);for(var n=0,r=e.length;r>n;n++)e[n][t]()},t.destroyAll=function(){t.invokeAll("destroy")},t.disableAll=function(){t.invokeAll("disable")},t.enableAll=function(){t.invokeAll("enable")},t.refreshAll=function(){t.Context.refreshAll()},t.viewportHeight=function(){return window.innerHeight||document.documentElement.clientHeight},t.viewportWidth=function(){return document.documentElement.clientWidth},t.adapters=[],t.defaults={context:window,continuous:!0,enabled:!0,group:"default",horizontal:!1,offset:0},t.offsetAliases={"bottom-in-view":function(){return this.context.innerHeight()-this.adapter.outerHeight()},"right-in-view":function(){return this.context.innerWidth()-this.adapter.outerWidth()}},window.Waypoint=t}(),function(){"use strict";function t(t){window.setTimeout(t,1e3/60)}function e(t){this.element=t,this.Adapter=n.Adapter,this.adapter=new this.Adapter(t),this.key="waypoint-context-"+i,this.didScroll=!1,this.didResize=!1,this.oldScroll={x:this.adapter.scrollLeft(),y:this.adapter.scrollTop()},this.waypoints={vertical:{},horizontal:{}},t.waypointContextKey=this.key,o[t.waypointContextKey]=this,i+=1,this.createThrottledScrollHandler(),this.createThrottledResizeHandler()}var i=0,o={},n=window.Waypoint,r=window.onload;e.prototype.add=function(t){var e=t.options.horizontal?"horizontal":"vertical";this.waypoints[e][t.key]=t,this.refresh()},e.prototype.checkEmpty=function(){var t=this.Adapter.isEmptyObject(this.waypoints.horizontal),e=this.Adapter.isEmptyObject(this.waypoints.vertical);t&&e&&(this.adapter.off(".waypoints"),delete o[this.key])},e.prototype.createThrottledResizeHandler=function(){function t(){e.handleResize(),e.didResize=!1}var e=this;this.adapter.on("resize.waypoints",function(){e.didResize||(e.didResize=!0,n.requestAnimationFrame(t))})},e.prototype.createThrottledScrollHandler=function(){function t(){e.handleScroll(),e.didScroll=!1}var e=this;this.adapter.on("scroll.waypoints",function(){(!e.didScroll||n.isTouch)&&(e.didScroll=!0,n.requestAnimationFrame(t))})},e.prototype.handleResize=function(){n.Context.refreshAll()},e.prototype.handleScroll=function(){var t={},e={horizontal:{newScroll:this.adapter.scrollLeft(),oldScroll:this.oldScroll.x,forward:"right",backward:"left"},vertical:{newScroll:this.adapter.scrollTop(),oldScroll:this.oldScroll.y,forward:"down",backward:"up"}};for(var i in e){var o=e[i],n=o.newScroll>o.oldScroll,r=n?o.forward:o.backward;for(var s in this.waypoints[i]){var a=this.waypoints[i][s],l=o.oldScroll=a.triggerPoint,p=l&&h,u=!l&&!h;(p||u)&&(a.queueTrigger(r),t[a.group.id]=a.group)}}for(var c in t)t[c].flushTriggers();this.oldScroll={x:e.horizontal.newScroll,y:e.vertical.newScroll}},e.prototype.innerHeight=function(){return this.element==this.element.window?n.viewportHeight():this.adapter.innerHeight()},e.prototype.remove=function(t){delete this.waypoints[t.axis][t.key],this.checkEmpty()},e.prototype.innerWidth=function(){return this.element==this.element.window?n.viewportWidth():this.adapter.innerWidth()},e.prototype.destroy=function(){var t=[];for(var e in this.waypoints)for(var i in this.waypoints[e])t.push(this.waypoints[e][i]);for(var o=0,n=t.length;n>o;o++)t[o].destroy()},e.prototype.refresh=function(){var t,e=this.element==this.element.window,i=e?void 0:this.adapter.offset(),o={};this.handleScroll(),t={horizontal:{contextOffset:e?0:i.left,contextScroll:e?0:this.oldScroll.x,contextDimension:this.innerWidth(),oldScroll:this.oldScroll.x,forward:"right",backward:"left",offsetProp:"left"},vertical:{contextOffset:e?0:i.top,contextScroll:e?0:this.oldScroll.y,contextDimension:this.innerHeight(),oldScroll:this.oldScroll.y,forward:"down",backward:"up",offsetProp:"top"}};for(var r in t){var s=t[r];for(var a in this.waypoints[r]){var l,h,p,u,c,d=this.waypoints[r][a],f=d.options.offset,w=d.triggerPoint,y=0,g=null==w;d.element!==d.element.window&&(y=d.adapter.offset()[s.offsetProp]),"function"==typeof f?f=f.apply(d):"string"==typeof f&&(f=parseFloat(f),d.options.offset.indexOf("%")>-1&&(f=Math.ceil(s.contextDimension*f/100))),l=s.contextScroll-s.contextOffset,d.triggerPoint=y+l-f,h=w=s.oldScroll,u=h&&p,c=!h&&!p,!g&&u?(d.queueTrigger(s.backward),o[d.group.id]=d.group):!g&&c?(d.queueTrigger(s.forward),o[d.group.id]=d.group):g&&s.oldScroll>=d.triggerPoint&&(d.queueTrigger(s.forward),o[d.group.id]=d.group)}}return n.requestAnimationFrame(function(){for(var t in o)o[t].flushTriggers()}),this},e.findOrCreateByElement=function(t){return e.findByElement(t)||new e(t)},e.refreshAll=function(){for(var t in o)o[t].refresh()},e.findByElement=function(t){return o[t.waypointContextKey]},window.onload=function(){r&&r(),e.refreshAll()},n.requestAnimationFrame=function(e){var i=window.requestAnimationFrame||window.mozRequestAnimationFrame||window.webkitRequestAnimationFrame||t;i.call(window,e)},n.Context=e}(),function(){"use strict";function t(t,e){return t.triggerPoint-e.triggerPoint}function e(t,e){return e.triggerPoint-t.triggerPoint}function i(t){this.name=t.name,this.axis=t.axis,this.id=this.name+"-"+this.axis,this.waypoints=[],this.clearTriggerQueues(),o[this.axis][this.name]=this}var o={vertical:{},horizontal:{}},n=window.Waypoint;i.prototype.add=function(t){this.waypoints.push(t)},i.prototype.clearTriggerQueues=function(){this.triggerQueues={up:[],down:[],left:[],right:[]}},i.prototype.flushTriggers=function(){for(var i in this.triggerQueues){var o=this.triggerQueues[i],n="up"===i||"left"===i;o.sort(n?e:t);for(var r=0,s=o.length;s>r;r+=1){var a=o[r];(a.options.continuous||r===o.length-1)&&a.trigger([i])}}this.clearTriggerQueues()},i.prototype.next=function(e){this.waypoints.sort(t);var i=n.Adapter.inArray(e,this.waypoints),o=i===this.waypoints.length-1;return o?null:this.waypoints[i+1]},i.prototype.previous=function(e){this.waypoints.sort(t);var i=n.Adapter.inArray(e,this.waypoints);return i?this.waypoints[i-1]:null},i.prototype.queueTrigger=function(t,e){this.triggerQueues[e].push(t)},i.prototype.remove=function(t){var e=n.Adapter.inArray(t,this.waypoints);e>-1&&this.waypoints.splice(e,1)},i.prototype.first=function(){return this.waypoints[0]},i.prototype.last=function(){return this.waypoints[this.waypoints.length-1]},i.findOrCreate=function(t){return o[t.axis][t.name]||new i(t)},n.Group=i}(),function(){"use strict";function t(t){this.$element=e(t)}var e=window.jQuery,i=window.Waypoint;e.each(["innerHeight","innerWidth","off","offset","on","outerHeight","outerWidth","scrollLeft","scrollTop"],function(e,i){t.prototype[i]=function(){var t=Array.prototype.slice.call(arguments);return this.$element[i].apply(this.$element,t)}}),e.each(["extend","inArray","isEmptyObject"],function(i,o){t[o]=e[o]}),i.adapters.push({name:"jquery",Adapter:t}),i.Adapter=t}(),function(){"use strict";function t(t){return function(){var i=[],o=arguments[0];return t.isFunction(arguments[0])&&(o=t.extend({},arguments[1]),o.handler=arguments[0]),this.each(function(){var n=t.extend({},o,{element:this});"string"==typeof n.context&&(n.context=t(this).closest(n.context)[0]),i.push(new e(n))}),i}}var e=window.Waypoint;window.jQuery&&(window.jQuery.fn.waypoint=t(window.jQuery)),window.Zepto&&(window.Zepto.fn.waypoint=t(window.Zepto))}(); \ No newline at end of file diff --git a/lib/noframework.waypoints.js b/lib/noframework.waypoints.js index f05275d6..2de1c3c5 100644 --- a/lib/noframework.waypoints.js +++ b/lib/noframework.waypoints.js @@ -2,7 +2,7 @@ Waypoints - 4.0.0 Copyright © 2011-2015 Caleb Troughton Licensed under the MIT license. -https://github.com/imakewebthings/waypoints/blog/master/licenses.txt +https://github.com/imakewebthings/waypoints/blob/master/licenses.txt */ (function() { 'use strict' diff --git a/lib/noframework.waypoints.min.js b/lib/noframework.waypoints.min.js index e153e630..2ce1f916 100644 --- a/lib/noframework.waypoints.min.js +++ b/lib/noframework.waypoints.min.js @@ -2,6 +2,6 @@ Waypoints - 4.0.0 Copyright © 2011-2015 Caleb Troughton Licensed under the MIT license. -https://github.com/imakewebthings/waypoints/blog/master/licenses.txt +https://github.com/imakewebthings/waypoints/blob/master/licenses.txt */ !function(){"use strict";function t(n){if(!n)throw new Error("No options passed to Waypoint constructor");if(!n.element)throw new Error("No element option passed to Waypoint constructor");if(!n.handler)throw new Error("No handler option passed to Waypoint constructor");this.key="waypoint-"+e,this.options=t.Adapter.extend({},t.defaults,n),this.element=this.options.element,this.adapter=new t.Adapter(this.element),this.callback=n.handler,this.axis=this.options.horizontal?"horizontal":"vertical",this.enabled=this.options.enabled,this.triggerPoint=null,this.group=t.Group.findOrCreate({name:this.options.group,axis:this.axis}),this.context=t.Context.findOrCreateByElement(this.options.context),t.offsetAliases[this.options.offset]&&(this.options.offset=t.offsetAliases[this.options.offset]),this.group.add(this),this.context.add(this),i[this.key]=this,e+=1}var e=0,i={};t.prototype.queueTrigger=function(t){this.group.queueTrigger(this,t)},t.prototype.trigger=function(t){this.enabled&&this.callback&&this.callback.apply(this,t)},t.prototype.destroy=function(){this.context.remove(this),this.group.remove(this),delete i[this.key]},t.prototype.disable=function(){return this.enabled=!1,this},t.prototype.enable=function(){return this.context.refresh(),this.enabled=!0,this},t.prototype.next=function(){return this.group.next(this)},t.prototype.previous=function(){return this.group.previous(this)},t.invokeAll=function(t){var e=[];for(var n in i)e.push(i[n]);for(var o=0,r=e.length;r>o;o++)e[o][t]()},t.destroyAll=function(){t.invokeAll("destroy")},t.disableAll=function(){t.invokeAll("disable")},t.enableAll=function(){t.invokeAll("enable")},t.refreshAll=function(){t.Context.refreshAll()},t.viewportHeight=function(){return window.innerHeight||document.documentElement.clientHeight},t.viewportWidth=function(){return document.documentElement.clientWidth},t.adapters=[],t.defaults={context:window,continuous:!0,enabled:!0,group:"default",horizontal:!1,offset:0},t.offsetAliases={"bottom-in-view":function(){return this.context.innerHeight()-this.adapter.outerHeight()},"right-in-view":function(){return this.context.innerWidth()-this.adapter.outerWidth()}},window.Waypoint=t}(),function(){"use strict";function t(t){window.setTimeout(t,1e3/60)}function e(t){this.element=t,this.Adapter=o.Adapter,this.adapter=new this.Adapter(t),this.key="waypoint-context-"+i,this.didScroll=!1,this.didResize=!1,this.oldScroll={x:this.adapter.scrollLeft(),y:this.adapter.scrollTop()},this.waypoints={vertical:{},horizontal:{}},t.waypointContextKey=this.key,n[t.waypointContextKey]=this,i+=1,this.createThrottledScrollHandler(),this.createThrottledResizeHandler()}var i=0,n={},o=window.Waypoint,r=window.onload;e.prototype.add=function(t){var e=t.options.horizontal?"horizontal":"vertical";this.waypoints[e][t.key]=t,this.refresh()},e.prototype.checkEmpty=function(){var t=this.Adapter.isEmptyObject(this.waypoints.horizontal),e=this.Adapter.isEmptyObject(this.waypoints.vertical);t&&e&&(this.adapter.off(".waypoints"),delete n[this.key])},e.prototype.createThrottledResizeHandler=function(){function t(){e.handleResize(),e.didResize=!1}var e=this;this.adapter.on("resize.waypoints",function(){e.didResize||(e.didResize=!0,o.requestAnimationFrame(t))})},e.prototype.createThrottledScrollHandler=function(){function t(){e.handleScroll(),e.didScroll=!1}var e=this;this.adapter.on("scroll.waypoints",function(){(!e.didScroll||o.isTouch)&&(e.didScroll=!0,o.requestAnimationFrame(t))})},e.prototype.handleResize=function(){o.Context.refreshAll()},e.prototype.handleScroll=function(){var t={},e={horizontal:{newScroll:this.adapter.scrollLeft(),oldScroll:this.oldScroll.x,forward:"right",backward:"left"},vertical:{newScroll:this.adapter.scrollTop(),oldScroll:this.oldScroll.y,forward:"down",backward:"up"}};for(var i in e){var n=e[i],o=n.newScroll>n.oldScroll,r=o?n.forward:n.backward;for(var s in this.waypoints[i]){var l=this.waypoints[i][s],a=n.oldScroll=l.triggerPoint,p=a&&h,u=!a&&!h;(p||u)&&(l.queueTrigger(r),t[l.group.id]=l.group)}}for(var c in t)t[c].flushTriggers();this.oldScroll={x:e.horizontal.newScroll,y:e.vertical.newScroll}},e.prototype.innerHeight=function(){return this.element==this.element.window?o.viewportHeight():this.adapter.innerHeight()},e.prototype.remove=function(t){delete this.waypoints[t.axis][t.key],this.checkEmpty()},e.prototype.innerWidth=function(){return this.element==this.element.window?o.viewportWidth():this.adapter.innerWidth()},e.prototype.destroy=function(){var t=[];for(var e in this.waypoints)for(var i in this.waypoints[e])t.push(this.waypoints[e][i]);for(var n=0,o=t.length;o>n;n++)t[n].destroy()},e.prototype.refresh=function(){var t,e=this.element==this.element.window,i=e?void 0:this.adapter.offset(),n={};this.handleScroll(),t={horizontal:{contextOffset:e?0:i.left,contextScroll:e?0:this.oldScroll.x,contextDimension:this.innerWidth(),oldScroll:this.oldScroll.x,forward:"right",backward:"left",offsetProp:"left"},vertical:{contextOffset:e?0:i.top,contextScroll:e?0:this.oldScroll.y,contextDimension:this.innerHeight(),oldScroll:this.oldScroll.y,forward:"down",backward:"up",offsetProp:"top"}};for(var r in t){var s=t[r];for(var l in this.waypoints[r]){var a,h,p,u,c,f=this.waypoints[r][l],d=f.options.offset,y=f.triggerPoint,g=0,w=null==y;f.element!==f.element.window&&(g=f.adapter.offset()[s.offsetProp]),"function"==typeof d?d=d.apply(f):"string"==typeof d&&(d=parseFloat(d),f.options.offset.indexOf("%")>-1&&(d=Math.ceil(s.contextDimension*d/100))),a=s.contextScroll-s.contextOffset,f.triggerPoint=g+a-d,h=y=s.oldScroll,u=h&&p,c=!h&&!p,!w&&u?(f.queueTrigger(s.backward),n[f.group.id]=f.group):!w&&c?(f.queueTrigger(s.forward),n[f.group.id]=f.group):w&&s.oldScroll>=f.triggerPoint&&(f.queueTrigger(s.forward),n[f.group.id]=f.group)}}return o.requestAnimationFrame(function(){for(var t in n)n[t].flushTriggers()}),this},e.findOrCreateByElement=function(t){return e.findByElement(t)||new e(t)},e.refreshAll=function(){for(var t in n)n[t].refresh()},e.findByElement=function(t){return n[t.waypointContextKey]},window.onload=function(){r&&r(),e.refreshAll()},o.requestAnimationFrame=function(e){var i=window.requestAnimationFrame||window.mozRequestAnimationFrame||window.webkitRequestAnimationFrame||t;i.call(window,e)},o.Context=e}(),function(){"use strict";function t(t,e){return t.triggerPoint-e.triggerPoint}function e(t,e){return e.triggerPoint-t.triggerPoint}function i(t){this.name=t.name,this.axis=t.axis,this.id=this.name+"-"+this.axis,this.waypoints=[],this.clearTriggerQueues(),n[this.axis][this.name]=this}var n={vertical:{},horizontal:{}},o=window.Waypoint;i.prototype.add=function(t){this.waypoints.push(t)},i.prototype.clearTriggerQueues=function(){this.triggerQueues={up:[],down:[],left:[],right:[]}},i.prototype.flushTriggers=function(){for(var i in this.triggerQueues){var n=this.triggerQueues[i],o="up"===i||"left"===i;n.sort(o?e:t);for(var r=0,s=n.length;s>r;r+=1){var l=n[r];(l.options.continuous||r===n.length-1)&&l.trigger([i])}}this.clearTriggerQueues()},i.prototype.next=function(e){this.waypoints.sort(t);var i=o.Adapter.inArray(e,this.waypoints),n=i===this.waypoints.length-1;return n?null:this.waypoints[i+1]},i.prototype.previous=function(e){this.waypoints.sort(t);var i=o.Adapter.inArray(e,this.waypoints);return i?this.waypoints[i-1]:null},i.prototype.queueTrigger=function(t,e){this.triggerQueues[e].push(t)},i.prototype.remove=function(t){var e=o.Adapter.inArray(t,this.waypoints);e>-1&&this.waypoints.splice(e,1)},i.prototype.first=function(){return this.waypoints[0]},i.prototype.last=function(){return this.waypoints[this.waypoints.length-1]},i.findOrCreate=function(t){return n[t.axis][t.name]||new i(t)},o.Group=i}(),function(){"use strict";function t(t){return t===t.window}function e(e){return t(e)?e:e.defaultView}function i(t){this.element=t,this.handlers={}}var n=window.Waypoint;i.prototype.innerHeight=function(){var e=t(this.element);return e?this.element.innerHeight:this.element.clientHeight},i.prototype.innerWidth=function(){var e=t(this.element);return e?this.element.innerWidth:this.element.clientWidth},i.prototype.off=function(t,e){function i(t,e,i){for(var n=0,o=e.length-1;o>n;n++){var r=e[n];i&&i!==r||t.removeEventListener(r)}}var n=t.split("."),o=n[0],r=n[1],s=this.element;if(r&&this.handlers[r]&&o)i(s,this.handlers[r][o],e),this.handlers[r][o]=[];else if(o)for(var l in this.handlers)i(s,this.handlers[l][o]||[],e),this.handlers[l][o]=[];else if(r&&this.handlers[r]){for(var a in this.handlers[r])i(s,this.handlers[r][a],e);this.handlers[r]={}}},i.prototype.offset=function(){if(!this.element.ownerDocument)return null;var t=this.element.ownerDocument.documentElement,i=e(this.element.ownerDocument),n={top:0,left:0};return this.element.getBoundingClientRect&&(n=this.element.getBoundingClientRect()),{top:n.top+i.pageYOffset-t.clientTop,left:n.left+i.pageXOffset-t.clientLeft}},i.prototype.on=function(t,e){var i=t.split("."),n=i[0],o=i[1]||"__default",r=this.handlers[o]=this.handlers[o]||{},s=r[n]=r[n]||[];s.push(e),this.element.addEventListener(n,e)},i.prototype.outerHeight=function(e){var i,n=this.innerHeight();return e&&!t(this.element)&&(i=window.getComputedStyle(this.element),n+=parseInt(i.marginTop,10),n+=parseInt(i.marginBottom,10)),n},i.prototype.outerWidth=function(e){var i,n=this.innerWidth();return e&&!t(this.element)&&(i=window.getComputedStyle(this.element),n+=parseInt(i.marginLeft,10),n+=parseInt(i.marginRight,10)),n},i.prototype.scrollLeft=function(){var t=e(this.element);return t?t.pageXOffset:this.element.scrollLeft},i.prototype.scrollTop=function(){var t=e(this.element);return t?t.pageYOffset:this.element.scrollTop},i.extend=function(){function t(t,e){if("object"==typeof t&&"object"==typeof e)for(var i in e)e.hasOwnProperty(i)&&(t[i]=e[i]);return t}for(var e=Array.prototype.slice.call(arguments),i=1,n=e.length;n>i;i++)t(e[0],e[i]);return e[0]},i.inArray=function(t,e,i){return null==e?-1:e.indexOf(t,i)},i.isEmptyObject=function(t){for(var e in t)return!1;return!0},n.adapters.push({name:"noframework",Adapter:i}),n.Adapter=i}(); \ No newline at end of file diff --git a/lib/shortcuts/infinite.js b/lib/shortcuts/infinite.js index 61f72cd8..eec5dacb 100644 --- a/lib/shortcuts/infinite.js +++ b/lib/shortcuts/infinite.js @@ -2,7 +2,7 @@ Waypoints Infinite Scroll Shortcut - 4.0.0 Copyright © 2011-2015 Caleb Troughton Licensed under the MIT license. -https://github.com/imakewebthings/waypoints/blog/master/licenses.txt +https://github.com/imakewebthings/waypoints/blob/master/licenses.txt */ (function() { 'use strict' diff --git a/lib/shortcuts/infinite.min.js b/lib/shortcuts/infinite.min.js index 50d1134d..8ecbc730 100644 --- a/lib/shortcuts/infinite.min.js +++ b/lib/shortcuts/infinite.min.js @@ -2,6 +2,6 @@ Waypoints Infinite Scroll Shortcut - 4.0.0 Copyright © 2011-2015 Caleb Troughton Licensed under the MIT license. -https://github.com/imakewebthings/waypoints/blog/master/licenses.txt +https://github.com/imakewebthings/waypoints/blob/master/licenses.txt */ !function(){"use strict";function t(n){this.options=i.extend({},t.defaults,n),this.container=this.options.element,"auto"!==this.options.container&&(this.container=this.options.container),this.$container=i(this.container),this.$more=i(this.options.more),this.$more.length&&(this.setupHandler(),this.waypoint=new o(this.options))}var i=window.jQuery,o=window.Waypoint;t.prototype.setupHandler=function(){this.options.handler=i.proxy(function(){this.options.onBeforePageLoad(),this.destroy(),this.$container.addClass(this.options.loadingClass),i.get(i(this.options.more).attr("href"),i.proxy(function(t){var n=i(i.parseHTML(t)),e=n.find(this.options.more),s=n.find(this.options.items);s.length||(s=n.filter(this.options.items)),this.$container.append(s),this.$container.removeClass(this.options.loadingClass),e.length||(e=n.filter(this.options.more)),e.length?(this.$more.replaceWith(e),this.$more=e,this.waypoint=new o(this.options)):this.$more.remove(),this.options.onAfterPageLoad(s)},this))},this)},t.prototype.destroy=function(){this.waypoint&&this.waypoint.destroy()},t.defaults={container:"auto",items:".infinite-item",more:".infinite-more-link",offset:"bottom-in-view",loadingClass:"infinite-loading",onBeforePageLoad:i.noop,onAfterPageLoad:i.noop},o.Infinite=t}(); \ No newline at end of file diff --git a/lib/shortcuts/inview.js b/lib/shortcuts/inview.js index 20aa59b8..acec502a 100644 --- a/lib/shortcuts/inview.js +++ b/lib/shortcuts/inview.js @@ -2,7 +2,7 @@ Waypoints Inview Shortcut - 4.0.0 Copyright © 2011-2015 Caleb Troughton Licensed under the MIT license. -https://github.com/imakewebthings/waypoints/blog/master/licenses.txt +https://github.com/imakewebthings/waypoints/blob/master/licenses.txt */ (function() { 'use strict' diff --git a/lib/shortcuts/inview.min.js b/lib/shortcuts/inview.min.js index 5a07530b..6375bafe 100644 --- a/lib/shortcuts/inview.min.js +++ b/lib/shortcuts/inview.min.js @@ -2,6 +2,6 @@ Waypoints Inview Shortcut - 4.0.0 Copyright © 2011-2015 Caleb Troughton Licensed under the MIT license. -https://github.com/imakewebthings/waypoints/blog/master/licenses.txt +https://github.com/imakewebthings/waypoints/blob/master/licenses.txt */ !function(){"use strict";function t(){}function e(t){this.options=i.Adapter.extend({},e.defaults,t),this.axis=this.options.horizontal?"horizontal":"vertical",this.waypoints=[],this.element=this.options.element,this.createWaypoints()}var i=window.Waypoint;e.prototype.createWaypoints=function(){for(var t={vertical:[{down:"enter",up:"exited",offset:"100%"},{down:"entered",up:"exit",offset:"bottom-in-view"},{down:"exit",up:"entered",offset:0},{down:"exited",up:"enter",offset:function(){return-this.adapter.outerHeight()}}],horizontal:[{right:"enter",left:"exited",offset:"100%"},{right:"entered",left:"exit",offset:"right-in-view"},{right:"exit",left:"entered",offset:0},{right:"exited",left:"enter",offset:function(){return-this.adapter.outerWidth()}}]},e=0,i=t[this.axis].length;i>e;e++){var n=t[this.axis][e];this.createWaypoint(n)}},e.prototype.createWaypoint=function(t){var e=this;this.waypoints.push(new i({context:this.options.context,element:this.options.element,enabled:this.options.enabled,handler:function(t){return function(i){e.options[t[i]].call(e,i)}}(t),offset:t.offset,horizontal:this.options.horizontal}))},e.prototype.destroy=function(){for(var t=0,e=this.waypoints.length;e>t;t++)this.waypoints[t].destroy();this.waypoints=[]},e.prototype.disable=function(){for(var t=0,e=this.waypoints.length;e>t;t++)this.waypoints[t].disable()},e.prototype.enable=function(){for(var t=0,e=this.waypoints.length;e>t;t++)this.waypoints[t].enable()},e.defaults={context:window,enabled:!0,enter:t,entered:t,exit:t,exited:t},i.Inview=e}(); \ No newline at end of file diff --git a/lib/shortcuts/sticky.js b/lib/shortcuts/sticky.js index 4e07cb7e..b609b84a 100644 --- a/lib/shortcuts/sticky.js +++ b/lib/shortcuts/sticky.js @@ -2,7 +2,7 @@ Waypoints Sticky Element Shortcut - 4.0.0 Copyright © 2011-2015 Caleb Troughton Licensed under the MIT license. -https://github.com/imakewebthings/waypoints/blog/master/licenses.txt +https://github.com/imakewebthings/waypoints/blob/master/licenses.txt */ (function() { 'use strict' diff --git a/lib/shortcuts/sticky.min.js b/lib/shortcuts/sticky.min.js index fd8dcc13..e2ea0603 100644 --- a/lib/shortcuts/sticky.min.js +++ b/lib/shortcuts/sticky.min.js @@ -2,6 +2,6 @@ Waypoints Sticky Element Shortcut - 4.0.0 Copyright © 2011-2015 Caleb Troughton Licensed under the MIT license. -https://github.com/imakewebthings/waypoints/blog/master/licenses.txt +https://github.com/imakewebthings/waypoints/blob/master/licenses.txt */ !function(){"use strict";function t(s){this.options=e.extend({},i.defaults,t.defaults,s),this.element=this.options.element,this.$element=e(this.element),this.createWrapper(),this.createWaypoint()}var e=window.jQuery,i=window.Waypoint;t.prototype.createWaypoint=function(){var t=this.options.handler;this.waypoint=new i(e.extend({},this.options,{element:this.wrapper,handler:e.proxy(function(e){var i=this.options.direction.indexOf(e)>-1,s=i?this.$element.outerHeight(!0):"";this.$wrapper.height(s),this.$element.toggleClass(this.options.stuckClass,i),t&&t.call(this,e)},this)}))},t.prototype.createWrapper=function(){this.options.wrapper&&this.$element.wrap(this.options.wrapper),this.$wrapper=this.$element.parent(),this.wrapper=this.$wrapper[0]},t.prototype.destroy=function(){this.$element.parent()[0]===this.wrapper&&(this.waypoint.destroy(),this.$element.removeClass(this.options.stuckClass),this.options.wrapper&&this.$element.unwrap())},t.defaults={wrapper:'
',stuckClass:"stuck",direction:"down right"},i.Sticky=t}(); \ No newline at end of file diff --git a/lib/waypoints.debug.js b/lib/waypoints.debug.js index f60a9592..49601e38 100644 --- a/lib/waypoints.debug.js +++ b/lib/waypoints.debug.js @@ -2,7 +2,7 @@ Waypoints Debug - 4.0.0 Copyright © 2011-2015 Caleb Troughton Licensed under the MIT license. -https://github.com/imakewebthings/waypoints/blog/master/licenses.txt +https://github.com/imakewebthings/waypoints/blob/master/licenses.txt */ (function() { 'use strict' diff --git a/lib/zepto.waypoints.js b/lib/zepto.waypoints.js index 0409af6d..70f49701 100644 --- a/lib/zepto.waypoints.js +++ b/lib/zepto.waypoints.js @@ -2,7 +2,7 @@ Waypoints - 4.0.0 Copyright © 2011-2015 Caleb Troughton Licensed under the MIT license. -https://github.com/imakewebthings/waypoints/blog/master/licenses.txt +https://github.com/imakewebthings/waypoints/blob/master/licenses.txt */ (function() { 'use strict' diff --git a/lib/zepto.waypoints.min.js b/lib/zepto.waypoints.min.js index 7062bc97..88d579d6 100644 --- a/lib/zepto.waypoints.min.js +++ b/lib/zepto.waypoints.min.js @@ -2,6 +2,6 @@ Waypoints - 4.0.0 Copyright © 2011-2015 Caleb Troughton Licensed under the MIT license. -https://github.com/imakewebthings/waypoints/blog/master/licenses.txt +https://github.com/imakewebthings/waypoints/blob/master/licenses.txt */ !function(){"use strict";function t(o){if(!o)throw new Error("No options passed to Waypoint constructor");if(!o.element)throw new Error("No element option passed to Waypoint constructor");if(!o.handler)throw new Error("No handler option passed to Waypoint constructor");this.key="waypoint-"+e,this.options=t.Adapter.extend({},t.defaults,o),this.element=this.options.element,this.adapter=new t.Adapter(this.element),this.callback=o.handler,this.axis=this.options.horizontal?"horizontal":"vertical",this.enabled=this.options.enabled,this.triggerPoint=null,this.group=t.Group.findOrCreate({name:this.options.group,axis:this.axis}),this.context=t.Context.findOrCreateByElement(this.options.context),t.offsetAliases[this.options.offset]&&(this.options.offset=t.offsetAliases[this.options.offset]),this.group.add(this),this.context.add(this),i[this.key]=this,e+=1}var e=0,i={};t.prototype.queueTrigger=function(t){this.group.queueTrigger(this,t)},t.prototype.trigger=function(t){this.enabled&&this.callback&&this.callback.apply(this,t)},t.prototype.destroy=function(){this.context.remove(this),this.group.remove(this),delete i[this.key]},t.prototype.disable=function(){return this.enabled=!1,this},t.prototype.enable=function(){return this.context.refresh(),this.enabled=!0,this},t.prototype.next=function(){return this.group.next(this)},t.prototype.previous=function(){return this.group.previous(this)},t.invokeAll=function(t){var e=[];for(var o in i)e.push(i[o]);for(var n=0,r=e.length;r>n;n++)e[n][t]()},t.destroyAll=function(){t.invokeAll("destroy")},t.disableAll=function(){t.invokeAll("disable")},t.enableAll=function(){t.invokeAll("enable")},t.refreshAll=function(){t.Context.refreshAll()},t.viewportHeight=function(){return window.innerHeight||document.documentElement.clientHeight},t.viewportWidth=function(){return document.documentElement.clientWidth},t.adapters=[],t.defaults={context:window,continuous:!0,enabled:!0,group:"default",horizontal:!1,offset:0},t.offsetAliases={"bottom-in-view":function(){return this.context.innerHeight()-this.adapter.outerHeight()},"right-in-view":function(){return this.context.innerWidth()-this.adapter.outerWidth()}},window.Waypoint=t}(),function(){"use strict";function t(t){window.setTimeout(t,1e3/60)}function e(t){this.element=t,this.Adapter=n.Adapter,this.adapter=new this.Adapter(t),this.key="waypoint-context-"+i,this.didScroll=!1,this.didResize=!1,this.oldScroll={x:this.adapter.scrollLeft(),y:this.adapter.scrollTop()},this.waypoints={vertical:{},horizontal:{}},t.waypointContextKey=this.key,o[t.waypointContextKey]=this,i+=1,this.createThrottledScrollHandler(),this.createThrottledResizeHandler()}var i=0,o={},n=window.Waypoint,r=window.onload;e.prototype.add=function(t){var e=t.options.horizontal?"horizontal":"vertical";this.waypoints[e][t.key]=t,this.refresh()},e.prototype.checkEmpty=function(){var t=this.Adapter.isEmptyObject(this.waypoints.horizontal),e=this.Adapter.isEmptyObject(this.waypoints.vertical);t&&e&&(this.adapter.off(".waypoints"),delete o[this.key])},e.prototype.createThrottledResizeHandler=function(){function t(){e.handleResize(),e.didResize=!1}var e=this;this.adapter.on("resize.waypoints",function(){e.didResize||(e.didResize=!0,n.requestAnimationFrame(t))})},e.prototype.createThrottledScrollHandler=function(){function t(){e.handleScroll(),e.didScroll=!1}var e=this;this.adapter.on("scroll.waypoints",function(){(!e.didScroll||n.isTouch)&&(e.didScroll=!0,n.requestAnimationFrame(t))})},e.prototype.handleResize=function(){n.Context.refreshAll()},e.prototype.handleScroll=function(){var t={},e={horizontal:{newScroll:this.adapter.scrollLeft(),oldScroll:this.oldScroll.x,forward:"right",backward:"left"},vertical:{newScroll:this.adapter.scrollTop(),oldScroll:this.oldScroll.y,forward:"down",backward:"up"}};for(var i in e){var o=e[i],n=o.newScroll>o.oldScroll,r=n?o.forward:o.backward;for(var s in this.waypoints[i]){var a=this.waypoints[i][s],l=o.oldScroll=a.triggerPoint,p=l&&h,c=!l&&!h;(p||c)&&(a.queueTrigger(r),t[a.group.id]=a.group)}}for(var u in t)t[u].flushTriggers();this.oldScroll={x:e.horizontal.newScroll,y:e.vertical.newScroll}},e.prototype.innerHeight=function(){return this.element==this.element.window?n.viewportHeight():this.adapter.innerHeight()},e.prototype.remove=function(t){delete this.waypoints[t.axis][t.key],this.checkEmpty()},e.prototype.innerWidth=function(){return this.element==this.element.window?n.viewportWidth():this.adapter.innerWidth()},e.prototype.destroy=function(){var t=[];for(var e in this.waypoints)for(var i in this.waypoints[e])t.push(this.waypoints[e][i]);for(var o=0,n=t.length;n>o;o++)t[o].destroy()},e.prototype.refresh=function(){var t,e=this.element==this.element.window,i=e?void 0:this.adapter.offset(),o={};this.handleScroll(),t={horizontal:{contextOffset:e?0:i.left,contextScroll:e?0:this.oldScroll.x,contextDimension:this.innerWidth(),oldScroll:this.oldScroll.x,forward:"right",backward:"left",offsetProp:"left"},vertical:{contextOffset:e?0:i.top,contextScroll:e?0:this.oldScroll.y,contextDimension:this.innerHeight(),oldScroll:this.oldScroll.y,forward:"down",backward:"up",offsetProp:"top"}};for(var r in t){var s=t[r];for(var a in this.waypoints[r]){var l,h,p,c,u,d=this.waypoints[r][a],f=d.options.offset,w=d.triggerPoint,y=0,g=null==w;d.element!==d.element.window&&(y=d.adapter.offset()[s.offsetProp]),"function"==typeof f?f=f.apply(d):"string"==typeof f&&(f=parseFloat(f),d.options.offset.indexOf("%")>-1&&(f=Math.ceil(s.contextDimension*f/100))),l=s.contextScroll-s.contextOffset,d.triggerPoint=y+l-f,h=w=s.oldScroll,c=h&&p,u=!h&&!p,!g&&c?(d.queueTrigger(s.backward),o[d.group.id]=d.group):!g&&u?(d.queueTrigger(s.forward),o[d.group.id]=d.group):g&&s.oldScroll>=d.triggerPoint&&(d.queueTrigger(s.forward),o[d.group.id]=d.group)}}return n.requestAnimationFrame(function(){for(var t in o)o[t].flushTriggers()}),this},e.findOrCreateByElement=function(t){return e.findByElement(t)||new e(t)},e.refreshAll=function(){for(var t in o)o[t].refresh()},e.findByElement=function(t){return o[t.waypointContextKey]},window.onload=function(){r&&r(),e.refreshAll()},n.requestAnimationFrame=function(e){var i=window.requestAnimationFrame||window.mozRequestAnimationFrame||window.webkitRequestAnimationFrame||t;i.call(window,e)},n.Context=e}(),function(){"use strict";function t(t,e){return t.triggerPoint-e.triggerPoint}function e(t,e){return e.triggerPoint-t.triggerPoint}function i(t){this.name=t.name,this.axis=t.axis,this.id=this.name+"-"+this.axis,this.waypoints=[],this.clearTriggerQueues(),o[this.axis][this.name]=this}var o={vertical:{},horizontal:{}},n=window.Waypoint;i.prototype.add=function(t){this.waypoints.push(t)},i.prototype.clearTriggerQueues=function(){this.triggerQueues={up:[],down:[],left:[],right:[]}},i.prototype.flushTriggers=function(){for(var i in this.triggerQueues){var o=this.triggerQueues[i],n="up"===i||"left"===i;o.sort(n?e:t);for(var r=0,s=o.length;s>r;r+=1){var a=o[r];(a.options.continuous||r===o.length-1)&&a.trigger([i])}}this.clearTriggerQueues()},i.prototype.next=function(e){this.waypoints.sort(t);var i=n.Adapter.inArray(e,this.waypoints),o=i===this.waypoints.length-1;return o?null:this.waypoints[i+1]},i.prototype.previous=function(e){this.waypoints.sort(t);var i=n.Adapter.inArray(e,this.waypoints);return i?this.waypoints[i-1]:null},i.prototype.queueTrigger=function(t,e){this.triggerQueues[e].push(t)},i.prototype.remove=function(t){var e=n.Adapter.inArray(t,this.waypoints);e>-1&&this.waypoints.splice(e,1)},i.prototype.first=function(){return this.waypoints[0]},i.prototype.last=function(){return this.waypoints[this.waypoints.length-1]},i.findOrCreate=function(t){return o[t.axis][t.name]||new i(t)},n.Group=i}(),function(){"use strict";function t(t){this.element=t,this.$element=e(t)}var e=window.Zepto,i=window.Waypoint;e.each(["off","on","scrollLeft","scrollTop"],function(e,i){t.prototype[i]=function(){var t=Array.prototype.slice.call(arguments);return this.$element[i].apply(this.$element,t)}}),t.prototype.offset=function(){return this.element!==this.element.window?this.$element.offset():void 0},e.each(["width","height"],function(i,o){function n(t,i){return function(t){var n=this.$element,r=n[o](),s={width:["left","right"],height:["top","bottom"]};return e.each(s[o],function(e,o){r+=parseInt(n.css("padding-"+o),10),i&&(r+=parseInt(n.css("border-"+o+"-width"),10)),t&&(r+=parseInt(n.css("margin-"+o),10))}),r}}var r=e.camelCase("inner-"+o),s=e.camelCase("outer-"+o);t.prototype[r]=n(!1),t.prototype[s]=n(!0)}),e.each(["extend","inArray"],function(i,o){t[o]=e[o]}),t.isEmptyObject=function(t){for(var e in t)return!1;return!0},i.adapters.push({name:"zepto",Adapter:t}),i.Adapter=t}(),function(){"use strict";function t(t){return function(){var i=[],o=arguments[0];return t.isFunction(arguments[0])&&(o=t.extend({},arguments[1]),o.handler=arguments[0]),this.each(function(){var n=t.extend({},o,{element:this});"string"==typeof n.context&&(n.context=t(this).closest(n.context)[0]),i.push(new e(n))}),i}}var e=window.Waypoint;window.jQuery&&(window.jQuery.fn.waypoint=t(window.jQuery)),window.Zepto&&(window.Zepto.fn.waypoint=t(window.Zepto))}(); \ No newline at end of file From b6c2046ecf1ffb8a2ca8defb55042724daf253cc Mon Sep 17 00:00:00 2001 From: "Yinxi.Zheng" Date: Mon, 14 Dec 2015 18:52:12 +0800 Subject: [PATCH 94/98] may fix https://github.com/imakewebthings/waypoints/issues/438 --- src/context.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/context.js b/src/context.js index 5e3551bc..b3041a2f 100644 --- a/src/context.js +++ b/src/context.js @@ -234,7 +234,7 @@ } contextModifier = axis.contextScroll - axis.contextOffset - waypoint.triggerPoint = elementOffset + contextModifier - adjustment + waypoint.triggerPoint = Math.floor(elementOffset + contextModifier - adjustment) wasBeforeScroll = oldTriggerPoint < axis.oldScroll nowAfterScroll = waypoint.triggerPoint >= axis.oldScroll triggeredBackward = wasBeforeScroll && nowAfterScroll From 1d90d5bdeeee614161b94ab9f54880f027d52b73 Mon Sep 17 00:00:00 2001 From: imakewebthings Date: Wed, 22 Jun 2016 16:55:18 -0700 Subject: [PATCH 95/98] Only refresh once during an enableAll call, #454 Previously, enableAll would invoke enable on each Waypoint, but enable calls refresh on the context. This meant n-refreshes where n is the number of active Waypoints. --- package.json | 2 +- src/waypoint.js | 6 +++++- test/waypoint-spec.js | 21 +++++++++++++++------ 3 files changed, 21 insertions(+), 8 deletions(-) diff --git a/package.json b/package.json index 22a85166..ab958cce 100644 --- a/package.json +++ b/package.json @@ -28,7 +28,7 @@ "gulp-tap": "^0.1.1", "gulp-uglify": "^0.3.1", "merge-stream": "^0.1.1", - "testem": "^0.6.24" + "testem": "0.6.24" }, "license": "MIT" } diff --git a/src/waypoint.js b/src/waypoint.js index 7f76f1d8..ac210c7e 100644 --- a/src/waypoint.js +++ b/src/waypoint.js @@ -115,7 +115,11 @@ /* Public */ /* http://imakewebthings.com/waypoints/api/enable-all */ Waypoint.enableAll = function() { - Waypoint.invokeAll('enable') + Waypoint.Context.refreshAll() + for (var waypointKey in allWaypoints) { + allWaypoints[waypointKey].enabled = true + } + return this } /* Public */ diff --git a/test/waypoint-spec.js b/test/waypoint-spec.js index 53670b5a..8ffa6580 100644 --- a/test/waypoint-spec.js +++ b/test/waypoint-spec.js @@ -527,8 +527,10 @@ window.jQuery.each(Waypoint.adapters, function(i, adapter) { }) describe('Waypoint.enableAll()', function() { - it('calls enable on all waypoints', function() { - var secondWaypoint = new Waypoint({ + var secondWaypoint + + beforeEach(function() { + secondWaypoint = new Waypoint({ element: $('#same1')[0], handler: function() {} }) @@ -536,11 +538,18 @@ window.jQuery.each(Waypoint.adapters, function(i, adapter) { element: $('#same1')[0], handler: function() {} }) - spyOn(secondWaypoint, 'enable').andCallThrough() - spyOn(waypoint, 'enable').andCallThrough() + Waypoint.disableAll() + spyOn(Waypoint.Context, 'refreshAll').andCallThrough() Waypoint.enableAll() - expect(secondWaypoint.enable).toHaveBeenCalled() - expect(waypoint.enable).toHaveBeenCalled() + }) + + it('sets enabled on all waypoints', function() { + expect(secondWaypoint.enabled).toBeTruthy() + expect(waypoint.enabled).toBeTruthy() + }) + + it('refreshes all contexts', function() { + expect(Waypoint.Context.refreshAll).toHaveBeenCalled() }) }) }) From 28c21674deb10b7aafcd03bc8f90f3b0dd81b978 Mon Sep 17 00:00:00 2001 From: imakewebthings Date: Wed, 22 Jun 2016 17:03:25 -0700 Subject: [PATCH 96/98] Ignore fresh waypoints in handleScroll In the rare event that a Waypoint was created in the instance where a scroll value went from negative to 0, that Waypoint would be triggered because of its null triggerPoint + the combination of checks that occured during the scroll handler. This change explicitly ignores waypoints with null trigger points during scroll checks. Fresh waypoints will be checked anyway during the refresh that occurs as part of Waypoint instantiation. --- src/context.js | 3 +++ 1 file changed, 3 insertions(+) diff --git a/src/context.js b/src/context.js index b3041a2f..7e357249 100644 --- a/src/context.js +++ b/src/context.js @@ -115,6 +115,9 @@ for (var waypointKey in this.waypoints[axisKey]) { var waypoint = this.waypoints[axisKey][waypointKey] + if (waypoint.triggerPoint === null) { + continue + } var wasBeforeTriggerPoint = axis.oldScroll < waypoint.triggerPoint var nowAfterTriggerPoint = axis.newScroll >= waypoint.triggerPoint var crossedForward = wasBeforeTriggerPoint && nowAfterTriggerPoint From 9122b72c0435f926675c817d43850f1711baeaf8 Mon Sep 17 00:00:00 2001 From: imakewebthings Date: Sat, 9 Jul 2016 22:23:11 -0700 Subject: [PATCH 97/98] Ensure a window context always exists We always care about window resizes to refresh trigger points, but previously if a developer only had non-window-context waypoints the window resize handler would never exist and no auto resize refreshes would happen. This commit ensures there is always a window context so there is always a window resize handler. --- src/context.js | 8 +++++++- test/context-spec.js | 6 ------ 2 files changed, 7 insertions(+), 7 deletions(-) diff --git a/src/context.js b/src/context.js index 7e357249..d6c52f70 100644 --- a/src/context.js +++ b/src/context.js @@ -30,6 +30,10 @@ element.waypointContextKey = this.key contexts[element.waypointContextKey] = this keyCounter += 1 + if (!Waypoint.windowContext) { + Waypoint.windowContext = true + Waypoint.windowContext = new Context(window) + } this.createThrottledScrollHandler() this.createThrottledResizeHandler() @@ -46,7 +50,8 @@ Context.prototype.checkEmpty = function() { var horizontalEmpty = this.Adapter.isEmptyObject(this.waypoints.horizontal) var verticalEmpty = this.Adapter.isEmptyObject(this.waypoints.vertical) - if (horizontalEmpty && verticalEmpty) { + var isWindow = this.element == this.element.window + if (horizontalEmpty && verticalEmpty && !isWindow) { this.adapter.off('.waypoints') delete contexts[this.key] } @@ -292,6 +297,7 @@ Context.refreshAll() } + Waypoint.requestAnimationFrame = function(callback) { var requestFn = window.requestAnimationFrame || window.mozRequestAnimationFrame || diff --git a/test/context-spec.js b/test/context-spec.js index c4c904d4..d70179f7 100644 --- a/test/context-spec.js +++ b/test/context-spec.js @@ -71,12 +71,6 @@ window.jQuery.each(Waypoint.adapters, function(i, adapter) { $scroller.scrollTop($target.offset().top) expect(currentDirection).toBeNull() }) - - it('removes context from global lookup', function() { - skipDestroy = true - context.destroy() - expect(Waypoint.Context.findByElement(window)).toBeFalsy() - }) }) describe('Waypoint.Context.refreshAll()', function() { From 34d9f6d77016cb9ed7884963c522e140fb8f8dc3 Mon Sep 17 00:00:00 2001 From: imakewebthings Date: Sat, 3 Sep 2016 07:22:49 -0700 Subject: [PATCH 98/98] 4.0.1 --- CHANGELOG.md | 6 ++++++ lib/jquery.waypoints.js | 23 ++++++++++++++++++----- lib/jquery.waypoints.min.js | 6 +++--- lib/noframework.waypoints.js | 23 ++++++++++++++++++----- lib/noframework.waypoints.min.js | 6 +++--- lib/shortcuts/infinite.js | 4 ++-- lib/shortcuts/infinite.min.js | 4 ++-- lib/shortcuts/inview.js | 4 ++-- lib/shortcuts/inview.min.js | 4 ++-- lib/shortcuts/sticky.js | 4 ++-- lib/shortcuts/sticky.min.js | 4 ++-- lib/waypoints.debug.js | 4 ++-- lib/zepto.waypoints.js | 23 ++++++++++++++++++----- lib/zepto.waypoints.min.js | 6 +++--- package.json | 2 +- 15 files changed, 84 insertions(+), 39 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index f35c9789..bf0e6acb 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,11 @@ # Changelog +## v4.0.1 + +- Improve performance of `enableAll`. (Issue #454) +- Handle edge case bug where Waypoint initialization during a specific part of iOS scroll bounce would cause an immediate trigger of it. (Issue #499) +- Maintain `window` Context/resize-handler even when there are only non-window-context waypoints. (Issue #442) + ## v4.0.0 - Allow Sticky option `wrapper` to accept false, which will not create a wrapper and instead use the preexisting parent element. (Pull #416) diff --git a/lib/jquery.waypoints.js b/lib/jquery.waypoints.js index 90372dd8..d70b2459 100644 --- a/lib/jquery.waypoints.js +++ b/lib/jquery.waypoints.js @@ -1,6 +1,6 @@ /*! -Waypoints - 4.0.0 -Copyright © 2011-2015 Caleb Troughton +Waypoints - 4.0.1 +Copyright © 2011-2016 Caleb Troughton Licensed under the MIT license. https://github.com/imakewebthings/waypoints/blob/master/licenses.txt */ @@ -121,7 +121,11 @@ https://github.com/imakewebthings/waypoints/blob/master/licenses.txt /* Public */ /* http://imakewebthings.com/waypoints/api/enable-all */ Waypoint.enableAll = function() { - Waypoint.invokeAll('enable') + Waypoint.Context.refreshAll() + for (var waypointKey in allWaypoints) { + allWaypoints[waypointKey].enabled = true + } + return this } /* Public */ @@ -196,6 +200,10 @@ https://github.com/imakewebthings/waypoints/blob/master/licenses.txt element.waypointContextKey = this.key contexts[element.waypointContextKey] = this keyCounter += 1 + if (!Waypoint.windowContext) { + Waypoint.windowContext = true + Waypoint.windowContext = new Context(window) + } this.createThrottledScrollHandler() this.createThrottledResizeHandler() @@ -212,7 +220,8 @@ https://github.com/imakewebthings/waypoints/blob/master/licenses.txt Context.prototype.checkEmpty = function() { var horizontalEmpty = this.Adapter.isEmptyObject(this.waypoints.horizontal) var verticalEmpty = this.Adapter.isEmptyObject(this.waypoints.vertical) - if (horizontalEmpty && verticalEmpty) { + var isWindow = this.element == this.element.window + if (horizontalEmpty && verticalEmpty && !isWindow) { this.adapter.off('.waypoints') delete contexts[this.key] } @@ -281,6 +290,9 @@ https://github.com/imakewebthings/waypoints/blob/master/licenses.txt for (var waypointKey in this.waypoints[axisKey]) { var waypoint = this.waypoints[axisKey][waypointKey] + if (waypoint.triggerPoint === null) { + continue + } var wasBeforeTriggerPoint = axis.oldScroll < waypoint.triggerPoint var nowAfterTriggerPoint = axis.newScroll >= waypoint.triggerPoint var crossedForward = wasBeforeTriggerPoint && nowAfterTriggerPoint @@ -400,7 +412,7 @@ https://github.com/imakewebthings/waypoints/blob/master/licenses.txt } contextModifier = axis.contextScroll - axis.contextOffset - waypoint.triggerPoint = elementOffset + contextModifier - adjustment + waypoint.triggerPoint = Math.floor(elementOffset + contextModifier - adjustment) wasBeforeScroll = oldTriggerPoint < axis.oldScroll nowAfterScroll = waypoint.triggerPoint >= axis.oldScroll triggeredBackward = wasBeforeScroll && nowAfterScroll @@ -455,6 +467,7 @@ https://github.com/imakewebthings/waypoints/blob/master/licenses.txt Context.refreshAll() } + Waypoint.requestAnimationFrame = function(callback) { var requestFn = window.requestAnimationFrame || window.mozRequestAnimationFrame || diff --git a/lib/jquery.waypoints.min.js b/lib/jquery.waypoints.min.js index 20e6f625..609ece0a 100644 --- a/lib/jquery.waypoints.min.js +++ b/lib/jquery.waypoints.min.js @@ -1,7 +1,7 @@ /*! -Waypoints - 4.0.0 -Copyright © 2011-2015 Caleb Troughton +Waypoints - 4.0.1 +Copyright © 2011-2016 Caleb Troughton Licensed under the MIT license. https://github.com/imakewebthings/waypoints/blob/master/licenses.txt */ -!function(){"use strict";function t(o){if(!o)throw new Error("No options passed to Waypoint constructor");if(!o.element)throw new Error("No element option passed to Waypoint constructor");if(!o.handler)throw new Error("No handler option passed to Waypoint constructor");this.key="waypoint-"+e,this.options=t.Adapter.extend({},t.defaults,o),this.element=this.options.element,this.adapter=new t.Adapter(this.element),this.callback=o.handler,this.axis=this.options.horizontal?"horizontal":"vertical",this.enabled=this.options.enabled,this.triggerPoint=null,this.group=t.Group.findOrCreate({name:this.options.group,axis:this.axis}),this.context=t.Context.findOrCreateByElement(this.options.context),t.offsetAliases[this.options.offset]&&(this.options.offset=t.offsetAliases[this.options.offset]),this.group.add(this),this.context.add(this),i[this.key]=this,e+=1}var e=0,i={};t.prototype.queueTrigger=function(t){this.group.queueTrigger(this,t)},t.prototype.trigger=function(t){this.enabled&&this.callback&&this.callback.apply(this,t)},t.prototype.destroy=function(){this.context.remove(this),this.group.remove(this),delete i[this.key]},t.prototype.disable=function(){return this.enabled=!1,this},t.prototype.enable=function(){return this.context.refresh(),this.enabled=!0,this},t.prototype.next=function(){return this.group.next(this)},t.prototype.previous=function(){return this.group.previous(this)},t.invokeAll=function(t){var e=[];for(var o in i)e.push(i[o]);for(var n=0,r=e.length;r>n;n++)e[n][t]()},t.destroyAll=function(){t.invokeAll("destroy")},t.disableAll=function(){t.invokeAll("disable")},t.enableAll=function(){t.invokeAll("enable")},t.refreshAll=function(){t.Context.refreshAll()},t.viewportHeight=function(){return window.innerHeight||document.documentElement.clientHeight},t.viewportWidth=function(){return document.documentElement.clientWidth},t.adapters=[],t.defaults={context:window,continuous:!0,enabled:!0,group:"default",horizontal:!1,offset:0},t.offsetAliases={"bottom-in-view":function(){return this.context.innerHeight()-this.adapter.outerHeight()},"right-in-view":function(){return this.context.innerWidth()-this.adapter.outerWidth()}},window.Waypoint=t}(),function(){"use strict";function t(t){window.setTimeout(t,1e3/60)}function e(t){this.element=t,this.Adapter=n.Adapter,this.adapter=new this.Adapter(t),this.key="waypoint-context-"+i,this.didScroll=!1,this.didResize=!1,this.oldScroll={x:this.adapter.scrollLeft(),y:this.adapter.scrollTop()},this.waypoints={vertical:{},horizontal:{}},t.waypointContextKey=this.key,o[t.waypointContextKey]=this,i+=1,this.createThrottledScrollHandler(),this.createThrottledResizeHandler()}var i=0,o={},n=window.Waypoint,r=window.onload;e.prototype.add=function(t){var e=t.options.horizontal?"horizontal":"vertical";this.waypoints[e][t.key]=t,this.refresh()},e.prototype.checkEmpty=function(){var t=this.Adapter.isEmptyObject(this.waypoints.horizontal),e=this.Adapter.isEmptyObject(this.waypoints.vertical);t&&e&&(this.adapter.off(".waypoints"),delete o[this.key])},e.prototype.createThrottledResizeHandler=function(){function t(){e.handleResize(),e.didResize=!1}var e=this;this.adapter.on("resize.waypoints",function(){e.didResize||(e.didResize=!0,n.requestAnimationFrame(t))})},e.prototype.createThrottledScrollHandler=function(){function t(){e.handleScroll(),e.didScroll=!1}var e=this;this.adapter.on("scroll.waypoints",function(){(!e.didScroll||n.isTouch)&&(e.didScroll=!0,n.requestAnimationFrame(t))})},e.prototype.handleResize=function(){n.Context.refreshAll()},e.prototype.handleScroll=function(){var t={},e={horizontal:{newScroll:this.adapter.scrollLeft(),oldScroll:this.oldScroll.x,forward:"right",backward:"left"},vertical:{newScroll:this.adapter.scrollTop(),oldScroll:this.oldScroll.y,forward:"down",backward:"up"}};for(var i in e){var o=e[i],n=o.newScroll>o.oldScroll,r=n?o.forward:o.backward;for(var s in this.waypoints[i]){var a=this.waypoints[i][s],l=o.oldScroll=a.triggerPoint,p=l&&h,u=!l&&!h;(p||u)&&(a.queueTrigger(r),t[a.group.id]=a.group)}}for(var c in t)t[c].flushTriggers();this.oldScroll={x:e.horizontal.newScroll,y:e.vertical.newScroll}},e.prototype.innerHeight=function(){return this.element==this.element.window?n.viewportHeight():this.adapter.innerHeight()},e.prototype.remove=function(t){delete this.waypoints[t.axis][t.key],this.checkEmpty()},e.prototype.innerWidth=function(){return this.element==this.element.window?n.viewportWidth():this.adapter.innerWidth()},e.prototype.destroy=function(){var t=[];for(var e in this.waypoints)for(var i in this.waypoints[e])t.push(this.waypoints[e][i]);for(var o=0,n=t.length;n>o;o++)t[o].destroy()},e.prototype.refresh=function(){var t,e=this.element==this.element.window,i=e?void 0:this.adapter.offset(),o={};this.handleScroll(),t={horizontal:{contextOffset:e?0:i.left,contextScroll:e?0:this.oldScroll.x,contextDimension:this.innerWidth(),oldScroll:this.oldScroll.x,forward:"right",backward:"left",offsetProp:"left"},vertical:{contextOffset:e?0:i.top,contextScroll:e?0:this.oldScroll.y,contextDimension:this.innerHeight(),oldScroll:this.oldScroll.y,forward:"down",backward:"up",offsetProp:"top"}};for(var r in t){var s=t[r];for(var a in this.waypoints[r]){var l,h,p,u,c,d=this.waypoints[r][a],f=d.options.offset,w=d.triggerPoint,y=0,g=null==w;d.element!==d.element.window&&(y=d.adapter.offset()[s.offsetProp]),"function"==typeof f?f=f.apply(d):"string"==typeof f&&(f=parseFloat(f),d.options.offset.indexOf("%")>-1&&(f=Math.ceil(s.contextDimension*f/100))),l=s.contextScroll-s.contextOffset,d.triggerPoint=y+l-f,h=w=s.oldScroll,u=h&&p,c=!h&&!p,!g&&u?(d.queueTrigger(s.backward),o[d.group.id]=d.group):!g&&c?(d.queueTrigger(s.forward),o[d.group.id]=d.group):g&&s.oldScroll>=d.triggerPoint&&(d.queueTrigger(s.forward),o[d.group.id]=d.group)}}return n.requestAnimationFrame(function(){for(var t in o)o[t].flushTriggers()}),this},e.findOrCreateByElement=function(t){return e.findByElement(t)||new e(t)},e.refreshAll=function(){for(var t in o)o[t].refresh()},e.findByElement=function(t){return o[t.waypointContextKey]},window.onload=function(){r&&r(),e.refreshAll()},n.requestAnimationFrame=function(e){var i=window.requestAnimationFrame||window.mozRequestAnimationFrame||window.webkitRequestAnimationFrame||t;i.call(window,e)},n.Context=e}(),function(){"use strict";function t(t,e){return t.triggerPoint-e.triggerPoint}function e(t,e){return e.triggerPoint-t.triggerPoint}function i(t){this.name=t.name,this.axis=t.axis,this.id=this.name+"-"+this.axis,this.waypoints=[],this.clearTriggerQueues(),o[this.axis][this.name]=this}var o={vertical:{},horizontal:{}},n=window.Waypoint;i.prototype.add=function(t){this.waypoints.push(t)},i.prototype.clearTriggerQueues=function(){this.triggerQueues={up:[],down:[],left:[],right:[]}},i.prototype.flushTriggers=function(){for(var i in this.triggerQueues){var o=this.triggerQueues[i],n="up"===i||"left"===i;o.sort(n?e:t);for(var r=0,s=o.length;s>r;r+=1){var a=o[r];(a.options.continuous||r===o.length-1)&&a.trigger([i])}}this.clearTriggerQueues()},i.prototype.next=function(e){this.waypoints.sort(t);var i=n.Adapter.inArray(e,this.waypoints),o=i===this.waypoints.length-1;return o?null:this.waypoints[i+1]},i.prototype.previous=function(e){this.waypoints.sort(t);var i=n.Adapter.inArray(e,this.waypoints);return i?this.waypoints[i-1]:null},i.prototype.queueTrigger=function(t,e){this.triggerQueues[e].push(t)},i.prototype.remove=function(t){var e=n.Adapter.inArray(t,this.waypoints);e>-1&&this.waypoints.splice(e,1)},i.prototype.first=function(){return this.waypoints[0]},i.prototype.last=function(){return this.waypoints[this.waypoints.length-1]},i.findOrCreate=function(t){return o[t.axis][t.name]||new i(t)},n.Group=i}(),function(){"use strict";function t(t){this.$element=e(t)}var e=window.jQuery,i=window.Waypoint;e.each(["innerHeight","innerWidth","off","offset","on","outerHeight","outerWidth","scrollLeft","scrollTop"],function(e,i){t.prototype[i]=function(){var t=Array.prototype.slice.call(arguments);return this.$element[i].apply(this.$element,t)}}),e.each(["extend","inArray","isEmptyObject"],function(i,o){t[o]=e[o]}),i.adapters.push({name:"jquery",Adapter:t}),i.Adapter=t}(),function(){"use strict";function t(t){return function(){var i=[],o=arguments[0];return t.isFunction(arguments[0])&&(o=t.extend({},arguments[1]),o.handler=arguments[0]),this.each(function(){var n=t.extend({},o,{element:this});"string"==typeof n.context&&(n.context=t(this).closest(n.context)[0]),i.push(new e(n))}),i}}var e=window.Waypoint;window.jQuery&&(window.jQuery.fn.waypoint=t(window.jQuery)),window.Zepto&&(window.Zepto.fn.waypoint=t(window.Zepto))}(); \ No newline at end of file +!function(){"use strict";function t(o){if(!o)throw new Error("No options passed to Waypoint constructor");if(!o.element)throw new Error("No element option passed to Waypoint constructor");if(!o.handler)throw new Error("No handler option passed to Waypoint constructor");this.key="waypoint-"+e,this.options=t.Adapter.extend({},t.defaults,o),this.element=this.options.element,this.adapter=new t.Adapter(this.element),this.callback=o.handler,this.axis=this.options.horizontal?"horizontal":"vertical",this.enabled=this.options.enabled,this.triggerPoint=null,this.group=t.Group.findOrCreate({name:this.options.group,axis:this.axis}),this.context=t.Context.findOrCreateByElement(this.options.context),t.offsetAliases[this.options.offset]&&(this.options.offset=t.offsetAliases[this.options.offset]),this.group.add(this),this.context.add(this),i[this.key]=this,e+=1}var e=0,i={};t.prototype.queueTrigger=function(t){this.group.queueTrigger(this,t)},t.prototype.trigger=function(t){this.enabled&&this.callback&&this.callback.apply(this,t)},t.prototype.destroy=function(){this.context.remove(this),this.group.remove(this),delete i[this.key]},t.prototype.disable=function(){return this.enabled=!1,this},t.prototype.enable=function(){return this.context.refresh(),this.enabled=!0,this},t.prototype.next=function(){return this.group.next(this)},t.prototype.previous=function(){return this.group.previous(this)},t.invokeAll=function(t){var e=[];for(var o in i)e.push(i[o]);for(var n=0,r=e.length;r>n;n++)e[n][t]()},t.destroyAll=function(){t.invokeAll("destroy")},t.disableAll=function(){t.invokeAll("disable")},t.enableAll=function(){t.Context.refreshAll();for(var e in i)i[e].enabled=!0;return this},t.refreshAll=function(){t.Context.refreshAll()},t.viewportHeight=function(){return window.innerHeight||document.documentElement.clientHeight},t.viewportWidth=function(){return document.documentElement.clientWidth},t.adapters=[],t.defaults={context:window,continuous:!0,enabled:!0,group:"default",horizontal:!1,offset:0},t.offsetAliases={"bottom-in-view":function(){return this.context.innerHeight()-this.adapter.outerHeight()},"right-in-view":function(){return this.context.innerWidth()-this.adapter.outerWidth()}},window.Waypoint=t}(),function(){"use strict";function t(t){window.setTimeout(t,1e3/60)}function e(t){this.element=t,this.Adapter=n.Adapter,this.adapter=new this.Adapter(t),this.key="waypoint-context-"+i,this.didScroll=!1,this.didResize=!1,this.oldScroll={x:this.adapter.scrollLeft(),y:this.adapter.scrollTop()},this.waypoints={vertical:{},horizontal:{}},t.waypointContextKey=this.key,o[t.waypointContextKey]=this,i+=1,n.windowContext||(n.windowContext=!0,n.windowContext=new e(window)),this.createThrottledScrollHandler(),this.createThrottledResizeHandler()}var i=0,o={},n=window.Waypoint,r=window.onload;e.prototype.add=function(t){var e=t.options.horizontal?"horizontal":"vertical";this.waypoints[e][t.key]=t,this.refresh()},e.prototype.checkEmpty=function(){var t=this.Adapter.isEmptyObject(this.waypoints.horizontal),e=this.Adapter.isEmptyObject(this.waypoints.vertical),i=this.element==this.element.window;t&&e&&!i&&(this.adapter.off(".waypoints"),delete o[this.key])},e.prototype.createThrottledResizeHandler=function(){function t(){e.handleResize(),e.didResize=!1}var e=this;this.adapter.on("resize.waypoints",function(){e.didResize||(e.didResize=!0,n.requestAnimationFrame(t))})},e.prototype.createThrottledScrollHandler=function(){function t(){e.handleScroll(),e.didScroll=!1}var e=this;this.adapter.on("scroll.waypoints",function(){(!e.didScroll||n.isTouch)&&(e.didScroll=!0,n.requestAnimationFrame(t))})},e.prototype.handleResize=function(){n.Context.refreshAll()},e.prototype.handleScroll=function(){var t={},e={horizontal:{newScroll:this.adapter.scrollLeft(),oldScroll:this.oldScroll.x,forward:"right",backward:"left"},vertical:{newScroll:this.adapter.scrollTop(),oldScroll:this.oldScroll.y,forward:"down",backward:"up"}};for(var i in e){var o=e[i],n=o.newScroll>o.oldScroll,r=n?o.forward:o.backward;for(var s in this.waypoints[i]){var a=this.waypoints[i][s];if(null!==a.triggerPoint){var l=o.oldScroll=a.triggerPoint,p=l&&h,u=!l&&!h;(p||u)&&(a.queueTrigger(r),t[a.group.id]=a.group)}}}for(var c in t)t[c].flushTriggers();this.oldScroll={x:e.horizontal.newScroll,y:e.vertical.newScroll}},e.prototype.innerHeight=function(){return this.element==this.element.window?n.viewportHeight():this.adapter.innerHeight()},e.prototype.remove=function(t){delete this.waypoints[t.axis][t.key],this.checkEmpty()},e.prototype.innerWidth=function(){return this.element==this.element.window?n.viewportWidth():this.adapter.innerWidth()},e.prototype.destroy=function(){var t=[];for(var e in this.waypoints)for(var i in this.waypoints[e])t.push(this.waypoints[e][i]);for(var o=0,n=t.length;n>o;o++)t[o].destroy()},e.prototype.refresh=function(){var t,e=this.element==this.element.window,i=e?void 0:this.adapter.offset(),o={};this.handleScroll(),t={horizontal:{contextOffset:e?0:i.left,contextScroll:e?0:this.oldScroll.x,contextDimension:this.innerWidth(),oldScroll:this.oldScroll.x,forward:"right",backward:"left",offsetProp:"left"},vertical:{contextOffset:e?0:i.top,contextScroll:e?0:this.oldScroll.y,contextDimension:this.innerHeight(),oldScroll:this.oldScroll.y,forward:"down",backward:"up",offsetProp:"top"}};for(var r in t){var s=t[r];for(var a in this.waypoints[r]){var l,h,p,u,c,d=this.waypoints[r][a],f=d.options.offset,w=d.triggerPoint,y=0,g=null==w;d.element!==d.element.window&&(y=d.adapter.offset()[s.offsetProp]),"function"==typeof f?f=f.apply(d):"string"==typeof f&&(f=parseFloat(f),d.options.offset.indexOf("%")>-1&&(f=Math.ceil(s.contextDimension*f/100))),l=s.contextScroll-s.contextOffset,d.triggerPoint=Math.floor(y+l-f),h=w=s.oldScroll,u=h&&p,c=!h&&!p,!g&&u?(d.queueTrigger(s.backward),o[d.group.id]=d.group):!g&&c?(d.queueTrigger(s.forward),o[d.group.id]=d.group):g&&s.oldScroll>=d.triggerPoint&&(d.queueTrigger(s.forward),o[d.group.id]=d.group)}}return n.requestAnimationFrame(function(){for(var t in o)o[t].flushTriggers()}),this},e.findOrCreateByElement=function(t){return e.findByElement(t)||new e(t)},e.refreshAll=function(){for(var t in o)o[t].refresh()},e.findByElement=function(t){return o[t.waypointContextKey]},window.onload=function(){r&&r(),e.refreshAll()},n.requestAnimationFrame=function(e){var i=window.requestAnimationFrame||window.mozRequestAnimationFrame||window.webkitRequestAnimationFrame||t;i.call(window,e)},n.Context=e}(),function(){"use strict";function t(t,e){return t.triggerPoint-e.triggerPoint}function e(t,e){return e.triggerPoint-t.triggerPoint}function i(t){this.name=t.name,this.axis=t.axis,this.id=this.name+"-"+this.axis,this.waypoints=[],this.clearTriggerQueues(),o[this.axis][this.name]=this}var o={vertical:{},horizontal:{}},n=window.Waypoint;i.prototype.add=function(t){this.waypoints.push(t)},i.prototype.clearTriggerQueues=function(){this.triggerQueues={up:[],down:[],left:[],right:[]}},i.prototype.flushTriggers=function(){for(var i in this.triggerQueues){var o=this.triggerQueues[i],n="up"===i||"left"===i;o.sort(n?e:t);for(var r=0,s=o.length;s>r;r+=1){var a=o[r];(a.options.continuous||r===o.length-1)&&a.trigger([i])}}this.clearTriggerQueues()},i.prototype.next=function(e){this.waypoints.sort(t);var i=n.Adapter.inArray(e,this.waypoints),o=i===this.waypoints.length-1;return o?null:this.waypoints[i+1]},i.prototype.previous=function(e){this.waypoints.sort(t);var i=n.Adapter.inArray(e,this.waypoints);return i?this.waypoints[i-1]:null},i.prototype.queueTrigger=function(t,e){this.triggerQueues[e].push(t)},i.prototype.remove=function(t){var e=n.Adapter.inArray(t,this.waypoints);e>-1&&this.waypoints.splice(e,1)},i.prototype.first=function(){return this.waypoints[0]},i.prototype.last=function(){return this.waypoints[this.waypoints.length-1]},i.findOrCreate=function(t){return o[t.axis][t.name]||new i(t)},n.Group=i}(),function(){"use strict";function t(t){this.$element=e(t)}var e=window.jQuery,i=window.Waypoint;e.each(["innerHeight","innerWidth","off","offset","on","outerHeight","outerWidth","scrollLeft","scrollTop"],function(e,i){t.prototype[i]=function(){var t=Array.prototype.slice.call(arguments);return this.$element[i].apply(this.$element,t)}}),e.each(["extend","inArray","isEmptyObject"],function(i,o){t[o]=e[o]}),i.adapters.push({name:"jquery",Adapter:t}),i.Adapter=t}(),function(){"use strict";function t(t){return function(){var i=[],o=arguments[0];return t.isFunction(arguments[0])&&(o=t.extend({},arguments[1]),o.handler=arguments[0]),this.each(function(){var n=t.extend({},o,{element:this});"string"==typeof n.context&&(n.context=t(this).closest(n.context)[0]),i.push(new e(n))}),i}}var e=window.Waypoint;window.jQuery&&(window.jQuery.fn.waypoint=t(window.jQuery)),window.Zepto&&(window.Zepto.fn.waypoint=t(window.Zepto))}(); \ No newline at end of file diff --git a/lib/noframework.waypoints.js b/lib/noframework.waypoints.js index 2de1c3c5..a735441c 100644 --- a/lib/noframework.waypoints.js +++ b/lib/noframework.waypoints.js @@ -1,6 +1,6 @@ /*! -Waypoints - 4.0.0 -Copyright © 2011-2015 Caleb Troughton +Waypoints - 4.0.1 +Copyright © 2011-2016 Caleb Troughton Licensed under the MIT license. https://github.com/imakewebthings/waypoints/blob/master/licenses.txt */ @@ -121,7 +121,11 @@ https://github.com/imakewebthings/waypoints/blob/master/licenses.txt /* Public */ /* http://imakewebthings.com/waypoints/api/enable-all */ Waypoint.enableAll = function() { - Waypoint.invokeAll('enable') + Waypoint.Context.refreshAll() + for (var waypointKey in allWaypoints) { + allWaypoints[waypointKey].enabled = true + } + return this } /* Public */ @@ -196,6 +200,10 @@ https://github.com/imakewebthings/waypoints/blob/master/licenses.txt element.waypointContextKey = this.key contexts[element.waypointContextKey] = this keyCounter += 1 + if (!Waypoint.windowContext) { + Waypoint.windowContext = true + Waypoint.windowContext = new Context(window) + } this.createThrottledScrollHandler() this.createThrottledResizeHandler() @@ -212,7 +220,8 @@ https://github.com/imakewebthings/waypoints/blob/master/licenses.txt Context.prototype.checkEmpty = function() { var horizontalEmpty = this.Adapter.isEmptyObject(this.waypoints.horizontal) var verticalEmpty = this.Adapter.isEmptyObject(this.waypoints.vertical) - if (horizontalEmpty && verticalEmpty) { + var isWindow = this.element == this.element.window + if (horizontalEmpty && verticalEmpty && !isWindow) { this.adapter.off('.waypoints') delete contexts[this.key] } @@ -281,6 +290,9 @@ https://github.com/imakewebthings/waypoints/blob/master/licenses.txt for (var waypointKey in this.waypoints[axisKey]) { var waypoint = this.waypoints[axisKey][waypointKey] + if (waypoint.triggerPoint === null) { + continue + } var wasBeforeTriggerPoint = axis.oldScroll < waypoint.triggerPoint var nowAfterTriggerPoint = axis.newScroll >= waypoint.triggerPoint var crossedForward = wasBeforeTriggerPoint && nowAfterTriggerPoint @@ -400,7 +412,7 @@ https://github.com/imakewebthings/waypoints/blob/master/licenses.txt } contextModifier = axis.contextScroll - axis.contextOffset - waypoint.triggerPoint = elementOffset + contextModifier - adjustment + waypoint.triggerPoint = Math.floor(elementOffset + contextModifier - adjustment) wasBeforeScroll = oldTriggerPoint < axis.oldScroll nowAfterScroll = waypoint.triggerPoint >= axis.oldScroll triggeredBackward = wasBeforeScroll && nowAfterScroll @@ -455,6 +467,7 @@ https://github.com/imakewebthings/waypoints/blob/master/licenses.txt Context.refreshAll() } + Waypoint.requestAnimationFrame = function(callback) { var requestFn = window.requestAnimationFrame || window.mozRequestAnimationFrame || diff --git a/lib/noframework.waypoints.min.js b/lib/noframework.waypoints.min.js index 2ce1f916..edfacb57 100644 --- a/lib/noframework.waypoints.min.js +++ b/lib/noframework.waypoints.min.js @@ -1,7 +1,7 @@ /*! -Waypoints - 4.0.0 -Copyright © 2011-2015 Caleb Troughton +Waypoints - 4.0.1 +Copyright © 2011-2016 Caleb Troughton Licensed under the MIT license. https://github.com/imakewebthings/waypoints/blob/master/licenses.txt */ -!function(){"use strict";function t(n){if(!n)throw new Error("No options passed to Waypoint constructor");if(!n.element)throw new Error("No element option passed to Waypoint constructor");if(!n.handler)throw new Error("No handler option passed to Waypoint constructor");this.key="waypoint-"+e,this.options=t.Adapter.extend({},t.defaults,n),this.element=this.options.element,this.adapter=new t.Adapter(this.element),this.callback=n.handler,this.axis=this.options.horizontal?"horizontal":"vertical",this.enabled=this.options.enabled,this.triggerPoint=null,this.group=t.Group.findOrCreate({name:this.options.group,axis:this.axis}),this.context=t.Context.findOrCreateByElement(this.options.context),t.offsetAliases[this.options.offset]&&(this.options.offset=t.offsetAliases[this.options.offset]),this.group.add(this),this.context.add(this),i[this.key]=this,e+=1}var e=0,i={};t.prototype.queueTrigger=function(t){this.group.queueTrigger(this,t)},t.prototype.trigger=function(t){this.enabled&&this.callback&&this.callback.apply(this,t)},t.prototype.destroy=function(){this.context.remove(this),this.group.remove(this),delete i[this.key]},t.prototype.disable=function(){return this.enabled=!1,this},t.prototype.enable=function(){return this.context.refresh(),this.enabled=!0,this},t.prototype.next=function(){return this.group.next(this)},t.prototype.previous=function(){return this.group.previous(this)},t.invokeAll=function(t){var e=[];for(var n in i)e.push(i[n]);for(var o=0,r=e.length;r>o;o++)e[o][t]()},t.destroyAll=function(){t.invokeAll("destroy")},t.disableAll=function(){t.invokeAll("disable")},t.enableAll=function(){t.invokeAll("enable")},t.refreshAll=function(){t.Context.refreshAll()},t.viewportHeight=function(){return window.innerHeight||document.documentElement.clientHeight},t.viewportWidth=function(){return document.documentElement.clientWidth},t.adapters=[],t.defaults={context:window,continuous:!0,enabled:!0,group:"default",horizontal:!1,offset:0},t.offsetAliases={"bottom-in-view":function(){return this.context.innerHeight()-this.adapter.outerHeight()},"right-in-view":function(){return this.context.innerWidth()-this.adapter.outerWidth()}},window.Waypoint=t}(),function(){"use strict";function t(t){window.setTimeout(t,1e3/60)}function e(t){this.element=t,this.Adapter=o.Adapter,this.adapter=new this.Adapter(t),this.key="waypoint-context-"+i,this.didScroll=!1,this.didResize=!1,this.oldScroll={x:this.adapter.scrollLeft(),y:this.adapter.scrollTop()},this.waypoints={vertical:{},horizontal:{}},t.waypointContextKey=this.key,n[t.waypointContextKey]=this,i+=1,this.createThrottledScrollHandler(),this.createThrottledResizeHandler()}var i=0,n={},o=window.Waypoint,r=window.onload;e.prototype.add=function(t){var e=t.options.horizontal?"horizontal":"vertical";this.waypoints[e][t.key]=t,this.refresh()},e.prototype.checkEmpty=function(){var t=this.Adapter.isEmptyObject(this.waypoints.horizontal),e=this.Adapter.isEmptyObject(this.waypoints.vertical);t&&e&&(this.adapter.off(".waypoints"),delete n[this.key])},e.prototype.createThrottledResizeHandler=function(){function t(){e.handleResize(),e.didResize=!1}var e=this;this.adapter.on("resize.waypoints",function(){e.didResize||(e.didResize=!0,o.requestAnimationFrame(t))})},e.prototype.createThrottledScrollHandler=function(){function t(){e.handleScroll(),e.didScroll=!1}var e=this;this.adapter.on("scroll.waypoints",function(){(!e.didScroll||o.isTouch)&&(e.didScroll=!0,o.requestAnimationFrame(t))})},e.prototype.handleResize=function(){o.Context.refreshAll()},e.prototype.handleScroll=function(){var t={},e={horizontal:{newScroll:this.adapter.scrollLeft(),oldScroll:this.oldScroll.x,forward:"right",backward:"left"},vertical:{newScroll:this.adapter.scrollTop(),oldScroll:this.oldScroll.y,forward:"down",backward:"up"}};for(var i in e){var n=e[i],o=n.newScroll>n.oldScroll,r=o?n.forward:n.backward;for(var s in this.waypoints[i]){var l=this.waypoints[i][s],a=n.oldScroll=l.triggerPoint,p=a&&h,u=!a&&!h;(p||u)&&(l.queueTrigger(r),t[l.group.id]=l.group)}}for(var c in t)t[c].flushTriggers();this.oldScroll={x:e.horizontal.newScroll,y:e.vertical.newScroll}},e.prototype.innerHeight=function(){return this.element==this.element.window?o.viewportHeight():this.adapter.innerHeight()},e.prototype.remove=function(t){delete this.waypoints[t.axis][t.key],this.checkEmpty()},e.prototype.innerWidth=function(){return this.element==this.element.window?o.viewportWidth():this.adapter.innerWidth()},e.prototype.destroy=function(){var t=[];for(var e in this.waypoints)for(var i in this.waypoints[e])t.push(this.waypoints[e][i]);for(var n=0,o=t.length;o>n;n++)t[n].destroy()},e.prototype.refresh=function(){var t,e=this.element==this.element.window,i=e?void 0:this.adapter.offset(),n={};this.handleScroll(),t={horizontal:{contextOffset:e?0:i.left,contextScroll:e?0:this.oldScroll.x,contextDimension:this.innerWidth(),oldScroll:this.oldScroll.x,forward:"right",backward:"left",offsetProp:"left"},vertical:{contextOffset:e?0:i.top,contextScroll:e?0:this.oldScroll.y,contextDimension:this.innerHeight(),oldScroll:this.oldScroll.y,forward:"down",backward:"up",offsetProp:"top"}};for(var r in t){var s=t[r];for(var l in this.waypoints[r]){var a,h,p,u,c,f=this.waypoints[r][l],d=f.options.offset,y=f.triggerPoint,g=0,w=null==y;f.element!==f.element.window&&(g=f.adapter.offset()[s.offsetProp]),"function"==typeof d?d=d.apply(f):"string"==typeof d&&(d=parseFloat(d),f.options.offset.indexOf("%")>-1&&(d=Math.ceil(s.contextDimension*d/100))),a=s.contextScroll-s.contextOffset,f.triggerPoint=g+a-d,h=y=s.oldScroll,u=h&&p,c=!h&&!p,!w&&u?(f.queueTrigger(s.backward),n[f.group.id]=f.group):!w&&c?(f.queueTrigger(s.forward),n[f.group.id]=f.group):w&&s.oldScroll>=f.triggerPoint&&(f.queueTrigger(s.forward),n[f.group.id]=f.group)}}return o.requestAnimationFrame(function(){for(var t in n)n[t].flushTriggers()}),this},e.findOrCreateByElement=function(t){return e.findByElement(t)||new e(t)},e.refreshAll=function(){for(var t in n)n[t].refresh()},e.findByElement=function(t){return n[t.waypointContextKey]},window.onload=function(){r&&r(),e.refreshAll()},o.requestAnimationFrame=function(e){var i=window.requestAnimationFrame||window.mozRequestAnimationFrame||window.webkitRequestAnimationFrame||t;i.call(window,e)},o.Context=e}(),function(){"use strict";function t(t,e){return t.triggerPoint-e.triggerPoint}function e(t,e){return e.triggerPoint-t.triggerPoint}function i(t){this.name=t.name,this.axis=t.axis,this.id=this.name+"-"+this.axis,this.waypoints=[],this.clearTriggerQueues(),n[this.axis][this.name]=this}var n={vertical:{},horizontal:{}},o=window.Waypoint;i.prototype.add=function(t){this.waypoints.push(t)},i.prototype.clearTriggerQueues=function(){this.triggerQueues={up:[],down:[],left:[],right:[]}},i.prototype.flushTriggers=function(){for(var i in this.triggerQueues){var n=this.triggerQueues[i],o="up"===i||"left"===i;n.sort(o?e:t);for(var r=0,s=n.length;s>r;r+=1){var l=n[r];(l.options.continuous||r===n.length-1)&&l.trigger([i])}}this.clearTriggerQueues()},i.prototype.next=function(e){this.waypoints.sort(t);var i=o.Adapter.inArray(e,this.waypoints),n=i===this.waypoints.length-1;return n?null:this.waypoints[i+1]},i.prototype.previous=function(e){this.waypoints.sort(t);var i=o.Adapter.inArray(e,this.waypoints);return i?this.waypoints[i-1]:null},i.prototype.queueTrigger=function(t,e){this.triggerQueues[e].push(t)},i.prototype.remove=function(t){var e=o.Adapter.inArray(t,this.waypoints);e>-1&&this.waypoints.splice(e,1)},i.prototype.first=function(){return this.waypoints[0]},i.prototype.last=function(){return this.waypoints[this.waypoints.length-1]},i.findOrCreate=function(t){return n[t.axis][t.name]||new i(t)},o.Group=i}(),function(){"use strict";function t(t){return t===t.window}function e(e){return t(e)?e:e.defaultView}function i(t){this.element=t,this.handlers={}}var n=window.Waypoint;i.prototype.innerHeight=function(){var e=t(this.element);return e?this.element.innerHeight:this.element.clientHeight},i.prototype.innerWidth=function(){var e=t(this.element);return e?this.element.innerWidth:this.element.clientWidth},i.prototype.off=function(t,e){function i(t,e,i){for(var n=0,o=e.length-1;o>n;n++){var r=e[n];i&&i!==r||t.removeEventListener(r)}}var n=t.split("."),o=n[0],r=n[1],s=this.element;if(r&&this.handlers[r]&&o)i(s,this.handlers[r][o],e),this.handlers[r][o]=[];else if(o)for(var l in this.handlers)i(s,this.handlers[l][o]||[],e),this.handlers[l][o]=[];else if(r&&this.handlers[r]){for(var a in this.handlers[r])i(s,this.handlers[r][a],e);this.handlers[r]={}}},i.prototype.offset=function(){if(!this.element.ownerDocument)return null;var t=this.element.ownerDocument.documentElement,i=e(this.element.ownerDocument),n={top:0,left:0};return this.element.getBoundingClientRect&&(n=this.element.getBoundingClientRect()),{top:n.top+i.pageYOffset-t.clientTop,left:n.left+i.pageXOffset-t.clientLeft}},i.prototype.on=function(t,e){var i=t.split("."),n=i[0],o=i[1]||"__default",r=this.handlers[o]=this.handlers[o]||{},s=r[n]=r[n]||[];s.push(e),this.element.addEventListener(n,e)},i.prototype.outerHeight=function(e){var i,n=this.innerHeight();return e&&!t(this.element)&&(i=window.getComputedStyle(this.element),n+=parseInt(i.marginTop,10),n+=parseInt(i.marginBottom,10)),n},i.prototype.outerWidth=function(e){var i,n=this.innerWidth();return e&&!t(this.element)&&(i=window.getComputedStyle(this.element),n+=parseInt(i.marginLeft,10),n+=parseInt(i.marginRight,10)),n},i.prototype.scrollLeft=function(){var t=e(this.element);return t?t.pageXOffset:this.element.scrollLeft},i.prototype.scrollTop=function(){var t=e(this.element);return t?t.pageYOffset:this.element.scrollTop},i.extend=function(){function t(t,e){if("object"==typeof t&&"object"==typeof e)for(var i in e)e.hasOwnProperty(i)&&(t[i]=e[i]);return t}for(var e=Array.prototype.slice.call(arguments),i=1,n=e.length;n>i;i++)t(e[0],e[i]);return e[0]},i.inArray=function(t,e,i){return null==e?-1:e.indexOf(t,i)},i.isEmptyObject=function(t){for(var e in t)return!1;return!0},n.adapters.push({name:"noframework",Adapter:i}),n.Adapter=i}(); \ No newline at end of file +!function(){"use strict";function t(n){if(!n)throw new Error("No options passed to Waypoint constructor");if(!n.element)throw new Error("No element option passed to Waypoint constructor");if(!n.handler)throw new Error("No handler option passed to Waypoint constructor");this.key="waypoint-"+e,this.options=t.Adapter.extend({},t.defaults,n),this.element=this.options.element,this.adapter=new t.Adapter(this.element),this.callback=n.handler,this.axis=this.options.horizontal?"horizontal":"vertical",this.enabled=this.options.enabled,this.triggerPoint=null,this.group=t.Group.findOrCreate({name:this.options.group,axis:this.axis}),this.context=t.Context.findOrCreateByElement(this.options.context),t.offsetAliases[this.options.offset]&&(this.options.offset=t.offsetAliases[this.options.offset]),this.group.add(this),this.context.add(this),i[this.key]=this,e+=1}var e=0,i={};t.prototype.queueTrigger=function(t){this.group.queueTrigger(this,t)},t.prototype.trigger=function(t){this.enabled&&this.callback&&this.callback.apply(this,t)},t.prototype.destroy=function(){this.context.remove(this),this.group.remove(this),delete i[this.key]},t.prototype.disable=function(){return this.enabled=!1,this},t.prototype.enable=function(){return this.context.refresh(),this.enabled=!0,this},t.prototype.next=function(){return this.group.next(this)},t.prototype.previous=function(){return this.group.previous(this)},t.invokeAll=function(t){var e=[];for(var n in i)e.push(i[n]);for(var o=0,r=e.length;r>o;o++)e[o][t]()},t.destroyAll=function(){t.invokeAll("destroy")},t.disableAll=function(){t.invokeAll("disable")},t.enableAll=function(){t.Context.refreshAll();for(var e in i)i[e].enabled=!0;return this},t.refreshAll=function(){t.Context.refreshAll()},t.viewportHeight=function(){return window.innerHeight||document.documentElement.clientHeight},t.viewportWidth=function(){return document.documentElement.clientWidth},t.adapters=[],t.defaults={context:window,continuous:!0,enabled:!0,group:"default",horizontal:!1,offset:0},t.offsetAliases={"bottom-in-view":function(){return this.context.innerHeight()-this.adapter.outerHeight()},"right-in-view":function(){return this.context.innerWidth()-this.adapter.outerWidth()}},window.Waypoint=t}(),function(){"use strict";function t(t){window.setTimeout(t,1e3/60)}function e(t){this.element=t,this.Adapter=o.Adapter,this.adapter=new this.Adapter(t),this.key="waypoint-context-"+i,this.didScroll=!1,this.didResize=!1,this.oldScroll={x:this.adapter.scrollLeft(),y:this.adapter.scrollTop()},this.waypoints={vertical:{},horizontal:{}},t.waypointContextKey=this.key,n[t.waypointContextKey]=this,i+=1,o.windowContext||(o.windowContext=!0,o.windowContext=new e(window)),this.createThrottledScrollHandler(),this.createThrottledResizeHandler()}var i=0,n={},o=window.Waypoint,r=window.onload;e.prototype.add=function(t){var e=t.options.horizontal?"horizontal":"vertical";this.waypoints[e][t.key]=t,this.refresh()},e.prototype.checkEmpty=function(){var t=this.Adapter.isEmptyObject(this.waypoints.horizontal),e=this.Adapter.isEmptyObject(this.waypoints.vertical),i=this.element==this.element.window;t&&e&&!i&&(this.adapter.off(".waypoints"),delete n[this.key])},e.prototype.createThrottledResizeHandler=function(){function t(){e.handleResize(),e.didResize=!1}var e=this;this.adapter.on("resize.waypoints",function(){e.didResize||(e.didResize=!0,o.requestAnimationFrame(t))})},e.prototype.createThrottledScrollHandler=function(){function t(){e.handleScroll(),e.didScroll=!1}var e=this;this.adapter.on("scroll.waypoints",function(){(!e.didScroll||o.isTouch)&&(e.didScroll=!0,o.requestAnimationFrame(t))})},e.prototype.handleResize=function(){o.Context.refreshAll()},e.prototype.handleScroll=function(){var t={},e={horizontal:{newScroll:this.adapter.scrollLeft(),oldScroll:this.oldScroll.x,forward:"right",backward:"left"},vertical:{newScroll:this.adapter.scrollTop(),oldScroll:this.oldScroll.y,forward:"down",backward:"up"}};for(var i in e){var n=e[i],o=n.newScroll>n.oldScroll,r=o?n.forward:n.backward;for(var s in this.waypoints[i]){var l=this.waypoints[i][s];if(null!==l.triggerPoint){var a=n.oldScroll=l.triggerPoint,p=a&&h,u=!a&&!h;(p||u)&&(l.queueTrigger(r),t[l.group.id]=l.group)}}}for(var d in t)t[d].flushTriggers();this.oldScroll={x:e.horizontal.newScroll,y:e.vertical.newScroll}},e.prototype.innerHeight=function(){return this.element==this.element.window?o.viewportHeight():this.adapter.innerHeight()},e.prototype.remove=function(t){delete this.waypoints[t.axis][t.key],this.checkEmpty()},e.prototype.innerWidth=function(){return this.element==this.element.window?o.viewportWidth():this.adapter.innerWidth()},e.prototype.destroy=function(){var t=[];for(var e in this.waypoints)for(var i in this.waypoints[e])t.push(this.waypoints[e][i]);for(var n=0,o=t.length;o>n;n++)t[n].destroy()},e.prototype.refresh=function(){var t,e=this.element==this.element.window,i=e?void 0:this.adapter.offset(),n={};this.handleScroll(),t={horizontal:{contextOffset:e?0:i.left,contextScroll:e?0:this.oldScroll.x,contextDimension:this.innerWidth(),oldScroll:this.oldScroll.x,forward:"right",backward:"left",offsetProp:"left"},vertical:{contextOffset:e?0:i.top,contextScroll:e?0:this.oldScroll.y,contextDimension:this.innerHeight(),oldScroll:this.oldScroll.y,forward:"down",backward:"up",offsetProp:"top"}};for(var r in t){var s=t[r];for(var l in this.waypoints[r]){var a,h,p,u,d,f=this.waypoints[r][l],c=f.options.offset,w=f.triggerPoint,y=0,g=null==w;f.element!==f.element.window&&(y=f.adapter.offset()[s.offsetProp]),"function"==typeof c?c=c.apply(f):"string"==typeof c&&(c=parseFloat(c),f.options.offset.indexOf("%")>-1&&(c=Math.ceil(s.contextDimension*c/100))),a=s.contextScroll-s.contextOffset,f.triggerPoint=Math.floor(y+a-c),h=w=s.oldScroll,u=h&&p,d=!h&&!p,!g&&u?(f.queueTrigger(s.backward),n[f.group.id]=f.group):!g&&d?(f.queueTrigger(s.forward),n[f.group.id]=f.group):g&&s.oldScroll>=f.triggerPoint&&(f.queueTrigger(s.forward),n[f.group.id]=f.group)}}return o.requestAnimationFrame(function(){for(var t in n)n[t].flushTriggers()}),this},e.findOrCreateByElement=function(t){return e.findByElement(t)||new e(t)},e.refreshAll=function(){for(var t in n)n[t].refresh()},e.findByElement=function(t){return n[t.waypointContextKey]},window.onload=function(){r&&r(),e.refreshAll()},o.requestAnimationFrame=function(e){var i=window.requestAnimationFrame||window.mozRequestAnimationFrame||window.webkitRequestAnimationFrame||t;i.call(window,e)},o.Context=e}(),function(){"use strict";function t(t,e){return t.triggerPoint-e.triggerPoint}function e(t,e){return e.triggerPoint-t.triggerPoint}function i(t){this.name=t.name,this.axis=t.axis,this.id=this.name+"-"+this.axis,this.waypoints=[],this.clearTriggerQueues(),n[this.axis][this.name]=this}var n={vertical:{},horizontal:{}},o=window.Waypoint;i.prototype.add=function(t){this.waypoints.push(t)},i.prototype.clearTriggerQueues=function(){this.triggerQueues={up:[],down:[],left:[],right:[]}},i.prototype.flushTriggers=function(){for(var i in this.triggerQueues){var n=this.triggerQueues[i],o="up"===i||"left"===i;n.sort(o?e:t);for(var r=0,s=n.length;s>r;r+=1){var l=n[r];(l.options.continuous||r===n.length-1)&&l.trigger([i])}}this.clearTriggerQueues()},i.prototype.next=function(e){this.waypoints.sort(t);var i=o.Adapter.inArray(e,this.waypoints),n=i===this.waypoints.length-1;return n?null:this.waypoints[i+1]},i.prototype.previous=function(e){this.waypoints.sort(t);var i=o.Adapter.inArray(e,this.waypoints);return i?this.waypoints[i-1]:null},i.prototype.queueTrigger=function(t,e){this.triggerQueues[e].push(t)},i.prototype.remove=function(t){var e=o.Adapter.inArray(t,this.waypoints);e>-1&&this.waypoints.splice(e,1)},i.prototype.first=function(){return this.waypoints[0]},i.prototype.last=function(){return this.waypoints[this.waypoints.length-1]},i.findOrCreate=function(t){return n[t.axis][t.name]||new i(t)},o.Group=i}(),function(){"use strict";function t(t){return t===t.window}function e(e){return t(e)?e:e.defaultView}function i(t){this.element=t,this.handlers={}}var n=window.Waypoint;i.prototype.innerHeight=function(){var e=t(this.element);return e?this.element.innerHeight:this.element.clientHeight},i.prototype.innerWidth=function(){var e=t(this.element);return e?this.element.innerWidth:this.element.clientWidth},i.prototype.off=function(t,e){function i(t,e,i){for(var n=0,o=e.length-1;o>n;n++){var r=e[n];i&&i!==r||t.removeEventListener(r)}}var n=t.split("."),o=n[0],r=n[1],s=this.element;if(r&&this.handlers[r]&&o)i(s,this.handlers[r][o],e),this.handlers[r][o]=[];else if(o)for(var l in this.handlers)i(s,this.handlers[l][o]||[],e),this.handlers[l][o]=[];else if(r&&this.handlers[r]){for(var a in this.handlers[r])i(s,this.handlers[r][a],e);this.handlers[r]={}}},i.prototype.offset=function(){if(!this.element.ownerDocument)return null;var t=this.element.ownerDocument.documentElement,i=e(this.element.ownerDocument),n={top:0,left:0};return this.element.getBoundingClientRect&&(n=this.element.getBoundingClientRect()),{top:n.top+i.pageYOffset-t.clientTop,left:n.left+i.pageXOffset-t.clientLeft}},i.prototype.on=function(t,e){var i=t.split("."),n=i[0],o=i[1]||"__default",r=this.handlers[o]=this.handlers[o]||{},s=r[n]=r[n]||[];s.push(e),this.element.addEventListener(n,e)},i.prototype.outerHeight=function(e){var i,n=this.innerHeight();return e&&!t(this.element)&&(i=window.getComputedStyle(this.element),n+=parseInt(i.marginTop,10),n+=parseInt(i.marginBottom,10)),n},i.prototype.outerWidth=function(e){var i,n=this.innerWidth();return e&&!t(this.element)&&(i=window.getComputedStyle(this.element),n+=parseInt(i.marginLeft,10),n+=parseInt(i.marginRight,10)),n},i.prototype.scrollLeft=function(){var t=e(this.element);return t?t.pageXOffset:this.element.scrollLeft},i.prototype.scrollTop=function(){var t=e(this.element);return t?t.pageYOffset:this.element.scrollTop},i.extend=function(){function t(t,e){if("object"==typeof t&&"object"==typeof e)for(var i in e)e.hasOwnProperty(i)&&(t[i]=e[i]);return t}for(var e=Array.prototype.slice.call(arguments),i=1,n=e.length;n>i;i++)t(e[0],e[i]);return e[0]},i.inArray=function(t,e,i){return null==e?-1:e.indexOf(t,i)},i.isEmptyObject=function(t){for(var e in t)return!1;return!0},n.adapters.push({name:"noframework",Adapter:i}),n.Adapter=i}(); \ No newline at end of file diff --git a/lib/shortcuts/infinite.js b/lib/shortcuts/infinite.js index eec5dacb..97ab913f 100644 --- a/lib/shortcuts/infinite.js +++ b/lib/shortcuts/infinite.js @@ -1,6 +1,6 @@ /*! -Waypoints Infinite Scroll Shortcut - 4.0.0 -Copyright © 2011-2015 Caleb Troughton +Waypoints Infinite Scroll Shortcut - 4.0.1 +Copyright © 2011-2016 Caleb Troughton Licensed under the MIT license. https://github.com/imakewebthings/waypoints/blob/master/licenses.txt */ diff --git a/lib/shortcuts/infinite.min.js b/lib/shortcuts/infinite.min.js index 8ecbc730..d429cfb5 100644 --- a/lib/shortcuts/infinite.min.js +++ b/lib/shortcuts/infinite.min.js @@ -1,6 +1,6 @@ /*! -Waypoints Infinite Scroll Shortcut - 4.0.0 -Copyright © 2011-2015 Caleb Troughton +Waypoints Infinite Scroll Shortcut - 4.0.1 +Copyright © 2011-2016 Caleb Troughton Licensed under the MIT license. https://github.com/imakewebthings/waypoints/blob/master/licenses.txt */ diff --git a/lib/shortcuts/inview.js b/lib/shortcuts/inview.js index acec502a..2d5c1b0d 100644 --- a/lib/shortcuts/inview.js +++ b/lib/shortcuts/inview.js @@ -1,6 +1,6 @@ /*! -Waypoints Inview Shortcut - 4.0.0 -Copyright © 2011-2015 Caleb Troughton +Waypoints Inview Shortcut - 4.0.1 +Copyright © 2011-2016 Caleb Troughton Licensed under the MIT license. https://github.com/imakewebthings/waypoints/blob/master/licenses.txt */ diff --git a/lib/shortcuts/inview.min.js b/lib/shortcuts/inview.min.js index 6375bafe..7c2675ce 100644 --- a/lib/shortcuts/inview.min.js +++ b/lib/shortcuts/inview.min.js @@ -1,6 +1,6 @@ /*! -Waypoints Inview Shortcut - 4.0.0 -Copyright © 2011-2015 Caleb Troughton +Waypoints Inview Shortcut - 4.0.1 +Copyright © 2011-2016 Caleb Troughton Licensed under the MIT license. https://github.com/imakewebthings/waypoints/blob/master/licenses.txt */ diff --git a/lib/shortcuts/sticky.js b/lib/shortcuts/sticky.js index b609b84a..4ca5a1ed 100644 --- a/lib/shortcuts/sticky.js +++ b/lib/shortcuts/sticky.js @@ -1,6 +1,6 @@ /*! -Waypoints Sticky Element Shortcut - 4.0.0 -Copyright © 2011-2015 Caleb Troughton +Waypoints Sticky Element Shortcut - 4.0.1 +Copyright © 2011-2016 Caleb Troughton Licensed under the MIT license. https://github.com/imakewebthings/waypoints/blob/master/licenses.txt */ diff --git a/lib/shortcuts/sticky.min.js b/lib/shortcuts/sticky.min.js index e2ea0603..20578171 100644 --- a/lib/shortcuts/sticky.min.js +++ b/lib/shortcuts/sticky.min.js @@ -1,6 +1,6 @@ /*! -Waypoints Sticky Element Shortcut - 4.0.0 -Copyright © 2011-2015 Caleb Troughton +Waypoints Sticky Element Shortcut - 4.0.1 +Copyright © 2011-2016 Caleb Troughton Licensed under the MIT license. https://github.com/imakewebthings/waypoints/blob/master/licenses.txt */ diff --git a/lib/waypoints.debug.js b/lib/waypoints.debug.js index 49601e38..df6256bc 100644 --- a/lib/waypoints.debug.js +++ b/lib/waypoints.debug.js @@ -1,6 +1,6 @@ /*! -Waypoints Debug - 4.0.0 -Copyright © 2011-2015 Caleb Troughton +Waypoints Debug - 4.0.1 +Copyright © 2011-2016 Caleb Troughton Licensed under the MIT license. https://github.com/imakewebthings/waypoints/blob/master/licenses.txt */ diff --git a/lib/zepto.waypoints.js b/lib/zepto.waypoints.js index 70f49701..ef3eb0ef 100644 --- a/lib/zepto.waypoints.js +++ b/lib/zepto.waypoints.js @@ -1,6 +1,6 @@ /*! -Waypoints - 4.0.0 -Copyright © 2011-2015 Caleb Troughton +Waypoints - 4.0.1 +Copyright © 2011-2016 Caleb Troughton Licensed under the MIT license. https://github.com/imakewebthings/waypoints/blob/master/licenses.txt */ @@ -121,7 +121,11 @@ https://github.com/imakewebthings/waypoints/blob/master/licenses.txt /* Public */ /* http://imakewebthings.com/waypoints/api/enable-all */ Waypoint.enableAll = function() { - Waypoint.invokeAll('enable') + Waypoint.Context.refreshAll() + for (var waypointKey in allWaypoints) { + allWaypoints[waypointKey].enabled = true + } + return this } /* Public */ @@ -196,6 +200,10 @@ https://github.com/imakewebthings/waypoints/blob/master/licenses.txt element.waypointContextKey = this.key contexts[element.waypointContextKey] = this keyCounter += 1 + if (!Waypoint.windowContext) { + Waypoint.windowContext = true + Waypoint.windowContext = new Context(window) + } this.createThrottledScrollHandler() this.createThrottledResizeHandler() @@ -212,7 +220,8 @@ https://github.com/imakewebthings/waypoints/blob/master/licenses.txt Context.prototype.checkEmpty = function() { var horizontalEmpty = this.Adapter.isEmptyObject(this.waypoints.horizontal) var verticalEmpty = this.Adapter.isEmptyObject(this.waypoints.vertical) - if (horizontalEmpty && verticalEmpty) { + var isWindow = this.element == this.element.window + if (horizontalEmpty && verticalEmpty && !isWindow) { this.adapter.off('.waypoints') delete contexts[this.key] } @@ -281,6 +290,9 @@ https://github.com/imakewebthings/waypoints/blob/master/licenses.txt for (var waypointKey in this.waypoints[axisKey]) { var waypoint = this.waypoints[axisKey][waypointKey] + if (waypoint.triggerPoint === null) { + continue + } var wasBeforeTriggerPoint = axis.oldScroll < waypoint.triggerPoint var nowAfterTriggerPoint = axis.newScroll >= waypoint.triggerPoint var crossedForward = wasBeforeTriggerPoint && nowAfterTriggerPoint @@ -400,7 +412,7 @@ https://github.com/imakewebthings/waypoints/blob/master/licenses.txt } contextModifier = axis.contextScroll - axis.contextOffset - waypoint.triggerPoint = elementOffset + contextModifier - adjustment + waypoint.triggerPoint = Math.floor(elementOffset + contextModifier - adjustment) wasBeforeScroll = oldTriggerPoint < axis.oldScroll nowAfterScroll = waypoint.triggerPoint >= axis.oldScroll triggeredBackward = wasBeforeScroll && nowAfterScroll @@ -455,6 +467,7 @@ https://github.com/imakewebthings/waypoints/blob/master/licenses.txt Context.refreshAll() } + Waypoint.requestAnimationFrame = function(callback) { var requestFn = window.requestAnimationFrame || window.mozRequestAnimationFrame || diff --git a/lib/zepto.waypoints.min.js b/lib/zepto.waypoints.min.js index 88d579d6..32fd5fba 100644 --- a/lib/zepto.waypoints.min.js +++ b/lib/zepto.waypoints.min.js @@ -1,7 +1,7 @@ /*! -Waypoints - 4.0.0 -Copyright © 2011-2015 Caleb Troughton +Waypoints - 4.0.1 +Copyright © 2011-2016 Caleb Troughton Licensed under the MIT license. https://github.com/imakewebthings/waypoints/blob/master/licenses.txt */ -!function(){"use strict";function t(o){if(!o)throw new Error("No options passed to Waypoint constructor");if(!o.element)throw new Error("No element option passed to Waypoint constructor");if(!o.handler)throw new Error("No handler option passed to Waypoint constructor");this.key="waypoint-"+e,this.options=t.Adapter.extend({},t.defaults,o),this.element=this.options.element,this.adapter=new t.Adapter(this.element),this.callback=o.handler,this.axis=this.options.horizontal?"horizontal":"vertical",this.enabled=this.options.enabled,this.triggerPoint=null,this.group=t.Group.findOrCreate({name:this.options.group,axis:this.axis}),this.context=t.Context.findOrCreateByElement(this.options.context),t.offsetAliases[this.options.offset]&&(this.options.offset=t.offsetAliases[this.options.offset]),this.group.add(this),this.context.add(this),i[this.key]=this,e+=1}var e=0,i={};t.prototype.queueTrigger=function(t){this.group.queueTrigger(this,t)},t.prototype.trigger=function(t){this.enabled&&this.callback&&this.callback.apply(this,t)},t.prototype.destroy=function(){this.context.remove(this),this.group.remove(this),delete i[this.key]},t.prototype.disable=function(){return this.enabled=!1,this},t.prototype.enable=function(){return this.context.refresh(),this.enabled=!0,this},t.prototype.next=function(){return this.group.next(this)},t.prototype.previous=function(){return this.group.previous(this)},t.invokeAll=function(t){var e=[];for(var o in i)e.push(i[o]);for(var n=0,r=e.length;r>n;n++)e[n][t]()},t.destroyAll=function(){t.invokeAll("destroy")},t.disableAll=function(){t.invokeAll("disable")},t.enableAll=function(){t.invokeAll("enable")},t.refreshAll=function(){t.Context.refreshAll()},t.viewportHeight=function(){return window.innerHeight||document.documentElement.clientHeight},t.viewportWidth=function(){return document.documentElement.clientWidth},t.adapters=[],t.defaults={context:window,continuous:!0,enabled:!0,group:"default",horizontal:!1,offset:0},t.offsetAliases={"bottom-in-view":function(){return this.context.innerHeight()-this.adapter.outerHeight()},"right-in-view":function(){return this.context.innerWidth()-this.adapter.outerWidth()}},window.Waypoint=t}(),function(){"use strict";function t(t){window.setTimeout(t,1e3/60)}function e(t){this.element=t,this.Adapter=n.Adapter,this.adapter=new this.Adapter(t),this.key="waypoint-context-"+i,this.didScroll=!1,this.didResize=!1,this.oldScroll={x:this.adapter.scrollLeft(),y:this.adapter.scrollTop()},this.waypoints={vertical:{},horizontal:{}},t.waypointContextKey=this.key,o[t.waypointContextKey]=this,i+=1,this.createThrottledScrollHandler(),this.createThrottledResizeHandler()}var i=0,o={},n=window.Waypoint,r=window.onload;e.prototype.add=function(t){var e=t.options.horizontal?"horizontal":"vertical";this.waypoints[e][t.key]=t,this.refresh()},e.prototype.checkEmpty=function(){var t=this.Adapter.isEmptyObject(this.waypoints.horizontal),e=this.Adapter.isEmptyObject(this.waypoints.vertical);t&&e&&(this.adapter.off(".waypoints"),delete o[this.key])},e.prototype.createThrottledResizeHandler=function(){function t(){e.handleResize(),e.didResize=!1}var e=this;this.adapter.on("resize.waypoints",function(){e.didResize||(e.didResize=!0,n.requestAnimationFrame(t))})},e.prototype.createThrottledScrollHandler=function(){function t(){e.handleScroll(),e.didScroll=!1}var e=this;this.adapter.on("scroll.waypoints",function(){(!e.didScroll||n.isTouch)&&(e.didScroll=!0,n.requestAnimationFrame(t))})},e.prototype.handleResize=function(){n.Context.refreshAll()},e.prototype.handleScroll=function(){var t={},e={horizontal:{newScroll:this.adapter.scrollLeft(),oldScroll:this.oldScroll.x,forward:"right",backward:"left"},vertical:{newScroll:this.adapter.scrollTop(),oldScroll:this.oldScroll.y,forward:"down",backward:"up"}};for(var i in e){var o=e[i],n=o.newScroll>o.oldScroll,r=n?o.forward:o.backward;for(var s in this.waypoints[i]){var a=this.waypoints[i][s],l=o.oldScroll=a.triggerPoint,p=l&&h,c=!l&&!h;(p||c)&&(a.queueTrigger(r),t[a.group.id]=a.group)}}for(var u in t)t[u].flushTriggers();this.oldScroll={x:e.horizontal.newScroll,y:e.vertical.newScroll}},e.prototype.innerHeight=function(){return this.element==this.element.window?n.viewportHeight():this.adapter.innerHeight()},e.prototype.remove=function(t){delete this.waypoints[t.axis][t.key],this.checkEmpty()},e.prototype.innerWidth=function(){return this.element==this.element.window?n.viewportWidth():this.adapter.innerWidth()},e.prototype.destroy=function(){var t=[];for(var e in this.waypoints)for(var i in this.waypoints[e])t.push(this.waypoints[e][i]);for(var o=0,n=t.length;n>o;o++)t[o].destroy()},e.prototype.refresh=function(){var t,e=this.element==this.element.window,i=e?void 0:this.adapter.offset(),o={};this.handleScroll(),t={horizontal:{contextOffset:e?0:i.left,contextScroll:e?0:this.oldScroll.x,contextDimension:this.innerWidth(),oldScroll:this.oldScroll.x,forward:"right",backward:"left",offsetProp:"left"},vertical:{contextOffset:e?0:i.top,contextScroll:e?0:this.oldScroll.y,contextDimension:this.innerHeight(),oldScroll:this.oldScroll.y,forward:"down",backward:"up",offsetProp:"top"}};for(var r in t){var s=t[r];for(var a in this.waypoints[r]){var l,h,p,c,u,d=this.waypoints[r][a],f=d.options.offset,w=d.triggerPoint,y=0,g=null==w;d.element!==d.element.window&&(y=d.adapter.offset()[s.offsetProp]),"function"==typeof f?f=f.apply(d):"string"==typeof f&&(f=parseFloat(f),d.options.offset.indexOf("%")>-1&&(f=Math.ceil(s.contextDimension*f/100))),l=s.contextScroll-s.contextOffset,d.triggerPoint=y+l-f,h=w=s.oldScroll,c=h&&p,u=!h&&!p,!g&&c?(d.queueTrigger(s.backward),o[d.group.id]=d.group):!g&&u?(d.queueTrigger(s.forward),o[d.group.id]=d.group):g&&s.oldScroll>=d.triggerPoint&&(d.queueTrigger(s.forward),o[d.group.id]=d.group)}}return n.requestAnimationFrame(function(){for(var t in o)o[t].flushTriggers()}),this},e.findOrCreateByElement=function(t){return e.findByElement(t)||new e(t)},e.refreshAll=function(){for(var t in o)o[t].refresh()},e.findByElement=function(t){return o[t.waypointContextKey]},window.onload=function(){r&&r(),e.refreshAll()},n.requestAnimationFrame=function(e){var i=window.requestAnimationFrame||window.mozRequestAnimationFrame||window.webkitRequestAnimationFrame||t;i.call(window,e)},n.Context=e}(),function(){"use strict";function t(t,e){return t.triggerPoint-e.triggerPoint}function e(t,e){return e.triggerPoint-t.triggerPoint}function i(t){this.name=t.name,this.axis=t.axis,this.id=this.name+"-"+this.axis,this.waypoints=[],this.clearTriggerQueues(),o[this.axis][this.name]=this}var o={vertical:{},horizontal:{}},n=window.Waypoint;i.prototype.add=function(t){this.waypoints.push(t)},i.prototype.clearTriggerQueues=function(){this.triggerQueues={up:[],down:[],left:[],right:[]}},i.prototype.flushTriggers=function(){for(var i in this.triggerQueues){var o=this.triggerQueues[i],n="up"===i||"left"===i;o.sort(n?e:t);for(var r=0,s=o.length;s>r;r+=1){var a=o[r];(a.options.continuous||r===o.length-1)&&a.trigger([i])}}this.clearTriggerQueues()},i.prototype.next=function(e){this.waypoints.sort(t);var i=n.Adapter.inArray(e,this.waypoints),o=i===this.waypoints.length-1;return o?null:this.waypoints[i+1]},i.prototype.previous=function(e){this.waypoints.sort(t);var i=n.Adapter.inArray(e,this.waypoints);return i?this.waypoints[i-1]:null},i.prototype.queueTrigger=function(t,e){this.triggerQueues[e].push(t)},i.prototype.remove=function(t){var e=n.Adapter.inArray(t,this.waypoints);e>-1&&this.waypoints.splice(e,1)},i.prototype.first=function(){return this.waypoints[0]},i.prototype.last=function(){return this.waypoints[this.waypoints.length-1]},i.findOrCreate=function(t){return o[t.axis][t.name]||new i(t)},n.Group=i}(),function(){"use strict";function t(t){this.element=t,this.$element=e(t)}var e=window.Zepto,i=window.Waypoint;e.each(["off","on","scrollLeft","scrollTop"],function(e,i){t.prototype[i]=function(){var t=Array.prototype.slice.call(arguments);return this.$element[i].apply(this.$element,t)}}),t.prototype.offset=function(){return this.element!==this.element.window?this.$element.offset():void 0},e.each(["width","height"],function(i,o){function n(t,i){return function(t){var n=this.$element,r=n[o](),s={width:["left","right"],height:["top","bottom"]};return e.each(s[o],function(e,o){r+=parseInt(n.css("padding-"+o),10),i&&(r+=parseInt(n.css("border-"+o+"-width"),10)),t&&(r+=parseInt(n.css("margin-"+o),10))}),r}}var r=e.camelCase("inner-"+o),s=e.camelCase("outer-"+o);t.prototype[r]=n(!1),t.prototype[s]=n(!0)}),e.each(["extend","inArray"],function(i,o){t[o]=e[o]}),t.isEmptyObject=function(t){for(var e in t)return!1;return!0},i.adapters.push({name:"zepto",Adapter:t}),i.Adapter=t}(),function(){"use strict";function t(t){return function(){var i=[],o=arguments[0];return t.isFunction(arguments[0])&&(o=t.extend({},arguments[1]),o.handler=arguments[0]),this.each(function(){var n=t.extend({},o,{element:this});"string"==typeof n.context&&(n.context=t(this).closest(n.context)[0]),i.push(new e(n))}),i}}var e=window.Waypoint;window.jQuery&&(window.jQuery.fn.waypoint=t(window.jQuery)),window.Zepto&&(window.Zepto.fn.waypoint=t(window.Zepto))}(); \ No newline at end of file +!function(){"use strict";function t(o){if(!o)throw new Error("No options passed to Waypoint constructor");if(!o.element)throw new Error("No element option passed to Waypoint constructor");if(!o.handler)throw new Error("No handler option passed to Waypoint constructor");this.key="waypoint-"+e,this.options=t.Adapter.extend({},t.defaults,o),this.element=this.options.element,this.adapter=new t.Adapter(this.element),this.callback=o.handler,this.axis=this.options.horizontal?"horizontal":"vertical",this.enabled=this.options.enabled,this.triggerPoint=null,this.group=t.Group.findOrCreate({name:this.options.group,axis:this.axis}),this.context=t.Context.findOrCreateByElement(this.options.context),t.offsetAliases[this.options.offset]&&(this.options.offset=t.offsetAliases[this.options.offset]),this.group.add(this),this.context.add(this),i[this.key]=this,e+=1}var e=0,i={};t.prototype.queueTrigger=function(t){this.group.queueTrigger(this,t)},t.prototype.trigger=function(t){this.enabled&&this.callback&&this.callback.apply(this,t)},t.prototype.destroy=function(){this.context.remove(this),this.group.remove(this),delete i[this.key]},t.prototype.disable=function(){return this.enabled=!1,this},t.prototype.enable=function(){return this.context.refresh(),this.enabled=!0,this},t.prototype.next=function(){return this.group.next(this)},t.prototype.previous=function(){return this.group.previous(this)},t.invokeAll=function(t){var e=[];for(var o in i)e.push(i[o]);for(var n=0,r=e.length;r>n;n++)e[n][t]()},t.destroyAll=function(){t.invokeAll("destroy")},t.disableAll=function(){t.invokeAll("disable")},t.enableAll=function(){t.Context.refreshAll();for(var e in i)i[e].enabled=!0;return this},t.refreshAll=function(){t.Context.refreshAll()},t.viewportHeight=function(){return window.innerHeight||document.documentElement.clientHeight},t.viewportWidth=function(){return document.documentElement.clientWidth},t.adapters=[],t.defaults={context:window,continuous:!0,enabled:!0,group:"default",horizontal:!1,offset:0},t.offsetAliases={"bottom-in-view":function(){return this.context.innerHeight()-this.adapter.outerHeight()},"right-in-view":function(){return this.context.innerWidth()-this.adapter.outerWidth()}},window.Waypoint=t}(),function(){"use strict";function t(t){window.setTimeout(t,1e3/60)}function e(t){this.element=t,this.Adapter=n.Adapter,this.adapter=new this.Adapter(t),this.key="waypoint-context-"+i,this.didScroll=!1,this.didResize=!1,this.oldScroll={x:this.adapter.scrollLeft(),y:this.adapter.scrollTop()},this.waypoints={vertical:{},horizontal:{}},t.waypointContextKey=this.key,o[t.waypointContextKey]=this,i+=1,n.windowContext||(n.windowContext=!0,n.windowContext=new e(window)),this.createThrottledScrollHandler(),this.createThrottledResizeHandler()}var i=0,o={},n=window.Waypoint,r=window.onload;e.prototype.add=function(t){var e=t.options.horizontal?"horizontal":"vertical";this.waypoints[e][t.key]=t,this.refresh()},e.prototype.checkEmpty=function(){var t=this.Adapter.isEmptyObject(this.waypoints.horizontal),e=this.Adapter.isEmptyObject(this.waypoints.vertical),i=this.element==this.element.window;t&&e&&!i&&(this.adapter.off(".waypoints"),delete o[this.key])},e.prototype.createThrottledResizeHandler=function(){function t(){e.handleResize(),e.didResize=!1}var e=this;this.adapter.on("resize.waypoints",function(){e.didResize||(e.didResize=!0,n.requestAnimationFrame(t))})},e.prototype.createThrottledScrollHandler=function(){function t(){e.handleScroll(),e.didScroll=!1}var e=this;this.adapter.on("scroll.waypoints",function(){(!e.didScroll||n.isTouch)&&(e.didScroll=!0,n.requestAnimationFrame(t))})},e.prototype.handleResize=function(){n.Context.refreshAll()},e.prototype.handleScroll=function(){var t={},e={horizontal:{newScroll:this.adapter.scrollLeft(),oldScroll:this.oldScroll.x,forward:"right",backward:"left"},vertical:{newScroll:this.adapter.scrollTop(),oldScroll:this.oldScroll.y,forward:"down",backward:"up"}};for(var i in e){var o=e[i],n=o.newScroll>o.oldScroll,r=n?o.forward:o.backward;for(var s in this.waypoints[i]){var a=this.waypoints[i][s];if(null!==a.triggerPoint){var l=o.oldScroll=a.triggerPoint,p=l&&h,u=!l&&!h;(p||u)&&(a.queueTrigger(r),t[a.group.id]=a.group)}}}for(var c in t)t[c].flushTriggers();this.oldScroll={x:e.horizontal.newScroll,y:e.vertical.newScroll}},e.prototype.innerHeight=function(){return this.element==this.element.window?n.viewportHeight():this.adapter.innerHeight()},e.prototype.remove=function(t){delete this.waypoints[t.axis][t.key],this.checkEmpty()},e.prototype.innerWidth=function(){return this.element==this.element.window?n.viewportWidth():this.adapter.innerWidth()},e.prototype.destroy=function(){var t=[];for(var e in this.waypoints)for(var i in this.waypoints[e])t.push(this.waypoints[e][i]);for(var o=0,n=t.length;n>o;o++)t[o].destroy()},e.prototype.refresh=function(){var t,e=this.element==this.element.window,i=e?void 0:this.adapter.offset(),o={};this.handleScroll(),t={horizontal:{contextOffset:e?0:i.left,contextScroll:e?0:this.oldScroll.x,contextDimension:this.innerWidth(),oldScroll:this.oldScroll.x,forward:"right",backward:"left",offsetProp:"left"},vertical:{contextOffset:e?0:i.top,contextScroll:e?0:this.oldScroll.y,contextDimension:this.innerHeight(),oldScroll:this.oldScroll.y,forward:"down",backward:"up",offsetProp:"top"}};for(var r in t){var s=t[r];for(var a in this.waypoints[r]){var l,h,p,u,c,d=this.waypoints[r][a],f=d.options.offset,w=d.triggerPoint,y=0,g=null==w;d.element!==d.element.window&&(y=d.adapter.offset()[s.offsetProp]),"function"==typeof f?f=f.apply(d):"string"==typeof f&&(f=parseFloat(f),d.options.offset.indexOf("%")>-1&&(f=Math.ceil(s.contextDimension*f/100))),l=s.contextScroll-s.contextOffset,d.triggerPoint=Math.floor(y+l-f),h=w=s.oldScroll,u=h&&p,c=!h&&!p,!g&&u?(d.queueTrigger(s.backward),o[d.group.id]=d.group):!g&&c?(d.queueTrigger(s.forward),o[d.group.id]=d.group):g&&s.oldScroll>=d.triggerPoint&&(d.queueTrigger(s.forward),o[d.group.id]=d.group)}}return n.requestAnimationFrame(function(){for(var t in o)o[t].flushTriggers()}),this},e.findOrCreateByElement=function(t){return e.findByElement(t)||new e(t)},e.refreshAll=function(){for(var t in o)o[t].refresh()},e.findByElement=function(t){return o[t.waypointContextKey]},window.onload=function(){r&&r(),e.refreshAll()},n.requestAnimationFrame=function(e){var i=window.requestAnimationFrame||window.mozRequestAnimationFrame||window.webkitRequestAnimationFrame||t;i.call(window,e)},n.Context=e}(),function(){"use strict";function t(t,e){return t.triggerPoint-e.triggerPoint}function e(t,e){return e.triggerPoint-t.triggerPoint}function i(t){this.name=t.name,this.axis=t.axis,this.id=this.name+"-"+this.axis,this.waypoints=[],this.clearTriggerQueues(),o[this.axis][this.name]=this}var o={vertical:{},horizontal:{}},n=window.Waypoint;i.prototype.add=function(t){this.waypoints.push(t)},i.prototype.clearTriggerQueues=function(){this.triggerQueues={up:[],down:[],left:[],right:[]}},i.prototype.flushTriggers=function(){for(var i in this.triggerQueues){var o=this.triggerQueues[i],n="up"===i||"left"===i;o.sort(n?e:t);for(var r=0,s=o.length;s>r;r+=1){var a=o[r];(a.options.continuous||r===o.length-1)&&a.trigger([i])}}this.clearTriggerQueues()},i.prototype.next=function(e){this.waypoints.sort(t);var i=n.Adapter.inArray(e,this.waypoints),o=i===this.waypoints.length-1;return o?null:this.waypoints[i+1]},i.prototype.previous=function(e){this.waypoints.sort(t);var i=n.Adapter.inArray(e,this.waypoints);return i?this.waypoints[i-1]:null},i.prototype.queueTrigger=function(t,e){this.triggerQueues[e].push(t)},i.prototype.remove=function(t){var e=n.Adapter.inArray(t,this.waypoints);e>-1&&this.waypoints.splice(e,1)},i.prototype.first=function(){return this.waypoints[0]},i.prototype.last=function(){return this.waypoints[this.waypoints.length-1]},i.findOrCreate=function(t){return o[t.axis][t.name]||new i(t)},n.Group=i}(),function(){"use strict";function t(t){this.element=t,this.$element=e(t)}var e=window.Zepto,i=window.Waypoint;e.each(["off","on","scrollLeft","scrollTop"],function(e,i){t.prototype[i]=function(){var t=Array.prototype.slice.call(arguments);return this.$element[i].apply(this.$element,t)}}),t.prototype.offset=function(){return this.element!==this.element.window?this.$element.offset():void 0},e.each(["width","height"],function(i,o){function n(t,i){return function(t){var n=this.$element,r=n[o](),s={width:["left","right"],height:["top","bottom"]};return e.each(s[o],function(e,o){r+=parseInt(n.css("padding-"+o),10),i&&(r+=parseInt(n.css("border-"+o+"-width"),10)),t&&(r+=parseInt(n.css("margin-"+o),10))}),r}}var r=e.camelCase("inner-"+o),s=e.camelCase("outer-"+o);t.prototype[r]=n(!1),t.prototype[s]=n(!0)}),e.each(["extend","inArray"],function(i,o){t[o]=e[o]}),t.isEmptyObject=function(t){for(var e in t)return!1;return!0},i.adapters.push({name:"zepto",Adapter:t}),i.Adapter=t}(),function(){"use strict";function t(t){return function(){var i=[],o=arguments[0];return t.isFunction(arguments[0])&&(o=t.extend({},arguments[1]),o.handler=arguments[0]),this.each(function(){var n=t.extend({},o,{element:this});"string"==typeof n.context&&(n.context=t(this).closest(n.context)[0]),i.push(new e(n))}),i}}var e=window.Waypoint;window.jQuery&&(window.jQuery.fn.waypoint=t(window.jQuery)),window.Zepto&&(window.Zepto.fn.waypoint=t(window.Zepto))}(); \ No newline at end of file diff --git a/package.json b/package.json index ab958cce..c5e9bb13 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "waypoints", - "version": "4.0.0", + "version": "4.0.1", "author": "Caleb Troughton (http://imakewebthings.com)", "description": "Easily execute a function when you scroll to an element", "scripts": {