77 < link rel ="stylesheet " href ="../../../css/zTreeStyle/zTreeStyle.css " type ="text/css ">
88 < script type ="text/javascript " src ="../../../js/jquery-1.4.4.min.js "> </ script >
99 < script type ="text/javascript " src ="../../../js/jquery.ztree.core.js "> </ script >
10+ < script src ="https://use.fontawesome.com/952447aaab.js "> </ script >
1011 <!-- <script type="text/javascript" src="../../../js/jquery.ztree.excheck.js"></script>
1112 <script type="text/javascript" src="../../../js/jquery.ztree.exedit.js"></script>-->
13+ < style >
14+ .ztree li > a .highlight_alt
15+ {
16+ color : # 00A600 !important ;
17+ font-weight : bold;
18+ }
19+ .ztree li > a .highlight span .node_name : before ,
20+ .ztree li > a .highlight_hiddennodes span .node_name : before ,
21+ .ztree li > a .hiddennodes span .node_name : before
22+ {
23+ font-family : FontAwesome;
24+ color : green;
25+ font-size : 14px ;
26+ margin-right : 4px ;
27+ position : absolute;
28+ background-color : white;
29+ margin-left : -9px ;
30+ }
31+ .ztree li > a .highlight span .node_name : before
32+ {
33+ content : '\f058' ;
34+ }
35+ .ztree li > a .hiddennodes span .node_name : before
36+ {
37+ content : '\f00e' ;
38+ }
39+ .ztree li > a .highlight .hiddennodes span .node_name : before
40+ {
41+ content : '\f058\f00e' ;
42+ }
43+ </ style >
1244 < SCRIPT type ="text/javascript ">
1345 <!--
1446 var setting = {
47+ callback :
48+ {
49+ onCollapse : clickButton ,
50+ onExpand : clickButton
51+ } ,
1552 data : {
1653 key : {
1754 title : "t"
2158 }
2259 } ,
2360 view : {
24- fontCss : getFontCss
61+ fontCss : getFontCss ,
62+ nodeClasses : getNodeClasses
2563 }
2664 } ;
2765
5189 key . addClass ( "empty" ) ;
5290 }
5391 }
54- var lastValue = "" , nodeList = [ ] , fontCss = { } ;
92+ var lastValue = "" , nodeList = [ ] , fontCss = { } , nodeClasses = [ ] ;
5593 function clickRadio ( e ) {
5694 lastValue = "" ;
5795 searchNode ( e ) ;
5896 }
97+ function clickButton ( e , treeId , treeNode )
98+ {
99+ if ( $ ( "#styleNodesByCSS" ) . attr ( 'checked' ) ) return ;
100+ updateNodes ( false , treeNode ) ;
101+ updateNodes ( true , treeNode )
102+ }
59103 function searchNode ( e ) {
60104 var zTree = $ . fn . zTree . getZTreeObj ( "treeDemo" ) ;
61105 if ( ! $ ( "#getNodesByFilter" ) . attr ( "checked" ) ) {
75119 }
76120 if ( lastValue === value ) return ;
77121 lastValue = value ;
78- if ( value === "" ) return ;
79122 updateNodes ( false ) ;
123+ if ( value === "" ) return ;
80124
81125 if ( $ ( "#getNodeByParam" ) . attr ( "checked" ) ) {
82126 var node = zTree . getNodeByParam ( keyType , value ) ;
97141 updateNodes ( true ) ;
98142
99143 }
100- function updateNodes ( highlight ) {
144+ function updateNodes ( highlight , node = null ) {
101145 var zTree = $ . fn . zTree . getZTreeObj ( "treeDemo" ) ;
102- for ( var i = 0 , l = nodeList . length ; i < l ; i ++ ) {
146+ var applyClasses = $ ( "#styleNodesByClasses" ) . attr ( 'checked' ) ;
147+ var expanded = node && node . open ;
148+
149+ // If expanding a node then it MUST be a parent
150+ // in which case it cannot be hiding matched nodes
151+ if ( applyClasses && expanded )
152+ {
153+ node . hiddenNodes = false ;
154+ zTree . updateNode ( node ) ;
155+ }
156+
157+ for ( var i = 0 , l = nodeList . length ; i < l ; i ++ )
158+ {
103159 nodeList [ i ] . highlight = highlight ;
160+ nodeList [ i ] . hiddenNodes = false ;
161+ if ( applyClasses && highlight )
162+ {
163+ // Make parent nodes of matched nodes show the
164+ // existence of hidden nodes if the parent is closed.
165+ var node = nodeList [ i ] ;
166+ while ( true )
167+ {
168+ if ( ! node . parentTId ) break ;
169+ var parentNode = zTree . getNodeByTId ( node . parentTId ) ;
170+ if ( parentNode . isParent && parentNode . open ) break ;
171+ parentNode . hiddenNodes = true ;
172+ zTree . updateNode ( parentNode ) ;
173+ node = parentNode ;
174+ }
175+ }
104176 zTree . updateNode ( nodeList [ i ] ) ;
105177 }
106178 }
107179 function getFontCss ( treeId , treeNode ) {
108- return ( ! ! treeNode . highlight ) ? { color :"#A60000" , "font-weight" :"bold" } : { color :"#333" , "font-weight" :"normal" } ;
180+ return $ ( "#styleNodesByCSS" ) . attr ( 'checked' )
181+ ? ( ( ! ! treeNode . highlight ) ? { color :"#A60000" , "font-weight" :"bold" } : { color :"#333" , "font-weight" :"normal" } )
182+ : { color :"#333" , "font-weight" :"normal" } ;
183+ }
184+ function getNodeClasses ( treeId , treeNode ) {
185+ var classes = $ ( "#styleNodesByCSS" ) . attr ( 'checked' ) || ! ( ! ! treeNode . highlight || ! ! treeNode . hiddenNodes )
186+ ? { remove : [ 'highlight' , 'highlight_alt' , 'hiddennodes' , 'highlight_hiddennodes' ] }
187+ : ( ! ! treeNode . highlight
188+ ? ( ( ! ! treeNode . hiddenNodes )
189+ ? { add :[ 'highlight' , 'highlight_alt' , 'hiddennodes' ] }
190+ : { add :[ 'highlight' , 'highlight_alt' ] }
191+ )
192+ : { add :[ 'hiddennodes' , 'highlight_alt' ] }
193+ ) ;
194+ return classes ;
109195 }
110196 function filter ( node ) {
111197 return ! node . isParent && node . isFirstNode ;
126212 $ ( "#getNodesByParam" ) . bind ( "change" , clickRadio ) ;
127213 $ ( "#getNodesByParamFuzzy" ) . bind ( "change" , clickRadio ) ;
128214 $ ( "#getNodesByFilter" ) . bind ( "change" , clickRadio ) ;
215+ $ ( "#styleNodesByCSS" ) . bind ( "change" , clickRadio ) ;
216+ $ ( "#styleNodesByClasses" ) . bind ( "change" , clickRadio ) ;
217+ // $(".ztree li > span.button").bind("click", clickButton);
129218 } ) ;
130219 //-->
131220 </ SCRIPT >
@@ -152,6 +241,8 @@ <h6>[ File Path: core/searchNodes.html ]</h6>
152241 < input type ="radio " id ="getNodesByParam " name ="funType " class ="radio " style ="margin-left:36px; " /> < span > getNodesByParam</ span > < br />
153242 < input type ="radio " id ="getNodesByParamFuzzy " name ="funType " class ="radio " style ="margin-left:36px; " checked /> < span > getNodesByParamFuzzy (only string)</ span > < br />
154243 < input type ="radio " id ="getNodesByFilter " name ="funType " class ="radio " style ="margin-left:36px; " /> < span > getNodesByFilter (see source: function filter)</ span > < br />
244+ < input type ="radio " id ="styleNodesByCSS " name ="styleType " class ="radio " style ="margin-left:36px; " checked /> < span > styleNodesByCSS (see source: function filter)</ span > < br />
245+ < input type ="radio " id ="styleNodesByClasses " name ="styleType " class ="radio " style ="margin-left:36px; " /> < span > styleNodesByClasses (see source: function filter)</ span > < br />
155246 </ p >
156247 </ li >
157248 </ ul >
0 commit comments