/*! HTML - v0.12.1 - 2014-10-22 * http://nbubna.github.io/HTML/ * Copyright (c) 2014 ESHA Research; Licensed MIT, GPL */ (function(document, HTML) { "use strict"; var _ = HTML._, event = _.fn.event = function() { var args = _.slice.call(arguments), self = this, action, ret = []; if (!args[0]) {// first is falsy action = 'off'; args.shift(); if (typeof args[1] === "function"){ args.splice(1, 0, false); }// selector omitted } else if (!args[1] || args[1].forEach) {// second is absent or data action = 'trigger'; } else { action = 'on'; if (args[0] === 1){ args[4] = args.shift(); }// first is _once if (!args[2] || args[2].forEach) {// selector omitted args.splice(1, 0, false); args.splice(4, 1);// put _once back as fifth arg } args[3] = (args[3]||[]).slice(0);// don't let listener data change if (typeof args[2] === "string") {// third is _prop for each args[5] = args[2]; args[3].unshift(args[2]);// _prop becomes first item in data args[2] = _.fn.each;// and is replace by each() } } (args[0]||'').split(' ').forEach(function(type) { args[0] = type; self.each(function(node) { ret.push(event[action].apply(node, args)); }); }); return action === 'trigger' ? ret.length === 1 ? ret[0] : ret : this; }, concat = Array.prototype.concat; event.on = function(type, selector, fn, data, _once, _prop) { var listener = function(e) { event.heard.call(this, e, selector, fn, data, _once, _prop); }; this.addEventListener(type, listener); _.define(this, '_evt', []); this._evt.push([type, selector, _prop||fn, listener]); }; event.off = function(type, selector, fn) { if (this._evt) { for (var i=0; i