User talk:Ohconfucius/test/MOSNUM dates.js: Difference between revisions

Content deleted Content added
m Updates: Yep, it is asynchronous.
m <nowiki/> to avoid {{ taken for template markup; properly close <p>
 
(One intermediate revision by one other user not shown)
Line 1:
==Bug and corrections==
#<s>[http://en.wikipedia.org/w/index.php?title=Slobodan_Milo%C5%A1evi%C4%87&diff=prev&oldid=487041738 "{<nowiki/>{main" becomes "{<nowiki/>{mainmain"], 13 April 2012</s> resolved 13 April 2012
#<s>[http://en.wikipedia.org/w/index.php?title=Ala_Paredes&diff=prev&oldid=487022955 "| accessdate = 25 December 2008" becomes "December 25 2008"], 12 April 2012</s> resolved 15 April 2012
#<s>[http://en.wikipedia.org/w/index.php?title=Albert_C._Barnes&diff=487281456&oldid=465949367 <code>''New York Times'' 26 Mar 1961</code> becomes <code>''New York Times''Mar , 26 1961</code>],</s> resolved 15 April 2012
Line 53:
Then you don't need to add <code>e.preventDefault()</code> to every function. [[User:Helder.wiki|Helder]] 21:46, 15 August 2014 (UTC)
*Brilliant. Much more elegant solution. --<small><span style="background-color:#ffffff;border: 1px solid;">[[User:Ohconfucius|'''<span style="color:#000000; background-color:#00FF00">&nbsp;Ohc&nbsp;</span>''']]</span></small>[[User talk:Ohconfucius|<sup>''¡digame!''</sup>]] 01:30, 16 August 2014 (UTC)
*{{ping|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. <p>Also thinking that there is perhaps no advantage to having this instruction as most of my script buttons have a trailing instruction <code>doaction('diff');</code>. Any comments? --<small><span style="background-color:#ffffff;border: 1px solid;">[[User:Ohconfucius|'''<span style="color:#000000; background-color:#00FF00">&nbsp;Ohc&nbsp;</span>''']]</span></small>[[User talk:Ohconfucius|<sup>''¡digame!''</sup>]] 02:44, 16 August 2014 (UTC)</p>
:{{reply to|Ohconfucius}} both <code>mw.util.addPortletLink</code> and the old <code>addPortletLink</code> add the link (by default) [https://github.com/wikimedia/mediawiki-core/blob/master/resources/src/mediawiki/mediawiki.util.js#L341-L342 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, [https://doc.wikimedia.org/mediawiki-core/master/js/#!/api/mw.util-method-addPortletLink see its documentation] - currently you are specifying an empty string). Therefore, since [[Special:PermaLink/621009023|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. [[User:Ohconfucius/script/flagcruft.js|flagcruft.js]] and [[User:Ohconfucius/test/MOSNUM dates code.js|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 <code>imporScript</code> is asynchronous, so the order of two calls to it on e.g. [[User:Ohconfucius/vector.js|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 [[Special:Preferences#mw-prefsection-editing|enabled Live Preview]] would still see the page scrolling up even if you execute <code>doaction('diff');</code>. [[User:Helder.wiki|Helder]] 17:18, 16 August 2014 (UTC)
::Right, I knew it had to be something like that. Thanks fr the explanations. regards, --<small><span style="background-color:#ffffff;border: 1px solid;">[[User:Ohconfucius|'''<span style="color:#000000; background-color:#00FF00">&nbsp;Ohc&nbsp;</span>''']]</span></small>[[User talk:Ohconfucius|<sup>''¡digame!''</sup>]] 02:37, 17 August 2014 (UTC)