Are there any restrictions on js functions allowed on MediaWiki? I'm asking because the function addEventListener() and setTimer don't seem to work.
The following js code works outside of MediaWiki (i.e. I troubleshot by creating a simple test.php file with the js script, and it works as intended.)
The following code is supposed to trigger every second and update a <nowiki><p></nowiki> tag on-screen, starting when the user clicks a button. Oddly, the function triggers on every button press, instead of once every second.
Here's the code: (I'm not using jQuery -- I copied an example online and didn't update it for jQuery.)
window.addEventListener( 'load', function ( ) {
var start = document .getElementById("start");
start.addEventListener( 'click', startTime );
});
function startTime( ) {
startWatch( );
// a few other things that hide / unhide some html elements
}
function startWatch( ) {
var x = document .getElementById("timer");
x.innerHTML = 'Time: ' + secs;
seconds++;
/* call the setTimeout( ) to keep the timer alive ! */
clearTime = setTimeout( "startWatch( )", 1000 );
}
Using MW version 1.30.0