2015-01-01 05:06:33 +03:00
|
|
|
|
/*
|
2019-05-17 06:28:50 +03:00
|
|
|
|
* Copyright (c) 2014-present, b3log.org
|
2015-01-01 05:06:33 +03:00
|
|
|
|
*
|
2014-11-12 18:13:14 +03:00
|
|
|
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
|
|
|
* you may not use this file except in compliance with the License.
|
|
|
|
|
* You may obtain a copy of the License at
|
2015-01-01 05:06:33 +03:00
|
|
|
|
*
|
2018-03-12 07:28:33 +03:00
|
|
|
|
* https://www.apache.org/licenses/LICENSE-2.0
|
2015-01-01 05:06:33 +03:00
|
|
|
|
*
|
2014-11-12 18:13:14 +03:00
|
|
|
|
* Unless required by applicable law or agreed to in writing, software
|
|
|
|
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
|
|
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
|
|
|
* See the License for the specific language governing permissions and
|
|
|
|
|
* limitations under the License.
|
2014-11-18 05:03:08 +03:00
|
|
|
|
*/
|
2014-11-12 18:13:14 +03:00
|
|
|
|
|
2015-12-08 18:48:16 +03:00
|
|
|
|
/*
|
|
|
|
|
* @file menu.js
|
|
|
|
|
*
|
|
|
|
|
* @author <a href="http://vanessa.b3log.org">Liyuan Li</a>
|
|
|
|
|
* @author <a href="http://88250.b3log.org">Liang Ding</a>
|
2018-10-05 16:04:40 +03:00
|
|
|
|
* @version 1.0.1.3, Oct 5, 2018
|
2015-12-08 18:48:16 +03:00
|
|
|
|
*/
|
2014-09-10 14:08:35 +04:00
|
|
|
|
var menu = {
|
2014-10-13 13:01:44 +04:00
|
|
|
|
init: function () {
|
2014-09-10 14:08:35 +04:00
|
|
|
|
this.subMenu();
|
2014-11-18 05:03:08 +03:00
|
|
|
|
this._initPreference();
|
|
|
|
|
this._initAbout();
|
2014-12-14 07:20:39 +03:00
|
|
|
|
this._initShare();
|
2014-09-13 09:05:50 +04:00
|
|
|
|
|
|
|
|
|
// 点击子菜单后消失
|
2015-01-03 11:01:24 +03:00
|
|
|
|
$(".menu .frame li").click(function () {
|
|
|
|
|
$(".menu > ul > li").unbind().removeClass("selected");
|
|
|
|
|
menu.subMenu();
|
2014-09-13 09:05:50 +04:00
|
|
|
|
});
|
2014-12-14 07:20:39 +03:00
|
|
|
|
},
|
|
|
|
|
_initShare: function () {
|
|
|
|
|
$(".menu .ico-share").hover(function () {
|
|
|
|
|
$(".menu .share-panel").show();
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
$(".share-panel .font-ico").click(function () {
|
|
|
|
|
var key = $(this).attr('class').split('-')[2];
|
2014-12-18 11:46:34 +03:00
|
|
|
|
var url = "https://wide.b3log.org", pic = 'https://wide.b3log.org/static/images/wide-logo.png';
|
2014-12-14 07:20:39 +03:00
|
|
|
|
var urls = {};
|
2014-12-18 11:46:34 +03:00
|
|
|
|
urls.email = "mailto:?subject=" + $('title').text()
|
2014-12-14 08:06:53 +03:00
|
|
|
|
+ "&body=" + $('meta[name=description]').attr('content') + ' ' + url;
|
2014-12-18 11:46:34 +03:00
|
|
|
|
|
|
|
|
|
var twitterShare = encodeURIComponent($('meta[name=description]').attr('content') + " " + url + " #golang");
|
|
|
|
|
urls.twitter = "https://twitter.com/intent/tweet?status=" + twitterShare;
|
|
|
|
|
|
2014-12-14 07:20:39 +03:00
|
|
|
|
urls.facebook = "https://www.facebook.com/sharer/sharer.php?u=" + url;
|
2014-12-18 11:46:34 +03:00
|
|
|
|
urls.googleplus = "https://plus.google.com/share?url=" + url;
|
|
|
|
|
|
|
|
|
|
var title = encodeURIComponent($('title').text() + '. \n' + $('meta[name=description]').attr('content')
|
|
|
|
|
+ " #golang#");
|
|
|
|
|
urls.weibo = "http://v.t.sina.com.cn/share/share.php?title=" + title + "&url=" + url + "&pic=" + pic;
|
2018-10-05 16:04:40 +03:00
|
|
|
|
urls.qqz = "https://sns.qzone.qq.com/cgi-bin/qzshare/cgi_qzshare_onekey?url=" + url + "&sharesource=qzone&title=" + title+ "&pics=" + pic;
|
2015-01-03 11:01:24 +03:00
|
|
|
|
|
2014-12-14 07:20:39 +03:00
|
|
|
|
window.open(urls[key], "_blank", "top=100,left=200,width=648,height=618");
|
|
|
|
|
});
|
2014-09-10 14:08:35 +04:00
|
|
|
|
},
|
2014-11-18 05:03:08 +03:00
|
|
|
|
_initAbout: function () {
|
2019-05-17 04:27:22 +03:00
|
|
|
|
$("#dialogAbout").load('/about', function () {
|
2014-11-18 05:03:08 +03:00
|
|
|
|
$("#dialogAbout").dialog({
|
|
|
|
|
"modal": true,
|
|
|
|
|
"title": config.label.about,
|
|
|
|
|
"hideFooter": true,
|
|
|
|
|
"afterOpen": function () {
|
|
|
|
|
$.ajax({
|
2014-12-15 05:30:42 +03:00
|
|
|
|
url: "https://rhythm.b3log.org/version/wide/latest",
|
2014-11-18 05:03:08 +03:00
|
|
|
|
type: "GET",
|
|
|
|
|
dataType: "jsonp",
|
|
|
|
|
jsonp: "callback",
|
|
|
|
|
success: function (data, textStatus) {
|
|
|
|
|
if ($("#dialogAbout .version").text() === data.wideVersion) {
|
|
|
|
|
$(".upgrade").text(config.label.uptodate);
|
|
|
|
|
} else {
|
|
|
|
|
$(".upgrade").html(config.label.new_version_available + config.label.colon
|
|
|
|
|
+ "<a href='" + data.wideDownload
|
|
|
|
|
+ "' target='_blank'>" + data.wideVersion + "</a>");
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
});
|
|
|
|
|
},
|
2014-10-13 13:01:44 +04:00
|
|
|
|
disabled: function (list) {
|
|
|
|
|
for (var i = 0, max = list.length; i < max; i++) {
|
|
|
|
|
$(".menu li." + list[i]).addClass("disabled");
|
|
|
|
|
}
|
|
|
|
|
},
|
|
|
|
|
undisabled: function (list) {
|
|
|
|
|
for (var i = 0, max = list.length; i < max; i++) {
|
|
|
|
|
$(".menu li." + list[i]).removeClass("disabled");
|
|
|
|
|
}
|
|
|
|
|
},
|
2014-09-13 09:05:50 +04:00
|
|
|
|
// 焦点不在菜单上时需点击展开子菜单,否则为鼠标移动展开
|
2014-10-13 13:01:44 +04:00
|
|
|
|
subMenu: function () {
|
2015-01-03 11:01:24 +03:00
|
|
|
|
$(".menu > ul > li").click(function (event) {
|
|
|
|
|
if ($(event.target).closest(".frame").length === 1) {
|
|
|
|
|
return;
|
|
|
|
|
}
|
2014-09-10 14:08:35 +04:00
|
|
|
|
var $it = $(this);
|
2015-01-03 11:01:24 +03:00
|
|
|
|
$it.find('.frame').show();
|
|
|
|
|
$(".menu > ul > li").removeClass("selected");
|
2014-11-05 10:09:39 +03:00
|
|
|
|
$(this).addClass("selected");
|
2014-09-10 14:08:35 +04:00
|
|
|
|
|
2015-01-03 11:01:24 +03:00
|
|
|
|
$(".menu > ul > li").unbind();
|
2014-09-10 14:08:35 +04:00
|
|
|
|
|
2015-01-03 11:01:24 +03:00
|
|
|
|
$(".menu > ul > li").mouseover(function () {
|
|
|
|
|
if ($(event.target).closest(".frame").length === 1) {
|
|
|
|
|
return;
|
|
|
|
|
}
|
2015-01-04 06:21:44 +03:00
|
|
|
|
$(".menu .frame").hide();
|
2015-01-03 11:01:24 +03:00
|
|
|
|
$(this).find('.frame').show();
|
|
|
|
|
$(".menu > ul > li").removeClass("selected");
|
2014-11-05 10:09:39 +03:00
|
|
|
|
$(this).addClass("selected");
|
2014-09-10 14:08:35 +04:00
|
|
|
|
});
|
|
|
|
|
});
|
2014-11-18 05:03:08 +03:00
|
|
|
|
},
|
|
|
|
|
openPreference: function () {
|
|
|
|
|
$("#dialogPreference").dialog("open");
|
|
|
|
|
},
|
|
|
|
|
saveAllFiles: function () {
|
|
|
|
|
if ($(".menu li.save-all").hasClass("disabled")) {
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
for (var i = 0, ii = editors.data.length; i < ii; i++) {
|
2015-04-26 16:58:23 +03:00
|
|
|
|
var path = editors.data[i].id;
|
2014-11-18 05:03:08 +03:00
|
|
|
|
var editor = editors.data[i].editor;
|
|
|
|
|
|
|
|
|
|
if ("text/x-go" === editor.getOption("mode")) {
|
|
|
|
|
wide.fmt(path, editor);
|
|
|
|
|
} else {
|
|
|
|
|
wide._save(path, editor);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
},
|
|
|
|
|
closeAllFiles: function () {
|
|
|
|
|
if ($(".menu li.close-all").hasClass("disabled")) {
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// 设置全部关闭标识
|
|
|
|
|
var removeData = [];
|
|
|
|
|
$(".edit-panel .tabs > div").each(function (i) {
|
|
|
|
|
if (i !== 0) {
|
|
|
|
|
removeData.push($(this).data("index"));
|
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
$("#dialogCloseEditor").data("removeData", removeData);
|
|
|
|
|
// 开始关闭
|
|
|
|
|
$(".edit-panel .tabs .ico-close:eq(0)").click();
|
|
|
|
|
},
|
|
|
|
|
exit: function () {
|
|
|
|
|
var request = newWideRequest();
|
|
|
|
|
|
|
|
|
|
$.ajax({
|
|
|
|
|
type: 'POST',
|
2019-05-17 04:27:22 +03:00
|
|
|
|
url: '/logout',
|
2014-11-18 05:03:08 +03:00
|
|
|
|
data: JSON.stringify(request),
|
|
|
|
|
dataType: "json",
|
2015-11-24 12:39:35 +03:00
|
|
|
|
success: function (result) {
|
|
|
|
|
if (result.succ) {
|
2019-05-17 04:27:22 +03:00
|
|
|
|
window.location.href = "/login";
|
2014-11-18 05:03:08 +03:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
},
|
|
|
|
|
openAbout: function () {
|
|
|
|
|
$("#dialogAbout").dialog("open");
|
|
|
|
|
},
|
|
|
|
|
goinstall: function () {
|
|
|
|
|
menu.saveAllFiles();
|
|
|
|
|
|
|
|
|
|
var currentPath = editors.getCurrentPath();
|
|
|
|
|
if (!currentPath) {
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if ($(".menu li.go-install").hasClass("disabled")) {
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
var request = newWideRequest();
|
|
|
|
|
request.file = currentPath;
|
|
|
|
|
|
|
|
|
|
$.ajax({
|
|
|
|
|
type: 'POST',
|
2019-05-17 04:27:22 +03:00
|
|
|
|
url: '/go/install',
|
2014-11-18 05:03:08 +03:00
|
|
|
|
data: JSON.stringify(request),
|
|
|
|
|
dataType: "json",
|
2015-11-24 11:44:34 +03:00
|
|
|
|
beforeSend: function () {
|
2014-11-18 05:03:08 +03:00
|
|
|
|
bottomGroup.resetOutput();
|
|
|
|
|
},
|
2015-11-24 11:44:34 +03:00
|
|
|
|
success: function (result) {
|
2014-11-18 05:03:08 +03:00
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
},
|
2014-12-25 05:41:19 +03:00
|
|
|
|
// go test.
|
2014-11-18 05:03:08 +03:00
|
|
|
|
test: function () {
|
|
|
|
|
menu.saveAllFiles();
|
|
|
|
|
|
|
|
|
|
var currentPath = editors.getCurrentPath();
|
|
|
|
|
if (!currentPath) {
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
|
2014-12-31 13:02:04 +03:00
|
|
|
|
if ($(".menu li.go-test").hasClass("disabled")) {
|
2014-11-18 05:03:08 +03:00
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
var request = newWideRequest();
|
|
|
|
|
request.file = currentPath;
|
|
|
|
|
|
|
|
|
|
$.ajax({
|
|
|
|
|
type: 'POST',
|
2019-05-17 04:27:22 +03:00
|
|
|
|
url: '/go/test',
|
2014-11-18 05:03:08 +03:00
|
|
|
|
data: JSON.stringify(request),
|
|
|
|
|
dataType: "json",
|
2015-11-24 11:44:34 +03:00
|
|
|
|
beforeSend: function () {
|
2014-11-18 05:03:08 +03:00
|
|
|
|
bottomGroup.resetOutput();
|
|
|
|
|
},
|
2015-11-24 11:44:34 +03:00
|
|
|
|
success: function (result) {
|
2014-12-31 13:02:04 +03:00
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
},
|
|
|
|
|
// go vet.
|
|
|
|
|
govet: function () {
|
|
|
|
|
menu.saveAllFiles();
|
|
|
|
|
|
|
|
|
|
var currentPath = editors.getCurrentPath();
|
|
|
|
|
if (!currentPath) {
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if ($(".menu li.go-vet").hasClass("disabled")) {
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
var request = newWideRequest();
|
|
|
|
|
request.file = currentPath;
|
|
|
|
|
|
|
|
|
|
$.ajax({
|
|
|
|
|
type: 'POST',
|
2019-05-17 04:27:22 +03:00
|
|
|
|
url: '/go/vet',
|
2014-12-31 13:02:04 +03:00
|
|
|
|
data: JSON.stringify(request),
|
|
|
|
|
dataType: "json",
|
2015-11-24 11:44:34 +03:00
|
|
|
|
beforeSend: function () {
|
2014-12-31 13:02:04 +03:00
|
|
|
|
bottomGroup.resetOutput();
|
|
|
|
|
},
|
2015-11-24 11:44:34 +03:00
|
|
|
|
success: function (result) {
|
2014-11-18 05:03:08 +03:00
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
},
|
2014-11-19 04:39:06 +03:00
|
|
|
|
// Build & Run.
|
2014-11-18 05:03:08 +03:00
|
|
|
|
run: function () {
|
|
|
|
|
menu.saveAllFiles();
|
|
|
|
|
|
2015-03-21 15:22:53 +03:00
|
|
|
|
if ($("#buildRun").hasClass("ico-stop")) {
|
|
|
|
|
wide.stop();
|
2014-11-18 05:03:08 +03:00
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
|
2015-03-21 15:22:53 +03:00
|
|
|
|
var currentPath = editors.getCurrentPath();
|
|
|
|
|
if (!currentPath) {
|
2014-11-18 05:03:08 +03:00
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
|
2015-03-21 15:22:53 +03:00
|
|
|
|
if ($(".menu li.run").hasClass("disabled")) {
|
2014-11-18 05:03:08 +03:00
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
var request = newWideRequest();
|
|
|
|
|
request.file = currentPath;
|
|
|
|
|
request.code = wide.curEditor.getValue();
|
|
|
|
|
request.nextCmd = "run";
|
|
|
|
|
|
|
|
|
|
$.ajax({
|
|
|
|
|
type: 'POST',
|
2019-05-17 04:27:22 +03:00
|
|
|
|
url: '/build',
|
2014-11-18 05:03:08 +03:00
|
|
|
|
data: JSON.stringify(request),
|
|
|
|
|
dataType: "json",
|
2015-11-24 11:44:34 +03:00
|
|
|
|
beforeSend: function () {
|
2014-11-18 05:03:08 +03:00
|
|
|
|
bottomGroup.resetOutput();
|
2017-03-27 16:31:35 +03:00
|
|
|
|
|
2014-12-13 17:58:43 +03:00
|
|
|
|
$("#buildRun").addClass("ico-stop")
|
2014-11-18 05:03:08 +03:00
|
|
|
|
.removeClass("ico-buildrun").attr("title", config.label.stop);
|
2017-03-15 18:26:10 +03:00
|
|
|
|
},
|
|
|
|
|
success: function (result) {
|
2014-11-18 05:03:08 +03:00
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
},
|
2014-11-19 04:39:06 +03:00
|
|
|
|
// Build.
|
2014-11-18 05:03:08 +03:00
|
|
|
|
build: function () {
|
|
|
|
|
menu.saveAllFiles();
|
|
|
|
|
|
|
|
|
|
var currentPath = editors.getCurrentPath();
|
|
|
|
|
if (!currentPath) {
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if ($(".menu li.build").hasClass("disabled")) {
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
var request = newWideRequest();
|
|
|
|
|
request.file = currentPath;
|
|
|
|
|
request.code = wide.curEditor.getValue();
|
2014-12-25 05:41:19 +03:00
|
|
|
|
request.nextCmd = ""; // build only, no following operation
|
2014-11-18 05:03:08 +03:00
|
|
|
|
|
|
|
|
|
$.ajax({
|
|
|
|
|
type: 'POST',
|
2019-05-17 04:27:22 +03:00
|
|
|
|
url: '/build',
|
2014-11-18 05:03:08 +03:00
|
|
|
|
data: JSON.stringify(request),
|
|
|
|
|
dataType: "json",
|
2015-11-24 11:44:34 +03:00
|
|
|
|
beforeSend: function () {
|
2014-11-18 05:03:08 +03:00
|
|
|
|
bottomGroup.resetOutput();
|
|
|
|
|
},
|
2015-11-24 11:30:37 +03:00
|
|
|
|
success: function (result) {
|
2014-11-18 05:03:08 +03:00
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
},
|
|
|
|
|
_initPreference: function () {
|
2019-05-17 04:27:22 +03:00
|
|
|
|
$("#dialogPreference").load('/preference', function () {
|
2014-11-18 05:03:08 +03:00
|
|
|
|
$("#dialogPreference input").keyup(function () {
|
2014-12-08 10:18:28 +03:00
|
|
|
|
var isChange = false,
|
|
|
|
|
emptys = [],
|
|
|
|
|
emptysTip = '';
|
2014-11-18 05:03:08 +03:00
|
|
|
|
$("#dialogPreference input").each(function () {
|
2014-12-08 10:18:28 +03:00
|
|
|
|
var $it = $(this);
|
|
|
|
|
// data-value 如为数字,则不会和 value 一样转换为 String,再次不使用全等
|
|
|
|
|
if ($it.val() != $it.data("value")) {
|
2014-11-18 05:03:08 +03:00
|
|
|
|
isChange = true;
|
|
|
|
|
}
|
2014-12-08 10:18:28 +03:00
|
|
|
|
|
|
|
|
|
if ($.trim($it.val()) === '') {
|
|
|
|
|
emptys.push($it);
|
|
|
|
|
}
|
2014-11-18 05:03:08 +03:00
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
var $okBtn = $("#dialogPreference").closest(".dialog-main").find(".dialog-footer > button:eq(0)");
|
|
|
|
|
if (isChange) {
|
|
|
|
|
$okBtn.prop("disabled", false);
|
|
|
|
|
} else {
|
|
|
|
|
$okBtn.prop("disabled", true);
|
|
|
|
|
}
|
2014-12-08 10:18:28 +03:00
|
|
|
|
|
|
|
|
|
if (emptys.length === 0) {
|
|
|
|
|
$("#dialogPreference").find(".tip").html("");
|
2014-12-09 10:07:26 +03:00
|
|
|
|
$okBtn.prop("disabled", false);
|
2014-12-08 10:18:28 +03:00
|
|
|
|
} else {
|
|
|
|
|
for (var i = 0, max = emptys.length; i < max; i++) {
|
2014-12-09 10:07:26 +03:00
|
|
|
|
var tabIndex = emptys[i].closest('div').data("index"),
|
|
|
|
|
text = $.trim(emptys[i].parent().text());
|
2015-04-26 16:58:23 +03:00
|
|
|
|
emptysTip += '[' + $('#dialogPreference .tabs > div[data-index="' + tabIndex + '"]').text()
|
2014-12-09 10:07:26 +03:00
|
|
|
|
+ '] -> [' + text.substr(0, text.length - 1)
|
2014-12-08 11:11:43 +03:00
|
|
|
|
+ ']: ' + config.label.no_empty + "<br/>";
|
2014-12-08 10:18:28 +03:00
|
|
|
|
}
|
|
|
|
|
$("#dialogPreference").find(".tip").html(emptysTip);
|
2014-12-09 10:07:26 +03:00
|
|
|
|
$okBtn.prop("disabled", true);
|
2014-12-08 10:18:28 +03:00
|
|
|
|
}
|
2014-11-18 05:03:08 +03:00
|
|
|
|
});
|
|
|
|
|
|
2014-11-26 06:24:24 +03:00
|
|
|
|
$("#dialogPreference select").on("change", function () {
|
|
|
|
|
var isChange = false;
|
2014-12-08 10:18:28 +03:00
|
|
|
|
$("#dialogPreference select").each(function () {
|
2014-11-26 06:24:24 +03:00
|
|
|
|
if ($(this).val() !== $(this).data("value")) {
|
|
|
|
|
isChange = true;
|
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
var $okBtn = $("#dialogPreference").closest(".dialog-main").find(".dialog-footer > button:eq(0)");
|
|
|
|
|
if (isChange) {
|
|
|
|
|
$okBtn.prop("disabled", false);
|
|
|
|
|
} else {
|
|
|
|
|
$okBtn.prop("disabled", true);
|
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
|
2014-11-18 05:03:08 +03:00
|
|
|
|
$("#dialogPreference").dialog({
|
|
|
|
|
"modal": true,
|
2014-12-01 11:54:22 +03:00
|
|
|
|
"height": 280,
|
2014-11-18 05:03:08 +03:00
|
|
|
|
"width": 800,
|
2015-09-08 04:27:01 +03:00
|
|
|
|
"title": config.label.preference,
|
2014-11-18 05:03:08 +03:00
|
|
|
|
"okText": config.label.apply,
|
|
|
|
|
"cancelText": config.label.cancel,
|
|
|
|
|
"afterOpen": function () {
|
|
|
|
|
var $okBtn = $("#dialogPreference").closest(".dialog-main").find(".dialog-footer > button:eq(0)");
|
|
|
|
|
$okBtn.prop("disabled", true);
|
|
|
|
|
},
|
|
|
|
|
"ok": function () {
|
|
|
|
|
var request = newWideRequest(),
|
|
|
|
|
$dialogPreference = $("#dialogPreference"),
|
|
|
|
|
$fontFamily = $dialogPreference.find("input[name=fontFamily]"),
|
|
|
|
|
$fontSize = $dialogPreference.find("input[name=fontSize]"),
|
2014-12-08 11:11:43 +03:00
|
|
|
|
$goFmt = $dialogPreference.find("select[name=goFmt]"),
|
2017-03-27 16:31:35 +03:00
|
|
|
|
$GoBuildArgsForLinux = $dialogPreference.find("input[name=GoBuildArgsForLinux]"),
|
|
|
|
|
$GoBuildArgsForWindows = $dialogPreference.find("input[name=GoBuildArgsForWindows]"),
|
|
|
|
|
$GoBuildArgsForDarwin = $dialogPreference.find("input[name=GoBuildArgsForDarwin]"),
|
2014-11-18 05:03:08 +03:00
|
|
|
|
$workspace = $dialogPreference.find("input[name=workspace]"),
|
|
|
|
|
$password = $dialogPreference.find("input[name=password]"),
|
2014-12-08 09:02:39 +03:00
|
|
|
|
$email = $dialogPreference.find("input[name=email]"),
|
2014-12-08 11:11:43 +03:00
|
|
|
|
$locale = $dialogPreference.find("select[name=locale]"),
|
|
|
|
|
$theme = $dialogPreference.find("select[name=theme]"),
|
2014-11-30 05:18:17 +03:00
|
|
|
|
$editorFontFamily = $dialogPreference.find("input[name=editorFontFamily]"),
|
|
|
|
|
$editorFontSize = $dialogPreference.find("input[name=editorFontSize]"),
|
|
|
|
|
$editorLineHeight = $dialogPreference.find("input[name=editorLineHeight]"),
|
2014-12-08 11:11:43 +03:00
|
|
|
|
$editorTheme = $dialogPreference.find("select[name=editorTheme]"),
|
2015-05-11 10:46:17 +03:00
|
|
|
|
$editorTabSize = $dialogPreference.find("input[name=editorTabSize]"),
|
|
|
|
|
$keymap = $dialogPreference.find("select[name=keymap]");
|
2014-11-18 05:03:08 +03:00
|
|
|
|
|
|
|
|
|
$.extend(request, {
|
|
|
|
|
"fontFamily": $fontFamily.val(),
|
|
|
|
|
"fontSize": $fontSize.val(),
|
|
|
|
|
"goFmt": $goFmt.val(),
|
2017-03-27 16:31:35 +03:00
|
|
|
|
"GoBuildArgsForLinux": $GoBuildArgsForLinux.val(),
|
|
|
|
|
"GoBuildArgsForWindows": $GoBuildArgsForWindows.val(),
|
|
|
|
|
"GoBuildArgsForDarwin": $GoBuildArgsForDarwin.val(),
|
2014-11-18 05:03:08 +03:00
|
|
|
|
"workspace": $workspace.val(),
|
|
|
|
|
"password": $password.val(),
|
2014-11-30 05:18:17 +03:00
|
|
|
|
"locale": $locale.val(),
|
|
|
|
|
"theme": $theme.val(),
|
|
|
|
|
"editorFontFamily": $editorFontFamily.val(),
|
|
|
|
|
"editorFontSize": $editorFontSize.val(),
|
|
|
|
|
"editorLineHeight": $editorLineHeight.val(),
|
2014-12-01 09:49:16 +03:00
|
|
|
|
"editorTheme": $editorTheme.val(),
|
2015-05-11 10:46:17 +03:00
|
|
|
|
"editorTabSize": $editorTabSize.val(),
|
|
|
|
|
"keymap": $keymap.val()
|
2014-11-18 05:03:08 +03:00
|
|
|
|
});
|
2015-11-24 11:44:34 +03:00
|
|
|
|
|
2015-05-11 10:46:17 +03:00
|
|
|
|
if (config.keymap !== $keymap.val()) {
|
|
|
|
|
window.location.reload();
|
|
|
|
|
}
|
2014-11-18 05:03:08 +03:00
|
|
|
|
|
|
|
|
|
$.ajax({
|
|
|
|
|
type: 'POST',
|
2019-05-17 04:27:22 +03:00
|
|
|
|
url: '/preference',
|
2014-11-18 05:03:08 +03:00
|
|
|
|
data: JSON.stringify(request),
|
2015-11-24 12:39:35 +03:00
|
|
|
|
success: function (result, textStatus, jqXHR) {
|
|
|
|
|
if (!result.succ) {
|
2014-11-18 05:03:08 +03:00
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
$fontFamily.data("value", $fontFamily.val());
|
|
|
|
|
$fontSize.data("value", $fontSize.val());
|
|
|
|
|
$goFmt.data("value", $goFmt.val());
|
2017-03-27 16:31:35 +03:00
|
|
|
|
$GoBuildArgsForLinux.data("value", $GoBuildArgsForLinux.val());
|
|
|
|
|
$GoBuildArgsForWindows.data("value", $GoBuildArgsForWindows.val());
|
|
|
|
|
$GoBuildArgsForDarwin.data("value", $GoBuildArgsForDarwin.val());
|
2014-11-18 05:03:08 +03:00
|
|
|
|
$workspace.data("value", $workspace.val());
|
|
|
|
|
$password.data("value", $password.val());
|
2014-12-08 09:02:39 +03:00
|
|
|
|
$email.data("value", $email.val());
|
2014-11-18 05:03:08 +03:00
|
|
|
|
$locale.data("value", $locale.val());
|
2014-11-30 05:18:17 +03:00
|
|
|
|
$theme.data("value", $theme.val());
|
|
|
|
|
$editorFontFamily.data("value", $editorFontFamily.val());
|
|
|
|
|
$editorFontSize.data("value", $editorFontSize.val());
|
|
|
|
|
$editorLineHeight.data("value", $editorLineHeight.val());
|
|
|
|
|
$editorTheme.data("value", $editorTheme.val());
|
2014-12-01 09:49:16 +03:00
|
|
|
|
$editorTabSize.data("value", $editorTabSize.val());
|
2015-05-11 10:46:17 +03:00
|
|
|
|
$keymap.data("value", $keymap.val());
|
2015-11-24 11:44:34 +03:00
|
|
|
|
|
2015-05-11 10:46:17 +03:00
|
|
|
|
// update the config
|
|
|
|
|
config.keymap = $keymap.val();
|
2014-11-18 05:03:08 +03:00
|
|
|
|
|
|
|
|
|
var $okBtn = $("#dialogPreference").closest(".dialog-main").find(".dialog-footer > button:eq(0)");
|
|
|
|
|
$okBtn.prop("disabled", true);
|
2014-12-01 10:19:59 +03:00
|
|
|
|
|
2019-05-17 04:27:22 +03:00
|
|
|
|
$("#themesLink").attr("href", '/static/css/themes/' + $theme.val() + '.css');
|
2014-12-01 10:19:59 +03:00
|
|
|
|
|
2014-12-01 10:25:21 +03:00
|
|
|
|
config.editorTheme = $editorTheme.val();
|
|
|
|
|
for (var i = 0, ii = editors.data.length; i < ii; i++) {
|
|
|
|
|
editors.data[i].editor.setOption("theme", $editorTheme.val());
|
|
|
|
|
}
|
2014-11-18 05:03:08 +03:00
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
new Tabs({
|
|
|
|
|
id: ".preference"
|
|
|
|
|
});
|
|
|
|
|
});
|
2014-12-01 10:19:59 +03:00
|
|
|
|
}
|
2017-03-27 04:58:05 +03:00
|
|
|
|
};
|