Open interactive dropdowns by hovering
authorAlexander Ebert <ebert@woltlab.com>
Tue, 28 Jun 2016 21:37:07 +0000 (23:37 +0200)
committerAlexander Ebert <ebert@woltlab.com>
Tue, 28 Jun 2016 21:37:14 +0000 (23:37 +0200)
wcfsetup/install/files/js/WCF.User.js
wcfsetup/install/files/js/WCF.js

index ccf0ae4bdc4d9db82e29a64e026fc0be756f2982..fb424d7cd958590c1b1d18b5dd753d607b1e1fdb 100644 (file)
@@ -183,6 +183,22 @@ WCF.User.Panel.Abstract = Class.extend({
                });
                
                this._triggerElement.click($.proxy(this.toggle, this));
+               
+               var timer = null;
+               this._triggerElement.hover(
+                       (function() {
+                               if (this._dropdown === null || !this._dropdown.isOpen()) {
+                                       timer = window.setTimeout((function() {
+                                               this.toggle(undefined, true);
+                                       }).bind(this), 300); 
+                               }
+                       }).bind(this),
+                       function() {
+                               window.clearTimeout(timer);
+                               timer = null;
+                       }
+               );
+               
                if (this._options.showAllLink) {
                        this._triggerElement.dblclick($.proxy(this._dblClick, this));
                }
@@ -201,10 +217,11 @@ WCF.User.Panel.Abstract = Class.extend({
        /**
         * Toggles the interactive dropdown.
         * 
-        * @param       {Event=}                event
+        * @param       {Event?}        event
+        * @param       {boolean?}      openOnly
         * @return      {boolean}
         */
-       toggle: function(event) {
+       toggle: function(event, openOnly) {
                if (event instanceof Event) {
                        event.preventDefault();
                }
@@ -213,6 +230,10 @@ WCF.User.Panel.Abstract = Class.extend({
                        this._dropdown = this._initDropdown();
                }
                
+               if (openOnly === true && this._dropdown.isOpen()) {
+                       return false;
+               }
+               
                if (this._dropdown.toggle()) {
                        if (!this._loadData) {
                                // check if there are outstanding items but there are no outstanding ones in the current list
index 06d40f7f4663e06a8799b06ffcc7da294d2b3ea5..c60a458e65546670368e688fe8fe067cd61178c7 100755 (executable)
@@ -1196,6 +1196,15 @@ WCF.Dropdown.Interactive.Instance = Class.extend({
                this._container.removeClass('open');
        },
        
+       /**
+        * Returns true if dropdown instance is visible.
+        * 
+        * @returns     {boolean}
+        */
+       isOpen: function() {
+               return this._triggerElement.hasClass('open');
+       },
+       
        /**
         * Toggles the dropdown state, returns true if dropdown is open afterwards, else false.
         *