Enabling indent/outdent within lists only
authorAlexander Ebert <ebert@woltlab.com>
Thu, 29 May 2014 21:54:18 +0000 (23:54 +0200)
committerAlexander Ebert <ebert@woltlab.com>
Thu, 29 May 2014 21:54:18 +0000 (23:54 +0200)
wcfsetup/install/files/js/3rdParty/redactor/plugins/wmonkeypatch.js

index 6c36e361d6745f69c57211a0c52ec61a66b18806..d1a894466d13157295c2007b35bc27ce43f212e0 100644 (file)
@@ -51,15 +51,45 @@ RedactorPlugins.wmonkeypatch = {
                        $mpModalInit.call(self, title, content, width, callback);
                };
                
+               // handle indent/outdent
+               var $mpButtonActiveObserver = this.buttonActiveObserver;
+               this.buttonActiveObserver = function(e, btnName) {
+                       self.mpButtonActiveObserver(e, btnName);
+                       
+                       $mpButtonActiveObserver.call(self, e, btnName);
+               };
+               if (this.opts.activeButtons) {
+                       this.$editor.off('mouseup.redactor keyup.redactor').on('mouseup.redactor keyup.redactor', $.proxy(this.buttonActiveObserver, this));
+               }
+               this.$toolbar.find('a.re-indent, a.re-outdent').addClass('redactor_button_disabled');
+               
                this.setOption('modalOpenedCallback', $.proxy(this.modalOpenedCallback, this));
                
                this.modalTemplatesInit();
+               
+               window.dtdesign = this;
        },
        
        cleanRemoveSpaces: function(html, buffer) {
                return html;
        },
        
+       /**
+        * Enable/Disable the 'Indent'/'Outdent' for lists/outside lists.
+        * 
+        * @param       object          e
+        * @param       string          btnName
+        */
+       mpButtonActiveObserver: function(e, btnName) {
+               var parent = this.getParent();
+               if (parent !== false && $(parent).closest('ul', this.$editor.get()[0]).length != 0) {
+                       this.$toolbar.find('a.re-indent, a.re-outdent').removeClass('redactor_button_disabled');
+               }
+               else {
+                       this.$toolbar.find('a.re-indent, a.re-outdent').addClass('redactor_button_disabled');
+               }
+       },
+       
        /**
         * Overwrites $.Redactor.inlineRemoveStyle() to drop empty <inline> elements.
         *