diff options
author | janekptacijarabaci <janekptacijarabaci@seznam.cz> | 2018-07-29 09:59:35 +0200 |
---|---|---|
committer | janekptacijarabaci <janekptacijarabaci@seznam.cz> | 2018-07-29 09:59:35 +0200 |
commit | 927853bde5ac254ce255a46b15266fbcf6046b09 (patch) | |
tree | 9d82b6265b5a5b0cce3fba1b9973242fcaf796fe /application/palemoon/components/downloads/content/downloads.js | |
parent | ac3159f02f3b60a8f20a22ff6a66c51d075e11a7 (diff) | |
download | UXP-927853bde5ac254ce255a46b15266fbcf6046b09.tar UXP-927853bde5ac254ce255a46b15266fbcf6046b09.tar.gz UXP-927853bde5ac254ce255a46b15266fbcf6046b09.tar.lz UXP-927853bde5ac254ce255a46b15266fbcf6046b09.tar.xz UXP-927853bde5ac254ce255a46b15266fbcf6046b09.zip |
[PALEMOON] Bug 1115379 - Streamline DownloadsViewItemController construction and remove now unneeded identifiers
Diffstat (limited to 'application/palemoon/components/downloads/content/downloads.js')
-rw-r--r-- | application/palemoon/components/downloads/content/downloads.js | 32 |
1 files changed, 21 insertions, 11 deletions
diff --git a/application/palemoon/components/downloads/content/downloads.js b/application/palemoon/components/downloads/content/downloads.js index af0c85535..a6c716b8c 100644 --- a/application/palemoon/components/downloads/content/downloads.js +++ b/application/palemoon/components/downloads/content/downloads.js @@ -896,6 +896,16 @@ const DownloadsView = { }, /** + * Associates each richlistitem for a download with its corresponding + * DownloadsViewItemController object. + */ + _controllersForElements: new Map(), + + controllerForElement(element) { + return this._controllersForElements.get(element); + }, + + /** * Creates a new view item associated with the specified data item, and adds * it to the top or the bottom of the list. */ @@ -907,6 +917,8 @@ const DownloadsView = { let element = document.createElement("richlistitem"); let viewItem = new DownloadsViewItem(aDataItem, element); this._visibleViewItems.set(aDataItem, viewItem); + let viewItemController = new DownloadsViewItemController(aDataItem); + this._controllersForElements.set(element, viewItemController); if (aNewest) { this.richListBox.insertBefore(element, this.richListBox.firstChild); } else { @@ -928,6 +940,7 @@ const DownloadsView = { this.richListBox.itemCount - 1); } this._visibleViewItems.delete(aDataItem); + this._controllersForElements.delete(element); }, ////////////////////////////////////////////////////////////////////////////// @@ -949,7 +962,7 @@ const DownloadsView = { while (target.nodeName != "richlistitem") { target = target.parentNode; } - new DownloadsViewItemController(target).doCommand(aCommand); + DownloadsView.controllerForElement(target).doCommand(aCommand); }, onDownloadClick: function DV_onDownloadClick(aEvent) @@ -1028,8 +1041,8 @@ const DownloadsView = { return; } - let controller = new DownloadsViewItemController(element); - let localFile = controller.dataItem.localFile; + let localFile = DownloadsView.controllerForElement(element) + .dataItem.localFile; if (!localFile.exists()) { return; } @@ -1082,8 +1095,6 @@ function DownloadsViewItem(aDataItem, aElement) let attributes = { "type": "download", "class": "download-state", - "id": "downloadsItem_" + this.dataItem.downloadGuid, - "downloadGuid": this.dataItem.downloadGuid, "state": this.dataItem.state, "progress": this.dataItem.inProgress ? this.dataItem.percentComplete : 100, "displayName": target, @@ -1360,8 +1371,8 @@ const DownloadsViewController = { // Other commands are selection-specific. let element = DownloadsView.richListBox.selectedItem; - return element && - new DownloadsViewItemController(element).isCommandEnabled(aCommand); + return element && DownloadsView.controllerForElement(element) + .isCommandEnabled(aCommand); }, doCommand: function DVC_doCommand(aCommand) @@ -1376,7 +1387,7 @@ const DownloadsViewController = { let element = DownloadsView.richListBox.selectedItem; if (element) { // The doCommand function also checks if the command is enabled. - new DownloadsViewItemController(element).doCommand(aCommand); + DownloadsView.controllerForElement(element).doCommand(aCommand); } }, @@ -1416,9 +1427,8 @@ XPCOMUtils.defineConstant(this, "DownloadsViewController", DownloadsViewControll * Handles all the user interaction events, in particular the "commands", * related to a single item in the downloads list widgets. */ -function DownloadsViewItemController(aElement) { - let downloadGuid = aElement.getAttribute("downloadGuid"); - this.dataItem = DownloadsCommon.getData(window).dataItems[downloadGuid]; +function DownloadsViewItemController(aDataItem) { + this.dataItem = aDataItem; } DownloadsViewItemController.prototype = { |