v1.0 beta init

This commit is contained in:
life
2014-10-22 16:20:45 +08:00
parent 8ae438272b
commit 593d2c2965
225 changed files with 27217 additions and 3675 deletions

View File

@ -13,15 +13,16 @@ Note.interval = ""; // 定时器
Note.itemIsBlog = '<div class="item-blog"><i class="fa fa-bold" title="blog"></i></div><div class="item-setting"><i class="fa fa-cog" title="setting"></i></div>';
// for render
Note.itemTplNoImg = '<div href="#" class="item ?" noteId="?">'
Note.itemTplNoImg += Note.itemIsBlog +'<div class="item-desc" style="right: 0;"><p class="item-title">?</p><p class="item-text"><i class="fa fa-book"></i> <span class="note-notebook">?</span> <i class="fa fa-calendar"></i> <span class="updated-time">?</span> <br /><span class="desc">?</span></p></div></div>';
Note.itemTplNoImg = '<li href="#" class="item ?" noteId="?">'
Note.itemTplNoImg += Note.itemIsBlog +'<div class="item-desc"><p class="item-title">?</p><p class="item-info"><i class="fa fa-book"></i> <span class="note-notebook">?</span> <i class="fa fa-calendar"></i> <span class="updated-time">?</span></p><p class="desc">?</p></div></li>';
Note.itemTpl = '<div href="#" class="item ?" noteId="?"><div class="item-thumb" style=""><img src="?"/></div>'
Note.itemTpl +=Note.itemIsBlog + '<div class="item-desc" style=""><p class="item-title">?</p><p class="item-text"><i class="fa fa-book"></i> <span class="note-notebook">?</span> <i class="fa fa-calendar"></i> <span class="updated-time">?</span> <br /><span class="desc">?</span></p></div></div>';
// 有image
Note.itemTpl = '<li href="#" class="item ? item-image" noteId="?"><div class="item-thumb" style=""><img src="?"/></div>'
Note.itemTpl +=Note.itemIsBlog + '<div class="item-desc" style=""><p class="item-title">?</p><p class="item-info"><i class="fa fa-book"></i> <span class="note-notebook">?</span> <i class="fa fa-calendar"></i> <span class="updated-time">?</span></p><p class="desc">?</p></div></li>';
// for new
Note.newItemTpl = '<div href="#" class="item item-active ?" fromUserId="?" noteId="?">'
Note.newItemTpl += Note.itemIsBlog + '<div class="item-desc" style="right: 0px;"><p class="item-title">?</p><p class="item-text"><i class="fa fa-book"></i> <span class="note-notebook">?</span> <i class="fa fa-calendar"></i> <span class="updated-time">?</span><br /><span class="desc">?</span></p></div></div>';
Note.newItemTpl = '<li href="#" class="item item-active ?" fromUserId="?" noteId="?">'
Note.newItemTpl += Note.itemIsBlog + '<div class="item-desc" style="right: 0px;"><p class="item-title">?</p><p class="item-text"><i class="fa fa-book"></i> <span class="note-notebook">?</span> <i class="fa fa-calendar"></i> <span class="updated-time">?</span><br /><span class="desc">?</span></p></div></li>';
Note.noteItemListO = $("#noteItemList");
@ -205,7 +206,7 @@ Note.curHasChanged = function(force) {
preview = contents[1];
contentText = content;
// preview可能没来得到及解析
if (content && previewIsEmpty(preview)) {
if (content && previewIsEmpty(preview) && Converter) {
preview = Converter.makeHtml(content);
}
if(!content) {
@ -276,6 +277,7 @@ Note.genDesc = function(content) {
}
// 将</div>, </p>替换成\n
/*
var token = "ALEALE";
content = content.replace(/<\/p>/g, token);
content = content.replace(/<\/div>/g, token);
@ -291,6 +293,19 @@ Note.genDesc = function(content) {
content = trimLeft(content, "<br />");
content = trimLeft(content, "</p>");
content = trimLeft(content, "</div>");
*/
// 留空格
content = content.replace(/<br \/>/g," <br />");
content = content.replace(/<\/p>/g," </p>");
content = content.replace(/<\/div>/g," </div>");
// 避免其它的<img 之类的不完全
content = $("<div></div>").html(content).text();
// pre下text()会将&lt; => < &gt; => >
content = content.replace(/</g, "&lt;");
content = content.replace(/>/g, "&gt;");
if(content.length < 300) {
return content;
@ -401,7 +416,16 @@ Note.selectTarget = function(target) {
// 可能改变的是share note
// 1. 保存之前的note
// 2. ajax得到现在的note
Note.showContentLoading = function() {
$("#noteMaskForLoading").css("z-index", 99999);
}
Note.hideContentLoading = function() {
$("#noteMaskForLoading").css("z-index", -1);
}
Note.contentAjax = null;
Note.contentAjaxSeq = 1;
Note.changeNote = function(selectNoteId, isShare, needSaveChanged) {
var self = this;
// -1 停止定时器
Note.stopInterval();
@ -433,30 +457,35 @@ Note.changeNote = function(selectNoteId, isShare, needSaveChanged) {
}
var hasPerm = !isShare || Share.hasUpdatePerm(selectNoteId); // 不是共享, 或者是共享但有权限
// 不是手机浏览器且有权限
if(!LEA.isMobile && hasPerm) {
// 有权限
if(hasPerm) {
Note.hideReadOnly();
Note.renderNote(cacheNote);
// 这里要切换编辑器
switchEditor(cacheNote.IsMarkdown)
} else {
Note.renderNoteReadOnly(cacheNote);
}
Attach.renderNoteAttachNum(selectNoteId, true);
Note.contentAjaxSeq++;
var seq = Note.contentAjaxSeq;
function setContent(ret) {
Note.contentAjax = null;
if(seq != Note.contentAjaxSeq) {
return;
}
Note.setNoteCache(ret, false);
// 把其它信息也带上
ret = Note.cache[selectNoteId]
if(!LEA.isMobile && hasPerm) {
if(hasPerm) {
Note.renderNoteContent(ret);
} else {
Note.renderNoteContentReadOnly(ret);
}
hideLoading();
self.hideContentLoading();
}
if(cacheNote.Content) {
@ -471,9 +500,11 @@ Note.changeNote = function(selectNoteId, isShare, needSaveChanged) {
param.sharedUserId = cacheNote.UserId // 谁的笔记
}
// 这里loading
showLoading();
ajaxGet(url, param, setContent);
self.showContentLoading();
if(Note.contentAjax != null) {
Note.contentAjax.abort();
}
note.contentAjax = ajaxGet(url, param, setContent);
}
// 渲染
@ -494,18 +525,19 @@ Note.renderChangedNote = function(changedNote) {
if(changedNote.Desc) {
$leftNoteNav.find(".desc").html(changedNote.Desc);
}
if(changedNote.ImgSrc && !LEA.isMobile) {
if(changedNote.ImgSrc) {
$thumb = $leftNoteNav.find(".item-thumb");
// 有可能之前没有图片
if($thumb.length > 0) {
$thumb.find("img").attr("src", changedNote.ImgSrc);
} else {
$leftNoteNav.append(tt('<div class="item-thumb" style=""><img src="?"></div>', changedNote.ImgSrc));
$leftNoteNav.addClass("item-image");
}
$leftNoteNav.find(".item-desc").removeAttr("style");
} else if(changedNote.ImgSrc == "") {
$leftNoteNav.find(".item-thumb").remove(); // 以前有, 现在没有了
$leftNoteNav.find(".item-desc").css("right", 0);
$leftNoteNav.removeClass("item-image");
}
}
@ -579,7 +611,7 @@ Note.renderNoteContent = function(content) {
*/
Note.showEditorMask = function() {
$("#editorMask").css("z-index", 10);
$("#editorMask").css("z-index", 10).show();
// 要判断是否是垃圾筒
if(Notebook.curNotebookIsTrashOrAll()) {
$("#editorMaskBtns").hide();
@ -590,7 +622,7 @@ Note.showEditorMask = function() {
}
}
Note.hideEditorMask = function() {
$("#editorMask").css("z-index", -10);
$("#editorMask").css("z-index", -10).hide();
}
// 这里如果notes过多>100个将会很慢!!, 使用setTimeout来分解
@ -598,7 +630,11 @@ Note.renderNotesC = 0;
Note.renderNotes = function(notes, forNewNote, isShared) {
var renderNotesC = ++Note.renderNotesC;
$("#noteItemList").slimScroll({ scrollTo: '0px', height: "100%", onlyScrollBar: true});
// 手机端不用
// slimScroll使得手机端滚动不流畅
if(!LEA.isMobile && !Mobile.isMobile()) {
$("#noteItemList").slimScroll({ scrollTo: '0px', height: "100%", onlyScrollBar: true});
}
if(!notes || typeof notes != "object" || notes.length <= 0) {
// 如果没有, 那么是不是应该hide editor?
@ -661,7 +697,7 @@ Note._renderNotes = function(notes, forNewNote, isShared, tang) { // 第几趟
}
var note = notes[i];
var tmp;
if(note.ImgSrc && !LEA.isMobile) {
if(note.ImgSrc) {
tmp = tt(Note.itemTpl, classes, note.NoteId, note.ImgSrc, note.Title, Notebook.getNotebookTitle(note.NotebookId), goNowToDatetime(note.UpdatedTime), note.Desc);
} else {
tmp = tt(Note.itemTplNoImg, classes, note.NoteId, note.Title, Notebook.getNotebookTitle(note.NotebookId), goNowToDatetime(note.UpdatedTime), note.Desc);
@ -763,6 +799,9 @@ Note.newNote = function(notebookId, isShare, fromUserId, isMarkdown) {
Note.renderNote(note);
Note.renderNoteContent(note);
Note.curNoteId = note.NoteId;
// 更新数量
Notebook.incrNotebookNumberNotes(notebookId)
}
// 保存note ctrl + s
@ -822,6 +861,9 @@ Note.deleteNote = function(target, contextmenuItem, isShared) {
var url = "/note/deleteNote"
if(note.IsTrash) {
url = "/note/deleteTrash";
} else {
// 减少数量
Notebook.minusNotebookNumberNotes(note.NotebookId);
}
ajaxGet(url, {noteId: noteId, userId: note.UserId, isShared: isShared}, function(ret) {
@ -843,6 +885,7 @@ Note.deleteNote = function(target, contextmenuItem, isShared) {
showMsg("删除失败!", 2000);
}
});
}
// 显示共享信息
@ -854,7 +897,7 @@ Note.listNoteShareUserInfo = function(target) {
// 共享笔记
Note.shareNote = function(target) {
var title = $(target).find(".item-title").text();
showDialog("dialogShareNote", {title: "分享笔记给好友-" + title});
showDialog("dialogShareNote", {title: getMsg("shareToFriends") + "-" + title});
setTimeout(function() {
$("#friendsEmail").focus();
@ -870,15 +913,15 @@ Note.listNoteContentHistories = function() {
$("#leanoteDialog #modalTitle").html(getMsg("history"));
$content = $("#leanoteDialog .modal-body");
$content.html("");
$("#leanoteDialog .modal-footer").html('<button type="button" class="btn btn-default" data-dismiss="modal">关闭</button>');
$("#leanoteDialog .modal-footer").html('<button type="button" class="btn btn-default" data-dismiss="modal">' + getMsg("close") + '</button>');
options = {}
options.show = true;
$("#leanoteDialog").modal(options);
ajaxGet("noteContentHistory/listHistories", {noteId: Note.curNoteId}, function(re) {
if(!isArray(re)) {$content.html("无历史记录"); return}
if(!isArray(re)) {$content.html(getMsg("noHistories")); return}
// 组装成一个tab
var str = 'leanote会保存笔记的最近10份历史记录. <div id="historyList"><table class="table table-hover">';
var str = "<p>" + getMsg("historiesNum") + '</p><div id="historyList"><table class="table table-hover">';
note = Note.cache[Note.curNoteId];
var s = "div"
if(note.IsMarkdown) {
@ -887,7 +930,7 @@ Note.listNoteContentHistories = function() {
for (i in re) {
var content = re[i]
content.Ab = Note.genAbstract(content.Content, 200);
str += tt('<tr><td seq="?"><? class="each-content">?</?> <div class="btns">时间: <span class="label label-default">?</span> <button class="btn btn-default all">展开</button> <button class="btn btn-primary back">还原</button></div></td></tr>', i, s, content.Ab, s, goNowToDatetime(content.UpdatedTime))
str += tt('<tr><td seq="?">#?<? class="each-content">?</?> <div class="btns">' + getMsg("datetime") + ': <span class="label label-default">?</span> <button class="btn btn-default all">' + getMsg("unfold") + '</button> <button class="btn btn-primary back">' + getMsg('restoreFromThisVersion') + '</button></div></td></tr>', i, (+i+1), s, content.Ab, s, goNowToDatetime(content.UpdatedTime))
}
str += "</table></div>";
$content.html(str);
@ -895,12 +938,15 @@ Note.listNoteContentHistories = function() {
$p = $(this).parent().parent();
var seq = $p.attr("seq");
var $c = $p.find(".each-content");
if($(this).text() == "展开") {
$(this).text("折叠")
$c.html(re[seq].Content);
var info = re[seq];
if(!info.unfold) { // 默认是折叠的
$(this).text(getMsg("fold")); // 折叠
$c.html(info.Content);
info.unfold = true;
} else {
$(this).text("展开")
$c.html(re[seq].Ab);
$(this).text(getMsg("unfold")); // 展开
$c.html(info.Ab);
info.unfold = false
}
});
@ -908,7 +954,7 @@ Note.listNoteContentHistories = function() {
$("#historyList .back").click(function() {
$p = $(this).parent().parent();
var seq = $p.attr("seq");
if(confirm("确定要从该版还原? 还原前leanote会备份当前版本到历史记录中.")) {
if(confirm(getMsg("confirmBackup"))) {
// 保存当前版本
Note.curChangedSaveIt();
// 设置之
@ -925,20 +971,36 @@ Note.listNoteContentHistories = function() {
// 长微博
Note.html2Image = function(target) {
var noteId = $(target).attr("noteId");
showDialog("html2ImageDialog", {title: "发送长微博", postShow: function() {
showDialog("html2ImageDialog", {title: "分享到社区", postShow: function() {
ajaxGet("/note/html2Image", {noteId: noteId}, function(ret) {
if (typeof ret == "object" && ret.Ok) {
$("#leanoteDialog .weibo span").html("生成成功, 右键图片保存到本地.")
$("#leanoteDialog .weibo img").attr("src", ret.Id);
$("#leanoteDialog .sendWeiboBtn").removeClass("disabled");
$("#leanoteDialog .weibo img").attr("src", ret.Id + "?" + ((new Date()).getTime()));
$("#leanoteDialog .btn-share").removeClass("disabled");
var note = Note.cache[noteId];
var pic = UrlPrefix + ret.Id;
var title = encodeURI(note.Title + " (" + UserInfo.Username + "分享. 来自leanote.com)");
var windowParam = 'width=700, height=580, top=180, left=320, toolbar=no, menubar=no, scrollbars=no, location=yes, resizable=no, status=no';
$("#leanoteDialog .sendWeiboBtn").click(function() {
var title = Note.cache[noteId].Title;
var url = "http://service.weibo.com/share/share.php?title=" + title + " (" + UserInfo.Username + "分享. 来自leanote.com)";
url += "&pic=" + UrlPrefix + ret.Id;
window.open(url, "_blank");
var url = "http://service.weibo.com/share/share.php?title=" + title;
url += "&pic=" + pic;
window.open(url, '分享到新浪微博', windowParam);
});
$("#leanoteDialog .sendTxWeiboBtn").click(function() {
var _appkey = '801542571';
var url = "http://share.v.t.qq.com/index.php?c=share&a=index&appkey=" + _appkey +"&title=" + title +"&url=&pic=" + pic
window.open(url, '分享到腾讯微博', windowParam);
});
$("#leanoteDialog .sendQQBtn").click(function() {
var url = 'http://sns.qzone.qq.com/cgi-bin/qzshare/cgi_qzshare_onekey?url=' + UrlPrefix + '&title=' + title + '&pics=' + pic;
window.open(url, '分享QQ空间', windowParam);
});
$("#leanoteDialog .sendRRBtn").click(function() {
var url = 'http://widget.renren.com/dialog/share?resourceUrl=' + UrlPrefix + '&srcUrl=' + UrlPrefix + '&title=' + title + '&pic=' + pic;
window.open(url, '分享人人网', windowParam);
});
} else {
$("#leanoteDialog .weibo span").html("对不起, 我们出错了!")
$("#leanoteDialog .weibo").html("对不起, 我们出错了!")
}
});
}});
@ -1109,6 +1171,13 @@ Note.moveNote = function(target, data) {
if(!note.IsTrash && note.NotebookId == notebookId) {
return;
}
// 修改数量
Notebook.incrNotebookNumberNotes(notebookId);
if(!note.IsTrash) {
Notebook.minusNotebookNumberNotes(note.NotebookId);
}
ajaxGet("/note/moveNote", {noteId: noteId, notebookId: notebookId}, function(ret) {
if(ret && ret.NoteId) {
if(note.IsTrash) {
@ -1168,6 +1237,9 @@ Note.copyNote = function(target, data, isShared) {
Note.setNoteCache(ret)
}
});
// 增加数量
Notebook.incrNotebookNumberNotes(notebookId)
}
// 这里速度不慢, 很快
@ -1218,24 +1290,24 @@ Note.initContextmenu = function() {
// context menu
//---------------------
var noteListMenu = {
width: 150,
width: 180,
items: [
{ text: "分享给好友", alias: 'shareToFriends', icon: "", faIcon: "fa-share-square-o", action: Note.listNoteShareUserInfo},
{ text: getMsg("shareToFriends"), alias: 'shareToFriends', icon: "", faIcon: "fa-share-square-o", action: Note.listNoteShareUserInfo},
{ type: "splitLine" },
{ text: "公开为博客", alias: 'set2Blog', icon: "", action: Note.setNote2Blog },
{ text: "取消公开为博客", alias: 'unset2Blog', icon: "", action: Note.setNote2Blog },
{ text: getMsg("publicAsBlog"), alias: 'set2Blog', faIcon: "fa-bold", action: Note.setNote2Blog },
{ text: getMsg("cancelPublic"), alias: 'unset2Blog', faIcon: "fa-undo", action: Note.setNote2Blog },
//{ type: "splitLine" },
//{ text: "分享到社区", alias: 'html2Image', icon: "", action: Note.html2Image},
{ type: "splitLine" },
// { text: "发送长微博", alias: 'html2Image', icon: "", action: Note.html2Image , width: 150, type: "group", items:[{text: "a"}]},
// { type: "splitLine" },
{ text: "删除", icon: "", faIcon: "fa-trash-o", action: Note.deleteNote },
{ text: "移动", alias: "move", icon: "",
{ text: getMsg("delete"), icon: "", faIcon: "fa-trash-o", action: Note.deleteNote },
{ text: getMsg("move"), alias: "move", faIcon: "fa-arrow-right",
type: "group",
width: 150,
width: 180,
items: notebooksMove
},
{ text: "复制", alias: "copy", icon: "",
{ text: getMsg("copy"), alias: "copy", icon:"", faIcon: "fa-copy",
type: "group",
width: 150,
width: 180,
items: notebooksCopy
}
],
@ -1446,6 +1518,8 @@ var Attach = {
self._renderAttachs(self.loadedNoteAttachs[noteId]);
return;
}
// 显示loading
self.attachListO.html('<li class="loading"><img src="/images/loading-24.gif"/></li>');
// ajax获取noteAttachs
ajaxGet("/attach/getAttachs", {noteId: noteId}, function(ret) {
var list = [];
@ -1501,22 +1575,20 @@ $(function() {
//-----------------
// for list nav
$("#noteItemList").on("click", ".item", function(event) {
log(event);
event.stopPropagation();
// 找到上级.item
var parent = findParents(this, ".item");
if(!parent) {
return;
}
var noteId = $(this).attr("noteId");
// 手机端处理
Mobile.changeNote(noteId);
var noteId = parent.attr("noteId");
if(!noteId) {
return;
}
// 当前的和所选的是一个, 不改变
if(Note.curNoteId == noteId) {
return;
if(Note.curNoteId != noteId) {
Note.changeNote(noteId);
}
Note.changeNote(noteId);
});
//------------------