-
Notifications
You must be signed in to change notification settings - Fork 1
/
app_list.js
83 lines (77 loc) · 2.97 KB
/
app_list.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
var app = angular.module('appListApp', ['loklak', 'ngTouch']);
app.controller("app_list", function ($scope, $http) {
$scope.apps = [];
$scope.categoryKeys = [];
var suggestionList = [];
$scope.category = null;
$scope.notFound = false;
var addr = window.location + "";
if (addr.indexOf("#") !== -1) {
$scope.category = addr.split('#')[1];
$('#categoryName')[0].innerHTML = $scope.category.match(/[A-Z][a-z]+/g).join(" ");
$scope.category = $scope.category.replace(/ /g, '');
$scope.category = $scope.category === "All" ? null : $scope.category;
}
$http.get('apps.json').success(function (data) {
$scope.categoryKeys = data.categories;
$scope.apps = data.apps;
$scope.categoryKeys.unshift({"name": "All","image":"all.png","style" : {"background-color": "#ED3B3B"}});
for (i = 0; i < $scope.apps.length; i++) {
suggestionList.push($scope.apps[i].name);
suggestionList.push($scope.apps[i].headline);
suggestionList.push($scope.apps[i].author.name);
}
var searchEngine = new Bloodhound({
datumTokenizer: Bloodhound.tokenizers.whitespace,
queryTokenizer: Bloodhound.tokenizers.whitespace,
local: suggestionList
});
// Initializing the typeahead
$('.typeahead').typeahead({
hint: true,
highlight: true, /* Enable substring highlighting */
minLength: 1 /* Specify minimum characters required for showing result */
},
{
name: 'apps',
source: searchEngine
});
});
$scope.categoryFilter = function (event) {
$scope.category = null;
item = event.target.id;
if (item != 'All') {
itemName = item.match(/[A-Z][a-z]+/g);
$('#categoryName')[0].innerHTML = itemName.join(" ");
$('div.span2').hide();
qConstruct = 'div.span2#'+item;
$(qConstruct).show();
event.stopImmediatePropagation();
}
else {
$('#categoryName')[0].innerHTML = 'All apps';
$('div.span2').show();
}
}
$scope.checkApp = function() {
for (var i = 0; i < $scope.apps.length; i++) {
var app = $scope.apps[i];
var searchTerm = $scope.searchTerm;
if (
((app.name.toUpperCase().indexOf(searchTerm.toUpperCase())!==-1) ||
(app.headline.toUpperCase().indexOf(searchTerm.toUpperCase())!==-1) ||
(app.author.name.toUpperCase().indexOf(searchTerm.toUpperCase())!==-1))) {
$scope.notFound = false;
$(".not-found").html("");
return;
}
}
$scope.notFound = true;
$(".not-found").html("No matching app found!");
}
});
app.filter('nospace', function () {
return function (value) {
return (!value) ? '' : value.replace(/ /g, '');
};
});