|
|
|
@ -1,5 +1,5 @@ |
|
|
|
import Backbone from 'backbone'; |
|
|
|
import { isString, isFunction, isArray } from 'underscore'; |
|
|
|
import { isString, isFunction, isArray, result } from 'underscore'; |
|
|
|
import { on, off, matches, getElement } from 'utils/mixins'; |
|
|
|
const $ = Backbone.$; |
|
|
|
|
|
|
|
@ -50,6 +50,7 @@ module.exports = Backbone.View.extend({ |
|
|
|
this.dragHelper = null; |
|
|
|
this.canvasRelative = o.canvasRelative || 0; |
|
|
|
this.selectOnEnd = !o.avoidSelectOnEnd; |
|
|
|
this.scale = o.scale; |
|
|
|
|
|
|
|
if (this.em && this.em.on) { |
|
|
|
this.em.on('change:canvasOffset', this.udpateOffset); |
|
|
|
@ -57,6 +58,10 @@ module.exports = Backbone.View.extend({ |
|
|
|
} |
|
|
|
}, |
|
|
|
|
|
|
|
getScale() { |
|
|
|
return result(this, scale) || 1; |
|
|
|
}, |
|
|
|
|
|
|
|
getContainerEl() { |
|
|
|
if (!this.el) { |
|
|
|
var el = this.opt.container; |
|
|
|
@ -702,19 +707,17 @@ module.exports = Backbone.View.extend({ |
|
|
|
* @return {Array<number>} |
|
|
|
*/ |
|
|
|
getDim(el) { |
|
|
|
const { em, canvasRelative } = this; |
|
|
|
var top, left, height, width; |
|
|
|
|
|
|
|
if (this.canvasRelative && this.em) { |
|
|
|
var pos = this.em.get('Canvas').getElementPos(el); |
|
|
|
var styles = window.getComputedStyle(el); |
|
|
|
var marginTop = parseFloat(styles['marginTop']); |
|
|
|
var marginBottom = parseFloat(styles['marginBottom']); |
|
|
|
var marginRight = parseFloat(styles['marginRight']); |
|
|
|
var marginLeft = parseFloat(styles['marginLeft']); |
|
|
|
top = pos.top - marginTop; |
|
|
|
left = pos.left - marginLeft; |
|
|
|
height = pos.height + marginTop + marginBottom; |
|
|
|
width = pos.width + marginLeft + marginRight; |
|
|
|
if (canvasRelative && em) { |
|
|
|
const canvas = em.get('Canvas'); |
|
|
|
const pos = canvas.getElementPos(el); |
|
|
|
const elOffsets = canvas.getElementOffsets(el); |
|
|
|
top = pos.top - elOffsets.marginTop; |
|
|
|
left = pos.left - elOffsets.marginLeft; |
|
|
|
height = pos.height + elOffsets.marginTop + elOffsets.marginBottom; |
|
|
|
width = pos.width + elOffsets.marginLeft + elOffsets.marginRight; |
|
|
|
} else { |
|
|
|
var o = this.offset(el); |
|
|
|
top = this.relative |
|
|
|
|