diff options
Diffstat (limited to 'js/popup.js')
-rw-r--r-- | js/popup.js | 94 |
1 files changed, 33 insertions, 61 deletions
diff --git a/js/popup.js b/js/popup.js index c27a29f..36d0685 100644 --- a/js/popup.js +++ b/js/popup.js @@ -1,71 +1,43 @@ -angular.module('popupApp', []).controller('PopupCtrl', ['$scope', function($s) { - var storage = chrome.storage.local; //TODO: Change to sync when Firefox supports it... - - storage.get({disabled:false}, function(obj) { - $s.disabled = obj.disabled; - $s.$apply(); - }); +var storage = chrome.storage.local; +var viewModel = {}; //Just an object for the databinding - $s.toggleDisabled = function() { - storage.get({disabled:false}, function(obj) { - storage.set({disabled:!obj.disabled}); - $s.disabled = !obj.disabled; - $s.$apply(); - }); - }; - +function applyBinding() { + dataBind(document.body, viewModel); +} - storage.get({logging:false}, function(obj) { - $s.logging = obj.logging; - $s.$apply(); +function toggle(prop) { + storage.get({[prop]: false}, function(obj) { + storage.set({[prop] : !obj[prop]}); + viewModel[prop] = !obj[prop]; + applyBinding(); }); +} - $s.toggleLogging = function() { - storage.get({logging:false}, function(obj) { - storage.set({logging:!obj.logging}); - $s.logging = !obj.logging; - $s.$apply(); - }); - }; - - - //Toggle Notifications by sending a notifications - $s.enableNotifications = false; - - storage.get({enableNotifications:false},function(obj){ - $s.enableNotifications = obj.enableNotifications; - $s.$apply(); - }); - - $s.toggleNotifications=function(){ - storage.get({enableNotifications:false},function(obj){ - storage.set({enableNotifications:!obj.enableNotifications}); - $s.enableNotifications = !obj.enableNotifications; - $s.$apply(); - }); - } +storage.get({logging:false, enableNotifications:false, disabled: false}, function(obj) { + viewModel = obj; + applyBinding(); +}) - $s.openRedirectorSettings = function() { +function openRedirectorSettings() { - //switch to open one if we have it to minimize conflicts - var url = chrome.extension.getURL('redirector.html'); - - //FIREFOXBUG: Firefox chokes on url:url filter if the url is a moz-extension:// url - //so we don't use that, do it the more manual way instead. - chrome.tabs.query({currentWindow:true}, function(tabs) { - for (var i=0; i < tabs.length; i++) { - if (tabs[i].url == url) { - chrome.tabs.update(tabs[i].id, {active:true}, function(tab) { - close(); - }); - return; - } + //switch to open one if we have it to minimize conflicts + var url = chrome.extension.getURL('redirector.html'); + + //FIREFOXBUG: Firefox chokes on url:url filter if the url is a moz-extension:// url + //so we don't use that, do it the more manual way instead. + chrome.tabs.query({currentWindow:true}, function(tabs) { + for (var i=0; i < tabs.length; i++) { + if (tabs[i].url == url) { + chrome.tabs.update(tabs[i].id, {active:true}, function(tab) { + close(); + }); + return; } + } - chrome.tabs.create({url:url, active:true}); - }); - return; - }; -}]);
\ No newline at end of file + chrome.tabs.create({url:url, active:true}); + }); + return; +}; |