Content deleted Content added
→Updates: 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). Thi |
@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', 'd |
||
Line 40:
*{{ping|Helder.wiki}} So, if I need to improve the other scripts (like [[User:Ohconfucius/test/formatgeneral.js|formatgeneral.js]]), presumably I need to put <code>e.preventDefault();</code> 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 <code>Ohc_run_formatgeneral()</code> only, or do I need to do it for <code>Ohc_downcase_headings()</code> and <code>Ohc_eject_zh()</code>, both of whose functions reside in a subscript? And what does that <code>e.</code> line do anyway? --<small><span style="background-color:#ffffff;border: 1px solid;">[[User:Ohconfucius|'''<span style="color:#000000; background-color:#00FF00"> Ohc </span>''']]</span></small>[[User talk:Ohconfucius|<sup>''¡digame!''</sup>]] 02:58, 15 August 2014 (UTC)
*:{{reply to|Ohconfucius}} In these cases, the [http://api.jquery.com/event.preventdefault/ 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 <code>Ohc_run_formatgeneral</code>, <code>Ohc_downcase_headings</code> and <code>Ohc_eject_zh</code>. [[User:Helder.wiki|Helder]] 03:25, 15 August 2014 (UTC)
@{{U|Ohconfucius}}: based on [[gerrit:139877]],it seems there is another option: create a function like
<syntaxhighlight lang="javascript">
function prevDef ( e ) {
e.preventDefault();
}</syntaxhighlight>
and then attach two click handlers to each link, as in
<syntaxhighlight lang="javascript">
$( 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);
...
</syntaxhighlight>
Then you don't need to add <code>e.preventDefault()</code> to every function. [[User:Helder.wiki|Helder]] 21:46, 15 August 2014 (UTC)
|