Skip to content

Commit

Permalink
Added post note previews
Browse files Browse the repository at this point in the history
  • Loading branch information
Marcin Kurczewski committed Nov 16, 2014
1 parent 4e28ccb commit 8e06881
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 1 deletion.
2 changes: 1 addition & 1 deletion public_html/css/post.css
Original file line number Diff line number Diff line change
Expand Up @@ -204,7 +204,7 @@
top: 20%;
}
.post-note-edit textarea {
width: 20em;
width: 25em;
height: 5em;
display: block;
}
Expand Down
21 changes: 21 additions & 0 deletions public_html/js/Presenters/PostNotesPresenter.js
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,8 @@ App.Presenters.PostNotesPresenter = function(
removePostNote(postNote);
} else if (sender === 'save') {
savePostNote(postNote);
} else if (sender === 'preview') {
previewPostNote(postNote);
}
}

Expand Down Expand Up @@ -132,6 +134,20 @@ App.Presenters.PostNotesPresenter = function(
}
}

function previewPostNote(postNote) {
var previewText = $form.find('textarea').val();
postNote.$element.find('.text').html(util.formatMarkdown(previewText));
showPostNoteText(postNote);
}

function showPostNoteText(postNote) {
postNote.$element.find('.text-wrapper').show();
}

function hidePostNoteText(postNote) {
postNote.$element.find('.text-wrapper').css('display', '');
}

function postNoteClicked(e) {
e.preventDefault();
var $postNote = jQuery(e.currentTarget).parents('.post-note');
Expand All @@ -142,6 +158,7 @@ App.Presenters.PostNotesPresenter = function(
}

function showFormForPostNote($postNote) {
hideForm();
var postNote = $postNote.data('postNote');
$form.data('postNote', postNote);
$form.find('textarea').val(postNote.text);
Expand All @@ -150,6 +167,10 @@ App.Presenters.PostNotesPresenter = function(
}

function hideForm() {
var previousPostNote = $form.data('post-note');
if (previousPostNote) {
hidePostNoteText(previousPostNote);
}
$form.hide();
}

Expand Down
1 change: 1 addition & 0 deletions public_html/templates/post-notes.tpl
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
<div class="actions"><!--
--><% if (privileges.canEditPostNotes) { %><!--
--><button type="submit" name="sender" value="save">Save</button><!--
--><button type="submit" name="sender" value="preview">Preview</button><!--
--><% } %><!--
--><button type="submit" name="sender" value="cancel">Cancel</button><!--
--><% if (privileges.canDeletePostNotes) { %><!--
Expand Down

0 comments on commit 8e06881

Please sign in to comment.