菜单起始页

This commit is contained in:
Van 2014-10-20 17:32:06 +08:00
parent d018b7d801
commit 1e4b5ab3b4
4 changed files with 73 additions and 49 deletions

View File

@ -17,11 +17,12 @@
"Workspace": "{pwd}/data/user_workspaces/admin", "Workspace": "{pwd}/data/user_workspaces/admin",
"LatestSessionContent": { "LatestSessionContent": {
"FileTree": [ "FileTree": [
"D:\\GoGoGo\\src\\github.com\\b3log\\wide\\data\\user_workspaces\\admin\\src\\mytest", "E:\\Work\\go\\src\\github.com\\b3log\\wide\\data\\user_workspaces\\admin\\src\\mytest",
"D:\\GoGoGo\\src\\github.com\\b3log\\wide\\data\\user_workspaces\\admin\\src\\mytest\\hello", "E:\\Work\\go\\src\\github.com\\b3log\\wide\\data\\user_workspaces\\admin\\src\\mytest\\hello"
"D:\\GoGoGo\\src\\github.com\\b3log\\wide\\data\\user_workspaces\\admin\\src\\mytest\\time" ],
"Files": [
"E:\\Work\\go\\src\\github.com\\b3log\\wide\\data\\user_workspaces\\admin\\src\\mytest\\hello\\main.go"
], ],
"Files": [],
"CurrentFile": "" "CurrentFile": ""
} }
} }

View File

@ -76,48 +76,49 @@ var editors = {
}); });
this._initCodeMirrorHotKeys(); this._initCodeMirrorHotKeys();
this._initStartPage() this.openStartPage()
}, },
_initStartPage: function () { openStartPage: function () {
editors.tabs.add({ editors.tabs.add({
id: "startPage", id: "startPage",
title: '<span title="' + config.label.initialise + '">' + config.label.initialise + '</span>', title: '<span title="' + config.label.initialise + '">' + config.label.initialise + '</span>',
content: '<div id="startPage"></div>' content: '<div id="startPage"></div>',
}); after: function () {
$("#startPage").load('/start');
$.ajax({
url: "http://symphony.b3log.org/apis/articles?tags=wide,golang&p=1&size=30",
type: "GET",
dataType: "jsonp",
jsonp: "callback",
error: function () {
$("#startPage").html("Loading B3log Announcement failed :-(");
},
success: function (data, textStatus) {
var articles = data.articles;
if (0 === articles.length) {
return;
}
$("#startPage").load('/start'); // 按 size = 30 取,但只保留最多 10 篇
$.ajax({ var length = articles.length;
url: "http://symphony.b3log.org/apis/articles?tags=wide,golang&p=1&size=30", if (length > 10) {
type: "GET", length = 10;
dataType: "jsonp", }
jsonp: "callback",
error: function () {
$("#startPage").html("Loading B3log Announcement failed :-(");
},
success: function (data, textStatus) {
var articles = data.articles;
if (0 === articles.length) {
return;
}
// 按 size = 30 取,但只保留最多 10 篇 var listHTML = "<ul>";
var length = articles.length; for (var i = 0; i < length; i++) {
if (length > 10) { var article = articles[i];
length = 10; var articleLiHtml = "<li>"
} + "<a target='_blank' href='http://symphony.b3log.org" + article.articlePermalink + "'>"
+ article.articleTitle + "</a>&nbsp; <span class='date'>" + article.articleCreateTime;
+"</span></li>"
listHTML += articleLiHtml;
}
listHTML += "</ul>";
var listHTML = "<ul>"; $("#startPage .news").html(listHTML);
for (var i = 0; i < length; i++) { }
var article = articles[i]; });
var articleLiHtml = "<li>"
+ "<a target='_blank' href='http://symphony.b3log.org" + article.articlePermalink + "'>"
+ article.articleTitle + "</a>&nbsp; <span class='date'>" + article.articleCreateTime;
+"</span></li>"
listHTML += articleLiHtml;
}
listHTML += "</ul>";
$("#startPage .news").html(listHTML);
} }
}); });
}, },

View File

@ -1,4 +1,4 @@
var Tabs = function(obj) { var Tabs = function (obj) {
obj._$tabsPanel = $(obj.id + " > .tabs-panel"); obj._$tabsPanel = $(obj.id + " > .tabs-panel");
obj._$tabs = $(obj.id + " > .tabs"); obj._$tabs = $(obj.id + " > .tabs");
@ -8,10 +8,10 @@ var Tabs = function(obj) {
}; };
$.extend(Tabs.prototype, { $.extend(Tabs.prototype, {
_init: function(obj) { _init: function (obj) {
var _that = this; var _that = this;
obj._$tabs.on("click", "div", function(event) { obj._$tabs.on("click", "div", function (event) {
var id = $(this).data("index"); var id = $(this).data("index");
_that.setCurrent(id); _that.setCurrent(id);
if (typeof (obj.clickAfter) === "function") { if (typeof (obj.clickAfter) === "function") {
@ -19,13 +19,31 @@ $.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); _that.del(id);
event.stopPropagation(); event.stopPropagation();
}); });
}, },
add: function(data) { _hasId: function (id) {
var $tabs = this.obj._$tabs;
if ($tabs.find("div[data-index=" + id + "]").length === 0) {
return false;
}
return true;
},
add: function (data) {
// 添加当前 tab
if (this.getCurrentId() === data.id) {
return false;
}
// 当前 tab 已经存在
if (this._hasId(data.id)) {
this.setCurrent(data.id);
return false;
}
var $tabsPanel = this.obj._$tabsPanel, var $tabsPanel = this.obj._$tabsPanel,
$tabs = this.obj._$tabs; $tabs = this.obj._$tabs;
@ -38,8 +56,12 @@ $.extend(Tabs.prototype, {
+ data.title + '<span class="ico-close font-ico"></span></div>'); + data.title + '<span class="ico-close font-ico"></span></div>');
$tabsPanel.append('<div data-index="' + data.id + '">' + data.content $tabsPanel.append('<div data-index="' + data.id + '">' + data.content
+ '</div>'); + '</div>');
if (typeof data.after === 'function') {
data.after();
}
}, },
del: function(id) { del: function (id) {
var $tabsPanel = this.obj._$tabsPanel, var $tabsPanel = this.obj._$tabsPanel,
$tabs = this.obj._$tabs, $tabs = this.obj._$tabs,
prevId = undefined, prevId = undefined,
@ -60,11 +82,11 @@ $.extend(Tabs.prototype, {
this.obj.removeAfter(id, prevId); this.obj.removeAfter(id, prevId);
this.setCurrent(prevId); this.setCurrent(prevId);
}, },
getCurrentId: function() { getCurrentId: function () {
var $tabs = this.obj._$tabs; var $tabs = this.obj._$tabs;
return $tabs.children(".current").data("index"); return $tabs.children(".current").data("index");
}, },
setCurrent: function(id) { setCurrent: function (id) {
if (!id) { if (!id) {
return false; return false;
} }

View File

@ -80,8 +80,8 @@
{{.i18n.report_issues}} {{.i18n.report_issues}}
</li> </li>
<li class="hr"></li> <li class="hr"></li>
<li onclick="window.open('/doc/{{.locale}}/index.html')"> <li onclick="editors.openStartPage()">
<span>{{.i18n.start_page}}</span> <span>{{.i18n.start_page}}</span>
</li> </li>
<li onclick="window.open('/doc/{{.locale}}/index.html')"> <li onclick="window.open('/doc/{{.locale}}/index.html')">
<span>{{.i18n.about}}</span> <span>{{.i18n.about}}</span>