📄 eventregistry.js
字号:
/*
* Isomorphic SmartClient
* Version 6.5 (2008-04-30)
* Copyright(c) 1998-2007 Isomorphic Software, Inc. All rights reserved.
* "SmartClient" is a trademark of Isomorphic Software, Inc.
*
* licensing@smartclient.com
*
* http://smartclient.com/license
*/
//> @object EventRegistry//// EventRegistry -- the event registry allows you to set global event handlers// that fire BEFORE the normal event processing fires. This lets you// ensure that certain actions will happen when you want them to.//// You define events by calling Page.setEvent, eg://// Page.setEvent("eventName","action", fireStyle)////<//// add properties to the Page object//isc.Page.addClassProperties({ //> @classAttr isc.Page._eventRegistry (array : [] : IRWA) // Registry for global events registered with Page event registry // @group EventRegistry // @see Page.setEvent() //< _eventRegistry : {}, //> @classAttr isc.Page._pageEventID (number : 0 : IRWA) // ID number for global events registered with Page event registry // @group EventRegistry // @see Page.setEvent() //< _pageEventID : 0, //> @type FireStyle // Flags to set automatic removal of events from the page event registry. // @value null Call the registered handler any time the event occurs // @value isc.Page.FIRE_ONCE Call the registered handler the first time the event // occurs, then unregister the handler as though // +link{Page.clearEvent()} had been called // @group EventRegistry // @see Page.setEvent() // @visibility external //< FIRE_ONCE : "once", //> @classAttr isc.Page._keyRegistry (array : [] : IRWA) // Registry for keyboard events registered with Page key registry // @group KeyRegistry // @see Page.registerKey() //< _keyRegistry : {} });//// add methods for the //isc.Page.addClassMethods({//> @classMethod Page.setEvent()// Register to be called whenever a given type of event occurs, at the page level.// <p>// This includes events that also occur on widgets (like "click") and events that only occur at// the page level ("resize" and "load").// <p>// For events that also occur on widgets, page level event registrations will fire BEFORE the// event handlers on Canvases. If your action returns <code>false</code>, this will prevent// the event from getting to the intended Canvas.// <p>// Capturing events on widgets can be done by setting one of the event methods available on Canvas// (and hence available to all widget classes). See +link{group:widgetEvents}.//// @group EventRegistry//// @param eventType (pageEvent) event type to register for ("mouseDown", "load", etc)// @param action (string) string to be eval'd when event fires// (function) function to be executed when event fires// (object) an object to call on which a method named "page" +// eventType will be called// @param [fireStyle](FireStyle) Flag to set automatic removal of the event after// it fires one or more times// @param [functionName] (string) optional - if an object was passed in as the second// parameter, this is a name of a method to call on that// object.// // @return (number) ID number of this event, may be used to remove the event later// via a call to <code>Page.clearEvent()</code>// @see class:EventHandler// @see classMethod:EventHandler.getX()// @see classMethod:EventHandler.getY()// @visibility external//<setEvent : function (eventType, action, fireStyle, functionName) { // make sure the action is a function if (isc.isA.String(action)) { if (eventType == isc.EH.LOAD || eventType == isc.EH.IDLE || eventType == isc.EH.RESIZE) { action = new Function("target,eventInfo", action); } else { action = isc.Func.expressionToFunction("target,eventInfo", action); } } //>DEBUG if (this.logIsDebugEnabled()) { this.logDebug("setEvent("+eventType+"): action => " + (isc.isA.Function(action) ? isc.Func.getShortBody(action) : action)); //(eventType == "load" ? "\r\n" + Page.getStackTrace() : "")); } //<DEBUG var ID = isc.Page._pageEventID++, // id of this event handler = { // create the handler object that we'll save action : action, functionName : functionName, fireStyle : fireStyle, ID : ID }; // make sure there's a slot for this eventType var registry = this._eventRegistry; if (registry[eventType] == null) registry[eventType] = []; // add the handler registry[eventType].add(handler); // if this is the "idle" event, start the idle timer if necessary if (eventType == isc.EH.IDLE) {// this.logWarn("scheduling idle event " + action); isc.EventHandler.startIdleTimer(); } // return the ID of this event return ID;},//> @classMethod Page.clearEvent()// Clear event(s) under the given eventType.<p>// To clear all events, omit the ID parameter. To clear a specific event,// pass the ID that was returned by Page.setEvent().// @group EventRegistry//// @param eventType (PageEvent, Event) event type to clear// @param [ID] (number) ID of the event to clear. // If not specified, all events in eventType will be cleared.// @see class:EventHandler// @visibility external//<_$ID:"ID",clearEvent : function (eventType,ID){ if (ID == null) { this._eventRegistry[eventType] = []; } else { // If we're currently processing this event type, don't modify the length of the array // Clear the entry and allow the processing function to clear out the empty slots when // it completes if (this._processingEvent == eventType) { var reg = this._eventRegistry[eventType], index = reg ? reg.findIndex(this._$ID, ID) : -1; if (index != -1) reg[index] = null; // Otherwise just clear out the appropriate entry. } else { if (this._eventRegistry[eventType]) this._eventRegistry[eventType].removeWhere(this._$ID, ID); } }},// Helper method to avoid reassembling 'pageClick' et all each time the event is fired_getPageEventName : function (eventType) { var eventMap = this._pageEventMap = this._pageEventMap || {}; if (!eventMap[eventType]) { eventMap[eventType] = "page" + eventType.charAt(0).toUpperCase() + eventType.substring(1); } return eventMap[eventType];},//> @classMethod Page.handleEvent() (A)// Handle an event by firing all events in the EventRegistry under a given eventType.// Called automatically by the isc.EventHandler in the normal course of handling events.// @group EventRegistry//// @param target (object) Canvas or DOM object that received the event// @param eventType (string) name of this event// @param eventInfo (any) information passed with a custom event (see e.g. Slider)//// @return (boolean) false == cancel further event processing// anything else == continue processing//<handleEvent : function (target, eventType, eventInfo) { if (eventType == isc.EH.UNLOAD) isc.Canvas._handleUnload(); // get the list of handlers var list = isc.Page._eventRegistry[eventType]; // if the list is empty, bail if (list == null || list.length == 0) return true; var pageEventName = this._getPageEventName(eventType); // execute each handler for this eventType in turn, as long as they don't return false var keepGoing = true; // if any return false, return false to cancel event processing this._processingEvent = eventType;
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -