From 407e4c3ac499b5610544e814609853b32b13b734 Mon Sep 17 00:00:00 2001 From: yfqin Date: Tue, 20 Jan 2015 14:08:52 +0800 Subject: [PATCH 1/2] =?UTF-8?q?=E7=AC=94=E8=AE=B0=E7=9A=84Tag=E4=B8=AD?= =?UTF-8?q?=E4=B8=8D=E5=85=81=E8=AE=B8=E5=87=BA=E7=8E=B0=E6=8D=A2=E8=A1=8C?= =?UTF-8?q?=E7=AC=A6?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- public/js/app/tag-min.js | 2 +- public/js/app/tag.js | 26 ++++++++++++++++---------- 2 files changed, 17 insertions(+), 11 deletions(-) diff --git a/public/js/app/tag-min.js b/public/js/app/tag-min.js index 38c2ada..fb6b99d 100644 --- a/public/js/app/tag-min.js +++ b/public/js/app/tag-min.js @@ -1 +1 @@ -Tag.classes={"蓝色":"label label-blue","红色":"label label-red","绿色":"label label-green","黄色":"label label-yellow",blue:"label label-blue",red:"label label-red",green:"label label-green",yellow:"label label-yellow"};Tag.mapCn2En={"蓝色":"blue","红色":"red","绿色":"green","黄色":"yellow"};Tag.mapEn2Cn={blue:"蓝色",red:"红色",green:"绿色",yellow:"黄色"};Tag.t=$("#tags");Tag.getTags=function(){var tags=[];Tag.t.children().each(function(){var text=$(this).text();text=text.substring(0,text.length-1);text=Tag.mapCn2En[text]||text;tags.push(text)});return tags};Tag.clearTags=function(){Tag.t.html("")};Tag.renderTags=function(tags){Tag.t.html("");if(isEmpty(tags)){return}for(var i=0;i?',classes,Note._toHtmlEntity(text));$("#noteReadTags").append(tag)}};Tag.appendTag=function(tag){var isColor=false;var classes,text;if(typeof tag=="object"){classes=tag.classes;text=tag.text;if(!text){return}}else{tag=$.trim(tag);text=tag;if(!text){return}var classes=Tag.classes[text];if(classes){isColor=true}else{classes="label label-default"}}if(LEA.locale=="zh"){text=Tag.mapEn2Cn[text]||text}tag=tt('?X',classes,Note._toHtmlEntity(text));$("#tags").children().each(function(){if(isColor){var tagHtml=$("
").append($(this).clone()).html();if(tagHtml==tag){$(this).remove()}}else if(text+"X"==$(this).text()){$(this).remove()}});$("#tags").append(tag);hideTagList();if(!isColor){reRenderTags()}};function reRenderTags(){var defautClasses=["label label-default","label label-info"];var i=0;$("#tags").children().each(function(){var thisClasses=$(this).attr("class");if(thisClasses=="label label-default"||thisClasses=="label label-info"){$(this).removeClass(thisClasses).addClass(defautClasses[i%2]);i++}})}Tag.renderTagNav=function(tags){tags=tags||[];for(var i in tags){var tag=tags[i];if(tag=="red"||tag=="blue"||tag=="yellow"||tag=="green"){continue}var text=Note._toHtmlEntity(Tag.mapEn2Cn[tag]||tag);var classes=Tag.classes[tag]||"label label-default";$("#tagNav").append(tt('
  • ?
  • ',text,classes,text))}};$(function(){$("#addTagTrigger").click(function(){$(this).hide();$("#addTagInput").show().focus().val("")});$("#addTagInput").click(function(event){showTagList(event)});$("#addTagInput").blur(function(){var val=$(this).val();if(val){Tag.appendTag(val,true)}return;$("#addTagTrigger").show();$("#addTagInput").hide()});$("#addTagInput").keydown(function(e){if(e.keyCode==13){hideTagList();if($("#addTagInput").val()){$(this).trigger("blur");$("#addTagTrigger").trigger("click")}else{$(this).trigger("blur")}}});$("#tagColor li").click(function(event){var a;if($(this).attr("role")){a=$(this).find("span")}else{a=$(this)}Tag.appendTag({classes:a.attr("class"),text:a.text()})});$("#tags").on("click","i",function(){$(this).parent().remove();reRenderTags()});function searchTag(){var tag=$.trim($(this).data("tag"));Note.curChangedSaveIt();Note.clearAll();$("#tagSearch").html($(this).html()).show();showLoading();ajaxGet("/note/searchNoteByTags",{tags:[tag]},function(notes){hideLoading();if(notes){Note.renderNotes(notes);if(!isEmpty(notes)){Note.changeNote(notes[0].NoteId)}}})}$("#myTag .folderBody").on("click","li",searchTag);$("#minTagNav").on("click","li",searchTag)}); \ No newline at end of file +Tag.classes={"蓝色":"label label-blue","红色":"label label-red","绿色":"label label-green","黄色":"label label-yellow",blue:"label label-blue",red:"label label-red",green:"label label-green",yellow:"label label-yellow"};Tag.mapCn2En={"蓝色":"blue","红色":"red","绿色":"green","黄色":"yellow"};Tag.mapEn2Cn={blue:"蓝色",red:"红色",green:"绿色",yellow:"黄色"};Tag.t=$("#tags");Tag.getTags=function(){var tags=[];Tag.t.children().each(function(){var text=$(this).text();text=text.substring(0,text.length-1);text=Tag.mapCn2En[text]||text;tags.push(text)});return tags};Tag.clearTags=function(){Tag.t.html("")};Tag.renderTags=function(tags){Tag.clearTags();if(isEmpty(tags)){return}for(var i=0;i?',Tag.classes[text]||getNextDefaultClasses(),Note._toHtmlEntity(text)))}$("#noteReadTags").append(html.join(""))};Tag.appendTag=function(tag){var isColor=false;var classes,text;if(typeof tag=="object"){classes=tag.classes;text=tag.text;if(!text){return}}else{tag=$.trim(tag);text=tag;if(!text){return}var classes=Tag.classes[text];if(classes){isColor=true}else{classes="label label-default"}}if(LEA.locale=="zh"){text=Tag.mapEn2Cn[text]||text}text=text.replace(/[\r\n]/g,"");tag=tt('?X',classes,Note._toHtmlEntity(text));$("#tags").children().each(function(){if(isColor){var tagHtml=$("
    ").append($(this).clone()).html();if(tagHtml==tag){$(this).remove()}}else if(text+"X"==$(this).text()){$(this).remove()}});$("#tags").append(tag);hideTagList();if(!isColor){reRenderTags()}};function reRenderTags(){var defautClasses=["label label-default","label label-info"];var i=0;$("#tags").children().each(function(){var thisClasses=$(this).attr("class");if(thisClasses=="label label-default"||thisClasses=="label label-info"){$(this).removeClass(thisClasses).addClass(defautClasses[i%2]);i++}})}Tag.renderTagNav=function(tags){tags=tags||[];for(var i in tags){var tag=tags[i];if(tag=="red"||tag=="blue"||tag=="yellow"||tag=="green"){continue}var text=Note._toHtmlEntity(Tag.mapEn2Cn[tag]||tag);text=text.replace(/[\r\n]/g,"");var classes=Tag.classes[tag]||"label label-default";$("#tagNav").append(tt('
  • ?
  • ',text,classes,text))}};$(function(){$("#addTagTrigger").click(function(){$(this).hide();$("#addTagInput").show().focus().val("")});$("#addTagInput").click(function(event){showTagList(event)});$("#addTagInput").blur(function(){var val=$(this).val();if(val){Tag.appendTag(val,true)}return;$("#addTagTrigger").show();$("#addTagInput").hide()});$("#addTagInput").keydown(function(e){if(e.keyCode==13){hideTagList();if($("#addTagInput").val()){$(this).trigger("blur");$("#addTagTrigger").trigger("click")}else{$(this).trigger("blur")}}});$("#tagColor li").click(function(event){var a;if($(this).attr("role")){a=$(this).find("span")}else{a=$(this)}Tag.appendTag({classes:a.attr("class"),text:a.text()})});$("#tags").on("click","i",function(){$(this).parent().remove();reRenderTags()});function searchTag(){var tag=$.trim($(this).data("tag"));Note.curChangedSaveIt();Note.clearAll();$("#tagSearch").html($(this).html()).show();showLoading();ajaxGet("/note/searchNoteByTags",{tags:[tag]},function(notes){hideLoading();if(notes){Note.renderNotes(notes);if(!isEmpty(notes)){Note.changeNote(notes[0].NoteId)}}})}$("#myTag .folderBody").on("click","li",searchTag);$("#minTagNav").on("click","li",searchTag)}); \ No newline at end of file diff --git a/public/js/app/tag.js b/public/js/app/tag.js index 4b72111..9b30dea 100644 --- a/public/js/app/tag.js +++ b/public/js/app/tag.js @@ -50,7 +50,7 @@ Tag.clearTags = function() { // 设置tags // called by Note Tag.renderTags = function(tags) { - Tag.t.html(""); + Tag.clearTags(); if(isEmpty(tags)) { return; } @@ -88,6 +88,7 @@ Tag.renderReadOnlyTags = function(tags) { $("#noteReadTags").html(""); if(isEmpty(tags)) { $("#noteReadTags").html(getMsg("noTag")); + return; } var i = true; @@ -101,17 +102,20 @@ Tag.renderReadOnlyTags = function(tags) { } } - for(var i in tags) { - var text = tags[i]; - text = Tag.mapEn2Cn[text] || text; - var classes = Tag.classes[text]; - if(!classes) { - classes = getNextDefaultClasses(); - } - tag = tt('?', classes, Note._toHtmlEntity(text)); + var html = [], text; - $("#noteReadTags").append(tag); + for(var i = 0, j = tags.length; i?', + Tag.classes[text] || getNextDefaultClasses(), + Note._toHtmlEntity(text) + )); } + + $("#noteReadTags").append(html.join('')); } // 添加tag @@ -144,6 +148,7 @@ Tag.appendTag = function(tag) { if(LEA.locale == "zh") { text = Tag.mapEn2Cn[text] || text; } + text = text.replace(/[\r\n]/g, ''); tag = tt('?X', classes, Note._toHtmlEntity(text)); // 避免重复 @@ -193,6 +198,7 @@ Tag.renderTagNav = function(tags) { continue; } var text = Note._toHtmlEntity(Tag.mapEn2Cn[tag] || tag); + text = text.replace(/[\r\n]/g, ''); var classes = Tag.classes[tag] || "label label-default"; $("#tagNav").append(tt('
  • ?
  • ', text, classes, text)); } From cbaa52e57b527dadc28bd9aca306b76945c89c58 Mon Sep 17 00:00:00 2001 From: dds_feng Date: Sat, 24 Jan 2015 17:28:28 +0800 Subject: [PATCH 2/2] staticUrl -> siteUrl --- app/controllers/BlogController.go | 21 +++++++++------------ 1 file changed, 9 insertions(+), 12 deletions(-) diff --git a/app/controllers/BlogController.go b/app/controllers/BlogController.go index 98c6c36..9cca9ab 100644 --- a/app/controllers/BlogController.go +++ b/app/controllers/BlogController.go @@ -57,9 +57,9 @@ func (c Blog) render(templateName string, themePath string) revel.Result { isPreview = true themePath = themePath2.(string) c.setPreviewUrl() - + // 因为common的themeInfo是从UserBlog.ThemeId来取的, 所以这里要fugai下 - c.RenderArgs["themeInfo"] = c.RenderArgs["themeInfoPreview"]; + c.RenderArgs["themeInfo"] = c.RenderArgs["themeInfoPreview"] } return blog.RenderTemplate(templateName, c.RenderArgs, revel.BasePath+"/"+themePath, isPreview) } @@ -119,9 +119,9 @@ func (c Blog) setPreviewUrl() { indexUrl = blogUrl + "/" + userIdOrEmail cateUrl = blogUrl + "/cate/" + userIdOrEmail // /notebookId - postUrl = blogUrl + "/post/" + userIdOrEmail // /xxxxx + postUrl = blogUrl + "/post/" + userIdOrEmail // /xxxxx searchUrl = blogUrl + "/search/" + userIdOrEmail // blog.leanote.com/search/userId - singleUrl = blogUrl + "/single/" + userIdOrEmail // blog.leanote.com/single/singleId + singleUrl = blogUrl + "/single/" + userIdOrEmail // blog.leanote.com/single/singleId archiveUrl = blogUrl + "/archives/" + userIdOrEmail // blog.leanote.com/archive/userId tagsUrl = blogUrl + "/tags/" + userIdOrEmail // blog.leanote.com/archive/userId @@ -143,10 +143,6 @@ func (c Blog) setPreviewUrl() { // 各种地址设置 func (c Blog) setUrl(userBlog info.UserBlog, userInfo info.User) { // 主页 http://leanote.com/blog/life or http://blog.leanote.com/life or http:// xxxx.leanote.com or aa.com - host := c.Request.Request.Host - var staticUrl = configService.GetUserUrl(strings.Split(host, ":")[0]) - // staticUrl == host, 为保证同源!!! 只有host, http://leanote.com, http://blog/leanote.com - // life.leanote.com, lealife.com siteUrl := configService.GetSiteUrl() blogUrls := blogService.GetBlogUrls(&userBlog, &userInfo) // 分类 @@ -173,12 +169,12 @@ func (c Blog) setUrl(userBlog info.UserBlog, userInfo info.User) { c.RenderArgs["prettifyJsUrl"] = siteUrl + "/js/google-code-prettify/prettify.js" c.RenderArgs["prettifyCssUrl"] = siteUrl + "/js/google-code-prettify/prettify.css" - c.RenderArgs["blogCommonJsUrl"] = siteUrl + "/public/blog/js/common.js" + c.RenderArgs["blogCommonJsUrl"] = siteUrl + "/blog/js/common.js" - c.RenderArgs["shareCommentCssUrl"] = siteUrl + "/public/blog/css/share_comment.css" - c.RenderArgs["shareCommentJsUrl"] = siteUrl + "/public/blog/js/share_comment.js" + c.RenderArgs["shareCommentCssUrl"] = siteUrl + "/blog/css/share_comment.css" + c.RenderArgs["shareCommentJsUrl"] = siteUrl + "/blog/js/share_comment.js" - c.RenderArgs["fontAwesomeUrl"] = staticUrl + "/css/font-awesome-4.2.0/css/font-awesome.css" + c.RenderArgs["fontAwesomeUrl"] = siteUrl + "/css/font-awesome-4.2.0/css/font-awesome.css" c.RenderArgs["bootstrapCssUrl"] = siteUrl + "/css/bootstrap.css" c.RenderArgs["bootstrapJsUrl"] = siteUrl + "/js/bootstrap-min.js" @@ -462,6 +458,7 @@ func (c Blog) Archives(userIdOrEmail string, cateId string, year, month int) (re // 进入某个用户的博客 var blogPageSize = 5 var searchBlogPageSize = 30 + // 分类 /cate/xxxxxxxx?notebookId=1212 func (c Blog) Cate(userIdOrEmail string, notebookId string) (re revel.Result) { // 自定义域名