Last active
December 17, 2015 04:49
-
-
Save mirontoli/5553166 to your computer and use it in GitHub Desktop.
A flyout menu widget for jQuery UI like in Facebook. I call it flydown
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| /*************************************************** | |
| jQuery UI Flyout widget like in Facebook | |
| ******************************************************/ | |
| (function($, undefined) { | |
| $.widget("ui.flydowns", { | |
| ///<summary>This is a custom jQuery widget | |
| ///for flydowns (flyout dropdowns) | |
| ///usage: $("your_selector").flydowns(); | |
| ///</summary> | |
| _create: function() { | |
| var self = this; | |
| self.element.on("click", ".flyout-menu", function(e) { | |
| var ul = $(this).children("ul"); | |
| var selected = ul.is(":visible"); | |
| self.collapse(); | |
| if (!selected) { | |
| ul.toggle(); // hide or show the list | |
| } | |
| }); | |
| $(document).on("click", function(e) { | |
| ///<summary>Collapses all dropdowns when blured</summary> | |
| e = e || window.event; | |
| var inDropdown = $(e.target).parents().andSelf().hasClass(".flyout-menu"); | |
| if (!inDropdown) { | |
| self.collapse(); | |
| } | |
| }); | |
| }, | |
| _init: function(){ | |
| }, | |
| collapse: function() { | |
| this.element.find(".flyout-menu > ul").hide(); | |
| } | |
| }); | |
| })(jQuery); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| <div class="right menu"> | |
| <div class="flyout-menu"> | |
| <div class="arrow"></div> | |
| <span class="flyout-menu-title">My menu</span> | |
| <ul> | |
| <li><a href="http://google.com">Google</a></li> | |
| <li><a href="http://bing.com">Bing</a></li> | |
| </ul> | |
| </div> | |
| </div> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| (function($, undefined) { | |
| "use strict"; | |
| $(document).on({ | |
| ready: function() { | |
| $(document).flydowns(); | |
| } | |
| }); | |
| })(jQuery); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment