626 lines
17 KiB
Plaintext
626 lines
17 KiB
Plaintext
<HTC URN="ex">
|
|
|
|
<!-- ---------------------------------------------------------------------
|
|
'
|
|
' Copyright 2001 Microsoft Corporation. All Rights Reserved.
|
|
'
|
|
' File: expand_vbs.htc
|
|
'
|
|
' Description: The expand behavior allows web authors to easily create
|
|
' expanding/collapsing menus and outlines.
|
|
'
|
|
'-------------------------------------------------------------------- -->
|
|
|
|
<PROPERTY NAME="imgExpand" />
|
|
<PROPERTY NAME="imgClose" />
|
|
<PROPERTY NAME="state" />
|
|
<PROPERTY NAME="masterState" />
|
|
<PROPERTY NAME="href" />
|
|
<PROPERTY NAME="target" />
|
|
<PROPERTY NAME="title" />
|
|
|
|
<METHOD NAME="expandAll" />
|
|
<METHOD NAME="closeAll" />
|
|
<METHOD NAME="expandNode" />
|
|
<METHOD NAME="closeNode" />
|
|
|
|
<EVENT NAME="onExpandAll" ID="expandall_event" />
|
|
<EVENT NAME="onCloseAll" ID="closeall_event" />
|
|
<EVENT NAME="onExpandNode" ID="expandnode_event" />
|
|
<EVENT NAME="onCloseNode" ID="closenode_event" />
|
|
<EVENT NAME="onError" ID="error" />
|
|
|
|
<ATTACH EVENT="ondocumentready" onevent="DoInit()" />
|
|
<ATTACH EVENT="onclick" onevent="CheckNode()" />
|
|
<ATTACH EVENT="ondrag" onevent="DoSelect()" />
|
|
|
|
|
|
<SCRIPT LANGUAGE="VBscript">
|
|
|
|
'+----------------------------------------------------------------------------
|
|
'
|
|
' Global Variables
|
|
'
|
|
'-----------------------------------------------------------------------------
|
|
|
|
dim bImage
|
|
bImage = true ' Tracks whether the node has an image associated with it
|
|
|
|
'+----------------------------------------------------------------------------
|
|
'
|
|
' Function: extant
|
|
'
|
|
' Description: Does the property exist? Unlike Jscript, VBS will choke rather than return
|
|
' NULL if you try to look at an undefined property.
|
|
'
|
|
' Arguments: The expression to be evaluated
|
|
'
|
|
' Returns: TRUE if the expression evaluates without error, FALSE otherwise
|
|
'
|
|
'-----------------------------------------------------------------------------
|
|
function extant( ex )
|
|
dim test
|
|
on error resume next
|
|
err.clear
|
|
test = eval( ex )
|
|
if err.number <> 0 then
|
|
extant = false
|
|
else
|
|
extant = true
|
|
end if
|
|
end function
|
|
|
|
|
|
'+----------------------------------------------------------------------------
|
|
'
|
|
' Function: DoInit
|
|
'
|
|
' Description: Nodes are formatted by setting defaults, adding images,
|
|
' and adding the indentation.
|
|
'
|
|
' Arguments: none
|
|
'
|
|
' Returns: nothing
|
|
'
|
|
'-----------------------------------------------------------------------------
|
|
|
|
sub DoInit()
|
|
SetDefaults()
|
|
|
|
' If imgExpand and imgClose are both null, don't include images
|
|
' !!! Possible nonexistence
|
|
if (IsNull(me.imgExpand) AND IsNull(me.imgClose)) then
|
|
bImage = false
|
|
else
|
|
' Set defaults for images.
|
|
if (IsNull(me.imgExpand) OR me.imgExpand = "default") then
|
|
me.imgExpand = "plus.gif"
|
|
end if
|
|
|
|
if (IsNull(me.imgClose) OR me.imgClose = "default") then
|
|
me.imgClose = "minus.gif"
|
|
end if
|
|
|
|
' Insert image into the element
|
|
sImgTag = "<IMG SRC='" & me.imgExpand & "' " _
|
|
& "imgExpand='" & me.imgExpand & "' " _
|
|
& "imgClose='" & me.imgClose & "'> "
|
|
end if
|
|
|
|
' If there are children, call FormatChildren() to format each
|
|
if children.length <> 0 then
|
|
FormatChildren(true)
|
|
if (bImage) then
|
|
insertAdjacentHTML "AfterBegin", sImgTag
|
|
end if
|
|
end if
|
|
|
|
' Attach onpropertychange
|
|
attachEvent "onpropertychange", GetRef("DoPropChange")
|
|
end sub
|
|
|
|
'+----------------------------------------------------------------------------
|
|
'
|
|
' Function: SetDefaults
|
|
'
|
|
' Description: Called during the initialization of the behavior. Sets
|
|
' the defaults for custom CSS properties (calls the
|
|
' CustomDefault() function), regular CSS properties (the
|
|
' NormalDefault() function), and attribute/properties.
|
|
'
|
|
' Arguments: none
|
|
'
|
|
' Returns: nothing
|
|
'
|
|
'-----------------------------------------------------------------------------
|
|
|
|
sub SetDefaults()
|
|
' Custom CSS Property Defaults
|
|
CustomDefault "mv--indent", "mvIndent", "17px"
|
|
|
|
' CSS Property Defaults
|
|
NormalDefault "cursor", "auto", "default"
|
|
|
|
' Attribute | Property Defaults
|
|
' !!! Possible nonexistence tests
|
|
if (IsNull(target)) then
|
|
target = "_self"
|
|
end if
|
|
|
|
if (IsNull(href)) then
|
|
href = ""
|
|
end if
|
|
|
|
state = "closed"
|
|
masterState = "closed"
|
|
end sub
|
|
|
|
|
|
'+----------------------------------------------------------------------------
|
|
'
|
|
' Function: CustomDefault
|
|
'
|
|
' Description: Sets the defaults for custom CSS properties and establishes
|
|
' a scriptable name for the property
|
|
'
|
|
' Arguments: sCSSName - the CSS name of the property
|
|
' sScriptName - the desired Scriptable name of the property
|
|
' sDefault - the desired default value
|
|
'
|
|
' Returns: nothing
|
|
'
|
|
'-----------------------------------------------------------------------------
|
|
|
|
sub CustomDefault(sCSSName, sScriptName, sDefault)
|
|
' !!! More nonexistence.. I should write a function..
|
|
if (IsNull(currentStyle.getAttribute(sCSSName))) then
|
|
Call style.setAttribute(sCSSName, sDefault)
|
|
else
|
|
Call style.setAttribute(sCSSName, currentStyle.getAttribute(sCSSName))
|
|
end if
|
|
Call style.setAttribute(sScriptName, style.getAttribute(sCSSName))
|
|
end sub
|
|
|
|
|
|
'+----------------------------------------------------------------------------
|
|
'
|
|
' Function: NormalDefault
|
|
'
|
|
' Description: Sets the defaults for CSS properties by checking the
|
|
' currentStyle and style of the object against the IE
|
|
' default.
|
|
'
|
|
' Arguments: sCSSName - the CSS name of the property
|
|
' sIEDefault - the IE standard default of the property
|
|
' sDefault - the desired default of the property
|
|
'
|
|
' Returns: nothing
|
|
'
|
|
'-----------------------------------------------------------------------------
|
|
|
|
sub NormalDefault(sCSSName, sIEDefault, sDefault)
|
|
if (currentStyle.getAttribute(sCSSName) = sIEDefault _
|
|
AND IsNull(style.getAttribute(sCSSName))) then
|
|
Call style.setAttribute(sCSSName, sDefault)
|
|
end if
|
|
end sub
|
|
|
|
|
|
'+----------------------------------------------------------------------------
|
|
'
|
|
' Function: FormatChildren
|
|
'
|
|
' Description: Sets the formatting for each level of child nodes
|
|
'
|
|
' Arguments: bInit - true (if setting at design time) or false (if
|
|
' setting at run time).
|
|
'
|
|
' Returns: nothing
|
|
'
|
|
'-----------------------------------------------------------------------------
|
|
|
|
sub FormatChildren(bInit)
|
|
' Check if an image is the first child, so it doesn't get formatted
|
|
dim iStart
|
|
iStart = 0
|
|
if ( not(bInit) AND bImage) then
|
|
iStart = 1
|
|
end if
|
|
|
|
' Iterate through children adding indenting as necessary and hiding them
|
|
for i = iStart to children.length - 1
|
|
' !!! Possible eval/execute
|
|
if (bInit) then
|
|
children(i).style.display = "none"
|
|
end if
|
|
children(i).style.marginLeft = style.mvIndent
|
|
next
|
|
end sub
|
|
|
|
|
|
'+----------------------------------------------------------------------------
|
|
'
|
|
' Function: DoPropChange
|
|
'
|
|
' Description: Handles property changes on CSS and regular property/
|
|
' attributes.
|
|
'
|
|
' Arguments: none
|
|
'
|
|
' Returns: nothing
|
|
'
|
|
'-----------------------------------------------------------------------------
|
|
|
|
sub DoPropChange()
|
|
|
|
propertyName = window.event.propertyName
|
|
|
|
'
|
|
' Handle CSS property changes by calling necessary functions, setting
|
|
' variables, and/or setting styles
|
|
'
|
|
if (Mid(propertyName , 1 , 5) = "style") then
|
|
select Case propertyName
|
|
case "style.mvIndent"
|
|
FormatChildren()
|
|
case "style.cursor"
|
|
|
|
end select
|
|
|
|
else
|
|
|
|
'
|
|
' Detach the onpropertychange event to prevent it from firing while
|
|
' the changes are handled
|
|
'
|
|
detachEvent "onpropertychange", GetRef("DoPropChange")
|
|
|
|
select Case (propertyName)
|
|
case "imgExpand"
|
|
if (bImage AND state = "closed") then
|
|
children(0).src = me.imgExpand
|
|
end if
|
|
|
|
case "imgClose"
|
|
if (bImage AND state = "expand") then
|
|
children[0].src = me.imgClose
|
|
end if
|
|
|
|
case "href"
|
|
|
|
|
|
case "target"
|
|
|
|
|
|
case "title"
|
|
|
|
|
|
case "state"
|
|
|
|
|
|
case "masterState"
|
|
|
|
|
|
case else
|
|
ReturnError(propertyName & " not a valid property")
|
|
|
|
end select
|
|
|
|
' Re-attach the onpropertychange event
|
|
attachEvent "onpropertychange", GetRef("DoPropChange")
|
|
end if
|
|
end sub
|
|
|
|
|
|
'+----------------------------------------------------------------------------
|
|
'
|
|
' Function: expandAll
|
|
'
|
|
' Description: Expand node and all children nodes
|
|
'
|
|
' Arguments: none
|
|
'
|
|
' Returns: nothing
|
|
'
|
|
'-----------------------------------------------------------------------------
|
|
|
|
sub expandAll()
|
|
|
|
' Get the collection of expand nodes in this element
|
|
Set oNodeTags = element.all.urns("ex")
|
|
|
|
' Expand all nodes in this element
|
|
for i = 0 to oNodeTags.length - 1
|
|
oNodeTags(i).expandNode(false)
|
|
next
|
|
|
|
' Expand this node
|
|
expandNode()
|
|
|
|
masterState = "expand"
|
|
expandall_event.fire()
|
|
end sub
|
|
|
|
|
|
'+----------------------------------------------------------------------------
|
|
'
|
|
' Function: closeAll
|
|
'
|
|
' Description: Close node and all children nodes
|
|
'
|
|
' Arguments: none
|
|
'
|
|
' Returns: nothing
|
|
'
|
|
'-----------------------------------------------------------------------------
|
|
|
|
sub closeAll()
|
|
' Close this node
|
|
closeNode()
|
|
|
|
' Get the collection of expand nodes in this element
|
|
Set oNodeTags = element.all.urns("ex")
|
|
|
|
' Expand all nodes in this element
|
|
for i = 0 to oNodeTags.length - 1
|
|
oNodeTags(i).closeNode(false)
|
|
next
|
|
|
|
msterState = "closed"
|
|
closeall_event.fire()
|
|
end sub
|
|
|
|
|
|
'+----------------------------------------------------------------------------
|
|
'
|
|
' Function: expandNode
|
|
'
|
|
' Description: Expands a node
|
|
'
|
|
' Arguments: bHref - true (function was called explicitly) or false
|
|
' (function was called as a result of an ExpandAll or
|
|
' CloseAll).
|
|
'
|
|
' Returns: nothing
|
|
'
|
|
'-----------------------------------------------------------------------------
|
|
|
|
sub expandNode(bHref)
|
|
|
|
' Call DoNode to expand this node
|
|
DoNode me.imgClose, "block"
|
|
|
|
' If this node has an HREF, do it
|
|
on error resume next
|
|
err.clear
|
|
hrefexists = href
|
|
if err.number <> 0 then
|
|
hrefexists = false
|
|
else
|
|
hrefexists = true
|
|
end if
|
|
on error goto 0
|
|
|
|
if (bHref AND href <> "" AND hrefexists) then
|
|
DoHref()
|
|
end if
|
|
|
|
state = "expand"
|
|
expandnode_event.fire()
|
|
end sub
|
|
|
|
|
|
'+----------------------------------------------------------------------------
|
|
'
|
|
' Function: closeNode
|
|
'
|
|
' Description: Closes a node
|
|
'
|
|
' Arguments: bHref - true (function was called explicitly) or false
|
|
' (function was called as a result of an ExpandAll or
|
|
' CloseAll).
|
|
'
|
|
' Returns: nothing
|
|
'
|
|
'-----------------------------------------------------------------------------
|
|
|
|
sub closeNode(bHref)
|
|
' Call DoNode to close this node
|
|
DoNode me.imgExpand, "none"
|
|
|
|
' If this node has an HREF, do it
|
|
if (bHref) then ' href != null) DoHref()
|
|
DoHref
|
|
end if
|
|
state = "closed"
|
|
closenode_event.fire()
|
|
end sub
|
|
|
|
|
|
'+----------------------------------------------------------------------------
|
|
'
|
|
' Function: CheckNode
|
|
'
|
|
' Description: Determine if a click occurred on a node or the image of a
|
|
' node. If so, based on the current state of that node,
|
|
' expand or close it.
|
|
'
|
|
' Arguments: none
|
|
'
|
|
' Returns: true if the source of the click was not a node or an
|
|
' image of a node.
|
|
'
|
|
'-----------------------------------------------------------------------------
|
|
|
|
function CheckNode()
|
|
' Did the click occur on the node or the node's image (if there is one)
|
|
if (window.event.srcElement Is element OR _
|
|
(bImage AND window.event.srcElement Is children(0))) then
|
|
|
|
setCapture()
|
|
|
|
' If the node is closed, open it
|
|
if (state = "closed") then
|
|
expandNode(true)
|
|
' Else close the node
|
|
else
|
|
closeNode(true)
|
|
end if
|
|
else
|
|
CheckNode = true
|
|
end if
|
|
end function
|
|
|
|
|
|
'+----------------------------------------------------------------------------
|
|
'
|
|
' Function: DoNode
|
|
'
|
|
' Description: Shows or hides a node and changes it's image source
|
|
' appropriately.
|
|
'
|
|
' Arguments: sImage - the source of the image to display for the node
|
|
' sDisplay - "block" or "none" to show or hide node
|
|
'
|
|
' Returns: nothing
|
|
'
|
|
'-----------------------------------------------------------------------------
|
|
|
|
sub DoNode(sImage, sDisplay)
|
|
|
|
' Apply the display formatting and image src as noted in the arguments
|
|
if children.length <> 0 then
|
|
|
|
if (bImage) then
|
|
children(0).src = sImage
|
|
end if
|
|
dim start
|
|
if bImage then
|
|
start = 1
|
|
else
|
|
start = 0
|
|
end if
|
|
for i = start to children.length - 1
|
|
children(i).style.display = sDisplay
|
|
next
|
|
end if
|
|
|
|
releaseCapture()
|
|
end sub
|
|
|
|
'+----------------------------------------------------------------------------
|
|
'
|
|
' Function: DoHref
|
|
'
|
|
' Description: Open the HREF into the TARGET.
|
|
'
|
|
' Arguments: none
|
|
'
|
|
' Returns: nothing
|
|
'
|
|
'-----------------------------------------------------------------------------
|
|
|
|
sub DoHref()
|
|
select case (target)
|
|
case "_self"
|
|
window.document.location.href = href
|
|
|
|
case "_top"
|
|
window.top.location.href = href
|
|
|
|
case "_parent"
|
|
window.parent.location.href = href
|
|
|
|
case "_blank"
|
|
window.open href, target
|
|
|
|
case else
|
|
FindTarget()
|
|
end select
|
|
end sub
|
|
|
|
|
|
'+----------------------------------------------------------------------------
|
|
'
|
|
' Function: FindTarget
|
|
'
|
|
' Description: Take the TARGET property and determine whether it is
|
|
' a separate frame or window, or an element. Open the
|
|
' HREF into that TARGET.
|
|
'
|
|
' Arguments: none
|
|
'
|
|
' Returns: nothing
|
|
'
|
|
'-----------------------------------------------------------------------------
|
|
|
|
function FindTarget()
|
|
if (target = "") then
|
|
window.open href, "_blank"
|
|
FindTarget = true
|
|
end if
|
|
|
|
' Is there a frames collection and is this one of them?
|
|
if (window.top.frames.length > 1) then
|
|
for i = 0 to window.top.frames.length - 1
|
|
'Possible eval problem..
|
|
if (window.top.frames(i).name = target) then
|
|
window.top.frames(i).src = href
|
|
FindTarget = true
|
|
end if
|
|
next
|
|
end if
|
|
|
|
for i = 0 to window.frames.length - 1
|
|
if (window.frames(i).name = target) then
|
|
window.frames(i).document.location.href = href
|
|
FindTarget = true
|
|
end if
|
|
next
|
|
|
|
window.open href, target
|
|
end function
|
|
|
|
|
|
'+----------------------------------------------------------------------------
|
|
'
|
|
' Function: DoSelect
|
|
'
|
|
' Description: Do not allow the contents of a node to be drag-selected.
|
|
'
|
|
' Arguments: none
|
|
'
|
|
' Returns: false (returnValue)
|
|
'
|
|
'-----------------------------------------------------------------------------
|
|
|
|
sub DoSelect()
|
|
window.event.cancelBubble = true
|
|
window.event.returnValue = false
|
|
end sub
|
|
|
|
|
|
'+----------------------------------------------------------------------------
|
|
'
|
|
' Function: ReturnError
|
|
'
|
|
' Description: Fires the error event, along with a descriptive text
|
|
' message.
|
|
'
|
|
' Arguments: sMsg - descriptive text message
|
|
'
|
|
' Returns: nothing
|
|
'
|
|
'-----------------------------------------------------------------------------
|
|
|
|
|
|
sub ReturnError(sMsg)
|
|
set oEvent = createEventObject
|
|
oEvent.setAttribute "error", sMsg
|
|
error.fire oEvent
|
|
end sub
|
|
|
|
|
|
</SCRIPT>
|
|
|
|
</HTC> |