Fav XMLHttpRequest function

var request = null;
function InitAJAX()
{
var objxml = null;
var ProgID = ["Msxml2.XMLHTTP.6.0", "Msxml2.XMLHTTP.3.0","Msxml2.XMLHTTP", "Microsoft.XMLHTTP"];

try {
objxml = new XMLHttpRequest();
}
[...]

More



Rock solid javascript addEvent()

Rock solid addEvent() written, again, by Dustin Diaz (my internet super hero).

function addEvent( obj, type, fn ) {
if (obj.addEventListener) {
obj.addEventListener( type, fn, false );
EventCache.add(obj, type, fn);
}
else if (obj.attachEvent) {
obj["e"+type+fn] = fn;
obj[type+fn] = function() { obj["e"+type+fn]( window.event ); }
obj.attachEvent( “on”+type, obj[type+fn] );
EventCache.add(obj, type, fn);
}
else {
obj["on"+type] = obj["e"+type+fn];
}
}

var EventCache = function(){
var listEvents = [];
return {
listEvents : [...]

More



Integer to Roman numeral

Changes and integer to a roman numeral.

private function numberToRoman($num)
{
$n = intval($num);
$result = ”;

$lookup = array(’M’ => 1000, ‘CM’ => 900, ‘D’ => 500, ‘CD’ => 400,
‘C’ => 100, ‘XC’ => 90, ‘L’ => 50, [...]

More



Optimised AJAX Call

A nice way to manage AJAX calls written by Dustin Diaz.

var asyncRequest = function() {
function handleReadyState(o, callback) {
if (o && o.readyState == 4 && o.status == 200) {
if (callback) {
callback(o);
[...]

More



Disable the Firebug extension

Useful for pages containing a lot of javascript that might bring Firefox to a grinding halt if it’s not disabled.

if (! (’console’ in window) || !(’firebug’ in console)) {
var names = ['log', 'debug', 'info', 'warn', 'error', 'assert', 'dir', 'dirxml', 'group', 'groupEnd', 'time', 'timeEnd', 'count', 'trace', 'profile', 'profileEnd'];
window.console [...]

More