Skip to content

Commit

Permalink
Post preview
Browse files Browse the repository at this point in the history
  • Loading branch information
ahushh committed Dec 16, 2015
1 parent 75c2e99 commit 6d3ca24
Show file tree
Hide file tree
Showing 6 changed files with 57 additions and 2 deletions.
14 changes: 14 additions & 0 deletions Handler/Ajax.hs
Original file line number Diff line number Diff line change
@@ -1,7 +1,10 @@
{-# LANGUAGE ScopedTypeVariables #-}
module Handler.Ajax where

import Import
import qualified Data.Text as T (concat)
import qualified Data.Map as M
import Utils.YobaMarkup (doYobaMarkup)
---------------------------------------------------------------------------------------------------------
-- Get multiple posts
---------------------------------------------------------------------------------------------------------
Expand Down Expand Up @@ -185,3 +188,14 @@ getAjaxBoardStatsReadR = do
selectRep $ do
provideRep $ bareLayout [whamlet|ok|]
provideJson $ object [("ok","marked as read")]
---------------------------------------------------------------------------------------------------------
-- Post preview
---------------------------------------------------------------------------------------------------------
postAjaxPostPreviewR :: Handler Html
postAjaxPostPreviewR = do
value <- requireJsonBody
let message = Textarea <$> M.lookup ("msg" :: Text) value
board = fromMaybe "error " $ M.lookup ("board" :: Text) value
thread = maybe (0::Int) tread $ M.lookup ("thread" :: Text) value
messageFormatted <- doYobaMarkup message board thread
bareLayout [whamlet|#{preEscapedToHtml $ unTextarea messageFormatted}|]
1 change: 1 addition & 0 deletions config/routes
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
/online OnlineR GET
/event EventR GET

/ajax/post/preview AjaxPostPreviewR POST
/ajax/postform/#Text AjaxGetPostFormR GET
/ajax/thread/#Text/#Int/new/#Int AjaxNewPostsR GET
/ajax/thread/#Text/#Int/last/#Int AjaxLastPostsR GET
Expand Down
3 changes: 2 additions & 1 deletion messages/en.msg
Original file line number Diff line number Diff line change
Expand Up @@ -395,4 +395,5 @@ PostsByIP: Posts by IP
DisplayOnlyHellbanned: Display only hellbanned posts
DisplayAllPosts: Display all posts
######################################################################################
ImageSource: Source
ImageSource: Source
PostPreview: Preview
3 changes: 2 additions & 1 deletion messages/ru.msg
Original file line number Diff line number Diff line change
Expand Up @@ -397,4 +397,5 @@ PostsByIP: Все посты с этим IP
DisplayOnlyHellbanned: Показывать только посты на премодерации
DisplayAllPosts: Показывать все посты
######################################################################################
ImageSource: Соус
ImageSource: Соус
PostPreview: Предварительный просмотр
35 changes: 35 additions & 0 deletions templates/default-layout.julius
Original file line number Diff line number Diff line change
Expand Up @@ -828,6 +828,41 @@ function hideRules() {
document.getElementsByClassName("show-rules")[0].style.display = 'inline';
document.getElementById("board-info").style.display = 'none';
}

function previewToggle() {
var postform = document.getElementById('post-form');
var textarea = postform.querySelector("textarea");
var preview = document.createElement("div");
preview.id = "post-preview";
preview.style.height = textarea.offsetHeight + 'px';
preview.style.width = textarea.offsetWidth + 'px';

if (textarea.style.display == 'none') {
textarea.style.display = 'inline';
textarea.parentNode.removeChild( document.getElementById('post-preview') );
return;
}

var thread = 0, board;
var action = postform.action.split('/');
if (postform.className == 'plain-post-form') {
board = action[ action.length - 1 ];
} else {
thread = action[ action.length - 1 ];
board = action[ action.length - 2 ];
}
httpRequest({
method: 'POST',
action: "@{AjaxPostPreviewR}",
headers: { 'Accept': 'application/json' },
data: JSON.stringify({ board: board, thread: thread.toString(), msg: textarea.value }),
onloadOk: function(request) {
preview.innerHTML = request.responseText;
insertAfter(preview, textarea);
textarea.style.display = 'none';
}
});
}
//-----------------------------------------------------------------
// Edit form
//-----------------------------------------------------------------
Expand Down
3 changes: 3 additions & 0 deletions templates/post-form.hamlet
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,9 @@
^{fvInput passwordView}#
^{fvInput subjectView}#
<input type=submit value=_{MsgSubmitBtn}>#
&nbsp;
<a>
<i title="_{MsgPostPreview}" .fa .fa-eye .preview-toggle onclick="previewToggle()">
^{fvInput messageView}
<div .markup-buttons>
<a onclick="insertTag('[b]','[/b]','post-form');countSymbols('post-form')">
Expand Down

0 comments on commit 6d3ca24

Please sign in to comment.