Oppaitime's version of Gazelle
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.

global.js 6.8KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203
  1. /**
  2. * Check or uncheck checkboxes in formElem
  3. * If masterElem is false, toggle each box, otherwise use masterElem's status on all boxes
  4. * If elemSelector is false, act on all checkboxes in formElem
  5. */
  6. function toggleChecks(formElem, masterElem, elemSelector) {
  7. elemSelector = elemSelector || 'input:checkbox';
  8. if (masterElem) {
  9. $('#' + formElem + ' ' + elemSelector).prop('checked', masterElem.checked);
  10. } else {
  11. $('#' + formElem + ' ' + elemSelector).each(function() {
  12. this.checked = !this.checked;
  13. })
  14. }
  15. }
  16. //Lightbox stuff
  17. /*
  18. * If loading from a thumbnail, the lightbox is shown first with a "loading" screen
  19. * while the full size image loads, then the HTML of the lightbox is replaced with the image.
  20. */
  21. var lightbox = {
  22. init: function (image, size) {
  23. if (typeof(image) == 'string') {
  24. $('#lightbox').gshow().listen('click', lightbox.unbox).raw().innerHTML =
  25. '<p size="7" style="color: gray; font-size: 50px;">Loading...<p>';
  26. $('#curtain').gshow().listen('click', lightbox.unbox);
  27. var src = image;
  28. image = new Image();
  29. image.onload = function() {
  30. lightbox.box_async(image);
  31. }
  32. image.src = src;
  33. }
  34. if (image.naturalWidth === undefined) {
  35. var tmp = document.createElement('img');
  36. tmp.style.visibility = 'hidden';
  37. tmp.src = image.src;
  38. image.naturalWidth = tmp.width;
  39. delete tmp;
  40. }
  41. if (image.naturalWidth > size) {
  42. lightbox.box(image);
  43. }
  44. },
  45. box: function (image) {
  46. var hasA = false;
  47. if (image.parentNode != null && image.parentNode.tagName.toUpperCase() == 'A') {
  48. hasA = true;
  49. }
  50. if (!hasA) {
  51. $('#lightbox').gshow().listen('click', lightbox.unbox).raw().innerHTML = '<img src="' + image.src + '" alt="" />';
  52. $('#curtain').gshow().listen('click', lightbox.unbox);
  53. }
  54. },
  55. box_async: function (image) {
  56. var hasA = false;
  57. if (image.parentNode != null && image.parentNode.tagName.toUpperCase() == 'A') {
  58. hasA = true;
  59. }
  60. if (!hasA) {
  61. $('#lightbox').raw().innerHTML = '<img src="' + image.src + '" alt="" />';
  62. }
  63. },
  64. unbox: function (data) {
  65. $('#curtain').ghide();
  66. $('#lightbox').ghide().raw().innerHTML = '';
  67. }
  68. };
  69. // Horrible hack to let arrow keys work as forward/back in lightbox
  70. window.onkeydown = function(e) {
  71. e = e || window.event
  72. if (e.keyCode == 37 || e.keyCode == 39) {
  73. if ($('#lightbox') && !$('#lightbox').raw().classList.contains('hidden')) {
  74. ($('[id!="lightbox"] > [src="'+$('#lightbox > img').raw().src+'"]').raw()[((e.keyCode==39)?'next':'previous')+'Sibling'].onclick||function(){})()
  75. }
  76. }
  77. }
  78. /* Still some issues
  79. function caps_check(e) {
  80. if (e === undefined) {
  81. e = window.event;
  82. }
  83. if (e.which === undefined) {
  84. e.which = e.keyCode;
  85. }
  86. if (e.which > 47 && e.which < 58) {
  87. return;
  88. }
  89. if ((e.which > 64 && e.which < 91 && !e.shiftKey) || (e.which > 96 && e.which < 123 && e.shiftKey)) {
  90. $('#capslock').gshow();
  91. }
  92. }
  93. */
  94. function hexify(str) {
  95. str = str.replace(/rgb\(|\)/g, "").split(",");
  96. str[0] = parseInt(str[0], 10).toString(16).toLowerCase();
  97. str[1] = parseInt(str[1], 10).toString(16).toLowerCase();
  98. str[2] = parseInt(str[2], 10).toString(16).toLowerCase();
  99. str[0] = (str[0].length == 1) ? '0' + str[0] : str[0];
  100. str[1] = (str[1].length == 1) ? '0' + str[1] : str[1];
  101. str[2] = (str[2].length == 1) ? '0' + str[2] : str[2];
  102. return (str.join(""));
  103. }
  104. function resize(id) {
  105. var textarea = document.getElementById(id);
  106. if (textarea.scrollHeight > textarea.clientHeight) {
  107. //textarea.style.overflowY = 'hidden';
  108. textarea.style.height = Math.min(1000, textarea.scrollHeight + textarea.style.fontSize) + 'px';
  109. }
  110. }
  111. //ZIP downloader stuff
  112. function add_selection() {
  113. var selected = $('#formats').raw().options[$('#formats').raw().selectedIndex];
  114. if (selected.disabled === false) {
  115. var listitem = document.createElement("li");
  116. listitem.id = 'list' + selected.value;
  117. listitem.innerHTML = ' <input type="hidden" name="list[]" value="' + selected.value + '" /> ' +
  118. ' <span style="float: left;">' + selected.innerHTML + '</span>' +
  119. ' <a href="#" onclick="remove_selection(\'' + selected.value + '\'); return false;" style="float: right;" class="brackets">X</a>' +
  120. ' <br style="clear: all;" />';
  121. $('#list').raw().appendChild(listitem);
  122. $('#opt' + selected.value).raw().disabled = true;
  123. }
  124. }
  125. function remove_selection(index) {
  126. $('#list' + index).remove();
  127. $('#opt' + index).raw().disabled = '';
  128. }
  129. // Thank you http://stackoverflow.com/questions/4578398/selecting-all-text-within-a-div-on-a-single-left-click-with-javascript
  130. function select_all(el) {
  131. if (typeof window.getSelection != "undefined" && typeof document.createRange != "undefined") {
  132. var range = document.createRange();
  133. range.selectNodeContents(el);
  134. var sel = window.getSelection();
  135. sel.removeAllRanges();
  136. sel.addRange(range);
  137. } else if (typeof document.selection != "undefined" && typeof document.body.createTextRange != "undefined") {
  138. var textRange = document.body.createTextRange();
  139. textRange.moveToElementText(el);
  140. textRange.select();
  141. }
  142. }
  143. function toggle_header_links(event) {
  144. event.stopPropagation()
  145. $('#userinfo_minor > li > ul').raw().style.display = ($('#userinfo_minor > li > ul').raw().style.display == 'block') ? 'none' : 'block'
  146. }
  147. function hide_header_links() {
  148. $('#userinfo_minor > li > ul').raw().style.display = 'none'
  149. }
  150. function preload(image) {
  151. var img = document.createElement('img')
  152. img.style.display = 'none'
  153. img.src = image
  154. document.body.appendChild(img)
  155. document.body.removeChild(img)
  156. }
  157. function getCover(event) {
  158. image = event.target.attributes.cover.value
  159. $('#coverCont img').remove()
  160. var coverCont = ($('#coverCont').length==0)?document.body.appendChild(document.createElement('div')):$('#coverCont')[0]
  161. coverCont.id = 'coverCont'
  162. if ($('#coverCont img').length == 0) {
  163. coverCont.appendChild(document.createElement('img'))
  164. }
  165. $('#coverCont img')[0].src = image?image:'/static/common/noartwork/comedy.png'
  166. coverCont.className = (event.clientX > (window.innerWidth/2)) ? 'left' : 'right'
  167. coverCont.style.display = 'block'
  168. //Preload next image
  169. if ($('.torrent_table, .request_table').length > 0) {
  170. var as = $('[cover]')
  171. var a = event.target
  172. preload((as[as.toArray().indexOf(a)+1]||as[0]).attributes.cover.value)
  173. preload((as[as.toArray().indexOf(a)-1]||as[0]).attributes.cover.value)
  174. }
  175. }
  176. function ungetCover(event) {
  177. $('#coverCont img').remove()
  178. coverCont.style.display = 'none'
  179. }
  180. $(function() {
  181. if ($('#header_links_menu').length > 0) {
  182. $('#header_links_menu')[0].addEventListener('click', toggle_header_links)
  183. $('body')[0].addEventListener('click', hide_header_links)
  184. }
  185. if ($('.request_table').length > 0) {
  186. var a = $('[cover]')[0]
  187. if (a) preload(a.attributes.cover.value)
  188. }
  189. })