a-template
Advanced tools
Comparing version 0.6.0 to 0.6.1
@@ -34,2 +34,3 @@ 'use strict'; | ||
this.atemplate = []; | ||
this.events = []; | ||
if (opt) { | ||
@@ -82,2 +83,7 @@ Object.keys(opt).forEach(function (key) { | ||
}); | ||
this.events.push({ | ||
element: ele, | ||
selector: '[data-bind]', | ||
event: bindType | ||
}); | ||
} | ||
@@ -116,4 +122,16 @@ }, { | ||
}); | ||
this.events.push({ | ||
element: ele, | ||
selector: dataAction, | ||
event: bindType | ||
}); | ||
} | ||
}, { | ||
key: 'removeTemplateEvents', | ||
value: function removeTemplateEvents() { | ||
this.events.forEach(function (event) { | ||
(0, _util.off)(event.element, event.selector, event.event); | ||
}); | ||
} | ||
}, { | ||
key: 'addTemplate', | ||
@@ -120,0 +138,0 @@ value: function addTemplate(id, html) { |
@@ -30,7 +30,10 @@ 'use strict'; | ||
var listenerList = []; | ||
var on = exports.on = function on(element, query, eventNames, fn) { | ||
var capture = arguments.length > 4 && arguments[4] !== undefined ? arguments[4] : false; | ||
var events = eventNames.split(' '); | ||
events.forEach(function (event) { | ||
element.addEventListener(event, function (e) { | ||
var target = e.target; | ||
var listener = function listener(e) { | ||
var delegateTarget = findAncestor(e.target, query); | ||
@@ -41,4 +44,18 @@ if (delegateTarget) { | ||
} | ||
}; | ||
listenerList.push({ listener: listener, element: element, query: query, event: event, capture: capture }); | ||
element.addEventListener(event, listener, capture); | ||
}); | ||
}; | ||
var off = exports.off = function off(element, query, eventNames) { | ||
var events = eventNames.split(' '); | ||
events.forEach(function (event) { | ||
listenerList.forEach(function (item, index) { | ||
if (item.element === element && item.query === query && item.event === event) { | ||
element.removeEventListener(event, item.listener, item.capture); | ||
listenerList.splice(index, 1); | ||
} | ||
}); | ||
}); | ||
}; |
{ | ||
"name": "a-template", | ||
"version": "0.6.0", | ||
"version": "0.6.1", | ||
"author": "steelydylan", | ||
@@ -5,0 +5,0 @@ "description": "Simple Template Engine", |
259745
2465