3
3
* See COPYING.txt for license details.
4
4
*/
5
5
6
+ /* global Base64 */
6
7
define ( [
7
8
'jquery' ,
8
9
'jquery/ui' ,
@@ -79,6 +80,7 @@ define([
79
80
tree = this . element ,
80
81
lastExistentFolderEl ,
81
82
pathId ,
83
+ encodedPath ,
82
84
83
85
/**
84
86
* Recursively open folders specified in path array.
@@ -102,14 +104,43 @@ define([
102
104
tree . jstree ( 'select_node' , folderEl ) ;
103
105
} ) ;
104
106
}
107
+ } ,
108
+
109
+ /**
110
+ * Get currentPath decode it returns new path array
111
+ */
112
+ _parseCurrentPath = function ( ) {
113
+ var paths = [ ] ;
114
+
115
+ $ . each ( encodedPath , function ( i , val ) {
116
+ var isLastElement = i === encodedPath . length - 1 ;
117
+
118
+ if ( isLastElement ) {
119
+ paths [ i ] = window . MediabrowserUtility . pathId . replace ( ',,' , '--' ) ;
120
+ } else {
121
+ paths [ i ] = Base64 . encode ( val ) . replace ( '==' , '--' ) ;
122
+ }
123
+ } ) ;
124
+ paths . unshift ( 'root' ) ;
125
+ paths . reverse ( ) ;
126
+
127
+ return paths ;
105
128
} ;
106
129
107
130
$ ( window ) . on ( 'reload.MediaGallery' , function ( ) {
131
+ encodedPath = Base64 . decode ( window . MediabrowserUtility . pathId . replace ( / - - | , , / , '==' ) ) . split ( '/' ) ;
108
132
pathId = window . MediabrowserUtility . pathId . replace ( ',,' , '--' ) ;
133
+
109
134
tree . jstree ( 'deselect_all' ) ;
110
- tree . jstree ( 'open_node' , $ ( '[data-id="' + pathId + '"]' ) , function ( ) {
111
- tree . jstree ( 'select_node' , $ ( '[data-id="' + pathId + '"]' ) ) ;
112
- } ) ;
135
+
136
+ if ( encodedPath . length > 1 ) {
137
+ path = _parseCurrentPath ( encodedPath ) ;
138
+ recursiveOpen ( ) ;
139
+ } else {
140
+ tree . jstree ( 'open_node' , $ ( '[data-id="' + pathId + '"]' ) , function ( ) {
141
+ tree . jstree ( 'select_node' , $ ( '[data-id="' + pathId + '"]' ) ) ;
142
+ } ) ;
143
+ }
113
144
} ) ;
114
145
115
146
recursiveOpen ( ) ;
0 commit comments