Tag Archives: Javascript

Short Ajax Script

April 13, 2008 by aaron

AJAX - it

I wanted to see how small you could make a fully functional AJAX script that worked cross-browser and degraded gracefully, so I went through an old custom AJAX script and made it as small as I possibly could. In the resulting AJAX scripts, the post version is 410 characters and the GET version is only 359 characters long. The scripts are fully functional and accept the following parameters: URL, DATA (in string form), and ELEMENT (to update).

The scripts could be a little smaller, but it would really kill readability.

“Get” AJAX Script

function a(l,d,u){
try{r = new XMLHttpRequest();}catch(e){try {r = new ActiveXObject('Msxml2.XMLHTTP');}catch(e){r = new ActiveXObject('Microsoft.XMLHTTP');}}
if(r){
r.onreadystatechange = function() {if (r.readyState == 4 && r.status == 200){document.getElementById(u).innerHTML = r.responseText;}}
r.open('GET', l+'?'+d, true);r.send(d);
}
}

“Post” AJAX Script

function b(l,d,u){
try{r = new XMLHttpRequest();} catch(e){try {r = new ActiveXObject('Msxml2.XMLHTTP');} catch(e){r = new ActiveXObject('Microsoft.XMLHTTP');}}
if(r){
r.onreadystatechange = function() {if (r.readyState == 4 && r.status == 200){document.getElementById(u).innerHTML=r.responseText;}}
r.open('POST', l, true);r.setRequestHeader('Content-type', 'application/x-www-form-urlencoded');r.send(d);
}
}

Combined AJAX Script

This combined script also accepts a fourth parameter ‘p’ that should evaluate true if the data is to be sent by post.

function a(l,d,u,p){
try{r = new XMLHttpRequest();}catch(e){try {r = new ActiveXObject('Msxml2.XMLHTTP');}catch(e){r = new ActiveXObject('Microsoft.XMLHTTP');}}
if(r){
r.onreadystatechange = function() {if (r.readyState == 4 && r.status == 200){document.getElementById(u).innerHTML = r.responseText;}}
if(p){r.open('POST', l, true);r.setRequestHeader('Content-type', 'application/x-www-form-urlencoded');}else{r.open('GET', l+'?'+d, true);}
}
}

Demo: (Sorry but you will have to go to the full page so the JavaScript is loaded.)

Read More ⟶

Displaying WordPress categories in a horizontal dropdown menu.

