pandora/static/js/document.js

137 lines
4.5 KiB
JavaScript
Raw Normal View History

2016-10-04 22:00:03 +00:00
'use strict';
pandora.ui.document = function() {
var $toolbar = Ox.Bar({size: 16})
.bindEvent({
doubleclick: function(e) {
if ($(e.target).is('.OxBar')) {
2017-01-27 12:19:42 +00:00
pandora.$ui.textPanel && pandora.$ui.textPanel.scrollTextTop();
2016-10-04 22:00:03 +00:00
}
}
}),
$content = Ox.Element(),
that = Ox.SplitPanel({
elements: [
{
element: $toolbar,
size: 16
},
{
element: $content
}
],
orientation: 'vertical'
})
2018-03-06 12:57:10 +00:00
.update(function(key, value) {
console.log('got update', key, value)
if (Ox.contains(['area', 'zoom', 'page'], key)) {
$content.options(key, value)
}
})
2016-10-04 22:00:03 +00:00
.bindEvent({
pandora_showbrowser: function(data) {
that.update();
}
}),
2017-01-27 12:19:42 +00:00
item;
2016-10-04 22:00:03 +00:00
pandora.api.getDocument({
id: pandora.user.ui.document
}, function(result) {
if (pandora.user.ui.document != result.data.id) {
return;
}
item = result.data;
var documentTitle = pandora.getWindowTitle(item);
document.title = pandora.getPageTitle(document.location.pathname) || documentTitle;
2018-03-05 11:25:03 +00:00
pandora.$ui.itemTitle && pandora.$ui.itemTitle
2016-10-04 22:00:03 +00:00
.options({title: '<b>' + (pandora.getDocumentTitle(item)) + '</b>'})
.show();
if (pandora.user.ui.documentView == 'info') {
$content.replaceWith(
$content = pandora.ui.documentInfoView(result.data)
);
} else {
setContent();
}
});
function setContent() {
that.replaceElement(1, $content = (
item.extension == 'pdf'
? Ox.PDFViewer({
2017-01-24 15:20:04 +00:00
height: that.height() - 16,
2016-10-04 22:00:03 +00:00
page: pandora.user.ui.documents[item.id]
? pandora.user.ui.documents[item.id].position
: 1,
url: '/documents/' + item.id + '/'
2019-02-21 05:40:12 +00:00
+ item.title.replace('?', '_') + '.' + item.extension,
2016-10-04 22:00:03 +00:00
width: that.width(),
zoom: 'fit'
})
: item.extension == 'html'
2017-01-27 12:19:42 +00:00
? pandora.$ui.textPanel = pandora.ui.textPanel(item, $toolbar)
2016-10-04 22:00:03 +00:00
: Ox.ImageViewer({
area: pandora.user.ui.documents[item.id]
? pandora.user.ui.documents[item.id].position
: [],
2017-01-24 15:20:04 +00:00
height: that.height() - 16,
2016-10-04 22:00:03 +00:00
imageHeight: item.dimensions[1],
imagePreviewURL: pandora.getMediaURL('/documents/' + item.id + '/256p.jpg?' + item.modified),
imageURL: pandora.getMediaURL('/documents/' + item.id + '/'
+ item.title + '.' + item.extension + '?' + item.modified),
imageWidth: item.dimensions[0],
width: that.width()
}).css({
//prevents image overflow on zoom, fixme: fix in Ox.ImageViewer
position: 'absolute'
})
)
.bindEvent({
center: function(data) {
pandora.UI.set(
'documents.' + item.id,
{position: $content.getArea().map(Math.round)}
);
},
key_escape: function() {
// ...
},
page: function(data) {
pandora.UI.set(
'documents.' + item.id,
{position: data.page}
);
},
zoom: function(data) {
pandora.UI.set(
'documents.' + item.id,
{position: $content.getArea().map(Math.round)}
);
}
})
);
if (item.extension == 'html') {
that.css({
'overflow-y': 'auto'
});
}
}
that.info = function() {
return item;
};
that.update = function() {
$content.options({
height: that.height(),
width: that.width()
});
2017-01-27 12:19:42 +00:00
pandora.$ui.textPanel && pandora.$ui.textPanel.update();
2016-10-04 22:00:03 +00:00
};
return that;
};