Login | Register For Free | Help
Search for: (Advanced)

Mailing List Archive: Wikipedia: Wikitech

JS2

 

 

Wikipedia wikitech RSS feed   Index | Next | Previous | View Threaded


tstarling at wikimedia

Nov 26, 2009, 4:17 AM

Post #1 of 6 (821 views)
Permalink
JS2

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


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


tstarling at wikimedia

Nov 26, 2009, 5:23 PM

Post #2 of 6 (763 views)
Permalink
Re: JS2 [In reply to]

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


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


roan.kattouw at gmail

Nov 27, 2009, 2:53 AM

Post #3 of 6 (762 views)
Permalink
Re: JS2 [In reply to]

2009/11/27 Tim Starling <tstarling [at] wikimedia>:
> 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)

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


lists at nadir-seen-fire

Nov 27, 2009, 7:31 PM

Post #4 of 6 (749 views)
Permalink
Re: JS2 [In reply to]

Roan Kattouw wrote:
> 2009/11/27 Tim Starling <tstarling [at] wikimedia>:
>
> ...
>> 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 (Dantman, Nadir-Seen-Fire) [http://daniel.friesen.name]

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


tstarling at wikimedia

Nov 28, 2009, 7:53 PM

Post #5 of 6 (750 views)
Permalink
Re: JS2 [In reply to]

Daniel Friesen wrote:
> Roan Kattouw wrote:
>> 2009/11/27 Tim Starling <tstarling [at] wikimedia>:
>>
>> ...
>>> 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


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


mdale at wikimedia

Nov 30, 2009, 9:10 AM

Post #6 of 6 (720 views)
Permalink
Re: JS2 [In reply to]

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
Wikitech-l [at] lists
https://lists.wikimedia.org/mailman/listinfo/wikitech-l

Wikipedia wikitech RSS feed   Index | Next | Previous | View Threaded
 
 


Interested in having your list archived? Contact Gossamer Threads
 
  Web Applications & Managed Hosting Powered by Gossamer Threads Inc.