From dd67bdf78864d763021281f957d6d05442ef2296 Mon Sep 17 00:00:00 2001 From: Artur Arseniev Date: Wed, 13 Jul 2016 14:18:35 +0200 Subject: [PATCH] Fix tests --- src/canvas/view/CanvasView.js | 5 ++-- src/class_manager/view/ClassTagsView.js | 4 ++- src/commands/view/CommandAbstract.js | 13 +++++----- src/panels/main.js | 10 ++++---- src/panels/view/ButtonView.js | 25 ++++++++++--------- .../dom_components/view/ComponentImageView.js | 2 +- 6 files changed, 32 insertions(+), 27 deletions(-) diff --git a/src/canvas/view/CanvasView.js b/src/canvas/view/CanvasView.js index ebf8d182a..6cb8c4ed0 100644 --- a/src/canvas/view/CanvasView.js +++ b/src/canvas/view/CanvasView.js @@ -6,6 +6,7 @@ function(Backbone, FrameView) { return Backbone.View.extend({ initialize: function(o) { + _.bindAll(this, 'renderBody', 'onFrameScroll'); this.config = o.config || {}; this.em = this.config.em || {}; this.ppfx = this.config.pStylePrefix || ''; @@ -47,7 +48,7 @@ function(Backbone, FrameView) { if(protCss) body.append(''); this.config.em.trigger('loaded'); - this.frame.el.contentWindow.onscroll = this.onFrameScroll.bind(this); + this.frame.el.contentWindow.onscroll = this.onFrameScroll; // When the iframe is focused the event dispatcher is not the same so // I need to delegate all events to the parent document @@ -105,7 +106,7 @@ function(Backbone, FrameView) { this.model.get('frame').set('wrapper', this.wrapper); this.$el.append(this.frame.render().el); var frame = this.frame; - frame.el.onload = this.renderBody.bind(this); + frame.el.onload = this.renderBody; } this.toolsEl = $('
', { id: this.ppfx + 'tools' }).get(0); this.hlEl = $('
', { class: this.ppfx + 'highlighter' }).get(0); diff --git a/src/class_manager/view/ClassTagsView.js b/src/class_manager/view/ClassTagsView.js index 5663151fc..45951ccaa 100644 --- a/src/class_manager/view/ClassTagsView.js +++ b/src/class_manager/view/ClassTagsView.js @@ -136,7 +136,9 @@ define(['backbone', 'text!./../template/classTags.html', './ClassTagView'], }); var state = this.compTarget.get('state'); result = state ? result + ':' + state : result; - this.el.querySelector('#' + this.pfx + 'sel').innerHTML = result; + var el = this.el.querySelector('#' + this.pfx + 'sel'); + if(el) + el.innerHTML = result; }, /** diff --git a/src/commands/view/CommandAbstract.js b/src/commands/view/CommandAbstract.js index c74deb53f..163081996 100644 --- a/src/commands/view/CommandAbstract.js +++ b/src/commands/view/CommandAbstract.js @@ -28,14 +28,15 @@ define(['backbone'], if(this.editorModel.get) this.setElement(this.getCanvas()); - this.$canvas = this.$el; - this.$wrapper = $(this.getCanvasWrapper()); + if(this.canvas){ + this.$canvas = this.$el; + this.$wrapper = $(this.getCanvasWrapper()); + this.frameEl = this.canvas.getFrameEl(); + this.canvasTool = this.getCanvasTools(); + this.bodyEl = this.getCanvasBody(); + } this.init(this.config); - - this.frameEl = this.canvas.getFrameEl(); - this.canvasTool = this.getCanvasTools(); - this.bodyEl = this.getCanvasBody(); }, /** diff --git a/src/panels/main.js b/src/panels/main.js index 43760fbb2..10547bd62 100644 --- a/src/panels/main.js +++ b/src/panels/main.js @@ -100,7 +100,7 @@ define(function(require) { * @example * var myPanel = panelManager.getPanel('myNewPanel'); */ - getPanel : function(id){ + getPanel: function(id){ var res = panels.where({id: id}); return res.length ? res[0] : null; }, @@ -119,7 +119,7 @@ define(function(require) { * active: false, * }); */ - addButton : function(panelId, button){ + addButton: function(panelId, button){ var pn = this.getPanel(panelId); return pn ? pn.get('buttons').add(button) : null; }, @@ -132,7 +132,7 @@ define(function(require) { * @example * var button = panelManager.getButton('myPanel','myButton'); */ - getButton : function(panelId, id){ + getButton: function(panelId, id){ var pn = this.getPanel(panelId); if(pn){ var res = pn.get('buttons').where({id: id}); @@ -145,7 +145,7 @@ define(function(require) { * Render panels and buttons * @return {HTMLElement} */ - render : function(){ + render: function(){ return PanelsViewObj.render().el; }, @@ -153,7 +153,7 @@ define(function(require) { * Active activable buttons * @private */ - active : function(){ + active: function(){ this.getPanels().each(function(p){ p.get('buttons').each(function(btn){ if(btn.get('active')) diff --git a/src/panels/view/ButtonView.js b/src/panels/view/ButtonView.js index 6505f2e1d..c3c73f8c0 100644 --- a/src/panels/view/ButtonView.js +++ b/src/panels/view/ButtonView.js @@ -41,18 +41,19 @@ function(Backbone, require) { this.events.click = 'clicked'; this.delegateEvents(); - this.canvasEl = this.em.Canvas.CanvasView.$el.get(0); - - this.sorter = new this.em.Utils.Sorter({ - container: this.canvasEl, - containerSel: '*', - itemSel: '*', - pfx: this.ppfx, - onMove: this.onDrag, - onEndMove: this.onDrop, - direction: 'auto', - nested: 1, - }); + if(this.em.Canvas){ + this.canvasEl = this.em.Canvas.getElement(); + this.sorter = new this.em.Utils.Sorter({ + container: this.canvasEl, + containerSel: '*', + itemSel: '*', + pfx: this.ppfx, + onMove: this.onDrag, + onEndMove: this.onDrop, + direction: 'auto', + nested: 1, + }); + } }, /** diff --git a/test/specs/dom_components/view/ComponentImageView.js b/test/specs/dom_components/view/ComponentImageView.js index bd55f75cb..dd5324bb2 100644 --- a/test/specs/dom_components/view/ComponentImageView.js +++ b/test/specs/dom_components/view/ComponentImageView.js @@ -35,7 +35,7 @@ define([path + 'ComponentImageView', 'DomComponents/model/Component'], }); it('Component empty', function() { - $fixture.html().should.equal(''); + $fixture.html().should.equal(''); }); it('TagName is ', function() {