-
Notifications
You must be signed in to change notification settings - Fork 2
/
dropdown.min.js
16 lines (15 loc) · 2.3 KB
/
dropdown.min.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
/*!
* jQuery Dropdown
* http://blog.gatherage.com/jquery-select-dropdown
*
* Copyright 2012, Rob Rothermel
* Dual licensed under the MIT or GPL Version 2 licenses.
* http://www.opensource.org/licenses/mit-license.php
* http://www.gnu.org/licenses/gpl-2.0.html
*
* Date: Fri Mar 16 20:46:40 EDT 2012
*/
(function(b){b?(b.fn.extend({dropdown:function(){this.filter("select").each(function(){var a=b(this);if(!0!==a.data("dropdown.initialized")){var c=function(){a.val(b(this).attr("value")).change();return!1},d=function(a,e){return a.append(e.map(function(){var a=b(this);return a.is("optgroup")?b(document.createElement("li")).append(b(document.createElement("strong")).text(a.attr("label"))).append(d(b(document.createElement("ul")),a.children())).get()[0]:b(document.createElement("li")).append(b(document.createElement("a")).text(a.text()).attr({value:a.attr("value")||
a.text(),href:""}).click(c)).get()[0]}))},e=b(document.createElement("dl")).addClass("dropdown").data("select",a).append(b(document.createElement("dt")).append(b(document.createElement("a")).attr("href","#").append(b(document.createElement("span")).addClass("label").text(a.attr("title")||a.find("option:first").text())).append(b(document.createElement("span")).addClass("arrow")))).append(b(document.createElement("dd")).append(d(b(document.createElement("ul")),a.children())));a.after(e).hide().data("dropdown.initialized",
!0)}});this.each(function(){var a=b(this);a.is("select")&&(a=a.next(".dropdown"));if(!0!==a.data("dropdown.initialized")){a.find("dt a").click(function(){b(".dropdown").not(a).removeClass("dropdownActive");a.toggleClass("dropdownActive");return!1}).end().find("dd ul li a").click(function(){a.removeClass("dropdownDefaultValue").find("dt a span.label").html(b(this).html()).end().removeClass("dropdownActive");if(!a.hasClass("dropdownNavigation"))return!1});var c=a.data("select"),d=c&&c.children().filter(function(){return this.getAttribute("selected")});
c&&0<d.length&&b(a.find("dd ul li a")[c.children().index(d)]).click();a.data("dropdown.initialized",!0)}});return this.not("select").addClass("dropdown").end()}}),b(function(){b(document).bind("click",function(a){b(a.target).parents().hasClass("dropdown")||b(".dropdown").removeClass("dropdownActive")})})):window.console&&console.log("Dropdown plugin: jQuery not found")})(window.jQuery);