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

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();

View File

@ -28,6 +28,54 @@ var MarkdownEditor;
var ScrollLink;
var MD;
//-------------
// 全局事件机制
$.extend(LEA, {
_eventCallbacks: {},
_listen: function(type, callback) {
var callbacks = this._eventCallbacks[type] || (this._eventCallbacks[type] = []);
callbacks.push(callback);
},
// on('a b', function(params) {})
on: function(name, callback) {
var names = name.split(/\s+/);
for (var i = 0; i < names.length; ++i) {
this._listen(names[i], callback);
}
return this;
},
// off('a b', function(params) {})
off: function(name, callback) {
var types = name.split(/\s+/);
var i, j, callbacks, removeIndex;
for (i = 0; i < types.length; i++) {
callbacks = this._eventCallbacks[types[i].toLowerCase()];
if (callbacks) {
removeIndex = null;
for (j = 0; j < callbacks.length; j++) {
if (callbacks[j] == callback) {
removeIndex = j;
}
}
if (removeIndex !== null) {
callbacks.splice(removeIndex, 1);
}
}
}
},
// LEA.trigger('a', {});
trigger: function(type, params) {
var callbacks = this._eventCallbacks[type] || [];
if (callbacks.length === 0) {
return;
}
for (var i = 0; i < callbacks.length; i++) {
callbacks[i].call(this, params);
}
}
});
//---------------------
// 公用方法
@ -829,10 +877,11 @@ function hideLoading() {
}
// 注销, 先清空cookie
function setCookie(c_name, value, expiredays){
function setCookie(c_name, value, expiredays) {
var exdate = new Date();
exdate.setDate(exdate.getDate() + expiredays);
document.cookie = c_name+ "=" + escape(value) + ((expiredays==null) ? "" : ";expires="+exdate.toGMTString());
document.cookie = c_name+ "=" + escape(value) + ((expiredays==null) ? "" : ";expires="+exdate.toGMTString()) + 'path=/';
document.cookie = c_name+ "=" + escape(value) + ((expiredays==null) ? "" : ";expires="+exdate.toGMTString()) + 'path=/note';
}
function logout() {
setCookie("LEANOTE_SESSION", '', -1);

View File

@ -0,0 +1 @@
.b-m-mpanel{background:url(images/contextmenu/menu_bg.gif) left repeat-y #fff;border:1px solid #ccc;position:absolute;padding:2px 0;z-index:99997;left:0;top:0;-webkit-box-shadow:0 6px 12px rgba(0,0,0,.175);box-shadow:0 6px 12px rgba(0,0,0,.175);background-clip:padding-box;overflow:auto}.b-m-split{height:6px;background:url(images/contextmenu/m_splitLine.gif) center repeat-x;font-size:0;margin:0 2px}.b-m-idisable,.b-m-ifocus,.b-m-item{padding:4px 10px 4px 4px;cursor:default;line-height:100%}.b-m-idisable{color:grey}.b-m-arrow,.b-m-ibody{overflow:hidden;text-overflow:ellipsis}.b-m-arrow{background:url(images/contextmenu/m_arrow.gif) right no-repeat}.b-m-idisable .b-m-arrow{background:0 0}.b-m-idisable img,.b-m-ifocus img,.b-m-item img{margin-right:8px;width:16px}.b-m-ifocus{background-color:#CDE3F6}.b-m-idisable img{visibility:hidden}.c-text{display:inline-block;padding-left:3px}.b-m-icon{width:23px;padding-left:3px}

View File

@ -1,16 +1 @@
var MSG = {"a":"a","aboutMe":"About Me","author":"Author","baseInfoSet":"Base info","blogClass":"Category","blogDesc":"Description","blogLogo":"Logo","blogLogoTips":"Upload image to replace blog title","blogName":"Title","blogNav":"Blog nav","blogNavs":"Navs","blogSet":"Blog configuration","cancel":"Cancel","chooseComment":"Comment System","chooseReason":"请选择举报理由","comment":"Comment","commentSet":"Comment","comments":"Comments","community":"Community","confirm":"Confirm","confirmDeleteComment":"Are you sure?","createdTime":"Created at","daysAgo":"days ago","delete":"Delete","disqusHelp":"Please input your Disqus Id","domain":"Custom domain","domainSet":"Domain","elegant":"Elegant","error":"Error","fullBlog":"Full blog","home":"Home","hoursAgo":"hours ago","justNow":"Just now","latestPosts":"Latest posts","like":"Like","minutesAgo":"minutes ago","monthsAgo":"months ago","more":"More...","moreShare":"More","navFixed":"Nav fixed at left side","needHelp":"Need help?","next":"Next","noBlog":"No blog","noTag":"No tag","none":"None","openComment":"Open comment?","other":"Other","previous":"Previous","qqZone":"QQ Zone","quickLinks":"Quick links","renren":"Renren","reply":"Reply","report":"Report","reportBlog?":"举报该博客?","reportComment?":"举报该评论?","reportReason":"Reason","reportReason1":"不友善内容","reportReason2":"广告等垃圾信息","reportReason3":"违法违规内容","reportReason4":"不宜公开讨论的政治内容","reportSuccess":"举报成功, 我们处理后会通知作者, 感谢您的监督","saveSuccess":"Save success","scanQRCode":"Open weichat and scan the QR code","signIn":"Sign In","signUp":"Sign Up","sinaWeibo":"Weibo","subDomain":"Sub domain","submitComment":"Submit","tencentWeibo":"Tencent Weibo","theme":"Theme","themeSet":"Theme","unlike":"Unlike","updatedTime":"Updated at","viewers":"Viewers","weeksAgo":"weeks ago","weixin":"Weichat"};
function getMsg(key, data) {
var msg = MSG[key]
if(msg) {
if(data) {
if(!isArray(data)) {
data = [data];
}
for(var i = 0; i < data.length; ++i) {
msg = msg.replace("%s", data[i]);
}
}
return msg;
}
return key;
}
var MSG={"noTag":"No tag","saveSuccess":"Save success","none":"None","like":"Like","unlike":"Unlike","delete":"Delete","cancel":"Cancel","confirm":"Confirm","chooseReason":"请选择举报理由","reportSuccess":"举报成功, 我们处理后会通知作者, 感谢您的监督","error":"Error","reportComment?":"举报该评论?","reportBlog?":"举报该博客?","confirmDeleteComment":"Are you sure?","scanQRCode":"Open weichat and scan the QR code","justNow":"Just now","minutesAgo":"minutes ago","hoursAgo":"hours ago","daysAgo":"days ago","weeksAgo":"weeks ago","monthsAgo":"months ago"};function getMsg(key, data) {var msg = MSG[key];if(msg) {if(data) {if(!isArray(data)) {data = [data];}for(var i = 0; i < data.length; ++i) {msg = msg.replace("%s", data[i]);}}return msg;}return key;}

View File

@ -1,16 +1 @@
var MSG = {"a":"a","aboutMe":"A propos de moi","author":"Auteur","baseInfoSet":"Information de base","blogClass":"Catégorie","blogDesc":"Description","blogLogo":"Logo","blogLogoTips":"Téléverser une image pour remplacer le titre du blog","blogName":"Titre","blogNav":"Navigation du blog","blogNavs":"Navigation","blogSet":"Configuration du blog","cancel":"Annuler","chooseComment":"Système de commentaires","chooseReason":"请选择举报理由","comment":"Commenter","commentSet":"Commentaires","comments":"Commentaires","community":"Communauté","confirm":"Confirmer","confirmDeleteComment":"Êtes-vous sûr?","createdTime":"Créé à","daysAgo":"Il y a plusieurs jours","delete":"Effacer","disqusHelp":"Veuillez renseigner votre identifiant Disqus","domain":"Domaine personnalisé","domainSet":"Domaine","elegant":"Elegant","error":"Erreur","fullBlog":"Blog entier","home":"Accueil","hoursAgo":"Il y a plusieurs heures","justNow":"Seulement maintenant","latestPosts":"Dernières publications","like":"J'aime","minutesAgo":"Il y a quelques minutes","monthsAgo":"Il y a plusieurs mois","more":"Plus...","moreShare":"Plus","navFixed":"Navigation figée sur le côté gauche","needHelp":"Besoin d'aide?","next":"Suivant","noBlog":"Aucun blog","noTag":"Aucune étiquette","none":"Aucun","openComment":"Ouvrir un commentaire?","other":"Autre","previous":"Précédent","qqZone":"QQ Zone","quickLinks":"Liens rapides","renren":"Renren","reply":"Répondre","report":"Rapport","reportBlog?":"举报该博客?","reportComment?":"举报该评论?","reportReason":"Raison","reportReason1":"不友善内容","reportReason2":"广告等垃圾信息","reportReason3":"违法违规内容","reportReason4":"不宜公开讨论的政治内容","reportSuccess":"举报成功, 我们处理后会通知作者, 感谢您的监督","saveSuccess":"Sauvegarde réussie","scanQRCode":"Ouvrez Weichat et scannez le QR Code","signIn":"S'identifier","signUp":"S'incrire","sinaWeibo":"Weibo","subDomain":"Sous-domaine","submitComment":"Soumettre","tencentWeibo":"Tencent Weibo","theme":"Thème","themeSet":"Thème","unlike":"Je n'aime plus","updatedTime":"Mis à jour à","viewers":"Lecteurs","weeksAgo":"Il y a plusieurs semaines","weixin":"Weichat"};
function getMsg(key, data) {
var msg = MSG[key]
if(msg) {
if(data) {
if(!isArray(data)) {
data = [data];
}
for(var i = 0; i < data.length; ++i) {
msg = msg.replace("%s", data[i]);
}
}
return msg;
}
return key;
}
var MSG={"noTag":"Aucune étiquette","saveSuccess":"Sauvegarde réussie","none":"Aucun","like":"J'aime","unlike":"Je n'aime plus","delete":"Effacer","cancel":"Annuler","confirm":"Confirmer","chooseReason":"请选择举报理由","reportSuccess":"举报成功, 我们处理后会通知作者, 感谢您的监督","error":"Erreur","reportComment?":"举报该评论?","reportBlog?":"举报该博客?","confirmDeleteComment":"Êtes-vous sûr?","scanQRCode":"Ouvrez Weichat et scannez le QR Code","justNow":"Seulement maintenant","minutesAgo":"Il y a quelques minutes","hoursAgo":"Il y a plusieurs heures","daysAgo":"Il y a plusieurs jours","weeksAgo":"Il y a plusieurs semaines","monthsAgo":"Il y a plusieurs mois"};function getMsg(key, data) {var msg = MSG[key];if(msg) {if(data) {if(!isArray(data)) {data = [data];}for(var i = 0; i < data.length; ++i) {msg = msg.replace("%s", data[i]);}}return msg;}return key;}

View File

@ -1,16 +1 @@
var MSG = {"a":"a","aboutMe":"关于我","author":"作者","baseInfoSet":"基本设置","blog":"博客","blogClass":"分类","blogDesc":"博客描述","blogLogo":"博客Logo","blogLogoTips":"上传logo将显示logo(替代博客标题)","blogName":"博客标题","blogNav":"导航","blogNavs":"导航","blogSet":"博客设置","cancel":"取消","chooseComment":"选择评论系统","chooseReason":"请选择举报理由","comment":"评论","commentSet":"评论设置","comments":"评论","community":"社区","confirm":"确认","confirmDeleteComment":"确定删除该评论?","createdTime":"创建","daysAgo":"天前","delete":"删除","disqusHelp":"请填写您申请的Disqus唯一url前缀. 建议您申请Disqus帐号, 这样可以自己管理评论. 或使用leanote的默认Disqus Id. ","domain":"自定义域名","domainSet":"域名设置","elegant":"大气","error":"错误","fullBlog":"全文","home":"主页","hoursAgo":"个小时前","justNow":"刚刚","latestPosts":"最近发表","like":"赞","minutesAgo":"分钟前","monthsAgo":"个月前","more":"更多...","moreShare":"更多分享","navFixed":"导航左侧固定","needHelp":"需要帮助?","next":"下一页","noBlog":"无博客","noTag":"无","none":"无","openComment":"开启评论?","other":"其它","previous":"上一页","qqZone":"QQ空间","quickLinks":"快速链接","renren":"人人网","reply":"回复","report":"举报","reportBlog?":"举报该博客?","reportComment?":"举报该评论?","reportReason":"举报理由","reportReason1":"不友善内容","reportReason2":"广告等垃圾信息","reportReason3":"违法违规内容","reportReason4":"不宜公开讨论的政治内容","reportSuccess":"举报成功, 我们处理后会通知作者, 感谢您的监督","saveSuccess":"保存成功","scanQRCode":"打开微信扫一扫二维码","signIn":"登录","signUp":"注册","sinaWeibo":"新浪微博","subDomain":"博客子域名","submitComment":"发表评论","tencentWeibo":"腾讯微博","theme":"主题","themeSet":"主题设置","unlike":"取消赞","updatedTime":"更新","viewers":"人读过","weeksAgo":"周前","weixin":"微信"};
function getMsg(key, data) {
var msg = MSG[key]
if(msg) {
if(data) {
if(!isArray(data)) {
data = [data];
}
for(var i = 0; i < data.length; ++i) {
msg = msg.replace("%s", data[i]);
}
}
return msg;
}
return key;
}
var MSG={"noTag":"","saveSuccess":"保存成功","none":"无","like":"赞","unlike":"取消赞","delete":"删除","cancel":"取消","confirm":"确认","chooseReason":"请选择举报理由","reportSuccess":"举报成功, 我们处理后会通知作者, 感谢您的监督","error":"错误","reportComment?":"举报该评论?","reportBlog?":"举报该博客?","confirmDeleteComment":"确定删除该评论?","scanQRCode":"打开微信扫一扫二维码","justNow":"刚刚","minutesAgo":"分钟前","hoursAgo":"个小时前","daysAgo":"天前","weeksAgo":"前","monthsAgo":"个月前"};function getMsg(key, data) {var msg = MSG[key];if(msg) {if(data) {if(!isArray(data)) {data = [data];}for(var i = 0; i < data.length; ++i) {msg = msg.replace("%s", data[i]);}}return msg;}return key;}

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

View File

@ -25,7 +25,6 @@ define('attachment_upload', ['jquery.ui.widget', 'fileupload'], function(){
if(timeout) {
clearTimeout(timeout);
}
var found = false,
node = e.target;
do {
@ -48,7 +47,6 @@ define('attachment_upload', ['jquery.ui.widget', 'fileupload'], function(){
}
setDropStyle("#dropAttach", "#uploadAttach");
setDropStyle("#dropAvatar", "#uploadAvatar");
var initUploader = function() {
$('.dropzone .btn-choose-file').click(function() {
@ -140,76 +138,6 @@ define('attachment_upload', ['jquery.ui.widget', 'fileupload'], function(){
$("#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();

View File

@ -258,6 +258,7 @@ define('editor_drop_paste', ['jquery.ui.widget', 'fileupload'], function(){
});
};
var lastTime = 0;
// pasteImage
var pasteImageInit = function() {
@ -285,7 +286,20 @@ define('editor_drop_paste', ['jquery.ui.widget', 'fileupload'], function(){
data.process.update(data.loaded / data.total);
}
},
// 调用了两次
// 不知道为什么会触发两次
add: function(e, data) {
// 防止两次
var now = (new Date()).getTime();
console.log(now - lastTime);
if (now - lastTime < 500) {
// console.log('haha');
return;
}
// console.log('nono');
lastTime = now;
var note = Note.getCurNote();
curNote = note;
if(!note || note.IsNew) {

View File

@ -0,0 +1,161 @@
/**
* @file 历史记录
* @author life
*
*/
define('history', [], function() {
var tpl = ['<div class="modal fade history-modal" tabindex="-1" role="dialog" aria-hidden="true">',
'<div class="modal-dialog modal-lg ">',
'<div class="modal-content">',
'<div class="modal-header">',
'<h4 class="modal-title" class="modalTitle">' + + '</h4>',
'</div>',
'<div class="modal-body clearfix">',
'<div class="history-list-wrap pull-left">',
'<div class="history-list-header">' + getMsg('history') +' (<span class="history-num"></span>)</div>',
'<div class="history-list list-group"></div>',
'</div>',
'<div class="history-content-wrap pull-left">',
'<div class="history-content-header">',
'<a class="btn btn-primary back">' + getMsg('restoreFromThisVersion') + '</a>',
'<button type="button" class="close" data-dismiss="modal" aria-hidden="true">&times;</button>',
'</div>',
'<div class="history-content"></div>',
'</div>',
'</div>',
'<div class="modal-footer hide">',
'<button type="button" class="btn btn-default" data-dismiss="modal">' + getMsg('close') + '</button>',
'</div>',
'</div>',
'</div>',
'</div>'].join('');
var $tpl = $(tpl);
var $historyContent = $tpl.find('.history-content');
var $historyList = $tpl.find('.history-list');
var $historyNum = $tpl.find('.history-num');
var view = {
note: null,
list: [],
curIndex: 0,
renderContent: function (i) {
var content = this.list[i].Content;
this.curIndex = i;
var wrap = '<div>';
var wrapEnd = '</div>';
if (this.note.IsMarkdown) {
wrap = '<pre>';
wrapEnd = '</pre>';
}
$historyContent.html(wrap + content + wrapEnd);
var as = $historyList.find('a');
as.removeClass('active');
as.eq(i).addClass('active');
},
render: function (list) {
var navs = '';
this.list = list;
if (list) {
for(var i = 0; i < list.length; ++i) {
var content = list[i];
navs += '<a class="list-group-item" data-index="' + i + '"><span class="badge">#' + (i+1)+ '</span>' + goNowToDatetime(content.UpdatedTime) + '</a>';
}
}
$historyList.html(navs);
this.renderContent(0);
$historyNum.html(list.length);
// show
$tpl.modal({show: true});
},
bind: function () {
var me = this;
$("#contentHistory").click(function() {
me.getHistories();
});
$historyList.on('click', 'a', function () {
var index = $(this).data('index');
me.renderContent(index);
});
// 还原
$tpl.find('.back').click(function() {
if(confirm(getMsg("confirmBackup"))) {
// 保存当前版本
Note.curChangedSaveIt(true);
// 设置之
note = Note.cache[Note.curNoteId];
setEditorContent(me.list[me.curIndex].Content, note.IsMarkdown);
$tpl.modal('hide');
// 保存
Note.curChangedSaveIt(true);
}
});
},
getHistories: function () {
var me = this;
var note = Note.getCurNote();
me.note = note;
ajaxGet("/noteContentHistory/listHistories", {noteId: Note.curNoteId}, function(re) {
if(!isArray(re)) {
alert(getMsg('noHistories'));
return;
}
me.render(re);
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
}
});
});
},
init: function () {
var me = this;
this.bind();
}
};
view.init();
});

File diff suppressed because one or more lines are too long

View File

@ -0,0 +1 @@
!function(t){"use strict";t(window.jQuery)}(function(t){"use strict";var e=0;t.ajaxTransport("iframe",function(r){if(r.async){var a,n,p;return{send:function(o,i){a=t('<form style="display:none;"></form>'),a.attr("accept-charset",r.formAcceptCharset),p=/\?/.test(r.url)?"&":"?","DELETE"===r.type?(r.url=r.url+p+"_method=DELETE",r.type="POST"):"PUT"===r.type?(r.url=r.url+p+"_method=PUT",r.type="POST"):"PATCH"===r.type&&(r.url=r.url+p+"_method=PATCH",r.type="POST"),n=t('<iframe src="javascript:false;" name="iframe-transport-'+(e+=1)+'"></iframe>').bind("load",function(){var e,p=t.isArray(r.paramName)?r.paramName:[r.paramName];n.unbind("load").bind("load",function(){var e;try{if(e=n.contents(),!e.length||!e[0].firstChild)throw new Error}catch(r){e=void 0}i(200,"success",{iframe:e}),t('<iframe src="javascript:false;"></iframe>').appendTo(a),a.remove()}),a.prop("target",n.prop("name")).prop("action",r.url).prop("method",r.type),r.formData&&t.each(r.formData,function(e,r){t('<input type="hidden"/>').prop("name",r.name).val(r.value).appendTo(a)}),r.fileInput&&r.fileInput.length&&"POST"===r.type&&(e=r.fileInput.clone(),r.fileInput.after(function(t){return e[t]}),r.paramName&&r.fileInput.each(function(e){t(this).prop("name",p[e]||r.paramName)}),a.append(r.fileInput).prop("enctype","multipart/form-data").prop("encoding","multipart/form-data")),a.submit(),e&&e.length&&r.fileInput.each(function(r,a){var n=t(e[r]);t(a).prop("name",n.prop("name")),n.replaceWith(a)})}),a.append(n).appendTo(document.body)},abort:function(){n&&n.unbind("load").prop("src","javascript".concat(":false;")),a&&a.remove()}}}}),t.ajaxSetup({converters:{"iframe text":function(e){return e&&t(e[0].body).text()},"iframe json":function(e){return e&&t.parseJSON(t(e[0].body).text())},"iframe html":function(e){return e&&t(e[0].body).html()},"iframe script":function(e){return e&&t.globalEval(t(e[0].body).text())}}})});

File diff suppressed because one or more lines are too long

38
public/js/plugins/main.js Normal file
View File

@ -0,0 +1,38 @@
// 插件, 不是立刻就需要的功能
// 1. 上传, 粘贴图片2
// 2. 笔记信息
// 3. 历史记录
// 4. 附件
requirejs.config({
paths: {
// life
'editor_drop_paste': 'js/plugins/editor_drop_paste',
'attachment_upload': 'js/plugins/attachment_upload',
'jquery.ui.widget': 'js/plugins/libs-min/jquery.ui.widget',
'fileupload': 'js/plugins/libs-min/jquery.fileupload',
'iframe-transport': 'js/plugins/libs-min/jquery.iframe-transport',
'note_info': 'js/plugins/note_info',
'tips': 'js/plugins/tips',
'history': 'js/plugins/history',
},
shim: {
// life
'fileupload': {deps: ['jquery.ui.widget', 'iframe-transport']},
}
});
// 异步加载
setTimeout(function () {
// 小异步
require(["editor_drop_paste", "attachment_upload"]);
require(['note_info']);
// 大异步
setTimeout(function () {
require(['tips']);
require(['history']);
}, 10);
});

6
public/js/plugins/main.min.js vendored Normal file

File diff suppressed because one or more lines are too long

View File

@ -0,0 +1,123 @@
/**
* @file 笔记信息
* @author life
*
*/
define('note_info', [], function() {
var tpl = ['<table>',
'<tr><th>' + getMsg('Create Time') + '</th><td id="noteInfoCreatedTime"></td></tr>',
'<tr><th>' + getMsg('Update Time') + '</th><td id="noteInfoUpdatedTime"></td></tr>',
'<tr class="post-url-tr">',
'<th>' + getMsg('Post Url') + '</th>',
'<td>',
'<div class="post-url-wrap">',
'<span class="post-url-base">http://blog.leanote.com/life/post/</span><span><span class="post-url-text">life-life-life-a-leanote</span>',
'<input type="text" class="form-control">',
'</span>',
' <a class="post-url-pencil" title="' + getMsg('update') + '"><i class="fa fa-pencil"></i></a>',
'</div>',
'</td>',
'</tr>',
'</table>'].join('');
var $tpl = $(tpl);
var $noteInfoCreatedTime = $tpl.find('#noteInfoCreatedTime');
var $noteInfoUpdatedTime = $tpl.find('#noteInfoUpdatedTime');
var $noteInfoPostUrl = $tpl.find('#noteInfoPostUrl');
var $noteInfoPostUrlTr = $tpl.find('.post-url-tr');
var $postUrlWrap = $tpl.find('.post-url-wrap');
var $input = $tpl.find('input');
var $postUrlBase = $tpl.find('.post-url-base');
var $postUrlText = $tpl.find('.post-url-text');
var view = {
$noteInfo: $('#noteInfo'),
note: null,
bind: function () {
var me = this;
$('#noteInfoDropdown').click(function () {
me.render();
});
$tpl.find('.post-url-pencil').click(function () {
$postUrlWrap.addClass('post-url-edit');
$input.val(decodeURI(me.note.UrlTitle));
$input.focus();
});
$input.keydown(function (e) {
if(e.keyCode === 13) {
$input.blur();
}
});
$input.blur(function () {
$postUrlWrap.removeClass('post-url-edit');
var val = $input.val();
if (!val) {
return;
}
ajaxPost("/member/blog/updateBlogUrlTitle", {noteId: me.note.NoteId, urlTitle: val}, function(re) {
if(reIsOk(re)) {
var encodedUrl = encodeURI(re.Item);
me.note.UrlTitle = encodedUrl;
$postUrlText.text(decodeURI(me.note.UrlTitle));
} else {
alert(re.Msg || "error");
}
});
});
// 当笔记Change时, 重新render
LEA.on('noteChanged', function (note) {
me.render(note);
});
},
getPostUrl: function (note) {
return '';
},
rendered: false,
render: function (note) {
var me = this;
if (!note) {
note = Note.getCurNote();
}
if (!note) {
return;
}
me.note = note;
$noteInfoCreatedTime.html(goNowToDatetime(note.CreatedTime));
$noteInfoUpdatedTime.html(goNowToDatetime(note.UpdatedTime));
if (!note.IsBlog) {
$noteInfoPostUrlTr.addClass('hide');
}
else {
$noteInfoPostUrlTr.removeClass('hide');
// post-url
$postUrlBase.text(UserInfo.PostUrl + '/');
$postUrlText.text(decodeURI(note.UrlTitle));
}
if (!me.rendered) {
me.$noteInfo.html($tpl);
me.rendered = true;
}
},
init: function () {
this.bind();
}
};
view.init();
});

32
public/js/plugins/tips.js Normal file
View File

@ -0,0 +1,32 @@
/**
* @file 提示帮助
* @author life
*
*/
define('tips', [], function() {
var tpl = ['<div class="modal fade bs-modal-sm" tabindex="-1" role="dialog" aria-labelledby="mySmallModalLabel" aria-hidden="true">',
'<div class="modal-dialog modal-sm">',
'<div class="modal-content">',
'<div class="modal-header">',
'<button type="button" class="close" data-dismiss="modal" aria-hidden="true">&times;</button>',
'<h4 class="modal-title" class="modalTitle">' + getMsg('editorTips') + '</h4>',
'</div>',
'<div class="modal-body">' + getMsg('editorTipsInfo') + '</div>',
'<div class="modal-footer">',
'<button type="button" class="btn btn-default" data-dismiss="modal">' + getMsg('close') + '</button>',
'</div>',
'</div>',
'</div>',
'</div>'].join('');
var $tpl = $(tpl);
var view = {
init: function () {
$("#tipsBtn").click(function() {
$tpl.modal({show: true});
});
}
};
view.init();
});

View File

@ -1,17 +0,0 @@
// 上传, 粘贴图片
requirejs.config({
paths: {
// life
'editor_drop_paste': 'js/upload_paste/editor_drop_paste',
'attachment_upload': 'js/upload_paste/attachment_upload',
'jquery.ui.widget': 'js/upload_paste/libs/jquery.ui.widget',
'fileupload': 'js/upload_paste/libs/jquery.fileupload',
'iframe-transport': 'js/upload_paste/libs/jquery.iframe-transport'
},
shim: {
// life
'fileupload': {deps: ['jquery.ui.widget', 'iframe-transport']},
}
});
require(["editor_drop_paste", "attachment_upload"], function() {
});