This commit is contained in:
Van 2014-11-01 12:05:52 +08:00
parent 7cb70347bf
commit 9c1d5b09a0
5 changed files with 114 additions and 52 deletions

View File

@ -1,6 +1,6 @@
/* start icon */ /* start icon */
@font-face { 1 @font-face {
font-family: 'icomoon'; font-family: 'icomoon';
src: url('fonts/icomoon.eot?35cb2z'); src: url('fonts/icomoon.eot?35cb2z');
src: url('fonts/icomoon.eot?#iefix35cb2z') format('embedded-opentype'), url('fonts/icomoon.woff?35cb2z') format('woff'), url('fonts/icomoon.ttf?35cb2z') format('truetype'), url('fonts/icomoon.svg?35cb2z#icomoon') format('svg'); src: url('fonts/icomoon.eot?#iefix35cb2z') format('embedded-opentype'), url('fonts/icomoon.woff?35cb2z') format('woff'), url('fonts/icomoon.ttf?35cb2z') format('truetype'), url('fonts/icomoon.svg?35cb2z#icomoon') format('svg');

View File

@ -37,7 +37,7 @@
"closeIconHover": "dialog-close-icon-hover", "closeIconHover": "dialog-close-icon-hover",
"title": "dialog-title" "title": "dialog-title"
} }
} };
}; };
$.extend(Dialog.prototype, { $.extend(Dialog.prototype, {
@ -174,6 +174,10 @@
$.dialog._close(id, settings); $.dialog._close(id, settings);
} }
}); });
if (typeof settings.afterInit === "function") {
settings.afterInit();
}
}, },
_bindMove: function (id, className) { _bindMove: function (id, className) {
$("#" + id + "Dialog ." + className).mousedown(function (event) { $("#" + id + "Dialog ." + className).mousedown(function (event) {

View File

@ -2,6 +2,32 @@ var editors = {
data: [], data: [],
tabs: {}, tabs: {},
init: function () { init: function () {
$("#dialogCloseEditor").dialog({
"modal": true,
"height": 26,
"width": 260,
"title": config.label.tip,
"hideFooter": true,
"afterInit": function () {
$("#dialogCloseEditor button.save").click(function () {
var i = $("#dialogCloseEditor").data("index");
wide.fmt(tree.fileTree.getNodeByTId(editors.data[i].id).path, editors.data[i].editor);
editors.tabs.del(editors.data[i].id);
$("#dialogCloseEditor").dialog("close");
});
$("#dialogCloseEditor button.discard").click(function () {
$("#dialogCloseEditor").dialog("close");
});
$("#dialogCloseEditor button.cancel").click(function () {
var i = $("#dialogCloseEditor").data("index");
editors.tabs.del(editors.data[i].id);
$("#dialogCloseEditor").dialog("close");
});
}
});
editors.tabs = new Tabs({ editors.tabs = new Tabs({
id: ".edit-panel", id: ".edit-panel",
clickAfter: function (id) { clickAfter: function (id) {
@ -23,6 +49,26 @@ var editors = {
wide.curEditor.focus(); wide.curEditor.focus();
}, },
removeBefore: function (id) {
if (id === 'startPage') { // 当前关闭的 tab 是起始页
return false;
}
// 移除编辑器
for (var i = 0, ii = editors.data.length; i < ii; i++) {
if (editors.data[i].id === id) {
if (editors.data[i].editor.doc.isClean()) {
return true;
} else {
$("#dialogCloseEditor").dialog("open");
$("#dialogCloseEditor").data("index", i);
return false;
}
break;
}
}
},
removeAfter: function (id, nextId) { removeAfter: function (id, nextId) {
if (id === 'startPage') { // 当前关闭的 tab 是起始页 if (id === 'startPage') { // 当前关闭的 tab 是起始页
return false; return false;
@ -31,8 +77,6 @@ var editors = {
// 移除编辑器 // 移除编辑器
for (var i = 0, ii = editors.data.length; i < ii; i++) { for (var i = 0, ii = editors.data.length; i < ii; i++) {
if (editors.data[i].id === id) { if (editors.data[i].id === id) {
wide.fmt(tree.fileTree.getNodeByTId(editors.data[i].id).path, editors.data[i].editor);
editors.data.splice(i, 1); editors.data.splice(i, 1);
break; break;
} }
@ -81,7 +125,7 @@ var editors = {
}); });
this._initCodeMirrorHotKeys(); this._initCodeMirrorHotKeys();
this.openStartPage() this.openStartPage();
}, },
openStartPage: function () { openStartPage: function () {
var dateFormat = function (time, fmt) { var dateFormat = function (time, fmt) {
@ -136,7 +180,7 @@ var editors = {
+ article.articlePermalink + "'>" + article.articlePermalink + "'>"
+ article.articleTitle + "</a>&nbsp; <span class='date'>" + article.articleTitle + "</a>&nbsp; <span class='date'>"
+ dateFormat(article.articleCreateTime, 'yyyy-MM-dd hh:mm'); + dateFormat(article.articleCreateTime, 'yyyy-MM-dd hh:mm');
+"</span></li>" +"</span></li>";
} }
$("#startPage .news").html(listHTML + "</ul>"); $("#startPage .news").html(listHTML + "</ul>");

View File

@ -22,8 +22,16 @@ $.extend(Tabs.prototype, {
}); });
obj._$tabs.on("click", ".ico-close", function (event) { obj._$tabs.on("click", ".ico-close", function (event) {
var id = $(this).parent().data("index"); var id = $(this).parent().data("index"),
_that.del(id); isRemove = true;
if (typeof obj.removeBefore === 'function') {
isRemove = obj.removeBefore(id);
}
if (isRemove) {
_that.del(id);
}
event.stopPropagation(); event.stopPropagation();
}); });
}, },
@ -65,6 +73,7 @@ $.extend(Tabs.prototype, {
$tabs = this.obj._$tabs, $tabs = this.obj._$tabs,
stack = this.obj._stack, stack = this.obj._stack,
prevId = null; prevId = null;
$tabs.children("div[data-index='" + id + "']").remove(); $tabs.children("div[data-index='" + id + "']").remove();
$tabsPanel.children("div[data-index='" + id + "']").remove(); $tabsPanel.children("div[data-index='" + id + "']").remove();
@ -74,7 +83,7 @@ $.extend(Tabs.prototype, {
stack.splice(i, 1); stack.splice(i, 1);
} }
} }
prevId = stack[stack.length - 1]; prevId = stack[stack.length - 1];
if (typeof this.obj.removeAfter === 'function') { if (typeof this.obj.removeAfter === 'function') {

View File

@ -222,50 +222,55 @@
<input placeholder="{{.i18n.keyword}}" /> <input placeholder="{{.i18n.keyword}}" />
<input placeholder="{{.i18n.file_format}}" /> <input placeholder="{{.i18n.file_format}}" />
</div> </div>
<div id="dialogCloseEditor" class="dialog-form fn-none">
<button class="save">save</button>
<button class="discard">discard</button>
<button class="cancel">cancel</button>
</div>
<script> <script>
var config = { var config = {
"pathSeparator": {{.pathSeparator}}, "pathSeparator": '{{.pathSeparator}}',
"latestSessionContent": {{.latestSessionContent}}, "latestSessionContent": '{{.latestSessionContent}}',
"label": { "label": {
"restore_editor": "{{.i18n.restore_editor}}", "restore_editor": "{{.i18n.restore_editor}}",
"max_editor": "{{.i18n.max_editor}}", "max_editor": "{{.i18n.max_editor}}",
"delete": "{{.i18n.delete}}", "delete": "{{.i18n.delete}}",
"cancel": "{{.i18n.cancel}}", "cancel": "{{.i18n.cancel}}",
"goto_line": "{{.i18n.goto_line}}", "goto_line": "{{.i18n.goto_line}}",
"go": "{{.i18n.go}}", "go": "{{.i18n.go}}",
"create": "{{.i18n.create}}", "create": "{{.i18n.create}}",
"create_file": "{{.i18n.create_file}}", "create_file": "{{.i18n.create_file}}",
"create_dir": "{{.i18n.create_dir}}", "create_dir": "{{.i18n.create_dir}}",
"tip": "{{.i18n.tip}}", "tip": "{{.i18n.tip}}",
"confirm": "{{.i18n.confirm}}", "confirm": "{{.i18n.confirm}}",
"build_n_run": "{{.i18n.build_n_run}}", "build_n_run": "{{.i18n.build_n_run}}",
"stop": "{{.i18n.stop}}", "stop": "{{.i18n.stop}}",
"find_usages": "{{.i18n.find_usages}}", "find_usages": "{{.i18n.find_usages}}",
"search_text": "{{.i18n.search_text}}", "search_text": "{{.i18n.search_text}}",
"search": "{{.i18n.search}}", "search": "{{.i18n.search}}",
"start_page": "{{.i18n.start_page}}", "start_page": "{{.i18n.start_page}}",
"confirm_save": "{{.i18n.confirm_save}}", "confirm_save": "{{.i18n.confirm_save}}",
"community": "{{.i18n.community}}", "community": "{{.i18n.community}}",
"about": "{{.i18n.about}}", "about": "{{.i18n.about}}",
"new_version_available": "{{.i18n.new_version_available}}", "new_version_available": "{{.i18n.new_version_available}}",
"colon": "{{.i18n.colon}}", "colon": "{{.i18n.colon}}",
"uptodate": "{{.i18n.uptodate}}" "uptodate": "{{.i18n.uptodate}}"
}, },
"channel": { "channel": {
"editor": '{{.conf.EditorChannel}}', "editor": '{{.conf.EditorChannel}}',
"shell": '{{.conf.ShellChannel}}', "shell": '{{.conf.ShellChannel}}',
"output": '{{.conf.OutputChannel}}', "output": '{{.conf.OutputChannel}}',
"session": '{{.conf.SessionChannel}}' "session": '{{.conf.SessionChannel}}'
}, },
"wideSessionId": '{{.session.Id}}' "wideSessionId": '{{.session.Id}}'
}; };
// 发往 Wide 的所有 AJAX 请求需要使用该函数创建请求参数. // 发往 Wide 的所有 AJAX 请求需要使用该函数创建请求参数.
function newWideRequest() { function newWideRequest() {
var ret = { var ret = {
sid: config.wideSessionId sid: config.wideSessionId
} };
return ret; return ret;
} }
</script> </script>
<script type="text/javascript" src="{{.conf.StaticServer}}/static/js/lib/jquery-2.1.1.min.js"></script> <script type="text/javascript" src="{{.conf.StaticServer}}/static/js/lib/jquery-2.1.1.min.js"></script>