This commit is contained in:
Liang Ding 2015-02-15 11:09:17 +08:00
parent c0fcae05f1
commit d4fb7f011c
4 changed files with 49 additions and 36 deletions

View File

@ -317,6 +317,11 @@ func GetGoFmt(username string) string {
// GetUser gets configuration of the user specified by the given username, returns nil if not found.
func GetUser(username string) *User {
if "playground" == username { // reserved user for Playground
// mock it
return NewUser("playground", "", "", "")
}
for _, user := range Users {
if user.Name == username {
return user

View File

@ -197,7 +197,6 @@ func indexHandler(w http.ResponseWriter, r *http.Request) {
}
username := httpSession.Values["username"].(string)
if "playground" == username { // reserved user for Playground
http.Redirect(w, r, conf.Wide.Context+"login", http.StatusFound)

View File

@ -22,6 +22,46 @@ var playground = {
playground.editor.setSize("auto", $("#editor").height() + "px");
},
_initShare: 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);
if (!data.succ) {
return;
}
$("#dialogShare").dialog({
"modal": true,
"height": 460,
"width": 800,
"title": "Share",
"hideFooter": true,
"afterOpen": function () {
}
});
var url = window.location.protocol + "//" + window.location.host + '/playground/' + data.fileName;
var html = 'URL: <a href="' + url + '" target="_blank">' + url + "</a><br/>";
html += "Embeded: xxxx";
$("#dialogShare").html(html);
}
});
},
_initWideShare: function () {
$(".share-panel .font-ico").click(function () {
var key = $(this).attr('class').split('-')[2];
var url = "https://wide.b3log.org", pic = 'https://wide.b3log.org/static/images/wide-logo.png';
@ -100,6 +140,7 @@ var playground = {
this._initWS();
this._resize();
this._initWideShare();
this._initShare();
menu._initAbout();
},
@ -148,38 +189,6 @@ var playground = {
console.log('[playground onerror] ' + JSON.parse(e));
};
},
share: function () {
if (!playground.editor) {
return;
}
var request = newWideRequest();
request.pid = playground.pid;
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);
if (!data.succ) {
return;
}
var url = window.location.protocol + "//" + window.location.host + '/playground/' + data.fileName;
var html = '<a href="' + url + '" target="_blank">'
+ url + "</a>";
$("#url").html(html);
}
});
},
stop: function () {
if (!playground.editor) {
return;

View File

@ -38,8 +38,7 @@
<button class="btn btn-red" id="stop" onclick="playground.stop();">Stop</button>
</li>
<li>
<button class="btn-white btn" id="share" onclick="playground.share();">Share</button>
<span id="url"></span>
<button class="btn-white btn" id="share" onclick='$("#dialogShare").dialog("open");'>Share</button>
</li>
</ul>
<div class="fn-right">
@ -58,7 +57,7 @@
</div>
</div>
<div class="fn-clear">
<div id="editorDiv" style="display: none;">
<div id="editorDiv" class="fn-none">
<textarea id='editor'>{{.code}}</textarea>
</div>
<textarea id="output" rows="20" readonly="readonly" ></textarea>
@ -70,6 +69,7 @@
</div>
<div id="dialogAbout" class="fn-none"></div>
<div id="dialogShare" class="fn-none">share!</div>
<script>
var config = {
"context": "{{.conf.Context}}",