25'ten fazla konu seçemezsiniz Konular bir harf veya rakamla başlamalı, kısa çizgiler ('-') içerebilir ve en fazla 35 karakter uzunluğunda olabilir.
 
 
 

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