(bug 16459) Use native getElementsByClassName
authorAryeh Gregor <simetrical@users.mediawiki.org>
Thu, 18 Dec 2008 18:16:09 +0000 (18:16 +0000)
committerAryeh Gregor <simetrical@users.mediawiki.org>
Thu, 18 Dec 2008 18:16:09 +0000 (18:16 +0000)
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
RELEASE-NOTES
skins/common/wikibits.js

diff --git a/CREDITS b/CREDITS
index 0ec11bf..1d39ae9 100644 (file)
--- 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
index a0524ca..84a700e 100644 (file)
@@ -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 ===
 
index 3a1cea9..15cc995 100644 (file)
@@ -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<oClassNames.length; i++){