Extension talk:CodeMirror
Add topic
|
jQuery in frontend hooks
[edit]I know it may be too late, but couldn’t we use native DOM objects in frontend hooks instead of jQuery objects? jQuery is a quite sloppy interface: it tries to handle everything uniformly, even though it’s impossible – one naturally has to handle elements and collections of elements differently (“elements” are jQuery objects with zero or one HTML element, “collections” are jQuery objects with potentially more than one element), just like different types of elements (e.g. jQuery provides a .val()
method on all jQuery objects, even though it makes sense only on form elements). If you see that the ext.CodeMirror.initialize
gives you a jQuery object, you don’t know what you actually get. If it gives you an HTMLTextAreaElement
, you know that
- it’s one element, not zero and not more,
- and it has all the properties a text area has (value, read-only state etc.).
Given the HTMLTextAreaElement
, you can always wrap it in a jQuery object if it’s more convenient, but unwrapping is not possible in a statically-provably safe way. —Tacsipacsi (talk) 19:19, 19 November 2024 (UTC)
- It's funny you mention this. As I writing more docs the other day, I had the same thought! I chose jQuery for frontend hooks pretty much only because so many other hooks (in Core and extensions) do the same. There's something to be said about consistency, but I do regret the decision nonetheless for the reasons you state, and indeed I'm afraid it's too late to change it now. Even in the CodeMirror extension itself, we more often than not need to access the HTMLTextAreaElement, so it would make things easier to work internally to rid of jQuery altogether!
- It's only tentative right now, but I believe
ext.CodeMirror.switch
(documented to work only with WikiEditor) will be deprecated in favor of a new hook,ext.CodeMirror.toggle
, which is fired regardless of where what editor CodeMirror is integrated with. I had already planned to not fire the hook with a jQuery object, but instead the CodeMirror instance. So at least we're head in that no-jQuery direction, I guess. — MusikAnimal talk 01:46, 26 November 2024 (UTC)