MediaWiki talk:Gadget-morebits.js

Latest comment: 12 years ago by This, that and the other in topic IndexOf x $.inArray

Untitled 2011 comment edit

Could a friendly admin please copy the contents of User:This, that and the other/temp/MediaWiki:Gadget-morebits.js to this page? I am currently in the process of testing this gadget script. — This, that, and the other (talk) 08:09, 16 May 2011 (UTC)Reply

Friendly admin gladly complies. Amalthea 10:10, 16 May 2011 (UTC)Reply

IndexOf x $.inArray edit

Wouldn't be better to change

mw.config.get( 'wgUserGroups' ).indexOf( group ) !== -1

to

$.inArray(group, mw.config.get( 'wgUserGroups' ))

to ensure cross-browser support? Helder 13:55, 18 May 2011 (UTC)Reply

I have no idea. But as there is no opposition I have made the change for you. — Martin (MSGJ · talk) 10:14, 19 May 2011 (UTC)Reply
Fair enough. Personally, I think it's a performance decrease, and doesn't really improve legibility. But, that aside, any changes to this page are likely to get unintentionally overwritten, unless Twinkle maintainers get a heads-up at WT:TW. — This, that, and the other (talk) 10:40, 19 May 2011 (UTC)Reply
Helder's point was mainly browser compatibility, I think: IE8 doesn't support JS 1.6 and thus doesn't know Array.indexOf.
Don't know how many other problems morebits has in IE8 (and older), of course. Amalthea 11:03, 19 May 2011 (UTC)Reply
Indeed. IE8 shows "undefined" if I put "javascript:alert(['foo'].indexOf)" in the adress bar while Firefox displays "function indexOf() {[native code]}". Helder 18:06, 25 May 2011 (UTC)Reply

Actually, that change broke stuff. Could an admin please revert it? Thanks, — This, that, and the other (talk) 10:57, 19 May 2011 (UTC)Reply

Done. Amalthea 11:03, 19 May 2011 (UTC)Reply
inArray also returns the index, comparing the return value with -1 should have worked. Amalthea 11:06, 19 May 2011 (UTC)Reply
My bad. I forgot to add the "!== -1" part to the code above. This should work:
$.inArray(group, mw.config.get( 'wgUserGroups' )) !== -1;
Helder 18:06, 25 May 2011 (UTC)Reply
I read at the top of the script: 'Most of the stuff here doesn't work on IE < 9.' I suspect it is not much use to fix this one incompatibility if several others remain. Anyway, as This, that and the other said, this script is in the middle of active development and any changes need to be made in the git repository to be persistent. Amalthea 19:20, 25 May 2011 (UTC)Reply
Eh, now I get it: userIsInGroup is called while loading this script, so activating this gadget would actually cause javascript errors in IE8 or below. We can't have that in a gadget. I've made the change here, could someone also do so in the repo? Amalthea 19:25, 25 May 2011 (UTC)Reply
I don't quite get it myself, but I trust your judgment, Amalthea. I have made the change in the git repo. — This, that, and the other (talk) 07:42, 26 May 2011 (UTC)Reply