Browse Source

Refactor select command

pull/36/head
Artur Arseniev 10 years ago
parent
commit
039fe23f5a
  1. 3
      src/canvas/main.js
  2. 1
      src/canvas/view/CanvasView.js
  3. 76
      src/commands/view/SelectComponent.js
  4. 4
      styles/css/main.css
  5. 2
      styles/scss/main.scss

3
src/canvas/main.js

@ -5,8 +5,7 @@ define(function(require) {
* *
* @return {Object} * @return {Object}
* */ * */
var Canvas = function(config) var Canvas = function(config) {
{
var c = config || {}, var c = config || {},
defaults = require('./config/config'), defaults = require('./config/config'),
Canvas = require('./model/Canvas'), Canvas = require('./model/Canvas'),

1
src/canvas/view/CanvasView.js

@ -18,6 +18,7 @@ function(Backbone, FrameView) {
this.badgeEl = $('<div>', {class: this.ppfx + 'badge'}).get(0); this.badgeEl = $('<div>', {class: this.ppfx + 'badge'}).get(0);
this.toolsEl.appendChild(this.hlEl); this.toolsEl.appendChild(this.hlEl);
this.toolsEl.appendChild(this.hlSelEl); this.toolsEl.appendChild(this.hlSelEl);
this.toolsEl.appendChild(this.badgeEl);
}, },
render: function() { render: function() {

76
src/commands/view/SelectComponent.js

@ -75,7 +75,7 @@ define(function() {
return; return;
comp.set('status',''); comp.set('status','');
comp.destroy(); comp.destroy();
this.removeBadge(); this.hideBadge();
this.clean(); this.clean();
this.editorModel.set('selectedComponent',null); this.editorModel.set('selectedComponent',null);
} }
@ -106,8 +106,7 @@ define(function() {
*/ */
onOut: function(e) { onOut: function(e) {
e.stopPropagation(); e.stopPropagation();
if(this.badge) this.hideBadge();
this.badge.css({ left: -10000, top:-10000 });
if(this.hl) if(this.hl)
this.hl.css({ left: -10000, top:-10000 }); this.hl.css({ left: -10000, top:-10000 });
}, },
@ -182,43 +181,56 @@ define(function() {
* @private * @private
* */ * */
updateBadge: function(el) { updateBadge: function(el) {
console.log('Hover');
var $el = $(el); var $el = $(el);
this.cacheEl = $el; this.cacheEl = $el;
var model = $el.data("model"); var model = $el.data("model");
if(!model || !model.get('badgable')) if(!model || !model.get('badgable'))
return; return;
if(!this.badge) var badge = this.getBadge();
this.createBadge(); badge.innerHTML = model.getName();
this.updateBadgeLabel(model); var bStyle = badge.style;
var elPos = this.getElementPos($el); var u = 'px';
this.badge.css({ left: elPos.left, top: elPos.top }); bStyle.display = 'block';
var elP = this.getElementPos($el, badge);
bStyle.left = elP.left + u;
bStyle.top = elP.top + u;
},
/**
* Returns badge element
* @return {HTMLElement}
* @private
*/
getBadge: function(){
return this.canvas.getBadgeEl();
}, },
/** /**
* On frame scroll callback * On frame scroll callback
* @param {[type]} e [description] * @private
* @return {[type]} [description]
*/ */
onFrameScroll: function(e){ onFrameScroll: function(e){
this.canvasTool.style.top = '-' + this.bodyEl.scrollTop + 'px'; this.canvasTool.style.top = '-' + this.bodyEl.scrollTop + 'px';
var elPos = this.getElementPos(this.cacheEl); if(this.cacheEl){
this.badge.css({ left: elPos.left, top: elPos.top }); this.updateBadge(this.cacheEl);
}
}, },
/** /**
* Returns element's data info * Returns element's data info
* @param {HTMLElement} el * @param {HTMLElement} el
* @return {Object} * @return {Object}
* @private
*/ */
getElementPos: function(el){ getElementPos: function(el, badge){
if(!this.frameOff) if(!this.frameOff)
this.frameOff = this.offset(this.canvas.getFrameEl()); this.frameOff = this.offset(this.canvas.getFrameEl());
if(!this.canvasOff) if(!this.canvasOff)
this.canvasOff = this.offset(this.canvas.getElement()); this.canvasOff = this.offset(this.canvas.getElement());
var eo = el.offset();//this.offset(el); var eo = el.offset();//this.offset(el);
var bodyEl = this.getCanvasBody(); var bodyEl = this.getCanvasBody();
var badgeH = this.badge.outerHeight(); var bdg = badge ? badge : null;
var badgeH = bdg ? bdg.offsetHeight : 0;
var top = eo.top + this.frameOff.top - this.canvasOff.top;// - bodyEl.scrollTop var top = eo.top + this.frameOff.top - this.canvasOff.top;// - bodyEl.scrollTop
var left = eo.left + this.frameOff.left - bodyEl.scrollLeft - this.canvasOff.left; var left = eo.left + this.frameOff.left - bodyEl.scrollLeft - this.canvasOff.left;
var topScroll = this.frameOff.top + bodyEl.scrollTop; var topScroll = this.frameOff.top + bodyEl.scrollTop;
@ -227,36 +239,18 @@ define(function() {
top = topScroll; top = topScroll;
else else
top -= badgeH; top -= badgeH;
return {topP: topP, top: top, left: left, height: el.height(), width: el.width() }; return {topP: topP, top: top, left: left, height: el.outerHeight(), width: el.outerWidth() };
},
/**
* Create badge for the component
* @private
* */
createBadge: function () {
this.badge = $('<div>', {class: this.badgeClass + " no-dots"}).appendTo(this.getCanvasTools());
},
/**
* Remove badge
* @private
* */
removeBadge: function () {
if(this.badge){
this.badge.remove();
delete this.badge;
}
}, },
/** /**
* Updates badge label * Hide badge
* @param {Object} Model
* @private * @private
* */ * */
updateBadgeLabel: function (model) { hideBadge: function () {
if(model) //var st = this.getBadge().style;
this.badge.html(model.getName()); //st.left = -10000;
//st.top = -10000;
this.getBadge().style.display = 'none';
}, },
/** /**
@ -289,7 +283,7 @@ define(function() {
if(sel) if(sel)
this.cleanPrevious(sel); this.cleanPrevious(sel);
this.$el.unbind(); //removes all attached events this.$el.unbind(); //removes all attached events
this.removeBadge(); this.hideBadge();
this.clean(); this.clean();
this.selEl.unbind('mouseover').unbind('mouseout').unbind('click'); this.selEl.unbind('mouseover').unbind('mouseout').unbind('click');
this.editorModel.set('selectedComponent',null); this.editorModel.set('selectedComponent',null);

4
styles/css/main.css

@ -2750,7 +2750,9 @@ ol.example li.placeholder:before {
padding: 2px 5px; padding: 2px 5px;
position: absolute; position: absolute;
z-index: 1; z-index: 1;
font-size: 12px; } font-size: 12px;
outline: none;
display: none; }
.wte-com-badge-red { .wte-com-badge-red {
background-color: #DD3636; } background-color: #DD3636; }

2
styles/scss/main.scss

@ -228,6 +228,8 @@ ol.example li.placeholder:before {position: absolute;}
padding: 2px 5px; padding: 2px 5px;
position: absolute; z-index: 1; position: absolute; z-index: 1;
font-size: 12px; font-size: 12px;
outline: none;
display: none;
} }
.#{$com-prefix}badge-red{ .#{$com-prefix}badge-red{
@extend .#{$com-prefix}badge; @extend .#{$com-prefix}badge;

Loading…
Cancel
Save