📄 core.js
字号:
* This operation is necessary due to Internet Explorer memory leak * issues. */ _garbageCollect: function() { this._removeCount = 0; var newMap = {}; for (var key in this.map) { newMap[key] = this.map[key]; } this.map = newMap; }, /** * Removes the value referenced by the specified key. * * @param key the key */ remove: function(key) { delete this.map[key]; if (Core.Arrays.LargeMap.garbageCollectEnabled) { ++this._removeCount; if (this._removeCount >= this.garbageCollectionInterval) { this._garbageCollect(); } } }});/** * @class 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 listeners = []; for (var i = 0; i < this._data.length; i += 2) { if (this._data[i] == event.type) { listeners.push(this._data[i + 1]); } } var returnValue = true; for (var 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; } } }, /** * Creates a string representation of the listener list. * This should be used for debugging purposes only. */ 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; }});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 subtag (if found) * from the specified RFC 1766 language code. If the language * code does not have a subtag, 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. */ _sourceBundles: null, _generatedBundles: null, /** * The default resource map that should be utilized in the event that a * locale-specific map is not available for a particular language code. */ _defaultBundle: null, $construct: function(defaultBundle) { this._sourceBundles = {}; this._generatedBundles = {}; this._defaultBundle = defaultBundle; }, /** * Returns a locale-specific map. */ get: function(languageCode) { var bundle = languageCode ? this._generatedBundles[languageCode] : this._defaultBundle; if (bundle) { return bundle; } bundle = {}; var x; // Copy items from exact language bundle into new bundle. var sourceBundle = this._sourceBundles[languageCode]; if (sourceBundle) { for (x in sourceBundle) { bundle[x] = sourceBundle[x]; } } // Copy any missing items found in parent language bundle (if it exists) into new bundle. parentLanguageCode = Core.ResourceBundle.getParentLanguageCode(languageCode); if (parentLanguageCode) { var sourceBundle = this._sourceBundles[parentLanguageCode]; if (sourceBundle) { for (x in sourceBundle) { if (bundle[x] === undefined) { bundle[x] = sourceBundle[x]; } } } } // Copy any missing items found in default bundle into new bundle. for (x in this._defaultBundle) { if (bundle[x] === undefined) { bundle[x] = this._defaultBundle[x]; } } this._generatedBundles[languageCode] = bundle; return bundle; }, /** * Adds a new locale-specific map to the */ set: function(languageCode, map) { this._generatedBundles = {}; this._sourceBundles[languageCode] = map; }, toString: function() { out = "ResourceBundle: "; for (var x in this._sourceBundles) { out += " " + x; } return out; }});
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -