diff --git a/public/js/app/page-min.js b/public/js/app/page-min.js index 796e8c1..3b7bd72 100644 --- a/public/js/app/page-min.js +++ b/public/js/app/page-min.js @@ -1 +1 @@ -function editorMode(){this.writingHash="writing";this.normalHash="normal";this.isWritingMode=location.hash.indexOf(this.writingHash)>=0;this.toggleA=null}editorMode.prototype.toggleAText=function(isWriting){var self=this;setTimeout(function(){var toggleA=$(".toggle-editor-mode a");var toggleSpan=$(".toggle-editor-mode span");if(isWriting){toggleA.attr("href","#"+self.normalHash);toggleSpan.text(getMsg("normalMode"))}else{toggleA.attr("href","#"+self.writingHash);toggleSpan.text(getMsg("writingMode"))}},0)};editorMode.prototype.isWriting=function(hash){return hash.indexOf(this.writingHash)>=0};editorMode.prototype.init=function(){this.changeMode(this.isWritingMode);var self=this;$(".toggle-editor-mode").click(function(e){e.preventDefault();saveBookmark();var $a=$(this).find("a");var isWriting=self.isWriting($a.attr("href"));self.changeMode(isWriting);if(isWriting){setHash("m",self.writingHash)}else{setHash("m",self.normalHash)}restoreBookmark()})};editorMode.prototype.changeMode=function(isWritingMode){this.toggleAText(isWritingMode);if(isWritingMode){this.writtingMode()}else{this.normalMode()}$("#moreBtn i").removeClass("fa-angle-up").addClass("fa-angle-down")};editorMode.prototype.resizeEditor=function(){setTimeout(function(){resizeEditor()},10);setTimeout(function(){resizeEditor()},20);setTimeout(function(){resizeEditor()},500)};editorMode.prototype.normalMode=function(){var $c=$("#editorContent_ifr").contents();$c.contents().find("#writtingMode").remove();$c.contents().find('link[href$="editor-writting-mode.css"]').remove();$("#noteItemListWrap, #notesAndSort").show();$("#noteList").unbind("mouseenter").unbind("mouseleave");var theme=UserInfo.Theme||"default";theme+=".css";$("#themeLink").attr("href","/css/theme/"+theme);$("#mceToolbar").css("height","30px");this.resizeEditor();$("#noteList").width(UserInfo.NoteListWidth);$("#note").css("left",UserInfo.NoteListWidth)};editorMode.prototype.writtingMode=function(){$("#themeLink").attr("href","/css/theme/writting-overwrite.css");setTimeout(function(){var $c=$("#editorContent_ifr").contents();$c.contents().find("head").append('')},0);$("#noteItemListWrap, #notesAndSort").fadeOut();$("#noteList").hover(function(){$("#noteItemListWrap, #notesAndSort").fadeIn()},function(){$("#noteItemListWrap, #notesAndSort").fadeOut()});$("#mceToolbar").css("height","40px");this.resizeEditor();$("#noteList").width(250);$("#note").css("left",0)};editorMode.prototype.getWritingCss=function(){if(this.isWritingMode){return["/css/editor/editor-writting-mode.css"]}return[]};var em=new editorMode;var Resize={lineMove:false,mdLineMove:false,target:null,leftNotebook:$("#leftNotebook"),notebookSplitter:$("#notebookSplitter"),noteList:$("#noteList"),noteAndEditor:$("#noteAndEditor"),noteSplitter:$("#noteSplitter"),note:$("#note"),body:$("body"),leftColumn:$("#left-column"),rightColumn:$("#right-column"),mdSplitter:$("#mdSplitter2"),init:function(){var self=this;self.initEvent()},initEvent:function(){var self=this;$(".noteSplit").bind("mousedown",function(event){event.preventDefault();self.lineMove=true;$(this).css("background-color","#ccc");self.target=$(this).attr("id");$("#noteMask").css("z-index",99999)});self.mdSplitter.bind("mousedown",function(event){event.preventDefault();if($(this).hasClass("open")){self.mdLineMove=true}});self.body.bind("mousemove",function(event){if(self.lineMove){event.preventDefault();self.resize3Columns(event)}else if(self.mdLineMove){event.preventDefault();self.resizeMdColumns(event)}});self.body.bind("mouseup",function(event){self.stopResize();$("#noteMask").css("z-index",-1)});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);$t.removeClass("open");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(){var self=this;if(self.lineMove||self.mdLineMove){ajaxGet("/user/updateColumnWidth",{mdEditorWidth:UserInfo.MdEditorWidth,notebookWidth:UserInfo.NotebookWidth,noteListWidth:UserInfo.NoteListWidth},function(){})}self.lineMove=false;self.mdLineMove=false;$(".noteSplit").css("background","none");self.mdSplitter.css("background","none")},set3ColumnsWidth:function(notebookWidth,noteListWidth){var self=this;if(notebookWidth<150||noteListWidth<100){return}var noteWidth=self.body.width()-notebookWidth-noteListWidth;if(noteWidth<400){return}self.leftNotebook.width(notebookWidth);self.notebookSplitter.css("left",notebookWidth);self.noteAndEditor.css("left",notebookWidth);self.noteList.width(noteListWidth);self.noteSplitter.css("left",noteListWidth);self.note.css("left",noteListWidth);UserInfo.NotebookWidth=notebookWidth;UserInfo.NoteListWidth=noteListWidth},resize3Columns:function(event,isFromeIfr){var self=this;if(isFromeIfr){event.clientX+=self.body.width()-self.note.width()}var notebookWidth,noteListWidth;if(self.lineMove){if(self.target=="notebookSplitter"){notebookWidth=event.clientX;noteListWidth=self.noteList.width();self.set3ColumnsWidth(notebookWidth,noteListWidth)}else{notebookWidth=self.leftNotebook.width();noteListWidth=event.clientX-notebookWidth;self.set3ColumnsWidth(notebookWidth,noteListWidth)}resizeEditor()}},resizeMdColumns:function(event){var self=this;if(self.mdLineMove){var mdEditorWidth=event.clientX-self.leftColumn.offset().left;self.setMdColumnWidth(mdEditorWidth)}},setMdColumnWidth:function(mdEditorWidth){var self=this;if(mdEditorWidth>100){UserInfo.MdEditorWidth=mdEditorWidth;log(mdEditorWidth);self.leftColumn.width(mdEditorWidth);self.rightColumn.css("left",mdEditorWidth)}if(MD){MD.onResize()}}};Mobile={noteO:$("#note"),bodyO:$("body"),setMenuO:$("#setMenu"),hashChange:function(){var self=Mobile;var hash=location.hash;if(hash.indexOf("noteId")!=-1){self.toEditor(false);var noteId=hash.substr(8);Note.changeNote(noteId,false,false)}else{self.toNormal(false)}},init:function(){var self=this;self.isMobile()},isMobile:function(){var u=navigator.userAgent;LEA.isMobile=false;LEA.isMobile=/Mobile|Android|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}return LEA.isMobile},changeNote:function(noteId){var self=this;if(!LEA.isMobile){return true}self.toEditor(true,noteId);return false},toEditor:function(changeHash,noteId){var self=this;self.bodyO.addClass("full-editor");self.noteO.addClass("editor-show")},toNormal:function(changeHash){var self=this;self.bodyO.removeClass("full-editor");self.noteO.removeClass("editor-show")},switchPage:function(){var self=this;if(!LEA.isMobile||LEA.isIpad){return true}if(self.bodyO.hasClass("full-editor")){self.toNormal(true)}else{self.toEditor(true)}return false}};function initSlimScroll(){if(Mobile.isMobile()){return}$("#notebook").slimScroll({height:"100%"});$("#noteItemList").slimScroll({height:"100%"});$("#wmd-panel-preview").slimScroll({height:"100%"});$("#wmd-panel-preview").css("width","100%")}function initEditor(){var mceToobarEverHeight=0;$("#moreBtn").click(function(){saveBookmark();var height=$("#mceToolbar").height();if(height<$("#popularToolbar").height()){$("#mceToolbar").height($("#popularToolbar").height());$(this).find("i").removeClass("fa-angle-down").addClass("fa-angle-up");mceToobarEverHeight=height}else{$("#mceToolbar").height(mceToobarEverHeight);$(this).find("i").removeClass("fa-angle-up").addClass("fa-angle-down")}resizeEditor();restoreBookmark()});tinymce.init({inline:true,valid_children:"+pre[div|#text|p|span|textarea|i|b|strong]",setup:function(ed){ed.on("keydown",Note.saveNote);ed.on("click",function(e){$("body").trigger("click")})},convert_urls:true,relative_urls:false,remove_script_host:false,selector:"#editorContent",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"],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",menubar:false,toolbar_items_size:"small",statusbar:false,url_converter:false,font_formats:"Arial=arial,helvetica,sans-serif;"+"Arial Black=arial black,avant garde;"+"Times New Roman=times new roman,times;"+"Courier New=courier new,courier;"+"Tahoma=tahoma,arial,helvetica,sans-serif;"+"Verdana=verdana,geneva;"+"宋体=SimSun;"+"新宋体=NSimSun;"+"黑体=SimHei;"+"微软雅黑=Microsoft YaHei",block_formats:"Header 1=h1;Header 2=h2;Header 3=h3;Header 4=h4;Paragraph=p",paste_data_images:true});window.onbeforeunload=function(e){Note.curChangedSaveIt()};$("body").on("keydown",Note.saveNote)}var random=1;function scrollTo(self,tagName,text){var iframe=$("#editorContent");var target=iframe.find(tagName+":contains("+text+")");random++;var navs=$('#leanoteNavContent [data-a="'+tagName+"-"+encodeURI(text)+'"]');var len=navs.size();for(var i=0;i=i+1){target=target.eq(i);var top=iframe.scrollTop()-iframe.offset().top+target.offset().top;iframe.animate({scrollTop:top},300);return}}$(function(){$(window).resize(function(){Mobile.isMobile();resizeEditor()});initEditor();$(".folderHeader").click(function(){var body=$(this).next();var p=$(this).parent();if(!body.is(":hidden")){$(".folderNote").removeClass("opened").addClass("closed");p.removeClass("opened").addClass("closed");$(this).find(".fa-angle-down").removeClass("fa-angle-down").addClass("fa-angle-right")}else{$(".folderNote").removeClass("opened").addClass("closed");p.removeClass("closed").addClass("opened");$(this).find(".fa-angle-right").removeClass("fa-angle-right").addClass("fa-angle-down")}});$(".leanoteNav h1").on("click",function(e){var $leanoteNav=$(this).closest(".leanoteNav");if(!$leanoteNav.hasClass("unfolder")){$leanoteNav.addClass("unfolder")}else{$leanoteNav.removeClass("unfolder")}});function openSetInfoDialog(whichTab){showDialogRemote("/user/account",{tab:whichTab})}$("#setInfo").click(function(){openSetInfoDialog(0)});$("#wrongEmail").click(function(){openSetInfoDialog(1)});$("#setAvatarMenu").click(function(){showDialog2("#avatarDialog",{title:"头像设置",postShow:function(){}})});$("#setTheme").click(function(){showDialog2("#setThemeDialog",{title:"主题设置",postShow:function(){if(!UserInfo.Theme){UserInfo.Theme="default"}$("#themeForm input[value='"+UserInfo.Theme+"']").attr("checked",true)}})});$("#themeForm").on("click","input",function(e){var val=$(this).val();$("#themeLink").attr("href","/css/theme/"+val+".css");ajaxPost("/user/updateTheme",{theme:val},function(re){if(reIsOk(re)){UserInfo.Theme=val}})});if(!UserInfo.Verified){}$("#notebook, #newMyNote, #myProfile, #topNav, #notesAndSort","#leanoteNavTrigger").bind("selectstart",function(e){e.preventDefault();return false});function updateLeftIsMin(is){ajaxGet("/user/updateLeftIsMin",{leftIsMin:is})}function minLeft(save){$("#leftNotebook").width(30);$("#notebook").hide();$("#noteAndEditor").css("left",30);$("#notebookSplitter").hide();$("#logo").hide();$("#leftSwitcher").hide();$("#leftSwitcher2").show();$("#leftNotebook .slimScrollDiv").hide();if(save){updateLeftIsMin(true)}}function maxLeft(save){$("#noteAndEditor").css("left",UserInfo.NotebookWidth);$("#leftNotebook").width(UserInfo.NotebookWidth);$("#notebook").show();$("#notebookSplitter").show();$("#leftSwitcher2").hide();$("#logo").show();$("#leftSwitcher").show();$("#leftNotebook .slimScrollDiv").show();if(save){updateLeftIsMin(false)}}$("#leftSwitcher2").on("click",function(){maxLeft(true)});$("#leftSwitcher").click("click",function(){if(Mobile.switchPage()){minLeft(true)}});function getMaxDropdownHeight(obj){var offset=$(obj).offset();var maxHeight=$(document).height()-offset.top;maxHeight-=70;if(maxHeight<0){maxHeight=0}var preHeight=$(obj).find("ul").height();return preHeight/gi,"\n").replace(//g,">");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/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;i0){everBrush=m[0]}return everBrush},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);var aceEditorAndPre=me.isInAce($pre);if(aceEditorAndPre){var aceEditor=aceEditorAndPre[0];var $pre=aceEditorAndPre[1];var value=aceEditor.getValue();value=value.replace(//g,">");var replacePre=$('
'+value+"
");$pre.replaceWith(replacePre);aceEditor.destroy();me._aceEditors[$pre.attr("id")]=null;if(isFocus){setTimeout(function(){var tinymceEditor=tinymce.activeEditor;var selection=tinymceEditor.selection;var rng=selection.getRng();rng.selectNode(replacePre.get(0));tinymceEditor.focus();replacePre.trigger("click");replacePre.html(value+" ")},0)}}},handleEvent:function(){if(!this.canAce()){return}var me=this;$("#editorContent").on("mouseenter","pre",function(){var $t=$(this);$raw=$t.find(".toggle-raw");if($raw.length==0){$t.append('
')}$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){me.preToAce($pre,true)}else{me.aceToPre($pre,true)}})}};function initPage(){$(function(){Notebook.renderNotebooks(notebooks);Share.renderShareNotebooks(sharedUserInfos,shareNotebooks);if(curSharedNoteNotebookId){Share.firstRenderShareNote(curSharedUserId,curSharedNoteNotebookId,curNoteId)}else{Note.setNoteCache(noteContentJson);Note.renderNotes(notes);if(curNoteId){setTimeout(function(){Note.changeNoteForPjax(curNoteId,true,curNotebookId)});if(!curNotebookId){Notebook.selectNotebook($(tt('#notebook [notebookId="?"]',Notebook.allNotebookId)))}}}if(latestNotes.length>0){for(var i=0;i=0;this.toggleA=null}editorMode.prototype.toggleAText=function(isWriting){var self=this;setTimeout(function(){var toggleA=$(".toggle-editor-mode a");var toggleSpan=$(".toggle-editor-mode span");if(isWriting){toggleA.attr("href","#"+self.normalHash);toggleSpan.text(getMsg("normalMode"))}else{toggleA.attr("href","#"+self.writingHash);toggleSpan.text(getMsg("writingMode"))}},0)};editorMode.prototype.isWriting=function(hash){return hash.indexOf(this.writingHash)>=0};editorMode.prototype.init=function(){this.changeMode(this.isWritingMode);var self=this;$(".toggle-editor-mode").click(function(e){e.preventDefault();saveBookmark();var $a=$(this).find("a");var isWriting=self.isWriting($a.attr("href"));self.changeMode(isWriting);if(isWriting){setHash("m",self.writingHash)}else{setHash("m",self.normalHash)}restoreBookmark()})};editorMode.prototype.changeMode=function(isWritingMode){this.toggleAText(isWritingMode);if(isWritingMode){this.writtingMode()}else{this.normalMode()}$("#moreBtn i").removeClass("fa-angle-up").addClass("fa-angle-down")};editorMode.prototype.resizeEditor=function(){setTimeout(function(){resizeEditor()},10);setTimeout(function(){resizeEditor()},20);setTimeout(function(){resizeEditor()},500)};editorMode.prototype.normalMode=function(){var $c=$("#editorContent_ifr").contents();$c.contents().find("#writtingMode").remove();$c.contents().find('link[href$="editor-writting-mode.css"]').remove();$("#noteItemListWrap, #notesAndSort").show();$("#noteList").unbind("mouseenter").unbind("mouseleave");var theme=UserInfo.Theme||"default";theme+=".css";$("#themeLink").attr("href","/css/theme/"+theme);$("#mceToolbar").css("height","30px");this.resizeEditor();$("#noteList").width(UserInfo.NoteListWidth);$("#note").css("left",UserInfo.NoteListWidth)};editorMode.prototype.writtingMode=function(){$("#themeLink").attr("href","/css/theme/writting-overwrite.css");setTimeout(function(){var $c=$("#editorContent_ifr").contents();$c.contents().find("head").append('')},0);$("#noteItemListWrap, #notesAndSort").fadeOut();$("#noteList").hover(function(){$("#noteItemListWrap, #notesAndSort").fadeIn()},function(){$("#noteItemListWrap, #notesAndSort").fadeOut()});$("#mceToolbar").css("height","40px");this.resizeEditor();$("#noteList").width(250);$("#note").css("left",0)};editorMode.prototype.getWritingCss=function(){if(this.isWritingMode){return["/css/editor/editor-writting-mode.css"]}return[]};var em=new editorMode;var Resize={lineMove:false,mdLineMove:false,target:null,leftNotebook:$("#leftNotebook"),notebookSplitter:$("#notebookSplitter"),noteList:$("#noteList"),noteAndEditor:$("#noteAndEditor"),noteSplitter:$("#noteSplitter"),note:$("#note"),body:$("body"),leftColumn:$("#left-column"),rightColumn:$("#right-column"),mdSplitter:$("#mdSplitter2"),init:function(){var self=this;self.initEvent()},initEvent:function(){var self=this;$(".noteSplit").bind("mousedown",function(event){event.preventDefault();self.lineMove=true;$(this).css("background-color","#ccc");self.target=$(this).attr("id");$("#noteMask").css("z-index",99999)});self.mdSplitter.bind("mousedown",function(event){event.preventDefault();if($(this).hasClass("open")){self.mdLineMove=true}});self.body.bind("mousemove",function(event){if(self.lineMove){event.preventDefault();self.resize3Columns(event)}else if(self.mdLineMove){event.preventDefault();self.resizeMdColumns(event)}});self.body.bind("mouseup",function(event){self.stopResize();$("#noteMask").css("z-index",-1)});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);$t.removeClass("open");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(){var self=this;if(self.lineMove||self.mdLineMove){ajaxGet("/user/updateColumnWidth",{mdEditorWidth:UserInfo.MdEditorWidth,notebookWidth:UserInfo.NotebookWidth,noteListWidth:UserInfo.NoteListWidth},function(){})}self.lineMove=false;self.mdLineMove=false;$(".noteSplit").css("background","none");self.mdSplitter.css("background","none")},set3ColumnsWidth:function(notebookWidth,noteListWidth){var self=this;if(notebookWidth<150||noteListWidth<100){return}var noteWidth=self.body.width()-notebookWidth-noteListWidth;if(noteWidth<400){return}self.leftNotebook.width(notebookWidth);self.notebookSplitter.css("left",notebookWidth);self.noteAndEditor.css("left",notebookWidth);self.noteList.width(noteListWidth);self.noteSplitter.css("left",noteListWidth);self.note.css("left",noteListWidth);UserInfo.NotebookWidth=notebookWidth;UserInfo.NoteListWidth=noteListWidth},resize3Columns:function(event,isFromeIfr){var self=this;if(isFromeIfr){event.clientX+=self.body.width()-self.note.width()}var notebookWidth,noteListWidth;if(self.lineMove){if(self.target=="notebookSplitter"){notebookWidth=event.clientX;noteListWidth=self.noteList.width();self.set3ColumnsWidth(notebookWidth,noteListWidth)}else{notebookWidth=self.leftNotebook.width();noteListWidth=event.clientX-notebookWidth;self.set3ColumnsWidth(notebookWidth,noteListWidth)}resizeEditor()}},resizeMdColumns:function(event){var self=this;if(self.mdLineMove){var mdEditorWidth=event.clientX-self.leftColumn.offset().left;self.setMdColumnWidth(mdEditorWidth)}},setMdColumnWidth:function(mdEditorWidth){var self=this;if(mdEditorWidth>100){UserInfo.MdEditorWidth=mdEditorWidth;log(mdEditorWidth);self.leftColumn.width(mdEditorWidth);self.rightColumn.css("left",mdEditorWidth)}if(MD){MD.onResize()}}};Mobile={noteO:$("#note"),bodyO:$("body"),setMenuO:$("#setMenu"),hashChange:function(){var self=Mobile;var hash=location.hash;if(hash.indexOf("noteId")!=-1){self.toEditor(false);var noteId=hash.substr(8);Note.changeNote(noteId,false,false)}else{self.toNormal(false)}},init:function(){var self=this;self.isMobile()},isMobile:function(){var u=navigator.userAgent;LEA.isMobile=false;LEA.isMobile=/Mobile|Android|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}return LEA.isMobile},changeNote:function(noteId){var self=this;if(!LEA.isMobile){return true}self.toEditor(true,noteId);return false},toEditor:function(changeHash,noteId){var self=this;self.bodyO.addClass("full-editor");self.noteO.addClass("editor-show")},toNormal:function(changeHash){var self=this;self.bodyO.removeClass("full-editor");self.noteO.removeClass("editor-show")},switchPage:function(){var self=this;if(!LEA.isMobile||LEA.isIpad){return true}if(self.bodyO.hasClass("full-editor")){self.toNormal(true)}else{self.toEditor(true)}return false}};function initSlimScroll(){if(Mobile.isMobile()){return}$("#notebook").slimScroll({height:"100%"});$("#noteItemList").slimScroll({height:"100%"});$("#wmd-panel-preview").slimScroll({height:"100%"});$("#wmd-panel-preview").css("width","100%")}function initEditor(){var mceToobarEverHeight=0;$("#moreBtn").click(function(){saveBookmark();var height=$("#mceToolbar").height();if(height<$("#popularToolbar").height()){$("#mceToolbar").height($("#popularToolbar").height());$(this).find("i").removeClass("fa-angle-down").addClass("fa-angle-up");mceToobarEverHeight=height}else{$("#mceToolbar").height(mceToobarEverHeight);$(this).find("i").removeClass("fa-angle-up").addClass("fa-angle-down")}resizeEditor();restoreBookmark()});tinymce.init({inline:true,theme:"leanote",valid_children:"+pre[div|#text|p|span|textarea|i|b|strong]",setup:function(ed){ed.on("keydown",Note.saveNote);ed.on("click",function(e){})},convert_urls:true,relative_urls:false,remove_script_host:false,selector:"#editorContent",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"],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",menubar:false,toolbar_items_size:"small",statusbar:false,url_converter:false,font_formats:"Arial=arial,helvetica,sans-serif;"+"Arial Black=arial black,avant garde;"+"Times New Roman=times new roman,times;"+"Courier New=courier new,courier;"+"Tahoma=tahoma,arial,helvetica,sans-serif;"+"Verdana=verdana,geneva;"+"宋体=SimSun;"+"新宋体=NSimSun;"+"黑体=SimHei;"+"微软雅黑=Microsoft YaHei",block_formats:"Header 1=h1;Header 2=h2;Header 3=h3;Header 4=h4;Paragraph=p",paste_data_images:true});window.onbeforeunload=function(e){Note.curChangedSaveIt()};$("body").on("keydown",Note.saveNote)}var random=1;function scrollTo(self,tagName,text){var iframe=$("#editorContent");var target=iframe.find(tagName+":contains("+text+")");random++;var navs=$('#leanoteNavContent [data-a="'+tagName+"-"+encodeURI(text)+'"]');var len=navs.size();for(var i=0;i=i+1){target=target.eq(i);var top=iframe.scrollTop()-iframe.offset().top+target.offset().top;iframe.animate({scrollTop:top},300);return}}$(function(){$(window).resize(function(){Mobile.isMobile();resizeEditor()});initEditor();$(".folderHeader").click(function(){var body=$(this).next();var p=$(this).parent();if(!body.is(":hidden")){$(".folderNote").removeClass("opened").addClass("closed");p.removeClass("opened").addClass("closed");$(this).find(".fa-angle-down").removeClass("fa-angle-down").addClass("fa-angle-right")}else{$(".folderNote").removeClass("opened").addClass("closed");p.removeClass("closed").addClass("opened");$(this).find(".fa-angle-right").removeClass("fa-angle-right").addClass("fa-angle-down")}});$(".leanoteNav h1").on("click",function(e){var $leanoteNav=$(this).closest(".leanoteNav");if(!$leanoteNav.hasClass("unfolder")){$leanoteNav.addClass("unfolder")}else{$leanoteNav.removeClass("unfolder")}});function openSetInfoDialog(whichTab){showDialogRemote("/user/account",{tab:whichTab})}$("#setInfo").click(function(){openSetInfoDialog(0)});$("#wrongEmail").click(function(){openSetInfoDialog(1)});$("#setAvatarMenu").click(function(){showDialog2("#avatarDialog",{title:"头像设置",postShow:function(){}})});$("#setTheme").click(function(){showDialog2("#setThemeDialog",{title:"主题设置",postShow:function(){if(!UserInfo.Theme){UserInfo.Theme="default"}$("#themeForm input[value='"+UserInfo.Theme+"']").attr("checked",true)}})});$("#themeForm").on("click","input",function(e){var val=$(this).val();$("#themeLink").attr("href","/css/theme/"+val+".css");ajaxPost("/user/updateTheme",{theme:val},function(re){if(reIsOk(re)){UserInfo.Theme=val}})});if(!UserInfo.Verified){}$("#notebook, #newMyNote, #myProfile, #topNav, #notesAndSort","#leanoteNavTrigger").bind("selectstart",function(e){e.preventDefault();return false});function updateLeftIsMin(is){ajaxGet("/user/updateLeftIsMin",{leftIsMin:is})}function minLeft(save){$("#leftNotebook").width(30);$("#notebook").hide();$("#noteAndEditor").css("left",30);$("#notebookSplitter").hide();$("#logo").hide();$("#leftSwitcher").hide();$("#leftSwitcher2").show();$("#leftNotebook .slimScrollDiv").hide();if(save){updateLeftIsMin(true)}}function maxLeft(save){$("#noteAndEditor").css("left",UserInfo.NotebookWidth);$("#leftNotebook").width(UserInfo.NotebookWidth);$("#notebook").show();$("#notebookSplitter").show();$("#leftSwitcher2").hide();$("#logo").show();$("#leftSwitcher").show();$("#leftNotebook .slimScrollDiv").show();if(save){updateLeftIsMin(false)}}$("#leftSwitcher2").on("click",function(){maxLeft(true)});$("#leftSwitcher").click("click",function(){if(Mobile.switchPage()){minLeft(true)}});function getMaxDropdownHeight(obj){var offset=$(obj).offset();var maxHeight=$(document).height()-offset.top;maxHeight-=70;if(maxHeight<0){maxHeight=0}var preHeight=$(obj).find("ul").height();return preHeight/gi,"\n").replace(//g,">");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/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;i0){everBrush=m[0]}return everBrush},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);var aceEditorAndPre=me.isInAce($pre);if(aceEditorAndPre){var aceEditor=aceEditorAndPre[0];var $pre=aceEditorAndPre[1];var value=aceEditor.getValue();value=value.replace(//g,">");var replacePre=$('
'+value+"
");$pre.replaceWith(replacePre);aceEditor.destroy();me._aceEditors[$pre.attr("id")]=null;if(isFocus){setTimeout(function(){var tinymceEditor=tinymce.activeEditor;var selection=tinymceEditor.selection;var rng=selection.getRng();rng.selectNode(replacePre.get(0));tinymceEditor.focus();replacePre.trigger("click");replacePre.html(value+" ")},0)}}},handleEvent:function(){if(!this.canAce()){return}var me=this;$("#editorContent").on("mouseenter","pre",function(){var $t=$(this);$raw=$t.find(".toggle-raw");if($raw.length==0){$t.append('
')}$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){me.preToAce($pre,true)}else{me.aceToPre($pre,true)}})}};function initPage(){$(function(){Notebook.renderNotebooks(notebooks);Share.renderShareNotebooks(sharedUserInfos,shareNotebooks);if(curSharedNoteNotebookId){Share.firstRenderShareNote(curSharedUserId,curSharedNoteNotebookId,curNoteId)}else{Note.setNoteCache(noteContentJson);Note.renderNotes(notes);if(curNoteId){setTimeout(function(){Note.changeNoteForPjax(curNoteId,true,curNotebookId)});if(!curNotebookId){Notebook.selectNotebook($(tt('#notebook [notebookId="?"]',Notebook.allNotebookId)))}}}if(latestNotes.length>0){for(var i=0;i
xx
这里的
消失 - // preHtml = preHtml.replace('/ /g', ' '); // 以前是把' ' 全换成了  - // aceEditor.setValue(preHtml); - // 全不选 - // aceEditor.selection.clearSelection(); + var rawCode = $pre.html(); // 原生code + try { + me.disableAddHistory(); + + // 本身就有格式的, 防止之前有格式的显示为(ace下) + if($pre.attr('style') || $pre.html().indexOf('style') != -1) { + $pre.html($pre.text()); + // return; + } + $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.session.setOption("useWorker", false); // 不用语法检查 + // retina + if(window.devicePixelRatio == 2) { + aceEditor.setFontSize("12px"); + } + else { + aceEditor.setFontSize("14px"); + } + aceEditor.getSession().setUseWorker(false); // 不用语法检查 + aceEditor.setOption("showInvisibles", false); // 不显示空格, 没用 + aceEditor.setShowInvisibles(false); // OK 不显示空格 + aceEditor.setOption("wrap", "free"); + aceEditor.setShowInvisibles(false); + aceEditor.setAutoScrollEditorIntoView(true); + aceEditor.setOption("maxLines", 10000); + 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 { + // 防止
xx
这里的
消失 + // preHtml = preHtml.replace('/ /g', ' '); // 以前是把' ' 全换成了  + // aceEditor.setValue(preHtml); + // 全不选 + // aceEditor.selection.clearSelection(); + } + + // XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX + // "XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX" + me.resetAddHistory(); + return aceEditor; + } catch(e) { + // 当有错误时, 会有XXXXX的形式, 此时不要ace, 直接原生的!!! + console.error('ace error!!!!'); + console.error(e); + $pre.attr("contenteditable", true); + $pre.removeClass('ace-tomorrow ace_editor ace-tm'); + $pre.html(rawCode); + me.resetAddHistory(); } - - // XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX - - me.resetAddHistory(); - return aceEditor; }, clearIntervalForInitAce: null, initAceFromContent: function(editor) {