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() {
}
}
- $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();
}
$scope.reset();
}
+ $scope.setActive = function(index) {
+ $scope.activeItem = index;
+ }
+
$scope.search = function() {
if(!$scope.query) {
$scope.reset();
$scope.reset();
}])
+ .directive('searchCard', function() {
+ return {
+ restrict: 'E',
+ scope: {
+ mentity: '='
+ },
+ replace: true,
+ templateUrl: '/directives/search/card.html'
+ };
+ })
+
.directive('uiFilters', function() {
return {
restrict: 'E',
};
})
+ .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',