-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Added Dropzone and removed import button, removed timestamp from json…
… format
- Loading branch information
Showing
5 changed files
with
290 additions
and
140 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
.dropzone | ||
{ | ||
width: 100%; | ||
min-height: 100px; | ||
height: auto; | ||
color: #ccc; | ||
line-height: 100px; | ||
text-align: center; | ||
cursor: pointer; | ||
position: relative; | ||
} | ||
|
||
.dropzone .dropzone-items | ||
{ | ||
width: 100%; | ||
height: 100%; | ||
padding: 10px; | ||
position: relative; | ||
} | ||
|
||
.dropzone .aero-dropzone-text | ||
{ | ||
position: absolute; | ||
left: 0; | ||
top: 0; | ||
width: 100%; | ||
height: 100%; | ||
transform: translateY(0px); | ||
transition: all .3s ease 0s; | ||
} | ||
|
||
.dropzone.dragover | ||
{ | ||
border-color: #000; | ||
color: #000; | ||
} | ||
|
||
.dropzone.wrongFile | ||
{ | ||
border-color: #f00; | ||
color: #f00; | ||
} | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,117 @@ | ||
var dropzone = document.querySelector('.dropzone'); | ||
var filesForUpload = []; | ||
|
||
function uploadFiles() | ||
{ | ||
for (let i = 0; i < filesForUpload.length; i++) | ||
{ | ||
let file = filesForUpload[i]; | ||
let fileReader = new FileReader(); | ||
|
||
fileReader.addEventListener('load', function(e) | ||
{ | ||
let fileContent = e.target.result; | ||
importTabs(fileContent); | ||
}); | ||
|
||
fileReader.readAsText(file); | ||
} | ||
} | ||
|
||
function insertIntoFileList(file) | ||
{ | ||
for (let i = 0; i < filesForUpload.length; i++) | ||
{ | ||
if (file.name === filesForUpload[i].name || file.type !== 'application/json') | ||
{ | ||
// File already exists or is wrong file type | ||
return; | ||
} | ||
} | ||
|
||
filesForUpload.push(file); | ||
} | ||
|
||
function traverseFileTree(item, path) | ||
{ | ||
path = path || ""; | ||
if (item.isFile) | ||
{ | ||
// Get file | ||
item.file(function(file) | ||
{ | ||
insertIntoFileList(file); | ||
}); | ||
} | ||
else if (item.isDirectory) | ||
{ | ||
// Get folder contents | ||
let dirReader = item.createReader(); | ||
dirReader.readEntries(function(entries) | ||
{ | ||
for (var i=0; i<entries.length; i++) | ||
{ | ||
traverseFileTree(entries[i], path + item.name + "/"); | ||
} | ||
}); | ||
} | ||
} | ||
|
||
dropzone.ondragover = function() | ||
{ | ||
this.className = "dropzone dragover"; | ||
return false; | ||
}; | ||
|
||
dropzone.ondragleave = function() | ||
{ | ||
this.className = "dropzone"; | ||
return false; | ||
}; | ||
|
||
dropzone.ondrop = function(e) | ||
{ | ||
// prevent dropped files from opening in browser | ||
e.preventDefault(); | ||
|
||
this.className = "dropzone"; | ||
let items = e.dataTransfer.items; | ||
for (let i = 0; i < items.length; i++) | ||
{ | ||
let item = items[i].webkitGetAsEntry(); | ||
if (item) | ||
{ | ||
traverseFileTree(item); | ||
} | ||
} | ||
|
||
let files = e.dataTransfer.files; | ||
for (let i = 0; i < files.length; i++) | ||
{ | ||
insertIntoFileList(files[i]); | ||
} | ||
|
||
uploadFiles(); | ||
}; | ||
|
||
dropzone.addEventListener('click', function() | ||
{ | ||
let element = document.createElement('input'); | ||
element.setAttribute('type', 'file'); | ||
element.click(); | ||
|
||
element.addEventListener('change', function(e) | ||
{ | ||
let file = this.files[0]; | ||
let fileReader = new FileReader(); | ||
|
||
fileReader.addEventListener('load', function(e) | ||
{ | ||
let fileContent = e.target.result; | ||
importTabs(fileContent); | ||
}); | ||
|
||
fileReader.readAsText(file); | ||
}); | ||
}); | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.