text: !function(e,t){"use strict";function o(o,n){this.selectedRange=null,this.editor=t(o);var a=t(o),i={hotKeys:{"Ctrl+b meta+b":"bold","Ctrl+i meta+i":"italic","Ctrl+u meta+u":"underline","Ctrl+z":"undo","Ctrl+y meta+y meta+shift+z":"redo","Ctrl+l meta+l":"justifyleft","Ctrl+r meta+r":"justifyright","Ctrl+e meta+e":"justifycenter","Ctrl+j meta+j":"justifyfull","Shift+tab":"outdent",tab:"indent"},toolbarSelector:"[data-role=editor-toolbar]",commandRole:"edit",activeToolbarClass:"btn-info",selectionMarker:"edit-focus-marker",selectionColor:"darkgrey",dragAndDropImages:!0,keypressTimeout:200,fileUploadError:function(e,t){console.log("File upload error",e,t)}},r=t.extend(!0,{},i,n),l="a[data-"+r.commandRole+"],button[data-"+r.commandRole+"],input[type=button][data-"+r.commandRole+"]";this.bindHotkeys(a,r,l),r.dragAndDropImages&&this.initFileDrops(a,r,l),this.bindToolbar(a,t(r.toolbarSelector),r,l),a.attr("contenteditable",!0).on("mouseup keyup mouseout",function(){this.saveSelection(),this.updateToolbar(a,l,r)}.bind(this)),t(e).bind("touchend",function(e){var t=a.is(e.target)||a.has(e.target).length>0,o=this.getCurrentRange();(!(o&&o.startContainer===o.endContainer&&o.startOffset===o.endOffset)||t)&&(this.saveSelection(),this.updateToolbar(a,l,r))})}o.prototype.readFileIntoDataUrl=function(e){var o=t.Deferred(),n=new FileReader;return n.onload=function(e){o.resolve(e.target.result)},n.onerror=o.reject,n.onprogress=o.notify,n.readAsDataURL(e),o.promise()},o.prototype.cleanHtml=function(e){var o=this;if(!0===t(o).data("wysiwyg-html-mode")&&(t(o).html(t(o).text()),t(o).attr("contenteditable",!0),t(o).data("wysiwyg-html-mode",!1)),!0===e&&t(o).parent().is("form")){var n=t(o).html;if(t(n).has("img").length){var a=t("img",t(n)),i=[],r=t(o).parent();t.each(a,function(e,o){t(o).attr("src").match(/^data:image\/.*$/)&&(i.push(a[e]),t(r).prepend("<input value='"+t(o).attr("src")+"' type='hidden' name='postedimage/"+e+"' />"),t(o).attr("src","postedimage/"+e))})}}var l=t(o).html();return l&&l.replace(/(<br>|\s|<div><br><\/div>|&nbsp;)*$/,"")},o.prototype.updateToolbar=function(e,o,n){n.activeToolbarClass&&t(n.toolbarSelector).find(o).each(function(){var e=t(this),o=e.data(n.commandRole).split(" "),a=o[0];o.length>1&&document.queryCommandEnabled(a)&&document.queryCommandValue(a)===o[1]?e.addClass(n.activeToolbarClass):1===o.length&&document.queryCommandEnabled(a)&&document.queryCommandState(a)?e.addClass(n.activeToolbarClass):e.removeClass(n.activeToolbarClass)})},o.prototype.execCommand=function(e,t,o,n,a){var i=e.split(" "),r=i.shift(),l=i.join(" ")+(t||""),s=e.split("-");1===s.length?document.execCommand(r,!1,l):"format"===s[0]&&2===s.length&&document.execCommand("formatBlock",!1,s[1]),o.trigger("change"),this.updateToolbar(o,a,n)},o.prototype.bindHotkeys=function(e,o,n){var a=this;t.each(o.hotKeys,function(i,r){t(e).keydown(i,function(i){e.attr("contenteditable")&&t(e).is(":visible")&&(i.preventDefault(),i.stopPropagation(),a.execCommand(r,null,e,o,n))}).keyup(i,function(o){e.attr("contenteditable")&&t(e).is(":visible")&&(o.preventDefault(),o.stopPropagation())})}),e.keyup(function(){e.trigger("change")})},o.prototype.getCurrentRange=function(){var t,o;return e.getSelection?(t=e.getSelection()).getRangeAt&&t.rangeCount&&(o=t.getRangeAt(0)):document.selection&&(o=document.selection.createRange()),o},o.prototype.saveSelection=function(){this.selectedRange=this.getCurrentRange()},o.prototype.restoreSelection=function(){var t;if(e.getSelection||document.createRange){if(t=e.getSelection(),this.selectedRange){try{t.removeAllRanges()}catch(e){document.body.createTextRange().select(),document.selection.empty()}t.addRange(this.selectedRange)}}else document.selection&&this.selectedRange&&this.selectedRange.select()},o.prototype.toggleHtmlEdit=function(e){if(!0!==e.data("wysiwyg-html-mode")){var o=e.html(),n=t("<pre />");t(n).append(document.createTextNode(o)),t(n).attr("contenteditable",!0),t(e).html(" "),t(e).append(t(n)),t(e).attr("contenteditable",!1),t(e).data("wysiwyg-html-mode",!0),t(n).focus()}else t(e).html(t(e).text()),t(e).attr("contenteditable",!0),t(e).data("wysiwyg-html-mode",!1),t(e).focus()},o.prototype.insertFiles=function(e,o,n,a){var i=this;n.focus(),t.each(e,function(e,r){/^image\//.test(r.type)?t.when(i.readFileIntoDataUrl(r)).done(function(e){i.execCommand("insertimage",e,n,o,a),n.trigger("image-inserted")}).fail(function(e){o.fileUploadError("file-reader",e)}):o.fileUploadError("unsupported-file-type",r.type)})},o.prototype.markSelection=function(e,t,o){this.restoreSelection(),document.queryCommandSupported("hiliteColor")&&document.execCommand("hiliteColor",!1,t||"transparent"),this.saveSelection(),e.data(o.selectionMarker,t)},o.prototype.bindToolbar=function(e,o,n,a){var i=this;o.find(a).click(function(){i.restoreSelection(),e.focus(),"html"===e.data(n.commandRole)?i.toggleHtmlEdit(e):i.execCommand(t(this).data(n.commandRole),null,e,n,a),i.saveSelection()}),o.find("[data-toggle=dropdown]").click(this.restoreSelection()),o.find("input[type=text][data-"+n.commandRole+"]").on("webkitspeechchange change",function(){var o=this.value;this.value="",i.restoreSelection(),o&&(e.focus(),i.execCommand(t(this).data(n.commandRole),o,e,n,a)),i.saveSelection()}).on("focus",function(){var e=t(this);e.data(n.selectionMarker)||(i.markSelection(e,n.selectionColor,n),e.focus())}).on("blur",function(){var e=t(this);e.data(n.selectionMarker)&&i.markSelection(e,!1,n)}),o.find("input[type=file][data-"+n.commandRole+"]").change(function(){i.restoreSelection(),"file"===this.type&&this.files&&this.files.length>0&&i.insertFiles(this.files,n,e,a),i.saveSelection(),this.value=""})},o.prototype.initFileDrops=function(e,t,o){var n=this;e.on("dragenter dragover",!1).on("drop",function(a){var i=a.originalEvent.dataTransfer;a.stopPropagation(),a.preventDefault(),i&&i.files&&i.files.length>0&&n.insertFiles(i.files,t,e,o)})},t.fn.wysiwyg=function(e){new o(this,e)}}(window,window.jQuery);