Browse Source

Make the panel be another element via `el` attribute

pull/856/head
Artur Arseniev 8 years ago
parent
commit
e43b36bc1b
  1. 12
      src/panels/view/PanelView.js
  2. 32
      src/panels/view/PanelsView.js

12
src/panels/view/PanelView.js

@ -85,20 +85,20 @@ module.exports = Backbone.View.extend({
},
render() {
const el = this.$el;
const pfx = this.ppfx;
el.attr('class', `${this.className} ${pfx}one-bg`);
this.id && el.attr('id', this.id);
const $el = this.$el;
const ppfx = this.ppfx;
const cls = `${this.className} ${this.id} ${ppfx}one-bg`;
$el.addClass(cls);
if (this.buttons.length) {
var buttons = new ButtonsView({
collection: this.buttons,
config: this.config
});
el.append(buttons.render().el);
$el.append(buttons.render().el);
}
el.append(this.model.get('content'));
$el.append(this.model.get('content'));
return this;
}
});

32
src/panels/view/PanelsView.js

@ -32,15 +32,20 @@ module.exports = Backbone.View.extend({
* @private
* */
addToCollection(model, fragmentEl) {
var fragment = fragmentEl || null;
var view = new PanelView({
const fragment = fragmentEl || null;
const config = this.config;
const el = model.get('el');
const view = new PanelView({
el,
model,
config: this.config
config
});
var rendered = view.render().el;
var appendTo = model.get('appendTo');
const rendered = view.render().el;
const appendTo = model.get('appendTo');
if (appendTo) {
// Do nothing if the panel was requested to be another element
if (el) {
} else if (appendTo) {
var appendEl = document.querySelector(appendTo);
appendEl.appendChild(rendered);
} else {
@ -56,15 +61,12 @@ module.exports = Backbone.View.extend({
},
render() {
var fragment = document.createDocumentFragment();
this.$el.empty();
this.collection.each(function(model) {
this.addToCollection(model, fragment);
}, this);
this.$el.append(fragment);
this.$el.attr('class', this.className);
const $el = this.$el;
const frag = document.createDocumentFragment();
$el.empty();
this.collection.each(model => this.addToCollection(model, frag));
$el.append(frag);
$el.attr('class', this.className);
return this;
}
});

Loading…
Cancel
Save