2014-10-22 10:42:15 +02:00
|
|
|
var App = App || {};
|
|
|
|
App.Presenters = App.Presenters || {};
|
|
|
|
|
|
|
|
App.Presenters.PostContentPresenter = function(
|
2014-10-26 12:39:55 +01:00
|
|
|
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}));
|
2014-10-25 17:45:01 +02:00
|
|
|
|
|
|
|
if (post.contentType === 'image') {
|
|
|
|
loadPostNotes();
|
2014-10-26 12:39:55 +01:00
|
|
|
updatePostNotesSize();
|
2014-10-25 17:45:01 +02:00
|
|
|
}
|
2014-10-26 12:39:55 +01:00
|
|
|
|
|
|
|
jQuery(window).resize(updatePostNotesSize);
|
2014-10-25 17:45:01 +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
|
|
|
}
|
|
|
|
|
2014-10-26 12:39:55 +01:00
|
|
|
function updatePostNotesSize() {
|
2015-03-13 20:56:12 +01:00
|
|
|
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',
|
|
|
|
});
|
2014-10-26 12:39:55 +01:00
|
|
|
}
|
|
|
|
|
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,
|
2015-03-13 09:29:26 +01:00
|
|
|
updatePostNotesSize: updatePostNotesSize,
|
2014-10-22 10:42:15 +02:00
|
|
|
};
|
|
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
App.DI.register('postContentPresenter', [
|
2014-10-26 12:39:55 +01:00
|
|
|
'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);
|