@@ -80,61 +80,84 @@ define([
80
80
tree = this . element ,
81
81
lastExistentFolderEl ,
82
82
pathId ,
83
- encodedPath ,
84
83
85
- /**
86
- * Recursively open folders specified in path array.
87
- */
88
- recursiveOpen = function ( ) {
89
- var folderEl = $ ( '[data-id="' + path . pop ( ) + '"]' ) ;
84
+ /**
85
+ * Recursively open folders specified in path array.
86
+ */
87
+ recursiveOpen = function ( ) {
88
+ var folderEl = $ ( '[data-id="' + path . pop ( ) + '"]' ) ;
90
89
91
- // if folder doesn't exist, select the last opened folder
92
- if ( ! folderEl . length ) {
93
- tree . jstree ( 'select_node' , lastExistentFolderEl ) ;
90
+ // if folder doesn't exist, select the last opened folder
91
+ if ( ! folderEl . length ) {
92
+ tree . jstree ( 'select_node' , lastExistentFolderEl ) ;
94
93
95
- return ;
96
- }
94
+ return ;
95
+ }
97
96
98
- lastExistentFolderEl = folderEl ;
97
+ lastExistentFolderEl = folderEl ;
99
98
100
- if ( path . length ) {
101
- tree . jstree ( 'open_node' , folderEl , recursiveOpen ) ;
99
+ if ( path . length ) {
100
+ tree . jstree ( 'open_node' , folderEl , recursiveOpen ) ;
101
+ } else {
102
+ tree . jstree ( 'open_node' , folderEl , function ( ) {
103
+ tree . jstree ( 'select_node' , folderEl ) ;
104
+ } ) ;
105
+ }
106
+ } ,
107
+
108
+ /**
109
+ * Encode path value
110
+ *
111
+ * @param {String } val
112
+ */
113
+ _encodePathId = function ( val ) {
114
+ return Base64 . encode ( val )
115
+ . replace ( / \+ / g, ':' )
116
+ . replace ( / \/ / g, '_' )
117
+ . replace ( / = / g, '-' ) ;
118
+ } ,
119
+
120
+ /**
121
+ * Decode path value
122
+ *
123
+ * @param {String } val
124
+ */
125
+ _decodePathId = function ( val ) {
126
+ return Base64 . decode ( val )
127
+ . replace ( / \: / g, '+' )
128
+ . replace ( / \_ / g, '/' )
129
+ . replace ( / - / g, '=' ) ;
130
+ } ,
131
+
132
+ /**
133
+ * Get currentPath decode it returns new path array
134
+ */
135
+ _parseCurrentPath = function ( ) {
136
+ var paths = [ ] ,
137
+ decodedPath = _decodePathId ( window . MediabrowserUtility . pathId . replace ( / - - | , , / , '==' ) ) . split ( '/' ) ;
138
+
139
+ $ . each ( decodedPath , function ( i , val ) {
140
+ var isLastElement = i === decodedPath . length - 1 ;
141
+
142
+ if ( isLastElement ) {
143
+ paths [ i ] = window . MediabrowserUtility . pathId . replace ( ',,' , '--' ) ;
102
144
} else {
103
- tree . jstree ( 'open_node' , folderEl , function ( ) {
104
- tree . jstree ( 'select_node' , folderEl ) ;
105
- } ) ;
145
+ paths [ i ] = _encodePathId ( val ) ;
106
146
}
107
- } ,
108
-
109
- /**
110
- * Get currentPath decode it returns new path array
111
- */
112
- _parseCurrentPath = function ( ) {
113
- var paths = [ ] ;
147
+ } ) ;
148
+ paths . unshift ( 'root' ) ;
149
+ paths . reverse ( ) ;
114
150
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 ;
128
- } ;
151
+ return paths ;
152
+ } ;
129
153
130
154
$ ( window ) . on ( 'reload.MediaGallery' , function ( ) {
131
- encodedPath = Base64 . decode ( window . MediabrowserUtility . pathId . replace ( / - - | , , / , '==' ) ) . split ( '/' ) ;
132
155
pathId = window . MediabrowserUtility . pathId . replace ( ',,' , '--' ) ;
156
+ path = _parseCurrentPath ( ) ;
133
157
134
158
tree . jstree ( 'deselect_all' ) ;
135
159
136
- if ( encodedPath . length > 1 ) {
137
- path = _parseCurrentPath ( encodedPath ) ;
160
+ if ( path . length > 1 ) {
138
161
recursiveOpen ( ) ;
139
162
} else {
140
163
tree . jstree ( 'open_node' , $ ( '[data-id="' + pathId + '"]' ) , function ( ) {
0 commit comments