Browse Source

Set frame size on render

pull/3411/head
Artur Arseniev 6 years ago
parent
commit
db48ffc97e
  1. 39
      src/canvas/view/FrameWrapView.js

39
src/canvas/view/FrameWrapView.js

@ -106,26 +106,19 @@ export default Backbone.View.extend({
*/ */
updateDim() { updateDim() {
const { em, el, $el, model, classAnim } = this; const { em, el, $el, model, classAnim } = this;
const { width, height } = model.attributes;
const { style } = el;
const currW = style.width || '';
const currH = style.height || '';
const newW = width || '';
const newH = height || '';
const noChanges = currW == newW && currH == newH;
const un = 'px';
this.frame.rect = 0; this.frame.rect = 0;
$el.addClass(classAnim); $el.addClass(classAnim);
style.width = isNumber(newW) ? `${newW}${un}` : newW; const { noChanges, width, height } = this.__handleSize();
style.height = isNumber(newH) ? `${newH}${un}` : newH;
// Set width and height from DOM (should be done only once) // Set width and height from DOM (should be done only once)
if (isNull(width) || isNull(height)) { if (isNull(width) || isNull(height)) {
const newDims = { model.set(
...(!width ? { width: el.offsetWidth } : {}), {
...(!height ? { height: el.offsetHeight } : {}) ...(!width ? { width: el.offsetWidth } : {}),
}; ...(!height ? { height: el.offsetHeight } : {})
model.set(newDims, { silent: 1 }); },
{ silent: 1 }
);
} }
// Prevent fixed highlighting box which appears when on // Prevent fixed highlighting box which appears when on
@ -149,9 +142,25 @@ export default Backbone.View.extend({
this.updateDim(); this.updateDim();
}, },
__handleSize() {
const un = 'px';
const { model, el } = this;
const { style } = el;
const { width, height } = model.attributes;
const currW = style.width || '';
const currH = style.height || '';
const newW = width || '';
const newH = height || '';
const noChanges = currW == newW && currH == newH;
style.width = isNumber(newW) ? `${newW}${un}` : newW;
style.height = isNumber(newH) ? `${newH}${un}` : newH;
return { noChanges, width, height, newW, newH };
},
render() { render() {
const { frame, $el, ppfx, cv, model, el } = this; const { frame, $el, ppfx, cv, model, el } = this;
const { onRender } = model.attributes; const { onRender } = model.attributes;
this.__handleSize();
frame.render(); frame.render();
$el $el
.empty() .empty()

Loading…
Cancel
Save