// BBCode control function BBCode(obj) { textarea = document.getElementById(obj); this.construct(textarea); } BBCode.prototype = { VK_TAB: 9, VK_ENTER: 13, VK_PAGE_UP: 33, BRK_OP: '[', BRK_CL: ']', textarea: null, stext: '', quoter: null, qouted_pid: null, collapseAfterInsert: false, replaceOnInsert: false, // Create new BBCode control construct: function(textarea) { this.textarea = textarea; this.tags = new Object(); // Tag for quoting this.addTag( '_quoter', function() { return '[quote="'+th.quoter+'"][qpost='+th.qouted_pid+']' }, '[/quote]\n', null, null, function() { th.collapseAfterInsert=true; return th._prepareMultiline(th.quoterText) } ); // Init events var th = this; addEvent(textarea, 'keydown', function(e) { return th.onKeyPress(e, window.HTMLElement? 'down' : 'press') }); addEvent(textarea, 'keypress', function(e) { return th.onKeyPress(e, 'press') }); }, // Insert poster name or poster quotes to the text onclickPoster: function(name, post_id) { var sel = this.getSelection()[0]; if (sel) { this.quoter = name; this.qouted_pid = post_id; this.quoterText = sel; this.insertTag('_quoter'); } else { this.insertAtCursor("[b]" + name + '[/b], '); } return false; }, // Quote selected text onclickQuoteSel: function() { var sel = this.getSelection()[0]; if (sel) { this.insertAtCursor('[quote]' + sel + '[/quote]\n'); } else { alert('Вы не выбрали текст'); } return false; }, // Quote selected text emoticon: function(em) { if (em) { this.insertAtCursor(' ' + em + ' '); } else { return false; } return false; }, // Return current selection and range (if exists) getSelection: function() { var w = window; var text='', range; if (w.getSelection) { text = w.getSelection(); } else { return [null, null]; } if (text == '') text = this.stext; text = ""+text; text = text.replace("/^\s+|\s+$/g", ""); return [text, range]; }, // Insert string at cursor position of textarea insertAtCursor: function(text) { // Focus is placed to textarea var t = this.textarea; t.focus(); // Insert the string if (document.selection && document.selection.createRange) { var r = document.selection.createRange(); if (!this.replaceOnInsert) r.collapse(); r.text = text; } else if (t.setSelectionRange) { var start = this.replaceOnInsert? t.selectionStart : t.selectionEnd; var end = t.selectionEnd; var sel1 = t.value.substr(0, start); var sel2 = t.value.substr(end); t.value = sel1 + text + sel2; t.setSelectionRange(start+text.length, start+text.length); } else{ t.value += text; } // For IE setTimeout(function() { t.focus() }, 100); }, // Surround piece of textarea text with tags surround: function(open, close, fTrans) { var t = this.textarea; t.focus(); if (!fTrans) fTrans = function(t) { return t; }; var rt = this.getSelection(); var text = rt[0]; var range = rt[1]; if (text == null) return false; var notEmpty = text != null && text != ''; // Surround if (range) { var notEmpty = text != null && text != ''; var newText = open + fTrans(text) + (close? close : ''); range.text = newText; range.collapse(); if (text != '') { // Correction for stupid IE: \r for moveStart is 0 character var delta = 0; for (var i=0; i= 0) text = "\n" + text + "\n"; return text; } }; // Emulation of innerText for Mozilla. if (window.HTMLElement && window.HTMLElement.prototype.__defineSetter__) { HTMLElement.prototype.__defineSetter__("innerText", function (sText) { this.innerHTML = sText.replace(/\&/g, "&").replace(//g, ">"); }); HTMLElement.prototype.__defineGetter__("innerText", function () { var r = this.ownerDocument.createRange(); r.selectNodeContents(this); return r.toString(); }); } function AddSelectedText(BBOpen, BBClose) { if (document.post.message.caretPos) document.post.message.caretPos.text = BBOpen + document.post.message.caretPos.text + BBClose; else document.post.message.value += BBOpen + BBClose; document.post.message.focus() } function InsertBBCode(BBcode) { AddSelectedText('[' + BBcode + ']','[/' + BBcode + ']'); } function storeCaret(textEl) { if (textEl.createTextRange) textEl.caretPos = document.selection.createRange().duplicate(); } function initPostBBCode(context) { $('span.post-hr', context).html('
'); initCodes(context); initQuotes(context); initExternalLinks(context); initPostImages(context); initSpoilers(context); initMedia(context); } function initCodes(context) { $('div.c-body', context).each(function(){ var $c = $(this); $c.before('
'+bbl['code']+':
'); }); } function initQuotes(context) { $('div.q', context).each(function(){ var $q = $(this); var name = $(this).attr('head'); var q_title = (name ? ''+name+' '+bbl['wrote']+':' : ''+bbl['quote']+''); if ( quoted_pid = $q.children('u.q-post:first').text() ) { var on_this_page = $('#post_'+quoted_pid).length; var href = (on_this_page) ? '#'+ quoted_pid : './viewtopic.php?p='+ quoted_pid +'#'+ quoted_pid; q_title += ' '; } $q.before('
'+ q_title +'
'); }); } function initPostImages(context) { if (hidePostImg) return; var $in_spoilers = $('div.sp-body var.postImg', context); $('var.postImg', context).not($in_spoilers).each(function(){ var $v = $(this); var src = $v.attr('title'); var $img = $('pic'); $img = fixPostImage($img); var maxW = ($v.hasClass('postImgAligned')) ? postImgAligned_MaxWidth : postImg_MaxWidth; $img.bind('click', function(){ return imgFit(this, maxW); }); if (user.opt_js.i_aft_l) { $('#preload').append($img); var loading_icon = ''; $v.html(loading_icon); if ($.browser.msie) { $v.after(''); } $img.one('load', function(){ imgFit(this, maxW); $v.empty().append(this); }); } else { $img.one('load', function(){ imgFit(this, maxW) }); $v.empty().append($img); if ($.browser.msie) { $v.after(''); } } }); } function initSpoilers(context) { $('div.sp-body', context).each(function(){ var $sp_body = $(this); var name = $.trim(this.title) || ''+bbl['spoiler_head']+''; this.title = ''; var $sp_head = $('
'+ name +'
'); $sp_head.insertBefore($sp_body).click(function(e){ if (!$sp_body.hasClass('inited')) { initPostImages($sp_body); var $sp_fold_btn = $('
['+bbl['spoiler_close']+']
').click(function(){ $.scrollTo($sp_head, { duration:200, axis:'y', offset:-200 }); $sp_head.click().animate({opacity: 0.1}, 500).animate({opacity: 1}, 700); }); $sp_body.prepend('
').append('
').append($sp_fold_btn).addClass('inited'); } if (e.shiftKey) { e.stopPropagation(); e.shiftKey = false; var fold = $(this).hasClass('unfolded'); $('div.sp-head', $($sp_body.parents('td')[0])).filter( function(){ return $(this).hasClass('unfolded') ? fold : !fold } ).click(); } else { $(this).toggleClass('unfolded'); $sp_body.slideToggle('fast'); } }); }); } function initExternalLinks(context) { var context = context || 'body'; if (ExternalLinks_InNewWindow) { $("a.postLink:not([href*='"+ window.location.hostname +"/'])", context).attr({ target: '_blank' }); } } function fixPostImage ($img) { var banned_image_hosts = /imagebanana|hidebehind/i; var src = $img[0].src; if (src.match(banned_image_hosts)) { $img.wrap('').attr({ src: ""+bb_url+"styles/images/smiles/tr_oops.gif", title: ""+bbl['scr_rules']+"" }); } return $img; } function initMedia(context) { var apostLink = $('a.postLink', context); for (var i = 0; i < apostLink.length; i++) { var link = apostLink[i]; if (typeof link.href != 'string') { continue; } if (/^http(?:s|):\/\/www.youtube.com\/watch\?(.*)?(&?v=([a-z0-9\-_]+))(.*)?|http:\/\/youtu.be\/.+/i.test(link.href)) { var a = document.createElement('span'); a.className = 'YTLink'; a.innerHTML = ''; window.addEvent(a, 'click', function (e) { var vhref = e.target.nextSibling.href.replace(/^http(?:s|):\/\/www.youtube.com\/watch\?(.*)?(&?v=([a-z0-9\-_]+))(.*)?|http:\/\/youtu.be\//ig, "https://www.youtube.com/embed/$3"); var text = e.target.nextSibling.innerText != "" ? e.target.nextSibling.innerText : e.target.nextSibling.href; $('#Panel_youtube').remove(); ypanel('youtube', { title: '' + text + '', resizing: 0, width: 862, height: 550, content: '' }); }); link.parentNode.insertBefore(a, link); a.appendChild(link); } } } $(document).ready(function(){ $('div.post_wrap, div.signature').each(function(){ initPostBBCode( $(this) ) }); });