1(function ($) { 2 3 function getScrollY(elem){ 4 return window.pageYOffset || document.documentElement.scrollTop; 5 } 6 7 function Sticky(el, options) { 8 var self = this; 9 this.el = el; 10 this.$el = $(el); 11 12 this.options = { 13 }; 14 $.extend(this.options, options); 15 16 self.init(); 17 } 18 19 $.fn.scSticky = function(options) { 20 $(this).each(function() { 21 return new Sticky(this, options); 22 }); 23 } 24 25 Sticky.prototype = { 26 init: function() { 27 var self = this; 28 29 this.$wrapper = false; 30 31 this.$parent = this.getParent(); 32 33 $(window).scroll(function() { 34 if (self.useSticky()) { 35 self.wrap(); 36 self.scroll(); 37 } else { 38 self.unwrap(); 39 } 40 }); 41 42 $(window).resize(function() { 43 if (self.useSticky()) { 44 self.wrap(); 45 self.scroll(); 46 } else { 47 self.unwrap(); 48 } 49 }); 50 }, 51 52 wrap: function() { 53 if (!this.$wrapper) 54 this.$wrapper = this.$el.wrap('<div />').parent(); 55 56 this.$wrapper.attr('class', this.$el.attr('class')).addClass('sc-sticky-block').css({ 57 padding: 0, 58 height: this.$el.outerHeight() 59 }); 60 61 this.$el.css({ 62 width: this.$wrapper.outerWidth(), 63 margin: 0 64 }); 65 }, 66 67 getParent: function() { 68 return this.$el.parent(); 69 }, 70 71 useSticky: function() { 72 var is_sidebar = true; 73 if (this.$el.hasClass('sidebar')) { 74 if (this.$wrapper) { 75 if (this.$wrapper.outerHeight() > this.$wrapper.siblings('.panel-center:first').outerHeight()) 76 is_sidebar = false; 77 } else { 78 if (this.$el.outerHeight() > this.$el.siblings('.panel-center:first').outerHeight()) 79 is_sidebar = false; 80 } 81 } 82 83 return $(window).width() > 1000 && is_sidebar; 84 }, 85 86 unwrap: function() { 87 if (this.$el.parent().is('.sc-sticky-block')) { 88 this.$el.unwrap(); 89 this.$wrapper = false;
90 } 91 this.$el.css({ 92 width: "", 93 top: "", 94 bottom: "", 95 margin: "" 96 }); 97 }, 98 99 scroll: function() { 100 var top_offset = parseInt($('html').css('margin-top')); 101 102 var $header = $('#site-header'); 103 if ($header.hasClass('fixed')) { 104 top_offset += $header.outerHeight(); 105 } 106 107 var scroll = getScrollY(); 108 var offset = this.$wrapper.offset(); 109 var parent_offset = this.$parent.offset(); 110 var parent_bottom = parent_offset.top + this.$parent.outerHeight() - scroll; 111 var bottom = $(window).height() - parent_bottom; 112 113 if ( (top_offset + this.$el.outerHeight() ) >= parent_bottom ) { 114 this.$el.addClass('sticky-fixed').css({ 115 top: "", 116 bottom: bottom, 117 left: offset.left 118 }); 119 return; 120 } 121 122 if ( (scroll + top_offset) > offset.top ) { 123 this.$el.addClass('sticky-fixed').css({ 124 top: top_offset, 125 bottom: "", 126 left: offset.left 127 }); 128 } else { 129 this.$el.removeClass('sticky-fixed').css({ 130 top: "", 131 bottom: "", 132 left: "" 133 }); 134 } 135 } 136 }; 137 138}(jQuery));
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.