This commit is contained in:
Van 2015-02-14 17:49:21 +08:00
parent 1cf399bdd5
commit ae2f6476be
3 changed files with 54 additions and 6 deletions

View File

@ -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, model := map[string]interface{}{"conf": conf.Wide, "i18n": i18n.GetAll(locale), "locale": locale,
"session": wideSession, "pathSeparator": conf.PathSeparator, "codeMirrorVer": conf.CodeMirrorVer, "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) wideSessions := session.WideSessions.GetByUsername(username)

View File

@ -35,7 +35,32 @@ var playground = {
foldGutter: true, foldGutter: true,
cursorHeight: 1, 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) { playground.editor.on('changes', function (cm) {
$("#url").html(""); $("#url").html("");
}); });
@ -70,7 +95,7 @@ var playground = {
console.log('[playground onmessage]' + e.data); console.log('[playground onmessage]' + e.data);
var data = JSON.parse(e.data); var data = JSON.parse(e.data);
if ("init-playground" === data.cmd) { if ("init-playground" === data.cmd) {
return; return;
} }
@ -111,7 +136,7 @@ var playground = {
if (!data.succ) { if (!data.succ) {
return; return;
} }
var url = window.location.protocol + "//" + window.location.host + '/playground/' + data.fileName; var url = window.location.protocol + "//" + window.location.host + '/playground/' + data.fileName;
var html = '<a href="' + url + '" target="_blank">' var html = '<a href="' + url + '" target="_blank">'
+ url + "</a>"; + url + "</a>";
@ -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);
}
});
} }
}; };

View File

@ -22,13 +22,16 @@
<div class="header menu fn-clear"> <div class="header menu fn-clear">
<ul class="fn-left"> <ul class="fn-left">
<li> <li>
<a href="/login" rel="login"> <a href="/" target="_blank">
<img title="Wide, a Web-based IDE for Teams using Golang." src="{{.conf.StaticServer}}/static/images/wide-logo.png" <img title="Wide, a Web-based IDE for Teams using Golang." src="{{.conf.StaticServer}}/static/images/wide-logo.png"
class="logo"/></a> class="logo"/></a>
</li> </li>
<li> <li>
<button class="btn" id="run" onclick="playground.run();">Run</button> <button class="btn" id="run" onclick="playground.run();">Run</button>
</li> </li>
<li>
<button class="btn btn-red" id="Format" onclick="playground.format();">Format</button>
</li>
<li> <li>
<button class="btn btn-red" id="stop" onclick="playground.stop();">Stop</button> <button class="btn btn-red" id="stop" onclick="playground.stop();">Stop</button>
</li> </li>
@ -42,7 +45,7 @@
<span class="font-ico ico-share"></span> &nbsp; <span class="font-ico ico-share"></span> &nbsp;
<span onclick="window.open('https://github.com/b3log/wide')" <span onclick="window.open('https://github.com/b3log/wide')"
class="font-ico ico-github"></span>&nbsp; class="font-ico ico-github"></span>&nbsp;
<div class="share-panel frame"> <div class="share-panel frame" style="display: none;">
<span title="Email" class="font-ico ico-email"></span> <span title="Email" class="font-ico ico-email"></span>
<span title="Twitter" class="font-ico ico-twitter"></span> <span title="Twitter" class="font-ico ico-twitter"></span>
<span title="Facebook" class="font-ico ico-facebook"></span> <span title="Facebook" class="font-ico ico-facebook"></span>