| 
									
										
										
										
											2012-02-01 05:58:28 +08:00
										 |  |  | /* ============================================================ | 
					
						
							| 
									
										
										
										
											2012-09-06 01:00:57 +08:00
										 |  |  |  * bootstrap-dropdown.js v2.1.2 | 
					
						
							| 
									
										
										
										
											2012-02-01 05:58:28 +08:00
										 |  |  |  * http://twitter.github.com/bootstrap/javascript.html#dropdowns
 | 
					
						
							|  |  |  |  * ============================================================ | 
					
						
							|  |  |  |  * Copyright 2012 Twitter, Inc. | 
					
						
							|  |  |  |  * | 
					
						
							|  |  |  |  * Licensed under the Apache License, Version 2.0 (the "License"); | 
					
						
							|  |  |  |  * you may not use this file except in compliance with the License. | 
					
						
							|  |  |  |  * You may obtain a copy of the License at | 
					
						
							|  |  |  |  * | 
					
						
							|  |  |  |  * http://www.apache.org/licenses/LICENSE-2.0
 | 
					
						
							|  |  |  |  * | 
					
						
							|  |  |  |  * Unless required by applicable law or agreed to in writing, software | 
					
						
							|  |  |  |  * distributed under the License is distributed on an "AS IS" BASIS, | 
					
						
							|  |  |  |  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | 
					
						
							|  |  |  |  * See the License for the specific language governing permissions and | 
					
						
							|  |  |  |  * limitations under the License. | 
					
						
							|  |  |  |  * ============================================================ */ | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2012-04-15 07:29:53 +08:00
										 |  |  | !function ($) { | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   "use strict"; // jshint ;_;
 | 
					
						
							| 
									
										
										
										
											2012-02-01 05:58:28 +08:00
										 |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |  /* DROPDOWN CLASS DEFINITION | 
					
						
							|  |  |  |   * ========================= */ | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2012-05-17 15:39:14 +08:00
										 |  |  |   var toggle = '[data-toggle=dropdown]' | 
					
						
							| 
									
										
										
										
											2012-04-15 07:29:53 +08:00
										 |  |  |     , Dropdown = function (element) { | 
					
						
							| 
									
										
										
										
											2012-02-01 05:58:28 +08:00
										 |  |  |         var $el = $(element).on('click.dropdown.data-api', this.toggle) | 
					
						
							|  |  |  |         $('html').on('click.dropdown.data-api', function () { | 
					
						
							|  |  |  |           $el.parent().removeClass('open') | 
					
						
							|  |  |  |         }) | 
					
						
							|  |  |  |       } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   Dropdown.prototype = { | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     constructor: Dropdown | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2012-04-15 07:29:53 +08:00
										 |  |  |   , toggle: function (e) { | 
					
						
							| 
									
										
										
										
											2012-02-01 05:58:28 +08:00
										 |  |  |       var $this = $(this) | 
					
						
							|  |  |  |         , $parent | 
					
						
							|  |  |  |         , isActive | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2012-04-15 13:43:36 +08:00
										 |  |  |       if ($this.is('.disabled, :disabled')) return | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2012-05-17 15:23:11 +08:00
										 |  |  |       $parent = getParent($this) | 
					
						
							| 
									
										
										
										
											2012-04-15 13:43:36 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2012-02-01 05:58:28 +08:00
										 |  |  |       isActive = $parent.hasClass('open') | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |       clearMenus() | 
					
						
							| 
									
										
										
										
											2012-04-15 07:29:53 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2012-05-17 15:23:11 +08:00
										 |  |  |       if (!isActive) { | 
					
						
							|  |  |  |         $parent.toggleClass('open') | 
					
						
							|  |  |  |         $this.focus() | 
					
						
							| 
									
										
										
										
											2012-02-01 05:58:28 +08:00
										 |  |  |       } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |       return false | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2012-05-17 15:23:11 +08:00
										 |  |  |   , keydown: function (e) { | 
					
						
							| 
									
										
										
										
											2012-05-17 15:39:14 +08:00
										 |  |  |       var $this | 
					
						
							| 
									
										
										
										
											2012-05-17 15:23:11 +08:00
										 |  |  |         , $items | 
					
						
							|  |  |  |         , $active | 
					
						
							|  |  |  |         , $parent | 
					
						
							| 
									
										
										
										
											2012-05-17 15:39:14 +08:00
										 |  |  |         , isActive | 
					
						
							| 
									
										
										
										
											2012-05-17 15:23:11 +08:00
										 |  |  |         , index | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2012-05-17 15:39:14 +08:00
										 |  |  |       if (!/(38|40|27)/.test(e.keyCode)) return | 
					
						
							| 
									
										
										
										
											2012-05-17 15:23:11 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2012-05-17 15:39:14 +08:00
										 |  |  |       $this = $(this) | 
					
						
							| 
									
										
										
										
											2012-05-17 15:23:11 +08:00
										 |  |  | 
 | 
					
						
							|  |  |  |       e.preventDefault() | 
					
						
							|  |  |  |       e.stopPropagation() | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |       if ($this.is('.disabled, :disabled')) return | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |       $parent = getParent($this) | 
					
						
							| 
									
										
										
										
											2012-02-01 05:58:28 +08:00
										 |  |  | 
 | 
					
						
							|  |  |  |       isActive = $parent.hasClass('open') | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2012-05-17 15:39:14 +08:00
										 |  |  |       if (!isActive || (isActive && e.keyCode == 27)) return $this.click() | 
					
						
							| 
									
										
										
										
											2012-04-15 07:29:53 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2012-05-17 15:39:14 +08:00
										 |  |  |       $items = $('[role=menu] li:not(.divider) a', $parent) | 
					
						
							| 
									
										
										
										
											2012-02-01 05:58:28 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2012-05-17 15:23:11 +08:00
										 |  |  |       if (!$items.length) return | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2012-05-17 15:39:14 +08:00
										 |  |  |       index = $items.index($items.filter(':focus')) | 
					
						
							| 
									
										
										
										
											2012-05-17 15:23:11 +08:00
										 |  |  | 
 | 
					
						
							|  |  |  |       if (e.keyCode == 38 && index > 0) index--                                        // up
 | 
					
						
							| 
									
										
										
										
											2012-05-17 15:39:14 +08:00
										 |  |  |       if (e.keyCode == 40 && index < $items.length - 1) index++                        // down
 | 
					
						
							| 
									
										
										
										
											2012-05-17 15:23:11 +08:00
										 |  |  |       if (!~index) index = 0 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |       $items | 
					
						
							|  |  |  |         .eq(index) | 
					
						
							| 
									
										
										
										
											2012-05-17 15:39:14 +08:00
										 |  |  |         .focus() | 
					
						
							| 
									
										
										
										
											2012-02-01 05:58:28 +08:00
										 |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2012-09-27 16:31:40 +08:00
										 |  |  |   function clearMenus() {  | 
					
						
							|  |  |  |     $(toggle).each(function () {  | 
					
						
							|  |  |  |       getParent($(this)).removeClass("open") | 
					
						
							|  |  |  |     }) | 
					
						
							| 
									
										
										
										
											2012-05-17 15:23:11 +08:00
										 |  |  |   } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   function getParent($this) { | 
					
						
							|  |  |  |     var selector = $this.attr('data-target') | 
					
						
							|  |  |  |       , $parent | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     if (!selector) { | 
					
						
							|  |  |  |       selector = $this.attr('href') | 
					
						
							| 
									
										
										
										
											2012-08-28 12:44:09 +08:00
										 |  |  |       selector = selector && /#/.test(selector) && selector.replace(/.*(?=#[^\s]*$)/, '') //strip for ie7
 | 
					
						
							| 
									
										
										
										
											2012-05-17 15:23:11 +08:00
										 |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     $parent = $(selector) | 
					
						
							|  |  |  |     $parent.length || ($parent = $this.parent()) | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     return $parent | 
					
						
							| 
									
										
										
										
											2012-02-01 05:58:28 +08:00
										 |  |  |   } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   /* DROPDOWN PLUGIN DEFINITION | 
					
						
							|  |  |  |    * ========================== */ | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2012-04-15 07:29:53 +08:00
										 |  |  |   $.fn.dropdown = function (option) { | 
					
						
							| 
									
										
										
										
											2012-02-01 05:58:28 +08:00
										 |  |  |     return this.each(function () { | 
					
						
							|  |  |  |       var $this = $(this) | 
					
						
							|  |  |  |         , data = $this.data('dropdown') | 
					
						
							|  |  |  |       if (!data) $this.data('dropdown', (data = new Dropdown(this))) | 
					
						
							|  |  |  |       if (typeof option == 'string') data[option].call($this) | 
					
						
							|  |  |  |     }) | 
					
						
							|  |  |  |   } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   $.fn.dropdown.Constructor = Dropdown | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   /* APPLY TO STANDARD DROPDOWN ELEMENTS | 
					
						
							|  |  |  |    * =================================== */ | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   $(function () { | 
					
						
							| 
									
										
										
										
											2012-05-17 15:23:11 +08:00
										 |  |  |     $('html') | 
					
						
							| 
									
										
										
										
											2012-08-19 11:18:15 +08:00
										 |  |  |       .on('click.dropdown.data-api touchstart.dropdown.data-api', clearMenus) | 
					
						
							| 
									
										
										
										
											2012-03-20 14:13:55 +08:00
										 |  |  |     $('body') | 
					
						
							| 
									
										
										
										
											2012-08-28 12:44:09 +08:00
										 |  |  |       .on('click.dropdown touchstart.dropdown.data-api', '.dropdown form', function (e) { e.stopPropagation() }) | 
					
						
							| 
									
										
										
										
											2012-08-19 11:18:15 +08:00
										 |  |  |       .on('click.dropdown.data-api touchstart.dropdown.data-api'  , toggle, Dropdown.prototype.toggle) | 
					
						
							|  |  |  |       .on('keydown.dropdown.data-api touchstart.dropdown.data-api', toggle + ', [role=menu]' , Dropdown.prototype.keydown) | 
					
						
							| 
									
										
										
										
											2012-02-01 05:58:28 +08:00
										 |  |  |   }) | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2012-04-15 07:29:53 +08:00
										 |  |  | }(window.jQuery); |