From 1015b4192e89002cca5c5f4409ba9db0522c4e38 Mon Sep 17 00:00:00 2001 From: trumae Date: Thu, 8 Feb 2018 15:25:18 -0200 Subject: [PATCH] Append + Prepend actions --- action/action.go | 36 ++++++++++++++++++++++-------------- 1 file changed, 22 insertions(+), 14 deletions(-) diff --git a/action/action.go b/action/action.go index f43070f..64a3728 100644 --- a/action/action.go +++ b/action/action.go @@ -90,24 +90,32 @@ func Remove(ws *websocket.Conn, target string) error { return errNotImplemented } -//InsertTop Insert content at the top of target -func InsertTop(ws *websocket.Conn, target, content string) error { - return errNotImplemented -} +//Append concate content at target +func Append(ws *websocket.Conn, target, content string) error { + c := strings.Replace(content, "\n", "\\n", -1) + c = strings.Replace(c, "\"", "\\\"", -1) + js := fmt.Sprintf("$( \"#%s\" ).append(\"%s\");", target, c) -//InsertBottom Insert content at the bottom of target -func InsertBottom(ws *websocket.Conn, target, content string) error { - return errNotImplemented + err := ws.WriteMessage(websocket.TextMessage, []byte(js)) + if err != nil { + return err + } + status.Status.SendedBytes += len(js) + return err } -//InsertBefore Insert content at the before of target -func InsertBefore(ws *websocket.Conn, target, content string) error { - return errNotImplemented -} +//Prepend concate content at the begin of target +func Prepend(ws *websocket.Conn, target, content string) error { + c := strings.Replace(content, "\n", "\\n", -1) + c = strings.Replace(c, "\"", "\\\"", -1) + js := fmt.Sprintf("$( \"#%s\" ).prepend(\"%s\");", target, c) -//InsertAfter Insert content at the after of target -func InsertAfter(ws *websocket.Conn, target, content string) error { - return errNotImplemented + err := ws.WriteMessage(websocket.TextMessage, []byte(js)) + if err != nil { + return err + } + status.Status.SendedBytes += len(js) + return err } //Redirect to url