笔记信息, 历史记录, 提示, 附件优化

https://github.com/leanote/leanote/issues/224
This commit is contained in:
lealife
2015-10-10 16:10:54 +08:00
parent 274875c6c4
commit 320263eefa
58 changed files with 2078 additions and 5398 deletions

View File

@ -1 +0,0 @@
var urlPrefix=UrlPrefix;define("attachment_upload",["jquery.ui.widget","fileupload"],function(){function formatFileSize(bytes){if(typeof bytes!=="number"){return""}if(bytes>=1e9){return(bytes/1e9).toFixed(2)+" GB"}if(bytes>=1e6){return(bytes/1e6).toFixed(2)+" MB"}return(bytes/1e3).toFixed(2)+" KB"}function setDropStyle(dropzoneId,formId){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");$("#uploadAttach").fileupload({dataType:"json",pasteZone:"",dropZone:$("#dropAttach"),formData:function(form){return[{name:"noteId",value:Note.curNoteId}]},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=$('<div class="alert alert-info"><img class="loader" src="/tinymce/plugins/leaui_image/public/images/ajax-loader.gif"> <a class="close" data-dismiss="alert">×</a></div>');tpl.append(data.files[0].name+" <small>[<i>"+formatFileSize(data.files[0].size)+"</i>]</small>");$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),3e3);return}var jqXHR;setTimeout(function(){jqXHR=data.submit()},10)},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=$('<div class="alert alert-danger"><a class="close" data-dismiss="alert">×</a></div>');tpl.append("<b>Error:</b> "+data.files[0].name+" <small>[<i>"+formatFileSize(data.files[0].size)+"</i>]</small> "+data.result.Msg);data.context.html(tpl);setTimeout(function(tpl){return function(){tpl.remove()}}(tpl),3e3)}$("#uploadAttachMsg").scrollTop(1e3)},fail:function(e,data){data.context.html("");var tpl=$('<div class="alert alert-danger"><a class="close" data-dismiss="alert">×</a></div>');tpl.append("<b>Error:</b> "+data.files[0].name+" <small>[<i>"+formatFileSize(data.files[0].size)+"</i>]</small> "+data.errorThrown);data.context.html(tpl);setTimeout(function(tpl){return function(){tpl.remove()}}(tpl),3e3);$("#uploadAttachMsg").scrollTop(1e3)}});var $msg2=$("#avatarUploadMsg");$("#uploadAvatar").fileupload({dataType:"json",dropZone:$("#dropAvatar"),pasteZone:"",add:function(e,data){var tpl=$('<div class="alert alert-info"><img class="loader" src="/tinymce/plugins/leaui_image/public/images/ajax-loader.gif"> <a class="close" data-dismiss="alert">×</a></div>');tpl.append(data.files[0].name+" <small>[<i>"+formatFileSize(data.files[0].size)+"</i>]</small>");$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),3e3);return}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=$('<div class="alert alert-danger"><a class="close" data-dismiss="alert">×</a></div>');tpl.append("<b>Error:</b> "+data.files[0].name+" <small>[<i>"+formatFileSize(data.files[0].size)+"</i>]</small> "+data.result.Msg);data.context.html(tpl);setTimeout(function(tpl){return function(){tpl.remove()}}(tpl),3e3)}},fail:function(e,data){data.context.html("");var tpl=$('<div class="alert alert-danger"><a class="close" data-dismiss="alert">×</a></div>');tpl.append("<b>Error:</b> "+data.files[0].name+" <small>[<i>"+formatFileSize(data.files[0].size)+"</i>]</small> "+data.errorThrown);data.context.html(tpl);setTimeout(function(tpl){return function(){tpl.remove()}}(tpl),3e3)}})};initUploader()});

View File

@ -1,216 +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',
pasteZone: '', // 不能通过paste来上传图片
// 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 = $('<div class="alert alert-info"><img class="loader" src="/tinymce/plugins/leaui_image/public/images/ajax-loader.gif"> <a class="close" data-dismiss="alert">×</a></div>');
// Append the file name and file size
tpl.append(data.files[0].name + ' <small>[<i>' + formatFileSize(data.files[0].size) + '</i>]</small>');
// 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 = $('<div class="alert alert-danger"><a class="close" data-dismiss="alert">×</a></div>');
tpl.append('<b>Error:</b> ' + data.files[0].name + ' <small>[<i>' + formatFileSize(data.files[0].size) + '</i>]</small> ' + 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 = $('<div class="alert alert-danger"><a class="close" data-dismiss="alert">×</a></div>');
tpl.append('<b>Error:</b> ' + data.files[0].name + ' <small>[<i>' + formatFileSize(data.files[0].size) + '</i>]</small> ' + data.errorThrown);
data.context.html(tpl);
setTimeout((function(tpl) {
return function() {
tpl.remove();
}
})(tpl), 3000);
$("#uploadAttachMsg").scrollTop(1000);
}
});
//-------------------
// 已经过时, 没有avatar了
var $msg2 = $('#avatarUploadMsg');
$('#uploadAvatar').fileupload({
dataType: 'json',
dropZone: $('#dropAvatar'),
pasteZone: '',
add: function(e, data) {
var tpl = $('<div class="alert alert-info"><img class="loader" src="/tinymce/plugins/leaui_image/public/images/ajax-loader.gif"> <a class="close" data-dismiss="alert">×</a></div>');
// Append the file name and file size
tpl.append(data.files[0].name + ' <small>[<i>' + formatFileSize(data.files[0].size) + '</i>]</small>');
// 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 = $('<div class="alert alert-danger"><a class="close" data-dismiss="alert">×</a></div>');
tpl.append('<b>Error:</b> ' + data.files[0].name + ' <small>[<i>' + formatFileSize(data.files[0].size) + '</i>]</small> ' + 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 = $('<div class="alert alert-danger"><a class="close" data-dismiss="alert">×</a></div>');
tpl.append('<b>Error:</b> ' + data.files[0].name + ' <small>[<i>' + formatFileSize(data.files[0].size) + '</i>]</small> ' + data.errorThrown);
data.context.html(tpl);
setTimeout((function(tpl) {
return function() {
tpl.remove();
}
})(tpl), 3000);
}
});
};
initUploader();
});

