/**
* Simple Machines Forum (SMF)
*
* @package SMF
* @author Simple Machines https://www.simplemachines.org
* @copyright 2022 Simple Machines and individual contributors
* @license https://www.simplemachines.org/about/smf/license.php BSD
*
* @version 2.1.0
*/
(function ($) {
var extensionMethods = {
insertQuoteFast: function (messageid)
{
var self = this;
getXMLDocument(
smf_prepareScriptUrl(smf_scripturl) + 'action=quotefast;quote=' + messageid + ';xml',
function(XMLDoc)
{
var text = '';
for (var i = 0, n = XMLDoc.getElementsByTagName('quote')[0].childNodes.length; i < n; i++)
text += XMLDoc.getElementsByTagName('quote')[0].childNodes[i].nodeValue;
self.insert(text);
// Manually move cursor to after the quote.
var
rangeHelper = self.getRangeHelper(),
parent = rangeHelper.parentNode();
if (parent && parent.nodeName === 'BLOCKQUOTE')
{
var range = rangeHelper.selectedRange();
range.setStartAfter(parent);
rangeHelper.selectRange(range);
}
ajax_indicator(false);
}
);
},
InsertText: function (text, bClear) {
if (bClear)
this.val('');
this.insert(text);
},
getText: function (filter) {
var current_value = '';
if (this.inSourceMode())
current_value = this.getSourceEditorValue(false);
else
current_value = this.getWysiwygEditorValue(filter);
return current_value;
},
appendEmoticon: function (code, emoticon, description) {
if (emoticon == '')
line.append($('
'));
else
line.append($('')
.attr({
src: emoticon,
alt: code,
title: description,
})
.click(function (e) {
var start = '', end = '';
if (base.opts.emoticonsCompat)
{
start = ' ';
end = ' ';
}
if (base.inSourceMode())
base.sourceEditorInsertText(' ' + $(this).attr('alt') + ' ');
else
base.wysiwygEditorInsertHtml(start + '' + end);
e.preventDefault();
})
);
},
storeLastState: function (){
this.wasSource = this.inSourceMode();
},
setTextMode: function () {
if (!this.inSourceMode())
this.toggleSourceMode();
},
createPermanentDropDown: function () {
var emoticons = $.extend({}, this.opts.emoticons.dropdown);
var popup_exists = false;
content = $('
', ''); } } ); sceditor.command.set( 'link', { exec: function (caller) { var editor = this; editor.commands.link._dropDown(editor, caller, function (url, text) { if (!editor.getRangeHelper().selectedHtml() || text) { text = text || url; editor.wysiwygEditorInsertHtml( '' + sceditor.escapeEntities(text, true) + '' ); } else { // Can't just use `editor.execCommand('createlink', url)` // because we need to set a custom attribute. editor.wysiwygEditorInsertHtml( '', '' ); } }); } } ); sceditor.command.set( 'bulletlist', { txtExec: function (caller, selected) { if (selected) this.insertText( '[list]\n[li]' + selected.split(/\r?\n/).join('[/li]\n[li]') + '[/li]\n[/list]' ); else this.insertText('[list]\n[li]', '[/li]\n[li][/li]\n[/list]'); } } ); sceditor.command.set( 'orderedlist', { txtExec: function (caller, selected) { if (selected) this.insertText( '[list type=decimal]\n[li]' + selected.split(/\r?\n/).join('[/li]\n[li]') + '[/li]\n[/list]' ); else this.insertText('[list type=decimal]\n[li]', '[/li]\n[li][/li]\n[/list]'); } } ); sceditor.command.set( 'table', { txtExec: ["[table]\n[tr]\n[td]", "[/td]\n[/tr]\n[/table]"] } ); sceditor.command.set( 'floatleft', { txtExec: ["[float=left max=45%]", "[/float]"], exec: function () { this.wysiwygEditorInsertHtml('
{0}\n" } ); sceditor.formats.bbcode.set( 'php', { isInline: false, format: "[php]{0}[/php]", html: '
{0}
'
}
);
sceditor.formats.bbcode.set(
'code', {
tags: {
code: null
},
isInline: false,
allowedChildren: ['#', '#newline'],
format: function (element, content) {
if ($(element).hasClass('php'))
return '[php]' + content.replace('[', '[') + '[/php]';
var
dom = sceditor.dom,
attr = dom.attr,
title = attr(element, 'data-title'),
from = title ?' =' + title : '';
return '[code' + from + ']' + content.replace('[', '[') + '[/code]';
},
html: function (element, attrs, content) {
var from = attrs.defaultattr ? ' data-title="' + attrs.defaultattr + '"' : '';
return '' + content.replace('[', '[') + '
'
}
}
);
sceditor.formats.bbcode.set(
'quote', {
tags: {
blockquote: null,
cite: null
},
quoteType: sceditor.BBCodeParser.QuoteType.never,
breakBefore: false,
isInline: false,
format: function (element, content)
{
var attrs = '';
var author = element.getAttribute('data-author');
var date = element.getAttribute('data-date');
var link = element.getAttribute('data-link');
// The contains only the graphic for the quote, so we can skip it
if (element.tagName === 'CITE')
return '';
if (author)
attrs += ' author=' + author.php_unhtmlspecialchars();
if (link)
attrs += ' link=' + link;
if (date)
attrs += ' date=' + date;
return '[quote' + attrs + ']' + content + '[/quote]';
},
html: function (element, attrs, content)
{
var attr_author = '', author = '';
var attr_date = '', sDate = '';
var attr_link = '', link = '';
if (attrs.author || attrs.defaultattr)
{
attr_author = attrs.author || attrs.defaultattr;
author = bbc_quote_from + ': ' + attr_author;
}
if (attrs.link)
{
attr_link = attrs.link;
link = attr_link.substr(0, 7) == 'http://' ? attr_link : smf_prepareScriptUrl(smf_scripturl) + attr_link;
author = '' + (author || bbc_quote_from + ': ' + link) + '';
}
if (attrs.date)
{
attr_date = attrs.date;
sDate = '' + (author || bbc_quote) + ' ' + sDate + '' + content + ''; } } ); sceditor.formats.bbcode.set( 'font', { format: function (element, content) { var element = $(element); var font; // Get the raw font value from the DOM if (!element.is('font') || !(font = element.attr('face'))) { font = element.css('font-family'); } // Strip all quotes font = font.replace(/['"]/g, ''); return '[font=' + font + ']' + content + '[/font]'; } } ); sceditor.formats.bbcode.set( 'member', { isInline: true, tags: { a: { 'data-mention': null } }, format: function (element, content) { return '[member='+ $(element).attr('data-mention') +']'+ content.replace('@','') +'[/member]'; }, html: function (token, attrs, content) { if (typeof attrs.defaultattr === "undefined" || attrs.defaultattr.length === 0) attrs.defaultattr = content; return '@'+ content.replace('@','') +''; } } ); sceditor.formats.bbcode.set( 'float', { tags: { div: { "class": ["floatleft", "floatright"], }, }, isInline: false, skipLastLineBreak: true, format: function (element, content) { var element = $(element); if (!element.css('float')) return content; side = (element[0].className == 'floatleft' ? 'left' : 'right'); max = ' max=' + (element.css('max-width') != "none" ? element.css('max-width') : '45%'); return '[float=' + side + max + ']' + content + '[/float]'; }, html: function (token, attrs, content) { if (typeof attrs.defaultattr === "undefined") return content; floatclass = attrs.defaultattr.indexOf('left') == 0 ? 'floatleft' : 'floatright'; style = typeof attrs.max !== "undefined" ? ' style="max-width:' + attrs.max + (+attrs.max === parseInt(attrs.max) ? 'px' : '') + ';"' : ''; return '