Posts

Showing posts from September, 2007

What's wrong with new IEContentLoaded solution?

Update This post talk about old implementation posted in Ajaxian before this one . After some interesting comment, posted by Diego Perini , it seems that His last proposal is logically the best We can use today to solve this IE problem. What I missed in my one is an onreadystatechange alternative to be sure function is called before onload one. In my case this is not a problem but if You use third party code libraries it should be a big problem. At this point Diego solution seems to be perfect for every case so just use them and thank You Diego and every other developer that helped Him to find this cool, portable, efficient solution :-) --------------------------------------------- The solution proposed in this page to solve in another way DOMContentLoaded IE problem, ir really interesting . I didn't test them so much but I suppose this is a valid alternative. I didn't know doScroll behaviour too, so it's quite a surprise for me and I'm happy if this will work as exp...

[TOD] The most compact Array.prototype.indexOf

The TOD is a JavaScript standard Array indexOf prototype implementation. I know this is a basic trick but many times useful in IE too: Array.prototype.indexOf=function(o,i){for(var j=this.length,i=i<0?i+j<0?0:i+j:i||0;i<j&&this[i]!==o;i++);return j<=i?-1:i} That's all ... in the most compact way ... but what about most compact lastIndexOf prototype? Array.prototype.lastIndexOf=function(o,i){var s=this,r=s.reverse().indexOf(o,i);s.reverse();return r} Update Thanks to Laurent, the most compact lastIndexOf should be this one: Array.prototype.lastIndexOf=function(o,i){return this.slice(0).reverse().indexOf(o,i)} Probably one slice instead of two reverse should be a better choice? I'll test them :-) Performances? Good enough ... Compatibility? IE4 or greater!

[ITA] Colpo basso a Beppe Grillo o un banale autogoal ?

Oggi, 24 settembre 2007, il telegiornale Studio Aperto ha trasmesso un servizio inerente un vecchio spettacolo del Beppe nazionale dove lo stesso criticava Internet e distruggeva un computer, descrivendo con rabbia l'inutilità della rete ma soprattutto l'incapacità di sfruttare la tecnologia a favore del lavoro e del progresso. Sebbene questo servizio possa sembrare, secondo il mio opinabile e probabilmente azzardato giudizio, volutamente screditante nei confronti delle "recenti" vicessitudini del noto comico, è possibile azzardare l'ipotesi che lo stesso sia nato indirettamente dal blog di un altro comico che stimo e seguo da molti anni ma che ha incentrato parte di una personale riflessione sul marketing. E' nel blog di Daniele Luttazzi infatti che si può leggere, ormai da giorni, il suo lucido giudizio riguardo il V-day e, prima ancora, sulle strategie commerciali della satira proposta da Grillo. Ma di che cosa parlava veramente Grillo nello spettacolo d...

[COW] document.create cross-browser implementation

This COW goal is to use a simple, cross-browser and fast way to create a DOM element. About document.createElement This function works in a different way if used inside browser Internet Explorer. This allows developers to create some HTML element instead of single one using its tag name. // Only with IE document.body.appendChild( document.createElement("<iframe />") ); Some library uses personal function to add an element, using its tag name, or to add a piece of HTML code, using innerHTML property instead of DOM element creation and manipulation. About document.createTextNode This function works in the same way inside every browser and its goal is to create a text node to add inside another element. document.body.appendChild( document.createTextNode("Hello Text Element") ); A Text Element is the correct way to write something inside a generic HTMLElement and doesn't work as innerHTML because it automatically escape each char. About COW, document.create...

noscript problems? Just fixed ;-)

While I was writing precedent post I thought about a really simple solution, showed in this post using PHP but compatible with every server-side program language. self brainstorming Head page doesn't accept a noscript tag but it accpets without problems one or more script tags. If I'm not wrong, page download and parse is syncronous and that's mean that if I write a piece of code inside a script, next one will have this code ready or just executed. Since downloading is syncronous, I can use this behaviour to save in a session this information and to show different layout using next tag. <head> <script type="text/javascript" src="cssFilter.php"><!--// CSS Filter //--></script> <link rel="stylesheet" media="all" href="myPage.php" /> </head> The order is absolutely important to use this solution, just because first file need to do something like that: <?php session_start(); $_SESSION[...

noscript tag behaviour and head conflicts

In this Web 2.something era there's a big problem with noscript tag and I wonder what does W3 think about them. noscript and its standard implementation This tag is really useful to increase page informations or accessibility, allowing developers to show an alternative content if user has not JavaScript enabled or his browser doesn't support other kind of tags. <script type="text/jvascript">doStuff()</script> <noscript>Your browser can't do my Stuff</noscript> This is a basic example of noscript usage and expected behaviour is that every JS compatible browser will try to execute code insde script tag while every JS disabled or not compatible browser will show an alternative information. So, what's wrong with noscript ? When a browser is JS compatible ignores totally noscript tag. It doesn't render its informations, just " jump " after the end of this tag. At the same time, if a browser is not compatible with tag used bef...

JavaScript namespace + using proposal

I've just uploaded inside devpro my last JavaScript proposal: a little, simple and fast namespace function, with a single static public method called using . What's a namespace ? A namespace is " a place where everything is unobtrusive ", where in this case unobtrusive means that You can't (shouldn't) modify other libraries. Who use a namespace ? Many program languages (C# / Python / Java / maybe one day PHP and others) use namespace since their first implementation (packages, from - import, using). In JavaScript world, big (but not too) libraries use namespace too (Dojo, YUI!) while many other libraries use a sort of internal namespace (jQuery, MooTools, Prototype) to separe FX, utils and other piece of code. What about my proposal ? It's really tiny as simple to use and You can find them in this page . Here there's a first, basic, simple example: // create / modify or overwrite a namespace called webreflection // setting an object with a type key a...

JPU - JavaScript CPU Monitor

Image
This is a little experiment, based on single threading JavaScript behaviour and for this reason not "perfect". As You can see on top right of this blog, JPU just tell You if your operations inside this page have a cost for your CPU. For example, try to click one mini-banner on the right side (OCS - DCS) and look at JPU monitor during fade in/out. The better browser I've tested is Opera but FireFox and Internet Explorer seems to work nicely too :-) If You want to add a JPU in your site, just use a script tag like this one: <script type="text/javascript" src="http://www.3site.eu/JPU/JPU.js" ><!--// JPU - by WebReflection //--></script> If You just want to test JPU inside another site, using FireFox or uriscript compatible browser, just use this lik . Please remember that JPU is just for fun, about 0.5 Kb and quite totally unobtrusive. Have fun with JPU :D Istant Update Here You can view a demo page comparing them with your Operat...