MediaWiki talk:Gadget-calculator.js
Make it previewable
![]() | It is requested that an edit be made to the interface page at MediaWiki:Gadget-calculator.js. (edit · history · last · links)
This template must be followed by a complete and specific description of the request, that is, specify what text should be removed and a verbatim copy of the text that should replace it. "Please change X" is not acceptable and will be rejected; the request must be of the form "please change X to Y".
The edit may be made by any interface administrator. Remember to change the |
Currently it doesn't work in live preview, reply tool, etc. This should fix it.
− | var setup = | + | var setup = function( $content ) {
var elms = Array.from( $content.find( '.calculator-field' ) ); |
− | + | mw.hook( 'wikipage.content' ).add( setup );
|
Nardog (talk) 01:59, 14 September 2024 (UTC)
- cc: @Bawolff. – SD0001 (talk) 07:18, 14 September 2024 (UTC)
- Should these sort of changes be made "upstream" during testing? — xaosflux Talk 08:15, 14 September 2024 (UTC)
- 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)
- @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)
- 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)
- Another technique is to attach a
--bound
class to the elements that have been processed, and skip them on further runs, c.f. mw:MediaWiki:Gadget-site-tpl-copy.js. – SD0001 (talk) 11:01, 14 September 2024 (UTC)
- Another technique is to attach a