66 */
77var ClassTree = function ( parent , treeViewContainer ) {
88
9+ var self = this ;
10+
911 this . cacheUMLExplorer = parent ;
1012 this . container = treeViewContainer ;
1113 this . loader = null ;
1214 this . SELECTED_NAME = null ;
1315 this . SELECTED_TYPE = null ; // "class" || "package"
1416 this . SELECTED_ELEMENT = null ;
17+ this . treeObject = null ;
18+
19+ this . cacheUMLExplorer . elements . classTreeSearch . addEventListener ( "input" , function ( e ) {
20+ self . searchChanged . call ( self , ( e . target || e . srcElement ) . value ) ;
21+ } ) ;
1522
1623} ;
1724
1825ClassTree . prototype . showLoader = function ( ) {
1926
2027 if ( this . loader ) return ;
2128
29+ this . cacheUMLExplorer . elements . classTreeSearch . value = "" ;
30+ this . treeObject = null ;
2231 this . loader = document . createElement ( "div" ) ;
2332 this . loader . className = "spinner" ;
2433 this . container . appendChild ( this . loader ) ;
@@ -28,6 +37,8 @@ ClassTree.prototype.showLoader = function () {
2837ClassTree . prototype . removeLoader = function ( ) {
2938
3039 if ( ! this . loader ) return ;
40+
41+ this . cacheUMLExplorer . elements . classTreeSearch . value = "" ;
3142 this . loader . parentNode . removeChild ( this . loader ) ;
3243 this . loader = null ;
3344
@@ -61,7 +72,36 @@ ClassTree.prototype.packageSelected = function (element, packageName) {
6172
6273} ;
6374
64- ClassTree . prototype . updateTree = function ( treeObject ) {
75+ ClassTree . prototype . searchChanged = function ( query ) {
76+
77+ var o = this . treeObject ;
78+
79+ if ( ! o ) return ;
80+ query = query . toLowerCase ( ) ;
81+
82+ var searchClone = function ( o , copyFlag ) {
83+ var i , matches = 0 , lm , t , clone = { } , cpf ;
84+ for ( i in o ) {
85+ lm = 0 ; cpf = false ;
86+ if ( i . toLowerCase ( ) . indexOf ( query ) !== - 1 ) { lm += 1 ; matches ++ ; cpf = true ; }
87+ if ( typeof o [ i ] === "object" ) {
88+ lm += ( t = searchClone ( o [ i ] , cpf ) ) . matches ;
89+ matches += t . matches ;
90+ } else t = { obj : o [ i ] } ;
91+ if ( copyFlag || lm !== 0 ) clone [ i ] = t . obj ;
92+ }
93+ return { matches : matches , obj : clone } ;
94+ } ;
95+
96+ this . updateTree ( searchClone ( o ) . obj || { } , true ) ;
97+
98+ } ;
99+
100+ /**
101+ * @param treeObject
102+ * @param {boolean } [doNotChangeRoot] - Determines to restrict assign of this.treeObject.
103+ */
104+ ClassTree . prototype . updateTree = function ( treeObject , doNotChangeRoot ) {
65105
66106 var self = this ,
67107 div = function ( ) { return document . createElement ( "div" ) ; } ,
@@ -159,4 +199,6 @@ ClassTree.prototype.updateTree = function (treeObject) {
159199
160200 build ( this . container , treeObject , [ ] , 0 ) ;
161201
202+ if ( ! doNotChangeRoot ) this . treeObject = treeObject ;
203+
162204} ;
0 commit comments