X-Git-Url: http://nitlanguage.org diff --git a/share/nitweb/javascripts/ui.js b/share/nitweb/javascripts/ui.js index cd30d06..e9f91d2 100644 --- a/share/nitweb/javascripts/ui.js +++ b/share/nitweb/javascripts/ui.js @@ -18,7 +18,7 @@ angular .module('ui', [ 'model' ]) - .controller('SearchCtrl', ['Model', '$routeParams', '$scope', '$window', function(Model, $routeParams, $scope, $window) { + .controller('SearchCtrl', ['Model', '$routeParams', '$scope', '$location', function(Model, $routeParams, $scope, $location) { $scope.query = ''; $scope.reset = function() { @@ -50,8 +50,8 @@ } } - $scope.selectEnter = function() { - $window.location.href = $scope.results[$scope.activeItem].web_url; + $scope.selectEnter = function(e) { + $location.url($scope.results[$scope.activeItem].web_url); $scope.reset(); } @@ -59,6 +59,10 @@ $scope.reset(); } + $scope.setActive = function(index) { + $scope.activeItem = index; + } + $scope.search = function() { if(!$scope.query) { $scope.reset(); @@ -77,6 +81,17 @@ $scope.reset(); }]) + .directive('searchCard', function() { + return { + restrict: 'E', + scope: { + mentity: '=' + }, + replace: true, + templateUrl: '/directives/search/card.html' + }; + }) + .directive('uiFilters', function() { return { restrict: 'E', @@ -114,6 +129,61 @@ }; }) + .directive('uiSummary', function($rootScope, $location, $anchorScroll) { + return { + restrict: 'E', + scope: { + target: '@' + }, + replace: true, + templateUrl: '/directives/ui-summary.html', + link: function ($scope, element, attrs) { + $scope.goTo = function(entity) { + $location.hash(entity.id); + } + + $scope.textToId = function(text) { + return text.replace(/ /g, '-').replace(/[^A-Za-z_-]/g, ''); + } + + $rootScope.reloadSummary = function() { + var h = angular.element(document.querySelectorAll( + $scope.target + ' h1, ' + + $scope.target + ' h2, ' + + $scope.target + ' h3, ' + + $scope.target + ' h4, ' + + $scope.target + ' h5, ' + + $scope.target + ' h6 ')); + + $scope.headings = []; + angular.forEach(h, function(heading) { + var head = angular.element(heading); + if(!head.is(':visible')) { return ; } + var text = head.text().trim(); + var id = $scope.textToId(text); + if(!head.attr('id')) { + head.attr('id', id); + } else { + id = head.attr('id'); + } + $scope.headings.push({ + id: id, + text: text, + level: parseInt(head[0].nodeName[1]) + }); + }); + $anchorScroll(); + } + + $scope.$watch('target', function() { + setTimeout(function() { + $rootScope.reloadSummary(); + }, 100); + }); + } + }; + }) + .directive('uiFilterForm', function() { return { restrict: 'E',