Browse Source

Update move and select commands

pull/36/head
Artur Arseniev 10 years ago
parent
commit
5a6dae3b47
  1. 4
      src/commands/view/MoveComponent.js
  2. 47
      src/commands/view/SelectComponent.js

4
src/commands/view/MoveComponent.js

@ -13,7 +13,7 @@ define(['backbone', './SelectComponent','./SelectPosition'],
}, },
enable: function(){ enable: function(){
this.frameEl.contentWindow.onscroll = this.onFrameScroll.bind(this); _.bindAll(this, 'onFrameScroll');
this.$el.css('cursor','move'); this.$el.css('cursor','move');
this.$el.on('mousedown', this.initSorter); this.$el.on('mousedown', this.initSorter);
this.startSelectComponent(); this.startSelectComponent();
@ -77,11 +77,11 @@ define(['backbone', './SelectComponent','./SelectPosition'],
stop: function(){ stop: function(){
this.stopSelectComponent(); this.stopSelectComponent();
this.hideBadge();
this.$badge = $(this.getBadge()); this.$badge = $(this.getBadge());
this.$badge.removeClass(this.badgeClass); this.$badge.removeClass(this.badgeClass);
this.$hl = $(this.canvas.getHighlighter()); this.$hl = $(this.canvas.getHighlighter());
this.$hl.removeClass(this.hoverClass); this.$hl.removeClass(this.hoverClass);
this.frameEl.contentWindow.onscroll = null;
this.$el.css('cursor','');//changes back aspect of the cursor this.$el.css('cursor','');//changes back aspect of the cursor
this.$el.unbind();//removes all attached events this.$el.unbind();//removes all attached events
this.$el.removeClass(this.noSelClass); this.$el.removeClass(this.noSelClass);

47
src/commands/view/SelectComponent.js

@ -11,17 +11,14 @@ define(function() {
enable: function() { enable: function() {
_.bindAll(this,'copyComp','pasteComp'); _.bindAll(this,'copyComp', 'pasteComp', 'onFrameScroll');
this.frameEl.contentWindow.onscroll = this.onFrameScroll.bind(this);
var config = this.config.em.get('Config'); var config = this.config.em.get('Config');
this.startSelectComponent(); this.startSelectComponent();
// TODO refactor // TODO refactor
if(config.copyPaste){ if(config.copyPaste){
key('⌘+c, ctrl+c', this.copyComp); key('⌘+c, ctrl+c', this.copyComp);
key('⌘+v, ctrl+v', this.pasteComp); key('⌘+v, ctrl+v', this.pasteComp);
} }
this.listenTo(this.em.editor, 'change:device', this.clearOff); this.listenTo(this.em.editor, 'change:device', this.clearOff);
}, },
@ -63,11 +60,23 @@ define(function() {
* @private * @private
* */ * */
startSelectComponent: function() { startSelectComponent: function() {
this.getContentWindow().on('scroll', this.onFrameScroll);
this.selEl = $(this.getCanvasBody()).find('*'); this.selEl = $(this.getCanvasBody()).find('*');
this.selEl.on('mouseover',this.onHover) this.selEl.on('mouseover',this.onHover)
.on('mouseout', this.onOut) .on('mouseout', this.onOut)
.on('click', this.onClick); .on('click', this.onClick);
$(this.frameEl.contentWindow).on('keydown', this.onKeyPress); this.getContentWindow().on('keydown', this.onKeyPress);
},
/**
* Stop select component event
* @private
* */
stopSelectComponent: function() {
this.getContentWindow().off('scroll', this.onFrameScroll);
if(this.selEl)
this.selEl.trigger('mouseout').off('mouseover mouseout click');
this.selEl = null;
}, },
/** /**
@ -149,16 +158,6 @@ define(function() {
this.hl.css({ left: elPos.left, top: elPos.topP, height: elPos.height, width: elPos.width }); this.hl.css({ left: elPos.left, top: elPos.topP, height: elPos.height, width: elPos.width });
}, },
/** Stop select component event
* @param Event
* @private
* */
stopSelectComponent: function(e) {
if(this.selEl)
this.selEl.trigger('mouseout').off('mouseover mouseout click');
this.selEl = null;
},
/** /**
* Say what to do after the component was selected * Say what to do after the component was selected
* @param {Object} e * @param {Object} e
@ -223,8 +222,7 @@ define(function() {
* @private * @private
*/ */
onFrameScroll: function(e){ onFrameScroll: function(e){
this.canvasTool.style.top = '-' + this.bodyEl.scrollTop + 'px'; console.log('scrolling');
this.canvasTool.style.left = '-' + this.bodyEl.scrollLeft + 'px';
if(this.cacheEl) if(this.cacheEl)
this.updateBadge(this.cacheEl); this.updateBadge(this.cacheEl);
}, },
@ -275,6 +273,16 @@ define(function() {
}); });
}, },
/**
* Returns content window
* @private
*/
getContentWindow: function(){
if(!this.contWindow)
this.contWindow = $(this.frameEl.contentWindow);
return this.contWindow;
},
run: function(em, sender) { run: function(em, sender) {
this.em = em; this.em = em;
this.enable(); this.enable();
@ -287,7 +295,6 @@ define(function() {
this.frameOff = this.canvasOff = this.adjScroll = null; this.frameOff = this.canvasOff = this.adjScroll = null;
var frameEl = this.canvas.getFrameEl(); var frameEl = this.canvas.getFrameEl();
frameEl.contentWindow.onscroll = null;
var sel = this.editorModel.get('selectedComponent'); var sel = this.editorModel.get('selectedComponent');
if(sel) if(sel)
this.cleanPrevious(sel); this.cleanPrevious(sel);
@ -298,7 +305,9 @@ define(function() {
this.editorModel.set('selectedComponent',null); this.editorModel.set('selectedComponent',null);
key.unbind('⌘+c, ctrl+c'); key.unbind('⌘+c, ctrl+c');
key.unbind('⌘+v, ctrl+v'); key.unbind('⌘+v, ctrl+v');
$(this.frameEl.contentWindow).off('keydown', this.onKeyPress); var cw = this.getContentWindow();
cw.off('keydown', this.onKeyPress);
this.stopSelectComponent();
} }
}; };
}); });
Loading…
Cancel
Save