Tim Starling wrote:
> The "js2" prefix will disappear from all interfaces in a future
> version. Callers can just use jQuery(document).ready() directly.
>   
One reason I don't just use jQuery(document).ready() was so remote 
embedding would only load jQuery where necessary. ie if remote embedding 
the library on a page did not include a <video> tag there would be no 
point in loading jQuery so you would not have the associated 
jQuery(document).ready() function. But then if some other page decided 
to use some "js2" interface it would call a defined function and we 
would know to load interfaces (including jquery)

But this can be adapted, for normal mediaWiki usage we can just say 
jQuery will always be available. For other remote embeds we can just 
create an entry point script similar to mwEmbedRemote.js

The other role the js2AddOnloadHook served was an entry point where 
extension or user scripts can start DOM manipulations and interface 
function calls knowing that core javascript interface have been built 
out (even if that build out happens asynchronously). 

For example when you have a page with a video tag and then you want to 
use an html5 video tag function call you could do:
js2AddOnloadHook (function(){
    vid = document.getElementById('embed_video');
    vid.play();
})
and have it work across IE and browsers that did not have the video tag 
supported since js2AddOnloadHook only got called once interfaces where 
ready.

Alternatively we have per interface bindings / onReady states or a 
"hook" system of sorts which is more modular ... but requires more code, 
documentation and coordination.
ie a separate: 
mw.videoInterfacesLoadedHook( //play )
or
$j('#embed_video').bind('onVideoInterfaceReady', function(){
    $j(this).get(0).play();
}); 

The problem is also present in the wikiEditor interface which is built 
out asynchronously. You end up having to queue the function requests or 
bind things to interface specific events which adds to the amount of 
code you have to write to hook into anything.
 
I would propose renaming js2AddOnloadHook to mw.addInterfaceReadyHook( 
function ) .. that would be a point for user script to hook into without 
having to write lots of separate checks to know that all the "core" 
interfaces had been built out / loaded.

--michael

_______________________________________________
Wikitech-l mailing list
[email protected]
https://lists.wikimedia.org/mailman/listinfo/wikitech-l

Reply via email to