diff options
author | gorhill <rhill@raymondhill.net> | 2015-08-11 15:29:14 -0400 |
---|---|---|
committer | gorhill <rhill@raymondhill.net> | 2015-08-11 15:29:14 -0400 |
commit | 690421aead701cb3045c1d8913cb85d432e494c3 (patch) | |
tree | 3c3fb062385ce409240d224d19c84a378ce3dca8 /src/js/3p-filters.js | |
parent | a7712116a78890924971b219ff49e75ef194cf00 (diff) | |
download | uBlock-690421aead701cb3045c1d8913cb85d432e494c3.zip uBlock-690421aead701cb3045c1d8913cb85d432e494c3.tar.gz uBlock-690421aead701cb3045c1d8913cb85d432e494c3.tar.bz2 |
sync feature (#80): draft
Diffstat (limited to 'src/js/3p-filters.js')
-rw-r--r-- | src/js/3p-filters.js | 78 |
1 files changed, 63 insertions, 15 deletions
diff --git a/src/js/3p-filters.js b/src/js/3p-filters.js index ebf6ac6..ac6abcf 100644 --- a/src/js/3p-filters.js +++ b/src/js/3p-filters.js @@ -495,7 +495,7 @@ var externalListsChangeHandler = function() { /******************************************************************************/ var externalListsApplyHandler = function() { - externalLists = uDom('#externalLists').val(); + externalLists = uDom.nodeFromId('externalLists').value; messager.send({ what: 'userSettings', name: 'externalLists', @@ -520,21 +520,69 @@ var groupEntryClickHandler = function() { /******************************************************************************/ -uDom.onLoad(function() { - uDom('#autoUpdate').on('change', autoUpdateCheckboxChanged); - uDom('#parseCosmeticFilters').on('change', cosmeticSwitchChanged); - uDom('#buttonApply').on('click', buttonApplyHandler); - uDom('#buttonUpdate').on('click', buttonUpdateHandler); - uDom('#buttonPurgeAll').on('click', buttonPurgeAllHandler); - uDom('#lists').on('change', '.listEntry > input', onListCheckboxChanged); - uDom('#lists').on('click', 'span.purge', onPurgeClicked); - uDom('#externalLists').on('input', externalListsChangeHandler); - uDom('#externalListsApply').on('click', externalListsApplyHandler); - uDom('#lists').on('click', '.groupEntry > span', groupEntryClickHandler); +var getCloudData = function() { + var bin = { + parseCosmeticFilters: uDom.nodeFromId('parseCosmeticFilters').checked, + selectedLists: [], + externalLists: externalLists + }; - renderFilterLists(); - renderExternalLists(); -}); + var lis = uDom('#lists .listEntry'), li; + var i = lis.length; + while ( i-- ) { + li = lis.at(i); + if ( li.descendants('input').prop('checked') ) { + bin.selectedLists.push(li.descendants('a').attr('data-listkey')); + } + } + + return bin; +}; + +var setCloudData = function(data) { + if ( typeof data !== 'object' || data === null ) { + return; + } + + var checked = data.parseCosmeticFilters === true; + uDom.nodeFromId('parseCosmeticFilters').checked = checked; + listDetails.cosmetic = checked; + + var lis = uDom('#lists .listEntry'), li, input, listKey; + var i = lis.length; + while ( i-- ) { + li = lis.at(i); + input = li.descendants('input'); + listKey = li.descendants('a').attr('data-listkey'); + checked = data.selectedLists.indexOf(listKey) !== -1; + input.prop('checked', checked); + listDetails.available[listKey].off = !checked; + } + + uDom.nodeFromId('externalLists').value = data.externalLists || ''; + + renderWidgets(); + externalListsChangeHandler(); +}; + +self.cloud.onPush = getCloudData; +self.cloud.onPull = setCloudData; + +/******************************************************************************/ + +uDom('#autoUpdate').on('change', autoUpdateCheckboxChanged); +uDom('#parseCosmeticFilters').on('change', cosmeticSwitchChanged); +uDom('#buttonApply').on('click', buttonApplyHandler); +uDom('#buttonUpdate').on('click', buttonUpdateHandler); +uDom('#buttonPurgeAll').on('click', buttonPurgeAllHandler); +uDom('#lists').on('change', '.listEntry > input', onListCheckboxChanged); +uDom('#lists').on('click', 'span.purge', onPurgeClicked); +uDom('#externalLists').on('input', externalListsChangeHandler); +uDom('#externalListsApply').on('click', externalListsApplyHandler); +uDom('#lists').on('click', '.groupEntry > span', groupEntryClickHandler); + +renderFilterLists(); +renderExternalLists(); /******************************************************************************/ |