1 2;(function ( $, window, document, undefined ) { 3 4 $.fixed = function(element, options) { 5 6 var defaults = { 7 topSpace: 0, 8 placeholder: true, 9 onFixed: function() {}, 10 onStatic: function() {} 11 } 12 13 var plugin = this; 14 plugin.settings = {} 15 var $element = $(element), 16 element = element; 17 var wrapper, placeholder, wrapperTop; 18 19 plugin.init = function() { 20 plugin.settings = $.extend({}, defaults, options); 21 22 $(element).wrap("<div class='navigation-fixed-wrapper'></div>").each(function(){ 23 wrapper = $(element).parent(); 24 if(plugin.settings.placeholder){ 25 $("<div class='navigation-fixed-placeholder'></div>").insertBefore(wrapper); 26 $(".navigation-fixed-placeholder").css("height", $(wrapper).outerHeight()); 27 placeholder = $(".navigation-fixed-placeholder"); 28 } 29 }); 30 31 wrapperTop = $(wrapper).offset().top; 32 33 if(wrapperTop <= plugin.settings.topSpace){ 34 toFixed(); 35 } 36 else{ 37 $(window).on("scroll", function(){ 38 if($(window).scrollTop() >= wrapperTop - plugin.settings.topSpace){ 39 if(!$(wrapper).hasClass("fixed")) 40 toFixed(); 41 } 42 else{ 43 if($(wrapper).hasClass("fixed")) 44 toStatic(); 45 } 46 }); 47 } 48 49 $(window).resize(function(){ 50 resizeNav(); 51 if(plugin.settings.placeholder){ 52 $(placeholder).css("height", $(wrapper).outerHeight()); 53 } 54 }) 55 56 $(element).on("click touchstart", function(){ 57 resizeNav(); 58 }); 59 } 60 61 var toFixed = function() { 62 $(wrapper).addClass("fixed"); 63 if(plugin.settings.placeholder){ 64 $(placeholder).addClass("visible"); 65 } 66 resizeNav(); 67 68 if(options !== undefined){ 69 plugin.callback("onFixed"); 70 } 71 } 72 73 var toStatic = function() { 74 $(wrapper).removeClass("fixed"); 75 if(plugin.settings.placeholder){ 76 $(placeholder).removeClass("visible"); 77 } 78 79 if(options !== undefined){ 80 plugin.callback("onStatic"); 81 } 82 } 83 84 var resizeNav = function() { 85 $(element).css("width", $(wrapper).parent().width()); 86 $(wrapper).css("top", plugin.settings.topSpace); 87 } 88 89 var detectIOS = function() { 90 var userAgent = navigator.userAgent || navigator.vendor || window.opera; 91 if (/iPad|iPhone|iPod/.test(userAgent) && !window.MSStream) { 92 return true; 93 } 94 else{ 95 return false; 96 } 97 } 98 99 plugin.callback = function(func) { 100 if (options[func] !== undefined) { 101 options[func].call(element); 102 } 103 } 104 105 plugin.init(); 106 107 } 108 109 $.fn.fixed = function(options) { 110 return this.each(function() { 111 if (undefined == $(this).data('fixed')) { 112 var plugin = new $.fixed(this, options); 113 $(this).data('fixed', plugin); 114 } 115 }); 116 } 117 118 119})( jQuery, window, document );
Line numbers count LF bytes from the start of the resource, as the search results do. Vendor segments are library code the classifier recognised; they are stored but not indexed. Bytes are shown as Latin1 characters, one per byte.