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 /** | |
19 * The function that shows the given element in the overlay. | |
20 * @type {Function} | |
21 * @param {HTMLElement} The element to show in the overlay. | |
22 * @private | |
23 */ | |
24 showOverlay_: undefined, | |
25 | |
26 /** | |
27 * Initialize the page. | |
28 * @param {function(HTMLDivElement)} showOverlay The function to show or | |
29 * hide the ExtensionOptionsOverlay; this should take a single parameter | |
30 * which is either the overlay Div if the overlay should be displayed, | |
31 * or null if the overlay should be hidden. | |
32 */ | |
33 initializePage: function(showOverlay) { | |
34 var overlay = $('overlay'); | |
35 | |
36 cr.ui.overlay.setupOverlay(overlay); | |
37 cr.ui.overlay.globalInitialization(); | |
38 overlay.addEventListener('cancelOverlay', this.handleDismiss_.bind(this)); | |
39 | |
40 this.showOverlay_ = showOverlay; | |
41 }, | |
42 | |
43 /** | |
44 * Handles a click on the close button. | |
45 * @param {Event} e The click event. | |
46 * @private | |
47 */ | |
48 handleDismiss_: function(event) { | |
49 this.setVisible_(false); | |
50 var extensionoptions = document.querySelector('extensionoptions'); | |
51 if (extensionoptions) | |
52 $('extension-options-overlay').removeChild(extensionoptions); | |
53 }, | |
54 | |
55 /** | |
56 * Associate an extension with the overlay and display it. | |
57 * @param {string} extensionId The id of the extension whose options page | |
58 * should be displayed in the overlay. | |
59 * @param {string} extensionName The name of the extension, which is used | |
60 * as the header of the overlay. | |
61 */ | |
62 setExtensionAndShowOverlay: function(extensionId, extensionName) { | |
63 var extensionoptions = new ExtensionOptions(); | |
Vitaly Pavlenko
2014/09/30 01:31:28
Constructor "ExtensionOptions()" is never defined
| |
64 extensionoptions.extension = extensionId; | |
65 extensionoptions.autosize = 'on'; | |
66 | |
67 // TODO(ericzeng): Resize in a non-jarring way. | |
68 extensionoptions.onsizechanged = function(evt) { | |
69 $('extension-options-overlay').style.width = evt.width; | |
70 $('extension-options-overlay').style.height = evt.height; | |
71 }.bind(this); | |
72 | |
73 $('extension-options-overlay').appendChild(extensionoptions); | |
74 | |
75 $('extension-options-overlay-title').textContent = extensionName; | |
76 | |
77 this.setVisible_(true); | |
78 }, | |
79 | |
80 /** | |
81 * Toggles the visibility of the ExtensionOptionsOverlay. | |
82 * @param {boolean} isVisible Whether the overlay should be visible. | |
83 * @private | |
84 */ | |
85 setVisible_: function(isVisible) { | |
86 this.showOverlay_(isVisible ? $('extension-options-overlay') : null); | |
87 } | |
88 }; | |
89 | |
90 // Export | |
91 return { | |
92 ExtensionOptionsOverlay: ExtensionOptionsOverlay | |
93 }; | |
94 }); | |
OLD | NEW |