szurubooru/public_html/js/Presenters/PostContentPresenter.js

92 lines
2.6 KiB
JavaScript
Raw Normal View History

2014-10-22 10:42:15 +02:00
var App = App || {};
App.Presenters = App.Presenters || {};
App.Presenters.PostContentPresenter = function(
2015-06-28 10:07:11 +02:00
jQuery,
util,
promise,
keyboard,
2015-06-28 10:07:11 +02:00
presenterManager,
postNotesPresenter) {
2014-10-22 10:42:15 +02:00
2015-06-28 10:07:11 +02:00
var post;
var templates = {};
var $target;
2014-10-22 10:42:15 +02:00
2015-06-28 10:07:11 +02:00
function init(params, loaded) {
$target = params.$target;
post = params.post;
2014-10-22 10:42:15 +02:00
2015-06-28 10:07:11 +02:00
promise.wait(util.promiseTemplate('post-content'))
.then(function(postContentTemplate) {
templates.postContent = postContentTemplate;
render();
loaded();
}).fail(function() {
console.log(arguments);
loaded();
});
}
2014-10-22 10:42:15 +02:00
2015-06-28 10:07:11 +02:00
function render() {
$target.html(templates.postContent({post: post}));
2015-06-28 10:07:11 +02:00
if (post.contentType === 'image') {
loadPostNotes();
updatePostNotesSize();
}
keyboard.keyup('f', function() {
var $wrapper = $target.find('.object-wrapper');
if ($wrapper.data('full')) {
$wrapper.css({maxWidth: $wrapper.attr('data-width') + 'px', width: 'auto'});
$wrapper.data('full', false);
} else {
$wrapper.css({maxWidth: null, width: $wrapper.attr('data-width')});
$wrapper.data('full', true);
}
updatePostNotesSize();
});
2015-06-28 10:07:11 +02:00
jQuery(window).resize(updatePostNotesSize);
}
2015-06-28 10:07:11 +02:00
function loadPostNotes() {
presenterManager.initPresenters([
[postNotesPresenter, {post: post, notes: post.notes, $target: $target.find('.post-notes-target')}]],
function() {});
}
2014-10-22 10:42:15 +02:00
2015-06-28 10:07:11 +02:00
function updatePostNotesSize() {
var $postNotes = $target.find('.post-notes-target');
var $objectWrapper = $target.find('.object-wrapper');
$postNotes.css({
width: $objectWrapper.outerWidth() + 'px',
height: $objectWrapper.outerHeight() + 'px',
left: ($objectWrapper.offset().left - $objectWrapper.parent().offset().left) + 'px',
top: ($objectWrapper.offset().top - $objectWrapper.parent().offset().top) + 'px',
});
}
2015-06-28 10:07:11 +02:00
function addNewPostNote() {
postNotesPresenter.addNewPostNote();
}
2014-10-26 01:01:16 +02:00
2015-06-28 10:07:11 +02:00
return {
init: init,
render: render,
addNewPostNote: addNewPostNote,
updatePostNotesSize: updatePostNotesSize,
};
2014-10-22 10:42:15 +02:00
};
App.DI.register('postContentPresenter', [
2015-06-28 10:07:11 +02:00
'jQuery',
'util',
'promise',
'keyboard',
2015-06-28 10:07:11 +02:00
'presenterManager',
'postNotesPresenter'],
App.Presenters.PostContentPresenter);