2011-07-29 18:48:43 +00:00
|
|
|
// vim: et:ts=4:sw=4:sts=4:ft=javascript
|
2011-05-16 08:24:46 +00:00
|
|
|
/*@
|
|
|
|
Ox.Resizebar <f:Ox.Element> Resizebar
|
|
|
|
() -> <f> Resizebar object
|
|
|
|
(options) -> <f> Resizebar object
|
|
|
|
(options, self) -> <f> Resizebar object
|
|
|
|
options <o> Options object
|
2011-05-16 10:49:48 +00:00
|
|
|
collapsed <b|false> inital collapse state
|
|
|
|
collapsible <b|true> collapse state can be changed
|
|
|
|
edge <s|left> edge
|
|
|
|
elements <a|[]> elements of the bar
|
|
|
|
orientation <s|horizontal> orientation, can be horizontal or vertical
|
|
|
|
panel <o|null> panel object
|
|
|
|
resizeable <b|true> can bar be resized
|
|
|
|
resize <a|[]> array with possible sizes
|
|
|
|
size <n|0> default size
|
2011-09-04 21:15:16 +00:00
|
|
|
tooltop <b|s|false> tooltip or not
|
2011-05-16 08:24:46 +00:00
|
|
|
self <o> Shared private variable
|
|
|
|
@*/
|
2011-04-22 22:03:10 +00:00
|
|
|
/**
|
|
|
|
*/
|
|
|
|
Ox.Resizebar = function(options, self) {
|
|
|
|
|
2011-06-19 17:48:32 +00:00
|
|
|
self = self || {};
|
|
|
|
var that = Ox.Element({}, self)
|
2011-04-22 22:03:10 +00:00
|
|
|
.defaults({
|
|
|
|
collapsed: false,
|
|
|
|
collapsible: true,
|
|
|
|
edge: 'left',
|
|
|
|
elements: [],
|
|
|
|
orientation: 'horizontal',
|
|
|
|
parent: null,
|
|
|
|
resizable: true,
|
|
|
|
resize: [],
|
|
|
|
size: 0
|
|
|
|
})
|
|
|
|
.options(options || {}) // fixme: options function should be able to handle undefined, no need for || {}
|
|
|
|
.addClass('OxResizebar Ox' + Ox.toTitleCase(self.options.orientation))
|
|
|
|
.bindEvent({
|
|
|
|
anyclick: toggle,
|
|
|
|
dragstart: dragstart,
|
|
|
|
drag: drag,
|
|
|
|
dragend: dragend
|
|
|
|
})
|
|
|
|
.append($('<div>').addClass('OxSpace'))
|
|
|
|
.append($('<div>').addClass('OxLine'))
|
|
|
|
.append($('<div>').addClass('OxSpace'));
|
|
|
|
|
2011-09-04 21:15:16 +00:00
|
|
|
if (self.options.tooltip) {
|
|
|
|
self.$tooltip = Ox.Tooltip({title: getTitle()});
|
|
|
|
that.bind({
|
|
|
|
mouseenter: self.$tooltip.show,
|
|
|
|
mouseleave: self.$tooltip.hide
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
2011-04-22 22:03:10 +00:00
|
|
|
$.extend(self, {
|
|
|
|
clientXY: self.options.orientation == 'horizontal' ? 'clientY' : 'clientX',
|
|
|
|
dimensions: Ox.UI.DIMENSIONS[self.options.orientation], // fixme: should orientation be the opposite orientation here?
|
|
|
|
edges: Ox.UI.EDGES[self.options.orientation],
|
2011-09-04 21:15:16 +00:00
|
|
|
isLeftOrTop: self.options.edge == 'left' || self.options.edge == 'top'
|
2011-04-22 22:03:10 +00:00
|
|
|
});
|
|
|
|
|
2011-09-04 21:15:16 +00:00
|
|
|
that.css({cursor: getCursor()});
|
|
|
|
|
2011-04-22 22:03:10 +00:00
|
|
|
function dragstart(event, e) {
|
|
|
|
if (self.options.resizable && !self.options.collapsed) {
|
|
|
|
Ox.print('DRAGSTART')
|
|
|
|
self.drag = {
|
|
|
|
startPos: e[self.clientXY],
|
|
|
|
startSize: self.options.size
|
|
|
|
}
|
|
|
|
} else { Ox.print('NO DRAGSTART r !c', self.options.resizable, !self.options.collapsed) }
|
|
|
|
}
|
|
|
|
|
|
|
|
function drag(event, e) {
|
|
|
|
if (self.options.resizable && !self.options.collapsed) {
|
|
|
|
var d = e[self.clientXY] - self.drag.startPos,
|
|
|
|
size = self.options.size;
|
|
|
|
self.options.size = Ox.limit(
|
2011-09-04 21:15:16 +00:00
|
|
|
self.drag.startSize + d * (self.isLeftOrTop ? 1 : -1),
|
2011-04-22 22:03:10 +00:00
|
|
|
self.options.resize[0],
|
|
|
|
self.options.resize[self.options.resize.length - 1]
|
|
|
|
);
|
|
|
|
Ox.forEach(self.options.resize, function(v) {
|
|
|
|
if (self.options.size >= v - 8 && self.options.size <= v + 8) {
|
|
|
|
self.options.size = v;
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
});
|
|
|
|
if (self.options.size != size) {
|
2011-09-04 21:15:16 +00:00
|
|
|
that.css(self.edges[self.isLeftOrTop ? 2 : 3], self.options.size + 'px');
|
2011-04-22 22:03:10 +00:00
|
|
|
// fixme: send {size: x}, not x
|
2011-09-04 21:15:16 +00:00
|
|
|
if (self.isLeftOrTop) {
|
2011-04-22 22:03:10 +00:00
|
|
|
self.options.elements[0]
|
|
|
|
.css(self.dimensions[1], self.options.size + 'px')
|
|
|
|
self.options.elements[1]
|
|
|
|
.css(self.edges[2], (self.options.size + 1) + 'px')
|
|
|
|
} else {
|
|
|
|
self.options.elements[0]
|
|
|
|
.css(self.edges[3], (self.options.size + 1) + 'px')
|
|
|
|
self.options.elements[1]
|
|
|
|
.css(self.dimensions[1], self.options.size + 'px')
|
|
|
|
}
|
|
|
|
triggerEvents('resize');
|
2011-09-04 21:15:16 +00:00
|
|
|
self.options.parent.updateSize(self.isLeftOrTop ? 0 : 1, self.options.size); // fixme: listen to event instead?
|
2011-04-22 22:03:10 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
function dragend() {
|
|
|
|
if (self.options.resizable && !self.options.collapsed) {
|
|
|
|
self.options.size != self.drag.startSize && triggerEvents('resizeend');
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2011-09-04 21:15:16 +00:00
|
|
|
function getCursor() {
|
|
|
|
var cursor = '';
|
|
|
|
if (self.options.collapsed) {
|
|
|
|
cursor = self.options.orientation == 'horizontal'
|
|
|
|
? (self.isLeftOrTop ? 's' : 'n')
|
|
|
|
: (self.isLeftOrTop ? 'e' : 'w');
|
|
|
|
} else {
|
|
|
|
if (self.options.resizable) {
|
|
|
|
cursor = self.options.orientation == 'horizontal'
|
|
|
|
? 'ns' : 'ew';
|
|
|
|
} else if (self.options.collapsible) {
|
|
|
|
cursor = self.options.orientation == 'horizontal'
|
|
|
|
? (self.isLeftOrTop ? 'n' : 's')
|
|
|
|
: (self.isLeftOrTop ? 'w' : 'e');
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
return cursor + '-resize';
|
|
|
|
}
|
|
|
|
|
|
|
|
function getTitle() {
|
|
|
|
var title = '';
|
|
|
|
if (self.options.collapsed) {
|
|
|
|
title = 'Click to show';
|
|
|
|
} else {
|
|
|
|
if (self.options.resizable) {
|
|
|
|
title = 'Drag to resize'
|
|
|
|
}
|
|
|
|
if (self.options.collapsible) {
|
|
|
|
title = (title ? title + ' or c' : 'C') + 'lick to hide'
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (title && Ox.isString(self.options.tooltip)) {
|
|
|
|
title += ' ' + self.options.tooltip;
|
|
|
|
}
|
|
|
|
return title;
|
|
|
|
}
|
|
|
|
|
2011-04-22 22:03:10 +00:00
|
|
|
function toggle() {
|
|
|
|
if (self.options.collapsible) {
|
|
|
|
// fixme: silly, pass a parameter
|
|
|
|
self.options.parent.toggle(
|
2011-09-04 21:15:16 +00:00
|
|
|
self.isLeftOrTop ? 0
|
|
|
|
: self.options.parent.options('elements').length - 1
|
2011-04-22 22:03:10 +00:00
|
|
|
);
|
|
|
|
self.options.collapsed = !self.options.collapsed;
|
2011-09-04 21:15:16 +00:00
|
|
|
that.css({cursor: getCursor()});
|
|
|
|
self.$tooltip.options({title: getTitle()});
|
2011-04-22 22:03:10 +00:00
|
|
|
}
|
|
|
|
/*
|
|
|
|
//Ox.print('toggle');
|
|
|
|
if (Ox.isUndefined(self.options.position)) {
|
|
|
|
self.options.position = parseInt(self.options.parent.css(self.options.edge)) +
|
|
|
|
(self.options.collapsed ? self.options.size : 0);
|
|
|
|
}
|
|
|
|
var size = self.options.position -
|
|
|
|
(self.options.collapsed ? 0 : self.options.size),
|
|
|
|
animate = {};
|
|
|
|
//Ox.print('s.o.e', self.options.edge);
|
|
|
|
animate[self.options.edge] = size;
|
|
|
|
self.options.parent.animate(animate, 200, function() {
|
|
|
|
var i = (self.options.edge == 'left' || self.options.edge == 'top') ? 0 : 1;
|
|
|
|
self.options.collapsed = !self.options.collapsed;
|
|
|
|
Ox.Event.trigger(self.ids[i], 'toggle', self.options.collapsed);
|
|
|
|
Ox.Event.trigger(self.ids[1 - i], 'resize', self.options.elements[1 - i][self.dimensions[1]]());
|
|
|
|
});
|
|
|
|
*/
|
|
|
|
}
|
|
|
|
|
|
|
|
function triggerEvents(event) {
|
|
|
|
self.options.elements[0].triggerEvent(event,
|
2011-09-04 21:15:16 +00:00
|
|
|
self.isLeftOrTop ?
|
2011-04-22 22:03:10 +00:00
|
|
|
self.options.size :
|
|
|
|
self.options.elements[0][self.dimensions[1]]()
|
|
|
|
);
|
|
|
|
self.options.elements[1].triggerEvent(event,
|
2011-09-04 21:15:16 +00:00
|
|
|
self.isLeftOrTop ?
|
2011-04-22 22:03:10 +00:00
|
|
|
self.options.elements[1][self.dimensions[1]]() :
|
|
|
|
self.options.size
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
return that;
|
|
|
|
|
|
|
|
};
|