Last modified: 2011-03-13 18:06:12 UTC

Wikimedia Bugzilla is closed!

Wikimedia migrated from Bugzilla to Phabricator. Bug reports are handled in Wikimedia Phabricator.
This static website is read-only and for historical purposes. It is not possible to log in and except for displaying bug reports and their history, links might be broken. See T18459, the corresponding Phabricator task for complete and up-to-date bug report information.
Bug 16459 - use native getElementsByClassName
use native getElementsByClassName
Status: RESOLVED WONTFIX
Product: MediaWiki
Classification: Unclassified
General/Unknown (Other open bugs)
unspecified
All All
: Lowest enhancement with 1 vote (vote)
: ---
Assigned To: Nobody - You can work on this!
:
Depends on:
Blocks:
  Show dependency treegraph
 
Reported: 2008-11-25 18:07 UTC by Derk-Jan Hartman
Modified: 2011-03-13 18:06 UTC (History)
7 users (show)

See Also:
Web browser: ---
Mobile Platform: ---
Assignee Huggle Beta Tester: ---


Attachments
patch to prefer native implementation (1.13 KB, patch)
2008-11-25 18:07 UTC, Derk-Jan Hartman
Details

Description Derk-Jan Hartman 2008-11-25 18:07:30 UTC
Created attachment 5540 [details]
patch to prefer native implementation

I have a patch that allows the wikibits.js getElementsByClassName to make use of a native version of that function when available. (FF 3, Saf 3.2 and Opera 9.5 all provide this function now). There is no loss of functionality.

To get an idea of how advantageous this can be: http://webkit.org/blog/153/webkit-gets-native-getelementsbyclassname/
Comment 1 Aryeh Gregor (not reading bugmail, please e-mail directly) 2008-11-25 23:15:20 UTC
Have you tested that this causes no regressions in any browsers (e.g., sortable tables still work)?
Comment 2 Derk-Jan Hartman 2008-11-26 14:07:13 UTC
I have created testcases here: http://test.wikipedia.org/wiki/User:TheDJ/monobook.js

Which i tested with this page: http://test.wikipedia.org/wiki/Transwiki:Wikiversity-School_of_Computer_Science/IntroProgramingJava

Safari 2, 3, Opera 9.5, FF 2 and FF 3, all returned identical numbers. IE is not tested, but i assume it understands typeof.
Comment 3 Derk-Jan Hartman 2008-12-01 17:12:39 UTC
Tested and works on IE6
Comment 4 Aryeh Gregor (not reading bugmail, please e-mail directly) 2008-12-18 18:16:35 UTC
Committed in r44774 with whitespace tweaks.
Comment 5 Lupo 2009-01-06 20:56:38 UTC
Sorry, but this change
r1=44192&r2=44774">http://svn.wikimedia.org/viewvc/mediawiki/trunk/phase3/skins/common/wikibits.js?r1=44192&r2=44774
breaks the interface of function getElementsByClassName. In the original implementation, oClassNames could be a regular expression such as 'wp\\S*', or a list of strings! In the native implementation in Firefox 3, the parameter can only be a single string, see
https://developer.mozilla.org/En/DOM/document.getElementsByClassName
As a result, a call like

getElementsByClassName (elem, '*', 'wp\\S*');

now returns an empty array, whereas it previously returned all child elements of elem having a class that started with "wp". This change breaks some functionality in the upload form on the Commons.

Calls like

getElementsByClassName (elem, '*', ['class1', 'class2']);

also won't work anymore.
Comment 6 Derk-Jan Hartman 2009-01-14 15:47:14 UTC
Hmm, I totally missed that in the original code.
Well, the original author did write a new version of this class back in May. http://www.robertnyman.com/2008/05/27/the-ultimate-getelementsbyclassname-anno-2008/

However, i'm not that big a fan. It seems like a gigantic amount of code to saddle upon all our clients, for just the smallest amount of usecases.
Comment 7 entlinkt 2010-07-27 03:43:42 UTC
Another inconsistency: The original implementation returns an array. The native implementation returns a live NodeList. The wrapper function returns that as-is if strTagName is the wildcard, but converts it to an array if strTagName is a specific tag name. That can be really confusing.
Comment 8 Roan Kattouw 2010-08-03 20:14:17 UTC
This should all be moot once we have jQuery on every page and people can just use $('.classname')
Comment 9 Mike.lifeguard 2010-08-03 22:33:36 UTC
(In reply to comment #8)
> This should all be moot once we have jQuery on every page and people can just
> use $('.classname')

How is anyone supposed to know to do that without some documentation?
Comment 10 Roan Kattouw 2010-08-04 11:30:00 UTC
(In reply to comment #9)
> (In reply to comment #8)
> > This should all be moot once we have jQuery on every page and people can just
> > use $('.classname')
> 
> How is anyone supposed to know to do that without some documentation?
We could change getElementsByClassName() to wrap around $('.classname') somehow and deprecate the former.
Comment 11 entlinkt 2010-08-08 00:49:39 UTC
Robert Nyman has released a new version at http://robertnyman.com/2008/05/27/the-ultimate-getelementsbyclassname-anno-2008/ that fixes the NodeList vs. Array issue. However,

* (elm, tag, className) is reversed to (className, tag, elm),
* calls like getElementsByClassName (elm, '*', 'wp\\S*') don't work and can't work with the native API,
* calls like getElementsByClassName (elm, '*', ['class1', 'class2']) don't work, but className can be "class1 class2", as in the native API,
* tag = "*" is broken in browsers with a native implementation (http://robertnyman.com/2008/05/27/the-ultimate-getelementsbyclassname-anno-2008/#comment-430876),
* IE 5.0 is broken (http://robertnyman.com/2008/05/27/the-ultimate-getelementsbyclassname-anno-2008/#comment-289524).
Comment 12 DieBuche 2011-02-20 14:18:15 UTC
Closing; jQuery is available on every page and wikibits.js will eventually be dropped.

Note You need to log in before you can comment on or make changes to this bug.


Navigation
Links