diff --git a/playground/playgrounds.go b/playground/playgrounds.go index c150ed0..2566ca5 100644 --- a/playground/playgrounds.go +++ b/playground/playgrounds.go @@ -77,7 +77,7 @@ func IndexHandler(w http.ResponseWriter, r *http.Request) { model := map[string]interface{}{"conf": conf.Wide, "i18n": i18n.GetAll(locale), "locale": locale, "session": wideSession, "pathSeparator": conf.PathSeparator, "codeMirrorVer": conf.CodeMirrorVer, - "code": template.HTML(code)} + "code": template.HTML(code), "ver": conf.WideVersion, "year": time.Now().Year()} wideSessions := session.WideSessions.GetByUsername(username) diff --git a/static/js/playground.js b/static/js/playground.js index 1606211..5a960a4 100644 --- a/static/js/playground.js +++ b/static/js/playground.js @@ -35,7 +35,32 @@ var playground = { foldGutter: true, cursorHeight: 1, }); - + + var hovered = false; + $(".menu .ico-share").hover(function () { + $(".menu .share-panel").show(); + hovered = true; + }, function () { + if (!hovered) { + $(".menu .share-panel").hide(); + } + + hovered = false; + setTimeout(function () { + if (!hovered) { + $(".menu .share-panel").hide(); + } + }, 500); + }); + + $(".menu .share-panel").hover(function () { + $(".menu .share-panel").show(); + hovered = true; + }, function () { + $(".menu .share-panel").hide(); + hovered = false; + }); + playground.editor.on('changes', function (cm) { $("#url").html(""); }); @@ -70,7 +95,7 @@ var playground = { console.log('[playground onmessage]' + e.data); var data = JSON.parse(e.data); - + if ("init-playground" === data.cmd) { return; } @@ -111,7 +136,7 @@ var playground = { if (!data.succ) { return; } - + var url = window.location.protocol + "//" + window.location.host + '/playground/' + data.fileName; var html = '' + url + ""; @@ -195,6 +220,26 @@ var playground = { }); } }); + }, + format: function () { + if (!playground.editor) { + return; + } + + var code = playground.editor.getValue(); + + var request = newWideRequest(); + request.code = code; + + $.ajax({ + type: 'POST', + url: config.context + '/playground/save', + data: JSON.stringify(request), + dataType: "json", + success: function (data) { + playground.editor.setValue(data.code); + } + }); } }; diff --git a/views/playground/index.html b/views/playground/index.html index 824d711..127bb49 100644 --- a/views/playground/index.html +++ b/views/playground/index.html @@ -22,13 +22,16 @@