HTML and CSS Reference
In-Depth Information
// Assign the target.paretNode to the target variable
target = target.parentNode;
* If there's a target, then process the link action
* 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!
// Get the controller, action, and params from the element
var controller = target.getAttribute('data-controller'),
action = target.getAttribute('data-action'),
params = target.getAttribute('data-params');
// Check to see whether the controller exists in the bootstrap and the
action is available
if(typeof _controller[controller] === 'undefined'
|| typeof _controller[controller][action] === 'undefined'){
// If they don't exist, throw an exception
throw "Action " + action + " for controller " + controller + "
doesn't appear to exist";
// Check to see whether the params exist
try {
// If they do, then parse them as JSON
params = JSON.parse(params);
} catch (e) {
// If there's a parsing exception, set the params to be null
params = null;
* Execute the controller within the context of the target.
* This will allow you to access the original element from
* the controller action. Also pass the parameters from the
* data-params attribute.
_controller[controller][action].call(target, params);
Search WWH ::

Custom Search