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.
 
 
 
 

183 lines
6.4 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.setRequestHeader("X_FILENAME", file.name);
  62. xhr.send(file);
  63. };
  64. $(document).bind("dragenter", function(event) {
  65. event.preventDefault();
  66. }).bind("dragover", function(event) {
  67. event.preventDefault();
  68. // show drop indicator
  69. $('#terminal').addClass('dragged');
  70. $('#web').addClass('dragged');
  71. }).bind("dragleave", function(event) {
  72. $('#terminal').removeClass('dragged');
  73. $('#web').removeClass('dragged');
  74. }).bind("drop dragdrop", function(event) {
  75. var files = event.originalEvent.target.files || event.originalEvent.dataTransfer.files;
  76. $.each(files, function(index, file) {
  77. upload(file);
  78. });
  79. event.stopPropagation();
  80. event.preventDefault();
  81. });
  82. $('a.browse').on('click', function(event) {
  83. $("input[type=file]").click();
  84. return (false);
  85. });
  86. $('input[type=file]').on('change', function(event) {
  87. $.each(this.files, function(index, file) {
  88. if (file instanceof Blob) {
  89. upload(file);
  90. }
  91. });
  92. });
  93. // clipboard
  94. if (window.location.href.indexOf("download") > -1 ) {
  95. (function() {
  96. var copylinkbtn = document.getElementById("copy-link-btn"),
  97. copylink = document.getElementById("copy-link-wrapper"),
  98. overlay = document.getElementById("overlay");
  99. var url = "http://url"
  100. copylinkbtn.addEventListener("click", function() {
  101. var error = document.getElementsByClassName('error');
  102. while (error[0]) {
  103. error[0].parentNode.removeChild(error[0]);
  104. }
  105. document.body.className += ' active';
  106. copylink.children[1].value = url;
  107. copylink.children[1].focus();
  108. copylink.children[1].select();
  109. }, false);
  110. overlay.addEventListener("click", function() {
  111. document.body.className = '';
  112. }, false);
  113. copylink.children[1].addEventListener("keydown", function(e) {
  114. var error = document.getElementsByClassName('error');
  115. while (error[0]) {
  116. error[0].parentNode.removeChild(error[0]);
  117. }
  118. setTimeout(function() {
  119. if ((e.metaKey || e.ctrlKey) && e.keyCode === 67 && isTextSelected(copylink.children[2])) {
  120. document.body.className = '';
  121. } else if ((e.metaKey || e.ctrlKey) && e.keyCode === 67 && isTextSelected(copylink.children[2]) === false) {
  122. var error = document.createElement('span');
  123. error.className = 'error';
  124. var errortext = document.createTextNode('The link was not copied, make sure the entire text is selected.');
  125. error.appendChild(errortext);
  126. copylink.appendChild(error);
  127. }
  128. }, 100);
  129. function isTextSelected(input) {
  130. if (typeof input.selectionStart == "number") {
  131. return input.selectionStart == 0 && input.selectionEnd == input.value.length;
  132. } else if (typeof document.selection != "undefined") {
  133. input.focus();
  134. return document.selection.createRange().text == input.value;
  135. }
  136. }
  137. }, false);
  138. })();
  139. };
  140. })();