Refactoring layout changing
This commit is contained in:
parent
19f7dbf6e6
commit
34453c96c6
|
@ -133,47 +133,8 @@ define([
|
||||||
};
|
};
|
||||||
|
|
||||||
var panel, resizer, stretch = false;
|
var panel, resizer, stretch = false;
|
||||||
options.items.forEach(function(item) {
|
this.freeze = options.freeze;
|
||||||
item.el instanceof HTMLElement && (item.el = $(item.el));
|
this.changeLayout(options.items);
|
||||||
panel = _.extend(new LayoutPanel(), item);
|
|
||||||
if ( panel.stretch ) {
|
|
||||||
stretch = true;
|
|
||||||
panel.rely = false;
|
|
||||||
panel.resize = false;
|
|
||||||
}
|
|
||||||
|
|
||||||
this.panels.push(panel);
|
|
||||||
|
|
||||||
if (panel.resize) {
|
|
||||||
resizer = {
|
|
||||||
isresizer : true,
|
|
||||||
minpos : panel.resize.min||0,
|
|
||||||
maxpos : panel.resize.max||0,
|
|
||||||
fmin : panel.resize.fmin,
|
|
||||||
fmax : panel.resize.fmax,
|
|
||||||
behaviour : panel.behaviour,
|
|
||||||
index : this.splitters.length,
|
|
||||||
offset : panel.resize.offset || 0
|
|
||||||
};
|
|
||||||
|
|
||||||
if (!stretch) {
|
|
||||||
panel.resize.el =
|
|
||||||
resizer.el = panel.el.after('<div class="layout-resizer after"></div>').next();
|
|
||||||
this.panels.push(resizer);
|
|
||||||
} else {
|
|
||||||
panel.resize.el =
|
|
||||||
resizer.el = panel.el.before('<div class="layout-resizer before"></div>').prev();
|
|
||||||
this.panels.splice(this.panels.length - 1, 0, resizer);
|
|
||||||
}
|
|
||||||
|
|
||||||
this.splitters.push({resizer:resizer});
|
|
||||||
|
|
||||||
panel.resize.hidden && resizer.el.hide();
|
|
||||||
Common.Gateway.on('processmouse', this.resize.eventStop);
|
|
||||||
}
|
|
||||||
}, this);
|
|
||||||
|
|
||||||
this.freeze = options.freeze; this.freeze && this.freezePanels(this.freeze);
|
|
||||||
},
|
},
|
||||||
|
|
||||||
doLayout: function() {
|
doLayout: function() {
|
||||||
|
@ -181,6 +142,10 @@ define([
|
||||||
|
|
||||||
changeLayout: function(items) {
|
changeLayout: function(items) {
|
||||||
var panel, resizer, stretch = false;
|
var panel, resizer, stretch = false;
|
||||||
|
this.splitters && this.splitters.forEach(function(item) {
|
||||||
|
item.resizer && item.resizer.el.remove();
|
||||||
|
}, this);
|
||||||
|
this.splitters = [];
|
||||||
this.panels = [];
|
this.panels = [];
|
||||||
items.forEach(function(item) {
|
items.forEach(function(item) {
|
||||||
item.el instanceof HTMLElement && (item.el = $(item.el));
|
item.el instanceof HTMLElement && (item.el = $(item.el));
|
||||||
|
@ -221,6 +186,7 @@ define([
|
||||||
Common.Gateway.on('processmouse', this.resize.eventStop);
|
Common.Gateway.on('processmouse', this.resize.eventStop);
|
||||||
}
|
}
|
||||||
}, this);
|
}, this);
|
||||||
|
this.freezePanels(this.freeze);
|
||||||
},
|
},
|
||||||
|
|
||||||
getElementHeight: function(el) {
|
getElementHeight: function(el) {
|
||||||
|
@ -422,8 +388,10 @@ define([
|
||||||
},
|
},
|
||||||
|
|
||||||
setResizeValue: function (index, value) {
|
setResizeValue: function (index, value) {
|
||||||
if (index >= this.splitters.length)
|
if (index >= this.splitters.length) {
|
||||||
|
this.doLayout();
|
||||||
return false;
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
var panel = null, next = null, oldValue = 0,
|
var panel = null, next = null, oldValue = 0,
|
||||||
resize = this.splitters[index].resizer,
|
resize = this.splitters[index].resizer,
|
||||||
|
@ -472,16 +440,6 @@ define([
|
||||||
Common.UI.VBoxLayout.prototype = _.extend(new BaseLayout(), {
|
Common.UI.VBoxLayout.prototype = _.extend(new BaseLayout(), {
|
||||||
initialize: function(options){
|
initialize: function(options){
|
||||||
BaseLayout.prototype.initialize.call(this,options);
|
BaseLayout.prototype.initialize.call(this,options);
|
||||||
|
|
||||||
this.panels.forEach(function(panel){
|
|
||||||
!panel.stretch && !panel.height && (panel.height = this.getElementHeight(panel.el));
|
|
||||||
|
|
||||||
if (panel.isresizer) {
|
|
||||||
panel.el.on('mousedown', {type: 'vertical', panel: panel}, _.bind(this.resizeStart, this));
|
|
||||||
}
|
|
||||||
}, this);
|
|
||||||
|
|
||||||
this.doLayout.call(this);
|
|
||||||
},
|
},
|
||||||
|
|
||||||
doLayout: function() {
|
doLayout: function() {
|
||||||
|
@ -518,6 +476,18 @@ define([
|
||||||
height += style.height || this.getElementHeight(panel.el);
|
height += style.height || this.getElementHeight(panel.el);
|
||||||
}
|
}
|
||||||
}, this);
|
}, this);
|
||||||
|
},
|
||||||
|
|
||||||
|
changeLayout: function(items) {
|
||||||
|
BaseLayout.prototype.changeLayout.call(this, items);
|
||||||
|
this.panels.forEach(function(panel){
|
||||||
|
!panel.stretch && !panel.height && (panel.height = this.getElementHeight(panel.el));
|
||||||
|
|
||||||
|
if (panel.isresizer) {
|
||||||
|
panel.el.on('mousedown', {type: 'vertical', panel: panel}, _.bind(this.resizeStart, this));
|
||||||
|
}
|
||||||
|
}, this);
|
||||||
|
this.doLayout.call(this);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
|
@ -529,16 +499,6 @@ define([
|
||||||
Common.UI.HBoxLayout.prototype = _.extend(new BaseLayout(), {
|
Common.UI.HBoxLayout.prototype = _.extend(new BaseLayout(), {
|
||||||
initialize: function(options){
|
initialize: function(options){
|
||||||
BaseLayout.prototype.initialize.call(this,options);
|
BaseLayout.prototype.initialize.call(this,options);
|
||||||
|
|
||||||
this.panels.forEach(function(panel){
|
|
||||||
!panel.stretch && !panel.width && (panel.width = this.getElementWidth(panel.el));
|
|
||||||
|
|
||||||
if (panel.isresizer) {
|
|
||||||
panel.el.on('mousedown', {type: 'horizontal', panel: panel}, _.bind(this.resizeStart, this));
|
|
||||||
}
|
|
||||||
}, this);
|
|
||||||
|
|
||||||
this.doLayout.call(this);
|
|
||||||
},
|
},
|
||||||
|
|
||||||
doLayout: function(event) {
|
doLayout: function(event) {
|
||||||
|
@ -581,6 +541,18 @@ define([
|
||||||
width += this.getElementWidth(panel.el);
|
width += this.getElementWidth(panel.el);
|
||||||
}
|
}
|
||||||
},this);
|
},this);
|
||||||
|
},
|
||||||
|
|
||||||
|
changeLayout: function(items) {
|
||||||
|
BaseLayout.prototype.changeLayout.call(this, items);
|
||||||
|
this.panels.forEach(function(panel){
|
||||||
|
!panel.stretch && !panel.width && (panel.width = this.getElementWidth(panel.el));
|
||||||
|
|
||||||
|
if (panel.isresizer) {
|
||||||
|
panel.el.on('mousedown', {type: 'horizontal', panel: panel}, _.bind(this.resizeStart, this));
|
||||||
|
}
|
||||||
|
}, this);
|
||||||
|
this.doLayout.call(this);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue