選択できるのは25トピックまでです。 トピックは、先頭が英数字で、英数字とダッシュ('-')を使用した35文字以内のものにしてください。
 
 
 

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