I was wondering ((aiming this question a little at John Q.)), how much
the various JavaScript libraries were actually looked over and compared
before the decision to use YUI was made.
I've just started looking at jQuery, and honestly, it's looking like a
much better library for use. Especially for anything to do with
MediaWiki's API.
Just a little comparison on the libraries in general first:
Library / Functionality
YUI
jQuery
License
BSD Style
MIT or GPL License
Company behind it
Yahoo
Unknown... However it appears to be a open group, rather than a company.
Also backed by the Open-source company Liferay
(However it appears Google and SorceForge use jQuery)
Maintained by 15 Employees paid by Yahoo, only 8 of whom are developers.
3 primary dev team members, 2 on the Evangelism team, 1 on the UI team,
3 on the plugins team, 2 on the web and design team.
Code openness
YUI Does not use their CVS to allow patches to the current working code.
jQuery actively uses SVN to allow for submission of patches to improve
or fix the core.
Now of course, all this data is something I found out only after
starting to get to like jQuery.
The primary thing here, is actually what the library can do, and how
good it's coding is.
Lets see... Starting with getting data using JSONP from MediaWiki's API.
Start with the request for the data from the current wiki, which will
grab the list of namespaces on the wiki, iterate over them, and output
an alert(); for each one.
Example url:
http://naruto.wikia.com/api.php?action=query&meta=siteinfo&siprop=namespaces
YUI:
function callback(result) {
for( var ns in result.query.namespaces ) {
alert(result.query.namespaces[ns]['*']);
}
};
YAHOO.util.Event.onDOMReady(
function() {
YAHOO.util.Get.script(
"http://naruto.wikia.com/api.php"+
"?action=query"+
"&meta=siteinfo"+
"&siprop=namespaces"+
"&format=json"+
"&callback=callback" );
} );
jQuery:
$.getJSON("http://naruto.wikia.com/api.php?action=query&meta=siteinfo&siprop=namespaces&format=json&callback=?",
function(data) {
$.each(data, function(i, item) {
alert(item['*']);
});
});
Actually, I should probably note something about the YUI one.
That one honestly took me well over an hour to create. And that's
because I stopped trying to do it properly. The YUI exmaples use YAHOO's
namespacing setup. Why? Because unlike jQuery, the callback being added
isn't automatic, you need to do it manually, and to do that properly you
need to create a big namespace, stick a pile of junk in int, and do
callback stuff and initialization in a object returned by that namespace.
And just a little extra, the for( ... in ... ) used in the YUI example
actually isn't the same as the $.each() used for jQuery. It actually
conditionally uses a for( ...; ...; ... ) [for arrays], or for( ... in
... ) [for objects], to bring out the best browser compatibility... Not
to mention the fact that it's cleaner, and a return false; is the same
as using a break; Except you can do something like this to break from
the $.each()...
$.each( fooBar, function(i, item) {
for( var ii = 0; ii < item.length; ii++ ) {
if( item[ii] = "baz" ) {
alert( "Found baz at "+i+"/"+ii );
return false;
}
}
};
It's a poor example... But quite simply, it's something absolutely
impossible anywhere else. Using a break inside of that for will break
out of the for and continue iteration over the fooBar. However, using
the return false; it actually breaks out of the iteration over fooBar.
jQuery also has a wide repo of Plugins which extend jQuery. I've even
seen things like JS doing XSL, an animator which animates from one class
to another, and a number of other things. Even a few DOM tree creation
plugins which are nice.
What's anyone's opinion, reply?
--
~Daniel Friesen(Dantman) of:
-The Gaiapedia (http://gaia.wikia.com)
-Wikia ACG on Wikia.com (http://wikia.com/wiki/Wikia_ACG)
-and Wiki-Tools.com (http://wiki-tools.com)
_______________________________________________
Wikia-tech-l mailing list
[email protected]
http://lists.wikia.com/mailman/listinfo/wikia-tech-l