DJCMBear
07-20-2010, 10:41 AM
Hi im in the middle of creating my own javascript library but got stuck I can do everything for this library I just got stuck on how to make it flow through a list of strings like jQuery does.
For example jQuery allows you to write a string like this:
$('li').add('p').css('background-color', 'red');
Which they can select all li tags add a p tag inside then change the background color of that tag, What im asking is how can I go about doing this where I can create a similar system which allows me to flow through my class functions.
Right now its a very small code because I started again to allow better overview of where things are but this is it so far.
This allows the use of both SDK and $ at the start of the function for example.
$.Display({'file':'index.php','id':'divid'});
And
SDK.Display({'file':'index.php','id':'divid'});
(function(window)
{
var $ = {
Display: function(info)
{
this.call(info.file,info.id,'file='+info.file);
},
call: function(file,id,parameters)
{
if (window.XMLHttpRequest)
{
xmlhttp=new XMLHttpRequest();
}
else
{
xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
}
xmlhttp.onreadystatechange=function()
{
if (xmlhttp.readyState==4 && xmlhttp.status==200)
{
document.getElementById(id).innerHTML=xmlhttp.responseText;
}
}
xmlhttp.open("POST",file,true)
xmlhttp.setRequestHeader("Content-type", "application/x-www-form-urlencoded")
xmlhttp.send(parameters)
},
Flash: function(params)
{
if(params.file){alert(params.file);}
if(params.id){alert(params.id);}
}
};
// Expose SDK to the global object
window.SDK = window.$ = $;
})(window);
For example jQuery allows you to write a string like this:
$('li').add('p').css('background-color', 'red');
Which they can select all li tags add a p tag inside then change the background color of that tag, What im asking is how can I go about doing this where I can create a similar system which allows me to flow through my class functions.
Right now its a very small code because I started again to allow better overview of where things are but this is it so far.
This allows the use of both SDK and $ at the start of the function for example.
$.Display({'file':'index.php','id':'divid'});
And
SDK.Display({'file':'index.php','id':'divid'});
(function(window)
{
var $ = {
Display: function(info)
{
this.call(info.file,info.id,'file='+info.file);
},
call: function(file,id,parameters)
{
if (window.XMLHttpRequest)
{
xmlhttp=new XMLHttpRequest();
}
else
{
xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
}
xmlhttp.onreadystatechange=function()
{
if (xmlhttp.readyState==4 && xmlhttp.status==200)
{
document.getElementById(id).innerHTML=xmlhttp.responseText;
}
}
xmlhttp.open("POST",file,true)
xmlhttp.setRequestHeader("Content-type", "application/x-www-form-urlencoded")
xmlhttp.send(parameters)
},
Flash: function(params)
{
if(params.file){alert(params.file);}
if(params.id){alert(params.id);}
}
};
// Expose SDK to the global object
window.SDK = window.$ = $;
})(window);