-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbackbone.renderer.js
More file actions
100 lines (84 loc) · 2.91 KB
/
Copy pathbackbone.renderer.js
File metadata and controls
100 lines (84 loc) · 2.91 KB
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
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
// Generated by CoffeeScript 1.3.1
(function() {
var Backbone, _,
__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; };
if (typeof require !== "undefined" && require !== null) {
Backbone = require("backbone");
_ = require("underscore");
} else {
Backbone = window.Backbone;
_ = window._;
}
Backbone.View = (function(_super) {
__extends(View, _super);
View.name = 'View';
_.extend(View.prototype, Backbone.Ancestry);
function View(options) {
var _ref;
if ((options != null ? (_ref = options.model) != null ? _ref.retain : void 0 : void 0) != null) {
options.model.retain(this);
}
this.insertedElements = {};
View.__super__.constructor.apply(this, arguments);
}
View.prototype.insertElement = function(tag, element) {
var index;
index = _.uniqueId("inserted_view_");
this.insertedElements[index] = element;
return "<" + tag + " data-inserted-view='" + index + "'></" + tag + ">";
};
View.prototype.insertEachElement = function(elements) {
var _this = this;
return _.map(elements, function(_arg) {
var element, tag;
tag = _arg[0], element = _arg[1];
return _this.insertElement(tag, element);
}).join("\n");
};
View.prototype.insertView = function(view) {
return this.insertElement(view.tagName, view.el);
};
View.prototype.insertEachView = function(views) {
return this.insertEachElement(_.map(views, function(view) {
return [view.tagName, view.el];
}));
};
View.prototype.remove = function() {
var _ref;
this.trigger("removing");
if (((_ref = this.model) != null ? _ref.release : void 0) != null) {
this.model.release(this);
}
View.__super__.remove.apply(this, arguments);
this.off();
this.eachChild(function(c) {
return c.remove();
});
if (this.hasParent()) {
this.getParent().removeChild(this);
}
return this;
};
View.prototype.render = function() {
var _this = this;
this.trigger("rendering");
_.each(this.insertedElements, function(el) {
return $(el).detach();
});
this.insertedElements = {};
this.$el.html(this.renderer());
this.delegateEvents();
this.trigger("rendered");
_.each(this.insertedElements, function(el, index) {
return _this.$("[data-inserted-view='" + index + "']").replaceWith(el);
});
this.trigger("populated");
return this;
};
View.prototype.renderer = function() {
return "MISSING IMPLEMENTATION";
};
return View;
})(Backbone.View);
}).call(this);