HTML and CSS Reference
In-Depth Information
app.bootstrap = (function(){
...
/**
* Add a click event listener over the entire document
* It will delegate clicks for controllers to the
* controller and action
*/
document.addEventListener("click", function(event){
var target = event.target;
/**
* Crawl up the DOM tree from the target element until
* the link surrounding the target element is found
*/
while(target.nodeName !== "A" && target.getAttribute('data-controller')
== null && target.getAttribute('data-action') == null){
// We've reached the body element break!
if(target.parentNode.nodeName == 'HTML'){
target = null;
break;
}
// Assign the target.paretNode to the target variable
target = target.parentNode;
}
});
})();
If you have a target, you now need to call the controller's action and pass the
parameters (if there are any) to it.
var app = app || {};
app.bootstrap = (function(){
...
/**
* If there's a target, then process the link action
*/
if(target){
/**
* You have the target link, so it makes sense to prevent the
* link from following through now.
* This will allow any JavaScript to fail silently!
*/
event.preventDefault();
}
 
Search WWH ::




Custom Search