| 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);
|
| },
|
|
|
| /**
|
|
|