diff --git a/angular-scroll.js b/angular-scroll.js index f38eaa1..766013b 100644 --- a/angular-scroll.js +++ b/angular-scroll.js @@ -18,8 +18,16 @@ run(function($window, requestAnimation, duScrollEasing) { return proto; }; + var isDocument = function(el) { + return (typeof HTMLDocument !== 'undefined' && el instanceof HTMLDocument) || (el.nodeType && el.nodeType === el.DOCUMENT_NODE); + }; + + var isElement = function(el) { + return (typeof HTMLElement !== 'undefined' && el instanceof HTMLElement) || (el.nodeType && el.nodeType === el.ELEMENT_NODE); + }; + var unwrap = function(el) { - return el instanceof HTMLElement || el instanceof HTMLDocument ? el : el[0]; + return isElement(el) || isDocument(el) ? el : el[0]; }; proto.scrollTo = function(left, top, duration, easing) { @@ -30,7 +38,7 @@ run(function($window, requestAnimation, duScrollEasing) { return this.scrollToAnimated.apply(this, arguments); } var el = unwrap(this); - if(el instanceof HTMLDocument) { + if(isDocument(el)) { return $window.scrollTo(left, top); } el.scrollLeft = left; @@ -65,7 +73,7 @@ run(function($window, requestAnimation, duScrollEasing) { proto.scrollToElement = function(target, offset, duration, easing) { var el = unwrap(this); var top = this.scrollTop() + unwrap(target).getBoundingClientRect().top - offset; - if(el instanceof HTMLElement) { + if(isElement(el)) { top -= el.getBoundingClientRect().top; } this.scrollTo(0, top, duration, easing); @@ -76,7 +84,7 @@ run(function($window, requestAnimation, duScrollEasing) { return this.scrollTo(value, this.scrollTop(), duration, easing); } var el = unwrap(this); - if(el instanceof HTMLDocument) { + if(isDocument(el)) { return $window.scrollX || document.documentElement.scrollLeft || document.body.scrollLeft; } return el.scrollLeft; @@ -87,7 +95,7 @@ run(function($window, requestAnimation, duScrollEasing) { return this.scrollTo(this.scrollTop(), value, duration, easing); } var el = unwrap(this); - if(el instanceof HTMLDocument) { + if(isDocument(el)) { return $window.scrollY || document.documentElement.scrollTop || document.body.scrollTop; } return el.scrollTop; diff --git a/angular-scroll.min.js b/angular-scroll.min.js index 19bc134..ce96a06 100644 --- a/angular-scroll.min.js +++ b/angular-scroll.min.js @@ -1,2 +1,2 @@ -var duScrollDefaultEasing=function(a){return.5>a?Math.pow(2*a,2)/2:1-Math.pow(2*(1-a),2)/2};angular.module("duScroll",["duScroll.scrollspy","duScroll.requestAnimation","duScroll.smoothScroll","duScroll.scrollContainer","duScroll.scrollHelpers"]).value("duScrollDuration",1e3).value("duScrollEasing",duScrollDefaultEasing),angular.module("duScroll.scrollHelpers",[]).run(["$window","requestAnimation","duScrollEasing",function(a,b,c){var d=angular.element.prototype;this.$get=function(){return d};var e=function(a){return a instanceof HTMLElement||a instanceof HTMLDocument?a:a[0]};d.scrollTo=function(b,c,d){if(angular.isElement(b))return this.scrollToElement(b,0,c,d);if(d)return this.scrollToAnimated.apply(this,arguments);var f=e(this);return f instanceof HTMLDocument?a.scrollTo(b,c):(f.scrollLeft=b,f.scrollTop=c,void 0)},d.scrollToAnimated=function(a,d,e,f){e&&!f&&(f=c);var g=this.scrollLeft(),h=this.scrollTop(),i=Math.round(a-g),j=Math.round(d-h);if(i||j){var k=0,l=Math.ceil(e/60),m=function(){k++;var a=k===l?1:f(k/l);this.scrollTo(g+Math.ceil(i*a),h+Math.ceil(j*a)),l>k&&b(m)}.bind(this);m()}},d.scrollToElement=function(a,b,c,d){var f=e(this),g=this.scrollTop()+e(a).getBoundingClientRect().top-b;f instanceof HTMLElement&&(g-=f.getBoundingClientRect().top),this.scrollTo(0,g,c,d)},d.scrollLeft=function(b,c,d){if(angular.isNumber(b))return this.scrollTo(b,this.scrollTop(),c,d);var f=e(this);return f instanceof HTMLDocument?a.scrollX||document.documentElement.scrollLeft||document.body.scrollLeft:f.scrollLeft},d.scrollTop=function(b,c,d){if(angular.isNumber(b))return this.scrollTo(this.scrollTop(),b,c,d);var f=e(this);return f instanceof HTMLDocument?a.scrollY||document.documentElement.scrollTop||document.body.scrollTop:f.scrollTop}}]),angular.module("duScroll.requestAnimation",[]).factory("requestAnimation",["$window","$timeout",function(a,b){return a.requestAnimationFrame||a.webkitRequestAnimationFrame||a.mozRequestAnimationFrame||a.oRequestAnimationFrame||a.msRequestAnimationFrame||function(a){b(a,1e3/60)}}]),angular.module("duScroll.spyAPI",["duScroll.scrollContainerAPI"]).factory("spyAPI",["$rootScope","scrollContainerAPI",function(a,b){var c=function(b){return function(){var c=b.container,d=c[0],e=0;d instanceof HTMLElement&&(e=d.getBoundingClientRect().top);var f,g,h,i,j,k;for(i=b.spies,g=b.currentlyActive,h=void 0,f=0;fa?Math.pow(2*a,2)/2:1-Math.pow(2*(1-a),2)/2};angular.module("duScroll",["duScroll.scrollspy","duScroll.requestAnimation","duScroll.smoothScroll","duScroll.scrollContainer","duScroll.scrollHelpers"]).value("duScrollDuration",1e3).value("duScrollEasing",duScrollDefaultEasing),angular.module("duScroll.scrollHelpers",[]).run(["$window","requestAnimation","duScrollEasing",function(a,b,c){var d=angular.element.prototype;this.$get=function(){return d};var e=function(a){return"undefined"!=typeof HTMLDocument&&a instanceof HTMLDocument||a.nodeType&&a.nodeType===a.DOCUMENT_NODE},f=function(a){return"undefined"!=typeof HTMLElement&&a instanceof HTMLElement||a.nodeType&&a.nodeType===a.ELEMENT_NODE},g=function(a){return f(a)||e(a)?a:a[0]};d.scrollTo=function(b,c,d){if(angular.isElement(b))return this.scrollToElement(b,0,c,d);if(d)return this.scrollToAnimated.apply(this,arguments);var f=g(this);return e(f)?a.scrollTo(b,c):(f.scrollLeft=b,f.scrollTop=c,void 0)},d.scrollToAnimated=function(a,d,e,f){e&&!f&&(f=c);var g=this.scrollLeft(),h=this.scrollTop(),i=Math.round(a-g),j=Math.round(d-h);if(i||j){var k=0,l=Math.ceil(e/60),m=function(){k++;var a=k===l?1:f(k/l);this.scrollTo(g+Math.ceil(i*a),h+Math.ceil(j*a)),l>k&&b(m)}.bind(this);m()}},d.scrollToElement=function(a,b,c,d){var e=g(this),h=this.scrollTop()+g(a).getBoundingClientRect().top-b;f(e)&&(h-=e.getBoundingClientRect().top),this.scrollTo(0,h,c,d)},d.scrollLeft=function(b,c,d){if(angular.isNumber(b))return this.scrollTo(b,this.scrollTop(),c,d);var f=g(this);return e(f)?a.scrollX||document.documentElement.scrollLeft||document.body.scrollLeft:f.scrollLeft},d.scrollTop=function(b,c,d){if(angular.isNumber(b))return this.scrollTo(this.scrollTop(),b,c,d);var f=g(this);return e(f)?a.scrollY||document.documentElement.scrollTop||document.body.scrollTop:f.scrollTop}}]),angular.module("duScroll.requestAnimation",[]).factory("requestAnimation",["$window","$timeout",function(a,b){return a.requestAnimationFrame||a.webkitRequestAnimationFrame||a.mozRequestAnimationFrame||a.oRequestAnimationFrame||a.msRequestAnimationFrame||function(a){b(a,1e3/60)}}]),angular.module("duScroll.spyAPI",["duScroll.scrollContainerAPI"]).factory("spyAPI",["$rootScope","scrollContainerAPI",function(a,b){var c=function(b){return function(){var c=b.container,d=c[0],e=0;d instanceof HTMLElement&&(e=d.getBoundingClientRect().top);var f,g,h,i,j,k;for(i=b.spies,g=b.currentlyActive,h=void 0,f=0;f