diff --git a/public/js/app.js b/public/js/app.js index b03d9070a..58bda9895 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 000000000..cc34c8fa0 --- /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 cbc21f6ce..b8a533a19 100644 --- a/templates/issue/create.tmpl +++ b/templates/issue/create.tmpl @@ -18,16 +18,16 @@ Content with Markdown