JS2 has been demerged out of trunk and into the js2-work branch, so that we can start making some progress again towards the release of 1.16, and the deployment of the current trunk to Wikimedia.
The relevant code is not ready for beta testing, the problems with it are plain to see on code review. That's why I'm not comfortable with the idea of promoting it as a core component at this stage.
It's been merged since July (r53282), but there's been very little work on it by anyone other than Michael and I. So I don't think the merge has had the desired effect of bringing it to the attention of a wider developer community.
-- Tim Starling
I wrote:
JS2 has been demerged out of trunk and into the js2-work branch, so that we can start making some progress again towards the release of 1.16, and the deployment of the current trunk to Wikimedia.
The relevant code is not ready for beta testing, the problems with it are plain to see on code review. That's why I'm not comfortable with the idea of promoting it as a core component at this stage.
It's been merged since July (r53282), but there's been very little work on it by anyone other than Michael and I. So I don't think the merge has had the desired effect of bringing it to the attention of a wider developer community.
Roan has re-added js2/js2stopgap.js. I would prefer to see the JS2 functions in that file deprecated, and for extensions targeting 1.16 to use interfaces which we can more easily continue to support into the future.
loadGM(), gM(): misnamed, neither should be global, excessively abbreviated and unintelligible function names. I suggest adding mw.getMsg() and mw.addMessages() to wikibits.js.
$j: idiosyncratic, what's wrong with calling jQuery jQuery like everyone else?
function js2AddOnloadHook( func ) { $j(document).ready( func ); }
The "js2" prefix will disappear from all interfaces in a future version. Callers can just use jQuery(document).ready() directly.
mvJsLoader = { doLoad: function( deps, callback ) { callback(); } };
Note that mv is an abbreviation for Metavid, nothing that starts with mv belongs in the core. Calls to this should just be removed for now, since it doesn't do anything. There will eventually be a function called mw.load() which does a similar thing.
The filename, js2/js2stopgap.js, has the problem of containing js2 not once but twice. I have previously suggested adding an OutputPage::addJQuery() interface, which removes the need to specify the filename in the extension and can be designed to avoid the possibility of duplicate script tags. I still think that this is a good idea. Then the combined jQuery file can be moved to skins/common/jquery.combined.js, and later moved again when we have the ability to split it up into modules and to handle dependencies and what not.
A more generic script inclusion interface will no doubt be established at some stage, but its calling convention is not yet decided, so it makes sense to have a single-purpose function which can later be implemented in terms of the generic function, when it comes along.
With these changes, preview.js can easily be ported and re-added without any other js2 code.
-- Tim Starling
2009/11/27 Tim Starling tstarling@wikimedia.org:
Roan has re-added js2/js2stopgap.js. I would prefer to see the JS2 functions in that file deprecated, and for extensions targeting 1.16 to use interfaces which we can more easily continue to support into the future.
I'm all for it, as long as the existing feature set provided by js2stopgap remains.
loadGM(), gM(): misnamed, neither should be global, excessively abbreviated and unintelligible function names. I suggest adding mw.getMsg() and mw.addMessages() to wikibits.js.
$j: idiosyncratic, what's wrong with calling jQuery jQuery like everyone else?
I have no idea why that was done. Note that the 'normal' alias for jQuery (the one it also defines itself) is $ .
function js2AddOnloadHook( func ) { $j(document).ready( func ); }
The "js2" prefix will disappear from all interfaces in a future version. Callers can just use jQuery(document).ready() directly.
mvJsLoader = { doLoad: function( deps, callback ) { callback(); } };
Note that mv is an abbreviation for Metavid, nothing that starts with mv belongs in the core. Calls to this should just be removed for now, since it doesn't do anything. There will eventually be a function called mw.load() which does a similar thing.
The filename, js2/js2stopgap.js, has the problem of containing js2 not once but twice. I have previously suggested adding an OutputPage::addJQuery() interface, which removes the need to specify the filename in the extension and can be designed to avoid the possibility of duplicate script tags. I still think that this is a good idea.
I agree; I must've missed this the first time you suggested it.
Roan Kattouw (Catrope)
Roan Kattouw wrote:
2009/11/27 Tim Starling tstarling@wikimedia.org:
...
loadGM(), gM(): misnamed, neither should be global, excessively abbreviated and unintelligible function names. I suggest adding mw.getMsg() and mw.addMessages() to wikibits.js.
$j: idiosyncratic, what's wrong with calling jQuery jQuery like everyone else?
I have no idea why that was done. Note that the 'normal' alias for jQuery (the one it also defines itself) is $ .
I believe I read a note saying it was for compatibility with other javascript libraries that set $ to other things.
IMHO the recommended technique should just be used instead of another alias: (function($) { // your code here })(jQuery);
... Roan Kattouw (Catrope)
Daniel Friesen wrote:
Roan Kattouw wrote:
2009/11/27 Tim Starling tstarling@wikimedia.org:
...
loadGM(), gM(): misnamed, neither should be global, excessively abbreviated and unintelligible function names. I suggest adding mw.getMsg() and mw.addMessages() to wikibits.js.
$j: idiosyncratic, what's wrong with calling jQuery jQuery like everyone else?
I have no idea why that was done. Note that the 'normal' alias for jQuery (the one it also defines itself) is $ .
I believe I read a note saying it was for compatibility with other javascript libraries that set $ to other things.
IMHO the recommended technique should just be used instead of another alias: (function($) { // your code here })(jQuery);
Pretty much every modern JavaScript library defines a function called $, I was quite astonished at that when I reviewed them.
I see now that the jQuery documentation recommends $j as an alias for jQuery, so calling it idiosyncratic may have been unfair:
http://docs.jquery.com/Using_jQuery_with_Other_Libraries#Referencing_Magic_-_Shortcuts_for_jQuery
"If you don't like typing the full "jQuery" all the time, there are some alternative shortcuts:"
I'm one of those people who doesn't mind typing the full "jQuery" all the time, but I can be flexible if others have other opinions.
-- Tim Starling
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@lists.wikimedia.org