JSFiddle - React, Tailwind, and code Playground
HTML
<ul>
<li class="added">
<div class='remove-timework'> DDDDDDDDDD </div>
<div class='add-timework'> DDDDDDDDDD </div>
</li>
</ul>
JavaScript
function SimpleView (el) {
this.$el = $(el);
this.init();
}
SimpleView.prototype = {
constructor: SimpleView,
/**
* @protected
*/
_delegateEventSplitter: /^(\S+)\s*(.*)$/,
init: function () {
this.delegateEvents();
},
$: function (selector) {
return this.$el.find(selector);
},
delegateEvents: function() {
var events = this.events;
this.undelegateEvents();
for (var key in events) {
var method = events[key];
if (!$.isFunction(method)) method = this[events[key]];
if (!method) continue;
var match = key.match(this._delegateEventSplitter);
this.delegate(match[1], match[2], _.bind(method, this));
}
return this;
},
delegate: function(eventName, selector, listener) {
this.$el.on(eventName + '.delegateEvents', selector, listener);
},
undelegateEvents: function() {
this.$el.off('.delegateEvents');
return this;
},
undelegate: function(eventName, selector, listener) {
this.$el.off(eventName + '.delegateEvents', selector, listener);
}
};
SimpleView.extend = function(protoProps, staticProps) {
var parent = this;
var child;
if (protoProps && _.has(protoProps, 'constructor')) {
child = protoProps.constructor;
} else {
child = function(){ return parent.apply(this, arguments); };
}
$.extend(true, child, parent, staticProps);
var Surrogate = function(){ this.constructor = child; };
Surrogate.prototype = parent.prototype;
child.prototype = new Surrogate;
if (protoProps) _.extend(child.prototype, protoProps);
child.__super__ = parent.prototype;
return child;
};
(function ($) {
var delegateEventSplitter = /^(\S+)\s*(.*)$/;
function undelegateEvents (el) {
el.off('.delegateEvents');
return this;
}
function delegate(eventName, selector,...