'wcf.editor.image.source.error.invalid': '{lang}wcf.editor.image.source.error.invalid{/lang}'
});
- var buttons = [], buttonOptions = [];
+ var buttons = [], buttonOptions = [], customButtons = [];
{include file='wysiwygToolbar'}
// TODO: Should the media stuff be here?
toolbarFixed: false,
woltlab: {
autosave: autosave,
- buttons: buttonOptions
+ buttons: buttonOptions,
+ customButtons: customButtons
}
};
woltlabQuote: { icon: 'fa-comment', title: '{lang}wcf.editor.button.quote{/lang}' },
woltlabSize: { icon: 'fa-text-height', title: '{lang}wcf.editor.button.size{/lang}' }
};
-
-buttons = [];
buttons.push('html');
buttons.push('woltlabMedia');
buttons.push('woltlabQuote');
+
+{foreach from=$__wcf->getBBCodeHandler()->getButtonBBCodes(true) item=__bbcode}
+ buttonOptions['{$__bbcode->bbcodeTag}'] = { icon: '{$__bbcode->wysiwygIcon}', title: '{lang}{$__bbcode->buttonLabel}{/lang}' };
+ buttons.push('{$__bbcode->bbcodeTag}');
+ customButtons.push('{$__bbcode->bbcodeTag}');
+{/foreach}
return {
init: function() {
+ // add custom buttons
+ var button, buttonName, i, length;
+ //noinspection JSUnresolvedVariable
+ for (i = 0, length = this.opts.woltlab.customButtons.length; i < length; i++) {
+ //noinspection JSUnresolvedVariable
+ buttonName = this.opts.woltlab.customButtons[i];
+
+ button = this.button.add(buttonName, '');
+ this.button.addCallback(button, this.WoltLabButton._handleCustomButton);
+ }
+
// set button icons and labels
- var button, buttonData, buttonName;
- for (var i = 0, length = this.opts.buttons.length; i < length; i++) {
+ var buttonData;
+ for (i = 0, length = this.opts.buttons.length; i < length; i++) {
buttonName = this.opts.buttons[i];
if (buttonName === 'wcfSeparator') {
});
WCF.DOMNodeInsertedHandler.execute();
+ },
+
+ _handleCustomButton: function (bbcode) {
+ var data = { cancel: false };
+ WCF.System.Event.fireEvent('com.woltlab.wcf.redactor2', 'bbcode_' + bbcode + '_' + this.$element[0].id, data);
+
+ if (data.cancel === true) {
+ return;
+ }
+
+ this.buffer.set();
+
+ var html = '[' + bbcode + ']' + this.selection.html() + (this.selection.is() ? '' : this.marker.html()) + '[/' + bbcode + ']';
+ this.insert.html(html);
+ this.selection.restore();
}
};
};
/**
* Returns a list of BBCodes displayed as buttons.
*
+ * @param boolean $excludeCoreBBCodes do not return bbcodes that are available by default
* @return BBCode[]
*/
- public function getButtonBBCodes() {
+ public function getButtonBBCodes($excludeCoreBBCodes = false) {
$buttons = [];
+ $coreBBCodes = ['align', 'b', 'color', 'i', 'img', 'list', 's', 'size', 'sub', 'sup', 'quote', 'table', 'u', 'url'];
foreach ($this->buttonBBCodes as $bbcode) {
+ if ($excludeCoreBBCodes && in_array($bbcode->bbcodeTag, $coreBBCodes)) {
+ continue;
+ }
+
if ($this->isAvailableBBCode($bbcode->bbcodeTag)) {
$buttons[] = $bbcode;
}