From ecce694d77756264864b03e6b06077592ed1676a Mon Sep 17 00:00:00 2001 From: FuXiaoHei Date: Sat, 29 Mar 2014 21:16:06 +0800 Subject: [PATCH] issue content ajax preview --- public/js/app.js | 61 +++++++++++++++++++++++++------------ routers/preview.go | 17 +++++++++++ templates/issue/create.tmpl | 8 ++--- templates/issue/view.tmpl | 8 ++--- web.go | 1 + 5 files changed, 67 insertions(+), 28 deletions(-) create mode 100644 routers/preview.go diff --git a/public/js/app.js b/public/js/app.js index b03d9070a7e..58bda9895e1 100644 --- a/public/js/app.js +++ b/public/js/app.js @@ -399,21 +399,24 @@ function initRepository() { function initInstall() { // database type change - $('#install-database').on("change", function () { - var val = $(this).val(); - if (val != "sqlite") { - $('.server-sql').show(); - $('.sqlite-setting').addClass("hide"); - if (val == "pgsql") { - $('.pgsql-setting').removeClass("hide"); + (function () { + $('#install-database').on("change", function () { + var val = $(this).val(); + if (val != "sqlite") { + $('.server-sql').show(); + $('.sqlite-setting').addClass("hide"); + if (val == "pgsql") { + $('.pgsql-setting').removeClass("hide"); + } else { + $('.pgsql-setting').addClass("hide"); + } } else { - $('.pgsql-setting').addClass("hide"); + $('.server-sql').hide(); + $('.sqlite-setting').removeClass("hide"); } - } else { - $('.server-sql').hide(); - $('.sqlite-setting').removeClass("hide"); - } - }); + }); + }()); + } function initIssue() { @@ -445,14 +448,32 @@ function initIssue() { }()); // issue ajax update - $('.issue-edit-save').on("click", function () { - $(this).toggleAjax(function(json){ - if(json.ok){ - $('.issue-head h1.title').text(json.title); - $('.issue-main > .issue-content .content').html(json.content); - } + (function () { + $('.issue-edit-save').on("click", function () { + $(this).toggleAjax(function (json) { + if (json.ok) { + $('.issue-head h1.title').text(json.title); + $('.issue-main > .issue-content .content').html(json.content); + } + }); }); - }); + }()); + + // issue ajax preview + (function () { + $('[data-ajax-name=issue-preview]').on("click", function () { + var $this = $(this); + $this.toggleAjax(function (json) { + if (json.ok) { + $($this.data("preview")).html(json.content); + } + }) + }); + $('.issue-write a[data-toggle]').on("click", function () { + $('.issue-preview-content').html("loading..."); + }); + }()) + } (function ($) { diff --git a/routers/preview.go b/routers/preview.go new file mode 100644 index 00000000000..cc34c8fa025 --- /dev/null +++ b/routers/preview.go @@ -0,0 +1,17 @@ +// Copyright 2014 The Gogs Authors. All rights reserved. +// Use of this source code is governed by a MIT-style +// license that can be found in the LICENSE file. + +package routers + +import "github.com/gogits/gogs/modules/middleware" + +func Preview(ctx *middleware.Context) { + content := ctx.Query("content") + // todo : gfm render content + // content = Markdown(content) + ctx.Render.JSON(200, map[string]interface{}{ + "ok": true, + "content": "preview : " + content, + }) +} diff --git a/templates/issue/create.tmpl b/templates/issue/create.tmpl index cbc21f6ce05..b8a533a198e 100644 --- a/templates/issue/create.tmpl +++ b/templates/issue/create.tmpl @@ -18,16 +18,16 @@ Content with Markdown
- +
-
preview
+
loading...
diff --git a/templates/issue/view.tmpl b/templates/issue/view.tmpl index 4266bcbf44e..431b1d10426 100644 --- a/templates/issue/view.tmpl +++ b/templates/issue/view.tmpl @@ -72,17 +72,17 @@ Content with Markdown
- +
-
preview
+
loading...
diff --git a/web.go b/web.go index 35695f0bfb9..451e52ff8c4 100644 --- a/web.go +++ b/web.go @@ -95,6 +95,7 @@ func runWeb(*cli.Context) { m.Get("/pulls", reqSignIn, user.Pulls) m.Get("/stars", reqSignIn, user.Stars) m.Get("/help", routers.Help) + m.Post("/preview", routers.Preview) avt := avatar.CacheServer("public/img/avatar/", "public/img/avatar_default.jpg") m.Get("/avatar/:hash", avt.ServeHTTP)