Oooo event:Selectors for Prototype
My article on the Separation of Layout and Logic touched on a key point of heavy Javascript use in an Ajax rich environment...the need for separation of Javascript code - namely events - from the HTML. Behaviour was my suggested CSS/Javascript event selector framework.
Behaviour is a stand-alone event framework. You can use it regardless of whether or not you are using Prototype (or some other Ajax/Javascript library) - which is pretty cool. But...if you are using Prototype there is a lot of code duplication between the two libraries. Luckily, Mir.aculo.us has brought event:Selectors to my attention which is causing me to sing a different tune! Justin Palmer, event:Selector's creator is crediting Behaviour for the idea, but he's has what Behaviour has done a few steps further.
- event:Selectors is dependant on Prototype which reduces code duplication.
- It has reduced the layer of complexity of event selecting by one layer of abstraction.
- The framework allows concatenation of CSS elements for event assignment.
- Lastly, its added a loaded event that is triggered when an element loads.
Here's an example of Behaviour event handlining:
JavaScript:
-
var rules = {
-
'#item li': function(element) {
-
Event.observe(element, 'click', function(event) {
-
var element = Event.element(element);
-
element.setStyle('color': '#c00');
-
});
-
},
-
-
'#otheritem li': function(element) {
-
Event.observe(element, 'click', function(event) {
-
var element = Event.element(element);
-
element.setStyle('color': '#c00');
-
});
-
}
-
};
-
Behaviour.register(rules);
Here's the equivalent in event:Selectors:
JavaScript:
-
var Rules = {
-
'#item li:click, #otheritem li:click': function(element) {
-
element.setStyle('color': '#c00');
-
}
-
};
-
-
EventSelectors.start(Rules);
Simplification makes me happy. I'm a convert.
Discuss This Article
Leave a Reply
(6082) - prototype onclick (236) - prototype click (92) - eventselectors (87) - prototype onmouseover (76) - event selectors (64) - prototype mouseover (55) - prototype observe click (49) - prototype behaviour (47) - onclick prototype (31) - prototype selector (28) - prototype selectors (27) - prototype setstyle (25) - prototype observe mouseover (20) - behaviour prototype (20) - onmouseover prototype (18) - prototype set onclick (17) - prototype onclick event (15) - prototype observe key (14) - prototype observe onmouseover (14) - event (14) - prototype event selectors (14) - javascript prototype setStyle (13) - Event.observe mouseover (13) - prototype click() (13) - mouseover prototype (13) - javascript prototype click (12) - prototype hover (12) - prototype hover event (12) - prototype onhover (11) - javascript prototype calendar (11) - event.observe click (11) - prototype click event (11) - prototype event calendar (10) - prototype observe hover (10) - Event.observe onmouseover (10) - javascript prototype onmouseover (8) - prototype calendar (7) - prototype mouseover event (7) - prototype onmouseover event (7) - prototype setStyle hover (7) - prototype element onclick (6) - prototype change onclick (6) - prototype mousemove (6) - prototype Element click (6) - prototype observe onclick (6) - prototype mouse over (6) - prototype setstyle example (6) - events prototype (6) - javascript calendar prototype (5) - prototype event.observe click (5) - prototype observe mouse (5) - prototype.onclick (5) - prototype observe (5) - javascript prototype event (5) - prototype observe mouse click (5) - prototype event selector (5) - prototype javascript onmouseover (5) - prototype observe('click (5) - prototype (5) - prototype on click (5) - javascript prototype mouseover (4) - prototype change onclick of an element (4) - event:selectors (4) - prototype event over (4) - prototype observe events (4) - set onclick with prototype (4) - click prototype (4) - prototype javascript mouseover (4) - prototype event list (4) - prototype setStyle color (4) - Event.observe onmousemove (4) - javascript prototype onmousemove (4) - prototype event.observe onclick (4) - prototype observe tutorial (4) - jquery event calendar (4) - javascript prototype selectors (4) - prototype onclick change class (4) - prototype setstyle examples (4) - prototype observe function (4) - prototype observe class (4) - prototype events list (4) - prototype color selector (4) - onclick with prototype (4) - key.observe javascript (3) - event observe key ajax (3) - EventSelectors prototype (3) - event with prototype (3) - Selector prototype (3) - prototype css selector observe (3) - prototype observe demo (3) - javascript mouse over title prototype (3) - prototype click observe (3) - setStyle javascript (3) - prototype events (3) - prototype onclick href (3) - prototype event observe onclick (3) - javascript prototype selector (3) - prototype Element color (3) - supressing an click prototype (3) - .onClick prototype (3) - onmousemove prototype (3) - prototype onclick a href (3) - prototype click a (3) - prototype .click (3) - prototype event observe click (3) - prototype Event.observe selector (3) - observe prototype click (3) - ajax prototype onclick (3) - calendar javascript prototype (3) - prototype .onClick (3) - prototype elements selectors (3) - change class of a selector in javascript (3) - prototype event mouse (3) - Event.observe class (3) - prototype observe mousemove (3) - prototype each onclick (3) - prototype setstyle class (3) - prototype class selector (3) - prototype onmouseover this (2) - observe('onmouseover (2) - prototype onmouseclick (2) - prototype calendar event (2) - javascript onmouseover prototype (2) - prototype observe click mouseover (2) - prototype observe tags (2) - prototype event observe mouse (2) - javascript prototype setstyle class (2) - prototype mouse click (2) - prototype setstyle color a (2) - Event.Observe onhover (2) - prototype tutorial setStyle (2) - click outside javascript prototype (2) - prototype javascript onhover (2) - javascript prototype click() (2) - prototype click (2) - prototype event tutorial (2) - click() prototype (2) - prototype each.observe (2) - prototype set onclick event (2) - javascript Event.observe onmouseover (2) - events prototype key (2) - click prototype javascript (2) - prototype javascript click examples (2) - Calendar EVENT PROTOTYPE (2) - prototype event mouse over (2) - onclick observe prototype (2) - behaviour in prototype (2) - .observe('click', (2) - ajax observe event click (2) -
[...] Separation of Layout and Logic with event:Selectors [...]