Skip to content

Commit

Permalink
View change: if no selector is given a mapping defaults to the top le…
Browse files Browse the repository at this point in the history
…vel element, f.e. "@html"
  • Loading branch information
kassens committed Mar 10, 2009
1 parent badeb46 commit f809493
Showing 1 changed file with 17 additions and 11 deletions.
28 changes: 17 additions & 11 deletions Source/View.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,25 +9,31 @@ View.create = function(specification){
return new Class({
Extends: View,
initialize: function(data){
this.element = new Element('div', {html: specification.html}).getFirst();
var element = new Element('div', {html: specification.html}).getFirst();
this.element = element;

var parseMapping = function(mapping){
mapping = mapping.split('@');
return {
element: mapping[0] ? element.getElement(mapping[0]) : element,
attribute: mapping[1]
};
};

if (specification.outlets) this.outlets = Hash.map(specification.outlets, function(mappings){
return $splat(mappings).map(function(mapping){
mapping = mapping.split('@');
return {
element: this.element.getElement(mapping[0]),
attribute: mapping[1]
};
}, this);
return $splat(mappings).map(parseMapping);
}, this);

if (specification.actions) Hash.each(specification.actions, function(mappings, action){
$splat(mappings).map(function(mapping){
mapping = mapping.split('@');
this.element.getElement(mapping[0]).addEvent(mapping[1], (function(event){
mapping = parseMapping(mapping);
mapping.element.addEvent(mapping.attribute, (function(event){
this.fireEvent(action, event);
}).bind(this));
}, this);
}, this);
this.set(data);

if (data) this.set(data);
},
set: function(key, value){
if (typeof key == 'object'){
Expand Down

0 comments on commit f809493

Please sign in to comment.