| OLD | NEW |
| (Empty) | |
| 1 /* ============================================================ |
| 2 * bootstrap-dropdown.js v2.0.4 |
| 3 * http://twitter.github.com/bootstrap/javascript.html#dropdowns |
| 4 * ============================================================ |
| 5 * Copyright 2012 Twitter, Inc. |
| 6 * |
| 7 * Licensed under the Apache License, Version 2.0 (the "License"); |
| 8 * you may not use this file except in compliance with the License. |
| 9 * You may obtain a copy of the License at |
| 10 * |
| 11 * http://www.apache.org/licenses/LICENSE-2.0 |
| 12 * |
| 13 * Unless required by applicable law or agreed to in writing, software |
| 14 * distributed under the License is distributed on an "AS IS" BASIS, |
| 15 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 16 * See the License for the specific language governing permissions and |
| 17 * limitations under the License. |
| 18 * ============================================================ */ |
| 19 |
| 20 |
| 21 !function ($) { |
| 22 |
| 23 "use strict"; // jshint ;_; |
| 24 |
| 25 |
| 26 /* DROPDOWN CLASS DEFINITION |
| 27 * ========================= */ |
| 28 |
| 29 var toggle = '[data-toggle="dropdown"]' |
| 30 , Dropdown = function (element) { |
| 31 var $el = $(element).on('click.dropdown.data-api', this.toggle) |
| 32 $('html').on('click.dropdown.data-api', function () { |
| 33 $el.parent().removeClass('open') |
| 34 }) |
| 35 } |
| 36 |
| 37 Dropdown.prototype = { |
| 38 |
| 39 constructor: Dropdown |
| 40 |
| 41 , toggle: function (e) { |
| 42 var $this = $(this) |
| 43 , $parent |
| 44 , selector |
| 45 , isActive |
| 46 |
| 47 if ($this.is('.disabled, :disabled')) return |
| 48 |
| 49 selector = $this.attr('data-target') |
| 50 |
| 51 if (!selector) { |
| 52 selector = $this.attr('href') |
| 53 selector = selector && selector.replace(/.*(?=#[^\s]*$)/, '') //strip fo
r ie7 |
| 54 } |
| 55 |
| 56 $parent = $(selector) |
| 57 $parent.length || ($parent = $this.parent()) |
| 58 |
| 59 isActive = $parent.hasClass('open') |
| 60 |
| 61 clearMenus() |
| 62 |
| 63 if (!isActive) $parent.toggleClass('open') |
| 64 |
| 65 return false |
| 66 } |
| 67 |
| 68 } |
| 69 |
| 70 function clearMenus() { |
| 71 $(toggle).parent().removeClass('open') |
| 72 } |
| 73 |
| 74 |
| 75 /* DROPDOWN PLUGIN DEFINITION |
| 76 * ========================== */ |
| 77 |
| 78 $.fn.dropdown = function (option) { |
| 79 return this.each(function () { |
| 80 var $this = $(this) |
| 81 , data = $this.data('dropdown') |
| 82 if (!data) $this.data('dropdown', (data = new Dropdown(this))) |
| 83 if (typeof option == 'string') data[option].call($this) |
| 84 }) |
| 85 } |
| 86 |
| 87 $.fn.dropdown.Constructor = Dropdown |
| 88 |
| 89 |
| 90 /* APPLY TO STANDARD DROPDOWN ELEMENTS |
| 91 * =================================== */ |
| 92 |
| 93 $(function () { |
| 94 $('html').on('click.dropdown.data-api', clearMenus) |
| 95 $('body') |
| 96 .on('click.dropdown', '.dropdown form', function (e) { e.stopPropagation()
}) |
| 97 .on('click.dropdown.data-api', toggle, Dropdown.prototype.toggle) |
| 98 }) |
| 99 |
| 100 }(window.jQuery); |
| OLD | NEW |