eventManager.htc
16560 단어 windowscssJ#HTCperformance
<!-- ---------------------------------------------------------------------
//
// Copyright 2001 Chordiant Software. All Rights Reserved.
//
// File: eventmanager.htc
//
// Auther: Ryan Carroll
// Created: 13/11/2001
//
// Description: Implements a manager registering and dispatching events
//
// Changes log:
//-------------------------------------------------------------------- -->
<PUBLIC:COMPONENT tagname="eventmanager" lightWeight="true">
<!-- Public Properties -->
<!-- Public Methods -->
<METHOD NAME="registerEvents" />
<METHOD NAME="dispatch" />
<METHOD NAME="unregisterWindow" />
<METHOD NAME="unregisterEvent" />
<!-- Public Events -->
<EVENT NAME="onError" ID="error" />
<!-- Private Event Listeners -->
<ATTACH EVENT="ondocumentready" HANDLER="setDefaults" />
// { start - performance fix
<ATTACH EVENT="ondetach" HANDLER="cleanUp" />
// } end - performance fix
</PUBLIC:COMPONENT>
<SCRIPT LANGUAGE="jscript">
//+----------------------------------------------------------------------------
//
// Global Variables
//
//-----------------------------------------------------------------------------
var registeredEvents = new Array();
function registeredEventObject(sEventName)
{
this.eventName = sEventName;
this.eventHandlers = new Array();
}
function registeredEventHandlerObject(sEventHandlerFunction, oWindow){
this.eventHandlerFunction = sEventHandlerFunction;
this.window = oWindow;
}
////////////////////////////////////////////////////////////////////////////////
// Methods Section //
////////////////////////////////////////////////////////////////////////////////
//+----------------------------------------------------------------------------
//
// Public Methods
//
//-----------------------------------------------------------------------------
//+----------------------------------------------------------------------------
//
// Function: registerEvents
//
// Description:
//
// Arguments: sMsg - descriptive text message
//
// Returns: nothing
//
//-----------------------------------------------------------------------------
function registerEvents(oEventRegistration, oWindow) {
var oEvents;
var oRegisterEventNodeList;
var sEventName;
var sEventHandler;
var sEventHandlerScriptFile;
var oSelectedRegisterEventNode;
var oRegisterEventNodeList;
var oNewEventScriptFile;
try {
oEvents = new ActiveXObject("Msxml.DOMDocument");
if((typeof oEventRegistration) == "string") {
oEvents.loadXML(oEventRegistration);
} else {
oEvents.loadXML(oEventRegistration.xml);
}
oRegisterEventNodeList = oEvents.selectNodes(".//registerevent");
for (var i=0; i < oRegisterEventNodeList.length; i++) {
oSelectedRegisterEventNode = oRegisterEventNodeList.item(i);
if(oSelectedRegisterEventNode.selectSingleNode("eventname") != null){
sEventName = oSelectedRegisterEventNode.selectSingleNode("eventname").text;
}
if(oSelectedRegisterEventNode.selectSingleNode("eventhandlerfunction") != null){
sEventHandler = oSelectedRegisterEventNode.selectSingleNode("eventhandlerfunction").text;
}
if(oSelectedRegisterEventNode.selectSingleNode("eventhandlerscriptfilename") != null){
sEventHandlerScriptFile = oSelectedRegisterEventNode.selectSingleNode("eventhandlerscriptfilename").text;
}
if( sEventHandlerScriptFile != null && sEventHandlerScriptFile != "") {
oNewEventScriptFile = oWindow.document.createElement("<script language=javascript src='"+sEventHandlerScriptFile+"'><\/script>")
oWindow.document.body.appendChild(oNewEventScriptFile);
}
addRegisteredEvent(sEventName, sEventHandler, oWindow);
}
} catch(e) {
returnError(e.toString());
} finally {
oEventRegistration = null;
oWindow = null;
oEvents = null;
oRegisterEventNodeList = null;
sEventName = null;
sEventHandler = null;
sEventHandlerScriptFile = null;
oSelectedRegisterEventNode = null;
oRegisterEventNodeList = null;
oNewEventScriptFile = null;
}
}
//+----------------------------------------------------------------------------
//
// Function: unregisterWindow
//
// Description:
//
// Arguments: sMsg - descriptive text message
//
// Returns: nothing
//
//-----------------------------------------------------------------------------
function unregisterWindow( oWindow ) {
var oRegisteredEvent;
try {
for(var i=0; i < registeredEvents.length; i++){
oRegisteredEvent = registeredEvents[i];
for(var j=oRegisteredEvent.eventHandlers.length - 1; j >= 0; j--){
if(oRegisteredEvent.eventHandlers[j].window == oWindow){
oRegisteredEvent.eventHandlers[j]=null;
oRegisteredEvent.eventHandlers.splice(j,1);
}
}
}
} catch(e) {
returnError(e.toString());
} finally {
oRegisteredEvent = null;
oWindow = null;
}
}
//+----------------------------------------------------------------------------
//
// Function: unregisterEvent
//
// Description:
//
// Arguments: sMsg - descriptive text message
//
// Returns: nothing
//
//-----------------------------------------------------------------------------
function unregisterEvent( sEventName, oWindow ) {
var oRegisteredEvent;
try {
for(var i=0; i < registeredEvents.length; i++){
if(registeredEvents[i].eventName == sEventName){
oRegisteredEvent = registeredEvents[i];
for(var j=oRegisteredEvent.eventHandlers.length - 1; j >= 0; j--){
if(oRegisteredEvent.eventHandlers[j].window == oWindow){
oRegisteredEvent.eventHandlers.splice(j,1);
}
}
break;
}
}
} catch(e) {
returnError(e.toString());
} finally {
oRegisteredEvent = null;
sEventName = null;
oWindow = null;
}
}
//+----------------------------------------------------------------------------
//
// Function: dispatch
//
// Description:
//
// Arguments: sMsg - descriptive text message
//
// Returns: nothing
//
//-----------------------------------------------------------------------------
function dispatch( sEventName, oEventData ) {
var oRegisteredEvent;
var sEventHandlerFunction;
var oEventHandlerWindow;
try {
for(var i=0; i < registeredEvents.length; i++){
if(registeredEvents[i].eventName == sEventName){
oRegisteredEvent = registeredEvents[i];
break;
}
}
if(oRegisteredEvent != null){
for(var i=0; i < oRegisteredEvent.eventHandlers.length; i++){
oEventHandlerWindow = oRegisteredEvent.eventHandlers[i].window;
sEventHandlerFunction = oRegisteredEvent.eventHandlers[i].eventHandlerFunction;
if(oEventHandlerWindow != null && sEventHandlerFunction != null){
try {
oEventHandlerWindow.eval(sEventHandlerFunction)(oEventData);
} catch(ex)
{
//don't do anything, handling windows that no longer exist but were not properly deregistered
}
}
}
}
} catch(e) {
returnError(e.toString());
} finally {
oRegisteredEvent = null;
sEventHandlerFunction = null;
oEventHandlerWindow = null;
sEventName = null;
oEventData = null;
}
}
//+----------------------------------------------------------------------------
//
// Private Methods
//
//-----------------------------------------------------------------------------
//+----------------------------------------------------------------------------
//
// Function: addRegisteredEvent
//
// Description:
//
// Arguments: sMsg - descriptive text message
//
// Returns: nothing
//
//-----------------------------------------------------------------------------
function addRegisteredEvent(sEventName, sEventHandlerFunction, oWindow){
var oRegisteredEvent;
var oEventHandler;
try {
//create new event handler object
oEventHandler = new registeredEventHandlerObject(sEventHandlerFunction, oWindow);
//search the registeredEvents collection to see if the event has already been registered
for(var i=0; i < registeredEvents.length; i++){
if(registeredEvents[i].eventName == sEventName){
oRegisteredEvent = registeredEvents[i];
break;
}
}
if(oRegisteredEvent == null){
oRegisteredEvent = new registeredEventObject(sEventName);
registeredEvents[registeredEvents.length] = oRegisteredEvent;
}
for(var i=0; i < oRegisteredEvent.eventHandlers.length; i++){
oSelectedEventHanlder = oRegisteredEvent.eventHandlers[i];
if(oSelectedEventHanlder.eventHandlerFunction == oEventHandler.eventHandlerFunction && oSelectedEventHanlder.window == oEventHandler.window ){
return;
}
}
oRegisteredEvent.eventHandlers[oRegisteredEvent.eventHandlers.length] = oEventHandler;
} catch(e) {
returnError(e.toString());
} finally {
oRegisteredEvent = null;
oEventHandler = null;
sEventName = null;
sEventHandlerFunction = null;
oWindow = null;
}
}
//+----------------------------------------------------------------------------
//
// Function: setDefaults
//
// Description: Called during the initialization of the behavior. Sets
// the required default settings, and attaches the
// onpropertychange event (not done in the header to prevent
// firing the event during initialization).
//
// Arguments: none
//
// Returns: nothing
//
//-----------------------------------------------------------------------------
function setDefaults()
{
if(element.document.media != "print") {
// Attach the onpropertychange event
attachEvent("onpropertychange", doPropChange);
}
// { start - performance fix
window.attachEvent("onbeforeunload", cleanUp);
// } end - performance fix
}
// { start - performance fix
function cleanUp() {
try {
if(element.document.media != "print") {
detachEvent("onpropertychange", doPropChange);
}
if (window)
window.detachEvent("onbeforeunload", cleanUp);
} catch(e) {
returnError(e.toString());
} finally {
// Make sure all module variables are freed
registeredEvents = null;
}
}
// } end - performance fix
//+----------------------------------------------------------------------------
//
// Function: doPropChange
//
// Description: Runs on the onpropertychange event and calls the necessary
// functions to correctly handle the property that was just
// changed.
//
// Arguments: none
//
// Returns: nothing
//
//-----------------------------------------------------------------------------
function doPropChange()
{
var propertyName;
try {
propertyName = window.event.propertyName;
// Handle CSS property changes by calling necessary functions, setting
// variables, and/or setting styles
//
if (propertyName.substring(0,5) == "style")
{
// Handle Style changes
// switch(propertyName)
// {
// case "style.zIndex" :
// break;
// }
}
else
{
//
// Detach the onpropertychange event to prevent it from firing while
// the changes are handled
//
detachEvent("onpropertychange", doPropChange);
// Handle Property changes
switch(propertyName)
{
//case "leftBoundary" :
// leftBoundary = parseInt(leftBoundary);
// setLeftBoundary(leftBoundary);
// break;
default :
returnError(propertyName + " not a valid property");
break;
}
// Re-attach the onpropertychange event
attachEvent("onpropertychange", doPropChange);
}
} catch(e) {
returnError(e.toString());
} finally {
propertyName = null;
}
}
//+----------------------------------------------------------------------------
//
// Function: returnError
//
// Description: Fires the error event, along with a descriptive text
// message.
//
// Arguments: sMsg - descriptive text message
//
// Returns: nothing
//
//-----------------------------------------------------------------------------
function returnError(sMsg)
{
var oEvent;
try {
oEvent = createEventObject();
oEvent.setAttribute("error", sMsg);
error.fire(oEvent);
//alert(sMsg);
} finally {
oEvent = null;
sMsg = null;
}
}
</SCRIPT>
페이지 참조 및 등록:
<IMPORT namespace="chordiant" implementation="/.../eventManager.htc" />
<xml id="CaseSearchResultListEventHandlers">
<events>
<registerevent>
<eventname>StopDisplayMessageReactivateHandler</eventname>
<eventhandlerfunction>stopDisplayMessageHandlerReactivate</eventhandlerfunction>
</registerevent>
</events>
</xml>
function stopDisplayMessageHandlerReactivate(){
do something here.
}
:
desktop.eventManager.registerEvents(CaseSearchResultListEventHandlers, window );
top.advisorDesktop.eventManager.dispatch("StopDisplayMessageReactivateHandler", obj);
이 내용에 흥미가 있습니까?
현재 기사가 여러분의 문제를 해결하지 못하는 경우 AI 엔진은 머신러닝 분석(스마트 모델이 방금 만들어져 부정확한 경우가 있을 수 있음)을 통해 가장 유사한 기사를 추천합니다:
제한된 크기의 디렉토리를 만드는 방법오늘 저는 장치에 공간이 없을 때 백업 중에 응용 프로그램이 어떻게 작동하는지 테스트(및 수정)하는 작업이 있습니다. 결과적으로 "남은 공간 없음"오류로 백업이 실패하면 새 파일이 없어야 합니다. 지금까지 문제를 재...
텍스트를 자유롭게 공유하거나 복사할 수 있습니다.하지만 이 문서의 URL은 참조 URL로 남겨 두십시오.
CC BY-SA 2.5, CC BY-SA 3.0 및 CC BY-SA 4.0에 따라 라이센스가 부여됩니다.