","$1"),r("\\s*(?"+i+"[^>]*>)","$1"),r("(?"+i+"[^>]*>)\\s*
","$1"),r("(?"+i+"[^>]*>)\\s*
","$1"),r("
(\\s*?(p|li|div|dl|dd|dt|th|pre|td|ul|ol)[^>]*>)","$1"),-1!=t.indexOf(")((.|\n)*?)
",function(e,t,r,i){return n(t,"\\\\(['\"\\\\])","$1")+n(n(n(i,"","\n"),"
|
",""),"\\\\(['\"\\\\])","$1")+""}),r("\n$","")},stripTags:function(t){var n=this.opts.allowedTags,r=/<\/?([a-z][a-z0-9]*)\b[^>]*>/gi;return t.replace(r,function(t,r){return e.inArray(r.toLowerCase(),n)>"-1"?t:""})},savePreCode:function(t){var n=t.match(/([\w\W]*?)<\/pre>/gi);return null!==n&&e.each(n,e.proxy(function(e,n){var r=n.match(/([\w\W]*?)<\/pre>/i);r[2]=this.encodeEntities(r[2]),t=t.replace(n,""+r[2]+"
")},this)),t},encodeEntities:function(e){return e=String(e).replace(/&/g,"&").replace(/</g,"<").replace(/>/g,">").replace(/"/g,'"'),String(e).replace(/&/g,"&").replace(//g,">").replace(/"/g,""")},cleanupPre:function(e){e=e.replace(/
/gi,"\n"),e=e.replace(/<\/p>/gi,"\n"),e=e.replace(/<\/div>/gi,"\n");var t=this.document.createElement("div");return t.innerHTML=e,t.textContent||t.innerText},pasteCleanUp:function(t){var n=this.getParentNode();return"PRE"===e(n).get(0).tagName?(t=this.cleanupPre(t),this.pasteCleanUpInsert(t),!0):(t=t.replace(/|<\?(?:php)?[\s\S]*?\?>/gi,""),t=t.replace(/( ){2,}/gi," "),t=t.replace(/([\w\W]*?)<\/b>/gi,"$2"),t=this.stripTags(t),t=t.replace(/<\/td>/gi,"[td]"),t=t.replace(/ | <\/td>/gi,"[td]"),t=t.replace(/ | <\/td>/gi,"[td]"),t=t.replace(/([\w\W]*?)<\/a>/gi,'[a href="$2"]$4[/a]'),t=t.replace(/ | ","",""],r=0;r").addClass("redactor_toolbar"),this.opts.air?(e(this.air).append(this.$toolbar),e("body").append(this.air)):this.opts.toolbarExternal===!1?this.$box.prepend(this.$toolbar):e(this.opts.toolbarExternal).html(this.$toolbar),void e.each(this.opts.buttons,e.proxy(function(t,n){if("|"!==n&&"undefined"!=typeof this.opts.toolbar[n]){var r=this.opts.toolbar[n];if(this.opts.fileUpload===!1&&"file"===n)return!0;this.$toolbar.append(e("").append(this.buildButton(n,r)))}"|"===n&&this.$toolbar.append(e(''))},this)))},buildButton:function(t,n){var r=e('');if("undefined"==typeof n.func?r.click(e.proxy(function(){-1!=e.inArray(t,this.opts.activeButtons)&&(this.inactiveAllButtons(),this.setBtnActive(t)),this.browser("mozilla")&&this.$editor.focus(),this.execCommand(n.exec,t)},this)):"show"!==n.func&&r.click(e.proxy(function(e){this[n.func](e)},this)),"undefined"!=typeof n.callback&&n.callback!==!1&&r.click(e.proxy(function(e){n.callback(this,e,t)},this)),"backcolor"===t||"fontcolor"===t||"undefined"!=typeof n.dropdown){var i=e('');i="backcolor"===t||"fontcolor"===t?this.buildColorPicker(i,t):this.buildDropdown(i,n.dropdown),this.dropdowns.push(i.appendTo(e(document.body))),this.hdlShowDropDown=e.proxy(function(e){this.showDropDown(e,i,t)},this),r.click(this.hdlShowDropDown)}return r},buildDropdown:function(t,n){return e.each(n,e.proxy(function(n,r){"undefined"==typeof r.className&&(r.className="");var i;"undefined"!=typeof r.name&&"separator"===r.name?i=e('
'):(i=e(''+r.title+""),e(i).click("function"==typeof r.callback?e.proxy(function(e){r.callback(this,e,n)},this):"undefined"==typeof r.func?e.proxy(function(){this.execCommand(r.exec,n)},this):e.proxy(function(e){this[r.func](e)},this))),e(t).append(i)},this)),t},buildColorPicker:function(t,n){var r;r="backcolor"===n?this.browser("msie")?"BackColor":"hilitecolor":"forecolor",e(t).width(210);for(var i=this.opts.colors.length,a=0;i>a;++a){var o=this.opts.colors[a],s=e('
').css({backgroundColor:o});e(t).append(s);var c=this;e(s).click(function(){c.execCommand(r,e(this).attr("rel")),"forecolor"===r&&c.$editor.find("font").replaceWith(function(){return e('
'+e(this).html()+"")}),c.browser("msie")&&"BackColor"===r&&c.$editor.find("font").replaceWith(function(){return e('
'+e(this).html()+"")})})}var l=e('
').html(RLANG.none);return l.click("backcolor"===n?e.proxy(this.setBackgroundNone,this):e.proxy(this.setColorNone,this)),e(t).append(l),t},setBackgroundNone:function(){e(this.getParentNode()).css("background-color","transparent"),this.syncCode()},setColorNone:function(){e(this.getParentNode()).attr("color","").css("color",""),this.syncCode()},showDropDown:function(t,n,r){if(this.getBtn(r).hasClass("dropact"))this.hideAllDropDown();else{this.hideAllDropDown(),this.setBtnActive(r),this.getBtn(r).addClass("dropact");var i=this.getBtn(r).offset().left;if(this.opts.air){var a=this.air.offset().top;e(n).css({position:"absolute",left:i+"px",top:a+30+"px"}).show()}else if(this.opts.fixed&&this.fixed)e(n).css({position:"fixed",left:i+"px",top:"30px"}).show();else{var o=this.$toolbar.offset().top+30;e(n).css({position:"absolute",left:i+"px",top:o+"px"}).show()}}var s=e.proxy(function(e){this.hideDropDown(e,n,r)},this);e(document).one("click",s),this.$editor.one("click",s),this.$content.one("click",s),t.stopPropagation()},hideAllDropDown:function(){this.$toolbar.find("a.dropact").removeClass("redactor_act").removeClass("dropact"),e(".redactor_dropdown").hide()},hideDropDown:function(t,n){e(t.target).hasClass("dropact")||(e(n).removeClass("dropact"),this.showedDropDown=!1,this.hideAllDropDown())},getBtn:function(t){return this.opts.toolbar===!1?!1:e(this.$toolbar.find("a.redactor_btn_"+t))},setBtnActive:function(e){this.getBtn(e).addClass("redactor_act")},setBtnInactive:function(e){this.getBtn(e).removeClass("redactor_act")},inactiveAllButtons:function(){e.each(this.opts.activeButtons,e.proxy(function(e,t){this.setBtnInactive(t)},this))},changeBtnIcon:function(e,t){this.getBtn(e).addClass("redactor_btn_"+t)},removeBtnIcon:function(e,t){this.getBtn(e).removeClass("redactor_btn_"+t)},addBtnSeparator:function(){this.$toolbar.append(e('
'))},addBtnSeparatorAfter:function(t){var n=this.getBtn(t);n.parent().after(e('
'))},addBtnSeparatorBefore:function(t){var n=this.getBtn(t);n.parent().before(e('
'))},removeBtnSeparatorAfter:function(e){var t=this.getBtn(e);t.parent().next().remove()},removeBtnSeparatorBefore:function(e){var t=this.getBtn(e);t.parent().prev().remove()},setBtnRight:function(e){return this.opts.toolbar===!1?!1:void this.getBtn(e).parent().addClass("redactor_btn_right")},setBtnLeft:function(e){return this.opts.toolbar===!1?!1:void this.getBtn(e).parent().removeClass("redactor_btn_right")},addBtn:function(t,n,r,i){if(this.opts.toolbar===!1)return!1;var a=this.buildButton(t,{title:n,callback:r,dropdown:i});this.$toolbar.append(e("
").append(a))},addBtnFirst:function(t,n,r,i){if(this.opts.toolbar===!1)return!1;var a=this.buildButton(t,{title:n,callback:r,dropdown:i});this.$toolbar.prepend(e("").append(a))},addBtnAfter:function(t,n,r,i,a){if(this.opts.toolbar===!1)return!1;var o=this.buildButton(n,{title:r,callback:i,dropdown:a}),s=this.getBtn(t);s.parent().after(e("").append(o))},addBtnBefore:function(t,n,r,i,a){if(this.opts.toolbar===!1)return!1;var o=this.buildButton(n,{title:r,callback:i,dropdown:a}),s=this.getBtn(t);s.parent().before(e("").append(o))},removeBtn:function(e,t){var n=this.getBtn(e);t===!0&&n.parent().next().remove(),n.parent().removeClass("redactor_btn_right"),n.remove()},getFragmentHtml:function(e){var t=e.cloneNode(!0),n=this.document.createElement("div");return n.appendChild(t),n.innerHTML},extractContent:function(){for(var e,t=this.$editor.get(0),n=this.document.createDocumentFragment();e=t.firstChild;)n.appendChild(e);return n},saveSelection:function(){this.$editor.focus(),this.savedSel=this.getOrigin(),this.savedSelObj=this.getFocus()},restoreSelection:function(){"undefined"!=typeof this.savedSel&&null!==this.savedSel&&null!==this.savedSelObj&&"BODY"!==this.savedSel[0].tagName?this.opts.iframe===!1&&0==e(this.savedSel[0]).closest(".redactor_editor").size()?this.$editor.focus():(this.browser("opera")&&this.$editor.focus(),this.setSelection(this.savedSel[0],this.savedSel[1],this.savedSelObj[0],this.savedSelObj[1]),this.browser("mozilla")&&this.$editor.focus()):this.$editor.focus()},getSelection:function(){var e=this.document;return this.window.getSelection?this.window.getSelection():e.getSelection?e.getSelection():e.selection.createRange()},hasSelection:function(){if(this.oldIE()){var e,t=this.$editor.get(0);return t.focus(),t.document.selection?(e=t.document.selection.createRange(),e&&e.parentElement().document===t.document):!1}var n;return(n=this.getSelection())&&null!=n.focusNode&&null!=n.anchorNode},getOrigin:function(){if(this.oldIE()){var e,t=this.$editor.get(0);return t.focus(),this.hasSelection()?(e=t.document.selection.createRange(),this._getBoundary(t.document,e,!0)):null}var n;return(n=this.getSelection())&&null!=n.anchorNode?[n.anchorNode,n.anchorOffset]:null},getFocus:function(){if(this.oldIE()){var e,t=this.$editor.get(0);return t.focus(),this.hasSelection()?(e=t.document.selection.createRange(),this._getBoundary(t.document,e,!1)):null}var n;return(n=this.getSelection())&&null!=n.focusNode?[n.focusNode,n.focusOffset]:null},setSelection:function(e,t,n,i){if(null==n&&(n=e),null==i&&(i=t),this.oldIE()){var a=this.$editor.get(0),o=a.document.body.createTextRange();return this._moveBoundary(a.document,o,!1,n,i),this._moveBoundary(a.document,o,!0,e,t),o.select()}var s=this.getSelection();if(s)if(s.collapse&&s.extend)s.collapse(e,t),s.extend(n,i);else{r=this.document.createRange(),r.setStart(e,t),r.setEnd(n,i);try{s.removeAllRanges()}catch(c){}s.addRange(r)}},getCurrentNode:function(){return"undefined"!=typeof this.window.getSelection?this.getSelectedNode().parentNode:"undefined"!=typeof this.document.selection?this.getSelection().parentElement():void 0},getParentNode:function(){return e(this.getCurrentNode()).parent()[0]},getSelectedNode:function(){if(this.oldIE())return this.getSelection().parentElement();if("undefined"!=typeof this.window.getSelection){var e=this.window.getSelection();return e.rangeCount>0?this.getSelection().getRangeAt(0).commonAncestorContainer:!1}return"undefined"!=typeof this.document.selection?this.getSelection():void 0},_getBoundary:function(e,t,n){var r,i,a,o,s;for(i=e.createElement("a"),r=t.duplicate(),r.collapse(n),s=r.parentElement();;)if(s.insertBefore(i,i.previousSibling),r.moveToElementText(i),!(r.compareEndPoints(n?"StartToStart":"StartToEnd",t)>0&&null!=i.previousSibling))break;return-1===r.compareEndPoints(n?"StartToStart":"StartToEnd",t)&&i.nextSibling?(r.setEndPoint(n?"EndToStart":"EndToEnd",t),a=i.nextSibling,o=r.text.length):(a=i.parentNode,o=this._getChildIndex(i)),i.parentNode.removeChild(i),[a,o]},_moveBoundary:function(e,t,n,r,i){var a,o,s,c,l;return l=0,a=this._isText(r)?r:r.childNodes[i],o=this._isText(r)?r.parentNode:r,this._isText(r)&&(l=i),c=e.createElement("a"),o.insertBefore(c,a||null),s=e.body.createTextRange(),s.moveToElementText(c),c.parentNode.removeChild(c),t.setEndPoint(n?"StartToStart":"EndToEnd",s),t[n?"moveStart":"moveEnd"]("character",l)},_isText:function(e){return null!=e?3==e.nodeType:!1},_getChildIndex:function(e){for(var t=0;e=e.previousSibling;)t++;return t},insertNodeAfterCaret:function(e){this.saveSelection(),this.insertNodeAtCaret(e),this.restoreSelection()},insertNodeAtCaret:function(e){if(this.window.getSelection){var t=this.getSelection();if(t.rangeCount){var n=t.getRangeAt(0);n.collapse(!1),n.insertNode(e),n=n.cloneRange(),n.selectNodeContents(e),n.collapse(!1),t.removeAllRanges(),t.addRange(n)}}else if(this.document.selection){var r=1===e.nodeType?e.outerHTML:e.data,i="marker_"+(""+Math.random()).slice(2);r+='';var a=this.getSelection();a.collapse(!1),a.pasteHTML(r);var o=this.document.getElementById(i);a.moveToElementText(o),a.select(),o.parentNode.removeChild(o)}},getSelectedHtml:function(){var e="";if(this.window.getSelection){var t=this.window.getSelection();if(t.rangeCount){for(var n=this.document.createElement("div"),r=0,i=t.rangeCount;i>r;++r)n.appendChild(t.getRangeAt(r).cloneContents());e=n.innerHTML}}else this.document.selection&&"Text"===this.document.selection.type&&(e=this.document.selection.createRange().htmlText);return e},resizeImage:function(t){var n,r,i=!1,a=!1,o=e(t).width()/e(t).height(),s=10,c=10;e(t).off("hover mousedown mouseup click mousemove"),e(t).hover(function(){e(t).css("cursor","nw-resize")},function(){e(t).css("cursor",""),i=!1}),e(t).mousedown(function(s){s.preventDefault(),o=e(t).width()/e(t).height(),i=!0,a=!0,n=Math.round(s.pageX-e(t).eq(0).offset().left),r=Math.round(s.pageY-e(t).eq(0).offset().top)}),e(t).mouseup(e.proxy(function(){i=!1,e(t).css("cursor",""),this.syncCode()},this)),e(t).click(e.proxy(function(e){a&&this.imageEdit(e)},this)),e(t).mousemove(function(l){if(i){a=!1;var u=(Math.round(l.pageX-e(this).eq(0).offset().left)-n,Math.round(l.pageY-e(this).eq(0).offset().top)-r),d=e(t).height(),f=parseInt(d,10)+u,h=f*o;h>s&&e(t).width(h),f>c&&e(t).height(f),n=Math.round(l.pageX-e(this).eq(0).offset().left),r=Math.round(l.pageY-e(this).eq(0).offset().top)}})},showTable:function(){this.saveSelection(),this.modalInit(RLANG.table,this.opts.modal_table,300,e.proxy(function(){e("#redactor_insert_table_btn").click(e.proxy(this.insertTable,this)),setTimeout(function(){e("#redactor_table_rows").focus()},200)},this))},insertTable:function(){for(var t=e("#redactor_table_rows").val(),n=e("#redactor_table_columns").val(),r=e(""),i=Math.floor(99999*Math.random()),a=e(''),o=0;t>o;o++){for(var s=e("
"),c=0;n>c;c++){var l=e("
| ");e(s).append(l)}e(a).append(s)}e(r).append(a);var u=e(r).html()+"";this.restoreSelection(),this.execCommand("inserthtml",u),this.modalClose(),this.observeTables()},tableObserver:function(t){this.$table=e(t.target).closest("table"),this.$table_tr=this.$table.find("tr"),this.$table_td=this.$table.find("td"),this.$tbody=e(t.target).closest("tbody"),this.$thead=e(this.$table).find("thead"),this.$current_td=e(t.target),this.$current_tr=e(t.target).closest("tr")},deleteTable:function(){e(this.$table).remove(),this.$table=!1,this.syncCode()},deleteRow:function(){e(this.$current_tr).remove(),this.syncCode()},deleteColumn:function(){var t=e(this.$current_td).get(0).cellIndex;e(this.$table).find("tr").each(function(){e(this).find("td").eq(t).remove()}),this.syncCode()},addHead:function(){if(0!==e(this.$table).find("thead").size())this.deleteHead();else{var t=e(this.$table).find("tr").first().clone();t.find("td").html(" "),this.$thead=e(""),this.$thead.append(t),e(this.$table).prepend(this.$thead),this.syncCode()}},deleteHead:function(){e(this.$thead).remove(),this.$thead=!1,this.syncCode()},insertRowAbove:function(){this.insertRow("before")},insertRowBelow:function(){this.insertRow("after")},insertColumnLeft:function(){this.insertColumn("before")},insertColumnRight:function(){this.insertColumn("after")},insertRow:function(t){var n=e(this.$current_tr).clone();n.find("td").html(" "),"after"===t?e(this.$current_tr).after(n):e(this.$current_tr).before(n),this.syncCode()},insertColumn:function(t){var n=0;this.$current_tr.find("td").each(e.proxy(function(t,r){e(r)[0]===this.$current_td[0]&&(n=t)},this)),this.$table_tr.each(function(r,i){var a=e(i).find("td").eq(n),o=a.clone();o.html(" "),"after"===t?e(a).after(o):e(a).before(o)}),this.syncCode()},showVideo:function(){this.saveSelection(),this.modalInit(RLANG.video,this.opts.modal_video,600,e.proxy(function(){e("#redactor_insert_video_btn").click(e.proxy(this.insertVideo,this)),setTimeout(function(){e("#redactor_insert_video_area").focus()},200)},this))},insertVideo:function(){var t=e("#redactor_insert_video_area").val();t=this.stripTags(t),this.restoreSelection(),this.execCommand("inserthtml",t),this.modalClose()},imageEdit:function(t){var n=e(t.target),r=n.parent(),i=e.proxy(function(){e("#redactor_file_alt").val(n.attr("alt")),e("#redactor_image_edit_src").attr("href",n.attr("src")),e("#redactor_form_image_align").val(n.css("float")),"A"===e(r).get(0).tagName&&e("#redactor_file_link").val(e(r).attr("href")),e("#redactor_image_delete_btn").click(e.proxy(function(){this.imageDelete(n)},this)),e("#redactorSaveBtn").click(e.proxy(function(){this.imageSave(n)},this))},this);this.modalInit(RLANG.image,this.opts.modal_image_edit,380,i)},imageDelete:function(t){var n=e(t).parent();0!=n.size()&&"A"==n[0].tagName?n.remove():e(t).remove(),this.modalClose(),this.syncCode()},imageSave:function(t){var n=e(t).parent();e(t).attr("alt",e("#redactor_file_alt").val());var r=e("#redactor_form_image_align").val();e(t).css("left"===r?{"float":"left",margin:"0 10px 10px 0"}:"right"===r?{"float":"right",margin:"0 0 10px 10px"}:{"float":"none",margin:"0"});var i=e.trim(e("#redactor_file_link").val());""!==i?"A"!==e(n).get(0).tagName?e(t).replaceWith(''+this.outerHTML(t)+""):e(n).attr("href",i):"A"===e(n).get(0).tagName&&e(n).replaceWith(this.outerHTML(t)),this.modalClose(),this.observeImages(),this.syncCode()},showImage:function(){this.saveSelection();var t=e.proxy(function(){if(this.opts.imageGetJson!==!1?e.getJSON(this.opts.imageGetJson,e.proxy(function(t){var n={},r=0;e.each(t,e.proxy(function(e,t){"undefined"!=typeof t.folder&&(r++,n[t.folder]=r)},this));var i=!1;if(e.each(t,e.proxy(function(t,r){var a="";"undefined"!=typeof r.title&&(a=r.title);var o=0;e.isEmptyObject(n)||"undefined"==typeof r.folder||(o=n[r.folder],i===!1&&(i=".redactorfolder"+o));var s=e('');e("#redactor_image_box").append(s),e(s).click(e.proxy(this.imageSetThumb,this))},this)),!e.isEmptyObject(n)){e(".redactorfolder").hide(),e(i).show();var a=function(t){e(".redactorfolder").hide(),e(".redactorfolder"+e(t.target).val()).show()},o=e('