/*! WysiBB v1.5.1 2014-03-26 Author: Vadim Dobroskok */ if (typeof (WBBLANG)=="undefined") {WBBLANG = {};} WBBLANG['en'] = CURLANG = { bold: "Bold", italic: "Italic", underline: "Underline", strike: "Strike", link: "Link", img: "Insert image", sup: "Superscript", sub: "Subscript", justifyleft: "Align left", justifycenter: "Align center", justifyright: "Align right", table: "Insert table", bullist: "• Unordered list", numlist: "1. Ordered list", quote: "Quote", offtop: "Offtop", code: "Code", spoiler: "Spoiler", fontcolor: "Font color", fontsize: "Font size", fontfamily: "Font family", fs_verysmall: "Very small", fs_small: "Small", fs_normal: "Normal", fs_big: "Big", fs_verybig: "Very big", smilebox: "Insert emoticon", video: "Insert YouTube", removeFormat:"Remove Format", modal_link_title: "Insert link", modal_link_text: "Display text", modal_link_url: "URL", modal_email_text: "Display email", modal_email_url: "Email", modal_link_tab1: "Insert URL", modal_img_title: "Insert image", modal_img_tab1: "Insert URL", modal_img_tab2: "Upload image", modal_imgsrc_text: "Enter image URL", modal_img_btn: "Choose file", add_attach: "Add Attachment", modal_video_text: "Enter the URL of the video", close: "Close", save: "Save", cancel: "Cancel", remove: "Delete", validation_err: "The entered data is invalid", error_onupload: "Error during file upload", fileupload_text1: "Drop file here", fileupload_text2: "or", loading: "Loading", auto: "Auto", views: "Views", downloads: "Downloads", //smiles sm1: "Smile", sm2: "Laughter", sm3: "Wink", sm4: "Thank you", sm5: "Scold", sm6: "Shock", sm7: "Angry", sm8: "Pain", sm9: "Sick" }; wbbdebug=true; (function($) { 'use strict'; $.wysibb = function(txtArea,settings) { $(txtArea).data("wbb",this); if (settings && settings.deflang && typeof(WBBLANG[settings.deflang])!="undefined") {CURLANG = WBBLANG[settings.deflang];} if (settings && settings.lang && typeof(WBBLANG[settings.lang])!="undefined") {CURLANG = WBBLANG[settings.lang];} this.txtArea=txtArea; this.$txtArea=$(txtArea); var id = this.$txtArea.attr("id") || this.setUID(this.txtArea); this.options = { bbmode: false, onlyBBmode: false, themeName: "default", bodyClass: "", lang: "ru", tabInsert: true, // toolbar: false, //img upload config imgupload: false, img_uploadurl: "/iupload.php", img_maxwidth: 800, img_maxheight: 800, hotkeys: true, showHotkeys: true, autoresize: true, resize_maxheight: 800, loadPageStyles: true, traceTextarea: true, // direction: "ltr", smileConversion: true, //END img upload config buttons: "bold,italic,underline,strike,sup,sub,|,img,video,link,|,bullist,numlist,|,fontcolor,fontsize,fontfamily,|,justifyleft,justifycenter,justifyright,|,quote,code,table,removeFormat", allButtons: { bold : { title: CURLANG.bold, buttonHTML: '\uE018', excmd: 'bold', hotkey: 'ctrl+b', transform : { '{SELTEXT}':"[b]{SELTEXT}[/b]", '{SELTEXT}':"[b]{SELTEXT}[/b]" } }, italic : { title: CURLANG.italic, buttonHTML: '\uE001', excmd: 'italic', hotkey: 'ctrl+i', transform : { '{SELTEXT}':"[i]{SELTEXT}[/i]", '{SELTEXT}':"[i]{SELTEXT}[/i]" } }, underline : { title: CURLANG.underline, buttonHTML: '\uE002', excmd: 'underline', hotkey: 'ctrl+u', transform : { '{SELTEXT}':"[u]{SELTEXT}[/u]" } }, strike : { title: CURLANG.strike, buttonHTML: '\uE003', excmd: 'strikeThrough', transform : { '{SELTEXT}':"[s]{SELTEXT}[/s]", '{SELTEXT}':"[s]{SELTEXT}[/s]" } }, sup : { title: CURLANG.sup, buttonHTML: '\uE005', excmd: 'superscript', transform : { '{SELTEXT}':"[sup]{SELTEXT}[/sup]" } }, sub : { title: CURLANG.sub, buttonHTML: '\uE004', excmd: 'subscript', transform : { '{SELTEXT}':"[sub]{SELTEXT}[/sub]" } }, link : { title: CURLANG.link, buttonHTML: '\uE007', hotkey: 'ctrl+shift+2', modal: { title: CURLANG.modal_link_title, width: "500px", tabs: [ { input: [ {param: "SELTEXT",title:CURLANG.modal_link_text, type: "div"}, {param: "URL",title:CURLANG.modal_link_url,validation: '^http(s)?://'} ] } ] }, transform : { '{SELTEXT}':"[url={URL}]{SELTEXT}[/url]", '{URL}':"[url]{URL}[/url]" } }, img : { title: CURLANG.img, buttonHTML: '\uE006', hotkey: 'ctrl+shift+1', addWrap: true, modal: { title: CURLANG.modal_img_title, width: "600px", tabs: [ { title: CURLANG.modal_img_tab1, input: [ {param: "SRC",title:CURLANG.modal_imgsrc_text,validation: '^http(s)?://.*?\.(jpg|png|gif|jpeg)$'} ] } ], onLoad: this.imgLoadModal }, transform : { '':"[img]{SRC}[/img]", '':"[img width={WIDTH},height={HEIGHT}]{SRC}[/img]" } }, bullist : { title: CURLANG.bullist, buttonHTML: '\uE009', excmd: 'insertUnorderedList', transform : { '':"[list]{SELTEXT}[/list]", '
  • {SELTEXT}
  • ':"[*]{SELTEXT}[/*]" } }, numlist : { title: CURLANG.numlist, buttonHTML: '\uE00a', excmd: 'insertOrderedList', transform : { '
      {SELTEXT}
    ':"[list=1]{SELTEXT}[/list]", '
  • {SELTEXT}
  • ':"[*]{SELTEXT}[/*]" } }, quote : { title: CURLANG.quote, buttonHTML: '\uE00c', hotkey: 'ctrl+shift+3', //subInsert: true, transform : { '
    {SELTEXT}
    ':"[quote]{SELTEXT}[/quote]" } }, code : { title: CURLANG.code, buttonText: '[code]', /* buttonHTML: '\uE00d', */ hotkey: 'ctrl+shift+4', onlyClearText: true, transform : { '{SELTEXT}':"[code]{SELTEXT}[/code]" } }, offtop : { title: CURLANG.offtop, buttonText: 'offtop', transform : { '{SELTEXT}':"[offtop]{SELTEXT}[/offtop]" } }, fontcolor: { type: "colorpicker", title: CURLANG.fontcolor, excmd: "foreColor", valueBBname: "color", subInsert: true, colors: "#000000,#444444,#666666,#999999,#b6b6b6,#cccccc,#d8d8d8,#efefef,#f4f4f4,#ffffff,-, \ #ff0000,#980000,#ff7700,#ffff00,#00ff00,#00ffff,#1e84cc,#0000ff,#9900ff,#ff00ff,-, \ #f4cccc,#dbb0a7,#fce5cd,#fff2cc,#d9ead3,#d0e0e3,#c9daf8,#cfe2f3,#d9d2e9,#ead1dc, \ #ea9999,#dd7e6b,#f9cb9c,#ffe599,#b6d7a8,#a2c4c9,#a4c2f4,#9fc5e8,#b4a7d6,#d5a6bd, \ #e06666,#cc4125,#f6b26b,#ffd966,#93c47d,#76a5af,#6d9eeb,#6fa8dc,#8e7cc3,#c27ba0, \ #cc0000,#a61c00,#e69138,#f1c232,#6aa84f,#45818e,#3c78d8,#3d85c6,#674ea7,#a64d79, \ #900000,#85200C,#B45F06,#BF9000,#38761D,#134F5C,#1155Cc,#0B5394,#351C75,#741B47, \ #660000,#5B0F00,#783F04,#7F6000,#274E13,#0C343D,#1C4587,#073763,#20124D,#4C1130", transform: { '{SELTEXT}':'[color={COLOR}]{SELTEXT}[/color]' } }, table: { type: "table", title: CURLANG.table, cols: 10, rows: 10, cellwidth: 20, transform: { '{SELTEXT}': '[td]{SELTEXT}[/td]', '{SELTEXT}': '[tr]{SELTEXT}[/tr]', '{SELTEXT}
    ': '[table]{SELTEXT}[/table]' }, skipRules: true }, fontsize: { type: 'select', title: CURLANG.fontsize, options: "fs_verysmall,fs_small,fs_normal,fs_big,fs_verybig" }, fontfamily: { type: 'select', title: CURLANG.fontfamily, excmd: 'fontName', valueBBname: "font", options: [ {title: "Arial",exvalue: "Arial"}, {title: "Comic Sans MS",exvalue: "Comic Sans MS"}, {title: "Courier New",exvalue: "Courier New"}, {title: "Georgia",exvalue: "Georgia"}, {title: "Lucida Sans Unicode",exvalue: "Lucida Sans Unicode"}, {title: "Tahoma",exvalue: "Tahoma"}, {title: "Times New Roman",exvalue: "Times New Roman"}, {title: "Trebuchet MS",exvalue: "Trebuchet MS"}, {title: "Verdana",exvalue: "Verdana"} ], transform: { '{SELTEXT}':'[font={FONT}]{SELTEXT}[/font]' } }, smilebox: { type: 'smilebox', title: CURLANG.smilebox, buttonHTML: '\uE00b' }, justifyleft: { title: CURLANG.justifyleft, buttonHTML: '\uE015', groupkey: 'align', transform: { '

    {SELTEXT}

    ': '[left]{SELTEXT}[/left]' } }, justifyright: { title: CURLANG.justifyright, buttonHTML: '\uE016', groupkey: 'align', transform: { '

    {SELTEXT}

    ': '[right]{SELTEXT}[/right]' } }, justifycenter: { title: CURLANG.justifycenter, buttonHTML: '\uE014', groupkey: 'align', transform: { '

    {SELTEXT}

    ': '[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 = $('
    ').appendTo(container).append(btnHTML).append(this.strf('{title}{hotkey}',{title:opt.title,hotkey:hotkey})); //attach events this.controllers.push($btn); $btn.bind('queryState',$.proxy(function(e) { (this.queryState(bn)) ? $(e.currentTarget).addClass("on"):$(e.currentTarget).removeClass("on"); },this)); $btn.mousedown($.proxy(function(e) { e.preventDefault(); this.execCommand(bn,opt.exvalue || false); $(e.currentTarget).trigger('queryState'); },this)); }, buildColorpicker: function(container,bn,opt) { var $btn = $('
    ').appendTo(container).append('
    \uE010
    \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]':''; for (var i=1; i<=rc[0]; i++) { code += (this.options.bbmode) ? ' [tr]\n':''; for (var j=1; j<=rc[1]; j++) { code += (this.options.bbmode) ? ' [td][/td]\n':''; } code += (this.options.bbmode) ? '[/tr]\n':''; } code += (this.options.bbmode) ? '[/table]':'
    \uFEFF
    '; this.insertAtCursor(code); },this)); //this.debug("END Attach event on: tbl-sel"); $btn.mousedown($.proxy(function(e) { e.preventDefault(); this.dropdownclick(".wbb-tbl",".wbb-list",e); },this)); }, buildSelect: function(container,bn,opt) { var $btn = $('
    ').appendTo(container).append(this.strf('{title}\uE012',opt)).append(this.strf('{title}',{title:opt.title})); var $sblock = $('
    ').appendTo($btn); var $sval = $btn.find("span.val"); var olist = ($.isArray(opt.options)) ? opt.options:opt.options.split(","); var $selectbox = (this.isMobile) ? $("
    ',inp)); } },this)); } },this)); //this.lastRange=this.getRange(); if ($.isFunction(opt.onLoad)) { opt.onLoad.call(this,cmd,opt,queryState); } $wbbm.find('#wbbm-submit').click($.proxy(function() { if ($.isFunction(opt.onSubmit)) { //custom submit function, if return false, then don't process our function var r = opt.onSubmit.call(this,cmd,opt,queryState); if (r===false) {return;} } var params={}; var valid=true; this.$modal.find(".wbbm-inperr").remove(); this.$modal.find(".wbbm-brdred").removeClass("wbbm-brdred"); //$.each(this.$modal.find(".tab-cont:visible input"),$.proxy(function(i,el) { $.each(this.$modal.find(".tab-cont:visible .inp-text"),$.proxy(function(i,el) { var tid = $(el).parents(".tab-cont").attr("tid"); var pname = $(el).attr("name").toLowerCase(); var pval=""; if ($(el).is("input,textrea,select")) { pval = $(el).val(); }else{ pval = $(el).html(); } var validation = opt.tabs[tid]["input"][i]["validation"]; if (typeof(validation)!="undefined") { if (!pval.match(new RegExp(validation,"i"))) { valid=false; $(el).after(''+CURLANG.validation_err+'').addClass("wbbm-brdred"); } } params[pname]=pval; },this)); if (valid) { $.log("Last range: "+this.lastRange); this.selectLastRange(); //insert callback if (queryState) { this.wbbRemoveCallback(cmd,true); } this.wbbInsertCallback(cmd,params); //END insert callback this.closeModal(); this.updateUI(); } },this)); $wbbm.find('#wbbm-remove').click($.proxy(function() { //clbk.remove(); this.selectLastRange(); this.wbbRemoveCallback(cmd); //remove callback this.closeModal(); this.updateUI(); },this)); $(document.body).css("overflow","hidden"); //lock the screen, remove scroll on body if ($("body").height() > $(window).height()) { //if body has scroll, add padding-right 18px $(document.body).css("padding-right","18px"); } this.$modal.show(); //if (window.getSelection) if (this.isMobile) { $wbbm.css("margin-top","10px"); }else{ $wbbm.css("margin-top",($(window).height()-$wbbm.outerHeight())/3+"px"); } //setTimeout($.proxy(function() {this.$modal.find("input:visible")[0].focus()},this),10); setTimeout($.proxy(function() {this.$modal.find(".inp-text:visible")[0].focus()},this),10); }, escModal: function(e) { if (e.which==27) {this.closeModal();} }, closeModal: function() { $(document.body).css("overflow","auto").css("padding-right","0").unbind("keyup",this.escModal); //ESC key close modal; this.$modal.find('#wbbm-submit,#wbbm-remove').unbind('click'); this.$modal.hide(); this.lastRange=false; return this; }, getParams: function(src,s,offset) { var params={}; if (this.options.bbmode) { //bbmode var stext = s.match(/\{[\s\S]+?\}/g); s = this.prepareRGX(s); var rgx = new RegExp(s,"g"); var val = this.txtArea.value; if (offset>0) { val = val.substr(offset,val.length-offset); } var a = rgx.exec(val); if (a) { $.each(stext,function(i,n) { params[n.replace(/\{|\}/g,"").replace(/"/g,"'").toLowerCase()] = a[i+1]; }); } }else{ var rules = this.options.rules[s][0][1]; $.each(rules,$.proxy(function(k,v) { var value=""; var $v = (v.sel!==false) ? value=$(src).find(v.sel):$(src); if (v.attr!==false) { value=$v.attr(v.attr); }else{ value=$v.html(); } if (value) { if (v.rgx!==false) { var m = value.match(new RegExp(v.rgx)); if (m && m.length==2) { value = m[1]; } } params[k]=value.replace(/"/g,"'"); } },this)) } return params; }, //imgUploader imgLoadModal: function() { $.log("imgLoadModal"); if (this.options.imgupload===true) { this.$modal.find("#imguploader").dragfileupload({ url: this.strf(this.options.img_uploadurl,this.options), extraParams: { maxwidth: this.options.img_maxwidth, maxheight: this.options.img_maxheight }, themePrefix: this.options.themePrefix, themeName: this.options.themeName, success: $.proxy(function(data) { this.$txtArea.insertImage(data.image_link,data.thumb_link); this.closeModal(); this.updateUI(); },this) }); this.$modal.find("#fileupl").bind("change",function() { $("#fupform").submit(); }); this.$modal.find("#fupform").bind("submit",$.proxy(function(e) { $(e.target).parents("#imguploader").hide().after('

    '+CURLANG.loading+'
    ').parent().css("text-align","center"); },this)) }else{ this.$modal.find(".hastabs").removeClass("hastabs"); this.$modal.find("#imguploader").parents(".tab-cont").remove(); this.$modal.find(".wbbm-tablist").remove(); } }, imgSubmitModal: function() { $.log("imgSubmitModal"); }, //DEBUG printObjectInIE: function(obj) { try{ $.log(JSON.stringify(obj)); }catch(e) {} }, checkFilter: function(node,filter) { $.log("node: "+$(node).get(0).outerHTML+" filter: "+filter+" res: "+$(node).is(filter.toLowerCase())); }, debug: function(msg) { if (this.options.debug===true) { var time = (new Date()).getTime(); if (typeof(console)!="undefined") { console.log((time-this.startTime)+" ms: "+msg); }else{ $("#exlog").append('

    '+(time-this.startTime)+" ms: "+msg+'

    '); } this.startTime=time; } }, //Browser fixes isChrome: function() { return (window.chrome) ? true:false; }, fixTableTransform: function(html) { if (!html) {return "";} if ($.inArray("table",this.options.buttons)==-1) { return html.replace(/\<(\/*?(table|tr|td|tbody))[^>]*\>/ig,""); }else{ return html.replace(/\<(\/*?(table|tr|td))[^>]*\>/ig,"[$1]".toLowerCase()).replace(/\<\/*tbody[^>]*\>/ig,""); } } } $.log = function(msg) { if (typeof(wbbdebug)!="undefined" && wbbdebug===true) { if (typeof(console)!="undefined") { console.log(msg); }else{ $("#exlog").append('

    '+msg+'

    '); } } } $.fn.wysibb = function(settings) { return this.each(function() { var data = $(this).data("wbb"); if (!data) { new $.wysibb(this, settings); } }); } $.fn.wdrag = function(opt) { if (!opt.scope) {opt.scope=this;} var start={x:0,y:0, height: 0}; var drag; opt.scope.drag_mousedown = function(e) { e.preventDefault(); start = { x: e.pageX, y: e.pageY, height: opt.height, sheight: opt.scope.$body.height() } drag=true; $(document).bind("mousemove",$.proxy(opt.scope.drag_mousemove,this)); $(this).addClass("drag"); }; opt.scope.drag_mouseup = function(e) { if (drag===true) { e.preventDefault(); $(document).unbind("mousemove",opt.scope.drag_mousemove); $(this).removeClass("drag"); drag=false; } }; opt.scope.drag_mousemove = function(e) { e.preventDefault(); var axisX=0,axisY=0; if (opt.axisX) { axisX = e.pageX-start.x; } if (opt.axisY) { axisY = e.pageY-start.y; } if (axisY!=0) { var nheight = start.sheight+axisY; if (nheight>start.height && nheight<=opt.scope.options.resize_maxheight) { if (opt.scope.options.bbmode==true) { opt.scope.$txtArea.css((opt.scope.options.autoresize===true) ? "min-height":"height",nheight+"px"); }else{ opt.scope.$body.css((opt.scope.options.autoresize===true) ? "min-height":"height",nheight+"px"); } } } }; $(this).bind("mousedown",opt.scope.drag_mousedown); $(document).bind("mouseup",$.proxy(opt.scope.drag_mouseup,this)); }, //API $.fn.getDoc = function() { return this.data('wbb').doc; } $.fn.getSelectText = function(fromTextArea) { return this.data('wbb').getSelectText(fromTextArea); } $.fn.bbcode = function(data) { if (typeof(data)!="undefined") { if (this.data('wbb').options.bbmode) { this.data('wbb').$txtArea.val(data); }else{ this.data('wbb').$body.html(this.data("wbb").getHTML(data)); } return this; }else{ return this.data('wbb').getBBCode(); } } $.fn.htmlcode = function(data) { if (!this.data('wbb').options.onlyBBMode && this.data('wbb').inited===true) { if (typeof(data)!="undefined") { this.data('wbb').$body.html(data); return this; }else{ return this.data('wbb').getHTML(this.data('wbb').$txtArea.val()); } } } $.fn.getBBCode = function() { return this.data('wbb').getBBCode(); } $.fn.getHTML = function() { var wbb = this.data('wbb'); return wbb.getHTML(wbb.$txtArea.val()); } $.fn.getHTMLByCommand = function(command,params) { return this.data("wbb").getHTMLByCommand(command,params); } $.fn.getBBCodeByCommand = function(command,params) { return this.data("wbb").getBBCodeByCommand(command,params); } $.fn.insertAtCursor = function(data,forceBBMode) { this.data("wbb").insertAtCursor(data,forceBBMode); return this.data("wbb"); } $.fn.execCommand = function(command,value) { this.data("wbb").execCommand(command,value); return this.data("wbb"); } $.fn.insertImage = function(imgurl,thumburl) { var editor = this.data("wbb"); var code = (thumburl) ? editor.getCodeByCommand('link',{url:imgurl,seltext: editor.getCodeByCommand('img',{src:thumburl})}): editor.getCodeByCommand('img',{src:imgurl}); this.insertAtCursor(code); return editor; } $.fn.sync = function() { this.data("wbb").sync(); return this.data("wbb"); } $.fn.destroy = function() { this.data("wbb").destroy(); } $.fn.queryState = function(command) { return this.data("wbb").queryState(command); } })(jQuery); //Drag&Drop file uploader (function($) { 'use strict'; $.fn.dragfileupload = function(options) { return this.each(function() { var upl = new FileUpload(this, options); upl.init(); }); }; function FileUpload(e, options) { this.$block=$(e); this.opt = $.extend({ url: false, success: false, extraParams: false, fileParam: 'img', validation: '\.(jpg|png|gif|jpeg)$', t1: CURLANG.fileupload_text1, t2: CURLANG.fileupload_text2 },options); } FileUpload.prototype = { init: function() { if (window.FormData != null) { this.$block.addClass("drag"); this.$block.prepend('
    '+this.opt.t2+'
    '); this.$block.prepend('
    '+this.opt.t1+'
    '); this.$block.bind('dragover', function() {$(this).addClass('dragover');return false;}); this.$block.bind('dragleave', function() {$(this).removeClass('dragover');return false;}); //upload progress var uploadProgress = $.proxy(function(e) { var p = parseInt(e.loaded/e.total*100, 10); this.$loader.children("span").text(CURLANG.loading+': '+ p+'%'); }, this); var xhr = jQuery.ajaxSettings.xhr(); if (xhr.upload) { xhr.upload.addEventListener('progress', uploadProgress, false); } this.$block[0].ondrop = $.proxy(function(e) { e.preventDefault(); this.$block.removeClass('dragover'); var ufile = e.dataTransfer.files[0]; if (this.opt.validation && !ufile.name.match(new RegExp(this.opt.validation))) { this.error(CURLANG.validation_err); return false; } var fData = new FormData(); fData.append(this.opt.fileParam, ufile); if (this.opt.extraParams) { //check for extraParams to upload $.each(this.opt.extraParams,function(k,v) { fData.append(k, v); }); } this.$loader = $('

    '+CURLANG.loading+'
    '); this.$block.html(this.$loader); $.ajax({ type: 'POST', url: this.opt.url, data: fData, processData: false, contentType: false, xhr: function() {return xhr}, dataType: 'json', success: $.proxy(function(data) { if (data && data.status==1) { this.opt.success(data); }else{ this.error(data.msg || CURLANG.error_onupload); } },this), error: $.proxy(function (xhr, txt, thr) {this.error(CURLANG.error_onupload)},this) }); },this); } }, error: function(msg) { this.$block.find(".upl-error").remove().end().append(''+msg+'').addClass("wbbm-brdred"); } } })(jQuery);