Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 <include src="extension_error.js"> | 5 <include src="extension_error.js"> |
| 6 | 6 |
| 7 cr.define('options', function() { | 7 cr.define('options', function() { |
| 8 'use strict'; | 8 'use strict'; |
| 9 | 9 |
| 10 /** | 10 /** |
| (...skipping 15 matching lines...) Expand all Loading... | |
| 26 * @type {Object.<string, string>} A map from extension id to last reloaded | 26 * @type {Object.<string, string>} A map from extension id to last reloaded |
| 27 * timestamp. The timestamp is recorded when the user click the 'Reload' | 27 * timestamp. The timestamp is recorded when the user click the 'Reload' |
| 28 * link. It is used to refresh the icon of an unpacked extension. | 28 * link. It is used to refresh the icon of an unpacked extension. |
| 29 * This persists between calls to decorate. | 29 * This persists between calls to decorate. |
| 30 */ | 30 */ |
| 31 var extensionReloadedTimestamp = {}; | 31 var extensionReloadedTimestamp = {}; |
| 32 | 32 |
| 33 ExtensionsList.prototype = { | 33 ExtensionsList.prototype = { |
| 34 __proto__: HTMLDivElement.prototype, | 34 __proto__: HTMLDivElement.prototype, |
| 35 | 35 |
| 36 /** | |
| 37 * Indicates whether an embedded options page that was navigated to through | |
| 38 * the '?options=' URL query has been shown to the user. This is necessary | |
| 39 * to prevent showExtensionNodes_ from opening the options more than once. | |
|
Devlin
2014/08/19 22:20:41
Can this happen?
ericzeng
2014/08/19 22:47:51
Yes, I was getting weird behavior where showExtens
| |
| 40 * @type {boolean} | |
| 41 * @private | |
| 42 */ | |
| 43 optionsShown_: false, | |
| 44 | |
| 36 /** @override */ | 45 /** @override */ |
| 37 decorate: function() { | 46 decorate: function() { |
| 38 this.textContent = ''; | 47 this.textContent = ''; |
| 39 | 48 |
| 40 this.showExtensionNodes_(); | 49 this.showExtensionNodes_(); |
| 41 }, | 50 }, |
| 42 | 51 |
| 43 getIdQueryParam_: function() { | 52 getIdQueryParam_: function() { |
| 44 return parseQueryParams(document.location)['id']; | 53 return parseQueryParams(document.location)['id']; |
| 45 }, | 54 }, |
| 46 | 55 |
| 56 getOptionsQueryParam_: function() { | |
| 57 return parseQueryParams(document.location)['options']; | |
| 58 }, | |
| 59 | |
| 47 /** | 60 /** |
| 48 * Creates all extension items from scratch. | 61 * Creates all extension items from scratch. |
| 49 * @private | 62 * @private |
| 50 */ | 63 */ |
| 51 showExtensionNodes_: function() { | 64 showExtensionNodes_: function() { |
| 52 // Iterate over the extension data and add each item to the list. | 65 // Iterate over the extension data and add each item to the list. |
| 53 this.data_.extensions.forEach(this.createNode_, this); | 66 this.data_.extensions.forEach(this.createNode_, this); |
| 54 | 67 |
| 55 var idToHighlight = this.getIdQueryParam_(); | 68 var idToHighlight = this.getIdQueryParam_(); |
| 56 if (idToHighlight && $(idToHighlight)) { | 69 if (idToHighlight && $(idToHighlight)) { |
|
Devlin
2014/08/19 22:20:41
no brackets around single-line ifs.
ericzeng
2014/08/19 22:47:51
Done.
| |
| 57 // Scroll offset should be calculated slightly higher than the actual | 70 this.scrollToNode_(idToHighlight); |
| 58 // offset of the element being scrolled to, so that it ends up not all | 71 } |
| 59 // the way at the top. That way it is clear that there are more elements | 72 |
| 60 // above the element being scrolled to. | 73 var idToOpenOptions = this.getOptionsQueryParam_(); |
| 61 var scrollFudge = 1.2; | 74 if (idToOpenOptions && $(idToOpenOptions) && !this.optionsShown_) { |
| 62 var scrollTop = $(idToHighlight).offsetTop - scrollFudge * | 75 this.scrollToNode_(idToOpenOptions); |
| 63 $(idToHighlight).clientHeight; | 76 $(idToOpenOptions).querySelector('.options-link').click(); |
| 64 setScrollTopForDocument(document, scrollTop); | 77 this.optionsShown_ = true; |
| 65 } | 78 } |
| 66 | 79 |
| 67 if (this.data_.extensions.length == 0) | 80 if (this.data_.extensions.length == 0) |
| 68 this.classList.add('empty-extension-list'); | 81 this.classList.add('empty-extension-list'); |
| 69 else | 82 else |
| 70 this.classList.remove('empty-extension-list'); | 83 this.classList.remove('empty-extension-list'); |
| 71 }, | 84 }, |
| 72 | 85 |
| 73 /** | 86 /** |
| 87 * Scrolls the page down to the extension node with the given id. | |
| 88 * @param {string} extensionId The id of the extension to scroll to. | |
| 89 * @private | |
| 90 */ | |
| 91 scrollToNode_: function(extensionId) { | |
| 92 // Scroll offset should be calculated slightly higher than the actual | |
| 93 // offset of the element being scrolled to, so that it ends up not all | |
| 94 // the way at the top. That way it is clear that there are more elements | |
| 95 // above the element being scrolled to. | |
| 96 var scrollFudge = 1.2; | |
| 97 var scrollTop = $(extensionId).offsetTop - scrollFudge * | |
| 98 $(extensionId).clientHeight; | |
| 99 setScrollTopForDocument(document, scrollTop); | |
| 100 }, | |
| 101 | |
| 102 /** | |
| 74 * Synthesizes and initializes an HTML element for the extension metadata | 103 * Synthesizes and initializes an HTML element for the extension metadata |
| 75 * given in |extension|. | 104 * given in |extension|. |
| 76 * @param {Object} extension A dictionary of extension metadata. | 105 * @param {Object} extension A dictionary of extension metadata. |
| 77 * @private | 106 * @private |
| 78 */ | 107 */ |
| 79 createNode_: function(extension) { | 108 createNode_: function(extension) { |
| 80 var template = $('template-collection').querySelector( | 109 var template = $('template-collection').querySelector( |
| 81 '.extension-list-item-wrapper'); | 110 '.extension-list-item-wrapper'); |
| 82 var node = template.cloneNode(true); | 111 var node = template.cloneNode(true); |
| 83 node.id = extension.id; | 112 node.id = extension.id; |
| (...skipping 330 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 414 topScroll -= pad / 2; | 443 topScroll -= pad / 2; |
| 415 setScrollTopForDocument(document, topScroll); | 444 setScrollTopForDocument(document, topScroll); |
| 416 } | 445 } |
| 417 }, | 446 }, |
| 418 }; | 447 }; |
| 419 | 448 |
| 420 return { | 449 return { |
| 421 ExtensionsList: ExtensionsList | 450 ExtensionsList: ExtensionsList |
| 422 }; | 451 }; |
| 423 }); | 452 }); |
| OLD | NEW |