Last active
August 29, 2015 14:04
-
-
Save asabaylus/b0fea14fbcc3d368b044 to your computer and use it in GitHub Desktop.
AEM DOM Based Routing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* | |
AEM DOM BASED ROUTING SECTION | |
The data-controller attribute should point to the module defined JS controller (required) | |
The data-action attribute should reference a method of that controller, which will be passed an array of dom elements . | |
(Defaults to init) | |
The data-config object should contain a JSON object with configuration parameters (optional) | |
See http://www.paulirish.com/2009/markup-based-unobtrusive-comprehensive-dom-ready-execution/ for inspiration | |
ex: <div id="${divId}" | |
data-composer='foo' | |
data-action='doit' | |
data-config='{"height": "${height}", "width": "${width}"}'> | |
Will invoke... | |
foo.doit(); | |
On... | |
foo = { | |
init : function(){ ... }, | |
doit : function(){ ... } | |
} | |
*/ | |
var grouped = _.groupBy($('[data-controller]'), function (elem) { | |
var $elem = $(elem); | |
return $elem.data("controller") + "." + ($elem.data("action") ? $elem.data("action") : 'init'); | |
}); | |
_.forIn(grouped, function(domArray, method) { | |
if (eval('typeof ' + method) == 'function'){ | |
eval(method)(domArray); | |
}else{ | |
console.log("Could not evaluate the function call for object / method pair named " + method); | |
} | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
John Dorrance is the author, all credit goes to him 😄