User talk:Alex brollo/Library.js

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

Code remarks[edit]

  1. We are using jQuery at MediaWiki. This is why we generally avoid prototyping of existing/buit-in-types. Never do it for arrays or objects, please. ✓ Done
  1. I would be happy having at least short English comments. This is, however, not mandatory.
  2. Please use strict/type comparison (===) or truthy-tests (if (a) { }). If you compare strings with numbers, convert the string to a number before, if required (Using Number(no) or parseFloat(no, base) or an unary "+" operator)
  3. Our edit-textareas have IDs. To get their value, simply var text = $('#wpTextbox1').val(); Setting their value: $('#wpTextbox1').val(text); See jQuery documentation.
  4. For performance reasons, create a reference to the textarea at the beginning of your script/ the initializer var $myTextarea = $('#wpTextbox1'); and then refer to the variable later: $myTextarea.val(text). This way you avoid jQuery looking up the DOM each time you write $(selector)
  5. Bind (click) handlers. Never use on_x.
    <elem onclick="'+funzione+'"/>var myFunction = function(params) {}; $('<elem>').click(myFunction);
  6. Save code for repetitive tasks:
    .replace("{{Book","{{book") ....replace(/\{\{(?:book|creator|bio)/ig, function(x) { return x.toLowerCase(); })
  7. Formatting and alignment:
    book:parseTemplate("book",testo)book: parseTemplate("book",testo). You may use jsBeautifyer. It's even on Commons: Help:JavaScript validation. Use
     if (/\.js(?:\/.+)?$/.test(mw.config.get('wgPageName')) && ($.inArray( mw.config.get('wgNamespaceNumber'), [ 8, 2 ]) > -1)) {
      mw.loader.load('//commons.wikimedia.org/w/index.php?title=MediaWiki:JSValidator.js&action=raw&ctype=text/javascript');
     }
    
    in your personal JS.
  8. async: false - This can freeze browsers. Don't use it. ✓ Done
  9. white-space:pre-wrap; width:97%; padding:5px; → use CSS and a class.
  10. selectionStart and selectionEnd are not supported by all browsers; but this can be fixed later when I created a RL module (so we can simply use mw.loader.using('ext.gadget.jQuerySelection', ...) for selecting/evaluating the selection
  11. There is a function newButton but it isn't used. ✓ Done (moved to user/Bottoni.js)
  12. You are maybe interested in the tools and references listed on COM:User scripts

-- Rillke(q?) 11:59, 5 October 2012 (UTC)[reply]

Thanks for so a big work! Many of your suggestions are far away my present skills; I'll study them one by one ans I'll try to apply them (as soon I will be sure that I understand them!) --Alex_brollo Talk|Contrib 20:35, 6 October 2012 (UTC)[reply]

Functional remarks[edit]

Hi Alex, tried to create Creator:Jean-Chrétien-Ferdinand Hoefer (article does not exist) and Creator:Ferdinand Hoefer (blank result). I suggest allowing to change the article to lookup in Wikipedia if nothing was found. Thanks for the script and kind regards -- Rillke(q?) 09:30, 11 October 2012 (UTC)[reply]

Thanks for patience, comments and testing. I know haw a hard job is, to browse into layman, undocumented scripts...
Just to let you understand the whole logic of the scripts consider that they are (better, they where intended as) only "the Commons side" of a project coming from it.wikisource. When you open a nsIndex it.wikisource page and you have WIP experimental gadget installed, you'll see a creator link in the bottom of sidebar; if you like, you can use too a tool to take a look to the content of existing djvu/pdf information file into Commons, and to see if they need to be updated/created; you are in a page which states by default an Author exists, that exists too a book into wikisource ns0, and in 95% of cases that a page about author exists into it.wikipedia. So, when you click creator link, you are sure that lots of data exist, and that some template/data (Book/Creator) are lacking. Then Jarekt asked me to extend to en.wikipedia the "data transfer engine", but this implies a completely different scenario: nothing ensures about existence of data into en.wikipedia, and I ave been deeply surpised when I saw that sometimes the whole stuff runs, while I' not surprised at all that often the sctipts do not run. :-)
Please test the tool from a Creator page linked to an it.wikisource djvu/pdf file, in preview mode if you will avoid the risk of destroy valuable content, to test the tool "as we intended it". I should work a lot to fix "en.wikipedia" side of it, but I've now the priority of work about a bookCreator script, following the same logic and updating Information to a decent Book template for it.wikisource djvu/pdf information pages. --Alex_brollo Talk|Contrib 13:17, 11 October 2012 (UTC)[reply]
Alex is it OK if me, Rillke and possibly others alter User:Alex brollo/Library.js? Or would it better if we copy it somewhere else and Work with that copy. I was planning on trying to understand the code better and the first step would be to translate comments and start adding my comments. --Jarekt (talk) 03:06, 12 October 2012 (UTC)[reply]
I'm not desparecido :-), I'm simply rewriting all the stuff by scratch encouraged by Rillke remarks. Resulting code promises to be much more well structured (and simple). Please be patient, since I'm avoiding write it in a hurry.... and Im' documenting new functions in English, step by step. --Alex_brollo Talk|Contrib 16:24, 29 October 2012 (UTC)[reply]