';
},
isInline: false
});
$.each(mybbCmd.align, function (i, val) {
$.sceditor.formats.bbcode.set(val, {
format: '[align=' + val + ']{0}[/align]'
});
$.sceditor.command
.set(val, {
txtExec: ['[align=' + val + ']', '[/align]']
});
});
// Update font to support MyBB's BBCode dialect
$.sceditor.formats.bbcode
.set('list', {
html: function (element, attrs, content) {
var type = (attrs.defaultattr === '1' ? 'ol' : 'ul');
if (attrs.defaultattr === 'a')
type = 'ol type="a"';
return '<' + type + '>' + content + '' + type + '>';
},
isInline: false,
skipLastLineBreak: true,
breakStart: true,
breakAfter: true,
})
.set('ul', {
format: '[list]{0}[/list]',
isInline: false,
skipLastLineBreak: true,
breakStart: true,
breakAfter: true,
})
.set('ol', {
format: function ($elm, content) {
var type = ($($elm).attr('type') === 'a' ? 'a' : '1');
return '[list=' + type + ']' + content + '[/list]';
},
isInline: false,
skipLastLineBreak: true,
breakStart: true,
breakAfter: true,
})
.set('li', {
format: '[*]{0}',
isInline: false,
skipLastLineBreak: true,
})
.set('*', {
html: '
{0}
',
isInline: false,
excludeClosing: true,
skipLastLineBreak: true,
breakAfter: false,
});
$.sceditor.command
.set('bulletlist', {
txtExec: function (caller, selected) {
var content = '';
$.each(selected.split(/\r?\n/), function () {
content += (content ? '\n' : '') +
'[*]' + this;
});
this.insertText('[list]\n' + content + '\n[/list]');
}
})
.set('orderedlist', {
txtExec: function (caller, selected) {
var content = '';
$.each(selected.split(/\r?\n/), function () {
content += (content ? '\n' : '') +
'[*]' + this;
});
this.insertText('[list=1]\n' + content + '\n[/list]');
}
});
// Update size tag to use xx-small-xx-large instead of 1-7
$.sceditor.formats.bbcode.set('size', {
format: function ($elm, content) {
var fontsize = 1,
scefontsize = $($elm).data('scefontsize'),
parsed = parseInt(scefontsize, 10),
size = parseInt($($elm).attr('size'), 10),
iframe = $('.sceditor-container iframe'),
editor_body = $('body', iframe.contents());
if ($($elm).css('font-size') == editor_body.css('font-size')) {
// Eliminate redundant [size] tags for unformatted text.
// Part of the fix for the browser-dependent bug of issue #4184.
// Also fixes the browser-dependent bug described here:
//
fontsize = -1;
} else if (!isNaN(size) && size >= 1 && size <= mybbCmd.fsStr.length) {
fontsize = mybbCmd.fsStr[size - 1];
} else if ($.inArray(scefontsize, mybbCmd.fsStr) !== -1) {
fontsize = scefontsize;
} else if (!isNaN(parsed)) {
fontsize = parsed;
}
return fontsize != -1 ? '[size=' + fontsize + ']' + content + '[/size]' : content;
},
html: function (token, attrs, content) {
var size = 0,
units = "",
parsed = parseInt(attrs.defaultattr, 10);
if (!isNaN(parsed)) {
size = parsed;
if (size < 1) {
size = 1;
} else if (size > 50) {
size = 50;
}
units = "pt";
} else {
var fsStrPos = $.inArray(attrs.defaultattr, mybbCmd.fsStr);
if (fsStrPos !== -1) {
size = attrs.defaultattr;
}
}
return '' + content + '';
}
});
$.sceditor.command.set('size', {
_dropDown: function (editor, caller, callback) {
var content = $(''),
clickFunc = function (e) {
callback($(this).data('size'));
editor.closeDropDown(true);
e.preventDefault();
};
for (var i = 1; i <= 7; i++)
content.append($('' + i + '').on('click', clickFunc));
editor.createDropDown(caller, 'fontsize-picker', content.get(0));
},
exec: function (caller) {
var editor = this;
$.sceditor.command.get('size')._dropDown(
editor,
caller,
function (fontSize) {
editor.execCommand('fontsize', fontSize);
}
);
},
txtExec: function (caller) {
var editor = this;
$.sceditor.command.get('size')._dropDown(
editor,
caller,
function (size) {
size = (~~size);
size = (size > 7) ? 7 : ((size < 1) ? 1 : size);
editor.insertText('[size=' + mybbCmd.fsStr[size - 1] + ']', '[/size]');
}
);
}
});
// Update quote to support pid and dateline
$.sceditor.formats.bbcode.set('quote', {
format: function (element, content) {
var author = '',
$elm = $(element),
$cite = $elm.children('cite').first();
if ($cite.length === 1 || $elm.data('author')) {
author = $cite.text() || $elm.data('author');
$elm.data('author', author);
$cite.remove();
content = this.elementToBbcode(element);
author = '=' + author.replace(/(^\s+|\s+$)/g, '');
$elm.prepend($cite);
}
if ($elm.data('pid'))
author += " pid='" + $elm.data('pid') + "'";
if ($elm.data('dateline'))
author += " dateline='" + $elm.data('dateline') + "'";
return '[quote' + author + ']' + content + '[/quote]';
},
html: function (token, attrs, content) {
var data = '';
if (attrs.pid)
data += ' data-pid="' + $.sceditor.escapeEntities(attrs.pid) + '"';
if (attrs.dateline)
data += ' data-dateline="' + $.sceditor.escapeEntities(attrs.dateline) + '"';
if (typeof attrs.defaultattr !== "undefined")
content = '' + $.sceditor.escapeEntities(attrs.defaultattr).replace(/ /g, ' ') + '' + content;
return '
' + content + '
';
},
quoteType: function (val, name) {
var quoteChar = val.indexOf('"') !== -1 ? "'" : '"';
return quoteChar + val + quoteChar;
},
breakStart: true,
breakEnd: true
});
// Update font tag to allow limiting to only first in stack
$.sceditor.formats.bbcode.set('font', {
format: function (element, content) {
var font;
if (element.nodeName.toLowerCase() !== 'font' || !(font = $(element).attr('face')))
font = $(element).css('font-family');
var iframe = $('.sceditor-container iframe');
var editor_body = $('body', iframe.contents());
if (typeof font == 'string' && font != '' && font != 'defaultattr'
&&
// Eliminate redundant [font] tags for unformatted text.
// Part of the fix for the browser-dependent bug of issue #4184.
font != editor_body.css('font-family')) {
font = font.trim();
// Strip all-enclosing double quotes from fonts so long as
// they are the only double quotes present...
if (font[0] == '"' && font[font.length-1] == '"' && (font.match(/"/g) || []).length == 2) {
font = font.substr(1, font.length-2);
}
// ...and then replace any other occurrence(s) of double quotes
// in fonts with single quotes.
// This is the client-side aspect of the fix for
// the browser-independent bug of issue #4182.
font = font.replace(/"/g, "'");
return '[font=' + font + ']' + content + '[/font]';
} else {
return content;
}
},
html: function (token, attrs, content) {
if (typeof attrs.defaultattr == 'string' && attrs.defaultattr != '' && attrs.defaultattr != '{defaultattr}') {
return '' + content + '';
} else {
return content;
}
}
});
$.sceditor.formats.bbcode.set('color', {
format: function (element, content) {
var color, defaultColor;
var iframe = $('.sceditor-container iframe');
var editor_body = $('body', iframe.contents());
if (element.nodeName.toLowerCase() != 'font' || !(color = $(element).attr('color'))) {
color = $(element).css('color');
}
color = _normaliseColour(color);
defaultColor = _normaliseColour(editor_body.css('color'));
// Eliminate redundant [color] tags for unformatted text.
// Part of the fix for the browser-dependent bug of issue #4184.
return color != defaultColor
? '[color=' + color + ']' + content + '[/color]'
: content;
},
html: function (token, attrs, content) {
return '' + content + '';
}
});
// Add MyBB PHP command
$.sceditor.formats.bbcode.set('php', {
allowsEmpty: true,
isInline: false,
allowedChildren: ['#', '#newline'],
format: '[php]{0}[/php]',
html: '{0}'
});
$.sceditor.command.set("php", {
_dropDown: function (editor, caller) {
var $content;
$content = $(
'
' +
'
' +
' ' +
'' +
'
' +
'' +
'
'
);
setTimeout(function () {
$content.find('#php').trigger('focus');
}, 100);
$content.find('.button').on('click', function (e) {
var val = $content.find('#php').val(),
before = '[php]',
end = '[/php]';
if (val) {
before = before + val + end;
end = null;
}
editor.insert(before, end);
editor.closeDropDown(true);
e.preventDefault();
});
editor.createDropDown(caller, 'insertphp', $content.get(0));
},
exec: function (caller) {
if ($.trim(this.getRangeHelper().selectedRange())) {
this.insert('[php]', '[/php]');
return;
}
$.sceditor.command.get('php')._dropDown(this, caller);
},
txtExec: ['[php]', '[/php]'],
tooltip: "PHP"
});
// Update code to support PHP
$.sceditor.formats.bbcode.set('code', {
allowsEmpty: true,
tags: {
code: null
},
isInline: false,
allowedChildren: ['#', '#newline'],
format: function (element, content) {
if ($(element).hasClass('phpcodeblock')) {
return '[php]' + content + '[/php]';
}
return '[code]' + content + '[/code]';
},
html: '{0}'
});
$.sceditor.command.set("code", {
_dropDown: function (editor, caller) {
var $content;
$content = $(
'
' +
'
' +
' ' +
'' +
'
' +
'' +
'
'
);
setTimeout(function () {
$content.find('#code').trigger('focus');
}, 100);
$content.find('.button').on('click', function (e) {
var val = $content.find('#code').val(),
before = '[code]',
end = '[/code]';
if (val) {
before = before + val + end;
end = null;
}
editor.insert(before, end);
editor.closeDropDown(true);
e.preventDefault();
});
editor.createDropDown(caller, 'insertcode', $content.get(0));
},
exec: function (caller) {
if ($.trim(this.getRangeHelper().selectedRange())) {
this.insert('[code]', '[/code]');
return;
}
$.sceditor.command.get('code')._dropDown(this, caller);
},
txtExec: ['[code]', '[/code]'],
});
// Update email to support description
$.sceditor.command.set('email', {
_dropDown: function (editor, caller) {
var $content;
$content = $(
'
' +
'
' +
' ' +
'' +
'
' +
'
' +
' ' +
'' +
'
' +
'' +
'
'
);
$content.find('.button').on('click', function (e) {
var val = $content.find('#email').val(),
description = $content.find('#des').val();
if (val) {
// needed for IE to reset the last range
$(editor).trigger('focus');
if (!editor.getRangeHelper().selectedHtml() || description) {
if (!description)
description = val;
editor.insert('[email=' + val + ']' + description + '[/email]');
} else
editor.execCommand('createlink', 'mailto:' + val);
}
editor.closeDropDown(true);
e.preventDefault();
});
editor.createDropDown(caller, 'insertemail', $content.get(0));
},
exec: function (caller) {
$.sceditor.command.get('email')._dropDown(this, caller);
}
});
// Add MyBB video command
$.sceditor.formats.bbcode.set('video', {
allowsEmpty: true,
allowedChildren: ['#', '#newline'],
tags: {
iframe: {
'data-mybb-vt': null
}
},
format: function ($element, content) {
return '[video=' + $($element).data('mybb-vt') + ']' + $($element).data('mybb-vsrc') + '[/video]';
},
html: function (token, attrs, content) {
var params = mybbCmd.video[Object.keys(mybbCmd.video).find(key => key.toLowerCase() === attrs.defaultattr)];
var matches, url;
var n = (attrs.defaultattr == 'dailymotion') ? 2 : 1;
if (typeof params !== "undefined") {
matches = content.match(params['match']);
url = matches ? params['url'] + matches[n] : false;
}
if (url) {
return params['html'].replace('{url}', url).replace('{src}', content).replace('{type}', attrs.defaultattr);
}
return $.sceditor.escapeEntities(token.val + content + (token.closing ? token.closing.val : ''));
}
});
$.sceditor.command.set('video', {
_dropDown: function (editor, caller) {
var $content, videourl, videotype, videoOpts;
$.each(mybbCmd.video, function (provider, data) {
videoOpts += '';
});
$content = $(
'