JSL or "JavaScript Library" is, well, a JavaScript Library. It borrows many ideas from jQuery.

Download

Features

The features in JSL(apart from the standard stuff) include...

Some Sample Code

Enough talk - this is what you can do with the Library...

Using the Event Handler

JSL.dom("a").click(function(e) { // Adds a click event handler to all links
	alert(this.href); //Shows the link URL
	JSL.event(e).stop(); //And stops the event from propagating any further
});

Of course, if you don't want to type in JSL.dom all the time, you can use the shortcut...

jslib("p.intro").hide(); // Hides all the <p> elements with the class 'intro'.

And, JSL, like almost all other major JavaScript libraries, supports $...

$("#download-link").on("mouseover", function() { // This is how you attach an event.
	alert("Why did you hover over me?");
});

About that '#' character in '$("#download-link")' - that's optional...

$("download-link").setStyle({"font-size":20});

There is a small gotcha here - this will fail if your the ID you are using is a valid HTML tag. Say that you have a anchor with ID 'link'. Now, if you use the code...

$("link").click(...);

you will be attaching the click event to the <link > elements - and not the anchor with the ID link. If you want to do that, make sure that your ID matechs no HTML elements - or use the '#' character...

$("#link").click(...);

The $() works with arrays...

$([23, 98, 4, 39]).map(function(x) { return x+1; }); //Will return [24, 99, 5, 40]. (1 + each element in the array).

numbers...


$(34.93323).round(2); // Returns 34.93
$(5).times(function() {
	alert("Hi!");
}); // runs alert("Hi") 5 times.

and events as well...

$("a").click(function(e) {
	$(e).stop(); // Stops the event.
});

Of course, it goes without saying that using this $() a lot will have a bad impact on readability. So I would suggest using it only for DOM selection. For other things, use the long form...

JSL.array([4,5,1]).indexOf(5); //Returns 1

Ajax is supported as well - this is basic Ajax syntax...

JSL.ajax("data.php").load(function(txt){
	alert(txt); //Fetches the URL data.php - and passes it to this function.
});
More Code Samples

Please use the JSL forum for all support questions.

blog comments powered by Disqus