List Info

Thread: Ultra Small Behaviour with Prototype




Ultra Small Behaviour with Prototype
user name
2006-09-13 17:22:32
After staring long and hard at the Behaviour code I decided
I loved the
concept and hated the implementation. Here is an alternative
implementation.

var Behaviour = Class.create();
Behaviour.prototype = {
	initialize: function(s) { this.sheet = s; },
	apply: function(){
		for (sel in this.sheet){
			var els = $$(sel);
			for (var i=0; i<els.length; i++)
				this.sheet[sel].call(this,els[i]);
		}
	}
};

And for implementation, you pass the same hashmap you would
have passed
to the old function and then do something like this:

var actions = new Behavior(myrules);
Event.observe(window,'load',function(){actions.apply();},f
alse);

Note that I removed the ability to add multiple sheets,
instead opting
to create a new instance of the class for each sheet that I
wish to
apply.

Let me know what you think.


--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the
Google Groups "Behaviour Javascript Library"
group.
To post to this group, send email to behaviourgooglegroups.com
To unsubscribe from this group, send email to
behaviour-unsubscribegooglegroups.com
For more options, visit this group at http://group
s.google.com/group/behaviour
-~----------~----~----~----~------~----~------~--~---

Ultra Small Behaviour with Prototype
user name
2006-09-13 17:30:58
Mike,

Nice!  FYI: http://encyte
media.com/event-selectors/ takes a similar
approach; using the behaviour idea but capitalizing on
prototype to
make it shorter/faster/better.  Event selectors also add an
event
assignment syntax into the css itself (like div:click or
div:hover).
I thought you might like to take a look at it.

Anyway, good job.

Ben West (not Nolan)

On 9/13/06, Mike Crute <mcrutegmail.com> wrote:
>
> After staring long and hard at the Behaviour code I
decided I loved the
> concept and hated the implementation. Here is an
alternative
> implementation.
>
> var Behaviour = Class.create();
> Behaviour.prototype = {
>         initialize: function(s) { this.sheet = s; },
>         apply: function(){
>                 for (sel in this.sheet){
>                         var els = $$(sel);
>                         for (var i=0; i<els.length;
i++)
>                                
this.sheet[sel].call(this,els[i]);
>                 }
>         }
> };
>
> And for implementation, you pass the same hashmap you
would have passed
> to the old function and then do something like this:
>
> var actions = new Behavior(myrules);
>
Event.observe(window,'load',function(){actions.apply();},f
alse);
>
> Note that I removed the ability to add multiple sheets,
instead opting
> to create a new instance of the class for each sheet
that I wish to
> apply.
>
> Let me know what you think.
>
>
> >
>

--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the
Google Groups "Behaviour Javascript Library"
group.
To post to this group, send email to behaviourgooglegroups.com
To unsubscribe from this group, send email to
behaviour-unsubscribegooglegroups.com
For more options, visit this group at http://group
s.google.com/group/behaviour
-~----------~----~----~----~------~----~------~--~---

Ultra Small Behaviour with Prototype
user name
2006-09-13 17:48:13
Benjamin West wrote:
> Nice!  FYI: http://encyte
media.com/event-selectors/ takes a similar
> approach; using the behaviour idea but capitalizing on
prototype to
> make it shorter/faster/better.  Event selectors also
add an event
> assignment syntax into the css itself (like div:click
or div:hover).
> I thought you might like to take a look at it.
>
> Anyway, good job.
>
> Ben West (not Nolan)

Thanks Ben! I took a look at the encytemedia.com version and
I like it
a lot! Thanks for the feedback.


--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the
Google Groups "Behaviour Javascript Library"
group.
To post to this group, send email to behaviourgooglegroups.com
To unsubscribe from this group, send email to
behaviour-unsubscribegooglegroups.com
For more options, visit this group at http://group
s.google.com/group/behaviour
-~----------~----~----~----~------~----~------~--~---

Ultra Small Behaviour with Prototype
user name
2006-09-15 06:21:54
Mike Crute wrote:
> Benjamin West wrote:
> > Nice!  FYI: http://encyte
media.com/event-selectors/ takes a similar
> > approach;
  <snip>
> Thanks Ben! I took a look at the encytemedia.com
version and I like it
> a lot! Thanks for the feedback.

If you prefer Prototype, I'd suggest you to check Low Pro
as
event:Selectors is too slow, IMHO.

You may also want to check my post here
<http://rajeshanbiah.blog
spot.com/2006/09/behaviorsjs-alternative-to-behaviourjs.html
>

--
  <?php echo 'Just another PHP saint'; ?>
Email: rrjanbiah-at-Y!com    Blog: http://rajeshanbiah
.blogspot.com/


--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the
Google Groups "Behaviour Javascript Library"
group.
To post to this group, send email to behaviourgooglegroups.com
To unsubscribe from this group, send email to
behaviour-unsubscribegooglegroups.com
For more options, visit this group at http://group
s.google.com/group/behaviour
-~----------~----~----~----~------~----~------~--~---

[1-4]

about | contact  Other archives ( Real Estate discussion Medical topics )