Ox.load('UI', {debug: true}, function() {
var $buttons = Ox.Bar({size: 24});
var $img, $previewDialog, preview = false;
var $list = Ox.IconList({
item: function(data, sort, size) {
var ratio = data.width / data.height;
size = size || 128;
return {
height: ratio <= 1 ? size : size / ratio,
id: data.id,
info: data.width + ' x ' + data.height + ' px',
title: Ox.toTitleCase(data.id),
url: 'png/' + data.id + '.png',
width: ratio >= 1 ? size : size * ratio
};
},
items: [
{
id: 'earth',
width: 1024,
height: 1024
},
{
id: 'north',
width: 1024,
height: 512
},
{
id: 'west',
width: 512,
height: 1024
}
],
orientation: 'horizontal',
size: 128,
sort: [{key: 'id', operator: '+'}],
unique: 'id'
}).bindEvent({
closepreview: function() {
$previewDialog.close();
preview = false;
},
openpreview: function(event) {
var data = Ox.getObjectById($list.options('items'), event.ids[0]),
ratio = data.width / data.height,
windowWidth = window.innerWidth * 0.8,
windowHeight = window.innerHeight * 0.8,
windowRatio = windowWidth / windowHeight,
width = Math.round(ratio > windowRatio ? windowWidth : windowHeight * ratio),
height = Math.round(ratio < windowRatio ? windowHeight : windowWidth / ratio);
Ox.print('d/w/h', data, width, height)
if (!preview) {
if (!$previewDialog) {
$previewDialog = Ox.Dialog({
closeButton: true,
content: $img = $('')
.attr({src: 'png/' + data.id + '.png'})
.css({width: width + 'px', height: height + 'px'}),
fixedRatio: true,
focus: false,
height: height,
maximizeButton: true,
title: Ox.toTitleCase(data.id),
width: width
})
.bindEvent({
close: function() {
$list.closePreview();
preview = false;
},
resize: function(event) {
$img.css({
width: event.width + 'px',
height: event.height + 'px'
});
}
}).open();
} else {
$previewDialog.options({
content: $img = $('
')
.attr({src: 'png/' + data.id + '.png'})
.css({width: width + 'px', height: height + 'px'}),
height: height,
title: Ox.toTitleCase(data.id),
width: width
}).open();
}
preview = true;
} else {
$previewDialog.options({
content: $img = $('
')
.attr({src: 'png/' + data.id + '.png'})
.css({width: width + 'px', height: height + 'px'}),
title: Ox.toTitleCase(data.id),
}).setSize(width, height);
}
}
});
Ox.SplitPanel({
elements: [
{
element: $buttons,
size: 24
},
{
element: $('