Improved UI for inline editors
authorAlexander Ebert <ebert@woltlab.com>
Thu, 1 Aug 2013 15:51:42 +0000 (17:51 +0200)
committerAlexander Ebert <ebert@woltlab.com>
Thu, 1 Aug 2013 15:51:42 +0000 (17:51 +0200)
wcfsetup/install/files/js/WCF.js

index 57b293e9892132ca6d34ff3ef895ef0ac286b9b1..51f2051d088ef7c27949eb63661ad3d990e8ef4f 100755 (executable)
@@ -6331,7 +6331,7 @@ WCF.InlineEditor = Class.extend({
                        }
                        else if (this._validate($elementID, $option.optionName) || this._validateCallbacks($elementID, $option.optionName)) {
                                var $listItem = $('<li><span>' + $option.label + '</span></li>').appendTo(this._dropdowns[$elementID]);
-                               $listItem.data('elementID', $elementID).data('optionName', $option.optionName).click($.proxy(this._click, this));
+                               $listItem.data('elementID', $elementID).data('optionName', $option.optionName).data('isQuickOption', ($option.isQuickOption ? true : false)).click($.proxy(this._click, this));
                                
                                $hasOptions = true;
                                $lastElementType = $option.optionName;
@@ -6344,6 +6344,32 @@ WCF.InlineEditor = Class.extend({
                        if ($lastChild.hasClass('dropdownDivider')) {
                                $lastChild.remove();
                        }
+                       
+                       // check if only element is a quick option
+                       var $quickOption = null;
+                       var $count = 0;
+                       this._dropdowns[$elementID].children().each(function(index, child) {
+                               var $child = $(child);
+                               if (!$child.hasClass('dropdownDivider')) {
+                                       if ($child.data('isQuickOption')) {
+                                               $quickOption = $child;
+                                       }
+                                       else {
+                                               $count++;
+                                       }
+                               }
+                       });
+                       console.debug($quickOption);
+                       console.debug($count);
+                       if (!$count) {
+                               $quickOption.trigger('click');
+                               
+                               if ($trigger === null) {
+                                       WCF.Dropdown.close($trigger.parents('.dropdown').wcfIdentify());
+                               }
+                               
+                               return false;
+                       }
                }
                
                if ($trigger !== null) {