+1
-1
| { | ||
| "name": "kb", | ||
| "description": "A Dom Attributes Binding and Event Listener Library", | ||
| "version": "0.7.1", | ||
| "version": "0.7.2", | ||
| "main": "index", | ||
@@ -6,0 +6,0 @@ "authors": [ |
+1
-1
@@ -1,1 +0,1 @@ | ||
| var KB = (function() { var CreateKB = (function() { function CreateKB() { /* This holds global attribute listeners when tied to kb */ var _attrListeners = {}, /* This holds global attribute update listeners when tied to kb */ _attrUpdateListeners = {}, /* This holds global style listeners when tied to kb */ _styleListeners = {}, /* This holds global style update listeners when tied to kb */ _styleUpdateListeners = {}, /* This holds all injected objects, so You can see what is injected */ _injected = {}, /* The symbol to dignify what the master global listener is */ _all = '*', _texts = ['textContent', 'innerHTML', 'innerText', 'outerHTML', 'outerText', 'appendChild', 'removeChild', 'replaceChild', 'insertAdjacentHTML', 'insertBefore'], /* A master list of all style prop names */ _allStyles = Object.getOwnPropertyNames(document.body.style), _allEvents = Object.keys(HTMLElement.prototype).filter(function(v) { return (v.indexOf('on') === 0); }).concat(['addEventListener', 'removeEventListener']), /* global iterators */ x, i, /* Default set method for all listeners, loops through and runs all attached listeners */ _set = function(el, prop, val, ret, args, stopChange) { var e = new _changeEvent(el, prop, val, ret, args, undefined, 'set', stopChange); if (el.__kb !== undefined) { var localAttrListeners = el.__kb._attrListeners, localStyleListeners = el.__kb._styleListeners, localParentAttrListeners = el.__kb._parentAttrListeners, localParentStyleListeners = el.__kb._parentStyleListeners; if (localAttrListeners[prop] !== undefined) { loopListener(localAttrListeners[prop], e); } if (e._stopPropogation === undefined && localStyleListeners[prop] !== undefined) { loopListener(localStyleListeners[prop], e); } if (e._stopPropogation === undefined && localAttrListeners[_all] !== undefined) { loopListener(localAttrListeners[_all], e); if (e._stopPropogation === undefined) { loopListener(localStyleListeners[_all], e); } } if (e._stopPropogation === undefined && localParentAttrListeners[prop] !== undefined) { loopParentListener(localParentAttrListeners[prop], e); } if (e._stopPropogation === undefined && localParentStyleListeners[prop] !== undefined) { loopParentListener(localParentStyleListeners[prop], e); } if (e._stopPropogation === undefined && localParentAttrListeners[_all] !== undefined) { loopParentListener(localParentAttrListeners[_all], e); if (e._stopPropogation === undefined) { loopParentListener(localParentStyleListeners[_all], e); } } } if (e._stopPropogation === undefined && _attrListeners[prop] !== undefined) { loopListener(_attrListeners[prop], e); } if (e._stopPropogation === undefined && _styleListeners[prop] !== undefined) { loopListener(_styleListeners[prop], e); } if (e._stopPropogation === undefined && _attrListeners[_all] !== undefined) { loopListener(_attrListeners[_all], e); if (e._stopPropogation === undefined) { loopListener(_styleListeners[_all], e); } } if (e._preventDefault !== undefined) return false; return true; }, /* Default update method for all listeners, loops through and runs all attached update listeners */ _update = function(el, prop, val, ret, args, action) { var e = new _changeEvent(el, prop, val, ret, args, action, 'update'); if (el.__kb !== undefined) { var localAttrListeners = el.__kb._attrUpdateListeners, localStyleListeners = el.__kb._styleUpdateListeners, localParentAttrListeners = el.__kb._parentAttrUpdateListeners, localParentStyleListeners = el.__kb._parentStyleUpdateListeners; if (localAttrListeners[prop] !== undefined) { loopListener(localAttrListeners[prop], e); } if (e._stopPropogation === undefined && localStyleListeners[prop] !== undefined) { loopListener(localStyleListeners[prop], e); } if (e._stopPropogation === undefined && localAttrListeners[_all] !== undefined) { loopListener(localAttrListeners[_all], e); if (e._stopPropogation === undefined) { loopListener(localStyleListeners[_all], e); } } if (e._stopPropogation === undefined && localParentAttrListeners[prop] !== undefined) { loopParentListener(localParentAttrListeners[prop], e); } if (e._stopPropogation === undefined && localParentStyleListeners[prop] !== undefined) { loopParentListener(localParentStyleListeners[prop], e); } if (e._stopPropogation === undefined && localParentAttrListeners[_all] !== undefined) { loopParentListener(localParentAttrListeners[_all], e); if (e._stopPropogation === undefined) { loopParentListener(localParentStyleListeners[_all], e); } } } if (e._stopPropogation === undefined && _attrUpdateListeners[prop] !== undefined) { loopListener(_attrUpdateListeners[prop], e); } if (e._stopPropogation === undefined && _styleUpdateListeners[prop] !== undefined) { loopListener(_styleUpdateListeners[prop], e); } if (e._stopPropogation === undefined && _attrUpdateListeners[_all] !== undefined) { loopListener(_attrUpdateListeners[_all], e); if (e._stopPropogation === undefined) { loopListener(_styleUpdateListeners[_all], e); } } if (e._preventDefault !== undefined) return false; return true; } /* Helper method to loop through listeners and run them */ function loopListener(looper, e) { var _looper = looper, _len = looper.length, _e = e, _x; for (_x = 0; _x < _len; _x++) { looper[_x](_e); if (_e._stopPropogation !== undefined) break; } } /* Helper method to loop through all parent listeners and run them */ function loopParentListener(looper, e) { var _looper = looper, _len = looper.length, _e = e, _x; for (_x = 0; _x < _len; _x++) { _e.child = _e.target; _e.target = looper[_x].parent; looper[_x].func(_e); if (_e._stopPropogation !== undefined) break; } } /* Helper method to loop through all listeners and return if a method exists */ function loopListenerCheck(looper, func) { var _looper = looper, _len = looper.length, _func = func, _x; for (_x = 0; _x < _len; x++) { if (_looper[x].toString() === _func.toString()) return true; } return false; } /* The event object that gets passed to each listener */ function _changeEvent(el, attr, value, oldValue, args, action, type, stopChange) { this.stopPropagation = function() { this._stopPropogation = true; }; this.preventDefault = function() { this._preventDefault = true; }; this.value = value; this.oldValue = oldValue; this.target = el; this.attr = attr; this.arguments = args; this.action = action; this.child = undefined; this.type = type; this.stopChange = stopChange; } /* This holds all listeners associated with a particular element */ function _localBinders() { this._attrListeners = {}; this._attrUpdateListeners = {}; this._styleListeners = {}; this._styleUpdateListeners = {}; this._parentStyleListeners = {}; this._parentStyleUpdateListeners = {}; this._parentAttrListeners = {}; this._parentAttrUpdateListeners = {}; this._injectedStyle = {}; } /* This is a standard property set overwrite */ function setStandard(descriptor, key, set, update) { var _descriptor = descriptor, _descGet = _descriptor.get, _descSet = _descriptor.set, _key = key, _set = set, _update = update, _oldValue; return function standardSet(v) { _oldValue = _descGet.call(this); if (_set(this, _key, v, _oldValue, undefined, this._stopChange)) { _descSet.call(this, v); } if (!this._stopChange) { _update(this, _key, v, _oldValue); } this._stopChange = undefined; } } /* This is a standard value set overwrite */ function setValue(descriptor, key, set, update) { var _descriptor = descriptor, _key = key, _set = set, _update = update, _oldValue; return function valueSet(v) { _oldValue = _descriptor.value; if (_set(this, _key, v, _oldValue, arguments, this._stopChange)) { _descriptor.value = v; } if (!this._stopChange) { _update(this, _key, v, _oldValue, arguments); } this._stopChange = undefined; } } /* This is a standard function overwrite */ function setFunction(descriptor, key, set, update) { var _descriptor = descriptor, _descVal = _descriptor.value, _key = key, _set = set, _update = update, _action; return function functionSet() { if (_set(this, _key, null, null, arguments, this._stopChange)) { _action = _descVal.apply(this, arguments); } if (!this._stopChange) { _update(this, _key, null, null, arguments, _action); } this._stopChange = undefined; return _action; } } /* This overwites a style property */ function setStyle(descriptor, key, set, update, el) { var _proto = el.style, _descriptor = descriptor, _key = key, _keyCP = key.replace(/([A-Z])/g, "-$1").replace('webkit', '-webkit'), _set = set, _update = update, _el = el, _oldValue, _value; return { get: function() { return _value; }, set: function styleSet(v) { _oldValue = _value; if (_set(_el, _key, v, _oldValue, undefined, this._stopChange)) { _value = v; _proto.setProperty(_keyCP, v); } if (!this._stopChange) { _update(_el, _key, v, _oldValue); } this._stopChange = undefined; }, enumerable: true, configurable: true } } /* A helper method that is run for all addListener methods */ function addListener(attr, func, child, update) { if (typeof func !== 'function') return bind; var isInput = (['value', 'checked'].indexOf(attr) !== -1), isStyle = (_allStyles.indexOf(attr) !== -1), listeners; if (this.toString() !== bind.toString()) { if (child) { var children = this.querySelectorAll('*'), len = children.length, listenerObj; for (var x = 0; x < len; x++) { listenerObj = children[x].attrListeners(); if (isInput || (attr === _all)) { if (children[x].addInputBinding !== undefined) children[x].addInputBinding(); if (children[x].addInputBoxBinding !== undefined) children[x].addInputBoxBinding(); } if (isStyle) { bind.injectStyleProperty(children[x], attr); listeners = (update ? '_parentStyleUpdateListeners' : '_parentStyleListeners'); if (listenerObj[listeners][attr] === undefined) listenerObj[listeners][attr] = []; listenerObj[listeners][attr].push({ parent: this, func: func }); } else { if (attr === _all) { listeners = (update ? '_parentStyleUpdateListeners' : '_parentStyleListeners'); var len = _allStyles.length; for (var i = 0; i < len; i++) { bind.injectStyleProperty(children[x], _allStyles[i]); } if (listenerObj[listeners][_all] === undefined) listenerObj[listeners][_all] = []; listenerObj[listeners][_all].push({ parent: this, func: func }); } listeners = (update ? '_parentAttrUpdateListeners' : '_parentAttrListeners'); if (listenerObj[listeners][attr] === undefined) listenerObj[listeners][attr] = []; listenerObj[listeners][attr].push({ parent: this, func: func }); } } } else { listenerObj = this.attrListeners(); if (isStyle) { listeners = (update ? '_styleUpdateListeners' : '_styleListeners'); bind.injectStyleProperty(this, attr); if (listenerObj[listeners][attr] === undefined) listenerObj[listeners][attr] = []; listenerObj[listeners][attr].push(func); } else { if (isInput || (attr === _all)) { if (this.addInputBinding !== undefined) this.addInputBinding(); if (this.addInputBoxBinding !== undefined) this.addInputBoxBinding(); } if (attr === _all) { listeners = (update ? '_styleUpdateListeners' : '_styleListeners'); var len = _allStyles.length; for (var x = 0; x < len; x++) { bind.injectStyleProperty(this, _allStyles[x]); } if (listenerObj[listeners][attr] === undefined) listenerObj[listeners][attr] = []; listenerObj[listeners][attr].push(func); } listeners = (update ? '_attrUpdateListeners' : '_attrListeners'); if (listenerObj[listeners][attr] === undefined) listenerObj[listeners][attr] = []; listenerObj[listeners][attr].push(func); } } } else { if (isInput || (attr === _all)) { var inputs = document.querySelectorAll('input, textarea'), len = inputs.length; for (var x = 0; x < len; x++) { if (inputs[x].addInputBinding !== undefined) inputs[x].addInputBinding(); if (inputs[x].addInputBoxBinding !== undefined) inputs[x].addInputBoxBinding(); } } if (isStyle) { var els = Array.prototype.slice.call(document.body.querySelectorAll('*')), len = (els.length + 1); els.unshift(document.body); for (var x = 0; x < len; x++) { bind.injectStyleProperty(els[x], attr); } listeners = (update ? _styleUpdateListeners : _styleListeners); if (listeners[attr] === undefined) listeners[attr] = []; listeners[attr].push(func); } else { if (attr === _all) { var els = Array.prototype.slice.call(document.body.querySelectorAll('*')), len = (els.length + 1), lenStyles = _allStyles.length; els.unshift(document.body); for (var x = 0; x < len; x++) { for (var i = 0; i < lenStyles; i++) { bind.injectStyleProperty(els[x], _allStyles[i]); } } listeners = (update ? _styleUpdateListeners : _styleListeners); if (listeners[attr] === undefined) listeners[attr] = []; listeners[attr].push(func); } listeners = (update ? _attrUpdateListeners : _attrListeners); if (listeners[attr] === undefined) listeners[attr] = []; listeners[attr].push(func); } } } /* A helper method that is ran for all removeListener methods */ function removeListener(attr, func, child, update) { if (typeof func !== 'function') return bind; var isInput = (['value', 'checked'].indexOf(attr) !== -1), isStyle = (_allStyles.indexOf(attr) !== -1), listeners, x; function cut(attr, list) { var listenerFuncs = list[attr], len = listenerFuncs.length; for (x = 0; x < len; x++) { if (listenerFuncs[x].toString() === func.toString()) { listenerFuncs.splice(x, 1); } } } if (this.toString() !== bind.toString()) { if (child) { var children = this.querySelectorAll('*'), len = children.length; if (isStyle) { listeners = (update ? '_childStyleUpdateListeners' : '_childStyleListeners'); cut(attr, this.attrListeners()[listeners]); listeners = (update ? '_parentStyleUpdateListeners' : '_parentStyleListeners'); } else { if (attr === _all) { listeners = (update ? '_childStyleUpdateListeners' : '_childStyleListeners'); cut(attr, this.attrListeners()[listeners]); } listeners = (update ? '_childAttrUpdateListeners' : '_childAttrListeners'); cut(attr, this.attrListeners()[listeners]); listeners = (update ? '_parentAttrUpdateListeners' : '_parentAttrListeners'); } for (x = 0; x < len; x++) { var parents = children[x].attrListeners()[listeners][attr], parentLen = parents.length; for (var i = 0; i < parentLen; i++) { if (parents[i].isEqualNode(this)) { parents.slice(i, 1); } } if (attr === _all) { listenersStyle = (update ? '_parentStyleUpdateListeners' : '_parentStyleListeners'); var parents = children[x].attrListeners()[listeners][attr], parentLen = parents.length; for (var i = 0; i < parentLen; i++) { if (parents[i].isEqualNode(this)) { parents.slice(i, 1); } } } } } else { if (isStyle) { listeners = (update ? '_styleUpdateListeners' : '_styleListeners'); cut(attr, this.attrListeners()[listeners]); } else { if (attr === _all) { listeners = (update ? '_styleUpdateListeners' : '_styleListeners'); cut(attr, this.attrListeners()[listeners]); } listeners = (update ? '_attrUpdateListeners' : '_attrListeners'); cut(attr, this.attrListeners()[listeners]); } } } else { if (isStyle) { listeners = (update ? _styleUpdateListeners : _styleListeners); cut(attr, listeners); } else { if (attr === _all) { listeners = (update ? _styleUpdateListeners : _styleListeners); cut(attr, listeners); } listeners = (update ? _attrUpdateListeners : _attrListeners); cut(attr, listeners); } } } /* this method gets attached to all elements for easy listener adding of child events */ function addChildAttrListener(attr, func) { bind.addAttrListener.call(this, attr, func, true); return this; } /* this method gets attached to all elements for easy listener adding of child update events */ function addChildAttrUpdateListener(attr, func) { bind.addAttrUpdateListener.call(this, attr, func, true); return this; } /* this method gets attached to all elements for easy listener removal of child events */ function removeChildAttrListener(attr, func) { bind.removeAttrListener.call(this, attr, func, true); return this; } /* this method gets attached to all elements for easy listener removal of child update events */ function removeChildAttrUpdateListener(attr, func) { bind.removeAttrUpdateListener.call(this, attr, func, true); return this; } /* This method checks if a listener of this function already exists on a desired attribute */ function hasListener(listener, attr, func) { var _listeners = this.attrListeners(); if (attr === 'html') attr = 'innerHTML'; if (attr === 'events') attr = 'onclick'; switch (listener) { case 'attr': if (typeof _listeners._attrListeners[attr] !== undefined) { if (loopListenerCheck(_listeners._attrListeners[attr], func)) return true; } else if (typeof _listeners._styleListeners[attr] !== undefined) { if (loopListenerCheck(_listeners._styleListeners[attr], func)) return true; } else if (typeof _listeners._parentAttrListeners[attr] !== undefined) { if (loopListenerCheck(_listeners._parentAttrListeners[attr], func)) return true; } else if (typeof _listeners._parentStyleListeners[attr] !== undefined) { if (loopListenerCheck(_listeners._parentStyleListeners[attr], func)) return true; } break; case 'attrupdate': if (typeof _listeners._attrUpdateListeners[attr] !== undefined) { if (loopListenerCheck(_listeners._attrUpdateListeners[attr], func)) return true; } else if (typeof _listeners._styleUpdateListeners[attr] !== undefined) { if (loopListenerCheck(_listeners._styleUpdateListeners[attr], func)) return true; } else if (typeof _listeners._parentAttrUpdateListeners[attr] !== undefined) { if (loopListenerCheck(_listeners._parentAttrUpdateListeners[attr], func)) return true; } else if (typeof _listeners._parentStyleUpdateListeners[attr] !== undefined) { if (loopListenerCheck(_listeners._parentStyleUpdateListeners[attr], func)) return true; } break; } return false; } /* sets stopChange Property for stopping update listeners to fire */ function stopChange() { this._stopChange = true; return this; } /* This is the master constructor, to be ran only once. */ function bind() { bind.injectPrototypes(Node, 'Node'); bind.injectPrototypes(Element, 'Element'); bind.injectPrototypes(HTMLElement, 'HTMLElement'); bind.injectPrototypes(HTMLInputElement, 'HTMLInputElement'); bind.injectPrototypes(HTMLTextAreaElement, 'HTMLTextAreaElement'); bind.injectPrototypes(Document, 'Document'); var __set = _set, __update = _update; function hasInput(attrListeners) { var attrs = ['value', 'checked'], _localListeners = attrListeners, _localAttr = _localListeners._attrListeners, _localUpdateAttr = _localListeners._attrUpdateListeners, _localParentAttr = _localListeners._parentAttrListeners, _localParentUpdateAttr = _localListeners._parentAttrUpdateListeners, has = false; if (_attrListeners[_all] !== undefined || _attrUpdateListeners[_all] !== undefined) { has = true; } if (has !== true && _localAttr[_all] !== undefined || _localUpdateAttr[_all] !== undefined || _localParentAttr[_all] !== undefined || _localParentUpdateAttr[_all] !== undefined) { has = true; } if (has !== true) { for (var x = 0; x < attrs.length; x++) { if (_attrListeners[attrs[x]] !== undefined || _attrUpdateListeners[attrs[x]] !== undefined || _localAttr[attrs[x]] !== undefined || _localUpdateAttr[attrs[x]] !== undefined || _localParentAttr[attrs[x]] !== undefined || _localParentUpdateAttr[attrs[x]] !== undefined) { has = true; break; } } } return has; } function getStyles(arr, styles) { var x, _arr = arr, _styles = styles, len = styles.length; for (x = 0; x < len; x++) { if (_arr.indexOf(_styles[x]) === -1) { _arr.push(_styles[x]); } } return _arr; } function hasStyle(attrListeners) { var _globalStyle = Object.keys(_styleListeners), _globalStyleUpdate = Object.keys(_styleUpdateListeners), _localListeners = attrListeners, _localStyle = Object.keys(_localListeners._styleListeners), _localUpdateStyle = Object.keys(_localListeners._styleUpdateListeners), _localParentStyle = Object.keys(_localListeners._parentStyleListeners), _localParentUpdateStyle = Object.keys(_localListeners._parentStyleUpdateListeners), has = []; if (_globalStyle.length !== 0 || _globalStyleUpdate.length !== 0) { has = getStyles(has, _globalStyle); has = getStyles(has, _globalStyleUpdate); } if (has.length !== 0 && _localParentStyle.length !== 0 || _localParentUpdateStyle.length !== 0) { has = getStyles(has, _localParentStyle); has = getStyles(has, _localParentUpdateStyle); } if (has.indexOf(_all) !== -1) has = _allStyles; return has; } function reSync(e) { if (e.target.nodeType !== 3 && e.target.nodeType !== 8) { var attrListeners = e.target.attrListeners(), _hasInput = hasInput(attrListeners), _hasStyle = hasStyle(attrListeners), _hasStyleLen = _hasStyle.length, _parentAttr, _parentAttrUpdate, _parentStyle, _parentStyleUpdate, _listeners, nodes = [], len, outer = ((e.attr === 'outerHTML' || e.attr === 'outerText') ? e.attr : undefined), target = e.target if (outer !== undefined) { e.attr = 'appendChild', e.arguments = [e.target]; e.target = e.target.parentElement; } if (_hasInput) { if (e.attr === 'appendChild' && e.arguments[0].nodeType !== 3 && e.arguments[0].nodeType !== 8) { nodes = Array.prototype.slice.call(e.arguments[0].querySelectorAll('input,textarea')); if (e.arguments[0].tagName === 'INPUT' || e.arguments[0].tagName === 'TEXTAREA') { nodes.unshift(e.arguments[0]) } } else { nodes = Array.prototype.slice.call(e.target.querySelectorAll('input,textarea')); } len = nodes.length; for (var x = 0; x < len; x++) { if (nodes[x].addInputBinding !== undefined) nodes[x].addInputBinding(); if (nodes[x].addInputBoxBinding !== undefined) nodes[x].addInputBoxBinding(); } } if (e.attr === 'appendChild' && e.arguments[0].nodeName !== '#text' && e.arguments[0].nodeName !== '#comment') { nodes = Array.prototype.slice.call(e.arguments[0].querySelectorAll('*')); nodes.unshift(e.arguments[0]); _parentAttr = e.target.__kb._parentAttrListeners; _parentAttrUpdate = e.target.__kb._parentAttrUpdateListeners; _parentStyle = e.target.__kb._parentStyleListeners; _parentStyleUpdate = e.target.__kb._parentStyleUpdateListeners; } else { nodes = Array.prototype.slice.call(e.target.querySelectorAll('*')); _parentAttr = e.target.__kb._parentAttrListeners; _parentAttrUpdate = e.target.__kb._parentAttrUpdateListeners; _parentStyle = e.target.__kb._parentStyleListeners; _parentStyleUpdate = e.target.__kb._parentStyleUpdateListeners; } len = nodes.length; for (var x = 0; x < len; x++) { if (_hasStyleLen !== 0) { for (var i = 0; i < _hasStyleLen; i++) { bind.injectStyleProperty(nodes[x], _hasStyle[i]); } } _listeners = nodes[x].attrListeners(); _listeners._parentAttrListeners = _parentAttr; _listeners._parentAttrUpdateListeners = _parentAttrUpdate; _listeners._parentStyleListeners = _parentStyle; _listeners._parentStyleUpdateListeners = _parentStyleUpdate; } if (outer !== undefined) { e.attr = outer; e.target = target; e.arguments = []; } } } function checkAttr(e) { var oldAttr = e.target.attributes[e.arguments[0]], old = (oldAttr !== undefined ? oldAttr.value : ""), val = (e.attr === 'setAttribute' ? e.arguments[1] : ""); if (!__set(e.target, e.arguments[0], val, old, [val])) { e.preventDefault(); } } function checkAttrUpdate(e) { var oldAttr = e.target.attributes[e.arguments[0]], old = (oldAttr !== undefined ? oldAttr.value : ""), val = (e.attr === 'setAttribute' ? e.arguments[1] : ""); __update(e.target, e.arguments[0], val, old, [val]); } //for keeping binds with inputs bind.addAttrUpdateListener('appendChild', reSync); bind.addAttrUpdateListener('removeChild', reSync); bind.addAttrUpdateListener('innerHTML', reSync); bind.addAttrUpdateListener('outerHTML', reSync); bind.addAttrUpdateListener('innerText', reSync); bind.addAttrUpdateListener('outerText', reSync); bind.addAttrUpdateListener('textContent', reSync); //allows for html attribute changes to be listened to just like properties bind.addAttrListener('setAttribute', checkAttr); bind.addAttrListener('removeAttribute', checkAttr); bind.addAttrUpdateListener('setAttribute', checkAttrUpdate); bind.addAttrUpdateListener('removeAttribute', checkAttrUpdate); return bind; } bind.injectPrototypeProperty = function(obj, key, injectName, set, update) { var _proto = obj.prototype, _descriptor = Object.getOwnPropertyDescriptor(_proto, key), _injectName = (injectName || obj.toString().split(/\s+/)[1].split('{')[0].replace('()', '')), _injectedObj = _injected[_injectName], __set = (set || _set), __update = (update || _update); if (_proto.attrListeners === undefined) { _proto = {}; _proto.attrListeners = (function() { if (this.__kb === undefined) { this.__kb = new _localBinders(); } return this.__kb; }).bind(_proto); _proto.addAttrListener = bind.addAttrListener; _proto.addAttrUpdateListener = bind.addAttrUpdateListener; _proto.addChildAttrListener = addChildAttrListener; _proto.addChildAttrUpdateListener = addChildAttrUpdateListener; _proto.hasListener = hasListener; _proto.removeAttrListener = bind.removeAttrListener; _proto.removeAttrUpdateListener = bind.removeAttrUpdateListener; _proto.removeChildAttrListener = removeChildAttrListener; _proto.removeChildAttrUpdateListener = removeChildAttrUpdateListener; _proto.stopChange = stopChange; } if (_injectedObj === undefined) { _injected[_injectName] = { obj: obj, proto: _proto, descriptors: {}, set: undefined, update: undefined }; _injectedObj = _injected[_injectName]; _injectedObj.set = __set; _injectedObj.update = __update; } if (_injectedObj.descriptors[key] === undefined) _injectedObj.descriptors[key] = _descriptor; if (_descriptor.configurable) { if (_descriptor.set !== undefined) { Object.defineProperty(_proto, key, { get: _descriptor.get, set: setStandard(_descriptor, key, __set, __update), enumerable: true, configurable: true }); } else if (typeof _descriptor.value === 'function') { Object.defineProperty(_proto, key, { value: setFunction(_descriptor, key, __set, __update), writable: true, enumerable: true, configurable: true }); } else if (_descriptor.value !== undefined) { Object.defineProperty(_proto, key, { get: function() { return _descriptor.value; }, set: setValue(_descriptor, key, __set, __update), enumerable: true, configurable: true }); } } return bind; } bind.injectStyleProperty = function(el, key, set, update) { var _proto = el.style, _descriptor = Object.getOwnPropertyDescriptor(_proto, key), _injectedObj = el.attrListeners().injectedStyle, __set = (set || _set), __update = (update || _update); if (_injectedObj === undefined) { el.attrListeners().injectedStyle = { obj: el, proto: _proto, descriptors: {}, set: undefined, update: undefined }; el.attrListeners().injectedStyle.set = __set; el.attrListeners().injectedStyle.update = __update; _injectedObj = el.attrListeners().injectedStyle; } if (_injectedObj.descriptors[key] === undefined) _injectedObj.descriptors[key] = _descriptor; if (_descriptor.configurable) { Object.defineProperty(_proto, key, setStyle(_descriptor, key, __set, __update, el)); } return bind; } bind.injectPrototypes = function(obj, injectName, set, update) { var _proto = obj.prototype, _injectName = (injectName || obj.toString().split(/\s+/)[1].split('{')[0].replace('()', '')), _injectedObj = _injected[_injectName], _keys = Object.getOwnPropertyNames(_proto), __set = (set || _set), __update = (update || _update), _descriptors, x; if (_proto.attrListeners === undefined) { _proto.attrListeners = function() { if (this.__kb === undefined) { this.__kb = new _localBinders(); } return this.__kb; } _proto.addAttrListener = bind.addAttrListener; _proto.addAttrUpdateListener = bind.addAttrUpdateListener; _proto.addChildAttrListener = addChildAttrListener; _proto.addChildAttrUpdateListener = addChildAttrUpdateListener; _proto.hasListener = hasListener; _proto.stopChange = stopChange; } if (_injectedObj === undefined) { _injected[_injectName] = { obj: obj, proto: _proto, descriptors: {}, set: undefined, update: undefined }; _injectedObj = _injected[_injectName]; _injectedObj.set = __set; _injectedObj.update = __update; } _descriptors = _injected[_injectName].descriptors; for (x = 0; x < _keys.length; x += 1) { if (_descriptors[_keys[x]] === undefined) { bind.injectPrototypeProperty(obj, _keys[x], _injectName, __set, _update); } } if (_keys.indexOf('value') !== -1) { function keyDown(e) { var isCheck, oldCheck, oldValue, value; if (this.type === 'checkbox' || this.type === 'radio') { oldCheck = this.checked; isCheck = true; } oldValue = (isCheck ? (typeof this.checked === 'string' ? this.checked : (this.checked ? "true" : "false")) : this.value); setTimeout((function() { value = (isCheck ? (typeof this.checked === 'string' ? this.checked : (this.checked ? "true" : "false")) : this.value); if (isCheck) { if (!_injectedObj.set(this, 'checked', this.checked, oldValue)) { _descriptors['checked'].set.call(this, oldValue); } else { _injectedObj.update(this, 'checked', this.checked, oldValue); } } this.value = value; if (!_injectedObj.set(this, 'value', this.value, oldValue)) { _descriptors['value'].set.call(this, oldValue); } else { _injectedObj.update(this, 'value', this.checked, oldValue); } }).bind(this), 0); } _proto.removeInputBinding = function() { this.attrListeners()._onkeydown = undefined; this.removeEventListener('keydown', keyDown); } _proto.addInputBinding = function() { this.attrListeners()._onkeydown = true; this.addEventListener('keydown', keyDown); } _proto.removeInputBoxBinding = function() { this.attrListeners()._onmousedown = undefined; this.removeEventListener('mouseup', keyDown); } _proto.addInputBoxBinding = function() { this.attrListeners()._onmousedown = true; this.addEventListener('mouseup', keyDown); } } return bind; } bind.addAttrListener = function(attr, func, child) { if (attr === 'html') { for (var x = 0, len = _texts.length; x < len; x++) { addListener.call(this, _texts[x], func, child, false); } } else if (attr === 'events') { for (var x = 0, len = _allEvents.length; x < len; x++) { addListener.call(this, _allEvents[x], func, child, false); } } else { addListener.call(this, attr, func, child, false); } return bind; } bind.addAttrUpdateListener = function(attr, func, child) { if (attr === 'html') { for (var x = 0, len = _texts.length; x < len; x++) { addListener.call(this, _texts[x], func, child, true); } } else if (attr === 'events') { for (var x = 0, len = _allEvents.length; x < len; x++) { addListener.call(this, _allEvents[x], func, child, true); } } else { addListener.call(this, attr, func, child, true); } return bind; } bind.removeAttrListener = function(attr, func, child) { if (attr === 'html') { for (var x = 0, len = _texts.length; x < len; x++) { removeListener.call(this, _texts[x], func, child, false); } } else if (attr === 'events') { for (var x = 0, len = _allEvents.length; x < len; x++) { removeListener.call(this, _allEvents[x], func, child, false); } } else { removeListener.call(this, attr, func, child, false); } return bind; } bind.removeAttrUpdateListener = function(attr, func, child) { if (attr === 'html') { for (var x = 0, len = _texts.length; x < len; x++) { removeListener.call(this, _texts[x], func, child, true); } } else if (attr === 'events') { for (var x = 0, len = _allEvents.length; x < len; x++) { removeListener.call(this, _allEvents[x], func, child, true); } } else { removeListener.call(this, attr, func, child, true); } return bind; } bind.hasListener = function(listener, attr, func) { if (attr === 'html') attr = 'innerHTML'; if (attr === 'events') attr = 'onclick'; switch (listener) { case 'attr': if (typeof _attrListeners[attr] !== undefined) { if (loopListenerCheck(_attrListeners[attr], func)) return true; } else if (typeof _styleListeners[attr] !== undefined) { if (loopListenerCheck(_styleListeners[attr], func)) return true; } break; case 'attrupdate': if (typeof _attrUpdateListeners[attr] !== undefined) { if (loopListenerCheck(_attrUpdateListeners[attr], func)) return true; } else if (typeof _styleUpdateListeners[attr] !== undefined) { if (loopListenerCheck(_styleUpdateListeners[attr], func)) return true; } break; } return false; } bind.injectedPrototypes = function() { return _injected; } return bind; } if (typeof define === "function" && define.amd) { define('KB', CreateKB); //global KM define in browser } return CreateKB; }()) if (window.define && window.require) { define([], function() { return CreateKB; }); } else if (window.module) { module.exports = CreateKB; } return CreateKB; }()) | ||
| var KB = (function() { var CreateKB = (function() { function CreateKB() { /* This holds global attribute listeners when tied to kb */ var _attrListeners = {}, /* This holds global attribute update listeners when tied to kb */ _attrUpdateListeners = {}, /* This holds global style listeners when tied to kb */ _styleListeners = {}, /* This holds global style update listeners when tied to kb */ _styleUpdateListeners = {}, /* This holds all injected objects, so You can see what is injected */ _injected = {}, /* The symbol to dignify what the master global listener is */ _all = '*', _texts = ['textContent', 'innerHTML', 'innerText', 'outerHTML', 'outerText', 'appendChild', 'removeChild', 'replaceChild', 'insertAdjacentHTML', 'insertBefore'], /* A master list of all style prop names */ _allStyles = Object.getOwnPropertyNames(document.body.style), _allEvents = Object.keys(HTMLElement.prototype).filter(function(v) { return (v.indexOf('on') === 0); }).concat(['addEventListener', 'removeEventListener']), /* global iterators */ x, i, /* Default set method for all listeners, loops through and runs all attached listeners */ _set = function(el, prop, val, ret, args, stopChange) { var e = new _changeEvent(el, prop, val, ret, args, undefined, 'set', stopChange); if (el.__kb !== undefined) { var localAttrListeners = el.__kb._attrListeners, localStyleListeners = el.__kb._styleListeners, localParentAttrListeners = el.__kb._parentAttrListeners, localParentStyleListeners = el.__kb._parentStyleListeners; if (localAttrListeners[prop] !== undefined) { loopListener(localAttrListeners[prop], e); } if (e._stopPropogation === undefined && localStyleListeners[prop] !== undefined) { loopListener(localStyleListeners[prop], e); } if (e._stopPropogation === undefined && localAttrListeners[_all] !== undefined) { loopListener(localAttrListeners[_all], e); if (e._stopPropogation === undefined) { loopListener(localStyleListeners[_all], e); } } if (e._stopPropogation === undefined && localParentAttrListeners[prop] !== undefined) { loopParentListener(localParentAttrListeners[prop], e); } if (e._stopPropogation === undefined && localParentStyleListeners[prop] !== undefined) { loopParentListener(localParentStyleListeners[prop], e); } if (e._stopPropogation === undefined && localParentAttrListeners[_all] !== undefined) { loopParentListener(localParentAttrListeners[_all], e); if (e._stopPropogation === undefined) { loopParentListener(localParentStyleListeners[_all], e); } } } if (e._stopPropogation === undefined && _attrListeners[prop] !== undefined) { loopListener(_attrListeners[prop], e); } if (e._stopPropogation === undefined && _styleListeners[prop] !== undefined) { loopListener(_styleListeners[prop], e); } if (e._stopPropogation === undefined && _attrListeners[_all] !== undefined) { loopListener(_attrListeners[_all], e); if (e._stopPropogation === undefined) { loopListener(_styleListeners[_all], e); } } if (e._preventDefault !== undefined) return false; return true; }, /* Default update method for all listeners, loops through and runs all attached update listeners */ _update = function(el, prop, val, ret, args, action) { var e = new _changeEvent(el, prop, val, ret, args, action, 'update'); if (el.__kb !== undefined) { var localAttrListeners = el.__kb._attrUpdateListeners, localStyleListeners = el.__kb._styleUpdateListeners, localParentAttrListeners = el.__kb._parentAttrUpdateListeners, localParentStyleListeners = el.__kb._parentStyleUpdateListeners; if (localAttrListeners[prop] !== undefined) { loopListener(localAttrListeners[prop], e); } if (e._stopPropogation === undefined && localStyleListeners[prop] !== undefined) { loopListener(localStyleListeners[prop], e); } if (e._stopPropogation === undefined && localAttrListeners[_all] !== undefined) { loopListener(localAttrListeners[_all], e); if (e._stopPropogation === undefined) { loopListener(localStyleListeners[_all], e); } } if (e._stopPropogation === undefined && localParentAttrListeners[prop] !== undefined) { loopParentListener(localParentAttrListeners[prop], e); } if (e._stopPropogation === undefined && localParentStyleListeners[prop] !== undefined) { loopParentListener(localParentStyleListeners[prop], e); } if (e._stopPropogation === undefined && localParentAttrListeners[_all] !== undefined) { loopParentListener(localParentAttrListeners[_all], e); if (e._stopPropogation === undefined) { loopParentListener(localParentStyleListeners[_all], e); } } } if (e._stopPropogation === undefined && _attrUpdateListeners[prop] !== undefined) { loopListener(_attrUpdateListeners[prop], e); } if (e._stopPropogation === undefined && _styleUpdateListeners[prop] !== undefined) { loopListener(_styleUpdateListeners[prop], e); } if (e._stopPropogation === undefined && _attrUpdateListeners[_all] !== undefined) { loopListener(_attrUpdateListeners[_all], e); if (e._stopPropogation === undefined) { loopListener(_styleUpdateListeners[_all], e); } } if (e._preventDefault !== undefined) return false; return true; } /* Helper method to loop through listeners and run them */ function loopListener(looper, e) { var _looper = looper, _len = looper.length, _e = e, _x; for (_x = 0; _x < _len; _x++) { looper[_x](_e); if (_e._stopPropogation !== undefined) break; } } /* Helper method to loop through all parent listeners and run them */ function loopParentListener(looper, e) { var _looper = looper, _len = looper.length, _e = e, _x; for (_x = 0; _x < _len; _x++) { _e.child = _e.target; _e.target = looper[_x].parent; looper[_x].func(_e); if (_e._stopPropogation !== undefined) break; } } /* Helper method to loop through all listeners and return if a method exists */ function loopListenerCheck(looper, func) { var _looper = looper, _len = looper.length, _func = func, _x; for (_x = 0; _x < _len; x++) { if (_looper[x].toString() === _func.toString()) return true; } return false; } /* The event object that gets passed to each listener */ function _changeEvent(el, attr, value, oldValue, args, action, type, stopChange) { this.stopPropagation = function() { this._stopPropogation = true; }; this.preventDefault = function() { this._preventDefault = true; }; this.value = value; this.oldValue = oldValue; this.target = el; this.attr = attr; this.arguments = args; this.action = action; this.child = undefined; this.type = type; this.stopChange = stopChange; } /* This holds all listeners associated with a particular element */ function _localBinders() { this._attrListeners = {}; this._attrUpdateListeners = {}; this._styleListeners = {}; this._styleUpdateListeners = {}; this._parentStyleListeners = {}; this._parentStyleUpdateListeners = {}; this._parentAttrListeners = {}; this._parentAttrUpdateListeners = {}; this._injectedStyle = {}; } /* This is a standard property set overwrite */ function setStandard(descriptor, key, set, update) { var _descriptor = descriptor, _descGet = _descriptor.get, _descSet = _descriptor.set, _key = key, _set = set, _update = update, _oldValue; return function standardSet(v) { _oldValue = _descGet.call(this); if (_set(this, _key, v, _oldValue, undefined, this._stopChange)) { _descSet.call(this, v); } if (!this._stopChange) { _update(this, _key, v, _oldValue); } this._stopChange = undefined; } } /* This is a standard value set overwrite */ function setValue(descriptor, key, set, update) { var _descriptor = descriptor, _key = key, _set = set, _update = update, _oldValue; return function valueSet(v) { _oldValue = _descriptor.value; if (_set(this, _key, v, _oldValue, arguments, this._stopChange)) { _descriptor.value = v; } if (!this._stopChange) { _update(this, _key, v, _oldValue, arguments); } this._stopChange = undefined; } } /* This is a standard function overwrite */ function setFunction(descriptor, key, set, update) { var _descriptor = descriptor, _descVal = _descriptor.value, _key = key, _set = set, _update = update, _action; return function functionSet() { if (_set(this, _key, null, null, arguments, this._stopChange)) { _action = _descVal.apply(this, arguments); } if (!this._stopChange) { _update(this, _key, null, null, arguments, _action); } this._stopChange = undefined; return _action; } } /* This overwites a style property */ function setStyle(descriptor, key, set, update, el) { var _proto = el.style, _descriptor = descriptor, _key = key, _keyCP = key.replace(/([A-Z])/g, "-$1").replace('webkit', '-webkit'), _set = set, _update = update, _el = el, _oldValue, _value; return { get: function() { return _value; }, set: function styleSet(v) { _oldValue = _value; if (_set(_el, _key, v, _oldValue, undefined, this._stopChange)) { _value = v; _proto.setProperty(_keyCP, v); } if (!this._stopChange) { _update(_el, _key, v, _oldValue); } this._stopChange = undefined; }, enumerable: true, configurable: true } } /* A helper method that is run for all addListener methods */ function addListener(attr, func, child, update) { if (typeof func !== 'function') return bind; var isInput = (['value', 'checked'].indexOf(attr) !== -1), isStyle = (_allStyles.indexOf(attr) !== -1), listeners; if (this.toString() !== bind.toString()) { if (child) { var children = this.querySelectorAll('*'), len = children.length, listenerObj; for (var x = 0; x < len; x++) { listenerObj = children[x].attrListeners(); if (isInput || (attr === _all)) { if (children[x].addInputBinding !== undefined) children[x].addInputBinding(); if (children[x].addInputBoxBinding !== undefined) children[x].addInputBoxBinding(); } if (isStyle) { bind.injectStyleProperty(children[x], attr); listeners = (update ? '_parentStyleUpdateListeners' : '_parentStyleListeners'); if (listenerObj[listeners][attr] === undefined) listenerObj[listeners][attr] = []; listenerObj[listeners][attr].push({ parent: this, func: func }); } else { if (attr === _all) { listeners = (update ? '_parentStyleUpdateListeners' : '_parentStyleListeners'); var len = _allStyles.length; for (var i = 0; i < len; i++) { bind.injectStyleProperty(children[x], _allStyles[i]); } if (listenerObj[listeners][_all] === undefined) listenerObj[listeners][_all] = []; listenerObj[listeners][_all].push({ parent: this, func: func }); } listeners = (update ? '_parentAttrUpdateListeners' : '_parentAttrListeners'); if (listenerObj[listeners][attr] === undefined) listenerObj[listeners][attr] = []; listenerObj[listeners][attr].push({ parent: this, func: func }); } } } else { listenerObj = this.attrListeners(); if (isStyle) { listeners = (update ? '_styleUpdateListeners' : '_styleListeners'); bind.injectStyleProperty(this, attr); if (listenerObj[listeners][attr] === undefined) listenerObj[listeners][attr] = []; listenerObj[listeners][attr].push(func); } else { if (isInput || (attr === _all)) { if (this.addInputBinding !== undefined) this.addInputBinding(); if (this.addInputBoxBinding !== undefined) this.addInputBoxBinding(); } if (attr === _all) { listeners = (update ? '_styleUpdateListeners' : '_styleListeners'); var len = _allStyles.length; for (var x = 0; x < len; x++) { bind.injectStyleProperty(this, _allStyles[x]); } if (listenerObj[listeners][attr] === undefined) listenerObj[listeners][attr] = []; listenerObj[listeners][attr].push(func); } listeners = (update ? '_attrUpdateListeners' : '_attrListeners'); if (listenerObj[listeners][attr] === undefined) listenerObj[listeners][attr] = []; listenerObj[listeners][attr].push(func); } } } else { if (isInput || (attr === _all)) { var inputs = document.querySelectorAll('input, textarea'), len = inputs.length; for (var x = 0; x < len; x++) { if (inputs[x].addInputBinding !== undefined) inputs[x].addInputBinding(); if (inputs[x].addInputBoxBinding !== undefined) inputs[x].addInputBoxBinding(); } } if (isStyle) { var els = Array.prototype.slice.call(document.body.querySelectorAll('*')), len = (els.length + 1); els.unshift(document.body); for (var x = 0; x < len; x++) { bind.injectStyleProperty(els[x], attr); } listeners = (update ? _styleUpdateListeners : _styleListeners); if (listeners[attr] === undefined) listeners[attr] = []; listeners[attr].push(func); } else { if (attr === _all) { var els = Array.prototype.slice.call(document.body.querySelectorAll('*')), len = (els.length + 1), lenStyles = _allStyles.length; els.unshift(document.body); for (var x = 0; x < len; x++) { for (var i = 0; i < lenStyles; i++) { bind.injectStyleProperty(els[x], _allStyles[i]); } } listeners = (update ? _styleUpdateListeners : _styleListeners); if (listeners[attr] === undefined) listeners[attr] = []; listeners[attr].push(func); } listeners = (update ? _attrUpdateListeners : _attrListeners); if (listeners[attr] === undefined) listeners[attr] = []; listeners[attr].push(func); } } } /* A helper method that is ran for all removeListener methods */ function removeListener(attr, func, child, update) { if (typeof func !== 'function') return bind; var isInput = (['value', 'checked'].indexOf(attr) !== -1), isStyle = (_allStyles.indexOf(attr) !== -1), listeners, x; function cut(attr, list) { var listenerFuncs = list[attr], len = listenerFuncs.length; for (x = 0; x < len; x++) { if (listenerFuncs[x].toString() === func.toString()) { listenerFuncs.splice(x, 1); } } } if (this.toString() !== bind.toString()) { if (child) { var children = this.querySelectorAll('*'), len = children.length; if (isStyle) { listeners = (update ? '_childStyleUpdateListeners' : '_childStyleListeners'); cut(attr, this.attrListeners()[listeners]); listeners = (update ? '_parentStyleUpdateListeners' : '_parentStyleListeners'); } else { if (attr === _all) { listeners = (update ? '_childStyleUpdateListeners' : '_childStyleListeners'); cut(attr, this.attrListeners()[listeners]); } listeners = (update ? '_childAttrUpdateListeners' : '_childAttrListeners'); cut(attr, this.attrListeners()[listeners]); listeners = (update ? '_parentAttrUpdateListeners' : '_parentAttrListeners'); } for (x = 0; x < len; x++) { var parents = children[x].attrListeners()[listeners][attr], parentLen = parents.length; for (var i = 0; i < parentLen; i++) { if (parents[i].isEqualNode(this)) { parents.slice(i, 1); } } if (attr === _all) { listenersStyle = (update ? '_parentStyleUpdateListeners' : '_parentStyleListeners'); var parents = children[x].attrListeners()[listeners][attr], parentLen = parents.length; for (var i = 0; i < parentLen; i++) { if (parents[i].isEqualNode(this)) { parents.slice(i, 1); } } } } } else { if (isStyle) { listeners = (update ? '_styleUpdateListeners' : '_styleListeners'); cut(attr, this.attrListeners()[listeners]); } else { if (attr === _all) { listeners = (update ? '_styleUpdateListeners' : '_styleListeners'); cut(attr, this.attrListeners()[listeners]); } listeners = (update ? '_attrUpdateListeners' : '_attrListeners'); cut(attr, this.attrListeners()[listeners]); } } } else { if (isStyle) { listeners = (update ? _styleUpdateListeners : _styleListeners); cut(attr, listeners); } else { if (attr === _all) { listeners = (update ? _styleUpdateListeners : _styleListeners); cut(attr, listeners); } listeners = (update ? _attrUpdateListeners : _attrListeners); cut(attr, listeners); } } } /* this method gets attached to all elements for easy listener adding of child events */ function addChildAttrListener(attr, func) { bind.addAttrListener.call(this, attr, func, true); return this; } /* this method gets attached to all elements for easy listener adding of child update events */ function addChildAttrUpdateListener(attr, func) { bind.addAttrUpdateListener.call(this, attr, func, true); return this; } /* this method gets attached to all elements for easy listener removal of child events */ function removeChildAttrListener(attr, func) { bind.removeAttrListener.call(this, attr, func, true); return this; } /* this method gets attached to all elements for easy listener removal of child update events */ function removeChildAttrUpdateListener(attr, func) { bind.removeAttrUpdateListener.call(this, attr, func, true); return this; } /* This method checks if a listener of this function already exists on a desired attribute */ function hasListener(listener, attr, func) { var _listeners = this.attrListeners(); if (attr === 'html') attr = 'innerHTML'; if (attr === 'events') attr = 'onclick'; switch (listener) { case 'attr': if (typeof _listeners._attrListeners[attr] !== undefined) { if (loopListenerCheck(_listeners._attrListeners[attr], func)) return true; } else if (typeof _listeners._styleListeners[attr] !== undefined) { if (loopListenerCheck(_listeners._styleListeners[attr], func)) return true; } else if (typeof _listeners._parentAttrListeners[attr] !== undefined) { if (loopListenerCheck(_listeners._parentAttrListeners[attr], func)) return true; } else if (typeof _listeners._parentStyleListeners[attr] !== undefined) { if (loopListenerCheck(_listeners._parentStyleListeners[attr], func)) return true; } break; case 'attrupdate': if (typeof _listeners._attrUpdateListeners[attr] !== undefined) { if (loopListenerCheck(_listeners._attrUpdateListeners[attr], func)) return true; } else if (typeof _listeners._styleUpdateListeners[attr] !== undefined) { if (loopListenerCheck(_listeners._styleUpdateListeners[attr], func)) return true; } else if (typeof _listeners._parentAttrUpdateListeners[attr] !== undefined) { if (loopListenerCheck(_listeners._parentAttrUpdateListeners[attr], func)) return true; } else if (typeof _listeners._parentStyleUpdateListeners[attr] !== undefined) { if (loopListenerCheck(_listeners._parentStyleUpdateListeners[attr], func)) return true; } break; } return false; } /* sets stopChange Property for stopping update listeners to fire */ function stopChange() { this._stopChange = true; return this; } /* This is the master constructor, to be ran only once. */ function bind() { bind.injectPrototypes(Node, 'Node'); bind.injectPrototypes(Element, 'Element'); bind.injectPrototypes(HTMLElement, 'HTMLElement'); bind.injectPrototypes(HTMLInputElement, 'HTMLInputElement'); bind.injectPrototypes(HTMLTextAreaElement, 'HTMLTextAreaElement'); bind.injectPrototypes(Document, 'Document'); var __set = _set, __update = _update; function hasInput(attrListeners) { var attrs = ['value', 'checked'], _localListeners = attrListeners, _localAttr = _localListeners._attrListeners, _localUpdateAttr = _localListeners._attrUpdateListeners, _localParentAttr = _localListeners._parentAttrListeners, _localParentUpdateAttr = _localListeners._parentAttrUpdateListeners, has = false; if (_attrListeners[_all] !== undefined || _attrUpdateListeners[_all] !== undefined) { has = true; } if (has !== true && _localAttr[_all] !== undefined || _localUpdateAttr[_all] !== undefined || _localParentAttr[_all] !== undefined || _localParentUpdateAttr[_all] !== undefined) { has = true; } if (has !== true) { for (var x = 0; x < attrs.length; x++) { if (_attrListeners[attrs[x]] !== undefined || _attrUpdateListeners[attrs[x]] !== undefined || _localAttr[attrs[x]] !== undefined || _localUpdateAttr[attrs[x]] !== undefined || _localParentAttr[attrs[x]] !== undefined || _localParentUpdateAttr[attrs[x]] !== undefined) { has = true; break; } } } return has; } function getStyles(arr, styles) { var x, _arr = arr, _styles = styles, len = styles.length; for (x = 0; x < len; x++) { if (_arr.indexOf(_styles[x]) === -1) { _arr.push(_styles[x]); } } return _arr; } function hasStyle(attrListeners) { var _globalStyle = Object.keys(_styleListeners), _globalStyleUpdate = Object.keys(_styleUpdateListeners), _localListeners = attrListeners, _localStyle = Object.keys(_localListeners._styleListeners), _localUpdateStyle = Object.keys(_localListeners._styleUpdateListeners), _localParentStyle = Object.keys(_localListeners._parentStyleListeners), _localParentUpdateStyle = Object.keys(_localListeners._parentStyleUpdateListeners), has = []; if (_globalStyle.length !== 0 || _globalStyleUpdate.length !== 0) { has = getStyles(has, _globalStyle); has = getStyles(has, _globalStyleUpdate); } if (has.length !== 0 && _localParentStyle.length !== 0 || _localParentUpdateStyle.length !== 0) { has = getStyles(has, _localParentStyle); has = getStyles(has, _localParentUpdateStyle); } if (has.indexOf(_all) !== -1) has = _allStyles; return has; } function copyListeners(listeners, copyTo) { var listenerProps = Object.keys(listeners), _currProp, _currListener; for (var x = 0, len = listenerProps.length; x < len; x++) { _currProp = listenerProps[x]; if (copyTo[_currProp] === undefined) { copyTo[_currProp] = listeners[_currProp].slice(); } else { for (var i = 0, lenI = listeners[_currProp].length; i < lenI; i++) { _currListener = listeners[_currProp][i]; copyTo[_currProp].push(_currListener); } } } } function reSync(e) { if (e.target.nodeType !== 3 && e.target.nodeType !== 8) { var attrListeners = e.target.attrListeners(), _hasInput = hasInput(attrListeners), _hasStyle = hasStyle(attrListeners), _hasStyleLen = _hasStyle.length, _parentAttr, _parentAttrUpdate, _parentStyle, _parentStyleUpdate, _listeners, nodes = [], len, outer = ((e.attr === 'outerHTML' || e.attr === 'outerText') ? e.attr : undefined), target = e.target if (outer !== undefined) { e.attr = 'appendChild', e.arguments = [e.target]; e.target = e.target.parentElement; } if (_hasInput) { if (e.attr === 'appendChild' && e.arguments[0].nodeType !== 3 && e.arguments[0].nodeType !== 8) { nodes = Array.prototype.slice.call(e.arguments[0].querySelectorAll('input,textarea')); if (e.arguments[0].tagName === 'INPUT' || e.arguments[0].tagName === 'TEXTAREA') { nodes.unshift(e.arguments[0]) } } else { nodes = Array.prototype.slice.call(e.target.querySelectorAll('input,textarea')); } len = nodes.length; for (var x = 0; x < len; x++) { if (nodes[x].addInputBinding !== undefined) nodes[x].addInputBinding(); if (nodes[x].addInputBoxBinding !== undefined) nodes[x].addInputBoxBinding(); } } if (e.attr === 'appendChild' && e.arguments[0].nodeName !== '#text' && e.arguments[0].nodeName !== '#comment') { nodes = Array.prototype.slice.call(e.arguments[0].querySelectorAll('*')); nodes.unshift(e.arguments[0]); _parentAttr = e.target.__kb._parentAttrListeners; _parentAttrUpdate = e.target.__kb._parentAttrUpdateListeners; _parentStyle = e.target.__kb._parentStyleListeners; _parentStyleUpdate = e.target.__kb._parentStyleUpdateListeners; } else { nodes = Array.prototype.slice.call(e.target.querySelectorAll('*')); _parentAttr = e.target.__kb._parentAttrListeners; _parentAttrUpdate = e.target.__kb._parentAttrUpdateListeners; _parentStyle = e.target.__kb._parentStyleListeners; _parentStyleUpdate = e.target.__kb._parentStyleUpdateListeners; } len = nodes.length; for (var x = 0; x < len; x++) { if (_hasStyleLen !== 0) { for (var i = 0; i < _hasStyleLen; i++) { bind.injectStyleProperty(nodes[x], _hasStyle[i]); } } _listeners = nodes[x].attrListeners(); copyListeners(_parentAttr, _listeners._parentAttrListeners); copyListeners(_parentAttrUpdate, _listeners._parentAttrUpdateListeners); copyListeners(_parentStyle, _listeners._parentStyleListeners); copyListeners(_parentStyleUpdate, _listeners._parentStyleUpdateListeners); } if (outer !== undefined) { e.attr = outer; e.target = target; e.arguments = []; } } } function checkAttr(e) { var oldAttr = e.target.attributes[e.arguments[0]], old = (oldAttr !== undefined ? oldAttr.value : ""), val = (e.attr === 'setAttribute' ? e.arguments[1] : ""); if (!__set(e.target, e.arguments[0], val, old, [val])) { e.preventDefault(); } } function checkAttrUpdate(e) { var oldAttr = e.target.attributes[e.arguments[0]], old = (oldAttr !== undefined ? oldAttr.value : ""), val = (e.attr === 'setAttribute' ? e.arguments[1] : ""); __update(e.target, e.arguments[0], val, old, [val]); } //for keeping binds with inputs bind.addAttrUpdateListener('appendChild', reSync); bind.addAttrUpdateListener('removeChild', reSync); bind.addAttrUpdateListener('innerHTML', reSync); bind.addAttrUpdateListener('outerHTML', reSync); bind.addAttrUpdateListener('innerText', reSync); bind.addAttrUpdateListener('outerText', reSync); bind.addAttrUpdateListener('textContent', reSync); //allows for html attribute changes to be listened to just like properties bind.addAttrListener('setAttribute', checkAttr); bind.addAttrListener('removeAttribute', checkAttr); bind.addAttrUpdateListener('setAttribute', checkAttrUpdate); bind.addAttrUpdateListener('removeAttribute', checkAttrUpdate); return bind; } bind.injectPrototypeProperty = function(obj, key, injectName, set, update) { var _proto = obj.prototype, _descriptor = Object.getOwnPropertyDescriptor(_proto, key), _injectName = (injectName || obj.toString().split(/\s+/)[1].split('{')[0].replace('()', '')), _injectedObj = _injected[_injectName], __set = (set || _set), __update = (update || _update); if (_proto.attrListeners === undefined) { _proto = {}; _proto.attrListeners = (function() { if (this.__kb === undefined) { this.__kb = new _localBinders(); } return this.__kb; }).bind(_proto); _proto.addAttrListener = bind.addAttrListener; _proto.addAttrUpdateListener = bind.addAttrUpdateListener; _proto.addChildAttrListener = addChildAttrListener; _proto.addChildAttrUpdateListener = addChildAttrUpdateListener; _proto.hasListener = hasListener; _proto.removeAttrListener = bind.removeAttrListener; _proto.removeAttrUpdateListener = bind.removeAttrUpdateListener; _proto.removeChildAttrListener = removeChildAttrListener; _proto.removeChildAttrUpdateListener = removeChildAttrUpdateListener; _proto.stopChange = stopChange; } if (_injectedObj === undefined) { _injected[_injectName] = { obj: obj, proto: _proto, descriptors: {}, set: undefined, update: undefined }; _injectedObj = _injected[_injectName]; _injectedObj.set = __set; _injectedObj.update = __update; } if (_injectedObj.descriptors[key] === undefined) _injectedObj.descriptors[key] = _descriptor; if (_descriptor.configurable) { if (_descriptor.set !== undefined) { Object.defineProperty(_proto, key, { get: _descriptor.get, set: setStandard(_descriptor, key, __set, __update), enumerable: true, configurable: true }); } else if (typeof _descriptor.value === 'function') { Object.defineProperty(_proto, key, { value: setFunction(_descriptor, key, __set, __update), writable: true, enumerable: true, configurable: true }); } else if (_descriptor.value !== undefined) { Object.defineProperty(_proto, key, { get: function() { return _descriptor.value; }, set: setValue(_descriptor, key, __set, __update), enumerable: true, configurable: true }); } } return bind; } bind.injectStyleProperty = function(el, key, set, update) { var _proto = el.style, _descriptor = Object.getOwnPropertyDescriptor(_proto, key), _injectedObj = el.attrListeners().injectedStyle, __set = (set || _set), __update = (update || _update); if (_injectedObj === undefined) { el.attrListeners().injectedStyle = { obj: el, proto: _proto, descriptors: {}, set: undefined, update: undefined }; el.attrListeners().injectedStyle.set = __set; el.attrListeners().injectedStyle.update = __update; _injectedObj = el.attrListeners().injectedStyle; } if (_injectedObj.descriptors[key] === undefined) _injectedObj.descriptors[key] = _descriptor; if (_descriptor.configurable) { Object.defineProperty(_proto, key, setStyle(_descriptor, key, __set, __update, el)); } return bind; } bind.injectPrototypes = function(obj, injectName, set, update) { var _proto = obj.prototype, _injectName = (injectName || obj.toString().split(/\s+/)[1].split('{')[0].replace('()', '')), _injectedObj = _injected[_injectName], _keys = Object.getOwnPropertyNames(_proto), __set = (set || _set), __update = (update || _update), _descriptors, x; if (_proto.attrListeners === undefined) { _proto.attrListeners = function() { if (this.__kb === undefined) { this.__kb = new _localBinders(); } return this.__kb; } _proto.addAttrListener = bind.addAttrListener; _proto.addAttrUpdateListener = bind.addAttrUpdateListener; _proto.addChildAttrListener = addChildAttrListener; _proto.addChildAttrUpdateListener = addChildAttrUpdateListener; _proto.hasListener = hasListener; _proto.stopChange = stopChange; } if (_injectedObj === undefined) { _injected[_injectName] = { obj: obj, proto: _proto, descriptors: {}, set: undefined, update: undefined }; _injectedObj = _injected[_injectName]; _injectedObj.set = __set; _injectedObj.update = __update; } _descriptors = _injected[_injectName].descriptors; for (x = 0; x < _keys.length; x += 1) { if (_descriptors[_keys[x]] === undefined) { bind.injectPrototypeProperty(obj, _keys[x], _injectName, __set, _update); } } if (_keys.indexOf('value') !== -1) { function keyDown(e) { var isCheck, oldCheck, oldValue, value; if (this.type === 'checkbox' || this.type === 'radio') { oldCheck = this.checked; isCheck = true; } oldValue = (isCheck ? (typeof this.checked === 'string' ? this.checked : (this.checked ? "true" : "false")) : this.value); setTimeout((function() { value = (isCheck ? (typeof this.checked === 'string' ? this.checked : (this.checked ? "true" : "false")) : this.value); if (isCheck) { if (!_injectedObj.set(this, 'checked', this.checked, oldValue)) { _descriptors['checked'].set.call(this, oldValue); } else { _injectedObj.update(this, 'checked', this.checked, oldValue); } } this.value = value; if (!_injectedObj.set(this, 'value', this.value, oldValue)) { _descriptors['value'].set.call(this, oldValue); } else { _injectedObj.update(this, 'value', this.checked, oldValue); } }).bind(this), 0); } _proto.removeInputBinding = function() { this.attrListeners()._onkeydown = undefined; this.removeEventListener('keydown', keyDown); } _proto.addInputBinding = function() { this.attrListeners()._onkeydown = true; this.addEventListener('keydown', keyDown); } _proto.removeInputBoxBinding = function() { this.attrListeners()._onmousedown = undefined; this.removeEventListener('mouseup', keyDown); } _proto.addInputBoxBinding = function() { this.attrListeners()._onmousedown = true; this.addEventListener('mouseup', keyDown); } } return bind; } bind.addAttrListener = function(attr, func, child) { if (attr === 'html') { for (var x = 0, len = _texts.length; x < len; x++) { addListener.call(this, _texts[x], func, child, false); } } else if (attr === 'events') { for (var x = 0, len = _allEvents.length; x < len; x++) { addListener.call(this, _allEvents[x], func, child, false); } } else { addListener.call(this, attr, func, child, false); } return bind; } bind.addAttrUpdateListener = function(attr, func, child) { if (attr === 'html') { for (var x = 0, len = _texts.length; x < len; x++) { addListener.call(this, _texts[x], func, child, true); } } else if (attr === 'events') { for (var x = 0, len = _allEvents.length; x < len; x++) { addListener.call(this, _allEvents[x], func, child, true); } } else { addListener.call(this, attr, func, child, true); } return bind; } bind.removeAttrListener = function(attr, func, child) { if (attr === 'html') { for (var x = 0, len = _texts.length; x < len; x++) { removeListener.call(this, _texts[x], func, child, false); } } else if (attr === 'events') { for (var x = 0, len = _allEvents.length; x < len; x++) { removeListener.call(this, _allEvents[x], func, child, false); } } else { removeListener.call(this, attr, func, child, false); } return bind; } bind.removeAttrUpdateListener = function(attr, func, child) { if (attr === 'html') { for (var x = 0, len = _texts.length; x < len; x++) { removeListener.call(this, _texts[x], func, child, true); } } else if (attr === 'events') { for (var x = 0, len = _allEvents.length; x < len; x++) { removeListener.call(this, _allEvents[x], func, child, true); } } else { removeListener.call(this, attr, func, child, true); } return bind; } bind.hasListener = function(listener, attr, func) { if (attr === 'html') attr = 'innerHTML'; if (attr === 'events') attr = 'onclick'; switch (listener) { case 'attr': if (typeof _attrListeners[attr] !== undefined) { if (loopListenerCheck(_attrListeners[attr], func)) return true; } else if (typeof _styleListeners[attr] !== undefined) { if (loopListenerCheck(_styleListeners[attr], func)) return true; } break; case 'attrupdate': if (typeof _attrUpdateListeners[attr] !== undefined) { if (loopListenerCheck(_attrUpdateListeners[attr], func)) return true; } else if (typeof _styleUpdateListeners[attr] !== undefined) { if (loopListenerCheck(_styleUpdateListeners[attr], func)) return true; } break; } return false; } bind.injectedPrototypes = function() { return _injected; } return bind; } if (typeof define === "function" && define.amd) { define('KB', CreateKB); //global KM define in browser } return CreateKB; }()) if (window.define && window.require) { define([], function() { return CreateKB; }); } else if (window.module) { module.exports = CreateKB; } return CreateKB; }()) |
+28
-4
@@ -791,2 +791,25 @@ define([],function(){ | ||
| function copyListeners(listeners,copyTo) | ||
| { | ||
| var listenerProps = Object.keys(listeners), | ||
| _currProp, | ||
| _currListener; | ||
| for(var x=0,len=listenerProps.length;x<len;x++) | ||
| { | ||
| _currProp = listenerProps[x]; | ||
| if(copyTo[_currProp] === undefined) | ||
| { | ||
| copyTo[_currProp] = listeners[_currProp].slice(); | ||
| } | ||
| else | ||
| { | ||
| for(var i=0,lenI=listeners[_currProp].length;i<lenI;i++) | ||
| { | ||
| _currListener = listeners[_currProp][i]; | ||
| copyTo[_currProp].push(_currListener); | ||
| } | ||
| } | ||
| } | ||
| } | ||
| function reSync(e) | ||
@@ -868,6 +891,7 @@ { | ||
| _listeners = nodes[x].attrListeners(); | ||
| _listeners._parentAttrListeners = _parentAttr; | ||
| _listeners._parentAttrUpdateListeners = _parentAttrUpdate; | ||
| _listeners._parentStyleListeners = _parentStyle; | ||
| _listeners._parentStyleUpdateListeners = _parentStyleUpdate; | ||
| copyListeners(_parentAttr,_listeners._parentAttrListeners); | ||
| copyListeners(_parentAttrUpdate,_listeners._parentAttrUpdateListeners); | ||
| copyListeners(_parentStyle,_listeners._parentStyleListeners); | ||
| copyListeners(_parentStyleUpdate,_listeners._parentStyleUpdateListeners); | ||
| } | ||
@@ -874,0 +898,0 @@ |
+31
-31
@@ -1,31 +0,31 @@ | ||
| var KB=function(){var H=function(){function H(){function k(a,b){var c=a.length,d;for(d=0;d<c&&(a[d](b),void 0===b._stopPropogation);d++);}function r(a,b){var c=a.length,d;for(d=0;d<c&&(b.child=b.target,b.target=a[d].parent,a[d].func(b),void 0===b._stopPropogation);d++);}function J(a,b){for(var c=a.length;0<c;L++)if(a[L].toString()===b.toString())return!0;return!1}function M(a,b,c,d,f,e,g,h){this.stopPropagation=function(){this._stopPropogation=!0};this.preventDefault=function(){this._preventDefault= | ||
| !0};this.value=c;this.oldValue=d;this.target=a;this.attr=b;this.arguments=f;this.action=e;this.child=void 0;this.type=g;this.stopChange=h}function N(){this._attrListeners={};this._attrUpdateListeners={};this._styleListeners={};this._styleUpdateListeners={};this._parentStyleListeners={};this._parentStyleUpdateListeners={};this._parentAttrListeners={};this._parentAttrUpdateListeners={};this._injectedStyle={}}function S(a,b,c,d){var f=a.get,e=a.set,g;return function(a){g=f.call(this);c(this,b,a,g,void 0, | ||
| this._stopChange)&&e.call(this,a);this._stopChange||d(this,b,a,g);this._stopChange=void 0}}function T(a,b,c,d){var f;return function(e){f=a.value;c(this,b,e,f,arguments,this._stopChange)&&(a.value=e);this._stopChange||d(this,b,e,f,arguments);this._stopChange=void 0}}function U(a,b,c,d){var f=a.value,e;return function(){c(this,b,null,null,arguments,this._stopChange)&&(e=f.apply(this,arguments));this._stopChange||d(this,b,null,null,arguments,e);this._stopChange=void 0;return e}}function V(a,b,c,d,f){var e= | ||
| f.style,g=b.replace(/([A-Z])/g,"-$1").replace("webkit","-webkit"),h,m;return{get:function(){return m},set:function(a){h=m;c(f,b,a,h,void 0,this._stopChange)&&(m=a,e.setProperty(g,a));this._stopChange||d(f,b,a,h);this._stopChange=void 0},enumerable:!0,configurable:!0}}function F(a,b,c,d){if("function"!==typeof b)return h;var f=-1!==["value","checked"].indexOf(a),e=-1!==w.indexOf(a),g;if(this.toString()!==h.toString())if(c){var u=this.querySelectorAll("*");c=u.length;for(var m,l=0;l<c;l++){m=u[l].attrListeners(); | ||
| if(f||"*"===a)void 0!==u[l].addInputBinding&&u[l].addInputBinding(),void 0!==u[l].addInputBoxBinding&&u[l].addInputBoxBinding();if(e)h.injectStyleProperty(u[l],a),g=d?"_parentStyleUpdateListeners":"_parentStyleListeners";else{if("*"===a){g=d?"_parentStyleUpdateListeners":"_parentStyleListeners";c=w.length;for(var n=0;n<c;n++)h.injectStyleProperty(u[l],w[n]);void 0===m[g]["*"]&&(m[g]["*"]=[]);m[g]["*"].push({parent:this,func:b})}g=d?"_parentAttrUpdateListeners":"_parentAttrListeners"}void 0===m[g][a]&& | ||
| (m[g][a]=[]);m[g][a].push({parent:this,func:b})}}else{m=this.attrListeners();if(e)g=d?"_styleUpdateListeners":"_styleListeners",h.injectStyleProperty(this,a);else{if(f||"*"===a)void 0!==this.addInputBinding&&this.addInputBinding(),void 0!==this.addInputBoxBinding&&this.addInputBoxBinding();if("*"===a){g=d?"_styleUpdateListeners":"_styleListeners";c=w.length;for(l=0;l<c;l++)h.injectStyleProperty(this,w[l]);void 0===m[g][a]&&(m[g][a]=[]);m[g][a].push(b)}g=d?"_attrUpdateListeners":"_attrListeners"}void 0=== | ||
| m[g][a]&&(m[g][a]=[]);m[g][a].push(b)}else{if(f||"*"===a)for(n=document.querySelectorAll("input, textarea"),c=n.length,l=0;l<c;l++)void 0!==n[l].addInputBinding&&n[l].addInputBinding(),void 0!==n[l].addInputBoxBinding&&n[l].addInputBoxBinding();if(e){e=Array.prototype.slice.call(document.body.querySelectorAll("*"));c=e.length+1;e.unshift(document.body);for(l=0;l<c;l++)h.injectStyleProperty(e[l],a);g=d?B:C}else{if("*"===a){e=Array.prototype.slice.call(document.body.querySelectorAll("*"));c=e.length+ | ||
| 1;f=w.length;e.unshift(document.body);for(l=0;l<c;l++)for(n=0;n<f;n++)h.injectStyleProperty(e[l],w[n]);g=d?B:C;void 0===g[a]&&(g[a]=[]);g[a].push(b)}g=d?x:y}void 0===g[a]&&(g[a]=[]);g[a].push(b)}}function G(a,b,c,d){function f(a,c){var d=c[a],e=d.length;for(g=0;g<e;g++)d[g].toString()===b.toString()&&d.splice(g,1)}if("function"!==typeof b)return h;["value","checked"].indexOf(a);var e=-1!==w.indexOf(a),g;if(this.toString()!==h.toString())if(c){c=this.querySelectorAll("*");var u=c.length;e?(e=d?"_childStyleUpdateListeners": | ||
| "_childStyleListeners",f(a,this.attrListeners()[e]),e=d?"_parentStyleUpdateListeners":"_parentStyleListeners"):("*"===a&&(e=d?"_childStyleUpdateListeners":"_childStyleListeners",f(a,this.attrListeners()[e])),e=d?"_childAttrUpdateListeners":"_childAttrListeners",f(a,this.attrListeners()[e]),e=d?"_parentAttrUpdateListeners":"_parentAttrListeners");for(g=0;g<u;g++){for(var m=c[g].attrListeners()[e][a],l=m.length,n=0;n<l;n++)m[n].isEqualNode(this)&&m.slice(n,1);if("*"===a)for(listenersStyle=d?"_parentStyleUpdateListeners": | ||
| "_parentStyleListeners",m=c[g].attrListeners()[e][a],l=m.length,n=0;n<l;n++)m[n].isEqualNode(this)&&m.slice(n,1)}}else e?e=d?"_styleUpdateListeners":"_styleListeners":("*"===a&&(e=d?"_styleUpdateListeners":"_styleListeners",f(a,this.attrListeners()[e])),e=d?"_attrUpdateListeners":"_attrListeners"),f(a,this.attrListeners()[e]);else e?e=d?B:C:("*"===a&&(e=d?B:C,f(a,e)),e=d?x:y),f(a,e)}function O(a,b){h.addAttrListener.call(this,a,b,!0);return this}function P(a,b){h.addAttrUpdateListener.call(this,a, | ||
| b,!0);return this}function W(a,b){h.removeAttrListener.call(this,a,b,!0);return this}function X(a,b){h.removeAttrUpdateListener.call(this,a,b,!0);return this}function Q(a,b,c){var d=this.attrListeners();"html"===b&&(b="innerHTML");"events"===b&&(b="onclick");switch(a){case "attr":if(J(d._attrListeners[b],c))return!0;break;case "attrupdate":if(J(d._attrUpdateListeners[b],c))return!0}return!1}function R(){this._stopChange=!0;return this}function h(){function a(a,b){var c,d=b.length;for(c=0;c<d;c++)-1=== | ||
| a.indexOf(b[c])&&a.push(b[c]);return a}function b(b){if(3!==b.target.nodeType&&8!==b.target.nodeType){var c=b.target.attrListeners(),d,e=["value","checked"],f=c._attrListeners,z=c._attrUpdateListeners,p=c._parentAttrListeners;d=c._parentAttrUpdateListeners;var k=!1;if(void 0!==y["*"]||void 0!==x["*"])k=!0;if(!0!==k&&void 0!==f["*"]||void 0!==z["*"]||void 0!==p["*"]||void 0!==d["*"])k=!0;if(!0!==k)for(var v=0;v<e.length;v++)if(void 0!==y[e[v]]||void 0!==x[e[v]]||void 0!==f[e[v]]||void 0!==z[e[v]]|| | ||
| void 0!==p[e[v]]||void 0!==d[e[v]]){k=!0;break}d=k;e=Object.keys(C);f=Object.keys(B);Object.keys(c._styleListeners);Object.keys(c._styleUpdateListeners);z=Object.keys(c._parentStyleListeners);c=Object.keys(c._parentStyleUpdateListeners);p=[];if(0!==e.length||0!==f.length)p=a(p,e),p=a(p,f);if(0!==p.length&&0!==z.length||0!==c.length)p=a(p,z),p=a(p,c);-1!==p.indexOf("*")&&(p=w);var c=p,e=c.length,r,A,f=[],q,z="outerHTML"===b.attr||"outerText"===b.attr?b.attr:void 0,p=b.target;void 0!==z&&(b.attr="appendChild", | ||
| b.arguments=[b.target],b.target=b.target.parentElement);if(d){"appendChild"===b.attr&&3!==b.arguments[0].nodeType&&8!==b.arguments[0].nodeType?(f=Array.prototype.slice.call(b.arguments[0].querySelectorAll("input,textarea")),"INPUT"!==b.arguments[0].tagName&&"TEXTAREA"!==b.arguments[0].tagName||f.unshift(b.arguments[0])):f=Array.prototype.slice.call(b.target.querySelectorAll("input,textarea"));q=f.length;for(var t=0;t<q;t++)void 0!==f[t].addInputBinding&&f[t].addInputBinding(),void 0!==f[t].addInputBoxBinding&& | ||
| f[t].addInputBoxBinding()}"appendChild"===b.attr&&"#text"!==b.arguments[0].nodeName&&"#comment"!==b.arguments[0].nodeName?(f=Array.prototype.slice.call(b.arguments[0].querySelectorAll("*")),f.unshift(b.arguments[0])):f=Array.prototype.slice.call(b.target.querySelectorAll("*"));d=b.target.__kb._parentAttrListeners;k=b.target.__kb._parentAttrUpdateListeners;v=b.target.__kb._parentStyleListeners;r=b.target.__kb._parentStyleUpdateListeners;q=f.length;for(t=0;t<q;t++){if(0!==e)for(A=0;A<e;A++)h.injectStyleProperty(f[t], | ||
| c[A]);A=f[t].attrListeners();A._parentAttrListeners=d;A._parentAttrUpdateListeners=k;A._parentStyleListeners=v;A._parentStyleUpdateListeners=r}void 0!==z&&(b.attr=z,b.target=p,b.arguments=[])}}function c(a){var b=a.target.attributes[a.arguments[0]],c="setAttribute"===a.attr?a.arguments[1]:"";f(a.target,a.arguments[0],c,void 0!==b?b.value:"",[c])||a.preventDefault()}function d(a){var b=a.target.attributes[a.arguments[0]],c="setAttribute"===a.attr?a.arguments[1]:"";e(a.target,a.arguments[0],c,void 0!== | ||
| b?b.value:"",[c])}h.injectPrototypes(Node,"Node");h.injectPrototypes(Element,"Element");h.injectPrototypes(HTMLElement,"HTMLElement");h.injectPrototypes(HTMLInputElement,"HTMLInputElement");h.injectPrototypes(HTMLTextAreaElement,"HTMLTextAreaElement");h.injectPrototypes(Document,"Document");var f=K,e=I;h.addAttrUpdateListener("appendChild",b);h.addAttrUpdateListener("removeChild",b);h.addAttrUpdateListener("innerHTML",b);h.addAttrUpdateListener("outerHTML",b);h.addAttrUpdateListener("innerText",b); | ||
| h.addAttrUpdateListener("outerText",b);h.addAttrUpdateListener("textContent",b);h.addAttrListener("setAttribute",c);h.addAttrListener("removeAttribute",c);h.addAttrUpdateListener("setAttribute",d);h.addAttrUpdateListener("removeAttribute",d);return h}var y={},x={},C={},B={},q={},D="textContent innerHTML innerText outerHTML outerText appendChild removeChild replaceChild insertAdjacentHTML insertBefore".split(" "),w=Object.getOwnPropertyNames(document.body.style),E=Object.keys(HTMLElement.prototype).filter(function(a){return 0=== | ||
| a.indexOf("on")}).concat(["addEventListener","removeEventListener"]),L,K=function(a,b,c,d,f,e){c=new M(a,b,c,d,f,void 0,"set",e);void 0!==a.__kb&&(d=a.__kb._attrListeners,f=a.__kb._styleListeners,e=a.__kb._parentAttrListeners,a=a.__kb._parentStyleListeners,void 0!==d[b]&&k(d[b],c),void 0===c._stopPropogation&&void 0!==f[b]&&k(f[b],c),void 0===c._stopPropogation&&void 0!==d["*"]&&(k(d["*"],c),void 0===c._stopPropogation&&k(f["*"],c)),void 0===c._stopPropogation&&void 0!==e[b]&&r(e[b],c),void 0===c._stopPropogation&& | ||
| void 0!==a[b]&&r(a[b],c),void 0===c._stopPropogation&&void 0!==e["*"]&&(r(e["*"],c),void 0===c._stopPropogation&&r(a["*"],c)));void 0===c._stopPropogation&&void 0!==y[b]&&k(y[b],c);void 0===c._stopPropogation&&void 0!==C[b]&&k(C[b],c);void 0===c._stopPropogation&&void 0!==y["*"]&&(k(y["*"],c),void 0===c._stopPropogation&&k(C["*"],c));return void 0!==c._preventDefault?!1:!0},I=function(a,b,c,d,f,e){c=new M(a,b,c,d,f,e,"update");void 0!==a.__kb&&(d=a.__kb._attrUpdateListeners,f=a.__kb._styleUpdateListeners, | ||
| e=a.__kb._parentAttrUpdateListeners,a=a.__kb._parentStyleUpdateListeners,void 0!==d[b]&&k(d[b],c),void 0===c._stopPropogation&&void 0!==f[b]&&k(f[b],c),void 0===c._stopPropogation&&void 0!==d["*"]&&(k(d["*"],c),void 0===c._stopPropogation&&k(f["*"],c)),void 0===c._stopPropogation&&void 0!==e[b]&&r(e[b],c),void 0===c._stopPropogation&&void 0!==a[b]&&r(a[b],c),void 0===c._stopPropogation&&void 0!==e["*"]&&(r(e["*"],c),void 0===c._stopPropogation&&r(a["*"],c)));void 0===c._stopPropogation&&void 0!== | ||
| x[b]&&k(x[b],c);void 0===c._stopPropogation&&void 0!==B[b]&&k(B[b],c);void 0===c._stopPropogation&&void 0!==x["*"]&&(k(x["*"],c),void 0===c._stopPropogation&&k(B["*"],c));return void 0!==c._preventDefault?!1:!0};h.injectPrototypeProperty=function(a,b,c,d,f){var e=a.prototype,g=Object.getOwnPropertyDescriptor(e,b);c=c||a.toString().split(/\s+/)[1].split("{")[0].replace("()","");var k=q[c];d=d||K;f=f||I;void 0===e.attrListeners&&(e={},e.attrListeners=function(){void 0===this.__kb&&(this.__kb=new N); | ||
| return this.__kb}.bind(e),e.addAttrListener=h.addAttrListener,e.addAttrUpdateListener=h.addAttrUpdateListener,e.addChildAttrListener=O,e.addChildAttrUpdateListener=P,e.hasListener=Q,e.removeAttrListener=h.removeAttrListener,e.removeAttrUpdateListener=h.removeAttrUpdateListener,e.removeChildAttrListener=W,e.removeChildAttrUpdateListener=X,e.stopChange=R);void 0===k&&(q[c]={obj:a,proto:e,descriptors:{},set:void 0,update:void 0},k=q[c],k.set=d,k.update=f);void 0===k.descriptors[b]&&(k.descriptors[b]= | ||
| g);g.configurable&&(void 0!==g.set?Object.defineProperty(e,b,{get:g.get,set:S(g,b,d,f),enumerable:!0,configurable:!0}):"function"===typeof g.value?Object.defineProperty(e,b,{value:U(g,b,d,f),writable:!0,enumerable:!0,configurable:!0}):void 0!==g.value&&Object.defineProperty(e,b,{get:function(){return g.value},set:T(g,b,d,f),enumerable:!0,configurable:!0}));return h};h.injectStyleProperty=function(a,b,c,d){var f=a.style,e=Object.getOwnPropertyDescriptor(f,b),g=a.attrListeners().injectedStyle;c=c|| | ||
| K;d=d||I;void 0===g&&(a.attrListeners().injectedStyle={obj:a,proto:f,descriptors:{},set:void 0,update:void 0},a.attrListeners().injectedStyle.set=c,a.attrListeners().injectedStyle.update=d,g=a.attrListeners().injectedStyle);void 0===g.descriptors[b]&&(g.descriptors[b]=e);e.configurable&&Object.defineProperty(f,b,V(e,b,c,d,a));return h};h.injectPrototypes=function(a,b,c,d){var f=a.prototype;b=b||a.toString().split(/\s+/)[1].split("{")[0].replace("()","");var e=q[b],g=Object.getOwnPropertyNames(f); | ||
| c=c||K;d=d||I;var k;void 0===f.attrListeners&&(f.attrListeners=function(){void 0===this.__kb&&(this.__kb=new N);return this.__kb},f.addAttrListener=h.addAttrListener,f.addAttrUpdateListener=h.addAttrUpdateListener,f.addChildAttrListener=O,f.addChildAttrUpdateListener=P,f.hasListener=Q,f.stopChange=R);void 0===e&&(q[b]={obj:a,proto:f,descriptors:{},set:void 0,update:void 0},e=q[b],e.set=c,e.update=d);k=q[b].descriptors;for(d=0;d<g.length;d+=1)void 0===k[g[d]]&&h.injectPrototypeProperty(a,g[d],b,c, | ||
| I);if(-1!==g.indexOf("value")){var m=function(a){var b,c,d;if("checkbox"===this.type||"radio"===this.type)b=!0;c=b?"string"===typeof this.checked?this.checked:this.checked?"true":"false":this.value;setTimeout(function(){d=b?"string"===typeof this.checked?this.checked:this.checked?"true":"false":this.value;b&&(e.set(this,"checked",this.checked,c)?e.update(this,"checked",this.checked,c):k.checked.set.call(this,c));this.value=d;e.set(this,"value",this.value,c)?e.update(this,"value",this.checked,c):k.value.set.call(this, | ||
| c)}.bind(this),0)};f.removeInputBinding=function(){this.attrListeners()._onkeydown=void 0;this.removeEventListener("keydown",m)};f.addInputBinding=function(){this.attrListeners()._onkeydown=!0;this.addEventListener("keydown",m)};f.removeInputBoxBinding=function(){this.attrListeners()._onmousedown=void 0;this.removeEventListener("mouseup",m)};f.addInputBoxBinding=function(){this.attrListeners()._onmousedown=!0;this.addEventListener("mouseup",m)}}return h};h.addAttrListener=function(a,b,c){if("html"=== | ||
| a){a=0;for(var d=D.length;a<d;a++)F.call(this,D[a],b,c,!1)}else if("events"===a)for(a=0,d=E.length;a<d;a++)F.call(this,E[a],b,c,!1);else F.call(this,a,b,c,!1);return h};h.addAttrUpdateListener=function(a,b,c){if("html"===a){a=0;for(var d=D.length;a<d;a++)F.call(this,D[a],b,c,!0)}else if("events"===a)for(a=0,d=E.length;a<d;a++)F.call(this,E[a],b,c,!0);else F.call(this,a,b,c,!0);return h};h.removeAttrListener=function(a,b,c){if("html"===a){a=0;for(var d=D.length;a<d;a++)G.call(this,D[a],b,c,!1)}else if("events"=== | ||
| a)for(a=0,d=E.length;a<d;a++)G.call(this,E[a],b,c,!1);else G.call(this,a,b,c,!1);return h};h.removeAttrUpdateListener=function(a,b,c){if("html"===a){a=0;for(var d=D.length;a<d;a++)G.call(this,D[a],b,c,!0)}else if("events"===a)for(a=0,d=E.length;a<d;a++)G.call(this,E[a],b,c,!0);else G.call(this,a,b,c,!0);return h};h.hasListener=function(a,b,c){"html"===b&&(b="innerHTML");"events"===b&&(b="onclick");switch(a){case "attr":if(J(y[b],c))return!0;break;case "attrupdate":if(J(x[b],c))return!0}return!1}; | ||
| h.injectedPrototypes=function(){return q};return h}"function"===typeof define&&define.amd&&define("KB",H);return H}();window.define&&window.require?define([],function(){return H}):window.module&&(module.exports=H);return H}(); | ||
| var KB=function(){var G=function(){function G(){function k(a,c){var b=a.length,d;for(d=0;d<b&&(a[d](c),void 0===c._stopPropogation);d++);}function p(a,c){var b=a.length,d;for(d=0;d<b&&(c.child=c.target,c.target=a[d].parent,a[d].func(c),void 0===c._stopPropogation);d++);}function I(a,c){for(var b=a.length;0<b;K++)if(a[K].toString()===c.toString())return!0;return!1}function L(a,c,b,d,f,e,g,r){this.stopPropagation=function(){this._stopPropogation=!0};this.preventDefault=function(){this._preventDefault= | ||
| !0};this.value=b;this.oldValue=d;this.target=a;this.attr=c;this.arguments=f;this.action=e;this.child=void 0;this.type=g;this.stopChange=r}function M(){this._attrListeners={};this._attrUpdateListeners={};this._styleListeners={};this._styleUpdateListeners={};this._parentStyleListeners={};this._parentStyleUpdateListeners={};this._parentAttrListeners={};this._parentAttrUpdateListeners={};this._injectedStyle={}}function R(a,c,b,d){var f=a.get,e=a.set,g;return function(a){g=f.call(this);b(this,c,a,g,void 0, | ||
| this._stopChange)&&e.call(this,a);this._stopChange||d(this,c,a,g);this._stopChange=void 0}}function S(a,c,b,d){var f;return function(e){f=a.value;b(this,c,e,f,arguments,this._stopChange)&&(a.value=e);this._stopChange||d(this,c,e,f,arguments);this._stopChange=void 0}}function T(a,c,b,d){var f=a.value,e;return function(){b(this,c,null,null,arguments,this._stopChange)&&(e=f.apply(this,arguments));this._stopChange||d(this,c,null,null,arguments,e);this._stopChange=void 0;return e}}function U(a,c,b,d,f){var e= | ||
| f.style,g=c.replace(/([A-Z])/g,"-$1").replace("webkit","-webkit"),r,m;return{get:function(){return m},set:function(a){r=m;b(f,c,a,r,void 0,this._stopChange)&&(m=a,e.setProperty(g,a));this._stopChange||d(f,c,a,r);this._stopChange=void 0},enumerable:!0,configurable:!0}}function E(a,c,b,d){if("function"!==typeof c)return h;var f=-1!==["value","checked"].indexOf(a),e=-1!==x.indexOf(a),g;if(this.toString()!==h.toString())if(b){var r=this.querySelectorAll("*");b=r.length;for(var m,l=0;l<b;l++){m=r[l].attrListeners(); | ||
| if(f||"*"===a)void 0!==r[l].addInputBinding&&r[l].addInputBinding(),void 0!==r[l].addInputBoxBinding&&r[l].addInputBoxBinding();if(e)h.injectStyleProperty(r[l],a),g=d?"_parentStyleUpdateListeners":"_parentStyleListeners";else{if("*"===a){g=d?"_parentStyleUpdateListeners":"_parentStyleListeners";b=x.length;for(var n=0;n<b;n++)h.injectStyleProperty(r[l],x[n]);void 0===m[g]["*"]&&(m[g]["*"]=[]);m[g]["*"].push({parent:this,func:c})}g=d?"_parentAttrUpdateListeners":"_parentAttrListeners"}void 0===m[g][a]&& | ||
| (m[g][a]=[]);m[g][a].push({parent:this,func:c})}}else{m=this.attrListeners();if(e)g=d?"_styleUpdateListeners":"_styleListeners",h.injectStyleProperty(this,a);else{if(f||"*"===a)void 0!==this.addInputBinding&&this.addInputBinding(),void 0!==this.addInputBoxBinding&&this.addInputBoxBinding();if("*"===a){g=d?"_styleUpdateListeners":"_styleListeners";b=x.length;for(l=0;l<b;l++)h.injectStyleProperty(this,x[l]);void 0===m[g][a]&&(m[g][a]=[]);m[g][a].push(c)}g=d?"_attrUpdateListeners":"_attrListeners"}void 0=== | ||
| m[g][a]&&(m[g][a]=[]);m[g][a].push(c)}else{if(f||"*"===a)for(n=document.querySelectorAll("input, textarea"),b=n.length,l=0;l<b;l++)void 0!==n[l].addInputBinding&&n[l].addInputBinding(),void 0!==n[l].addInputBoxBinding&&n[l].addInputBoxBinding();if(e){e=Array.prototype.slice.call(document.body.querySelectorAll("*"));b=e.length+1;e.unshift(document.body);for(l=0;l<b;l++)h.injectStyleProperty(e[l],a);g=d?B:C}else{if("*"===a){e=Array.prototype.slice.call(document.body.querySelectorAll("*"));b=e.length+ | ||
| 1;f=x.length;e.unshift(document.body);for(l=0;l<b;l++)for(n=0;n<f;n++)h.injectStyleProperty(e[l],x[n]);g=d?B:C;void 0===g[a]&&(g[a]=[]);g[a].push(c)}g=d?y:z}void 0===g[a]&&(g[a]=[]);g[a].push(c)}}function F(a,c,b,d){function f(a,b){var d=b[a],e=d.length;for(g=0;g<e;g++)d[g].toString()===c.toString()&&d.splice(g,1)}if("function"!==typeof c)return h;["value","checked"].indexOf(a);var e=-1!==x.indexOf(a),g;if(this.toString()!==h.toString())if(b){b=this.querySelectorAll("*");var r=b.length;e?(e=d?"_childStyleUpdateListeners": | ||
| "_childStyleListeners",f(a,this.attrListeners()[e]),e=d?"_parentStyleUpdateListeners":"_parentStyleListeners"):("*"===a&&(e=d?"_childStyleUpdateListeners":"_childStyleListeners",f(a,this.attrListeners()[e])),e=d?"_childAttrUpdateListeners":"_childAttrListeners",f(a,this.attrListeners()[e]),e=d?"_parentAttrUpdateListeners":"_parentAttrListeners");for(g=0;g<r;g++){for(var m=b[g].attrListeners()[e][a],l=m.length,n=0;n<l;n++)m[n].isEqualNode(this)&&m.slice(n,1);if("*"===a)for(listenersStyle=d?"_parentStyleUpdateListeners": | ||
| "_parentStyleListeners",m=b[g].attrListeners()[e][a],l=m.length,n=0;n<l;n++)m[n].isEqualNode(this)&&m.slice(n,1)}}else e?e=d?"_styleUpdateListeners":"_styleListeners":("*"===a&&(e=d?"_styleUpdateListeners":"_styleListeners",f(a,this.attrListeners()[e])),e=d?"_attrUpdateListeners":"_attrListeners"),f(a,this.attrListeners()[e]);else e?e=d?B:C:("*"===a&&(e=d?B:C,f(a,e)),e=d?y:z),f(a,e)}function N(a,c){h.addAttrListener.call(this,a,c,!0);return this}function O(a,c){h.addAttrUpdateListener.call(this,a, | ||
| c,!0);return this}function V(a,c){h.removeAttrListener.call(this,a,c,!0);return this}function W(a,c){h.removeAttrUpdateListener.call(this,a,c,!0);return this}function P(a,c,b){var d=this.attrListeners();"html"===c&&(c="innerHTML");"events"===c&&(c="onclick");switch(a){case "attr":if(I(d._attrListeners[c],b))return!0;break;case "attrupdate":if(I(d._attrUpdateListeners[c],b))return!0}return!1}function Q(){this._stopChange=!0;return this}function h(){function a(a,b){var c,d=b.length;for(c=0;c<d;c++)-1=== | ||
| a.indexOf(b[c])&&a.push(b[c]);return a}function c(a,b){for(var c=Object.keys(a),d,e,g=0,f=c.length;g<f;g++)if(d=c[g],void 0===b[d])b[d]=a[d].slice();else for(var h=0,k=a[d].length;h<k;h++)e=a[d][h],b[d].push(e)}function b(b){if(3!==b.target.nodeType&&8!==b.target.nodeType){var d=b.target.attrListeners(),e,g=["value","checked"],f=d._attrListeners,k=d._attrUpdateListeners,q=d._parentAttrListeners;e=d._parentAttrUpdateListeners;var p=!1;if(void 0!==z["*"]||void 0!==y["*"])p=!0;if(!0!==p&&void 0!==f["*"]|| | ||
| void 0!==k["*"]||void 0!==q["*"]||void 0!==e["*"])p=!0;if(!0!==p)for(var w=0;w<g.length;w++)if(void 0!==z[g[w]]||void 0!==y[g[w]]||void 0!==f[g[w]]||void 0!==k[g[w]]||void 0!==q[g[w]]||void 0!==e[g[w]]){p=!0;break}e=p;g=Object.keys(C);f=Object.keys(B);Object.keys(d._styleListeners);Object.keys(d._styleUpdateListeners);k=Object.keys(d._parentStyleListeners);d=Object.keys(d._parentStyleUpdateListeners);q=[];if(0!==g.length||0!==f.length)q=a(q,g),q=a(q,f);if(0!==q.length&&0!==k.length||0!==d.length)q= | ||
| a(q,k),q=a(q,d);-1!==q.indexOf("*")&&(q=x);var d=q,g=d.length,v,A,f=[],t,k="outerHTML"===b.attr||"outerText"===b.attr?b.attr:void 0,q=b.target;void 0!==k&&(b.attr="appendChild",b.arguments=[b.target],b.target=b.target.parentElement);if(e){"appendChild"===b.attr&&3!==b.arguments[0].nodeType&&8!==b.arguments[0].nodeType?(f=Array.prototype.slice.call(b.arguments[0].querySelectorAll("input,textarea")),"INPUT"!==b.arguments[0].tagName&&"TEXTAREA"!==b.arguments[0].tagName||f.unshift(b.arguments[0])):f= | ||
| Array.prototype.slice.call(b.target.querySelectorAll("input,textarea"));t=f.length;for(var u=0;u<t;u++)void 0!==f[u].addInputBinding&&f[u].addInputBinding(),void 0!==f[u].addInputBoxBinding&&f[u].addInputBoxBinding()}"appendChild"===b.attr&&"#text"!==b.arguments[0].nodeName&&"#comment"!==b.arguments[0].nodeName?(f=Array.prototype.slice.call(b.arguments[0].querySelectorAll("*")),f.unshift(b.arguments[0])):f=Array.prototype.slice.call(b.target.querySelectorAll("*"));e=b.target.__kb._parentAttrListeners; | ||
| p=b.target.__kb._parentAttrUpdateListeners;w=b.target.__kb._parentStyleListeners;v=b.target.__kb._parentStyleUpdateListeners;t=f.length;for(u=0;u<t;u++){if(0!==g)for(A=0;A<g;A++)h.injectStyleProperty(f[u],d[A]);A=f[u].attrListeners();c(e,A._parentAttrListeners);c(p,A._parentAttrUpdateListeners);c(w,A._parentStyleListeners);c(v,A._parentStyleUpdateListeners)}void 0!==k&&(b.attr=k,b.target=q,b.arguments=[])}}function d(a){var b=a.target.attributes[a.arguments[0]],c="setAttribute"===a.attr?a.arguments[1]: | ||
| "";e(a.target,a.arguments[0],c,void 0!==b?b.value:"",[c])||a.preventDefault()}function f(a){var b=a.target.attributes[a.arguments[0]],c="setAttribute"===a.attr?a.arguments[1]:"";g(a.target,a.arguments[0],c,void 0!==b?b.value:"",[c])}h.injectPrototypes(Node,"Node");h.injectPrototypes(Element,"Element");h.injectPrototypes(HTMLElement,"HTMLElement");h.injectPrototypes(HTMLInputElement,"HTMLInputElement");h.injectPrototypes(HTMLTextAreaElement,"HTMLTextAreaElement");h.injectPrototypes(Document,"Document"); | ||
| var e=J,g=H;h.addAttrUpdateListener("appendChild",b);h.addAttrUpdateListener("removeChild",b);h.addAttrUpdateListener("innerHTML",b);h.addAttrUpdateListener("outerHTML",b);h.addAttrUpdateListener("innerText",b);h.addAttrUpdateListener("outerText",b);h.addAttrUpdateListener("textContent",b);h.addAttrListener("setAttribute",d);h.addAttrListener("removeAttribute",d);h.addAttrUpdateListener("setAttribute",f);h.addAttrUpdateListener("removeAttribute",f);return h}var z={},y={},C={},B={},v={},t="textContent innerHTML innerText outerHTML outerText appendChild removeChild replaceChild insertAdjacentHTML insertBefore".split(" "), | ||
| x=Object.getOwnPropertyNames(document.body.style),D=Object.keys(HTMLElement.prototype).filter(function(a){return 0===a.indexOf("on")}).concat(["addEventListener","removeEventListener"]),K,J=function(a,c,b,d,f,e){b=new L(a,c,b,d,f,void 0,"set",e);void 0!==a.__kb&&(d=a.__kb._attrListeners,f=a.__kb._styleListeners,e=a.__kb._parentAttrListeners,a=a.__kb._parentStyleListeners,void 0!==d[c]&&k(d[c],b),void 0===b._stopPropogation&&void 0!==f[c]&&k(f[c],b),void 0===b._stopPropogation&&void 0!==d["*"]&&(k(d["*"], | ||
| b),void 0===b._stopPropogation&&k(f["*"],b)),void 0===b._stopPropogation&&void 0!==e[c]&&p(e[c],b),void 0===b._stopPropogation&&void 0!==a[c]&&p(a[c],b),void 0===b._stopPropogation&&void 0!==e["*"]&&(p(e["*"],b),void 0===b._stopPropogation&&p(a["*"],b)));void 0===b._stopPropogation&&void 0!==z[c]&&k(z[c],b);void 0===b._stopPropogation&&void 0!==C[c]&&k(C[c],b);void 0===b._stopPropogation&&void 0!==z["*"]&&(k(z["*"],b),void 0===b._stopPropogation&&k(C["*"],b));return void 0!==b._preventDefault?!1: | ||
| !0},H=function(a,c,b,d,f,e){b=new L(a,c,b,d,f,e,"update");void 0!==a.__kb&&(d=a.__kb._attrUpdateListeners,f=a.__kb._styleUpdateListeners,e=a.__kb._parentAttrUpdateListeners,a=a.__kb._parentStyleUpdateListeners,void 0!==d[c]&&k(d[c],b),void 0===b._stopPropogation&&void 0!==f[c]&&k(f[c],b),void 0===b._stopPropogation&&void 0!==d["*"]&&(k(d["*"],b),void 0===b._stopPropogation&&k(f["*"],b)),void 0===b._stopPropogation&&void 0!==e[c]&&p(e[c],b),void 0===b._stopPropogation&&void 0!==a[c]&&p(a[c],b),void 0=== | ||
| b._stopPropogation&&void 0!==e["*"]&&(p(e["*"],b),void 0===b._stopPropogation&&p(a["*"],b)));void 0===b._stopPropogation&&void 0!==y[c]&&k(y[c],b);void 0===b._stopPropogation&&void 0!==B[c]&&k(B[c],b);void 0===b._stopPropogation&&void 0!==y["*"]&&(k(y["*"],b),void 0===b._stopPropogation&&k(B["*"],b));return void 0!==b._preventDefault?!1:!0};h.injectPrototypeProperty=function(a,c,b,d,f){var e=a.prototype,g=Object.getOwnPropertyDescriptor(e,c);b=b||a.toString().split(/\s+/)[1].split("{")[0].replace("()", | ||
| "");var k=v[b];d=d||J;f=f||H;void 0===e.attrListeners&&(e={},e.attrListeners=function(){void 0===this.__kb&&(this.__kb=new M);return this.__kb}.bind(e),e.addAttrListener=h.addAttrListener,e.addAttrUpdateListener=h.addAttrUpdateListener,e.addChildAttrListener=N,e.addChildAttrUpdateListener=O,e.hasListener=P,e.removeAttrListener=h.removeAttrListener,e.removeAttrUpdateListener=h.removeAttrUpdateListener,e.removeChildAttrListener=V,e.removeChildAttrUpdateListener=W,e.stopChange=Q);void 0===k&&(v[b]={obj:a, | ||
| proto:e,descriptors:{},set:void 0,update:void 0},k=v[b],k.set=d,k.update=f);void 0===k.descriptors[c]&&(k.descriptors[c]=g);g.configurable&&(void 0!==g.set?Object.defineProperty(e,c,{get:g.get,set:R(g,c,d,f),enumerable:!0,configurable:!0}):"function"===typeof g.value?Object.defineProperty(e,c,{value:T(g,c,d,f),writable:!0,enumerable:!0,configurable:!0}):void 0!==g.value&&Object.defineProperty(e,c,{get:function(){return g.value},set:S(g,c,d,f),enumerable:!0,configurable:!0}));return h};h.injectStyleProperty= | ||
| function(a,c,b,d){var f=a.style,e=Object.getOwnPropertyDescriptor(f,c),g=a.attrListeners().injectedStyle;b=b||J;d=d||H;void 0===g&&(a.attrListeners().injectedStyle={obj:a,proto:f,descriptors:{},set:void 0,update:void 0},a.attrListeners().injectedStyle.set=b,a.attrListeners().injectedStyle.update=d,g=a.attrListeners().injectedStyle);void 0===g.descriptors[c]&&(g.descriptors[c]=e);e.configurable&&Object.defineProperty(f,c,U(e,c,b,d,a));return h};h.injectPrototypes=function(a,c,b,d){var f=a.prototype; | ||
| c=c||a.toString().split(/\s+/)[1].split("{")[0].replace("()","");var e=v[c],g=Object.getOwnPropertyNames(f);b=b||J;d=d||H;var k;void 0===f.attrListeners&&(f.attrListeners=function(){void 0===this.__kb&&(this.__kb=new M);return this.__kb},f.addAttrListener=h.addAttrListener,f.addAttrUpdateListener=h.addAttrUpdateListener,f.addChildAttrListener=N,f.addChildAttrUpdateListener=O,f.hasListener=P,f.stopChange=Q);void 0===e&&(v[c]={obj:a,proto:f,descriptors:{},set:void 0,update:void 0},e=v[c],e.set=b,e.update= | ||
| d);k=v[c].descriptors;for(d=0;d<g.length;d+=1)void 0===k[g[d]]&&h.injectPrototypeProperty(a,g[d],c,b,H);if(-1!==g.indexOf("value")){var m=function(a){var b,c,d;if("checkbox"===this.type||"radio"===this.type)b=!0;c=b?"string"===typeof this.checked?this.checked:this.checked?"true":"false":this.value;setTimeout(function(){d=b?"string"===typeof this.checked?this.checked:this.checked?"true":"false":this.value;b&&(e.set(this,"checked",this.checked,c)?e.update(this,"checked",this.checked,c):k.checked.set.call(this, | ||
| c));this.value=d;e.set(this,"value",this.value,c)?e.update(this,"value",this.checked,c):k.value.set.call(this,c)}.bind(this),0)};f.removeInputBinding=function(){this.attrListeners()._onkeydown=void 0;this.removeEventListener("keydown",m)};f.addInputBinding=function(){this.attrListeners()._onkeydown=!0;this.addEventListener("keydown",m)};f.removeInputBoxBinding=function(){this.attrListeners()._onmousedown=void 0;this.removeEventListener("mouseup",m)};f.addInputBoxBinding=function(){this.attrListeners()._onmousedown= | ||
| !0;this.addEventListener("mouseup",m)}}return h};h.addAttrListener=function(a,c,b){if("html"===a){a=0;for(var d=t.length;a<d;a++)E.call(this,t[a],c,b,!1)}else if("events"===a)for(a=0,d=D.length;a<d;a++)E.call(this,D[a],c,b,!1);else E.call(this,a,c,b,!1);return h};h.addAttrUpdateListener=function(a,c,b){if("html"===a){a=0;for(var d=t.length;a<d;a++)E.call(this,t[a],c,b,!0)}else if("events"===a)for(a=0,d=D.length;a<d;a++)E.call(this,D[a],c,b,!0);else E.call(this,a,c,b,!0);return h};h.removeAttrListener= | ||
| function(a,c,b){if("html"===a){a=0;for(var d=t.length;a<d;a++)F.call(this,t[a],c,b,!1)}else if("events"===a)for(a=0,d=D.length;a<d;a++)F.call(this,D[a],c,b,!1);else F.call(this,a,c,b,!1);return h};h.removeAttrUpdateListener=function(a,c,b){if("html"===a){a=0;for(var d=t.length;a<d;a++)F.call(this,t[a],c,b,!0)}else if("events"===a)for(a=0,d=D.length;a<d;a++)F.call(this,D[a],c,b,!0);else F.call(this,a,c,b,!0);return h};h.hasListener=function(a,c,b){"html"===c&&(c="innerHTML");"events"===c&&(c="onclick"); | ||
| switch(a){case "attr":if(I(z[c],b))return!0;break;case "attrupdate":if(I(y[c],b))return!0}return!1};h.injectedPrototypes=function(){return v};return h}"function"===typeof define&&define.amd&&define("KB",G);return G}();window.define&&window.require?define([],function(){return G}):window.module&&(module.exports=G);return G}(); |
+1
-1
| { | ||
| "name": "KB", | ||
| "version": "0.7.1", | ||
| "version": "0.7.2", | ||
| "description": "A Dom Attributes Binding and Event Listener Library", | ||
@@ -5,0 +5,0 @@ "keywords": [ |
6707752
0.03%1392
1.75%