2017-06-12 17:58:45 +08:00
|
|
|
$(document).ready(function(){function getParameters(){var parameters={};window.location.search.substr(1).split("&").forEach(function(pair){if(pair===""){return;}var parts=pair.split("=");if(parts.length===2&&parts[1].search(/^(true|1)$/i)>=0){parameters[parts[0]]=true;}else{if(parts.length===2&&parts[1].search(/^(false|0)$/i)>=0){parameters[parts[0]]=false;}else{parameters[parts[0]]=parts[1]&&decodeURIComponent(parts[1].replace(/\+/g," "));}}});return{get:function(name,defaultValue){if(parameters.hasOwnProperty(name)){return parameters[name];}return defaultValue;}};}var parameters=getParameters();if(parameters.get("test",false)){var li=$("<li>Tests</li>");var ul=$("<ul>");for(var i=1;i<=8;++i){ul.append($('<li id="examples-test'+i+'">Test '+i+"</li>"));}li.append(ul);$("#main-menu").append(li);}function handleFind(column){if(!column.length){return false;}var ed=$("#mergely");var find=column.find(".find");var input=find.find('input[type="text"]');var side=column.attr("id").indexOf("-lhs")>0?"lhs":"rhs";var origautoupdate=ed.mergely("options").autoupdate;find.slideDown("fast",function(){input.focus();ed.mergely("options",{autoupdate:false});ed.mergely("unmarkup");});find.find(".find-prev").click(function(){ed.mergely("search",side,input.val(),"prev");});find.find(".find-next").click(function(){ed.mergely("search",side,input.val(),"next");});find.find(".find-close").click(function(){find.css("display","none");ed.mergely("options",{autoupdate:origautoupdate});});input.keydown(function(evt){if(evt.which!=13&&evt.which!=27){return true;}if(evt.which==27){find.css("display","none");ed.mergely("options",{autoupdate:origautoupdate});}ed.mergely("search",side,input.val());return false;});}$(document).keydown(function(event){if(!(String.fromCharCode(event.which).toLowerCase()=="f"&&event.ctrlKey)){return true;}event.preventDefault();var range=window.getSelection().getRangeAt(0);var column=$(range.commonAncestorContainer).parents(".mergely-column");handleFind(column);return false;});String.prototype.random=function(length){var chars="0123456789ABCDEFGHIJKLMNOPQRSTUVWXTZabcdefghiklmnopqrstuvwxyz";var randomstring="";for(var i=0;i<length;i++){var rnum=Math.floor(Math.random()*chars.length);randomstring+=chars.substring(rnum,rnum+1);}return randomstring;};$("body").css("visibility","");var ed=$("#mergely");var menu=$("#main-menu");var toolbar=$("#toolbar");ed.mergely({width:"auto",height:"auto",cmsettings:{lineNumbers:true,readOnly:false}});ed.mergely("lhs",$("#historyContent").html());ed.mergely("rhs",$("#documentContent").html());var urloptions={};var optmap={au:"autoupdate",ws:"ignorews",cs:"ignorecase",sb:"sidebar",vp:"viewport",wl:"wrap_lines",ln:"line_numbers"};var doopt=false;for(var name in optmap){if(!optmap.hasOwnProperty(name)){continue;}if(parameters.get(name,null)!==null){urloptions[optmap[name]]=parameters.get(name);doopt=true;}}if(parameters.get("rm",null)!==null){urloptions.rhs_margin=parameters.get("rm")?"left":"right";}if(doopt){ed.mergely("options",urloptions);}var color_defaults={cb:"cccccc",cg:"fafafa",ab:"a3d1ff",ag:"ddeeff",db:"ff7f7f",dg:"ffe9e9"};applyParameterCss(false);window.addEventListener("popstate",function(ev){if(ev.state){parameters=getParameters();applyParameterCss(false);}});if(key.length===8){$.when($.ajax({type:"GET",async:true,dataType:"text",data:{key:key,name:"lhs"},url:"/ajax/handle_get.php",success:function(response){ed.mergely("lhs",response);},error:function(xhr,ajaxOptions,thrownError){}}),$.ajax({type:"GET",async:true,dataType:"text",data:{key:key,name:"rhs"},url:"/ajax/handle_get.php",success:function(response){ed.mergely("rhs",response);},error:function(xhr,ajaxOptions,thrownError){}})).done(function(){var anchor=window.location.hash.substring(1);if(anchor){var m=anchor.match(/([lr]hs)([0-9]+)/);if(m&&m.length==3){console.log(m);ed.mergely("scrollTo",m[1],parseInt(m[2],10));}}});}var find=$(".find");var flhs=find.clone().attr("id","mergely-editor-lhs-find");var frhs=find.clone().attr("id","mergely-editor-rhs-find");$("#mergely-editor-lhs").append(flhs);$("#mergely-editor-rhs").append(fr
|