|
110 | 110 | this.onDrop = function (event) { |
111 | 111 | event.stopPropagation(); |
112 | 112 | event.preventDefault(); |
113 | | - $.addFiles(event.dataTransfer.files, event); |
| 113 | + var dataTransfer = event.dataTransfer; |
| 114 | + if (dataTransfer.items && dataTransfer.items[0].webkitGetAsEntry) { |
| 115 | + $.webkitReadDataTransfer(event); |
| 116 | + } else { |
| 117 | + $.addFiles(dataTransfer.files, event); |
| 118 | + } |
114 | 119 | }; |
115 | 120 |
|
116 | 121 | /** |
|
169 | 174 | return !preventDefault; |
170 | 175 | }, |
171 | 176 |
|
| 177 | + /** |
| 178 | + * Read webkit dataTransfer object |
| 179 | + * @param event |
| 180 | + */ |
| 181 | + webkitReadDataTransfer: function (event) { |
| 182 | + var $ = this; |
| 183 | + each(event.dataTransfer.items, function (item) { |
| 184 | + var entry = item.webkitGetAsEntry(); |
| 185 | + if (!entry) { |
| 186 | + return ; |
| 187 | + } |
| 188 | + if (entry.isFile) { |
| 189 | + // due to a bug in Chrome's File System API impl - #149735 |
| 190 | + fileReadSuccess(item.getAsFile(), entry.fullPath); |
| 191 | + } else { |
| 192 | + entry.createReader().readEntries(readSuccess, readError); |
| 193 | + } |
| 194 | + }); |
| 195 | + function readSuccess(entries) { |
| 196 | + each(entries, function(entry) { |
| 197 | + if (entry.isFile) { |
| 198 | + var fullPath = entry.fullPath; |
| 199 | + entry.file(function (file) { |
| 200 | + fileReadSuccess(file, fullPath); |
| 201 | + }, readError); |
| 202 | + } else if (entry.isDirectory) { |
| 203 | + entry.createReader().readEntries(readSuccess, readError); |
| 204 | + } |
| 205 | + }); |
| 206 | + } |
| 207 | + function fileReadSuccess(file, fullPath) { |
| 208 | + // relative path should not start with "/" |
| 209 | + file.relativePath = fullPath.substring(1); |
| 210 | + $.addFile(file, event); |
| 211 | + } |
| 212 | + function readError(fileError) { |
| 213 | + throw fileError; |
| 214 | + } |
| 215 | + }, |
172 | 216 |
|
173 | 217 | /** |
174 | 218 | * Generate unique identifier for a file |
|
182 | 226 | return custom(file); |
183 | 227 | } |
184 | 228 | // Some confusion in different versions of Firefox |
185 | | - var relativePath = file.webkitRelativePath || file.fileName || file.name; |
186 | | - var size = file.size; |
187 | | - return size + '-' + relativePath.replace(/[^0-9a-zA-Z_-]/img, ''); |
| 229 | + var relativePath = file.relativePath || file.webkitRelativePath || file.fileName || file.name; |
| 230 | + return file.size + '-' + relativePath.replace(/[^0-9a-zA-Z_-]/img, ''); |
188 | 231 | }, |
189 | 232 |
|
190 | 233 | /** |
|
557 | 600 | * Relative file path |
558 | 601 | * @type {string} |
559 | 602 | */ |
560 | | - this.relativePath = file.webkitRelativePath || this.name; |
| 603 | + this.relativePath = file.relativePath || file.webkitRelativePath || this.name; |
561 | 604 |
|
562 | 605 | /** |
563 | 606 | * File unique identifier |
|
0 commit comments