You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
zhky/web/js/2k3Button.htc

273 lines
6.4 KiB

1 year ago
<PUBLIC:COMPONENT
<EFBFBD><EFBFBD><EFBFBD><EFBFBD>lightWeight<EFBFBD>=<3D>true
>
<PUBLIC:DEFAULTS
<EFBFBD><EFBFBD><EFBFBD><EFBFBD>contentEditable<EFBFBD>=<3D>false
<EFBFBD><EFBFBD><EFBFBD><EFBFBD>tabStop<EFBFBD>=<3D>true
/>
<PUBLIC:attach event="ondocumentready" onevent="initElement()" />
<PUBLIC:attach event="onmouseover" onevent="elementOnMouseOver()" />
<PUBLIC:attach event="onmouseout" onevent="elementOnMouseOut()" />
<PUBLIC:attach event="onmousedown" onevent="elementOnMouseDown()" />
<PUBLIC:attach event="onmouseup" onevent="elementOnMouseUp()" />
<PUBLIC:attach event="onpropertychange" onevent="elementPropertyChange()" />
<PUBLIC:attach event="onselectstart" onevent="elementOnSelect()" />
<PUBLIC:attach event="oncontextmenu" onevent="elementOnContextMenu()" />
<PUBLIC:attach event="ondetach" onevent="cleanupElement()" />
<PUBLIC:property name="buttonStyle" value="normal" />
<PUBLIC:property name="group" value="" />
<PUBLIC:property name="value" value=false />
<PUBLIC:property name="enabled" value=true />
<script language="jscript">
// ----------------------------------------------------
// 2k3Widgets: 2k3Button
//
// Copyright <20>2002-2004 Stedy Software and Systems
// Please see http://www.stedy.com for terms of use.
// ----------------------------------------------------
var onClickHolder = null ;
var vbLeftButton = 1 ;
var settingValueInternally = false ;
function initElement() {
settingValueInternally = true ;
element.value = makeBooleanOfAttribute("value") ;
if (element.value) {
showToggled(element) ;
}
element.enabled = makeBooleanOfAttribute("enabled") ;
if (!element.enabled) {
showDisabled(element) ;
}
settingValueInternally = false ;
}
function cleanupElement() {
}
function elementOnMouseOver() {
if (element.enabled) {
var fromElement = window.event.fromElement ;
if (fromElement != null) {
if (getRealItem(fromElement) == element) { return ; }
}
if (element.parentElement.parentElement.parentElement.parentElement.activeChild == null) {
if (element.buttonStyle.toLowerCase() == "toggle" && element.value) {
showActive(element) ;
}
else {
showOver(element) ;
}
}
}
}
function elementOnMouseOut() {
if (element.enabled) {
var toElement = window.event.toElement ;
if (toElement != null) {
if (getRealItem(toElement) == element) { return ; }
}
if (element.parentElement.parentElement.parentElement.parentElement.activeChild == null) {
if (element.buttonStyle.toLowerCase() == "toggle" && element.value) {
showToggled(element) ;
}
else {
showNormal(element) ;
}
}
}
}
function elementOnMouseDown() {
var el = getRealItem(window.event.srcElement) ;
if (element.parentElement.parentElement.parentElement.parentElement.activeChild == null) {
if ((window.event.button == vbLeftButton) && element.enabled) {
if (el.className.indexOf("2k3Button") == -1) {
return ;
}
if (el.className == "2k3ButtonOver") {
showActive(el) ;
}
}
}
}
function elementOnMouseUp() {
var el = getRealItem(window.event.srcElement) ;
if (element.parentElement.parentElement.parentElement.parentElement.activeChild == null) {
if ((window.event.button == vbLeftButton) && element.enabled) {
if (el.className.indexOf("2k3Button") == -1) {
return ;
}
if (el.className == "2k3ButtonActive") {
if (el == element) {
element.settingValueInternally = true ;
element.value = !element.value ;
element.settingValueInternally = false ;
if (buttonStyle == "toggle" && element.value) {
showActive(el) ;
setGroupItemState(el) ;
}
else {
showOver(el) ;
}
}
else {
showNormal(element) ;
}
}
}
}
}
function elementPropertyChange() {
if (window.event.propertyName == "enabled") {
if (element.enabled) {
showEnabled(element) ;
}
else {
showDisabled(element) ;
}
}
if (window.event.propertyName == "value") {
if (!element.settingValueInternally && element.enabled) {
setGroupItemState(element) ;
if (element.value) {
showToggled(element) ;
}
else {
showNormal(element) ;
}
// un-comment next line if you want a click event on toggle state change
//element.click() ;
}
}
}
function elementOnSelect() {
with (window.event) {
cancelBubble = true ;
returnValue = false ;
}
return false ;
}
function elementOnContextMenu() {
with (window.event) {
cancelBubble = true ;
returnValue = false ;
}
return false ;
}
function setGroupItemState(objUnknown) {
var currentRow = element.parentElement.parentElement ;
for (var i = 0; i < currentRow.cells.length; i++) {
var el = currentRow.cells[i].children[0] ;
if (el != null) {
if (el.className == "2k3ButtonToggled") {
if (el != element && el.group == element.group && el.group != "") {
if (el.value) {
el.value = false ;
return ;
}
}
}
}
}
}
function showNormal(el) {
with (el) {
if (className = "2k3Button") { className = "2k3Button" } ;
}
}
function showOver(el) {
with (el) {
if (className = "2k3ButtonOver") { className = "2k3ButtonOver" } ;
}
}
function showActive(el) {
with (el) {
if (className = "2k3ButtonActive") { className = "2k3ButtonActive" } ;
}
}
function showToggled(el) {
with (el) {
if (className = "2k3ButtonToggled") { className = "2k3ButtonToggled" } ;
}
}
function showDisabled(el) {
with (el) {
var strClassName = className ;
if (strClassName.substring(0, 9) == "2k3Button" && strClassName.indexOf("Disabled") == -1) {
className = "2k3ButtonDisabled" ;
if (onclick != null) {
onClickHolder = onclick ;
onclick = null ;
}
}
}
}
function showEnabled(el) {
with (el) {
if (className == "2k3ButtonDisabled") {
if (element.buttonStyle == "toggle" && element.value) {
className = "2k3ButtonToggled" ;
}
else {
className = "2k3Button" ;
}
if (onClickHolder != null) {
onclick = onClickHolder ;
onClickHolder = null ;
}
}
}
}
function getRealItem(el) {
var tmpElement = el ;
if (tmpElement == null) { return tmpElement ; }
if (tmpElement.tagName.toLowerCase() == "img") {
tmpElement = tmpElement.parentElement ;
}
if (tmpElement.className == "2k3ButtonCaption") {
tmpElement = tmpElement.parentElement ;
}
return tmpElement ;
}
function makeBooleanOfAttribute(attName) {
a = element.getAttribute(attName) ;
if (typeof(a) == "boolean") {
return a ;
}
else if (a == null) {
a = false ;
}
else if (typeof(a) == "string") {
a = a.toLowerCase() ;
a = (a == "true" || a == "1" || a == "yes") ;
}
else {
a = new Boolean(a) ;
}
return a ;
}
</script>
</PUBLIC:COMPONENT>