/*! wangEditor-mobile.js 2016-01-04 */
!function(a){a.___E_mod=function(b){var c=a.___E;null!=c&&b(c,a.Zepto)}}(window),function(a){var b=a.Zepto,c=a.___E,d="github.com/wangfupeng1988/wangEditor-mobile";if(null!=c){if(c.gitlink===d)return void alert("不得重复引用wangEditor的js文件");if(!c.gitlink||c.gitlink!==d)return void alert("window.___E 属性名已经被其他程序占用。wangEditor-mobile引用失败")}return null==b?void alert("wangEditor-mobile依赖于zepto,请先引用zepto.js"):document.createRange&&"function"==typeof document.createRange?void 0:void alert("当前浏览器不支持document.createRange,不能生成富文本编辑器")}(window),function(a,b){var c="github.com/wangfupeng1988/wangEditor-mobile",d=function(a){var c=this;c.$body=b("body");var d=b("#"+a);c.$textarea=d,c.checkTapTime=function(a,d){var e,f,g=a.type.toLowerCase(),h=!0;return g.indexOf("tap")<0?h:(a?(e=a.currentTarget||a.target,f=b(e)):f=c.$body,null==f.data("tapTime")?(f.data("tapTime",Date.now().toString()),h=!0):Date.now()-parseInt(f.data("tapTime"))<100?(a.preventDefault(),a.stopPropagation(),h=!1):(f.data("tapTime",Date.now().toString()),h=!0),h)},c.initDefaultConfig(),c.addTxt(),c.addMenus()};d.fn=d.prototype,d.fn.gitlink=c,d.log=function(b,c){a.console?c?console.log(b,c):console.log(b):(alert(b),c&&alert(c))},d.warn=function(b,c){a.console?c?console.warn(b,c):console.warn(b):(alert(b),c&&alert(c))},a.___E=d}(window,window.Zepto),window.___E_mod(function(a,b){}),window.___E_mod(function(a,b){var c=window.navigator.userAgent.toLowerCase();a.isAndroid=c.indexOf("android")>0,a.isUC=c.indexOf("ucbrowser")>0,a.agent=c}),window.___E_mod(function(a,b){a.config={menuColorValue:"red",menuQuoteStyle:{display:"block","border-left":"5px solid #d0e5f2",padding:"4px 0 4px 10px","background-color":"#f1f1f1",margin:"4px 0"},menus:["head","bold","color","quote","list","img","happy","check"],happy:["http://wangeditor.github.io/expressions/1.gif","http://wangeditor.github.io/expressions/2.gif","http://wangeditor.github.io/expressions/3.gif","http://wangeditor.github.io/expressions/4.gif","http://wangeditor.github.io/expressions/5.gif","http://wangeditor.github.io/expressions/6.gif","http://wangeditor.github.io/expressions/7.gif","http://wangeditor.github.io/expressions/8.gif","http://wangeditor.github.io/expressions/9.gif","http://wangeditor.github.io/expressions/10.gif","http://wangeditor.github.io/expressions/11.gif","http://wangeditor.github.io/expressions/12.gif","http://wangeditor.github.io/expressions/13.gif","http://wangeditor.github.io/expressions/14.gif","http://wangeditor.github.io/expressions/15.gif","http://wangeditor.github.io/expressions/16.gif","http://wangeditor.github.io/expressions/17.gif","http://wangeditor.github.io/expressions/18.gif","http://wangeditor.github.io/expressions/19.gif","http://wangeditor.github.io/expressions/20.gif"],uploadImgUrl:"",uploadTimeout:1e4,testHostname:"localhost",loadingImg:"http://images2015.cnblogs.com/blog/138012/201512/138012-20151208194759027-506651939.gif"}}),window.___E_mod(function(a,b){a.fn.initDefaultConfig=function(){var c=this,d=a.config,e=b.extend({},d);c.config=e}}),window.___E_mod(function(a,b){a.isAndroid,a.isUC}),window.___E_mod(function(a,b){a.fn.addTxt=function(){var a=this,c=a.$textarea,d=b.trim(c.val()),e=b('
'),$modal:b('
'),renderModal:function(){var a=this,c=a.$modal,f='

',h=[];b.each(g,function(a,b){h.push(f.replace(/#{imgUrl}/gi,b))}),c.append(h.join("")),e.append(c);var i=c.width();c.css("margin-left",(0-i)/2),c.on("click",".command-link",function(a){a.preventDefault()}),c.on("singleTap",".command-link",function(c){if(d.checkTapTime(c,"happy command-link")!==!1){var e=b(c.currentTarget),f=e.attr("commandValue");d.command("InsertImage",!1,f,c),a.hideModal()}})},showModal:function(){var a=this,b=a.$modal,c=e.get(0).scrollTop;b.show(),b.css({"margin-top":c+50+"px"});var d=function(b){a.hideModal(),h.off("singleTap",d)};h.on("singleTap",d)},hideModal:function(){this.$modal.hide()},bindEvent:function(a){function b(){e.renderModal(),e.showModal()}function c(){e.showModal()}var e=this,f=e.$trigger;e.$modal;f.one("singleTap",function(a){d.checkTapTime(a,"happy one")!==!1&&d.customCommand(!0,b,a)}),f.on("singleTap",function(a){d.checkTapTime(a,"happy on")!==!1&&d.customCommand(!0,c,a)})},updateStyle:function(){}}}}),window.___E_mod(function(a,b){a.fn.addMenuImg=function(c){function d(b){j&&a.log(b)}var e=this,f=e.$body,g=(e.$txt,e.menus),h=a.isAndroid,i=a.isUC,j=!1,k="inputfile"+Math.random().toString().slice(2);g[c]={selected:!1,$trigger:function(){return b(h||i?'
':'
')}(),$wrap:b('
'),renderForm:function(){var a=["
"].join(""),c=b('
');c.html(a),f.append(c)},bindEvent:function(a){function c(a,b){for(var c=window.atob(a.split(",")[1]),d=new ArrayBuffer(c.length),e=new Uint8Array(d),f=0;f
上传中...

')):(h=k,q.after('

')),d("生成预览图片,src是:"+h),i=new XMLHttpRequest,j=new FormData,d("准备上传文件..."),i.open("POST",g,!0),m=setTimeout(f,l),i.onload=function(){clearTimeout(m);var a,c,f,g=i.responseText,h=b("#"+r);d("服务器端的返回数据为:"+g),0===g.indexOf("error|")?(a=g.split("|")[1],d("很遗憾,后台返回error,错误信息为:"+a),alert("上传图片错误: \n"+a),h.remove()):(d("请确认以上图片是否有效,无效将无法显示在页面中"),d("准备下载该图片..."),b("#"+s).text("加载中..."),c=document.createElement("img"),c.src=g,c.onload=function(){d("下载完成,正式呈现在编辑区域"),f=b(c),f.css("max-width","100%"),h.after(f),h.remove(),e.saveSourceCode()},c.onerror=function(){d("图片加载失败,请确定这个url是否能成功得到图片:"+g),alert("图片加载失败"),h.remove(),e.saveSourceCode()})},j.append("wangEditorMobileFile",c(p,o)),i.send(j)},p.readAsDataURL(n)}}),g.on("singleTap",function(a){function b(){h.trigger("click")}e.checkTapTime(a,"img")!==!1&&e.customCommand(!0,b,a)})},updateStyle:function(){}}}}),window.___E_mod(function(a,b){a.fn.renderTxt=function(){var a=this,b=a.$textarea,c=a.$txt,d=a.$modalContainer,e=a.$body;b.after(c),b.hide(),e.append(d)}}),window.___E_mod(function(a,b){a.fn.renderMenu=function(){var a=this,c=a.menus,d=a.$menuContainer,e=a.$menuItemContainer,f=(a.$txt,b('
')),g=a.$body,h=a.config.menus;b.each(h,function(a,b){var d=c[b];if(null!=d){var g=d.$trigger,h=d.$wrap;g&&(h?(h.append(g),e.append(h)):e.append(g),e.append(f.clone()))}}),e.children().last().remove(),d.hide(),a.menuDisplayShow=!1,g.append(d)}}),window.___E_mod(function(a,b){a.fn.bindDocumentEvent=function(){var a=b(document),c=this,d=(c.$txt,Date.now());a.on("scroll",function(a){Date.now()-d<=50||(d=Date.now(),c.hideMenuContainer())})}}),window.___E_mod(function(a,b){a.fn.bindTxtEvent=function(){function a(){var a,d;c.saveSelection(),a=c.getWrapRangeElem(),a&&(d=b(a),d.addClass("focus-elem"),c.$focusElem=d),c.updateMenuStyle()}var c=this,d=c.$txt,e=c.$menuContainer,f=e.get(0),g=Date.now();d.on("focus",function(){c.isFocus=!0}),d.on("singleTap",function(e){if(c.checkTapTime(e,"$txt")!==!1&&c.isFocus){var f=b(e.target);if(c.eventTarget(f),f.hasClass("focus-elem"))return void c.hideMenuContainer();if("IMG"===f.get(0).nodeName)return void c.hideMenuContainer();if(f.get(0)===d.get(0))return void c.hideMenuContainer();c.setMenuContainerPosition();var g=c.$focusElem;g&&g.removeClass("focus-elem"),setTimeout(a,c.txtTapDelay),c.txtTapDelay=100,e.stopPropagation()}}),d.on("scroll",function(a){Date.now()-g<=50||(g=Date.now(),c.hideMenuContainer(),a.stopPropagation())}),d.on("keydown",function(a){c.hideMenuContainer();var b=d.html();8===a.keyCode&&/^<(\w+)[^<>]*>
<\/\1>$/.test(b)&&a.preventDefault()}),d.on("longTap, doubleTap",function(){c.hideMenuContainer()}),d.on("blur",function(a){c.isFocus=!1;var b=a.explicitOriginalTarget;return f.contains(b)?void a.preventDefault():(c.saveSourceCode(),void c.hideMenuContainer())})}}),window.___E_mod(function(a,b){a.fn.bindMenuContainerEvent=function(){var a=this,b=a.$menuContainer;b.on("tap",function(a){a.preventDefault(),a.stopPropagation()})}}),window.___E_mod(function(a,b){a.fn.bindMenuBtnEvent=function(){var a=this,c=a.menus;b.each(c,function(b,c){var d=c.bindEvent;d&&"function"==typeof d&&d.call(c,a)})}}),window.___E_mod(function(a,b){a.fn.eventTarget=function(a){var b=this;return null==a?b.$eventTargetElem:void(b.$eventTargetElem=a)},a.fn.saveSourceCode=function(){var a=this,b=a.$txt,c=a.$textarea,d="",e=b.clone(),f=e.find(".focus-elem");f.removeClass("focus-elem"),d=e.html(),d=d.replace(/\s?class=""/g,""),c.val(d)},a.fn.insertEmpltyLink=function(){var a=this,c=a.$txt,d=c.children();return 0===d.length?void c.append(b("
")):void("
"!==d.last().html()&&c.append(b("
")))}}),window.___E_mod(function(a,b){a.fn.setMenuContainerPosition=function(){var a=this,b=a.eventTarget(),c=b.offset().top,d=a.$txt,e=d.offset().top,f=d.offset().left,g=a.$menuContainer,h=(g.height(),c);e>h&&(h=e),h-=55,g.css({top:h,left:f+2}),a.showMenuContainer()},a.fn.showMenuContainer=function(){var a=this,b=a.$menuContainer;a.menuDisplayShow===!1&&(b.show(),b.css("opacity","0.9"),a.menuDisplayShow=!0)},a.fn.hideMenuContainer=function(){var a=this,b=a.$menuContainer,c=a.$txt,d=a.$focusElem,e=c.find(".focus-elem");a.menuDisplayShow&&(b.hide(),b.css("opacity","0"),a.menuDisplayShow=!1,d&&(d.removeClass("focus-elem"),e.removeClass("focus-elem")))}}),window.___E_mod(function(a,b){a.fn.updateMenuStyle=function(){var a=this,c=a.menus;b.each(c,function(a,b){var c=b.updateStyle;c&&c.call(b)})}}),window.___E_mod(function(a,b){var c=/insertimage/i;a.fn.command=function(a,b,d,e,f){var g=this,h=c.test(a),i=function(){document.execCommand(a,!!b,d)};g.customCommand(h,i,e,f)},a.fn.customCommand=function(a,b,c,d){var e=this,f=e.currentRange(),g=e.currentWrapRange();e.$txt;a?e.restoreSelection(f):e.restoreSelection(g),b(),e.insertEmpltyLink(),e.saveSelection(),e.restoreSelection(f),c&&(c.preventDefault(),c.stopPropagation()),d&&d.call(e),e.hideMenuContainer()}}),window.___E_mod(function(a,b){a.fn.currentRange=function(a){return a?void(this.currentRangeData=a):this.currentRangeData},a.fn.currentWrapRange=function(a){return a?void(this.currentWrapRangeData=a):this.currentWrapRangeData},a.fn.getWrapRangeElem=function(){var a,b,c=this,d=c.$txt,e=d.attr("class"),f=this.currentWrapRange();c.eventTarget().get(0);return null!=f?(a=f.commonAncestorContainer,b=3===a.nodeType?a.parentNode:a,b.className===e&&(b=d.children().last().get(0)||b),b):void 0},a.fn.saveSelection=function(a){var b,c,d,e=this,f=e.$txt.get(0);a?b=a.commonAncestorContainer:(c=document.getSelection(),c.getRangeAt&&c.rangeCount&&(a=document.getSelection().getRangeAt(0),b=a.commonAncestorContainer)),b&&(f.contains(b)||f===b)&&(e.currentRange(a),d=document.getSelection().getRangeAt(0),d.selectNodeContents(b),e.currentWrapRange(d))},a.fn.restoreSelection=function(a){var b;a&&(b=document.getSelection(),b.removeAllRanges(),b.addRange(a))}}),window.___E_mod(function(a,b){}),window.___E_mod(function(a,b){a.fn.init=function(){var a=this;a.renderTxt(),a.renderMenu(),a.bindDocumentEvent(),a.bindTxtEvent(),a.bindMenuBtnEvent(),a.bindMenuContainerEvent()}});