From e1ee80f99e97938280ed6292084e3b4583919761 Mon Sep 17 00:00:00 2001 From: Aryeh Gregor Date: Thu, 18 Dec 2008 18:16:09 +0000 Subject: [PATCH] (bug 16459) Use native getElementsByClassName Patch by Derk-Jan Hartman. Seems not to break table sorting in Firefox 3, and he's tested it in other browsers, including IE6. (Of course it falls back to ordinary JS if the native version is unavailable.) --- CREDITS | 1 + RELEASE-NOTES | 2 ++ skins/common/wikibits.js | 13 ++++++++++++- 3 files changed, 15 insertions(+), 1 deletion(-) diff --git a/CREDITS b/CREDITS index 0ec11bf8eb..1d39ae9ee3 100644 --- a/CREDITS +++ b/CREDITS @@ -18,6 +18,7 @@ following names for their contribution to the product. * Daniel Kinzler * Danny B. * David McCabe +* Derk-Jan Hartman * Domas Mituzas * Fran Rogers * Greg Sabino Mullane diff --git a/RELEASE-NOTES b/RELEASE-NOTES index a0524ca225..84a700e33e 100644 --- a/RELEASE-NOTES +++ b/RELEASE-NOTES @@ -233,6 +233,8 @@ The following extensions are migrated into MediaWiki 1.14: * (bug 7492) Rights can now be assigned to specific IP addresses and ranges by using $wgAutopromote (new defines: APCOND_ISIP and APCOND_IPINRANGE) * Add a 'change block' link to Special:IPBlockList and Special:Log +* (bug 16459) Use native getElementsByClassName where possible, for better + performance in modern browsers === Bug fixes in 1.14 === diff --git a/skins/common/wikibits.js b/skins/common/wikibits.js index 3a1cea9b37..15cc99536e 100644 --- a/skins/common/wikibits.js +++ b/skins/common/wikibits.js @@ -454,8 +454,19 @@ function toggle_element_check(ida,idb) { From http://www.robertnyman.com/2005/11/07/the-ultimate-getelementsbyclassname/ */ function getElementsByClassName(oElm, strTagName, oClassNames){ - var arrElements = (strTagName == "*" && oElm.all)? oElm.all : oElm.getElementsByTagName(strTagName); var arrReturnElements = new Array(); + if ( typeof( oElm.getElementsByClassName ) == "function" ) { + /* Use a native implementation where possible FF3, Saf3.2, Opera 9.5 */ + var arrNativeReturn = oElm.getElementsByClassName( oClassNames ); + if ( strTagName == "*" ) + return arrNativeReturn; + for ( var h=0; h < arrNativeReturn.length; h++ ) { + if( arrNativeReturn[h].tagName.toLowerCase() == strTagName.toLowerCase() ) + arrReturnElements[arrReturnElements.length] = arrNativeReturn[h]; + } + return arrReturnElements; + } + var arrElements = (strTagName == "*" && oElm.all)? oElm.all : oElm.getElementsByTagName(strTagName); var arrRegExpClassNames = new Array(); if(typeof oClassNames == "object"){ for(var i=0; i