| 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 cr.define('options', function() { | 5 cr.define('options', function() { |
| 6 'use strict'; | 6 'use strict'; |
| 7 | 7 |
| 8 /** | 8 /** |
| 9 * A lookup helper function to find the first node that has an id (starting | 9 * A lookup helper function to find the first node that has an id (starting |
| 10 * at |node| and going up the parent chain). | 10 * at |node| and going up the parent chain). |
| (...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 47 }, | 47 }, |
| 48 | 48 |
| 49 /** | 49 /** |
| 50 * Creates all extension items from scratch. | 50 * Creates all extension items from scratch. |
| 51 * @private | 51 * @private |
| 52 */ | 52 */ |
| 53 showExtensionNodes_: function() { | 53 showExtensionNodes_: function() { |
| 54 // Iterate over the extension data and add each item to the list. | 54 // Iterate over the extension data and add each item to the list. |
| 55 this.data_.extensions.forEach(this.createNode_, this); | 55 this.data_.extensions.forEach(this.createNode_, this); |
| 56 | 56 |
| 57 var id_to_highlight = this.getIdQueryParam_(); | 57 var idToHighlight = this.getIdQueryParam_(); |
| 58 if (id_to_highlight) { | 58 if (idToHighlight) { |
| 59 // Scroll offset should be calculated slightly higher than the actual | 59 // Scroll offset should be calculated slightly higher than the actual |
| 60 // offset of the element being scrolled to, so that it ends up not all | 60 // offset of the element being scrolled to, so that it ends up not all |
| 61 // the way at the top. That way it is clear that there are more elements | 61 // the way at the top. That way it is clear that there are more elements |
| 62 // above the element being scrolled to. | 62 // above the element being scrolled to. |
| 63 var scroll_fudge = 1.2; | 63 var scrollFudge = 1.2; |
| 64 var offset = $(id_to_highlight).offsetTop - | 64 var offset = $(idToHighlight).offsetTop - |
| 65 (scroll_fudge * $(id_to_highlight).clientHeight); | 65 (scrollFudge * $(idToHighlight).clientHeight); |
| 66 var wrapper = this.parentNode; | 66 var wrapper = this.parentNode; |
| 67 var list = wrapper.parentNode; | 67 var list = wrapper.parentNode; |
| 68 list.scrollTop = offset; | 68 list.scrollTop = offset; |
| 69 } | 69 } |
| 70 | 70 |
| 71 if (this.data_.extensions.length == 0) | 71 if (this.data_.extensions.length == 0) |
| 72 this.classList.add('empty-extension-list'); | 72 this.classList.add('empty-extension-list'); |
| 73 else | 73 else |
| 74 this.classList.remove('empty-extension-list'); | 74 this.classList.remove('empty-extension-list'); |
| 75 }, | 75 }, |
| 76 | 76 |
| 77 /** | 77 /** |
| 78 * Synthesizes and initializes an HTML element for the extension metadata | 78 * Synthesizes and initializes an HTML element for the extension metadata |
| 79 * given in |extension|. | 79 * given in |extension|. |
| 80 * @param {Object} extension A dictionary of extension metadata. | 80 * @param {Object} extension A dictionary of extension metadata. |
| 81 * @private | 81 * @private |
| 82 */ | 82 */ |
| 83 createNode_: function(extension) { | 83 createNode_: function(extension) { |
| 84 var template = $('template-collection').querySelector( | 84 var template = $('template-collection').querySelector( |
| 85 '.extension-list-item-wrapper'); | 85 '.extension-list-item-wrapper'); |
| 86 var node = template.cloneNode(true); | 86 var node = template.cloneNode(true); |
| 87 node.id = extension.id; | 87 node.id = extension.id; |
| 88 | 88 |
| 89 if (!extension.enabled || extension.terminated) | 89 if (!extension.enabled || extension.terminated) |
| 90 node.classList.add('inactive-extension'); | 90 node.classList.add('inactive-extension'); |
| 91 | 91 |
| 92 if (!extension.userModifiable) | 92 if (!extension.userModifiable) |
| 93 node.classList.add('may-not-disable'); | 93 node.classList.add('may-not-disable'); |
| 94 | 94 |
| 95 var id_to_highlight = this.getIdQueryParam_(); | 95 var idToHighlight = this.getIdQueryParam_(); |
| 96 if (node.id == id_to_highlight) | 96 if (node.id == idToHighlight) |
| 97 node.classList.add('extension-highlight'); | 97 node.classList.add('extension-highlight'); |
| 98 | 98 |
| 99 var item = node.querySelector('.extension-list-item'); | 99 var item = node.querySelector('.extension-list-item'); |
| 100 item.style.backgroundImage = 'url(' + extension.icon + ')'; | 100 item.style.backgroundImage = 'url(' + extension.icon + ')'; |
| 101 | 101 |
| 102 var title = node.querySelector('.extension-title'); | 102 var title = node.querySelector('.extension-title'); |
| 103 title.textContent = extension.name; | 103 title.textContent = extension.name; |
| 104 | 104 |
| 105 var version = node.querySelector('.extension-version'); | 105 var version = node.querySelector('.extension-version'); |
| 106 version.textContent = extension.version; | 106 version.textContent = extension.version; |
| (...skipping 127 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 234 // but this page will be updated asynchronously if the extension | 234 // but this page will be updated asynchronously if the extension |
| 235 // becomes enabled/disabled. It also might not become enabled or | 235 // becomes enabled/disabled. It also might not become enabled or |
| 236 // disabled, because the user might e.g. get prompted when enabling | 236 // disabled, because the user might e.g. get prompted when enabling |
| 237 // and choose not to. | 237 // and choose not to. |
| 238 e.preventDefault(); | 238 e.preventDefault(); |
| 239 }); | 239 }); |
| 240 } | 240 } |
| 241 | 241 |
| 242 enable.querySelector('input').checked = extension.enabled; | 242 enable.querySelector('input').checked = extension.enabled; |
| 243 } else { | 243 } else { |
| 244 var terminated_reload = node.querySelector('.terminated-reload-link'); | 244 var terminatedReload = node.querySelector('.terminated-reload-link'); |
| 245 terminated_reload.hidden = false; | 245 terminatedReload.hidden = false; |
| 246 terminated_reload.addEventListener('click', function(e) { | 246 terminatedReload.addEventListener('click', function(e) { |
| 247 chrome.send('extensionSettingsReload', [extension.id]); | 247 chrome.send('extensionSettingsReload', [extension.id]); |
| 248 }); | 248 }); |
| 249 } | 249 } |
| 250 | 250 |
| 251 // 'Remove' button. | 251 // 'Remove' button. |
| 252 var trashTemplate = $('template-collection').querySelector('.trash'); | 252 var trashTemplate = $('template-collection').querySelector('.trash'); |
| 253 var trash = trashTemplate.cloneNode(true); | 253 var trash = trashTemplate.cloneNode(true); |
| 254 trash.title = loadTimeData.getString('extensionUninstall'); | 254 trash.title = loadTimeData.getString('extensionUninstall'); |
| 255 trash.addEventListener('click', function(e) { | 255 trash.addEventListener('click', function(e) { |
| 256 chrome.send('extensionSettingsUninstall', [extension.id]); | 256 chrome.send('extensionSettingsUninstall', [extension.id]); |
| (...skipping 71 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 328 } | 328 } |
| 329 | 329 |
| 330 this.appendChild(node); | 330 this.appendChild(node); |
| 331 } | 331 } |
| 332 }; | 332 }; |
| 333 | 333 |
| 334 return { | 334 return { |
| 335 ExtensionsList: ExtensionsList | 335 ExtensionsList: ExtensionsList |
| 336 }; | 336 }; |
| 337 }); | 337 }); |
| OLD | NEW |