Last active
August 29, 2015 14:07
-
-
Save jfsiii/8a4a0a9a5ec78a72d01c to your computer and use it in GitHub Desktop.
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
goog.provide('jsaction.eventContractAuto'); | |
goog.require('jsaction.EventContract'); | |
/** | |
* Binds all events for a given JsAction container. | |
* @param {!jsaction.EventContract} contract | |
* @param {Element} container | |
* @return {boolean} True, if events were successfully bound. | |
*/ | |
function bindEventsForContainer(contract, container) { | |
console.log('bEFC', contract, container); | |
if (goog.isNull(container)) { console.log('null', container, 'bailing'); | |
return false; | |
} | |
var eventTypes = container.getAttribute('jsaction'); | |
console.log('event types', eventTypes); | |
if (!eventTypes) { | |
return false; | |
} | |
contract.addContainer(container); | |
eventTypes = eventTypes.split(';'); | |
for (var i = 0, eventType; eventType = eventTypes[i++];) { | |
console.log('add', eventType, 'to contract'); | |
contract.addEvent(eventType); | |
} | |
return true; | |
} | |
/** | |
* Creates an event contract. | |
* @param {!Object} global | |
*/ | |
function main2(global) { | |
console.log('event contract auto main') | |
var contract = new jsaction.EventContract(); | |
var container = document.querySelector('[jsaction]'); | |
var handler; | |
if (!global['jsaction']) global['jsaction'] = {}; | |
if (bindEventsForContainer(contract, container)) { | |
handler = function(dispatcher) { | |
console.log('__dispatchTo', dispatcher); | |
contract.dispatchTo(dispatcher); | |
}; | |
} else { | |
handler = goog.nullFunction; | |
} | |
global['jsaction']['__dispatchTo'] = handler; | |
} | |
// Bootstraps an event contract. | |
main2(goog.global); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment