From 253d0011abaef030dca306ba6c1f037cc0421226 Mon Sep 17 00:00:00 2001 From: Artur Arseniev Date: Sat, 3 Feb 2018 15:18:16 +0100 Subject: [PATCH] Refactor ItemsView --- src/navigator/index.js | 2 -- src/navigator/view/ItemView.js | 11 ++++----- src/navigator/view/ItemsView.js | 42 ++++++++++++++++----------------- 3 files changed, 25 insertions(+), 30 deletions(-) diff --git a/src/navigator/index.js b/src/navigator/index.js index 93f3c5ab5..0f787be83 100644 --- a/src/navigator/index.js +++ b/src/navigator/index.js @@ -37,7 +37,6 @@ module.exports = () => { options.collection = collection; } - console.log('options', options); layers = new View(options); em && em.on('component:selected', this.componentChanged); this.componentChanged(); @@ -79,7 +78,6 @@ module.exports = () => { }, render() { - console.log('render layers'); return layers.render().el; } }; diff --git a/src/navigator/view/ItemView.js b/src/navigator/view/ItemView.js index cfbe0275d..ab9a9225b 100644 --- a/src/navigator/view/ItemView.js +++ b/src/navigator/view/ItemView.js @@ -204,13 +204,10 @@ module.exports = require('backbone').View.extend({ * */ startSort(e) { e.stopPropagation(); - - //Right or middel click - if (e.button !== 0) { - return; - } - - this.sorter && this.sorter.startSort(e.target); + const sorter = this.sorter; + // Right or middel click + if (e.button !== 0) return; + sorter && sorter.startSort(e.target); }, /** diff --git a/src/navigator/view/ItemsView.js b/src/navigator/view/ItemsView.js index b14b54a66..1cfdb9492 100644 --- a/src/navigator/view/ItemsView.js +++ b/src/navigator/view/ItemsView.js @@ -1,7 +1,6 @@ -var Backbone = require('backbone'); -var ItemView = require('./ItemView'); +const ItemView = require('./ItemView'); -module.exports = Backbone.View.extend({ +module.exports = require('backbone').View.extend({ initialize(o = {}) { this.opt = o; const config = o.config || {}; @@ -11,33 +10,33 @@ module.exports = Backbone.View.extend({ this.ppfx = config.pStylePrefix || ''; this.pfx = config.stylePrefix || ''; this.parent = o.parent; - this.listenTo(this.collection, 'add', this.addTo); - this.listenTo(this.collection, 'reset resetNavigator', this.render); - this.className = this.pfx + 'items'; + const pfx = this.pfx; + const ppfx = this.ppfx; + 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) { - var pfx = this.pfx; - var utils = config.em.get('Utils'); + const utils = config.em.get('Utils'); this.opt.sorter = new utils.Sorter({ container: config.sortContainer || this.el, - containerSel: '.' + pfx + 'items', - itemSel: '.' + pfx + 'item', - ppfx: this.ppfx, + containerSel: `.${this.className}`, + itemSel: `.${pfx}layer`, ignoreViewChildren: 1, avoidSelectOnEnd: 1, - pfx, - nested: 1 + nested: 1, + ppfx, + pfx }); } this.sorter = this.opt.sorter || ''; // For the sorter - this.$el.data('collection', this.collection); - - if (this.parent) { - this.$el.data('model', this.parent); - } + this.$el.data('collection', coll); + parent && this.$el.data('model', parent); }, /** @@ -123,10 +122,11 @@ module.exports = Backbone.View.extend({ render() { const frag = document.createDocumentFragment(); - this.el.innerHTML = ''; + const el = this.el; + el.innerHTML = ''; this.collection.each(model => this.addToCollection(model, frag)); - this.el.appendChild(frag); - this.$el.attr('class', this.className); + el.appendChild(frag); + el.className = this.className; return this; } });