API, Tag
This commit is contained in:
app
controllers
db
info
init.golea
service
AttachService.goAuthService.goBlogService.goConfigService.goFileService.goNoteImageService.goNoteService.goNotebookService.goSessionService.goShareService.goTagService.goTrashService.goUpgradeService.goUserService.go
views
public
blog
css
js
themes
README.html
backup
default
archive.htmlcate.htmlcomment.htmlfooter.htmlheader.htmlhighlight.html
images
index.htmlnoise.pngpage.htmlpaging.htmlsearch.htmlsingle.htmlstyle.csstag_posts.htmltags.htmltheme.jsonview.htmlview.jselegant
archive.htmlcate.htmlcomment.htmlfooter.htmlheader.htmlhighlight.html
images
index.htmlpage.htmlpaging.htmlsearch.htmlsingle.htmlstyle.csstag_posts.htmltags.htmltheme.jsonview.htmlview.jsnav_fixed
default
archive.htmlcate.htmlfooter.htmlheader.htmlindex.htmlpaging.htmlpost.htmlpost_abstract.htmlsearch.htmlshare_comment.htmlsingle.htmlstyle.csstag_posts.htmltags.htmltheme.json
elegant
archive.htmlcate.htmlfooter.htmlheader.htmlindex.htmlpaging.htmlpost.htmlpost_abstract.htmlsearch.htmlshare_comment.htmlsingle.htmltag_posts.htmltags.htmltheme.json
nav_fixed
css
blog
bootstrap.csscss
font-awesome-4.0.3
css
fonts
FontAwesome.otffontawesome-webfont.eotfontawesome-webfont.svgfontawesome-webfont.ttffontawesome-webfont.woff
less
bordered-pulled.lesscore.lessfixed-width.lessfont-awesome.lessicons.lesslarger.lesslist.lessmixins.lesspath.lessrotated-flipped.lessspinning.lessstacked.lessvariables.less
scss
theme
dist
themes
js
libs
ace
ace-modify.txtace.js
ck
ext-beautify-min.jsext-chromevox-min.jsext-elastic_tabstops_lite-min.jsext-emmet-min.jsext-error_marker-min.jsext-keybinding_menu-min.jsext-language_tools-min.jsext-linking-min.jsext-modelist-min.jsext-old_ie-min.jsext-settings_menu-min.jsext-spellcheck-min.jsext-split-min.jsext-static_highlight-min.jsext-statusbar-min.jsext-textarea-min.jsext-themelist-min.jsext-whitespace-min.jskeybinding-emacs-min.jsmode-abap-min.jsmode-actionscript-min.jsmode-ada-min.jsmode-apache_conf-min.jsmode-asciidoc-min.jsmode-assembly_x86-min.jsmode-autohotkey-min.jsmode-batchfile-min.jsmode-c9search-min.jsmode-cirru-min.jsmode-clojure-min.jsmode-cobol-min.jsmode-coffee-min.jsmode-coldfusion-min.jsmode-csharp-min.jsmode-css-min.jsmode-d-min.jsmode-dart-min.jsmode-diff-min.jsmode-django-min.jsmode-dot-min.jsmode-eiffel-min.jsmode-ejs-min.jsmode-erlang-min.jsmode-ftl-min.jsmode-gcode-min.jsmode-gherkin-min.jsmode-gitignore-min.jsmode-glsl-min.jsmode-golang-min.jsmode-groovy-min.jsmode-haml-min.jsmode-handlebars-min.js
ext-beautify.jsext-chromevox.jsext-elastic_tabstops_lite.jsext-emmet.jsext-error_marker.jsext-keybinding_menu.jsext-language_tools.jsext-linking.jsext-modelist.jsext-old_ie.jsext-searchbox.jsext-settings_menu.jsext-spellcheck.jsext-split.jsext-static_highlight.jsext-statusbar.jsext-textarea.jsext-themelist.jsext-whitespace.jskeybinding-emacs.jskeybinding-vim.jsmode-abap.jsmode-abc.jsmode-actionscript.jsmode-ada.jsmode-apache_conf.jsmode-applescript.jsmode-asciidoc.jsmode-assembly_x86.jsmode-autohotkey.jsmode-batchfile.jsmode-c9search.jsmode-c_cpp.jsmode-cirru.jsmode-clojure.jsmode-cobol.jsmode-coffee.jsmode-coldfusion.jsmode-csharp.jsmode-css.jsmode-curly.jsmode-d.jsmode-dart.jsmode-diff.jsmode-django.jsmode-dockerfile.jsmode-dot.jsmode-eiffel.jsmode-ejs.jsmode-elixir.jsmode-elm.jsmode-erlang.jsmode-forth.jsmode-ftl.jsmode-gcode.jsmode-gherkin.jsmode-gitignore.jsmode-glsl.jsmode-golang.jsmode-groovy.jsmode-haml.jsmode-handlebars.jsmode-haskell.jsmode-haxe.jsmode-html.jsmode-html_ruby.jsmode-ini.jsmode-io.jsmode-jack.jsmode-jade.jsmode-java.jsmode-javascript.jsmode-json.jsmode-jsoniq.jsmode-jsp.jsmode-jsx.jsmode-julia.jsmode-latex.jsmode-lean.jsmode-less.jsmode-liquid.jsmode-lisp.jsmode-livescript.jsmode-logiql.jsmode-lsl.jsmode-lua.jsmode-luapage.jsmode-lucene.jsmode-makefile.jsmode-markdown.jsmode-mask.jsmode-matlab.jsmode-mel.jsmode-mushcode.jsmode-mysql.jsmode-nix.jsmode-objectivec.jsmode-ocaml.jsmode-pascal.jsmode-perl.jsmode-pgsql.jsmode-php.jsmode-plain_text.jsmode-powershell.jsmode-praat.jsmode-prolog.jsmode-properties.jsmode-protobuf.jsmode-python.jsmode-r.jsmode-rdoc.jsmode-rhtml.jsmode-ruby.jsmode-rust.jsmode-sass.jsmode-scad.jsmode-scala.jsmode-scheme.jsmode-scss.jsmode-sh.jsmode-sjs.jsmode-smarty.jsmode-snippets.jsmode-soy_template.jsmode-space.jsmode-sql.jsmode-stylus.jsmode-svg.jsmode-tcl.jsmode-tex.jsmode-text.jsmode-textile.jsmode-toml.jsmode-twig.jsmode-typescript.jsmode-vala.jsmode-vbscript.jsmode-velocity.jsmode-verilog.jsmode-vhdl.jsmode-xml.jsmode-xquery.jsmode-yaml.jssnippets
abap.jsabc.jsactionscript.jsada.jsapache_conf.jsapplescript.jsasciidoc.jsassembly_x86.jsautohotkey.jsbatchfile.jsc9search.jsc_cpp.jscirru.jsclojure.jscobol.jscoffee.jscoldfusion.jscsharp.jscss.jscurly.jsd.jsdart.jsdiff.jsdjango.jsdockerfile.jsdot.jseiffel.jsejs.jselixir.jselm.jserlang.jsforth.jsftl.jsgcode.jsgherkin.jsgitignore.jsglsl.jsgolang.jsgroovy.jshaml.jshandlebars.jshaskell.jshaxe.jshtml.jshtml_ruby.jsini.jsio.jsjack.jsjade.jsjava.jsjavascript.jsjson.jsjsoniq.jsjsp.jsjsx.jsjulia.jslatex.jslean.jsless.jsliquid.jslisp.jslivescript.jslogiql.jslsl.jslua.jsluapage.jslucene.jsmakefile.jsmarkdown.jsmask.jsmatlab.jsmel.jsmushcode.jsmysql.jsnix.jsobjectivec.jsocaml.jspascal.jsperl.jspgsql.jsphp.jsplain_text.jspowershell.jspraat.jsprolog.jsproperties.jsprotobuf.jspython.jsr.jsrdoc.jsrhtml.jsruby.jsrust.jssass.jsscad.jsscala.jsscheme.jsscss.jssh.jssjs.jssmarty.jssnippets.jssoy_template.jsspace.jssql.jsstylus.jssvg.jstcl.jstex.jstext.jstextile.jstoml.jstwig.jstypescript.jsvala.jsvbscript.jsvelocity.jsverilog.jsvhdl.jsxml.jsxquery.jsyaml.js
theme-ambiance.jstheme-chaos.jstheme-chrome.jstheme-clouds.jstheme-clouds_midnight.jstheme-cobalt.jstheme-crimson_editor.jstheme-dawn.jstheme-dreamweaver.jstheme-eclipse.jstheme-github.jstheme-idle_fingers.jstheme-katzenmilch.jstheme-kr_theme.jstheme-kuroir.jstheme-merbivore.jstheme-merbivore_soft.jstheme-mono_industrial.jstheme-monokai.jstheme-pastel_on_dark.jstheme-solarized_dark.jstheme-solarized_light.jstheme-terminal.jstheme-textmate.jstheme-tomorrow.jstheme-tomorrow_night.jstheme-tomorrow_night_blue.jstheme-tomorrow_night_bright.jstheme-tomorrow_night_eighties.jstheme-twilight.jstheme-vibrant_ink.jstheme-xcode.jsworker-coffee.jsworker-css.jsworker-html.jsworker-javascript.jsworker-json.jsworker-lua.jsworker-php.jsworker-xml.jsworker-xquery.jstinymce
plugins
leaui_image
public
paste
spellchecker
table
2
public/js/app/note-min.js
vendored
2
public/js/app/note-min.js
vendored
File diff suppressed because one or more lines are too long
@ -164,7 +164,16 @@ Note.getNotesByNotebookId = function(notebookId, sortBy, isAsc) {
|
||||
// 缓存之
|
||||
Note.cacheByNotebookId[notebookId][sortBy] = notes;
|
||||
return notes;
|
||||
}
|
||||
};
|
||||
|
||||
// 该笔记点击后已污染
|
||||
Note.curNoteIsDirtied = function() {
|
||||
var me = this;
|
||||
var note = me.getCurNote();
|
||||
if(note) {
|
||||
note.isDirty = true;
|
||||
}
|
||||
};
|
||||
|
||||
// called by Notebook
|
||||
// render 所有notes, 和第一个note的content
|
||||
@ -226,11 +235,18 @@ Note.curHasChanged = function(force) {
|
||||
IsMarkdown: cacheNote.IsMarkdown, // 是否是markdown笔记
|
||||
FromUserId: cacheNote.FromUserId, // 是否是共享新建的
|
||||
NoteId: cacheNote.NoteId,
|
||||
NotebookId: cacheNote.NotebookId
|
||||
NotebookId: cacheNote.NotebookId,
|
||||
Version: cacheNote.Version || 0, // 版本控制
|
||||
};
|
||||
|
||||
if(hasChanged.IsNew) {
|
||||
$.extend(hasChanged, cacheNote);
|
||||
} else {
|
||||
if(!cacheNote.isDirty) {
|
||||
log("no dirty");
|
||||
hasChanged.hasChanged = false;
|
||||
return hasChanged;
|
||||
}
|
||||
}
|
||||
|
||||
if(cacheNote.Title != title) {
|
||||
@ -243,7 +259,7 @@ Note.curHasChanged = function(force) {
|
||||
|
||||
if(!arrayEqual(cacheNote.Tags, tags)) {
|
||||
hasChanged.hasChanged = true;
|
||||
hasChanged.Tags = tags;
|
||||
hasChanged.Tags = tags.join(","); // 为什么? 因为空数组不会传到后台
|
||||
}
|
||||
|
||||
// 比较text, 因为note Nav会添加dom会导致content改变
|
||||
@ -375,44 +391,94 @@ Note.getImgSrc = function(content) {
|
||||
// 以后要定时调用
|
||||
// force , 默认是true, 表强校验内容
|
||||
// 定时保存传false
|
||||
Note.curChangedSaveIt = function(force) {
|
||||
Note.saveInProcess = {}; // noteId => bool, true表示该note正在保存到服务器, 服务器未响应
|
||||
Note.savePool = {}; // 保存池, 以后的保存先放在pool中, id => note
|
||||
Note.curChangedSaveIt = function(force, callback) {
|
||||
var me = this;
|
||||
// 如果当前没有笔记, 不保存
|
||||
if(!Note.curNoteId || Note.isReadOnly) {
|
||||
return;
|
||||
}
|
||||
|
||||
var hasChanged = Note.curHasChanged(force);
|
||||
|
||||
// 把已改变的渲染到左边 item-list
|
||||
Note.renderChangedNote(hasChanged);
|
||||
|
||||
if(hasChanged.hasChanged || hasChanged.IsNew) {
|
||||
// 把已改变的渲染到左边 item-list
|
||||
Note.renderChangedNote(hasChanged);
|
||||
delete hasChanged.hasChanged;
|
||||
|
||||
// 先缓存, 把markdown的preview也缓存起来
|
||||
Note.setNoteCache(hasChanged, false);
|
||||
|
||||
// 设置更新时间
|
||||
Note.setNoteCache({"NoteId": hasChanged.NoteId, "UpdatedTime": (new Date()).format("yyyy-MM-ddThh:mm:ss.S")}, false);
|
||||
// 表示有未完成的保存
|
||||
/*
|
||||
if(me.saveInProcess[hasChanged.NoteId]) {
|
||||
log("in process");
|
||||
me.savePool[hasChanged.NoteId] = hasChanged;
|
||||
me.startUpdatePoolNoteInterval();
|
||||
return;
|
||||
}
|
||||
*/
|
||||
|
||||
// 保存之
|
||||
showMsg(getMsg("saving"));
|
||||
|
||||
me.saveInProcess[hasChanged.NoteId] = true;
|
||||
|
||||
ajaxPost("/note/updateNoteOrContent", hasChanged, function(ret) {
|
||||
me.saveInProcess[hasChanged.NoteId] = false;
|
||||
if(hasChanged.IsNew) {
|
||||
// 缓存之, 后台得到其它信息
|
||||
ret.IsNew = false;
|
||||
Note.setNoteCache(ret, false);
|
||||
|
||||
|
||||
// 新建笔记也要change history
|
||||
Pjax.changeNote(ret);
|
||||
}
|
||||
callback && callback();
|
||||
showMsg(getMsg("saveSuccess"), 1000);
|
||||
});
|
||||
|
||||
if(hasChanged['Tags'] != undefined && typeof hasChanged['Tags'] == 'string') {
|
||||
hasChanged['Tags'] = hasChanged['Tags'].split(',');
|
||||
}
|
||||
// 先缓存, 把markdown的preview也缓存起来
|
||||
Note.setNoteCache(hasChanged, false);
|
||||
// 设置更新时间
|
||||
Note.setNoteCache({"NoteId": hasChanged.NoteId, "UpdatedTime": (new Date()).format("yyyy-MM-ddThh:mm:ss.S")}, false);
|
||||
|
||||
return hasChanged;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
};
|
||||
|
||||
// 更新池里的笔记
|
||||
Note.updatePoolNote = function() {
|
||||
var me = this;
|
||||
for(var noteId in me.savePool) {
|
||||
if(!noteId) {
|
||||
continue;
|
||||
}
|
||||
// 删除之
|
||||
delete me.savePool[noteId];
|
||||
var hasChanged = me.savePool[noteId];
|
||||
me.saveInProcess[noteId] = true;
|
||||
ajaxPost("/note/updateNoteOrContent", hasChanged, function(ret) {
|
||||
me.saveInProcess[noteId] = false;
|
||||
});
|
||||
}
|
||||
};
|
||||
// 启动保存, 暂不处理
|
||||
Note.updatePoolNoteInterval = null;
|
||||
Note.startUpdatePoolNoteInterval = function() {
|
||||
return;
|
||||
var me = this;
|
||||
if(me.updatePoolNoteInterval) {
|
||||
return;
|
||||
}
|
||||
me.updatePoolNoteInterval = setTimeout(function() {
|
||||
log('update pool');
|
||||
me.updatePoolNote();
|
||||
}, 1000);
|
||||
};
|
||||
|
||||
|
||||
// 样式
|
||||
Note.selectTarget = function(target) {
|
||||
@ -661,18 +727,19 @@ Note.clearAll = function() {
|
||||
Note.clearNoteList();
|
||||
}
|
||||
|
||||
// render到编辑器
|
||||
// render note
|
||||
Note.renderNote = function(note) {
|
||||
if(!note) {
|
||||
return;
|
||||
}
|
||||
// title
|
||||
$("#noteTitle").val(note.Title);
|
||||
$("#noteTitle").val(trimTitle(note.Title));
|
||||
|
||||
// 当前正在编辑的
|
||||
// tags
|
||||
Tag.renderTags(note.Tags);
|
||||
|
||||
// 笔记是新render的, 没有污染过
|
||||
note.isDirty = false;
|
||||
}
|
||||
|
||||
// render content
|
||||
@ -788,6 +855,7 @@ Note._renderNotes = function(notes, forNewNote, isShared, tang) { // 第几趟
|
||||
}
|
||||
var note = notes[i];
|
||||
var tmp;
|
||||
note.Title = trimTitle(note.Title);
|
||||
if(note.ImgSrc) {
|
||||
tmp = tt(Note.itemTpl, classes, note.NoteId, note.ImgSrc, note.Title, Notebook.getNotebookTitle(note.NotebookId), goNowToDatetime(note.UpdatedTime), note.Desc);
|
||||
} else {
|
||||
@ -965,8 +1033,8 @@ Note.deleteNote = function(target, contextmenuItem, isShared) {
|
||||
|
||||
// 删除缓存
|
||||
if(note) {
|
||||
Note.clearCacheByNotebookId(note.NotebookId)
|
||||
delete Note.cache[noteId]
|
||||
Note.clearCacheByNotebookId(note.NotebookId);
|
||||
delete Note.cache[noteId];
|
||||
}
|
||||
|
||||
showMsg("删除成功!", 500);
|
||||
@ -1338,7 +1406,31 @@ Note.copyNote = function(target, data, isShared) {
|
||||
|
||||
// 增加数量
|
||||
Notebook.incrNotebookNumberNotes(notebookId)
|
||||
}
|
||||
};
|
||||
|
||||
// 删除笔记标签
|
||||
// item = {noteId => usn}
|
||||
Note.deleteNoteTag = function(item, tag) {
|
||||
if(!item) {
|
||||
return;
|
||||
}
|
||||
for(var noteId in item) {
|
||||
var note = Note.getNote(noteId);
|
||||
if(note) {
|
||||
note.Tags = note.Tags || [];
|
||||
for(var i in note.Tags) {
|
||||
if(note.Tags[i] == tag) {
|
||||
note.Tags.splice(i, 1);
|
||||
continue;
|
||||
}
|
||||
}
|
||||
// 如果当前笔记是展示的笔记, 则重新renderTags
|
||||
if(noteId == Note.curNoteId) {
|
||||
Tag.renderTags(note.Tags);
|
||||
}
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
// 这里速度不慢, 很快
|
||||
Note.getContextNotebooks = function(notebooks) {
|
||||
@ -1697,6 +1789,16 @@ $(function() {
|
||||
}
|
||||
});
|
||||
|
||||
// 当前笔记可以已修改
|
||||
$('#editorContent, #wmd-input, #noteTitle').keyup(function() {
|
||||
Note.curNoteIsDirtied();
|
||||
});
|
||||
/*
|
||||
$('#addTagInput').click(function() {
|
||||
Note.curNoteIsDirtied();
|
||||
});
|
||||
*/
|
||||
|
||||
//------------------
|
||||
// 新建笔记
|
||||
// 1. 直接点击新建 OR
|
||||
|
2
public/js/app/notebook-min.js
vendored
2
public/js/app/notebook-min.js
vendored
File diff suppressed because one or more lines are too long
@ -21,6 +21,10 @@ Notebook.getCurNotebookId = function() {
|
||||
return Notebook.curNotebookId;
|
||||
};
|
||||
|
||||
Notebook.getCurNotebook = function() {
|
||||
return Notebook.cache[Notebook.curNotebookId];
|
||||
};
|
||||
|
||||
// 笔记本的笔记数量更新
|
||||
Notebook._updateNotebookNumberNotes = function(notebookId, n) {
|
||||
var self = this;
|
||||
@ -249,6 +253,12 @@ Notebook.renderNotebooks = function(notebooks) {
|
||||
notebooks = [];
|
||||
}
|
||||
|
||||
// title可能有<script>
|
||||
for(var i = 0, len = notebooks.length; i < len; ++i) {
|
||||
var notebook = notebooks[i];
|
||||
notebook.Title = trimTitle(notebook.Title);
|
||||
}
|
||||
|
||||
notebooks = [{NotebookId: Notebook.allNotebookId, Title: getMsg("all"), drop:false, drag: false}].concat(notebooks);
|
||||
notebooks.push({NotebookId: Notebook.trashNotebookId, Title: getMsg("trash"), drop:false, drag: false});
|
||||
Notebook.notebooks = notebooks; // 缓存之
|
||||
@ -579,6 +589,7 @@ Notebook.curActiveNotebookIsAll = function() {
|
||||
// 2. ajax得到该notebook下的所有note
|
||||
// 3. 使用Note.RederNotes()
|
||||
// callback Pjax, 当popstate时调用
|
||||
Notebook.changeNotebookSeq = 1;
|
||||
Notebook.changeNotebook = function(notebookId, callback) {
|
||||
var me = this;
|
||||
Notebook.changeNotebookNav(notebookId);
|
||||
@ -602,37 +613,54 @@ Notebook.changeNotebook = function(notebookId, callback) {
|
||||
param = {};
|
||||
// 得到全部的...
|
||||
cacheNotes = Note.getNotesByNotebookId();
|
||||
if(!isEmpty(cacheNotes)) { // 万一真的是没有呢?
|
||||
// 数量一致
|
||||
if(!isEmpty(cacheNotes)) {
|
||||
if(callback) {
|
||||
callback(cacheNotes);
|
||||
} else {
|
||||
Note.renderNotesAndFirstOneContent(cacheNotes);
|
||||
}
|
||||
return;
|
||||
}
|
||||
}
|
||||
} else {
|
||||
cacheNotes = Note.getNotesByNotebookId(notebookId);
|
||||
if(!isEmpty(cacheNotes)) { // 万一真的是没有呢? 执行后面的ajax
|
||||
var notebook = Notebook.cache[notebookId];
|
||||
var len = cacheNotes ? cacheNotes.length : 0;
|
||||
// alert( notebook.NumberNotes + " " + len);
|
||||
if(len == notebook.NumberNotes) {
|
||||
if(callback) {
|
||||
callback(cacheNotes);
|
||||
} else {
|
||||
Note.renderNotesAndFirstOneContent(cacheNotes);
|
||||
}
|
||||
return;
|
||||
} else {
|
||||
Note.clearCacheByNotebookId(notebookId);
|
||||
log('数量不一致');
|
||||
}
|
||||
}
|
||||
|
||||
// 2 得到笔记本
|
||||
// 这里可以缓存起来, note按notebookId缓存
|
||||
// 这里可能点击过快导致前面点击的后来才返回
|
||||
me.showNoteAndEditorLoading();
|
||||
ajaxGet(url, param, function(cacheNotes) {
|
||||
if(callback) {
|
||||
callback(cacheNotes);
|
||||
} else {
|
||||
Note.renderNotesAndFirstOneContent(cacheNotes);
|
||||
}
|
||||
me.hideNoteAndEditorLoading();
|
||||
});
|
||||
me.changeNotebookSeq++;
|
||||
(function(seq) {
|
||||
ajaxGet(url, param, function(cacheNotes) {
|
||||
// 后面点击过快, 之前的结果不要了
|
||||
if(seq != me.changeNotebookSeq) {
|
||||
log("notebook changed too fast!");
|
||||
log(cacheNotes);
|
||||
return;
|
||||
}
|
||||
if(callback) {
|
||||
callback(cacheNotes);
|
||||
} else {
|
||||
Note.renderNotesAndFirstOneContent(cacheNotes);
|
||||
}
|
||||
me.hideNoteAndEditorLoading();
|
||||
});
|
||||
})(me.changeNotebookSeq);
|
||||
}
|
||||
|
||||
// 笔记列表与编辑器的mask loading
|
||||
|
2
public/js/app/page-min.js
vendored
2
public/js/app/page-min.js
vendored
File diff suppressed because one or more lines are too long
@ -996,7 +996,7 @@ LeaAce = {
|
||||
aceEditor.setOption("wrap", "free");
|
||||
aceEditor.setShowInvisibles(false);
|
||||
aceEditor.setAutoScrollEditorIntoView(true);
|
||||
aceEditor.setOption("maxLines", 100);
|
||||
aceEditor.setOption("maxLines", 10000);
|
||||
aceEditor.commands.addCommand({
|
||||
name: "undo",
|
||||
bindKey: {win: "Ctrl-z", mac: "Command-z"},
|
||||
|
2
public/js/app/tag-min.js
vendored
2
public/js/app/tag-min.js
vendored
File diff suppressed because one or more lines are too long
@ -33,8 +33,8 @@ Tag.t = $("#tags");
|
||||
Tag.getTags = function() {
|
||||
var tags = [];
|
||||
Tag.t.children().each(function(){
|
||||
var text = $(this).text();
|
||||
text = text.substring(0, text.length - 1); // 把X去掉
|
||||
var text = $(this).data('tag');
|
||||
// text = text.substring(0, text.length - 1); // 把X去掉
|
||||
text = Tag.mapCn2En[text] || text;
|
||||
tags.push(text);
|
||||
});
|
||||
@ -117,7 +117,7 @@ Tag.renderReadOnlyTags = function(tags) {
|
||||
// 添加tag
|
||||
// tag = {classes:"label label-red", text:"红色"}
|
||||
// tag = life
|
||||
Tag.appendTag = function(tag) {
|
||||
Tag.appendTag = function(tag, save) {
|
||||
var isColor = false;
|
||||
var classes, text;
|
||||
|
||||
@ -140,21 +140,25 @@ Tag.appendTag = function(tag) {
|
||||
classes = "label label-default";
|
||||
}
|
||||
}
|
||||
|
||||
var rawText = text;
|
||||
if(LEA.locale == "zh") {
|
||||
text = Tag.mapEn2Cn[text] || text;
|
||||
rawText = Tag.mapCn2En[rawText] || rawText;
|
||||
}
|
||||
tag = tt('<span class="?">?<i title="' + getMsg("delete") + '">X</i></span>', classes, text);
|
||||
tag = tt('<span class="?" data-tag="?">?<i title="' + getMsg("delete") + '">X</i></span>', classes, text, text);
|
||||
|
||||
// 避免重复
|
||||
var isExists = false;
|
||||
$("#tags").children().each(function() {
|
||||
if (isColor) {
|
||||
var tagHtml = $("<div></div>").append($(this).clone()).html();
|
||||
if (tagHtml == tag) {
|
||||
$(this).remove();
|
||||
isExists = true;
|
||||
}
|
||||
} else if (text + "X" == $(this).text()) {
|
||||
$(this).remove();
|
||||
isExists = true;
|
||||
}
|
||||
});
|
||||
|
||||
@ -165,6 +169,22 @@ Tag.appendTag = function(tag) {
|
||||
if (!isColor) {
|
||||
reRenderTags();
|
||||
}
|
||||
|
||||
// 笔记已污染
|
||||
if(save) {
|
||||
Note.curNoteIsDirtied();
|
||||
|
||||
// 如果之前不存, 则添加之
|
||||
if(!isExists) {
|
||||
Note.curChangedSaveIt(true, function() {
|
||||
ajaxPost("/tag/updateTag", {tag: rawText}, function(ret) {
|
||||
if(reIsOk(ret)) {
|
||||
Tag.addTagNav(ret.Item);
|
||||
}
|
||||
});
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// 为了颜色间隔, add, delete时调用
|
||||
@ -181,23 +201,59 @@ function reRenderTags() {
|
||||
i++;
|
||||
}
|
||||
});
|
||||
}
|
||||
};
|
||||
|
||||
// 删除tag
|
||||
Tag.removeTag = function($target) {
|
||||
var tag = $target.data('tag');
|
||||
$target.remove();
|
||||
reRenderTags();
|
||||
if(LEA.locale == "zh") {
|
||||
tag = Tag.mapCn2En[tag] || tag;
|
||||
}
|
||||
Note.curChangedSaveIt(true, function() {
|
||||
ajaxPost("/tag/updateTag", {tag: tag}, function(ret) {
|
||||
if(reIsOk(ret)) {
|
||||
Tag.addTagNav(ret.Item);
|
||||
}
|
||||
});
|
||||
});
|
||||
};
|
||||
|
||||
//-----------
|
||||
// 左侧nav en -> cn
|
||||
Tag.tags = [];
|
||||
Tag.renderTagNav = function(tags) {
|
||||
var me = this;
|
||||
tags = tags || [];
|
||||
Tag.tags = tags;
|
||||
$("#tagNav").html('');
|
||||
for(var i in tags) {
|
||||
var tag = tags[i];
|
||||
if(tag == "red" || tag == "blue" || tag == "yellow" || tag == "green") {
|
||||
continue;
|
||||
var noteTag = tags[i];
|
||||
var tag = noteTag.Tag;
|
||||
var text = tag;
|
||||
if(LEA.locale == "zh") {
|
||||
var text = Tag.mapEn2Cn[tag] || text;
|
||||
}
|
||||
var text = Tag.mapEn2Cn[tag] || tag;
|
||||
var classes = Tag.classes[tag] || "label label-default";
|
||||
$("#tagNav").append(tt('<li data-tag="?"><a> <span class="?">?</span></li>', text, classes, text));
|
||||
$("#tagNav").append(tt('<li data-tag="?"><a> <span class="?">?</span> <span class="tag-delete">X</span></li>', tag, classes, text));
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
// 添加的标签重新render到左边, 放在第一个位置
|
||||
// 重新render
|
||||
Tag.addTagNav = function(newTag) {
|
||||
var me = this;
|
||||
for(var i in me.tags) {
|
||||
var noteTag = me.tags[i];
|
||||
if(noteTag.Tag == newTag.Tag) {
|
||||
me.tags.splice(i, 1);
|
||||
break;
|
||||
}
|
||||
}
|
||||
me.tags.unshift(newTag);
|
||||
me.renderTagNav(me.tags);
|
||||
};
|
||||
|
||||
// 事件
|
||||
$(function() {
|
||||
@ -245,7 +301,7 @@ $(function() {
|
||||
Tag.appendTag({
|
||||
classes : a.attr("class"),
|
||||
text : a.text()
|
||||
});
|
||||
}, true);
|
||||
});
|
||||
// 这是个问题, 为什么? 捕获不了事件?, input的blur造成
|
||||
/*
|
||||
@ -260,14 +316,29 @@ $(function() {
|
||||
*/
|
||||
|
||||
$("#tags").on("click", "i", function() {
|
||||
$(this).parent().remove();
|
||||
reRenderTags();
|
||||
Tag.removeTag($(this).parent());
|
||||
});
|
||||
//----------
|
||||
//
|
||||
function deleteTag() {
|
||||
$li = $(this).closest('li');
|
||||
var tag = $.trim($li.data("tag"));
|
||||
if(confirm("Are you sure ?")) {
|
||||
ajaxPost("/tag/deleteTag", {tag: tag}, function(re) {
|
||||
if(reIsOk(re)) {
|
||||
var item = re.Item; // 被删除的
|
||||
Note.deleteNoteTag(item, tag);
|
||||
$li.remove();
|
||||
}
|
||||
});
|
||||
};
|
||||
}
|
||||
|
||||
//-------------
|
||||
// nav 标签搜索
|
||||
function searchTag() {
|
||||
var tag = $.trim($(this).data("tag"));
|
||||
var $li = $(this).closest('li');
|
||||
var tag = $.trim($li.data("tag"));
|
||||
// tag = Tag.mapCn2En[tag] || tag;
|
||||
|
||||
// 学习changeNotebook
|
||||
@ -279,7 +350,9 @@ $(function() {
|
||||
// 也会把curNoteId清空
|
||||
Note.clearAll();
|
||||
|
||||
$("#tagSearch").html($(this).html()).show();
|
||||
$("#tagSearch").html($li.html()).show();
|
||||
$("#tagSearch .tag-delete").remove();
|
||||
|
||||
showLoading();
|
||||
ajaxGet("/note/searchNoteByTags", {tags: [tag]}, function(notes) {
|
||||
hideLoading();
|
||||
@ -295,6 +368,8 @@ $(function() {
|
||||
}
|
||||
});
|
||||
}
|
||||
$("#myTag .folderBody").on("click", "li", searchTag);
|
||||
$("#minTagNav").on("click", "li", searchTag);
|
||||
$("#myTag .folderBody").on("click", "li .label", searchTag);
|
||||
// $("#minTagNav").on("click", "li", searchTag);
|
||||
|
||||
$("#myTag .folderBody").on("click", "li .tag-delete", deleteTag);
|
||||
});
|
2
public/js/common-min.js
vendored
2
public/js/common-min.js
vendored
File diff suppressed because one or more lines are too long
@ -759,7 +759,7 @@ function post(url, param, func, btnId) {
|
||||
|
||||
// 是否是正确的email
|
||||
function isEmail(email) {
|
||||
var myreg = /^([a-zA-Z0-9]+[_|\_|\.]?)*[a-zA-Z0-9]+@([a-zA-Z0-9]+[_|\_|\.]?)*[a-zA-Z0-9]+\.[0-9a-zA-Z]{2,3}$/;
|
||||
var myreg = /^([a-zA-Z0-9]+[_|\_|\.|\-]?)*[a-zA-Z0-9\-]+@([a-zA-Z0-9\-]+[_|\_|\.|\-]?)*[a-zA-Z0-9\-]+\.[0-9a-zA-Z]{2,3}$/;
|
||||
return myreg.test(email);
|
||||
}
|
||||
|
||||
@ -967,8 +967,9 @@ var vd = {
|
||||
return result;
|
||||
},
|
||||
isEmail: function(emailValue){
|
||||
var emailPattern=/^[^@.]+@([^@.]+\.)+[^@.]+$/; //邮箱的正则表达式
|
||||
var emailPattern=/^([a-zA-Z0-9]+[_|\_|\.|\-]?)*[a-zA-Z0-9\-]+@([a-zA-Z0-9\-]+[_|\_|\.|\-]?)*[a-zA-Z0-9\-]+\.[0-9a-zA-Z]{2,3}$/; //邮箱的正则表达式
|
||||
result=emailPattern.test(emailValue);
|
||||
|
||||
return result;
|
||||
},
|
||||
isBlank: function(o) {
|
||||
@ -1024,7 +1025,7 @@ var vd = {
|
||||
if(val === "" && !is_required(target)) {
|
||||
return true;
|
||||
}
|
||||
return isEmail(val);
|
||||
return vd.isEmail(val);
|
||||
},
|
||||
noSpecialChars: function(target) {
|
||||
var val = get_val(target);
|
||||
@ -1275,4 +1276,8 @@ function setHash(key, value) {
|
||||
}
|
||||
}
|
||||
location.href = "#" + str;
|
||||
}
|
||||
}
|
||||
|
||||
var trimTitle = function(title) {
|
||||
return title.replace(/<.*?script.*?>/g, '');
|
||||
};
|
@ -11,7 +11,7 @@ pre.prettyprint {
|
||||
}
|
||||
|
||||
code.prettyprint,pre.prettyprint {
|
||||
padding: 8px;
|
||||
padding: 18px;
|
||||
background-color: #f7f7f9;
|
||||
border: 1px solid #e1e1e8;
|
||||
-moz-border-radius: 3px;
|
||||
|
Reference in New Issue
Block a user