'use strict'; var directivesModule = angular.module('directives', []); directivesModule /** * backToTop Directive * @param {Function} $anchorScroll * * @description Ensure that the browser scrolls when the anchor is clicked */ .directive('backToTop', ['$anchorScroll', '$location', function($anchorScroll, $location) { return function link(scope, element) { element.on('click', function(event) { $location.hash(''); scope.$apply($anchorScroll); }); }; }]) .directive('code', function() { return { restrict: 'E', terminal: true, compile: function(element) { var linenums = element.hasClass('linenum');// || element.parent()[0].nodeName === 'PRE'; var match = /lang-(\S+)/.exec(element[0].className); var lang = match && match[1]; var html = element.html(); element.html(window.prettyPrintOne(html, lang, linenums)); } }; }) .directive('scrollYOffsetElement', ['$anchorScroll', function($anchorScroll) { return function(scope, element) { $anchorScroll.yOffset = element; }; }]) .directive('table', function() { return { restrict: 'E', link: function(scope, element, attrs) { if (!attrs['class']) { element.addClass('table table-bordered table-striped code-table'); } } }; }) .directive('tocCollector', ['$rootScope', function($rootScope) { return { controller: ['$element', function($element) { /* eslint-disable no-invalid-this */ var ctrl = this; $rootScope.$on('$includeContentRequested', function() { ctrl.hs = []; ctrl.root = []; }); this.hs = []; this.root = []; this.element = $element; this.register = function(h) { var previousLevel; for (var i = ctrl.hs.length - 1; i >= 0; i--) { if (ctrl.hs[i].level === (h.level - 1)) { previousLevel = ctrl.hs[i]; break; } } if (previousLevel) { previousLevel.children.push(h); } else { this.root.push(h); } ctrl.hs.push(h); /* eslint-enable no-invalid-this */ }; }] }; }]) .component('tocTree', { template: '