Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(2599)

Unified Diff: chrome/browser/resources/md_extensions/manager.js

Issue 1447183005: [MD Extensions] Fix item sorting (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Michael's Created 5 years, 1 month ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « no previous file | chrome/browser/resources/md_extensions/service.js » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: chrome/browser/resources/md_extensions/manager.js
diff --git a/chrome/browser/resources/md_extensions/manager.js b/chrome/browser/resources/md_extensions/manager.js
index f7f94d83c77f69597c872471172c6c30a39e4ca7..0c5a2c35ad362e1b3dbf4b534f377183a8c753bc 100644
--- a/chrome/browser/resources/md_extensions/manager.js
+++ b/chrome/browser/resources/md_extensions/manager.js
@@ -3,30 +3,57 @@
// found in the LICENSE file.
cr.define('extensions', function() {
+ 'use strict';
+
+ /**
+ * Compares two extensions to determine which should come first in the list.
+ * @param {chrome.developerPrivate.ExtensionInfo} a
+ * @param {chrome.developerPrivate.ExtensionInfo} b
+ * @return {number}
+ */
+ var compareExtensions = function(a, b) {
+ function compare(x, y) {
+ return x < y ? -1 : (x > y ? 1 : 0);
+ }
+ function compareLocation(x, y) {
+ if (x.location == y.location)
+ return 0;
+ if (x.location == chrome.developerPrivate.Location.UNPACKED)
+ return -1;
+ if (y.location == chrome.developerPrivate.Location.UNPACKED)
+ return 1;
+ return 0;
+ }
+ return compareLocation(a, b) ||
+ compare(a.name.toLowerCase(), b.name.toLowerCase()) ||
+ compare(a.id, b.id);
+ };
+
var Manager = Polymer({
is: 'extensions-manager',
properties: {
+ /** @type {extensions.Sidebar} */
sidebar: {
type: Object,
}
},
ready: function() {
+ /** @type {extensions.Sidebar} */
this.sidebar = this.$$('extensions-sidebar');
extensions.Service.getInstance().managerReady(this);
this.sidebar.setScrollDelegate(new ScrollHelper(this));
},
/**
- * Creates and adds a new extensions-item element to the list.
+ * Creates and adds a new extensions-item element to the list, inserting it
+ * into its sorted position in the relevant section.
* @param {!chrome.developerPrivate.ExtensionInfo} extension The extension
* the item is representing.
* @param {!extensions.ItemDelegate} delegate The delegate for the item.
- * @param {!number=} opt_index The index at which to place the item. If
- * not present, the item is appended to the end of the list.
*/
- addItem: function(extension, delegate, opt_index) {
+ addItem: function(extension, delegate) {
var listId;
var ExtensionType = chrome.developerPrivate.ExtensionType;
switch (extension.type) {
@@ -49,9 +76,12 @@ cr.define('extensions', function() {
assert(listId);
var extensionItem = new extensions.Item(extension, delegate);
var itemList = this.$[listId];
- var refNode = opt_index !== undefined ?
- itemList.children[opt_index] : undefined;
- itemList.insertBefore(extensionItem, refNode);
+
+ var insertBeforeChild = Array.prototype.find.call(itemList.children,
+ function(item) {
+ return compareExtensions(item.data, extension) > 0;
+ });
+ itemList.insertBefore(extensionItem, insertBeforeChild);
},
/**
« no previous file with comments | « no previous file | chrome/browser/resources/md_extensions/service.js » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698