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.
 
 
 
 

185 lines
6.3 KiB

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