forked from loklak/apps.loklak.org
-
Notifications
You must be signed in to change notification settings - Fork 0
/
app_list.js
65 lines (60 loc) · 2.28 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
var app = angular.module('appListApp', ['loklak', 'ngTouch']);
app.controller("app_list", function ($scope, $http) {
$scope.apps = [];
$scope.categoryKeys = [];
var suggestionList = [];
$scope.category = null;
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();
}
}
});
app.filter('nospace', function () {
return function (value) {
return (!value) ? '' : value.replace(/ /g, '');
};
});