This repository has been archived by the owner on Aug 11, 2021. It is now read-only.
forked from Tiffney/UrNEU
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathswitch.js
70 lines (54 loc) · 1.91 KB
/
switch.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
var app = angular.module('instantSearch', ['angular.css.injector']);
var viewURL = chrome.runtime.getURL('view.html');
var container = document.createElement('span');
var shadowRoot = document.documentElement.createShadowRoot();
shadowRoot.appendChild(container);
//Switching
app.controller('switchCtrl', ['$scope', function ($scope) {
$scope.state = 'off';
$scope.$on('switch', function () {
console.log('switching');
$scope.state = $scope.state === 'off' ? 'on' : 'off';
});
}]);
app.run(['$rootElement', '$rootScope', function ($rootElement, $rootScope) {
$rootElement.html('<ng-include src="\'' + viewURL + '\'" />');
chrome.runtime.onMessage.addListener(function (message, sender, sendResponse) {
console.log('got message', message);
if (message === 'switch') {
$rootScope.$broadcast('switch');
$rootScope.$apply();
}
});
}]);
//End Switching
//Custom app
var dataURL = chrome.runtime.getURL('data/allmyneu.json');
var demoCSSURL = chrome.runtime.getURL('css/demo.css');
app.controller("InstantSearchCtrl", function($scope, $http, cssInjector) {
$scope.styles = ['template1.css', 'template2.css'];
cssInjector.add(demoCSSURL);
$http.get(dataURL).
success(function(data, status, headers, config) {
$scope.data = data;
});
});
app.filter('searchFor', function(){
// {inputData:argument} here is (searchFor:searchString)
return function(arr, searchString){
if(!searchString){
return arr;
}
var result = [];
searchString = searchString.toLowerCase();
// Using the forEach helper method to loop through the array
angular.forEach(arr, function(item){
if(item.name.toLowerCase().indexOf(searchString) !== -1 || item.desc.toLowerCase().indexOf(searchString) !== -1){
result.push(item);
}
});
return result;
};
});
//End Custom app
angular.bootstrap(container, [app.name]);