add (but do not enable) reset-size-on-doubleclick for split panel elements

This commit is contained in:
rlx 2012-04-23 09:37:49 +00:00
parent 43495de239
commit 771b15c25a
2 changed files with 38 additions and 4 deletions

View file

@ -36,6 +36,8 @@ Ox.Resizebar = function(options, self) {
.options(options || {}) // fixme: options function should be able to handle undefined, no need for || {}
.addClass('OxResizebar Ox' + Ox.toTitleCase(self.options.orientation))
.bindEvent({
// singleclick: toggle,
// doubleclick: reset,
anyclick: toggle,
dragstart: dragstart,
drag: drag,
@ -149,9 +151,19 @@ Ox.Resizebar = function(options, self) {
return title;
}
function reset() {
if (self.options.resizable && !self.options.collapsed) {
// fixme: silly, pass an option
self.options.parent.reset(
self.isLeftOrTop ? 0
: self.options.parent.options('elements').length - 1
);
}
}
function toggle() {
if (self.options.collapsible) {
// fixme: silly, pass a parameter
// fixme: silly, pass an option
self.options.parent.toggle(
self.isLeftOrTop ? 0
: self.options.parent.options('elements').length - 1

View file

@ -40,6 +40,10 @@ Ox.SplitPanel = function(options, self) {
Ox.extend(self, {
dimensions: Ox.UI.DIMENSIONS[self.options.orientation],
edges: Ox.UI.EDGES[self.options.orientation],
defaultSize: self.options.elements.map(function(element) {
return !Ox.isUndefined(element.defaultSize)
? element.defaultSize : element.size;
}),
length: self.options.elements.length,
resizebarElements: [],
$resizebars: []
@ -58,12 +62,10 @@ Ox.SplitPanel = function(options, self) {
that.$elements[i] = element.element
.css(self.edges[2], (parseInt(element.element.css(self.edges[2])) || 0) + 'px')
.css(self.edges[3], (parseInt(element.element.css(self.edges[3])) || 0) + 'px');
//alert(v.element.css(self.edges[3]))
});
// create resizebars
self.options.elements.forEach(function(element, i) {
//that.append(element)
var index = i == 0 ? 0 : 1;
that.$elements[i].appendTo(that.$element); // fixme: that.$content
if (element.collapsible || element.resizable) {
@ -117,6 +119,7 @@ Ox.SplitPanel = function(options, self) {
}
function setSizes(init, animate) {
// will animate if animate is truthy, and call animate if its a function
self.options.elements.forEach(function(element, i) {
// fixme: maybe we can add a conditional here, since init
// is about elements that are collapsed splitpanels
@ -255,6 +258,25 @@ Ox.SplitPanel = function(options, self) {
return that;
};
/*@
reset <f> Reset an outer element to its initial size
@*/
that.reset = function(id) {
// one can pass pos instead of id
var pos = Ox.isNumber(id) ? id : getPositionById(id),
element = self.options.elements[pos];
element.size = self.defaultSize[pos];
setSizes(false, function() {
element.element.triggerEvent('resize', {
size: element.size
});
element = self.options.elements[pos == 0 ? 1 : pos - 1];
element.element.triggerEvent('resize', {
size: element.element[self.dimensions[0]]()
});
});
};
/*@
size <f> Get or set size of an element
(id) -> <i> Returns size
@ -295,7 +317,7 @@ Ox.SplitPanel = function(options, self) {
that.animate(animate, 250, function() {
element.collapsed = !element.collapsed;
element.element.triggerEvent('toggle', {
'collapsed': element.collapsed
collapsed: element.collapsed
});
self.$resizebars[pos == 0 ? 0 : 1].options({collapsed: element.collapsed});
element = self.options.elements[pos == 0 ? 1 : pos - 1];