2828} ) ( function ( $ ) {
2929 "use strict" ;
3030
31- // prevent duplicate loading
32- // if ( $.ui.fancytree && $.ui.fancytree.version ) {
33- // $.ui.fancytree.warn("Fancytree: duplicate include");
34- // return;
35- // }
36-
3731 /*******************************************************************************
3832 * Private functions and variables
3933 */
40- /*
41- function _assert(cond, msg){
42- msg = msg || "";
43- if(!cond){
44- $.error("Assertion failed " + msg);
45- }
46- }
47- */
34+ var _assert = $ . ui . fancytree . assert ,
35+ FT = $ . ui . fancytree ;
4836
4937 /*******************************************************************************
5038 * Private functions and variables
@@ -65,76 +53,116 @@ function _assert(cond, msg){
6553 $table = tree . widget . element ;
6654
6755 tree . tr = $ ( "tbody tr" , $table ) [ 0 ] ;
68- tree . columnCount = $ ( ">td" , tree . tr ) . length ;
56+ tree . $tdList = $ ( ">td" , tree . tr ) ;
57+ tree . columnCount = tree . $tdList . length ;
6958 // Perform default behavior
7059 this . _superApply ( arguments ) ;
7160 // Standard Fancytree created a root <ul>. Now move this into first table cell
7261 $ul = $ ( tree . rootNode . ul ) ;
73- $tdFirst = $ ( ">td" , tree . tr ) . eq ( 0 ) ;
62+ $tdFirst = tree . $tdList . eq ( 0 ) ;
7463
75- $ul . removeClass ( "fancytree-container" ) ;
76- $ul . removeAttr ( "tabindex" ) ;
64+ _assert (
65+ $ . inArray ( "table" , this . options . extensions ) < 0 ,
66+ "columnview extensions must not use ext-table"
67+ ) ;
68+ _assert (
69+ tree . columnCount >= 2 ,
70+ "columnview target must be a table with at least two columns"
71+ ) ;
72+
73+ $ul . removeClass ( "fancytree-container" ) . removeAttr ( "tabindex" ) ;
7774 tree . $container = $table ;
78- $table . addClass ( "fancytree-container fancytree-ext-columnview" ) ;
79- $table . attr ( "tabindex" , "0" ) ;
75+ $table
76+ . addClass ( "fancytree-container fancytree-ext-columnview" )
77+ . attr ( "tabindex" , "0" ) ;
8078
8179 $tdFirst . empty ( ) ;
8280 $ul . detach ( ) . appendTo ( $tdFirst ) ;
8381
8482 // Force some required options
8583 tree . widget . options . autoCollapse = true ;
86- // tree.widget.options.autoActivate = true;
84+ // tree.widget.options.autoActivate = true;
8785 tree . widget . options . toggleEffect = false ;
8886 tree . widget . options . clickFolderMode = 1 ;
8987
90- // Make sure that only active path is expanded when a node is activated:
9188 $table
89+ // Make sure that only active path is expanded when a node is activated:
9290 . on ( "fancytreeactivate" , function ( event , data ) {
93- var i ,
94- tdList ,
95- node = data . node ,
91+ var node = data . node ,
9692 tree = data . tree ,
9793 level = node . getLevel ( ) ;
9894
9995 tree . _callHook ( "nodeCollapseSiblings" , node ) ;
10096 // Clear right neighbours
101- if ( level <= tree . columnCount ) {
102- tdList = $ ( ">td" , tree . tr ) ;
103- for ( i = level ; i < tree . columnCount ; i ++ ) {
104- tdList . eq ( i ) . empty ( ) ;
105- }
97+ if ( ! node . expanded ) {
98+ tree . $tdList
99+ . eq ( level )
100+ . nextAll ( )
101+ . empty ( ) ;
106102 }
107103 // Expand nodes on activate, so we populate the right neighbor cell
108104 if ( ! node . expanded && ( node . children || node . lazy ) ) {
109105 node . setExpanded ( ) ;
110106 }
111- // Adjust keyboard behaviour:
112107 } )
108+ // Adjust keyboard behaviour:
113109 . on ( "fancytreekeydown" , function ( event , data ) {
114110 var next = null ,
115111 node = data . node || data . tree . getFirstChild ( ) ;
116- switch ( event . which ) {
117- case $ . ui . keyCode . DOWN :
112+
113+ if ( node . getLevel ( ) >= tree . columnCount ) {
114+ return ;
115+ }
116+ switch ( FT . eventToString ( event ) ) {
117+ case "down" :
118118 next = node . getNextSibling ( ) ;
119- if ( next ) {
120- next . setFocus ( ) ;
119+ break ;
120+ case "left" :
121+ if ( ! node . isTopLevel ( ) ) {
122+ next = node . getParent ( ) ;
121123 }
122- return false ;
123- case $ . ui . keyCode . LEFT :
124- next = node . getParent ( ) ;
125- if ( next ) {
126- next . setFocus ( ) ;
124+ break ;
125+ case "right" :
126+ next = node . getFirstChild ( ) ;
127+ if ( ! next ) {
128+ // default processing: expand or ignore
129+ return ;
127130 }
128- return false ;
129- case $ . ui . keyCode . UP :
131+ // Prefer an expanded child if any
132+ next . visitSiblings ( function ( n ) {
133+ if ( n . expanded ) {
134+ next = n ;
135+ return false ;
136+ }
137+ } , true ) ;
138+ break ;
139+ case "up" :
130140 next = node . getPrevSibling ( ) ;
131- if ( next ) {
132- next . setFocus ( ) ;
133- }
134- return false ;
141+ break ;
142+ }
143+ if ( next ) {
144+ next . setActive ( ) ;
135145 }
146+ return false ;
136147 } ) ;
137148 } ,
149+ nodeSetExpanded : function ( ctx , flag , callOpts ) {
150+ var $wait ,
151+ node = ctx . node ,
152+ tree = ctx . tree ,
153+ level = node . getLevel ( ) ;
154+
155+ if ( flag !== false && ! node . expanded && node . isUndefined ( ) ) {
156+ $wait = $ (
157+ "<span class='fancytree-icon fancytree-icon-loading'>"
158+ ) ;
159+ tree . $tdList
160+ . eq ( level )
161+ . empty ( )
162+ . append ( $wait ) ;
163+ }
164+ return this . _superApply ( arguments ) ;
165+ } ,
138166 nodeRender : function ( ctx , force , deep , collapsed , _recursive ) {
139167 // Render standard nested <ul> - <li> hierarchy
140168 this . _super ( ctx , force , deep , collapsed , _recursive ) ;
@@ -156,11 +184,12 @@ function _assert(cond, msg){
156184 ) ;
157185 }
158186 // Move <ul> with children into the appropriate <td>
159- if ( node . ul ) {
187+ if ( node . ul && node . expanded ) {
160188 node . ul . style . display = "" ; // might be hidden if RIGHT was pressed
161189 level = node . getLevel ( ) ;
162190 if ( level < tree . columnCount ) {
163- $tdChild = $ ( ">td" , tree . tr ) . eq ( level ) ;
191+ // only if we are not in the last column
192+ $tdChild = tree . $tdList . eq ( level ) ;
164193 $ul = $ ( node . ul ) . detach ( ) ;
165194 $tdChild . empty ( ) . append ( $ul ) ;
166195 }
0 commit comments