lunedì, ottobre 29, 2007

[jsn]getElementByClass revisited

Today me and my friends Andr3a had a talk about getElementsByClassName,
I had the idea to write my own implementation since 1 year ago,
in that time I first saw firefox document.evaluate and I blogged to remind myself that I must wrote a better implementation.
The original one was based on Dustin Diaz works.
Seems that the day is come for me, so I've taken my previous work and i've done a lot of optimization, i think now is one of the fastest that you can find around the net
...here the code:


getElementsByClassName.js

/*Kentaromiura 1.0 version*/
document.getElementsByClassName = function(searchClass,tag,node){
var p = function(){
if([].push)return function(a,b){a.push(b)};
return function(a,b){a[a.length]=b}
}();

node = node || document;
tag = tag || '*';

if(document.evaluate){
var xpr = document.evaluate([".//",tag,"[contains(concat(' ',@class,' '),' ",searchClass," ')]"].join(''),node, null, 0, null),
t = true,
els = new Array();
while(t=xpr.iterateNext()){
p(els,t);
}
return els;
}


var els = node.getElementsByTagName(tag),
pattern = new RegExp(["(^|\\s)",searchClass,"(\\s|$)"].join('')),
ce = new Array();

for (var i = 0, max = els.length; i < max; i++) {
if(pattern.test(els[i].className))
p(ce,els[i]);
}
return ce;
}


Tomorrow I will test it more, for now i only can say that it will work on
IE7, FF 2.0.x.x and safari 3.0.3
Teoretically it should work with IE4+, NN 7+,opera 8+ ff 1+ but keep this as not sure
since I can't test it right now.
So if you can leave a comment with your browser I would be grateful.

Ps. since I share my ideas with andr3a, he had wrote his own implementation,
it is very similar to my approach but it's different in some way, so be sure to take a look at his work

bye ;D

sabato, ottobre 20, 2007

post informativo: eliminazione adsense

Come potete notare ho eliminato adsense dal mio blog, mi è servito nel breve periodo in cui l'ho utilizzato a fare alcune statistiche, ho lasciato comunque la barra di ricerca di google perchè ho visto che è stata utilizzata diverse volte.

ho aggiunto comunque analitycs per vedere se il blog necessita di modifiche al layout o se, come penso, i contenuti sono accessibili senza troppi problemi..

sto inoltre rivalutando l'ipotesi di riabilitare i commenti anonimi in un futuro prossimo, faccio però notare che l'iscrizione a blogger è gratuita.

Alla prossima

domenica, ottobre 14, 2007

[jsn]Adobe Flex Presentation - Behaviour - Business Logic

Before I start I would say that I never seen an action script line
before today, day in which I started playing around with FLEX.

Since the Hello World example is old fashioned, I have the great idea to start
with something a bit harder, but just a bit since I want to separate my action script
code from the mxml.
basically i would to use mxml as a presentation layer,
an external file for all the logic (I called it BI.as)
and another AS file for handle the behaviour of my code



Seems that doing so i didn't respect the K&R commandments #0 that is
c:\> Thou shalt not start to learn a language without write THE proper hello world_

so, for that, i had to pay a big pain!
but in the end I'll be forgive and I come to a solution.


here the MXML:
kentatest.mxml

<?xml version="1.0"?>
<mx:Application xmlns:mx="http://www.adobe.com/2006/mxml" creationComplete="oncreation();">
<mx:Script source="BI.as" />
<mx:Script source="behaviour.as" />
<mx:Panel title="kenta template" paddingTop="10" paddingBottom="10" paddingLeft="10" paddingRight="10">
<mx:TextArea id="area1" />
<mx:Button id="btnSubmit" label="Submit" />
</mx:Panel>
</mx:Application>



and here the code, first the Business logic file:

BI.as

public function hello():void{
area1.text='Hello.kenta()';
}


and now the Behaviour file:

behaviour.as

private function oncreation():void{
btnSubmit.addEventListener('click', function (event:MouseEvent):void{
hello();
});
}


so in the end seems that I did i...what?!? why I put that lines in orange?
basically it was the fault that cause all of my pain trying doing this, without that lines
nothing work.
that lines is the same thing of write <body onload="oncreation"
on a HTML page.

so even if I can't completely separate actionscript code from the mxml presentation,
in this way I can add events externally in the behaviour file,
after that i tried to use addEventListener('creationComplete',...
but seems that flex didn't recognise the addEventListener function.

martedì, ottobre 09, 2007

Sorry? what time is now in UK?


THANK YOU FOR ORDERING IN RAINBOWS. THIS IS AN UPDATE.

YOUR UNIQUE ACTIVATION CODE(S) WILL BE SENT OUT TOMORROW MORNING (UK TIME). THIS WILL TAKE YOU STRAIGHT TO THE DOWNLOAD AREA.

HERE IS SOME INFORMATION ABOUT THE DOWNLOAD:

THE ALBUM WILL COME AS A 48.4MB ZIP FILE CONTAINING 10 X 160KBPS DRM FREE MP3s.


Just because I simply can't wait!