-
Notifications
You must be signed in to change notification settings - Fork 1
/
kee-tree.min.js
92 lines (92 loc) · 12 KB
/
kee-tree.min.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
!function(){function e(e,n){for(var t=0;t<e.length;t++)n==e[t]&&(e[t]=null)}var n=navigator.userAgent.toLowerCase()
window.kzg={browser:{version:(n.match(/.+(?:rv|it|ra|ie)[\/: ]([\d.]+)/)||[0,"0"])[1],safari:/webkit/.test(n),opera:/opera/.test(n),msie:/msie/.test(n)&&!/opera/.test(n),mozilla:/mozilla/.test(n)&&!/(compatible|webkit)/.test(n),chrome:/chrome/.test(n)},get:function(e){return document.getElementById(e)},setStyle:function(e,n){this.browser.msie&&this.browser.version<8?e.style.cssText=n:e.setAttribute("style",n)},addCss:function(e,n){if(n&&""!=n){for(var t=this._getCsss(e),r=n.split(/\s+/),i=0;i<r.length;i++)t[r[i]]=r[i]
var o=""
for(k in t)""!=k&&(o+=" "+k)
this.setCss(e,o)}},removeCss:function(e,n){if(n&&""!=n){var t=this._getCsss(e),r=""
for(k in t)""!=k&&n!=k&&(r+=" "+k)
this.setCss(e,r)}},_getCsss:function(e){for(var n={},t=this.getCss(e),r=t?t.split(/\s+/):[],i=0;i<r.length;i++)n[r[i]]=r[i]
return n},getCss:function(e){return this.browser.msie&&this.browser.version<8?e.getAttribute("className"):e.getAttribute("class")},setCss:function(e,n){this.browser.msie&&this.browser.version<8?e.setAttribute("className",n):e.setAttribute("class",n)},clearCss:function(e){this.setStyle(""),this.browser.msie&&this.browser.version<8?e.removeAttribute("className"):e.removeAttribute("class")},remove:function(e){e.parentNode&&e.parentNode.removeChild(e)},on:function(e,n,t){e.addEventListener?e.addEventListener(n,function(e){t(e)},!1):e.attachEvent&&e.attachEvent("on"+n,function(){t(window.event)})},oe:function(e,n,t){e.eves||(e.eves=[]),e.eves[n]||(e.eves[n]=[]),e.eves[n][e.eves[n].length]=t},ue:function(n,t,r){n.eves&&n.eves[t]&&e(n.eves[t],r)},fire:function(e,n,t){if(e.eves&&e.eves[n])for(var r={src:e,stop:!1},i=0;i<e.eves[n].length;i++)if(e.eves[n][i]&&(e.eves[n][i](r,t),r.stop))return},cr:function(e){return document.createElement(e)},crradio:function(e,n){var t
if(this.browser.msie&&this.browser.version<8){var r='<input type="radio" name="'+e+'" value="checked" >'
t=document.createElement(r)}else t=document.createElement("input"),t.setAttribute("type","radio"),t.setAttribute("name",e),t.setAttribute("value","checked")
return t.checked=n,t},ok:function(e){kzg.oe(kzg,"ok",e)},inade:function(e,n,t){switch(n.toLowerCase()){case"beforebegin":e.parentNode.insertBefore(t,e)
break
case"afterbegin":var r=e.childNodes?e.childNodes[0]:null
r||(r=null),e.insertBefore(t,r)
break
case"beforeend":e.appendChild(t)
break
case"afterend":var i=this.nextnode(e)
e.parentNode.insertBefore(t,i)}},nextnode:function(e){var n,t
t=null,n=e.parentNode
for(var r=0;n.childNodes[r];r++)if(n.childNodes[r]===e){try{t=n.childNodes[r+1]}catch(e){t=null}break}return t}},kzg.on(window,"load",function(){kzg.fire(kzg,"ok")})}(),kzg.TreeNode=function(e){var n=e.tree
this.tree=n
var t=this
t.keydex=null
var r=kzg.cr("span"),i=kzg.cr("span")
kzg.inade(i,"afterBegin",r),t.body=r,t.container=i
t.first=t.last=t.next=t.prev=null,t.caption=e.text,t.tier=null,t.parent=null,t.hasChild=!1,t.labstyle=null,t.type=e.type,t.expandStyle=null!=e.expandStyle?e.expandStyle:"auto",t.exIcon=null
var o=new Image
o.align="absmiddle",t.label=null,t.icon=o,t.tree=n,t.lineIcon=[],t.type=e.type?e.type:kzg.Tree.NORMAL,t.children=[],t.key=e.key
if(n.depth,t.label=kzg.cr("span"),kzg.setStyle(i,"margin:0px;padding:0px;white-space:nowrap;"),kzg.inade(r,"beforeEnd",t.label),kzg.setStyle(r,"margin:0px;cursor:default;text-align:left;color:black;font-size:9pt;"),e.iconCls?(o.src=kzg.Tree.S,kzg.setCss(o,e.iconCls)):e.icon?o.src=e.icon:(o.src=kzg.Tree.S,kzg.setCss(o,"k_tree_icon_default")),kzg.setStyle(t.label,n.labelStyle),kzg.inade(r,"afterBegin",o),o.tabIndex=t.label.tabIndex=1,o.hideFocus=!0,t.select=function(){t.isEnable()&&n.doSelect(t)},t.enable=function(e){t.disabled=!1===e},t.isEnable=function(){return!t.disabled},t.isVisible=function(){var e
return(e=t.container.style.display)&&"none"!=e},kzg.on(t.label,"click",t.select),kzg.on(t.icon,"click",t.select),r.oncontextmenu=function(){var e
if(e=kzg.browser.msie?window.event:arguments[0],n.oncontextmenu)return n.oncontextmenu(e,t)},t.addExIcon=function(){if(!t.exIcon){t.exIcon=new Image,t.exIcon.align="absmiddle",t.exIcon.src=kzg.Tree.S,kzg.on(t.exIcon,"click",function(){t.expand()})
var e=""==t.icon.src?t.label:t.icon
kzg.inade(e,"beforeBegin",t.exIcon)}},t.removeChildren=function(){for(t.getChildrenCount();t.children[0];)n.removeNode(t.children[0],!0)},t.setExpandStyle=function(e){null==e&&(e=t.expandStyle),"always"==e?(t.addExIcon(),!t.hasChild&&t.expanded&&(t.expanded=!1)):"auto"==e&&"auto"!=t.expandStyle&&(t.hasChild||null==t.exIcon||n.isLineStyle()||(t.body.removeChild(t.exIcon),t.exIcon=null)),t.expandStyle=e,n.setExIcon(t)},t.expand=function(e,r){if(0!=t.children.length||"always"==t.expandStyle){t.expanded=null==e?!t.expanded:e
for(var i=t.expanded?"block":"none",o=t.children.length,l=0;l<o;l++)t.children[l].container.style.display=i,!r||e^t.children[l].expanded||t.children[l].expand(t.expanded,!0)
n.setExIcon(t),t.expanded?kzg.fire(t,"expand"):kzg.fire(t,"collapse")}},kzg.Tree.CHECKBOX==t.type){var l=null
l=kzg.cr("input"),l.setAttribute("type","checkbox"),l.align="absmiddle",l.style.verticalAlign="middle",kzg.inade(t.label,"beforeBegin",l),t.checkBox=l,l.checked=t.checked=!1,kzg.on(l,"click",function(){t.checked=l.checked,kzg.fire(t,"click")})}else if(kzg.Tree.RADIOBOX==t.type){t.rdobox=null,t.checked=!1
var g=kzg.crradio(null,!1)
g.style.verticalAlign="middle",kzg.inade(t.label,"beforeBegin",g),kzg.on(g,"click",function(){t.setRadioCheck()}),t.rdoBox=g}return t.setChecked=function(e,n,r){if(kzg.Tree.CHECKBOX==t.type&&(t.checkBox.checked!=e&&(t.checked=t.checkBox.checked=e,r&&kzg.fire(t,"click")),n))for(var i=0;i<t.getChildrenCount();i++)t.children[i].setChecked(e,!0,r)},t.setRadioCheck=function(){if(kzg.Tree.RADIOBOX!=t.type)throw new Error("this is not a radiobox node.")
var e,r,i
if(null!=(e=t.parent)&&e!=n.root){i=e.checkedRdobox
for(var o=0;o<e.getChildrenCount();o++)r=e.children[o],r.rdoBox&&t!=r&&(r.checked=r.rdoBox.checked=!1)
e.checkedRdobox=t}t.checked=t.rdoBox.checked=!0,t.parent&&t.parent!=n.root&&i!=t&&kzg.fire(t.parent,"rdocheckchanged",{preNode:i,curNode:t})},this.setCaption=function(e){t.caption=e,t.label.innerHTML=e},t.setCaption(e.text),t.remove=function(){n.removeNode(t)},t.getChildrenCount=function(){return t.children?t.children.length:0},t.getTier=function(){return t.tier},t},kzg.Tree=function(e){function n(e,n){var t
t=!1
for(var r=0;r<e.length;r++)(n===e[r]||t)&&(e[r]=e[r+1],t=!0)
t&&e.length--}var t=this
kzg.Tree.SI||(kzg.Tree.SI=new Image,kzg.Tree.SI.src=kzg.Tree.S)
var r=e.labelStyle?r:"padding:0;margin-left:2;vertical-align:middle;text-align:left;"
this.labelStyle=r,t.depth=0
var i=0,o=[]
this.showline=e.showline
var l={}
l.children=[],l.expanded=!0,l.getTier=function(){return 0},t.selectedNode=null
var g=function(e){return"always"==e.expandStyle||e.hasChild},a=function(e){return e.parent==l&&l.children[0]==e},c=function(e){return null!=e.next},A=function(e){return null==e.next},s=function(e){var n,r=e.expanded
g(e)?n=t.showline?a(e)?A(e)?r?"k_tree_icon_collapse":"k_tree_icon_expand":r?"k_tree_icon_collapse_top":"k_tree_icon_expand_top":c(e)?r?"k_tree_icon_collapse_mid":"k_tree_icon_expand_mid":r?"k_tree_icon_collapse_end":"k_tree_icon_expand_end":r?"k_tree_icon_collapse_noline":"k_tree_icon_expand_noline":t.showline?a(e)?A(e)?e.exIcon&&(n="k_tree_icon_blank"):n="k_tree_icon_leaf_top":n=c(e)?"k_tree_icon_leaf":"k_tree_icon_twig":n="k_tree_icon_blank",e.exIcon||e.addExIcon(),e.exIcon?(e.icon.style.marginLeft="0",kzg.setCss(e.exIcon,n)):t.showline||(e.icon.style.marginLeft=kzg.Tree.SI.width)}
this.setExIcon=s
var d=function(e,n){if(e.hasChild)for(var r=0;r<e.children.length;r++)kzg.setCss(e.children[r].lineIcon[n],t.showline?"k_tree_icon_line":"k_tree_icon_blank"),d(e.children[r],n)}
this.setLine=d
var h=function(e){null!=t.selectedNode&&(t.selectedNode.label.style.background=t.selectedNode.label._background,t.selectedNode.label.style.color=t.selectedNode.label._color),e.label._background=e.label.style.background?e.label.style.background:"none",e.label._color=e.label.style.color?e.label.style.color:"black",e.label.style.background="highlight",e.label.style.color="highlighttext",t.selectedNode=e,kzg.fire(t,"select")}
this.doSelect=h,this.enable=function(e){for(var e=!1!==e,n=0;n<i;n++)o[n].enable(e)}
var u=function(n,r){r.tier=n.getTier()+1,n.children[n.children.length]=r
var o=n==l?t.body:n.container
kzg.inade(o,"beforeEnd",r.container),r.parent=n,n.hasChild?(r.prev=n.last,n.last.next=r,n.last=r):n.first=n.last=r,r.keydex=n.getChildrenCount(),r.parent.hasChild=!0,t.depth<r.tier&&(t.depth=r.tier),r.container.style.display=r.parent.expanded?"block":"none"
for(var a=(e.indent&&e.indent,r.tier-2);a>=0;a--){var c=new Image
c.align="absmiddle",c.src=kzg.Tree.S,kzg.inade(r.body,"afterBegin",c),r.lineIcon[a]=c}null!=r.prev&&t.setLine(r.prev,r.tier-1)
for(var A=r.parent,a=r.tier-2;A!=l&&a>=0;)null!=A.next&&kzg.setCss(r.lineIcon[a],t.showline?"k_tree_icon_line":"k_tree_icon_blank"),A=A.parent,a--
var s=r.parent
if(s!=l){if(null==s.exIcon){s.exIcon=new Image,s.exIcon.src=kzg.Tree.S,s.exIcon.align="absmiddle",kzg.on(s.exIcon,"click",function(){s.expand()})
var o=""==s.icon.src?s.label:s.icon
kzg.inade(o,"beforeBegin",s.exIcon)}t.setExIcon(s)}return r.expanded=!0,g(r)||(r.icon.style.marginLeft=kzg.Tree.SI.width),r.expanded=!0,r.setExpandStyle(),r.prev&&t.showline&&t.setExIcon(r.prev),r.key&&""!=r.key&&(t.nodes[r.key]=r),t.nodes[i]=r,i++,r}
this.addNode=u
var k=function(e){kzg.remove(e.container),n(o,e)}
this.removeAll=function(){var e,n
n=t.root.children,e=n.length
for(var r=0;r<e;)n[r]?t.removeNode(n[r],!0):r++},this.removeNode=function(e,r){if(e)if(e.hasChild){for(var i=e.children.length,o=0;o<i;)e.children[o]?t.removeNode(e.children[o],!0):o++
t.removeNode(e,r)}else{k(e)
var g=e.parent,a=e.prev,c=e.next
if(!r)if(g.first==e&&g.last==e&&g!=l)g.hasChild=!1,"always"!=g.expandStyle?kzg.remove(g.exIcon):g.expanded=!1,s(g),g.first=g.last=null
else if(null!=a?(a.next=c,s(a)):g.first=c,null!=c){c.prev=a,s(c)
var A
for(A=c;A;)A.keydex--,A=A.next}else g.last=a
g!=l&&(n(g.children,e),g.children.length<1&&(g.hasChild=!1)),i--,e=null}}
var C=function(e){var n,r,i
if("."==e)return t.root
i=t.root,n=e.split(".")
for(var o=0;o<n.length;o++)""!=n[o]&&(r=new Number(n[o]),i=i.children[r-1])
return t.root==i?null:i}
this.locate=C,this.getNodeKeydex=function(e){var n,t
for(n=e!=l?e.keydex:"",t=e.parent;l!=t;)n=t.keydex+"."+n,t=t.parent
return n="."+n},l.getChildrenCount=function(){return null!=l.children?l.children.length:0},this.getNodesByTier=function(e){for(var n=[],t=0;t<i;t++)o[t].getTier()==e&&(n[n.length]=o[t])
return n},this.expandAll=function(e,n){e=null==e?!l.expanded:e
for(var t=0;t<i;t++)o[t].expand(e,n),l.expanded=e},this.expandToTier=function(e){for(var n=0;n<i;n++)o[n].getTier()==e&&o[n].expanded&&o[n].expand(!1,!1),o[n].getTier()<e&&!o[n].expanded&&o[n].expand(!0,!1)},this.body=kzg.cr("div"),this.count=function(){return i},this.root=l,this.nodes=o,kzg.inade(e.to,"afterBegin",t.body)},kzg.Tree.NORMAL=0,kzg.Tree.CHECKBOX=1,kzg.Tree.RADIOBOX=2,kzg.Tree.S="data:image/gif;base64,R0lGODlhEwAUAPcAAAAAAIAAAACAAICAAAAAgIAAgACAgMDAwMDcwKbK8EAgAGAgAIAgAKAgAMAgAOAgAABAACBAAEBAAGBAAIBAAKBAAMBAAOBAAABgACBgAEBgAGBgAIBgAKBgAMBgAOBgAACAACCAAECAAGCAAICAAKCAAMCAAOCAAACgACCgAECgAGCgAICgAKCgAMCgAOCgAADAACDAAEDAAGDAAIDAAKDAAMDAAODAAADgACDgAEDgAGDgAIDgAKDgAMDgAODgAAAAQCAAQEAAQGAAQIAAQKAAQMAAQOAAQAAgQCAgQEAgQGAgQIAgQKAgQMAgQOAgQABAQCBAQEBAQGBAQIBAQKBAQMBAQOBAQABgQCBgQEBgQGBgQIBgQKBgQMBgQOBgQACAQCCAQECAQGCAQICAQKCAQMCAQOCAQACgQCCgQECgQGCgQICgQKCgQMCgQOCgQADAQCDAQEDAQGDAQIDAQKDAQMDAQODAQADgQCDgQEDgQGDgQIDgQKDgQMDgQODgQAAAgCAAgEAAgGAAgIAAgKAAgMAAgOAAgAAggCAggEAggGAggIAggKAggMAggOAggABAgCBAgEBAgGBAgIBAgKBAgMBAgOBAgABggCBggEBggGBggIBggKBggMBggOBggACAgCCAgECAgGCAgICAgKCAgMCAgOCAgACggCCggECggGCggICggKCggMCggOCggADAgCDAgEDAgGDAgIDAgKDAgMDAgODAgADggCDggEDggGDggIDggKDggMDggODggAAAwCAAwEAAwGAAwIAAwKAAwMAAwOAAwAAgwCAgwEAgwGAgwIAgwKAgwMAgwOAgwABAwCBAwEBAwGBAwIBAwKBAwMBAwOBAwABgwCBgwEBgwGBgwIBgwKBgwMBgwOBgwACAwCCAwECAwGCAwICAwKCAwMCAwOCAwACgwCCgwECgwGCgwICgwKCgwMCgwOCgwADAwCDAwEDAwGDAwIDAwKDAwP/78KCgpICAgP8AAAD/AP//AAAA//8A/wD//////yH5BAEAAP0ALAAAAAATABQAQAgiAPsJHEiwoMGDCBMqXMiwocOHECNKnEixosWLGDNq3CgwIAA7"