': '[center]{SELTEXT}[/center]'
}
},
video: {
title: CURLANG.video,
buttonHTML: '\uE008',
modal: {
title: CURLANG.video,
width: "600px",
tabs: [
{
title: CURLANG.video,
input: [
{param: "SRC",title:CURLANG.modal_video_text}
]
}
],
onSubmit: function(cmd,opt,queryState) {
var url = this.$modal.find('input[name="SRC"]').val();
if (url) {
url = url.replace(/^\s+/,"").replace(/\s+$/,"");
}
var a;
if (url.indexOf("youtu.be")!=-1) {
a = url.match(/^http[s]*:\/\/youtu\.be\/([a-z0-9_-]+)/i);
}else{
a = url.match(/^http[s]*:\/\/www\.youtube\.com\/watch\?.*?v=([a-z0-9_-]+)/i);
}
if (a && a.length==2) {
var code = a[1];
this.insertAtCursor(this.getCodeByCommand(cmd,{src:code}));
}
this.closeModal();
this.updateUI();
return false;
}
},
transform: {
'':'[video]{SRC}[/video]'
}
},
//select options
fs_verysmall: {
title: CURLANG.fs_verysmall,
buttonText: "fs1",
excmd: 'fontSize',
exvalue: "1",
transform: {
'{SELTEXT}':'[size=50]{SELTEXT}[/size]'
}
},
fs_small: {
title: CURLANG.fs_small,
buttonText: "fs2",
excmd: 'fontSize',
exvalue: "2",
transform: {
'{SELTEXT}':'[size=85]{SELTEXT}[/size]'
}
},
fs_normal: {
title: CURLANG.fs_normal,
buttonText: "fs3",
excmd: 'fontSize',
exvalue: "3",
transform: {
'{SELTEXT}':'[size=100]{SELTEXT}[/size]'
}
},
fs_big: {
title: CURLANG.fs_big,
buttonText: "fs4",
excmd: 'fontSize',
exvalue: "4",
transform: {
'{SELTEXT}':'[size=150]{SELTEXT}[/size]'
}
},
fs_verybig: {
title: CURLANG.fs_verybig,
buttonText: "fs5",
excmd: 'fontSize',
exvalue: "6",
transform: {
'{SELTEXT}':'[size=200]{SELTEXT}[/size]'
}
},
removeformat: {
title: CURLANG.removeFormat,
buttonHTML: '\uE00f',
excmd: "removeFormat"
}
},
systr: {
' ':"\n",
'{SELTEXT}': ' {SELTEXT}'
},
customRules: {
td: [["[td]{SELTEXT}[/td]",{seltext: {rgx:false,attr:false,sel:false}}]],
tr: [["[tr]{SELTEXT}[/tr]",{seltext: {rgx:false,attr:false,sel:false}}]],
table: [["[table]{SELTEXT}[/table]",{seltext: {rgx:false,attr:false,sel:false}}]]
//blockquote: [[" {SELTEXT}",{seltext: {rgx:false,attr:false,sel:false}}]]
},
smileList: [
//{title:CURLANG.sm1, img: '', bbcode:":)"},
],
attrWrap: ['src','color','href'] //use becouse FF and IE change values for this attr, modify [attr] to _[attr]
}
//FIX for Opera. Wait while iframe loaded
this.inited=this.options.onlyBBmode;
//init css prefix, if not set
if (!this.options.themePrefix) {
$('link').each($.proxy(function(idx, el) {
var sriptMatch = $(el).get(0).href.match(/(.*\/)(.*)\/wbbtheme\.css.*$/);
if (sriptMatch !== null) {
this.options.themeName = sriptMatch[2];
this.options.themePrefix = sriptMatch[1];
}
},this));
}
//check for preset
if (typeof(WBBPRESET)!="undefined") {
if (WBBPRESET.allButtons) {
//clear transform
$.each(WBBPRESET.allButtons,$.proxy(function(k,v) {
if (v.transform && this.options.allButtons[k]) {
delete this.options.allButtons[k].transform;
}
},this));
}
$.extend(true,this.options,WBBPRESET);
}
if (settings && settings.allButtons) {
$.each(settings.allButtons,$.proxy(function(k,v) {
if (v.transform && this.options.allButtons[k]) {
delete this.options.allButtons[k].transform;
}
},this));
}
$.extend(true,this.options,settings);
this.init();
}
$.wysibb.prototype = {
lastid : 1,
init: function() {
$.log("Init",this);
//check for mobile
this.isMobile = function(a) {(/android|avantgo|bada\/|blackberry|blazer|compal|elaine|fennec|hiptop|iemobile|ip(hone|od)|iris|kindle|lge |maemo|meego.+mobile|midp|mmp|netfront|opera m(ob|in)i|palm( os)?|phone|p(ixi|re)\/|plucker|pocket|psp|series(4|6)0|symbian|treo|up\.(browser|link)|vodafone|wap|windows (ce|phone)|xda|xiino/i.test(a))}(navigator.userAgent||navigator.vendor||window.opera);
//use bbmode on mobile devices
//this.isMobile = true; //TEMP
if (this.options.onlyBBmode===true) {this.options.bbmode=true;}
//create array of controls, for queryState
this.controllers = [];
//convert button string to array
this.options.buttons = this.options.buttons.toLowerCase();
this.options.buttons = this.options.buttons.split(",");
//init system transforms
this.options.allButtons["_systr"] = {};
this.options.allButtons["_systr"]["transform"]= this.options.systr;
this.smileFind();
this.initTransforms();
this.build();
this.initModal();
if (this.options.hotkeys===true && !this.isMobile) {
this.initHotkeys();
}
//sort smiles
if (this.options.smileList && this.options.smileList.length>0) {
this.options.smileList.sort(function(a,b) {
return (b.bbcode.length-a.bbcode.length);
})
}
this.$txtArea.parents("form").bind("submit",$.proxy(function() {
this.sync();
return true;
},this));
//phpbb2
this.$txtArea.parents("form").find("input[id*='preview'],input[id*='submit'],input[class*='preview'],input[class*='submit'],input[name*='preview'],input[name*='submit']").bind("mousedown",$.proxy(function() {
this.sync();
setTimeout($.proxy(function() {
if (this.options.bbmode===false) {
this.$txtArea.removeAttr("wbbsync").val("");
}
},this),1000);
},this));
//end phpbb2
if (this.options.initCallback) {
this.options.initCallback.call(this);
}
$.log(this);
},
initTransforms: function() {
$.log("Create rules for transform HTML=>BB");
var o = this.options;
//need to check for active buttons
if (!o.rules) {o.rules={};}
if (!o.groups) {o.groups={};} //use for groupkey, For example: justifyleft,justifyright,justifycenter. It is must replace each other.
var btnlist = o.buttons.slice();
//add system transform
btnlist.push("_systr");
for (var bidx=0; bidx'+bhtml+'';
obtr[newhtml] = bbcode;
}
} */
for (var bhtml in obtr) {
var orightml = bhtml;
var bbcode = obtr[bhtml];
//create root selector for isContain bbmode
if (!ob.bbSelector) {ob.bbSelector=[];}
if ($.inArray(bbcode,ob.bbSelector)==-1) {
ob.bbSelector.push(bbcode);
}
if (this.options.onlyBBmode===false) {
//wrap attributes
bhtml = this.wrapAttrs(bhtml);
var $bel = $(document.createElement('DIV')).append($(this.elFromString(bhtml,document)));
var rootSelector = this.filterByNode($bel.children());
//check if current rootSelector is exist, create unique selector for each transform (1.2.2)
if (rootSelector=="div" || typeof(o.rules[rootSelector])!="undefined") {
//create unique selector
$.log("create unique selector: "+rootSelector);
this.setUID($bel.children());
rootSelector = this.filterByNode($bel.children());
$.log("New rootSelector: "+rootSelector);
//replace transform with unique selector
var nhtml2 = $bel.html();
nhtml2 = this.unwrapAttrs(nhtml2);
var obhtml = this.unwrapAttrs(bhtml);
ob.transform[nhtml2]=bbcode;
delete ob.transform[obhtml];
bhtml=nhtml2;
orightml = nhtml2;
}
//create root selector for isContain
if (!ob.excmd) {
if (!ob.rootSelector) {ob.rootSelector=[];}
ob.rootSelector.push(rootSelector);
}
//check for rules on this rootSeletor
if (typeof(o.rules[rootSelector])=="undefined") {
o.rules[rootSelector]=[];
}
var crules={};
if (bhtml.match(/\{\S+?\}/)) {
$bel.find('*').each($.proxy(function(idx,el) {
//check attributes
var attributes = this.getAttributeList(el);
$.each(attributes,$.proxy(function(i, item) {
var attr = $(el).attr(item);
if (item.substr(0,1)=='_') {
item = item.substr(1);
}
var r = attr.match(/\{\S+?\}/g);
if (r) {
for (var a=0; a-1 || $(rel).parent().contents().size()>1) {
//has dublicate and not one children, need wrap
var nel = $("").html("{"+rname+"}");
this.setUID(nel,"wbb");
var start = (txt.indexOf(rname)+rname.length)+1;
var after_txt = txt.substr(start,txt.length-start);
//create wrap element
rel.data = txt.substr(0,txt.indexOf(rname)-1);
$(rel).after(this.elFromString(after_txt,document)).after(nel);
sel=((sel) ? sel+" ":"")+this.filterByNode(nel);
regRepl=false;
}
crules[rname.toLowerCase()]={sel:sel,attr:false,rgx:regRepl}
sl[sl.length]=sel;
}
}
},this));
}
sl=null;
},this));
var nbhtml = $bel.html();
//UnWrap attributes
nbhtml = this.unwrapAttrs(nbhtml);
if (orightml!=nbhtml) {
//if we modify html, replace it
delete ob.transform[orightml];
ob.transform[nbhtml]=bbcode;
bhtml=nbhtml;
}
}
o.rules[rootSelector].push([bbcode,crules]);
//check for onlyClearText
if (ob.onlyClearText===true) {
if (!this.cleartext) {this.cleartext={};}
this.cleartext[rootSelector]=btnlist[bidx];
}
//check for groupkey
if (ob.groupkey) {
if (!o.groups[ob.groupkey]) {o.groups[ob.groupkey]=[]}
o.groups[ob.groupkey].push(rootSelector);
}
}
}
//sort rootSelector
if (ob.rootSelector) {
this.sortArray(ob.rootSelector,-1);
}
var htmll = $.map(ob.transform,function(bb,html) {return html}).sort(function(a,b) {
return ((b[0] || "").length-(a[0] || "").length)
});
ob.bbcode = ob.transform[htmll[0]];
ob.html = htmll[0];
}
};
this.options.btnlist=btnlist; //use for transforms, becouse select elements not present in buttons
//add custom rules, for table,tr,td and other
$.extend(o.rules,this.options.customRules);
//smile rules
o.srules={};
if (this.options.smileList) {
$.each(o.smileList,$.proxy(function(i,sm) {
var $sm = $(this.strf(sm.img,o));
var f = this.filterByNode($sm);
o.srules[f]=[sm.bbcode,sm.img];
},this));
}
//sort transforms by bbcode length desc
for (var rootsel in o.rules) {
this.options.rules[rootsel].sort(function(a,b) {
return (b[0].length-a[0].length)
});
}
//create rootsel list
this.rsellist = [];
for (var rootsel in this.options.rules) {
this.rsellist.push(rootsel);
}
this.sortArray(this.rsellist,-1);
},
//BUILD
build: function() {
$.log("Build editor");
//this.$editor = $('
');
this.$editor = $('
').addClass("wysibb");
if (this.isMobile) {
this.$editor.addClass("wysibb-mobile");
}
//set direction if defined
if (this.options.direction) {this.$editor.css("direction",this.options.direction)}
this.$editor.insertAfter(this.txtArea).append(this.txtArea);
this.startHeight = this.$txtArea.outerHeight();
this.$txtArea.addClass("wysibb-texarea");
this.buildToolbar();
//Build iframe if needed
this.$txtArea.wrap('
');
if (this.options.onlyBBmode===false) {
var height = this.options.minheight || this.$txtArea.outerHeight();
var maxheight = this.options.resize_maxheight;
var mheight = (this.options.autoresize===true) ? this.options.resize_maxheight:height;
this.$body = $(this.strf('',{maxheight:mheight,height:height})).insertAfter(this.$txtArea);
this.body = this.$body[0];
this.$txtArea.hide();
if (height>32) {
this.$toolbar.css("max-height",height);
}
$.log("WysiBB loaded");
this.$body.addClass("wysibb-body").addClass(this.options.bodyClass);
//set direction if defined
if (this.options.direction) {this.$body.css("direction",this.options.direction)}
if ('contentEditable' in this.body) {
this.body.contentEditable=true;
try{
//fix for mfirefox
//document.execCommand('enableObjectResizing', false, 'false'); //disable image resizing
document.execCommand('StyleWithCSS', false, false);
//document.designMode = "on";
this.$body.append("");
}catch(e) {}
}else{
//use onlybbmode
this.options.onlyBBmode=this.options.bbmode=true;
}
//check for exist content in textarea
if (this.txtArea.value.length>0) {
this.txtAreaInitContent();
}
//clear html on paste from external editors
this.$body.bind('keydown', $.proxy(function(e) {
if ((e.which == 86 && (e.ctrlKey==true || e.metaKey==true)) || (e.which == 45 && (e.shiftKey==true || e.metaKey==true))) {
if (!this.$pasteBlock) {
this.saveRange();
this.$pasteBlock = $(this.elFromString('
\uFEFF
'));
this.$pasteBlock.appendTo(this.body);
//if (!$.support.search?type=2) {this.$pasteBlock.focus();} //IE 7,8 FIX
setTimeout($.proxy(function() {
this.clearPaste(this.$pasteBlock);
var rdata = ''+this.$pasteBlock.html()+'';
this.$body.attr("contentEditable","true");
this.$pasteBlock.blur().remove();
this.body.focus();
if (this.cleartext) {
$.log("Check if paste to clearText Block");
if (this.isInClearTextBlock()) {
rdata = this.toBB(rdata).replace(/\n/g," ").replace(/\s{3}/g,'');
}
}
rdata = rdata.replace(/\t/g,'');
this.selectRange(this.lastRange);
this.insertAtCursor(rdata,false);
this.lastRange=false;
this.$pasteBlock=false;
}
,this), 1);
this.selectNode(this.$pasteBlock[0]);
}
return true;
}
},this));
//insert BR on press enter
this.$body.bind('keydown',$.proxy(function(e) {
if (e.which == 13) {
var isLi = this.isContain(this.getSelectNode(),'li');
if (!isLi) {
if (e.preventDefault) {e.preventDefault();}
this.checkForLastBR(this.getSelectNode());
this.insertAtCursor(' ',false);
}
}
},this));
//tabInsert
if (this.options.tabInsert===true) {
this.$body.bind('keydown', $.proxy(this.pressTab,this));
}
//add event listeners
this.$body.bind('mouseup keyup',$.proxy(this.updateUI,this));
this.$body.bind('mousedown',$.proxy(function(e) {this.clearLastRange();this.checkForLastBR(e.target)},this));
//trace Textarea
if (this.options.traceTextarea===true) {
$(document).bind("mousedown",$.proxy(this.traceTextareaEvent,this));
this.$txtArea.val("");
}
//attach hotkeys
if (this.options.hotkeys===true) {
this.$body.bind('keydown',$.proxy(this.presskey,this));
}
//smileConversion
if (this.options.smileConversion===true) {
this.$body.bind('keyup',$.proxy(this.smileConversion,this));
}
this.inited=true;
//create resize lines
if (this.options.autoresize===true) {
this.$bresize = $(this.elFromString('')).appendTo(this.$editor)
.wdrag({
scope:this,
axisY: true,
height: height
});
}
this.imgListeners();
}
//this.$editor.append('Powered by WysiBB');
//add event listeners to textarea
this.$txtArea.bind('mouseup keyup',$.proxy(function() {
clearTimeout(this.uitimer);
this.uitimer = setTimeout($.proxy(this.updateUI,this),100);
},this));
//attach hotkeys
if (this.options.hotkeys===true) {
$(document).bind('keydown',$.proxy(this.presskey,this));
}
},
buildToolbar: function() {
if (this.options.toolbar === false) {return false;}
//this.$toolbar = $('
').prependTo(this.$editor);
this.$toolbar = $('
').addClass("wysibb-toolbar").prependTo(this.$editor);
var $btnContainer;
$.each(this.options.buttons,$.proxy(function(i,bn) {
var opt = this.options.allButtons[bn];
if (i==0 || bn=="|" || bn=="-") {
if (bn=="-") {
this.$toolbar.append("
");
}
$btnContainer = $('
').appendTo(this.$toolbar);
}
if (opt) {
if (opt.type=="colorpicker") {
this.buildColorpicker($btnContainer,bn,opt);
}else if (opt.type=="table") {
this.buildTablepicker($btnContainer,bn,opt);
}else if (opt.type=="select") {
this.buildSelect($btnContainer,bn,opt);
}else if (opt.type=="smilebox") {
this.buildSmilebox($btnContainer,bn,opt);
}else{
this.buildButton($btnContainer,bn,opt);
}
}
},this));
//fix for hide tooltip on quick mouse over
this.$toolbar.find(".btn-tooltip").hover(function () {$(this).parent().css("overflow","hidden")},function() {$(this).parent().css("overflow","visible")});
//build bbcode switch button
//var $bbsw = $('
').appendTo(this.$toolbar);
var $bbsw = $(document.createElement('div')).addClass("wysibb-toolbar-container modeSwitch").html('
[bbcode]
').appendTo(this.$toolbar);
if (this.options.bbmode==true) {$bbsw.children(".wysibb-toolbar-btn").addClass("on");}
if (this.options.onlyBBmode===false) {
$bbsw.children(".wysibb-toolbar-btn").click($.proxy(function(e) {
$(e.currentTarget).toggleClass("on");
this.modeSwitch();
},this));
}
},
buildButton: function(container,bn,opt) {
if (typeof(container)!="object") {
container = this.$toolbar;
}
var btnHTML = (opt.buttonHTML) ? $(this.strf(opt.buttonHTML,this.options)).addClass("btn-inner") : this.strf('{text}',{text:opt.buttonText.replace(/['+opt.hotkey+']'):""
var $btn = $('
\uE011').append(this.strf('{title}',{title:opt.title}));
var $cpline = $btn.find(".cp-line");
var $dropblock = $('
').appendTo($btn);
$dropblock.append('
'+CURLANG.auto+'
');
var colorlist = (opt.colors) ? opt.colors.split(","):[];
for (var j=0; j');
}else{
$dropblock.append(this.strf('',{color:colorlist[j]}));
}
}
var basecolor = $(document.body).css("color");
//attach events
this.controllers.push($btn);
$btn.bind('queryState',$.proxy(function(e) {
//queryState
$cpline.css("background-color",basecolor);
var r = this.queryState(bn,true);
if (r) {
$cpline.css("background-color",(this.options.bbmode) ? r.color:r);
$btn.find(".ve-tlb-colorpick span.fonticon").css("color",(this.options.bbmode) ? r.color:r);
}
},this));
$btn.mousedown($.proxy(function(e) {
e.preventDefault();
this.dropdownclick(".wbb-cp",".wbb-list",e);
},this));
$btn.find(".sc").mousedown($.proxy(function(e) {
e.preventDefault();
this.selectLastRange();
var c = $(e.currentTarget).attr("title");
this.execCommand(bn,c);
$btn.trigger('queryState');
},this));
$btn.find(".nc").mousedown($.proxy(function(e) {
e.preventDefault();
this.selectLastRange();
this.execCommand(bn,basecolor);
$btn.trigger('queryState');
},this));
$btn.mousedown(function(e) {
if (e.preventDefault) e.preventDefault();
});
},
buildTablepicker: function(container,bn,opt) {
var $btn = $('
').appendTo(container).append('\uE00e\uE011').append(this.strf('{title}',{title:opt.title}));
var $listblock = $('
').appendTo($btn);
var $dropblock = $('
').css({"position":"relative","box-sizing":"border-box"}).appendTo($listblock);
var rows = opt.rows || 10;
var cols = opt.cols || 10;
var allcount = rows*cols;
$dropblock.css("height",(rows*opt.cellwidth+2)+"px");
for (var j=1; j<=cols; j++) {
for (var h=1; h<=rows; h++) {
//var html = this.strf('',{width: (j*opt.cellwidth),height: (h*opt.cellwidth),zindex: --allcount,row:h,col:j});
var html = '';
$dropblock.append(html);
}
}
//this.debug("Attach event on: tbl-sel");
$btn.find(".tbl-sel").mousedown($.proxy(function(e) {
e.preventDefault();
var t = $(e.currentTarget).attr("title");
var rc = t.split(",");
var code = (this.options.bbmode) ? '[table]':'