haha I guess I am full of fail today ><
So it looks like the wikibits.js version of getElementsByClassName
requires you to specify the element/tag first THEN the class
change
var extlinks = getElementsByClassName('extlink');
to
var extlinks = getElementsByClassName('span','extlink');
replace 'span' with the name of the container tag (div, p, h3, etc)
Never really noticed that as I replaced our wikibits.js function
with the latest version of this function(
)
which does not require us to specify the element/tag.
Walter Mazza
On Fri, Dec 5, 2008 at 4:34 PM, Matthias Korn
<matsch(a)rockinchina.com>wrote;wrote:
Hi,
trying your function gives me an error from the called function
getElementsByClassName(). That is with the original one shipped
with MediaWiki 1.13.0 as well as the new one from your link below.
The error is
1) from the original function:
Error: oElm.getElementsByTagName is not a function
Source File:
http://wiki.rockinchina.com/skins/common/wikibits.js?164 Line: 452
which is the line (near to the beginning of that function):
var arrElements = (strTagName == "*" && oElm.all)? oElm.all :
oElm.getElementsByTagName(strTagName);
2) from the new function:
Error: elm.getElementsByClassName is not a function
Source File:
http://wiki.rockinchina.com/index.php?title=-&action=raw&smaxage=0&…
Line: 152
which is the line (near to the beginning of that function):
var elements = elm.getElementsByClassName(className),
What am I doing wrong here?
Thanks,
Matthias
P.S.: I am using Firefox 3, but some IE gave me the same problem.
Am Fri, 5 Dec 2008 14:12:43 -0600
schrieb "Walter Mazza" <wjmazza(a)gmail.com>om>:
oh my! deepest apologies ><
I quickly typed up that code instead of copy/pasting from our JS
file cause I also have other code in this function I didn't want
to add :P Here is the updated code.
function ExtLinks() {
var extlinks = getElementsByClassName('extlink');
for (var i=0, il=extlinks.length; i<il; i++) {
var ele = extlinks[i];
var link = ele.getElementsByTagName('a')[0];
if (link) link.setAttribute('target','_blank');
};
};
addOnloadHook(ExtLinks);
And yes, it runs on page load because we need it to run after the
elements are loaded. :) let me know if it doesnt work.
@ Platonides:
Thanks for pointing that out! I must have overlooked that
variable
Walter Mazza
On Fri, Dec 5, 2008 at 2:02 PM, Matthias Korn
<matsch(a)rockinchina.com>wrote;wrote:
> Hi,
>
> Am Fri, 5 Dec 2008 12:20:50 -0600
> schrieb "Walter Mazza" <wjmazza(a)gmail.com>om>:
>
> [..]
> > Code for [[Template:ExtLink]]: (new page)
> > <span class="extlink">[[{{{1}}}]]</span>
> >
> > Code for [[MediaWiki:Common.js]]: ("append" to page)
> > function ExtLinks() {
> > var extlinks = getElementsByClassName('extlink');
> > for (var i=0, il=extlinks.length; i<il; i++) {
> > extlinks[i].setAttribute('target','_blank');
> > };
> > };
> > addOnloadHook(ExtLinks);
> >
> > Now whenever we want to make a interwiki link open in a new
> > window, we just use {{ExtLink|Special:Upload}}
> >
> > the function getElementsByClassName should already be
> > defined in the wikibits.js file but if for some reason it is
> > not available, you can get the updated version at
> >
>
http://www.robertnyman.com/2008/05/27/the-ultimate-getelementsbyclassname-a…
>
> I tried your JavaScript function, which seemed the way to go
> for me (just without the template around it). But, somehow, it
> is not working.
>
> Yes, I force reloaded.
> Yes, I have getElementsByClassName.
>
> The method seems to be executed onLoad (I inserted an
> alert()), but links still open in the same window. Also, while
> looking at the method: isn't it rather adding the
> target-attribute to the span-tag than to the link itself?
> Without trying it, this seems suspicious.
>
> I also checked the DOM (with Firebug) and the target-attribute
> of the link is empty (don't know if it should be there though).
>
> Thanks for your help,
> Matthias
>
> _______________________________________________
> MediaWiki-l mailing list
> MediaWiki-l(a)lists.wikimedia.org
>
https://lists.wikimedia.org/mailman/listinfo/mediawiki-l
>
_______________________________________________
MediaWiki-l mailing list
MediaWiki-l(a)lists.wikimedia.org
https://lists.wikimedia.org/mailman/listinfo/mediawiki-l
--
Rock in China
http://wiki.rockinchina.com/
http://www.rockinchina.com/
_______________________________________________
MediaWiki-l mailing list
MediaWiki-l(a)lists.wikimedia.org
https://lists.wikimedia.org/mailman/listinfo/mediawiki-l