From e5f7c66d1ec6b1badc3b52276c59e33c1744e71e Mon Sep 17 00:00:00 2001
From: life
Date: Sun, 9 Nov 2014 22:14:08 +0800
Subject: [PATCH] test
---
app/controllers/BaseController.go | 3 +
app/controllers/init.go | 1 +
app/views/share/note_share_user_infos.html | 84 -
public/js/app/attachment_upload.js | 212 ---
public/js/app/blog/common.js | 207 ---
public/js/app/blog/view.js | 509 ------
public/js/app/import_theme.js | 114 --
public/js/app/note-min.js | 1 -
public/js/app/note.js | 1674 --------------------
public/js/app/notebook-min.js | 1 -
public/js/app/notebook.js | 888 -----------
public/js/app/page-min.js | 1 -
public/js/app/page.js | 795 ----------
public/js/app/share-min.js | 1 -
public/js/app/share.js | 583 -------
public/js/app/tag-min.js | 1 -
public/js/app/tag.js | 300 ----
17 files changed, 4 insertions(+), 5371 deletions(-)
delete mode 100644 app/views/share/note_share_user_infos.html
delete mode 100644 public/js/app/attachment_upload.js
delete mode 100644 public/js/app/blog/common.js
delete mode 100644 public/js/app/blog/view.js
delete mode 100644 public/js/app/import_theme.js
delete mode 100644 public/js/app/note-min.js
delete mode 100644 public/js/app/note.js
delete mode 100644 public/js/app/notebook-min.js
delete mode 100644 public/js/app/notebook.js
delete mode 100644 public/js/app/page-min.js
delete mode 100644 public/js/app/page.js
delete mode 100644 public/js/app/share-min.js
delete mode 100644 public/js/app/share.js
delete mode 100644 public/js/app/tag-min.js
delete mode 100644 public/js/app/tag.js
diff --git a/app/controllers/BaseController.go b/app/controllers/BaseController.go
index d86a99e..8ed0de9 100644
--- a/app/controllers/BaseController.go
+++ b/app/controllers/BaseController.go
@@ -196,6 +196,9 @@ func (c BaseController) SetLocale() string {
func (c BaseController) SetUserInfo() {
userInfo := c.GetUserInfo()
c.RenderArgs["userInfo"] = userInfo
+ if(userInfo.Username == adminUsername) {
+ c.RenderArgs["isAdmin"] = true
+ }
}
// life
diff --git a/app/controllers/init.go b/app/controllers/init.go
index 186323e..2af847f 100644
--- a/app/controllers/init.go
+++ b/app/controllers/init.go
@@ -33,6 +33,7 @@ var themeService *service.ThemeService
var pageSize = 1000
var defaultSortField = "UpdatedTime"
var leanoteUserId = "admin" // 不能更改
+var adminUsername = "admin"
var siteUrl = "http://leanote.com"
// 拦截器
diff --git a/app/views/share/note_share_user_infos.html b/app/views/share/note_share_user_infos.html
deleted file mode 100644
index 68bc9fe..0000000
--- a/app/views/share/note_share_user_infos.html
+++ /dev/null
@@ -1,84 +0,0 @@
-
-
-
-
- {{$noteId := .note.NoteId.Hex}}
-
-
- {{if .noteShareUserInfos }}
-
-
-
- #
- Email
- 权限
- 删除分享
-
-
-
- {{range $i, $v := .noteShareUserInfos}}
- {{$toUserId := $v.ToUserId.Hex}}
-
- {{add $i}}
- {{$v.Email}}
-
- {{if eq $v.Perm 0}}
- 只读
- {{else}}
- 可编辑
- {{end}}
-
-
- 删除
-
-
- {{end}}
-
-
- {{else}}
- 无分享信息
- {{end}}
-
-
-
-
-
-
-
\ No newline at end of file
diff --git a/public/js/app/attachment_upload.js b/public/js/app/attachment_upload.js
deleted file mode 100644
index 8b25956..0000000
--- a/public/js/app/attachment_upload.js
+++ /dev/null
@@ -1,212 +0,0 @@
-// upload attachment
-// 依赖note
-var urlPrefix = UrlPrefix;
-define('attachment_upload', ['jquery.ui.widget', 'fileupload'], function(){
- // Helper function that formats the file sizes
- function formatFileSize(bytes) {
- if (typeof bytes !== 'number') {
- return '';
- }
- if (bytes >= 1000000000) {
- return (bytes / 1000000000).toFixed(2) + ' GB';
- }
- if (bytes >= 1000000) {
- return (bytes / 1000000).toFixed(2) + ' MB';
- }
- return (bytes / 1000).toFixed(2) + ' KB';
- }
-
- function setDropStyle(dropzoneId, formId) {
- // drag css
- var dropZone = $(dropzoneId);
- $(formId).bind('dragover', function (e) {
- e.preventDefault();
- var timeout = window.dropZoneTimeoutAttach;
- if(timeout) {
- clearTimeout(timeout);
- }
-
- var found = false,
- node = e.target;
- do {
- if (node === dropZone[0]) {
- found = true;
- break;
- }
- node = node.parentNode;
- } while (node != null);
- if (found) {
- dropZone.addClass('hover');
- } else {
- dropZone.removeClass('hover');
- }
- window.dropZoneTimeoutAttach = setTimeout(function () {
- window.dropZoneTimeoutAttach = null;
- dropZone.removeClass('in hover');
- }, 100);
- });
- }
-
- setDropStyle("#dropAttach", "#uploadAttach");
- setDropStyle("#dropAvatar", "#uploadAvatar");
-
- var initUploader = function() {
- $('.dropzone .btn-choose-file').click(function() {
- $(this).parent().find('input').click();
- });
-
- var $msg = $('#attachUploadMsg');
- // Initialize the jQuery File Upload plugin
- $('#uploadAttach').fileupload({
- dataType: 'json',
- // This element will accept file drag/drop uploading
- dropZone: $('#dropAttach'),
- formData: function(form) {
- return [{name: 'noteId', value: Note.curNoteId}] // 传递笔记本过去
- },
- // This function is called when a file is added to the queue;
- // either via the browse button, or via drag/drop:
- add: function(e, data) {
- var note = Note.getCurNote();
- if(!note || note.IsNew) {
- alert("This note hasn't saved, please save it firstly!")
- return;
- }
- var tpl = $('');
-
- // Append the file name and file size
- tpl.append(data.files[0].name + ' [' + formatFileSize(data.files[0].size) + ' ] ');
-
- // Add the HTML to the UL element
- $msg.html(tpl);
- data.context = $msg;
-
- // 检查文件大小
- var size = data.files[0].size;
- var maxFileSize = +GlobalConfigs["uploadAttachSize"] || 100;
- if(typeof size == 'number' && size > 1024 * 1024 * maxFileSize) {
- tpl.find("img").remove();
- tpl.removeClass("alert-info").addClass("alert-danger");
- tpl.append(" Warning: File size is bigger than " + maxFileSize + "M");
- setTimeout((function(tpl) {
- return function() {
- tpl.remove();
- }
- })(tpl), 3000);
- return;
- }
-
- // Automatically upload the file once it is added to the queue
- var jqXHR;
- setTimeout(function() {
- jqXHR = data.submit();
- }, 10);
- },
- /*
- progress: function (e, data) {
- },
- */
- done: function(e, data) {
- if (data.result.Ok == true) {
- data.context.html("");
- Attach.addAttach(data.result.Item);
- } else {
- var re = data.result;
- data.context.html("");
- var tpl = $('');
- tpl.append('Error: ' + data.files[0].name + ' [' + formatFileSize(data.files[0].size) + ' ] ' + data.result.Msg);
- data.context.html(tpl);
- setTimeout((function(tpl) {
- return function() {
- tpl.remove();
- }
- })(tpl), 3000);
- }
- $("#uploadAttachMsg").scrollTop(1000);
- },
- fail: function(e, data) {
- data.context.html("");
- var tpl = $('');
- tpl.append('Error: ' + data.files[0].name + ' [' + formatFileSize(data.files[0].size) + ' ] ' + data.errorThrown);
- data.context.html(tpl);
- setTimeout((function(tpl) {
- return function() {
- tpl.remove();
- }
- })(tpl), 3000);
-
- $("#uploadAttachMsg").scrollTop(1000);
- }
- });
-
- //-------------------
-
- var $msg2 = $('#avatarUploadMsg');
- $('#uploadAvatar').fileupload({
- dataType: 'json',
- dropZone: $('#dropAvatar'),
- add: function(e, data) {
- var tpl = $('');
-
- // Append the file name and file size
- tpl.append(data.files[0].name + ' [' + formatFileSize(data.files[0].size) + ' ] ');
-
- // Add the HTML to the UL element
- $msg2.html(tpl);
- data.context = $msg2;
-
- // 检查文件大小
- var size = data.files[0].size;
- var maxFileSize = +GlobalConfigs["uploadAvatarSize"] || 100;
- if(typeof size == 'number' && size > 1024 * 1024 * maxFileSize) {
- tpl.find("img").remove();
- tpl.removeClass("alert-info").addClass("alert-danger");
- tpl.append(" Warning: File size is bigger than " + maxFileSize + "M");
- setTimeout((function(tpl) {
- return function() {
- tpl.remove();
- }
- })(tpl), 3000);
- return;
- }
-
- // Automatically upload the file once it is added to the queue
- var jqXHR;
- setTimeout(function() {
- jqXHR = data.submit();
- }, 10);
- },
- done: function(e, data) {
- if (data.result.Ok == true) {
- data.context.html("");
- var re = data.result;
- $("#avatar").attr("src", UrlPrefix + "/" + re.Id);
- } else {
- var re = data.result;
- data.context.html("");
- var tpl = $('');
- tpl.append('Error: ' + data.files[0].name + ' [' + formatFileSize(data.files[0].size) + ' ] ' + data.result.Msg);
- data.context.html(tpl);
- setTimeout((function(tpl) {
- return function() {
- tpl.remove();
- }
- })(tpl), 3000);
- }
- },
- fail: function(e, data) {
- data.context.html("");
- var tpl = $('');
- tpl.append('Error: ' + data.files[0].name + ' [' + formatFileSize(data.files[0].size) + ' ] ' + data.errorThrown);
- data.context.html(tpl);
- setTimeout((function(tpl) {
- return function() {
- tpl.remove();
- }
- })(tpl), 3000);
- }
- });
- }
-
- initUploader();
-});
\ No newline at end of file
diff --git a/public/js/app/blog/common.js b/public/js/app/blog/common.js
deleted file mode 100644
index be4e505..0000000
--- a/public/js/app/blog/common.js
+++ /dev/null
@@ -1,207 +0,0 @@
-// 返回是否是re.Ok == true
-function reIsOk(re) {
- return re && typeof re == "object" && re.Ok;
-}
-function showAlert(id, msg, type, id2Focus) {
- $(id).html(msg).removeClass("alert-danger").removeClass("alert-success").removeClass("alert-warning").addClass("alert-" + type).show();
- if(id2Focus) {
- $(id2Focus).focus();
- }
-}
-function hideAlert(id, timeout) {
- if(timeout) {
- setTimeout(function() {
- $(id).hide();
- }, timeout);
- } else {
- $(id).hide();
- }
-}
-function ajaxGet(url, param, func) {
- $.get(url, param, func);
-}
-function ajaxPost(url, param, func) {
- $.post(url, param, func);
-}
-function goLogin(){
- var loginUrl = urlPrefix + '/login?from=' + encodeURI(location.href);
- location.href = loginUrl;
-}
-function goRegister() {
- var registerUrl = urlPrefix + '/register?from=' + encodeURI(location.href);
- location.href = registerUrl;
-}
-function needLogin() {
- if(typeof visitUserInfo == "undefined" || !visitUserInfo || !visitUserInfo.UserId) {
- // 弹框之
- var loginUrl = urlPrefix + '/login?from=' + encodeURI(location.href);
- var registerUrl = urlPrefix + '/register?from=' + encodeURI(location.href);
- var modal = BootstrapDialog.show({
- title: "你还未登录",
- message: '立即登录 , 发表评论.
没有帐号?
立即注册 ',
- nl2br: false
- });
- return true;
- }
- return false;
-}
-function scrollToTarget(t, fixed) {
- if(!fixed) {
- fixed = 0;
- }
- var $t = $(t)
- var targetOffset = $t.offset().top + fixed;
- $('html,body').animate({scrollTop: targetOffset}, 300);
-}
-
-var windowParam = 'width=700, height=580, top=180, left=320, toolbar=no, menubar=no, scrollbars=no, location=yes, resizable=no, status=no';
-function getShareUrl(noteId) {
- return viewUrl + "/" + noteId;
-}
-function getShareTitle(title) {
- return encodeURI(title + " (来自leanote.com)");
-}
-function shareSinaWeibo(noteId, title, pic) {
- var url = "http://service.weibo.com/share/share.php?title=" + getShareTitle(title) + "&url=" + getShareUrl(noteId);
- window.open(url, 'Share', windowParam);
-}
-function shareTencentWeibo(noteId, title, pic) {
- var _appkey = '801542571';
- var url = "http://share.v.t.qq.com/index.php?c=share&a=index&appkey=" + _appkey +"&title=" + getShareTitle(title) + "&url=" + getShareUrl(noteId) +"&pic=" + pic;
- window.open(url, 'Share', windowParam);
-}
-function shareQQ(noteId, title, pic) {
- var url = 'http://sns.qzone.qq.com/cgi-bin/qzshare/cgi_qzshare_onekey?url=' + getShareUrl(noteId) + '&title=' + title + '&pics=' + pic;
- window.open(url, 'Share', windowParam);
-}
-function shareRenRen(noteId, title, pic) {
- var url = 'http://widget.renren.com/dialog/share?resourceUrl=' + getShareUrl(noteId) + '&srcUrl=' + getShareUrl(noteId) + '&title=' + getShareTitle(title) + '&pic=' + pic;
- window.open(url, 'Share', windowParam);
-}
-
-// https://twitter.com/intent/tweet?text=&pic=
-function shareTwitter(noteId, title, pic) {
- var url = 'https://twitter.com/intent/tweet?text=' + getShareTitle(title) + '&pic=' + pic;
- window.open(url, 'Share', windowParam);
-}
-// http://www.facebook.com/sharer.php?u=&t=”
-function shareFacebook(noteId, title, pic) {
- var url = ' http://www.facebook.com/sharer.php?t=' + getShareTitle(title) + '&pic=' + pic;
- window.open(url, 'Share', windowParam);
-}
-
-//JavaScript函数:
-var minute = 1000 * 60;
-var hour = minute * 60;
-var day = hour * 24;
-var halfamonth = day * 15;
-var month = day * 30;
-// 2014-01-06T18:29:48.802+08:00
-
-function goNowToDatetime(goNow) {
- if(!goNow) {
- return "";
- }
- return goNow.substr(0, 10) + " " + goNow.substr(11, 8);
-}
-function getDateDiff(dateTimeStamp){
- var now = new Date().getTime();
- var diffValue = now - dateTimeStamp;
- if(diffValue < 0){
- return "";
- }
- var monthC =diffValue/month;
- var weekC =diffValue/(7*day);
- var dayC =diffValue/day;
- var hourC =diffValue/hour;
- var minC =diffValue/minute;
- if(monthC>=1){
- result=parseInt(monthC) + getMsg("monthsAgo");
- }
- else if(weekC>=1){
- result=parseInt(weekC) + getMsg("weeksAgo");
- }
- else if(dayC>=1){
- result=parseInt(dayC) + getMsg("daysAgo");
- }
- else if(hourC>=1){
- result=parseInt(hourC) + getMsg("hoursAgo");
- }
- else if(minC>=1){
- result=parseInt(minC) + getMsg("minutesAgo");
- }else {
- result=getMsg("justNow");
- }
- return result;
-}
-
-function weixin() {
- var local=window.location.href;
- var title = $.trim($(".title").text());
- var desc = $.trim($("#desc").text());
- var imgUrl = $("#content img").eq(0).attr('src');
- window.shareData = {
- "imgUrl": imgUrl,
- "timeLineLink":local,
- "sendFriendLink": local,
- "weiboLink":local,
- "tTitle": title,
- "tContent": desc,
- "fTitle": title,
- "fContent": desc,
- "wContent": desc
- };
- document.addEventListener('WeixinJSBridgeReady', function onBridgeReady() {
- // 发送给好友
- WeixinJSBridge.on('menu:share:appmessage', function (argv) {
- WeixinJSBridge.invoke('sendAppMessage', {
- "img_url": window.shareData.imgUrl,
- "img_width": "200",
- "link": window.shareData.sendFriendLink,
- "desc": window.shareData.fContent,
- "title": window.shareData.fTitle
- }, function (res) {
- hs_guide('none');
- _report('send_msg', res.err_msg);
- })
- });
-
- // 分享到朋友圈
- WeixinJSBridge.on('menu:share:timeline', function (argv) {
- WeixinJSBridge.invoke('shareTimeline', {
- "img_url": window.shareData.imgUrl,
- "img_width": "200",
- "link": window.shareData.timeLineLink,
- "desc": window.shareData.tContent,
- "title": window.shareData.tTitle
- }, function (res) {
- hs_guide('none');
- _report('timeline', res.err_msg);
- });
- });
-
- // 分享到微博
- WeixinJSBridge.on('menu:share:weibo', function (argv) {
- WeixinJSBridge.invoke('shareWeibo', {
- "content": window.shareData.wContent,
- "url": window.shareData.weiboLink,
- }, function (res) {
- hs_guide('none');
- _report('weibo', res.err_msg);
- });
- });
- }, false);
-}
-
-var LEA = {isMobile: false};
-function isMobile() {
- var u = navigator.userAgent;
- LEA.isMobile = false;
- LEA.isMobile = /Mobile|Android|iPhone/i.test(u);
- if(!LEA.isMobile && $(document).width() <= 600){
- LEA.isMobile = true
- }
-}
-$(function() {
- isMobile();
-});
\ No newline at end of file
diff --git a/public/js/app/blog/view.js b/public/js/app/blog/view.js
deleted file mode 100644
index 8bb7b09..0000000
--- a/public/js/app/blog/view.js
+++ /dev/null
@@ -1,509 +0,0 @@
-function scrollTo(self, tagName, text) {
- var iframe = $("#content");
- var target = iframe.find(tagName + ":contains(" + text + ")");
-
- // 找到是第几个
- // 在nav是第几个
- var navs = $('#blogNavContent [data-a="' + tagName + '-' + encodeURI(text) + '"]');
- var len = navs.size();
- for(var i = 0; i < len; ++i) {
- if(navs[i] == self) {
- break;
- }
- }
-
- if (target.size() >= i+1) {
- target = target.eq(i);
- // 之前插入, 防止多行定位不准
- var top = target.offset().top;
- if(LEA.isMobile) {
- top -= 50;
- }
- var nowTop = $(document).scrollTop();
- // 用$("body").scrllTop(10)没反应 firefox下
- $('html,body').animate({scrollTop: top}, 200);
- return;
- }
-}
-function genNav() {
- var $con = $("#content");
- var html = $con.html();
- // 构造一棵树
- // {"h1-title":{h2-title:{}}}
- var tree = [];//[{title: "xx", children:[{}]}, {title:"xx2"}];
- var hs = $con.find("h1,h2,h3,h4,h5,h6").toArray();
- var titles = '
';
- for(var i = 0; i < hs.length; ++i) {
- var text = $(hs[i]).text();
- var tagName = hs[i].tagName.toLowerCase();
- // scrollTo在page.js中定义
- titles += '' + text + ' ';
- }
- titles += " ";
- $("#blogNavContent").html(titles);
- if(!hs.length) {
- $("#blogNavContent").html(getMsg("none"));
- return false;
- }
- return true;
-}
-
-function initNav() {
- var hasNav = genNav();
- if(!hasNav) {
- return;
- }
-
- var $title = $(".title");
- var titlePos = $title.offset();
- var top = titlePos.top + 10;// - $title.height();
- // 手机下不要与标题在同一高度
- if(LEA.isMobile){
- top += 30;
- }
- if(top < 0) {
- top = 10;
- }
-
- var left = $title.width() + titlePos.left - 100;
- $("#blogNav").css("top", top).css("left", left);
- $("#blogNav").show();
-
- $("#blogNavNav").click(function() {
- var $o = $("#blogNavContent");
- if($o.is(":hidden")) {
- $o.show();
- } else {
- $o.hide();
- }
- });
-
- var $d = $(document);
- function reNav() {
- var vtop = $d.scrollTop();
- if(vtop <= top) {
- $("#blogNav").css("top", top-vtop);
- } else {
- // 差距很磊了
- if(LEA.isMobile) {
- $("#blogNav").css("top", 50);
- } else {
- $("#blogNav").css("top", 10);
- }
- }
- }
- reNav();
- $(window).scroll(reNav);
-}
-
-var C = {
- info: null,
- noteId: noteId,
- preLikeNum: preLikeNum,
- commentNum: commentNum,
- likeBtnO: $("#likeBtn"),
- likeNumO: $("#likeNum"),
- tLikersO: $("#tLikers"),
- likersO: $("#likers"),
- tCommentsO: $("#tComments"),
- commentsO: $("#comments"),
-
- commentBtnO: $("#commentBtn"),
-
- commentsLoadingO: $(".comments-loading"),
- commentsMoreO: $(".comments-more"),
-
- commentBoxO: $(".comment-box"),
- init: function() {
- var self = this;
- if(UserBlogInfo.CanComment && UserBlogInfo.CommentType != "disqus") {
- self.initLikeAndComments();
- } else {
- self.initLike();
- }
- self.initEvent();
- self.incReadNum();
- },
- incReadNum: function() {
- var self = this;
- if(!$.cookie(self.noteId)) {
- $.cookie(self.noteId, 1);
- ajaxGet(staticUrl + "/blog/incReadNum", {noteId: self.noteId});
- }
- },
- initLike: function() {
- var self = this;
- ajaxGet(staticUrl + "/blog/getLike", {noteId: self.noteId}, function(ret) {
- self.info = ret;
- self.toggleLikeBtnActive();
- self.renderLikers();
- });
- },
- initLikeAndComments: function() {
- var self = this;
- ajaxGet(staticUrl + "/blog/getLikeAndComments", {noteId: self.noteId}, function(ret) {
- self.info = ret;
- self.toggleLikeBtnActive();
- self.renderLikers();
- // 是否需要renderComments?
- self.info.commentUserInfo = self.info.commentUserInfo || {};
- // 为了防止第一条评论找不到用户信息情况
- if(visitUserInfo.UserId) {
- self.info.commentUserInfo[visitUserInfo.UserId] = visitUserInfo;
- }
- self.renderComments();
-
- self.commentBoxO.removeClass("hide");
- self.commentsLoadingO.addClass("hide");
- if(self.info.pageInfo.TotalPage > self.info.pageInfo.CurPage) {
- self.commentsMoreO.removeClass("hide");
- self.initMoreComments();
- }
- });
- },
- initMoreComments: function() {
- var self = this;
- self.commentsMoreO.find("a").click(function(){
- if(self.info.pageInfo.TotalPage > self.info.pageInfo.CurPage) {
- self.commentsMoreO.addClass("hide");
- self.commentsLoadingO.removeClass("hide");
- ajaxGet(staticUrl + "/blog/listComments", {noteId: self.noteId, page: self.info.pageInfo.CurPage+1}, function(ret) {
- var pageInfo = ret.pageInfo;
- var comments = ret.comments;
- var commentUserInfo = ret.commentUserInfo;
-
- $.extend(self.info.commentUserInfo, commentUserInfo);
-
- // 渲染之
- for(var i in comments) {
- var comment = comments[i];
- comment = self.parseComment(comment);
- }
- var html = self.tCommentsO.render({comments: comments, visitUserInfo: visitUserInfo});
- self.commentsO.append(html);
-
- self.info.pageInfo = pageInfo;
-
- if(self.info.pageInfo.TotalPage > self.info.pageInfo.CurPage) {
- self.commentsMoreO.removeClass("hide");
- } else {
- self.commentsMoreO.addClass("hide");
- }
-
- self.commentsLoadingO.addClass("hide");
- });
- }
- });
- },
- addCommentRender: function(comment){
- var self = this;
- comment = self.parseComment(comment);
- var html = self.tCommentsO.render({blogUrl: blogUrl, comments: [comment], visitUserInfo: visitUserInfo});
- self.commentsO.prepend(html);
- var li = self.commentsO.find("li").eq(0);
- li.hide();
- li.show(500);
- li.addClass("item-highlight");
- setTimeout(function() {
- li.removeClass("item-highlight");
- }, 2000);
- },
- parseComment: function(comment) {
- var self = this;
- var authorUserId = UserInfo.UserId;
- commentUserInfo = self.info.commentUserInfo;
- comment.UserInfo = commentUserInfo[comment.UserId];
- // 是作者自己
- if(visitUserInfo.UserId == UserInfo.UserId) {
- comment.IsMyNote = true;
- }
- if(comment.UserId == authorUserId) {
- comment.IsAuthorComment = true;
- }
- if(comment.UserId == visitUserInfo.UserId) {
- comment.IsMyComment = true;
- }
- // 不是回复自己
- if(comment.ToUserId && comment.ToUserId != comment.UserId) {
- comment.ToUserInfo = commentUserInfo[comment.ToUserId];
- if(comment.ToUserInfo.UserId == UserInfo.UserId) {
- comment.ToUserIsAuthor = true;
- }
- }
- comment.PublishDate = getDateDiff(Date.parse(goNowToDatetime(comment.CreatedTime)));
- return comment;
- },
- // 渲染评论
- renderComments: function() {
- var self = this;
- var comments = self.info.comments || [];
- if(comments.length == 0) {
- return;
- }
-
- // 整理数据
- // 回复谁, 是否是作者?
- // 回复日期, 几天前, 刚刚
- for(var i in comments) {
- var comment = comments[i];
- comment = self.parseComment(comment);
- }
- var html = self.tCommentsO.render({blogUrl: blogUrl, comments: comments, visitUserInfo: visitUserInfo});
- self.commentsO.html(html);
- },
-
- // 重新渲染likers
- reRenderLikers: function(addMe) {
- var self = this;
- var likedUsers = self.info.likedUsers || [];
- for(var i = 0; i < likedUsers.length; ++i) {
- var user = likedUsers[i];
- if(user.UserId == visitUserInfo.UserId) {
- likedUsers.splice(i, 1);
- break;
- }
- }
- if(addMe) {
- likedUsers = [visitUserInfo].concat(likedUsers);
- self.info.likedUsers = likedUsers;
- }
- self.renderLikers();
- },
- renderLikers: function() {
- var self = this;
- var users = self.info.likedUsers || [];
- var html = self.tLikersO.render({blogUrl: blogUrl, users: users});
- self.likersO.html(html);
- },
- toggleLikeBtnActive: function() {
- var self = this;
- if(self.info.isILikeIt) {
- self.likeBtnO.addClass("active");
- } else {
- self.likeBtnO.removeClass("active");
- }
- },
- commentNumO: $("#commentNum"),
- bindCommentNum: function(fix) {
- var self = this;
- self.commentNum += fix;
- self.commentNumO.text(self.commentNum);
- },
- initEvent: function() {
- var self = this;
-
- // like or not
- self.likeBtnO.click(function() {
- if(!visitUserInfo.UserId) {
- needLogin();
- return;
- }
- ajaxPost(staticUrl + "/blog/likeBlog", {noteId: self.noteId}, function(ret) {
- if(ret.Ok) {
- // like
- if(ret.Item) {
- var num = self.preLikeNum+1;
- } else {
- var num = self.preLikeNum-1;
- }
- self.preLikeNum = num >= 0 ? num : 0;
- self.likeNumO.text(self.preLikeNum);
- self.info.isILikeIt = ret.Item;
- self.toggleLikeBtnActive();
-
- // 重新render likers
- // 我是否在列表中
- self.reRenderLikers(ret.Item);
- }
- });
- });
-
- // 显示回复回复
- $("#comments").on("click", ".comment-reply", function() {
- var form = $(this).closest("li").find("form");
- if(form.is(":hidden")) {
- form.show();
- form.find("textarea").focus();
- } else {
- form.hide();
- }
- });
- $("#comments").on("click", ".reply-cancel", function() {
- $(this).closest("form").hide();
- });
-
- // 回复
- $(".comment-box").on("click", ".reply-comment-btn", function(e) {
- e.preventDefault();
- var commentId = $(this).data("comment-id");
- var $form = $(this).closest("form");
- var $content = $form.find("textarea");
- var content = $.trim($content.val());
- if(!content) {
- $content.focus();
- return;
- }
- var t = $(this);
- t.button("loading");
- var data = {noteId: self.noteId, toCommentId: commentId, content: content};
- ajaxPost(staticUrl + "/blog/comment", data, function(ret) {
- t.button("reset");
- $content.val("");
- self.bindCommentNum(1);
- if(commentId) {
- $form.hide();
- }
-
- if(commentId) {
- scrollToTarget("#comments", -200);
- }
-
- // 添加一个
- self.addCommentRender(ret.Item);
- });
- });
-
- // 删除
- $(".comment-box").on("click", ".comment-trash", function(e) {
- var commentId = $(this).parent().data("comment-id");
- var t = this;
- BootstrapDialog.confirm(getMsg("confirmDeleteComment"), function(yes) {
- if(yes) {
- ajaxPost(staticUrl + "/blog/deleteComment", {noteId: self.noteId, commentId: commentId}, function(ret) {
- if(ret.Ok) {
- var li = $(t).closest("li");
- li.hide(500); // remove();
- setTimeout(function() {
- li.remove();
- }, 300);
-
- self.bindCommentNum(-1);
- }
- });
- }
- });
- });
-
- // 点zan
- $(".comment-box").on("click", ".comment-like", function(e) {
- var commentId = $(this).parent().data("comment-id");
- var t = this;
-
- ajaxPost(staticUrl + "/blog/likeComment", {commentId: commentId}, function(re) {
- if(re.Ok) {
- var ret = re.Item;
- if(ret.Num <= 0) {
- $(t).parent().find(".like-num").addClass("hide");
- } else {
- $(t).parent().find(".like-num").removeClass("hide");
- $(t).parent().find(".like-num-i").text(ret.Num)
- }
- if(ret.IsILikeIt) {
- $(t).find(".like-text").text(getMsg("unlike"));
- } else {
- $(t).find(".like-text").text(getMsg('like'));
- }
- }
- });
- });
-
- // 举报
- function report(commentId, noteId, title) {
- var form = $("#reportMsg").html();
- var body;
- var input;
- var isOver = false;
- var modal = BootstrapDialog.show({
- title: title,
- message: form,
- nl2br: false,
- buttons: [{
- label: getMsg("cancel"),
- action: function(dialog) {
- dialog.close();
- }
- }, {
- label: getMsg("confirm"),
- cssClass: 'btn-primary',
- action: function(dialog) {
- if(isOver) {
- dialog.close();
- }
- var val = body.find("input[type='radio']:checked").val();
- if(!val) {
- var val = body.find(".input-container input").val();
- }
- if(!val) {
- body.find(".footnote").html(getMsg("chooseReason"));
- return;
- }
- ajaxPost(staticUrl + "/blog/report", {commentId: commentId, noteId: noteId, reason: val}, function(re) {
- isOver = true;
- if(reIsOk(re)) {
- body.html(getMsg("reportSuccess"));
- } else {
- body.html(getMsg("error"));
- }
- setTimeout(function() {
- dialog.close();
- }, 3000);
- });
- }
- }]
- });
- body = modal.getModalBody();
- input = body.find(".input-container");
- body.find("input[type='radio']").click(function(){
- if(!$(this).val()) {
- input.show();
- input.find("input").focus();
- } else {
- input.hide();
- }
- });
- }
- $(".comment-box").on("click", ".comment-report", function() {
- if(needLogin()) {
- return;
- }
- var commentId = $(this).parent().data("comment-id");
- report(commentId, self.noteId, getMsg("reportComment?"));
- });
- $("#reportBtn").click(function() {
- if(needLogin()) {
- return;
- }
- report("", self.noteId, getMsg("reportBlog?"));
- });
-
- self.initShare();
- },
- weixinQRCodeO: $("#weixinQRCode"),
- initShare: function() {
- var self = this;
- $(".btn-weixin").click(function() {
- if(!self.weixinQRCodeO.html()) {
- self.weixinQRCodeO.qrcode(viewUrl + "/" + self.noteId);
- }
- BootstrapDialog.show({
- title: getMsg('scanQRCode'),
- message: self.weixinQRCodeO
- });
- });
-
- $(".btn-share").click(function() {
- var $this = $(this);
- var map = {"btn-weibo": shareSinaWeibo, "tencent-weibo": shareTencentWeibo, "qq": shareQQ, "renren": shareRenRen};
- for(var i in map) {
- if($this.hasClass(i)) {
- map[i](self.noteId, document.title);
- break;
- }
- }
- });
- }
-}
-
-$(function() {
- C.init();
-});
\ No newline at end of file
diff --git a/public/js/app/import_theme.js b/public/js/app/import_theme.js
deleted file mode 100644
index 83f7b52..0000000
--- a/public/js/app/import_theme.js
+++ /dev/null
@@ -1,114 +0,0 @@
-define('import_theme', ['jquery.ui.widget', 'fileupload'], function(){
- // Helper function that formats the file sizes
- function formatFileSize(bytes) {
- if (typeof bytes !== 'number') {
- return '';
- }
- if (bytes >= 1000000000) {
- return (bytes / 1000000000).toFixed(2) + ' GB';
- }
- if (bytes >= 1000000) {
- return (bytes / 1000000).toFixed(2) + ' MB';
- }
- return (bytes / 1000).toFixed(2) + ' KB';
- }
-
- function setDropStyle(dropzoneId, formId) {
- // drag css
- var dropZone = $(dropzoneId);
- $(formId).bind('dragover', function (e) {
- e.preventDefault();
- var timeout = window.dropZoneTimeoutAttach;
- if(timeout) {
- clearTimeout(timeout);
- }
-
- var found = false,
- node = e.target;
- do {
- if (node === dropZone[0]) {
- found = true;
- break;
- }
- node = node.parentNode;
- } while (node != null);
- if (found) {
- dropZone.addClass('hover');
- } else {
- dropZone.removeClass('hover');
- }
- window.dropZoneTimeoutAttach = setTimeout(function () {
- window.dropZoneTimeoutAttach = null;
- dropZone.removeClass('in hover');
- }, 100);
- });
- }
-
- setDropStyle("#dropAvatar", "#uploadAvatar");
-
- var initUploader = function() {
- $('.dropzone .btn-choose-file').click(function() {
- $(this).parent().find('input').click();
- });
-
- var $msg2 = $('#avatarUploadMsg');
- $('#uploadAvatar').fileupload({
- dataType: 'json',
- dropZone: $('#dropAvatar'),
- add: function(e, data) {
- var tpl = $('
');
-
- // Append the file name and file size
- tpl.append(data.files[0].name + '
[' + formatFileSize(data.files[0].size) + ' ] ');
-
- // Add the HTML to the UL element
- $msg2.html(tpl);
- data.context = $msg2;
-
- // 检查文件大小
- var size = data.files[0].size;
- if(typeof size == 'number' && size > 10 * 1024 * 1024) {
- tpl.find("img").remove();
- tpl.removeClass("alert-info").addClass("alert-danger");
- tpl.append("Warning: File size is bigger than 10M");
- return;
- }
-
- // Automatically upload the file once it is added to the queue
- var jqXHR;
- setTimeout(function() {
- jqXHR = data.submit();
- }, 10);
- },
- done: function(e, data) {
- if (data.result.Ok == true) {
- data.context.html("");
- var re = data.result;
- art.tips("Success");
- setTimeout(function() {
- location.reload();
- }, 1000);
- } else {
- var re = data.result;
- data.context.html("");
- var tpl = $('
');
- tpl.append('
Error: ' + data.files[0].name + '
[' + formatFileSize(data.files[0].size) + ' ] ' + data.result.Msg);
- data.context.html(tpl);
- }
- },
- fail: function(e, data) {
- data.context.html("");
- var tpl = $('
');
- tpl.append('
Error: ' + data.files[0].name + '
[' + formatFileSize(data.files[0].size) + ' ] ' + data.errorThrown);
- data.context.html(tpl);
- setTimeout((function(tpl) {
- return function() {
- tpl.remove();
- }
- })(tpl), 3000);
- }
- });
- }
-
- initUploader();
-});
\ No newline at end of file
diff --git a/public/js/app/note-min.js b/public/js/app/note-min.js
deleted file mode 100644
index 26a4329..0000000
--- a/public/js/app/note-min.js
+++ /dev/null
@@ -1 +0,0 @@
-Note.curNoteId="";Note.interval="";Note.itemIsBlog='
';Note.itemTplNoImg='
';Note.itemTplNoImg+=Note.itemIsBlog+' ';Note.itemTpl='
';Note.itemTpl+=Note.itemIsBlog+' ';Note.newItemTpl='
';Note.newItemTpl+=Note.itemIsBlog+' ';Note.noteItemListO=$("#noteItemList");Note.cacheByNotebookId={all:{}};Note.notebookIds={};Note.isReadOnly=false;Note.intervalTime=6e5;Note.startInterval=function(){Note.interval=setInterval(function(){log("自动保存开始...");changedNote=Note.curChangedSaveIt(false)},Note.intervalTime)};Note.stopInterval=function(){clearInterval(Note.interval);setTimeout(function(){Note.startInterval()},Note.intervalTime)};Note.addNoteCache=function(note){Note.cache[note.NoteId]=note;Note.clearCacheByNotebookId(note.NotebookId)};Note.setNoteCache=function(content,clear){if(!Note.cache[content.NoteId]){Note.cache[content.NoteId]=content}else{$.extend(Note.cache[content.NoteId],content)}if(clear==undefined){clear=true}if(clear){Note.clearCacheByNotebookId(content.NotebookId)}};Note.getCurNote=function(){var self=this;if(self.curNoteId==""){return null}return self.cache[self.curNoteId]};Note.getNote=function(noteId){var self=this;return self.cache[noteId]};Note.clearCacheByNotebookId=function(notebookId){if(notebookId){Note.cacheByNotebookId[notebookId]={};Note.cacheByNotebookId["all"]={};Note.notebookIds[notebookId]=true}};Note.notebookHasNotes=function(notebookId){var notes=Note.getNotesByNotebookId(notebookId);return!isEmpty(notes)};Note.getNotesByNotebookId=function(notebookId,sortBy,isAsc){if(!sortBy){sortBy="UpdatedTime"}if(isAsc=="undefined"){isAsc=false}if(!notebookId){notebookId="all"}if(!Note.cacheByNotebookId[notebookId]){return[]}if(Note.cacheByNotebookId[notebookId][sortBy]){return Note.cacheByNotebookId[notebookId][sortBy]}else{}var notes=[];var sortBys=[];for(var i in Note.cache){if(!i){continue}var note=Note.cache[i];if(note.IsTrash||note.IsShared){continue}if(notebookId=="all"||note.NotebookId==notebookId){notes.push(note)}}notes.sort(function(a,b){var t1=a[sortBy];var t2=b[sortBy];if(isAsc){if(t1
t2){return 1}}else{if(t1t2){return-1}}return 0});Note.cacheByNotebookId[notebookId][sortBy]=notes;return notes};Note.renderNotesAndFirstOneContent=function(ret){if(!isArray(ret)){return}Note.renderNotes(ret);if(!isEmpty(ret[0])){Note.changeNote(ret[0].NoteId)}else{}};Note.curHasChanged=function(force){if(force==undefined){force=true}var cacheNote=Note.cache[Note.curNoteId]||{};var title=$("#noteTitle").val();var tags=Tag.getTags();var contents=getEditorContent(cacheNote.IsMarkdown);var content,preview;var contentText;if(isArray(contents)){content=contents[0];preview=contents[1];contentText=content;if(content&&previewIsEmpty(preview)&&Converter){preview=Converter.makeHtml(content)}if(!content){preview=""}cacheNote.Preview=preview}else{content=contents;try{contentText=$(content).text()}catch(e){}}var hasChanged={hasChanged:false,IsNew:cacheNote.IsNew,IsMarkdown:cacheNote.IsMarkdown,FromUserId:cacheNote.FromUserId,NoteId:cacheNote.NoteId,NotebookId:cacheNote.NotebookId};if(hasChanged.IsNew){$.extend(hasChanged,cacheNote)}if(cacheNote.Title!=title){hasChanged.hasChanged=true;hasChanged.Title=title;if(!hasChanged.Title){}}if(!arrayEqual(cacheNote.Tags,tags)){hasChanged.hasChanged=true;hasChanged.Tags=tags}if(force&&cacheNote.Content!=content||!force&&$(cacheNote.Content).text()!=contentText){hasChanged.hasChanged=true;hasChanged.Content=content;var c=preview||content;hasChanged.Desc=Note.genDesc(c);hasChanged.ImgSrc=Note.getImgSrc(c);hasChanged.Abstract=Note.genAbstract(c)}else{log("text相同");log(cacheNote.Content==content)}hasChanged["UserId"]=cacheNote["UserId"]||"";return hasChanged};Note.genDesc=function(content){if(!content){return""}content=content.replace(/ /g," ");content=content.replace(/<\/p>/g," ");content=content.replace(/<\/div>/g," ");content=$("
").html(content).text();content=content.replace(//g,">");if(content.length<300){return content}return content.substring(0,300)};Note.genAbstract=function(content,len){if(len==undefined){len=1e3}if(content.length"&&isCode){n=n-1;isCode=false}else if(temp==";"&&isHTML){isHTML=false}if(!isCode&&!isHTML){n=n+1}result+=temp;if(n>=maxLen){break}}var d=document.createElement("div");d.innerHTML=result;return d.innerHTML};Note.getImgSrc=function(content){if(!content){return""}var imgs=$(content).find("img");for(var i in imgs){var src=imgs.eq(i).attr("src");if(src){return src}}return""};Note.curChangedSaveIt=function(force){if(!Note.curNoteId||Note.isReadOnly){return}var hasChanged=Note.curHasChanged(force);Note.renderChangedNote(hasChanged);if(hasChanged.hasChanged||hasChanged.IsNew){delete hasChanged.hasChanged;Note.setNoteCache(hasChanged,false);Note.setNoteCache({NoteId:hasChanged.NoteId,UpdatedTime:(new Date).format("yyyy-MM-ddThh:mm:ss.S")},false);showMsg(getMsg("saving"));ajaxPost("/note/UpdateNoteOrContent",hasChanged,function(ret){if(hasChanged.IsNew){ret.IsNew=false;Note.setNoteCache(ret,false)}showMsg(getMsg("saveSuccess"),1e3)});return hasChanged}return false};Note.selectTarget=function(target){$(".item").removeClass("item-active");$(target).addClass("item-active")};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;Note.stopInterval();var target=$(tt('[noteId="?"]',selectNoteId));Note.selectTarget(target);if(needSaveChanged==undefined){needSaveChanged=true}if(needSaveChanged){var changedNote=Note.curChangedSaveIt()}Note.curNoteId="";var cacheNote=Note.cache[selectNoteId];if(!isShare){if(cacheNote.Perm!=undefined){isShare=true}}var hasPerm=!isShare||Share.hasUpdatePerm(selectNoteId);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(hasPerm){Note.renderNoteContent(ret)}else{Note.renderNoteContentReadOnly(ret)}self.hideContentLoading()}if(cacheNote.Content){setContent(cacheNote);return}var url="/note/GetNoteContent";var param={noteId:selectNoteId};if(isShare){url="/share/GetShareNoteContent";param.sharedUserId=cacheNote.UserId}self.showContentLoading();if(Note.contentAjax!=null){Note.contentAjax.abort()}note.contentAjax=ajaxGet(url,param,setContent)};Note.renderChangedNote=function(changedNote){if(!changedNote){return}var $leftNoteNav=$(tt('[noteId="?"]',changedNote.NoteId));if(changedNote.Title){$leftNoteNav.find(".item-title").html(changedNote.Title)}if(changedNote.Desc){$leftNoteNav.find(".desc").html(changedNote.Desc)}if(changedNote.ImgSrc){$thumb=$leftNoteNav.find(".item-thumb");if($thumb.length>0){$thumb.find("img").attr("src",changedNote.ImgSrc)}else{$leftNoteNav.append(tt(' ',changedNote.ImgSrc));$leftNoteNav.addClass("item-image")}$leftNoteNav.find(".item-desc").removeAttr("style")}else if(changedNote.ImgSrc==""){$leftNoteNav.find(".item-thumb").remove();$leftNoteNav.removeClass("item-image")}};Note.clearNoteInfo=function(){Note.curNoteId="";Tag.clearTags();$("#noteTitle").val("");setEditorContent("");$("#wmd-input").val("");$("#wmd-preview").html("");$("#noteRead").hide()};Note.clearNoteList=function(){Note.noteItemListO.html("")};Note.clearAll=function(){Note.curNoteId="";Note.clearNoteInfo();Note.clearNoteList()};Note.renderNote=function(note){if(!note){return}$("#noteTitle").val(note.Title);Tag.renderTags(note.Tags)};Note.renderNoteContent=function(content){setEditorContent(content.Content,content.IsMarkdown,content.Preview);Note.curNoteId=content.NoteId};Note.showEditorMask=function(){$("#editorMask").css("z-index",10).show();if(Notebook.curNotebookIsTrashOrAll()){$("#editorMaskBtns").hide();$("#editorMaskBtnsEmpty").show()}else{$("#editorMaskBtns").show();$("#editorMaskBtnsEmpty").hide()}};Note.hideEditorMask=function(){$("#editorMask").css("z-index",-10).hide()};Note.renderNotesC=0;Note.renderNotes=function(notes,forNewNote,isShared){var renderNotesC=++Note.renderNotesC;if(!LEA.isMobile&&!Mobile.isMobile()){$("#noteItemList").slimScroll({scrollTo:"0px",height:"100%",onlyScrollBar:true})}if(!notes||typeof notes!="object"||notes.length<=0){if(!forNewNote){Note.showEditorMask()}return}Note.hideEditorMask();if(forNewNote==undefined){forNewNote=false}if(!forNewNote){Note.noteItemListO.html("")}var len=notes.length;var c=Math.ceil(len/20);Note._renderNotes(notes,forNewNote,isShared,1);for(var i=0;i'+getMsg("close")+"");options={};options.show=true;$("#leanoteDialog").modal(options);ajaxGet("noteContentHistory/listHistories",{noteId:Note.curNoteId},function(re){if(!isArray(re)){$content.html(getMsg("noHistories"));return}var str=""+getMsg("historiesNum")+'
';note=Note.cache[Note.curNoteId];var s="div";if(note.IsMarkdown){s="pre"}for(i in re){var content=re[i];content.Ab=Note.genAbstract(content.Content,200);str+=tt('#? class="each-content">??> '+getMsg("datetime")+': ? '+getMsg("unfold")+' '+getMsg("restoreFromThisVersion")+"
",i,+i+1,s,content.Ab,s,goNowToDatetime(content.UpdatedTime))}str+="
";$content.html(str);$("#historyList .all").click(function(){$p=$(this).parent().parent();var seq=$p.attr("seq");var $c=$p.find(".each-content");var info=re[seq];if(!info.unfold){$(this).text(getMsg("fold"));$c.html(info.Content);info.unfold=true}else{$(this).text(getMsg("unfold"));$c.html(info.Ab);info.unfold=false}});$("#historyList .back").click(function(){$p=$(this).parent().parent();var seq=$p.attr("seq");if(confirm(getMsg("confirmBackup"))){Note.curChangedSaveIt();note=Note.cache[Note.curNoteId];setEditorContent(re[seq].Content,note.IsMarkdown);hideDialog()}})})};Note.html2Image=function(target){var noteId=$(target).attr("noteId");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+"?"+(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 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").html("对不起, 我们出错了!")}})}})};Note.showReadOnly=function(){Note.isReadOnly=true;$("#noteRead").show()};Note.hideReadOnly=function(){Note.isReadOnly=false;$("#noteRead").hide()};Note.renderNoteReadOnly=function(note){Note.showReadOnly();$("#noteReadTitle").html(note.Title);Tag.renderReadOnlyTags(note.Tags);$("#noteReadCreatedTime").html(goNowToDatetime(note.CreatedTime));$("#noteReadUpdatedTime").html(goNowToDatetime(note.UpdatedTime))};Note.renderNoteContentReadOnly=function(note){if(note.IsMarkdown){$("#noteReadContent").html(''+note.Content+" ")}else{$("#noteReadContent").html(note.Content)}};Note.lastSearch=null;Note.lastKey=null;Note.lastSearchTime=new Date;Note.isOver2Seconds=false;Note.isSameSearch=function(key){var now=new Date;var duration=now.getTime()-Note.lastSearchTime.getTime();Note.isOver2Seconds=duration>2e3?true:false;if(!Note.lastKey||Note.lastKey!=key||duration>1e3){Note.lastKey=key;Note.lastSearchTime=now;return false}if(key==Note.lastKey){return true}Note.lastSearchTime=now;Note.lastKey=key;return false};Note.searchNote=function(){var val=$("#searchNoteInput").val();if(!val){Notebook.changeNotebook("0");return}if(Note.isSameSearch(val)){return}if(Note.lastSearch){Note.lastSearch.abort()}Note.curChangedSaveIt();Note.clearAll();showLoading();Note.lastSearch=$.post("/note/searchNote",{key:val},function(notes){hideLoading();if(notes){Note.lastSearch=null;Note.renderNotes(notes);if(!isEmpty(notes)){Note.changeNote(notes[0].NoteId,false)}}else{}})};Note.setNote2Blog=function(target){var noteId=$(target).attr("noteId");var note=Note.cache[noteId];var isBlog=true;if(note.IsBlog!=undefined){isBlog=!note.IsBlog}if(isBlog){$(target).find(".item-blog").show()}else{$(target).find(".item-blog").hide()}ajaxPost("/blog/setNote2Blog",{noteId:noteId,isBlog:isBlog},function(ret){if(ret){Note.setNoteCache({NoteId:noteId,IsBlog:isBlog},false)}})};Note.setAllNoteBlogStatus=function(notebookId,isBlog){if(!notebookId){return}var notes=Note.getNotesByNotebookId(notebookId);if(!isArray(notes)){return}var len=notes.length;if(len==0){for(var i in Note.cache){if(Note.cache[i].NotebookId==notebookId){Note.cache[i].IsBlog=isBlog}}}else{for(var i=0;i'+attach.Title+"")}});self.linkAllBtnO.on("click",function(e){e.stopPropagation();var note=Note.getCurNote();if(!note){return}var src=UrlPrefix+"/attach/downloadAll?noteId="+Note.curNoteId;var title=note.Title?note.Title+".tar.gz":"all.tar.gz";if(LEA.isMarkdownEditor()&&MarkdownEditor){MarkdownEditor.insertLink(src,title)}else{tinymce.activeEditor.insertContent(''+title+" ")}})},attachListO:$("#attachList"),attachNumO:$("#attachNum"),attachDropdownO:$("#attachDropdown"),downloadAllBtnO:$("#downloadAllBtn"),linkAllBtnO:$("#linkAllBtn"),clearNoteAttachNum:function(){var self=this;self.attachNumO.html("").hide()},renderNoteAttachNum:function(noteId,needHide){var self=this;var note=Note.getNote(noteId);if(note.AttachNum){self.attachNumO.html("("+note.AttachNum+")").show();self.downloadAllBtnO.show();self.linkAllBtnO.show()}else{self.attachNumO.hide();self.downloadAllBtnO.hide();self.linkAllBtnO.hide()}if(needHide){self.attachDropdownO.removeClass("open")}},_renderAttachs:function(attachs){var self=this;var html="";var attachNum=attachs.length;for(var i=0;i'+''+each.Title+"
"+' '+' '+' '+' '+"
"+"";self.attachsMap[each.AttachId]=each}self.attachListO.html(html);var note=Note.getCurNote();if(note){note.AttachNum=attachNum;self.renderNoteAttachNum(note.NoteId,false)}},renderAttachs:function(noteId){var self=this;if(self.loadedNoteAttachs[noteId]){self._renderAttachs(self.loadedNoteAttachs[noteId]);return}self.attachListO.html(' ');ajaxGet("/attach/getAttachs",{noteId:noteId},function(ret){var list=[];if(ret.Ok){list=ret.List;if(!list){list=[]}}self.loadedNoteAttachs[noteId]=list;self._renderAttachs(list)})},addAttach:function(attachInfo){var self=this;if(!self.loadedNoteAttachs[attachInfo.NoteId]){self.loadedNoteAttachs[attachInfo.NoteId]=[]}self.loadedNoteAttachs[attachInfo.NoteId].push(attachInfo);self.renderAttachs(attachInfo.NoteId)},deleteAttach:function(attachId){var self=this;var noteId=Note.curNoteId;var attachs=self.loadedNoteAttachs[noteId];for(var i=0;i 得到该notebook的notes, 显示出来, 并选中第一个!
-// 在这期间定时器还会保存, curNoteId还没换, 所以会清空curNoteId的content!!!
-
-// 2. note change, save cur, 立即curNoteId = ""!!
-
-// 3. 什么时候设置curNoteId? 是ajax得到内容之后设置
-
-// note
-Note.curNoteId = "";
-
-Note.interval = ""; // 定时器
-
-Note.itemIsBlog = '
';
-// for render
-Note.itemTplNoImg = ''
-Note.itemTplNoImg += Note.itemIsBlog +' ';
-
-// 有image
-Note.itemTpl = ''
-Note.itemTpl +=Note.itemIsBlog + ' ';
-
-// for new
-Note.newItemTpl = ''
-Note.newItemTpl += Note.itemIsBlog + ' ';
-
-Note.noteItemListO = $("#noteItemList");
-
-// notbeookId => {"updatedTime" => [noteId1, noteId2], "title" => [noteId1, noteId2...]} 排序方式分组
-// 一旦某notebook改变了就清空, 重新排序之. (用js排)
-Note.cacheByNotebookId = {all: {}};
-Note.notebookIds = {}; // notebookId => true
-
-Note.isReadOnly = false;
-// 定时保存信息
-Note.intervalTime = 600000; // 600s, 10mins
-Note.startInterval = function() {
- Note.interval = setInterval(function() {
- log("自动保存开始...")
- changedNote = Note.curChangedSaveIt(false);
- }, Note.intervalTime); // 600s, 10mins
-}
-// 停止, 当切换note时
-// 但过5000后自动启动
-Note.stopInterval = function() {
- clearInterval(Note.interval);
-
- setTimeout(function() {
- Note.startInterval();
- }, Note.intervalTime);
-}
-
-// note = {NoteId, Desc, UserId,...}
-Note.addNoteCache = function(note) {
- Note.cache[note.NoteId] = note;
- Note.clearCacheByNotebookId(note.NotebookId);
-}
-// content = {NoteId:, Content:}
-// 还可以设置其它的值
-Note.setNoteCache = function(content, clear) {
- if(!Note.cache[content.NoteId]) {
- Note.cache[content.NoteId] = content;
- } else {
- $.extend(Note.cache[content.NoteId], content);
- }
-
- if(clear == undefined) {
- clear = true;
- }
- if(clear) {
- Note.clearCacheByNotebookId(content.NotebookId);
- }
-}
-
-// 得到当前的笔记
-Note.getCurNote = function() {
- var self = this;
- if(self.curNoteId == "") {
- return null;
- }
- return self.cache[self.curNoteId];
-}
-Note.getNote = function(noteId) {
- var self = this;
- return self.cache[noteId];
-}
-
-// 每当有notebookId相应的note改变时都要重新清空之
-// 并设置该notebookId有值
-Note.clearCacheByNotebookId = function(notebookId) {
- if(notebookId) {
- Note.cacheByNotebookId[notebookId] = {};
- Note.cacheByNotebookId["all"] = {};
- Note.notebookIds[notebookId] = true;
- }
-}
-
-// notebook是否有notes
-// called by Notebook
-Note.notebookHasNotes = function(notebookId) {
- var notes = Note.getNotesByNotebookId(notebookId);
- return !isEmpty(notes);
-}
-
-// 得到notebook下的notes, 按什么排序 updatedTime?
-Note.getNotesByNotebookId = function(notebookId, sortBy, isAsc) {
- if(!sortBy) {
- sortBy = "UpdatedTime";
- }
- if(isAsc == "undefined") {
- isAsc = false; // 默认是降序
- }
-
- if(!notebookId) {
- notebookId = "all";
- }
-
- if(!Note.cacheByNotebookId[notebookId]) {
- return [];
- }
-
- if(Note.cacheByNotebookId[notebookId][sortBy]) {
- return Note.cacheByNotebookId[notebookId][sortBy];
- } else {
- }
-
- // 从所有的notes中找到notebookId的, 并排序之
- var notes = [];
- var sortBys = [];
- for(var i in Note.cache) {
- if(!i) {
- continue;
- }
- var note = Note.cache[i];
- // 不要trash的not, 共享的也不要
- if(note.IsTrash || note.IsShared) {
- continue;
- }
- if(notebookId == "all" || note.NotebookId == notebookId) {
- notes.push(note);
- }
- }
- // 排序之
- notes.sort(function(a, b) {
- var t1 = a[sortBy];
- var t2 = b[sortBy];
-
- if(isAsc) {
- if(t1 < t2) {
- return -1;
- } else if (t1 > t2) {
- return 1;
- }
- } else {
- if(t1 < t2) {
- return 1;
- } else if (t1 > t2) {
- return -1;
- }
- }
- return 0;
- });
-
- // 缓存之
- Note.cacheByNotebookId[notebookId][sortBy] = notes;
- return notes;
-}
-
-// called by Notebook
-// render 所有notes, 和第一个note的content
-Note.renderNotesAndFirstOneContent = function(ret) {
- // 错误的ret是一个Object
- if(!isArray(ret)) {
- return;
- }
-
- // note 导航
- Note.renderNotes(ret);
- // 渲染第一个
- if(!isEmpty(ret[0])) {
- Note.changeNote(ret[0].NoteId);
- } else {
- }
-
-}
-
-// 当前的note是否改变过了?
-// 返回已改变的信息
-// force bool true表示content比较是比较HTML, 否则比较text, 默认为true
-// 定时保存用false
-Note.curHasChanged = function(force) {
- if(force == undefined) {
- force = true;
- }
- var cacheNote = Note.cache[Note.curNoteId] || {};
- // 收集当前信息, 与cache比对
- var title = $("#noteTitle").val();
- var tags = Tag.getTags(); // TODO
-
- // 如果是markdown返回[content, preview]
- var contents = getEditorContent(cacheNote.IsMarkdown);
- var content, preview;
- var contentText;
- if (isArray(contents)) {
- content = contents[0];
- preview = contents[1];
- contentText = content;
- // preview可能没来得到及解析
- if (content && previewIsEmpty(preview) && Converter) {
- preview = Converter.makeHtml(content);
- }
- if(!content) {
- preview = "";
- }
- cacheNote.Preview = preview; // 仅仅缓存在前台
- } else {
- content = contents;
- try {
- contentText = $(content).text();
- } catch(e) {
- }
- }
-
- var hasChanged = {
- hasChanged: false, // 总的是否有改变
- IsNew: cacheNote.IsNew, // 是否是新添加的
- IsMarkdown: cacheNote.IsMarkdown, // 是否是markdown笔记
- FromUserId: cacheNote.FromUserId, // 是否是共享新建的
- NoteId: cacheNote.NoteId,
- NotebookId: cacheNote.NotebookId
- };
-
- if(hasChanged.IsNew) {
- $.extend(hasChanged, cacheNote);
- }
-
- if(cacheNote.Title != title) {
- hasChanged.hasChanged = true; // 本页使用用小写
- hasChanged.Title = title; // 要传到后台的用大写
- if(!hasChanged.Title) {
-// alert(1);
- }
- }
-
- if(!arrayEqual(cacheNote.Tags, tags)) {
- hasChanged.hasChanged = true;
- hasChanged.Tags = tags;
- }
-
- // 比较text, 因为note Nav会添加dom会导致content改变
- if((force && cacheNote.Content != content) || (!force && $(cacheNote.Content).text() != contentText)) {
- hasChanged.hasChanged = true;
- hasChanged.Content = content;
-
- // 从html中得到...
- var c = preview || content;
-
- hasChanged.Desc = Note.genDesc(c);
- hasChanged.ImgSrc = Note.getImgSrc(c);
- hasChanged.Abstract = Note.genAbstract(c);
-
- } else {
- log("text相同");
- log(cacheNote.Content == content);
- }
-
- hasChanged["UserId"] = cacheNote["UserId"] || "";
-
- return hasChanged;
-}
-
-// 由content生成desc
-// 换行不要替换
-Note.genDesc = function(content) {
- if(!content) {
- return "";
- }
-
- // 将,
替换成\n
- /*
- var token = "ALEALE";
- content = content.replace(/<\/p>/g, token);
- content = content.replace(/<\/div>/g, token);
- content = content.replace(/<\/?.+?>/g," ");
-
- pattern = new RegExp(token, "g");
- content = content.replace(pattern, " ");
- content = content.replace(/ ( *) /g, " "); // 两个 之间可能有空白
- content = content.replace(/ ( *) /g, " ");
-
- // 去掉最开始的 或
- content = trimLeft(content, " ");
- content = trimLeft(content, " ");
- content = trimLeft(content, "");
- content = trimLeft(content, "");
- */
-
- // 留空格
- content = content.replace(/ /g," ");
- content = content.replace(/<\/p>/g," ");
- content = content.replace(/<\/div>/g," ");
-
- // 避免其它的 ").html(content).text();
-
- // pre下text()会将< => < > => >
- content = content.replace(//g, ">");
-
- if(content.length < 300) {
- return content;
- }
- return content.substring(0, 300);
-}
-
-// 得到摘要
-Note.genAbstract = function(content, len) {
- if(len == undefined) {
- len = 1000;
- }
- if(content.length < len) {
- return content;
- }
- var isCode = false;
- var isHTML = false;
- var n = 0;
- var result = "";
- var maxLen = len;
- for(var i = 0; i < content.length; ++i) {
- var temp = content[i]
- if (temp == '<') {
- isCode = true
- } else if (temp == '&') {
- isHTML = true
- } else if (temp == '>' && isCode) {
- n = n - 1
- isCode = false
- } else if (temp == ';' && isHTML) {
- isHTML = false
- }
- if (!isCode && !isHTML) {
- n = n + 1
- }
- result += temp
- if (n >= maxLen) {
- break
- }
- }
-
- var d = document.createElement("div");
- d.innerHTML = result
- return d.innerHTML;
-}
-
-Note.getImgSrc = function(content) {
- if(!content) {
- return "";
- }
- var imgs = $(content).find("img");
- for(var i in imgs) {
- var src = imgs.eq(i).attr("src");
- if(src) {
- return src;
- }
- }
- return "";
-}
-
-// 如果当前的改变了, 就保存它
-// 以后要定时调用
-// force , 默认是true, 表强校验内容
-// 定时保存传false
-Note.curChangedSaveIt = function(force) {
- // 如果当前没有笔记, 不保存
- if(!Note.curNoteId || Note.isReadOnly) {
- return;
- }
-
- var hasChanged = Note.curHasChanged(force);
-
- // 把已改变的渲染到左边 item-list
- Note.renderChangedNote(hasChanged);
-
- if(hasChanged.hasChanged || hasChanged.IsNew) {
- 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);
-
- // 保存之
- showMsg(getMsg("saving"));
- ajaxPost("/note/UpdateNoteOrContent", hasChanged, function(ret) {
- if(hasChanged.IsNew) {
- // 缓存之, 后台得到其它信息
- ret.IsNew = false;
- Note.setNoteCache(ret, false);
- }
- showMsg(getMsg("saveSuccess"), 1000);
- });
-
- return hasChanged;
- }
- return false;
-}
-
-// 样式
-Note.selectTarget = function(target) {
- $(".item").removeClass("item-active");
- $(target).addClass("item-active");
-}
-
-// 改变note
-// 可能改变的是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();
-
- // 0
- var target = $(tt('[noteId="?"]', selectNoteId))
- Note.selectTarget(target);
-
- // 1 之前的note, 判断是否已改变, 改变了就要保存之
- // 这里, 在搜索的时候总是保存, 搜索的话, 比较快, 肯定没有变化, 就不要执行该操作
- if(needSaveChanged == undefined) {
- needSaveChanged = true;
- }
- if(needSaveChanged) {
- var changedNote = Note.curChangedSaveIt();
- }
-
- // 2. 设空, 防止在内容得到之前又发生保存
- Note.curNoteId = "";
-
- // 2 得到现在的
- // ajax之
- var cacheNote = Note.cache[selectNoteId];
-
- // 判断是否是共享notes
- if(!isShare) {
- if(cacheNote.Perm != undefined) {
- isShare = true;
- }
- }
- var hasPerm = !isShare || Share.hasUpdatePerm(selectNoteId); // 不是共享, 或者是共享但有权限
-
- // 有权限
- 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(hasPerm) {
- Note.renderNoteContent(ret);
- } else {
- Note.renderNoteContentReadOnly(ret);
- }
- self.hideContentLoading();
- }
-
- if(cacheNote.Content) {
- setContent(cacheNote);
- return;
- }
-
- var url = "/note/GetNoteContent";
- var param = {noteId: selectNoteId};
- if(isShare) {
- url = "/share/GetShareNoteContent";
- param.sharedUserId = cacheNote.UserId // 谁的笔记
- }
-
- self.showContentLoading();
- if(Note.contentAjax != null) {
- Note.contentAjax.abort();
- }
- note.contentAjax = ajaxGet(url, param, setContent);
-}
-
-// 渲染
-
-// 更改信息到左侧
-// 定时更改 当前正在编辑的信息到左侧导航
-// 或change select. 之前的note, 已经改变了
-Note.renderChangedNote = function(changedNote) {
- if(!changedNote) {
- return;
- }
-
- // 找到左侧相应的note
- var $leftNoteNav = $(tt('[noteId="?"]', changedNote.NoteId));
- if(changedNote.Title) {
- $leftNoteNav.find(".item-title").html(changedNote.Title);
- }
- if(changedNote.Desc) {
- $leftNoteNav.find(".desc").html(changedNote.Desc);
- }
- if(changedNote.ImgSrc) {
- $thumb = $leftNoteNav.find(".item-thumb");
- // 有可能之前没有图片
- if($thumb.length > 0) {
- $thumb.find("img").attr("src", changedNote.ImgSrc);
- } else {
- $leftNoteNav.append(tt(' ', changedNote.ImgSrc));
- $leftNoteNav.addClass("item-image");
- }
- $leftNoteNav.find(".item-desc").removeAttr("style");
- } else if(changedNote.ImgSrc == "") {
- $leftNoteNav.find(".item-thumb").remove(); // 以前有, 现在没有了
- $leftNoteNav.removeClass("item-image");
- }
-}
-
-// 清空右侧note信息, 可能是共享的,
-// 此时需要清空只读的, 且切换到note edit模式下
-Note.clearNoteInfo = function() {
- Note.curNoteId = "";
- Tag.clearTags();
- $("#noteTitle").val("");
- setEditorContent("");
-
- // markdown editor
- $("#wmd-input").val("");
- $("#wmd-preview").html("");
-
- // 只隐藏即可
- $("#noteRead").hide();
-}
-// 清除noteList导航
-Note.clearNoteList = function() {
- Note.noteItemListO.html(""); // 清空
-}
-
-// 清空所有, 在转换notebook时使用
-Note.clearAll = function() {
- // 当前的笔记清空掉
- Note.curNoteId = "";
-
- Note.clearNoteInfo();
- Note.clearNoteList();
-}
-
-// render到编辑器
-// render note
-Note.renderNote = function(note) {
- if(!note) {
- return;
- }
- // title
- $("#noteTitle").val(note.Title);
-
- // 当前正在编辑的
- // tags
- Tag.renderTags(note.Tags);
-}
-
-// render content
-Note.renderNoteContent = function(content) {
- setEditorContent(content.Content, content.IsMarkdown, content.Preview);
- // 只有在renderNoteContent时才设置curNoteId
- Note.curNoteId = content.NoteId;
-}
-
-// 初始化时渲染最初的notes
-/**
-
-
-*/
-
-Note.showEditorMask = function() {
- $("#editorMask").css("z-index", 10).show();
- // 要判断是否是垃圾筒
- if(Notebook.curNotebookIsTrashOrAll()) {
- $("#editorMaskBtns").hide();
- $("#editorMaskBtnsEmpty").show();
- } else {
- $("#editorMaskBtns").show();
- $("#editorMaskBtnsEmpty").hide();
- }
-}
-Note.hideEditorMask = function() {
- $("#editorMask").css("z-index", -10).hide();
-}
-
-// 这里如果notes过多>100个将会很慢!!, 使用setTimeout来分解
-Note.renderNotesC = 0;
-Note.renderNotes = function(notes, forNewNote, isShared) {
- var renderNotesC = ++Note.renderNotesC;
-
- // 手机端不用
- // slimScroll使得手机端滚动不流畅
- if(!LEA.isMobile && !Mobile.isMobile()) {
- $("#noteItemList").slimScroll({ scrollTo: '0px', height: "100%", onlyScrollBar: true});
- }
-
- if(!notes || typeof notes != "object" || notes.length <= 0) {
- // 如果没有, 那么是不是应该hide editor?
- if(!forNewNote) {
- Note.showEditorMask();
- }
- return;
- }
- Note.hideEditorMask();
- // 新建笔记时会先创建一个新笔记, 所以不能清空
- if(forNewNote == undefined) {
- forNewNote = false;
- }
- if(!forNewNote) {
- Note.noteItemListO.html(""); // 清空
- }
-
- // 20个一次
- var len = notes.length;
- var c = Math.ceil(len/20);
-
- Note._renderNotes(notes, forNewNote, isShared, 1);
-
- // 先设置缓存
- for(var i = 0; i < len; ++i) {
- var note = notes[i];
- // 不清空
- // 之前是addNoteCache, 如果是搜索出的, 会把内容都重置了
- Note.setNoteCache(note, false);
-
- // 如果是共享的笔记本, 缓存也放在Share下
- if(isShared) {
- Share.setCache(note);
- }
- }
-
- for(var i = 1; i < c; ++i) {
- setTimeout(
- (function(i) {
- // 防止还没渲染完就点击另一个notebook了
- return function() {
- if(renderNotesC == Note.renderNotesC) {
- Note._renderNotes(notes, forNewNote, isShared, i+1);
- }
- }
- })(i), i*2000);
- }
-}
-Note._renderNotes = function(notes, forNewNote, isShared, tang) { // 第几趟
- var baseClasses = "item-my";
- if(isShared) {
- baseClasses = "item-shared";
- }
-
- var len = notes.length;
- for(var i = (tang-1)*20; i < len && i < tang*20; ++i) {
- var classes = baseClasses;
- if(!forNewNote && i == 0) {
- classes += " item-active";
- }
- var note = notes[i];
- var tmp;
- 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);
- }
- if(!note.IsBlog) {
- tmp = $(tmp);
- tmp.find(".item-blog").hide();
- }
- Note.noteItemListO.append(tmp);
-
- /*
- // 共享的note也放在Note的cache一份
- if(isShared) {
- note.IsShared = true; // 注明是共享的
- }
-
- // 不清空
- // 之前是addNoteCache, 如果是搜索出的, 会把内容都重置了
- Note.setNoteCache(note, false);
-
- // 如果是共享的笔记本, 缓存也放在Share下
- if(isShared) {
- Share.setCache(note);
- }
- */
- }
-}
-
-// 新建一个笔记
-// 要切换到当前的notebook下去新建笔记
-// isShare时fromUserId才有用
-// 3.8 add isMarkdown
-Note.newNote = function(notebookId, isShare, fromUserId, isMarkdown) {
- // 切换编辑器
- switchEditor(isMarkdown);
- Note.hideEditorMask();
-
- // 防止从共享read only跳到添加
- Note.hideReadOnly();
-
- Note.stopInterval();
- // 保存当前的笔记
- Note.curChangedSaveIt();
-
- var note = {NoteId: getObjectId(), Title: "", Tags:[], Content:"", NotebookId: notebookId, IsNew: true, FromUserId: fromUserId, IsMarkdown: isMarkdown}; // 是新的
- // 添加到缓存中
- Note.addNoteCache(note);
-
- // 清空附件数
- Attach.clearNoteAttachNum();
-
- // 是否是为共享的notebook添加笔记, 如果是, 则还要记录fromUserId
- var newItem = "";
-
- var baseClasses = "item-my";
- if(isShare) {
- baseClasses = "item-shared";
- }
-
- var notebook = Notebook.getNotebook(notebookId);
- var notebookTitle = notebook ? notebook.Title : "";
- var curDate = getCurDate();
- if(isShare) {
- newItem = tt(Note.newItemTpl, baseClasses, fromUserId, note.NoteId, note.Title, notebookTitle, curDate, "");
- } else {
- newItem = tt(Note.newItemTpl, baseClasses, "", note.NoteId, note.Title, notebookTitle, curDate, "");
- }
-
- // notebook是否是Blog
- if(!notebook.IsBlog) {
- newItem = $(newItem);
- newItem.find(".item-blog").hide();
- }
-
- // 是否在当前notebook下, 不是则切换过去, 并得到该notebook下所有的notes, 追加到后面!
- if(!Notebook.isCurNotebook(notebookId)) {
- // 先清空所有
- Note.clearAll();
-
- // 插入到第一个位置
- Note.noteItemListO.prepend(newItem);
-
- // 改变为当前的notebookId
- // 会得到该notebookId的其它笔记
- if(!isShare) {
- Notebook.changeNotebookForNewNote(notebookId);
- } else {
- Share.changeNotebookForNewNote(notebookId);
- }
- } else {
- // 插入到第一个位置
- Note.noteItemListO.prepend(newItem);
- }
-
- Note.selectTarget($(tt('[noteId="?"]', note.NoteId)));
-
- $("#noteTitle").focus();
-
- Note.renderNote(note);
- Note.renderNoteContent(note);
- Note.curNoteId = note.NoteId;
-
- // 更新数量
- Notebook.incrNotebookNumberNotes(notebookId)
-}
-
-// 保存note ctrl + s
-Note.saveNote = function(e) {
- var num = e.which ? e.which : e.keyCode;
- // 保存
- if((e.ctrlKey || e.metaKey) && num == 83 ) { // ctrl + s or command + s
- Note.curChangedSaveIt();
- e.preventDefault();
- return false;
- } else {
- }
-};
-
-// 删除或移动笔记后, 渲染下一个或上一个
-Note.changeToNext = function(target) {
- var $target = $(target);
- var next = $target.next();
- if(!next.length) {
- var prev = $target.prev();
- if(prev.length) {
- next = prev;
- } else {
- // 就它一个
- Note.showEditorMask();
- return;
- }
- }
-
- Note.changeNote(next.attr("noteId"));
-}
-
-// 删除笔记
-// 1. 先隐藏, 成功后再移除DOM
-// 2. ajax之 noteId
-// Share.deleteSharedNote调用
-Note.deleteNote = function(target, contextmenuItem, isShared) {
- // 如果删除的是已选中的, 赶紧设置curNoteId = null
- if($(target).hasClass("item-active")) {
- // -1 停止定时器
- Note.stopInterval();
- // 不保存
- Note.curNoteId = null;
- // 清空信息
- Note.clearNoteInfo();
- }
-
- noteId = $(target).attr("noteId");
- if(!noteId) {
- return;
- }
- // 1
- $(target).hide();
-
- // 2
- var note = Note.cache[noteId];
- 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) {
- if(ret) {
- Note.changeToNext(target);
-
- $(target).remove();
-
- // 删除缓存
- if(note) {
- Note.clearCacheByNotebookId(note.NotebookId)
- delete Note.cache[noteId]
- }
-
- showMsg("删除成功!", 500);
- } else {
- // 弹出信息 popup 不用点确认的
- $(target).show();
- showMsg("删除失败!", 2000);
- }
- });
-
-}
-
-// 显示共享信息
-Note.listNoteShareUserInfo = function(target) {
- var noteId = $(target).attr("noteId");
- showDialogRemote("share/listNoteShareUserInfo", {noteId: noteId});
-}
-
-// 共享笔记
-Note.shareNote = function(target) {
- var title = $(target).find(".item-title").text();
- showDialog("dialogShareNote", {title: getMsg("shareToFriends") + "-" + title});
-
- setTimeout(function() {
- $("#friendsEmail").focus();
- }, 500);
-
- var noteId = $(target).attr("noteId");
- shareNoteOrNotebook(noteId, true);
-}
-
-// 历史记录
-Note.listNoteContentHistories = function() {
- // 弹框
- $("#leanoteDialog #modalTitle").html(getMsg("history"));
- $content = $("#leanoteDialog .modal-body");
- $content.html("");
- $("#leanoteDialog .modal-footer").html('
' + getMsg("close") + ' ');
- options = {}
- options.show = true;
- $("#leanoteDialog").modal(options);
-
- ajaxGet("noteContentHistory/listHistories", {noteId: Note.curNoteId}, function(re) {
- if(!isArray(re)) {$content.html(getMsg("noHistories")); return}
- // 组装成一个tab
- var str = "
" + getMsg("historiesNum") + '
';
- note = Note.cache[Note.curNoteId];
- var s = "div"
- if(note.IsMarkdown) {
- s = "pre";
- }
- for (i in re) {
- var content = re[i]
- content.Ab = Note.genAbstract(content.Content, 200);
- str += tt('#? class="each-content">??> ' + getMsg("datetime") + ': ? ' + getMsg("unfold") + ' ' + getMsg('restoreFromThisVersion') + '
', i, (+i+1), s, content.Ab, s, goNowToDatetime(content.UpdatedTime))
- }
- str += "
";
- $content.html(str);
- $("#historyList .all").click(function() {
- $p = $(this).parent().parent();
- var seq = $p.attr("seq");
- var $c = $p.find(".each-content");
- var info = re[seq];
- if(!info.unfold) { // 默认是折叠的
- $(this).text(getMsg("fold")); // 折叠
- $c.html(info.Content);
- info.unfold = true;
- } else {
- $(this).text(getMsg("unfold")); // 展开
- $c.html(info.Ab);
- info.unfold = false
- }
- });
-
- // 还原
- $("#historyList .back").click(function() {
- $p = $(this).parent().parent();
- var seq = $p.attr("seq");
- if(confirm(getMsg("confirmBackup"))) {
- // 保存当前版本
- Note.curChangedSaveIt();
- // 设置之
- note = Note.cache[Note.curNoteId];
- setEditorContent(re[seq].Content, note.IsMarkdown);
- //
- hideDialog();
- }
- });
-
- });
-}
-
-// 长微博
-Note.html2Image = function(target) {
- var noteId = $(target).attr("noteId");
- 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 + "?" + ((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 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").html("对不起, 我们出错了!")
- }
- });
- }});
-}
-
-//--------------
-// read only
-
-Note.showReadOnly = function() {
- Note.isReadOnly = true;
- $("#noteRead").show();
-}
-Note.hideReadOnly = function() {
- Note.isReadOnly = false;
- $("#noteRead").hide();
-}
-// read only
-Note.renderNoteReadOnly = function(note) {
- Note.showReadOnly();
- $("#noteReadTitle").html(note.Title);
-
- Tag.renderReadOnlyTags(note.Tags);
-
- $("#noteReadCreatedTime").html(goNowToDatetime(note.CreatedTime));
- $("#noteReadUpdatedTime").html(goNowToDatetime(note.UpdatedTime));
-}
-Note.renderNoteContentReadOnly = function(note) {
- if(note.IsMarkdown) {
- $("#noteReadContent").html('
' + note.Content + " ");
- } else {
- $("#noteReadContent").html(note.Content);
- }
-}
-
-//---------------------------
-// 搜索
-// 有点小复杂, 因为速度过快会导致没加载完, 然后就保存上一个 => 致使标题没有
-// 为什么会标题没有?
-Note.lastSearch = null;
-Note.lastKey = null; // 判断是否与上一个相等, 相等就不查询, 如果是等了很久再按enter?
-Note.lastSearchTime = new Date();
-Note.isOver2Seconds = false;
-Note.isSameSearch = function(key) {
- // 判断时间是否超过了1秒, 超过了就认为是不同的
- var now = new Date();
- var duration = now.getTime() - Note.lastSearchTime.getTime();
- Note.isOver2Seconds = duration > 2000 ? true : false;
- if(!Note.lastKey || Note.lastKey != key || duration > 1000) {
- Note.lastKey = key;
- Note.lastSearchTime = now;
- return false;
- }
-
- if(key == Note.lastKey) {
- return true;
- }
-
- Note.lastSearchTime = now;
- Note.lastKey = key;
- return false;
-}
-
-Note.searchNote = function() {
- var val = $("#searchNoteInput").val();
- if(!val) {
- // 定位到all
- Notebook.changeNotebook("0");
- return;
- }
- // 判断是否与上一个是相同的搜索, 是则不搜索
- if(Note.isSameSearch(val)) {
- return;
- }
-
- // 之前有, 还有结束的
- if(Note.lastSearch) {
- Note.lastSearch.abort();
- }
-
- // 步骤与tag的搜索一样
- // 1
- Note.curChangedSaveIt();
-
- // 2 先清空所有
- Note.clearAll();
-
- // 发送请求之
- // 先取消上一个
- showLoading();
- Note.lastSearch = $.post("/note/searchNote", {key: val}, function(notes) {
- hideLoading();
- if(notes) {
- // 成功后设为空
- Note.lastSearch = null;
- // renderNotes只是note列表加载, 右侧笔记详情还没加载
- // 这个时候, 定位第一个, 保存之前的,
- // 如果: 第一次搜索, renderNotes OK, 还没等到changeNote时
- // 第二次搜索来到, Note.curChangedSaveIt();
- // 导致没有标题了
- // 不是这个原因, 下面的Note.changeNote会导致保存
-
- // 设空, 防止发生上述情况
- // Note.curNoteId = "";
-
- Note.renderNotes(notes);
- if(!isEmpty(notes)) {
- Note.changeNote(notes[0].NoteId, false/*, true || Note.isOver2Seconds*/); // isShare, needSaveChanged?, 超过2秒就要保存
- }
- } else {
- // abort的
- }
- });
- // Note.lastSearch.abort();
-}
-
-//----------
-//设为blog/unset
-Note.setNote2Blog = function(target) {
- var noteId = $(target).attr("noteId");
- var note = Note.cache[noteId];
- var isBlog = true;
- if(note.IsBlog != undefined) {
- isBlog = !note.IsBlog;
- }
- // 标志添加/去掉
- if(isBlog) {
- $(target).find(".item-blog").show();
- } else {
- $(target).find(".item-blog").hide();
- }
- ajaxPost("/blog/setNote2Blog", {noteId: noteId, isBlog: isBlog}, function(ret) {
- if(ret) {
- Note.setNoteCache({NoteId: noteId, IsBlog: isBlog}, false); // 不清空NotesByNotebookId缓存
- }
- });
-}
-
-// 设置notebook的blog状态
-// 当修改notebook是否是blog时调用
-Note.setAllNoteBlogStatus = function(notebookId, isBlog) {
- if(!notebookId) {
- return;
- }
- var notes = Note.getNotesByNotebookId(notebookId);
- if(!isArray(notes)) {
- return;
- }
- var len = notes.length;
- if(len == 0) {
- for(var i in Note.cache) {
- if(Note.cache[i].NotebookId == notebookId) {
- Note.cache[i].IsBlog = isBlog;
- }
- }
- } else {
- for(var i = 0; i < len; ++i) {
- notes[i].IsBlog = isBlog;
- }
- }
-}
-
-// 移动
-Note.moveNote = function(target, data) {
- var noteId = $(target).attr("noteId");
- var note = Note.cache[noteId];
- var notebookId = data.notebookId;
-
- 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) {
- Note.changeToNext(target);
- $(target).remove();
- Note.clearCacheByNotebookId(notebookId);
- } else {
- // 不是trash, 移动, 那么判断是当前是否是all下
- // 不在all下, 就删除之
- // 如果当前是active, 那么clearNoteInfo之
- if(!Notebook.curActiveNotebookIsAll()) {
- Note.changeToNext(target);
- if($(target).hasClass("item-active")) {
- Note.clearNoteInfo();
- }
- $(target).remove();
- } else {
- // 不移动, 那么要改变其notebook title
- $(target).find(".note-notebook").html(Notebook.getNotebookTitle(notebookId));
- }
-
- // 重新清空cache 之前的和之后的
- Note.clearCacheByNotebookId(note.NotebookId);
- Note.clearCacheByNotebookId(notebookId);
- }
-
- // 改变缓存
- Note.setNoteCache(ret)
- }
- });
-}
-
-// 复制
-// data是自动传来的, 是contextmenu数据
-Note.copyNote = function(target, data, isShared) {
- var noteId = $(target).attr("noteId");
- var note = Note.cache[noteId];
- var notebookId = data.notebookId;
-
- // trash不能复制, 不能复制给自己
- if(note.IsTrash || note.NotebookId == notebookId) {
- return;
- }
-
- var url = "/note/copyNote";
- var data = {noteId: noteId, notebookId: notebookId};
- if(isShared) {
- url = "/note/copySharedNote";
- data.fromUserId = note.UserId;
- }
-
- ajaxGet(url, data, function(ret) {
- if(ret && ret.NoteId) {
- // 重新清空cache 之后的
- Note.clearCacheByNotebookId(notebookId);
- // 改变缓存, 添加之
- Note.setNoteCache(ret)
- }
- });
-
- // 增加数量
- Notebook.incrNotebookNumberNotes(notebookId)
-}
-
-// 这里速度不慢, 很快
-Note.getContextNotebooks = function(notebooks) {
- var moves = [];
- var copys = [];
- var copys2 = [];
- for(var i in notebooks) {
- var notebook = notebooks[i];
- var move = {text: notebook.Title, notebookId: notebook.NotebookId, action: Note.moveNote}
- var copy = {text: notebook.Title, notebookId: notebook.NotebookId, action: Note.copyNote}
- var copy2 = {text: notebook.Title, notebookId: notebook.NotebookId, action: Share.copySharedNote}
- if(!isEmpty(notebook.Subs)) {
- var mc = Note.getContextNotebooks(notebook.Subs);
- move.items = mc[0];
- copy.items = mc[1];
- copy2.items = mc[2];
- move.type = "group";
- move.width = 150;
- copy.type = "group";
- copy.width = 150;
- copy2.type = "group";
- copy2.width = 150;
- }
- moves.push(move);
- copys.push(copy);
- copys2.push(copy2);
- }
- return [moves, copys, copys2];
-}
-// Notebook调用
-Note.contextmenu = null;
-Note.notebooksCopy = []; // share会用到
-Note.initContextmenu = function() {
- var self = Note;
- if(Note.contextmenu) {
- Note.contextmenu.destroy();
- }
- // 得到可移动的notebook
- var notebooks = Notebook.everNotebooks;
- var mc = self.getContextNotebooks(notebooks);
-
- var notebooksMove = mc[0];
- var notebooksCopy = mc[1];
- self.notebooksCopy = mc[2];
-
- //---------------------
- // context menu
- //---------------------
- var noteListMenu = {
- width: 180,
- items: [
- { text: getMsg("shareToFriends"), alias: 'shareToFriends', icon: "", faIcon: "fa-share-square-o", action: Note.listNoteShareUserInfo},
- { type: "splitLine" },
- { 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: getMsg("delete"), icon: "", faIcon: "fa-trash-o", action: Note.deleteNote },
- { text: getMsg("move"), alias: "move", faIcon: "fa-arrow-right",
- type: "group",
- width: 180,
- items: notebooksMove
- },
- { text: getMsg("copy"), alias: "copy", icon:"", faIcon: "fa-copy",
- type: "group",
- width: 180,
- items: notebooksCopy
- }
- ],
- onShow: applyrule,
- onContextMenu: beforeContextMenu,
-
- parent: "#noteItemList",
- children: ".item-my",
- }
-
- function menuAction(target) {
- // $('#myModal').modal('show')
- showDialog("dialogUpdateNotebook", {title: "修改笔记本", postShow: function() {
- }});
- }
- function applyrule(menu) {
- var noteId = $(this).attr("noteId");
- var note = Note.cache[noteId];
- if(!note) {
- return;
- }
- // 要disable的items
- var items = [];
-
- // 如果是trash, 什么都不能做
- if(note.IsTrash) {
- items.push("shareToFriends");
- items.push("shareStatus");
- items.push("unset2Blog");
- items.push("set2Blog");
- items.push("copy");
- } else {
- // 是否已公开为blog
- if(!note.IsBlog) {
- items.push("unset2Blog");
- } else {
- items.push("set2Blog");
- }
-
- // 移动与复制不能是本notebook下
- var notebookTitle = Notebook.getNotebookTitle(note.NotebookId);
- items.push("move." + notebookTitle);
- items.push("copy." + notebookTitle);
- }
-
- menu.applyrule({
- name: "target..",
- disable: true,
- items: items
- });
-
- }
- function beforeContextMenu() {
- return this.id != "target3";
- }
-
- // 这里很慢!!
- Note.contextmenu = $("#noteItemList .item-my").contextmenu(noteListMenu);
-}
-
-// 附件
-// 笔记的附件需要ajax获取
-// 建一张附件表? attachId, noteId, 其它信息
-// note里有attach_nums字段记录个数
-// [ok]
-var Attach = {
- loadedNoteAttachs: {}, // noteId => [attch1Info, attach2Info...] // 按笔记
- attachsMap: {}, // attachId => attachInfo
- init: function() {
- var self = this;
- // 显示attachs
- $("#showAttach").click(function(){
- self.renderAttachs(Note.curNoteId);
- });
- // 防止点击隐藏
- self.attachListO.click(function(e) {
- e.stopPropagation();
- });
- // 删除
- self.attachListO.on("click", ".delete-attach", function(e) {
- e.stopPropagation();
- var attachId = $(this).closest('li').data("id");
- var t = this;
- if(confirm("Are you sure to delete it ?")) {
- $(t).button("loading");
- ajaxPost("/attach/deleteAttach", {attachId: attachId}, function(re) {
- $(t).button("reset");
- if(reIsOk(re)) {
- self.deleteAttach(attachId);
- } else {
- alert(re.Msg);
- }
- });
- }
- });
- // 下载
- self.attachListO.on("click", ".download-attach", function(e) {
- e.stopPropagation();
- var attachId = $(this).closest('li').data("id");
- window.open(UrlPrefix + "/attach/download?attachId=" + attachId);
- // location.href = "/attach/download?attachId=" + attachId;
- });
- // 下载全部
- self.downloadAllBtnO.click(function() {
- window.open(UrlPrefix + "/attach/downloadAll?noteId=" + Note.curNoteId);
- // location.href = "/attach/downloadAll?noteId=" + Note.curNoteId;
- });
-
- // make link
- self.attachListO.on("click", ".link-attach", function(e) {
- e.stopPropagation();
- var attachId = $(this).closest('li').data("id");
- var attach = self.attachsMap[attachId];
- var src = UrlPrefix + "/attach/download?attachId=" + attachId;
- if(LEA.isMarkdownEditor() && MarkdownEditor) {
- MarkdownEditor.insertLink(src, attach.Title);
- } else {
- tinymce.activeEditor.insertContent('
' + attach.Title + ' ');
- }
- });
-
- // make all link
- self.linkAllBtnO.on("click",function(e) {
- e.stopPropagation();
- var note = Note.getCurNote();
- if(!note) {
- return;
- }
- var src = UrlPrefix + "/attach/downloadAll?noteId=" + Note.curNoteId
- var title = note.Title ? note.Title + ".tar.gz" : "all.tar.gz";
-
- if(LEA.isMarkdownEditor() && MarkdownEditor) {
- MarkdownEditor.insertLink(src, title);
- } else {
- tinymce.activeEditor.insertContent('
' + title + ' ');
- }
- });
- },
- attachListO: $("#attachList"),
- attachNumO: $("#attachNum"),
- attachDropdownO: $("#attachDropdown"),
- downloadAllBtnO: $("#downloadAllBtn"),
- linkAllBtnO: $("#linkAllBtn"),
- // 添加笔记时
- clearNoteAttachNum: function() {
- var self = this;
- self.attachNumO.html("").hide();
- },
- renderNoteAttachNum: function(noteId, needHide) {
- var self = this;
- var note = Note.getNote(noteId);
- if(note.AttachNum) {
- self.attachNumO.html("(" + note.AttachNum + ")").show();
- self.downloadAllBtnO.show();
- self.linkAllBtnO.show();
- } else {
- self.attachNumO.hide();
- self.downloadAllBtnO.hide();
- self.linkAllBtnO.hide();
- }
-
- // 隐藏掉
- if(needHide) {
- self.attachDropdownO.removeClass("open");
- }
- },
- _renderAttachs: function(attachs) {
- var self = this;
- // foreach 循环之
- /*
-
- leanote官abcefedafadfadfadfadfad方文档.doc
-
- Delete
- Download
-
-
- */
- var html = "";
- var attachNum = attachs.length;
- for(var i = 0; i < attachNum; ++i) {
- var each = attachs[i];
- html += '
' +
- '' + each.Title + '
' +
- ' ' +
- ' ' +
- ' ' +
- ' ' +
- '
' +
- ' ';
- self.attachsMap[each.AttachId] = each;
- }
- self.attachListO.html(html);
-
- // 设置数量
- var note = Note.getCurNote();
- if(note) {
- note.AttachNum = attachNum;
- self.renderNoteAttachNum(note.NoteId, false);
- }
- },
- // 渲染noteId的附件
- // 当点击"附件"时加载,
- // TODO 判断是否已loaded
- renderAttachs: function(noteId) {
- var self = this;
- if(self.loadedNoteAttachs[noteId]) {
- self._renderAttachs(self.loadedNoteAttachs[noteId]);
- return;
- }
- // 显示loading
- self.attachListO.html('
');
- // ajax获取noteAttachs
- ajaxGet("/attach/getAttachs", {noteId: noteId}, function(ret) {
- var list = [];
- if(ret.Ok) {
- list = ret.List;
- if(!list) {
- list = [];
- }
- }
- // 添加到缓存中
- self.loadedNoteAttachs[noteId] = list;
- self._renderAttachs(list);
- });
- },
- // 添加附件, attachment_upload上传调用
- addAttach: function(attachInfo) {
- var self = this;
- if(!self.loadedNoteAttachs[attachInfo.NoteId]) {
- self.loadedNoteAttachs[attachInfo.NoteId] = [];
- }
- self.loadedNoteAttachs[attachInfo.NoteId].push(attachInfo);
- self.renderAttachs(attachInfo.NoteId);
- },
- // 删除
- deleteAttach: function(attachId) {
- var self = this;
- var noteId = Note.curNoteId;
- var attachs = self.loadedNoteAttachs[noteId];
- for(var i = 0; i < attachs.length; ++i) {
- if(attachs[i].AttachId == attachId) {
- // 删除之, 并render之
- attachs.splice(i, 1);
- break;
- }
- }
- // self.loadedNoteAttachs[noteId] = attachs;
- self.renderAttachs(noteId);
- },
-
- // 下载
- downloadAttach: function(fileId) {
- var self = this;
- },
- downloadAll: function() {
- }
-}
-
-//------------------- 事件
-$(function() {
- // 附件初始化
- Attach.init();
-
- //-----------------
- // for list nav
- $("#noteItemList").on("click", ".item", function(event) {
- log(event);
- event.stopPropagation();
- var noteId = $(this).attr("noteId");
-
- // 手机端处理
- Mobile.changeNote(noteId);
-
- if(!noteId) {
- return;
- }
- // 当前的和所选的是一个, 不改变
- if(Note.curNoteId != noteId) {
- Note.changeNote(noteId);
- }
- });
-
- //------------------
- // 新建笔记
- // 1. 直接点击新建 OR
- // 2. 点击nav for new note
- $("#newNoteBtn, #editorMask .note").click(function() {
- var notebookId = $("#curNotebookForNewNote").attr('notebookId');
- Note.newNote(notebookId);
- });
- $("#newNoteMarkdownBtn, #editorMask .markdown").click(function() {
- var notebookId = $("#curNotebookForNewNote").attr('notebookId');
- Note.newNote(notebookId, false, "", true);
- });
- $("#notebookNavForNewNote").on("click", "li div", function() {
- var notebookId = $(this).attr("notebookId");
- if($(this).hasClass("new-note-right")) {
- Note.newNote(notebookId, false, "", true);
- } else {
- Note.newNote(notebookId);
- }
- });
- $("#searchNotebookForAdd").click(function(e) {
- e.stopPropagation();
- });
- $("#searchNotebookForAdd").keyup(function() {
- var key = $(this).val();
- Notebook.searchNotebookForAddNote(key);
- });
- $("#searchNotebookForList").keyup(function() {
- var key = $(this).val();
- Notebook.searchNotebookForList(key);
- });
-
- //---------------------------
- // 搜索, 按enter才搜索
- /*
- $("#searchNoteInput").on("keyup", function(e) {
- Note.searchNote();
- });
- */
- $("#searchNoteInput").on("keydown", function(e) {
- var theEvent = e; // window.event || arguments.callee.caller.arguments[0];
- if(theEvent.keyCode == 13 || theEvent.keyCode == 108) {
- theEvent.preventDefault();
- Note.searchNote();
- return false;
- }
- });
-
- //--------------------
- // Note.initContextmenu();
-
- //------------
- // 文档历史
- $("#contentHistory").click(function() {
- Note.listNoteContentHistories()
- });
-
- $("#saveBtn").click(function() {
- Note.curChangedSaveIt(true);
- });
-
- // blog
- $("#noteItemList").on("click", ".item-blog", function(e) {
- e.preventDefault();
- e.stopPropagation();
- // 得到ID
- var noteId = $(this).parent().attr('noteId');
- window.open("/blog/view/" + noteId);
- });
-
- // note setting
- $("#noteItemList").on("click", ".item-my .item-setting", function(e) {
- e.preventDefault();
- e.stopPropagation();
- var $p = $(this).parent();
- Note.contextmenu.showMenu(e, $p);
- });
-});
-
-// 定时器启动
-Note.startInterval();
\ No newline at end of file
diff --git a/public/js/app/notebook-min.js b/public/js/app/notebook-min.js
deleted file mode 100644
index 24c8b43..0000000
--- a/public/js/app/notebook-min.js
+++ /dev/null
@@ -1 +0,0 @@
-Notebook.curNotebookId="";Notebook.cache={};Notebook.notebooks=[];Notebook.notebookNavForListNote="";Notebook.notebookNavForNewNote="";Notebook.setCache=function(notebook){var notebookId=notebook.NotebookId;if(!notebookId){return}if(!Notebook.cache[notebookId]){Notebook.cache[notebookId]={}}$.extend(Notebook.cache[notebookId],notebook)};Notebook.getCurNotebookId=function(){return Notebook.curNotebookId};Notebook._updateNotebookNumberNotes=function(notebookId,n){var self=this;var notebook=self.getNotebook(notebookId);if(!notebook){return}notebook.NumberNotes+=n;if(notebook.NumberNotes<0){notebook.NumberNotes=0}$("#numberNotes_"+notebookId).html(notebook.NumberNotes)};Notebook.incrNotebookNumberNotes=function(notebookId){var self=this;self._updateNotebookNumberNotes(notebookId,1)};Notebook.minusNotebookNumberNotes=function(notebookId){var self=this;self._updateNotebookNumberNotes(notebookId,-1)};Notebook.getNotebook=function(notebookId){return Notebook.cache[notebookId]};Notebook.getNotebookTitle=function(notebookId){var notebook=Notebook.cache[notebookId];if(notebook){return notebook.Title}else{return"未知"}};Notebook.getTreeSetting=function(isSearch,isShare){var noSearch=!isSearch;var self=this;function addDiyDom(treeId,treeNode){var spaceWidth=5;var switchObj=$("#"+treeId+" #"+treeNode.tId+"_switch"),icoObj=$("#"+treeId+" #"+treeNode.tId+"_ico");switchObj.remove();icoObj.before(switchObj);if(!isShare){if(!Notebook.isAllNotebookId(treeNode.NotebookId)&&!Notebook.isTrashNotebookId(treeNode.NotebookId)){icoObj.after($('
'+(treeNode.NumberNotes||0)+" "));icoObj.after($('
'))}}else{if(!Share.isDefaultNotebookId(treeNode.NotebookId)){icoObj.after($('
'))}}if(treeNode.level>1){var spaceStr="
";switchObj.before(spaceStr)}}function beforeDrag(treeId,treeNodes){for(var i=0,l=treeNodes.length;i
?
M
',classes,notebook.NotebookId,notebook.Title,notebook.NotebookId);if(!isEmpty(notebook.Subs)){eachForNew+=""}eachForNew+="";navForNewNote+=eachForNew}return navForNewNote};Notebook.everNavForNewNote="";Notebook.everNotebooks=[];Notebook.changeNav=function(){var self=Notebook;var notebooks=Notebook.tree.getNodes();var pureNotebooks=notebooks.slice(1,-1);var html=self.getChangedNotebooks(pureNotebooks);self.everNavForNewNote=html;self.everNotebooks=pureNotebooks;$("#notebookNavForNewNote").html(html);var t1=(new Date).getTime();Note.initContextmenu();Share.initContextmenu(Note.notebooksCopy);var t2=(new Date).getTime();log(t2-t1)};Notebook.renderShareNotebooks=function(sharedUserInfos,shareNotebooks){if(isEmpty(sharedUserInfos)){return}if(!shareNotebooks||typeof shareNotebooks!="object"||shareNotebooks.length<0){return}var $shareNotebooks=$("#shareNotebooks");var user2ShareNotebooks={};for(var i in shareNotebooks){var userNotebooks=shareNotebooks[i];user2ShareNotebooks[userNotebooks.UserId]=userNotebooks}for(var i in sharedUserInfos){var userInfo=sharedUserInfos[i];var userNotebooks=user2ShareNotebooks[userInfo.UserId]||{ShareNotebooks:[]};userNotebooks.ShareNotebooks=[{NotebookId:"-2",Title:"默认共享"}].concat(userNotebooks.ShareNotebooks);var username=userInfo.Username||userInfo.Email;var header=tt('',username,username);var body='
';for(var j in userNotebooks.ShareNotebooks){var notebook=userNotebooks.ShareNotebooks[j];body+=tt('? ',notebook.NotebookId,notebook.Title)}body+=" ";$shareNotebooks.append(header+body+"
")}};Notebook.selectNotebook=function(target){$(".notebook-item").removeClass("curSelectedNode");$(target).addClass("curSelectedNode")};Notebook.changeNotebookNavForNewNote=function(notebookId,title){if(!notebookId){var notebook=Notebook.notebooks[0];notebookId=notebook.NotebookId;title=notebook.Title}if(!title){var notebook=Notebook.cache[0];title=notebook.Title}if(!Notebook.isAllNotebookId(notebookId)&&!Notebook.isTrashNotebookId(notebookId)){$("#curNotebookForNewNote").html(title).attr("notebookId",notebookId)}else if(!$("#curNotebookForNewNote").attr("notebookId")){if(Notebook.notebooks.length>2){var notebook=Notebook.notebooks[1];notebookId=notebook.NotebookId;title=notebook.Title;Notebook.changeNotebookNavForNewNote(notebookId,title)}}};Notebook.toggleToMyNav=function(userId,notebookId){$("#sharedNotebookNavForListNav").hide();$("#myNotebookNavForListNav").show();$("#newMyNote").show();$("#newSharedNote").hide();$("#tagSearch").hide()};Notebook.changeNotebookNav=function(notebookId){Notebook.toggleToMyNav();Notebook.selectNotebook($(tt('#notebookList [notebookId="?"]',notebookId)));var notebook=Notebook.cache[notebookId];if(!notebook){return}$("#curNotebookForListNote").html(notebook.Title);Notebook.changeNotebookNavForNewNote(notebookId,notebook.Title)};Notebook.isAllNotebookId=function(notebookId){return notebookId==Notebook.allNotebookId};Notebook.isTrashNotebookId=function(notebookId){return notebookId==Notebook.trashNotebookId};Notebook.curActiveNotebookIsAll=function(){return Notebook.isAllNotebookId($("#notebookList .active").attr("notebookId"))};Notebook.changeNotebook=function(notebookId){Notebook.changeNotebookNav(notebookId);Notebook.curNotebookId=notebookId;Note.curChangedSaveIt();Note.clearAll();var url="/note/ListNotes/";var param={notebookId:notebookId};if(Notebook.isTrashNotebookId(notebookId)){url="/note/listTrashNotes";param={}}else if(Notebook.isAllNotebookId(notebookId)){param={};cacheNotes=Note.getNotesByNotebookId();if(!isEmpty(cacheNotes)){Note.renderNotesAndFirstOneContent(cacheNotes);return}}else{cacheNotes=Note.getNotesByNotebookId(notebookId);if(!isEmpty(cacheNotes)){Note.renderNotesAndFirstOneContent(cacheNotes);return}}ajaxGet(url,param,Note.renderNotesAndFirstOneContent)};Notebook.isCurNotebook=function(notebookId){return $(tt('#notebookList [notebookId="?"], #shareNotebooks [notebookId="?"]',notebookId,notebookId)).attr("class")=="active"};Notebook.changeNotebookForNewNote=function(notebookId){if(Notebook.isTrashNotebookId(notebookId)||Notebook.isAllNotebookId(notebookId)){return}Notebook.changeNotebookNav(notebookId);Notebook.curNotebookId=notebookId;var url="/note/ListNotes/";var param={notebookId:notebookId};ajaxGet(url,param,function(ret){Note.renderNotes(ret,true)})};Notebook.listNotebookShareUserInfo=function(target){var notebookId=$(target).attr("notebookId");showDialogRemote("share/listNotebookShareUserInfo",{notebookId:notebookId})};Notebook.shareNotebooks=function(target){var title=$(target).text();showDialog("dialogShareNote",{title:"分享笔记本给好友-"+title});setTimeout(function(){$("#friendsEmail").focus()},500);var notebookId=$(target).attr("notebookId");shareNoteOrNotebook(notebookId,false)};Notebook.setNotebook2Blog=function(target){var notebookId=$(target).attr("notebookId");var notebook=Notebook.cache[notebookId];var isBlog=true;if(notebook.IsBlog!=undefined){isBlog=!notebook.IsBlog}if(Notebook.curNotebookId==notebookId){if(isBlog){$("#noteList .item-blog").show()}else{$("#noteList .item-blog").hide()}}else if(Notebook.curNotebookId==Notebook.allNotebookId){$("#noteItemList .item").each(function(){var noteId=$(this).attr("noteId");var note=Note.cache[noteId];if(note.NotebookId==notebookId){if(isBlog)$(this).find(".item-blog").show();else $(this).find(".item-blog").hide()}})}ajaxPost("blog/setNotebook2Blog",{notebookId:notebookId,isBlog:isBlog},function(ret){if(ret){Note.setAllNoteBlogStatus(notebookId,isBlog);Notebook.setCache({NotebookId:notebookId,IsBlog:isBlog})}})};Notebook.updateNotebookTitle=function(target){var self=Notebook;var notebookId=$(target).attr("notebookId");if(self.tree2){self.tree2.editName(self.tree2.getNodeByTId(notebookId))}else{self.tree.editName(self.tree.getNodeByTId(notebookId))}};Notebook.doUpdateNotebookTitle=function(notebookId,newTitle){var self=Notebook;ajaxPost("/notebook/updateNotebookTitle",{notebookId:notebookId,title:newTitle},function(ret){Notebook.cache[notebookId].Title=newTitle;Notebook.changeNav();if(self.tree2){var notebook=self.tree.getNodeByTId(notebookId);notebook.Title=newTitle;self.tree.updateNode(notebook)}})};Notebook.addNotebookSeq=1;Notebook.addNotebook=function(){var self=Notebook;if($("#myNotebooks").hasClass("closed")){$("#myNotebooks .folderHeader").trigger("click")}self.tree.addNodes(null,{Title:"",NotebookId:getObjectId(),IsNew:true},true,true)};Notebook.doAddNotebook=function(notebookId,title,parentNotebookId){var self=Notebook;ajaxPost("/notebook/addNotebook",{notebookId:notebookId,title:title,parentNotebookId:parentNotebookId},function(ret){if(ret.NotebookId){Notebook.cache[ret.NotebookId]=ret;var notebook=self.tree.getNodeByTId(notebookId);$.extend(notebook,ret);notebook.IsNew=false;Notebook.changeNotebook(notebookId);Notebook.changeNav()}})};Notebook.addChildNotebook=function(target){var self=Notebook;if($("#myNotebooks").hasClass("closed")){$("#myNotebooks .folderHeader").trigger("click")}var notebookId=$(target).attr("notebookId");self.tree.addNodes(self.tree.getNodeByTId(notebookId),{Title:"",NotebookId:getObjectId(),IsNew:true},false,true)};Notebook.deleteNotebook=function(target){var self=Notebook;var notebookId=$(target).attr("notebookId");if(!notebookId){return}ajaxGet("/notebook/deleteNotebook",{notebookId:notebookId},function(ret){if(ret.Ok){self.tree.removeNode(self.tree.getNodeByTId(notebookId));if(self.tree2){self.tree2.removeNode(self.tree2.getNodeByTId(notebookId))}delete Notebook.cache[notebookId];Notebook.changeNav()}else{alert(ret.Msg)}})};$(function(){$("#minNotebookList").on("click","li",function(){var notebookId=$(this).find("a").attr("notebookId");Notebook.changeNotebook(notebookId)});var notebookListMenu={width:180,items:[{text:getMsg("shareToFriends"),alias:"shareToFriends",icon:"",faIcon:"fa-share-square-o",action:Notebook.listNotebookShareUserInfo},{type:"splitLine"},{text:getMsg("publicAsBlog"),alias:"set2Blog",faIcon:"fa-bold",action:Notebook.setNotebook2Blog},{text:getMsg("cancelPublic"),alias:"unset2Blog",faIcon:"fa-undo",action:Notebook.setNotebook2Blog},{type:"splitLine"},{text:getMsg("addChildNotebook"),faIcon:"fa-sitemap",action:Notebook.addChildNotebook},{text:getMsg("rename"),faIcon:"fa-pencil",action:Notebook.updateNotebookTitle},{text:getMsg("delete"),icon:"",alias:"delete",faIcon:"fa-trash-o",action:Notebook.deleteNotebook}],onShow:applyrule,onContextMenu:beforeContextMenu,parent:"#notebookList ",children:"li a"};var notebookListMenu2={width:180,items:[{text:getMsg("shareToFriends"),alias:"shareToFriends",icon:"",faIcon:"fa-share-square-o",action:Notebook.listNotebookShareUserInfo},{type:"splitLine"},{text:getMsg("publicAsBlog"),alias:"set2Blog",faIcon:"fa-bold",action:Notebook.setNotebook2Blog},{text:getMsg("cancelPublic"),alias:"unset2Blog",faIcon:"fa-undo",action:Notebook.setNotebook2Blog},{type:"splitLine"},{text:getMsg("rename"),icon:"",action:Notebook.updateNotebookTitle},{text:getMsg("delete"),icon:"",alias:"delete",faIcon:"fa-trash-o",action:Notebook.deleteNotebook}],onShow:applyrule,onContextMenu:beforeContextMenu,parent:"#notebookListForSearch ",children:"li a"};function applyrule(menu){var notebookId=$(this).attr("notebookId");var notebook=Notebook.cache[notebookId];if(!notebook){return}var items=[];if(!notebook.IsBlog){items.push("unset2Blog")}else{items.push("set2Blog")}if(Note.notebookHasNotes(notebookId)){items.push("delete")}menu.applyrule({name:"target2",disable:true,items:items})}function beforeContextMenu(){var notebookId=$(this).attr("notebookId");return!Notebook.isTrashNotebookId(notebookId)&&!Notebook.isAllNotebookId(notebookId)}Notebook.contextmenu=$("#notebookList li a").contextmenu(notebookListMenu);Notebook.contextmenuSearch=$("#notebookListForSearch li a").contextmenu(notebookListMenu2);$("#addNotebookPlus").click(function(e){e.stopPropagation();Notebook.addNotebook()});$("#notebookList").on("click",".notebook-setting",function(e){e.preventDefault();e.stopPropagation();var $p=$(this).parent();Notebook.contextmenu.showMenu(e,$p)});$("#notebookListForSearch").on("click",".notebook-setting",function(e){e.preventDefault();e.stopPropagation();var $p=$(this).parent();Notebook.contextmenuSearch.showMenu(e,$p)})});
\ No newline at end of file
diff --git a/public/js/app/notebook.js b/public/js/app/notebook.js
deleted file mode 100644
index 36bd343..0000000
--- a/public/js/app/notebook.js
+++ /dev/null
@@ -1,888 +0,0 @@
-Notebook.curNotebookId = "";
-Notebook.cache = {}; // notebookId => {};
-Notebook.notebooks = []; // 按次序
-// CSS
-Notebook.notebookNavForListNote = ""; // html 为了note list上面和新建时的ul
-Notebook.notebookNavForNewNote = ""; // html 为了note list上面和新建时的ul
-
-// 设置缓存
-Notebook.setCache = function(notebook) {
- var notebookId = notebook.NotebookId;
- if(!notebookId) {
- return;
- }
- if(!Notebook.cache[notebookId]) {
- Notebook.cache[notebookId] = {};
- }
- $.extend(Notebook.cache[notebookId], notebook);
-}
-
-Notebook.getCurNotebookId = function() {
- return Notebook.curNotebookId;
-};
-
-// 笔记本的笔记数量更新
-Notebook._updateNotebookNumberNotes = function(notebookId, n) {
- var self = this;
- var notebook = self.getNotebook(notebookId);
- if(!notebook) {
- return;
- }
- notebook.NumberNotes += n;
- if(notebook.NumberNotes < 0) {
- notebook.NumberNotes = 0;
- }
- $("#numberNotes_" + notebookId).html(notebook.NumberNotes);
-};
-// addNote, copyNote, moveNote
-Notebook.incrNotebookNumberNotes = function(notebookId) {
- var self = this;
- self._updateNotebookNumberNotes(notebookId, 1);
-};
-// moteNote, deleteNote
-Notebook.minusNotebookNumberNotes = function(notebookId) {
- var self = this;
- self._updateNotebookNumberNotes(notebookId, -1);
-};
-
-// 得到notebook标题, 给note显示其notebook标题用
-// called by Note
-Notebook.getNotebook = function(notebookId) {
- return Notebook.cache[notebookId];
-}
-// called by Note
-Notebook.getNotebookTitle = function(notebookId) {
- var notebook = Notebook.cache[notebookId];
- if(notebook) {
- return notebook.Title;
- } else {
- return "未知";
- }
-}
-
-/**
- * 我的notebooks
-
- */
-
-Notebook.getTreeSetting = function(isSearch, isShare){
- var noSearch = !isSearch;
-
- var self = this;
- // 添加自定义dom
- function addDiyDom(treeId, treeNode) {
- var spaceWidth = 5;
- var switchObj = $("#" + treeId + " #" + treeNode.tId + "_switch"),
- icoObj = $("#" + treeId + " #" + treeNode.tId + "_ico");
- switchObj.remove();
- icoObj.before(switchObj);
- if(!isShare) {
- if(!Notebook.isAllNotebookId(treeNode.NotebookId) && !Notebook.isTrashNotebookId(treeNode.NotebookId)) {
- icoObj.after($('' + (treeNode.NumberNotes || 0) + ' '));
- icoObj.after($(' '));
- }
- } else {
- if(!Share.isDefaultNotebookId(treeNode.NotebookId)) {
- icoObj.after($(' '));
- }
- }
- if (treeNode.level > 1) {
- var spaceStr = " ";
- switchObj.before(spaceStr);
- }
- }
- // 拖拽
- function beforeDrag(treeId, treeNodes) {
- for (var i=0,l=treeNodes.length; i?
M
', classes, notebook.NotebookId, notebook.Title, notebook.NotebookId);
-
- if(!isEmpty(notebook.Subs)) {
- eachForNew += "";
- }
-
- eachForNew += '';
-
- navForNewNote += eachForNew;
- }
- return navForNewNote;
-}
-
-Notebook.everNavForNewNote = "";
-Notebook.everNotebooks = [];
-Notebook.changeNav = function() {
- var self = Notebook;
- var notebooks = Notebook.tree.getNodes();
- var pureNotebooks = notebooks.slice(1, -1); // 不含新和垃圾
- var html = self.getChangedNotebooks(pureNotebooks);
-
- self.everNavForNewNote = html;
- self.everNotebooks = pureNotebooks;
-
- $("#notebookNavForNewNote").html(html);
-
- // 移动, 复制重新来, 因为nav变了, 移动至-----的notebook导航也变了
- // 这里速度很慢
- var t1 = (new Date()).getTime();
- Note.initContextmenu();
- Share.initContextmenu(Note.notebooksCopy);
- var t2 = (new Date()).getTime();
- log(t2-t1);
-}
-
-/**
- * 我的共享notebooks
-
-
- */
-// TODO 层级
-Notebook.renderShareNotebooks = function(sharedUserInfos, shareNotebooks) {
- if(isEmpty(sharedUserInfos)) {
- return;
- }
-
- if(!shareNotebooks || typeof shareNotebooks != "object" || shareNotebooks.length < 0) {
- return;
- }
-
- var $shareNotebooks = $("#shareNotebooks");
- var user2ShareNotebooks = {};
- for(var i in shareNotebooks) {
- var userNotebooks = shareNotebooks[i];
- user2ShareNotebooks[userNotebooks.UserId] = userNotebooks;
- }
- for(var i in sharedUserInfos) {
- var userInfo = sharedUserInfos[i];
- var userNotebooks = user2ShareNotebooks[userInfo.UserId] || {ShareNotebooks:[]};
-
- userNotebooks.ShareNotebooks = [{NotebookId: "-2", Title: "默认共享"}].concat(userNotebooks.ShareNotebooks)
-
- var username = userInfo.Username || userInfo.Email;
- var header = tt('
', username, username);
- var body = '
';
- for(var j in userNotebooks.ShareNotebooks) {
- var notebook = userNotebooks.ShareNotebooks[j];
- body += tt('? ', notebook.NotebookId, notebook.Title)
- }
- body += " ";
-
- $shareNotebooks.append(header + body + "
")
- }
-}
-
-// 左侧导航, 选中某个notebook
-Notebook.selectNotebook = function(target) {
- $(".notebook-item").removeClass("curSelectedNode");
- $(target).addClass("curSelectedNode");
-};
-
-// 新建笔记导航
-Notebook.changeNotebookNavForNewNote = function(notebookId, title) {
- // 没有notebookId, 则选择第1个notebook
- // 第一个是全部笔记
- if(!notebookId) {
- var notebook = Notebook.notebooks[0];
- notebookId = notebook.NotebookId;
- title = notebook.Title;
- }
- if(!title) {
- var notebook = Notebook.cache[0];
- title = notebook.Title;
- }
-
- if(!Notebook.isAllNotebookId(notebookId) && !Notebook.isTrashNotebookId(notebookId)) {
- $("#curNotebookForNewNote").html(title).attr("notebookId", notebookId);
- } else if(!$("#curNotebookForNewNote").attr("notebookId")) {
- // 但又没有一个笔记, 默认选第一个吧
- // 这里很可能会死循环, 万一用户没有其它笔记呢?
- // 服务端肯定要在新建一个用户时给他创建一个默认笔记本的
- if(Notebook.notebooks.length > 2) {
- var notebook = Notebook.notebooks[1];
- notebookId = notebook.NotebookId;
- title = notebook.Title;
- Notebook.changeNotebookNavForNewNote(notebookId, title);
- }
- }
-}
-
-// 改变导航, 两处
-// 单击左侧, 单击新建下拉时调用
-// 1 选中左侧导航,
-// 2 notelist上面 >
-// 3 新建笔记 - js >
-// 转成我的nav <-> 共享
-Notebook.toggleToMyNav = function(userId, notebookId) {
- $("#sharedNotebookNavForListNav").hide();
- $("#myNotebookNavForListNav").show();
-
- $("#newMyNote").show();
- $("#newSharedNote").hide();
-
- // 搜索tag隐藏
- $("#tagSearch").hide();
-}
-Notebook.changeNotebookNav = function(notebookId) {
- Notebook.toggleToMyNav();
-
- // 1
- Notebook.selectNotebook($(tt('#notebookList [notebookId="?"]', notebookId)));
-
- var notebook = Notebook.cache[notebookId];
-
- if(!notebook) {
- return;
- }
-
- // 2
- $("#curNotebookForListNote").html(notebook.Title);
-
- // 3
- Notebook.changeNotebookNavForNewNote(notebookId, notebook.Title);
-}
-
-Notebook.isAllNotebookId = function(notebookId) {
- return notebookId == Notebook.allNotebookId;
-}
-Notebook.isTrashNotebookId = function(notebookId) {
- return notebookId == Notebook.trashNotebookId;
-}
-// 当前选中的笔记本是否是"所有"
-// called by Note
-Notebook.curActiveNotebookIsAll = function() {
- return Notebook.isAllNotebookId($("#notebookList .active").attr("notebookId"));
-}
-
-// 改变笔记本
-// 0. 改变样式
-// 1. 改变note, 此时需要先保存
-// 2. ajax得到该notebook下的所有note
-// 3. 使用Note.RederNotes()
-Notebook.changeNotebook = function(notebookId) {
- Notebook.changeNotebookNav(notebookId);
-
- Notebook.curNotebookId = notebookId;
-
- // 1
- Note.curChangedSaveIt();
-
- // 2 先清空所有
- Note.clearAll();
-
- var url = "/note/ListNotes/";
- var param = {notebookId: notebookId};
-
- // 废纸篓
- if(Notebook.isTrashNotebookId(notebookId)) {
- url = "/note/listTrashNotes";
- param = {};
- } else if(Notebook.isAllNotebookId(notebookId)) {
- param = {};
- // 得到全部的...
- cacheNotes = Note.getNotesByNotebookId();
- if(!isEmpty(cacheNotes)) { // 万一真的是没有呢?
- Note.renderNotesAndFirstOneContent(cacheNotes);
- return;
- }
- } else {
- cacheNotes = Note.getNotesByNotebookId(notebookId);
- if(!isEmpty(cacheNotes)) { // 万一真的是没有呢?
- Note.renderNotesAndFirstOneContent(cacheNotes);
- return;
- }
- }
-
- // 2 得到笔记本
- // 这里可以缓存起来, note按notebookId缓存
- ajaxGet(url, param, Note.renderNotesAndFirstOneContent);
-}
-
-// 是否是当前选中的notebookId
-// 还包括共享
-// called by Note
-Notebook.isCurNotebook = function(notebookId) {
- return $(tt('#notebookList [notebookId="?"], #shareNotebooks [notebookId="?"]', notebookId, notebookId)).attr("class") == "active";
-}
-
-// 改变nav, 为了新建note
-// called by Note
-Notebook.changeNotebookForNewNote = function(notebookId) {
- // 废纸篓
- if(Notebook.isTrashNotebookId(notebookId) || Notebook.isAllNotebookId(notebookId)) {
- return;
- }
-
- Notebook.changeNotebookNav(notebookId);
- Notebook.curNotebookId = notebookId;
-
- var url = "/note/ListNotes/";
- var param = {notebookId: notebookId};
-
- // 2 得到笔记本
- // 这里可以缓存起来, note按notebookId缓存
- ajaxGet(url, param, function(ret) {
- // note 导航
- Note.renderNotes(ret, true);
- });
-};
-
-//---------------------------
-// 显示共享信息
-Notebook.listNotebookShareUserInfo = function(target) {
- var notebookId = $(target).attr("notebookId");
- showDialogRemote("share/listNotebookShareUserInfo", {notebookId: notebookId});
-}
-// 共享笔记本
-Notebook.shareNotebooks= function(target) {
- var title = $(target).text();
- showDialog("dialogShareNote", {title: "分享笔记本给好友-" + title});
- setTimeout(function() {
- $("#friendsEmail").focus();
- }, 500);
- var notebookId = $(target).attr("notebookId");
-
- shareNoteOrNotebook(notebookId, false);
-}
-
-//-----------------------------
-// 设为blog/unset
-Notebook.setNotebook2Blog = function(target) {
- var notebookId = $(target).attr("notebookId");
- var notebook = Notebook.cache[notebookId];
- var isBlog = true;
- if(notebook.IsBlog != undefined) {
- isBlog = !notebook.IsBlog;
- }
-
- // 那么, 如果当前是该notebook下, 重新渲染之
- if(Notebook.curNotebookId == notebookId) {
- if(isBlog) {
- $("#noteList .item-blog").show();
- } else {
- $("#noteList .item-blog").hide();
- }
-
- // 如果当前在所有笔记本下
- } else if(Notebook.curNotebookId == Notebook.allNotebookId){
- $("#noteItemList .item").each(function(){
- var noteId = $(this).attr("noteId");
- var note = Note.cache[noteId];
- if(note.NotebookId == notebookId) {
- if(isBlog) $(this).find(".item-blog").show();
- else $(this).find(".item-blog").hide();
- }
- });
- }
- ajaxPost("blog/setNotebook2Blog", {notebookId: notebookId, isBlog: isBlog}, function(ret) {
- if(ret) {
- // 这里要设置notebook下的note的blog状态
- Note.setAllNoteBlogStatus(notebookId, isBlog);
- Notebook.setCache({NotebookId: notebookId, IsBlog: isBlog});
- }
- });
-}
-
-// 添加, 修改完后都要对notebook的列表重新计算 TODO
-
-// 修改笔记本标题
-Notebook.updateNotebookTitle = function(target) {
- var self = Notebook;
- var notebookId = $(target).attr("notebookId");
-
- if(self.tree2) {
- self.tree2.editName(self.tree2.getNodeByTId(notebookId));
- } else {
- self.tree.editName(self.tree.getNodeByTId(notebookId));
- }
-}
-Notebook.doUpdateNotebookTitle = function(notebookId, newTitle) {
- var self = Notebook;
- ajaxPost("/notebook/updateNotebookTitle", {notebookId: notebookId, title: newTitle}, function(ret) {
- // 修改缓存
- Notebook.cache[notebookId].Title = newTitle;
- // 改变nav
- Notebook.changeNav();
-
- // 同步
- if(self.tree2) {
- var notebook = self.tree.getNodeByTId(notebookId);
- notebook.Title = newTitle;
- self.tree.updateNode(notebook);
- }
- });
-}
-
-//-----------
-// 添加笔记本
-// 1 确保是展开的
-// 2 在所有后面添加
-Notebook.addNotebookSeq = 1; // inputId
-Notebook.addNotebook = function() {
- var self = Notebook;
- if($("#myNotebooks").hasClass("closed")) {
- $("#myNotebooks .folderHeader").trigger("click");
- }
-
- // 添加并修改
- self.tree.addNodes(null, {Title: "", NotebookId: getObjectId(), IsNew: true}, true, true);
-}
-
-// rename 调用
-Notebook.doAddNotebook = function(notebookId, title, parentNotebookId) {
- var self = Notebook;
- ajaxPost("/notebook/addNotebook", {notebookId: notebookId, title: title, parentNotebookId: parentNotebookId}, function(ret) {
- if(ret.NotebookId) {
- Notebook.cache[ret.NotebookId] = ret;
- var notebook = self.tree.getNodeByTId(notebookId);
- $.extend(notebook, ret);
- notebook.IsNew = false;
-
- // 选中之
- Notebook.changeNotebook(notebookId);
-
- // 改变nav
- Notebook.changeNav();
- }
- });
-}
-
-//-------------
-// 添加子笔记本
-Notebook.addChildNotebook = function(target) {
- var self = Notebook;
- if($("#myNotebooks").hasClass("closed")) {
- $("#myNotebooks .folderHeader").trigger("click");
- }
-
- var notebookId = $(target).attr("notebookId");
-
- // 添加并修改
- self.tree.addNodes(self.tree.getNodeByTId(notebookId), {Title: "", NotebookId: getObjectId(), IsNew: true}, false, true);
-}
-
-//-------------
-// 删除
-Notebook.deleteNotebook = function(target) {
- var self = Notebook;
-
- var notebookId = $(target).attr("notebookId");
- if(!notebookId) {
- return;
- }
-
- ajaxGet("/notebook/deleteNotebook", {notebookId: notebookId}, function(ret) {
- if(ret.Ok) {
- /*
- $(target).parent().remove();
- */
- self.tree.removeNode(self.tree.getNodeByTId(notebookId));
- if(self.tree2) {
- self.tree2.removeNode(self.tree2.getNodeByTId(notebookId));
- }
- delete Notebook.cache[notebookId];
-
- // 改变nav
- Notebook.changeNav();
- } else {
- alert(ret.Msg);
- }
- });
-}
-
-$(function() {
- //-------------------
- // 点击notebook
- /*
- $("#myNotebooks").on("click", "ul.folderBody li a", function() {
- var notebookId = $(this).attr("notebookId");
- Notebook.changeNotebook(notebookId);
- });
- */
- // min
- $("#minNotebookList").on("click", "li", function() {
- var notebookId = $(this).find("a").attr("notebookId");
- Notebook.changeNotebook(notebookId);
- });
-
- // 修改笔记本标题, blur后修改标题之
- /*
- enterBlur("#notebookList", "input#editNotebookTitle");
- $("#notebookList").on("blur", "input#editNotebookTitle", Notebook.doUpdateNotebookTitle);
- */
-
- //-------------------
- // 右键菜单
- var notebookListMenu = {
- width: 180,
- items: [
- { text: getMsg("shareToFriends"), alias: 'shareToFriends', icon: "", faIcon: "fa-share-square-o", action: Notebook.listNotebookShareUserInfo},
- { type: "splitLine" },
- { text: getMsg("publicAsBlog"), alias: 'set2Blog', faIcon: "fa-bold", action: Notebook.setNotebook2Blog },
- { text: getMsg("cancelPublic"), alias: 'unset2Blog',faIcon: "fa-undo", action: Notebook.setNotebook2Blog }, // Unset
- { type: "splitLine" },
- { text: getMsg("addChildNotebook"), faIcon: "fa-sitemap", action: Notebook.addChildNotebook },
- { text: getMsg("rename"), faIcon: "fa-pencil", action: Notebook.updateNotebookTitle },
- { text: getMsg("delete"), icon: "", alias: 'delete', faIcon: "fa-trash-o", action: Notebook.deleteNotebook }
- ],
- onShow: applyrule,
- onContextMenu: beforeContextMenu,
- parent: "#notebookList ",
- children: "li a"
- }
-
- // for search
- var notebookListMenu2 = {
- width: 180,
- items: [
- { text: getMsg("shareToFriends"), alias: 'shareToFriends', icon: "", faIcon: "fa-share-square-o", action: Notebook.listNotebookShareUserInfo},
- { type: "splitLine" },
- { text: getMsg("publicAsBlog"), alias: 'set2Blog', faIcon: "fa-bold", action: Notebook.setNotebook2Blog },
- { text: getMsg("cancelPublic"), alias: 'unset2Blog',faIcon: "fa-undo", action: Notebook.setNotebook2Blog }, // Unset
- { type: "splitLine" },
- { text: getMsg("rename"), icon: "", action: Notebook.updateNotebookTitle },
- { text: getMsg("delete"), icon: "", alias: 'delete', faIcon: "fa-trash-o", action: Notebook.deleteNotebook }
- ],
- onShow: applyrule,
- onContextMenu: beforeContextMenu,
- parent: "#notebookListForSearch ",
- children: "li a"
- }
-
- function applyrule(menu) {
- var notebookId = $(this).attr("notebookId");
- var notebook = Notebook.cache[notebookId];
- if(!notebook) {
- return;
- }
- // disabled的items
- var items = [];
- // 是否已公开为blog
- if(!notebook.IsBlog) {
- items.push("unset2Blog");
- } else {
- items.push("set2Blog");
- }
- // 是否还有笔记
- if(Note.notebookHasNotes(notebookId)) {
- items.push("delete");
- }
- menu.applyrule({
- name: "target2",
- disable: true,
- items: items
- });
- }
- // 哪个不能
- function beforeContextMenu() {
- var notebookId = $(this).attr("notebookId");
- return !Notebook.isTrashNotebookId(notebookId) && !Notebook.isAllNotebookId(notebookId);
- }
-
- Notebook.contextmenu = $("#notebookList li a").contextmenu(notebookListMenu);
-
- Notebook.contextmenuSearch = $("#notebookListForSearch li a").contextmenu(notebookListMenu2);
-
- // 添加笔记本
- $("#addNotebookPlus").click(function(e) {
- e.stopPropagation();
- Notebook.addNotebook();
- });
-
- // notebook setting
- $("#notebookList").on("click", ".notebook-setting", function(e) {
- e.preventDefault();
- e.stopPropagation();
- var $p = $(this).parent();
- Notebook.contextmenu.showMenu(e, $p);
- });
- $("#notebookListForSearch").on("click", ".notebook-setting", function(e) {
- e.preventDefault();
- e.stopPropagation();
- var $p = $(this).parent();
- Notebook.contextmenuSearch.showMenu(e, $p);
- });
-});
\ No newline at end of file
diff --git a/public/js/app/page-min.js b/public/js/app/page-min.js
deleted file mode 100644
index c9b445d..0000000
--- a/public/js/app/page-min.js
+++ /dev/null
@@ -1 +0,0 @@
-function editorMode(){this.writingHash="#writing";this.normalHash="#normal";this.isWritingMode=location.hash==this.writingHash;this.toggleA=null}editorMode.prototype.toggleAText=function(isWriting){var self=this;setTimeout(function(){toggleA=$("#toggleEditorMode a");if(isWriting){toggleA.attr("href",self.normalHash).text(getMsg("normalMode"))}else{toggleA.attr("href",self.writingHash).text(getMsg("writingMode"))}},0)};editorMode.prototype.isWriting=function(hash){return hash==this.writingHash};editorMode.prototype.init=function(){this.changeMode(this.isWritingMode);var self=this;$("#toggleEditorMode").click(function(){saveBookmark();var $a=$(this).find("a");var isWriting=self.isWriting($a.attr("href"));self.changeMode(isWriting);restoreBookmark()})};editorMode.prototype.changeMode=function(isWritingMode){this.toggleAText(isWritingMode);if(isWritingMode){this.writtingMode()}else{this.normalMode()}$("#moreBtn i").removeClass("fa-angle-up").addClass("fa-angle-down")};editorMode.prototype.resizeEditor=function(){setTimeout(function(){resizeEditor()},10);setTimeout(function(){resizeEditor()},20);setTimeout(function(){resizeEditor()},500)};editorMode.prototype.normalMode=function(){var $c=$("#editorContent_ifr").contents();$c.contents().find("#writtingMode").remove();$c.contents().find('link[href$="editor-writting-mode.css"]').remove();$("#noteItemListWrap, #notesAndSort").show();$("#noteList").unbind("mouseenter").unbind("mouseleave");var theme=UserInfo.Theme||"default";theme+=".css";$("#themeLink").attr("href","/css/theme/"+theme);$("#mceToolbar").css("height","30px");this.resizeEditor();$("#noteList").width(UserInfo.NoteListWidth);$("#note").css("left",UserInfo.NoteListWidth)};editorMode.prototype.writtingMode=function(){$("#themeLink").attr("href","/css/theme/writting-overwrite.css");setTimeout(function(){var $c=$("#editorContent_ifr").contents();$c.contents().find("head").append('
')},0);$("#noteItemListWrap, #notesAndSort").fadeOut();$("#noteList").hover(function(){$("#noteItemListWrap, #notesAndSort").fadeIn()},function(){$("#noteItemListWrap, #notesAndSort").fadeOut()});$("#mceToolbar").css("height","40px");this.resizeEditor();$("#noteList").width(250);$("#note").css("left",0)};editorMode.prototype.getWritingCss=function(){if(this.isWritingMode){return["css/editor/editor-writting-mode.css"]}return[]};var em=new editorMode;var Resize={lineMove:false,mdLineMove:false,target:null,leftNotebook:$("#leftNotebook"),notebookSplitter:$("#notebookSplitter"),noteList:$("#noteList"),noteAndEditor:$("#noteAndEditor"),noteSplitter:$("#noteSplitter"),note:$("#note"),body:$("body"),leftColumn:$("#left-column"),rightColumn:$("#right-column"),mdSplitter:$("#mdSplitter"),init:function(){var self=this;self.initEvent()},initEvent:function(){var self=this;$(".noteSplit").bind("mousedown",function(event){event.preventDefault();self.lineMove=true;$(this).css("background-color","#ccc");self.target=$(this).attr("id");$("#noteMask").css("z-index",99999)});self.mdSplitter.bind("mousedown",function(event){event.preventDefault();self.mdLineMove=true;$(this).css("background-color","#ccc")});self.body.bind("mousemove",function(event){if(self.lineMove){event.preventDefault();self.resize3Columns(event)}else if(self.mdLineMove){event.preventDefault();self.resizeMdColumns(event)}});self.body.bind("mouseup",function(event){self.stopResize();$("#noteMask").css("z-index",-1)})},stopResize:function(){var self=this;if(self.lineMove||self.mdLineMove){ajaxGet("/user/updateColumnWidth",{mdEditorWidth:UserInfo.MdEditorWidth,notebookWidth:UserInfo.NotebookWidth,noteListWidth:UserInfo.NoteListWidth},function(){})}self.lineMove=false;self.mdLineMove=false;$(".noteSplit").css("background","none");self.mdSplitter.css("background","none")},set3ColumnsWidth:function(notebookWidth,noteListWidth){var self=this;if(notebookWidth<150||noteListWidth<100){return}var noteWidth=self.body.width()-notebookWidth-noteListWidth;if(noteWidth<400){return}self.leftNotebook.width(notebookWidth);self.notebookSplitter.css("left",notebookWidth);self.noteAndEditor.css("left",notebookWidth);self.noteList.width(noteListWidth);self.noteSplitter.css("left",noteListWidth);self.note.css("left",noteListWidth);UserInfo.NotebookWidth=notebookWidth;UserInfo.NoteListWidth=noteListWidth},resize3Columns:function(event,isFromeIfr){var self=this;if(isFromeIfr){event.clientX+=self.body.width()-self.note.width()}var notebookWidth,noteListWidth;if(self.lineMove){if(self.target=="notebookSplitter"){notebookWidth=event.clientX;noteListWidth=self.noteList.width();self.set3ColumnsWidth(notebookWidth,noteListWidth)}else{notebookWidth=self.leftNotebook.width();noteListWidth=event.clientX-notebookWidth;self.set3ColumnsWidth(notebookWidth,noteListWidth)}resizeEditor()}},resizeMdColumns:function(event){var self=this;if(self.mdLineMove){var mdEditorWidth=event.clientX-self.leftNotebook.width()-self.noteList.width();self.setMdColumnWidth(mdEditorWidth)}},setMdColumnWidth:function(mdEditorWidth){var self=this;if(mdEditorWidth>100){UserInfo.MdEditorWidth=mdEditorWidth;self.leftColumn.width(mdEditorWidth);self.rightColumn.css("left",mdEditorWidth);self.mdSplitter.css("left",mdEditorWidth)}}};Mobile={noteO:$("#note"),bodyO:$("body"),setMenuO:$("#setMenu"),hashChange:function(){var self=Mobile;var hash=location.hash;if(hash.indexOf("noteId")!=-1){self.toEditor(false);var noteId=hash.substr(8);Note.changeNote(noteId,false,false)}else{self.toNormal(false)}},init:function(){var self=this;self.isMobile();$(window).on("hashchange",self.hashChange);self.hashChange()},isMobile:function(){var u=navigator.userAgent;LEA.isMobile=false;LEA.isMobile=/Mobile|Android|iPhone/i.test(u);if(!LEA.isMobile&&$(document).width()<=700){LEA.isMobile=true}return LEA.isMobile},changeNote:function(noteId){var self=this;if(!LEA.isMobile){return true}self.toEditor(true,noteId);return false},toEditor:function(changeHash,noteId){var self=this;self.bodyO.addClass("full-editor");self.noteO.addClass("editor-show");if(changeHash){if(!noteId){noteId=Note.curNoteId}location.hash="noteId="+noteId}},toNormal:function(changeHash){var self=this;self.bodyO.removeClass("full-editor");self.noteO.removeClass("editor-show");if(changeHash){location.hash="notebookAndNote"}},switchPage:function(){var self=this;if(!LEA.isMobile){return true}if(self.bodyO.hasClass("full-editor")){self.toNormal(true)}else{self.toEditor(true)}return false}};function initSlimScroll(){if(Mobile.isMobile()){return}$("#notebook").slimScroll({height:"100%"});$("#noteItemList").slimScroll({height:"100%"});$("#wmd-input").slimScroll({height:"100%"});$("#wmd-input").css("width","100%");$("#wmd-panel-preview").slimScroll({height:"100%"});$("#wmd-panel-preview").css("width","100%")}function initEditor(){var mceToobarEverHeight=0;$("#moreBtn").click(function(){saveBookmark();var height=$("#mceToolbar").height();if(height<$("#popularToolbar").height()){$("#mceToolbar").height($("#popularToolbar").height());$(this).find("i").removeClass("fa-angle-down").addClass("fa-angle-up");mceToobarEverHeight=height}else{$("#mceToolbar").height(mceToobarEverHeight);$(this).find("i").removeClass("fa-angle-up").addClass("fa-angle-down")}resizeEditor();restoreBookmark()});tinymce.init({setup:function(ed){ed.on("keydown",Note.saveNote);ed.on("keydown",function(e){var num=e.which?e.which:e.keyCode;if(num==9){if(!e.shiftKey){var node=ed.selection.getNode();if(node.nodeName=="PRE"){ed.execCommand("mceInsertRawHTML",false," ")}else{ed.execCommand("mceInsertRawHTML",false," ")}}else{}e.preventDefault();e.stopPropagation();return false}});ed.on("click",function(e){$("body").trigger("click")});ed.on("click",function(){log(ed.selection.getNode())})},convert_urls:true,relative_urls:false,remove_script_host:false,selector:"#editorContent",content_css:["css/bootstrap.css","css/editor/editor.css"].concat(em.getWritingCss()),skin:"custom",language:LEA.locale,plugins:["autolink link leaui_image lists charmap hr","paste","searchreplace leanote_nav leanote_code tabfocus","table directionality textcolor codemirror"],toolbar1:"formatselect | forecolor backcolor | bold italic underline strikethrough | leaui_image | leanote_code | bullist numlist | alignleft aligncenter alignright alignjustify",toolbar2:"outdent indent blockquote | link unlink | table | hr removeformat | subscript superscript |searchreplace | code | pastetext pasteCopyImage | fontselect fontsizeselect",menubar:false,toolbar_items_size:"small",statusbar:false,url_converter:false,font_formats:"Arial=arial,helvetica,sans-serif;"+"Arial Black=arial black,avant garde;"+"Times New Roman=times new roman,times;"+"Courier New=courier new,courier;"+"Tahoma=tahoma,arial,helvetica,sans-serif;"+"Verdana=verdana,geneva;"+"宋体=SimSun;"+"新宋体=NSimSun;"+"黑体=SimHei;"+"微软雅黑=Microsoft YaHei",block_formats:"Header 1=h1;Header 2=h2;Header 3=h3; Header 4=h4;Pre=pre;Paragraph=p",codemirror:{indentOnInit:true,path:"CodeMirror",config:{lineNumbers:true},jsFiles:[]},paste_data_images:true});window.onbeforeunload=function(e){Note.curChangedSaveIt()};$("body").on("keydown",Note.saveNote)}var random=1;function scrollTo(self,tagName,text){var iframe=$("#editorContent_ifr").contents();var target=iframe.find(tagName+":contains("+text+")");random++;var navs=$('#leanoteNavContent [data-a="'+tagName+"-"+encodeURI(text)+'"]');var len=navs.size();for(var i=0;i
=i+1){target=target.eq(i);var top=target.offset().top;var nowTop=iframe.scrollTop();var d=200;for(var i=0;i');
- }, 0);
-
- $("#noteItemListWrap, #notesAndSort").fadeOut();
- $("#noteList").hover(function() {
- $("#noteItemListWrap, #notesAndSort").fadeIn();
- }, function() {
- $("#noteItemListWrap, #notesAndSort").fadeOut();
- });
-
- // 点击扩展会使html的height生成, 切换后会覆盖css文件的
- $("#mceToolbar").css("height", "40px");
-
- //$("#pageInner").addClass("animated fadeInUp");
-
- this.resizeEditor();
-
- $("#noteList").width(250);
- $("#note").css("left", 0);
-}
-
-editorMode.prototype.getWritingCss = function() {
- if(this.isWritingMode) {
- return ["css/editor/editor-writting-mode.css"];
- }
- return [];
-}
-var em = new editorMode();
-
-//----------------
-// 拖拉改变变宽度
-var Resize = {
- lineMove: false,
- mdLineMove: false,
- target: null,
-
- leftNotebook: $("#leftNotebook"),
- notebookSplitter: $("#notebookSplitter"),
- noteList: $("#noteList"),
- noteAndEditor: $("#noteAndEditor"),
- noteSplitter: $("#noteSplitter"),
- note: $("#note"),
- body: $("body"),
- leftColumn: $("#left-column"),
- rightColumn: $("#right-column"),
- mdSplitter: $("#mdSplitter"),
-
- init: function() {
- var self = this;
- self.initEvent();
- },
-
- initEvent: function() {
- var self = this;
-
- // 鼠标点下
- $(".noteSplit").bind("mousedown", function(event) {
- event.preventDefault(); // 防止选择文本
- self.lineMove = true;
- $(this).css("background-color", "#ccc");
- self.target = $(this).attr("id");
- // 防止iframe捕获不了事件
- $("#noteMask").css("z-index", 99999); // .css("background-color", // "#ccc");
- });
-
- // 鼠标点下
- self.mdSplitter.bind("mousedown", function(event) {
- event.preventDefault(); // 防止选择文本
- self.mdLineMove = true;
- $(this).css("background-color", "#ccc");
- });
-
- // 鼠标移动时
- self.body.bind("mousemove", function(event) {
- if(self.lineMove) { // 如果没有这个if会导致不能选择文本
- event.preventDefault();
- self.resize3Columns(event);
- } else if(self.mdLineMove) {
- event.preventDefault();
- self.resizeMdColumns(event);
- }
- });
-
- // 鼠标放开, 结束
- self.body.bind("mouseup", function(event) {
- self.stopResize();
- // 取消遮罩
- $("#noteMask").css("z-index", -1);
- });
- },
- // 停止, 保存数据
- stopResize: function() {
- var self = this;
- if(self.lineMove || self.mdLineMove) {
- // ajax保存
- ajaxGet("/user/updateColumnWidth", {mdEditorWidth: UserInfo.MdEditorWidth, notebookWidth: UserInfo.NotebookWidth, noteListWidth: UserInfo.NoteListWidth}, function() {
- });
- }
- self.lineMove = false;
- self.mdLineMove = false;
- $(".noteSplit").css("background", "none");
- self.mdSplitter.css("background", "none");
- },
-
- // 最终调用该方法
- set3ColumnsWidth: function(notebookWidth, noteListWidth) {
- var self = this;
- if(notebookWidth < 150 || noteListWidth < 100) {
- return;
- }
- var noteWidth = self.body.width() - notebookWidth - noteListWidth;
- if(noteWidth < 400) {
- return;
- }
-
- self.leftNotebook.width(notebookWidth);
- self.notebookSplitter.css("left", notebookWidth);
-
- self.noteAndEditor.css("left", notebookWidth);
- self.noteList.width(noteListWidth);
- self.noteSplitter.css("left", noteListWidth);
- self.note.css("left", noteListWidth);
-
- UserInfo.NotebookWidth = notebookWidth;
- UserInfo.NoteListWidth = noteListWidth;
- },
- resize3Columns: function(event, isFromeIfr) {
- var self = this;
- if (isFromeIfr) {
- event.clientX += self.body.width() - self.note.width();
- }
-
- var notebookWidth, noteListWidth;
- if(self.lineMove) {
- if (self.target == "notebookSplitter") {
- notebookWidth = event.clientX;
- noteListWidth = self.noteList.width();
- self.set3ColumnsWidth(notebookWidth, noteListWidth);
- } else {
- notebookWidth = self.leftNotebook.width();
- noteListWidth = event.clientX - notebookWidth;
- self.set3ColumnsWidth(notebookWidth, noteListWidth);
- }
-
- resizeEditor();
- }
- },
-
- // mdeditor
- resizeMdColumns: function(event) {
- var self = this;
- if (self.mdLineMove) {
- var mdEditorWidth = event.clientX - self.leftNotebook.width() - self.noteList.width();
- self.setMdColumnWidth(mdEditorWidth);
- }
- },
- // 设置宽度
- setMdColumnWidth: function(mdEditorWidth) {
- var self = this;
- if(mdEditorWidth > 100) {
- UserInfo.MdEditorWidth = mdEditorWidth;
- self.leftColumn.width(mdEditorWidth);
- self.rightColumn.css("left", mdEditorWidth);
- self.mdSplitter.css("left", mdEditorWidth);
- }
- }
-}
-
-//--------------------------
-// 手机端访问之
-Mobile = {
- // 点击之笔记
- // 切换到编辑器模式
- noteO: $("#note"),
- bodyO: $("body"),
- setMenuO: $("#setMenu"),
- hashChange: function() {
- var self = Mobile;
- var hash = location.hash;
- // noteId
- if(hash.indexOf("noteId") != -1) {
- self.toEditor(false);
- var noteId = hash.substr(8);
- Note.changeNote(noteId, false, false);
- } else {
- // 笔记本和笔记列表
- self.toNormal(false);
- }
- },
- init: function() {
- var self = this;
- self.isMobile();
- $(window).on("hashchange", self.hashChange);
- self.hashChange();
- /*
- $("#noteItemList").on("tap", ".item", function(event) {
- $(this).click();
- });
- $(document).on("swipeleft",function(e){
- e.stopPropagation();
- e.preventDefault();
- self.toEditor();
- });
- $(document).on("swiperight",function(e){
- e.stopPropagation();
- e.preventDefault();
- self.toNormal();
- });
- */
- },
- isMobile: function() {
- var u = navigator.userAgent;
- LEA.isMobile = false;
- LEA.isMobile = /Mobile|Android|iPhone/i.test(u);
- if(!LEA.isMobile && $(document).width() <= 700){
- LEA.isMobile = true
- }
- return LEA.isMobile;
- },
- changeNote: function(noteId) {
- var self = this;
- if(!LEA.isMobile) {return true;}
- self.toEditor(true, noteId);
- return false;
- },
-
- toEditor: function(changeHash, noteId) {
- var self = this;
- self.bodyO.addClass("full-editor");
- self.noteO.addClass("editor-show");
- if(changeHash) {
- if(!noteId) {
- noteId = Note.curNoteId;
- }
- location.hash = "noteId=" + noteId;
- }
- },
- toNormal: function(changeHash) {
- var self = this;
- self.bodyO.removeClass("full-editor");
- self.noteO.removeClass("editor-show");
-
- if(changeHash) {
- location.hash = "notebookAndNote";
- }
- },
- switchPage: function() {
- var self = this;
- if(!LEA.isMobile) {return true;}
- if(self.bodyO.hasClass("full-editor")) {
- self.toNormal(true);
- } else {
- self.toEditor(true);
- }
- return false;
- }
-}
-
-
-function initSlimScroll() {
- if(Mobile.isMobile()) {
- return;
- }
- $("#notebook").slimScroll({
- height: "100%", // $("#leftNotebook").height()+"px"
- });
- $("#noteItemList").slimScroll({
- height: "100%", // ($("#leftNotebook").height()-42)+"px"
- });
- $("#wmd-input").slimScroll({
- height: "100%", // $("#wmd-input").height()+"px"
- });
- $("#wmd-input").css("width", "100%");
-
- $("#wmd-panel-preview").slimScroll({
- height: "100%", // $("#wmd-panel-preview").height()+"px"
- });
-
- $("#wmd-panel-preview").css("width", "100%");
-}
-
-//-----------
-// 初始化编辑器
-function initEditor() {
- // editor
- // toolbar 下拉扩展, 也要resizeEditor
- var mceToobarEverHeight = 0;
- $("#moreBtn").click(function() {
- saveBookmark();
-
- var height = $("#mceToolbar").height();
-
- // 现在是折叠的
- if (height < $("#popularToolbar").height()) {
- $("#mceToolbar").height($("#popularToolbar").height());
- $(this).find("i").removeClass("fa-angle-down").addClass("fa-angle-up");
- mceToobarEverHeight = height;
- } else {
- $("#mceToolbar").height(mceToobarEverHeight);
- $(this).find("i").removeClass("fa-angle-up").addClass("fa-angle-down");
- }
-
- resizeEditor();
-
- restoreBookmark();
- });
-
- // 初始化编辑器
- tinymce.init({
- setup: function(ed) {
- ed.on('keydown', Note.saveNote);
- // indent outdent
- ed.on('keydown', function(e) {
- var num = e.which ? e.which : e.keyCode;
- if (num == 9) { // tab pressed
-
- if(!e.shiftKey) {
-// ed.execCommand('Indent');
- // TODO 如果当前在li, ul, ol下不执行!!
- // 如果在pre下就加tab
- var node = ed.selection.getNode();
- if(node.nodeName == "PRE") {
- ed.execCommand('mceInsertRawHTML', false, '\x09'); // inserts tab
- } else {
- ed.execCommand('mceInsertRawHTML', false, " "); // inserts 空格
- }
- } else {
- // delete 4 个空格
-// ed.execCommand('Outdent');
- }
-
- e.preventDefault();
- e.stopPropagation();
- return false;
- }
- });
-
- // 为了把下拉菜单关闭
- ed.on("click", function(e) {
- $("body").trigger("click");
- });
-
- // 鼠标移上时
- ed.on("click", function() {
- log(ed.selection.getNode())
- });
- },
-
- // fix TinyMCE Removes site base url
- // http://stackoverflow.com/questions/3360084/tinymce-removes-site-base-urls
- convert_urls:true,
- relative_urls:false,
- remove_script_host:false,
-
- selector : "#editorContent",
- // height: 100,//这个应该是文档的高度, 而其上层的高度是$("#content").height(),
- // parentHeight: $("#content").height(),
- content_css : ["css/bootstrap.css", "css/editor/editor.css"].concat(em.getWritingCss()),
- skin : "custom",
- language: LEA.locale, // 语言
- plugins : [
- "autolink link leaui_image lists charmap hr", "paste",
- "searchreplace leanote_nav leanote_code tabfocus",
- "table directionality textcolor codemirror" ], // nonbreaking
-
- toolbar1 : "formatselect | forecolor backcolor | bold italic underline strikethrough | leaui_image | leanote_code | bullist numlist | alignleft aligncenter alignright alignjustify",
- toolbar2 : "outdent indent blockquote | link unlink | table | hr removeformat | subscript superscript |searchreplace | code | pastetext pasteCopyImage | fontselect fontsizeselect",
-
- // 使用tab键: http://www.tinymce.com/wiki.php/Plugin3x:nonbreaking
- // http://stackoverflow.com/questions/13543220/tiny-mce-how-to-allow-people-to-indent
- // nonbreaking_force_tab : true,
-
- menubar : false,
- toolbar_items_size : 'small',
- statusbar : false,
- url_converter: false,
- font_formats : "Arial=arial,helvetica,sans-serif;"
- + "Arial Black=arial black,avant garde;"
- + "Times New Roman=times new roman,times;"
- + "Courier New=courier new,courier;"
- + "Tahoma=tahoma,arial,helvetica,sans-serif;"
- + "Verdana=verdana,geneva;" + "宋体=SimSun;"
- + "新宋体=NSimSun;" + "黑体=SimHei;"
- + "微软雅黑=Microsoft YaHei",
- block_formats : "Header 1=h1;Header 2=h2;Header 3=h3; Header 4=h4;Pre=pre;Paragraph=p",
- codemirror: {
- indentOnInit: true, // Whether or not to indent code on init.
- path: 'CodeMirror', // Path to CodeMirror distribution
- config: { // CodeMirror config object
- //mode: 'application/x-httpd-php',
- lineNumbers: true
- },
- jsFiles: [ // Additional JS files to load
- // 'mode/clike/clike.js',
- //'mode/php/php.js'
- ]
- },
- // This option specifies whether data:url images (inline images) should be removed or not from the pasted contents.
- // Setting this to "true" will allow the pasted images, and setting this to "false" will disallow pasted images.
- // For example, Firefox enables you to paste images directly into any contentEditable field. This is normally not something people want, so this option is "false" by default.
- paste_data_images: true
- });
-
- // 刷新时保存 参考autosave插件
- window.onbeforeunload = function(e) {
- Note.curChangedSaveIt();
- }
-
- // 全局ctrl + s
- $("body").on('keydown', Note.saveNote);
-}
-
-//-----------------------
-// 导航
-var random = 1;
-function scrollTo(self, tagName, text) {
- var iframe = $("#editorContent_ifr").contents();
- var target = iframe.find(tagName + ":contains(" + text + ")");
- random++;
-
- // 找到是第几个
- // 在nav是第几个
- var navs = $('#leanoteNavContent [data-a="' + tagName + '-' + encodeURI(text) + '"]');
-// alert('#leanoteNavContent [data-a="' + tagName + '-' + encodeURI(text) + '"]')
- var len = navs.size();
- for(var i = 0; i < len; ++i) {
- if(navs[i] == self) {
- break;
- }
- }
-
- if (target.size() >= i+1) {
- target = target.eq(i);
- // 之前插入, 防止多行定位不准
- var top = target.offset().top;
- var nowTop = iframe.scrollTop();
-
- // iframe.scrollTop(top);
- // $(iframe).animate({scrollTop: top}, 300); // 有问题
-
- var d = 200; // 时间间隔
- for(var i = 0; i < d; i++) {
- setTimeout(
- (function(top) {
- return function() {
- iframe.scrollTop(top);
- }
- })(nowTop + 1.0*i*(top-nowTop)/d), i);
- }
- // 最后必然执行
- setTimeout(function() {
- iframe.scrollTop(top);
- }, d+5);
- return;
- }
-}
-
-//--------------
-// 调用之
-$(function() {
- // 窗口缩放时
- $(window).resize(function() {
- Mobile.isMobile();
- resizeEditor();
- });
-
- // 初始化编辑器
- initEditor();
-
- // 左侧, folder 展开与关闭
- $(".folderHeader").click(function() {
- var body = $(this).next();
- var p = $(this).parent();
- if (!body.is(":hidden")) {
- $(".folderNote").removeClass("opened").addClass("closed");
-// body.hide();
- p.removeClass("opened").addClass("closed");
- $(this).find(".fa-angle-down").removeClass("fa-angle-down").addClass("fa-angle-right");
- } else {
- $(".folderNote").removeClass("opened").addClass("closed");
-// body.show();
- p.removeClass("closed").addClass("opened");
- $(this).find(".fa-angle-right").removeClass("fa-angle-right").addClass("fa-angle-down");
- }
- });
-
- // 导航隐藏与显示
- $("#leanoteNav h1").on("click", function(e) {
- if (!$("#leanoteNav").hasClass("unfolder")) {
- $("#leanoteNav").addClass("unfolder");
- } else {
- $("#leanoteNav").removeClass("unfolder");
- }
- });
-
- // 打开设置
- function openSetInfoDialog(whichTab) {
- showDialogRemote("/user/account", {tab: whichTab});
- }
- // 帐号设置
- $("#setInfo").click(function() {
- openSetInfoDialog(0);
- });
- // 邮箱验证
- $("#wrongEmail").click(function() {
- openSetInfoDialog(1);
- });
-
- $("#setAvatarMenu").click(function() {
- showDialog2("#avatarDialog", {title: "头像设置", postShow: function() {
- }});
- });
- $("#setTheme").click(function() {
- showDialog2("#setThemeDialog", {title: "主题设置", postShow: function() {
- if (!UserInfo.Theme) {
- UserInfo.Theme = "default";
- }
- $("#themeForm input[value='" + UserInfo.Theme + "']").attr("checked", true);
- }});
- });
-
- //---------
- // 主题
- $("#themeForm").on("click", "input", function(e) {
- var val = $(this).val();
- $("#themeLink").attr("href", "/css/theme/" + val + ".css");
-
- ajaxPost("/user/updateTheme", {theme: val}, function(re) {
- if(reIsOk(re)) {
- UserInfo.Theme = val
- }
- });
- });
-
- //-------------
- // 邮箱验证
- if(!UserInfo.Verified) {
-// $("#leanoteMsg").hide();
-// $("#verifyMsg").show();
- }
-
- // 禁止双击选中文字
- $("#notebook, #newMyNote, #myProfile, #topNav, #notesAndSort", "#leanoteNavTrigger").bind("selectstart", function(e) {
- e.preventDefault();
- return false;
- });
-
- // 左侧隐藏或展示
- function updateLeftIsMin(is) {
- ajaxGet("/user/updateLeftIsMin", {leftIsMin: is})
- }
- function minLeft(save) {
- $("#leftNotebook").width(30);
- $("#notebook").hide();
- // 左侧
- $("#noteAndEditor").css("left", 30)
- $("#notebookSplitter").hide();
-
-// $("#leftSwitcher").removeClass("fa-angle-left").addClass("fa-angle-right");
-
- // logo
- $("#logo").hide();
- $("#leftSwitcher").hide();
- $("#leftSwitcher2").show();
- $("#leftNotebook .slimScrollDiv").hide();
-
- if(save) {
- updateLeftIsMin(true);
- }
- }
-
- function maxLeft(save) {
- $("#noteAndEditor").css("left", UserInfo.NotebookWidth);
- $("#leftNotebook").width(UserInfo.NotebookWidth);
- $("#notebook").show();
- $("#notebookSplitter").show();
-
-// $("#leftSwitcher").removeClass("fa-angle-right").addClass("fa-angle-left");
-
- $("#leftSwitcher2").hide();
- $("#logo").show();
- $("#leftSwitcher").show();
- $("#leftNotebook .slimScrollDiv").show();
-
- if(save) {
- updateLeftIsMin(false);
- }
- }
-
- $("#leftSwitcher2").click(function() {
- maxLeft(true);
- });
- $("#leftSwitcher").click(function() {
- if(Mobile.switchPage()) {
- minLeft(true);
- }
- });
-
- // 得到最大dropdown高度
- // 废弃
- function getMaxDropdownHeight(obj) {
- var offset = $(obj).offset();
- var maxHeight = $(document).height()-offset.top;
- maxHeight -= 70;
- if(maxHeight < 0) {
- maxHeight = 0;
- }
-
- var preHeight = $(obj).find("ul").height();
- return preHeight < maxHeight ? preHeight : maxHeight;
- }
-
- // mini版
- // 点击展开
- $("#notebookMin div.minContainer").click(function() {
- var target = $(this).attr("target");
- maxLeft(true);
- if(target == "#notebookList") {
- if($("#myNotebooks").hasClass("closed")) {
- $("#myNotebooks .folderHeader").trigger("click");
- }
- } else if(target == "#tagNav") {
- if($("#myTag").hasClass("closed")) {
- $("#myTag .folderHeader").trigger("click");
- }
- } else {
- if($("#myShareNotebooks").hasClass("closed")) {
- $("#myShareNotebooks .folderHeader").trigger("click");
- }
- }
- });
-
- //------------------------
- // 界面设置, 左侧是否是隐藏的
- UserInfo.NotebookWidth = UserInfo.NotebookWidth || $("#notebook").width();
- UserInfo.NoteListWidth = UserInfo.NoteListWidth || $("#noteList").width();
-
- Resize.init();
- Resize.set3ColumnsWidth(UserInfo.NotebookWidth, UserInfo.NoteListWidth);
- Resize.setMdColumnWidth(UserInfo.MdEditorWidth);
-
- if (UserInfo.LeftIsMin) {
- minLeft(false);
- }
-
- // end
- // 开始时显示loading......
- // 隐藏mask
- $("#mainMask").html("");
- $("#mainMask").hide(100);
-
- // 4/25 防止dropdown太高
- // dropdown
- $('.dropdown').on('shown.bs.dropdown', function () {
- var $ul = $(this).find("ul");
- // $ul.css("max-height", getMaxDropdownHeight(this));
- });
-
- //--------
- // 编辑器帮助
- $("#tipsBtn").click(function() {
- showDialog2("#tipsDialog");
- });
-
- //--------
- // 建议
- $("#yourSuggestions").click(function() {
- showDialog2("#suggestionsDialog");
- });
- $("#suggestionBtn").click(function(e) {
- e.preventDefault();
- var suggestion = $.trim($("#suggestionTextarea").val());
- if(!suggestion) {
- $("#suggestionMsg").html("请输入您的建议, 谢谢!").show().addClass("alert-warning").removeClass("alert-success");
- $("#suggestionTextarea").focus();
- return;
- }
- $("#suggestionBtn").html("正在处理...").addClass("disabled");
- $("#suggestionMsg").html("正在处理...");
- $.post("/suggestion", {suggestion: suggestion}, function(ret) {
- $("#suggestionBtn").html("提交").removeClass("disabled");
- if(ret.Ok) {
- $("#suggestionMsg").html("谢谢反馈, 我们会第一时间处理, 祝您愉快!").addClass("alert-success").removeClass("alert-warning").show();
- } else {
- $("#suggestionMsg").html("出错了").show().addClass("alert-warning").removeClass("alert-success");
- }
- });
- });
-
- // 编辑器模式
- em.init();
-
- // 手机端?
- Mobile.init();
-});
-
diff --git a/public/js/app/share-min.js b/public/js/app/share-min.js
deleted file mode 100644
index f959a81..0000000
--- a/public/js/app/share-min.js
+++ /dev/null
@@ -1 +0,0 @@
-Share.defaultNotebookId="share0";Share.defaultNotebookTitle=getMsg("defaulthhare");Share.sharedUserInfos={};Share.userNavs={};Share.notebookCache={};Share.cache={};Share.dialogIsNote=true;Share.setCache=function(note){if(!note||!note.NoteId){return}Share.cache[note.NoteId]=note};Share.getNotebooksForNew=function(userId,notebooks){var self=this;var navForNewNote="";var len=notebooks.length;for(var i=0;i?
M
',classes,userId,notebook.NotebookId,notebook.Title);if(subs){eachForNew+=""}eachForNew+=""}navForNewNote+=eachForNew}return navForNewNote};Share.trees={};Share.renderShareNotebooks=function(sharedUserInfos,shareNotebooks){var self=Share;if(isEmpty(sharedUserInfos)){return}if(!shareNotebooks||typeof shareNotebooks!="object"||shareNotebooks.length<0){shareNotebooks={}}var $shareNotebooks=$("#shareNotebooks");for(var i in sharedUserInfos){var userInfo=sharedUserInfos[i];var userNotebooksPre=shareNotebooks[userInfo.UserId]||[];userNotebooks=[{NotebookId:self.defaultNotebookId,Title:Share.defaultNotebookTitle}].concat(userNotebooksPre);self.notebookCache[self.defaultNotebookId]=userNotebooks[0];var username=userInfo.Username||userInfo.Email;userInfo.Username=username;Share.sharedUserInfos[userInfo.UserId]=userInfo;var userId=userInfo.UserId;var header=tt('',userInfo.UserId,username);var friendId="friendContainer_"+userId;var body='';$shareNotebooks.append(header+body+" ");self.trees[userId]=$.fn.zTree.init($("#"+friendId),Notebook.getTreeSetting(true,true),userNotebooks);self.userNavs[userId]={forNew:self.getNotebooksForNew(userId,userNotebooksPre)};log(self.userNavs)}$(".friend-notebooks").hover(function(){if(!$(this).hasClass("showIcon")){$(this).addClass("showIcon")}},function(){$(this).removeClass("showIcon")});$(".friend-header i").click(function(){var $this=$(this);var $tree=$(this).parent().next();if($tree.is(":hidden")){$tree.slideDown("fast");$this.removeClass("fa-angle-right fa-angle-down").addClass("fa-angle-down")}else{$tree.slideUp("fast");$this.removeClass("fa-angle-right fa-angle-down").addClass("fa-angle-right")}});var shareNotebookMenu={width:180,items:[{text:getMsg("deleteSharedNotebook"),icon:"",faIcon:"fa-trash-o",action:Share.deleteShareNotebook}],onShow:applyrule,onContextMenu:beforeContextMenu,parent:"#shareNotebooks",children:".notebook-item"};function applyrule(menu){return}function beforeContextMenu(){var notebookId=$(this).attr("notebookId");return!Share.isDefaultNotebookId(notebookId)}var menuNotebooks=$("#shareNotebooks").contextmenu(shareNotebookMenu);var shareUserMenu={width:180,items:[{text:getMsg("deleteAllShared"),icon:"",faIcon:"fa-trash-o",action:Share.deleteUserShareNoteAndNotebook}],parent:"#shareNotebooks",children:".friend-header"};var menuUser=$("#shareNotebooks").contextmenu(shareUserMenu);$(".friend-header").on("click",".notebook-setting",function(e){e.preventDefault();e.stopPropagation();var $p=$(this).parent();menuUser.showMenu(e,$p)});$("#shareNotebooks .notebook-item").on("click",".notebook-setting",function(e){e.preventDefault();e.stopPropagation();var $p=$(this).parent();menuNotebooks.showMenu(e,$p)})};Share.isDefaultNotebookId=function(notebookId){return Share.defaultNotebookId==notebookId};Share.toggleToSharedNav=function(userId,notebookId){var self=this;$("#curNotebookForListNote").html(Share.notebookCache[notebookId].Title+"("+Share.sharedUserInfos[userId].Username+")");var forNew=Share.userNavs[userId].forNew;if(forNew){$("#notebookNavForNewSharedNote").html(forNew);var curNotebookId="";var curNotebookTitle="";if(Share.notebookCache[notebookId].Perm){curNotebookId=notebookId;curNotebookTitle=Share.notebookCache[notebookId].Title}else{var $f=$("#notebookNavForNewSharedNote li").eq(0);curNotebookId=$f.attr("notebookId");curNotebookTitle=$f.find(".new-note-left").text()}$("#curNotebookForNewSharedNote").html(curNotebookTitle+"("+Share.sharedUserInfos[userId].Username+")");$("#curNotebookForNewSharedNote").attr("notebookId",curNotebookId);$("#curNotebookForNewSharedNote").attr("userId",userId);$("#newSharedNote").show();$("#newMyNote").hide()}else{$("#newMyNote").show();$("#newSharedNote").hide()}$("#tagSearch").hide()};Share.changeNotebook=function(userId,notebookId){Notebook.selectNotebook($(tt('#friendContainer_? a[notebookId="?"]',userId,notebookId)));Share.toggleToSharedNav(userId,notebookId);Note.curChangedSaveIt();Note.clearAll();var url="/share/ListShareNotes/";var param={userId:userId};if(!Share.isDefaultNotebookId(notebookId)){param.notebookId=notebookId}ajaxGet(url,param,function(ret){if(param.notebookId){}Note.renderNotes(ret,false,true);if(!isEmpty(ret)){Note.changeNote(ret[0].NoteId,true)}else{}})};Share.hasUpdatePerm=function(notebookId){var note=Share.cache[notebookId];if(!note||!note.Perm){return false}return true};Share.deleteShareNotebook=function(target){if(confirm("Are you sure to delete it?")){var notebookId=$(target).attr("notebookId");var fromUserId=$(target).closest(".friend-notebooks").attr("fromUserId");ajaxGet("/share/DeleteShareNotebookBySharedUser",{notebookId:notebookId,fromUserId:fromUserId},function(ret){if(ret){$(target).parent().remove()}})}};Share.deleteShareNote=function(target){var noteId=$(target).attr("noteId");var fromUserId=$(target).attr("fromUserId");ajaxGet("/share/DeleteShareNoteBySharedUser",{noteId:noteId,fromUserId:fromUserId},function(ret){if(ret){$(target).remove()}})};Share.deleteUserShareNoteAndNotebook=function(target){if(confirm("Are you sure to delete all shared notebooks and notes?")){var fromUserId=$(target).attr("fromUserId");ajaxGet("/share/deleteUserShareNoteAndNotebook",{fromUserId:fromUserId},function(ret){if(ret){$(target).parent().remove()}})}};Share.changeNotebookForNewNote=function(notebookId){Notebook.selectNotebook($(tt('#shareNotebooks [notebookId="?"]',notebookId)));var userId=Share.notebookCache[notebookId].UserId;Share.toggleToSharedNav(userId,notebookId);var url="/share/ListShareNotes/";var param={userId:userId,notebookId:notebookId};ajaxGet(url,param,function(ret){Note.renderNotes(ret,true,true)})};Share.deleteSharedNote=function(target,contextmenuItem){Note.deleteNote(target,contextmenuItem,true)};Share.copySharedNote=function(target,contextmenuItem){Note.copyNote(target,contextmenuItem,true)};Share.contextmenu=null;Share.initContextmenu=function(notebooksCopy){if(Share.contextmenu){Share.contextmenu.destroy()}var noteListMenu={width:180,items:[{text:getMsg("copyToMyNotebook"),alias:"copy",faIcon:"fa-copy",type:"group",width:180,items:notebooksCopy},{type:"splitLine"},{text:getMsg("delete"),alias:"delete",icon:"",faIcon:"fa-trash-o",action:Share.deleteSharedNote}],onShow:applyrule,parent:"#noteItemList",children:".item-shared"};function applyrule(menu){var noteId=$(this).attr("noteId");var note=Share.cache[noteId];if(!note){return}var items=[];if(!(note.Perm&¬e.CreatedUserId==UserInfo.UserId)){items.push("delete")}menu.applyrule({name:"target...",disable:true,items:items})}Share.contextmenu=$("#noteItemList .item-shared").contextmenu(noteListMenu)};$(function(){$("#noteItemList").on("click",".item-shared .item-setting",function(e){e.preventDefault();e.stopPropagation();var $p=$(this).parent();Share.contextmenu.showMenu(e,$p)});$("#newSharedNoteBtn").click(function(){var notebookId=$("#curNotebookForNewSharedNote").attr("notebookId");var userId=$("#curNotebookForNewSharedNote").attr("userId");Note.newNote(notebookId,true,userId)});$("#newShareNoteMarkdownBtn").click(function(){var notebookId=$("#curNotebookForNewSharedNote").attr("notebookId");var userId=$("#curNotebookForNewSharedNote").attr("userId");Note.newNote(notebookId,true,userId,true)});$("#notebookNavForNewSharedNote").on("click","li div",function(){var notebookId=$(this).parent().attr("notebookId");var userId=$(this).parent().attr("userId");if($(this).text()=="M"){Note.newNote(notebookId,true,userId,true)}else{Note.newNote(notebookId,true,userId)}});$("#leanoteDialogRemote").on("click",".change-perm",function(){var self=this;var perm=$(this).attr("perm");var noteOrNotebookId=$(this).attr("noteOrNotebookId");var toUserId=$(this).attr("toUserId");var toHtml=getMsg("writable");var toPerm="1";if(perm=="1"){toHtml=getMsg("readOnly");toPerm="0"}var url="/share/UpdateShareNotebookPerm";var param={perm:toPerm,toUserId:toUserId};if(Share.dialogIsNote){url="/share/UpdateShareNotePerm";param.noteId=noteOrNotebookId}else{param.notebookId=noteOrNotebookId}ajaxGet(url,param,function(ret){if(ret){$(self).html(toHtml);$(self).attr("perm",toPerm)}})});$("#leanoteDialogRemote").on("click",".delete-share",function(){var self=this;var noteOrNotebookId=$(this).attr("noteOrNotebookId");var toUserId=$(this).attr("toUserId");var url="/share/DeleteShareNotebook";var param={toUserId:toUserId};if(Share.dialogIsNote){url="/share/DeleteShareNote";param.noteId=noteOrNotebookId}else{param.notebookId=noteOrNotebookId}ajaxGet(url,param,function(ret){if(ret){$(self).parent().parent().remove()}})});var seq=1;$("#leanoteDialogRemote").on("click","#addShareNotebookBtn",function(){seq++;var tpl='# ';tpl+=' '+getMsg("readOnly")+" ";tpl+=' '+getMsg("writable")+" ";tpl+=''+getMsg("share")+" ";tpl+=' '+getMsg("delete")+" ";tpl+=" ";$("#shareNotebookTable tbody").prepend(tpl);$("#tr"+seq+" #friendsEmail").focus()});$("#registerEmailBtn").click(function(){var content=$("#emailContent").val();var toEmail=$("#toEmail").val();if(!content){showAlert("#registerEmailMsg",getMsg("emailBodyRequired"),"danger");return}post("/user/sendRegisterEmail",{content:content,toEmail:toEmail},function(ret){showAlert("#registerEmailMsg",getMsg("sendSuccess"),"success");hideDialog2("#sendRegisterEmailDialog",1e3)},this)})});function addShareNoteOrNotebook(trSeq){var trId="#tr"+trSeq;var id=Share.dialogNoteOrNotebookId;var emails=isEmailFromInput(trId+" #friendsEmail","#shareMsg",getMsg("inputFriendEmail"));if(!emails){return}var shareNotePerm=$(trId+' input[name="perm'+trSeq+'"]:checked').val()||0;var perm=shareNotePerm;var url="share/addShareNote";var data={noteId:id,emails:[emails],perm:shareNotePerm};if(!Share.dialogIsNote){url="share/addShareNotebook";data={notebookId:id,emails:[emails],perm:shareNotePerm}}hideAlert("#shareMsg");post(url,data,function(ret){var ret=ret[emails];if(ret){if(ret.Ok){var tpl=tt("? ","#");tpl+=tt("? ",emails);tpl+=tt('? ',id,perm,ret.Id,!perm||perm=="0"?getMsg("readOnly"):getMsg("writable"));tpl+=tt(''+getMsg("delete")+" ",id,ret.Id);$(trId).html(tpl)}else{var shareUrl=UrlPrefix+"/register?from="+UserInfo.Username;showAlert("#shareMsg",getMsg("friendNotExits",[getMsg("app"),shareUrl])+' '+getMsg("clickToCopy")+' '+getMsg("sendInviteEmailToYourFriend")+', "+getMsg("send"),"warning");$("#copyDiv").text(shareUrl);initCopy("shareCopy",function(args){if(args.text){showMsg2("#copyStatus",getMsg("copySuccess"),1e3)}else{showMsg2("#copyStatus",getMsg("copyFailed"),1e3)}})}}},trId+" .btn-success")}function sendRegisterEmail(email){showDialog2("#sendRegisterEmailDialog",{postShow:function(){$("#emailContent").val(getMsg("inviteEmailBody",[UserInfo.Username,getMsg("app")]));setTimeout(function(){$("#emailContent").focus()},500);$("#toEmail").val(email)}})}function deleteShareNoteOrNotebook(trSeq){$("#tr"+trSeq).remove()}
\ No newline at end of file
diff --git a/public/js/app/share.js b/public/js/app/share.js
deleted file mode 100644
index c0aaf3f..0000000
--- a/public/js/app/share.js
+++ /dev/null
@@ -1,583 +0,0 @@
-//------------------------------------
-// 共享, notbeook, note
-//------------------------------------
-
-// 默认共享notebook id
-Share.defaultNotebookId = "share0";
-Share.defaultNotebookTitle = getMsg("defaulthhare");
-Share.sharedUserInfos = {}; // userId => {}
-
-// 在render时就创建, 以后复用之
-Share.userNavs = {}; // userId => {"forList":html, "forNew":html}
-
-// 缓存都不要, 统一放在Note.cache中
-// 放在这里, 只是为了debug, 分离
-Share.notebookCache = {}; // notebooks 的cache
-Share.cache = {}; // note的cache
-
-// 分享的弹出框是note的
-Share.dialogIsNote = true;
-
-// 设置缓存 note
-Share.setCache = function(note) {
- if(!note || !note.NoteId) {
- return;
- }
- Share.cache[note.NoteId] = note;
-}
-
-/**
- * 我的共享notebooks
-
-
- */
-// TODO 层级
-// shareNotebooks = {userId => {}}
-Share.getNotebooksForNew = function(userId, notebooks) {
- var self = this;
- var navForNewNote = "";
-
- var len = notebooks.length;
- for(var i = 0; i < len; ++i) {
- var notebook = notebooks[i];
- notebook.IsShared = true;
- notebook.UserId = userId;
- self.notebookCache[notebook.NotebookId] = notebook;
- // notebook的cache也缓存一份, 为了显示标题
- Notebook.cache[notebook.NotebookId] = notebook;
-
- var classes = "";
- var subs = false;
- if(!isEmpty(notebook.Subs)) {
- log(11);
- log(notebook.Subs);
- var subs = self.getNotebooksForNew(userId, notebook.Subs);
- if(subs) {
- classes = "dropdown-submenu";
- }
- }
-
- var eachForNew = "";
- if(notebook.Perm) {
- var eachForNew = tt('
?
M
', classes, userId, notebook.NotebookId, notebook.Title);
- if(subs) {
- eachForNew += "";
- }
- eachForNew += '';
- }
-
- navForNewNote += eachForNew;
- }
- return navForNewNote;
-}
-Share.trees = {};
-Share.renderShareNotebooks = function(sharedUserInfos, shareNotebooks) {
- var self = Share;
- if(isEmpty(sharedUserInfos)) {
- return;
- }
-
- if(!shareNotebooks || typeof shareNotebooks != "object" || shareNotebooks.length < 0) {
- shareNotebooks = {};
- }
-
- var $shareNotebooks = $("#shareNotebooks");
-
- // render每一个用户的share给我的笔记本, 之前先建一个默认共享
- for(var i in sharedUserInfos) {
- var userInfo = sharedUserInfos[i];
- var userNotebooksPre = shareNotebooks[userInfo.UserId] || [];
-
- userNotebooks = [{NotebookId: self.defaultNotebookId, Title: Share.defaultNotebookTitle}].concat(userNotebooksPre)
-
- self.notebookCache[self.defaultNotebookId] = userNotebooks[0];
-
- var username = userInfo.Username || userInfo.Email;
- userInfo.Username = username;
- Share.sharedUserInfos[userInfo.UserId] = userInfo;
- var userId = userInfo.UserId;
- var header = tt('
', userInfo.UserId, username);
- var friendId = "friendContainer_" + userId;
- var body = '';
- $shareNotebooks.append(header + body + " ")
-
- self.trees[userId] = $.fn.zTree.init($("#" + friendId), Notebook.getTreeSetting(true, true), userNotebooks);
-
- self.userNavs[userId] = {"forNew": self.getNotebooksForNew(userId, userNotebooksPre)};
- log(self.userNavs);
- }
-
- $(".friend-notebooks").hover(function () {
- if (!$(this).hasClass("showIcon")) {
- $(this).addClass("showIcon");
- }
- }, function() {
- $(this).removeClass("showIcon");
- });
-
- $(".friend-header i").click(function() {
- var $this = $(this);
- var $tree = $(this).parent().next();
- if($tree.is(":hidden")) {
- $tree.slideDown("fast");
- $this.removeClass("fa-angle-right fa-angle-down").addClass("fa-angle-down");
- } else {
- $tree.slideUp("fast");
- $this.removeClass("fa-angle-right fa-angle-down").addClass("fa-angle-right");
- }
- });
-
- //-----------------------------
- // contextmenu shareNotebooks
- // 删除共享笔记本
- var shareNotebookMenu = {
- width: 180,
- items: [
- { text: getMsg("deleteSharedNotebook"), icon: "", faIcon: "fa-trash-o", action: Share.deleteShareNotebook }
- ],
- onShow: applyrule,
- onContextMenu: beforeContextMenu,
-
- parent: "#shareNotebooks",
- children: ".notebook-item",
- };
- function applyrule(menu) {
- return;
- }
- // 默认共享不能删除
- function beforeContextMenu() {
- var notebookId = $(this).attr("notebookId");
- return !Share.isDefaultNotebookId(notebookId);
- }
-
- var menuNotebooks = $("#shareNotebooks").contextmenu(shareNotebookMenu);
-
- //---------------------------
- // contextmenu shareNotebooks
- // 删除某用户所有的
- var shareUserMenu = {
- width: 180,
- items: [
- { text: getMsg("deleteAllShared"), icon: "", faIcon: "fa-trash-o", action: Share.deleteUserShareNoteAndNotebook }
- ],
- parent: "#shareNotebooks",
- children: ".friend-header",
- };
-
- var menuUser = $("#shareNotebooks").contextmenu(shareUserMenu);
-
- $(".friend-header").on("click", ".notebook-setting", function(e) {
- e.preventDefault();
- e.stopPropagation();
- var $p = $(this).parent();
- menuUser.showMenu(e, $p);
- });
- $("#shareNotebooks .notebook-item").on("click", ".notebook-setting", function(e) {
- e.preventDefault();
- e.stopPropagation();
- var $p = $(this).parent();
- menuNotebooks.showMenu(e, $p);
- });
-};
-
-Share.isDefaultNotebookId = function(notebookId) {
- return Share.defaultNotebookId == notebookId;
-}
-
-// 转成共享的nav
-// for list和for new
-// 如果forNew没有, 那么还是保持我的nav
-Share.toggleToSharedNav = function(userId, notebookId) {
- var self = this;
- // for list
- $("#curNotebookForListNote").html(Share.notebookCache[notebookId].Title + '(' + Share.sharedUserInfos[userId].Username + ")");
-
- // for new
- // 如果该用户下有新建的note, 那么列出, 如果没有, 则列出我的笔记
- var forNew = Share.userNavs[userId].forNew;
- if(forNew) {
- $("#notebookNavForNewSharedNote").html(forNew);
- // 新建之, 可能当前选择的没有权限新建. 此时需要得到第一个
- var curNotebookId = "";
- var curNotebookTitle = "";
- if(Share.notebookCache[notebookId].Perm) {
- curNotebookId = notebookId;
- curNotebookTitle = Share.notebookCache[notebookId].Title;
- } else {
- // 得到第一个
- var $f = $("#notebookNavForNewSharedNote li").eq(0);
- curNotebookId = $f.attr("notebookId");
- curNotebookTitle = $f.find(".new-note-left").text();
- }
-
- $("#curNotebookForNewSharedNote").html(curNotebookTitle + '(' + Share.sharedUserInfos[userId].Username + ')');
- $("#curNotebookForNewSharedNote").attr("notebookId", curNotebookId);
- $("#curNotebookForNewSharedNote").attr("userId", userId);
-
- $("#newSharedNote").show();
- $("#newMyNote").hide();
-
- } else {
- // 展示出我的笔记
- $("#newMyNote").show();
- $("#newSharedNote").hide();
- }
-
- // 隐藏tag
- $("#tagSearch").hide();
-}
-
-//改变笔记本
-//0. 改变样式
-//1. 改变note, 此时需要先保存
-//2. ajax得到该notebook下的所有note
-//3. 使用Note.RederNotes()
-Share.changeNotebook = function(userId, notebookId) {
- // 选中
- Notebook.selectNotebook($(tt('#friendContainer_? a[notebookId="?"]', userId, notebookId)));
-
- // 改变nav!!!! TODO
- Share.toggleToSharedNav(userId, notebookId);
-
- // 1
- Note.curChangedSaveIt();
-
- // 2 先清空所有
- Note.clearAll();
-
- var url = "/share/ListShareNotes/";
- var param = {userId: userId};
- if(!Share.isDefaultNotebookId(notebookId)) {
- param.notebookId = notebookId;
- }
-
- // 2 得到笔记本
- // 这里可以缓存起来, note按notebookId缓存
- ajaxGet(url, param, function(ret) {
- // note 导航
- //
- // 如果是特定笔记本下的notes, 那么传过来的没有权限信息, 此时权限由notebookId决定
- if(param.notebookId) {
-
- }
- Note.renderNotes(ret, false, true);
- // 渲染第一个
- // 这里, 有点小复杂, 还要判断权限...
- if(!isEmpty(ret)) {
- // 定位
- Note.changeNote(ret[0].NoteId, true);
- } else {
- }
- });
-}
-
-// 是否有更新权限
-// called by Note
-Share.hasUpdatePerm = function(notebookId) {
- var note = Share.cache[notebookId];
- if(!note || !note.Perm) {
- return false;
- }
- return true;
-}
-
-//---------------------------
-// 我删除别人共享给我的笔记本
-Share.deleteShareNotebook = function(target) {
- if(confirm("Are you sure to delete it?")) {
- var notebookId = $(target).attr("notebookId");
- var fromUserId = $(target).closest(".friend-notebooks").attr("fromUserId"); // 谁共享给了我 from
- ajaxGet("/share/DeleteShareNotebookBySharedUser", {notebookId: notebookId, fromUserId: fromUserId}, function(ret) {
- if(ret) {
- $(target).parent().remove();
- }
- });
- }
-}
-Share.deleteShareNote = function(target) {
- var noteId = $(target).attr("noteId");
- var fromUserId = $(target).attr("fromUserId"); // 谁共享给了我 from
- ajaxGet("/share/DeleteShareNoteBySharedUser", {noteId: noteId, fromUserId: fromUserId}, function(ret) {
- if(ret) {
- $(target).remove();
- }
- });
-}
-Share.deleteUserShareNoteAndNotebook = function(target) {
- if(confirm("Are you sure to delete all shared notebooks and notes?")) {
- var fromUserId = $(target).attr("fromUserId"); // 谁共享给了我 from
- ajaxGet("/share/deleteUserShareNoteAndNotebook", {fromUserId: fromUserId}, function(ret) {
- if(ret) {
- $(target).parent().remove();
- }
- });
- }
-}
-
-// 新建shared note
-Share.changeNotebookForNewNote = function(notebookId) {
- // 改变nav for list, for new
- Notebook.selectNotebook($(tt('#shareNotebooks [notebookId="?"]', notebookId)));
- var userId = Share.notebookCache[notebookId].UserId;
- Share.toggleToSharedNav(userId, notebookId);
-
- // 得到笔记本
- var url = "/share/ListShareNotes/";
- var param = {userId: userId, notebookId: notebookId};
-
- // 2 得到笔记本
- // 这里可以缓存起来, note按notebookId缓存
- ajaxGet(url, param, function(ret) {
- // note 导航
- Note.renderNotes(ret, true, true);
- });
-}
-
-// 删除笔记, 我有权限, 且是我创建的笔记
-Share.deleteSharedNote = function(target, contextmenuItem) {
- Note.deleteNote(target, contextmenuItem, true);
-}
-Share.copySharedNote = function(target, contextmenuItem) {
- Note.copyNote(target, contextmenuItem, true);
-}
-
-Share.contextmenu = null;
-Share.initContextmenu = function(notebooksCopy) {
- if(Share.contextmenu) {
- Share.contextmenu.destroy();
- }
-
- //---------------------
- // context menu
- //---------------------
- var noteListMenu = {
- width: 180,
- items: [
- { text: getMsg("copyToMyNotebook"), alias: "copy", faIcon: "fa-copy",
- type: "group",
- width: 180,
- items: notebooksCopy
- },
- { type: "splitLine" },
- { text: getMsg("delete"), alias: "delete", icon: "", faIcon: "fa-trash-o", action: Share.deleteSharedNote }
- ],
- onShow: applyrule,
- parent: "#noteItemList",
- children: ".item-shared",
- }
- function applyrule(menu) {
- var noteId = $(this).attr("noteId");
- var note = Share.cache[noteId];
- if(!note) {
- return;
- }
- var items = [];
- if(!(note.Perm && note.CreatedUserId == UserInfo.UserId)) {
- items.push("delete");
- }
- // 不是自己的创建的不能删除
- menu.applyrule({
- name: "target...",
- disable: true,
- items: items
- });
-
- }
-
- Share.contextmenu = $("#noteItemList .item-shared").contextmenu(noteListMenu);
-}
-
-$(function() {
- // note setting
- $("#noteItemList").on("click", ".item-shared .item-setting", function(e) {
- e.preventDefault();
- e.stopPropagation();
- // 得到ID
- var $p = $(this).parent();
- Share.contextmenu.showMenu(e, $p);
- });
-
-
-
- //---------------------------
- // 新建笔记
- // 1. 直接点击新建 OR
- // 2. 点击nav for new note
- $("#newSharedNoteBtn").click(function() {
- var notebookId = $("#curNotebookForNewSharedNote").attr('notebookId');
- var userId = $("#curNotebookForNewSharedNote").attr('userId');
- Note.newNote(notebookId, true, userId);
- });
- $("#newShareNoteMarkdownBtn").click(function() {
- var notebookId = $("#curNotebookForNewSharedNote").attr('notebookId');
- var userId = $("#curNotebookForNewSharedNote").attr('userId');
- Note.newNote(notebookId, true, userId, true);
- });
- $("#notebookNavForNewSharedNote").on("click", "li div", function() {
- var notebookId = $(this).parent().attr("notebookId");
- var userId = $(this).parent().attr("userId");
-
- if($(this).text() == "M") {
- Note.newNote(notebookId, true, userId, true);
- } else {
- Note.newNote(notebookId, true, userId);
- }
- });
-
- //------------------
- // 添加共享
- $("#leanoteDialogRemote").on("click", ".change-perm", function() {
- var self = this;
- var perm = $(this).attr("perm");
- var noteOrNotebookId = $(this).attr("noteOrNotebookId");
- var toUserId = $(this).attr("toUserId");
- var toHtml = getMsg("writable");
- var toPerm = "1";
- if(perm == "1") {
- toHtml = getMsg("readOnly");
- toPerm = "0";
- }
- var url = "/share/UpdateShareNotebookPerm";
- var param = {perm: toPerm, toUserId: toUserId};
- if(Share.dialogIsNote) {
- url = "/share/UpdateShareNotePerm";
- param.noteId = noteOrNotebookId;
- } else {
- param.notebookId = noteOrNotebookId;
- }
- ajaxGet(url, param, function(ret) {
- if(ret) {
- $(self).html(toHtml);
- $(self).attr("perm", toPerm);
- }
- });
- });
-
- $("#leanoteDialogRemote").on("click", ".delete-share", function() {
- var self = this;
- var noteOrNotebookId = $(this).attr("noteOrNotebookId");
- var toUserId = $(this).attr("toUserId");
-
- var url = "/share/DeleteShareNotebook";
- var param = {toUserId: toUserId};
- if(Share.dialogIsNote) {
- url = "/share/DeleteShareNote";
- param.noteId = noteOrNotebookId;
- } else {
- param.notebookId = noteOrNotebookId;
- }
-
- ajaxGet(url, param, function(ret) {
- if(ret) {
- $(self).parent().parent().remove();
- }
- });
- });
-
- // 添加共享
- var seq = 1;
- $("#leanoteDialogRemote").on("click", "#addShareNotebookBtn", function() {
- seq++;
- var tpl = '
# ';
- tpl += ' ' + getMsg('readOnly') + ' ';
- tpl += ' ' + getMsg('writable') + ' ';
- tpl += '' + getMsg('share') + ' ';
- tpl += ' ' + getMsg("delete") + ' ';
- tpl += "";
- $("#shareNotebookTable tbody").prepend(tpl);
-
- $("#tr" + seq + " #friendsEmail").focus();
- });
-
- //-------------------
- // 发送邀请邮件
- $("#registerEmailBtn").click(function() {
- var content = $("#emailContent").val();
- var toEmail = $("#toEmail").val();
- if(!content) {
- showAlert("#registerEmailMsg", getMsg("emailBodyRequired"), "danger");
- return;
- }
- post("/user/sendRegisterEmail", {content: content, toEmail: toEmail}, function(ret) {
- showAlert("#registerEmailMsg", getMsg("sendSuccess"), "success");
- hideDialog2("#sendRegisterEmailDialog", 1000);
- }, this);
- });
-});
-
-// trSeq 1,2,3...
-function addShareNoteOrNotebook(trSeq) {
- var trId = "#tr" + trSeq;
- var id = Share.dialogNoteOrNotebookId;
-
- var emails = isEmailFromInput(trId + " #friendsEmail", "#shareMsg", getMsg("inputFriendEmail"));
- if(!emails) {
- return;
- }
- var shareNotePerm = $(trId + ' input[name="perm' + trSeq + '"]:checked').val() || 0;
- var perm = shareNotePerm;
- // emails = emails.split(";");
- var url = "share/addShareNote";
- var data = {noteId: id, emails: [emails], perm: shareNotePerm};
- if(!Share.dialogIsNote) {
- url = "share/addShareNotebook";
- data = {notebookId: id, emails: [emails], perm: shareNotePerm};
- }
- hideAlert("#shareMsg");
- post(url, data, function(ret) {
- var ret = ret[emails];
- if(ret) {
- // 成功
- // 成功了则去掉输入框
- if(ret.Ok) {
- var tpl = tt('
? ', '#');
- tpl += tt('
? ', emails);
- tpl += tt('
? ', id, perm, ret.Id, !perm || perm == '0' ? getMsg("readOnly") : getMsg("writable"));
- tpl += tt('
' + getMsg("delete") +' ', id, ret.Id);
- $(trId).html(tpl);
- } else {
- var shareUrl = UrlPrefix + '/register?from=' + UserInfo.Username;
- showAlert("#shareMsg", getMsg('friendNotExits', [getMsg("app"), shareUrl]) + '
' + getMsg("clickToCopy") + ' ' + getMsg("sendInviteEmailToYourFriend") + ',
' + getMsg("send"), "warning");
- $("#copyDiv").text(shareUrl);
- initCopy("shareCopy", function(args) {
- if(args.text) {
- showMsg2("#copyStatus", getMsg("copySuccess"), 1000);
- } else {
- showMsg2("#copyStatus", getMsg("copyFailed"), 1000);
- }
- });
- }
- }
- }, trId + " .btn-success");
-}
-
-// 发送邀请邮件
-function sendRegisterEmail(email) {
- showDialog2("#sendRegisterEmailDialog", {postShow: function() {
- $("#emailContent").val(getMsg("inviteEmailBody", [UserInfo.Username, getMsg("app")]));
- setTimeout(function() {
- $("#emailContent").focus();
- }, 500);
- $("#toEmail").val(email);
- }});
-}
-
-function deleteShareNoteOrNotebook(trSeq) {
- $("#tr" + trSeq).remove();
-}
diff --git a/public/js/app/tag-min.js b/public/js/app/tag-min.js
deleted file mode 100644
index 0b50a63..0000000
--- a/public/js/app/tag-min.js
+++ /dev/null
@@ -1 +0,0 @@
-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,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,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=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
diff --git a/public/js/app/tag.js b/public/js/app/tag.js
deleted file mode 100644
index 0a8c27f..0000000
--- a/public/js/app/tag.js
+++ /dev/null
@@ -1,300 +0,0 @@
-// Tag
-
-// 蓝色, 红色怎么存到数据库中? 直接存蓝色
-
-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"
-}
-
-// 数据库中统一存En
-Tag.mapCn2En = {
- "蓝色": "blue",
- "红色": "red",
- "绿色": "green",
- "黄色": "yellow",
-}
-Tag.mapEn2Cn = {
- "blue": "蓝色",
- "red": "红色",
- "green": "绿色",
- "yellow": "黄色",
-}
-
-Tag.t = $("#tags");
-
-// called by Note
-Tag.getTags = function() {
- var tags = [];
- Tag.t.children().each(function(){
- var text = $(this).text();
- text = text.substring(0, text.length - 1); // 把X去掉
- text = Tag.mapCn2En[text] || text;
- tags.push(text);
- });
- // 需要去重吗? 正常情况下不会重复
- return tags;
-}
-
-// called by Note
-Tag.clearTags = function() {
- Tag.t.html("");
-}
-
-// 设置tags
-// called by Note
-Tag.renderTags = function(tags) {
- Tag.t.html("");
- if(isEmpty(tags)) {
- return;
- }
- // TODO 重构, 这样不高效
- for(var i = 0; i < tags.length; ++i) {
- var tag = tags[i];
- Tag.appendTag(tag);
- }
-}
-
-// tag最初状态
-function revertTagStatus() {
- $("#addTagTrigger").show();
- $("#addTagInput").hide();
- // hideTagList();
-}
-
-function hideTagList(event) {
- $("#tagDropdown").removeClass("open");
- if (event) {
- event.stopPropagation()
- }
-}
-function showTagList(event) {
- $("#tagDropdown").addClass("open");
- if (event) {
- event.stopPropagation()
- }
-}
-
-// 只读模式下显示tags
-// called by Note
-Tag.renderReadOnlyTags = function(tags) {
- // 先清空
- $("#noteReadTags").html("");
- if(isEmpty(tags)) {
- $("#noteReadTags").html(getMsg("noTag"));
- }
-
- var i = true;
- function getNextDefaultClasses() {
- if (i) {
- return "label label-default";
- i = false
- } else {
- i = true;
- return "label label-info";
- }
- }
-
- 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, text);
-
- $("#noteReadTags").append(tag);
- }
-}
-
-// 添加tag
-// tag = {classes:"label label-red", text:"红色"}
-// tag = life
-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, 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();
- }
-}
-
-// 为了颜色间隔, add, delete时调用
-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++;
- }
- });
-}
-
-//-----------
-// 左侧nav en -> cn
-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 = Tag.mapEn2Cn[tag] || tag;
- var classes = Tag.classes[tag] || "label label-default";
- $("#tagNav").append(tt(' ? ', text, classes, text));
- }
-}
-
-
-// 事件
-$(function() {
- // tag
- $("#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();
- // revertTagStatus();
- });
- $('#addTagInput').keydown(function(e) {
- if (e.keyCode == 13) {
- hideTagList();
- // 如果有值, 再生成, 没值直接隐藏
- if ($("#addTagInput").val()) {
- $(this).trigger("blur");
- $("#addTagTrigger").trigger("click");
- } else {
- $(this).trigger("blur");
- }
- }
- });
- // 点击下拉时也会触发input的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()
- });
- });
- // 这是个问题, 为什么? 捕获不了事件?, input的blur造成
- /*
- $(".label").click(function(event) {
- var a = $(this);
- Tag.appendTag({
- classes : a.attr("class"),
- text : a.text()
- });
- // event.stopPropagation();
- });
- */
-
- $("#tags").on("click", "i", function() {
- $(this).parent().remove();
- reRenderTags();
- });
-
- //-------------
- // nav 标签搜索
- function searchTag() {
- var tag = $.trim($(this).data("tag"));
- // tag = Tag.mapCn2En[tag] || tag;
-
- // 学习changeNotebook
-
- // 1
- Note.curChangedSaveIt();
-
- // 2 先清空所有
- // 也会把curNoteId清空
- Note.clearAll();
-
- $("#tagSearch").html($(this).html()).show();
- showLoading();
- ajaxGet("/note/searchNoteByTags", {tags: [tag]}, function(notes) {
- hideLoading();
- if(notes) {
- // 和note搜索一样
- // 设空, 防止发生上述情况
- // Note.curNoteId = "";
-
- 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