home *** CD-ROM | disk | FTP | other *** search
HTML Component | 2001-08-08 | 9.1 KB | 378 lines |
- <PUBLIC:COMPONENT NAME="toolbar_button" URN="www.cogitum.com/toolbar_button.htc">
- <PUBLIC:ATTACH EVENT="oncontentready" ONEVENT="fnDraw()" FOR=element/>
- <PUBLIC:ATTACH EVENT="onpropertychange" ONEVENT="fnPropertyChange()" FOR="element"/>
- <PUBLIC:ATTACH EVENT="onmousedown" ONEVENT="fnMouseDown()" FOR="element"/>
- <PUBLIC:ATTACH EVENT="onmouseup" ONEVENT="fnMouseUp()" FOR="element"/>
- <PUBLIC:ATTACH EVENT="onclick" ONEVENT="fnMouseClick()" FOR="element"/>
- <PUBLIC:ATTACH EVENT="onmouseover" ONEVENT="fnMouseOver()" FOR="element"/>
- <PUBLIC:ATTACH EVENT="onmouseout" ONEVENT="fnMouseOut()" FOR="element"/>
- <PUBLIC:ATTACH EVENT="ondragstart" ONEVENT="fnDragStart()" FOR="element"/>
- <PUBLIC:PROPERTY NAME="ct_toolbar_button" GET="fnIdentify"/>
- <PUBLIC:PROPERTY NAME="ct_checkbutton" INTERNALNAME="bCheckButton" />
- <PUBLIC:PROPERTY NAME="ct_state" INTERNALNAME="bState" />
- <PUBLIC:PROPERTY NAME="ct_disabled" INTERNALNAME="bDisabled" />
- <PUBLIC:PROPERTY NAME="ct_dropdown" INTERNALNAME="bDropDown" />
- <PUBLIC:PROPERTY NAME="ct_sticky" INTERNALNAME="bSticky" />
- <PUBLIC:PROPERTY NAME="ct_onclick" INTERNALNAME="szOnClick" />
- <PUBLIC:METHOD NAME="ct_unstick" INTERNALNAME="fnUnStick"/>
- <PUBLIC:METHOD NAME="ct_stick_self" INTERNALNAME="fnStickSelf"/>
- <PUBLIC:METHOD NAME="ct_unstick_self" INTERNALNAME="fnUnStickSelf"/>
- <PUBLIC:METHOD NAME="ct_mouseover" INTERNALNAME="fnMouseOverSelf"/>
- <PUBLIC:METHOD NAME="ct_mouseout" INTERNALNAME="fnMouseOutSelf"/>
-
-
- <SCRIPT LANGUAGE="JScript">
- //
- // Sticky button (ct_sticky (bSticky) = 1 else nothing special happens)
- // ---------------
- // Disable/Enable (set ct_disabled = 0/1) result in clearing of stick state (bSticked)
- //
- // bSticked store stickness state. It's internal variable.
- // = 0 - normal functionality
- // = 1 - button have sticked. Switch to this state on button click (script execute)
- //
- // In "sticked" state (bSticked = 1):
- // - changes to the button other states stored in special variables (bActiveSticked, bPressedSticked)
- // instead of normal variables (bActive, bPressed)
- // - no changes happen to visual state of the button (no call to fnDraw())
- // - if ct_sticky changes to 0 then it equals to ct_unstick() call
- //
- // To switch to normal state script should call button's ct_unstick() method after execution
- // On ct_unstick():
- // - states from special variables (bActiveSticked, bPressedSticked) copied
- // to normal ones (bActive, bPressed)
- // - fnDraw() called to display all changes to the button since it was sticked
- //
- // Next calls to ct_unstick() do nothing.
- //
-
- var szOnClick = ""; // script to execute on ONCLICK event
-
- var bCheckButton = 0; // the button is the check button (it fixes in pressed state)
- var bDropDown = 0; // the button is the down arrow that call drop down list to select from
- // ex. Back in Internet Explorer
- var bSticky = 0; // if 1 then button stay pressed after ct_onclick executed until
- // call to ct_stickyup
- var bSticked = 0; // store current state of the button if it's sticky
- var bDisabled = 0; // the button is disabled (does not response to actions)
- var bState = 0; // mouse button is pressed (but not released) on the button
- var bActive = 0; // mouse is over the button
- var bActiveSticked = 0; // mouse is over the button that is in sticked state
- var bPressed = 0; // the button have been pressed previously
- var bPressedSticked = 0;// the button that is in sticked state have been pressed previously
-
- var activeCache = null;
- var grayCache = null;
-
- function fnToBoolean(someValue) {
- if( someValue == "false" || someValue == false
- || someValue == "0" || someValue == 0
- || isNaN(someValue) )
- {
- return false;
- }
- else
- {
- return true;
- }
- };
-
- function fnIdentify()
- {
- // this used for property ct_toolbar_button which is used to identify this behavior
- // always return 1
-
- return 1;
- }
-
- //
- // use "eltSibling" in the code string passed to this function to refer to sibling object
- //
- function fnExecCodeOnSibling(szCode, bPrevious)
- {
- if(!fnToBoolean(bDropDown))
- {
- var eltSibling = nextSibling;
- //
- if(eltSibling
- && fnToBoolean(eltSibling.ct_toolbar_button)
- && fnToBoolean(eltSibling.ct_dropdown) )
- {
- eval(szCode);
- }
- }
- else if(bPrevious)
- {
- var eltSibling = previousSibling;
- //
- if(eltSibling
- && fnToBoolean(eltSibling.ct_toolbar_button)
- && !fnToBoolean(eltSibling.ct_dropdown) )
- {
- eval(szCode);
- }
- }
- }
-
- function fnDraw()
- {
- /*
- if (activeCache == null) {
- activeCache = new Image();
- activeCache.src= element.activesrc;
- };
- if (grayCache == null) {
- grayCache = new Image();
- grayCache.src = element.graysrc;
- };
- */
- if(!fnToBoolean(bCheckButton))
- bState = 0;
- //
- // it's more correct to leave background setting to toolbar (as it can be image and so on)
- // element.runtimeStyle.backgroundColor = "#C0C0C0";
- //
- if(fnToBoolean(bDisabled))
- {
- //element.runtimeStyle.filter = "Gray Chroma(color = #C0C0C0) Alpha(Opacity=25) DropShadow(color=white, offx=1, offy=1)";
- element.src = element.graysrc;
- if(fnToBoolean(bCheckButton) & fnToBoolean(bState))
- {
- element.runtimeStyle.borderRight = "1px solid white";
- element.runtimeStyle.borderBottom = "1px solid white";
- element.runtimeStyle.borderTop = "1px solid black";
- element.runtimeStyle.borderLeft = "1px solid black";
- }
- else
- {
- element.runtimeStyle.border = "1px solid #C0C0C0";
- }
- }
- else
- {
- if(fnToBoolean(bState) || bPressed)
- {
- element.runtimeStyle.borderRight = "1px solid white";
- element.runtimeStyle.borderBottom = "1px solid white";
- element.runtimeStyle.borderTop = "1px solid black";
- element.runtimeStyle.borderLeft = "1px solid black";
- //if(bActive)
- // element.runtimeStyle.filter = "";
- //else
- // element.runtimeStyle.filter = "Gray";
- if(bActive)
- element.src = element.activesrc;
- else
- element.src = element.graysrc;
-
- }
- else
- {
- if(bActive)
- {
- //element.runtimeStyle.filter = "";
-
- element.src = element.activesrc;
-
- element.runtimeStyle.borderRight = "1px solid black";
- element.runtimeStyle.borderBottom = "1px solid black";
- element.runtimeStyle.borderTop = "1px solid white";
- element.runtimeStyle.borderLeft = "1px solid white";
- }
- else
- {
- //element.runtimeStyle.filter = "Gray Chroma(color = #C0C0C0)";
- element.src = element.graysrc;
- element.runtimeStyle.border = "1px solid #C0C0C0";
- }
- }
- }
-
- }
-
- function fnPropertyChange()
- {
- switch(window.event.propertyName)
- {
- case "ct_dropdown":
- return;
-
- case "ct_checkbutton":
- return;
-
- case "ct_state":
- break;
-
- case "ct_disabled":
- bPressed = 0;
- bActive = 0;
- bSticked = 0;
- //
- // you can't disable sibling button via dropdown button
- // disable both only via main button (with picture)
- // this done to don't produce endless loop
- fnExecCodeOnSibling("eltSibling.ct_disabled = bDisabled;", 0)
- //
- break;
-
- case "ct_sticky":
- if(fnToBoolean(bSticky))
- {
- fnUnStickSelf();
- break;
- }
- else
- return;
-
- default:
- return;
- }
- fnDraw();
- }
-
- function fnMouseDown()
- {
- if(window.event.button & 1) // pressed left button
- if(!fnToBoolean(bDisabled))
- if(bSticked)
- bPressedSticked = 1;
- else
- {
- bPressed = 1;
- fnDraw();
- }
- }
-
- function fnMouseUp()
- {
- if(window.event.button & 1) // pressed left button
- if(!fnToBoolean(bDisabled))
- if(bSticked)
- bPressedSticked = 0;
- else
- if(bPressed)
- {
- if(fnToBoolean(bCheckButton))
- {
- if(fnToBoolean(bState))
- bState = 0;
- else
- bState = 1;
- }
- if(szOnClick.length > 0)
- {
- fnStick();
- window.execScript(szOnClick);
- }
- bPressed = 0;
- fnDraw();
- }
- }
-
- //
- // called from sibling button if required
- //
- function fnMouseOverSelf()
- {
- if(!fnToBoolean(bDisabled))
- {
- if(bSticked)
- {
- bActiveSticked = 1;
- }
- else
- {
- bActive = 1;
- fnDraw();
- }
- }
- }
-
- function fnMouseOver()
- {
- if(!fnToBoolean(bDisabled))
- {
- fnMouseOverSelf();
- fnExecCodeOnSibling("eltSibling.ct_mouseover();", 1)
- }
- }
-
- //
- // called from sibling button if required
- //
- function fnMouseOutSelf()
- {
- if(!fnToBoolean(bDisabled))
- {
- if(bSticked)
- {
- bActiveSticked = 0;
- bPressedSticked = 0;
- }
- else
- {
- bActive = 0;
- bPressed = 0;
- fnDraw();
- }
- }
- }
-
- function fnMouseOut()
- {
- if(!fnToBoolean(bDisabled))
- {
- fnMouseOutSelf();
- fnExecCodeOnSibling("eltSibling.ct_mouseout();", 1)
- }
- }
-
- function fnMouseClick()
- {
- }
-
- function fnDragStart()
- {
- window.event.returnValue = false;
- }
-
- function fnUnStickSelf()
- {
- if(bSticked)
- {
- bSticked = 0;
- bPressed = bPressedSticked;
- bActive = bActiveSticked;
- fnDraw();
- }
- }
-
- function fnUnStick()
- {
- if(bSticked)
- {
- fnUnStickSelf();
- fnExecCodeOnSibling("eltSibling.ct_unstick_self();", 1)
- }
- }
-
- function fnStickSelf()
- {
- if(fnToBoolean(bSticky))
- {
- bSticked = 1;
- }
- }
-
- function fnStick()
- {
- if(fnToBoolean(bSticky))
- {
- fnStickSelf();
- fnExecCodeOnSibling("eltSibling.ct_stick_self();", 1)
- }
- }
-
- </SCRIPT>
- </PUBLIC:COMPONENT>
-