[Pkg-mozext-commits] [greasemonkey] 18/62: Update addons4-overlay.js

David Prévot taffit at moszumanska.debian.org
Sun Sep 13 22:10:21 UTC 2015


This is an automated email from the git hooks/post-receive script.

taffit pushed a commit to branch master
in repository greasemonkey.

commit 55820c14de40c8c5bdd575e20f7e628cac2ab278
Author: janekptacijarabaci <janekptacijarabaci at users.noreply.github.com>
Date:   Thu Mar 26 12:28:50 2015 +0100

    Update addons4-overlay.js
---
 content/addons4-overlay.js | 58 ++++++++++++++++++++++++++++++++++++++++++----
 1 file changed, 53 insertions(+), 5 deletions(-)

diff --git a/content/addons4-overlay.js b/content/addons4-overlay.js
index 501e78e..0917387 100644
--- a/content/addons4-overlay.js
+++ b/content/addons4-overlay.js
@@ -4,11 +4,17 @@
 (function private_scope() {
 Components.utils.import("resource://gre/modules/AddonManager.jsm");
 Components.utils.import("chrome://greasemonkey-modules/content/addons4.js");
+Components.utils.import("chrome://greasemonkey-modules/content/prefmanager.js");
 Components.utils.import('chrome://greasemonkey-modules/content/third-party/droppedUrls.js');
 Components.utils.import('chrome://greasemonkey-modules/content/util.js');
 
 var userScriptViewId = 'addons://list/greasemonkey-user-script';
 
+var sortByValueDef = 'uiState,name';
+var sortByCheckStateReverse = '!';
+var sortByCheckStateValueAscending = '2';
+var sortByCheckStateValueDescending = '1';
+
 window.addEventListener('focus', focus, false);
 window.addEventListener('load', init, false);
 window.addEventListener('unload', unload, false);
@@ -192,6 +198,41 @@ function init() {
   applySort();
 };
 
+function getSortBy(buttons) {
+
+  var sortBy = GM_prefRoot.getValue('sortBy', sortByValueDef);
+  var sortByValue = sortBy.replace(sortByCheckStateReverse, '');
+  var sortByCheckStateAscending =
+      !(sortByCheckStateReverse == sortBy.substring(0, 1));
+
+  // Remove checkState from all buttons.
+  for (var i = 0, el = null; el = buttons[i]; i++) {
+    el.removeAttribute('checkState');
+  }
+
+  for (var i = 0, button = null; button = buttons[i]; i++) {
+    if (button.getAttribute('sortBy') == sortByValue) {
+      button.setAttribute('checkState',
+      (sortByCheckStateAscending ? sortByCheckStateValueAscending
+                                 : sortByCheckStateValueDescending));
+      break;
+    }
+  }
+
+  return button;
+
+}
+
+function setSortBy(button) {
+
+  var ascending = sortByCheckStateValueDescending
+                  != button.getAttribute('checkState');
+
+  GM_prefRoot.setValue('sortBy',
+      (!ascending ? sortByCheckStateReverse : '') + button.getAttribute('sortBy'));
+
+}
+
 function onSortersClicked(aEvent) {
   if ('button' != aEvent.target.tagName) return;
   var button = aEvent.target;
@@ -206,28 +247,35 @@ function onSortersClicked(aEvent) {
   }
 
   // Toggle state of this button.
-  if ('2' == checkState) {
-    button.setAttribute('checkState', '1');
+  if (sortByCheckStateValueAscending == checkState) {
+    button.setAttribute('checkState', sortByCheckStateValueDescending);
   } else {
-    button.setAttribute('checkState', '2');
+    button.setAttribute('checkState', sortByCheckStateValueAscending);
   }
 
+  setSortBy(button);
+
   applySort();
 };
 
 function applySort() {
   if (userScriptViewId != gViewController.currentViewId) return;
 
-  // Find checked button.
   var buttons = document.getElementById('greasemonkey-sort-bar')
     .getElementsByTagName('button');
+
+  var button = getSortBy(buttons);
+
+  // Find checked button.
   for (var i = 0, button = null; button = buttons[i]; i++) {
     if (button.hasAttribute('checkState')) break;
   }
 
-  var ascending = '1' != button.getAttribute('checkState');
+  var ascending = sortByCheckStateValueDescending != button.getAttribute('checkState');
   var sortBy = button.getAttribute('sortBy').split(',');
 
+  setSortBy(button);
+
   var list = document.getElementById('addon-list');
   var elements = Array.slice(list.childNodes, 0);
   sortElements(elements, sortBy, ascending);

-- 
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/pkg-mozext/greasemonkey.git



More information about the Pkg-mozext-commits mailing list