User talk:Ohconfucius/test/MOSNUM dates.js
Appearance
Bug and corrections
[edit]"{{main" becomes "{{mainmain", 13 April 2012resolved 13 April 2012"| accessdate = 25 December 2008" becomes "December 25 2008", 12 April 2012resolved 15 April 2012resolved 15 April 2012New York Times 26 Mar 1961
becomesNew York TimesMar , 26 1961
,resolved 15 April 2012<ref name="chronicle">Houston Chronicle, 18 November 2008</ref>
becomes<ref name="chronicle">Houston Chronicle,November 18 2008</ref>
http://en.wikipedia.org/w/index.php?title=Alcohol_laws_of_Utah&diff=487366373&oldid=481660290resolved 15 April 2012'05.09.08' becomes '05@ERROR@08'resolved 15 Aprildmy - Non-conversion of July 31, 2005.resolved 15 Aprildmy - Non-conversion of January 31, 2005.resolved 15 AprilUnwarranted expansion of date:resolved 20 April 2012br >Region 4: Feb 14, 2008<re
tobr />Region 4: February 14, 2008<ref
Unwarranted removal of ordinalresolved 20 April 2012resolved 20 April 2012Vol. 23, No. 5, May 1987, p. 3
becomesVol. 23, No. May 5, 1987, p. 3
"$424 billion" becomes ",24 billion"(from Virginia) resolved 13 May|date=October 10-1997}}
->date=October 10–1, 997}}
[[Progressive Conservative Association of Alberta leadership election, 2011|October 2, 2011]]
becomes[[Progressive Conservative Association of Alberta leadership election, 2011|October 02, 2011]]
- missing comma.
took place between 3–22 November 1967
becomestook place between November 3–22 1967
- stripping of hyphens without changing month "
accessed 12-08-2011
" becomes "accessed 12 08 2011
" - order of month switched with year in range
|date=2003 Jul-Aug
becomes|date=July 2003–Aug
- fails to remove ordinal 'the 17th of May'
accessdate=2012 Apr 07
becomesaccessdate=April 2012 07
- '1st Marquess' becomes '1 Marquess'
Simplifications
[edit]Hi!
What do you think about optimizing some regexes? Helder 21:46, 6 July 2012 (UTC)
Updates
[edit]Hello Ohconfucius!
Could you make these fixes and improvements to the script? Helder 02:26, 13 August 2014 (UTC)
- Done 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)
- @Ohconfucius: 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)
- Ohconfucius: 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
$( '#t-ISOdmy' ).click();
), and jQuery would take care of passing the event object as a parameter (which is used in the linese.preventDefault()
). 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)
- Ohconfucius: 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
- 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)
- @Helder.wiki: So, if I need to improve the other scripts (like formatgeneral.js), presumably I need to put
e.preventDefault();
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 forOhc_run_formatgeneral()
only, or do I need to do it forOhc_downcase_headings()
andOhc_eject_zh()
, both of whose functions reside in a subscript? And what does thate.
line do anyway? -- Ohc ¡digame! 02:58, 15 August 2014 (UTC)- @Ohconfucius: 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
Ohc_run_formatgeneral
,Ohc_downcase_headings
andOhc_eject_zh
. Helder 03:25, 15 August 2014 (UTC)
- @Ohconfucius: 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
@Ohconfucius: based on gerrit:139877,it seems there is another option: create a function like
function prevDef ( e ) {
e.preventDefault();
}
and then attach two click handlers to each link, as in
$( add('p-tb', '#', 'Body dates to dmy', 't-dmy', 'day month', , ) ).click(prevDef).click(ohc_body_to_dmy_driver);
$( add('p-tb', '#', 'Body dates to mdy', 't-mdy', 'month day', , ) ).click(prevDef).click(ohc_body_to_mdy_driver);
...
Then you don't need to add e.preventDefault()
to every function. Helder 21:46, 15 August 2014 (UTC)
- Brilliant. Much more elegant solution. -- Ohc ¡digame! 01:30, 16 August 2014 (UTC)
- @Helder.wiki: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
doaction('diff');
. Any comments? -- Ohc ¡digame! 02:44, 16 August 2014 (UTC)
- @Ohconfucius: both
mw.util.addPortletLink
and the oldaddPortletLink
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 thatimporScript
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)#Notify another JavaScript file that my script has finished running?). - 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
doaction('diff');
. 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)