JJ JavaScript Library

JJ is a light weight JavaScript library. The combination of JJ with ajax gives a very powerful development suit.

Download JJ

You can download (copy / paste) it from here or link to it directly by adding the following line:

<script type="text/javascript" src="http://www.btoot.com/jj.js"></script>

If you link to the script directly, please mentioned it on your site.

API reference

Main function

Parameters:

Return true.

e.g.

jj(function(){
	//the main program
});

Selectors

Selects one or more elements.

Parameters:

Return element.

e.g.

jj("#id");
jj("div");
jj("div.bold");

Json

Make an HTTP call, when the call returns a call-back function is called with the response object.

Parameters:

e.g.

jj("/json/msgs", {from : "Alex", limit : 10}, function(ms){
	//do something with messages (ms)
});

Event handlers (operate on element)

There is a single function which handle all events.

Parameters:

Return element.

e.g.

on("click", function(e){
	alert("click");
});

Content manipulation (operate on element)

There are five functions which manipulate the content of an element.

HTML content

Set or return the HTML content of the element.

Parameters:

Return element.

e.g.

ih();
ih("<p>Good</p>");

Text content

Parameters:

Return element.

e.g.

tc("Bad");

Append element

Parameters:

Return element.

e.g.

ap(elm);
ap(elm, '+');
ap(elm, '-');
ap(elm, '0');

Remove element

Parameters:

Return element.

e.g.

rm(elm);

Clear

Remove all children of the current element.

Return element.

e.g.

clr();

Style and attributes (operate on element)

There are three functions which query / change the style and attributes of elements.

Class name

Set or return class name of the element.

Parameters:

Return css value / element.

e.g.

cn();
cn("bold");
cn("+bold");
cn("-bold");

CSS

Set or return the css value.

Parameters:

Return css value / element.

e.g.

css("color");
css("color", "black");
css({
	color : "black",
	backgroundColor : "white"
});

Attributes

Set or return attribute value of the element.

Parameters:

Return css value / element.

e.g.

att("name");
att("name", "Bibo");
att({
	name : "Bibo",
	age : 22
});

Position and dimension (operate on element)

NOTE: These functions assume element is displayed as block and has absolute position.

There are four functions which query / change the position and dimension of elements.

X / Y position

Set or return the X position of the element.

Parameters:

Return x position / element.

e.g.

x();
x(100);
x(100, 200);
x(100, 200, function(){
	alert("done moving " + this);
});
y();
y(100);
y(100, 200);
y(100, 200, function(){
	alert("done moving " + this);
});

Width / Height

Set or return the width of the element.

Parameters:

Return width / element.

e.g.

w();
w(100);
w(100, 200);
w(100, 200, function(){
	alert("done resizing " + this);
});
h();
h(100);
h(100, 200);
h(100, 200, function(){
	alert("done resizing " + this);
});

Visibility (operate on element)

There are three functions which control the visibility of elements.

Opacity

Set opacity of the element.

Parameters:

Return element.

e.g.

op(0.2);
op(0.2, 100);
op(0.2, 100, function(){
	alert("done changing opacity " + this);
});

Hide

Hide the element.

Return element.

e.g.

hide();

Show

Show the element.

Return element.

e.g.

show();

Creating elements

There is a single function that create new elements.

je

Create a new element / component from template

Parameters:

Return element.

e.g.

je("div");