source: OKFNAnnotator (for Zope)/annotator_files/lib/class.js @ 4:6979313586cf

Last change on this file since 4:6979313586cf was 4:6979313586cf, checked in by casties, 12 years ago

new version of annotator.

File size: 2.8 KB
Line 
1// Generated by CoffeeScript 1.3.3
2var Delegator,
3  __slice = [].slice,
4  __hasProp = {}.hasOwnProperty;
5
6Delegator = (function() {
7
8  Delegator.prototype.events = {};
9
10  Delegator.prototype.options = {};
11
12  Delegator.prototype.element = null;
13
14  function Delegator(element, options) {
15    this.options = $.extend(true, {}, this.options, options);
16    this.element = $(element);
17    this.on = this.subscribe;
18    this.addEvents();
19  }
20
21  Delegator.prototype.addEvents = function() {
22    var event, functionName, sel, selector, _i, _ref, _ref1, _results;
23    _ref = this.events;
24    _results = [];
25    for (sel in _ref) {
26      functionName = _ref[sel];
27      _ref1 = sel.split(' '), selector = 2 <= _ref1.length ? __slice.call(_ref1, 0, _i = _ref1.length - 1) : (_i = 0, []), event = _ref1[_i++];
28      _results.push(this.addEvent(selector.join(' '), event, functionName));
29    }
30    return _results;
31  };
32
33  Delegator.prototype.addEvent = function(bindTo, event, functionName) {
34    var closure, isBlankSelector,
35      _this = this;
36    closure = function() {
37      return _this[functionName].apply(_this, arguments);
38    };
39    isBlankSelector = typeof bindTo === 'string' && bindTo.replace(/\s+/g, '') === '';
40    if (isBlankSelector) {
41      bindTo = this.element;
42    }
43    if (typeof bindTo === 'string') {
44      this.element.delegate(bindTo, event, closure);
45    } else {
46      if (this.isCustomEvent(event)) {
47        this.subscribe(event, closure);
48      } else {
49        $(bindTo).bind(event, closure);
50      }
51    }
52    return this;
53  };
54
55  Delegator.prototype.isCustomEvent = function(event) {
56    event = event.split('.')[0];
57    return $.inArray(event, Delegator.natives) === -1;
58  };
59
60  Delegator.prototype.publish = function() {
61    this.element.triggerHandler.apply(this.element, arguments);
62    return this;
63  };
64
65  Delegator.prototype.subscribe = function(event, callback) {
66    var closure;
67    closure = function() {
68      return callback.apply(this, [].slice.call(arguments, 1));
69    };
70    closure.guid = callback.guid = ($.guid += 1);
71    this.element.bind(event, closure);
72    return this;
73  };
74
75  Delegator.prototype.unsubscribe = function() {
76    this.element.unbind.apply(this.element, arguments);
77    return this;
78  };
79
80  return Delegator;
81
82})();
83
84Delegator.natives = (function() {
85  var key, specials, val;
86  specials = (function() {
87    var _ref, _results;
88    _ref = jQuery.event.special;
89    _results = [];
90    for (key in _ref) {
91      if (!__hasProp.call(_ref, key)) continue;
92      val = _ref[key];
93      _results.push(key);
94    }
95    return _results;
96  })();
97  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);
98})();
Note: See TracBrowser for help on using the repository browser.