File diff suppressed because one or more lines are too long

View File

@ -1,375 +0,0 @@
// for editor.
// drag image to editor
var urlPrefix = UrlPrefix; // window.location.protocol + "//" + window.location.host;
define('editor_drop_paste', ['jquery.ui.widget', 'fileupload'], function(){
function Process(editor) {
var id = '__mcenew' + (new Date()).getTime();
var str = '<div contenteditable="false" id="' + id + '" class="leanote-image-container">' +
'<img class="loader" src="/images/ajax-loader.gif">' +
'<div class="progress">' +
'<div class="progress-bar progress-bar-success progress-bar-striped" role="progressbar" aria-valuenow="2" aria-valuemin="0" aria-valuemax="100" style="width: 0%;">' +
'0%' +
'</div>' +
'</div>' +
'</div>';
this.containerStr = str;
editor.insertContent(str);
var container = $('#' + id);
this.container = container;
this.id = id;
this.processBar = container.find('.progress-bar');
}
Process.prototype.update = function(process) {
var me = this;
// 98%, 不要小数
process = Math.ceil(process * 100);
if(process >= 100) {
process = 99;
}
process += "%";
$('#' + me.id + ' .progress-bar').html(process).css('width', process);
}
Process.prototype.replace = function(src) {
var me = this;
getImageSize(src, function() {
$('#' + me.id).replaceWith('<img src="' + src + '" />');
});
}
Process.prototype.remove = function() {
var me = this;
$('#' + me.id).remove();
}
// 当url改变时, 得到图片的大小
function getImageSize(url, callback) {
var img = document.createElement('img');
function done(width, height) {
img.parentNode.removeChild(img);
callback({width: width, height: height});
}
img.onload = function() {
done(img.clientWidth, img.clientHeight);
};
img.onerror = function() {
done();
};
img.src = url;
var style = img.style;
style.visibility = 'hidden';
style.position = 'fixed';
style.bottom = style.left = 0;
style.width = style.height = 'auto';
document.body.appendChild(img);
}
var i = 1;
function insertImage(data) {
var editor = tinymce.activeEditor;
var dom = editor.dom;
var renderImage = function(data2) {
// 这里, 如果图片宽度过大, 这里设置成500px
var d = {};
var imgElm;
// 先显示loading...
d.id = '__mcenew' + (i++);
d.src = "http://leanote.com/images/loading-24.gif";
imgElm = dom.createHTML('img', d);
tinymce.activeEditor.insertContent(imgElm);
imgElm = dom.get(d.id);
function callback (wh) {
dom.setAttrib(imgElm, 'src', data2.src);
// dom.setAttrib(imgElm, 'width', data2.width);
if(data2.title) {
dom.setAttrib(imgElm, 'title', data2.title);
}
dom.setAttrib(imgElm, 'id', null);
};
getImageSize(data.src, callback);
}
//-------------
// outputImage?fileId=123232323
var fileId = "";
fileIds = data.src.split("fileId=")
if(fileIds.length == 2 && fileIds[1].length == "53aecf8a8a039a43c8036282".length) {
fileId = fileIds[1];
}
if(fileId) {
// 得到fileId, 如果这个笔记不是我的, 那么肯定是协作的笔记, 那么需要将图片copy给原note owner
var curNote = Note.getCurNote();
if(curNote && curNote.UserId != UserInfo.UserId) {
(function(data) {
ajaxPost("/file/copyImage", {userId: UserInfo.UserId, fileId: fileId, toUserId: curNote.UserId}, function(re) {
if(reIsOk(re) && re.Id) {
var urlPrefix = window.location.protocol + "//" + window.location.host;
data.src = urlPrefix + "/file/outputImage?fileId=" + re.Id;
}
renderImage(data);
});
})(data);
} else {
renderImage(data);
}
} else {
renderImage(data);
}
}
var initUploader = function() {
var ul = $('#upload ul');
$('#drop a').click(function() {
// trigger to show file select
$(this).parent().find('input').click();
});
// Initialize the jQuery File Upload plugin
$('#upload').fileupload({
dataType: 'json',
pasteZone: '', // 不允许paste
acceptFileTypes: /(\.|\/)(gif|jpg|jpeg|png|jpe)$/i,
maxFileSize: 210000,
// This element will accept file drag/drop uploading
dropZone: $('#drop'),
formData: function(form) {
return [{name: 'albumId', value: ""}]
},
// 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 tpl = $('<li><div class="alert alert-info"><img class="loader" src="/tinymce/plugins/leaui_image/public/images/ajax-loader.gif"> <a class="close" data-dismiss="alert">×</a></div></li>');
// Append the file name and file size
tpl.find('div').append(data.files[0].name + ' <small>[<i>' + formatFileSize(data.files[0].size) + '</i>]</small>');
// Add the HTML to the UL element
data.context = tpl.appendTo(ul);
// data.form[0].action += "&album_id=" + $("#albumsForUpload").val();
// Automatically upload the file once it is added to the queue
var jqXHR = data.submit();
},
done: function(e, data) {
if (data.result.Ok == true) {
data.context.remove();
// life
var data2 = {src: urlPrefix + "/file/outputImage?fileId=" + data.result.Id}
insertImage(data2);
} else {
data.context.empty();
var tpl = $('<li><div class="alert alert-danger"><a class="close" data-dismiss="alert">×</a></div></li>');
tpl.find('div').append('<b>Error:</b> ' + data.files[0].name + ' <small>[<i>' + formatFileSize(data.files[0].size) + '</i>]</small> ' + data.result.Msg);
data.context.append(tpl);
setTimeout((function(tpl) {
return function() {
tpl.remove();
}
})(tpl), 2000);
}
$("#uploadMsg").scrollTop(1000);
},
fail: function(e, data) {
data.context.empty();
var tpl = $('<li><div class="alert alert-danger"><a class="close" data-dismiss="alert">×</a></div></li>');
tpl.find('div').append('<b>Error:</b> ' + data.files[0].name + ' <small>[<i>' + formatFileSize(data.files[0].size) + '</i>]</small> ' + data.errorThrown);
data.context.append(tpl);
setTimeout((function(tpl) {
return function() {
tpl.remove();
}
})(tpl), 2000);
$("#uploadMsg").scrollTop(1000);
}
});
// Prevent the default action when a file is dropped on the window
$(document).on('drop dragover', function(e) {
e.preventDefault();
});
// 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 showUpload() {
$("#upload").css("z-index", 12);
var top = +$("#mceToolbar").css("height").slice(0, -2); // px
$("#upload").css("top", top - 8);
$("#upload").show();
}
function hideUpload() {
$("#upload").css("z-index", 0).css("top", "auto").hide();
}
// drag css
$(document).bind('dragover', function (e) {
var dropZone = $('#drop'),
timeout = window.dropZoneTimeout;
if (!timeout) {
dropZone.addClass('in');
showUpload();
} else {
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.dropZoneTimeout = setTimeout(function () {
window.dropZoneTimeout = null;
dropZone.removeClass('in hover');
hideUpload();
}, 100);
});
};
// pasteImage
var pasteImageInit = function() {
// Initialize the jQuery File Upload plugin
var dom, editor;
$('#editorContent').fileupload({
dataType: 'json',
pasteZone: $('#editorContent'),
dropZone: '', // 只允许paste
maxFileSize: 210000,
url: "/file/pasteImage",
paramName: 'file',
formData: function(form) {
return [{name: 'from', value: 'pasteImage'}, {name: 'noteId', value: Note.curNoteId}]
},
/*
paste: function(e, data) {
var jqXHR = data.submit();
},
*/
progress: function(e, data) {
data.process.update(data.loaded / data.total);
},
add: function(e, data) {
var note = Note.getCurNote();
if(!note || note.IsNew) {
alert("This note hasn't saved, please save it firstly!")
return;
}
// 先显示loading...
editor = tinymce.EditorManager.activeEditor;
var process = new Process(editor);
data.process = process;
var jqXHR = data.submit();
/*
d.id = '__mcenew' + (new Date()).getTime();
d.src = "http://leanote.com/images/loading-24.gif"; // 写死了
var img = '<img src="' + d.src + '" id="' + d.id + '" />';
editor.insertContent(img);
var imgElm = $(d.id);
data.imgId = d.id;
data.context = imgElm;
*/
/*
// 上传之
var c = new FormData;
c.append("from", "pasteImage");
// var d;
// d = $.ajaxSettings.xhr();
// d.withCredentials = i;var d = {};
// 先显示loading...
var editor = tinymce.EditorManager.activeEditor;
var dom = editor.dom;
var d = {};
d.id = '__mcenew';
d.src = "http://leanote.com/images/loading-24.gif"; // 写死了
editor.insertContent(dom.createHTML('img', d));
var imgElm = dom.get('__mcenew');
$.ajax({url: "/file/pasteImage", contentType:false, processData:false , data: c, type: "POST"}
).done(function(re) {
if(!re || typeof re != "object" || !re.Ok) {
// 删除
dom.remove(imgElm);
return;
}
// 这里, 如果图片宽度过大, 这里设置成500px
var urlPrefix = UrlPrefix; // window.location.protocol + "//" + window.location.host;
var src = urlPrefix + "/file/outputImage?fileId=" + re.Id;
getImageSize(src, function(wh) {
// life 4/25
if(wh && wh.width) {
if(wh.width > 600) {
wh.width = 600;
}
d.width = wh.width;
dom.setAttrib(imgElm, 'width', d.width);
}
dom.setAttrib(imgElm, 'src', src);
});
dom.setAttrib(imgElm, 'id', null);
});
};
reader.readAsDataURL(blob);
*/
},
done: function(e, data) {
if (data.result.Ok == true) {
// 这里, 如果图片宽度过大, 这里设置成500px
var re = data.result;
var urlPrefix = UrlPrefix; // window.location.protocol + "//" + window.location.host;
var src = urlPrefix + "/file/outputImage?fileId=" + re.Id;
data.process.replace(src);
/*
getImageSize(src, function() {
$img.attr('src', src);
$img.removeAttr('id');
});
*/
} else {
data.process.remove();
}
},
fail: function(e, data) {
data.process.remove();
}
});
};
initUploader();
pasteImageInit();
});

