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

163 lines
5.6 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
2014-10-24 09:58:59 +02:00
/* hljs.initHighlightingOnLoad();*/
2014-10-16 20:01:43 +02:00
// Terminal typing animation
2014-10-24 09:58:59 +02:00
/* $("#terminal-code").typed({
strings: ["# Upload using this \n acurl --upload-file ./hello.txt https://transfer.sh/hello.txt\n######################################################\nhttps://transfer.sh/66nb8/hello.txt \n "],
2014-10-20 15:08:28 +02:00
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
2014-10-24 09:58:59 +02:00
});*/
/*
var typewriter = require('typewriter');
2014-10-20 15:08:28 +02:00
2014-10-22 14:39:44 +02:00
var twSpan = document.getElementById('terminal-code');
2014-10-20 15:08:28 +02:00
2014-10-20 16:20:00 +02:00
var tw = typewriter(twSpan).withAccuracy(100)
2014-10-24 09:58:59 +02:00
.withMinimumSpeed()
2014-10-20 16:20:00 +02:00
.withMaximumSpeed(25)
2014-10-20 15:08:28 +02:00
.build();
2014-10-20 17:23:12 +02:00
2014-10-24 09:58:59 +02:00
tw.put('$ ')
.put('<span class="hljs-comment"># Upload using cURL </span>')
2014-10-20 15:08:28 +02:00
.waitRange(500, 1000)
2014-10-24 09:58:59 +02:00
.put('<br/>')
.type('$ curl --upload-file ./hello.txt https://transfer.sh/hello.txt')
2014-10-20 15:08:28 +02:00
.put('<br/>')
2014-10-20 17:23:12 +02:00
.put('https://transfer.sh/66nb8/hello.txt ')
.put('<br/>')
2014-10-24 09:58:59 +02:00
2014-10-20 17:23:12 +02:00
.waitRange(500, 1000)
.put('<br/>')
.waitRange(500, 1000)
2014-10-24 09:58:59 +02:00
.put('<span class="hljs-comment"># Upload using alias</span>')
2014-10-20 17:23:12 +02:00
.put('<br/>')
.type('transfer hello.txt')
.put('<br/>')
.type('####################################################')
.put(' 100.0%')
.put('<br/>')
2014-10-24 09:58:59 +02:00
.put('https://transfer.sh/eibhM/hello.txt ')*/
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() {
2014-10-24 09:58:59 +02:00
// var h = $(window).heightP();
2014-10-20 15:08:28 +02:00
// 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-24 09:58:59 +02:00
li.append($('<div><div class="progress active upload-progress" style="margin-bottom: 0;"><div class="bar" style="width: 0%;">############################>span></span></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));
2014-10-24 09:58:59 +02:00
/* $('.upload-progress', $(li)).show();*/
2014-10-16 20:01:43 +02:00
$('.upload-progress .bar', $(li)).css('width', pc + "%");
2014-10-24 09:58:59 +02:00
$('.upload-progress .bar .span').append( pc + "%");
2014-10-16 20:01:43 +02:00
}, 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);
}
});
});
})();
2014-10-22 14:39:44 +02:00