':'[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();
var a;
if (url.indexOf("youtu.be") != -1) {
a = url.match(/^http:\/\/youtu\.be\/([a-z0-9_]+)/i);
} else {
a = url.match(/^http:\/\/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:":)"},
{title:CURLANG.sm8, img:'', bbcode:":("},
{title:CURLANG.sm1, img:'', bbcode:":D"},
{title:CURLANG.sm3, img:'', bbcode:";)"},
{title:CURLANG.sm4, img:'', bbcode:":up:"},
{title:CURLANG.sm5, img:'', bbcode:":down:"},
{title:CURLANG.sm6, img:'', bbcode:":shock:"},
{title:CURLANG.sm7, img:'', bbcode:":angry:"},
{title:CURLANG.sm9, img:'', bbcode:":sick:"}
],
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
if (this.isMobile) {
this.onlyBBmode = this.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 < btnlist.length; bidx++) {
var ob = o.allButtons[btnlist[bidx]];
if (!ob) {
continue;
}
ob.en = true;
//add transforms to option list
if (ob.type == "select" && typeof(ob.options) == "string") {
var olist = ob.options.split(",");
$.each(olist, function (i, op) {
if ($.inArray(op, btnlist) == -1) {
btnlist.push(op);
}
});
}
if (ob.transform && ob.skipRules !== true) {
var obtr = $.extend({}, ob.transform);
for (var bhtml in obtr) {
var orightml = bhtml;
var bbcode = ob.transform[bhtml];
//wrap attributes
$.each(o.attrWrap, function (i, a) {
bhtml = bhtml.replace(a + '="', '_' + a + '="');
});
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());
//replace transform with unique selector
var nhtml2 = $bel.html();
ob.transform[nhtml2] = bbcode;
delete ob.transform[bhtml];
bhtml = nhtml2;
}
//create root selector for isContain
if (!ob.excmd) {
if (!ob.rootSelector) {
ob.rootSelector = [];
}
ob.rootSelector.push(rootSelector);
}
if (!ob.bbSelector) {
ob.bbSelector = [];
}
if ($.inArray(bbcode, ob.bbSelector) == -1) {
ob.bbSelector.push(bbcode);
}
//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 < r.length; a++) {
var rname = r[a].substr(1, r[a].length - 2);
rname = rname.replace(this.getValidationRGX(rname), "");
var p = this.relFilterByNode(el, rootSelector);
var regRepl = (attr != r[a]) ? this.getRegexpReplace(attr, r[a]) : false;
crules[rname.toLowerCase()] = {sel:(p) ? $.trim(p) : false, attr:item, rgx:regRepl}
}
}
}, this));
//check for text
var sl = [];
if (!$(el).is("iframe")) {
$(el).contents().filter(function () {
return this.nodeType === 3
}).each($.proxy(function (i, rel) {
var txt = rel.textContent || rel.data;
if (typeof(txt) == "undefined") {
return true;
}
var r = txt.match(/\{\S+?\}/g)
if (r) {
for (var a = 0; a < r.length; a++) {
var rname = r[a].substr(1, r[a].length - 2);
rname = rname.replace(this.getValidationRGX(rname), "");
var p = this.relFilterByNode(el, rootSelector);
var regRepl = (txt != r[a]) ? this.getRegexpReplace(txt, r[a]) : false;
var sel = (p) ? $.trim(p) : false;
if ($.inArray(sel, sl) > -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
$.each(o.attrWrap, function (i, a) {
nbhtml = nbhtml.replace('_' + a + '="', a + '="');
});
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);
}
}
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");
//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();
$.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.lastRange = this.getRangeClone();
this.$pasteBlock = $(this.elFromString('
\uE011').append(this.strf('{title}', {title:opt.title}));
var $cpline = $btn.find(".cp-line");
//if ($.browser.msie) {$btn.attr("unselectable","on").find("*").attr("unselectable","on");} //fix for ie8 and lower
var $dropblock = $('
').appendTo(container).append('\uE00e\uE011').append(this.strf('{title}', {title:opt.title}));
//if ($.browser.msie) {$btn.attr("unselectable","on").find("*").attr("unselectable","on");} //fix for ie8 and lower
var $dropblock = $('
').appendTo($btn);
var rows = opt.rows || 10;
var cols = opt.cols || 10;
var allcount = rows * cols;
$dropblock.css("width", (cols * opt.cellwidth + 2) + "px").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();
this.selectLastRange();
var t = $(e.currentTarget).attr("title");
var rc = t.split(",");
var code = (this.options.bbmode) ? '[table]' : '
';
for (var i = 1; i <= rc[0]; i++) {
code += (this.options.bbmode) ? ' [tr]\n' : '