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.
21 .controller('SearchCtrl', function(Model
, $scope
, $location
, $document
) {
25 $scope
.reset
= function() {
26 $scope
.activeItem
= 0;
30 $scope
.update
= function(e
) {
33 } else if(e
.keyCode
== 40) {
35 } else if(e
.keyCode
== 27) {
36 $scope
.selectEscape();
37 } else if(e
.keyCode
== 13) {
42 $scope
.selectUp
= function() {
43 if($scope
.activeItem
> 0) {
44 $scope
.activeItem
-= 1;
48 $scope
.selectDown
= function() {
49 if($scope
.activeItem
< $scope
.results
.length
- 1) {
50 $scope
.activeItem
+= 1;
54 $scope
.selectEnter
= function(e
) {
55 $location
.url($scope
.results
[$scope
.activeItem
].web_url
);
59 $scope
.selectEscape
= function() {
63 $scope
.setActive
= function(index
) {
64 $scope
.activeItem
= index
;
67 $scope
.search
= function() {
72 Model
.search($scope
.query
, 10,
75 $scope
.results
= data
;
85 .directive('searchField', function($document
) {
89 controller
: 'SearchCtrl',
90 controllerAs
: 'searchCtrl',
91 templateUrl
: '/directives/search/field.html',
92 link
: function ($scope
, element
, attrs
) {
93 $document
.bind('click', function (event
) {
94 var isChild
= $
(element
).has(event
.target
).length
> 0;
95 var isSelf
= element
[0] == event
.target
;
96 var isInside
= isChild || isSelf
;
106 .directive('searchCard', function() {
113 templateUrl
: '/directives/search/card.html'
117 .directive('uiFilters', function() {
126 templateUrl
: '/directives/ui-filter-button-vis.html',
127 link
: function ($scope
, element
, attrs
) {
128 $scope
.toggle
= function() {
129 $scope
.property
= !$scope
.property
;
135 .filter('visibility', function() {
136 return function(input
, visibilityFilter
) {
138 input
.forEach(function(entry
) {
139 if(visibilityFilter
.public == false && entry
.visibility
== "public") {
142 if(visibilityFilter
.protected == false && entry
.visibility
== "protected") {
145 if(visibilityFilter
.private == false && entry
.visibility
== "private") {
154 .directive('uiSummary', function($rootScope
, $location
, $anchorScroll
) {
161 templateUrl
: '/directives/ui-summary.html',
162 link
: function ($scope
, element
, attrs
) {
163 $scope
.goTo
= function(entity
) {
164 $location
.hash(entity
.id
);
167 $scope
.textToId
= function(text
) {
168 return text
.replace(/ /g
, '-').replace(/[^A
-Za
-z_
-]/g
, '');
171 $rootScope
.reloadSummary
= function() {
172 var h
= angular
.element(document
.querySelectorAll(
173 $scope
.target
+ ' h1, ' +
174 $scope
.target
+ ' h2, ' +
175 $scope
.target
+ ' h3, ' +
176 $scope
.target
+ ' h4, ' +
177 $scope
.target
+ ' h5, ' +
178 $scope
.target
+ ' h6 '));
180 $scope
.headings
= [];
181 angular
.forEach(h
, function(heading
) {
182 var head
= angular
.element(heading
);
183 if(!head
.is(':visible')) { return ; }
184 var text
= head
.text().trim();
185 var id
= $scope
.textToId(text
);
186 if(!head
.attr('id')) {
189 id
= head
.attr('id');
191 $scope
.headings
.push({
194 level
: parseInt(head
[0].nodeName
[1])
200 $scope
.$
watch('target', function() {
201 setTimeout(function() {
202 $rootScope
.reloadSummary();
209 .directive('uiFilterForm', function() {
214 visibilityFilter
: '='
217 templateUrl
: '/directives/ui-filter-form.html'
221 .directive('uiFilterField', function() {
228 templateUrl
: '/directives/ui-filter-field.html'
232 .directive('uiFilterGroupVis', function() {
239 templateUrl
: '/directives/ui-filter-group-vis.html'
243 .directive('uiFilterButtonVis', function() {
252 templateUrl
: '/directives/ui-filter-button-vis.html',
253 link
: function ($scope
, element
, attrs
) {
254 $scope
.toggle
= function() {
255 $scope
.property
= !$scope
.property
;