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.
 
 
 

162 lines
5.5 KiB

  1. $(document).ready(function() {
  2. // Smooth scrolling
  3. $('a[href*=#]:not([href=#])').click(function() {
  4. if (location.pathname.replace(/^\//, '') == this.pathname.replace(/^\//, '') && location.hostname == this.hostname) {
  5. var target = $(this.hash);
  6. target = target.length ? target : $('[name=' + this.hash.slice(1) + ']');
  7. if (target.length) {
  8. $('html,body').animate({
  9. scrollTop: target.offset().top
  10. }, 1000);
  11. return false;
  12. }
  13. }
  14. });
  15. });
  16. (function() {
  17. var files = Array()
  18. function upload(file) {
  19. $('.browse').addClass('uploading');
  20. var li = $('<li style="clear:both;"/>');
  21. li.append($('<div><div class="upload-progress"><span></span><div class="bar" style="width:0%;">####################################################</div></div><p>Uploading... ' + file.name + '</p></div>'));
  22. $(li).appendTo($('.queue'));
  23. var xhr = new XMLHttpRequest();
  24. xhr.upload.addEventListener("progress", function(e) {
  25. var pc = parseInt((e.loaded / e.total * 100));
  26. $('.upload-progress', $(li)).show();
  27. $('.upload-progress .bar', $(li)).css('width', pc + "%");
  28. $('.upload-progress span ').empty().append(pc + "%");
  29. }, false);
  30. xhr.onreadystatechange = function(e) {
  31. if (xhr.readyState == 4) {
  32. /* $('.upload-progress', $(li)).hide();*/
  33. $('#web').addClass('uploading');
  34. // progress.className = (xhr.status == 200 ? "success" : "failure");
  35. if (xhr.status == 200) {
  36. $(li).html('<a target="_blank" href="' + xhr.responseText + '">' + xhr.responseText + '</a>');
  37. } else {
  38. $(li).html('<span>Error (' + xhr.status + ') during upload of file ' + file.name + '</span>');
  39. }
  40. files.push(xhr.responseText.replace("https://transfer.sh/", "").replace("\n", ""));
  41. // files.push(URI(xhr.responseText).absoluteTo(location.href).toString());
  42. $(".download-zip").attr("href", URI("(" + files.join(",") + ").zip").absoluteTo(location.href).toString());
  43. $(".download-tar").attr("href", URI("(" + files.join(",") + ").tar.gz").absoluteTo(location.href).toString());
  44. $(".all-files").addClass('show');
  45. }
  46. };
  47. // should queue all uploads.
  48. // start upload
  49. xhr.open("PUT", '/' + file.name, true);
  50. xhr.setRequestHeader("X_FILENAME", file.name);
  51. xhr.send(file);
  52. };
  53. $(document).bind("dragenter", function(event) {
  54. event.preventDefault();
  55. }).bind("dragover", function(event) {
  56. event.preventDefault();
  57. // show drop indicator
  58. $('#terminal').addClass('dragged');
  59. $('#web').addClass('dragged');
  60. }).bind("dragleave", function(event) {
  61. $('#terminal').removeClass('dragged');
  62. $('#web').removeClass('dragged');
  63. }).bind("drop dragdrop", function(event) {
  64. var files = event.originalEvent.target.files || event.originalEvent.dataTransfer.files;
  65. $.each(files, function(index, file) {
  66. console.debug(file);
  67. upload(file);
  68. });
  69. event.stopPropagation();
  70. event.preventDefault();
  71. });
  72. $('a.browse').on('click', function(event) {
  73. $("input[type=file]").click();
  74. return (false);
  75. });
  76. $('input[type=file]').on('change', function(event) {
  77. $.each(this.files, function(index, file) {
  78. if (file instanceof Blob) {
  79. upload(file);
  80. }
  81. });
  82. });
  83. })();
  84. (function() {
  85. var copylinkbtn = document.getElementById("copy-link-btn"),
  86. copylink = document.getElementById("copy-link-wrapper"),
  87. overlay = document.getElementById("overlay");
  88. copylinkbtn.addEventListener("click", function() {
  89. var error = document.getElementsByClassName('error');
  90. while (error[0]) {
  91. error[0].parentNode.removeChild(error[0]);
  92. }
  93. document.body.className += ' active';
  94. copylink.children[2].value = window.location.href;
  95. copylink.children[2].focus();
  96. copylink.children[2].select();
  97. }, false);
  98. overlay.addEventListener("click", function() {
  99. document.body.className = '';
  100. }, false);
  101. copylink.children[2].addEventListener("keydown", function(e) {
  102. var error = document.getElementsByClassName('error');
  103. while (error[0]) {
  104. error[0].parentNode.removeChild(error[0]);
  105. }
  106. setTimeout(function() {
  107. if((e.metaKey || e.ctrlKey) && e.keyCode === 67 && isTextSelected(copylink.children[2])) {
  108. document.body.className = '';
  109. } else if((e.metaKey || e.ctrlKey) && e.keyCode === 67 && isTextSelected(copylink.children[2]) === false) {
  110. var error = document.createElement('span');
  111. error.className = 'error';
  112. var errortext = document.createTextNode('The link was not copied, make sure the entire text is selected.');
  113. error.appendChild(errortext);
  114. copylink.appendChild(error);
  115. }
  116. }, 100);
  117. function isTextSelected(input) {
  118. if (typeof input.selectionStart == "number") {
  119. return input.selectionStart == 0 && input.selectionEnd == input.value.length;
  120. } else if (typeof document.selection != "undefined") {
  121. input.focus();
  122. return document.selection.createRange().text == input.value;
  123. }
  124. }
  125. }, false);
  126. })();