Files
leanote/public/js/app/min/page-ck.js
2014-07-08 21:45:43 +08:00

1 line
15 KiB
JavaScript
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

function stopResize3Columns(){lineMove&&ajaxGet("/user/updateColumnWidth",{notebookWidth:UserInfo.NotebookWidth,noteListWidth:UserInfo.NoteListWidth},function(){}),lineMove=!1,$(".noteSplit").css("background","none")}function resize3ColumnsEnd(e,t){var o=$("body").width()-e-t;$("#leftNotebook").width(e),$("#notebookSplitter").css("left",e),$("#noteAndEditor").css("left",e),$("#noteList").width(t),$("#noteSplitter").css("left",t),$("#note").css("left",t),UserInfo.NotebookWidth=e,UserInfo.NoteListWidth=t}function resize3Columns(e,t){t&&(e.clientX+=$("body").width()-$("#note").width());var o,i;1==lineMove&&("notebookSplitter"==target?(o=e.clientX,i=$("#noteList").width(),resize3ColumnsEnd(o,i)):(o=$("#leftNotebook").width(),i=e.clientX-o,resize3ColumnsEnd(o,i)),resizeEditor())}function scrollTo(e,t,o){var i=$("#editorContent_ifr").contents(),n=i.find(t+":contains("+o+")");random++;for(var s=$('#leanoteNavContent [data-a="'+t+"-"+encodeURI(o)+'"]'),r=s.size(),a=0;r>a&&s[a]!=e;++a);if(n.size()>=a+1){n=n.eq(a);for(var l=n.offset().top,d=i.scrollTop(),c=200,a=0;c>a;a++)setTimeout(function(e){return function(){i.scrollTop(e)}}(d+1*a*(l-d)/c),a);return void setTimeout(function(){i.scrollTop(l)},c+5)}}function initSlimScroll(){$("#notebook").slimScroll({height:"100%"}),$("#noteItemList").slimScroll({height:"100%"}),$("#wmd-input").slimScroll({height:"100%"}),$("#wmd-input").css("width","100%"),$("#wmd-panel-preview").slimScroll({height:"100%"}),$("#wmd-panel-preview").css("width","100%")}function editorMode(){this.writingHash="#writing",this.normalHash="#normal",this.isWritingMode=location.hash==this.writingHash,this.toggleA=null}var em=new editorMode,lineMove=!1,target=null;$(function(){$(".noteSplit").bind("mousedown",function(e){e.preventDefault(),lineMove=!0,$(this).css("background-color","#ccc"),target=$(this).attr("id"),$("#noteMask").css("z-index",99999)}),$("body").bind("mouseup",function(e){stopResize3Columns(),$("#noteMask").css("z-index",-1)}),$("body").bind("mousemove",function(e){lineMove&&(e.preventDefault(),resize3Columns(e))}),$("#moreBtn").click(function(){saveBookmark();var e=$("#mceToolbar").height();e<$("#popularToolbar").height()?($("#mceToolbar").height($("#popularToolbar").height()),$(this).find("i").removeClass("fa-angle-down").addClass("fa-angle-up")):($("#mceToolbar").height(e/2),$(this).find("i").removeClass("fa-angle-up").addClass("fa-angle-down")),resizeEditor(),restoreBookmark()}),$(window).resize(function(){resizeEditor()}),$(".folderHeader").click(function(){var e=$(this).next(),t=$(this).parent();e.is(":hidden")?($(".folderNote").removeClass("opened").addClass("closed"),t.removeClass("closed").addClass("opened"),$(this).find(".fa-angle-right").removeClass("fa-angle-right").addClass("fa-angle-down")):($(".folderNote").removeClass("opened").addClass("closed"),t.removeClass("opened").addClass("closed"),$(this).find(".fa-angle-down").removeClass("fa-angle-down").addClass("fa-angle-right"))}),tinymce.init({setup:function(e){e.on("keydown",Note.saveNote),e.on("keydown",function(t){var o=t.which?t.which:t.keyCode;if(9==o){if(!t.shiftKey){var i=e.selection.getNode();"PRE"==i.nodeName?e.execCommand("mceInsertRawHTML",!1," "):e.execCommand("mceInsertRawHTML",!1,"&nbsp;&nbsp;&nbsp;&nbsp;")}return t.preventDefault(),t.stopPropagation(),!1}}),e.on("click",function(e){$("body").trigger("click")}),e.on("click",function(){log(e.selection.getNode())})},selector:"#editorContent",content_css:["css/bootstrap.css","css/editor/editor.css"].concat(em.getWritingCss()),skin:"custom",language:LEA.locale,plugins:["autolink link leaui_image lists charmap hr","paste","searchreplace leanote_nav leanote_code tabfocus","table directionality textcolor codemirror"],toolbar1:"formatselect | forecolor backcolor | bold italic underline strikethrough | leaui_image | leanote_code | bullist numlist | alignleft aligncenter alignright alignjustify",toolbar2:"outdent indent blockquote | link unlink | table | hr removeformat | subscript superscript |searchreplace | code | pastetext | fontselect fontsizeselect",menubar:!1,toolbar_items_size:"small",statusbar:!1,url_converter:!1,font_formats:"Arial=arial,helvetica,sans-serif;Arial Black=arial black,avant garde;Times New Roman=times new roman,times;Courier New=courier new,courier;Tahoma=tahoma,arial,helvetica,sans-serif;Verdana=verdana,geneva;宋体=SimSun;新宋体=NSimSun;黑体=SimHei;微软雅黑=Microsoft YaHei",block_formats:"Header 1=h1;Header 2=h2;Header 3=h3; Header 4=h4;Pre=pre;Paragraph=p",codemirror:{indentOnInit:!0,path:"CodeMirror",config:{lineNumbers:!0},jsFiles:[]},paste_data_images:!0}),window.onbeforeunload=function(e){Note.curChangedSaveIt()},$("body").on("keydown",Note.saveNote)});var random=1;$(function(){function e(e){showDialog("dialogSetInfo",{title:"帐户设置",postShow:function(){$("#myTabs a").eq(e).tab("show"),$("#username").val(UserInfo.Username)}})}function t(e){ajaxGet("/user/updateLeftIsMin",{leftIsMin:e})}function o(e){$("#leftNotebook").width(30),$("#notebook").hide(),$("#noteAndEditor").css("left",30),$("#notebookSplitter").hide(),$("#logo").hide(),$("#leftSwitcher").hide(),$("#leftSwitcher2").show(),e&&t(!0)}function i(e){$("#noteAndEditor").css("left",UserInfo.NotebookWidth),$("#leftNotebook").width(UserInfo.NotebookWidth),$("#notebook").show(),$("#notebookSplitter").show(),$("#leftSwitcher2").hide(),$("#logo").show(),$("#leftSwitcher").show(),e&&t(!1)}function n(e){var t=$(e).offset(),o=$(document).height()-t.top;o-=70,0>o&&(o=0);var i=$(e).find("ul").height();return o>i?i:o}$("#leanoteNav h1").on("click",function(e){$("#leanoteNav").hasClass("unfolder")?$("#leanoteNav").removeClass("unfolder"):$("#leanoteNav").addClass("unfolder")}),$("#setInfo").click(function(){UserInfo.Email?e(0):showDialog("thirdDialogSetInfo",{title:"帐户设置",postShow:function(){$("#thirdMyTabs a").eq(0).tab("show")}})}),$("#setTheme").click(function(){showDialog2("#setThemeDialog",{title:"主题设置",postShow:function(){UserInfo.Theme||(UserInfo.Theme="default"),$("#themeForm input[value='"+UserInfo.Theme+"']").attr("checked",!0)}})}),$("#themeForm").on("click","input",function(e){var t=$(this).val();$("#themeLink").attr("href","/css/theme/"+t+".css"),ajaxPost("/user/updateTheme",{theme:t},function(e){reIsOk(e)&&(UserInfo.Theme=t)})}),$("#leanoteDialog").on("click","#accountBtn",function(e){e.preventDefault();var t=$("#thirdEmail").val(),o=$("#thirdPwd").val(),i=$("#thirdPwd2").val();if(!t)return void showAlert("#thirdAccountMsg","请输入邮箱","danger","#thirdEmail");var n=/^([a-zA-Z0-9]+[_|\_|\.]?)*[a-zA-Z0-9]+@([a-zA-Z0-9]+[_|\_|\.]?)*[a-zA-Z0-9]+\.[a-zA-Z]{2,3}$/;return n.test(t)?o?o.length<6?void showAlert("#thirdAccountMsg","密码长度至少6位","danger","#thirdPwd"):i?o!=i?void showAlert("#thirdAccountMsg","两次密码输入不一致","danger","#thirdPwd2"):(hideAlert("#thirdAccountMsg"),void post("/user/addAccount",{email:t,pwd:o},function(e){e.Ok?(showAlert("#thirdAccountMsg","添加成功!","success"),UserInfo.Email=t,$("#curEmail").html(t),hideDialog(1e3)):showAlert("#thirdAccountMsg",e.Msg||"添加失败!","danger")},this)):void showAlert("#thirdAccountMsg","请重复输入密码","danger","#thirdPwd2"):void showAlert("#thirdAccountMsg","请输入密码","danger","#thirdPwd"):void showAlert("#thirdAccountMsg","请输入正确的邮箱","danger","#thirdEmail")}),$("#leanoteDialog").on("click","#usernameBtn",function(e){e.preventDefault();var t=$("#leanoteDialog #username").val();return t?t.length<4?void showAlert("#usernameMsg","用户名长度至少4位","danger"):/[^0-9a-zzA-Z_\-]/.test(t)?void showAlert("#usernameMsg","用户名不能含除数字,字母之外的字符","danger"):(hideAlert("#usernameMsg"),void post("/user/updateUsername",{username:t},function(e){e.Ok?(UserInfo.UsernameRaw=t,UserInfo.Username=t.toLowerCase(),$(".username").html(t),showAlert("#usernameMsg","用户名修改成功!","success")):showAlert("#usernameMsg",re.Msg||"该用户名已存在","danger")},"#usernameBtn")):void showAlert("#usernameMsg","请输入用户名","danger")}),$("#leanoteDialog").on("click","#emailBtn",function(e){e.preventDefault();var t=isEmailFromInput("#email","#emailMsg");t&&(hideAlert("#emailMsg"),post("/user/updateEmailSendActiveEmail",{email:t},function(e){if(e.Ok){var o=getEmailLoginAddress(t);showAlert("#emailMsg","验证邮件已发送, 请及时查阅邮件并验证. <a href='"+o+"' target='_blank'>立即验证</a>","success")}else showAlert("#emailMsg",e.Msg||"邮件发送失败","danger")},"#emailBtn"))}),$("#leanoteDialog").on("click","#pwdBtn",function(e){e.preventDefault();var t=$("#oldPwd").val(),o=$("#pwd").val(),i=$("#pwd2").val();return t?t.length<6?void showAlert("#pwdMsg","密码长度至少6位","danger","#oldPwd"):o?o.length<6?void showAlert("#pwdMsg","密码长度至少6位","danger","#pwd"):i?o!=i?void showAlert("#pwdMsg","两次密码输入不一致","danger","#pwd2"):(hideAlert("#pwdMsg"),void post("/user/updatePwd",{oldPwd:t,pwd:o},function(e){e.Ok?showAlert("#pwdMsg","修改密码成功","success"):showAlert("#pwdMsg",e.Msg,"danger")},"#pwdBtn")):void showAlert("#pwdMsg","请重复输入新密码","danger","#pwd2"):void showAlert("#pwdMsg","请输入新密码","danger","#pwd"):void showAlert("#pwdMsg","请输入旧密码","danger","#oldPwd")}),!UserInfo.Verified,$("#wrongEmail").click(function(){e(1)}),$("#leanoteDialog").on("click",".reSendActiveEmail",function(){showDialog("reSendActiveEmailDialog",{title:"发送验证邮件",postShow:function(){ajaxGet("/user/reSendActiveEmail",{},function(e){"object"==typeof e&&e.Ok?($("#leanoteDialog .text").html("发送成功!"),$("#leanoteDialog .viewEmailBtn").removeClass("disabled"),$("#leanoteDialog .viewEmailBtn").click(function(){hideDialog();var e=getEmailLoginAddress(UserInfo.Email);window.open(e,"_blank")})):$("#leanoteDialog .text").html("发送失败")})}})}),$("#leanoteDialog").on("click",".nowToActive",function(){var e=getEmailLoginAddress(UserInfo.Email);window.open(e,"_blank")}),$("#notebook, #newMyNote, #myProfile, #topNav, #notesAndSort","#leanoteNavTrigger").bind("selectstart",function(e){return e.preventDefault(),!1}),$("#leftSwitcher2").click(function(){i(!0)}),$("#leftSwitcher").click(function(){o(!0)}),$("#notebookMin div.minContainer").hover(function(){var e=$(this).attr("target");$(this).find("ul").html($(e).html()).show().height(n(this))},function(){$(this).find("ul").hide()}),UserInfo.NotebookWidth=UserInfo.NotebookWidth||$("#notebook").width(),UserInfo.NoteListWidth=UserInfo.NoteListWidth||$("#noteList").width(),LEA.isMobile&&(UserInfo.NoteListWidth=101),UserInfo.LeftIsMin&&o(!1),$("#mainMask").html(""),$("#mainMask").hide(100),$(".dropdown").on("shown.bs.dropdown",function(){var e=$(this).find("ul");e.height(n(this))}),$("#tipsBtn").click(function(){showDialog2("#tipsDialog")}),$("#yourSuggestions").click(function(){showDialog2("#suggestionsDialog")}),$("#suggestionBtn").click(function(e){e.preventDefault();var t=$.trim($("#suggestionTextarea").val());return t?($("#suggestionBtn").html("正在处理...").addClass("disabled"),$("#suggestionMsg").html("正在处理..."),void $.post("/suggestion",{suggestion:t},function(e){$("#suggestionBtn").html("提交").removeClass("disabled"),e.Ok?$("#suggestionMsg").html("谢谢反馈, 我们会第一时间处理, 祝您愉快!").addClass("alert-success").removeClass("alert-warning").show():$("#suggestionMsg").html("出错了").show().addClass("alert-warning").removeClass("alert-success")})):($("#suggestionMsg").html("请输入您的建议, 谢谢!").show().addClass("alert-warning").removeClass("alert-success"),void $("#suggestionTextarea").focus())}),em.init()}),editorMode.prototype.toggleAText=function(e){var t=this;setTimeout(function(){toggleA=$("#toggleEditorMode a"),e?toggleA.attr("href",t.normalHash).text(getMsg("normalMode")):toggleA.attr("href",t.writingHash).text(getMsg("writingMode"))},0)},editorMode.prototype.isWriting=function(e){return e==this.writingHash},editorMode.prototype.init=function(){this.changeMode(this.isWritingMode);var e=this;$("#toggleEditorMode").click(function(){saveBookmark();var t=$(this).find("a"),o=e.isWriting(t.attr("href"));e.changeMode(o),restoreBookmark()})},editorMode.prototype.changeMode=function(e){this.toggleAText(e),e?this.writtingMode():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 e=$("#editorContent_ifr").contents();e.contents().find("#writtingMode").remove(),e.contents().find('link[href$="editor-writting-mode.css"]').remove(),$("#noteItemListWrap, #notesAndSort").show(),$("#noteList").unbind("mouseenter").unbind("mouseleave");var t=UserInfo.Theme||"default";t+=".css",$("#themeLink").attr("href","/css/theme/"+t),$("#mceToolbar").css("height","30px"),this.resizeEditor()},editorMode.prototype.writtingMode=function(){$("#themeLink").attr("href","/css/theme/writting-overwrite.css"),setTimeout(function(){var e=$("#editorContent_ifr").contents();e.contents().find("head").append('<link type="text/css" rel="stylesheet" href="/css/editor/editor-writting-mode.css" id="writtingMode">')},0),$("#noteItemListWrap, #notesAndSort").fadeOut(),$("#noteList").hover(function(){$("#noteItemListWrap, #notesAndSort").fadeIn()},function(){$("#noteItemListWrap, #notesAndSort").fadeOut()}),$("#mceToolbar").css("height","40px"),this.resizeEditor()},editorMode.prototype.getWritingCss=function(){return this.isWritingMode?["css/editor/editor-writting-mode.css"]:[]};var initUploader=function(){function e(e){return"number"!=typeof e?"":e>=1e9?(e/1e9).toFixed(2)+" GB":e>=1e6?(e/1e6).toFixed(2)+" MB":(e/1e3).toFixed(2)+" KB"}var t=$("#upload ul");$("#drop a").click(function(){$(this).parent().find("input").click()}),$("#upload").fileupload({dataType:"json",acceptFileTypes:/(\.|\/)(gif|jpg|jpeg|png|jpe)$/i,maxFileSize:21e4,dropZone:$("#drop"),formData:function(e){return[{name:"albumId",value:""}]},add:function(o,i){var n=$('<li><div class="alert alert-info"><img class="loader" src="public/images/ajax-loader.gif"> <a class="close" data-dismiss="alert">×</a></div></li>');n.find("div").append(i.files[0].name+" <small>[<i>"+e(i.files[0].size)+"</i>]</small>"),i.context=n.appendTo(t);var s=i.submit()},done:function(t,o){if(1==o.result.Ok)o.context.remove(),self.addSelectedImage(o.result.Id),self.uploadRefreshImageList();else{o.context.empty();var i=$('<li><div class="alert alert-danger"><a class="close" data-dismiss="alert">×</a></div></li>');i.find("div").append("<b>Error:</b> "+o.files[0].name+" <small>[<i>"+e(o.files[0].size)+"</i>]</small> "+o.result.Msg),o.context.append(i)}$("#upload-msg").scrollTop(1e3)},fail:function(t,o){o.context.empty();var i=$('<li><div class="alert alert-danger"><a class="close" data-dismiss="alert">×</a></div></li>');i.find("div").append("<b>Error:</b> "+o.files[0].name+" <small>[<i>"+e(o.files[0].size)+"</i>]</small> "+o.errorThrown),o.context.append(i),$("#upload-msg").scrollTop(1e3)}}),$(document).on("drop dragover",function(e){e.preventDefault()}),$(document).bind("dragover",function(e){var t=$("#drop"),o=window.dropZoneTimeout;o?clearTimeout(o):t.addClass("in");var i=!1,n=e.target;do{if(n===t[0]){i=!0;break}n=n.parentNode}while(null!=n);i?t.addClass("hover"):t.removeClass("hover"),window.dropZoneTimeout=setTimeout(function(){window.dropZoneTimeout=null,t.removeClass("in hover")},100)})};$(function(){initUploader()});