-
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.
- Loading branch information
Showing
29 changed files
with
831 additions
and
203 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
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
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
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
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,72 @@ | ||
define([], function () { | ||
|
||
function readFile (file) { | ||
var reader = new FileReader(); | ||
// Closure to capture the file information. | ||
reader.onload = (function(theFile) { | ||
return function(e) { | ||
// FIXME (emit events?) | ||
// Render thumbnail. | ||
var span = document.createElement('span'); | ||
span.innerHTML = ['<p><img class="thumb" src="', e.target.result, | ||
'" title="', escape(theFile.name), '"/>', | ||
'<input type="checkbox" id="', escape(theFile.name) ,'">Is this a preview ?</p>'].join(''); | ||
$('#preview').html(span); | ||
}; | ||
})(file); | ||
|
||
// Read in the image file as a data URL. | ||
reader.readAsDataURL(file); | ||
} | ||
|
||
function sendFile () { | ||
var formData = new FormData(); | ||
var file = this.files[0]; | ||
var progress = document.createElement('progress'); | ||
progress.value = 0; | ||
progress.max = 100; | ||
progress.innerHTML = '0%' | ||
$(this).replaceWith(progress); | ||
|
||
if (file.type.match('image.*')) { | ||
$('button[type=submit]').attr('disabled', true); | ||
readFile(file); | ||
} | ||
|
||
var attached = $('.js-handler--filesAttached')[0].innerHTML.split(', '); | ||
attached.push(escape(file.name)); | ||
$('.js-handler--filesAttached')[0].innerHTML = attached.join(', '); | ||
|
||
formData.append('myFile', file); | ||
|
||
var xhr = new XMLHttpRequest(); | ||
|
||
xhr.open('post', '/upload', true); | ||
|
||
xhr.upload.onprogress = function(e) { | ||
if (e.lengthComputable) { | ||
var percentage = (e.loaded / e.total) * 100; | ||
$('progress').attr('value', percentage).text(percentage + '%'); | ||
} | ||
}; | ||
|
||
xhr.onerror = function(e) { | ||
console.log('An error occurred while submitting the form. Maybe your file is too big'); | ||
}; | ||
|
||
xhr.onload = function() { | ||
if (this.status == 200) { | ||
var $fileInput = $('<input type="file" class="topcoat-text-input">'); | ||
$('progress').replaceWith($fileInput); | ||
$fileInput.on('change', sendFile); | ||
$('button[type=submit]').attr('disabled', false); | ||
} | ||
}; | ||
|
||
xhr.send(formData); | ||
} | ||
|
||
return { | ||
sendFile: sendFile | ||
} | ||
}) |
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,6 @@ | ||
metrics-reset() | ||
margin 0 | ||
padding 0 | ||
|
||
warningBg = #FFFFBF | ||
var-item__title-color = #0096dd |
Oops, something went wrong.