ace editor, markdown editor

This commit is contained in:
life
2015-01-08 00:36:28 +08:00
parent be01c9c3f7
commit 2cfc89ca5f
1233 changed files with 24568 additions and 10275 deletions

View File

@ -0,0 +1 @@
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

@ -54,11 +54,12 @@ define('attachment_upload', ['jquery.ui.widget', 'fileupload'], 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) {
@ -72,6 +73,7 @@ define('attachment_upload', ['jquery.ui.widget', 'fileupload'], function(){
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
@ -140,11 +142,13 @@ define('attachment_upload', ['jquery.ui.widget', 'fileupload'], function(){
});
//-------------------
// 已经过时, 没有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>');
@ -206,7 +210,7 @@ define('attachment_upload', ['jquery.ui.widget', 'fileupload'], function(){
})(tpl), 3000);
}
});
}
};
initUploader();
});

File diff suppressed because one or more lines are too long

View File

@ -0,0 +1,375 @@
// 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();
});

File diff suppressed because one or more lines are too long

View File

@ -247,7 +247,7 @@ Note.curHasChanged = function(force) {
}
// 比较text, 因为note Nav会添加dom会导致content改变
if((force && cacheNote.Content != content) || (!force && $(cacheNote.Content).text() != contentText)) {
if((force && cacheNote.Content != content) || (!force && (/**/(!cacheNote.IsMarkdown && $(cacheNote.Content).text() != contentText) || (cacheNote.IsMarkdown && cacheNote.Content != contentText)) /**/) ) {
hasChanged.hasChanged = true;
hasChanged.Content = content;
@ -304,6 +304,7 @@ Note.genDesc = function(content) {
// 避免其它的<img 之类的不完全
content = $("<div></div>").html(content).text();
// pre下text()会将&lt; => < &gt; => >
content = content.replace(/</g, "&lt;");
content = content.replace(/>/g, "&gt;");
@ -638,8 +639,10 @@ Note.clearNoteInfo = function() {
setEditorContent("");
// markdown editor
/*
$("#wmd-input").val("");
$("#wmd-preview").html("");
*/
// 只隐藏即可
$("#noteRead").hide();
@ -680,22 +683,22 @@ Note.renderNoteContent = function(content) {
}
// 初始化时渲染最初的notes
/**
<div id="noteItemList">
<!--
<div href="#" class="item">
<div class="item-thumb" style="">
<img src="images/a.gif"/>
</div>
<div class="item-desc" style="">
<p class="item-title">?</p>
<p class="item-text">
?
</p>
</div>
</div>
-->
/**
<div id="noteItemList">
<!--
<div href="#" class="item">
<div class="item-thumb" style="">
<img src="images/a.gif"/>
</div>
<div class="item-desc" style="">
<p class="item-title">?</p>
<p class="item-text">
?
</p>
</div>
</div>
-->
*/
Note.showEditorMask = function() {
@ -1056,6 +1059,13 @@ Note.listNoteContentHistories = function() {
});
}
// 导出成PDF
Note.exportPDF = function(target) {
var noteId = $(target).attr("noteId");
ajaxGet("/note/exportPdf", {noteId: noteId}, function(ret) {
});
};
// 长微博
Note.html2Image = function(target) {
var noteId = $(target).attr("noteId");
@ -1384,8 +1394,9 @@ Note.initContextmenu = function() {
{ 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: "分享到社区", alias: 'html2Image', icon: "", action: Note.html2Image},
// { text: "导出PDF", alias: 'exportPDF', icon: "", action: Note.exportPDF},
{ type: "splitLine" },
{ text: getMsg("delete"), icon: "", faIcon: "fa-trash-o", action: Note.deleteNote },
{ text: getMsg("move"), alias: "move", faIcon: "fa-arrow-right",
@ -1510,8 +1521,8 @@ var Attach = {
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);
if(LEA.isMarkdownEditor() && MD) {
MD.insertLink(src, attach.Title);
} else {
tinymce.activeEditor.insertContent('<a target="_blank" href="' + src + '">' + attach.Title + '</a>');
}
@ -1527,8 +1538,8 @@ var Attach = {
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);
if(LEA.isMarkdownEditor() && MD) {
MD.insertLink(src, title);
} else {
tinymce.activeEditor.insertContent('<a target="_blank" href="' + src + '">' + title + '</a>');
}
@ -1661,9 +1672,15 @@ $(function() {
Attach.init();
//-----------------
// for list nav
// 点击笔记展示之
// 避免iphone, ipad两次点击
// http://stackoverflow.com/questions/3038898/ipad-iphone-hover-problem-causes-the-user-to-double-click-a-link
$("#noteItemList").on("mouseenter", ".item", function(event) {
if(LEA.isIpad || LEA.isIphone) {
$(this).trigger("click");
}
});
$("#noteItemList").on("click", ".item", function(event) {
log(event);
event.stopPropagation();
var noteId = $(this).attr("noteId");
@ -1720,7 +1737,7 @@ $(function() {
});
*/
$("#searchNoteInput").on("keydown", function(e) {
var theEvent = e; // window.event || arguments.callee.caller.arguments[0];
var theEvent = e; // window.event || arguments.callee.caller.arguments[0];
if(theEvent.keyCode == 13 || theEvent.keyCode == 108) {
theEvent.preventDefault();
Note.searchNote();

View File

@ -60,13 +60,13 @@ Notebook.getNotebookTitle = function(notebookId) {
}
}
/**
* 我的notebooks
/**
* 我的notebooks
<ul class="folderBody" id="notebookList">
<li><a class="active">所有</a></li>
<li><a class="active">Hadoop</a></li>
<li><a>August 13, 2013</a></li>
</ul>
<li><a class="active">所有</a></li>
<li><a class="active">Hadoop</a></li>
<li><a>August 13, 2013</a></li>
</ul>
*/
Notebook.getTreeSetting = function(isSearch, isShare){
@ -236,7 +236,7 @@ Notebook.getTreeSetting = function(isSearch, isShare){
}
return setting;
}
}
Notebook.allNotebookId = "0";
Notebook.trashNotebookId = "-1";
Notebook.curNotebookIsTrashOrAll = function() {
@ -436,38 +436,38 @@ Notebook.changeNav = function() {
log(t2-t1);
}
/**
* 我的共享notebooks
<div id="shareNotebooks">
<div class="folderNote closed">
<div class="folderHeader">
<a>
<h1>
<i class="fa fa-angle-right"></i>
Life's</h1>
</a>
</div>
<ul class="folderBody">
<li><a>Hadoop</a></li>
<li><a>Node webkit</a></li>
<li><a>Hadoop</a></li>
<li><a>Node webkit</a></li>
</ul>
</div>
*/
/**
* 我的共享notebooks
<div id="shareNotebooks">
<div class="folderNote closed">
<div class="folderHeader">
<a>
<h1>
<i class="fa fa-angle-right"></i>
Life's</h1>
</a>
</div>
<ul class="folderBody">
<li><a>Hadoop</a></li>
<li><a>Node webkit</a></li>
<li><a>Hadoop</a></li>
<li><a>Node webkit</a></li>
</ul>
</div>
*/
// TODO 层级
Notebook.renderShareNotebooks = function(sharedUserInfos, shareNotebooks) {
if(isEmpty(sharedUserInfos)) {
return;
}
if(!shareNotebooks || typeof shareNotebooks != "object" || shareNotebooks.length < 0) {
return;
if(!shareNotebooks || typeof shareNotebooks != "object" || shareNotebooks.length < 0) {
return;
}
var $shareNotebooks = $("#shareNotebooks");
var user2ShareNotebooks = {};
for(var i in shareNotebooks) {
var user2ShareNotebooks = {};
for(var i in shareNotebooks) {
var userNotebooks = shareNotebooks[i];
user2ShareNotebooks[userNotebooks.UserId] = userNotebooks;
}
@ -477,17 +477,17 @@ Notebook.renderShareNotebooks = function(sharedUserInfos, shareNotebooks) {
userNotebooks.ShareNotebooks = [{NotebookId: "-2", Title: "默认共享"}].concat(userNotebooks.ShareNotebooks)
var username = userInfo.Username || userInfo.Email;
var header = tt('<div class="folderNote closed"><div class="folderHeader"><a><h1 title="? 的共享"><i class="fa fa-angle-right"></i>?</h1></a></div>', username, username);
var body = '<ul class="folderBody">';
for(var j in userNotebooks.ShareNotebooks) {
var notebook = userNotebooks.ShareNotebooks[j];
body += tt('<li><a notebookId="?">?</a></li>', notebook.NotebookId, notebook.Title)
}
body += "</ul>";
$shareNotebooks.append(header + body + "</div>")
}
var username = userInfo.Username || userInfo.Email;
var header = tt('<div class="folderNote closed"><div class="folderHeader"><a><h1 title="? 的共享"><i class="fa fa-angle-right"></i>?</h1></a></div>', username, username);
var body = '<ul class="folderBody">';
for(var j in userNotebooks.ShareNotebooks) {
var notebook = userNotebooks.ShareNotebooks[j];
body += tt('<li><a notebookId="?">?</a></li>', notebook.NotebookId, notebook.Title)
}
body += "</ul>";
$shareNotebooks.append(header + body + "</div>")
}
}
// 左侧导航, 选中某个notebook

File diff suppressed because one or more lines are too long

View File

@ -149,8 +149,8 @@ var Resize = {
note: $("#note"),
body: $("body"),
leftColumn: $("#left-column"),
rightColumn: $("#right-column"),
mdSplitter: $("#mdSplitter"),
rightColumn: $("#right-column"), // $("#preview-panel"), //
mdSplitter: $("#mdSplitter2"),
init: function() {
var self = this;
@ -173,8 +173,10 @@ var Resize = {
// 鼠标点下
self.mdSplitter.bind("mousedown", function(event) {
event.preventDefault(); // 防止选择文本
self.mdLineMove = true;
$(this).css("background-color", "#ccc");
if($(this).hasClass('open')) {
self.mdLineMove = true;
}
// $(this).css("background-color", "#ccc");
});
// 鼠标移动时
@ -194,6 +196,37 @@ var Resize = {
// 取消遮罩
$("#noteMask").css("z-index", -1);
});
// 瞬间
var everLeftWidth;
$('.layout-toggler-preview').click(function() {
var $t = $(this);
var $p = self.leftColumn.parent();
// 是开的
if($t.hasClass('open')) {
var totalWidth = $p.width();
var minRightWidth = 22;
var leftWidth = totalWidth - minRightWidth;
everLeftWidth = self.leftColumn.width();
self.leftColumn.width(leftWidth);
self.rightColumn.css('left', 'auto').width(minRightWidth);
// 禁止split
$t.removeClass('open');//.addClass('close');
self.rightColumn.find('.layout-resizer').removeClass('open');
$('.preview-container').hide();
} else {
$t.addClass('open');
self.rightColumn.find('.layout-resizer').addClass('open');
self.leftColumn.width(everLeftWidth);
$('.preview-container').show();
self.rightColumn.css('left', everLeftWidth).width('auto');
if(MD) {
MD.onResize();
}
}
});
},
// 停止, 保存数据
stopResize: function() {
@ -257,7 +290,7 @@ var Resize = {
resizeMdColumns: function(event) {
var self = this;
if (self.mdLineMove) {
var mdEditorWidth = event.clientX - self.leftNotebook.width() - self.noteList.width();
var mdEditorWidth = event.clientX - self.leftColumn.offset().left; // self.leftNotebook.width() - self.noteList.width();
self.setMdColumnWidth(mdEditorWidth);
}
},
@ -266,9 +299,15 @@ var Resize = {
var self = this;
if(mdEditorWidth > 100) {
UserInfo.MdEditorWidth = mdEditorWidth;
log(mdEditorWidth)
self.leftColumn.width(mdEditorWidth);
self.rightColumn.css("left", mdEditorWidth);
self.mdSplitter.css("left", mdEditorWidth);
// self.mdSplitter.css("left", mdEditorWidth);
}
// 这样, scrollPreview 才会到正确的位置
if(MD) {
MD.onResize();
}
}
}
@ -320,7 +359,8 @@ Mobile = {
var u = navigator.userAgent;
LEA.isMobile = false;
LEA.isMobile = /Mobile|Android|iPhone|iPad/i.test(u);
LEA.isIpad = /iPhone|iPad/i.test(u);
LEA.isIpad = /iPad/i.test(u);
LEA.isIphone = /iPhone/i.test(u);
if(!LEA.isMobile && $(document).width() <= 700){
LEA.isMobile = true
}
@ -382,10 +422,12 @@ function initSlimScroll() {
$("#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"
@ -422,43 +464,24 @@ function initEditor() {
// 初始化编辑器
tinymce.init({
// inline: true,
inline: true,
valid_children: "+pre[div|#text|p|span|textarea|i|b|strong]", // ace
/*
protect: [
/\<\/?(if|endif)\>/g, // Protect <if> & </endif>
/\<xsl\:[^>]+\>/g, // Protect <xsl:...>
// /<pre.*?>.*?<\/pre>/g, // Protect <pre ></pre>
// /<p.*?>.*?<\/p>/g, // Protect <pre ></pre>
// /<\?php.*?\?>/g // Protect php code
],
*/
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, "&nbsp;&nbsp;&nbsp;&nbsp;"); // 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
@ -470,17 +493,17 @@ function initEditor() {
selector : "#editorContent",
// height: 100,//这个应该是文档的高度, 而其上层的高度是$("#content").height(),
// parentHeight: $("#content").height(),
content_css : ["/css/bootstrap.css", "/css/editor/editor.css"].concat(em.getWritingCss()),
// content_css : ["/css/editor/editor.css"].concat(em.getWritingCss()),
// content_css : ["/css/bootstrap.css", "/css/editor/editor.css"].concat(em.getWritingCss()),
content_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
"table directionality textcolor" ], // 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",
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",
// 使用tab键: http://www.tinymce.com/wiki.php/Plugin3x:nonbreaking
// http://stackoverflow.com/questions/13543220/tiny-mce-how-to-allow-people-to-indent
@ -498,7 +521,8 @@ function initEditor() {
+ "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",
block_formats : "Header 1=h1;Header 2=h2;Header 3=h3;Header 4=h4;Paragraph=p",
/*
codemirror: {
indentOnInit: true, // Whether or not to indent code on init.
path: 'CodeMirror', // Path to CodeMirror distribution
@ -511,6 +535,7 @@ function initEditor() {
//'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.
@ -530,7 +555,7 @@ function initEditor() {
// 导航
var random = 1;
function scrollTo(self, tagName, text) {
var iframe = $("#editorContent_ifr").contents();
var iframe = $("#editorContent"); // .contents();
var target = iframe.find(tagName + ":contains(" + text + ")");
random++;
@ -548,12 +573,15 @@ function scrollTo(self, tagName, text) {
if (target.size() >= i+1) {
target = target.eq(i);
// 之前插入, 防止多行定位不准
var top = target.offset().top;
var nowTop = iframe.scrollTop();
// log(target.scrollTop());
var top = iframe.scrollTop() - iframe.offset().top + target.offset().top; // 相对于iframe的位置
// var nowTop = iframe.scrollTop();
// log(nowTop);
// log(top);
// iframe.scrollTop(top);
// $(iframe).animate({scrollTop: top}, 300); // 有问题
iframe.animate({scrollTop: top}, 300); // 有问题
/*
var d = 200; // 时间间隔
for(var i = 0; i < d; i++) {
setTimeout(
@ -567,6 +595,7 @@ function scrollTo(self, tagName, text) {
setTimeout(function() {
iframe.scrollTop(top);
}, d+5);
*/
return;
}
}
@ -601,11 +630,12 @@ $(function() {
});
// 导航隐藏与显示
$("#leanoteNav h1").on("click", function(e) {
if (!$("#leanoteNav").hasClass("unfolder")) {
$("#leanoteNav").addClass("unfolder");
$(".leanoteNav h1").on("click", function(e) {
var $leanoteNav = $(this).closest('.leanoteNav');
if (!$leanoteNav.hasClass("unfolder")) {
$leanoteNav.addClass("unfolder");
} else {
$("#leanoteNav").removeClass("unfolder");
$leanoteNav.removeClass("unfolder");
}
});
@ -703,10 +733,10 @@ $(function() {
}
}
$("#leftSwitcher2").click(function() {
$("#leftSwitcher2").on('click', function() {
maxLeft(true);
});
$("#leftSwitcher").click(function() {
$("#leftSwitcher").click('click', function() {
if(Mobile.switchPage()) {
minLeft(true);
}
@ -902,6 +932,380 @@ $(function() {
Pjax.init();
});
//----------
// aceEditor
LeaAce = {
// aceEditorID
_aceId: 0,
// {id=>ace}
_aceEditors: {},
_isInit: false,
_canAce: false,
isAce: true, // 切换pre, 默认是true
disableAddHistory: function() {
tinymce.activeEditor.undoManager.setCanAdd(false);
},
resetAddHistory: function() {
tinymce.activeEditor.undoManager.setCanAdd(true);
},
canAce: function() {
if(this._isInit) {
return this._canAce;
}
if(getVendorPrefix() == "webkit" && !Mobile.isMobile()) {
this._canAce = true;
} else {
this._canAce = false;
}
this._isInit = true;
return this._canAce;
},
canAndIsAce: function() {
return this.canAce() && this.isAce;
},
getAceId: function () {
this.aceId++;
return "leanote_ace_" + (new Date()).getTime() + "_" + this._aceId;
},
initAce: function(id, val, force) {
var me = this;
if(!force && !me.canAndIsAce()) {
return;
}
me.disableAddHistory();
var $pre = $('#' + id);
$pre.find('.toggle-raw').remove();
var preHtml = $pre.html();
$pre.removeClass('ace-to-pre');
$pre.attr("contenteditable", false); // ? 避免tinymce编辑
var aceEditor = ace.edit(id);
aceEditor.setTheme("ace/theme/tomorrow");
var brush = me.getPreBrush($pre);
var b = "";
if(brush) {
try {
b = brush.split(':')[1];
} catch(e) {}
}
b = b || "javascript";
aceEditor.session.setMode("ace/mode/" + b);
aceEditor.getSession().setUseWorker(false); // 不用语法检查
aceEditor.setOption("showInvisibles", false); // 不显示空格, 没用
aceEditor.setOption("wrap", "free");
aceEditor.setShowInvisibles(false);
aceEditor.setAutoScrollEditorIntoView(true);
aceEditor.setOption("maxLines", 100);
aceEditor.commands.addCommand({
name: "undo",
bindKey: {win: "Ctrl-z", mac: "Command-z"},
exec: function(editor) {
var undoManager = editor.getSession().getUndoManager();
if(undoManager.hasUndo()){
undoManager.undo();
} else {
undoManager.reset();
tinymce.activeEditor.undoManager.undo();
}
}
});
this._aceEditors[id] = aceEditor;
if(val) {
aceEditor.setValue(val);
// 不要选择代码
// TODO
} else {
// 防止 <pre><div>xx</div></pre> 这里的<div>消失
// preHtml = preHtml.replace('/&nbsp;/g', ' '); // 以前是把' ' 全换成了&nbsp;
// aceEditor.setValue(preHtml);
// 全不选
// aceEditor.selection.clearSelection();
}
// XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
me.resetAddHistory();
return aceEditor;
},
clearIntervalForInitAce: null,
initAceFromContent: function(editor) {
if(!this.canAndIsAce()) {
var content = $(editor.getBody());
content.find('pre').removeClass('ace_editor');
return;
}
var me = this;
// 延迟
if(this.clearIntervalForInitAce) {
clearInterval(this.clearIntervalForInitAce);
}
this.clearIntervalForInitAce = setTimeout(function() {
var content = $(editor.getBody());
var pres = content.find('pre');
for(var i = 0 ; i < pres.length; ++i) {
var pre = pres.eq(i);
// 如果不是ace
if(me.isInAce(pre)) {
break;
}
setTimeout((function(pre) {
return function() {
pre.find('.toggle-raw').remove();
var value = pre.html();
log(value);
value = value.replace(/ /g, "&nbsp;").replace(/\<br *\/*\>/gi,"\n").replace(/</g, '&lt;').replace(/>/g, '&gt;');
pre.html(value);
var id = pre.attr('id');
if(!id) {
id = me.getAceId();
pre.attr('id', id);
}
me.initAce(id);
}
})(pre));
}
}, 10);
},
allToPre: function(editor) {
if(!this.canAndIsAce()) {
return;
}
var me = this;
// 延迟
if(me.clearIntervalForInitAce) {
clearInterval(me.clearIntervalForInitAce);
}
me.clearIntervalForInitAce = setTimeout(function() {
var content = $(editor.getBody());
var pres = content.find('pre');
for(var i = 0 ; i < pres.length; ++i) {
var pre = pres.eq(i);
setTimeout((function(pre) {
return function() {
me.aceToPre(pre);
}
})(pre));
}
}, 10);
},
undo: function(editor) {
if(!this.canAndIsAce()) {
return;
}
var me = this;
// 延迟
if(this.clearIntervalForInitAce) {
clearInterval(this.clearIntervalForInitAce);
}
this.clearIntervalForInitAce = setTimeout(function() {
var content = $(editor.getBody());
var pres = content.find('pre');
for(var i = 0 ; i < pres.length; ++i) {
var pre = pres.eq(i);
setTimeout((function(pre) {
return function() {
var value = pre.html();
var id = pre.attr('id');
var aceEditor = me.getAce(id);
if(aceEditor) {
var value = aceEditor.getValue();
aceEditor.destroy();
var aceEditor = me.initAce(id, value);
// 全不选
aceEditor.selection.clearSelection();
} else {
value = value.replace(/ /g, "&nbsp;").replace(/\<br *\/*\>/gi,"\n");
pre.html(value);
var id = pre.attr('id');
if(!id) {
id = me.getAceId();
pre.attr('id', id);
}
me.initAce(id);
}
}
})(pre));
}
}, 10);
},
destroyAceFromContent: function(everContent) {
if(!this.canAce()) {
return;
}
var pres = everContent.find('pre');
for(var i = 0 ; i < pres.length; ++i) {
var id = pres.eq(i).attr('id');
var aceEditorAndPre = this.getAce(id);
if(aceEditorAndPre) {
aceEditorAndPre.destroy();
this._aceEditors[id] = null;
}
}
},
getAce: function(id) {
if(!this.canAce()) {
return;
}
return this._aceEditors[id];
},
// 当前焦点是否在aceEditor中
nowIsInAce: function () {
if(!this.canAce()) {
return;
}
var node = tinymce.activeEditor.selection.getNode();
// log("now...");
// log(node);
return this.isInAce(node);
},
nowIsInPre: function(){
var node = tinymce.activeEditor.selection.getNode();
// log("now...");
// log(node);
return this.isInPre(node);
},
isInPre: function(node) {
var $node = $(node);
var node = $node.get(0);
if(node.nodeName == "PRE") {
return true;
} else {
// 找到父是pre
$pre = $node.closest("pre");
if($pre.length == 0) {
return false;
}
return true;
}
},
// 是否在node内
isInAce: function(node) {
if(!this.canAce()) {
return;
}
var $node = $(node);
var node = $node.get(0);
if(node.nodeName == "PRE") {
// $node.data('brush', brush);
var id = $node.attr('id');
var aceEditor = this.getAce(id);
if(aceEditor) {
return [aceEditor, $node];
}
return false;
} else {
// 找到父是pre
$pre = $node.closest("pre");
if($pre.length == 0) {
return false;
}
return this.isInAce($pre);
}
return false;
},
getPreBrush: function (node) {
var $pre = $(node);
var classes = $pre.attr('class');
if(!classes) {
return '';
}
var m = classes.match(/brush:[^ ]*/);
var everBrush = "";
if(m && m.length > 0) {
everBrush = m[0];
}
return everBrush;
},
// pre转换成ace
preToAce: function (pre, force) {
if(!force && !this.canAce()) {
return;
}
var $pre = $(pre);
var id = this.getAceId();
$pre.attr('id', id);
var editor = this.initAce(id, "", true);
if(editor) {
editor.focus();
}
},
aceToPre: function(pre, isFocus) {
var me = this;
var $pre = $(pre);
// 转成pre
var aceEditorAndPre = me.isInAce($pre);
if(aceEditorAndPre) {
var aceEditor = aceEditorAndPre[0];
var $pre = aceEditorAndPre[1];
var value = aceEditor.getValue();
value = value.replace(/</g, '&lt').replace(/>/g, '&gt');
// var id = getAceId();
var replacePre = $('<pre class="' + $pre.attr('class') + ' ace-to-pre">' + value + "</pre>");
$pre.replaceWith(replacePre);
aceEditor.destroy();
me._aceEditors[$pre.attr('id')] = null;
// log($replacePre);
if(isFocus) {
setTimeout(function() {
var tinymceEditor = tinymce.activeEditor;
var selection = tinymceEditor.selection;
var rng = selection.getRng();
// rng.setStart(replacePre.get(0), 1);
// rng.setEnd(replacePre.get(0), 9);
rng.selectNode(replacePre.get(0));
// selection.setRng(rng);
// replacePre.focus();
tinymceEditor.focus();
replacePre.trigger("click");
replacePre.html(value + " ");
// log(">>>>>>>>>>>>>>")
}, 0);
}
}
},
// 转换raw <-> code
handleEvent: function () {
if(!this.canAce()) {
return;
}
var me = this;
$("#editorContent").on('mouseenter', 'pre', function(){
// log('in');
// log($(this));
var $t = $(this);
$raw = $t.find('.toggle-raw');
if($raw.length == 0) {
$t.append('<div class="toggle-raw" title="Toggle code with raw html"><input type="checkbox" /></div>');
}
$input = $t.find('.toggle-raw input');
if(LeaAce.isInAce($t)) {
$input.prop('checked', true);
} else {
$input.prop('checked', false);
}
});
$("#editorContent").on('mouseleave', 'pre', function(){
var $raw = $(this).find('.toggle-raw');
$raw.remove();
});
$("#editorContent").on('change', '.toggle-raw input', function(){
var checked = $(this).prop('checked');
var $pre = $(this).closest('pre');
if(checked) {
// 转成ace
me.preToAce($pre, true);
} else {
me.aceToPre($pre, true);
}
});
}
};
// note.html调用
// 实始化页面
function initPage() {
@ -939,48 +1343,7 @@ function initPage() {
Tag.renderTagNav(tagsJson);
// init notebook后才调用
initSlimScroll();
LeaAce.handleEvent();
});
}
//----------
// aceeditor
var aceEditors = {};
function initAce(id, val){
var aceEditor = ace.edit(id);
aceEditor.setTheme("ace/theme/tomorrow");
aceEditor.session.setMode("ace/mode/javascript");
aceEditor.setAutoScrollEditorIntoView(true);
aceEditor.setOption("maxLines", 100);
if(val) {
aceEditor.setValue(val);
}
aceEditors [id] = aceEditor;
return aceEditor;
}
function getAce(id) {
return aceEditors[id];
}
// 是否在node内
function isInAce(node, brush) {
var $node = $(node);
var node = $node.get(0);
if(node.nodeName == "PRE") {
$node.data('brush', brush);
var id = $node.attr('id');
var aceEditor = getAce(id);
if(aceEditor) {
return [aceEditor, $node];
}
return false;
} else {
// 找到父是pre
$pre = $node.closest("pre");
if($pre.length == 0) {
return false;
}
return isInAce($pre, brush);
}
return false;
}

File diff suppressed because one or more lines are too long

View File

@ -26,25 +26,25 @@ Share.setCache = function(note) {
Share.cache[note.NoteId] = note;
}
/**
* 我的共享notebooks
<div id="shareNotebooks">
<div class="folderNote closed">
<div class="folderHeader">
<a>
<h1>
<i class="fa fa-angle-right"></i>
Life's</h1>
</a>
</div>
<ul class="folderBody">
<li><a>Hadoop</a></li>
<li><a>Node webkit</a></li>
<li><a>Hadoop</a></li>
<li><a>Node webkit</a></li>
</ul>
</div>
*/
/**
* 我的共享notebooks
<div id="shareNotebooks">
<div class="folderNote closed">
<div class="folderHeader">
<a>
<h1>
<i class="fa fa-angle-right"></i>
Life's</h1>
</a>
</div>
<ul class="folderBody">
<li><a>Hadoop</a></li>
<li><a>Node webkit</a></li>
<li><a>Hadoop</a></li>
<li><a>Node webkit</a></li>
</ul>
</div>
*/
// TODO 层级
// shareNotebooks = {userId => {}}
Share.getNotebooksForNew = function(userId, notebooks) {
@ -94,7 +94,7 @@ Share.renderShareNotebooks = function(sharedUserInfos, shareNotebooks) {
}
if(!shareNotebooks || typeof shareNotebooks != "object" || shareNotebooks.length < 0) {
shareNotebooks = {};
shareNotebooks = {};
}
var $shareNotebooks = $("#shareNotebooks");
@ -113,7 +113,7 @@ Share.renderShareNotebooks = function(sharedUserInfos, shareNotebooks) {
Share.sharedUserInfos[userInfo.UserId] = userInfo;
var userId = userInfo.UserId;
var header = tt('<li class="each-user"><div class="friend-header" fromUserId="?"><i class="fa fa-angle-down"></i><span>?</span> <span class="fa notebook-setting" title="setting"></span> </div>', userInfo.UserId, username);
var friendId = "friendContainer_" + userId;
var friendId = "friendContainer_" + userId;
var body = '<ul class="friend-notebooks ztree" id="' + friendId + '" fromUserId="' + userId + '"></ul>';
$shareNotebooks.append(header + body + "</li>")
@ -193,7 +193,7 @@ Share.renderShareNotebooks = function(sharedUserInfos, shareNotebooks) {
e.stopPropagation();
var $p = $(this).parent();
menuNotebooks.showMenu(e, $p);
});
});
};
Share.isDefaultNotebookId = function(notebookId) {
@ -579,16 +579,8 @@ function addShareNoteOrNotebook(trSeq) {
tpl += tt('<td><a href="#" noteOrNotebookId="?" toUserId="?" class="btn btn-warning delete-share">' + getMsg("delete") +'</a></td>', id, ret.Id);
$(trId).html(tpl);
} else {
var shareUrl = UrlPrefix + '/register?from=' + UserInfo.Username;
showAlert("#shareMsg", getMsg('friendNotExits', [getMsg("app"), shareUrl]) + ' <a id="shareCopy" data-clipboard-target="copyDiv">' + getMsg("clickToCopy") + '</a> <span id="copyStatus"></span> <br /> ' + getMsg("sendInviteEmailToYourFriend") + ', <a href="#" onclick="sendRegisterEmail(\'' + emails + '\')">' + getMsg("send"), "warning");
$("#copyDiv").text(shareUrl);
initCopy("shareCopy", function(args) {
if(args.text) {
showMsg2("#copyStatus", getMsg("copySuccess"), 1000);
} else {
showMsg2("#copyStatus", getMsg("copyFailed"), 1000);
}
});
var shareUrl = UrlPrefix + '/register?iu=' + UserInfo.Username;
showAlert("#shareMsg", getMsg('friendNotExits', [getMsg("app"), '<input style="background: none;border: 1px solid #ccc;width: 300px;padding: 3px;border-radius: 3px;outline: none;" onclick="$(this).focus().select()" type="text" value="' + shareUrl + '" />']) + '</a> <br /> ' + getMsg("sendInviteEmailToYourFriend") + ', <a href="#" onclick="sendRegisterEmail(\'' + emails + '\')">' + getMsg("send"), "warning");
}
}
}, trId + " .btn-success");
@ -607,4 +599,4 @@ function sendRegisterEmail(email) {
function deleteShareNoteOrNotebook(trSeq) {
$("#tr" + trSeq).remove();
}
}