transfer.sh/transfersh-web/scripts/main.js

151 lines
5.2 KiB
JavaScript
Raw Normal View History

2014-10-20 15:08:28 +02:00
$(document).ready(function() {
2014-10-16 20:01:43 +02:00
// Terminal typing animation
2014-10-20 15:08:28 +02:00
/* $("#from-terminal p").typed({
strings: ["curl --upload-file ./hello.txt https://transfer.sh/hello.txt\n######################################################\nhttps://transfer.sh/66nb8/hello.txt \n "],
typeSpeed: 0, // typing speed
backSpeed: 0, // backspacing speed
startDelay: 0, // time before typing starts
backDelay: 500, // pause before backspacing
loop: false, // loop on or off (true or false)
loopCount: false, // number of loops, false = infinite
showCursor: true,
attr: null, // attribute to type, null = text for everything except inputs, which default to placeholder
callback: function(){ } // call function after typing is done
});
*/
var typewriter = require('typewriter');
var twSpan = document.getElementById('terminal');
var tw = typewriter(twSpan).withAccuracy(95)
.withMinimumSpeed(5)
.withMaximumSpeed(17)
.build();
tw.put('$ ')
.waitRange(500, 1000)
.type('curl --upload-file ./hello.txt https://transfer.sh/hello.txt\n#######################')
.put('<br/>')
.waitRange(1000, 1500)
.put('ls: realistic-typewriter.js: No such file or directory<br/>')
.put('$ ')
.waitRange(1000, 1500)
.type('exit')
.put('<br/>')
.wait(500)
.put('logout<br/><br/>')
.put('[Process completed]<br/>');
2014-10-16 20:01:43 +02:00
// Smooth scrolling
2014-10-20 15:08:28 +02:00
$('a[href*=#]:not([href=#])').click(function() {
2014-10-16 20:01:43 +02:00
if (location.pathname.replace(/^\//, '') == this.pathname.replace(/^\//, '') && location.hostname == this.hostname) {
var target = $(this.hash);
target = target.length ? target : $('[name=' + this.hash.slice(1) + ']');
if (target.length) {
$('html,body').animate({
scrollTop: target.offset().top
}, 1000);
return false;
}
}
});
2014-10-20 11:15:41 +02:00
2014-10-20 15:08:28 +02:00
// function resizePages() {
// var h = $(window).height();
// var height = h < 600 ? 600 : h;
/* $('section').css('height',height);
2014-10-20 11:15:41 +02:00
$('#home').css('height',height*0.98);
}
resizePages();*/
2014-10-16 20:01:43 +02:00
});
2014-10-20 15:08:28 +02:00
(function() {
2014-10-16 20:01:43 +02:00
var files = Array()
function upload(file) {
2014-10-20 15:08:28 +02:00
$('.browse').addClass('uploading');
2014-10-16 20:01:43 +02:00
var li = $('<li style="clear:both;"/>');
2014-10-20 11:15:41 +02:00
2014-10-16 21:06:56 +02:00
li.append($('<div><div class="progress active upload-progress" style="margin-bottom: 0;"><div class="progress-bar bar" style="width: 0%;"></div></div><p>Uploading... ' + file.name + '</p></div>'));
2014-10-16 20:01:43 +02:00
$(li).appendTo($('.queue'));
var xhr = new XMLHttpRequest();
2014-10-20 15:08:28 +02:00
xhr.upload.addEventListener("progress", function(e) {
2014-10-16 20:01:43 +02:00
var pc = parseInt((e.loaded / e.total * 100));
$('.upload-progress', $(li)).show();
$('.upload-progress .bar', $(li)).css('width', pc + "%");
}, false);
2014-10-20 15:08:28 +02:00
xhr.onreadystatechange = function(e) {
2014-10-16 20:01:43 +02:00
if (xhr.readyState == 4) {
$('.upload-progress', $(li)).hide();
2014-10-20 11:15:41 +02:00
$('#web').addClass('uploading');
2014-10-16 20:01:43 +02:00
// progress.className = (xhr.status == 200 ? "success" : "failure");
if (xhr.status == 200) {
2014-10-16 21:25:04 +02:00
$(li).html('<a target="_blank" href="' + xhr.responseText + '">' + xhr.responseText + '</a>');
2014-10-16 20:01:43 +02:00
} else {
2014-10-16 21:25:04 +02:00
$(li).html('<span>Error (' + xhr.status + ') during upload of file ' + file.name + '</span>');
2014-10-16 20:01:43 +02:00
}
2014-10-16 21:35:37 +02:00
files.push(xhr.responseText.replace("https://transfer.sh/", "").replace("\n", ""));
// files.push(URI(xhr.responseText).absoluteTo(location.href).toString());
2014-10-16 20:01:43 +02:00
$(".download-zip").attr("href", URI("(" + files.join(",") + ").zip").absoluteTo(location.href).toString());
$(".download-tar").attr("href", URI("(" + files.join(",") + ").tar.gz").absoluteTo(location.href).toString());
2014-10-20 15:08:28 +02:00
$(".all-files").addClass('show');
2014-10-16 20:01:43 +02:00
}
};
// should queue all uploads.
// start upload
xhr.open("PUT", '/' + file.name, true);
xhr.setRequestHeader("X_FILENAME", file.name);
xhr.send(file);
};
2014-10-20 15:08:28 +02:00
$(document).bind("dragenter", function(event) {
2014-10-16 20:01:43 +02:00
event.preventDefault();
2014-10-20 15:08:28 +02:00
}).bind("dragover", function(event) {
2014-10-16 20:01:43 +02:00
event.preventDefault();
// show drop indicator
2014-10-20 15:08:28 +02:00
$('#web').addClass('dragged');
}).bind("dragleave", function(event) {
$('#web').removeClass('dragged');
console.log('asdasd');
}).bind("drop dragdrop", function(event) {
2014-10-16 20:01:43 +02:00
var files = event.originalEvent.target.files || event.originalEvent.dataTransfer.files;
2014-10-20 15:08:28 +02:00
$.each(files, function(index, file) {
2014-10-16 20:01:43 +02:00
console.debug(file);
upload(file);
});
event.stopPropagation();
event.preventDefault();
});
2014-10-20 15:08:28 +02:00
$('a.browse').on('click', function(event) {
2014-10-16 20:01:43 +02:00
$("input[type=file]").click();
return (false);
});
2014-10-20 15:08:28 +02:00
$('input[type=file]').on('change', function(event) {
$.each(this.files, function(index, file) {
2014-10-16 20:01:43 +02:00
if (file instanceof Blob) {
upload(file);
}
});
});
})();