Free Small / Tiny Javascript Library - updated 8th June 2011

Some people have been grabbing my javascript library from the various sites I have used it on.
Several of these miscreants have then asked me for some explanations of its functioning. { I am, you will understand joking about 'miscreants' - you are all very welcome to copy any code of mine whereever you find it]
So I've made some of it available here in case it may be of use or interest for you.
I will just run through a brief synopsis of the library covering the points that have been raised.
Perhaps a few examples of its use, and please feel free to grab either the zipped version or if U prefer, you can copy the text, and paste it into a text file and save it as 'whatever.js'.
If you are a very rich person, you could make a donation and get good karma, or otherwise don't make a donation and still get good karma, But if you are poor please DON'T make a donation (and get good karma).
This is a free server so no php or sql. but if you have a comment, put it in the yummy page and I will post it here.

Tiny javascript library: Easily editable (by a baby) = Extendable - Support for Flash - Cross Browser support - 3k.


Science is fun!!!! never take it seriously.

Download Library

Download text of the tiny javascript library
download tiny javascript library.zip

So here it is

$ = function(a){
object = document.getElementById(a); ...
...
...
...
return object
}
So we made a function to 'get' the object we are interested in and we have returned the object all ready for chaining.

So we write $(id)

$ = function(a){
O = document.getElementById(a);
...
O.op= function (b) {
if (b){
if (!document.all)
this.style.opacity = b;
else
this.style.filter = 'alpha(opacity=' + b * 100 + ')';
return b;
else {
if (!document.all)
try {
o = this.style.opacity;
} catch(e) {
o = 1
}
else
{ if (!this.currentStyle.filter) return 1; opac = this.currentStyle.filter.split('=')[1].split(')')[0]/100; }
if (!o)
o= 1
}
return o;
};
...
return O;
}
Firstly you will notice 'object' is now called 'O' (easier to type)
A plug-in has been added - to get and set opacity. On the getter, the main reason for failure here is that opacity has not been explicitly set so 'undefined' will typically be returned. In that case it means its probably 1 (100% for IE) so I’m returning 1. But very strange things have been know to happen here (beyond the scope of this discourse), hence to try catch clauses.
Anyway, since it's your code, you will know what is most appropriate for your particular circumstance.
The point is simply to show anyone who is not quite sure, how the plug ins can be easily added or taken away according to your needs at the time.

So we write $(id).op(.5); set the opacity to 50%.

.
I will put one more in for absolute clarity.

$ = function(a){
O = document.getElementById(a);
...
O.Op= function (b) {
if (b){
if (!document.all)
this.style.opacity = b;
else
this.style.filter = 'alpha(opacity=' + b * 100 + ')';
return b;
else {
if (!document.all)
try {
o = this.style.opacity;
} catch(e) {
o = 1
}
else
{ if (!this.currentStyle.filter) return 1; opac = this.currentStyle.filter.split('=')[1].split(')')[0]/100; }
if (!o)
o= 1
}
return o;
};
O.css = function(b,c){
if (!c){
return this.style[b];
} else {
this.style[b] = c;
}
};

...
return O;
}
If you cleaned the code up a bit, you could 'Packer' it. I treat all the sites I'm involved with as 'works in progress' so I never do that. Also I'm far tooooo lazy. Also, since the library is so small, server calls become the main time consuming factor - I put the site code in the same file as the library for that. You will have your own ideas.


So we write $(id).css("backgroundImage",'url(3_1.jpg)'); Change backgrond image.

Addendum: I have been asked about the O.style[a] in the css plug-in. just to explain then, It is the same as O.style.whatever except it expects a string as its argument.
Thus if b = 'width', this.style[b] would be like saying this.style.width. OK?

Some usage examples then.





$('ex1').css('backgroundColor','#f00');

Click me!

to see the effect.
$('ex1').A('width','900',2000,function(){
$('ex1').A('width','350',5000) });
animate width

Click me!


$('body').css('backgroundImage',"url('yummy5sm.jpg')");

Put Yummy

Click me!



$('ex1').h(330); set height

Click me!




I'm a Test Box. My id='ex1'



$('ex1').op(.5); set opacity

Click me!



$('ex1').A('op','1',5000);
fade to full opacity 5sec

Click me!


$('ex1').A('op','0',5000);

fade to 0 opacity 5sec

Click me!


$('el.id').A("vars","params",period,callback()) Fading- read on
$('ex1').A('op','.9',2000, function(){
$('ex1').A('op','.5',3000, function(){
$('ex1').css('backgroundColor','#ff0');
$('ex1').css('color','#000')})}); } ) Click me!
);
So this is an example of callback on the fade routine.

$('flm').fl('http://www.electrician-for-london.com/flash/electCube.swf','100%','100%',
'wmode=transparent')

Click me!




Could put 123px here in place of %s.