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

Content deleted Content added
Updates: both mw.util.addPortletLink and the old addPortletLink 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 documentatio
m Updates: Yep, it is asynchronous.
Line 54:
*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)
:{{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. IfNotice I remember correctly,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)