").appendTo(e("body")).hide().html(s);r!==!1&&o.options.getHtmlHandler&&(s=o.options.getHtmlHandler(s,u),u.remove()),t+=s+n}r!==!1&&o.options.getTextHandler&&(t=o.options.getTextHandler(t,!0)),i!==!1&&(t=x(t)),o.wysiwygEditorInsertHtml(t)}return this},o.getWysiwygEditorValue=function(t){var n=c.contents().find("body"),r;return e.sceditor.dom.fixNesting(n.get(0)),r=n.html(),t!==!1&&o.options.getHtmlHandler&&(r=o.options.getHtmlHandler(r,n)),r},o.getTextareaValue=function(e){var t=p.val();return e!==!1&&o.options.getTextHandler&&(t=o.options.getTextHandler(t)),t},o.setWysiwygEditorValue=function(t){t||(t="
"+(e.sceditor.ie?"":" ")+"
"),F().body.innerHTML=x(t)},o.setTextareaValue=function(e){p.val(e)},o.updateTextareaValue=function(){o.inSourceMode()?u.val(o.getTextareaValue(!1)):u.val(o.getWysiwygEditorValue())},x=function(t){if(o.options.toolbar.indexOf("emoticon")===-1)return t;var n=e.extend({},o.options.emoticons.more,o.options.emoticons.dropdown,o.options.emoticons.hidden);return e.each(n,function(n,r){var s=e.sceditor.regexEscape(n)+"(?=([^\\<\\>]*?<(?!/code)|[^\\<\\>]*?$))",u="";o.options.emoticonsCompat&&(s="((>|^|\\s| | | | | ))"+s+"(?=(\\s|$|<| | | | | ))",u="$1"),t=t.replace(new RegExp(s,"gm"),u+i("emoticon",{key:n,url:r}))}),t},o.inSourceMode=function(){return p.is(":visible")},o.sourceMode=function(e){return typeof e!="boolean"?o.inSourceMode():((o.inSourceMode()&&!e||!o.inSourceMode()&&e)&&o.toggleTextMode(),this)},o.toggleTextMode=function(){if(!e.sceditor.isWysiwygSupported()&&o.inSourceMode())return;o.inSourceMode()?o.setWysiwygEditorValue(o.getTextareaValue()):o.setTextareaValue(o.getWysiwygEditorValue()),g=null,p.toggle(),c.toggle(),f.removeClass("sourceMode"),f.removeClass("wysiwygMode"),o.inSourceMode()?f.addClass("sourceMode"):f.addClass("wysiwygMode"),R()},U=function(){d.focus();if(d.selectionStart!=null)return d.value.substring(d.selectionStart,d.selectionEnd);if(n.selection.createRange)return n.selection.createRange().text},T=function(t,n){if(o.inSourceMode()){n.txtExec&&(e.isArray(n.txtExec)?o.textEditorInsertText.apply(o,n.txtExec):n.txtExec.call(o,t,U()));return}if(!n.exec)return;e.isFunction(n.exec)?n.exec.call(o,t):o.execCommand(n.exec,n.hasOwnProperty("execParam")?n.execParam:null)},o.focus=function(){return o.inSourceMode()?d.focus():(h.contentWindow.focus(),g&&(w.selectRange(g),g=null)),this},o.blur=function(){return E||(E=e('
').appendTo(f)),E.removeAttr("disabled").focus().blur().attr("disabled","disabled"),this},N=function(){if(!e.sceditor.ie)return;g=w.selectedRange()},o.execCommand=function(t,n){var r=!1,i=e(w.parentNode());o.focus();if(i.is("code")||i.parents("code").length!==0)return;if(F())try{r=F().execCommand(t,!1,n)}catch(s){}!r&&o.commands[t]&&o.commands[t].errorMessage&&alert(o._(o.commands[t].errorMessage))},L=function(t){o.closeDropDown();var n=e(w.parentNode());if(t.which===13)if(n.is("code,blockquote,pre")||n.parents("code,blockquote,pre").length!==0)return g=null,o.wysiwygEditorInsertHtml("
",null,!0),!1;var r=F();e.sceditor.dom.rTraverse(r.body,function(t){if(t.nodeType===3&&t.nodeValue!==""||t.nodeName.toLowerCase()==="br")return e(t).parents("code, blockquote").length>0&&e(r.body).append(r.createElement("br")),!1},!0);if(n.is("code")||n.parents("code").length!==0)return;var i=m.length;while(i--)m[i].call(o,t,h,p)},A=function(){o.val(u.val())},O=function(){o.closeDropDown(),g=null},I=function(){o.options.height&&o.options.height.toString().indexOf("%")>-1&&o.height(f.parent().height()*(parseFloat(o.options.height)/100)),o.options.width&&o.options.width.toString().indexOf("%")>-1&&o.width(f.parent().width()*(parseFloat(o.options.width)/100))},o._=function(){var e=arguments;return y&&y[e[0]]&&(e[0]=y[e[0]]),e[0].replace(/\{(\d+)\}/g,function(t,n){return typeof e[n-0+1]!="undefined"?e[n-0+1]:"{"+n+"}"})},q=function(){if(e.sceditor.locale[o.options.locale])y=e.sceditor.locale[o.options.locale];else{var t=o.options.locale.split("-");e.sceditor.locale[t[0]]&&(y=e.sceditor.locale[t[0]])}y&&y.dateFormat&&(o.options.dateFormat=y.dateFormat)},S()},e.sceditor.ie=function(){var e,t=3,r=n.createElement("div"),i=r.getElementsByTagName("i");do r.innerHTML="";while(i[0]);return t>4?t:e}(),e.sceditor.isWysiwygSupported=function(){var t=e('
')[0].contentEditable,n=typeof t!="undefined"&&t!=="inherit",r=navigator.userAgent,i;if(!n)return!1;var s=/Opera Mobi|Opera Mini/i.test(r);return/Android/i.test(r)&&(s=!0,/Safari/.test(r)&&(i=/Safari\/(\d+)/.exec(r),s=!i||!i[1]?!0:i[1]<534)),/ Silk\//i.test(r)&&(i=/AppleWebKit\/(\d+)/.exec(r),s=!i||!i[1]?!0:i[1]<534),/iPhone|iPod|iPad/i.test(r)&&(s=!/OS 5(_\d)+ like Mac OS X/i.test(r)),/fennec/i.test(r)&&(s=!1),!s},e.sceditor.regexEscape=function(e){return e.replace(/[\$\?\[\]\.\*\(\)\|]/g,"\\$&").replace("<","<").replace(">",">")},e.sceditor.locale={},e.sceditor.commands={bold:{exec:"bold",tooltip:"Bold"},italic:{exec:"italic",tooltip:"Italic"},underline:{exec:"underline",tooltip:"Underline"},strike:{exec:"strikethrough",tooltip:"Strikethrough"},subscript:{exec:"subscript",tooltip:"Subscript"},superscript:{exec:"superscript",tooltip:"Superscript"},left:{exec:"justifyleft",tooltip:"Align left"},center:{exec:"justifycenter",tooltip:"Center"},right:{exec:"justifyright",tooltip:"Align right"},justify:{exec:"justifyfull",tooltip:"Justify"},font:{_dropDown:function(t,n,r){var s=t.options.fonts.split(","),o=e("
"),u=function(){return r(e(this).data("font")),t.closeDropDown(!0),!1};for(var a=0;a
"),o=function(n){r(e(this).data("size")),t.closeDropDown(!0),n.preventDefault()};for(var u=1;u<=7;u++)s.append(i("sizeOpt",{size:u},!0).click(o));t.createDropDown(n,"fontsize-picker",s)},exec:function(t){var n=this;e.sceditor.command.get("size")._dropDown(n,t,function(e){n.execCommand("fontsize",e)})},tooltip:"Font Size"},color:{_dropDown:function(t,n,r){var i={r:255,g:255,b:255},s=e("
"),o=t.options.colors?t.options.colors.split("|"):new Array(21),u=[],a=0;for(var f=0;f
';for(var c=0;c',c%5===0?i={r:i.r,g:i.g-51,b:255}:i={r:i.r,g:i.g,b:i.b-51}}u[a++]=" ",f%5===0?i={r:i.r-51,g:255,b:255}:i={r:i.r,g:255,b:255}}s.append(u.join("")).find("a").click(function(n){r(e(this).attr("data-color")),t.closeDropDown(!0),n.preventDefault()}),t.createDropDown(n,"color-picker",s)},exec:function(t){var n=this;e.sceditor.command.get("color")._dropDown(n,t,function(e){n.execCommand("forecolor",e)})},tooltip:"Font Color"},removeformat:{exec:"removeformat",tooltip:"Remove Formatting"},cut:{exec:"cut",tooltip:"Cut",errorMessage:"Your browser does not allow the cut command. Please use the keyboard shortcut Ctrl/Cmd-X"},copy:{exec:"copy",tooltip:"Copy",errorMessage:"Your browser does not allow the copy command. Please use the keyboard shortcut Ctrl/Cmd-C"},paste:{exec:"paste",tooltip:"Paste",errorMessage:"Your browser does not allow the paste command. Please use the keyboard shortcut Ctrl/Cmd-V"},pastetext:{exec:function(e){var t,n=this,r=i("pastetext",{label:n._("Paste your text inside the following box:"),insert:n._("Insert")},!0);r.find(".button").click(function(e){t=r.find("#txt").val(),t&&n.wysiwygEditorInsertText(t),n.closeDropDown(!0),e.preventDefault()}),n.createDropDown(e,"pastetext",r)},tooltip:"Paste Text"},bulletlist:{exec:"insertunorderedlist",tooltip:"Bullet list"},orderedlist:{exec:"insertorderedlist",tooltip:"Numbered list"},table:{exec:function(t){var n=this,r=i("table",{rows:n._("Rows:"),cols:n._("Cols:"),insert:n._("Insert")},!0);r.find(".button").click(function(t){var i=r.find("#rows").val()-0,s=r.find("#cols").val()-0,o="
";if(i<1||s<1)return;for(var u=0;u";for(var a=0;a"+(e.sceditor.ie?"":' ')+"";o+=""}o+="
",n.wysiwygEditorInsertHtml(o),n.closeDropDown(!0),t.preventDefault()}),n.createDropDown(t,"inserttable",r)},tooltip:"Insert a table"},horizontalrule:{exec:"inserthorizontalrule",tooltip:"Insert a horizontal rule"},code:{exec:function(){this.wysiwygEditorInsertHtml("
","")},tooltip:"Code"},image:{exec:function(e){var t=this,n=i("image",{url:t._("URL:"),width:t._("Width (optional):"),height:t._("Height (optional):"),insert:t._("Insert")},!0);n.find(".button").click(function(e){var r=n.find("#image").val(),i="",s,o;if(s=n.find("#width").val())i+=' width="'+s+'"';if(o=n.find("#height").val())i+=' height="'+o+'"';r&&r!=="http://"&&t.wysiwygEditorInsertHtml("
'),t.closeDropDown(!0),e.preventDefault()}),t.createDropDown(e,"insertimage",n)},tooltip:"Insert an image"},email:{exec:function(e){var t=this,n=i("email",{label:t._("E-mail:"),insert:t._("Insert")},!0);n.find(".button").click(function(e){var r=n.find("#email").val();r&&(t.focus(),t.getRangeHelper().selectedHtml()?t.execCommand("createlink","mailto:"+r):t.wysiwygEditorInsertHtml('
'+r+" ")),t.closeDropDown(!0),e.preventDefault()}),t.createDropDown(e,"insertemail",n)},tooltip:"Insert an email"},link:{exec:function(e){var t=this,n=i("link",{url:t._("URL:"),desc:t._("Description (optional):"),ins:t._("Insert")},!0);n.find(".button").click(function(e){var r=n.find("#link").val(),i=n.find("#des").val();r!==""&&r!=="http://"&&(t.focus(),!t.getRangeHelper().selectedHtml()||i?(i||(i=r),t.wysiwygEditorInsertHtml('
'+i+" ")):t.execCommand("createlink",r)),t.closeDropDown(!0),e.preventDefault()}),t.createDropDown(e,"insertlink",n)},tooltip:"Insert a link"},unlink:{exec:"unlink",tooltip:"Unlink"},quote:{exec:function(e,t,n){var r="
",i=" ";t?(n=n?"
"+n+" ":"",r=r+n+t+i+"
",i=null):this.getRangeHelper().selectedHtml()===""&&(i="
"+i),this.wysiwygEditorInsertHtml(r,i)},tooltip:"Insert a Quote"},emoticon:{exec:function(t){var n,r=this,i=r.options.emoticonsCompat?" ":"",s=e("
"),o=e("
");n=function(t,n){o.append(e("
").attr({src:n,alt:t}).click(function(t){r.insert(e(this).attr("alt")+i),r.closeDropDown(!0),t.preventDefault()})),o.children().length>3&&(s.append(o),o=e("
"))},e.each(r.options.emoticons.dropdown,n),o.children().length>0&&s.append(o);if(r.options.emoticons.more){var u=e(this._('
{0} ',this._("More"))).click(function(){var i=e.extend({},r.options.emoticons.dropdown,r.options.emoticons.more);return s=e("
"),e.each(i,n),o.children().length>0&&s.append(o),r.createDropDown(t,"insertemoticon",s),!1});s.append(u)}r.createDropDown(t,"insertemoticon",s)},txtExec:function(t){e.sceditor.command.get("emoticon").exec.call(this,t)},keyPress:function(t){if(this.options.toolbar.indexOf("emoticon")===-1)return;var n=this,r=0,s=String.fromCharCode(t.which);n.EmoticonsCache||(n.EmoticonsCache=[],e.each(e.extend({},n.options.emoticons.more,n.options.emoticons.dropdown,n.options.emoticons.hidden),function(e,t){n.EmoticonsCache[r++]=[e,i("emoticon",{key:e,url:t})]}),n.EmoticonsCache.sort(function(e,t){return e[0].length-t[0].length})),n.longestEmoticonCode||(n.longestEmoticonCode=n.EmoticonsCache[n.EmoticonsCache.length-1][0].length);if(n.getRangeHelper().raplaceKeyword(n.EmoticonsCache,!0,!0,n.longestEmoticonCode,n.options.emoticonsCompat,s))return/^\s$/.test(s)&&n.options.emoticonsCompat?!0:(t.preventDefault(),t.stopPropagation(),!1)},tooltip:"Insert an emoticon"},youtube:{_dropDown:function(e,t,n){var r,s=i("youtubeMenu",{label:e._("Video URL:"),insert:e._("Insert")},!0);s.find(".button").click(function(t){var i=s.find("#link").val().replace("http://","");i!==""&&(r=i.match(/(?:v=|v\/|embed\/|youtu.be\/)(.{11})/),r&&(i=r[1]),/^[a-zA-Z0-9_\-]{11}$/.test(i)?n(i):alert("Invalid YouTube video")),e.closeDropDown(!0),t.preventDefault()}),e.createDropDown(t,"insertlink",s)},exec:function(t){var n=this;e.sceditor.command.get("youtube")._dropDown(n,t,function(e){n.wysiwygEditorInsertHtml(i("youtube",{id:e}))})},tooltip:"Insert a YouTube video"},date:{_date:function(e){var t=new Date,n=t.getYear(),r=t.getMonth()+1,i=t.getDate();return n<2e3&&(n=1900+n),r<10&&(r="0"+r),i<10&&(i="0"+i),e.options.dateFormat.replace(/year/i,n).replace(/month/i,r).replace(/day/i,i)},exec:function(){this.insertText(e.sceditor.command.get("date")._date(this))},txtExec:function(){this.insertText(e.sceditor.command.get("date")._date(this))},tooltip:"Insert current date"},time:{_time:function(){var e=new Date,t=e.getHours(),n=e.getMinutes(),r=e.getSeconds();return t<10&&(t="0"+t),n<10&&(n="0"+n),r<10&&(r="0"+r),t+":"+n+":"+r},exec:function(){this.insertText(e.sceditor.command.get("time")._time())},txtExec:function(){this.insertText(e.sceditor.command.get("time")._time())},tooltip:"Insert current time"},ltr:{exec:function(){var t=this,n=t.getRangeHelper().getFirstBlockParent(),r=e(n);t.focus();if(!n||r.is("body")){t.execCommand("formatBlock","p"),n=t.getRangeHelper().getFirstBlockParent(),r=e(n);if(!n||r.is("body"))return}r.css("direction")==="ltr"?e(n).css("direction",""):e(n).attr("direction","ltr")},tooltip:"Left-to-Right"},rtl:{exec:function(){var t=this,n=t.getRangeHelper().getFirstBlockParent(),r=e(n);t.focus();if(!n||r.is("body")){t.execCommand("formatBlock","p"),n=t.getRangeHelper().getFirstBlockParent(),r=e(n);if(!n||r.is("body"))return}r.css("direction")==="rtl"?e(n).css("direction",""):e(n).css("direction","rtl")},tooltip:"Right-to-Left"},print:{exec:"print",tooltip:"Print"},source:{exec:function(){this.toggleTextMode()},txtExec:function(){this.toggleTextMode()},tooltip:"View source"},ignore:{}},e.sceditor.rangeHelper=function(n,r){var i,s,o=!0,u="sceditor-start-marker",a="sceditor-end-marker",f=this,l,c,h,p;l=function(e,t){s=t||e.contentDocument||e.document,i=e,o=!!e.getSelection}(n,r),f.insertHTML=function(e,t){var n,r;t&&(e+=f.selectedHtml()+t);if(o){r=s.createElement("div"),n=s.createDocumentFragment(),r.innerHTML=e;while(r.firstChild)n.appendChild(r.firstChild);f.insertNode(n)}else f.selectedRange().pasteHTML(e)},f.insertNode=function(e,t){if(o){var n=s.createDocumentFragment(),r=f.selectedRange(),i,u;n.appendChild(e),t&&(n.appendChild(r.extractContents()),n.appendChild(t)),u=n.lastChild,r.deleteContents(),r.insertNode(n),i=s.createRange(),i.setStartAfter(u),f.selectRange(i)}else f.insertHTML(e.outerHTML,t?t.outerHTML:null)},f.cloneSelected=function(){return o?f.selectedRange().cloneRange():f.selectedRange().duplicate()},f.selectedRange=function(){var e;return i.getSelection?e=i.getSelection():e=s.selection,e.getRangeAt&&e.rangeCount<=0&&e.addRange(s.createRange()),o?e.getRangeAt(0):e.createRange()},f.selectedHtml=function(){var e=f.selectedRange();return e?t.XMLSerializer?(new XMLSerializer).serializeToString(e.cloneContents()):!o&&e.text!==""&&e.htmlText?e.htmlText:"":""},f.parentNode=function(){var e=f.selectedRange();return o?e.commonAncestorContainer:e.parentElement()},f.getFirstBlockParent=function(){var t=function(n){if(!e.sceditor.dom.isInline(n))return n;var r=n.parentNode;return r?t(r):null};return t(f.parentNode())},f.insertNodeAt=function(e,t){var n=f.cloneSelected();n.collapse(e),n.insertNode?n.insertNode(t):n.pasteHTML(t.outerHTML)},c=function(e){f.removeMarker(e);var t=s.createElement("span");return t.id=e,t.style.lineHeight="0",t.style.display="none",t.className="sceditor-selection",t},f.insertMarkers=function(){f.insertNodeAt(!0,c(u)),f.insertNodeAt(!1,c(a))},f.getMarker=function(e){return s.getElementById(e)},f.removeMarker=function(e){var t=f.getMarker(e);t&&t.parentNode.removeChild(t)},f.removeMarkers=function(){f.removeMarker(u),f.removeMarker(a)},f.saveRange=function(){f.insertMarkers()},f.selectRange=function(e){o?(i.getSelection().removeAllRanges(),i.getSelection().addRange(e)):e.select()},f.restoreRange=function(){var e=f.selectedRange(),t=f.getMarker(u),n=f.getMarker(a);if(!t||!n)return!1;if(!o){e=s.body.createTextRange();var r=s.body.createTextRange();r.moveToElementText(t),e.setEndPoint("StartToStart",r),e.moveStart("character",0),r.moveToElementText(n),e.setEndPoint("EndToStart",r),e.moveEnd("character",0),f.selectRange(e)}else e=s.createRange(),e.setStartBefore(t),e.setEndAfter(n),f.selectRange(e);f.removeMarkers()},p=function(e,t){var n=f.cloneSelected();n.collapse(!1),o?(n.setStart(n.startContainer,n.startOffset-e),n.setEnd(n.endContainer,n.endOffset+t)):(n.moveStart("character",0-e),n.moveEnd("character",t)),f.selectRange(n)},h=function(e,t){var n="",r=f.cloneSelected();return r.collapse(!1),e?o?(n=r.startContainer.textContent.substr(0,r.startOffset),n=n.substr(Math.max(0,n.length-t))):(r.moveStart("character",0-t),n=r.text):o?n=r.startContainer.textContent.substr(r.startOffset,t):(r.moveEnd("character",t),n=r.text),n},f.raplaceKeyword=function(t,n,r,i,s,u){r||t.sort(function(e,t){return e.length-t.length});var a=i||t[t.length-1][0].length,l,c,d,v,m,g,y,b;l=c=d="";if(s){if(!o)return!1;++a}l=h(!0,a),n&&(c=h(!1,a)),d=l+(u!=null?u:"")+c,v=t.length;while(v--){y=new RegExp("(?:[\\s ])"+e.sceditor.regexEscape(t[v][0])+"(?=[\\s ])"),b=l.length-1-t[v][0].length,s&&--b,b=Math.max(0,b);if(!s&&(m=d.indexOf(t[v][0],b))>-1||s&&(m=d.substr(b).search(y))>-1){s&&(m+=b+1);if(m>l.length||m+t[v][0].length+(s?1:0)
-1?null:t,r=prompt(this._("Enter the e-mail address:"),n?"":t),i=prompt(this._("Enter the displayed text:"),n||r)||r;r&&this.insertText("[email="+r+"]"+i+"[/email]")}},link:{txtExec:function(e,t){var n=t&&t.indexOf("http://")>-1?null:t,r=prompt(this._("Enter URL:"),n?"http://":t),i=prompt(this._("Enter the displayed text:"),n||r)||r;r&&this.insertText("[url="+r+"]"+i+"[/url]")}},quote:{txtExec:["[quote]","[/quote]"]},youtube:{txtExec:function(t){var n=this;e.sceditor.command.get("youtube")._dropDown(n,t,function(e){n.insertText("[youtube]"+e+"[/youtube]")})}},rtl:{txtExec:["[rtl]","[/rtl]"]},ltr:{txtExec:["[ltr]","[/ltr]"]}};return e.extend(!0,{},t,e.sceditor.commands)},s=function(){e.each(r.bbcodes,function(t,n){typeof r.bbcodes[t].tags!="undefined"&&e.each(r.bbcodes[t].tags,function(e,n){var i=!!r.bbcodes[t].isBlock;p[e]=p[e]||{},p[e][i]=p[e][i]||{},p[e][i][t]=n}),typeof r.bbcodes[t].styles!="undefined"&&e.each(r.bbcodes[t].styles,function(e,n){var i=!!r.bbcodes[t].isBlock;d[i]=d[i]||{},d[i][e]=d[i][e]||{},d[i][e][t]=n})})},f=function(t,n){var r=e.camelCase(n),i,s,o;return"text-align"===n?(i=e(t),i.parent().css(n)!==i.css(n)&&i.css("display")==="block"&&!i.is("hr")&&!i.is("th")&&(s=i.css(n)),o=t.style.direction,o&&(/right/i.test(s)&&o==="rtl"||/left/i.test(s)&&o==="ltr")?null:s):t.style?t.style[r]:null},c=function(e){var t=e.childNodes,n=t.length;if(e.nodeValue)return!1;if(t.length===0||t.length===1&&(/br/i.test(t[0].nodeName)||c(t[0])))return!0;while(n--)if(!c(t[n]))return!1;return!0},o=function(t,n,i){var s;return i=!!i,d[i]?(e.each(d[i],function(i,o){s=f(t[0],i);if(!s||f(t.parent()[0],i)===s)return;e.each(o,function(i,o){if(!/\S|\u00A0/.test(n)&&!r.bbcodes[i].allowsEmpty&&c(t[0]))return;if(!o||e.inArray(s.toString(),o)>-1)e.isFunction(r.bbcodes[i].format)?n=r.bbcodes[i].format.call(r,t,n):n=a(r.bbcodes[i].format,n)})}),n):n},u=function(t,n,i){var s=t[0].nodeName.toLowerCase();i=!!i,p[s]&&p[s][i]&&e.each(p[s][i],function(i,s){if(!/\S|\u00A0/.test(n)&&!r.bbcodes[i].allowsEmpty&&c(t[0]))return;if(s){var o=!1;e.each(s,function(n,r){if(!t.attr(n)||r&&e.inArray(t.attr(n),r)<0)return;return o=!0,!1});if(!o)return}e.isFunction(r.bbcodes[i].format)?n=r.bbcodes[i].format.call(r,t,n):n=a(r.bbcodes[i].format,n)});if(i&&/^(br|div|p)$/.test(s)){if(!/^(div|p)$/i.test(s)||!t[0].lastChild||t[0].lastChild.nodeName.toLowerCase()!=="br")n+="\n";"br"!==s&&!e.sceditor.dom.isInline(t[0].parentNode)&&t[0].previousSibling&&t[0].previousSibling.nodeType===3&&(n="\n"+n)}return n},a=function(){var e=arguments;return e[0].replace(/\{(\d+)\}/g,function(t,n){return typeof e[n-0+1]!="undefined"?e[n-0+1]:"{"+n+"}"})},r.stripQuotes=function(e){return e.replace(/^(["'])(.*?)\1$/,"$2")},r.getHtmlHandler=function(t,n){return e.sceditor.dom.removeWhiteSpace(n[0]),e.trim(r.elementToBbcode(n))},r.elementToBbcode=function(t){return function n(t,r){var i="";return e.sceditor.dom.traverse(t,function(t){var s=e(t),a="",f=t.nodeName.toLowerCase(),l=v[f],c=!0;typeof r=="object"&&(c=e.inArray(f,r)>-1,c||(l=r));if(t.nodeType!==3){if(s.hasClass("sceditor-ignore"))return;f!=="iframe"&&(a=n(t,l)),c?(s.is("code")||(a=o(s,a),a=u(s,a),a=o(s,a,!0)),i+=u(s,a,!0)):i+=a}else t.wholeText&&(!t.previousSibling||t.previousSibling.nodeType!==3)?e(t).parents("code").length===0?i+=t.wholeText.replace(/ +/g," "):i+=t.wholeText:t.wholeText||(i+=t.nodeValue)},!1,!0),i}(t.get(0))},r.getTextHandler=function(t,n){var i,s,o=/\[([^\[\s=]+)(?:([^\[\]]+))?\]((?:[\s\S](?!\[\1))*?)\[\/(\1)\]/g,u=/(\S+)=((?:(?:(["'])(?:\\\3|[^\3])*?\3))|(?:[^'"\s]+))/g;s=function(t,n,i,s){var o={},f;n=n.toLowerCase();if(i){i=e.trim(i);if(i.charAt(0)==="="&&i.split("=").length-1<=1||n==="url")o.defaultattr=r.stripQuotes(i.substr(1));else{i.charAt(0)==="="&&(i="defaultattr"+i);while(f=u.exec(i))o[f[1].toLowerCase()]=r.stripQuotes(f[2])}}return r.bbcodes[n]?e.isFunction(r.bbcodes[n].html)?r.bbcodes[n].html.call(r,n,o,s):a(r.bbcodes[n].html,s):t},t=t.replace(/&/g,"&").replace(//g,">").replace(/\r/g,"").replace(/(\[\/?(?:left|center|right|justify|align|rtl|ltr)\])\n/g,"$1").replace(/\n/g," ");while(t!==i)i=t,t=t.replace(o,s);return t=t.replace(/\[hr\]/gi," ").replace(/\[\*\]/gi,""),t=t.replace(/ {2}(?=([^<\>]*?<|[^<\>]*?$))/g," "),l(t,n)},l=function(t,n){var r=document,i=r.createDocumentFragment(),s=r.createElement("div"),o=r.createElement("div"),u,a,f,l;e(o).hide().appendTo(r.body),o.innerHTML=t,a=o.firstChild;while(a){f=a.nextSibling,l=a.nodeName.toLowerCase();if(a.nodeType===1&&!e.sceditor.dom.isInline(a)||l==="br"){if(i.childNodes.length>0||l==="br")u=r.createElement("div"),u.appendChild(i),l==="br"&&!e.sceditor.ie&&u.appendChild(r.createElement("br")),!u.childNodes.length&&(r.documentMode&&r.documentMode<8||e.sceditor.ie<8)&&u.appendChild(r.createTextNode(" ")),s.appendChild(u),i=r.createDocumentFragment();l!=="br"&&s.appendChild(a)}else i.appendChild(a);a=f}i.childNodes.length>0&&(u=r.createElement("div"),u.appendChild(i),s.appendChild(u));if(n){a=s.firstChild;if(a&&a.nodeName.toLowerCase()==="div"){while(f=a.firstChild)s.insertBefore(f,a);e.sceditor.ie>=9&&s.insertBefore(r.createElement("br"),a),s.removeChild(a)}a=s.lastChild;if(a&&a.nodeName.toLowerCase()==="div"){while(f=a.firstChild)s.insertBefore(f,a);e.sceditor.ie>=9&&s.insertBefore(r.createElement("br"),a),s.removeChild(a)}}return e(o).remove(),s.innerHTML},i()},e.sceditorBBCodePlugin.bbcodes={b:{tags:{b:null,strong:null},styles:{"font-weight":["bold","bolder","401","700","800","900"]},format:"[b]{0}[/b]",html:"{0} "},i:{tags:{i:null,em:null},styles:{"font-style":["italic","oblique"]},format:"[i]{0}[/i]",html:"{0} "},u:{tags:{u:null},styles:{"text-decoration":["underline"]},format:"[u]{0}[/u]",html:"{0} "},s:{tags:{s:null,strike:null},styles:{"text-decoration":["line-through"]},format:"[s]{0}[/s]",html:"{0} "},sub:{tags:{sub:null},format:"[sub]{0}[/sub]",html:"{0} "},sup:{tags:{sup:null},format:"[sup]{0}[/sup]",html:"{0} "},font:{tags:{font:{face:null}},styles:{"font-family":null},format:function(e,t){return e[0].nodeName.toLowerCase()==="font"&&e.attr("face")?"[font="+this.stripQuotes(e.attr("face"))+"]"+t+"[/font]":"[font="+this.stripQuotes(e.css("font-family"))+"]"+t+"[/font]"},html:function(e,t,n){return''+n+" "}},size:{tags:{font:{size:null}},styles:{"font-size":null},format:function(e,t){var n=e.css("fontSize"),r=1;return e.attr("size")?r=e.attr("size"):n.indexOf("px")>-1?(n=n.replace("px","")-0,n>12&&(r=2),n>15&&(r=3),n>17&&(r=4),n>23&&(r=5),n>31&&(r=6),n>47&&(r=7)):r=n,"[size="+r+"]"+t+"[/size]"},html:function(e,t,n){return''+n+" "}},color:{tags:{font:{color:null}},styles:{color:null},format:function(e,t){var n=function(e){function n(e){return e=parseInt(e,10),isNaN(e)?"00":(e=Math.max(0,Math.min(e,255)).toString(16),e.length<2?"0"+e:e)}var t;return(t=e.match(/rgb\((\d+),\s*?(\d+),\s*?(\d+)\)/i))?"#"+n(t[1])+n(t[2]-0)+n(t[3]-0):(t=e.match(/#([0-f])([0-f])([0-f])\s*?$/i))?"#"+t[1]+t[1]+t[2]+t[2]+t[3]+t[3]:e},r=e.css("color");return e[0].nodeName.toLowerCase()==="font"&&e.attr("color")&&(r=e.attr("color")),r=n(r),"[color="+r+"]"+t+"[/color]"},html:function(e,t,n){return''+n+" "}},ul:{tags:{ul:null},isBlock:!0,format:"[ul]{0}[/ul]",html:""},list:{html:""},ol:{tags:{ol:null},isBlock:!0,format:"[ol]{0}[/ol]",html:"{0} "},li:{tags:{li:null},format:"[li]{0}[/li]",html:" {0} "},"*":{html:"{0} "},table:{tags:{table:null},format:"[table]{0}[/table]",html:""},tr:{tags:{tr:null},format:"[tr]{0}[/tr]",html:"{0} "},th:{tags:{th:null},isBlock:!0,format:"[th]{0}[/th]",html:"{0} "},td:{tags:{td:null},isBlock:!0,format:"[td]{0}[/td]",html:'{0} '},emoticon:{allowsEmpty:!0,tags:{img:{src:null,"data-sceditor-emoticon":null}},format:function(e,t){return e.attr("data-sceditor-emoticon")+t},html:"{0}"},horizontalrule:{allowsEmpty:!0,tags:{hr:null},format:"[hr]{0}",html:" "},img:{allowsEmpty:!0,tags:{img:{src:null}},format:function(t,n){var r="",i=function(e){return t.style?t.style[e]:null};if(typeof t.attr("data-sceditor-emoticon")!="undefined")return n;if(t.attr("width")||t.attr("height")||i("width")||i("height"))r="="+e(t).width()+"x"+e(t).height();return"[img"+r+"]"+t.attr("src")+"[/img]"},html:function(e,t,n){var r="",i;return typeof t.width!="undefined"&&(r+=' width="'+t.width+'"'),typeof t.height!="undefined"&&(r+=' height="'+t.height+'"'),typeof t.defaultattr!="undefined"&&(i=t.defaultattr.split(/x/i),r=' width="'+i[0]+'"'+' height="'+(i.length===2?i[1]:i[0])+'"')," '}},url:{allowsEmpty:!0,tags:{a:{href:null}},format:function(e,t){return e.attr("href").substr(0,7)==="mailto:"?"[email="+e.attr("href").substr(7)+"]"+t+"[/email]":"[url="+decodeURI(e.attr("href"))+"]"+t+"[/url]"},html:function(e,t,n){if(typeof t.defaultattr=="undefined"||t.defaultattr.length===0)t.defaultattr=n;return''+n+" "}},email:{html:function(e,t,n){return typeof t.defaultattr=="undefined"&&(t.defaultattr=n),''+n+" "}},quote:{tags:{blockquote:null},isBlock:!0,format:function(t,n){var r,i="",s=e(t);if(s.children("cite:first").length===1||s.data("author"))r=e(t).children("cite:first").text()||s.data("author"),s.data("author",r),e(t).children("cite:first").remove(),n="",n=this.elementToBbcode(e(t)),i="="+r;return"[quote"+i+"]"+n+"[/quote]"},html:function(e,t,n){return typeof t.defaultattr!="undefined"&&(n=""+t.defaultattr+" "+n),""+n+" "}},code:{tags:{code:null},isBlock:!0,format:"[code]{0}[/code]",html:"{0}"},left:{styles:{"text-align":["left","-webkit-left","-moz-left","-khtml-left"]},isBlock:!0,format:"[left]{0}[/left]",html:'{0}
'},center:{styles:{"text-align":["center","-webkit-center","-moz-center","-khtml-center"]},isBlock:!0,format:"[center]{0}[/center]",html:'{0}
'},right:{styles:{"text-align":["right","-webkit-right","-moz-right","-khtml-right"]},isBlock:!0,format:"[right]{0}[/right]",html:'{0}
'},justify:{styles:{"text-align":["justify","-webkit-justify","-moz-justify","-khtml-justify"]},isBlock:!0,format:"[justify]{0}[/justify]",html:'{0}
'},youtube:{allowsEmpty:!0,tags:{iframe:{"data-youtube-id":null}},format:function(e,t){return e.attr("data-youtube-id")?"[youtube]"+e.attr("data-youtube-id")+"[/youtube]":t},html:'VIDEO '},rtl:{styles:{direction:["rtl"]},format:"[rtl]{0}[/rtl]",html:'{0}
'},ltr:{styles:{direction:["ltr"]},format:"[ltr]{0}[/ltr]",html:'{0}
'},ignore:{}},e.sceditorBBCodePlugin.bbcode={get:function(t){return e.sceditorBBCodePlugin.bbcodes[t]||null},set:function(t,n){return!t||!n?!1:(n=e.extend(e.sceditorBBCodePlugin.bbcodes[t]||{},n),n.remove=function(){e.sceditorBBCodePlugin.bbcode.remove(t)},e.sceditorBBCodePlugin.bbcodes[t]=n,this)},remove:function(t){return e.sceditorBBCodePlugin.bbcodes[t]&&delete e.sceditorBBCodePlugin.bbcodes[t],this}},e.sceditorBBCodePlugin.commandExists=function(t){return!!e.sceditorBBCodePlugin.bbcode.get(t)},e.sceditorBBCodePlugin.setCommand=function(t,n,r,i,s,o,u){return e.sceditorBBCodePlugin.bbcode.set(t,{tags:n||{},styles:r||{},allowsEmpty:o,isBlock:u,format:i,html:s})},e.fn.sceditorBBCodePlugin=function(t){if((!t||!t.runWithoutWysiwygSupport)&&!e.sceditor.isWysiwygSupported())return;return this.each(function(){new e.sceditorBBCodePlugin(this,t)})}}(jQuery);