|
| 1 | +;(function() { |
| 2 | + 'use strict'; |
| 3 | + |
| 4 | + angular |
| 5 | + .module('fullPage.js', []) |
| 6 | + .directive('fullPage', fullPage); |
| 7 | + |
| 8 | + fullPage.$inject = ['$timeout', '$window']; |
| 9 | + |
| 10 | + function fullPage($timeout, $window) { |
| 11 | + var directive = { |
| 12 | + restrict: 'A', |
| 13 | + scope: {options: '='}, |
| 14 | + link: link |
| 15 | + }; |
| 16 | + |
| 17 | + return directive; |
| 18 | + |
| 19 | + function link(scope, element, attrs) { |
| 20 | + |
| 21 | + var rebuild = function() { |
| 22 | + destroyFullPage(); |
| 23 | + |
| 24 | + angular.element(element).fullpage(sanatizeOptions(scope.options)); |
| 25 | + }; |
| 26 | + |
| 27 | + var destroyFullPage = function() { |
| 28 | + if ($.fn.fullpage.destroy) { |
| 29 | + $.fn.fullpage.destroy('all'); |
| 30 | + } |
| 31 | + }; |
| 32 | + |
| 33 | + var sanatizeOptions = function(options) { |
| 34 | + if (options && options.navigation) { |
| 35 | + options.afterRender = function() { |
| 36 | + |
| 37 | + //We want to remove the HREF targets for navigation because they use hashbang |
| 38 | + //They still work without the hash though, so its all good. |
| 39 | + $('#fp-nav').find('a').removeAttr('href'); |
| 40 | + }; |
| 41 | + } |
| 42 | + |
| 43 | + //if we are using a ui-router, we need to be able to handle anchor clicks without 'href="#thing"' |
| 44 | + $(document).on('click', '[data-menuanchor]', function () { |
| 45 | + $.fn.fullpage.moveTo($(this).attr('data-menuanchor')); |
| 46 | + }); |
| 47 | + |
| 48 | + return options; |
| 49 | + }; |
| 50 | + |
| 51 | + scope.$watch('options', rebuild, true); |
| 52 | + |
| 53 | + element.on('$destroy', destroyFullPage); |
| 54 | + } |
| 55 | + } |
| 56 | + |
| 57 | +})(); |
0 commit comments