"use strict";function _classCallCheck(e,t){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")}function _defineProperties(e,t){for(var n=0;n'},makphone:{icon:''}},this.element=$(this.option.element),this.element.addClass("cEditor"),this.savedRange=null,this.recodeTimeout=null,this.init()}return _createClass(t,[{key:"init",value:function(){var t=this,e='\n
\n
\n
\n
\n ');2==this.option.windowStyle&&(e='\n
\n \n
\n ')),this.element.html(e),this.area=this.element.find(".cEditor-area"),1==this.option.windowStyle?(this.renderBtn(),this.area.on("keydown",function(e){e.ctrlKey||13!=e.keyCode?e.ctrlKey&&13==e.keyCode&&(e.preventDefault(),document.execCommand("insertParagraph",!1,null),t.area.parent().scrollTop(99999)):e.preventDefault()}),this.area.on("keyup",function(e){e.ctrlKey||13!=e.keyCode||t.option.onenter(),t.option.onchange(t.getData())}),this.area.on("paste",function(e){!function(e){e=e||window.event;e.preventDefault();e=(e=(e.originalEvent||e).clipboardData.getData("text/plain")).replace(/\[\d+\]|\n|\r/gi,"");document.execCommand("insertText",!1,e)}(e),t.option.onchange(t.getData()),t.area.parent().scrollTop(99999)})):(this.area.on("keydown",function(e){13==e.keyCode&&(t.option.onenter(),e.preventDefault())}),this.area.on("input",function(e){t.option.onchange(t.getData())}))}},{key:"makphoneStatus",value:function(e,t){1==t?(e.addClass("loading").removeClass("active"),this.element.find(".con-makphone").text("正在获取当前浏览器的麦克风权限").show(),e.html('')):2==t?(e.addClass("active").removeClass("loading"),this.element.find(".con-makphone").text("录音中,点击停止录音,最多支持30秒").show(),e.html('')):3==t?(e.removeClass("active").removeClass("loading").removeClass("stopLoading"),this.element.find(".con-makphone").hide(),e.html('')):4==t&&(e.removeClass("active").removeClass("loading").addClass("stopLoading"),this.element.find(".con-makphone").text("正在识别语音内容").show(),e.html(''))}},{key:"renderBtn",value:function(){var n=this;this.option.btn.forEach(function(t){n.element.find(".cEditor-oprate").append('")),n.element.find(".cEditor-oprate").append('
')),n.handleBar(t),n.element.on("click",".".concat(t),function(e){"emoji"==t?(n.focus(),n.saveSelection(),0==n.savedRange.startOffset&&0==n.savedRange.endOffset&&(n.placeCursorAtEnd(),n.saveSelection()),n.opClick(t)):"makphone"==t&&(navigator.getUserMedia?$(e.currentTarget).hasClass("loading")||$(e.currentTarget).hasClass("stopLoading")||(n.focus(),n.saveSelection(),$(e.currentTarget).hasClass("active")?n.stopRecord(e):n.startRecord(e)):$.pl_toast({msg:"您的浏览器不支持录音功能!"}))})}),$(document).click(function(e){var t=n.element.find(".op-btn");t.is(e.target)||0!==t.has(e.target).length||n.element.find(".op-con.con-emoji").hide()})}},{key:"startRecord",value:function(t){var n=this;this.makphoneStatus($(t.currentTarget),1),this.recording.startRecording(function(e){"error"!=e?(n.makphoneStatus($(t.currentTarget),2),n.recodeTimeout=setTimeout(function(){n.stopRecord(t)},3e4)):n.makphoneStatus($(t.currentTarget),3)})}},{key:"stopRecord",value:function(n){var o=this;this.recodeTimeout&&clearTimeout(this.recodeTimeout),this.makphoneStatus($(n.currentTarget),4),this.recording.stopRecording(function(e){o.makphoneStatus($(n.currentTarget),3);try{var t=e.data.result[0];o.focus(),document.execCommand("insertText",!1,t),o.option.onchange(o.getData())}catch(e){}})}},{key:"handleBar",value:function(t){var n=this;"emoji"==t?o.init({ele:this.element.find(".cEditor-oprate .con-emoji"),onClick:function(e){n.element.find(".con-".concat(t)).hide();e=o.symbolToEmoji(e);n.insertEmoji(e)}}):"makphone"==t&&(this.recording=new a)}},{key:"placeCursorAtEnd",value:function(){var e=this.area[0],t=document.createRange(),n=window.getSelection();t.selectNodeContents(e),t.collapse(!1),n.removeAllRanges(),n.addRange(t)}},{key:"saveSelection",value:function(){var e=window.getSelection();0