source: trunk/forum/styles/prosilver/template/forum_fn.js

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