📄 core.js
字号:
this._garbageCollect(); } } }, /** * Returns a string representation, for debugging purposes only. * * @return a string representation of the map * @type String */ toString: function() { return Core.Debug.toString(this.map); }});/** * A collection of event listeners. Provides capability to manage listeners * of multiple types, and fire events to listeners based on type. */Core.ListenerList = Core.extend({ /** * Array containing event types and event listeners. * Even indexes contain event types, and the subsequent odd * index contain Functions to invoke. * @type Array */ _data: null, /** * Creates a new listener list. * * @constructor */ $construct: function() { this._data = []; }, /** * Adds an event listener. * * @param {String} eventType the event type * @param {Function} eventTarget the event target */ addListener: function(eventType, eventTarget) { this._data.push(eventType, eventTarget); }, /** * Fires an event. * * @param event the event to fire * @return true if all event listeners returned values that evaluate to true, * or false if any event listeners returned values that evaluate to * false * @type Boolean */ fireEvent: function(event) { if (event.type == null) { throw new Error("Cannot fire event, type property not set."); } var i, returnValue = true, listeners = []; for (i = 0; i < this._data.length; i += 2) { if (this._data[i] == event.type) { listeners.push(this._data[i + 1]); } } for (i = 0; i < listeners.length; ++i) { returnValue = listeners[i](event) && returnValue; } return returnValue; }, /** * Returns an array containing the types of all listeners * in the list. * * @return the event types * @type Array */ getListenerTypes: function() { var types = []; for (var i = 0; i < this._data.length; i += 2) { types.push(this._data[i]); } Core.Arrays.removeDuplicates(types); return types; }, /** * Returns an array of all listeners for a specific event type. * * @param {String} eventType the event type * @return the listeners * @type Array */ getListeners: function(eventType) { var listeners = []; for (var i = 0; i < this._data.length; i += 2) { if (this._data[i] == eventType) { listeners.push(this._data[i + 1]); } } return listeners; }, /** * Determines the number of listeners for a specific event type. * * @param {String} eventType the event type * @return the listener count * @type Number */ getListenerCount: function(eventType) { var count = 0; for (var i = 0; i < this._data.length; i += 2) { if (this._data[i] == eventType) { ++count; } } return count; }, /** * Determines if the listeners list has any listeners of a specific type. * * @param {String} eventType the event type * @return true if any listeners exist * @type Boolean */ hasListeners: function(eventType) { for (var i = 0; i < this._data.length; i += 2) { if (this._data[i] == eventType) { return true; } } return false; }, /** * Determines if any number of listeners are registered to the list. * * @return true if the listener list is empty * @type Boolean */ isEmpty: function() { return this._data.length === 0; }, /** * Removes an event listener. * * @param {String} eventType the event type * @param {Function} eventTarget the event target */ removeListener: function(eventType, eventTarget) { for (var i = 0; i < this._data.length; i += 2) { if (this._data[i] == eventType && eventTarget == this._data[i + 1]) { var oldLength = this._data.length; this._data.splice(i, 2); return; } } }, /** @see Object#toString */ toString: function() { var out = ""; for (var i = 0; i < this._data.length; i += 2) { if (i > 0) { out += ", "; } out += this._data[i] + ":" + this._data[i + 1]; } return out; }});/** * Provides locale-specific resources for multiple localizations. * A default resource map and locale-specific resource maps may be added to a resource bundle. * The resource bundle may then be queried to return a complete resource map for a specific locale. * When a locale-specific map is requested, any entries not available specifically in that map will be provided * by more generic resource maps that have been added to the bundle. */Core.ResourceBundle = Core.extend({ $static: { /** * Generates a less specific version of the specified language code. * Returns null if no "parent" language code can be determined. * This operation is implemented by removing the sub-tag (if found) * from the specified RFC 1766 language code. If the language * code does not have a sub-tag, null is returned. * * @param {String} languageCode an RFC 1766 language code * @return a less specific version of the specified language code, * or null if none can be determined * @type String */ getParentLanguageCode: function(languageCode) { if (languageCode.indexOf("-") == -1) { return null; } else { return languageCode.substring(0, languageCode.indexOf("-")); } } }, /** * Association between RFC 1766 language codes and resource maps. * These are the maps which have been added using the <code>set()</code> method. * The contents of these maps may not be modified. */ _sourceMaps: null, /** * Cache of generated resource maps which fill omissions in more-specific resource maps * with those from less-specific resource maps. A generated map is returned * when the user requests a locale-specific map. */ _generatedMaps: null, /** * The default resource map that should be used in the event that a * locale-specific map is not available for a particular language code. */ _defaultMap: null, /** * Creates a new <code>ResourceBundle</code>. * * @param defaultMap the default resource map */ $construct: function(defaultMap) { this._sourceMaps = {}; this._generatedMaps = {}; this._defaultMap = defaultMap; }, /** * Returns a locale-specific resource map. The returned map will contain entries from less-specific and/or the default map * if they are not available from the map for the specified language code. * * @param {String} languageCode an RFC 1766 language code, or null to return the default map * @return a locale-specific map for the language code */ get: function(languageCode) { var map = languageCode ? this._generatedMaps[languageCode] : this._defaultMap; if (map) { return map; } map = {}; var x; // Copy items from exact language resource map into generated resource map. var sourceMap = this._sourceMaps[languageCode]; if (sourceMap) { for (x in sourceMap) { map[x] = sourceMap[x]; } } // Copy any missing items found in parent language resource map (if it exists) into new resource map. var parentLanguageCode = Core.ResourceBundle.getParentLanguageCode(languageCode); if (parentLanguageCode) { sourceMap = this._sourceMaps[parentLanguageCode]; if (sourceMap) { for (x in sourceMap) { if (map[x] === undefined) { map[x] = sourceMap[x]; } } } } // Copy any missing items found in default resource map into new resource map. for (x in this._defaultMap) { if (map[x] === undefined) { map[x] = this._defaultMap[x]; } } this._generatedMaps[languageCode] = map; return map; }, /** * Adds a new locale-specific map to the bundle. * * @param languageCode the language code * @param map the key-value resource map for the language code */ set: function(languageCode, map) { this._generatedMaps = {}; this._sourceMaps[languageCode] = map; }, /** @see Object#toString */ toString: function() { var out = "ResourceBundle: "; for (var x in this._sourceMaps) { out += " " + x; } return out; }});
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -