diff --git a/.travis.yml b/.travis.yml index f4910ba..626ede8 100644 --- a/.travis.yml +++ b/.travis.yml @@ -3,5 +3,6 @@ sudo: false node_js: - "0.10" before_script: - - npm install -g bower + - npm install -g bower gulp-cli - bower install + - gulp build diff --git a/gulpfile.js b/gulpfile.js index 2eb60bc..ccf8459 100644 --- a/gulpfile.js +++ b/gulpfile.js @@ -1,3 +1,6 @@ +var browserify = require('browserify') +var source = require('vinyl-source-stream') +var buffer = require('vinyl-buffer') var gulp = require('gulp') var eslint = require('gulp-eslint') var concat = require('gulp-concat') @@ -33,18 +36,15 @@ gulp.task('lint', function() { }) gulp.task('build-core', function() { - var streams = ['noframework', 'jquery', 'zepto'].map(function(adapter) { - 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', { newLine: ';' })) + var streams = ['noframework', 'jquery', 'zepto', 'test'].map(function(adapter) { + var b = browserify({ + entries: './src/entries/' + adapter + '.js', + debug: false + }); + + return b.bundle() + .pipe(source(adapter + '.waypoints.js')) + .pipe(buffer()) .pipe(header(fileHeader('Waypoints'))) .pipe(footer(';')) .pipe(gulp.dest('lib/')) diff --git a/lib/jquery.waypoints.js b/lib/jquery.waypoints.js index 90372dd..9f5fb63 100644 --- a/lib/jquery.waypoints.js +++ b/lib/jquery.waypoints.js @@ -1,180 +1,92 @@ /*! Waypoints - 4.0.0 -Copyright © 2011-2015 Caleb Troughton +Copyright © 2011-2016 Caleb Troughton Licensed under the MIT license. https://github.com/imakewebthings/waypoints/blob/master/licenses.txt */ -(function() { +(function e(t,n,r){function s(o,u){if(!n[o]){if(!t[o]){var a=typeof require=="function"&&require;if(!u&&a)return a(o,!0);if(i)return i(o,!0);var f=new Error("Cannot find module '"+o+"'");throw f.code="MODULE_NOT_FOUND",f}var l=n[o]={exports:{}};t[o][0].call(l.exports,function(e){var n=t[o][1][e];return s(n?n:e)},l,l.exports,e,t,n,r)}return n[o].exports}var i=typeof require=="function"&&require;for(var o=0;o -1 + var wrapperHeight = shouldBeStuck ? this.$element.outerHeight(true) : '' + + this.$wrapper.height(wrapperHeight) + this.$element.toggleClass(this.options.stuckClass, shouldBeStuck) + + if (originalHandler) { + originalHandler.call(this, direction) + } + }, this) + })) + } + + /* Private */ + Sticky.prototype.createWrapper = function() { + if (this.options.wrapper) { + this.$element.wrap(this.options.wrapper) + } + this.$wrapper = this.$element.parent() + this.wrapper = this.$wrapper[0] + } + + /* Public */ + Sticky.prototype.destroy = function() { + if (this.$element.parent()[0] === this.wrapper) { + this.waypoint.destroy() + this.$element.removeClass(this.options.stuckClass) + if (this.options.wrapper) { + this.$element.unwrap() + } } } - if (window.jQuery) { - window.jQuery.fn.waypoint = createExtension(window.jQuery) + Sticky.defaults = { + wrapper: '
', + stuckClass: 'stuck', + direction: 'down right' + } + + return typeof module !== 'undefined' ? module.exports = Sticky : undefined +}(typeof global !== 'undefined' ? global : window)) + +}).call(this,typeof global !== "undefined" ? global : typeof self !== "undefined" ? self : typeof window !== "undefined" ? window : {}) +},{"../waypoint":9}],9:[function(require,module,exports){ +(function (global){ + 'use strict' + + 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') + } + 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) + 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.group.add(this) + this.context.add(this) + allWaypoints[this.key] = this + keyCounter += 1 } - if (window.Zepto) { - window.Zepto.fn.waypoint = createExtension(window.Zepto) + + /* Private */ + Waypoint.prototype.queueTrigger = function(direction) { + this.group.queueTrigger(this, direction) } -}()) + + /* Private */ + Waypoint.prototype.trigger = function(args) { + if (!this.enabled) { + return + } + if (this.callback) { + this.callback.apply(this, args) + } + } + + /* Public */ + /* http://imakewebthings.com/waypoints/api/destroy */ + Waypoint.prototype.destroy = function() { + this.context.remove(this) + this.group.remove(this) + delete allWaypoints[this.key] + } + + /* 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 + return this + } + + /* 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) + } + + /* 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][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() { + Waypoint.Context.refreshAll() + } + + /* Public */ + /* http://imakewebthings.com/waypoints/api/viewport-height */ + Waypoint.viewportHeight = function() { + return global.innerHeight || document.documentElement.clientHeight + } + + /* Public */ + /* http://imakewebthings.com/waypoints/api/viewport-width */ + Waypoint.viewportWidth = function() { + return document.documentElement.clientWidth + } + + Waypoint.adapters = [] + + Waypoint.defaults = { + context: global, + continuous: true, + enabled: true, + group: 'default', + horizontal: false, + offset: 0 + } + + Waypoint.offsetAliases = { + 'bottom-in-view': function() { + return this.context.innerHeight() - this.adapter.outerHeight() + }, + 'right-in-view': function() { + return this.context.innerWidth() - this.adapter.outerWidth() + } + } + + module.exports = Waypoint + +}).call(this,typeof global !== "undefined" ? global : typeof self !== "undefined" ? self : typeof window !== "undefined" ? window : {}) +},{}]},{},[4]); ; \ No newline at end of file diff --git a/lib/jquery.waypoints.min.js b/lib/jquery.waypoints.min.js index 20e6f62..0628c11 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 +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 t(e,i,o){function n(s,a){if(!i[s]){if(!e[s]){var p="function"==typeof require&&require;if(!a&&p)return p(s,!0);if(r)return r(s,!0);var l=new Error("Cannot find module '"+s+"'");throw l.code="MODULE_NOT_FOUND",l}var h=i[s]={exports:{}};e[s][0].call(h.exports,function(t){var i=e[s][1][t];return n(i?i:t)},h,h.exports,t,e,i,o)}return i[s].exports}for(var r="function"==typeof require&&require,s=0;so.oldScroll,r=n?o.forward:o.backward;for(var s in this.waypoints[i]){var a=this.waypoints[i][s],p=o.oldScroll=a.triggerPoint,h=p&&l,f=!p&&!l;(h||f)&&(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}},n.prototype.innerHeight=function(){return this.element==this.element.window?r.viewportHeight():this.adapter.innerHeight()},n.prototype.remove=function(t){delete this.waypoints[t.axis][t.key],this.checkEmpty()},n.prototype.innerWidth=function(){return this.element==this.element.window?r.viewportWidth():this.adapter.innerWidth()},n.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()},n.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 n in t){var s=t[n];for(var a in this.waypoints[n]){var p,l,h,f,u,d=this.waypoints[n][a],c=d.options.offset,y=d.triggerPoint,w=0,g=null==y;d.element!==d.element.window&&(w=d.adapter.offset()[s.offsetProp]),"function"==typeof c?c=c.apply(d):"string"==typeof c&&(c=parseFloat(c),d.options.offset.indexOf("%")>-1&&(c=Math.ceil(s.contextDimension*c/100))),p=s.contextScroll-s.contextOffset,d.triggerPoint=w+p-c,l=y=s.oldScroll,f=l&&h,u=!l&&!h,!g&&f?(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 r.requestAnimationFrame(function(){for(var t in o)o[t].flushTriggers()}),this},n.findOrCreateByElement=function(t){return n.findByElement(t)||new n(t)},n.refreshAll=function(){for(var t in a)a[t].refresh()},n.findByElement=function(t){return a[t.waypointContextKey]},i.onload=function(){p&&p(),n.refreshAll()},r.requestAnimationFrame=function(t){var e=i.requestAnimationFrame||i.mozRequestAnimationFrame||i.webkitRequestAnimationFrame||o;e.call(window,t)},e.exports=n}).call(this,"undefined"!=typeof global?global:"undefined"!=typeof self?self:"undefined"!=typeof window?window:{})},{"./waypoint":9}],4:[function(t,e){(function(i){"use strict";var o=t("../waypoint"),n=t("../context"),r=t("../group"),s=t("../adapters/jquery"),a=t("../shortcuts/inview"),p=t("../shortcuts/infinite"),l=t("../shortcuts/sticky"),h=t("../adapters/jquery-zepto-fn-extension");i.Waypoint=o,o.Context=n,o.Group=r,o.adapters.push(s),o.Adapter=s.Adapter,i.jQuery&&(i.jQuery.fn.waypoint=h(i.jQuery)),o.Inview=a,o.Infinite=p,o.Sticky=l,e.exports=o}).call(this,"undefined"!=typeof global?global:"undefined"!=typeof self?self:"undefined"!=typeof window?window:{})},{"../adapters/jquery":2,"../adapters/jquery-zepto-fn-extension":1,"../context":3,"../group":5,"../shortcuts/infinite":6,"../shortcuts/inview":7,"../shortcuts/sticky":8,"../waypoint":9}],5:[function(t,e){"use strict";function i(t,e){return t.triggerPoint-e.triggerPoint}function o(t,e){return e.triggerPoint-t.triggerPoint}function n(t){this.name=t.name,this.axis=t.axis,this.id=this.name+"-"+this.axis,this.waypoints=[],this.clearTriggerQueues(),s[this.axis][this.name]=this}var r=t("./waypoint"),s={vertical:{},horizontal:{}};n.prototype.add=function(t){this.waypoints.push(t)},n.prototype.clearTriggerQueues=function(){this.triggerQueues={up:[],down:[],left:[],right:[]}},n.prototype.flushTriggers=function(){for(var t in this.triggerQueues){var e=this.triggerQueues[t],n="up"===t||"left"===t;e.sort(n?o:i);for(var r=0,s=e.length;s>r;r+=1){var a=e[r];(a.options.continuous||r===e.length-1)&&a.trigger([t])}}this.clearTriggerQueues()},n.prototype.next=function(t){this.waypoints.sort(i);var e=r.Adapter.inArray(t,this.waypoints),o=e===this.waypoints.length-1;return o?null:this.waypoints[e+1]},n.prototype.previous=function(t){this.waypoints.sort(i);var e=r.Adapter.inArray(t,this.waypoints);return e?this.waypoints[e-1]:null},n.prototype.queueTrigger=function(t,e){this.triggerQueues[e].push(t)},n.prototype.remove=function(t){var e=r.Adapter.inArray(t,this.waypoints);e>-1&&this.waypoints.splice(e,1)},n.prototype.first=function(){return this.waypoints[0]},n.prototype.last=function(){return this.waypoints[this.waypoints.length-1]},n.findOrCreate=function(t){return s[t.axis][t.name]||new n(t)},e.exports=n},{"./waypoint":9}],6:[function(t,e){(function(i){!function(i){"use strict";function o(t){this.options=r.extend({},o.defaults,t),this.container=this.options.element,"auto"!==this.options.container&&(this.container=this.options.container),this.$container=r(this.container),this.$more=r(this.options.more),this.$more.length&&(this.setupHandler(),this.waypoint=new n(this.options))}var n;n="function"==typeof t?t("../waypoint"):i.Waypoint;var r=i.jQuery;return o.prototype.setupHandler=function(){this.options.handler=r.proxy(function(){this.options.onBeforePageLoad(),this.destroy(),this.$container.addClass(this.options.loadingClass),r.get(r(this.options.more).attr("href"),r.proxy(function(t){var e=r(r.parseHTML(t)),i=e.find(this.options.more),o=e.find(this.options.items);o.length||(o=e.filter(this.options.items)),this.$container.append(o),this.$container.removeClass(this.options.loadingClass),i.length||(i=e.filter(this.options.more)),i.length?(this.$more.replaceWith(i),this.$more=i,this.waypoint=new n(this.options)):this.$more.remove(),this.options.onAfterPageLoad(o)},this))},this)},o.prototype.destroy=function(){this.waypoint&&this.waypoint.destroy()},o.defaults={container:"auto",items:".infinite-item",more:".infinite-more-link",offset:"bottom-in-view",loadingClass:"infinite-loading",onBeforePageLoad:r.noop,onAfterPageLoad:r.noop},"undefined"!=typeof e?e.exports=o:void 0}("undefined"!=typeof i?i:window)}).call(this,"undefined"!=typeof global?global:"undefined"!=typeof self?self:"undefined"!=typeof window?window:{})},{"../waypoint":9}],7:[function(t,e){(function(i){!function(i){"use strict";function o(){}function n(t){this.options=r.Adapter.extend({},n.defaults,t),this.axis=this.options.horizontal?"horizontal":"vertical",this.waypoints=[],this.element=this.options.element,this.createWaypoints()}var r;return"function"==typeof t?r=t("../waypoint"):(i=window,r=i.Waypoint),n.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)}},n.prototype.createWaypoint=function(t){var e=this;this.waypoints.push(new r({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}))},n.prototype.destroy=function(){for(var t=0,e=this.waypoints.length;e>t;t++)this.waypoints[t].destroy();this.waypoints=[]},n.prototype.disable=function(){for(var t=0,e=this.waypoints.length;e>t;t++)this.waypoints[t].disable()},n.prototype.enable=function(){for(var t=0,e=this.waypoints.length;e>t;t++)this.waypoints[t].enable()},n.defaults={context:i,enabled:!0,enter:o,entered:o,exit:o,exited:o},"undefined"!=typeof e?e.exports=n:void 0}("undefined"!=typeof i?i:window)}).call(this,"undefined"!=typeof global?global:"undefined"!=typeof self?self:"undefined"!=typeof window?window:{})},{"../waypoint":9}],8:[function(t,e){(function(i){!function(i){"use strict";function o(t){this.options=r.extend({},n.defaults,o.defaults,t),this.element=this.options.element,this.$element=r(this.element),this.createWrapper(),this.createWaypoint()}var n;n="function"==typeof t?t("../waypoint"):i.Waypoint;var r=i.jQuery;return o.prototype.createWaypoint=function(){var t=this.options.handler;this.waypoint=new n(r.extend({},this.options,{element:this.wrapper,handler:r.proxy(function(e){var i=this.options.direction.indexOf(e)>-1,o=i?this.$element.outerHeight(!0):"";this.$wrapper.height(o),this.$element.toggleClass(this.options.stuckClass,i),t&&t.call(this,e)},this)}))},o.prototype.createWrapper=function(){this.options.wrapper&&this.$element.wrap(this.options.wrapper),this.$wrapper=this.$element.parent(),this.wrapper=this.$wrapper[0]},o.prototype.destroy=function(){this.$element.parent()[0]===this.wrapper&&(this.waypoint.destroy(),this.$element.removeClass(this.options.stuckClass),this.options.wrapper&&this.$element.unwrap())},o.defaults={wrapper:'
',stuckClass:"stuck",direction:"down right"},"undefined"!=typeof e?e.exports=o:void 0}("undefined"!=typeof i?i:window)}).call(this,"undefined"!=typeof global?global:"undefined"!=typeof self?self:"undefined"!=typeof window?window:{})},{"../waypoint":9}],9:[function(t,e){(function(t){"use strict";function i(t){if(!t)throw new Error("No options passed to Waypoint constructor");if(!t.element)throw new Error("No element option passed to Waypoint constructor");if(!t.handler)throw new Error("No handler option passed to Waypoint constructor");this.key="waypoint-"+o,this.options=i.Adapter.extend({},i.defaults,t),this.element=this.options.element,this.adapter=new i.Adapter(this.element),this.callback=t.handler,this.axis=this.options.horizontal?"horizontal":"vertical",this.enabled=this.options.enabled,this.triggerPoint=null,this.group=i.Group.findOrCreate({name:this.options.group,axis:this.axis}),this.context=i.Context.findOrCreateByElement(this.options.context),i.offsetAliases[this.options.offset]&&(this.options.offset=i.offsetAliases[this.options.offset]),this.group.add(this),this.context.add(this),n[this.key]=this,o+=1}var o=0,n={};i.prototype.queueTrigger=function(t){this.group.queueTrigger(this,t)},i.prototype.trigger=function(t){this.enabled&&this.callback&&this.callback.apply(this,t)},i.prototype.destroy=function(){this.context.remove(this),this.group.remove(this),delete n[this.key]},i.prototype.disable=function(){return this.enabled=!1,this},i.prototype.enable=function(){return this.context.refresh(),this.enabled=!0,this},i.prototype.next=function(){return this.group.next(this)},i.prototype.previous=function(){return this.group.previous(this)},i.invokeAll=function(t){var e=[];for(var i in n)e.push(n[i]);for(var o=0,r=e.length;r>o;o++)e[o][t]()},i.destroyAll=function(){i.invokeAll("destroy")},i.disableAll=function(){i.invokeAll("disable")},i.enableAll=function(){i.invokeAll("enable")},i.refreshAll=function(){i.Context.refreshAll()},i.viewportHeight=function(){return t.innerHeight||document.documentElement.clientHeight},i.viewportWidth=function(){return document.documentElement.clientWidth},i.adapters=[],i.defaults={context:t,continuous:!0,enabled:!0,group:"default",horizontal:!1,offset:0},i.offsetAliases={"bottom-in-view":function(){return this.context.innerHeight()-this.adapter.outerHeight()},"right-in-view":function(){return this.context.innerWidth()-this.adapter.outerWidth()}},e.exports=i}).call(this,"undefined"!=typeof global?global:"undefined"!=typeof self?self:"undefined"!=typeof window?window:{})},{}]},{},[4]); \ No newline at end of file diff --git a/lib/noframework.waypoints.js b/lib/noframework.waypoints.js index 2de1c3c..58c6e80 100644 --- a/lib/noframework.waypoints.js +++ b/lib/noframework.waypoints.js @@ -1,180 +1,193 @@ /*! Waypoints - 4.0.0 -Copyright © 2011-2015 Caleb Troughton +Copyright © 2011-2016 Caleb Troughton Licensed under the MIT license. https://github.com/imakewebthings/waypoints/blob/master/licenses.txt */ -(function() { +(function e(t,n,r){function s(o,u){if(!n[o]){if(!t[o]){var a=typeof require=="function"&&require;if(!u&&a)return a(o,!0);if(i)return i(o,!0);var f=new Error("Cannot find module '"+o+"'");throw f.code="MODULE_NOT_FOUND",f}var l=n[o]={exports:{}};t[o][0].call(l.exports,function(e){var n=t[o][1][e];return s(n?n:e)},l,l.exports,e,t,n,r)}return n[o].exports}var i=typeof require=="function"&&require;for(var o=0;oo;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 t(e,n,i){function o(s,a){if(!n[s]){if(!e[s]){var l="function"==typeof require&&require;if(!a&&l)return l(s,!0);if(r)return r(s,!0);var h=new Error("Cannot find module '"+s+"'");throw h.code="MODULE_NOT_FOUND",h}var p=n[s]={exports:{}};e[s][0].call(p.exports,function(t){var n=e[s][1][t];return o(n?n:t)},p,p.exports,t,e,n,i)}return n[s].exports}for(var r="function"==typeof require&&require,s=0;si;i++){var r=e[i];n&&n!==r||t.removeEventListener(r)}}var i=t.split("."),o=i[0],r=i[1],s=this.element;if(r&&this.handlers[r]&&o)n(s,this.handlers[r][o],e),this.handlers[r][o]=[];else if(o)for(var a in this.handlers)n(s,this.handlers[a][o]||[],e),this.handlers[a][o]=[];else if(r&&this.handlers[r]){for(var l in this.handlers[r])n(s,this.handlers[r][l],e);this.handlers[r]={}}},o.prototype.offset=function(){if(!this.element.ownerDocument)return null;var t=this.element.ownerDocument.documentElement,e=i(this.element.ownerDocument),n={top:0,left:0};return this.element.getBoundingClientRect&&(n=this.element.getBoundingClientRect()),{top:n.top+e.pageYOffset-t.clientTop,left:n.left+e.pageXOffset-t.clientLeft}},o.prototype.on=function(t,e){var n=t.split("."),i=n[0],o=n[1]||"__default",r=this.handlers[o]=this.handlers[o]||{},s=r[i]=r[i]||[];s.push(e),this.element.addEventListener(i,e)},o.prototype.outerHeight=function(e){var i,o=this.innerHeight();return e&&!n(this.element)&&(i=t.getComputedStyle(this.element),o+=parseInt(i.marginTop,10),o+=parseInt(i.marginBottom,10)),o},o.prototype.outerWidth=function(e){var i,o=this.innerWidth();return e&&!n(this.element)&&(i=t.getComputedStyle(this.element),o+=parseInt(i.marginLeft,10),o+=parseInt(i.marginRight,10)),o},o.prototype.scrollLeft=function(){var t=i(this.element);return t?t.pageXOffset:this.element.scrollLeft},o.prototype.scrollTop=function(){var t=i(this.element);return t?t.pageYOffset:this.element.scrollTop},o.extend=function(){function t(t,e){if("object"==typeof t&&"object"==typeof e)for(var n in e)e.hasOwnProperty(n)&&(t[n]=e[n]);return t}for(var e=Array.prototype.slice.call(arguments),n=1,i=e.length;i>n;n++)t(e[0],e[n]);return e[0]},o.inArray=function(t,e,n){return null==e?-1:e.indexOf(t,n)},o.isEmptyObject=function(t){for(var e in t)return!1;return!0},e.exports={name:"noframework",Adapter:o}}).call(this,"undefined"!=typeof global?global:"undefined"!=typeof self?self:"undefined"!=typeof window?window:{})},{}],2:[function(t,e){(function(n){"use strict";function i(t){n.setTimeout(t,1e3/60)}function o(t){this.element=t,this.Adapter=r.Adapter,this.adapter=new this.Adapter(t),this.key="waypoint-context-"+s,this.didScroll=!1,this.didResize=!1,this.oldScroll={x:this.adapter.scrollLeft(),y:this.adapter.scrollTop()},this.waypoints={vertical:{},horizontal:{}},t.waypointContextKey=this.key,a[t.waypointContextKey]=this,s+=1,this.createThrottledScrollHandler(),this.createThrottledResizeHandler()}var r=t("./waypoint"),s=0,a={},l=n.onload;o.prototype.add=function(t){var e=t.options.horizontal?"horizontal":"vertical";this.waypoints[e][t.key]=t,this.refresh()},o.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 a[this.key])},o.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))})},o.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))})},o.prototype.handleResize=function(){r.Context.refreshAll()},o.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 n in e){var i=e[n],o=i.newScroll>i.oldScroll,r=o?i.forward:i.backward;for(var s in this.waypoints[n]){var a=this.waypoints[n][s],l=i.oldScroll=a.triggerPoint,p=l&&h,f=!l&&!h;(p||f)&&(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}},o.prototype.innerHeight=function(){return this.element==this.element.window?r.viewportHeight():this.adapter.innerHeight()},o.prototype.remove=function(t){delete this.waypoints[t.axis][t.key],this.checkEmpty()},o.prototype.innerWidth=function(){return this.element==this.element.window?r.viewportWidth():this.adapter.innerWidth()},o.prototype.destroy=function(){var t=[];for(var e in this.waypoints)for(var n in this.waypoints[e])t.push(this.waypoints[e][n]);for(var i=0,o=t.length;o>i;i++)t[i].destroy()},o.prototype.refresh=function(){var t,e=this.element==this.element.window,n=e?void 0:this.adapter.offset(),i={};this.handleScroll(),t={horizontal:{contextOffset:e?0:n.left,contextScroll:e?0:this.oldScroll.x,contextDimension:this.innerWidth(),oldScroll:this.oldScroll.x,forward:"right",backward:"left",offsetProp:"left"},vertical:{contextOffset:e?0:n.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 s=t[o];for(var a in this.waypoints[o]){var l,h,p,f,u,d=this.waypoints[o][a],c=d.options.offset,y=d.triggerPoint,w=0,g=null==y;d.element!==d.element.window&&(w=d.adapter.offset()[s.offsetProp]),"function"==typeof c?c=c.apply(d):"string"==typeof c&&(c=parseFloat(c),d.options.offset.indexOf("%")>-1&&(c=Math.ceil(s.contextDimension*c/100))),l=s.contextScroll-s.contextOffset,d.triggerPoint=w+l-c,h=y=s.oldScroll,f=h&&p,u=!h&&!p,!g&&f?(d.queueTrigger(s.backward),i[d.group.id]=d.group):!g&&u?(d.queueTrigger(s.forward),i[d.group.id]=d.group):g&&s.oldScroll>=d.triggerPoint&&(d.queueTrigger(s.forward),i[d.group.id]=d.group)}}return r.requestAnimationFrame(function(){for(var t in i)i[t].flushTriggers()}),this},o.findOrCreateByElement=function(t){return o.findByElement(t)||new o(t)},o.refreshAll=function(){for(var t in a)a[t].refresh()},o.findByElement=function(t){return a[t.waypointContextKey]},n.onload=function(){l&&l(),o.refreshAll()},r.requestAnimationFrame=function(t){var e=n.requestAnimationFrame||n.mozRequestAnimationFrame||n.webkitRequestAnimationFrame||i;e.call(window,t)},e.exports=o}).call(this,"undefined"!=typeof global?global:"undefined"!=typeof self?self:"undefined"!=typeof window?window:{})},{"./waypoint":6}],3:[function(t,e){"use strict";var n=t("../waypoint"),i=t("../context"),o=t("../group"),r=t("../adapters/noframework"),s=t("../shortcuts/inview");n.Context=i,n.Group=o,n.adapters.push(r),n.Adapter=r.Adapter,n.Inview=s,e.exports=n},{"../adapters/noframework":1,"../context":2,"../group":4,"../shortcuts/inview":5,"../waypoint":6}],4:[function(t,e){"use strict";function n(t,e){return t.triggerPoint-e.triggerPoint}function i(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(),s[this.axis][this.name]=this}var r=t("./waypoint"),s={vertical:{},horizontal:{}};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 t in this.triggerQueues){var e=this.triggerQueues[t],o="up"===t||"left"===t;e.sort(o?i:n);for(var r=0,s=e.length;s>r;r+=1){var a=e[r];(a.options.continuous||r===e.length-1)&&a.trigger([t])}}this.clearTriggerQueues()},o.prototype.next=function(t){this.waypoints.sort(n);var e=r.Adapter.inArray(t,this.waypoints),i=e===this.waypoints.length-1;return i?null:this.waypoints[e+1]},o.prototype.previous=function(t){this.waypoints.sort(n);var e=r.Adapter.inArray(t,this.waypoints);return e?this.waypoints[e-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 s[t.axis][t.name]||new o(t)},e.exports=o},{"./waypoint":6}],5:[function(t,e){(function(n){!function(n){"use strict";function i(){}function o(t){this.options=r.Adapter.extend({},o.defaults,t),this.axis=this.options.horizontal?"horizontal":"vertical",this.waypoints=[],this.element=this.options.element,this.createWaypoints()}var r;return"function"==typeof t?r=t("../waypoint"):(n=window,r=n.Waypoint),o.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,n=t[this.axis].length;n>e;e++){var i=t[this.axis][e];this.createWaypoint(i)}},o.prototype.createWaypoint=function(t){var e=this;this.waypoints.push(new r({context:this.options.context,element:this.options.element,enabled:this.options.enabled,handler:function(t){return function(n){e.options[t[n]].call(e,n)}}(t),offset:t.offset,horizontal:this.options.horizontal}))},o.prototype.destroy=function(){for(var t=0,e=this.waypoints.length;e>t;t++)this.waypoints[t].destroy();this.waypoints=[]},o.prototype.disable=function(){for(var t=0,e=this.waypoints.length;e>t;t++)this.waypoints[t].disable()},o.prototype.enable=function(){for(var t=0,e=this.waypoints.length;e>t;t++)this.waypoints[t].enable()},o.defaults={context:n,enabled:!0,enter:i,entered:i,exit:i,exited:i},"undefined"!=typeof e?e.exports=o:void 0}("undefined"!=typeof n?n:window)}).call(this,"undefined"!=typeof global?global:"undefined"!=typeof self?self:"undefined"!=typeof window?window:{})},{"../waypoint":6}],6:[function(t,e){(function(t){"use strict";function n(t){if(!t)throw new Error("No options passed to Waypoint constructor");if(!t.element)throw new Error("No element option passed to Waypoint constructor");if(!t.handler)throw new Error("No handler option passed to Waypoint constructor");this.key="waypoint-"+i,this.options=n.Adapter.extend({},n.defaults,t),this.element=this.options.element,this.adapter=new n.Adapter(this.element),this.callback=t.handler,this.axis=this.options.horizontal?"horizontal":"vertical",this.enabled=this.options.enabled,this.triggerPoint=null,this.group=n.Group.findOrCreate({name:this.options.group,axis:this.axis}),this.context=n.Context.findOrCreateByElement(this.options.context),n.offsetAliases[this.options.offset]&&(this.options.offset=n.offsetAliases[this.options.offset]),this.group.add(this),this.context.add(this),o[this.key]=this,i+=1}var i=0,o={};n.prototype.queueTrigger=function(t){this.group.queueTrigger(this,t)},n.prototype.trigger=function(t){this.enabled&&this.callback&&this.callback.apply(this,t)},n.prototype.destroy=function(){this.context.remove(this),this.group.remove(this),delete o[this.key]},n.prototype.disable=function(){return this.enabled=!1,this},n.prototype.enable=function(){return this.context.refresh(),this.enabled=!0,this},n.prototype.next=function(){return this.group.next(this)},n.prototype.previous=function(){return this.group.previous(this)},n.invokeAll=function(t){var e=[];for(var n in o)e.push(o[n]);for(var i=0,r=e.length;r>i;i++)e[i][t]()},n.destroyAll=function(){n.invokeAll("destroy")},n.disableAll=function(){n.invokeAll("disable")},n.enableAll=function(){n.invokeAll("enable")},n.refreshAll=function(){n.Context.refreshAll()},n.viewportHeight=function(){return t.innerHeight||document.documentElement.clientHeight},n.viewportWidth=function(){return document.documentElement.clientWidth},n.adapters=[],n.defaults={context:t,continuous:!0,enabled:!0,group:"default",horizontal:!1,offset:0},n.offsetAliases={"bottom-in-view":function(){return this.context.innerHeight()-this.adapter.outerHeight()},"right-in-view":function(){return this.context.innerWidth()-this.adapter.outerWidth()}},e.exports=n}).call(this,"undefined"!=typeof global?global:"undefined"!=typeof self?self:"undefined"!=typeof window?window:{})},{}]},{},[3]); \ No newline at end of file diff --git a/lib/shortcuts/infinite.js b/lib/shortcuts/infinite.js index eec5dac..4966c13 100644 --- a/lib/shortcuts/infinite.js +++ b/lib/shortcuts/infinite.js @@ -1,15 +1,20 @@ /*! Waypoints Infinite Scroll Shortcut - 4.0.0 -Copyright © 2011-2015 Caleb Troughton +Copyright © 2011-2016 Caleb Troughton Licensed under the MIT license. https://github.com/imakewebthings/waypoints/blob/master/licenses.txt */ -(function() { +(function(global) { 'use strict' - var $ = window.jQuery - var Waypoint = window.Waypoint - + var Waypoint + if (typeof require == 'function') { + Waypoint = require('../waypoint') + } + else { + Waypoint = global.Waypoint + } + var $ = global.jQuery //require('jquery') /* http://imakewebthings.com/waypoints/shortcuts/infinite-scroll */ function Infinite(options) { this.options = $.extend({}, Infinite.defaults, options) @@ -79,6 +84,6 @@ https://github.com/imakewebthings/waypoints/blob/master/licenses.txt onAfterPageLoad: $.noop } - Waypoint.Infinite = Infinite -}()) + return typeof module !== 'undefined' ? module.exports = Infinite : undefined +}(typeof global !== 'undefined' ? global : window)) ; \ No newline at end of file diff --git a/lib/shortcuts/infinite.min.js b/lib/shortcuts/infinite.min.js index 8ecbc73..c4cae5a 100644 --- a/lib/shortcuts/infinite.min.js +++ b/lib/shortcuts/infinite.min.js @@ -1,7 +1,7 @@ /*! Waypoints Infinite Scroll Shortcut - 4.0.0 -Copyright © 2011-2015 Caleb Troughton +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){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 +!function(t){"use strict";function o(t){this.options=n.extend({},o.defaults,t),this.container=this.options.element,"auto"!==this.options.container&&(this.container=this.options.container),this.$container=n(this.container),this.$more=n(this.options.more),this.$more.length&&(this.setupHandler(),this.waypoint=new i(this.options))}var i;i="function"==typeof require?require("../waypoint"):t.Waypoint;var n=t.jQuery;return o.prototype.setupHandler=function(){this.options.handler=n.proxy(function(){this.options.onBeforePageLoad(),this.destroy(),this.$container.addClass(this.options.loadingClass),n.get(n(this.options.more).attr("href"),n.proxy(function(t){var o=n(n.parseHTML(t)),e=o.find(this.options.more),s=o.find(this.options.items);s.length||(s=o.filter(this.options.items)),this.$container.append(s),this.$container.removeClass(this.options.loadingClass),e.length||(e=o.filter(this.options.more)),e.length?(this.$more.replaceWith(e),this.$more=e,this.waypoint=new i(this.options)):this.$more.remove(),this.options.onAfterPageLoad(s)},this))},this)},o.prototype.destroy=function(){this.waypoint&&this.waypoint.destroy()},o.defaults={container:"auto",items:".infinite-item",more:".infinite-more-link",offset:"bottom-in-view",loadingClass:"infinite-loading",onBeforePageLoad:n.noop,onAfterPageLoad:n.noop},"undefined"!=typeof module?module.exports=o:void 0}("undefined"!=typeof global?global:window); \ No newline at end of file diff --git a/lib/shortcuts/inview.js b/lib/shortcuts/inview.js index acec502..079eec2 100644 --- a/lib/shortcuts/inview.js +++ b/lib/shortcuts/inview.js @@ -1,15 +1,21 @@ /*! Waypoints Inview Shortcut - 4.0.0 -Copyright © 2011-2015 Caleb Troughton +Copyright © 2011-2016 Caleb Troughton Licensed under the MIT license. https://github.com/imakewebthings/waypoints/blob/master/licenses.txt */ -(function() { +(function(global) { 'use strict' - + var Waypoint + if (typeof require == 'function') { + Waypoint = require('../waypoint') + } + else { + global = window + Waypoint = global.Waypoint + } function noop() {} - var Waypoint = window.Waypoint /* http://imakewebthings.com/waypoints/shortcuts/inview */ function Inview(options) { @@ -107,7 +113,7 @@ https://github.com/imakewebthings/waypoints/blob/master/licenses.txt } Inview.defaults = { - context: window, + context: global, enabled: true, enter: noop, entered: noop, @@ -115,6 +121,6 @@ https://github.com/imakewebthings/waypoints/blob/master/licenses.txt exited: noop } - Waypoint.Inview = Inview -}()) + return typeof module !== 'undefined' ? module.exports = Inview : undefined +}(typeof global !== 'undefined' ? global : window)) ; \ No newline at end of file diff --git a/lib/shortcuts/inview.min.js b/lib/shortcuts/inview.min.js index 6375baf..fd3abd6 100644 --- a/lib/shortcuts/inview.min.js +++ b/lib/shortcuts/inview.min.js @@ -1,7 +1,7 @@ /*! Waypoints Inview Shortcut - 4.0.0 -Copyright © 2011-2015 Caleb Troughton +Copyright © 2011-2016 Caleb Troughton Licensed under the MIT license. 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 +!function(t){"use strict";function e(){}function i(t){this.options=o.Adapter.extend({},i.defaults,t),this.axis=this.options.horizontal?"horizontal":"vertical",this.waypoints=[],this.element=this.options.element,this.createWaypoints()}var o;return"function"==typeof require?o=require("../waypoint"):(t=window,o=t.Waypoint),i.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)}},i.prototype.createWaypoint=function(t){var e=this;this.waypoints.push(new o({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}))},i.prototype.destroy=function(){for(var t=0,e=this.waypoints.length;e>t;t++)this.waypoints[t].destroy();this.waypoints=[]},i.prototype.disable=function(){for(var t=0,e=this.waypoints.length;e>t;t++)this.waypoints[t].disable()},i.prototype.enable=function(){for(var t=0,e=this.waypoints.length;e>t;t++)this.waypoints[t].enable()},i.defaults={context:t,enabled:!0,enter:e,entered:e,exit:e,exited:e},"undefined"!=typeof module?module.exports=i:void 0}("undefined"!=typeof global?global:window); \ No newline at end of file diff --git a/lib/shortcuts/sticky.js b/lib/shortcuts/sticky.js index b609b84..8003b5c 100644 --- a/lib/shortcuts/sticky.js +++ b/lib/shortcuts/sticky.js @@ -1,14 +1,20 @@ /*! Waypoints Sticky Element Shortcut - 4.0.0 -Copyright © 2011-2015 Caleb Troughton +Copyright © 2011-2016 Caleb Troughton Licensed under the MIT license. https://github.com/imakewebthings/waypoints/blob/master/licenses.txt */ -(function() { +(function(global) { 'use strict' - var $ = window.jQuery - var Waypoint = window.Waypoint + var Waypoint + if (typeof require == 'function') { + Waypoint = require('../waypoint') + } + else { + Waypoint = global.Waypoint + } + var $ = global.jQuery //require('jquery') /* http://imakewebthings.com/waypoints/shortcuts/sticky-elements */ function Sticky(options) { @@ -65,6 +71,6 @@ https://github.com/imakewebthings/waypoints/blob/master/licenses.txt direction: 'down right' } - Waypoint.Sticky = Sticky -}()) + return typeof module !== 'undefined' ? module.exports = Sticky : undefined +}(typeof global !== 'undefined' ? global : window)) ; \ No newline at end of file diff --git a/lib/shortcuts/sticky.min.js b/lib/shortcuts/sticky.min.js index e2ea060..43db41d 100644 --- a/lib/shortcuts/sticky.min.js +++ b/lib/shortcuts/sticky.min.js @@ -1,7 +1,7 @@ /*! Waypoints Sticky Element Shortcut - 4.0.0 -Copyright © 2011-2015 Caleb Troughton +Copyright © 2011-2016 Caleb Troughton Licensed under the MIT license. 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 +!function(t){"use strict";function e(t){this.options=s.extend({},i.defaults,e.defaults,t),this.element=this.options.element,this.$element=s(this.element),this.createWrapper(),this.createWaypoint()}var i;i="function"==typeof require?require("../waypoint"):t.Waypoint;var s=t.jQuery;return e.prototype.createWaypoint=function(){var t=this.options.handler;this.waypoint=new i(s.extend({},this.options,{element:this.wrapper,handler:s.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)}))},e.prototype.createWrapper=function(){this.options.wrapper&&this.$element.wrap(this.options.wrapper),this.$wrapper=this.$element.parent(),this.wrapper=this.$wrapper[0]},e.prototype.destroy=function(){this.$element.parent()[0]===this.wrapper&&(this.waypoint.destroy(),this.$element.removeClass(this.options.stuckClass),this.options.wrapper&&this.$element.unwrap())},e.defaults={wrapper:'
',stuckClass:"stuck",direction:"down right"},"undefined"!=typeof module?module.exports=e:void 0}("undefined"!=typeof global?global:window); \ No newline at end of file diff --git a/lib/test.waypoints.js b/lib/test.waypoints.js new file mode 100644 index 0000000..bb9cd1d --- /dev/null +++ b/lib/test.waypoints.js @@ -0,0 +1,1260 @@ +/*! +Waypoints - 4.0.0 +Copyright © 2011-2016 Caleb Troughton +Licensed under the MIT license. +https://github.com/imakewebthings/waypoints/blob/master/licenses.txt +*/ +(function e(t,n,r){function s(o,u){if(!n[o]){if(!t[o]){var a=typeof require=="function"&&require;if(!u&&a)return a(o,!0);if(i)return i(o,!0);var f=new Error("Cannot find module '"+o+"'");throw f.code="MODULE_NOT_FOUND",f}var l=n[o]={exports:{}};t[o][0].call(l.exports,function(e){var n=t[o][1][e];return s(n?n:e)},l,l.exports,e,t,n,r)}return n[o].exports}var i=typeof require=="function"&&require;for(var o=0;o 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 + } + } + + /* Private */ + Context.prototype.innerHeight = function() { + /*eslint-disable eqeqeq */ + if (this.element == this.element.window) { + return Waypoint.viewportHeight() + } + /*eslint-enable eqeqeq */ + return this.adapter.innerHeight() + } + + /* Private */ + Context.prototype.remove = function(waypoint) { + delete this.waypoints[waypoint.axis][waypoint.key] + this.checkEmpty() + } + + /* Private */ + Context.prototype.innerWidth = function() { + /*eslint-disable eqeqeq */ + if (this.element == this.element.window) { + return Waypoint.viewportWidth() + } + /*eslint-enable eqeqeq */ + return this.adapter.innerWidth() + } + + /* Public */ + /* http://imakewebthings.com/waypoints/api/context-destroy */ + 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 */ + /* 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 = isWindow ? undefined : this.adapter.offset() + var triggeredGroups = {} + var axes + + this.handleScroll() + axes = { + horizontal: { + contextOffset: isWindow ? 0 : contextOffset.left, + contextScroll: isWindow ? 0 : this.oldScroll.x, + contextDimension: this.innerWidth(), + oldScroll: this.oldScroll.x, + forward: 'right', + backward: 'left', + offsetProp: 'left' + }, + vertical: { + contextOffset: isWindow ? 0 : contextOffset.top, + contextScroll: isWindow ? 0 : this.oldScroll.y, + contextDimension: this.innerHeight(), + 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, wasBeforeScroll, nowAfterScroll + var triggeredBackward, triggeredForward + + 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 + wasBeforeScroll = oldTriggerPoint < axis.oldScroll + nowAfterScroll = waypoint.triggerPoint >= axis.oldScroll + triggeredBackward = wasBeforeScroll && nowAfterScroll + 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 + } + } + } + + Waypoint.requestAnimationFrame(function() { + for (var groupKey in triggeredGroups) { + triggeredGroups[groupKey].flushTriggers() + } + }) + + return this + } + + /* Private */ + Context.findOrCreateByElement = function(element) { + return Context.findByElement(element) || new Context(element) + } + + /* Private */ + Context.refreshAll = function() { + for (var contextId in contexts) { + contexts[contextId].refresh() + } + } + + /* Public */ + /* http://imakewebthings.com/waypoints/api/context-find-by-element */ + Context.findByElement = function(element) { + return contexts[element.waypointContextKey] + } + + global.onload = function() { + if (oldWindowLoad) { + oldWindowLoad() + } + Context.refreshAll() + } + + Waypoint.requestAnimationFrame = function(callback) { + var requestFn = global.requestAnimationFrame || + global.mozRequestAnimationFrame || + global.webkitRequestAnimationFrame || + requestAnimationFrameShim + requestFn.call(window, callback) + } + module.exports = Context + +}).call(this,typeof global !== "undefined" ? global : typeof self !== "undefined" ? self : typeof window !== "undefined" ? window : {}) +},{"./waypoint":12}],6:[function(require,module,exports){ +(function (global){ + '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 = global.Waypoint.Context.prototype.refresh + + global.Waypoint.Context.prototype.refresh = function() { + for (var axis in this.waypoints) { + for (var key in this.waypoints[axis]) { + var waypoint = this.waypoints[axis][key] + var style = global.getComputedStyle(waypoint.element) + if (!waypoint.enabled) { + continue + } + if (style && style.display === 'none') { + console.error(displayNoneMessage) + } + if (style && style.position === 'fixed') { + console.error(fixedMessage) + } + } + } + return originalRefresh.call(this) + } + } + + module.exports = checkWaypointStyles + +}).call(this,typeof global !== "undefined" ? global : typeof self !== "undefined" ? self : typeof window !== "undefined" ? window : {}) +},{}],7:[function(require,module,exports){ +(function (global){ +'use strict' +var Waypoint = require('../waypoint') +var Context = require('../context') +var Group = require('../group') +var JQueryAdapter = require('../adapters/jquery') +var ZeptoAdapter = require('../adapters/zepto') +var NoFrameworkAdapter = require('../adapters/noframework') +var Inview = require('../shortcuts/inview') +var Infinite = require('../shortcuts/infinite') +var Sticky = require('../shortcuts/sticky') +var Debug = require('../debug') +var createExtension = require('../adapters/jquery-zepto-fn-extension') + +Waypoint.Context = Context +Waypoint.Group = Group +Waypoint.adapters.push(JQueryAdapter) +Waypoint.adapters.push(ZeptoAdapter) +if (global.jQuery) { + global.jQuery.fn.waypoint = createExtension(global.jQuery) +} +if (global.Zepto) { + global.Zepto.fn.waypoint = createExtension(global.Zepto) +} +Waypoint.adapters.push(NoFrameworkAdapter) +Waypoint.Adapter = JQueryAdapter.Adapter +Waypoint.Inview = Inview +Waypoint.Infinite = Infinite +Waypoint.Sticky = Sticky +global.Waypoint = Waypoint // debux expects global Waypoint +Debug() +module.exports = Waypoint + +}).call(this,typeof global !== "undefined" ? global : typeof self !== "undefined" ? self : typeof window !== "undefined" ? window : {}) +},{"../adapters/jquery":2,"../adapters/jquery-zepto-fn-extension":1,"../adapters/noframework":3,"../adapters/zepto":4,"../context":5,"../debug":6,"../group":8,"../shortcuts/infinite":9,"../shortcuts/inview":10,"../shortcuts/sticky":11,"../waypoint":12}],8:[function(require,module,exports){ + 'use strict' + var Waypoint = require('./waypoint') + + function byTriggerPoint(a, b) { + return a.triggerPoint - b.triggerPoint + } + + function byReverseTriggerPoint(a, b) { + return b.triggerPoint - a.triggerPoint + } + + var groups = { + vertical: {}, + horizontal: {} + } + + /* http://imakewebthings.com/waypoints/api/group */ + 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 + } + + /* Private */ + Group.prototype.add = function(waypoint) { + this.waypoints.push(waypoint) + } + + /* Private */ + Group.prototype.clearTriggerQueues = function() { + this.triggerQueues = { + up: [], + down: [], + left: [], + right: [] + } + } + + /* Private */ + 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() + } + + /* Private */ + Group.prototype.next = function(waypoint) { + 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] + } + + /* Private */ + Group.prototype.previous = function(waypoint) { + this.waypoints.sort(byTriggerPoint) + 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) + } + + /* Private */ + Group.prototype.remove = function(waypoint) { + var index = Waypoint.Adapter.inArray(waypoint, this.waypoints) + if (index > -1) { + this.waypoints.splice(index, 1) + } + } + + /* 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] + } + + /* Private */ + Group.findOrCreate = function(options) { + return groups[options.axis][options.name] || new Group(options) + } + + module.exports = Group + +},{"./waypoint":12}],9:[function(require,module,exports){ +(function (global){ +(function(global) { + 'use strict' + + var Waypoint + if (typeof require == 'function') { + Waypoint = require('../waypoint') + } + else { + Waypoint = global.Waypoint + } + var $ = global.jQuery //require('jquery') + /* http://imakewebthings.com/waypoints/shortcuts/infinite-scroll */ + 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) + + if (this.$more.length) { + this.setupHandler() + this.waypoint = new Waypoint(this.options) + } + } + + /* Private */ + Infinite.prototype.setupHandler = function() { + this.options.handler = $.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) + + 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) { + $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($items) + }, this)) + }, this) + } + + /* Public */ + Infinite.prototype.destroy = function() { + if (this.waypoint) { + this.waypoint.destroy() + } + } + + Infinite.defaults = { + container: 'auto', + items: '.infinite-item', + more: '.infinite-more-link', + offset: 'bottom-in-view', + loadingClass: 'infinite-loading', + onBeforePageLoad: $.noop, + onAfterPageLoad: $.noop + } + + return typeof module !== 'undefined' ? module.exports = Infinite : undefined +}(typeof global !== 'undefined' ? global : window)) + +}).call(this,typeof global !== "undefined" ? global : typeof self !== "undefined" ? self : typeof window !== "undefined" ? window : {}) +},{"../waypoint":12}],10:[function(require,module,exports){ +(function (global){ +(function(global) { + 'use strict' + var Waypoint + if (typeof require == 'function') { + Waypoint = require('../waypoint') + } + else { + global = window + Waypoint = global.Waypoint + } + function noop() {} + + + /* http://imakewebthings.com/waypoints/shortcuts/inview */ + function Inview(options) { + this.options = Waypoint.Adapter.extend({}, Inview.defaults, options) + this.axis = this.options.horizontal ? 'horizontal' : 'vertical' + this.waypoints = [] + this.element = this.options.element + this.createWaypoints() + } + + /* Private */ + 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) + } + } + + /* Private */ + 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) { + return function(direction) { + self.options[config[direction]].call(self, direction) + } + }(config)), + offset: config.offset, + horizontal: this.options.horizontal + })) + } + + /* Public */ + Inview.prototype.destroy = function() { + for (var i = 0, end = this.waypoints.length; i < end; i++) { + this.waypoints[i].destroy() + } + 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 = { + context: global, + enabled: true, + enter: noop, + entered: noop, + exit: noop, + exited: noop + } + + return typeof module !== 'undefined' ? module.exports = Inview : undefined +}(typeof global !== 'undefined' ? global : window)) + +}).call(this,typeof global !== "undefined" ? global : typeof self !== "undefined" ? self : typeof window !== "undefined" ? window : {}) +},{"../waypoint":12}],11:[function(require,module,exports){ +(function (global){ +(function(global) { + 'use strict' + + var Waypoint + if (typeof require == 'function') { + Waypoint = require('../waypoint') + } + else { + Waypoint = global.Waypoint + } + var $ = global.jQuery //require('jquery') + + /* http://imakewebthings.com/waypoints/shortcuts/sticky-elements */ + function Sticky(options) { + this.options = $.extend({}, Waypoint.defaults, Sticky.defaults, options) + this.element = this.options.element + this.$element = $(this.element) + this.createWrapper() + this.createWaypoint() + } + + /* Private */ + 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.$wrapper.height(wrapperHeight) + this.$element.toggleClass(this.options.stuckClass, shouldBeStuck) + + if (originalHandler) { + originalHandler.call(this, direction) + } + }, this) + })) + } + + /* Private */ + Sticky.prototype.createWrapper = function() { + if (this.options.wrapper) { + this.$element.wrap(this.options.wrapper) + } + this.$wrapper = this.$element.parent() + this.wrapper = this.$wrapper[0] + } + + /* Public */ + Sticky.prototype.destroy = function() { + if (this.$element.parent()[0] === this.wrapper) { + this.waypoint.destroy() + this.$element.removeClass(this.options.stuckClass) + if (this.options.wrapper) { + this.$element.unwrap() + } + } + } + + Sticky.defaults = { + wrapper: '
', + stuckClass: 'stuck', + direction: 'down right' + } + + return typeof module !== 'undefined' ? module.exports = Sticky : undefined +}(typeof global !== 'undefined' ? global : window)) + +}).call(this,typeof global !== "undefined" ? global : typeof self !== "undefined" ? self : typeof window !== "undefined" ? window : {}) +},{"../waypoint":12}],12:[function(require,module,exports){ +(function (global){ + 'use strict' + + 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') + } + 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) + 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.group.add(this) + this.context.add(this) + allWaypoints[this.key] = this + keyCounter += 1 + } + + /* Private */ + Waypoint.prototype.queueTrigger = function(direction) { + this.group.queueTrigger(this, direction) + } + + /* Private */ + Waypoint.prototype.trigger = function(args) { + if (!this.enabled) { + return + } + if (this.callback) { + this.callback.apply(this, args) + } + } + + /* Public */ + /* http://imakewebthings.com/waypoints/api/destroy */ + Waypoint.prototype.destroy = function() { + this.context.remove(this) + this.group.remove(this) + delete allWaypoints[this.key] + } + + /* 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 + return this + } + + /* 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) + } + + /* 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][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() { + Waypoint.Context.refreshAll() + } + + /* Public */ + /* http://imakewebthings.com/waypoints/api/viewport-height */ + Waypoint.viewportHeight = function() { + return global.innerHeight || document.documentElement.clientHeight + } + + /* Public */ + /* http://imakewebthings.com/waypoints/api/viewport-width */ + Waypoint.viewportWidth = function() { + return document.documentElement.clientWidth + } + + Waypoint.adapters = [] + + Waypoint.defaults = { + context: global, + continuous: true, + enabled: true, + group: 'default', + horizontal: false, + offset: 0 + } + + Waypoint.offsetAliases = { + 'bottom-in-view': function() { + return this.context.innerHeight() - this.adapter.outerHeight() + }, + 'right-in-view': function() { + return this.context.innerWidth() - this.adapter.outerWidth() + } + } + + module.exports = Waypoint + +}).call(this,typeof global !== "undefined" ? global : typeof self !== "undefined" ? self : typeof window !== "undefined" ? window : {}) +},{}]},{},[7]); +; \ No newline at end of file diff --git a/lib/test.waypoints.min.js b/lib/test.waypoints.min.js new file mode 100644 index 0000000..f5d2622 --- /dev/null +++ b/lib/test.waypoints.min.js @@ -0,0 +1,7 @@ +/*! +Waypoints - 4.0.0 +Copyright © 2011-2016 Caleb Troughton +Licensed under the MIT license. +https://github.com/imakewebthings/waypoints/blob/master/licenses.txt +*/ +!function t(e,n,i){function o(s,a){if(!n[s]){if(!e[s]){var l="function"==typeof require&&require;if(!a&&l)return l(s,!0);if(r)return r(s,!0);var p=new Error("Cannot find module '"+s+"'");throw p.code="MODULE_NOT_FOUND",p}var h=n[s]={exports:{}};e[s][0].call(h.exports,function(t){var n=e[s][1][t];return o(n?n:t)},h,h.exports,t,e,n,i)}return n[s].exports}for(var r="function"==typeof require&&require,s=0;si;i++){var r=e[i];n&&n!==r||t.removeEventListener(r)}}var i=t.split("."),o=i[0],r=i[1],s=this.element;if(r&&this.handlers[r]&&o)n(s,this.handlers[r][o],e),this.handlers[r][o]=[];else if(o)for(var a in this.handlers)n(s,this.handlers[a][o]||[],e),this.handlers[a][o]=[];else if(r&&this.handlers[r]){for(var l in this.handlers[r])n(s,this.handlers[r][l],e);this.handlers[r]={}}},o.prototype.offset=function(){if(!this.element.ownerDocument)return null;var t=this.element.ownerDocument.documentElement,e=i(this.element.ownerDocument),n={top:0,left:0};return this.element.getBoundingClientRect&&(n=this.element.getBoundingClientRect()),{top:n.top+e.pageYOffset-t.clientTop,left:n.left+e.pageXOffset-t.clientLeft}},o.prototype.on=function(t,e){var n=t.split("."),i=n[0],o=n[1]||"__default",r=this.handlers[o]=this.handlers[o]||{},s=r[i]=r[i]||[];s.push(e),this.element.addEventListener(i,e)},o.prototype.outerHeight=function(e){var i,o=this.innerHeight();return e&&!n(this.element)&&(i=t.getComputedStyle(this.element),o+=parseInt(i.marginTop,10),o+=parseInt(i.marginBottom,10)),o},o.prototype.outerWidth=function(e){var i,o=this.innerWidth();return e&&!n(this.element)&&(i=t.getComputedStyle(this.element),o+=parseInt(i.marginLeft,10),o+=parseInt(i.marginRight,10)),o},o.prototype.scrollLeft=function(){var t=i(this.element);return t?t.pageXOffset:this.element.scrollLeft},o.prototype.scrollTop=function(){var t=i(this.element);return t?t.pageYOffset:this.element.scrollTop},o.extend=function(){function t(t,e){if("object"==typeof t&&"object"==typeof e)for(var n in e)e.hasOwnProperty(n)&&(t[n]=e[n]);return t}for(var e=Array.prototype.slice.call(arguments),n=1,i=e.length;i>n;n++)t(e[0],e[n]);return e[0]},o.inArray=function(t,e,n){return null==e?-1:e.indexOf(t,n)},o.isEmptyObject=function(t){for(var e in t)return!1;return!0},e.exports={name:"noframework",Adapter:o}}).call(this,"undefined"!=typeof global?global:"undefined"!=typeof self?self:"undefined"!=typeof window?window:{})},{}],4:[function(t,e){(function(t){"use strict";function n(t){this.element=t,this.$element=i(t)}var i=t.Zepto;i.each(["off","on","scrollLeft","scrollTop"],function(t,e){n.prototype[e]=function(){var t=Array.prototype.slice.call(arguments);return this.$element[e].apply(this.$element,t)}}),n.prototype.offset=function(){return this.element!==this.element.window?this.$element.offset():void 0},i.each(["width","height"],function(t,e){function o(t,n){return function(t){var o=this.$element,r=o[e](),s={width:["left","right"],height:["top","bottom"]};return i.each(s[e],function(e,i){r+=parseInt(o.css("padding-"+i),10),n&&(r+=parseInt(o.css("border-"+i+"-width"),10)),t&&(r+=parseInt(o.css("margin-"+i),10))}),r}}var r=i.camelCase("inner-"+e),s=i.camelCase("outer-"+e);n.prototype[r]=o(!1),n.prototype[s]=o(!0)}),i.each(["extend","inArray"],function(t,e){n[e]=i[e]}),n.isEmptyObject=function(t){for(var e in t)return!1;return!0},e.exports={name:"zepto",Adapter:n}}).call(this,"undefined"!=typeof global?global:"undefined"!=typeof self?self:"undefined"!=typeof window?window:{})},{}],5:[function(t,e){(function(n){"use strict";function i(t){n.setTimeout(t,1e3/60)}function o(t){this.element=t,this.Adapter=r.Adapter,this.adapter=new this.Adapter(t),this.key="waypoint-context-"+s,this.didScroll=!1,this.didResize=!1,this.oldScroll={x:this.adapter.scrollLeft(),y:this.adapter.scrollTop()},this.waypoints={vertical:{},horizontal:{}},t.waypointContextKey=this.key,a[t.waypointContextKey]=this,s+=1,this.createThrottledScrollHandler(),this.createThrottledResizeHandler()}var r=t("./waypoint"),s=0,a={},l=n.onload;o.prototype.add=function(t){var e=t.options.horizontal?"horizontal":"vertical";this.waypoints[e][t.key]=t,this.refresh()},o.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 a[this.key])},o.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))})},o.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))})},o.prototype.handleResize=function(){r.Context.refreshAll()},o.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 n in e){var i=e[n],o=i.newScroll>i.oldScroll,r=o?i.forward:i.backward;for(var s in this.waypoints[n]){var a=this.waypoints[n][s],l=i.oldScroll=a.triggerPoint,h=l&&p,f=!l&&!p;(h||f)&&(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}},o.prototype.innerHeight=function(){return this.element==this.element.window?r.viewportHeight():this.adapter.innerHeight()},o.prototype.remove=function(t){delete this.waypoints[t.axis][t.key],this.checkEmpty()},o.prototype.innerWidth=function(){return this.element==this.element.window?r.viewportWidth():this.adapter.innerWidth()},o.prototype.destroy=function(){var t=[];for(var e in this.waypoints)for(var n in this.waypoints[e])t.push(this.waypoints[e][n]);for(var i=0,o=t.length;o>i;i++)t[i].destroy()},o.prototype.refresh=function(){var t,e=this.element==this.element.window,n=e?void 0:this.adapter.offset(),i={};this.handleScroll(),t={horizontal:{contextOffset:e?0:n.left,contextScroll:e?0:this.oldScroll.x,contextDimension:this.innerWidth(),oldScroll:this.oldScroll.x,forward:"right",backward:"left",offsetProp:"left"},vertical:{contextOffset:e?0:n.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 s=t[o];for(var a in this.waypoints[o]){var l,p,h,f,u,d=this.waypoints[o][a],c=d.options.offset,y=d.triggerPoint,w=0,g=null==y;d.element!==d.element.window&&(w=d.adapter.offset()[s.offsetProp]),"function"==typeof c?c=c.apply(d):"string"==typeof c&&(c=parseFloat(c),d.options.offset.indexOf("%")>-1&&(c=Math.ceil(s.contextDimension*c/100))),l=s.contextScroll-s.contextOffset,d.triggerPoint=w+l-c,p=y=s.oldScroll,f=p&&h,u=!p&&!h,!g&&f?(d.queueTrigger(s.backward),i[d.group.id]=d.group):!g&&u?(d.queueTrigger(s.forward),i[d.group.id]=d.group):g&&s.oldScroll>=d.triggerPoint&&(d.queueTrigger(s.forward),i[d.group.id]=d.group)}}return r.requestAnimationFrame(function(){for(var t in i)i[t].flushTriggers()}),this},o.findOrCreateByElement=function(t){return o.findByElement(t)||new o(t)},o.refreshAll=function(){for(var t in a)a[t].refresh()},o.findByElement=function(t){return a[t.waypointContextKey]},n.onload=function(){l&&l(),o.refreshAll()},r.requestAnimationFrame=function(t){var e=n.requestAnimationFrame||n.mozRequestAnimationFrame||n.webkitRequestAnimationFrame||i;e.call(window,t)},e.exports=o}).call(this,"undefined"!=typeof global?global:"undefined"!=typeof self?self:"undefined"!=typeof window?window:{})},{"./waypoint":12}],6:[function(t,e){(function(t){"use strict";function n(){var e=t.Waypoint.Context.prototype.refresh;t.Waypoint.Context.prototype.refresh=function(){for(var n in this.waypoints)for(var r in this.waypoints[n]){var s=this.waypoints[n][r],a=t.getComputedStyle(s.element);s.enabled&&(a&&"none"===a.display&&console.error(i),a&&"fixed"===a.position&&console.error(o))}return e.call(this)}}var i=["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(""),o=["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("");e.exports=n}).call(this,"undefined"!=typeof global?global:"undefined"!=typeof self?self:"undefined"!=typeof window?window:{})},{}],7:[function(t,e){(function(n){"use strict";var i=t("../waypoint"),o=t("../context"),r=t("../group"),s=t("../adapters/jquery"),a=t("../adapters/zepto"),l=t("../adapters/noframework"),p=t("../shortcuts/inview"),h=t("../shortcuts/infinite"),f=t("../shortcuts/sticky"),u=t("../debug"),d=t("../adapters/jquery-zepto-fn-extension");i.Context=o,i.Group=r,i.adapters.push(s),i.adapters.push(a),n.jQuery&&(n.jQuery.fn.waypoint=d(n.jQuery)),n.Zepto&&(n.Zepto.fn.waypoint=d(n.Zepto)),i.adapters.push(l),i.Adapter=s.Adapter,i.Inview=p,i.Infinite=h,i.Sticky=f,n.Waypoint=i,u(),e.exports=i}).call(this,"undefined"!=typeof global?global:"undefined"!=typeof self?self:"undefined"!=typeof window?window:{})},{"../adapters/jquery":2,"../adapters/jquery-zepto-fn-extension":1,"../adapters/noframework":3,"../adapters/zepto":4,"../context":5,"../debug":6,"../group":8,"../shortcuts/infinite":9,"../shortcuts/inview":10,"../shortcuts/sticky":11,"../waypoint":12}],8:[function(t,e){"use strict";function n(t,e){return t.triggerPoint-e.triggerPoint}function i(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(),s[this.axis][this.name]=this}var r=t("./waypoint"),s={vertical:{},horizontal:{}};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 t in this.triggerQueues){var e=this.triggerQueues[t],o="up"===t||"left"===t;e.sort(o?i:n);for(var r=0,s=e.length;s>r;r+=1){var a=e[r];(a.options.continuous||r===e.length-1)&&a.trigger([t])}}this.clearTriggerQueues()},o.prototype.next=function(t){this.waypoints.sort(n);var e=r.Adapter.inArray(t,this.waypoints),i=e===this.waypoints.length-1;return i?null:this.waypoints[e+1]},o.prototype.previous=function(t){this.waypoints.sort(n);var e=r.Adapter.inArray(t,this.waypoints);return e?this.waypoints[e-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 s[t.axis][t.name]||new o(t)},e.exports=o},{"./waypoint":12}],9:[function(t,e){(function(n){!function(n){"use strict";function i(t){this.options=r.extend({},i.defaults,t),this.container=this.options.element,"auto"!==this.options.container&&(this.container=this.options.container),this.$container=r(this.container),this.$more=r(this.options.more),this.$more.length&&(this.setupHandler(),this.waypoint=new o(this.options))}var o;o="function"==typeof t?t("../waypoint"):n.Waypoint;var r=n.jQuery;return i.prototype.setupHandler=function(){this.options.handler=r.proxy(function(){this.options.onBeforePageLoad(),this.destroy(),this.$container.addClass(this.options.loadingClass),r.get(r(this.options.more).attr("href"),r.proxy(function(t){var e=r(r.parseHTML(t)),n=e.find(this.options.more),i=e.find(this.options.items);i.length||(i=e.filter(this.options.items)),this.$container.append(i),this.$container.removeClass(this.options.loadingClass),n.length||(n=e.filter(this.options.more)),n.length?(this.$more.replaceWith(n),this.$more=n,this.waypoint=new o(this.options)):this.$more.remove(),this.options.onAfterPageLoad(i)},this))},this)},i.prototype.destroy=function(){this.waypoint&&this.waypoint.destroy()},i.defaults={container:"auto",items:".infinite-item",more:".infinite-more-link",offset:"bottom-in-view",loadingClass:"infinite-loading",onBeforePageLoad:r.noop,onAfterPageLoad:r.noop},"undefined"!=typeof e?e.exports=i:void 0}("undefined"!=typeof n?n:window)}).call(this,"undefined"!=typeof global?global:"undefined"!=typeof self?self:"undefined"!=typeof window?window:{})},{"../waypoint":12}],10:[function(t,e){(function(n){!function(n){"use strict";function i(){}function o(t){this.options=r.Adapter.extend({},o.defaults,t),this.axis=this.options.horizontal?"horizontal":"vertical",this.waypoints=[],this.element=this.options.element,this.createWaypoints()}var r;return"function"==typeof t?r=t("../waypoint"):(n=window,r=n.Waypoint),o.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,n=t[this.axis].length;n>e;e++){var i=t[this.axis][e];this.createWaypoint(i)}},o.prototype.createWaypoint=function(t){var e=this;this.waypoints.push(new r({context:this.options.context,element:this.options.element,enabled:this.options.enabled,handler:function(t){return function(n){e.options[t[n]].call(e,n)}}(t),offset:t.offset,horizontal:this.options.horizontal}))},o.prototype.destroy=function(){for(var t=0,e=this.waypoints.length;e>t;t++)this.waypoints[t].destroy();this.waypoints=[]},o.prototype.disable=function(){for(var t=0,e=this.waypoints.length;e>t;t++)this.waypoints[t].disable()},o.prototype.enable=function(){for(var t=0,e=this.waypoints.length;e>t;t++)this.waypoints[t].enable()},o.defaults={context:n,enabled:!0,enter:i,entered:i,exit:i,exited:i},"undefined"!=typeof e?e.exports=o:void 0}("undefined"!=typeof n?n:window)}).call(this,"undefined"!=typeof global?global:"undefined"!=typeof self?self:"undefined"!=typeof window?window:{})},{"../waypoint":12}],11:[function(t,e){(function(n){!function(n){"use strict";function i(t){this.options=r.extend({},o.defaults,i.defaults,t),this.element=this.options.element,this.$element=r(this.element),this.createWrapper(),this.createWaypoint()}var o;o="function"==typeof t?t("../waypoint"):n.Waypoint;var r=n.jQuery;return i.prototype.createWaypoint=function(){var t=this.options.handler;this.waypoint=new o(r.extend({},this.options,{element:this.wrapper,handler:r.proxy(function(e){var n=this.options.direction.indexOf(e)>-1,i=n?this.$element.outerHeight(!0):"";this.$wrapper.height(i),this.$element.toggleClass(this.options.stuckClass,n),t&&t.call(this,e)},this)}))},i.prototype.createWrapper=function(){this.options.wrapper&&this.$element.wrap(this.options.wrapper),this.$wrapper=this.$element.parent(),this.wrapper=this.$wrapper[0]},i.prototype.destroy=function(){this.$element.parent()[0]===this.wrapper&&(this.waypoint.destroy(),this.$element.removeClass(this.options.stuckClass),this.options.wrapper&&this.$element.unwrap())},i.defaults={wrapper:'
',stuckClass:"stuck",direction:"down right"},"undefined"!=typeof e?e.exports=i:void 0}("undefined"!=typeof n?n:window)}).call(this,"undefined"!=typeof global?global:"undefined"!=typeof self?self:"undefined"!=typeof window?window:{})},{"../waypoint":12}],12:[function(t,e){(function(t){"use strict";function n(t){if(!t)throw new Error("No options passed to Waypoint constructor");if(!t.element)throw new Error("No element option passed to Waypoint constructor");if(!t.handler)throw new Error("No handler option passed to Waypoint constructor");this.key="waypoint-"+i,this.options=n.Adapter.extend({},n.defaults,t),this.element=this.options.element,this.adapter=new n.Adapter(this.element),this.callback=t.handler,this.axis=this.options.horizontal?"horizontal":"vertical",this.enabled=this.options.enabled,this.triggerPoint=null,this.group=n.Group.findOrCreate({name:this.options.group,axis:this.axis}),this.context=n.Context.findOrCreateByElement(this.options.context),n.offsetAliases[this.options.offset]&&(this.options.offset=n.offsetAliases[this.options.offset]),this.group.add(this),this.context.add(this),o[this.key]=this,i+=1}var i=0,o={};n.prototype.queueTrigger=function(t){this.group.queueTrigger(this,t)},n.prototype.trigger=function(t){this.enabled&&this.callback&&this.callback.apply(this,t)},n.prototype.destroy=function(){this.context.remove(this),this.group.remove(this),delete o[this.key]},n.prototype.disable=function(){return this.enabled=!1,this},n.prototype.enable=function(){return this.context.refresh(),this.enabled=!0,this},n.prototype.next=function(){return this.group.next(this)},n.prototype.previous=function(){return this.group.previous(this)},n.invokeAll=function(t){var e=[];for(var n in o)e.push(o[n]);for(var i=0,r=e.length;r>i;i++)e[i][t]()},n.destroyAll=function(){n.invokeAll("destroy")},n.disableAll=function(){n.invokeAll("disable")},n.enableAll=function(){n.invokeAll("enable")},n.refreshAll=function(){n.Context.refreshAll()},n.viewportHeight=function(){return t.innerHeight||document.documentElement.clientHeight},n.viewportWidth=function(){return document.documentElement.clientWidth},n.adapters=[],n.defaults={context:t,continuous:!0,enabled:!0,group:"default",horizontal:!1,offset:0},n.offsetAliases={"bottom-in-view":function(){return this.context.innerHeight()-this.adapter.outerHeight()},"right-in-view":function(){return this.context.innerWidth()-this.adapter.outerWidth()}},e.exports=n}).call(this,"undefined"!=typeof global?global:"undefined"!=typeof self?self:"undefined"!=typeof window?window:{})},{}]},{},[7]); \ No newline at end of file diff --git a/lib/waypoints.debug.js b/lib/waypoints.debug.js index 49601e3..5396329 100644 --- a/lib/waypoints.debug.js +++ b/lib/waypoints.debug.js @@ -1,12 +1,10 @@ /*! Waypoints Debug - 4.0.0 -Copyright © 2011-2015 Caleb Troughton +Copyright © 2011-2016 Caleb Troughton Licensed under the MIT license. https://github.com/imakewebthings/waypoints/blob/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 ', @@ -19,13 +17,13 @@ https://github.com/imakewebthings/waypoints/blob/master/licenses.txt ].join('') function checkWaypointStyles() { - var originalRefresh = window.Waypoint.Context.prototype.refresh + var originalRefresh = global.Waypoint.Context.prototype.refresh - window.Waypoint.Context.prototype.refresh = function() { + global.Waypoint.Context.prototype.refresh = function() { for (var axis in this.waypoints) { for (var key in this.waypoints[axis]) { var waypoint = this.waypoints[axis][key] - var style = window.getComputedStyle(waypoint.element) + var style = global.getComputedStyle(waypoint.element) if (!waypoint.enabled) { continue } @@ -41,6 +39,5 @@ https://github.com/imakewebthings/waypoints/blob/master/licenses.txt } } - checkWaypointStyles() -}()) + module.exports = checkWaypointStyles ; \ No newline at end of file diff --git a/lib/zepto.waypoints.js b/lib/zepto.waypoints.js index 70f4970..7d845d7 100644 --- a/lib/zepto.waypoints.js +++ b/lib/zepto.waypoints.js @@ -1,180 +1,134 @@ /*! Waypoints - 4.0.0 -Copyright © 2011-2015 Caleb Troughton +Copyright © 2011-2016 Caleb Troughton Licensed under the MIT license. https://github.com/imakewebthings/waypoints/blob/master/licenses.txt */ -(function() { +(function e(t,n,r){function s(o,u){if(!n[o]){if(!t[o]){var a=typeof require=="function"&&require;if(!u&&a)return a(o,!0);if(i)return i(o,!0);var f=new Error("Cannot find module '"+o+"'");throw f.code="MODULE_NOT_FOUND",f}var l=n[o]={exports:{}};t[o][0].call(l.exports,function(e){var n=t[o][1][e];return s(n?n:e)},l,l.exports,e,t,n,r)}return n[o].exports}var i=typeof require=="function"&&require;for(var o=0;o -1 + var wrapperHeight = shouldBeStuck ? this.$element.outerHeight(true) : '' + + this.$wrapper.height(wrapperHeight) + this.$element.toggleClass(this.options.stuckClass, shouldBeStuck) + + if (originalHandler) { + originalHandler.call(this, direction) } - waypoints.push(new Waypoint(options)) - }) + }, this) + })) + } - return waypoints + /* Private */ + Sticky.prototype.createWrapper = function() { + if (this.options.wrapper) { + this.$element.wrap(this.options.wrapper) } + this.$wrapper = this.$element.parent() + this.wrapper = this.$wrapper[0] } - if (window.jQuery) { - window.jQuery.fn.waypoint = createExtension(window.jQuery) + /* Public */ + Sticky.prototype.destroy = function() { + if (this.$element.parent()[0] === this.wrapper) { + this.waypoint.destroy() + this.$element.removeClass(this.options.stuckClass) + if (this.options.wrapper) { + this.$element.unwrap() + } + } } - if (window.Zepto) { - window.Zepto.fn.waypoint = createExtension(window.Zepto) + + Sticky.defaults = { + wrapper: '
', + stuckClass: 'stuck', + direction: 'down right' } -}()) + + return typeof module !== 'undefined' ? module.exports = Sticky : undefined +}(typeof global !== 'undefined' ? global : window)) + +}).call(this,typeof global !== "undefined" ? global : typeof self !== "undefined" ? self : typeof window !== "undefined" ? window : {}) +},{"../waypoint":9}],9:[function(require,module,exports){ +(function (global){ + 'use strict' + + 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') + } + 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) + 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.group.add(this) + this.context.add(this) + allWaypoints[this.key] = this + keyCounter += 1 + } + + /* Private */ + Waypoint.prototype.queueTrigger = function(direction) { + this.group.queueTrigger(this, direction) + } + + /* Private */ + Waypoint.prototype.trigger = function(args) { + if (!this.enabled) { + return + } + if (this.callback) { + this.callback.apply(this, args) + } + } + + /* Public */ + /* http://imakewebthings.com/waypoints/api/destroy */ + Waypoint.prototype.destroy = function() { + this.context.remove(this) + this.group.remove(this) + delete allWaypoints[this.key] + } + + /* 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 + return this + } + + /* 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) + } + + /* 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][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() { + Waypoint.Context.refreshAll() + } + + /* Public */ + /* http://imakewebthings.com/waypoints/api/viewport-height */ + Waypoint.viewportHeight = function() { + return global.innerHeight || document.documentElement.clientHeight + } + + /* Public */ + /* http://imakewebthings.com/waypoints/api/viewport-width */ + Waypoint.viewportWidth = function() { + return document.documentElement.clientWidth + } + + Waypoint.adapters = [] + + Waypoint.defaults = { + context: global, + continuous: true, + enabled: true, + group: 'default', + horizontal: false, + offset: 0 + } + + Waypoint.offsetAliases = { + 'bottom-in-view': function() { + return this.context.innerHeight() - this.adapter.outerHeight() + }, + 'right-in-view': function() { + return this.context.innerWidth() - this.adapter.outerWidth() + } + } + + module.exports = Waypoint + +}).call(this,typeof global !== "undefined" ? global : typeof self !== "undefined" ? self : typeof window !== "undefined" ? window : {}) +},{}]},{},[4]); ; \ No newline at end of file diff --git a/lib/zepto.waypoints.min.js b/lib/zepto.waypoints.min.js index 88d579d..8bd03bb 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 +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 t(e,i,o){function n(s,a){if(!i[s]){if(!e[s]){var p="function"==typeof require&&require;if(!a&&p)return p(s,!0);if(r)return r(s,!0);var l=new Error("Cannot find module '"+s+"'");throw l.code="MODULE_NOT_FOUND",l}var h=i[s]={exports:{}};e[s][0].call(h.exports,function(t){var i=e[s][1][t];return n(i?i:t)},h,h.exports,t,e,i,o)}return i[s].exports}for(var r="function"==typeof require&&require,s=0;so.oldScroll,r=n?o.forward:o.backward;for(var s in this.waypoints[i]){var a=this.waypoints[i][s],p=o.oldScroll=a.triggerPoint,h=p&&l,f=!p&&!l;(h||f)&&(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}},n.prototype.innerHeight=function(){return this.element==this.element.window?r.viewportHeight():this.adapter.innerHeight()},n.prototype.remove=function(t){delete this.waypoints[t.axis][t.key],this.checkEmpty()},n.prototype.innerWidth=function(){return this.element==this.element.window?r.viewportWidth():this.adapter.innerWidth()},n.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()},n.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 n in t){var s=t[n];for(var a in this.waypoints[n]){var p,l,h,f,u,d=this.waypoints[n][a],c=d.options.offset,y=d.triggerPoint,w=0,g=null==y;d.element!==d.element.window&&(w=d.adapter.offset()[s.offsetProp]),"function"==typeof c?c=c.apply(d):"string"==typeof c&&(c=parseFloat(c),d.options.offset.indexOf("%")>-1&&(c=Math.ceil(s.contextDimension*c/100))),p=s.contextScroll-s.contextOffset,d.triggerPoint=w+p-c,l=y=s.oldScroll,f=l&&h,u=!l&&!h,!g&&f?(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 r.requestAnimationFrame(function(){for(var t in o)o[t].flushTriggers()}),this},n.findOrCreateByElement=function(t){return n.findByElement(t)||new n(t)},n.refreshAll=function(){for(var t in a)a[t].refresh()},n.findByElement=function(t){return a[t.waypointContextKey]},i.onload=function(){p&&p(),n.refreshAll()},r.requestAnimationFrame=function(t){var e=i.requestAnimationFrame||i.mozRequestAnimationFrame||i.webkitRequestAnimationFrame||o;e.call(window,t)},e.exports=n}).call(this,"undefined"!=typeof global?global:"undefined"!=typeof self?self:"undefined"!=typeof window?window:{})},{"./waypoint":9}],4:[function(t,e){(function(i){"use strict";var o=t("../waypoint"),n=t("../context"),r=t("../group"),s=t("../adapters/zepto"),a=t("../shortcuts/inview"),p=t("../shortcuts/infinite"),l=t("../shortcuts/sticky"),h=t("../adapters/jquery-zepto-fn-extension");i.Waypoint=o,o.Context=n,o.Group=r,o.adapters.push(s),o.Adapter=s.Adapter,i.Zepto&&(i.Zepto.fn.waypoint=h(i.Zepto)),o.Inview=a,o.Infinite=p,o.Sticky=l,e.exports=o}).call(this,"undefined"!=typeof global?global:"undefined"!=typeof self?self:"undefined"!=typeof window?window:{})},{"../adapters/jquery-zepto-fn-extension":1,"../adapters/zepto":2,"../context":3,"../group":5,"../shortcuts/infinite":6,"../shortcuts/inview":7,"../shortcuts/sticky":8,"../waypoint":9}],5:[function(t,e){"use strict";function i(t,e){return t.triggerPoint-e.triggerPoint}function o(t,e){return e.triggerPoint-t.triggerPoint}function n(t){this.name=t.name,this.axis=t.axis,this.id=this.name+"-"+this.axis,this.waypoints=[],this.clearTriggerQueues(),s[this.axis][this.name]=this}var r=t("./waypoint"),s={vertical:{},horizontal:{}};n.prototype.add=function(t){this.waypoints.push(t)},n.prototype.clearTriggerQueues=function(){this.triggerQueues={up:[],down:[],left:[],right:[]}},n.prototype.flushTriggers=function(){for(var t in this.triggerQueues){var e=this.triggerQueues[t],n="up"===t||"left"===t;e.sort(n?o:i);for(var r=0,s=e.length;s>r;r+=1){var a=e[r];(a.options.continuous||r===e.length-1)&&a.trigger([t])}}this.clearTriggerQueues()},n.prototype.next=function(t){this.waypoints.sort(i);var e=r.Adapter.inArray(t,this.waypoints),o=e===this.waypoints.length-1;return o?null:this.waypoints[e+1]},n.prototype.previous=function(t){this.waypoints.sort(i);var e=r.Adapter.inArray(t,this.waypoints);return e?this.waypoints[e-1]:null},n.prototype.queueTrigger=function(t,e){this.triggerQueues[e].push(t)},n.prototype.remove=function(t){var e=r.Adapter.inArray(t,this.waypoints);e>-1&&this.waypoints.splice(e,1)},n.prototype.first=function(){return this.waypoints[0]},n.prototype.last=function(){return this.waypoints[this.waypoints.length-1]},n.findOrCreate=function(t){return s[t.axis][t.name]||new n(t)},e.exports=n},{"./waypoint":9}],6:[function(t,e){(function(i){!function(i){"use strict";function o(t){this.options=r.extend({},o.defaults,t),this.container=this.options.element,"auto"!==this.options.container&&(this.container=this.options.container),this.$container=r(this.container),this.$more=r(this.options.more),this.$more.length&&(this.setupHandler(),this.waypoint=new n(this.options))}var n;n="function"==typeof t?t("../waypoint"):i.Waypoint;var r=i.jQuery;return o.prototype.setupHandler=function(){this.options.handler=r.proxy(function(){this.options.onBeforePageLoad(),this.destroy(),this.$container.addClass(this.options.loadingClass),r.get(r(this.options.more).attr("href"),r.proxy(function(t){var e=r(r.parseHTML(t)),i=e.find(this.options.more),o=e.find(this.options.items);o.length||(o=e.filter(this.options.items)),this.$container.append(o),this.$container.removeClass(this.options.loadingClass),i.length||(i=e.filter(this.options.more)),i.length?(this.$more.replaceWith(i),this.$more=i,this.waypoint=new n(this.options)):this.$more.remove(),this.options.onAfterPageLoad(o)},this))},this)},o.prototype.destroy=function(){this.waypoint&&this.waypoint.destroy()},o.defaults={container:"auto",items:".infinite-item",more:".infinite-more-link",offset:"bottom-in-view",loadingClass:"infinite-loading",onBeforePageLoad:r.noop,onAfterPageLoad:r.noop},"undefined"!=typeof e?e.exports=o:void 0}("undefined"!=typeof i?i:window)}).call(this,"undefined"!=typeof global?global:"undefined"!=typeof self?self:"undefined"!=typeof window?window:{})},{"../waypoint":9}],7:[function(t,e){(function(i){!function(i){"use strict";function o(){}function n(t){this.options=r.Adapter.extend({},n.defaults,t),this.axis=this.options.horizontal?"horizontal":"vertical",this.waypoints=[],this.element=this.options.element,this.createWaypoints()}var r;return"function"==typeof t?r=t("../waypoint"):(i=window,r=i.Waypoint),n.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)}},n.prototype.createWaypoint=function(t){var e=this;this.waypoints.push(new r({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}))},n.prototype.destroy=function(){for(var t=0,e=this.waypoints.length;e>t;t++)this.waypoints[t].destroy();this.waypoints=[]},n.prototype.disable=function(){for(var t=0,e=this.waypoints.length;e>t;t++)this.waypoints[t].disable()},n.prototype.enable=function(){for(var t=0,e=this.waypoints.length;e>t;t++)this.waypoints[t].enable()},n.defaults={context:i,enabled:!0,enter:o,entered:o,exit:o,exited:o},"undefined"!=typeof e?e.exports=n:void 0}("undefined"!=typeof i?i:window)}).call(this,"undefined"!=typeof global?global:"undefined"!=typeof self?self:"undefined"!=typeof window?window:{})},{"../waypoint":9}],8:[function(t,e){(function(i){!function(i){"use strict";function o(t){this.options=r.extend({},n.defaults,o.defaults,t),this.element=this.options.element,this.$element=r(this.element),this.createWrapper(),this.createWaypoint()}var n;n="function"==typeof t?t("../waypoint"):i.Waypoint;var r=i.jQuery;return o.prototype.createWaypoint=function(){var t=this.options.handler;this.waypoint=new n(r.extend({},this.options,{element:this.wrapper,handler:r.proxy(function(e){var i=this.options.direction.indexOf(e)>-1,o=i?this.$element.outerHeight(!0):"";this.$wrapper.height(o),this.$element.toggleClass(this.options.stuckClass,i),t&&t.call(this,e)},this)}))},o.prototype.createWrapper=function(){this.options.wrapper&&this.$element.wrap(this.options.wrapper),this.$wrapper=this.$element.parent(),this.wrapper=this.$wrapper[0]},o.prototype.destroy=function(){this.$element.parent()[0]===this.wrapper&&(this.waypoint.destroy(),this.$element.removeClass(this.options.stuckClass),this.options.wrapper&&this.$element.unwrap())},o.defaults={wrapper:'
',stuckClass:"stuck",direction:"down right"},"undefined"!=typeof e?e.exports=o:void 0}("undefined"!=typeof i?i:window)}).call(this,"undefined"!=typeof global?global:"undefined"!=typeof self?self:"undefined"!=typeof window?window:{})},{"../waypoint":9}],9:[function(t,e){(function(t){"use strict";function i(t){if(!t)throw new Error("No options passed to Waypoint constructor");if(!t.element)throw new Error("No element option passed to Waypoint constructor");if(!t.handler)throw new Error("No handler option passed to Waypoint constructor");this.key="waypoint-"+o,this.options=i.Adapter.extend({},i.defaults,t),this.element=this.options.element,this.adapter=new i.Adapter(this.element),this.callback=t.handler,this.axis=this.options.horizontal?"horizontal":"vertical",this.enabled=this.options.enabled,this.triggerPoint=null,this.group=i.Group.findOrCreate({name:this.options.group,axis:this.axis}),this.context=i.Context.findOrCreateByElement(this.options.context),i.offsetAliases[this.options.offset]&&(this.options.offset=i.offsetAliases[this.options.offset]),this.group.add(this),this.context.add(this),n[this.key]=this,o+=1}var o=0,n={};i.prototype.queueTrigger=function(t){this.group.queueTrigger(this,t)},i.prototype.trigger=function(t){this.enabled&&this.callback&&this.callback.apply(this,t)},i.prototype.destroy=function(){this.context.remove(this),this.group.remove(this),delete n[this.key]},i.prototype.disable=function(){return this.enabled=!1,this},i.prototype.enable=function(){return this.context.refresh(),this.enabled=!0,this},i.prototype.next=function(){return this.group.next(this)},i.prototype.previous=function(){return this.group.previous(this)},i.invokeAll=function(t){var e=[];for(var i in n)e.push(n[i]);for(var o=0,r=e.length;r>o;o++)e[o][t]()},i.destroyAll=function(){i.invokeAll("destroy")},i.disableAll=function(){i.invokeAll("disable")},i.enableAll=function(){i.invokeAll("enable")},i.refreshAll=function(){i.Context.refreshAll()},i.viewportHeight=function(){return t.innerHeight||document.documentElement.clientHeight},i.viewportWidth=function(){return document.documentElement.clientWidth},i.adapters=[],i.defaults={context:t,continuous:!0,enabled:!0,group:"default",horizontal:!1,offset:0},i.offsetAliases={"bottom-in-view":function(){return this.context.innerHeight()-this.adapter.outerHeight()},"right-in-view":function(){return this.context.innerWidth()-this.adapter.outerWidth()}},e.exports=i}).call(this,"undefined"!=typeof global?global:"undefined"!=typeof self?self:"undefined"!=typeof window?window:{})},{}]},{},[4]); \ No newline at end of file diff --git a/package.json b/package.json index 22a8516..64c9206 100644 --- a/package.json +++ b/package.json @@ -18,6 +18,7 @@ "scroll" ], "devDependencies": { + "browserify": "^13.0.0", "eslint": "^0.6.2", "gulp": "^3.6.2", "gulp-concat": "^2.2.0", @@ -28,7 +29,14 @@ "gulp-tap": "^0.1.1", "gulp-uglify": "^0.3.1", "merge-stream": "^0.1.1", - "testem": "^0.6.24" + "testem": "^0.6.24", + "vinyl-buffer": "^1.0.0", + "vinyl-source-stream": "^1.1.0" }, + "optionalDependencies": { + "jquery": "^1.12.0", + "zepto": "^1.0.1" + }, + "main": "src/entries/noframework", "license": "MIT" } diff --git a/src/adapters/jquery-zepto-fn-extension.js b/src/adapters/jquery-zepto-fn-extension.js index 8857569..b88b906 100644 --- a/src/adapters/jquery-zepto-fn-extension.js +++ b/src/adapters/jquery-zepto-fn-extension.js @@ -1,7 +1,5 @@ -(function() { 'use strict' - - var Waypoint = window.Waypoint + var Waypoint = require('../waypoint') function createExtension(framework) { return function() { @@ -27,10 +25,4 @@ } } - if (window.jQuery) { - window.jQuery.fn.waypoint = createExtension(window.jQuery) - } - if (window.Zepto) { - window.Zepto.fn.waypoint = createExtension(window.Zepto) - } -}()) + module.exports = createExtension diff --git a/src/adapters/jquery.js b/src/adapters/jquery.js index ac71236..2a0777e 100644 --- a/src/adapters/jquery.js +++ b/src/adapters/jquery.js @@ -1,14 +1,12 @@ -(function() { 'use strict' - var $ = window.jQuery - var Waypoint = window.Waypoint + var jquery = global.jQuery //require('jquery') function JQueryAdapter(element) { - this.$element = $(element) + this.$element = jquery(element) } - $.each([ + jquery.each([ 'innerHeight', 'innerWidth', 'off', @@ -25,17 +23,15 @@ } }) - $.each([ + jquery.each([ 'extend', 'inArray', 'isEmptyObject' ], function(i, method) { - JQueryAdapter[method] = $[method] + JQueryAdapter[method] = jquery[method] }) - Waypoint.adapters.push({ + module.exports = { name: 'jquery', Adapter: JQueryAdapter - }) - Waypoint.Adapter = JQueryAdapter -}()) + } diff --git a/src/adapters/noframework.js b/src/adapters/noframework.js index bac75ea..890dbee 100644 --- a/src/adapters/noframework.js +++ b/src/adapters/noframework.js @@ -1,8 +1,5 @@ -(function() { 'use strict' - var Waypoint = window.Waypoint - function isWindow(element) { return element === element.window } @@ -101,7 +98,7 @@ var computedStyle if (includeMargin && !isWindow(this.element)) { - computedStyle = window.getComputedStyle(this.element) + computedStyle = global.getComputedStyle(this.element) height += parseInt(computedStyle.marginTop, 10) height += parseInt(computedStyle.marginBottom, 10) } @@ -114,7 +111,7 @@ var computedStyle if (includeMargin && !isWindow(this.element)) { - computedStyle = window.getComputedStyle(this.element) + computedStyle = global.getComputedStyle(this.element) width += parseInt(computedStyle.marginLeft, 10) width += parseInt(computedStyle.marginRight, 10) } @@ -165,9 +162,7 @@ return true } - Waypoint.adapters.push({ + module.exports = { name: 'noframework', Adapter: NoFrameworkAdapter - }) - Waypoint.Adapter = NoFrameworkAdapter -}()) + } diff --git a/src/adapters/zepto.js b/src/adapters/zepto.js index 203e40e..330812b 100644 --- a/src/adapters/zepto.js +++ b/src/adapters/zepto.js @@ -1,15 +1,12 @@ -(function() { 'use strict' - - var $ = window.Zepto - var Waypoint = window.Waypoint + var Zepto = global.Zepto //require('zepto') function ZeptoAdapter(element) { this.element = element - this.$element = $(element) + this.$element = Zepto(element) } - $.each([ + Zepto.each([ 'off', 'on', 'scrollLeft', @@ -28,7 +25,7 @@ } // Adapted from https://gist.github.com/wheresrhys/5823198 - $.each([ + Zepto.each([ 'width', 'height' ], function(i, dimension) { @@ -41,7 +38,7 @@ height: ['top', 'bottom'] } - $.each(sides[dimension], function(i, side) { + Zepto.each(sides[dimension], function(i, side) { size += parseInt($element.css('padding-' + side), 10) if (includeBorder) { size += parseInt($element.css('border-' + side + '-width'), 10) @@ -54,18 +51,18 @@ } } - var innerMethod = $.camelCase('inner-' + dimension) - var outerMethod = $.camelCase('outer-' + dimension) + var innerMethod = Zepto.camelCase('inner-' + dimension) + var outerMethod = Zepto.camelCase('outer-' + dimension) ZeptoAdapter.prototype[innerMethod] = createDimensionMethod(false) ZeptoAdapter.prototype[outerMethod] = createDimensionMethod(true) }) - $.each([ + Zepto.each([ 'extend', 'inArray' ], function(i, method) { - ZeptoAdapter[method] = $[method] + ZeptoAdapter[method] = Zepto[method] }) ZeptoAdapter.isEmptyObject = function(obj) { @@ -76,9 +73,7 @@ return true } - Waypoint.adapters.push({ + module.exports = { name: 'zepto', Adapter: ZeptoAdapter - }) - Waypoint.Adapter = ZeptoAdapter -}()) + } diff --git a/src/context.js b/src/context.js index 5e3551b..ba142f0 100644 --- a/src/context.js +++ b/src/context.js @@ -1,14 +1,13 @@ -(function() { 'use strict' + var Waypoint = require('./waypoint') function requestAnimationFrameShim(callback) { - window.setTimeout(callback, 1000 / 60) + global.setTimeout(callback, 1000 / 60) } var keyCounter = 0 var contexts = {} - var Waypoint = window.Waypoint - var oldWindowLoad = window.onload + var oldWindowLoad = global.onload /* http://imakewebthings.com/waypoints/api/context */ function Context(element) { @@ -282,7 +281,7 @@ return contexts[element.waypointContextKey] } - window.onload = function() { + global.onload = function() { if (oldWindowLoad) { oldWindowLoad() } @@ -290,11 +289,10 @@ } Waypoint.requestAnimationFrame = function(callback) { - var requestFn = window.requestAnimationFrame || - window.mozRequestAnimationFrame || - window.webkitRequestAnimationFrame || + var requestFn = global.requestAnimationFrame || + global.mozRequestAnimationFrame || + global.webkitRequestAnimationFrame || requestAnimationFrameShim requestFn.call(window, callback) } - Waypoint.Context = Context -}()) + module.exports = Context diff --git a/src/debug.js b/src/debug.js index be9510b..b68369a 100644 --- a/src/debug.js +++ b/src/debug.js @@ -1,6 +1,4 @@ -(function() { 'use strict' - var displayNoneMessage = [ 'You have a Waypoint element with display none. For more information on ', 'why this is a bad idea read ', @@ -13,13 +11,13 @@ ].join('') function checkWaypointStyles() { - var originalRefresh = window.Waypoint.Context.prototype.refresh + var originalRefresh = global.Waypoint.Context.prototype.refresh - window.Waypoint.Context.prototype.refresh = function() { + global.Waypoint.Context.prototype.refresh = function() { for (var axis in this.waypoints) { for (var key in this.waypoints[axis]) { var waypoint = this.waypoints[axis][key] - var style = window.getComputedStyle(waypoint.element) + var style = global.getComputedStyle(waypoint.element) if (!waypoint.enabled) { continue } @@ -35,5 +33,4 @@ } } - checkWaypointStyles() -}()) + module.exports = checkWaypointStyles diff --git a/src/entries/debug.js b/src/entries/debug.js new file mode 100644 index 0000000..83eaaf7 --- /dev/null +++ b/src/entries/debug.js @@ -0,0 +1,4 @@ +'use strict' +var Debug = require('../debug') +Debug() +module.exports = Debug diff --git a/src/entries/jquery.js b/src/entries/jquery.js new file mode 100644 index 0000000..fbbf266 --- /dev/null +++ b/src/entries/jquery.js @@ -0,0 +1,25 @@ +'use strict' +var Waypoint = require('../waypoint') +var Context = require('../context') +var Group = require('../group') +var JQueryAdapter = require('../adapters/jquery') +var Inview = require('../shortcuts/inview') +var Infinite = require('../shortcuts/infinite') +var Sticky = require('../shortcuts/sticky') +var createExtension = require('../adapters/jquery-zepto-fn-extension') + +global.Waypoint = Waypoint + +Waypoint.Context = Context +Waypoint.Group = Group +Waypoint.adapters.push(JQueryAdapter) +Waypoint.Adapter = JQueryAdapter.Adapter +if (global.jQuery) { + global.jQuery.fn.waypoint = createExtension(global.jQuery) +} + +Waypoint.Inview = Inview +Waypoint.Infinite = Infinite +Waypoint.Sticky = Sticky + +module.exports = Waypoint diff --git a/src/entries/noframework.js b/src/entries/noframework.js new file mode 100644 index 0000000..c8885a5 --- /dev/null +++ b/src/entries/noframework.js @@ -0,0 +1,14 @@ +'use strict' +var Waypoint = require('../waypoint') +var Context = require('../context') +var Group = require('../group') +var NoFrameworkAdapter = require('../adapters/noframework') +var Inview = require('../shortcuts/inview') + +Waypoint.Context = Context +Waypoint.Group = Group +Waypoint.adapters.push(NoFrameworkAdapter) +Waypoint.Adapter = NoFrameworkAdapter.Adapter +Waypoint.Inview = Inview + +module.exports = Waypoint diff --git a/src/entries/shortcuts.inview.js b/src/entries/shortcuts.inview.js new file mode 100644 index 0000000..549677e --- /dev/null +++ b/src/entries/shortcuts.inview.js @@ -0,0 +1,4 @@ +var InView = require('../shortcuts/inview') + +global.Waypoint.Inview = InView +module.exports = InView diff --git a/src/entries/test.js b/src/entries/test.js new file mode 100644 index 0000000..a4ff063 --- /dev/null +++ b/src/entries/test.js @@ -0,0 +1,31 @@ +'use strict' +var Waypoint = require('../waypoint') +var Context = require('../context') +var Group = require('../group') +var JQueryAdapter = require('../adapters/jquery') +var ZeptoAdapter = require('../adapters/zepto') +var NoFrameworkAdapter = require('../adapters/noframework') +var Inview = require('../shortcuts/inview') +var Infinite = require('../shortcuts/infinite') +var Sticky = require('../shortcuts/sticky') +var Debug = require('../debug') +var createExtension = require('../adapters/jquery-zepto-fn-extension') + +Waypoint.Context = Context +Waypoint.Group = Group +Waypoint.adapters.push(JQueryAdapter) +Waypoint.adapters.push(ZeptoAdapter) +if (global.jQuery) { + global.jQuery.fn.waypoint = createExtension(global.jQuery) +} +if (global.Zepto) { + global.Zepto.fn.waypoint = createExtension(global.Zepto) +} +Waypoint.adapters.push(NoFrameworkAdapter) +Waypoint.Adapter = JQueryAdapter.Adapter +Waypoint.Inview = Inview +Waypoint.Infinite = Infinite +Waypoint.Sticky = Sticky +global.Waypoint = Waypoint // debux expects global Waypoint +Debug() +module.exports = Waypoint diff --git a/src/entries/zepto.js b/src/entries/zepto.js new file mode 100644 index 0000000..3f6d4fb --- /dev/null +++ b/src/entries/zepto.js @@ -0,0 +1,24 @@ +'use strict' +var Waypoint = require('../waypoint') +var Context = require('../context') +var Group = require('../group') +var ZeptoAdapter = require('../adapters/zepto') +var Inview = require('../shortcuts/inview') +var Infinite = require('../shortcuts/infinite') +var Sticky = require('../shortcuts/sticky') +var createExtension = require('../adapters/jquery-zepto-fn-extension') + +global.Waypoint = Waypoint +Waypoint.Context = Context +Waypoint.Group = Group +Waypoint.adapters.push(ZeptoAdapter) +Waypoint.Adapter = ZeptoAdapter.Adapter +if (global.Zepto) { + global.Zepto.fn.waypoint = createExtension(global.Zepto) +} + +Waypoint.Inview = Inview +Waypoint.Infinite = Infinite +Waypoint.Sticky = Sticky + +module.exports = Waypoint diff --git a/src/group.js b/src/group.js index 57c3038..1426106 100644 --- a/src/group.js +++ b/src/group.js @@ -1,5 +1,5 @@ -(function() { 'use strict' + var Waypoint = require('./waypoint') function byTriggerPoint(a, b) { return a.triggerPoint - b.triggerPoint @@ -13,7 +13,6 @@ vertical: {}, horizontal: {} } - var Waypoint = window.Waypoint /* http://imakewebthings.com/waypoints/api/group */ function Group(options) { @@ -101,5 +100,4 @@ return groups[options.axis][options.name] || new Group(options) } - Waypoint.Group = Group -}()) + module.exports = Group diff --git a/src/shortcuts/infinite.js b/src/shortcuts/infinite.js index a904dab..c715b93 100644 --- a/src/shortcuts/infinite.js +++ b/src/shortcuts/infinite.js @@ -1,9 +1,14 @@ -(function() { +(function(global) { 'use strict' - var $ = window.jQuery - var Waypoint = window.Waypoint - + var Waypoint + if (typeof require == 'function') { + Waypoint = require('../waypoint') + } + else { + Waypoint = global.Waypoint + } + var $ = global.jQuery //require('jquery') /* http://imakewebthings.com/waypoints/shortcuts/infinite-scroll */ function Infinite(options) { this.options = $.extend({}, Infinite.defaults, options) @@ -73,5 +78,5 @@ onAfterPageLoad: $.noop } - Waypoint.Infinite = Infinite -}()) + return typeof module !== 'undefined' ? module.exports = Infinite : undefined +}(typeof global !== 'undefined' ? global : window)) diff --git a/src/shortcuts/inview.js b/src/shortcuts/inview.js index cda4b1f..df03aad 100644 --- a/src/shortcuts/inview.js +++ b/src/shortcuts/inview.js @@ -1,9 +1,15 @@ -(function() { +(function(global) { 'use strict' - + var Waypoint + if (typeof require == 'function') { + Waypoint = require('../waypoint') + } + else { + global = window + Waypoint = global.Waypoint + } function noop() {} - var Waypoint = window.Waypoint /* http://imakewebthings.com/waypoints/shortcuts/inview */ function Inview(options) { @@ -101,7 +107,7 @@ } Inview.defaults = { - context: window, + context: global, enabled: true, enter: noop, entered: noop, @@ -109,5 +115,5 @@ exited: noop } - Waypoint.Inview = Inview -}()) + return typeof module !== 'undefined' ? module.exports = Inview : undefined +}(typeof global !== 'undefined' ? global : window)) diff --git a/src/shortcuts/sticky.js b/src/shortcuts/sticky.js index 7dc7054..df8882f 100644 --- a/src/shortcuts/sticky.js +++ b/src/shortcuts/sticky.js @@ -1,8 +1,14 @@ -(function() { +(function(global) { 'use strict' - var $ = window.jQuery - var Waypoint = window.Waypoint + var Waypoint + if (typeof require == 'function') { + Waypoint = require('../waypoint') + } + else { + Waypoint = global.Waypoint + } + var $ = global.jQuery //require('jquery') /* http://imakewebthings.com/waypoints/shortcuts/sticky-elements */ function Sticky(options) { @@ -59,5 +65,5 @@ direction: 'down right' } - Waypoint.Sticky = Sticky -}()) + return typeof module !== 'undefined' ? module.exports = Sticky : undefined +}(typeof global !== 'undefined' ? global : window)) diff --git a/src/waypoint.js b/src/waypoint.js index 7f76f1d..6ae74fd 100644 --- a/src/waypoint.js +++ b/src/waypoint.js @@ -1,4 +1,3 @@ -(function() { 'use strict' var keyCounter = 0 @@ -127,7 +126,7 @@ /* Public */ /* http://imakewebthings.com/waypoints/api/viewport-height */ Waypoint.viewportHeight = function() { - return window.innerHeight || document.documentElement.clientHeight + return global.innerHeight || document.documentElement.clientHeight } /* Public */ @@ -139,7 +138,7 @@ Waypoint.adapters = [] Waypoint.defaults = { - context: window, + context: global, continuous: true, enabled: true, group: 'default', @@ -156,5 +155,4 @@ } } - window.Waypoint = Waypoint -}()) + module.exports = Waypoint diff --git a/testem.json b/testem.json index 21f89a0..6c82dd2 100644 --- a/testem.json +++ b/testem.json @@ -11,12 +11,7 @@ "bower_components/jasmine-jquery/lib/jasmine-jquery.js", "bower_components/zepto/zepto.js", - "src/waypoint.js", - "src/context.js", - "src/group.js", - "src/debug.js", - "src/adapters/*.js", - "src/shortcuts/*.js", + "lib/test.waypoints.js", "test/settings.js", "test/*-spec.js"