Added support for void BBCodes
authorAlexander Ebert <ebert@woltlab.com>
Mon, 29 Dec 2014 23:21:39 +0000 (00:21 +0100)
committerAlexander Ebert <ebert@woltlab.com>
Mon, 29 Dec 2014 23:21:39 +0000 (00:21 +0100)
wcfsetup/install/files/js/3rdParty/redactor/plugins/wbutton.js

index 3694b5e4b189eafc50a9ec76ffdc9b36a6232cc3..a90f2f774a59fb5c53df32fdf8434afbb17aa698 100644 (file)
@@ -121,7 +121,10 @@ RedactorPlugins.wbutton = function() {
                        var $button = this.button.add($buttonName, data.label);
                        this.button.addCallback($button, this.wbutton._insertBBCode);
                        
-                       this._bbcodes[$buttonName] = data.name;
+                       this._bbcodes[$buttonName] = {
+                               name: data.name,
+                               voidElement: (data.voidElement === true)
+                       };
                        
                        // FontAwesome class name
                        if (data.icon.match(/^fa\-[a-z\-]+$/)) {
@@ -139,7 +142,7 @@ RedactorPlugins.wbutton = function() {
                 * @param       string          buttonName
                 */
                _insertBBCode: function(buttonName) {
-                       var $bbcode = this._bbcodes[buttonName];
+                       var $bbcode = this._bbcodes[buttonName].name;
                        var $eventData = {
                                buttonName: buttonName,
                                cancel: false
@@ -162,7 +165,14 @@ RedactorPlugins.wbutton = function() {
                                }
                                else {
                                        this.buffer.set();
-                                       this.insert.html('[' + $bbcode + ']' + $selectedHtml + this.selection.getMarkerAsHtml() + '[/' + $bbcode + ']', false);
+                                       
+                                       if (this._bbcodes[buttonName].voidElement) {
+                                               this.insert.html($selectedHtml + this.selection.getMarkerAsHtml() + '[' + $bbcode + ']', false);
+                                       }
+                                       else {
+                                               this.insert.html('[' + $bbcode + ']' + $selectedHtml + this.selection.getMarkerAsHtml() + '[/' + $bbcode + ']', false);
+                                       }
+                                       
                                        this.selection.restore();
                                }
                        }