You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 

111 regels
4.0 KiB

  1. $(document).ready(function () {
  2. // Terminal typing animation
  3. $("#from-terminal p").typed({
  4. strings: ["curl --upload-file ./hello.txt https://transfer.sh/hello.txt\n######################################################\nhttps://transfer.sh/66nb8/hello.txt \n "],
  5. typeSpeed: 0, // typing speed
  6. backSpeed: 0, // backspacing speed
  7. startDelay: 0, // time before typing starts
  8. backDelay: 500, // pause before backspacing
  9. loop: false, // loop on or off (true or false)
  10. loopCount: false, // number of loops, false = infinite
  11. showCursor: true,
  12. attr: null, // attribute to type, null = text for everything except inputs, which default to placeholder
  13. callback: function(){ } // call function after typing is done
  14. });
  15. // Smooth scrolling
  16. $('a[href*=#]:not([href=#])').click(function () {
  17. if (location.pathname.replace(/^\//, '') == this.pathname.replace(/^\//, '') && location.hostname == this.hostname) {
  18. var target = $(this.hash);
  19. target = target.length ? target : $('[name=' + this.hash.slice(1) + ']');
  20. if (target.length) {
  21. $('html,body').animate({
  22. scrollTop: target.offset().top
  23. }, 1000);
  24. return false;
  25. }
  26. }
  27. });
  28. });
  29. (function () {
  30. var files = Array()
  31. function upload(file) {
  32. var li = $('<li style="clear:both;"/>');
  33. 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>'));
  34. $(li).appendTo($('.queue'));
  35. var xhr = new XMLHttpRequest();
  36. xhr.upload.addEventListener("progress", function (e) {
  37. var pc = parseInt((e.loaded / e.total * 100));
  38. $('.upload-progress', $(li)).show();
  39. $('.upload-progress .bar', $(li)).css('width', pc + "%");
  40. }, false);
  41. xhr.onreadystatechange = function (e) {
  42. if (xhr.readyState == 4) {
  43. $('.upload-progress', $(li)).hide();
  44. // progress.className = (xhr.status == 200 ? "success" : "failure");
  45. if (xhr.status == 200) {
  46. $(li).html('<a target="_blank" href="' + xhr.responseText + '">' + xhr.responseText + '</a>');
  47. } else {
  48. $(li).html('<span>Error (' + xhr.status + ') during upload of file ' + file.name + '</span>');
  49. }
  50. files.push(URI(xhr.responseText).absoluteTo(location.href).toString());
  51. $(".download-zip").attr("href", URI("(" + files.join(",") + ").zip").absoluteTo(location.href).toString());
  52. $(".download-tar").attr("href", URI("(" + files.join(",") + ").tar.gz").absoluteTo(location.href).toString());
  53. $(".all-files").css("opacity", "1");
  54. }
  55. };
  56. // should queue all uploads.
  57. // start upload
  58. xhr.open("PUT", '/' + file.name, true);
  59. xhr.setRequestHeader("X_FILENAME", file.name);
  60. xhr.send(file);
  61. };
  62. $(document).bind("dragenter", function (event) {
  63. event.preventDefault();
  64. }).bind("dragover", function (event) {
  65. event.preventDefault();
  66. // show drop indicator
  67. }).bind("dragleave", function (event) {}).bind("drop dragdrop", function (event) {
  68. var files = event.originalEvent.target.files || event.originalEvent.dataTransfer.files;
  69. $.each(files, function (index, file) {
  70. console.debug(file);
  71. upload(file);
  72. });
  73. event.stopPropagation();
  74. event.preventDefault();
  75. });
  76. $('a.browse').on('click', function (event) {
  77. $("input[type=file]").click();
  78. return (false);
  79. });
  80. $('input[type=file]').on('change', function (event) {
  81. $.each(this.files, function (index, file) {
  82. if (file instanceof Blob) {
  83. upload(file);
  84. }
  85. });
  86. });
  87. })();