forked from oblador/angular-scroll
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathangular-scroll.min.js
2 lines (2 loc) · 4.72 KB
/
angular-scroll.min.js
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.scroller","duScroll.scrollPosition","duScroll.scrollspy","duScroll.requestAnimation","duScroll.smoothScroll"]).value("duScrollDuration",1e3).value("duScrollEasing",duScrollDefaultEasing),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.scrollPosition",["duScroll.requestAnimation"]).factory("scrollPosition",["$document","$window","$rootScope","$timeout","requestAnimation",function(a,b,c,d,e){var f,g,h=function(a){return a?a.scrollTop():b.scrollY||document.documentElement.scrollTop||document.body.scrollTop},i=function(a){return a?a.scrollLeft():b.scrollX||document.documentElement.scrollLeft||document.body.scrollLeft},j=[],k=function(){g=f,c.$emit("$duScrollChanged",g);for(var a=0;a<j.length;a++)j[a](g)},l=function(){f=h(),f!==g&&e(k)};angular.element(a).on("scroll",l).triggerHandler("scroll");var m=!1;return{observe:function(a){!m&&console&&console.warn&&(console.warn("scrollPosition.observe is deprecated, use $rootScope.$on('$duScrollChanged') instead"),m=!0),j.push(a)},x:i,y:h}}]),angular.module("duScroll.scroller",["duScroll.requestAnimation"]).factory("scroller",["$window","requestAnimation","scrollPosition","duScrollEasing",function(a,b,c,d){function e(e,f,g,h){if(!g)return void(h?(h.scrollLeft(e),h.scrollTop(f)):a.scrollTo(e,f));var i={y:c.y(h),x:c.x(h)},j={y:Math.round(f-i.y),x:Math.round(e-i.x)};if(j.x||j.y){var k=0,l=Math.ceil(g/60),m=function(){k++;var c=k===l?1:d(k/l);h?(h.scrollLeft(i.x+Math.ceil(j.x*c)),h.scrollTop(i.y+Math.ceil(j.y*c))):a.scrollTo(i.x+Math.ceil(j.x*c),i.y+Math.ceil(j.y*c)),l>k&&b(m)};m()}}function f(a,b,d,f){e(c.x(f)+(a||0),c.y(f)+(b||0),d,f)}function g(a,b,c,d){if(angular.isElement(a)&&(a=a[0]||a,a.getBoundingClientRect)){var e=a.getBoundingClientRect();f(0,e.top+(!b||isNaN(b)?0:-b),c,d)}}return{scrollTo:e,scrollToElement:g,scrollDelta:f}}]),angular.module("duScroll.smoothScroll",["duScroll.scroller"]).directive("duSmoothScroll",["scroller","duScrollDuration",function(a,b){return{link:function(c,d,e){var f=angular.element(d[0]);f.on("click",function(c){if(e.href&&-1!==e.href.indexOf("#")){var d=document.getElementById(e.href.replace(/.*(?=#[^\s]+$)/,"").substring(1));if(d&&d.getBoundingClientRect){c.stopPropagation&&c.stopPropagation(),c.preventDefault&&c.preventDefault();var f=-(e.offset?parseInt(e.offset,10):0),g=e.duration?parseInt(e.duration,10):b,h=d.getBoundingClientRect();a.scrollDelta(0,h.top+(isNaN(f)?0:f),g)}}})}}}]),angular.module("duScroll.scrollspy",["duScroll.scrollPosition"]).factory("duSpyAPI",["$rootScope","scrollPosition",function(a){var b={},c=!1,d=function(a){var c=a.$id;return b[c]={spies:[]},c},e=d(a),f=function(){var c,d,e,f,g,h,i,j;for(d in b){for(e=b[d],h=e.spies,f=e.currentlyActive,g=void 0,c=0;c<h.length;c++)i=h[c],j=i.getTargetPosition(),j&&j.top+i.offset<20&&-1*j.top<j.height&&(!g||g.top<j.top)&&(g={top:j.top,spy:i});g&&(g=g.spy),f!==g&&(f&&(f.$element.removeClass("active"),a.$broadcast("duScrollspy:becameInactive",f.$element)),g&&(g.$element.addClass("active"),a.$broadcast("duScrollspy:becameActive",g.$element)),e.currentlyActive=g)}},g=function(a){return b[a.$id]?b[a.$id]:a.$parent?g(a.$parent):b[e]},h=function(a){return g(a.$element.scope())},i=function(b){c||(a.$on("$duScrollChanged",f),c=!0),h(b).spies.push(b)},j=function(a){var b=h(a);a===b.currentlyActive&&(b.currentlyActive=null);var c=b.spies.indexOf(a);-1!==c&&b.spies.splice(c,1)};return{addSpy:i,removeSpy:j,createContext:d}}]).directive("duSpyContext",["duSpyAPI",function(a){return{restrict:"A",scope:!0,compile:function(){return{pre:function(b){a.createContext(b)}}}}}]).directive("duScrollspy",["duSpyAPI",function(a){var b=function(a,b,c){angular.isElement(a)?this.target=a:angular.isString(a)&&(this.targetId=a),this.$element=b,this.offset=c};return b.prototype.getTargetElement=function(){return!this.target&&this.targetId&&(this.target=document.getElementById(this.targetId)),this.target},b.prototype.getTargetPosition=function(){var a=this.getTargetElement();return a?a.getBoundingClientRect():void 0},b.prototype.flushTargetCache=function(){this.targetId&&(this.target=void 0)},{link:function(c,d,e){var f,g=e.ngHref||e.href;if(g&&-1!==g.indexOf("#")?f=g.replace(/.*(?=#[^\s]+$)/,"").substring(1):e.duScrollspy&&(f=e.duScrollspy),f){var h=new b(f,d,-(e.offset?parseInt(e.offset,10):0));a.addSpy(h),c.$on("$destroy",function(){a.removeSpy(h)}),c.$on("$locationChangeSuccess",h.flushTargetCache.bind(h))}}}}]);
//# sourceMappingURL=angular-scroll.min.js.map