ft.js
来自「非常好的JAVASCRIPT树型」· JavaScript 代码 · 共 2,015 行 · 第 1/4 页
JS
2,015 行
}
function clickOnNode(folderId)
{
var cF = 0
var state = 0
oldwinheight = thisFrame.innerHeight
oldwinwidth = thisFrame.innerWidth
cF = indexOfEntries[folderId]
level = cF.nodeLevel
if (!cF) return false;
if (!cF.navObj && bV == 1) cF.navObj = doc.all["node" + cF.id]
state = cF.isOpen
if (!state) {
if (cF.isInitial == false) {
if(cF.nC == 0)
if (!addToTree)
alert("Folder has no children")
else
if (addToTree(cF) == true) return false;
if(cF.nC > 0) {
mWidth = -1
for (var i=0 ; i < cF.nC; i++){
mWidth = Math.max(mWidth, cF.c[i].menuWidth)
}
if (mWidth < 0) mWidth = menuWidth
if (bV == 2)
if (noFrame && cascade ) doc.yPos = 0
else doc.yPos = cF.navObj.clip.height
if (bV > 0) prior = cF.navObj
if (bV == 2 && noFrame && cascade) {
var divLayer = new Layer(mWidth, topLayer)
divLayer.document.open()
divLayer.document.write("")
divLayer.document.close()
divLayer.top = cF.navObj.top
if (horizontal && level == 1) divLayer.top += cF.navObj.clip.height
if (cF.nodeParent.divObj)
divLayer.top += cF.nodeParent.divObj.top
divLayer.bgColor = menuBackColor
if (cF.nodeParent.divObj)
divLayer.left = cF.nodeParent.divObj.left + cF.nodeParent.divObj.clip.width
else
divLayer.left = cF.navObj.clip.width + cF.navObj.left
if (horizontal && level == 1) divLayer.left = cF.navObj.left
divLayer.visibility = "show"
divLayer.zIndex=6000 + cF.id
divLayer.clip.width = mWidth
cF.divObj = divLayer
}
if (bV > 0) {
leftSide = cF.nodeLeftSide
if (bV == 1) {
strbufarray = new Array()
strbufIndex = 0
}
for (var i=0 ; i < cF.nC; i++)
{
cF.c[i].nodeParent = cF
if (i == cF.nC-1)
newLastNode = 1
else
last = 0
if (noDocs)
{
newLastNode = 1
for (var j=i+1; j < cF.nC; j++)
if (cF.c[j].isFolder) newLastNode = 0
}
else
{
newLastNode = 0
if (i == cF.nC-1) newLastNode = 1
}
if (!noDocs || cF.c[i].isFolder) {
if (bV == 2 && noFrame && cascade)
cF.c[i].initialize(level + 1, newLastNode, leftSide, doc, divLayer)
else
cF.c[i].initialize(level + 1, newLastNode, leftSide, doc, prior)
needRewrite = true
}
}
if (bV == 1){
htmlStr = strbufarray.join("")
if (cascade && noFrame) {
if (!horizontal || level > 1) {
leftdivpos = prior.offsetWidth + prior.offsetLeft
topdivpos = prior.offsetTop
} else {
if (!isNav6)leftdivpos = prior.offsetParent.offsetLeft
else leftdivpos = prior.offsetLeft
topdivpos = prior.offsetTop + prior.offsetHeight
}
zpos = 6000 + level
}
if (isNav6 || (isMac && isMSIE && isver4Min) ) {
newObj = thisFrame.document.createElement("DIV")
prior = doc.getElementById("node" + cF.id)
prior.appendChild(newObj)
newObj.innerHTML = htmlStr
newObj.id = "div" + cF.id
if (cascade && noFrame) {
newObj.style.position = "absolute"
newObj.style.backgroundColor = menuBackColor
newObj.style.top = topdivpos
newObj.style.left = leftdivpos
newObj.style.borderWidth = "2px"
newObj.style.borderStyle = menuBorderStyle
newObj.style.width = mWidth
//style? zIndex for mac IE. Book has zIndex. NN6?
newObj.style.zIndex = zpos
}
} else {
//alert(htmlStr)
if (!(cascade && noFrame))prior.insertAdjacentHTML("AfterEnd",htmlStr)
else {
if (!rightToLeft)
htmlStr = "<DIV id = 'div" + cF.id + "' style='position:absolute;border-style:" + menuBorderStyle + ";border-width:2px;background-color:" + menuBackColor + ";z-index:" + zpos + ";top:" + topdivpos + ";left:" +leftdivpos + "'>" + htmlStr + "</DIV>"
else
htmlStr = "<DIV align = 'right' id = 'div" + cF.id + "' style='position:absolute;border-style:solid;border-style:" + menuBorderStyle + ";border-width:2px;background-color:" + menuBackColor + ";z-index:" + zpos + ";top:" + topdivpos + ";left:" +leftdivpos + "'>" + htmlStr + "</DIV>"
prior.insertAdjacentHTML("AfterBegin",htmlStr)
}
}
}
}
cF.setState(!state)
cF.isInitial = true
}
}
else {
cF.setState(!state)
}
}
else {
if (bV == 0) cF.isInitial = false
cF.setState(!state)
}
if (bV == 2)cF.moveState(!state);
if (!state && modalClick && (cF.nodeLevel > 0))
for (i=0; i < cF.nodeParent.nC; i++)
{
if (cF.nodeParent.c[i].isOpen && (cF.nodeParent.c[i] != cF))
{
if (bV == 2) cF.nodeParent.c[i].moveState(false)
if (bV == 0) cF.nodeParent.c[i].isInitial = false
cF.nodeParent.c[i].setState(false)
}
}
if (noFrame && cascade && bV == 2) {
cascadeHeight = 0
cascadeWidth = 0
fT.totalSize()
topLayer.clip.width = cascadeWidth
topLayer.clip.height = cascadeHeight
}
if (bV == 0)
setTimeout("rewritepage()",50)
else
doc.close()
return false;
}
function collExp(mode)
{
var i=0
if (mode == 1)
{
this.isInitial = true
if (this.isFolder)
this.isOpen = true
}
else
{
this.isInitial = false
if (this.isFolder)
this.isOpen = false
}
if (this.isFolder) {
for (i=0; i<this.nC; i++)
this.c[i].collExp(mode)
}
}
function initMode()
{
var i=0
if (initialMode == 2)
{
if (this.isFolder) this.isOpen = true
this.isInitial = true
}
if (this.isFolder) {
for (i=0; i<this.nC; i++)
{
this.c[i].initMode()
if (this.c[i].isOpen && this.c[i].isInitial)
{
this.isOpen = true
this.isInitial = true
}
}
}
}
function reInitMode(state)
{
var i=0
if (this.isFolder) {
if (!this.isOpen || !state)
{
state = false
this.isInitial = false
}
for (i=0; i<this.nC; i++)
{
if (!state) this.c[i].isInitial = false
if (!state) this.c[i].isOpen = false
this.c[i].reInitMode(state)
}
}
}
function initializeDocument()
{
if (firstInitial)
{
if (initialMode == 0)
{
fT.isInitial = false
fT.isOpen = false
}
if (initialMode == 1)
{
fT.isInitial = true
fT.isOpen = true
}
fT.initMode()
}
else {
if (bV == 1) fT.reInitMode(true)
}
prior = null
fT.initialize(0, 1, "", doc, prior)
firstInitial = false
}
function collapseAll(){
var i=0
if (noFrame)
{
if (initialMode == 0)
{
if (!fT.navObj && bV == 1) fT.navObj = doc.all["node" + fT.id]
if (fT.isOpen){
fT.setState(!state)
if (bV == 2)fT.moveState(!state);
}
}
if (initialMode > 0)
{
for (i=0; i<fT.nC; i++)
{
if (fT.c[i].isOpen) {
if (!fT.c[i].navObj && bV == 1) fT.c[i].navObj = doc.all["node" + fT.c[i].id]
state = fT.c[i].isOpen
fT.c[i].setState(!state)
if (bV == 2)fT.c[i].moveState(!state);
if (cascade && bV == 2) {
cascadeHeight = fT.navObj.clip.height
cascadeWidth = fT.navObj.clip.width
fT.totalSize()
topLayer.clip.width = cascadeWidth
topLayer.clip.height = cascadeHeight
}
}
}
}
}
else
{
if (initialMode == 0)
{
fT.isInitial = false
fT.isOpen = false
}
if (initialMode > 0)
{
fT.isInitial = true
fT.isOpen = true
}
for (i=0; i<fT.nC; i++)
fT.c[i].collExp(0)
backButton = false
setTimeout("rewritepage()",50)
}
}
function expandAll(){
var i=0
if (noFrame)
{
for (i=0; i<nEntries; i++)
if (!indexOfEntries[i].isOpen)
{
indexOfEntries[i].setState(!state)
if (bV == 2)indexOfEntries[i].moveState(!state);
}
}
else
{
fT.collExp(1)
backButton = false
setTimeout("rewritepage()",50)
}
}
function initLayer() {
var i
var totalHeight
var oldyPos
var width = 0
if (!this.nodeParent)
layer = topLayer
else
layer = this.nodeParent.navObj
this.navObj = layer.document.layers["node"+this.id]
this.navObj.top = doc.yPos
if (horizontal && noFrame && cascade) this.navObj.left = doc.xPos
this.navObj.visibility = "show"
if (this.nC > 0 && this.isInitial && this.navObj.document.layers.length > 0)
{
doc.yPos += this.navObj.document.layers[0].top
oldyPos = doc.yPos
doc.yPos = this.navObj.document.layers[0].top
this.navObj.clip.height = doc.yPos
totalHeight = 0
for (i=0 ; i < this.nC; i++)
{
if (!noDocs || this.c[i].isFolder)
{
if (this.c[i].hidden == false) this.c[i].initLayer()
if (bV == 2)
{
totalHeight += this.c[i].navObj.clip.height
width = Math.max(width,this.c[i].navObj.clip.width)
}
}
}
if (this.isOpen)
{
doc.yPos = oldyPos + totalHeight
if (horizontal && noFrame && cascade) doc.yPos = oldyPos
this.navObj.clip.height += totalHeight
this.navObj.clip.width = Math.max(width, this.navObj.clip.width)
}
else
{
doc.yPos = oldyPos
}
}
else {
if (!(horizontal && noFrame && cascade)) doc.yPos += this.navObj.clip.height
if (horizontal && noFrame && cascade) doc.xPos += this.navObj.clip.width
}
}
suiArray = new Object()
function gFld(d, h, suid)
{
folder = new Node(d, h)
folder.isFolder = true
if (suid != null)
folder.suid = suid;
suiArray[suid] = folder
return folder
}
function gLnk(d, h, suid)
{
linkItem = new Node(d, h)
linkItem.isFolder = false
if (suid != null)
linkItem.suid = suid;
suiArray[suid] = linkItem
return linkItem
}
function insFld(p, c)
{
return p.addChild(c)
}
function insDoc(p, d)
{
return p.addChild(d)
}
function addChild(childNode)
{
this.c[this.nC] = childNode
childNode.nodeParent = this
childNode.nodeLevel = this.nodeLevel + 1
this.nC++
return childNode
}
function setCheckBox(visible, checkState) {
this.checkBox = visible
if(visible) this.checked = checkState
}
function setFont(font){
this.font = font
return
}
function setInitial(initial){
if (initial && this.isFolder)
{
this.isInitial = true
this.isOpen = true
}
return
}
function setIcon(o,c, oO,cO){
if (this.isFolder){
if (o != null) this.openIcon = o
if (c != null) this.closedIcon = c
if (oO != null) this.openIconOver = oO
if (cO != null) this.closedIconOver = cO
}
else
{
if (o != null) this.openIcon = o
if (c != null) this.openIconOver = c
}
return
}
function setWidth(menuW, textW){
if (menuW != null) this.menuWidth = menuW
if (textW != null) this.textWidth = textW
return
}
function setHeight(menuH){
if (menuH != null) this.menuHeight = menuH
return
}
function setBack(backI, backIO){
if (backI != null) this.backNImage = backI
if (backIO != null) this.backNImageOver = backIO
return
}
function fTimage(f){
this.src = iconFolder + f
return
}
function addImage(name, f){
if (!(document.all || isNav6) && !isOpera)
imageArray[name] = new fTimage(f)
else
{
imageArray[name] = new Image()
imageArray[name].src = iconFolder + f
}
nImageArray++
}
function addIcon(icon,prop,f) {
if (!(document.all || isNav6) && !isOpera)
icon[prop] = new fTimage(f)
else
{
icon[prop] = new Image()
icon[prop].src = iconFolder + f
}
if (f == "")
icon[prop] = null
}
function setTarget(t){
this.targetFrame = t
return
}
function setLinkType(l){
if (l >= 0 && 1 <= 3)
this.linkType = l
return
}
function setStatusBar(s){
if (s != null) this.statusText = s
return
}
function setUserDef(name,text){
if (text != null) this.userDef += "<" + name + ">" + text + "</" + name + ">"
return
}
function getUserDef(name){
substr1 = "<" + name + ">"
substr2 = "</" + name + ">"
length1 = substr1.length
index1 = this.userDef.indexOf(substr1)
index2 = this.userDef.indexOf(substr2)
if (index1 == -1 || index2 == -1) return "";
return this.userDef.substring(index1+length1,index2);
}
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?