April 16, 2008 by aaron
One of my readers recently asked how I created my horizontal menu bar: the short answer is by mixing CSS and Javascript. The first step is to get WordPress to display the menu as a hierarchical list without a title. <?php wp_list_categories('sort_column=name&sort_order=asc&style=list&children=true&hierarchical=true&title_li=0'); ?> We then wrap this WordPress code in the following so we can style it. <div style="text-align:center;"> <ul id="menu" style="padding:0; margin:0;"> <?php wp_list_categories(&#039;sort_column=name&sort_order=asc&style=list&children=true&hierarchical=true&title_li=0&#039;); ?> </ul> </div> I added this to my header.php, but you can add it anywhere you want it to appear.
Read More ⟶

DIY Javascript Effects Library

April 12, 2007 by aaron
As part of a project I needed an extremely light-weight special effects library that would allow queuing of effects (required), multiple effects, the ability to set a per-effect “framerate”, and enough extensibility to fill any need, but it had to be independent of any Javascript library or OS. For the “core”: I needed it to be able to queue effects to run one after another, but still be able to run effects synchronously with their own queues.
Read More ⟶

The Online Desktop.

April 8, 2007 by aaron
Is anyone using StartForce? It is an online desktop that is built in JavaScript, I played around with it a little bit and was impressed, but at 424KB compressed and 1305KB uncompressed it is definitely not for the lower end computer if you like to do other things on it. Update: Sorry, I forgot there was this thing called anchor text in links.

PHP classes = ‘Happy’; Javascript “classes” = ‘Pull your hair out’;

April 29, 2007 by aaron
As mentioned previously I have been trying to move INAP away from a simply function based system to a class based system. The PHP was unbelievably easy to convert. It literally took a couple hours to convert the entire program from prefixed functions to nice, neat and easy-to-read classes. It was rolled out with a few bugfixes and very little stress. Then I started to do the same to Javascript, so the plugin could clarify its variables and functions and still “play nice,” and I swear the all the Javascript was specifically coded to make it difficult.
Read More ⟶

Adsense Creator

April 16, 2007 by aaron
This creator makes it painlessly simple for you to adjust your adsense ads. Just select the options you want, and once you are done adjusting the adsense code the creator will update your code and you can move on with life. The creator includes an advanced color picker to make it easy for you to pick just the right color. Originally, I made the following creator for my WordPress Adsense widget; however, I decided that it was being wasted, and I wanted to see if I could make WordPress pages behave as real HTML files, so this became a one-day project to get it working.
Read More ⟶

Short Ajax Script

April 13, 2008 by aaron

AJAX - it

I wanted to see how small you could make a fully functional AJAX script that worked cross-browser and degraded gracefully, so I went through an old custom AJAX script and made it as small as I possibly could. In the resulting AJAX scripts, the post version is 410 characters and the GET version is only 359 characters long. The scripts are fully functional and accept the following parameters: URL, DATA (in string form), and ELEMENT (to update).

The scripts could be a little smaller, but it would really kill readability.

“Get” AJAX Script

function a(l,d,u){
try{r = new XMLHttpRequest();}catch(e){try {r = new ActiveXObject(&#039;Msxml2.XMLHTTP&#039;);}catch(e){r = new ActiveXObject(&#039;Microsoft.XMLHTTP&#039;);}}
if(r){
r.onreadystatechange = function() {if (r.readyState == 4 && r.status == 200){document.getElementById(u).innerHTML = r.responseText;}}
r.open(&#039;GET&#039;, l+&#039;?&#039;+d, true);r.send(d);
}
}

“Post” AJAX Script

function b(l,d,u){
try{r = new XMLHttpRequest();} catch(e){try {r = new ActiveXObject(&#039;Msxml2.XMLHTTP&#039;);} catch(e){r = new ActiveXObject(&#039;Microsoft.XMLHTTP&#039;);}}
if(r){
r.onreadystatechange = function() {if (r.readyState == 4 && r.status == 200){document.getElementById(u).innerHTML=r.responseText;}}
r.open(&#039;POST&#039;, l, true);r.setRequestHeader(&#039;Content-type&#039;, &#039;application/x-www-form-urlencoded&#039;);r.send(d);
}
}

Combined AJAX Script

This combined script also accepts a fourth parameter ‘p’ that should evaluate true if the data is to be sent by post.

function a(l,d,u,p){
try{r = new XMLHttpRequest();}catch(e){try {r = new ActiveXObject(&#039;Msxml2.XMLHTTP&#039;);}catch(e){r = new ActiveXObject(&#039;Microsoft.XMLHTTP&#039;);}}
if(r){
r.onreadystatechange = function() {if (r.readyState == 4 && r.status == 200){document.getElementById(u).innerHTML = r.responseText;}}
if(p){r.open(&#039;POST&#039;, l, true);r.setRequestHeader(&#039;Content-type&#039;, &#039;application/x-www-form-urlencoded&#039;);}else{r.open(&#039;GET&#039;, l+&#039;?&#039;+d, true);}
}
}

Demo: (Sorry but you will have to go to the full page so the JavaScript is loaded.)

Read More ⟶

Displaying WordPress categories in a horizontal dropdown menu.

April 16, 2008 by aaron
One of my readers recently asked how I created my horizontal menu bar: the short answer is by mixing CSS and Javascript. The first step is to get WordPress to display the menu as a hierarchical list without a title. <?php wp_list_categories('sort_column=name&sort_order=asc&style=list&children=true&hierarchical=true&title_li=0'); ?> We then wrap this WordPress code in the following so we can style it. <div style="text-align:center;"> <ul id="menu" style="padding:0; margin:0;"> <?php wp_list_categories(&#039;sort_column=name&sort_order=asc&style=list&children=true&hierarchical=true&title_li=0&#039;); ?> </ul> </div> I added this to my header.php, but you can add it anywhere you want it to appear.
Read More ⟶

DIY Javascript Effects Library

April 12, 2007 by aaron
As part of a project I needed an extremely light-weight special effects library that would allow queuing of effects (required), multiple effects, the ability to set a per-effect “framerate”, and enough extensibility to fill any need, but it had to be independent of any Javascript library or OS. For the “core”: I needed it to be able to queue effects to run one after another, but still be able to run effects synchronously with their own queues.
Read More ⟶

The Online Desktop.

April 8, 2007 by aaron
Is anyone using StartForce? It is an online desktop that is built in JavaScript, I played around with it a little bit and was impressed, but at 424KB compressed and 1305KB uncompressed it is definitely not for the lower end computer if you like to do other things on it. Update: Sorry, I forgot there was this thing called anchor text in links.

PHP classes = ‘Happy’; Javascript “classes” = ‘Pull your hair out’;

April 29, 2007 by aaron
As mentioned previously I have been trying to move INAP away from a simply function based system to a class based system. The PHP was unbelievably easy to convert. It literally took a couple hours to convert the entire program from prefixed functions to nice, neat and easy-to-read classes. It was rolled out with a few bugfixes and very little stress. Then I started to do the same to Javascript, so the plugin could clarify its variables and functions and still “play nice,” and I swear the all the Javascript was specifically coded to make it difficult.
Read More ⟶

Adsense Creator

April 16, 2007 by aaron
This creator makes it painlessly simple for you to adjust your adsense ads. Just select the options you want, and once you are done adjusting the adsense code the creator will update your code and you can move on with life. The creator includes an advanced color picker to make it easy for you to pick just the right color. Originally, I made the following creator for my WordPress Adsense widget; however, I decided that it was being wasted, and I wanted to see if I could make WordPress pages behave as real HTML files, so this became a one-day project to get it working.
Read More ⟶