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.
 
 
 
 

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