1 // Copyright 2014 The ChromeOS IME Authors. All Rights Reserved.
2 // limitations under the License.
3 // See the License for the specific language governing permissions and
4 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
5 // distributed under the License is distributed on an "AS-IS" BASIS,
6 // Unless required by applicable law or agreed to in writing, software
8 // http://www.apache.org/licenses/LICENSE-2.0
10 // You may obtain a copy of the License at
11 // you may not use this file except in compliance with the License.
12 // Licensed under the Apache License, Version 2.0 (the "License");
14 goog
.provide('i18n.input.chrome.inputview.Model');
16 goog
.require('goog.array');
17 goog
.require('goog.events.EventTarget');
18 goog
.require('goog.net.jsloader');
19 goog
.require('i18n.input.chrome.inputview.ConditionName');
20 goog
.require('i18n.input.chrome.inputview.Settings');
21 goog
.require('i18n.input.chrome.inputview.SpecNodeName');
22 goog
.require('i18n.input.chrome.inputview.StateManager');
23 goog
.require('i18n.input.chrome.inputview.events.ConfigLoadedEvent');
24 goog
.require('i18n.input.chrome.inputview.events.LayoutLoadedEvent');
26 goog
.scope(function() {
27 var SpecNodeName
= i18n
.input
.chrome
.inputview
.SpecNodeName
;
34 * @extends {goog.events.EventTarget}
36 i18n
.input
.chrome
.inputview
.Model = function() {
42 * @type {!i18n.input.chrome.inputview.StateManager}
44 this.stateManager
= new i18n
.input
.chrome
.inputview
.StateManager();
49 * @type {!i18n.input.chrome.inputview.Settings}
51 this.settings
= new i18n
.input
.chrome
.inputview
.Settings();
53 /** @private {!Array.<string>} */
54 this.loadingResources_
= [];
56 goog
.exportSymbol('google.ime.chrome.inputview.onLayoutLoaded',
57 goog
.bind(this.onLayoutLoaded_
, this));
58 goog
.exportSymbol('google.ime.chrome.inputview.onConfigLoaded',
59 goog
.bind(this.onConfigLoaded_
, this));
61 var Model
= i18n
.input
.chrome
.inputview
.Model
;
62 goog
.inherits(Model
, goog
.events
.EventTarget
);
66 * The path to the layouts directory.
72 '/inputview_layouts/';
76 * The path to the content directory.
86 * Callback when configuration is loaded.
88 * @param {!Object} data The configuration data.
91 Model
.prototype.onConfigLoaded_ = function(data
) {
92 goog
.array
.remove(this.loadingResources_
, this.getConfigUrl_(
93 data
[SpecNodeName
.ID
]));
94 this.dispatchEvent(new i18n
.input
.chrome
.inputview
.events
.ConfigLoadedEvent(
100 * Gets the layout url.
102 * @param {string} layout .
104 * @return {string} The url of the layout data.
106 Model
.prototype.getLayoutUrl_ = function(layout
) {
107 return Model
.LAYOUTS_PATH_
+ layout
+ '.js';
112 * Gets the keyset configuration url.
114 * @param {string} keyset .
118 Model
.prototype.getConfigUrl_ = function(keyset
) {
119 // Strips out all the suffixes in the keyboard code.
120 var configId
= keyset
.replace(/\..*$/, '');
121 return Model
.CONTENT_PATH_
+ configId
+ '.js';
126 * Callback when layout is loaded.
128 * @param {!Object} data The layout data.
131 Model
.prototype.onLayoutLoaded_ = function(data
) {
132 goog
.array
.remove(this.loadingResources_
, this.getLayoutUrl_(data
[
133 SpecNodeName
.LAYOUT_ID
]));
134 this.dispatchEvent(new i18n
.input
.chrome
.inputview
.events
.LayoutLoadedEvent(
142 * @param {string} layout The layout name.
144 Model
.prototype.loadLayout = function(layout
) {
145 var url
= this.getLayoutUrl_(layout
);
146 if (!goog
.array
.contains(this.loadingResources_
, url
)) {
147 this.loadingResources_
.push(url
);
148 goog
.net
.jsloader
.load(url
);
154 * Loads the configuration for the keyboard code.
156 * @param {string} keyboardCode The keyboard code.
158 Model
.prototype.loadConfig = function(keyboardCode
) {
159 var url
= this.getConfigUrl_(keyboardCode
);
160 if (!goog
.array
.contains(this.loadingResources_
, url
)) {
161 this.loadingResources_
.push(url
);
162 goog
.net
.jsloader
.load(url
);