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
|
|
|
|
2011-11-05 16:46:53 +00:00
|
|
|
'use strict';
|
|
|
|
|
2011-05-16 08:24:46 +00:00
|
|
|
/*@
|
2011-05-16 10:49:48 +00:00
|
|
|
Ox.CollapsePanel <f:Ox.Panel> CollapsePanel Object
|
2011-05-16 08:24:46 +00:00
|
|
|
() -> <f> CollapsePanel Object
|
|
|
|
(options) -> <f> CollapsePanel Object
|
|
|
|
(options, self) -> <f> CollapsePanel Object
|
|
|
|
options <o> Options object
|
2011-05-16 10:49:48 +00:00
|
|
|
collapsed <b|false> collapsed state
|
|
|
|
extras <a|[]> panel extras
|
|
|
|
size <n|16> size
|
|
|
|
title <s> title
|
2011-05-16 08:24:46 +00:00
|
|
|
self <o> shared private variable
|
|
|
|
@*/
|
|
|
|
|
2011-04-22 22:03:10 +00:00
|
|
|
Ox.CollapsePanel = function(options, self) {
|
2011-06-19 17:48:32 +00:00
|
|
|
|
|
|
|
self = self || {};
|
|
|
|
var that = Ox.Panel({}, self)
|
2011-04-22 22:03:10 +00:00
|
|
|
.defaults({
|
|
|
|
collapsed: false,
|
|
|
|
extras: [],
|
|
|
|
size: 16,
|
|
|
|
title: ''
|
|
|
|
})
|
|
|
|
.options(options)
|
2011-12-22 15:47:46 +00:00
|
|
|
.addClass('OxCollapsePanel');
|
|
|
|
|
|
|
|
self.$titlebar = Ox.Bar({
|
|
|
|
orientation: 'horizontal',
|
|
|
|
size: self.options.size,
|
|
|
|
})
|
|
|
|
.bindEvent({
|
|
|
|
doubleclick: doubleclickTitlebar
|
|
|
|
})
|
|
|
|
.appendTo(that);
|
|
|
|
|
|
|
|
self.$button = Ox.Button({
|
|
|
|
style: 'symbol',
|
|
|
|
type: 'image',
|
|
|
|
value: self.options.collapsed ? 'expand' : 'collapse',
|
|
|
|
values: [
|
|
|
|
{id: 'expand', title: 'right'},
|
|
|
|
{id: 'collapse', title: 'down'}
|
|
|
|
]
|
|
|
|
})
|
|
|
|
.bindEvent({
|
|
|
|
click: toggleCollapsed
|
|
|
|
})
|
|
|
|
.appendTo(self.$titlebar);
|
|
|
|
|
|
|
|
self.$title = Ox.Element()
|
|
|
|
.addClass('OxTitle')
|
|
|
|
.html(self.options.title)
|
|
|
|
.appendTo(self.$titlebar);
|
2011-09-01 04:46:14 +00:00
|
|
|
|
2011-04-22 22:03:10 +00:00
|
|
|
if (self.options.extras.length) {
|
2011-12-22 15:47:46 +00:00
|
|
|
self.$extras = Ox.Element()
|
2011-04-22 22:03:10 +00:00
|
|
|
.addClass('OxExtras')
|
2011-12-22 15:47:46 +00:00
|
|
|
.appendTo(self.$titlebar);
|
2011-04-22 22:03:10 +00:00
|
|
|
self.options.extras.forEach(function($extra) {
|
2011-12-22 15:47:46 +00:00
|
|
|
$extra.appendTo(self.$extras);
|
2011-04-22 22:03:10 +00:00
|
|
|
});
|
|
|
|
}
|
2011-09-01 04:46:14 +00:00
|
|
|
|
2011-06-19 17:48:32 +00:00
|
|
|
that.$content = Ox.Element()
|
2011-04-22 22:03:10 +00:00
|
|
|
.addClass('OxContent')
|
|
|
|
.appendTo(that);
|
|
|
|
// fixme: doesn't work, content still empty
|
|
|
|
// need to hide it if collapsed
|
|
|
|
if (self.options.collapsed) {
|
|
|
|
that.$content.css({
|
|
|
|
marginTop: -that.$content.height() + 'px'
|
2012-01-02 14:25:04 +00:00
|
|
|
}).hide();
|
2011-04-22 22:03:10 +00:00
|
|
|
}
|
2011-09-01 04:46:14 +00:00
|
|
|
|
2011-12-22 15:47:46 +00:00
|
|
|
function doubleclickTitlebar(e) {
|
2011-04-22 22:03:10 +00:00
|
|
|
if (!$(e.target).hasClass('OxButton')) {
|
2011-12-22 15:47:46 +00:00
|
|
|
self.$button.trigger('click');
|
2011-04-22 22:03:10 +00:00
|
|
|
}
|
|
|
|
}
|
2011-09-01 04:46:14 +00:00
|
|
|
|
2011-04-22 22:03:10 +00:00
|
|
|
function toggleCollapsed() {
|
2012-01-02 14:05:14 +00:00
|
|
|
// show/hide is needed in case the collapsed content
|
|
|
|
// grows vertically when shrinking the panel horizontally
|
2011-04-22 22:03:10 +00:00
|
|
|
var marginTop;
|
|
|
|
self.options.collapsed = !self.options.collapsed;
|
|
|
|
marginTop = self.options.collapsed ? -that.$content.height() : 0;
|
2012-01-02 14:25:04 +00:00
|
|
|
!self.options.collapsed && that.$content.css({
|
|
|
|
marginTop: -that.$content.height() + 'px'
|
|
|
|
}).show();
|
2011-04-22 22:03:10 +00:00
|
|
|
that.$content.animate({
|
|
|
|
marginTop: marginTop + 'px'
|
2012-01-02 14:05:14 +00:00
|
|
|
}, 250, function() {
|
2012-01-02 14:16:08 +00:00
|
|
|
self.options.collapsed && that.$content.hide();
|
2012-01-02 14:05:14 +00:00
|
|
|
});
|
2011-04-22 22:03:10 +00:00
|
|
|
that.triggerEvent('toggle', {
|
|
|
|
collapsed: self.options.collapsed
|
|
|
|
});
|
|
|
|
}
|
2011-09-01 04:46:14 +00:00
|
|
|
|
2011-05-16 10:49:48 +00:00
|
|
|
/*@
|
|
|
|
setOption <f> setOption
|
|
|
|
(key, value) -> <u> set key to value
|
|
|
|
@*/
|
2011-04-29 12:40:51 +00:00
|
|
|
self.setOption = function(key, value) {
|
2011-04-22 22:03:10 +00:00
|
|
|
if (key == 'collapsed') {
|
2011-12-22 15:47:46 +00:00
|
|
|
self.$button.trigger('click');
|
2011-04-22 22:03:10 +00:00
|
|
|
} else if (key == 'title') {
|
2011-12-22 15:47:46 +00:00
|
|
|
self.$title.html(self.options.title);
|
2011-04-22 22:03:10 +00:00
|
|
|
}
|
|
|
|
};
|
2011-05-16 10:49:48 +00:00
|
|
|
|
|
|
|
/*@
|
|
|
|
update <f> update // fixme: used anywhere?
|
|
|
|
@*/
|
|
|
|
that.update = function() {
|
2011-04-22 22:03:10 +00:00
|
|
|
self.options.collapsed && that.$content.css({
|
|
|
|
marginTop: -that.$content.height()
|
|
|
|
});
|
|
|
|
};
|
2011-09-01 04:46:14 +00:00
|
|
|
|
2011-04-22 22:03:10 +00:00
|
|
|
return that;
|
2011-09-01 04:46:14 +00:00
|
|
|
|
2011-04-22 22:03:10 +00:00
|
|
|
};
|