View File

@ -61,9 +61,12 @@ Note.setNoteCache = function(content, clear) {
if(!Note.cache[content.NoteId]) {
Note.cache[content.NoteId] = content;
} else {
// console.log('pre');
// console.log(Note.cache[content.NoteId].IsBlog);
$.extend(Note.cache[content.NoteId], content);
// console.log(Note.cache[content.NoteId].IsBlog);
}
if(clear == undefined) {
clear = true;
}
@ -228,7 +231,7 @@ Note.curHasChanged = function(force) {
} catch(e) {
}
}
var hasChanged = {
hasChanged: false, // 总的是否有改变
IsNew: cacheNote.IsNew, // 是否是新添加的
@ -238,11 +241,11 @@ Note.curHasChanged = function(force) {
NotebookId: cacheNote.NotebookId,
Version: cacheNote.Version || 0, // 版本控制
};
if(hasChanged.IsNew) {
$.extend(hasChanged, cacheNote);
} else {
if(!cacheNote.isDirty) {
if(!force && !cacheNote.isDirty) {
log("no dirty");
hasChanged.hasChanged = false;
return hasChanged;
@ -619,7 +622,10 @@ Note.changeNote = function(selectNoteId, isShare, needSaveChanged, callback) {
}
// 这里要切换编辑器
switchEditor(cacheNote.IsMarkdown)
switchEditor(cacheNote.IsMarkdown);
// 发送事件
LEA.trigger('noteChanged', cacheNote);
Attach.renderNoteAttachNum(selectNoteId, true);
@ -631,9 +637,9 @@ Note.changeNote = function(selectNoteId, isShare, needSaveChanged, callback) {
return;
}
Note.setNoteCache(ret, false);
// 把其它信息也带上
ret = Note.cache[selectNoteId]
Note.renderNoteContent(ret);
/* 都用editable的render
if(hasPerm) {
@ -651,7 +657,7 @@ Note.changeNote = function(selectNoteId, isShare, needSaveChanged, callback) {
setContent(cacheNote);
return;
}
var url = "/note/getNoteContent";
var param = {noteId: selectNoteId};
if(isShare) {
@ -663,7 +669,11 @@ Note.changeNote = function(selectNoteId, isShare, needSaveChanged, callback) {
if(Note.contentAjax != null) {
Note.contentAjax.abort();
}
Note.contentAjax = ajaxGet(url, param, setContent);
Note.contentAjax = ajaxGet(url, param, function (ret) {
// 因为之前Content内的IsBlog和Note的IsBlog不同步, 所以去掉Content中的IsBlog
delete ret['IsBlog'];
setContent(ret);
});
}
// 渲染
@ -1075,69 +1085,16 @@ Note.shareNote = function(target) {
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('<button type="button" class="btn btn-default" data-dismiss="modal">' + getMsg("close") + '</button>');
options = {}
options.show = true;
$("#leanoteDialog").modal(options);
ajaxGet("/noteContentHistory/listHistories", {noteId: Note.curNoteId}, function(re) {
if(!isArray(re)) {$content.html(getMsg("noHistories")); return}
// 组装成一个tab
var str = "<p>" + getMsg("historiesNum") + '</p><div id="historyList"><table class="table table-hover">';
note = Note.cache[Note.curNoteId];
var s = "div"
if(note.IsMarkdown) {
s = "pre";
}
for (i in re) {
var content = re[i]
content.Ab = Note.genAbstract(content.Content, 200);
// 为什么不用tt(), 因为content可能含??
str += '<tr><td seq="' + i + '">#' + (i+1) +'<' + s + ' class="each-content">' + content.Ab + '</' + s + '> <div class="btns">' + getMsg("datetime") + ': <span class="label label-default">' + goNowToDatetime(content.UpdatedTime) + '</span> <button class="btn btn-default all">' + getMsg("unfold") + '</button> <button class="btn btn-primary back">' + getMsg('restoreFromThisVersion') + '</button></div></td></tr>';
}
str += "</table></div>";
$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.download = function(url, params) {
var inputs = '';
for (var i in params) {
inputs += '<input name="' + i + '" value="' + params[i] + '">';
}
$('<form target="mdImageManager" action="' + url + '" method="GET">' + inputs + '</form>').appendTo('body').submit().remove();
};
//--------------
// read only
@ -1256,14 +1213,15 @@ Note.setNote2Blog = function(target) {
if(note.IsBlog != undefined) {
isBlog = !note.IsBlog;
}
// 标志添加/去掉
if(isBlog) {
$(target).find(".item-blog").show();
} else {
$(target).find(".item-blog").hide();
}
ajaxPost("/note/setNote2Blog", {noteId: noteId, isBlog: isBlog}, function(ret) {
if(ret) {
// 标志添加/去掉
if(isBlog) {
$(target).find(".item-blog").show();
} else {
$(target).find(".item-blog").hide();
}
Note.setNoteCache({NoteId: noteId, IsBlog: isBlog}, false); // 不清空NotesByNotebookId缓存
}
});
@ -1482,6 +1440,11 @@ Note.toggleWriteable = function() {
Note.readOnly = false;
};
Note.getPostUrl = function (note) {
var urlTitle = note.UrlTitle || note.NoteId;
return UserInfo.PostUrl + '/' + urlTitle;
};
// 这里速度不慢, 很快
Note.getContextNotebooks = function(notebooks) {
var moves = [];
@ -1578,6 +1541,8 @@ Note.initContextmenu = function() {
items.push("set2Blog");
items.push("copy");
} else {
// console.log('haha');
// console.log(note);
// 是否已公开为blog
if(!note.IsBlog) {
items.push("unset2Blog");
@ -1591,11 +1556,12 @@ Note.initContextmenu = function() {
items.push("copy." + notebookTitle);
}
// diable 这里
menu.applyrule({
name: "target..",
disable: true,
items: items
});
});
}
function beforeContextMenu() {
@ -1630,7 +1596,7 @@ var Attach = {
e.stopPropagation();
var attachId = $(this).closest('li').data("id");
var t = this;
if(confirm("Are you sure to delete it ?")) {
if(confirm(getMsg("Are you sure to delete it ?"))) {
$(t).button("loading");
ajaxPost("/attach/deleteAttach", {attachId: attachId}, function(re) {
$(t).button("reset");
@ -1646,21 +1612,20 @@ var Attach = {
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;
Note.download(UrlPrefix + "/attach/download", {attachId:attachId});
});
// 下载全部
self.downloadAllBtnO.click(function() {
window.open(UrlPrefix + "/attach/downloadAll?noteId=" + Note.curNoteId);
// location.href = "/attach/downloadAll?noteId=" + Note.curNoteId;
Note.download(UrlPrefix + "/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;
Note.toggleWriteable();
if(LEA.isMarkdownEditor() && MD) {
MD.insertLink(src, attach.Title);
} else {
@ -1668,8 +1633,9 @@ var Attach = {
tinymce.activeEditor.insertContent('<a target="_blank" href="' + src + '">' + attach.Title + '</a>');
}
});
// make all link
/*
self.linkAllBtnO.on("click",function(e) {
e.stopPropagation();
var note = Note.getCurNote();
@ -1685,6 +1651,7 @@ var Attach = {
tinymce.activeEditor.insertContent('<a target="_blank" href="' + src + '">' + title + '</a>');
}
});
*/
},
attachListO: $("#attachList"),
attachNumO: $("#attachNum"),
@ -1728,14 +1695,17 @@ var Attach = {
*/
var html = "";
var attachNum = attachs.length;
var titleDelete = getMsg('Delete');
var titleDownload = getMsg('Download');
var titleLink = getMsg('Insert link into content');
for(var i = 0; i < attachNum; ++i) {
var each = attachs[i];
html += '<li class="clearfix" data-id="' + each.AttachId + '">' +
'<div class="attach-title">' + each.Title + '</div>' +
'<div class="attach-process"> ' +
' <button class="btn btn-sm btn-warning delete-attach" data-loading-text="..."><i class="fa fa-trash-o"></i></button> ' +
' <button type="button" class="btn btn-sm btn-primary download-attach"><i class="fa fa-download"></i></button> ' +
' <button type="button" class="btn btn-sm btn-default link-attach" title="Insert link into content"><i class="fa fa-link"></i></button> ' +
' <button class="btn btn-sm btn-warning delete-attach" data-loading-text="..." title="' + titleDelete + '"><i class="fa fa-trash-o"></i></button> ' +
' <button type="button" class="btn btn-sm btn-primary download-attach" title="' + titleDownload + '"><i class="fa fa-download"></i></button> ' +
' <button type="button" class="btn btn-sm btn-default link-attach" title="' + titleLink + '"><i class="fa fa-link"></i></button> ' +
'</div>' +
'</li>';
self.attachsMap[each.AttachId] = each;
@ -1807,7 +1777,7 @@ var Attach = {
},
downloadAll: function() {
}
}
};
//------------------- 事件
$(function() {
@ -1824,7 +1794,9 @@ $(function() {
}
});
$("#noteItemList").on("click", ".item", function(event) {
event.stopPropagation();
// 为什么要stop, 这会导致context, dropdown不隐藏
// event.stopPropagation();
var noteId = $(this).attr("noteId");
// 手机端处理
@ -1839,7 +1811,7 @@ $(function() {
Note.changeNoteForPjax(noteId, true, false);
}
});
// 当前笔记可以已修改
$('#editorContent, #wmd-input, #noteTitle').on('keyup input', function() {
Note.curNoteIsDirtied();
@ -1849,7 +1821,7 @@ $(function() {
Note.curNoteIsDirtied();
});
*/
//------------------
// 新建笔记
// 1. 直接点击新建 OR
@ -1901,33 +1873,39 @@ $(function() {
//--------------------
// Note.initContextmenu();
//------------
// 文档历史
$("#contentHistory").click(function() {
Note.listNoteContentHistories()
});
$("#saveBtn").click(function() {
Note.curChangedSaveIt(true);
});
// blog
$("#noteItemList").on("click", ".item-blog", function(e) {
e.preventDefault();
// 这导致其它dropdown不能隐藏
e.stopPropagation();
// 所以
$(document).click();
// 得到ID
var noteId = $(this).parent().attr('noteId');
window.open("/blog/view/" + noteId);
var note = Note.getNote(noteId);
if (note) {
window.open(Note.getPostUrl(note));
}
});
// note setting
$("#noteItemList").on("click", ".item-my .item-setting", function(e) {
e.preventDefault();
// 这导致其它dropdown不能隐藏
e.stopPropagation();
// 所以
$(document).click();
var $p = $(this).parent();
Note.contextmenu.showMenu(e, $p);
});
// readony
// 修改
$('.toolbar-update').click(function() {

View File

@ -480,7 +480,8 @@ function initEditor() {
e.preventDefault();
return;
}
Note.saveNote(e);
// 这里就不要了, 避免两次updateNote
// Note.saveNote(e);
// 当输入的时候, 把当前raw删除掉
LeaAce.removeCurToggleRaw();
@ -511,12 +512,12 @@ function initEditor() {
"searchreplace leanote_nav leanote_code tabfocus",
"table textcolor" ], // nonbreaking directionality charmap
toolbar1 : "formatselect | forecolor backcolor | bold italic underline strikethrough | leaui_image | leanote_code leanote_inline_code | bullist numlist | alignleft aligncenter alignright alignjustify",
toolbar2 : "outdent indent blockquote | link unlink | table | hr removeformat | subscript superscript |searchreplace | pastetext pasteCopyImage | leanote_ace_pre | fontselect fontsizeselect",
toolbar2 : "outdent indent blockquote | link unlink | table | hr removeformat | subscript superscript |searchreplace | pastetext | leanote_ace_pre | 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,
@ -554,7 +555,7 @@ function initEditor() {
window.onbeforeunload = function(e) {
Note.curChangedSaveIt();
}
// 全局ctrl + s
$("body").on('keydown', Note.saveNote);
}
@ -813,12 +814,7 @@ function scrollTo(self, tagName, text) {
// $ul.css("max-height", getMaxDropdownHeight(this));
});
//--------
// 编辑器帮助
$("#tipsBtn").click(function() {
showDialog2("#tipsDialog");
});
/*
//--------
// 建议
$("#yourSuggestions").click(function() {
@ -843,6 +839,7 @@ function scrollTo(self, tagName, text) {
}
});
});
*/
// 编辑器模式
em.init();