PageRenderTime 60ms CodeModel.GetById 20ms RepoModel.GetById 0ms app.codeStats 0ms

/phpBB/styles/lucid_lime/template/forum_fn.js

https://bitbucket.org/enitarzi/phpbb3-gorgon
JavaScript | 443 lines | 298 code | 59 blank | 86 comment | 111 complexity | fdf320f8ac95994939999c6ba8a75fba MD5 | raw file
  1. /**
  2. * phpBB3 forum functions
  3. */
  4. /**
  5. * Window popup
  6. */
  7. function popup(url, width, height, name)
  8. {
  9. if (!name)
  10. {
  11. name = '_popup';
  12. }
  13. window.open(url.replace(/&/g, '&'), name, 'height=' + height + ',resizable=yes,scrollbars=yes, width=' + width);
  14. return false;
  15. }
  16. /**
  17. * Jump to page
  18. */
  19. function jumpto()
  20. {
  21. var page = prompt(jump_page, on_page);
  22. if (page !== null && !isNaN(page) && page == Math.floor(page) && page > 0)
  23. {
  24. if (base_url.indexOf('?') == -1)
  25. {
  26. document.location.href = base_url + '?start=' + ((page - 1) * per_page);
  27. }
  28. else
  29. {
  30. document.location.href = base_url.replace(/&/g, '&') + '&start=' + ((page - 1) * per_page);
  31. }
  32. }
  33. }
  34. /**
  35. * Mark/unmark checklist
  36. * id = ID of parent container, name = name prefix, state = state [true/false]
  37. */
  38. function marklist(id, name, state)
  39. {
  40. var parent = document.getElementById(id);
  41. if (!parent)
  42. {
  43. eval('parent = document.' + id);
  44. }
  45. if (!parent)
  46. {
  47. return;
  48. }
  49. var rb = parent.getElementsByTagName('input');
  50. for (var r = 0; r < rb.length; r++)
  51. {
  52. if (rb[r].name.substr(0, name.length) == name)
  53. {
  54. rb[r].checked = state;
  55. }
  56. }
  57. }
  58. /**
  59. * Resize viewable area for attached image or topic review panel (possibly others to come)
  60. * e = element
  61. */
  62. function viewableArea(e, itself)
  63. {
  64. if (!e) return;
  65. if (!itself)
  66. {
  67. e = e.parentNode;
  68. }
  69. if (!e.vaHeight)
  70. {
  71. // Store viewable area height before changing style to auto
  72. e.vaHeight = e.offsetHeight;
  73. e.vaMaxHeight = e.style.maxHeight;
  74. e.style.height = 'auto';
  75. e.style.maxHeight = 'none';
  76. e.style.overflow = 'visible';
  77. }
  78. else
  79. {
  80. // Restore viewable area height to the default
  81. e.style.height = e.vaHeight + 'px';
  82. e.style.overflow = 'auto';
  83. e.style.maxHeight = e.vaMaxHeight;
  84. e.vaHeight = false;
  85. }
  86. }
  87. /**
  88. * Set display of page element
  89. * s[-1,0,1] = hide,toggle display,show
  90. * type = string: inline, block, inline-block or other CSS "display" type
  91. */
  92. function dE(n, s, type)
  93. {
  94. if (!type)
  95. {
  96. type = 'block';
  97. }
  98. var e = document.getElementById(n);
  99. if (!s)
  100. {
  101. s = (e.style.display == '' || e.style.display == type) ? -1 : 1;
  102. }
  103. e.style.display = (s == 1) ? type : 'none';
  104. }
  105. /**
  106. * Alternate display of subPanels
  107. */
  108. function subPanels(p)
  109. {
  110. var i, e, t;
  111. if (typeof(p) == 'string')
  112. {
  113. show_panel = p;
  114. }
  115. for (i = 0; i < panels.length; i++)
  116. {
  117. e = document.getElementById(panels[i]);
  118. t = document.getElementById(panels[i] + '-tab');
  119. if (e)
  120. {
  121. if (panels[i] == show_panel)
  122. {
  123. e.style.display = 'block';
  124. if (t)
  125. {
  126. t.className = 'activetab';
  127. }
  128. }
  129. else
  130. {
  131. e.style.display = 'none';
  132. if (t)
  133. {
  134. t.className = '';
  135. }
  136. }
  137. }
  138. }
  139. }
  140. /**
  141. * Call print preview
  142. */
  143. function printPage()
  144. {
  145. if (is_ie)
  146. {
  147. printPreview();
  148. }
  149. else
  150. {
  151. window.print();
  152. }
  153. }
  154. /**
  155. * Show/hide groups of blocks
  156. * c = CSS style name
  157. * e = checkbox element
  158. * t = toggle dispay state (used to show 'grip-show' image in the profile block when hiding the profiles)
  159. */
  160. function displayBlocks(c, e, t)
  161. {
  162. var s = (e.checked == true) ? 1 : -1;
  163. if (t)
  164. {
  165. s *= -1;
  166. }
  167. var divs = document.getElementsByTagName("DIV");
  168. for (var d = 0; d < divs.length; d++)
  169. {
  170. if (divs[d].className.indexOf(c) == 0)
  171. {
  172. divs[d].style.display = (s == 1) ? 'none' : 'block';
  173. }
  174. }
  175. }
  176. function selectCode(a)
  177. {
  178. // Get ID of code block
  179. var e = a.parentNode.parentNode.getElementsByTagName('CODE')[0];
  180. // Not IE and IE9+
  181. if (window.getSelection)
  182. {
  183. var s = window.getSelection();
  184. // Safari
  185. if (s.setBaseAndExtent)
  186. {
  187. s.setBaseAndExtent(e, 0, e, e.innerText.length - 1);
  188. }
  189. // Firefox and Opera
  190. else
  191. {
  192. // workaround for bug # 42885
  193. if (window.opera && e.innerHTML.substring(e.innerHTML.length - 4) == '<BR>')
  194. {
  195. e.innerHTML = e.innerHTML + '&nbsp;';
  196. }
  197. var r = document.createRange();
  198. r.selectNodeContents(e);
  199. s.removeAllRanges();
  200. s.addRange(r);
  201. }
  202. }
  203. // Some older browsers
  204. else if (document.getSelection)
  205. {
  206. var s = document.getSelection();
  207. var r = document.createRange();
  208. r.selectNodeContents(e);
  209. s.removeAllRanges();
  210. s.addRange(r);
  211. }
  212. // IE
  213. else if (document.selection)
  214. {
  215. var r = document.body.createTextRange();
  216. r.moveToElementText(e);
  217. r.select();
  218. }
  219. }
  220. /**
  221. * Play quicktime file by determining it's width/height
  222. * from the displayed rectangle area
  223. */
  224. function play_qt_file(obj)
  225. {
  226. var rectangle = obj.GetRectangle();
  227. if (rectangle)
  228. {
  229. rectangle = rectangle.split(',');
  230. var x1 = parseInt(rectangle[0]);
  231. var x2 = parseInt(rectangle[2]);
  232. var y1 = parseInt(rectangle[1]);
  233. var y2 = parseInt(rectangle[3]);
  234. var width = (x1 < 0) ? (x1 * -1) + x2 : x2 - x1;
  235. var height = (y1 < 0) ? (y1 * -1) + y2 : y2 - y1;
  236. }
  237. else
  238. {
  239. var width = 200;
  240. var height = 0;
  241. }
  242. obj.width = width;
  243. obj.height = height + 16;
  244. obj.SetControllerVisible(true);
  245. obj.Play();
  246. }
  247. /**
  248. * Check if the nodeName of elem is name
  249. * @author jQuery
  250. */
  251. function is_node_name(elem, name)
  252. {
  253. return elem.nodeName && elem.nodeName.toUpperCase() == name.toUpperCase();
  254. }
  255. /**
  256. * Check if elem is in array, return position
  257. * @author jQuery
  258. */
  259. function is_in_array(elem, array)
  260. {
  261. for (var i = 0, length = array.length; i < length; i++)
  262. // === is correct (IE)
  263. if (array[i] === elem)
  264. return i;
  265. return -1;
  266. }
  267. /**
  268. * Find Element, type and class in tree
  269. * Not used, but may come in handy for those not using JQuery
  270. * @author jQuery.find, Meik Sievertsen
  271. */
  272. function find_in_tree(node, tag, type, class_name)
  273. {
  274. var result, element, i = 0, length = node.childNodes.length;
  275. for (element = node.childNodes[0]; i < length; element = node.childNodes[++i])
  276. {
  277. if (!element || element.nodeType != 1) continue;
  278. if ((!tag || is_node_name(element, tag)) && (!type || element.type == type) && (!class_name || is_in_array(class_name, (element.className || element).toString().split(/\s+/)) > -1))
  279. {
  280. return element;
  281. }
  282. if (element.childNodes.length)
  283. result = find_in_tree(element, tag, type, class_name);
  284. if (result) return result;
  285. }
  286. }
  287. var in_autocomplete = false;
  288. var last_key_entered = '';
  289. /**
  290. * Check event key
  291. */
  292. function phpbb_check_key(event)
  293. {
  294. // Keycode is array down or up?
  295. if (event.keyCode && (event.keyCode == 40 || event.keyCode == 38))
  296. in_autocomplete = true;
  297. // Make sure we are not within an "autocompletion" field
  298. if (in_autocomplete)
  299. {
  300. // If return pressed and key changed we reset the autocompletion
  301. if (!last_key_entered || last_key_entered == event.which)
  302. {
  303. in_autocompletion = false;
  304. return true;
  305. }
  306. }
  307. // Keycode is not return, then return. ;)
  308. if (event.which != 13)
  309. {
  310. last_key_entered = event.which;
  311. return true;
  312. }
  313. return false;
  314. }
  315. /**
  316. * Usually used for onkeypress event, to submit a form on enter
  317. */
  318. function submit_default_button(event, selector, class_name)
  319. {
  320. // Add which for key events
  321. if (!event.which && ((event.charCode || event.charCode === 0) ? event.charCode : event.keyCode))
  322. event.which = event.charCode || event.keyCode;
  323. if (phpbb_check_key(event))
  324. return true;
  325. var current = selector['parentNode'];
  326. // Search parent form element
  327. while (current && (!current.nodeName || current.nodeType != 1 || !is_node_name(current, 'form')) && current != document)
  328. current = current['parentNode'];
  329. // Find the input submit button with the class name
  330. //current = find_in_tree(current, 'input', 'submit', class_name);
  331. var input_tags = current.getElementsByTagName('input');
  332. current = false;
  333. for (var i = 0, element = input_tags[0]; i < input_tags.length; element = input_tags[++i])
  334. {
  335. if (element.type == 'submit' && is_in_array(class_name, (element.className || element).toString().split(/\s+/)) > -1)
  336. current = element;
  337. }
  338. if (!current)
  339. return true;
  340. // Submit form
  341. current.focus();
  342. current.click();
  343. return false;
  344. }
  345. /**
  346. * Apply onkeypress event for forcing default submit button on ENTER key press
  347. * The jQuery snippet used is based on http://greatwebguy.com/programming/dom/default-html-button-submit-on-enter-with-jquery/
  348. * The non-jQuery code is a mimick of the jQuery code ;)
  349. */
  350. function apply_onkeypress_event()
  351. {
  352. // jQuery code in case jQuery is used
  353. if (jquery_present)
  354. {
  355. jQuery('form input[type=text], form input[type=password]').live('keypress', function (e)
  356. {
  357. var default_button = jQuery(this).parents('form').find('input[type=submit].default-submit-action');
  358. if (!default_button || default_button.length <= 0)
  359. return true;
  360. if (phpbb_check_key(e))
  361. return true;
  362. if ((e.which && e.which == 13) || (e.keyCode && e.keyCode == 13))
  363. {
  364. default_button.click();
  365. return false;
  366. }
  367. return true;
  368. });
  369. return;
  370. }
  371. var input_tags = document.getElementsByTagName('input');
  372. for (var i = 0, element = input_tags[0]; i < input_tags.length ; element = input_tags[++i])
  373. {
  374. if (element.type == 'text' || element.type == 'password')
  375. {
  376. // onkeydown is possible too
  377. element.onkeypress = function (evt) { submit_default_button((evt || window.event), this, 'default-submit-action'); };
  378. }
  379. }
  380. }
  381. /**
  382. * Detect JQuery existance. We currently do not deliver it, but some styles do, so why not benefit from it. ;)
  383. */
  384. var jquery_present = typeof jQuery == 'function';