This repository has been archived by the owner on Jan 6, 2019. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 3
/
backbone.widget.js
72 lines (59 loc) · 2.02 KB
/
backbone.widget.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
// Generated by CoffeeScript 1.6.2
/*
Backbone.Widget
https://github.com/meleyal/backbone.widget
Copyright (c) 2013 William Meleyal
MIT License
*/
(function() {
var _ref,
__bind = function(fn, me){ return function(){ return fn.apply(me, arguments); }; },
__hasProp = {}.hasOwnProperty,
__extends = function(child, parent) { for (var key in parent) { if (__hasProp.call(parent, key)) child[key] = parent[key]; } function ctor() { this.constructor = child; } ctor.prototype = parent.prototype; child.prototype = new ctor(); child.__super__ = parent.prototype; return child; };
Backbone.Widget = (function(_super) {
__extends(Widget, _super);
function Widget() {
this.remove = __bind(this.remove, this); _ref = Widget.__super__.constructor.apply(this, arguments);
return _ref;
}
Widget.exportWidget = function(namespace) {
var klass;
klass = this;
return $.fn[namespace] = function(options) {
if (options == null) {
options = {};
}
return this.each(function(idx, el) {
return klass.install(el, options, namespace);
});
};
};
Widget.install = function(el, options, namespace) {
var instance, klass;
klass = this;
if (instance = $(el).data(namespace)) {
if (options && typeof options === 'string') {
return instance[options].call(klass);
} else {
return instance;
}
} else {
options = _.extend(options, {
el: el,
namespace: namespace
});
instance = new klass(options);
$(el).data(namespace, instance);
this.removeEvent = Backbone.Widget.removeEvent;
if (this.removeEvent) {
return $(document).on(this.removeEvent, instance.remove);
}
}
};
Widget.prototype.remove = function() {
$(document).off(this.removeEvent, this.remove);
return Widget.__super__.remove.apply(this, arguments);
};
return Widget;
})(Backbone.View);
}).call(this);