openmedialibrary/static/js/previewDialog.js

97 lines
2.9 KiB
JavaScript
Raw Normal View History

2014-05-04 17:26:43 +00:00
'use strict';
oml.ui.previewDialog = function() {
var ui = oml.user.ui,
$image,
$list = oml.$ui.list,
item = Ox.last($list.options('selected')),
2016-01-12 08:37:41 +00:00
imageRatio = $list.value(
item, ui.icons == 'cover' ? 'coverRatio' : 'previewRatio'
) || oml.config.iconRatio,
size = getSize(imageRatio),
2014-05-04 17:26:43 +00:00
that = Ox.Dialog({
closeButton: true,
content: Ox.Element(),
fixedRatio: true,
focus: false,
height: size.height,
maximizeButton: true,
title: Ox._('Loading...'),
width: size.width
})
.bindEvent({
resize: function(data) {
$image.css({
width: data.width,
height: data.height
});
},
oml_find: function() {
that.close();
},
oml_item: function() {
that.close();
},
oml_page: function() {
that.close();
}
});
function getSize(posterRatio) {
var windowWidth = window.innerWidth * 0.8,
windowHeight = window.innerHeight * 0.8,
windowRatio = windowWidth / windowHeight;
return {
width: Math.round(
posterRatio > windowRatio ? windowWidth : windowHeight * posterRatio
),
height: Math.round(
posterRatio < windowRatio ? windowHeight : windowWidth / posterRatio
)
};
}
2014-05-17 11:45:57 +00:00
that.updateElement = function() {
2014-05-04 17:26:43 +00:00
oml.api.get({
id: Ox.last($list.options('selected')),
2016-01-12 08:37:41 +00:00
keys: ['coverRatio', 'id', 'modified', 'previewRatio', 'title']
2014-05-04 17:26:43 +00:00
}, function(result) {
var item = result.data,
2016-01-12 08:37:41 +00:00
imageRatio = item[
ui.icons == 'cover' ? 'coverRatio' : 'previewRatio'
] || oml.config.iconRatio,
size = getSize(imageRatio),
2014-05-04 17:26:43 +00:00
title = Ox.encodeHTMLEntities(item.title);
$image = $('<img>')
.attr({
src: '/' + item.id + '/cover128.jpg?' + item.modified
})
.css({
width: size.width + 'px',
height: size.height + 'px'
});
$('<img>')
.load(function() {
$image.attr({
src: $(this).attr('src')
});
})
.attr({
2016-01-12 08:37:41 +00:00
src: '/' + item.id + '/' + ui.icons + '1024.jpg?' + item.modified
2014-05-04 17:26:43 +00:00
});
that.options({
content: $image,
title: title,
})
.setSize(size.width, size.height);
});
return that;
};
2014-05-17 11:45:57 +00:00
return that.updateElement();
2014-05-04 17:26:43 +00:00
};