-
Notifications
You must be signed in to change notification settings - Fork 265
/
jquery.dropdown.min.js
9 lines (9 loc) · 2.32 KB
/
jquery.dropdown.min.js
1
2
3
4
5
6
7
8
9
/*
* jQuery Dropdown: A simple dropdown plugin
*
* Contribute: https://github.com/claviska/jquery-dropdown
*
* @license: MIT license: http://opensource.org/licenses/MIT
*
*/
jQuery&&function($){function t(t,e){var d=t?$(this):e,n=$(d.attr("data-jq-dropdown")),a=d.hasClass("jq-dropdown-open");if(t){if($(t.target).hasClass("jq-dropdown-ignore"))return;t.preventDefault(),t.stopPropagation()}else if(d!==e.target&&$(e.target).hasClass("jq-dropdown-ignore"))return;o(),a||d.hasClass("jq-dropdown-disabled")||(d.addClass("jq-dropdown-open"),n.data("jq-dropdown-trigger",d).show(),r(),n.trigger("show",{jqDropdown:n,trigger:d}))}function o(t){var o=t?$(t.target).parents().addBack():null;if(o&&o.is(".jq-dropdown")){if(!o.is(".jq-dropdown-menu"))return;if(!o.is("A"))return}var r=jQuery.Event("hide");$(document).find(".jq-dropdown:visible").each(function(){var t=$(this);t.hide().removeData("jq-dropdown-trigger").trigger("hide",{jqDropdown:t})}),r.isDefaultPrevented()||($(document).find(".jq-dropdown:visible").each(function(){var t=$(this);t.hide().removeData("jq-dropdown-trigger").trigger("hide",{jqDropdown:t})}),$(document).find(".jq-dropdown-open").removeClass("jq-dropdown-open"))}function r(){var t=$(".jq-dropdown:visible").eq(0),o=t.data("jq-dropdown-trigger"),r=o?parseInt(o.attr("data-horizontal-offset")||0,10):null,e=o?parseInt(o.attr("data-vertical-offset")||0,10):null;0!==t.length&&o&&(t.hasClass("jq-dropdown-relative")?t.css({left:t.hasClass("jq-dropdown-anchor-right")?o.position().left-(t.outerWidth(!0)-o.outerWidth(!0))-parseInt(o.css("margin-right"),10)+r:o.position().left+parseInt(o.css("margin-left"),10)+r,top:o.position().top+o.outerHeight(!0)-parseInt(o.css("margin-top"),10)+e}):t.css({left:t.hasClass("jq-dropdown-anchor-right")?o.offset().left-(t.outerWidth()-o.outerWidth())+r:o.offset().left+r,top:o.offset().top+o.outerHeight()+e}))}$.extend($.fn,{jqDropdown:function(r,e){switch(r){case"show":return t(null,$(this)),$(this);case"hide":return o(),$(this);case"attach":return $(this).attr("data-jq-dropdown",e);case"detach":return o(),$(this).removeAttr("data-jq-dropdown");case"disable":return $(this).addClass("jq-dropdown-disabled");case"enable":return o(),$(this).removeClass("jq-dropdown-disabled")}}}),$(document).on("click.jq-dropdown","[data-jq-dropdown]",t),$(document).on("click.jq-dropdown",o),$(window).on("resize",r)}(jQuery);