oxjs/source/Ox.UI/js/Window/Dialog.js

762 lines
25 KiB
JavaScript
Raw Normal View History

2011-11-05 16:46:53 +00:00
'use strict';
2012-05-21 10:38:18 +00:00
2011-05-16 08:24:46 +00:00
/*@
2012-05-31 10:32:54 +00:00
Ox.Dialog <f> Dialog object
([options[, self]]) -> <o:Ox.Element> Dialog object
2011-05-16 08:24:46 +00:00
options <o> Options object
2011-08-15 12:18:14 +00:00
self <o> Shared private variable
2011-05-16 08:24:46 +00:00
@*/
2011-04-22 22:03:10 +00:00
Ox.Dialog = function(options, self) {
2011-08-15 12:18:14 +00:00
// fixme: use controlsTop/controlsBottom options, like in VideoPlayer (????)
self = self || {};
var that = Ox.Element({}, self)
2011-04-22 22:03:10 +00:00
.defaults({
buttons: [],
2011-08-15 12:18:14 +00:00
controlsBottom: [],
controlsTop: [],
closeButton: false,
2011-04-22 22:03:10 +00:00
content: null,
2011-08-15 12:18:14 +00:00
fixedCenter: false,
fixedSize: false,
fixedRatio: false,
focus: true,
2011-08-15 12:18:14 +00:00
height: 200,
2011-08-17 11:39:33 +00:00
keys: {},
2011-08-15 12:18:14 +00:00
maxHeight: Infinity,
maximizeButton: false,
maxWidth: Infinity,
minHeight: 64,
minWidth: 128,
2011-11-09 17:39:06 +00:00
removeOnClose: false,
2011-08-15 12:18:14 +00:00
title: '',
width: 400
2011-04-22 22:03:10 +00:00
})
.options(options || {})
2012-05-28 19:35:41 +00:00
.update({
buttons: setButtons,
content: setContent,
height: function() {
setMinAndMax();
setCSS({height: self.options.height});
},
title: function() {
self.$title.animate({
opacity: 0
}, 50, function() {
self.$title.html(self.options.title).animate({
opacity: 1
}, 50);
});
},
width: function() {
setMinAndMax();
setCSS({width: self.options.width});
}
})
2011-08-15 12:25:58 +00:00
.addClass('OxDialog')
2011-08-17 11:39:33 +00:00
.bindEvent({
key_enter: function() {
keypress('enter');
},
key_escape: function() {
keypress('escape');
}
})
2011-08-15 12:18:14 +00:00
.hide()
2012-06-16 17:24:19 +00:00
.appendTo(Ox.$body);
2011-08-15 12:18:14 +00:00
self.hasButtons = !!self.options.buttons.length;
self.barsHeight = 24 + 24 * self.hasButtons;
2011-08-15 16:41:54 +00:00
self.initialMaxHeight = self.options.maxHeight;
self.initialMaxWidth = self.options.maxWidth;
2011-08-15 12:18:14 +00:00
self.titleMargin = 8 + (self.options.closeButton ? 20 : 0)
+ (self.options.maximizeButton ? 20 : 0);
if (self.options.focus) {
self.$layer = Ox.Layer({type: 'dialog'});
2011-08-15 12:18:14 +00:00
}
2011-04-22 22:03:10 +00:00
2011-08-15 12:18:14 +00:00
self.$box = $('<div>')
.addClass('OxDialogBox')
.css({zIndex: 11});
2011-04-22 22:03:10 +00:00
2011-08-15 12:18:14 +00:00
self.$titlebar = Ox.Bar({
size: 24
2011-04-22 22:03:10 +00:00
})
2011-08-15 12:18:14 +00:00
.addClass('OxTitlebar')
2011-04-22 22:03:10 +00:00
.appendTo(that);
2011-08-15 12:18:14 +00:00
if (self.options.closeButton) {
self.$closeButton = Ox.Button({
title: 'close',
type: 'image'
})
.css({
top: '4px',
left: '4px'
})
.bindEvent({
click: function() {
that.close();
}
})
.appendTo(self.$titlebar);
}
if (self.options.maximizeButton) {
self.$maximizeButton = Ox.Button({
2011-12-22 07:24:20 +00:00
type: 'image',
values: ['add', 'remove']
2011-08-15 12:18:14 +00:00
})
.css({
top: '4px',
left: '24px'
})
.bindEvent({
click: maximize
})
.appendTo(self.$titlebar);
}
2011-04-22 22:03:10 +00:00
2011-08-15 12:18:14 +00:00
self.$title = Ox.Element()
.addClass('OxTitle')
2011-04-22 22:03:10 +00:00
.css({
2011-08-15 12:18:14 +00:00
marginLeft: self.titleMargin + 'px',
marginRight: self.titleMargin + 'px'
2011-04-22 22:03:10 +00:00
})
2011-08-15 12:18:14 +00:00
.html(self.options.title)
.appendTo(self.$titlebar);
2011-04-22 22:03:10 +00:00
2011-08-15 12:18:14 +00:00
setContent();
2011-04-22 22:03:10 +00:00
2011-08-15 12:18:14 +00:00
if (self.hasButtons) {
self.$buttonsbar = Ox.Bar({
size: 24
})
.addClass('OxButtonsbar')
.appendTo(that);
self.$buttonsLeft = $('<div>')
.addClass('OxButtonsLeft')
.appendTo(self.$buttonsbar.$element);
self.$buttonsRight = $('<div>')
.addClass('OxButtonsRight')
.appendTo(self.$buttonsbar.$element);
2011-08-17 11:39:33 +00:00
setButtons();
2011-04-22 22:03:10 +00:00
}
2011-08-15 12:18:14 +00:00
if (!self.options.fixedCenter) {
self.$titlebar.css({
cursor: 'move'
})
.bindEvent({
doubleclick: function() {
!self.centered && center(true);
},
dragstart: dragstart,
drag: drag,
2012-05-26 15:48:19 +00:00
dragend: dragend
2011-08-15 12:18:14 +00:00
});
self.hasButtons && self.$buttonsbar.css({
cursor: 'move'
})
.bindEvent({
doubleclick: function() {
!self.centered && center(true);
},
dragstart: dragstart,
drag: drag,
dragend: dragend
});
2011-04-22 22:03:10 +00:00
}
2011-08-15 12:18:14 +00:00
!self.options.fixedSize && [
'TopLeft', 'Top', 'TopRight', 'Left', 'Right', 'BottomLeft', 'Bottom', 'BottomRight'
].forEach(function(edge) {
Ox.Element()
.addClass('OxResize OxResize' + edge)
.bindEvent({
doubleclick: function() {
reset(true);
},
dragstart: resizestart,
drag: resize,
dragend: resizeend
})
.appendTo(that);
});
function center(animate) {
var ms = animate ? 100 : 0;
self.centered && decenter();
that.animate({
left: Math.round(
(window.innerWidth - self.options.width) / 2
) + 'px',
top: Math.round(
(window.innerHeight - self.options.height - self.barsHeight) * 0.4
) + 'px',
width: self.options.width + 'px',
height: self.options.height + self.barsHeight + 'px'
}, ms, function() {
that.css({
left: 0,
top: 0,
right: 0,
bottom: Math.round(
(window.innerHeight - self.options.height - self.barsHeight) * 0.2
) + 'px',
margin: 'auto'
});
self.centered = true;
Ox.isFunction(animate) && animate();
2011-04-22 22:03:10 +00:00
});
}
2011-08-15 12:18:14 +00:00
function decenter() {
var offset = that.offset();
if (self.centered) {
that.css({
left: offset.left + 'px',
top: offset.top + 'px',
margin: 0
});
self.centered = false;
2011-04-22 22:03:10 +00:00
}
}
2011-08-15 12:18:14 +00:00
function dragstart(event) {
var offset;
if (!$(event.target).is('.OxButton')) {
offset = that.offset();
self.drag = {
left: offset.left,
top: offset.top,
x: event.clientX,
y: event.clientY
};
decenter();
that.wrap(self.$box);
}
2011-04-22 22:03:10 +00:00
}
2011-08-15 12:18:14 +00:00
function drag(event) {
2011-11-04 15:54:28 +00:00
Ox.Log('Window', document.body.scrollTop, '...')
2011-09-19 13:17:35 +00:00
var left, top;
if (!$(event.target).is('.OxButton')) {
left = Ox.limit(
2011-08-15 12:18:14 +00:00
self.drag.left - self.drag.x + event.clientX,
self.minLeft, self.maxLeft
2011-09-19 13:17:35 +00:00
);
2011-08-15 12:18:14 +00:00
top = Ox.limit(
self.drag.top - self.drag.y + event.clientY,
self.minTop, self.maxTop
);
2012-06-16 17:24:19 +00:00
setCSS({left: left, top: top});
2011-09-19 13:17:35 +00:00
}
2011-04-22 22:03:10 +00:00
}
2011-08-15 12:18:14 +00:00
function dragend() {
that.unwrap();
2011-04-22 22:03:10 +00:00
}
2011-08-17 11:39:33 +00:00
function getButtonById(id) {
var ret = null;
Ox.forEach(self.options.buttons, function(button) {
if (button.options && button.options('id') == id) {
ret = button;
2012-05-25 07:46:34 +00:00
Ox.Break();
2011-08-17 11:39:33 +00:00
}
});
return ret;
}
function keypress(key) {
var id = self.options.keys[key];
2011-11-04 15:54:28 +00:00
Ox.Log('Window', id, getButtonById(id));
2011-08-17 11:39:33 +00:00
id && getButtonById(id).$element.trigger('click');
}
2011-08-15 12:18:14 +00:00
function maximize() {
var data, offset = that.offset();
2011-08-15 12:18:14 +00:00
decenter();
if (!self.maximized) {
self.originalLeft = offset.left;
self.originalTop = offset.top;
self.originalWidth = self.options.width;
self.originalHeight = self.options.height;
2011-04-22 22:03:10 +00:00
}
2011-08-15 12:18:14 +00:00
setCSS(self.maximized ? {
left: self.originalLeft,
top: self.originalTop,
width: self.originalWidth,
height: self.originalHeight
} : {
left: Math.round((window.innerWidth - self.options.maxWidth) / 2),
top: Math.round((window.innerHeight - self.options.maxHeight - self.barsHeight) / 2),
width: self.options.maxWidth,
height: self.options.maxHeight
}, true);
self.maximized = !self.maximized;
2011-04-22 22:03:10 +00:00
}
2011-08-15 12:18:14 +00:00
function reset(animate) {
var data, left, offset, top;
2011-08-15 12:18:14 +00:00
if (!self.centered) {
offset = that.offset();
left = Ox.limit(
offset.left + Math.round((self.options.width - self.initialWidth) / 2),
self.minLeft, self.maxLeft
);
top = Ox.limit(
offset.top + Math.round((self.options.height - self.initialHeight) / 2),
self.minTop, self.maxTop
);
}
setCSS(Ox.extend({
width: self.initialWidth,
height: self.initialHeight
}, self.centered ? {} : {
left: left,
top: top
}), animate);
2011-04-22 22:03:10 +00:00
}
2011-08-15 12:18:14 +00:00
function resizestart(event) {
2012-05-24 09:47:33 +00:00
var edge = event.target.className.slice(17).toLowerCase(),
2011-08-15 12:18:14 +00:00
offset = that.offset();
self.drag = {
edge: edge,
height: self.options.height,
isLeft: edge.indexOf('left') > -1,
isTop: edge.indexOf('top') > -1,
isRight: edge.indexOf('right') > -1,
isBottom: edge.indexOf('bottom') > -1,
left: offset.left,
top: offset.top,
width: self.options.width
};
decenter();
if (self.maximized) {
2011-12-22 07:24:20 +00:00
self.$maximizeButton.toggle();
2011-08-15 12:18:14 +00:00
self.maximized = false;
}
that.wrap(self.$box);
}
function resize(event) {
2012-06-16 17:24:19 +00:00
var horizontal, vertical, offset, ratio = self.drag.width / self.drag.height;
2011-08-15 12:18:14 +00:00
if (!self.drag.fixedRatio && event.shiftKey) {
self.drag.centerX = Math.round(self.drag.left + self.drag.width / 2);
self.drag.centerY = Math.round(self.drag.top + self.drag.height / 2);
}
self.drag.fixedCenter = self.options.fixedCenter || event.altKey;
self.drag.fixedRatio = self.options.fixedRatio || event.shiftKey;
horizontal = self.drag.edge == 'left' || self.drag.edge == 'right'
|| ratio >= 1 || !self.drag.fixedRatio;
vertical = self.drag.edge == 'top' || self.drag.edge == 'bottom'
|| ratio < 1 || !self.drag.fixedRatio;
if (self.drag.isLeft && horizontal) {
self.options.width = Ox.limit(
self.options.width + (
self.drag.left - Math.min(event.clientX, self.maxLeft)
) * (self.drag.fixedCenter ? 2 : 1),
self.options.minWidth,
self.options.maxWidth
);
if (self.drag.fixedRatio) {
self.options.height = Ox.limit(
Math.round(self.options.width / ratio),
self.options.minHeight,
self.options.maxHeight
);
self.options.width = Math.round(self.options.height * ratio);
}
setCSS(Ox.extend({
left: self.drag.left + (
self.drag.width - self.options.width
) / (self.drag.fixedCenter ? 2 : 1),
2012-05-26 15:48:19 +00:00
width: self.options.width
2011-08-15 12:18:14 +00:00
}, self.drag.fixedRatio ? {
top: Math.max(Math.round(
self.drag.edge == 'topleft'
? self.drag.top + self.drag.height - self.options.height
: self.drag.edge == 'bottomleft'
? self.drag.top
: self.drag.centerY - self.options.height / 2
), self.minTop),
height: self.options.height
} : {}));
}
if (self.drag.isTop && vertical) {
self.options.height = Ox.limit(
self.options.height + (
self.drag.top - Ox.limit(event.clientY, self.minTop, self.maxTop)
) * (self.drag.fixedCenter ? 2 : 1),
self.options.minHeight,
self.options.maxHeight
);
if (self.drag.fixedRatio) {
self.options.width = Ox.limit(
Math.round(self.options.height * ratio),
self.options.minWidth,
self.options.maxWidth
);
self.options.height = Math.round(self.options.width / ratio);
}
setCSS(Ox.extend({
top: Math.max(self.drag.top + (
self.drag.height - self.options.height
) / (self.drag.fixedCenter ? 2 : 1), self.minTop),
2012-05-26 15:48:19 +00:00
height: self.options.height
2011-08-15 12:18:14 +00:00
}, (self.drag.fixedRatio) ? {
left: Math.round(
self.drag.edge == 'topleft'
? self.drag.left + self.drag.width - self.options.width
: self.drag.edge == 'topright'
? self.drag.left
: self.drag.centerX - self.options.width / 2
),
width: self.options.width
} : {}));
}
if (self.drag.isRight && horizontal) {
self.options.width = Ox.limit(
self.options.width + (
Math.max(event.clientX, 24) - self.drag.left - self.drag.width
) * (self.drag.fixedCenter ? 2 : 1),
self.options.minWidth,
self.options.maxWidth
);
if (self.drag.fixedRatio) {
self.options.height = Ox.limit(
Math.round(self.options.width / ratio),
self.options.minHeight,
self.options.maxHeight
);
self.options.width = Math.round(self.options.height * ratio);
}
setCSS(Ox.extend({
2012-05-26 15:48:19 +00:00
width: self.options.width
2011-08-15 12:18:14 +00:00
}, self.drag.fixedCenter ? {
left: self.drag.left + (
self.drag.width - self.options.width
) / 2
} : {}, self.drag.fixedRatio ? {
top: Math.max(Math.round(
self.drag.edge == 'topright'
? self.drag.top + self.drag.height - self.options.height
: self.drag.edge == 'bottomright'
? self.drag.top
: self.drag.centerY - self.options.height / 2
), self.minTop),
height: self.options.height
} : {}));
}
if (self.drag.isBottom && vertical) {
self.options.height = Ox.limit(
self.options.height + (
Math.max(event.clientY, 24) - self.drag.top - self.drag.height - self.barsHeight
) * (self.drag.fixedCenter ? 2 : 1),
self.options.minHeight,
self.options.maxHeight
);
if (self.drag.fixedRatio) {
self.options.width = Ox.limit(
Math.round(self.options.height * ratio),
self.options.minWidth,
self.options.maxWidth
);
self.options.height = Math.round(self.options.width / ratio);
}
setCSS(Ox.extend({
2012-05-26 15:48:19 +00:00
height: self.options.height
2011-08-15 12:18:14 +00:00
}, self.drag.fixedCenter ? {
top: Math.max(self.drag.top + (
self.drag.height - self.options.height
) / 2, self.minTop)
} : {}, self.drag.fixedRatio && self.drag.edge == 'bottom' ? {
left: Math.round(
self.drag.edge == 'bottomleft'
? self.drag.left + self.drag.width - self.options.width
: self.drag.edge == 'bottomright'
? self.drag.left
: self.drag.centerX - self.options.width / 2
),
width: self.options.width
} : {}));
}
2012-06-16 17:24:19 +00:00
offset = that.offset();
2011-08-15 12:18:14 +00:00
self.drag.left = offset.left;
self.drag.top = offset.top;
self.drag.width = self.options.width;
self.drag.height = self.options.height;
self.drag.minLeft = 24 - self.options.width;
self.drag.minTop = self.hasButtons ? 24 - self.options.height - self.barsHeight : 0;
2011-04-22 22:03:10 +00:00
that.triggerEvent('resize', {
width: self.options.width,
height: self.options.height
});
}
2011-08-15 12:18:14 +00:00
function resizeend() {
that.unwrap();
that.triggerEvent('resizeend', {
width: self.options.width,
height: self.options.height
});
2011-08-15 12:18:14 +00:00
}
2012-06-16 17:24:19 +00:00
function resizeWindow() {
self.options.width = Math.min(self.options.width, window.innerWidth);
self.options.height = Math.min(self.options.height, window.innerHeight - self.barsHeight);
var offset = that.offset();
setMinAndMax();
if (self.centered) {
center();
} else if (self.maximized) {
self.maximized = false;
maximize();
} else {
setCSS({
left: Math.min(offset.left, self.maxLeft),
top: Math.min(offset.top, self.maxTop),
width: self.options.width,
height: self.options.height
});
}
}
2011-08-17 11:39:33 +00:00
function setButtons() {
var buttonsLeft,
buttonsRight,
2012-05-22 14:29:37 +00:00
index = Ox.indexOf(self.options.buttons, Ox.isEmpty);
2011-08-17 11:39:33 +00:00
if (index) {
2012-05-24 09:02:59 +00:00
buttonsLeft = self.options.buttons.slice(0, index);
buttonsRight = self.options.buttons.slice(index + 1);
2011-08-17 11:39:33 +00:00
} else {
buttonsLeft = [];
buttonsRight = self.options.buttons;
}
self.$buttonsLeft.empty();
buttonsLeft.forEach(function($button) {
$button.addClass('OxLeft').appendTo(self.$buttonsLeft);
});
self.$buttonsRight.empty();
buttonsRight.forEach(function($button) {
$button.addClass('OxRight').appendTo(self.$buttonsRight);
});
}
2011-08-15 12:18:14 +00:00
function setContent() {
2011-11-05 17:27:11 +00:00
var animate = !!self.$content,
2012-05-22 14:08:09 +00:00
isImage = !Ox.UI.isElement(self.options.content) && self.options.content.is('img');
2011-08-15 12:18:14 +00:00
if (animate) {
self.$content.animate({
2011-04-22 22:03:10 +00:00
opacity: 0
2011-08-17 11:39:33 +00:00
}, 250, function() {
$(this).remove();
2011-04-22 22:03:10 +00:00
});
2011-08-15 12:18:14 +00:00
self.options.content.css({
2011-04-22 22:03:10 +00:00
opacity: 0
});
}
2011-08-15 12:18:14 +00:00
self.$content = (isImage ? self.options.content : Ox.Element())
.addClass('OxContent')
.css(self.hasButtons ? {
bottom: '24px'
} : {
bottom: 0,
borderBottomLeftRadius: '8px',
borderBottomRightRadius: '8px'
})
.appendTo(that.$element);
!isImage && self.$content.append(
self.options.content.css(self.hasButtons ? {} : {
borderBottomLeftRadius: '8px',
borderBottomRightRadius: '8px'
})
);
animate && self.options.content.animate({
opacity: 1
2011-08-17 11:39:33 +00:00
}, 250);
2011-08-15 12:18:14 +00:00
}
2011-04-22 22:03:10 +00:00
2011-08-15 12:18:14 +00:00
function setCSS(css, animate) {
var ms = animate ? 100 : 0,
offset = that.offset(),
2012-01-30 22:26:38 +00:00
triggerEvent = self.isOpen && (
(css.width && css.width != self.options.width)
2011-08-15 12:18:14 +00:00
|| (css.height && css.height != self.options.height)
2012-01-30 22:26:38 +00:00
);
2011-08-15 12:18:14 +00:00
css = Ox.extend({
left: offset.left,
top: offset.top,
width: self.options.width,
height: self.options.height
}, css);
2011-04-22 22:03:10 +00:00
that.animate({
2011-08-15 12:18:14 +00:00
left: css.left + 'px',
top: css.top + 'px',
width: css.width + 'px',
height: css.height + self.barsHeight + 'px'
}, ms, function() {
self.options.width = css.width;
self.options.height = css.height;
self.minLeft = 24 - self.options.width;
self.minTop = self.hasButtons ? 24 - self.options.height - self.barsHeight : 0;
triggerEvent && that.triggerEvent('resize', {
width: self.options.width,
height: self.options.height
2011-04-22 22:03:10 +00:00
});
2011-08-15 12:18:14 +00:00
Ox.isFunction(animate) && animate();
2011-04-22 22:03:10 +00:00
});
2011-08-15 12:18:14 +00:00
}
2011-04-22 22:03:10 +00:00
2011-08-15 12:18:14 +00:00
function setMinAndMax() {
var ratio, maxRatio, minRatio;
self.maxLeft = window.innerWidth - 24;
self.maxTop = window.innerHeight - 24;
self.minLeft = 24 - self.options.width;
self.minTop = self.hasButtons ? 24 - self.options.height : 0;
self.options.maxHeight = Ox.limit(self.initialMaxHeight, 64, window.innerHeight - self.barsHeight);
self.options.maxWidth = Ox.limit(self.initialMaxWidth, 128, window.innerWidth);
if (self.options.fixedRatio) {
ratio = self.options.width / self.options.height;
maxRatio = self.options.maxWidth / self.options.maxHeight;
minRatio = self.options.minWidth / self.options.minHeight;
if (maxRatio > ratio) {
self.options.maxWidth = Math.round(self.options.maxHeight * ratio);
} else if (maxRatio < ratio) {
self.options.maxHeight = Math.round(self.options.maxWidth / ratio);
}
if (minRatio > ratio) {
self.options.minWidth = Math.round(self.options.minHeight * ratio);
} else if (minRatio < ratio) {
self.options.minHeight = Math.round(self.options.minWidth / ratio);
}
}
}
2011-04-22 22:03:10 +00:00
2012-05-21 10:38:18 +00:00
/*@
close <f> close
(callback) -> <o> close
@*/
2011-08-15 12:18:14 +00:00
that.close = function(callback) {
2011-11-09 17:39:06 +00:00
if (self.isOpen) {
self.isOpen = false;
that.animate({
opacity: 0
}, 250, function() {
// that.remove();
that.hide();
callback && callback();
});
if (self.maximized) {
2011-12-22 07:24:20 +00:00
self.$maximizeButton.toggle();
2011-11-09 17:39:06 +00:00
self.maximized = false;
}
if (self.options.focus) {
self.$layer.hide();
that.loseFocus();
}
2012-06-16 17:24:19 +00:00
Ox.$window.off({resize: resizeWindow});
2011-11-09 17:39:06 +00:00
that.triggerEvent('close');
self.options.removeOnClose && that.remove();
2011-08-15 12:18:14 +00:00
}
2011-04-22 22:03:10 +00:00
return that;
};
2012-05-21 10:38:18 +00:00
/*@
disableButton <f> disable button
(id) -> <o> disable button
@*/
2011-08-17 11:39:33 +00:00
that.disableButton = function(id) {
getButtonById(id).options({disabled: true});
return that;
};
2012-05-21 10:38:18 +00:00
/*@
disableButtons <f> disable buttons
() -> <o> disable all buttons
@*/
that.disableButtons = function() {
self.options.buttons.forEach(function(button) {
!Ox.isEmpty(button) && button.options({disabled: true});
});
};
2012-05-21 10:38:18 +00:00
/*@
enableButton <f> enable button
(id) -> <o> enable button
@*/
2011-08-17 11:39:33 +00:00
that.enableButton = function(id) {
getButtonById(id).options({disabled: false});
return that;
};
2012-05-21 10:38:18 +00:00
/*@
enableButtons <f> enable buttons
() -> <o> enable all buttons
@*/
that.enableButtons = function() {
self.options.buttons.forEach(function(button) {
!Ox.isEmpty(button) && button.options({disabled: false});
});
};
2012-05-21 10:38:18 +00:00
/*@
open <f> open
() -> <o> open dialog
@*/
2011-04-22 22:03:10 +00:00
that.open = function() {
2011-11-09 17:39:06 +00:00
if (!self.isOpen) {
self.isOpen = true;
self.initialHeight = self.options.height;
self.initialWidth = self.options.width;
setMinAndMax();
center();
reset();
that.css({
opacity: 0
}).show().animate({
opacity: 1
}, 250);
if (self.options.focus) {
self.$layer.show();
that.gainFocus();
2011-08-15 12:18:14 +00:00
}
2012-06-16 17:24:19 +00:00
Ox.$window.on({resize: resizeWindow});
2011-11-09 17:39:06 +00:00
that.triggerEvent('open');
}
2011-08-15 12:18:14 +00:00
return that;
2011-04-22 22:03:10 +00:00
};
2012-05-21 10:38:18 +00:00
/*@
setSize <f> set size
(width, height) -> <o> set size
@*/
2011-08-15 12:18:14 +00:00
that.setSize = function(width, height) {
self.options.width = width;
self.options.height = height;
setMinAndMax();
if (self.maximized) {
2011-08-15 14:11:13 +00:00
self.originalWidth = width;
self.originalHeight = height;
2011-08-15 12:18:14 +00:00
self.options.width = self.options.maxWidth;
self.options.height = self.options.maxHeight;
}
center(true);
that.triggerEvent('resize', {
width: self.options.width,
height: self.options.height
2011-04-22 22:03:10 +00:00
});
2012-05-21 10:38:18 +00:00
return that;
};
2011-04-22 22:03:10 +00:00
return that;
};