@@ -141,109 +141,30 @@ function renderImages(dirEntry) {
141
141
readDirectory ( dirEntry , function ( entries ) {
142
142
// Handle no files case.
143
143
if ( ! entries . length ) {
144
- footer . textContent = 'Add some files chief!' ;
145
- footer . classList . add ( 'nofiles' ) ;
146
- return ;
144
+ /* no files */
147
145
}
148
146
149
- footer . classList . remove ( 'nofiles' ) ;
150
-
151
- var frag = document . createDocumentFragment ( ) ;
152
-
153
- var span = document . createElement ( 'span' ) ;
154
- span . innerHTML = '«' ;
155
- span . title = 'Move up a directory;' ;
156
- span . addEventListener ( 'click' , onThumbnailClick ) ;
157
- frag . appendChild ( span ) ;
158
-
159
147
entries . forEach ( function ( entry , i ) {
160
148
var div = document . createElement ( 'div' ) ;
161
149
162
150
div . dataset . fullPath = entry . fullPath ;
151
+ console . info ( 'div.dataset.fullPath' , div . dataset . fullPath ) ;
163
152
164
153
var img = new Image ( ) ;
165
154
if ( entry . isDirectory ) {
166
- img . src = 'folder.png' ;
167
- div . dataset . isDirectory = 'true' ;
155
+ /* it's a folder */
168
156
} else {
169
157
//img.src = window.URL.createObjectURL(files[i]); // Equivalent to item.getAsFile().
170
158
entry . file ( function ( f ) {
159
+ console . info ( 'entry.toURL()' , entry . toURL ( ) ) ;
171
160
img . src = f . type . match ( '^image/' ) ? entry . toURL ( ) : 'file.png' ;
161
+ document . body . appendChild ( img ) ;
172
162
} , onError ) ;
173
163
}
174
164
175
165
img . title = entry . name ;
176
166
img . alt = entry . name ;
177
-
178
- var span = document . createElement ( 'span' ) ;
179
- span . textContent = entry . name ;
180
-
181
- var span2 = document . createElement ( 'span' ) ;
182
- span2 . textContent = 'X' ;
183
- span2 . classList . add ( 'close' ) ;
184
- span2 . addEventListener ( 'click' , onClose ) ;
185
-
186
- div . appendChild ( span2 ) ;
187
- div . appendChild ( img ) ;
188
- div . appendChild ( span ) ;
189
- div . addEventListener ( 'click' , onThumbnailClick ) ;
190
-
191
- frag . appendChild ( div ) ;
192
- } ) ;
193
-
194
- footer . innerHTML = '' ;
195
- footer . appendChild ( frag ) ;
196
- } ) ;
197
- }
198
-
199
- function onChange ( e ) {
200
- e . stopPropagation ( ) ;
201
- e . preventDefault ( ) ;
202
-
203
- var entries = e . target . webkitEntries ;
204
-
205
- // Dragging and dropping into the file input works fine but onchange doesn't
206
- // populate .webkitEntries when selecting from the file dialog
207
- // (crbug.com/138987). Thus, we need to explicitly write out files.
208
- if ( ! entries . length ) {
209
- var files = e . target . files ;
210
- var numWritten = 0 ;
211
-
212
- [ ] . forEach . call ( files , function ( f , i ) {
213
- if ( f . type . match ( '^image/' ) ) {
214
- writeFile ( f , cwd , function ( e ) {
215
- if ( ++ numWritten ) {
216
- setLoadingTxt ( { txt : DONE_MSG + ' writing ' + files . length + ' files.' } ) ;
217
- renderImages ( cwd ) ;
218
- }
219
- } ) ;
220
- } else {
221
- setLoadingTxt ( { txt : NOT_IMG_MSG , error : true } ) ;
222
- }
223
167
} ) ;
224
- return ;
225
- }
226
-
227
- [ ] . forEach . call ( entries , function ( entry ) {
228
-
229
- if ( entry . isDirectory ) {
230
- setLoadingTxt ( {
231
- txt : 'Importing directory: ' + entry . name ,
232
- stayOpen : true
233
- } ) ;
234
- } else {
235
- setLoadingTxt ( {
236
- txt : 'Importing file: ' + entry . name ,
237
- stayOpen : true
238
- } ) ;
239
- }
240
-
241
- // Copy entry over to the local filesystem.
242
- entry . copyTo ( cwd , null , function ( copiedEntry ) {
243
- setLoadingTxt ( { txt : DONE_MSG } ) ;
244
- renderImages ( cwd ) ;
245
- } , onError ) ;
246
-
247
168
} ) ;
248
169
}
249
170
@@ -262,33 +183,29 @@ function onDrop(e) {
262
183
263
184
var entry = item . webkitGetAsEntry ( ) ;
264
185
if ( entry . isDirectory ) {
265
- setLoadingTxt ( {
266
- txt : 'Importing directory: ' + entry . name ,
267
- stayOpen : true
268
- } ) ;
269
-
270
- // Copy the dropped DirectoryEntry over to our local filesystem.
271
- entry . copyTo ( cwd , null , function ( copiedEntry ) {
272
- renderImages ( cwd ) ;
273
- } , onError ) ;
186
+ /* it's a folder */
274
187
} else {
275
188
if ( entry . isFile && files [ i ] . type . match ( '^image/' ) ) {
276
189
// Copy the dropped entry into local filesystem.
277
190
entry . copyTo ( cwd , null , function ( copiedEntry ) {
278
191
renderImages ( cwd ) ;
279
192
} , onError ) ;
280
193
} else {
281
- setLoadingTxt ( { txt : NOT_IMG_MSG , error : true } ) ;
194
+ /* it's not an image */
282
195
}
283
196
}
284
197
}
285
198
}
286
199
287
- function init ( ) {
288
- $ ( "#new-profile-pic" ) . on ( "drop" , function ( e ) {
289
- onDrop ( e ) ;
200
+ function initFileDragDrop ( ) {
201
+ $ ( ".lbl-new-profile-pic" ) . on ( "drop" , function ( e ) {
202
+ onDrop ( e . originalEvent ) ;
203
+ } ) . on ( "dragstart" , function ( ) {
204
+ e . preventDefault ( ) ;
205
+ return false ;
290
206
} ) . on ( "dragover" , function ( e ) {
291
207
e . preventDefault ( ) ;
208
+ return false ;
292
209
} ) . on ( "dragenter" , function ( e ) {
293
210
e . target . classList . add ( 'active' ) ;
294
211
} ) . on ( "dragleave" , function ( ) {
@@ -302,3 +219,7 @@ function init() {
302
219
renderImages ( cwd ) ;
303
220
} , onError ) ;
304
221
}
222
+
223
+ $ ( function ( ) {
224
+ initFileDragDrop ( ) ;
225
+ } ) ;
0 commit comments