| 
									
										
										
										
											2012-07-23 09:28:39 +08:00
										 |  |  | /* ========================================================== | 
					
						
							| 
									
										
										
										
											2012-09-06 01:00:57 +08:00
										 |  |  |  * bootstrap-affix.js v2.1.2 | 
					
						
							| 
									
										
										
										
											2012-07-23 09:28:39 +08:00
										 |  |  |  * http://twitter.github.com/bootstrap/javascript.html#affix
 | 
					
						
							|  |  |  |  * ========================================================== | 
					
						
							|  |  |  |  * 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. | 
					
						
							|  |  |  |  * ========================================================== */ | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | !function ($) { | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   "use strict"; // jshint ;_;
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |  /* AFFIX CLASS DEFINITION | 
					
						
							|  |  |  |   * ====================== */ | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   var Affix = function (element, options) { | 
					
						
							|  |  |  |     this.options = $.extend({}, $.fn.affix.defaults, options) | 
					
						
							| 
									
										
										
										
											2012-08-15 12:06:08 +08:00
										 |  |  |     this.$window = $(window).on('scroll.affix.data-api', $.proxy(this.checkPosition, this)) | 
					
						
							| 
									
										
										
										
											2012-07-23 09:28:39 +08:00
										 |  |  |     this.$element = $(element) | 
					
						
							| 
									
										
										
										
											2012-08-15 12:23:29 +08:00
										 |  |  |     this.checkPosition() | 
					
						
							| 
									
										
										
										
											2012-07-23 09:28:39 +08:00
										 |  |  |   } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   Affix.prototype.checkPosition = function () { | 
					
						
							|  |  |  |     if (!this.$element.is(':visible')) return | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2012-08-15 12:06:08 +08:00
										 |  |  |     var scrollHeight = $(document).height() | 
					
						
							| 
									
										
										
										
											2012-07-23 09:28:39 +08:00
										 |  |  |       , scrollTop = this.$window.scrollTop() | 
					
						
							| 
									
										
										
										
											2012-08-15 12:06:08 +08:00
										 |  |  |       , position = this.$element.offset() | 
					
						
							| 
									
										
										
										
											2012-07-23 09:28:39 +08:00
										 |  |  |       , offset = this.options.offset | 
					
						
							| 
									
										
										
										
											2012-08-15 12:06:08 +08:00
										 |  |  |       , offsetBottom = offset.bottom | 
					
						
							|  |  |  |       , offsetTop = offset.top | 
					
						
							|  |  |  |       , reset = 'affix affix-top affix-bottom' | 
					
						
							| 
									
										
										
										
											2012-07-23 09:28:39 +08:00
										 |  |  |       , affix | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2012-08-15 12:06:08 +08:00
										 |  |  |     if (typeof offset != 'object') offsetBottom = offsetTop = offset | 
					
						
							|  |  |  |     if (typeof offsetTop == 'function') offsetTop = offset.top() | 
					
						
							|  |  |  |     if (typeof offsetBottom == 'function') offsetBottom = offset.bottom() | 
					
						
							| 
									
										
										
										
											2012-07-23 09:28:39 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2012-08-15 12:06:08 +08:00
										 |  |  |     affix = this.unpin != null && (scrollTop + this.unpin <= position.top) ? | 
					
						
							|  |  |  |       false    : offsetBottom != null && (position.top + this.$element.height() >= scrollHeight - offsetBottom) ? | 
					
						
							|  |  |  |       'bottom' : offsetTop != null && scrollTop <= offsetTop ? | 
					
						
							|  |  |  |       'top'    : false | 
					
						
							| 
									
										
										
										
											2012-07-23 09:28:39 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2012-08-15 12:06:08 +08:00
										 |  |  |     if (this.affixed === affix) return | 
					
						
							| 
									
										
										
										
											2012-07-23 09:28:39 +08:00
										 |  |  | 
 | 
					
						
							|  |  |  |     this.affixed = affix | 
					
						
							| 
									
										
										
										
											2012-08-15 12:06:08 +08:00
										 |  |  |     this.unpin = affix == 'bottom' ? position.top - scrollTop : null | 
					
						
							| 
									
										
										
										
											2012-07-23 09:28:39 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2012-08-15 12:06:08 +08:00
										 |  |  |     this.$element.removeClass(reset).addClass('affix' + (affix ? '-' + affix : '')) | 
					
						
							| 
									
										
										
										
											2012-07-23 09:28:39 +08:00
										 |  |  |   } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |  /* AFFIX PLUGIN DEFINITION | 
					
						
							|  |  |  |   * ======================= */ | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   $.fn.affix = function (option) { | 
					
						
							|  |  |  |     return this.each(function () { | 
					
						
							|  |  |  |       var $this = $(this) | 
					
						
							|  |  |  |         , data = $this.data('affix') | 
					
						
							|  |  |  |         , options = typeof option == 'object' && option | 
					
						
							|  |  |  |       if (!data) $this.data('affix', (data = new Affix(this, options))) | 
					
						
							|  |  |  |       if (typeof option == 'string') data[option]() | 
					
						
							|  |  |  |     }) | 
					
						
							|  |  |  |   } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   $.fn.affix.Constructor = Affix | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   $.fn.affix.defaults = { | 
					
						
							|  |  |  |     offset: 0 | 
					
						
							|  |  |  |   } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |  /* AFFIX DATA-API | 
					
						
							|  |  |  |   * ============== */ | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2012-08-15 12:06:08 +08:00
										 |  |  |   $(window).on('load', function () { | 
					
						
							| 
									
										
										
										
											2012-07-23 09:28:39 +08:00
										 |  |  |     $('[data-spy="affix"]').each(function () { | 
					
						
							|  |  |  |       var $spy = $(this) | 
					
						
							|  |  |  |         , data = $spy.data() | 
					
						
							| 
									
										
										
										
											2012-07-24 09:17:43 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2012-07-23 09:28:39 +08:00
										 |  |  |       data.offset = data.offset || {} | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2012-08-15 12:06:08 +08:00
										 |  |  |       data.offsetBottom && (data.offset.bottom = data.offsetBottom) | 
					
						
							|  |  |  |       data.offsetTop && (data.offset.top = data.offsetTop) | 
					
						
							| 
									
										
										
										
											2012-07-23 09:28:39 +08:00
										 |  |  | 
 | 
					
						
							|  |  |  |       $spy.affix(data) | 
					
						
							|  |  |  |     }) | 
					
						
							|  |  |  |   }) | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | }(window.jQuery); |