szurubooru/public_html/js/Presenters/PostContentPresenter.js

71 lines
1.5 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(
jQuery,
2014-10-22 10:42:15 +02:00
util,
2014-10-25 15:02:46 +02:00
promise,
presenterManager,
postNotesPresenter) {
2014-10-22 10:42:15 +02:00
var post;
var templates = {};
var $target;
function init(params, loaded) {
$target = params.$target;
post = params.post;
promise.wait(util.promiseTemplate('post-content'))
.then(function(postContentTemplate) {
templates.postContent = postContentTemplate;
render();
loaded();
}).fail(function() {
console.log(arguments);
loaded();
});
}
function render() {
$target.html(templates.postContent({post: post}));
if (post.contentType === 'image') {
loadPostNotes();
updatePostNotesSize();
}
jQuery(window).resize(updatePostNotesSize);
}
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
}
function updatePostNotesSize() {
$target.find('.post-notes-target').width($target.find('.image-wrapper').outerWidth());
$target.find('.post-notes-target').height($target.find('.image-wrapper').outerHeight());
}
2014-10-26 01:01:16 +02:00
function addNewPostNote() {
postNotesPresenter.addNewPostNote();
}
2014-10-22 10:42:15 +02:00
return {
init: init,
render: render,
2014-10-26 01:01:16 +02:00
addNewPostNote: addNewPostNote,
2014-10-22 10:42:15 +02:00
};
};
App.DI.register('postContentPresenter', [
'jQuery',
2014-10-22 10:42:15 +02:00
'util',
2014-10-25 15:02:46 +02:00
'promise',
'presenterManager',
'postNotesPresenter'],
2014-10-22 10:42:15 +02:00
App.Presenters.PostContentPresenter);