/
Intersectable.min.js
12 lines (12 loc) · 2.09 KB
/
Intersectable.min.js
1
2
3
4
5
6
7
8
9
10
11
12
/**
* Intersectable JavaScript Module v1.1.1
* http://www.intheloftstudios.com/packages/js/intersectable
*
* Plugin to detect when an element scrolls past a portion of the visible screen.
*
* Copyright 2015, Aaron Klump <sourcecode@intheloftstudios.com>
* @license Dual licensed under the MIT or GPL Version 2 licenses.
*
* Date: Thu Oct 22 10:21:20 PDT 2015
*/
var Intersectable=function($){function t(t){this.version="1.1.1","string"==typeof t&&(t={key:t}),this.settings=$.extend({},this.options,t),this.items={},this.items.window=[0,$(window).height()],this.items.document=[0,$(document).height()]}return t.prototype.options={cssPrefix:"intersectable__"},t.prototype.overlaps=function(t,e){return 0===this.intersection(t,e)},t.prototype.intersection=function(t,e){return e[0]>t[1]?-1:e[1]<t[0]?1:0},t.prototype.getElementBounds=function(t){return $element=t instanceof jQuery?t:$(t),[$element.offset().top,$element.offset().top+$element.height()]},t.prototype.toAbsoluteBounds=function(t){return this.addOffset(t,$(window).scrollTop())},t.prototype.getBoundsFromPoint=function(t,e,n){switch(n){case"bottom":return[t-e,t];case"top":return[t,t+e];default:return[t-e/2,t+e/2]}},t.prototype.getWindowCenterBounds=function(t,e){"string"==typeof t&&"%"===t.slice(-1)&&(t=this.getHeight(this.items.window)*parseInt(t,10)/100);var n=this.getCenter(this.items.window),o=this.getBoundsFromPoint(n,t,e);return o},t.prototype.getHeight=function(t){return t[1]-t[0]},t.prototype.getCenter=function(t){return this.getHeight(t)/2+t[0]},t.prototype.addOffset=function(t,e){return[t[0]+e,t[1]+e]},t.prototype.pre=function(t){return this.settings.cssPrefix+t},t.prototype.showBounds=function(t,e,n){if(""===e)throw"Invalid Argument: uuid cannot be empty.";if("string"==typeof n&&(n=n.split(" ")),n=n||[],n.constructor!==Array)throw"Invalid Argument: classesArray must be an array.";e=this.pre(e),n.unshift(this.pre("bounds"));var o=$("#"+e);0===o.length&&(o=$('<div id="'+e+'" class="'+n.join(" ")+'"></div>'),$("body").append(o));var i={top:t[0],height:this.getHeight(t)};return o.css(i),$("body").addClass("intersectable"),o.get(0)},t}(jQuery);