This commit is contained in:
parent
c0fcae05f1
commit
d4fb7f011c
|
@ -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.
|
// GetUser gets configuration of the user specified by the given username, returns nil if not found.
|
||||||
func GetUser(username string) *User {
|
func GetUser(username string) *User {
|
||||||
|
if "playground" == username { // reserved user for Playground
|
||||||
|
// mock it
|
||||||
|
return NewUser("playground", "", "", "")
|
||||||
|
}
|
||||||
|
|
||||||
for _, user := range Users {
|
for _, user := range Users {
|
||||||
if user.Name == username {
|
if user.Name == username {
|
||||||
return user
|
return user
|
||||||
|
|
1
main.go
1
main.go
|
@ -197,7 +197,6 @@ func indexHandler(w http.ResponseWriter, r *http.Request) {
|
||||||
}
|
}
|
||||||
|
|
||||||
username := httpSession.Values["username"].(string)
|
username := httpSession.Values["username"].(string)
|
||||||
|
|
||||||
if "playground" == username { // reserved user for Playground
|
if "playground" == username { // reserved user for Playground
|
||||||
http.Redirect(w, r, conf.Wide.Context+"login", http.StatusFound)
|
http.Redirect(w, r, conf.Wide.Context+"login", http.StatusFound)
|
||||||
|
|
||||||
|
|
|
@ -22,6 +22,46 @@ var playground = {
|
||||||
playground.editor.setSize("auto", $("#editor").height() + "px");
|
playground.editor.setSize("auto", $("#editor").height() + "px");
|
||||||
},
|
},
|
||||||
_initShare: function () {
|
_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 () {
|
$(".share-panel .font-ico").click(function () {
|
||||||
var key = $(this).attr('class').split('-')[2];
|
var key = $(this).attr('class').split('-')[2];
|
||||||
var url = "https://wide.b3log.org", pic = 'https://wide.b3log.org/static/images/wide-logo.png';
|
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._initWS();
|
||||||
this._resize();
|
this._resize();
|
||||||
|
this._initWideShare();
|
||||||
this._initShare();
|
this._initShare();
|
||||||
menu._initAbout();
|
menu._initAbout();
|
||||||
},
|
},
|
||||||
|
@ -148,38 +189,6 @@ var playground = {
|
||||||
console.log('[playground onerror] ' + JSON.parse(e));
|
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 () {
|
stop: function () {
|
||||||
if (!playground.editor) {
|
if (!playground.editor) {
|
||||||
return;
|
return;
|
||||||
|
|
|
@ -38,8 +38,7 @@
|
||||||
<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>
|
||||||
<li>
|
<li>
|
||||||
<button class="btn-white btn" id="share" onclick="playground.share();">Share</button>
|
<button class="btn-white btn" id="share" onclick='$("#dialogShare").dialog("open");'>Share</button>
|
||||||
<span id="url"></span>
|
|
||||||
</li>
|
</li>
|
||||||
</ul>
|
</ul>
|
||||||
<div class="fn-right">
|
<div class="fn-right">
|
||||||
|
@ -58,7 +57,7 @@
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
<div class="fn-clear">
|
<div class="fn-clear">
|
||||||
<div id="editorDiv" style="display: none;">
|
<div id="editorDiv" class="fn-none">
|
||||||
<textarea id='editor'>{{.code}}</textarea>
|
<textarea id='editor'>{{.code}}</textarea>
|
||||||
</div>
|
</div>
|
||||||
<textarea id="output" rows="20" readonly="readonly" ></textarea>
|
<textarea id="output" rows="20" readonly="readonly" ></textarea>
|
||||||
|
@ -70,6 +69,7 @@
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<div id="dialogAbout" class="fn-none"></div>
|
<div id="dialogAbout" class="fn-none"></div>
|
||||||
|
<div id="dialogShare" class="fn-none">share!</div>
|
||||||
<script>
|
<script>
|
||||||
var config = {
|
var config = {
|
||||||
"context": "{{.conf.Context}}",
|
"context": "{{.conf.Context}}",
|
||||||
|
|
Loading…
Reference in New Issue