2 * phpBB3 forum functions
8 function popup(url, width, height, name)
15 window.open(url.replace(/&/g, '&'), name, 'height=' + height + ',resizable=yes,scrollbars=yes, width=' + width);
24 var page = prompt(jump_page, on_page);
26 if (page !== null && !isNaN(page) && page == Math.floor(page) && page > 0)
28 if (base_url.indexOf('?') == -1)
30 document.location.href = base_url + '?start=' + ((page - 1) * per_page);
34 document.location.href = base_url.replace(/&/g, '&') + '&start=' + ((page - 1) * per_page);
40 * Mark/unmark checklist
41 * id = ID of parent container, name = name prefix, state = state [true/false]
43 function marklist(id, name, state)
45 var parent = document.getElementById(id);
48 eval('parent = document.' + id);
56 var rb = parent.getElementsByTagName('input');
58 for (var r = 0; r < rb.length; r++)
60 if (rb[r].name.substr(0, name.length) == name)
62 rb[r].checked = state;
68 * Resize viewable area for attached image or topic review panel (possibly others to come)
71 function viewableArea(e, itself)
81 // Store viewable area height before changing style to auto
82 e.vaHeight = e.offsetHeight;
83 e.vaMaxHeight = e.style.maxHeight;
84 e.style.height = 'auto';
85 e.style.maxHeight = 'none';
86 e.style.overflow = 'visible';
90 // Restore viewable area height to the default
91 e.style.height = e.vaHeight + 'px';
92 e.style.overflow = 'auto';
93 e.style.maxHeight = e.vaMaxHeight;
99 * Set display of page element
100 * s[-1,0,1] = hide,toggle display,show
101 * type = string: inline, block, inline-block or other CSS "display" type
103 function dE(n, s, type)
110 var e = document.getElementById(n);
113 s = (e.style.display == '' || e.style.display == type) ? -1 : 1;
115 e.style.display = (s == 1) ? type : 'none';
119 * Alternate display of subPanels
121 function subPanels(p)
125 if (typeof(p) == 'string')
130 for (i = 0; i < panels.length; i++)
132 e = document.getElementById(panels[i]);
133 t = document.getElementById(panels[i] + '-tab');
137 if (panels[i] == show_panel)
139 e.style.display = 'block';
143 if(jquery_present) $(t).addClass('activetab');
144 else t.className = 'activetab';
149 e.style.display = 'none';
153 if(jquery_present) $(t).removeClass('activetab');
154 else t.className = '';
177 * Show/hide groups of blocks
179 * e = checkbox element
180 * t = toggle dispay state (used to show 'grip-show' image in the profile block when hiding the profiles)
182 function displayBlocks(c, e, t)
184 var s = (e.checked == true) ? 1 : -1;
191 var divs = document.getElementsByTagName("DIV");
193 for (var d = 0; d < divs.length; d++)
195 if (divs[d].className.indexOf(c) == 0)
197 divs[d].style.display = (s == 1) ? 'none' : 'block';
202 function selectCode(a)
204 // Get ID of code block
205 var e = a.parentNode.parentNode.getElementsByTagName('CODE')[0];
208 if (window.getSelection)
210 var s = window.getSelection();
212 if (s.setBaseAndExtent)
214 s.setBaseAndExtent(e, 0, e, e.innerText.length - 1);
219 // workaround for bug # 42885
220 if (window.opera && e.innerHTML.substring(e.innerHTML.length - 4) == '<BR>')
222 e.innerHTML = e.innerHTML + ' ';
225 var r = document.createRange();
226 r.selectNodeContents(e);
231 // Some older browsers
232 else if (document.getSelection)
234 var s = document.getSelection();
235 var r = document.createRange();
236 r.selectNodeContents(e);
241 else if (document.selection)
243 var r = document.body.createTextRange();
244 r.moveToElementText(e);
250 * Play quicktime file by determining it's width/height
251 * from the displayed rectangle area
253 function play_qt_file(obj)
255 var rectangle = obj.GetRectangle();
259 rectangle = rectangle.split(',');
260 var x1 = parseInt(rectangle[0]);
261 var x2 = parseInt(rectangle[2]);
262 var y1 = parseInt(rectangle[1]);
263 var y2 = parseInt(rectangle[3]);
265 var width = (x1 < 0) ? (x1 * -1) + x2 : x2 - x1;
266 var height = (y1 < 0) ? (y1 * -1) + y2 : y2 - y1;
275 obj.height = height + 16;
277 obj.SetControllerVisible(true);
282 * Check if the nodeName of elem is name
285 function is_node_name(elem, name)
287 return elem.nodeName && elem.nodeName.toUpperCase() == name.toUpperCase();
291 * Check if elem is in array, return position
294 function is_in_array(elem, array)
296 for (var i = 0, length = array.length; i < length; i++)
297 // === is correct (IE)
298 if (array[i] === elem)
305 * Find Element, type and class in tree
306 * Not used, but may come in handy for those not using JQuery
307 * @author jQuery.find, Meik Sievertsen
309 function find_in_tree(node, tag, type, class_name)
311 var result, element, i = 0, length = node.childNodes.length;
313 for (element = node.childNodes[0]; i < length; element = node.childNodes[++i])
315 if (!element || element.nodeType != 1) continue;
317 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))
322 if (element.childNodes.length)
323 result = find_in_tree(element, tag, type, class_name);
325 if (result) return result;
329 var in_autocomplete = false;
330 var last_key_entered = '';
335 function phpbb_check_key(event)
337 // Keycode is array down or up?
338 if (event.keyCode && (event.keyCode == 40 || event.keyCode == 38))
339 in_autocomplete = true;
341 // Make sure we are not within an "autocompletion" field
344 // If return pressed and key changed we reset the autocompletion
345 if (!last_key_entered || last_key_entered == event.which)
347 in_autocompletion = false;
352 // Keycode is not return, then return. ;)
353 if (event.which != 13)
355 last_key_entered = event.which;
363 * Usually used for onkeypress event, to submit a form on enter
365 function submit_default_button(event, selector, class_name)
367 // Add which for key events
368 if (!event.which && ((event.charCode || event.charCode === 0) ? event.charCode : event.keyCode))
369 event.which = event.charCode || event.keyCode;
371 if (phpbb_check_key(event))
374 var current = selector['parentNode'];
376 // Search parent form element
377 while (current && (!current.nodeName || current.nodeType != 1 || !is_node_name(current, 'form')) && current != document)
378 current = current['parentNode'];
380 // Find the input submit button with the class name
381 //current = find_in_tree(current, 'input', 'submit', class_name);
382 var input_tags = current.getElementsByTagName('input');
385 for (var i = 0, element = input_tags[0]; i < input_tags.length; element = input_tags[++i])
387 if (element.type == 'submit' && is_in_array(class_name, (element.className || element).toString().split(/\s+/)) > -1)
401 * Apply onkeypress event for forcing default submit button on ENTER key press
402 * The jQuery snippet used is based on http://greatwebguy.com/programming/dom/default-html-button-submit-on-enter-with-jquery/
403 * The non-jQuery code is a mimick of the jQuery code ;)
405 function apply_onkeypress_event()
407 // jQuery code in case jQuery is used
410 jQuery('form input[type=text], form input[type=password]').live('keypress', function (e)
412 var default_button = jQuery(this).parents('form').find('input[type=submit].default-submit-action');
414 if (!default_button || default_button.length <= 0)
417 if (phpbb_check_key(e))
420 if ((e.which && e.which == 13) || (e.keyCode && e.keyCode == 13))
422 default_button.click();
432 var input_tags = document.getElementsByTagName('input');
434 for (var i = 0, element = input_tags[0]; i < input_tags.length ; element = input_tags[++i])
436 if (element.type == 'text' || element.type == 'password')
438 // onkeydown is possible too
439 element.onkeypress = function (evt) { submit_default_button((evt || window.event), this, 'default-submit-action'); };
445 * Detect JQuery existance. We currently do not deliver it, but some styles do, so why not benefit from it. ;)
447 var jquery_present = typeof jQuery == 'function';