diff --git a/public/js/app.js b/public/js/app.js index b03d9070a7..58bda9895e 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 0000000000..cc34c8fa02 --- /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 cbc21f6ce0..b8a533a198 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 4266bcbf44..431b1d1042 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 35695f0bfb..451e52ff8c 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)