2 lines
46 KiB
JavaScript
2 lines
46 KiB
JavaScript
(function(e,t,n){"use strict";var r={html:'<!DOCTYPE html><html><head><!--[if IE]><style>* {min-height: auto}</style><![endif]--><meta http-equiv="Content-Type" content="text/html;charset={charset}" /><link rel="stylesheet" type="text/css" href="{style}" /></head><body contenteditable="true"></body></html>',toolbarButton:'<a class="sceditor-button sceditor-button-{name}" data-sceditor-command="{name}" unselectable="on"><div unselectable="on">{dispName}</div></a>',emoticon:'<img src="{url}" data-sceditor-emoticon="{key}" alt="{key}" />',fontOpt:'<a class="sceditor-font-option" href="#" data-font="{font}"><font face="{font}">{font}</font></a>',sizeOpt:'<a class="sceditor-fontsize-option" data-size="{size}" href="#"><font size="{size}">{size}</font></a>',pastetext:'<div><label for="txt">{label}</label> <textarea cols="20" rows="7" id="txt"></textarea></div><div><input type="button" class="button" value="{insert}" /></div>',table:'<div><label for="rows">{rows}</label><input type="text" id="rows" value="2" /></div><div><label for="cols">{cols}</label><input type="text" id="cols" value="2" /></div><div><input type="button" class="button" value="{insert}" /></div>',image:'<div><label for="link">{url}</label> <input type="text" id="image" value="http://" /></div><div><input type="button" class="button" value="{insert}" /></div>',email:'<div><label for="email">{label}</label> <input type="text" id="email" /></div><div><input type="button" class="button" value="{insert}" /></div>',link:'<div><label for="link">{url}</label> <input type="text" id="link" value="http://" /></div><div><label for="des">{desc}</label> <input type="text" id="des" /></div><div><input type="button" class="button" value="{ins}" /></div>',youtubeMenu:'<div><label for="link">{label}</label> <input type="text" id="link" value="http://" /></div><div><input type="button" class="button" value="{insert}" /></div>',youtube:'<iframe width="560" height="315" src="http://www.youtube.com/embed/{id}?wmode=opaque" data-youtube-id="{id}" frameborder="0" allowfullscreen></iframe>'},i=function(t,n,i){var s=r[t];return e.each(n,function(e,t){s=s.replace(new RegExp("\\{"+e+"\\}","g"),t)}),i&&(s=e(s)),s};e.sceditor=function(r,s){var o=this,u=e(r),a=r,f,l,c,h,p,d,v,m=[],g,y,b=[],w,E,S,x,T,N,C,k,L,A,O,M,_,D,P,H,B,j,F,I,q,R,U,z;o.commands=e.extend({},s.commands||e.sceditor.commands),S=function(){u.data("sceditor",o),o.options=e.extend({},e.sceditor.defaultOptions,s),o.options.locale&&o.options.locale!=="en"&&q();var r=o.options.height,i=o.options.width;(r&&(r+"").indexOf("%")>-1||i&&(i+"").indexOf("%")>-1)&&e(t).resize(I),f=e('<div class="sceditor-container" />').insertAfter(u),_(),M(),D(),o.options.resizeEnabled&&P(),o.options.id&&f.attr("id",o.options.id),e(n).click(H),e(a.form).attr("novalidate","novalidate").bind("reset",A).submit(B),o.val(u.hide().val()),o.options.autofocus&&z(),e.sceditor.isWysiwygSupported()||o.toggleTextMode(),o.options.toolbar.indexOf("emoticon")!==-1&&j();if(o.options.autoExpand)var l=setInterval(function(){if(!n.readyState||n.readyState==="complete")o.expandToContent(),clearInterval(l)},10)},M=function(){var n,r;p=e("<textarea></textarea>").hide(),c=e('<iframe frameborder="0"></iframe>'),t.location.protocol==="https:"&&c.attr("src","javascript:false"),f.append(c).append(p),h=c[0],d=p[0],o.width(o.options.width||u.width()),o.height(o.options.height||u.height()),F().open(),F().write(i("html",{charset:o.options.charset,style:o.options.style})),F().close(),o.readOnly(!!o.options.readOnly),n=e(F()),r=n.find("body"),e.sceditor.ie&&n.find("html").addClass("ie"+e.sceditor.ie),/iPhone|iPod|iPad| wosbrowser\//i.test(navigator.userAgent)&&r.height("100%"),r.keypress(L),n.keypress(L).mousedown(O).bind("beforedeactivate keyup",N).focus(function(){g=null}),o.options.rtl&&(r.attr("dir","rtl"),p.attr("dir","rtl")),o.options.enablePasteFiltering&&r.bind("paste",C),o.options.autoExpand&&n.bind("keyup",o.expandToContent),w=new e.sceditor.rangeHelper(h.contentWindow)},_=function(){var t,n,r,s,u,a,c=o.options.toolbar.split("|");a=function(){var t=e(this);return t.hasClass("disabled")||T(t,o.commands[t.data("sceditor-command")]),!1},l=e('<div class="sceditor-toolbar" />');for(s=0;s<c.length;s++){t=e('<div class="sceditor-group" />'),r=c[s].split(",");for(u=0;u<r.length;u++){if(!o.commands[r[u]])continue;n=i("toolbarButton",{name:r[u],dispName:o.commands[r[u]].tooltip||r[u]},!0).click(a),o.commands[r[u]].tooltip&&n.attr("title",o._(o.commands[r[u]].tooltip)),o.commands[r[u]].exec?n.data("sceditor-wysiwygmode",!0):n.addClass("disabled"),o.commands[r[u]].txtExec&&n.data("sceditor-txtmode",!0),t.append(n)}l.append(t)}o.options.toolbarContainer?e(o.options.toolbarContainer).append(l):f.append(l)},z=function(){var e=h.contentWindow.document,t=e.body,n;if(!e.createRange)return o.focus();if(!t.firstChild)return;n=e.createRange(),n.setStart(t.firstChild,0),n.setEnd(t.firstChild,0),w.selectRange(n),t.focus()},o.readOnly=function(e){return typeof e!="boolean"?p.attr("readonly")==="readonly":(F().body.contentEditable=!e,e?p.attr("readonly","readonly"):p.removeAttr("readonly"),R(e),this)},R=function(t){l.find(".sceditor-button").removeClass("disabled"),l.find(".sceditor-button").each(function(){var n=e(this);t===!0?n.addClass("disabled"):o.inSourceMode()&&!n.data("sceditor-txtmode")?n.addClass("disabled"):!o.inSourceMode()&&!n.data("sceditor-wysiwygmode")&&n.addClass("disabled")})},D=function(){e.each(o.commands,function(e,t){t.keyPress&&m.push(t.keyPress)})},o.width=function(e){return e?(f.width(e),c.width(e),c.width(e+(e-c.outerWidth(!0))),p.width(e),p.width(e+(e-p.outerWidth(!0))),this):f.width()},o.height=function(e){return e?(f.height(e),e-=o.options.toolbarContainer?0:l.outerHeight(!0),c.height(e),c.height(e+(e-c.outerHeight(!0))),p.height(e),p.height(e+(e-p.outerHeight(!0))),this):f.height()},o.expandToContent=function(e){var t=F(),n=f.height(),r=t.body.scrollHeight||t.documentElement.scrollHeight,i=n-c.height(),s=o.options.resizeMaxHeight||(o.options.height||u.height())*2;r+=i,e!==!0&&r>s&&(r=s),r>n&&o.height(r)},P=function(){var t=e('<div class="sceditor-grip" />'),r=e('<div class="sceditor-resize-cover" />'),i=0,s=0,u=0,a=0,l=f.width(),c=f.height(),h=!1,p,d,v,m,g;p=o.options.resizeMinHeight||c/1.5,d=o.options.resizeMaxHeight||c*2.5,v=o.options.resizeMinWidth||l/1.25,m=o.options.resizeMaxWidth||l*1.25,g=function(e){var t=a+(e.pageY-s),n=u+(e.pageX-i);n>=v&&(m<0||n<=m)&&o.width(n),t>=p&&(d<0||t<=d)&&o.height(t),e.preventDefault()},f.append(t),f.append(r.hide()),t.mousedown(function(t){i=t.pageX,s=t.pageY,u=f.width(),a=f.height(),h=!0,f.addClass("resizing"),r.show(),e(n).bind("mousemove",g),t.preventDefault()}),e(n).mouseup(function(t){if(!h)return;h=!1,r.hide(),f.removeClass("resizing"),e(n).unbind("mousemove",g),t.preventDefault()})},B=function(t){o.updateTextareaValue(),e(this).removeAttr("novalidate"),this.checkValidity&&!this.checkValidity()&&t.preventDefault(),e(this).attr("novalidate","novalidate"),o.blur()},o.destory=function(){e(n).unbind("click",H),e(t).unbind("resize",I),e(a.form).removeAttr("novalidate").unbind("submit",B).unbind("reset",A),e(F()).find("*").remove(),e(F()).unbind("keypress mousedown beforedeactivate keyup focus paste keypress"),f.find("*").remove(),f.remove(),u.removeData("sceditor").removeData("sceditorbbcode").show()},j=function(){o.options.emoticonsRoot&&o.options.emoticons&&e.each(o.options.emoticons,function(t,n){e.each(n,function(e,n){o.options.emoticons[t][e]=o.options.emoticonsRoot+n})});var t=e.extend({},o.options.emoticons.more,o.options.emoticons.dropdown,o.options.emoticons.hidden),r;e.each(t,function(e,t){r=n.createElement("img"),r.src=t,b.push(r)})},o.createDropDown=function(t,n,r,i){o.closeDropDown(),i!==!1&&e(r).find(":not(input,textarea)").filter(function(){return this.nodeType===1}).attr("unselectable","on");var s={top:t.offset().top,left:t.offset().left};e.extend(s,o.options.dropDownCss),v=e('<div class="sceditor-dropdown sceditor-'+n+'" />').css(s).append(r).appendTo(e("body")).click(function(e){e.stopPropagation()})},H=function(e){e.which!==3&&o.closeDropDown()},C=function(e){function f(e,t){if(e.childNodes.length>0){while(e.firstChild)t.appendChild(e.firstChild);while(s.firstChild)e.appendChild(s.firstChild);k(e,t)}else{if(r>25){while(s.firstChild)e.appendChild(s.firstChild);return}++r,setTimeout(function(){f(e,t)},20)}}var t=F().body,r=0,i=t.ownerDocument.createElement("div"),s=t.ownerDocument.createDocumentFragment();w.saveRange(),n.body.appendChild(i);if(e&&e.clipboardData&&e.clipboardData.getData){var u,a=!0;(u=e.clipboardData.getData("text/html"))||(u=e.clipboardData.getData("text/plain"))?i.innerHTML=u:a=!1;if(a)return k(t,i),e.preventDefault&&(e.stopPropagation(),e.preventDefault()),!1}while(t.firstChild)s.appendChild(t.firstChild);return f(t,i),o.focus(),!0},k=function(t,n){e.sceditor.dom.fixNesting(n);var r=n.innerHTML;o.options.getHtmlHandler&&(r=o.options.getHtmlHandler(r,e(n))),n.parentNode.removeChild(n),o.options.getTextHandler&&(r=o.options.getTextHandler(r,!0)),w.restoreRange(),w.insertHTML(r)},o.closeDropDown=function(e){v&&(v.remove(),v=null),e===!0&&o.focus()},F=function(){return h.contentDocument?h.contentDocument:h.contentWindow&&h.contentWindow.document?h.contentWindow.document:h.document?h.document:null},o.wysiwygEditorInsertHtml=function(t,n,r){o.focus();if(!r&&(e(w.parentNode()).is("code")||e(w.parentNode()).parents("code").length!==0))return;w.insertHTML(t,n)},o.wysiwygEditorInsertText=function(e,t){var n=function(e){return e?e.replace(/&/g,"&").replace(/</g,"<").replace(/>/g,">").replace(/ /g," ").replace(/\r\n|\r/g,"\n").replace(/\n/g,"<br />"):e};o.wysiwygEditorInsertHtml(n(e),n(t))},o.insertText=function(e,t){return o.inSourceMode()?o.textEditorInsertText(e,t):o.wysiwygEditorInsertText(e,t),this},o.textEditorInsertText=function(e,t){var r,i,s,o;d.focus(),typeof d.selectionStart!="undefined"?(i=d.selectionStart,s=d.selectionEnd,o=e.length,t&&(e+=d.value.substring(i,s)+t),d.value=d.value.substring(0,i)+e+d.value.substring(s,d.value.length),t?d.selectionStart=i+e.length-t.length:d.selectionStart=i+e.length,d.selectionEnd=d.selectionStart):typeof n.selection.createRange!="undefined"?(r=n.selection.createRange(),t&&(e+=r.text+t),r.text=e,t&&r.moveEnd("character",0-t.length),r.moveStart("character",r.End-r.Start),r.select()):d.value+=e+t,d.focus()},o.getRangeHelper=function(){return w},o.val=function(e,t){return typeof e=="string"?(o.inSourceMode()?o.setTextareaValue(e):(t!==!1&&o.options.getTextHandler&&(e=o.options.getTextHandler(e)),o.setWysiwygEditorValue(e)),this):o.inSourceMode()?o.getTextareaValue(!1):o.getWysiwygEditorValue()},o.insert=function(t,n,r,i){if(o.inSourceMode())o.textEditorInsertText(t,n);else{if(n){var s=o.getRangeHelper().selectedHtml(),u=e("<div>").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="<p>"+(e.sceditor.ie?"":"<br />")+"</p>"),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('<input style="width:0; height:0; opacity:0; filter: alpha(opacity=0)" type="text" />').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("<br />",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="<!--[if gt IE "+ ++t+"]><i></i><![endif]-->";while(i[0]);return t>4?t:e}(),e.sceditor.isWysiwygSupported=function(){var t=e('<div contenteditable="true">')[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("<div />"),u=function(){return r(e(this).data("font")),t.closeDropDown(!0),!1};for(var a=0;a<s.length;a++)o.append(i("fontOpt",{font:s[a]},!0).click(u));t.createDropDown(n,"font-picker",o)},exec:function(t){var n=this;e.sceditor.command.get("font")._dropDown(n,t,function(e){n.execCommand("fontname",e)})},tooltip:"Font Name"},size:{_dropDown:function(t,n,r){var s=e("<div />"),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("<div />"),o=t.options.colors?t.options.colors.split("|"):new Array(21),u=[],a=0;for(var f=0;f<o.length;++f){var l=o[f]?o[f].split(","):new Array(21);u[a++]='<div class="sceditor-color-column">';for(var c=0;c<l.length;++c){var h=l[c]?l[c]:"#"+i.r.toString(16)+i.g.toString(16)+i.b.toString(16);u[a++]='<a href="#" class="sceditor-color-option" style="background-color: '+h+'" data-color="'+h+'"></a>',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++]="</div>",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="<table>";if(i<1||s<1)return;for(var u=0;u<i;u++){o+="<tr>";for(var a=0;a<s;a++)o+="<td>"+(e.sceditor.ie?"":'<br class="sceditor-ignore" />')+"</td>";o+="</tr>"}o+="</table>",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("<code>","<br /></code>")},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("<img"+i+' src="'+r+'" />'),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('<a href="mailto:'+r+'">'+r+"</a>")),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('<a href="'+r+'">'+i+"</a>")):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="<blockquote>",i="</blockquote>";t?(n=n?"<cite>"+n+"</cite>":"",r=r+n+t+i+"<br />",i=null):this.getRangeHelper().selectedHtml()===""&&(i="<br />"+i),this.wysiwygEditorInsertHtml(r,i)},tooltip:"Insert a Quote"},emoticon:{exec:function(t){var n,r=this,i=r.options.emoticonsCompat?" ":"",s=e("<div />"),o=e("<div />");n=function(t,n){o.append(e("<img />").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("<div />"))},e.each(r.options.emoticons.dropdown,n),o.children().length>0&&s.append(o);if(r.options.emoticons.more){var u=e(this._('<a class="sceditor-more">{0}</a>',this._("More"))).click(function(){var i=e.extend({},r.options.emoticons.dropdown,r.options.emoticons.more);return s=e("<div />"),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)<l.length)continue;return g=l.length-m,p(g,t[v][0].length-g-(u!=null&&/^\S/.test(u)?1:0)),f.insertHTML(t[v][1]),!0}}return!1}},e.sceditor.dom={traverse:function(e,t,n,r,i){if(e){e=i?e.lastChild:e.firstChild;while(e!=null){var s=i?e.previousSibling:e.nextSibling;if(!n&&t(e)===!1)return!1;if(!r&&this.traverse(e,t,n,r,i)===!1)return!1;if(n&&t(e)===!1)return!1;e=s}}},rTraverse:function(e,t,n,r){this.traverse(e,t,n,r,!0)},blockLevelList:"|body|hr|p|div|h1|h2|h3|h4|h5|h6|address|pre|form|table|tbody|thead|tfoot|th|tr|td|li|ol|ul|blockquote|center|",isInline:function(t,n){return!t||t.nodeType!==1?!0:n&&t.tagName.toLowerCase()==="code"?!1:e.sceditor.dom.blockLevelList.indexOf("|"+t.tagName.toLowerCase()+"|")<0},copyCSS:function(e,t){t.style.cssText=e.style.cssText},fixNesting:function(e){var t=this,n=function(e){while(t.isInline(e.parentNode,!0))e=e.parentNode;return e};t.traverse(e,function(e){if(e.nodeType===1&&!t.isInline(e,!0)&&t.isInline(e.parentNode,!0)){var r=n(e),i=r.parentNode,s=t.extractContents(r,e),o=e;t.copyCSS(o,o),i.insertBefore(s,r),i.insertBefore(o,r)}})},findCommonAncestor:function(t,n){return e(t).parents().has(e(n)).first()},removeWhiteSpace:function(t){var n=/[^\S|\u00A0]+/g;this.traverse(t,function(t){if(t.nodeType===3&&e(t).parents("code, pre").length===0&&t.nodeValue){t.nodeValue=t.nodeValue.replace(/[\r\n]/,"");if(!t.nodeValue.length){t.parentNode.removeChild(t);return}/\S|\u00A0/.test(t.nodeValue)?n.test(t.nodeValue)&&(t.nodeValue=t.nodeValue.replace(n," ")):t.nodeValue=" "}})},extractContents:function(e,t){var n=this,r=n.findCommonAncestor(e,t),i=r?r.get(0):null,s=!1,o=!1;return function u(r){var i=e.ownerDocument.createDocumentFragment();return n.traverse(r,function(n){if(o||n===t&&s)return o=!0,!1;n===e&&(s=!0);var r,a;s?jQuery.contains(n,t)&&n.nodeType===1?(r=u(n),a=n.cloneNode(!1),a.appendChild(r),i.appendChild(a)):i.appendChild(n):jQuery.contains(n,e)&&n.nodeType===1&&(r=u(n),a=n.cloneNode(!1),a.appendChild(r),i.appendChild(a))},!1),i}(i)}},e.sceditor.command={get:function(t){return e.sceditor.commands[t]||null},set:function(t,n){return!t||!n?!1:(n=e.extend(e.sceditor.commands[t]||{},n),n.remove=function(){e.sceditor.command.remove(t)},e.sceditor.commands[t]=n,this)},remove:function(t){return e.sceditor.commands[t]&&delete e.sceditor.commands[t],this}},e.sceditor.commandExists=function(t){return!!e.sceditor.command.get(t)},e.sceditor.setCommand=function(t,n,r,i,s){return!!e.sceditor.command.set(t,{exec:n,tooltip:r,keypress:i,txtExec:s})},e.sceditor.defaultOptions={toolbar:"bold,italic,underline,strike,subscript,superscript|left,center,right,justify|font,size,color,removeformat|cut,copy,paste,pastetext|bulletlist,orderedlist|table|code,quote|horizontalrule,image,email,link,unlink|emoticon,youtube,date,time|ltr,rtl|print,source",style:"jquery.sceditor.default.css",fonts:"Arial,Helvetica,sans-serif",colors:null,locale:"en",charset:"utf-8",emoticonsCompat:!1,emoticonsRoot:"",emoticons:{dropdown:{":)":"emoticons/smile.png",":angel:":"emoticons/angel.png",":angry:":"emoticons/angry.png","8-)":"emoticons/cool.png",":'(":"emoticons/cwy.png",":ermm:":"emoticons/ermm.png",":D":"emoticons/grin.png","<3":"emoticons/heart.png",":(":"emoticons/sad.png",":O":"emoticons/shocked.png",":P":"emoticons/tongue.png",";)":"emoticons/wink.png"},more:{":alien:":"emoticons/alien.png",":blink:":"emoticons/blink.png",":blush:":"emoticons/blush.png",":cheerful:":"emoticons/cheerful.png",":devil:":"emoticons/devil.png",":dizzy:":"emoticons/dizzy.png",":getlost:":"emoticons/getlost.png",":happy:":"emoticons/happy.png",":kissing:":"emoticons/kissing.png",":ninja:":"emoticons/ninja.png",":pinch:":"emoticons/pinch.png",":pouty:":"emoticons/pouty.png",":sick:":"emoticons/sick.png",":sideways:":"emoticons/sideways.png",":silly:":"emoticons/silly.png",":sleeping:":"emoticons/sleeping.png",":unsure:":"emoticons/unsure.png",":woot:":"emoticons/w00t.png",":wassat:":"emoticons/wassat.png"
|
||
},hidden:{":whistling:":"emoticons/whistling.png",":love:":"emoticons/wub.png"}},width:null,height:null,resizeEnabled:!0,resizeMinWidth:null,resizeMinHeight:null,resizeMaxHeight:null,resizeMaxWidth:null,getHtmlHandler:null,getTextHandler:null,dateFormat:"year-month-day",toolbarContainer:null,enablePasteFiltering:!1,readOnly:!1,rtl:!1,autofocus:!1,autoExpand:!1,runWithoutWysiwygSupport:!1,id:null,dropDownCss:{}},e.fn.sceditor=function(t){if((!t||!t.runWithoutWysiwygSupport)&&!e.sceditor.isWysiwygSupported())return;return this.each(function(){new e.sceditor(this,t)})}})(jQuery,window,document),function(e){"use strict";e.sceditorBBCodePlugin=function(t,n){var r=this,i,s,o,u,a,f,l,c,h;r.bbcodes=e.sceditorBBCodePlugin.bbcodes;var p={},d={},v={ul:["li"],ol:["li"],table:["tr"],tr:["td","th"],code:["br","p","div"],youtube:[]};i=function(){e.data(t,"sceditorbbcode",r),r.options=e.extend({},e.sceditor.defaultOptions,n),s(),new e.sceditor(t,e.extend({},r.options,{getHtmlHandler:r.getHtmlHandler,getTextHandler:r.getTextHandler,commands:h()}))},h=function(){var t={bold:{txtExec:["[b]","[/b]"]},italic:{txtExec:["[i]","[/i]"]},underline:{txtExec:["[u]","[/u]"]},strike:{txtExec:["[s]","[/s]"]},subscript:{txtExec:["[sub]","[/sub]"]},superscript:{txtExec:["[sup]","[/sup]"]},left:{txtExec:["[left]","[/left]"]},center:{txtExec:["[center]","[/center]"]},right:{txtExec:["[right]","[/right]"]},justify:{txtExec:["[justify]","[/justify]"]},font:{txtExec:function(t){var n=this;e.sceditor.command.get("font")._dropDown(n,t,function(e){n.insertText("[font="+e+"]","[/font]")})}},size:{txtExec:function(t){var n=this;e.sceditor.command.get("size")._dropDown(n,t,function(e){n.insertText("[size="+e+"]","[/size]")})}},color:{txtExec:function(t){var n=this;e.sceditor.command.get("color")._dropDown(n,t,function(e){n.insertText("[color="+e+"]","[/color]")})}},bulletlist:{txtExec:["[ul][li]","[/li][/ul]"]},orderedlist:{txtExec:["[ol][li]","[/li][/ol]"]},table:{txtExec:["[table][tr][td]","[/td][/tr][/table]"]},horizontalrule:{txtExec:["[hr]"]},code:{txtExec:["[code]","[/code]"]},image:{txtExec:function(e,t){var n=prompt(this._("Enter the image URL:"),t);n&&this.insertText("[img]"+n+"[/img]")}},email:{txtExec:function(e,t){var n=t&&t.indexOf("@")>-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(/>/g,">").replace(/\r/g,"").replace(/(\[\/?(?:left|center|right|justify|align|rtl|ltr)\])\n/g,"$1").replace(/\n/g,"<br />");while(t!==i)i=t,t=t.replace(o,s);return t=t.replace(/\[hr\]/gi,"<hr>").replace(/\[\*\]/gi,"<li>"),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:"<strong>{0}</strong>"},i:{tags:{i:null,em:null},styles:{"font-style":["italic","oblique"]},format:"[i]{0}[/i]",html:"<em>{0}</em>"},u:{tags:{u:null},styles:{"text-decoration":["underline"]},format:"[u]{0}[/u]",html:"<u>{0}</u>"},s:{tags:{s:null,strike:null},styles:{"text-decoration":["line-through"]},format:"[s]{0}[/s]",html:"<s>{0}</s>"},sub:{tags:{sub:null},format:"[sub]{0}[/sub]",html:"<sub>{0}</sub>"},sup:{tags:{sup:null},format:"[sup]{0}[/sup]",html:"<sup>{0}</sup>"},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'<font face="'+t.defaultattr+'">'+n+"</font>"}},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'<font size="'+t.defaultattr+'">'+n+"</font>"}},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'<font color="'+t.defaultattr+'">'+n+"</font>"}},ul:{tags:{ul:null},isBlock:!0,format:"[ul]{0}[/ul]",html:"<ul>{0}</ul>"},list:{html:"<ul>{0}</ul>"},ol:{tags:{ol:null},isBlock:!0,format:"[ol]{0}[/ol]",html:"<ol>{0}</ol>"},li:{tags:{li:null},format:"[li]{0}[/li]",html:"<li>{0}</li>"},"*":{html:"<li>{0}</li>"},table:{tags:{table:null},format:"[table]{0}[/table]",html:"<table>{0}</table>"},tr:{tags:{tr:null},format:"[tr]{0}[/tr]",html:"<tr>{0}</tr>"},th:{tags:{th:null},isBlock:!0,format:"[th]{0}[/th]",html:"<th>{0}</th>"},td:{tags:{td:null},isBlock:!0,format:"[td]{0}[/td]",html:'<td>{0}<br class="sceditor-ignore" /></td>'},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:"<hr />"},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])+'"'),"<img "+r+' src="'+n+'" />'}},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'<a href="'+encodeURI(t.defaultattr)+'">'+n+"</a>"}},email:{html:function(e,t,n){return typeof t.defaultattr=="undefined"&&(t.defaultattr=n),'<a href="mailto:'+t.defaultattr+'">'+n+"</a>"}},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="<cite>"+t.defaultattr+"</cite>"+n),"<blockquote>"+n+"</blockquote>"}},code:{tags:{code:null},isBlock:!0,format:"[code]{0}[/code]",html:"<code>{0}</code>"},left:{styles:{"text-align":["left","-webkit-left","-moz-left","-khtml-left"]},isBlock:!0,format:"[left]{0}[/left]",html:'<div align="left">{0}</div>'},center:{styles:{"text-align":["center","-webkit-center","-moz-center","-khtml-center"]},isBlock:!0,format:"[center]{0}[/center]",html:'<div align="center">{0}</div>'},right:{styles:{"text-align":["right","-webkit-right","-moz-right","-khtml-right"]},isBlock:!0,format:"[right]{0}[/right]",html:'<div align="right">{0}</div>'},justify:{styles:{"text-align":["justify","-webkit-justify","-moz-justify","-khtml-justify"]},isBlock:!0,format:"[justify]{0}[/justify]",html:'<div align="justify">{0}</div>'},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:'<iframe width="560" height="315" src="http://www.youtube.com/embed/{0}?wmode=opaque" data-youtube-id="{0}" frameborder="0" allowfullscreen></iframe>'},rtl:{styles:{direction:["rtl"]},format:"[rtl]{0}[/rtl]",html:'<div style="direction: rtl">{0}</div>'},ltr:{styles:{direction:["ltr"]},format:"[ltr]{0}[/ltr]",html:'<div style="direction: ltr">{0}</div>'},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); |