vendor/assets/javascripts/emerson/view.js in emerson-0.0.2 vs vendor/assets/javascripts/emerson/view.js in emerson-0.0.3

- old
+ new

@@ -17,10 +17,11 @@ // * `ns` is a reference to the namespace. // * `init` is a hook for initializing the module. _.extend(define, { ns : ns, init : function init() { + configure(); $('body').view(); } }); @@ -64,21 +65,21 @@ // it works on the surrounding DOM match, as well as nested matches. $.fn.view = function() { _.each(this, function(e) { var keys = []; var element = $(e); - var as_view = element.add(element.find('[data-view]')).filter('[data-view]'); - var as_trait = element.add(element.find('[data-traits]')).filter('[data-traits]'); + var as_view = element.add(element.find(selectors.view)).filter(selectors.view); + var as_trait = element.add(element.find(selectors.traits)).filter(selectors.traits); _.each(as_view, function(html) { var element = $(html); - attach.apply(element, [element.data('view')]); + attach.apply(element, [element.data(attrs.view)]); }); _.each(as_trait, function(html) { var element = $(html); - attach.apply(element, _.map(element.data('traits').split(/\s+/), function(key) { + attach.apply(element, _.map(element.data(attrs.traits).split(/\s+/), function(key) { return [':', key].join(''); })); }); }); @@ -108,10 +109,18 @@ // Internal Implementation // -------------------------------------------------------------------------- + // Attr definitions. + // @private + var attrs = {}; + + // Selector definitions. + // @private + var selectors = {}; + // Storage place for the defined Views. // @private var library = {}; // Storage place for attachments made. @@ -119,9 +128,20 @@ var attachments = {}; // emerson id, for tracking attachments. // @private var _eid = 0; + + // configure + // @private + function configure() { + var config = ns.config('attrs'); + + _.extend(attrs, config); + _.each(config, function(value, key) { + selectors[key] = '[data-' + value + ']'; + }); + } // ### eid // Retrieves a unique and persistent ID for the given DOM element. // @private function eid(element) {