1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
|
// Copyright (c) 2012 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
cr.define('options', function() {
const ArrayDataModel = cr.ui.ArrayDataModel;
const OptionsPage = options.OptionsPage;
const SettingsDialog = options.SettingsDialog;
/**
* StartupOverlay class
* Encapsulated handling of the 'Set Startup pages' overlay page.
* @constructor
* @class
*/
function StartupOverlay() {
SettingsDialog.call(this, 'startup',
templateData.startupPagesOverlayTabTitle,
'startup-overlay',
$('startup-overlay-confirm'),
$('startup-overlay-cancel'));
};
cr.addSingletonGetter(StartupOverlay);
StartupOverlay.prototype = {
__proto__: SettingsDialog.prototype,
/**
* An autocomplete list that can be attached to a text field during editing.
* @type {HTMLElement}
* @private
*/
autocompleteList_: null,
/**
* Initialize the page.
*/
initializePage: function() {
SettingsDialog.prototype.initializePage.call(this);
var self = this;
var startupPagesList = $('startupPagesList');
options.browser_options.StartupPageList.decorate(startupPagesList);
startupPagesList.autoExpands = true;
$('startupUseCurrentButton').onclick = function(event) {
chrome.send('setStartupPagesToCurrentPages');
};
var suggestionList = new cr.ui.AutocompleteList();
suggestionList.autoExpands = true;
suggestionList.suggestionUpdateRequestCallback =
this.requestAutocompleteSuggestions_.bind(this);
$('startup-overlay').appendChild(suggestionList);
this.autocompleteList_ = suggestionList;
startupPagesList.autocompleteList = suggestionList;
},
/** @inheritDoc */
handleConfirm: function() {
SettingsDialog.prototype.handleConfirm.call(this);
chrome.send('commitStartupPrefChanges');
},
/** @inheritDoc */
handleCancel: function() {
SettingsDialog.prototype.handleCancel.call(this);
chrome.send('cancelStartupPrefChanges');
},
/**
* Updates the startup pages list with the given entries.
* @param {Array} pages List of startup pages.
* @private
*/
updateStartupPages_: function(pages) {
var model = new ArrayDataModel(pages);
// Add a "new page" row.
model.push({
'modelIndex': '-1'
});
$('startupPagesList').dataModel = model;
},
/**
* Sends an asynchronous request for new autocompletion suggestions for the
* the given query. When new suggestions are available, the C++ handler will
* call updateAutocompleteSuggestions_.
* @param {string} query List of autocomplete suggestions.
* @private
*/
requestAutocompleteSuggestions_: function(query) {
chrome.send('requestAutocompleteSuggestionsForStartupPages', [query]);
},
/**
* Updates the autocomplete suggestion list with the given entries.
* @param {Array} pages List of autocomplete suggestions.
* @private
*/
updateAutocompleteSuggestions_: function(suggestions) {
var list = this.autocompleteList_;
// If the trigger for this update was a value being selected from the
// current list, do nothing.
if (list.targetInput && list.selectedItem &&
list.selectedItem['url'] == list.targetInput.value) {
return;
}
list.suggestions = suggestions;
},
};
// Forward public APIs to private implementations.
[
'updateStartupPages',
'updateAutocompleteSuggestions',
].forEach(function(name) {
StartupOverlay[name] = function() {
var instance = StartupOverlay.getInstance();
return instance[name + '_'].apply(instance, arguments);
};
});
// Export
return {
StartupOverlay: StartupOverlay
};
});
|