desktopmanager.htc

11873 단어 cssHTCperformance

<!-- ---------------------------------------------------------------------
//
//  Copyright 2001 Chordiant Software.  All Rights Reserved.
//
//  File:         desktopmanager.htc
//
//	Auther:				Ryan Carroll
//	Created:			13/11/2001
//
//  Description:  Implements a manager for desktop specific items(settings)
//
//	Changes log:
//-------------------------------------------------------------------- -->

<PUBLIC:COMPONENT tagname="desktopmanager" lightWeight="true">

<!-- Public Properties -->    

<!-- Public Methods -->    
<METHOD   NAME="setDesktopSetting"				/>
<METHOD   NAME="getDesktopSetting"				/>
<METHOD   NAME="clearDesktopSettings"			/>
<METHOD   NAME="getAllDesktopSettings"			/>
<METHOD   NAME="removeDesktopSetting"			/>


<!-- Public Events -->    
<EVENT    NAME="onError"  						ID="error"		  />
<EVENT    NAME="onDesktopSettingChanged" 		ID="desktopSettingChanged" />

    
<!-- 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 desktopSettings = new Array();

function desktopSettingObject(sSettingName, sSettingValue)
{
	this.settingName = sSettingName;
	this.settingValue = sSettingValue;
}

////////////////////////////////////////////////////////////////////////////////
//	Methods Section																										        // 
////////////////////////////////////////////////////////////////////////////////

//+----------------------------------------------------------------------------
//
//  Public Methods
//
//-----------------------------------------------------------------------------


//+----------------------------------------------------------------------------
//
//  Function:       setDesktopSetting
//
//  Description:    
//
//  Arguments:      none
//
//  Returns:        nothing
//
//-----------------------------------------------------------------------------

function setDesktopSetting( sSettingName, sSettingValue ) {
	var oDesktopSetting;
	var oEvent;
	
	try {		
    	for(var i=0; i < desktopSettings.length; i++){
    		if(desktopSettings[i].settingName == sSettingName){
    			oDesktopSetting = desktopSettings[i];
    			oDesktopSetting.settingValue = sSettingValue;
    			break;
    		}
    	}
    	
    	if(oDesktopSetting == null){
    		oDesktopSetting = new desktopSettingObject(sSettingName, sSettingValue);
    		desktopSettings[desktopSettings.length] = oDesktopSetting;
    	} 
    
    	oEvent = createEventObject();
        oEvent.setAttribute("settingData", oDesktopSetting);
        desktopSettingChanged.fire(oEvent);
	} catch(e) {
	  	returnError(e.toString());
	} finally {
	  	oDesktopSetting = null;
		oEvent = null;
		sSettingName = null;
    	sSettingValue = null;
	}	
}


//+----------------------------------------------------------------------------
//
//  Function:       getDesktopSetting
//
//  Description:    
//
//  Arguments:      none
//
//  Returns:        nothing
//
//-----------------------------------------------------------------------------

function getDesktopSetting( sSettingName ) {
	try {		
    	for(var i=0; i < desktopSettings.length; i++){
    		if(desktopSettings[i].settingName == sSettingName){
    			return desktopSettings[i].settingValue;
    		}
    	}
    	
    	return null;
	} catch(e) {
	  	returnError(e.toString());
		return null;
	} finally {
	  	sSettingName = null;
	}	
}


//+----------------------------------------------------------------------------
//
//  Function:       clearDesktopSettings
//
//  Description:    
//
//  Arguments:      none
//
//  Returns:        nothing
//
//-----------------------------------------------------------------------------

function clearDesktopSettings() {
	var oRemovedDesktopSettings;

	try {	
		oRemovedDesktopSettings = desktopSettings.splice(0,desktopSettings.length);
	} catch(e) {
	  	returnError(e.toString());
	} finally {
	  	oRemovedDesktopSettings = null;
	}	
}


//+----------------------------------------------------------------------------
//
//  Function:       removeDesktopSetting
//
//  Description:    
//
//  Arguments:      none
//
//  Returns:        nothing
//
//-----------------------------------------------------------------------------

function removeDesktopSetting(sSettingName) {
	var oRemovedDesktopSetting;

	try {
    	for(var i=0; i < desktopSettings.length; i++){
    		if(desktopSettings[i].settingName == sSettingName){
    			oRemovedDesktopSetting = desktopSettings.splice(i,1);
    			return oRemovedDesktopSetting;
    		}
    	}
    	
    	return null;
	} catch(e) {
	  	returnError(e.toString());
    	return null;
	} finally {
	  	oRemovedDesktopSetting = null;
		sSettingName = null;
	}	
}


//+----------------------------------------------------------------------------
//
//  Function:       getAllDesktopSettings
//
//  Description:    
//
//  Arguments:      none
//
//  Returns:        nothing
//
//-----------------------------------------------------------------------------

function getAllDesktopSettings() {
	var oAllDesktopSettings = new Array;
	
	try {	
    	for(var i=0; i < desktopSettings.length; i++){
    		oAllDesktopSettings[oAllDesktopSettings.length] = desktopSettings[i]; 
    	}
    	
    	return oAllDesktopSettings;
	} catch(e) {
	  	returnError(e.toString());
    	return null;
	} finally {
	  	oAllDesktopSettings = null;
	}	
}


//+----------------------------------------------------------------------------
//
//  Private Methods
//
//-----------------------------------------------------------------------------


//+----------------------------------------------------------------------------
//
//  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
    desktopSettings = 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>

좋은 웹페이지 즐겨찾기