Changeset 702 for trunk/forum/styles/prosilver/template/forum_fn.js
- Timestamp:
- Mar 31, 2010, 6:32:40 PM (14 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/forum/styles/prosilver/template/forum_fn.js
r400 r702 24 24 var page = prompt(jump_page, on_page); 25 25 26 if (page !== null && !isNaN(page) && page > 0) 27 { 28 document.location.href = base_url.replace(/&/g, '&') + '&start=' + ((page - 1) * per_page); 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 } 29 36 } 30 37 } … … 201 208 else 202 209 { 210 // workaround for bug # 42885 211 if (window.opera && e.innerHTML.substring(e.innerHTML.length - 4) == '<BR>') 212 { 213 e.innerHTML = e.innerHTML + ' '; 214 } 215 203 216 var r = document.createRange(); 204 217 r.selectNodeContents(e); … … 256 269 obj.Play(); 257 270 } 271 272 /** 273 * Check if the nodeName of elem is name 274 * @author jQuery 275 */ 276 function 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 */ 285 function 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 */ 300 function 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 320 var in_autocomplete = false; 321 var last_key_entered = ''; 322 323 /** 324 * Check event key 325 */ 326 function 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 */ 356 function 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 */ 396 function 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 */ 438 var jquery_present = typeof jQuery == 'function';
Note:
See TracChangeset
for help on using the changeset viewer.