Chromium Code Reviews| OLD | NEW |
|---|---|
| (Empty) | |
| 1 // Copyright 2014 The Chromium Authors. All rights reserved. | |
| 2 // Use of this source code is governed by a BSD-style license that can be | |
| 3 // found in the LICENSE file. | |
| 4 | |
| 5 cr.define('extensions', function() { | |
| 6 'use strict'; | |
| 7 | |
| 8 /** | |
| 9 * The ExtensionOptionsOverlay will show an extension's options page using | |
| 10 * an <extensionoptions> element. | |
| 11 * @constructor | |
| 12 */ | |
| 13 function ExtensionOptionsOverlay() {} | |
| 14 | |
| 15 cr.addSingletonGetter(ExtensionOptionsOverlay); | |
| 16 | |
| 17 ExtensionOptionsOverlay.prototype = { | |
| 18 | |
|
Dan Beam
2014/08/18 17:31:32
nit: remove \n
ericzeng
2014/08/18 18:00:25
Done.
| |
| 19 /** | |
| 20 * The function that shows the given element in the overlay. | |
| 21 * @type {function} | |
|
Dan Beam
2014/08/18 17:31:32
Function
ericzeng
2014/08/18 18:00:25
Done.
| |
| 22 * @param {HTMLElement} The element to show in the overlay. | |
| 23 * @private | |
| 24 */ | |
| 25 showOverlay_: undefined, | |
| 26 | |
| 27 /** | |
| 28 * Initialize the page. | |
| 29 * @param {function(HTMLDivElement)} showOverlay The function to show or | |
| 30 * hide the ExtensionOptionsOverlay; this should take a single parameter | |
| 31 * which is either the overlay Div if the overlay should be displayed, | |
| 32 * or null if the overlay should be hidden. | |
| 33 */ | |
| 34 initializePage: function(showOverlay) { | |
| 35 var overlay = $('overlay'); | |
| 36 cr.ui.overlay.setupOverlay(overlay); | |
| 37 cr.ui.overlay.globalInitialization(); | |
| 38 overlay.addEventListener('cancelOverlay', this.handleDismiss_.bind(this)); | |
| 39 this.showOverlay_ = showOverlay; | |
|
Dan Beam
2014/08/18 17:31:32
nit: sprinkle some \n in here
ericzeng
2014/08/18 18:00:25
Done.
| |
| 40 | |
| 41 /** | |
| 42 * The element of the full overlay. | |
| 43 * @type {HTMLDivElement} | |
| 44 * @private | |
| 45 */ | |
| 46 this.overlayDiv_ = $('extension-options-overlay'); | |
|
Dan Beam
2014/08/18 17:31:32
why not just $('extension-options-overlay') whenev
ericzeng
2014/08/18 18:00:25
I used the extension error overlay as a reference
| |
| 47 }, | |
| 48 | |
| 49 /** | |
| 50 * Handles a click on the close button. | |
| 51 * @param {Event} e The click event. | |
| 52 * @private | |
| 53 */ | |
| 54 handleDismiss_: function(event) { | |
| 55 this.setVisible_(false); | |
| 56 var extensionoptions = document.querySelector('extensionoptions'); | |
| 57 if (extensionoptions) | |
| 58 this.overlayDiv_.removeChild(extensionoptions); | |
| 59 }, | |
| 60 | |
| 61 /** | |
| 62 * Associate an extension with the overlay and display it. | |
| 63 * @param {string} extensionId The id of the extension whose options page | |
| 64 * should be displayed in the overlay. | |
| 65 * @param {string} extensionName The name of the extension, which is used | |
| 66 * as the header of the overlay. | |
| 67 */ | |
| 68 setExtensionAndShowOverlay: function(extensionId, extensionName) { | |
| 69 var extensionoptions = new ExtensionOptions(); | |
| 70 extensionoptions.extension = extensionId; | |
| 71 extensionoptions.autosize = 'on'; | |
| 72 | |
| 73 // TODO(ericzeng): Resize in a non-jarring way. | |
| 74 extensionoptions.onsizechanged = function(evt) { | |
| 75 this.overlayDiv_.style.width = evt.width; | |
| 76 this.overlayDiv_.style.height = evt.height; | |
| 77 }.bind(this); | |
| 78 | |
| 79 this.overlayDiv_.appendChild(extensionoptions); | |
| 80 | |
| 81 $('extension-options-overlay-title').textContent = extensionName; | |
| 82 | |
| 83 this.setVisible_(true); | |
| 84 }, | |
| 85 | |
| 86 /** | |
| 87 * Toggles the visibility of the ExtensionOptionsOverlay. | |
| 88 * @param {boolean} isVisible Whether the overlay should be visible. | |
| 89 * @private | |
| 90 */ | |
| 91 setVisible_: function(isVisible) { | |
| 92 this.showOverlay_(isVisible ? this.overlayDiv_ : null); | |
| 93 } | |
| 94 }; | |
| 95 | |
| 96 // Export | |
| 97 return { | |
| 98 ExtensionOptionsOverlay: ExtensionOptionsOverlay | |
| 99 }; | |
| 100 }); | |
| OLD | NEW |