mirror of
https://github.com/futurepress/epub.js.git
synced 2025-10-03 14:59:18 +02:00
Added several usage examples, fixed bugs, turned off restore by default
This commit is contained in:
parent
0e08b734ec
commit
416f7ab6a0
112 changed files with 23903 additions and 3348 deletions
132
libs/annotator/lib/class.js
Normal file
132
libs/annotator/lib/class.js
Normal file
|
@ -0,0 +1,132 @@
|
|||
// Generated by CoffeeScript 1.6.3
|
||||
var Delegator,
|
||||
__slice = [].slice,
|
||||
__hasProp = {}.hasOwnProperty;
|
||||
|
||||
Delegator = (function() {
|
||||
Delegator.prototype.events = {};
|
||||
|
||||
Delegator.prototype.options = {};
|
||||
|
||||
Delegator.prototype.element = null;
|
||||
|
||||
function Delegator(element, options) {
|
||||
this.options = $.extend(true, {}, this.options, options);
|
||||
this.element = $(element);
|
||||
this._closures = {};
|
||||
this.on = this.subscribe;
|
||||
this.addEvents();
|
||||
}
|
||||
|
||||
Delegator.prototype.addEvents = function() {
|
||||
var event, _i, _len, _ref, _results;
|
||||
_ref = Delegator._parseEvents(this.events);
|
||||
_results = [];
|
||||
for (_i = 0, _len = _ref.length; _i < _len; _i++) {
|
||||
event = _ref[_i];
|
||||
_results.push(this._addEvent(event.selector, event.event, event.functionName));
|
||||
}
|
||||
return _results;
|
||||
};
|
||||
|
||||
Delegator.prototype.removeEvents = function() {
|
||||
var event, _i, _len, _ref, _results;
|
||||
_ref = Delegator._parseEvents(this.events);
|
||||
_results = [];
|
||||
for (_i = 0, _len = _ref.length; _i < _len; _i++) {
|
||||
event = _ref[_i];
|
||||
_results.push(this._removeEvent(event.selector, event.event, event.functionName));
|
||||
}
|
||||
return _results;
|
||||
};
|
||||
|
||||
Delegator.prototype._addEvent = function(selector, event, functionName) {
|
||||
var closure,
|
||||
_this = this;
|
||||
closure = function() {
|
||||
return _this[functionName].apply(_this, arguments);
|
||||
};
|
||||
if (selector === '' && Delegator._isCustomEvent(event)) {
|
||||
this.subscribe(event, closure);
|
||||
} else {
|
||||
this.element.delegate(selector, event, closure);
|
||||
}
|
||||
this._closures["" + selector + "/" + event + "/" + functionName] = closure;
|
||||
return this;
|
||||
};
|
||||
|
||||
Delegator.prototype._removeEvent = function(selector, event, functionName) {
|
||||
var closure;
|
||||
closure = this._closures["" + selector + "/" + event + "/" + functionName];
|
||||
if (selector === '' && Delegator._isCustomEvent(event)) {
|
||||
this.unsubscribe(event, closure);
|
||||
} else {
|
||||
this.element.undelegate(selector, event, closure);
|
||||
}
|
||||
delete this._closures["" + selector + "/" + event + "/" + functionName];
|
||||
return this;
|
||||
};
|
||||
|
||||
Delegator.prototype.publish = function() {
|
||||
this.element.triggerHandler.apply(this.element, arguments);
|
||||
return this;
|
||||
};
|
||||
|
||||
Delegator.prototype.subscribe = function(event, callback) {
|
||||
var closure;
|
||||
closure = function() {
|
||||
return callback.apply(this, [].slice.call(arguments, 1));
|
||||
};
|
||||
closure.guid = callback.guid = ($.guid += 1);
|
||||
this.element.bind(event, closure);
|
||||
return this;
|
||||
};
|
||||
|
||||
Delegator.prototype.unsubscribe = function() {
|
||||
this.element.unbind.apply(this.element, arguments);
|
||||
return this;
|
||||
};
|
||||
|
||||
return Delegator;
|
||||
|
||||
})();
|
||||
|
||||
Delegator._parseEvents = function(eventsObj) {
|
||||
var event, events, functionName, sel, selector, _i, _ref;
|
||||
events = [];
|
||||
for (sel in eventsObj) {
|
||||
functionName = eventsObj[sel];
|
||||
_ref = sel.split(' '), selector = 2 <= _ref.length ? __slice.call(_ref, 0, _i = _ref.length - 1) : (_i = 0, []), event = _ref[_i++];
|
||||
events.push({
|
||||
selector: selector.join(' '),
|
||||
event: event,
|
||||
functionName: functionName
|
||||
});
|
||||
}
|
||||
return events;
|
||||
};
|
||||
|
||||
Delegator.natives = (function() {
|
||||
var key, specials, val;
|
||||
specials = (function() {
|
||||
var _ref, _results;
|
||||
_ref = jQuery.event.special;
|
||||
_results = [];
|
||||
for (key in _ref) {
|
||||
if (!__hasProp.call(_ref, key)) continue;
|
||||
val = _ref[key];
|
||||
_results.push(key);
|
||||
}
|
||||
return _results;
|
||||
})();
|
||||
return "blur focus focusin focusout load resize scroll unload click dblclick\nmousedown mouseup mousemove mouseover mouseout mouseenter mouseleave\nchange select submit keydown keypress keyup error".split(/[^a-z]+/).concat(specials);
|
||||
})();
|
||||
|
||||
Delegator._isCustomEvent = function(event) {
|
||||
event = event.split('.')[0];
|
||||
return $.inArray(event, Delegator.natives) === -1;
|
||||
};
|
||||
|
||||
/*
|
||||
//@ sourceMappingURL=class.map
|
||||
*/
|
Loading…
Add table
Add a link
Reference in a new issue