// wupload.js
if(!RedactorPlugins){var RedactorPlugins={}}RedactorPlugins.wupload=function(){return{_boundGlobalUploadEvents:false,_dropArea:{},_timer:null,_isDragging:false,_isFile:false,init:function(){var a=".redactor_"+this.$textarea.wcfIdentify();$(document).on("dragstart"+a,function(){return false});$(document).on("dragover"+a,$.proxy(this.wupload._dragOver,this));$(document).on("dragleave"+a,$.proxy(this.wupload._dragLeave,this));$(document).on("drop"+a,(function(b){b.preventDefault();this.wupload._revertDropArea(undefined,this.$textarea.wcfIdentify())}).bind(this));if(!this.wupload._boundGlobalUploadEvents){this.wupload._boundGlobalUploadEvents=true;$(document).on("dragend",function(b){b.preventDefault()})}WCF.System.Event.addListener("com.woltlab.wcf.attachment","autoInsert_"+this.$textarea.wcfIdentify(),$.proxy(this.wupload.insertPastedImageAttachment,this))},_dragOver:function(c){c=c.originalEvent;if(!c.dataTransfer||!c.dataTransfer.types){return}this.wupload._isFile=false;if(c.dataTransfer.types[0]==="application/x-moz-file"){this.wupload._isFile=true}else{for(var e=0;e<c.dataTransfer.types.length;e++){if(c.dataTransfer.types[e]==="Files"){this.wupload._isFile=true;break}}}if(!this.wupload._isFile){return}this.wupload._isFile=true;c.preventDefault();if(!this.wupload._isDragging){var b=this.$textarea.wcfIdentify();if(this.wupload._dropArea[b]===undefined){this.wupload._dropArea[b]=$('<div class="redactorDropArea">'+WCF.Language.get("wcf.attachment.dragAndDrop.dropHere")+"</div>").hide().appendTo(document.body);this.wupload._dropArea[b].on("dragover",$.proxy(this.wupload._hoverDropArea,this)).on("dragleave",$.proxy(this.wupload._revertDropArea,this)).on("drop",$.proxy(this.wupload._drop,this))}var a=(this.wutil.inWysiwygMode())?this.$editor.getDimensions("outer"):this.$textarea.getDimensions("outer");var d=(this.wutil.inWysiwygMode())?this.$editor.getOffsets("offset"):this.$textarea.getOffsets("offset");this.wupload._dropArea[b].css({height:a.height+"px",left:d.left+"px",lineHeight:a.height+"px",top:d.top+"px",width:a.width+"px"}).show();this.wupload._isDragging=true}c.preventDefault()},_hoverDropArea:function(a){this.wupload._dropArea[this.$textarea.wcfIdentify()].addClass("active").text(WCF.Language.get("wcf.attachment.dragAndDrop.dropNow"))},_revertDropArea:function(c,a){if(!this.wupload._isFile){return}var b=a||this.$textarea.wcfIdentify();this.wupload._dropArea[b].removeClass("active").text(WCF.Language.get("wcf.attachment.dragAndDrop.dropHere"));if(a){this.wupload._dropArea[b].hide()}},_dragLeave:function(){if(!this.wupload._isDragging||!this.wupload._isFile){return}if(this.wupload._timer===null){this.wupload._timer=new WCF.PeriodicalExecuter((function(a){a.stop();if(!this.wupload._isDragging){this.wupload._dropArea[this.$source.wcfIdentify()].hide()}}).bind(this),100)}else{this.wupload._timer.resume()}this.wupload._isDragging=false},_drop:function(c){if(!this.wupload._isFile){return}c=c.originalEvent||c;if(c.dataTransfer&&c.dataTransfer.files.length){c.preventDefault();var b=this.$textarea.wcfIdentify();this.wupload._revertDropArea(undefined,b);for(var d=0;d<c.dataTransfer.files.length;d++){var a=c.dataTransfer.files[d];if(a.type){WCF.System.Event.fireEvent("com.woltlab.wcf.redactor","upload_"+b,{file:a})}}}},pasteClipboardUploadMozilla:function(){this.$editor.find("img[data-mozilla-paste-image]").each($.proxy(function(d,g){var f=$(g);var a=f.prop("src").split(",");var e=a[0].split(";")[0].split(":")[1];var c=a[1];var b={blob:WCF.base64toBlob(c,e),uploadID:null};WCF.System.Event.fireEvent("com.woltlab.wcf.redactor","upload_"+this.$textarea.wcfIdentify(),b);f.replaceWith('<span class="redactor-pastedImageFromClipboard-'+b.uploadID+'" />')},this))},insertPastedImageAttachment:function(b){var a=this.$editor.find("span.redactor-pastedImageFromClipboard-"+b.uploadID);a.before(b.attachment);a.remove()}}};
// wutil.js
-if(!RedactorPlugins){var RedactorPlugins={}}RedactorPlugins.wutil=function(){return{_autosaveWorker:null,init:function(){this.$textarea.parents("form").submit($.proxy(this.wutil.submit,this));if(this.wutil.getOption("woltlab.autosave").active){this.wutil.autosaveEnable();if(this.wutil.getOption("woltlab.autosave").saveOnInit||this.$textarea.data("saveOnInit")){this.wutil.setOption("woltlab.autosaveOnce",true)}else{this.wutil.autosaveRestore()}}this.wutil.setOption("autosave",false);var a=this.core.destroy;this.core.destroy=(function(){this.wutil.autosaveDisable();a.call(this)}).bind(this)},insertAtCaret:function(b){if(this.opts.visual){console.debug("insertAtCaret() failed: Editor is in WYSIWYG-mode.");return false}this.$textarea.focus();var c=this.$textarea.getCaret();if(c==-1){console.debug("insertAtCaret() failed: Source is not input[type=text], input[type=password] or textarea.")}var a=this.$textarea.val();a=a.substr(0,c)+b+a.substr(c);this.$textarea.val(a);return true},insertDynamic:function(a,b){if(this.wutil.inWysiwygMode()){this.insert.html(a,false)}else{if(b===undefined||b===null){b=a}this.wutil.insertAtCaret(b)}},setOption:function(a,b){if(a.indexOf(".")!==-1){a=a.split(".",2);this.opts[a[0]][a[1]]=b}else{this.opts[a]=b}},getOption:function(a){if(a.indexOf(".")!==-1){a=a.split(".",2);if(this.opts[a[0]][a[1]]){return this.opts[a[0]][a[1]]}}else{if(this.opts[a]){return this.opts[a]}}return null},inPlainMode:function(){return !this.opts.visual},inWysiwygMode:function(){return(this.opts.visual)},replaceRangesWith:function(a){getSelection().removeAllRanges();getSelection().addRange(a)},getText:function(){if(this.wutil.inWysiwygMode()){this.code.startSync();this.$textarea.val($.trim(this.wbbcode.convertFromHtml(this.$textarea.val())))}return $.trim(this.$textarea.val())},isEmptyEditor:function(){if(this.opts.visual){return this.utils.isEmpty(this.$editor.html())}return(!$.trim(this.$textarea.val()))},submit:function(){if(this.wutil.inWysiwygMode()){this.code.startSync();this.$textarea.val($.trim(this.wbbcode.convertFromHtml(this.$textarea.val())))}this.wutil.autosavePurge()},reset:function(){if(this.opts.visual){this.$editor.html("<p>"+this.opts.invisibleSpace+"</p>")}this.$textarea.val("");WCF.System.Event.fireEvent("com.woltlab.wcf.redactor","reset",{wysiwygContainerID:this.$textarea.wcfIdentify()})},autosaveEnable:function(a){if(!this.wutil.getOption("woltlab.autosave").active){this.wutil.setOption("woltlab.autosave",{active:true,key:a})}if(this.wutil._autosaveWorker===null){this.wutil._autosaveWorker=new WCF.PeriodicalExecuter($.proxy(this.wutil._saveTextToStorage,this),60*1000)}return true},_saveTextToStorage:function(){localStorage.setItem(this.wutil.getOption("woltlab.autosave").key,this.wutil.getText())},autosaveDisable:function(){if(!this.wutil.getOption("woltlab.autosave").active){return false}this.wutil._autosaveWorker.stop();this.wutil._autosaveWorker=null;this.wutil.setOption("woltlab.autosave",{active:false,key:""});return true},autosavePurge:function(){localStorage.removeItem(this.wutil.getOption("woltlab.autosave").key)},autosaveRestore:function(){var a=this.wutil.getOption("woltlab.autosave");var b=localStorage.getItem(a.key);if(b!==null){if(this.wutil.inWysiwygMode()){this.wutil.setOption("woltlab.originalValue",b)}else{this.$textarea.val(b)}return true}return false},buttonReplace:function(d,b,e,g,f){var a=this.buttonGet(d);var c=this.buttonAddAfter(d,b,e,g,f);if(a.parent().hasClass("separator")){c.parent().addClass("separator")}a.parent().remove();return c},removeZeroWidthSpace:function(a){var b="";for(var e=0,d=a.length;e<d;e++){var c=a.charCodeAt(e).toString(16);if(c!="200b"){b+=a[e]}}return b},getSource:function(){return this.$textarea},getName:function(){return this.$textarea.wcfIdentify()},selectionEndOfEditor:function(){this.focus.setEnd();var a=this.$editor.children(":last")[0];if(a.tagName==="P"){if(a.innerHTML===""){a.remove();a=$(this.opts.emptyHtml).appendTo(this.$editor)}this.caret.setEnd(a[0])}else{this.wutil.setCaretAfter(a)}},isCaret:function(){this.selection.get();return this.range.collapsed},isEndOfElement:function(a){this.selection.get();if(!this.wutil.isCaret()){return false}if(this.range.endContainer.nodeType===Element.TEXT_NODE){if(this.range.endOffset<this.range.endContainer.length){return false}}if(!this.wutil.isNodeWithin(this.range.endContainer,a)){return false}var b=this.range.endContainer;while(b!==a){if(b.nextSibling){return false}b=b.parentNode}return true},isNodeWithin:function(c,b){var a=$(c);while(a[0]!==this.$editor[0]){if(a[0]===b){return true}a=a.parent()}return false},containsTag:function(b,a){switch(b.nodeType){case Element.ELEMENT_NODE:if(b.tagName===a){return true}case Element.DOCUMENT_FRAGMENT_NODE:for(var c=0;c<b.childNodes.length;c++){if(this.wutil.containsTag(b.childNodes[c],a)){return true}}return false;break;default:return false;break}},replaceText:function(c){var d=$(document);var a=d.scrollTop();var b=false;if(this.wutil.inWysiwygMode()){this.code.toggle();b=true}this.$textarea.val(c);if(b){this.code.toggle();d.scrollTop(a)}d.trigger("resize")},setCaretBefore:function(a){this.wutil._setCaret(a,true)},setCaretAfter:function(a){this.wutil._setCaret(a,false)},_setCaret:function(b,c){var a=$(this.opts.emptyHtml);a[(c?"insertBefore":"insertAfter")](b);this.caret.setStart(a[0])}}};
+if(!RedactorPlugins){var RedactorPlugins={}}RedactorPlugins.wutil=function(){return{_autosaveWorker:null,init:function(){this.$textarea.parents("form").submit($.proxy(this.wutil.submit,this));if(this.wutil.getOption("woltlab.autosave").active){this.wutil.autosaveEnable();if(this.wutil.getOption("woltlab.autosave").saveOnInit||this.$textarea.data("saveOnInit")){this.wutil.setOption("woltlab.autosaveOnce",true)}else{this.wutil.autosaveRestore()}}this.wutil.setOption("autosave",false);var a=this.core.destroy;this.core.destroy=(function(){this.wutil.autosaveDisable();a.call(this)}).bind(this)},insertAtCaret:function(b){if(this.opts.visual){console.debug("insertAtCaret() failed: Editor is in WYSIWYG-mode.");return false}this.$textarea.focus();var c=this.$textarea.getCaret();if(c==-1){console.debug("insertAtCaret() failed: Source is not input[type=text], input[type=password] or textarea.")}var a=this.$textarea.val();a=a.substr(0,c)+b+a.substr(c);this.$textarea.val(a);return true},insertDynamic:function(a,b){if(this.wutil.inWysiwygMode()){this.insert.html(a,false)}else{if(b===undefined||b===null){b=a}this.wutil.insertAtCaret(b)}},setOption:function(a,b){if(a.indexOf(".")!==-1){a=a.split(".",2);this.opts[a[0]][a[1]]=b}else{this.opts[a]=b}},getOption:function(a){if(a.indexOf(".")!==-1){a=a.split(".",2);if(this.opts[a[0]][a[1]]){return this.opts[a[0]][a[1]]}}else{if(this.opts[a]){return this.opts[a]}}return null},inPlainMode:function(){return !this.opts.visual},inWysiwygMode:function(){return(this.opts.visual)},replaceRangesWith:function(a){getSelection().removeAllRanges();getSelection().addRange(a)},getText:function(){if(this.wutil.inWysiwygMode()){this.code.startSync();this.$textarea.val($.trim(this.wbbcode.convertFromHtml(this.$textarea.val())))}return $.trim(this.$textarea.val())},isEmptyEditor:function(){if(this.opts.visual){return this.utils.isEmpty(this.$editor.html())}return(!$.trim(this.$textarea.val()))},submit:function(){if(this.wutil.inWysiwygMode()){this.code.startSync();this.$textarea.val($.trim(this.wbbcode.convertFromHtml(this.$textarea.val())))}this.wutil.autosavePurge()},reset:function(){if(this.opts.visual){this.$editor.html("<p>"+this.opts.invisibleSpace+"</p>")}this.$textarea.val("");WCF.System.Event.fireEvent("com.woltlab.wcf.redactor","reset",{wysiwygContainerID:this.$textarea.wcfIdentify()})},autosaveEnable:function(a){if(!this.wutil.getOption("woltlab.autosave").active){this.wutil.setOption("woltlab.autosave",{active:true,key:a})}if(this.wutil._autosaveWorker===null){this.wutil._autosaveWorker=new WCF.PeriodicalExecuter($.proxy(this.wutil._saveTextToStorage,this),60*1000)}return true},_saveTextToStorage:function(){localStorage.setItem(this.wutil.getOption("woltlab.autosave").key,this.wutil.getText())},autosaveDisable:function(){if(!this.wutil.getOption("woltlab.autosave").active){return false}this.wutil._autosaveWorker.stop();this.wutil._autosaveWorker=null;this.wutil.setOption("woltlab.autosave",{active:false,key:""});return true},autosavePurge:function(){localStorage.removeItem(this.wutil.getOption("woltlab.autosave").key)},autosaveRestore:function(){var a=this.wutil.getOption("woltlab.autosave");var b=localStorage.getItem(a.key);if(b!==null){if(this.wutil.inWysiwygMode()){this.wutil.setOption("woltlab.originalValue",b)}else{this.$textarea.val(b)}return true}return false},buttonReplace:function(d,b,e,g,f){var a=this.buttonGet(d);var c=this.buttonAddAfter(d,b,e,g,f);if(a.parent().hasClass("separator")){c.parent().addClass("separator")}a.parent().remove();return c},removeZeroWidthSpace:function(a){var b="";for(var e=0,d=a.length;e<d;e++){var c=a.charCodeAt(e).toString(16);if(c!="200b"){b+=a[e]}}return b},getSource:function(){return this.$textarea},getName:function(){return this.$textarea.wcfIdentify()},selectionEndOfEditor:function(){this.focus.setEnd();var a=this.$editor.children(":last")[0];if(a.tagName==="P"){if(a.innerHTML===""){a.remove();a=$(this.opts.emptyHtml).appendTo(this.$editor)[0]}this.caret.setEnd(a)}else{this.wutil.setCaretAfter(a)}},isCaret:function(){this.selection.get();return this.range.collapsed},isEndOfElement:function(a){this.selection.get();if(!this.wutil.isCaret()){return false}if(this.range.endContainer.nodeType===Element.TEXT_NODE){if(this.range.endOffset<this.range.endContainer.length){return false}}if(!this.wutil.isNodeWithin(this.range.endContainer,a)){return false}var b=this.range.endContainer;while(b!==a){if(b.nextSibling){return false}b=b.parentNode}return true},isNodeWithin:function(c,b){var a=$(c);while(a[0]!==this.$editor[0]){if(a[0]===b){return true}a=a.parent()}return false},containsTag:function(b,a){switch(b.nodeType){case Element.ELEMENT_NODE:if(b.tagName===a){return true}case Element.DOCUMENT_FRAGMENT_NODE:for(var c=0;c<b.childNodes.length;c++){if(this.wutil.containsTag(b.childNodes[c],a)){return true}}return false;break;default:return false;break}},replaceText:function(c){var d=$(document);var a=d.scrollTop();var b=false;if(this.wutil.inWysiwygMode()){this.code.toggle();b=true}this.$textarea.val(c);if(b){this.code.toggle();d.scrollTop(a)}d.trigger("resize")},setCaretBefore:function(a){this.wutil._setCaret(a,true)},setCaretAfter:function(a){this.wutil._setCaret(a,false)},_setCaret:function(b,c){var a=$(this.opts.emptyHtml);a[(c?"insertBefore":"insertAfter")](b);this.caret.setStart(a[0])}}};