forked from jdart/who-cors
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathpopup.js
90 lines (75 loc) · 1.7 KB
/
popup.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
84
85
86
87
88
89
90
var app = angular.module('cors', ['ionic']);
app.constant('config', config);
app.controller('PopupCtrl', ['$scope', 'config', PopupCtrl]);
function PopupCtrl($scope, config) {
activate();
function reload() {
chrome.extension.getBackgroundPage().reload();
}
function persist(key) {
config.set(key, $scope[key]);
reload();
}
function activate() {
angular.extend($scope, config.defaults);
config.get(listen);
}
function watch(key) {
$scope.$watch(key, persist.bind(this, key));
}
function listen(config) {
angular.extend($scope, config);
$scope.$apply();
watch('active');
watch('allowMethods');
watch('exposeHeaders');
}
$scope.openInNewTab = function(url) {
chrome.tabs.create({ url: url });
};
$scope.addUrl = function() {
$scope.urls.unshift($scope.url);
persist('urls');
$scope.url = '';
};
$scope.removeUrl = function(index) {
$scope.urls.splice(index, 1);
persist('urls');
};
}
app.directive("textOption", function() {
return {
restrict: 'E',
scope: {
option: '=',
placeholder: '@'
},
templateUrl: 'text-option.html',
controller: function($scope) {
$scope.editing = false;
$scope.onEdit = function() {
$scope.editableOption = $scope.option;
$scope.editing = true;
};
$scope.onCancel = function() {
$scope.editing = false;
};
$scope.onSave = function() {
$scope.option = $scope.editableOption;
$scope.editing = false;
};
}
};
});
app.directive('submitOnEnter', function() {
return {
restrict: 'A',
link: function(scope, element, attrs) {
$(element).on('keydown', function(e) {
if (e.which == 13) {
$(element).parents('.item').find('.submit-action').trigger('click');
}
});
}
};
});