Você não pode selecionar mais de 25 tópicos Os tópicos devem começar com uma letra ou um número, podem incluir traços ('-') e podem ter até 35 caracteres.
 
 
 

173 linhas
6.2 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. $(window).bind('beforeunload', function(){
  30. return 'File are still uploading';
  31. });
  32. }, false);
  33. xhr.onreadystatechange = function(e) {
  34. if (xhr.readyState == 4) {
  35. /* $('.upload-progress', $(li)).hide();*/
  36. $('#web').addClass('uploading');
  37. // progress.className = (xhr.status == 200 ? "success" : "failure");
  38. if (xhr.status == 200) {
  39. $(li).html('<a target="_blank" href="' + xhr.responseText + '">' + xhr.responseText + '</a>');
  40. } else {
  41. $(li).html('<span>Error (' + xhr.status + ') during upload of file ' + file.name + '</span>');
  42. }
  43. files.push(xhr.responseText.replace("https://transfer.sh/", "").replace("\n", ""));
  44. // files.push(URI(xhr.responseText).absoluteTo(location.href).toString());
  45. $(".download-zip").attr("href", URI("(" + files.join(",") + ").zip").absoluteTo(location.href).toString());
  46. $(".download-tar").attr("href", URI("(" + files.join(",") + ").tar.gz").absoluteTo(location.href).toString());
  47. $(".all-files").addClass('show');
  48. }
  49. };
  50. // should queue all uploads.
  51. // start upload
  52. xhr.open("PUT", '/' + file.name, true);
  53. xhr.setRequestHeader("X_FILENAME", file.name);
  54. xhr.send(file);
  55. };
  56. $(document).bind("dragenter", function(event) {
  57. event.preventDefault();
  58. }).bind("dragover", function(event) {
  59. event.preventDefault();
  60. // show drop indicator
  61. $('#terminal').addClass('dragged');
  62. $('#web').addClass('dragged');
  63. }).bind("dragleave", function(event) {
  64. $('#terminal').removeClass('dragged');
  65. $('#web').removeClass('dragged');
  66. }).bind("drop dragdrop", function(event) {
  67. var files = event.originalEvent.target.files || event.originalEvent.dataTransfer.files;
  68. $.each(files, function(index, file) {
  69. console.debug(file);
  70. upload(file);
  71. });
  72. event.stopPropagation();
  73. event.preventDefault();
  74. });
  75. $('a.browse').on('click', function(event) {
  76. $("input[type=file]").click();
  77. return (false);
  78. });
  79. $('input[type=file]').on('change', function(event) {
  80. $.each(this.files, function(index, file) {
  81. if (file instanceof Blob) {
  82. upload(file);
  83. }
  84. });
  85. });
  86. // clipboard
  87. if (window.location.href.indexOf("download") > -1 ) {
  88. (function() {
  89. var copylinkbtn = document.getElementById("copy-link-btn"),
  90. copylink = document.getElementById("copy-link-wrapper"),
  91. overlay = document.getElementById("overlay");
  92. var url = "http://url"
  93. copylinkbtn.addEventListener("click", function() {
  94. var error = document.getElementsByClassName('error');
  95. while (error[0]) {
  96. error[0].parentNode.removeChild(error[0]);
  97. }
  98. document.body.className += ' active';
  99. copylink.children[1].value = url;
  100. copylink.children[1].focus();
  101. copylink.children[1].select();
  102. }, false);
  103. overlay.addEventListener("click", function() {
  104. document.body.className = '';
  105. }, false);
  106. copylink.children[1].addEventListener("keydown", function(e) {
  107. var error = document.getElementsByClassName('error');
  108. while (error[0]) {
  109. error[0].parentNode.removeChild(error[0]);
  110. }
  111. setTimeout(function() {
  112. if ((e.metaKey || e.ctrlKey) && e.keyCode === 67 && isTextSelected(copylink.children[2])) {
  113. document.body.className = '';
  114. } else if ((e.metaKey || e.ctrlKey) && e.keyCode === 67 && isTextSelected(copylink.children[2]) === false) {
  115. var error = document.createElement('span');
  116. error.className = 'error';
  117. var errortext = document.createTextNode('The link was not copied, make sure the entire text is selected.');
  118. error.appendChild(errortext);
  119. copylink.appendChild(error);
  120. }
  121. }, 100);
  122. function isTextSelected(input) {
  123. if (typeof input.selectionStart == "number") {
  124. return input.selectionStart == 0 && input.selectionEnd == input.value.length;
  125. } else if (typeof document.selection != "undefined") {
  126. input.focus();
  127. return document.selection.createRange().text == input.value;
  128. }
  129. }
  130. }, false);
  131. })();
  132. };
  133. })();