User talk:Ohconfucius/test/MOSNUM dates.js

Bug and corrections

 * 1) "{ {main" becomes "{ {mainmain", 13 April 2012 resolved 13 April 2012
 * 2) "| accessdate = 25 December 2008" becomes "December   25 2008", 12 April 2012 resolved 15 April 2012
 * 3) becomes, resolved 15 April 2012
 * 4) becomes resolved 15 April 2012
 * 5) http://en.wikipedia.org/w/index.php?title=Alcohol_laws_of_Utah&diff=487366373&oldid=481660290 resolved 15 April 2012
 * 6) '05.09.08' becomes '05@ERROR@08' resolved 15 April
 * 7) dmy - Non-conversion of July 31, 2005. resolved 15 April
 * 8) dmy - Non-conversion of January 31, 2005. resolved 15 April
 * 9) Unwarranted expansion of date:   to resolved 20 April 2012
 * 10) Unwarranted removal of ordinal resolved 20 April 2012
 * 11) becomes resolved 20 April 2012
 * 12) "$424 billion" becomes ",24 billion" (from Virginia) resolved 13 May
 * 13) ->
 * 14) becomes
 * 15) missing comma.  becomes
 * 16) stripping of hyphens without changing month " " becomes " "
 * 17) order of month switched with year in range  becomes
 * 18) fails to remove ordinal 'the 17th of May'
 * 19) becomes
 * 20) '1st Marquess' becomes '1 Marquess'

Simplifications
Hi!

What do you think about [//en.wikipedia.org/w/index.php?title=User:Ohconfucius/test/MOSNUM_dates.js&oldid=500061806&diff=501012556 optimizing] some regexes? Helder 21:46, 6 July 2012 (UTC)

Updates
Hello !

Could you make these fixes and improvements to the script? Helder 02:26, 13 August 2014 (UTC)
 * ✅ Do I have to change the function calls (from other scripts such as this) in any way? --  Ohc  ¡digame! 02:32, 13 August 2014 (UTC)
 * is any function defined in this script called from another js page? Helder 03:06, 13 August 2014 (UTC)
 * Helder, the only place these functions would normally be called from is my vector file, and it doesn't seem to be the case. But if I have to call it, how would this be achieved? --  Ohc  ¡digame! 03:12, 13 August 2014 (UTC)
 * If you are referring to any of the functions which are used in the click events, you could trigger the click event of the link associated to the function (e.g. executing ), and jQuery would take care of passing the event object as a parameter (which is used in the lines  ). But if these functions are also intended to be called without a click event, then it would need some change to avoid errors such as "ReferenceError: e is not defined".
 * BTW: I just noticed the script is creating duplicated ids in the page (there are 4 "t-expand", 2 "t-dmy", 2 "ca-unitfixer", etc), which is invalid in HTML. You should choose a unique id for each link. Helder 03:43, 13 August 2014 (UTC)
 * Noted. I never knew what those IDs' functions were, and the fact they were the same never caused any problems. Now renamed. I will do that for my other scripts too. --  Ohc  ¡digame! 03:52, 13 August 2014 (UTC)

@: based on 139877,it seems there is another option: create a function like and then attach two click handlers to each link, as in Then you don't need to add  to every function. Helder 21:46, 15 August 2014 (UTC)
 * So, if I need to improve the other scripts (like formatgeneral.js), presumably I need to put  as the first line in each driver (the one activated directly by the button) and then change the syntax for the click buttons? Would I do that for   only, or do I need to do it for   and , both of whose functions reside in a subscript? And what does that   line do anyway? --  Ohc  ¡digame! 02:58, 15 August 2014 (UTC)
 * In these cases, the event.preventDefault is to avoid scrolling to the top of the page when clicking in the link (which is what a link with href "#" would do by default - you can check that commenting the line and clicking in the link). This is necessary in each function used as a click handler for a link, such as,   and  . Helder 03:25, 15 August 2014 (UTC)
 * Brilliant. Much more elegant solution. --  Ohc  ¡digame! 01:30, 16 August 2014 (UTC)
 * I've just been using some of the new buttons. I've observed that the script seems to place the script button higher up on the sidebar. Also thinking that there is perhaps no advantage to having this instruction as most of my script buttons have a trailing instruction . Any comments? --  Ohc  ¡digame! 02:44, 16 August 2014 (UTC)
 * both  and the old   add the link (by default) after the last item which is in the portlet at the time they are executed (unless you specify where it should be in the 7th parameter, see its documentation - currently you are specifying an empty string). Therefore, since User:Ohconfucius/test/MOSNUM dates.js add the link "ALL dates to dmy" before "Body dates to dmy", this will be their relative order in the sidebar. Moreover, if you have multiple scripts adding buttons to the portlet (e.g. flagcruft.js and MOSNUM dates code.js), when the second script is executed all the buttons from the fist script will be in the portlet already, so the second script will add them after the existing links. So I assume you noticed some change in the order because your scripts are executed in a different order. Notice that   is asynchronous, so the order of two calls to it on e.g. your vector.js may not be the same in which the imported scripts will be executed. If you need a specific loading order you need to use some kind of callback or hook (there is a related discussion on WP:Village pump (technical)).
 * I think if you do not prevent the default behavior of the link, user who enabled Live Preview would still see the page scrolling up even if you execute . Helder 17:18, 16 August 2014 (UTC)
 * Right, I knew it had to be something like that. Thanks fr the explanations. regards, --  Ohc  ¡digame! 02:37, 17 August 2014 (UTC)