diff --git a/data/user_workspaces/admin/src/format/test.css b/data/user_workspaces/admin/src/format/test.css index 1f4ed9e..2d33df6 100644 --- a/data/user_workspaces/admin/src/format/test.css +++ b/data/user_workspaces/admin/src/format/test.css @@ -1,6 +1,6 @@ /* start icon */ -@font-face { +1 @font-face { font-family: 'icomoon'; 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'); diff --git a/static/js/dialog.js b/static/js/dialog.js index 073ca4d..08a3e15 100644 --- a/static/js/dialog.js +++ b/static/js/dialog.js @@ -37,7 +37,7 @@ "closeIconHover": "dialog-close-icon-hover", "title": "dialog-title" } - } + }; }; $.extend(Dialog.prototype, { @@ -174,6 +174,10 @@ $.dialog._close(id, settings); } }); + + if (typeof settings.afterInit === "function") { + settings.afterInit(); + } }, _bindMove: function (id, className) { $("#" + id + "Dialog ." + className).mousedown(function (event) { diff --git a/static/js/editors.js b/static/js/editors.js index d03d54e..7dfbb07 100644 --- a/static/js/editors.js +++ b/static/js/editors.js @@ -2,6 +2,32 @@ var editors = { data: [], tabs: {}, 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({ id: ".edit-panel", clickAfter: function (id) { @@ -23,6 +49,26 @@ var editors = { 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) { if (id === 'startPage') { // 当前关闭的 tab 是起始页 return false; @@ -31,8 +77,6 @@ var editors = { // 移除编辑器 for (var i = 0, ii = editors.data.length; i < ii; i++) { 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); break; } @@ -81,7 +125,7 @@ var editors = { }); this._initCodeMirrorHotKeys(); - this.openStartPage() + this.openStartPage(); }, openStartPage: function () { var dateFormat = function (time, fmt) { @@ -136,7 +180,7 @@ var editors = { + article.articlePermalink + "'>" + article.articleTitle + "  " + dateFormat(article.articleCreateTime, 'yyyy-MM-dd hh:mm'); - +"" + +""; } $("#startPage .news").html(listHTML + ""); diff --git a/static/js/tabs.js b/static/js/tabs.js index ff4c1a5..1b773d9 100644 --- a/static/js/tabs.js +++ b/static/js/tabs.js @@ -22,8 +22,16 @@ $.extend(Tabs.prototype, { }); obj._$tabs.on("click", ".ico-close", function (event) { - var id = $(this).parent().data("index"); - _that.del(id); + var id = $(this).parent().data("index"), + isRemove = true; + + if (typeof obj.removeBefore === 'function') { + isRemove = obj.removeBefore(id); + } + + if (isRemove) { + _that.del(id); + } event.stopPropagation(); }); }, @@ -65,6 +73,7 @@ $.extend(Tabs.prototype, { $tabs = this.obj._$tabs, stack = this.obj._stack, prevId = null; + $tabs.children("div[data-index='" + id + "']").remove(); $tabsPanel.children("div[data-index='" + id + "']").remove(); @@ -74,7 +83,7 @@ $.extend(Tabs.prototype, { stack.splice(i, 1); } } - + prevId = stack[stack.length - 1]; if (typeof this.obj.removeAfter === 'function') { diff --git a/views/index.html b/views/index.html index c40c7c8..698a401 100644 --- a/views/index.html +++ b/views/index.html @@ -222,50 +222,55 @@ +
+ + + +