-
Notifications
You must be signed in to change notification settings - Fork 0
/
ng-front-page.min.js
executable file
·1 lines (1 loc) · 3.57 KB
/
ng-front-page.min.js
1
!function(){"use strict";angular.module("ngFrontPage",["duScroll"]).service("frontPageService",["$document","$rootScope","$timeout","$window",function(a,b,c,d){var e,f,g=angular.element(a[0].body),h=angular.element(g.parent()),i=[],j={enabled:!1,scrollCapture:!1,activeElementIndex:null,aligned:!1,enable:function(){j.enabled||(g.addClass("front-page-enabled"),h.addClass("front-page-init"),b.$broadcast("front-page-initialized"),a.on("scroll",m),a.on("keydown",o),angular.element(d).bind("resize",k),j.enabled=!0,i=[])},destroy:function(){g.removeClass("front-page-enabled"),h.removeClass("front-page-init"),b.$broadcast("front-page-destroyed"),a.off("scroll",m),angular.element(a).off("keydown",o),angular.element(d).bind("resize",k)},registerFullPage:function(b){i.push(b),j.safeScroll(a.scrollTop())},safeScroll:function(b,d,f){if(!j.aligned){a.off("scroll",m),c.cancel(e),e=c(function(){a.on("scroll",m)},500);for(var g=0;g<i.length;g++){var h=i[g];if("up"===d&&b>=h.offsetTop&&b<h.offsetTop+h.clientHeight||"up"!==d&&h.offsetTop>=b&&h.offsetTop<b+h.clientHeight){j.activeElementIndex=g,j.scrollCapture=!0,j.align=!0;break}j.scrollCapture=!1}var k=j.scrollCapture?i[j.activeElementIndex].offsetTop:b;a.scrollTop(k,350).then(function(){c.cancel(e),a.on("scroll",m)})}}},k=function(){j.safeScroll(a.scrollTop())},l=function(a,b){var c;a>b&&(c="down"),b>a&&(c="up"),j.align=!1,j.safeScroll(a,c),f=null},m=function(b){var d=a.scrollTop(),e=d,g=function(){var b=a.scrollTop();b===e?(c.cancel(f),f=void 0,l(b,d)):(f=c(g,50),e=b)};f||(f=c(g,50))},n=function(a,b){a.preventDefault(),j.scrollCapture&&angular.element(i[j.activeElementIndex]).triggerHandler("move-"+b)},o=function(a){if(j.scrollCapture){var b=a.charCode||a.keyCode;37===b&&n(a,"left"),39===b&&(a.preventDefault(),n(a,"right"))}};return j}]).directive("frontPage",["$window","$document","frontPageService","$timeout",function(a,b,c,d){return{restrict:"A",link:function(a,b){a.settings={activeSlide:0,slideRange:[0,1],slideCount:2},a.slideController={ready:function(a){},goSlide:function(b){a.settings.activeSlide=b,a.$broadcast("change-slide",{slide:b})},nextSlide:function(){a.settings.activeSlide=(a.settings.activeSlide+1)%a.settings.slideCount,a.$broadcast("change-slide",{slide:a.settings.activeSlide})},previousSlide:function(){a.settings.activeSlide=(a.settings.activeSlide-1+a.settings.slideCount)%a.settings.slideCount,a.$broadcast("change-slide",{slide:a.settings.activeSlide})}},b.on("move-left",function(){a.slideController.previousSlide(),a.$apply()}),b.on("move-right",function(){a.slideController.nextSlide(),a.$apply()}),d(function(){c.enable(),c.registerFullPage(b[0])}),a.$on("$destroy",function(){b.off("move-left"),b.off("move-right")})}}}]).directive("slideContainer",["$window","$document","$timeout",function(a,b,c){return{restrict:"C",link:function(a,b){var d=b.children(),e=d.length;c(function(){e>1&&(b[0].style.width=100*e+"%",angular.forEach(d,function(a){a.style.width=100/e+"%"}),a.slideController.ready({count:e}))}),a.$on("change-slide",function(a,c){angular.isNumber(c.slide)&&(b[0].style["margin-left"]="-"+100*c.slide+"%")})}}}]).directive("horizontalNav",[function(){return{restrict:"C",template:'<a href="javascript:;" data-ng-repeat="i in settings.slideRange" data-ng-class="{\'active\': i === settings.activeSlide}" data-ng-click="slideController.goSlide(i)"></a>'}}]).directive("prevButton",[function(){return{restrict:"C",template:'<a href="javascript:;" data-ng-click="slideController.previousSlide()"></a>'}}]).directive("nextButton",[function(){return{restrict:"C",template:'<a href="javascript:;" data-ng-click="slideController.nextSlide()"></a>'}}])}();