e9f91d27485273af6f935c500d44de39663b6151
2 * Copyright 2016 Alexandre Terrasa <alexandre@moz-code.org>.
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
8 * http://www.apache.org/licenses/LICENSE-2.0
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
19 .module('ui', [ 'model' ])
21 .controller('SearchCtrl', ['Model', '$routeParams', '$scope', '$location', function(Model
, $routeParams
, $scope
, $location
) {
24 $scope
.reset
= function() {
25 $scope
.activeItem
= 0;
29 $scope
.update
= function(e
) {
32 } else if(e
.keyCode
== 40) {
34 } else if(e
.keyCode
== 27) {
35 $scope
.selectEscape();
36 } else if(e
.keyCode
== 13) {
41 $scope
.selectUp
= function() {
42 if($scope
.activeItem
> 0) {
43 $scope
.activeItem
-= 1;
47 $scope
.selectDown
= function() {
48 if($scope
.activeItem
< $scope
.results
.length
- 1) {
49 $scope
.activeItem
+= 1;
53 $scope
.selectEnter
= function(e
) {
54 $location
.url($scope
.results
[$scope
.activeItem
].web_url
);
58 $scope
.selectEscape
= function() {
62 $scope
.setActive
= function(index
) {
63 $scope
.activeItem
= index
;
66 $scope
.search
= function() {
71 Model
.search($scope
.query
, 10,
74 $scope
.results
= data
;
84 .directive('searchCard', function() {
91 templateUrl
: '/directives/search/card.html'
95 .directive('uiFilters', function() {
104 templateUrl
: '/directives/ui-filter-button-vis.html',
105 link
: function ($scope
, element
, attrs
) {
106 $scope
.toggle
= function() {
107 $scope
.property
= !$scope
.property
;
113 .filter('visibility', function() {
114 return function(input
, visibilityFilter
) {
116 input
.forEach(function(entry
) {
117 if(visibilityFilter
.public == false && entry
.visibility
== "public") {
120 if(visibilityFilter
.protected == false && entry
.visibility
== "protected") {
123 if(visibilityFilter
.private == false && entry
.visibility
== "private") {
132 .directive('uiSummary', function($rootScope
, $location
, $anchorScroll
) {
139 templateUrl
: '/directives/ui-summary.html',
140 link
: function ($scope
, element
, attrs
) {
141 $scope
.goTo
= function(entity
) {
142 $location
.hash(entity
.id
);
145 $scope
.textToId
= function(text
) {
146 return text
.replace(/ /g
, '-').replace(/[^A
-Za
-z_
-]/g
, '');
149 $rootScope
.reloadSummary
= function() {
150 var h
= angular
.element(document
.querySelectorAll(
151 $scope
.target
+ ' h1, ' +
152 $scope
.target
+ ' h2, ' +
153 $scope
.target
+ ' h3, ' +
154 $scope
.target
+ ' h4, ' +
155 $scope
.target
+ ' h5, ' +
156 $scope
.target
+ ' h6 '));
158 $scope
.headings
= [];
159 angular
.forEach(h
, function(heading
) {
160 var head
= angular
.element(heading
);
161 if(!head
.is(':visible')) { return ; }
162 var text
= head
.text().trim();
163 var id
= $scope
.textToId(text
);
164 if(!head
.attr('id')) {
167 id
= head
.attr('id');
169 $scope
.headings
.push({
172 level
: parseInt(head
[0].nodeName
[1])
178 $scope
.$
watch('target', function() {
179 setTimeout(function() {
180 $rootScope
.reloadSummary();
187 .directive('uiFilterForm', function() {
192 visibilityFilter
: '='
195 templateUrl
: '/directives/ui-filter-form.html'
199 .directive('uiFilterField', function() {
206 templateUrl
: '/directives/ui-filter-field.html'
210 .directive('uiFilterGroupVis', function() {
217 templateUrl
: '/directives/ui-filter-group-vis.html'
221 .directive('uiFilterButtonVis', function() {
230 templateUrl
: '/directives/ui-filter-button-vis.html',
231 link
: function ($scope
, element
, attrs
) {
232 $scope
.toggle
= function() {
233 $scope
.property
= !$scope
.property
;