Thursday, February 22, 2007
Monday, February 12, 2007
Could I change a native function ?
Just a quick post about how to modify a document (and others generic objects) native methods.
What's that ?
... a really simple way to extend with your defined object each element created using document.createElement function.
This is an example with useful comments (I hope)
That's all, and this method is only a basic native method override example, have fun with JavaScript :-)
// basic example
document.createElement = (function(createElement, Element){
return function(nodeName){
var element, key;
try{element = createElement(nodeName)}
catch(e){element = createElement.call(document, nodeName)};
for(key in Element)
element[key] = Element[key];
return element;
}
})(document.createElement, {});
What's that ?
... a really simple way to extend with your defined object each element created using document.createElement function.
This is an example with useful comments (I hope)
// redefine document.createElement native function
// using anonymous function
document.createElement = (
function(
// original document.createElementFunction
createElement,
// object used to extend created elements
Element
){
// new document.createElement function
return function(
// type of element (div, p, link, style ... )
nodeName
){
// element and key to loop over object
var element, key;
// IE like this
try{element = createElement(nodeName)}
// FireFox like that
catch(e){element = createElement.call(document, nodeName)};
// loop over Element
for(key in Element)
// and assign each method to new element
element[key] = Element[key];
// return created element
return element;
}
})(
// send to anonymous, the original function
document.createElement,
// send object used to extend created elements too
{
// read firstChild node
read:function(){
return this.firstChild.nodeValue
},
// write text into node
write:function(text){
this.appendChild(document.createTextNode(text))
}
}
);
// basic example
onload = function(){
var div = document.createElement("div");
document.body.appendChild(div);
div.write("Hello World !!!");
alert(div.read()); // Hello World !!!
};
That's all, and this method is only a basic native method override example, have fun with JavaScript :-)
Friday, February 2, 2007
GzOutput 0.5 finally approved !!!
PHPClasses has approved my last notable uploaded class, GzOutput :-)
Features
Use them to optimize your feeds, your javascripts, your css, your txt files ... or why not, every page of your portal, e-commerce or everything else.
Do you need an example ? My overbyte.Editor single script source use them from different weeks without any problem, using crunch level 2 and compression level 9.
Easy to configure and mod_reqrite ready.
Could be enought ?
Features
- compatible with both php version 4 and 5 (E_ALL | E_STRICT notice free)
- create runtime every kind of content-type with or without dedicated charset
- cache automatically every kind of file or file list (one or more JavaScript, CSS, XML, xHTML, TXT, others)
- decrease client download time (about 5 times faster!)
- increase server performances if cache option is enabled (about 3 times faster!)
- give you control with differents public static methods, easy to use, secure and portable
- "perfect" unobtrusive solution, compatible with every browser, every page parser (W3, WatchFire, WebSiteoptimizzation, others) and doesn't modify sources, just crunch them with different levels if you choose to crunch so you don't need any kind of packer, for example for your javascript files
- "forgettable solution", automatically update chached file when one or more required file has been changed
Use them to optimize your feeds, your javascripts, your css, your txt files ... or why not, every page of your portal, e-commerce or everything else.
Do you need an example ? My overbyte.Editor single script source use them from different weeks without any problem, using crunch level 2 and compression level 9.
Easy to configure and mod_reqrite ready.
Could be enought ?
Subscribe to:
Posts (Atom)