UNPKG

insight-ui-crown

Version:

An open-source frontend for the Insight API. The Insight API provides you with a convenient, powerful and simple way to query and broadcast data on the Crown network and build your own services with it.

57 lines (51 loc) 1.48 kB
'use strict'; angular.module('insight') .directive('scroll', function ($window) { return function(scope, element, attrs) { angular.element($window).bind('scroll', function() { if (this.pageYOffset >= 200) { scope.secondaryNavbar = true; } else { scope.secondaryNavbar = false; } scope.$apply(); }); }; }) .directive('whenScrolled', function($window) { return { restric: 'A', link: function(scope, elm, attr) { var pageHeight, clientHeight, scrollPos; $window = angular.element($window); var handler = function() { pageHeight = window.document.documentElement.scrollHeight; clientHeight = window.document.documentElement.clientHeight; scrollPos = window.pageYOffset; if (pageHeight - (scrollPos + clientHeight) === 0) { scope.$apply(attr.whenScrolled); } }; $window.on('scroll', handler); scope.$on('$destroy', function() { return $window.off('scroll', handler); }); } }; }) .directive('focus', function ($timeout) { return { scope: { trigger: '@focus' }, link: function (scope, element) { scope.$watch('trigger', function (value) { if (value === "true") { $timeout(function () { element[0].focus(); }); } }); } }; });