1 if (!RedactorPlugins
) var RedactorPlugins
= {};
4 * Provides custom BBCode buttons for Redactor.
6 * @author Alexander Ebert
7 * @copyright 2001-2014 WoltLab GmbH
8 * @license GNU Lesser General Public License <http://opensource.org/licenses/lgpl-license.php>
10 RedactorPlugins
.wbutton
= {
12 * list of button names and their associated bbcode tag
18 * Initializes the RedactorPlugins.wbutton plugin.
23 for (var $i
= 0, $length
= __REDACTOR_BUTTONS
.length
; $i
< $length
; $i
++) {
24 this._addBBCodeButton(__REDACTOR_BUTTONS
[$i
]);
27 // this list contains overrides for built-in buttons, if a button is not present
28 // Redactor's own icon will be used instead. This solves the problem of FontAwesome
29 // not providing an icon for everything we need (especially the core stuff)
31 'html': 'fa-square-o',
33 'italic': 'fa-italic',
34 'underline': 'fa-underline',
35 'deleted': 'fa-strikethrough',
36 'subscript': 'fa-subscript',
37 'superscript': 'fa-superscript',
38 'orderedlist': 'fa-list-ol',
39 'unorderedlist': 'fa-list-ul',
40 'outdent': 'fa-outdent',
41 'indent': 'fa-indent',
43 'alignment': 'fa-align-left',
47 var $buttons
= this.getOption('buttons');
49 for (var $i
= 0, $length
= $buttons
.length
; $i
< $length
; $i
++) {
50 var $button
= $buttons
[$i
];
52 if ($button
== 'separator') {
53 this.buttonGet($lastButton
).parent().addClass('separator');
58 // check if button does not exist
59 var $buttonObj
= this.buttonGet($button
);
60 if ($buttonObj
.length
) {
61 if ($faIcons
[$button
]) {
62 this.buttonAwesome($button
, $faIcons
[$button
]);
66 this._addCoreButton($button
, ($faIcons
[$button
] ? $faIcons
[$button
] : null), $lastButton
);
69 $lastButton
= $button
;
73 _addCoreButton: function(buttonName
, faIcon
, insertAfter
) {
74 var $button
= this.buttonBuild(buttonName
, {
78 $('<li />').append($button
).insertAfter(this.buttonGet(insertAfter
).parent());
80 if (faIcon
!== null) {
81 this.buttonAwesome(buttonName
, faIcon
);
86 * Adds a custom button.
88 * @param object<string> data
90 _addBBCodeButton: function(data
) {
91 var $buttonName
= '__wcf_' + data
.name
;
92 var $button
= this.buttonAdd($buttonName
, data
.label
, this._insertBBCode
);
93 this._bbcodes
[$buttonName
] = data
.name
;
95 // FontAwesome class name
96 if (data
.icon
.match(/^fa\-[a-z\-]+$/)) {
97 this.buttonAwesome($buttonName
, data
.icon
);
101 $button
.css('background-image', 'url(' + __REDACTOR_ICON_PATH
+ data
.icon
+ ')');
106 * Inserts the specified BBCode.
108 * @param string buttonName
109 * @param jQuery buttonDOM
110 * @param object buttonObj
111 * @param object event
113 _insertBBCode: function(buttonName
, buttonDOM
, buttonObj
, event
) {
114 var $bbcode
= this._bbcodes
[buttonName
];
115 var $selectedHtml
= this.getSelectionHtml();
116 this.insertHtml('[' + $bbcode
+ ']' + $selectedHtml
+ '[/' + $bbcode
+ ']');