Jump to content

MediaWiki talk:Gadget-calculator.js

Page contents not supported in other languages.
From Wikipedia, the free encyclopedia
This is an old revision of this page, as edited by Nardog (talk | contribs) at 10:40, 14 September 2024 (Make it previewable). The present address (URL) is a permanent link to this revision, which may differ significantly from the current revision.

Make it previewable

Currently it doesn't work in live preview, reply tool, etc. This should fix it.

var setup = function() { var elms = Array.from( document.getElementsByClassName( 'calculator-field' ) );
+
var setup = function( $content ) { var elms = Array.from( $content.find( '.calculator-field' ) );
$( setup );
+
mw.hook( 'wikipage.content' ).add( setup );

Nardog (talk) 01:59, 14 September 2024 (UTC)[reply]

cc: @Bawolff. – SD0001 (talk) 07:18, 14 September 2024 (UTC)[reply]
Should these sort of changes be made "upstream" during testing? — xaosflux Talk 08:15, 14 September 2024 (UTC)[reply]
I'm unsure that would work properly if the wikipage.content hook was fired multiple times during one page view. Bawolff (talk) 08:51, 14 September 2024 (UTC)[reply]
@Bawolff: For what reason do you suspect it might not? And if it doesn't then it should be fixed. Not being able to preview is unacceptable IMO. I tested my patch and it works in live preview, realtime preview, and reply tool. Nardog (talk) 10:25, 14 September 2024 (UTC)[reply]
Ah, it doesn't work if both live and realtime preview are used, presumably because elements with the same IDs exist. That could be mitigated by scoping queries to the $content fired by the hook and keeping references to the associated elements, requiring a wrapper element, or including a serial number in the IDs that increases on each hook firing. Nardog (talk) 10:34, 14 September 2024 (UTC)[reply]