Commons talk:JavaScript styleguide

From Wikimedia Commons, the free media repository
Jump to: navigation, search

This is a great idea! pfctdayelise (说什么?) 02:51, 6 July 2007 (UTC)

Use single whitespace indent - Show me an example on commons obeying[edit]

I do not see any script on commons obeying this guideline. Editing .js in the big Browser-Edit is not very clever and convenient (and I think nobody does it). Therefore this rule should be removed. --RE RILLKE Questions? 12:11, 24 March 2011 (UTC)

I agree. Besides, the sentense "Reducing the indent [...] can considerably reduce the weight of the script." seems not to be valid with ResourceLoader minification in use. Helder 13:26, 24 March 2011 (UTC)
By the way: the resource loader does not touch or modify any MediaWiki.js from Commons. How should it accomplish this task? -- RE RILLKE Questions? 17:48, 25 March 2011 (UTC)
A lot of Mediawiki:Common.js still does. But if people do whatever the heck they want to do there is not much point in having such a rule. Hell, let's just ditch the entire styleguide, who needs schmanchy fancy stuff like that anyways? --Dschwen (talk) 16:39, 25 March 2011 (UTC)
Ironic or serious? And what the hell is schmanchy fancy? My dictionary cannot find it. --RE RILLKE Questions? 17:03, 25 March 2011 (UTC)
A bit of both. I would like to see a clean unified look of code. I used to edit in a lot of the JS files on commons and it was a royal pain in the butt to switch back and forth between zillions of individual indenting styles. I made an effort by writing this Styleguide, but I can see that it is indeed pointless as people still continue to ignore it and format the code however they please. So, yes, I think it is a good idea, but unfortunately the commons world does not seem to be ready for it. --Dschwen (talk) 17:08, 25 March 2011 (UTC)
Don't worry. We can feel happy that nobody gets the idea of compacting the code (replacing long variables with short letters, ...). But there is a JavaScript solution, that "beautifies" code: http://jsbeautifier.org/ that makes correcting indents easy. --RE RILLKE Questions? 17:49, 25 March 2011 (UTC)
Yeah, I also looked for scripts to auto indent in textareas. That stuff exists and we might think about adding something here for *.js pages. Catching tab alone and replacing it by n-spaces would be a huge help. Adding the same number of indent characters (spaces) as the previous line on a keyupevent for the return key would be 90% of the way in my opinion. This would effectively force consistent indentation and save a ton of work. --Dschwen (talk) 05:10, 27 March 2011 (UTC)
Coincidentally Brion posted on teh Mailinglist about his frustration with editing js in browser. He whipped up a script which you can include like this:
importScriptURI('http://www.mediawiki.org/w/index.php?title=MediaWiki:Gadget-CodeEditor.js&action=raw&ctype=text/javascript&dontcountme=s');
--Dschwen (talk) 04:33, 13 April 2011 (UTC)

┌─────────────────────────────────┘
Thanks for this information. The editor is very useful and works fine; however scrolling through long scripts is slow (because DOM tree has to become modified). I tried to do this myself, but the result was horrible, especially because IE and Firefox treat selections differently. Therefore this approach, using HTML DOM is a blessing. We should include the script into the settings (not by default because there are maybe Opera-users) on .js pages. -- RE rillke questions? 09:29, 13 April 2011 (UTC)

Seems pretty snappy to me on Google Chrome. Yeah, we should make this into a gadget. I was just too lazy/busy. --Dschwen (talk) 20:46, 13 April 2011 (UTC)