|
|
@ -1,7 +1,6 @@ |
|
|
var Backbone = require('backbone'); |
|
|
const ItemView = require('./ItemView'); |
|
|
var ItemView = require('./ItemView'); |
|
|
|
|
|
|
|
|
|
|
|
module.exports = Backbone.View.extend({ |
|
|
module.exports = require('backbone').View.extend({ |
|
|
initialize(o = {}) { |
|
|
initialize(o = {}) { |
|
|
this.opt = o; |
|
|
this.opt = o; |
|
|
const config = o.config || {}; |
|
|
const config = o.config || {}; |
|
|
@ -11,33 +10,33 @@ module.exports = Backbone.View.extend({ |
|
|
this.ppfx = config.pStylePrefix || ''; |
|
|
this.ppfx = config.pStylePrefix || ''; |
|
|
this.pfx = config.stylePrefix || ''; |
|
|
this.pfx = config.stylePrefix || ''; |
|
|
this.parent = o.parent; |
|
|
this.parent = o.parent; |
|
|
this.listenTo(this.collection, 'add', this.addTo); |
|
|
const pfx = this.pfx; |
|
|
this.listenTo(this.collection, 'reset resetNavigator', this.render); |
|
|
const ppfx = this.ppfx; |
|
|
this.className = this.pfx + 'items'; |
|
|
const parent = this.parent; |
|
|
|
|
|
const coll = this.collection; |
|
|
|
|
|
this.listenTo(coll, 'add', this.addTo); |
|
|
|
|
|
this.listenTo(coll, 'reset resetNavigator', this.render); |
|
|
|
|
|
this.className = `${pfx}layers`; |
|
|
|
|
|
|
|
|
if (config.sortable && !this.opt.sorter) { |
|
|
if (config.sortable && !this.opt.sorter) { |
|
|
var pfx = this.pfx; |
|
|
const utils = config.em.get('Utils'); |
|
|
var utils = config.em.get('Utils'); |
|
|
|
|
|
this.opt.sorter = new utils.Sorter({ |
|
|
this.opt.sorter = new utils.Sorter({ |
|
|
container: config.sortContainer || this.el, |
|
|
container: config.sortContainer || this.el, |
|
|
containerSel: '.' + pfx + 'items', |
|
|
containerSel: `.${this.className}`, |
|
|
itemSel: '.' + pfx + 'item', |
|
|
itemSel: `.${pfx}layer`, |
|
|
ppfx: this.ppfx, |
|
|
|
|
|
ignoreViewChildren: 1, |
|
|
ignoreViewChildren: 1, |
|
|
avoidSelectOnEnd: 1, |
|
|
avoidSelectOnEnd: 1, |
|
|
pfx, |
|
|
nested: 1, |
|
|
nested: 1 |
|
|
ppfx, |
|
|
|
|
|
pfx |
|
|
}); |
|
|
}); |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
this.sorter = this.opt.sorter || ''; |
|
|
this.sorter = this.opt.sorter || ''; |
|
|
|
|
|
|
|
|
// For the sorter
|
|
|
// For the sorter
|
|
|
this.$el.data('collection', this.collection); |
|
|
this.$el.data('collection', coll); |
|
|
|
|
|
parent && this.$el.data('model', parent); |
|
|
if (this.parent) { |
|
|
|
|
|
this.$el.data('model', this.parent); |
|
|
|
|
|
} |
|
|
|
|
|
}, |
|
|
}, |
|
|
|
|
|
|
|
|
/** |
|
|
/** |
|
|
@ -123,10 +122,11 @@ module.exports = Backbone.View.extend({ |
|
|
|
|
|
|
|
|
render() { |
|
|
render() { |
|
|
const frag = document.createDocumentFragment(); |
|
|
const frag = document.createDocumentFragment(); |
|
|
this.el.innerHTML = ''; |
|
|
const el = this.el; |
|
|
|
|
|
el.innerHTML = ''; |
|
|
this.collection.each(model => this.addToCollection(model, frag)); |
|
|
this.collection.each(model => this.addToCollection(model, frag)); |
|
|
this.el.appendChild(frag); |
|
|
el.appendChild(frag); |
|
|
this.$el.attr('class', this.className); |
|
|
el.className = this.className; |
|
|
return this; |
|
|
return this; |
|
|
} |
|
|
} |
|
|
}); |
|
|
}); |
|
|
|