1/** 2 * Sticky blocks wrapper. 3 * 4 * @author Htmlstream 5 * @version 1.0 6 * @requires 7 * 8 */ 9;(function ($) { 10 'use strict'; 11 12 $.HSCore.components.HSStickyBlock = { 13 /** 14 * 15 * 16 * @var Object _baseConfig 17 */ 18 _baseConfig: {}, 19 20 /** 21 * 22 * 23 * @var jQuery pageCollection 24 */ 25 pageCollection: $(), 26 27 /** 28 * Initialization of Sticky blocks wrapper. 29 * 30 * @param String selector (optional) 31 * @param Object config (optional) 32 * 33 * @return jQuery pageCollection - collection of initialized items. 34 */ 35 36 init: function (selector, config) { 37 this.collection = selector && $(selector).length ? $(selector) : $(); 38 if (!$(selector).length) return; 39 40 this.config = config && $.isPlainObject(config) ? 41 $.extend({}, this._baseConfig, config) : this._baseConfig; 42 43 this.config.itemSelector = selector; 44 45 this.initStickyBlock(); 46 47 return this.pageCollection; 48 }, 49 50 initStickyBlock: function () { 51 //Variables 52 var $self = this, 53 config = $self.config, 54 collection = $self.pageCollection, 55 windW = window.innerWidth; 56 57 this.collection.each(function (i, el) { 58 //Variables 59 var $stickyBlock = $(el), 60 stickyBlockClasses = $stickyBlock.attr('class').replace($self.config.itemSelector.substring(1), ''), 61 stickyBlockH = $stickyBlock.outerHeight(), 62 stickyBlockW = $stickyBlock.outerWidth(), 63 stickyBlockParentW = $stickyBlock.parent().width(), 64 stickyBlockOffsetTop = $stickyBlock.offset().top, 65 stickyBlockOffsetLeft = $stickyBlock.offset().left, 66 startPoint = $.isNumeric($stickyBlock.data('start-point')) ? $stickyBlock.data('start-point') : $($stickyBlock.data('start-point')).offset().top, 67 endPoint = $.isNumeric($stickyBlock.data('end-point')) ? $stickyBlock.data('end-point') : $($stickyBlock.data('end-point')).offset().top, 68 hasStickyHeader = $stickyBlock.data('has-sticky-header'), 69 stickyView = $stickyBlock.data('sticky-view'), 70 offsetTarget = $stickyBlock.data('offset-target'), 71 offsetTargetH = $(offsetTarget).outerHeight(), 72 stickyOffsetTop = $stickyBlock.data('offset-top'), 73 stickyOffsetBottom = $stickyBlock.data('offset-bottom'); 74 75 $('.collapse').on('hidden.bs.collapse', function () { 76 endPoint = $.isNumeric($stickyBlock.data('end-point')) ? $stickyBlock.data('end-point') : $($stickyBlock.data('end-point')).offset().top; 77 }); 78 79 $('.collapse').on('shown.bs.collapse', function () { 80 endPoint = $.isNumeric($stickyBlock.data('end-point')) ? $stickyBlock.data('end-point') : $($stickyBlock.data('end-point')).offset().top; 81 }); 82 83 //Break function if there are no target element 84 if (!$stickyBlock.length) return; 85 if (stickyBlockH > (endPoint - startPoint)) return; 86 87 $self.killSticky($stickyBlock); 88 89 if (stickyView == 'sm' && windW <= 576) { 90 $stickyBlock.addClass('die-sticky'); 91 $self.killSticky($stickyBlock); 92 } else if (stickyView == 'md' && windW <= 768) { 93 $stickyBlock.addClass('die-sticky'); 94 $self.killSticky($stickyBlock); 95 } else if (stickyView == 'lg' && windW <= 992) { 96 $stickyBlock.addClass('die-sticky'); 97 $self.killSticky($stickyBlock); 98 } else if (stickyView == 'xl' && windW <= 1200) { 99 $stickyBlock.addClass('die-sticky'); 100 $self.killSticky($stickyBlock); 101 } else { 102 $stickyBlock.removeClass('die-sticky'); 103 } 104 105 $(window).on('resize', function () { 106 var windW = window.innerWidth; 107 108 $stickyBlock.css({ 109 'height': '' 110 }); 111 112 if (stickyView == 'sm' && windW <= 576) { 113 $stickyBlock.addClass('die-sticky'); 114 $self.killSticky($stickyBlock); 115 } else if (stickyView == 'md' && windW <= 768) { 116 $stickyBlock.addClass('die-sticky'); 117 $self.killSticky($stickyBlock); 118 } else if (stickyView == 'lg' && windW <= 992) { 119 $stickyBlock.addClass('die-sticky'); 120 $self.killSticky($stickyBlock); 121 } else if (stickyView == 'xl' && windW <= 1200) { 122 $stickyBlock.addClass('die-sticky'); 123 $self.killSticky($stickyBlock); 124 } else { 125 $stickyBlock 126 .removeClass('die-sticky') 127 .css({ 128 'top': '', 129 'left': '' 130 }); 131 } 132 133 setTimeout(function () { 134 var offsetTop = $(this).scrollTop(); 135 stickyBlockH = $stickyBlock.outerHeight(), 136 stickyBlockW = $stickyBlock.outerWidth(), 137 stickyBlockParentW = $stickyBlock.parent().width(), 138 stickyBlockOffsetTop = $stickyBlock.offset().top, 139 stickyBlockOffsetLeft = $stickyBlock.offset().left, 140 startPoint = $.isNumeric($stickyBlock.data('start-point')) ? $stickyBlock.data('start-point') : $($stickyBlock.data('start-point')).offset().top, 141 endPoint = $.isNumeric($stickyBlock.data('end-point')) ? $stickyBlock.data('end-point') : $($stickyBlock.data('end-point')).offset().top, 142 offsetTargetH = $(offsetTarget).outerHeight(); 143 144 if (hasStickyHeader === true) { 145 $stickyBlock 146 .not('.die-sticky') 147 .css({ 148 'top': offsetTop + offsetTargetH >
148= (endPoint - stickyBlockH) ? endPoint - stickyBlockH - stickyBlockOffsetTop : offsetTargetH, 149 'left': stickyBlockOffsetLeft, 150 'width': stickyBlockParentW 151 }); 152 } else { 153 $stickyBlock 154 .not('.die-sticky') 155 .css({ 156 'top': offsetTop >= (endPoint - stickyBlockH) ? endPoint - stickyBlockH - stickyBlockOffsetTop : 0, 157 'left': stickyBlockOffsetLeft, 158 'width': stickyBlockParentW 159 }); 160 } 161 }, 400); 162 }); 163 164 var offsetTop = $(this).scrollTop(); 165 166 //Add responsive sticky state 167 $self.addShadow($stickyBlock, hasStickyHeader ? offsetTop + offsetTargetH : offsetTop, stickyBlockH, stickyBlockW, i, stickyBlockClasses, startPoint, endPoint); 168 169 //Add sticky state 170 $self.addSticky($stickyBlock, hasStickyHeader ? offsetTop + offsetTargetH : offsetTop, stickyBlockH, stickyBlockParentW, stickyBlockOffsetLeft, startPoint, endPoint); 171 172 $(window).on('scroll', function () { 173 var offsetTop = $(this).scrollTop(); 174 175 //Add "shadow" element 176 $self.addShadow($stickyBlock, hasStickyHeader ? offsetTop + offsetTargetH : offsetTop, stickyBlockH, stickyBlockParentW, i, stickyBlockClasses, startPoint, endPoint, stickyOffsetTop); 177 178 //Add sticky state 179 $self.addSticky($stickyBlock, hasStickyHeader ? offsetTop + offsetTargetH : offsetTop, stickyBlockH, stickyBlockParentW, stickyBlockOffsetLeft, startPoint, endPoint, hasStickyHeader ? offsetTargetH : 0, stickyOffsetTop); 180 181 //Remove sticky state 182 $self.removeSticky($stickyBlock, hasStickyHeader ? offsetTop + offsetTargetH : offsetTop, startPoint, stickyOffsetTop); 183 184 if (endPoint) { 185 //Add absolute state 186 $self.addAbsolute($stickyBlock, stickyBlockH, i, stickyBlockOffsetTop, hasStickyHeader ? offsetTop + offsetTargetH : offsetTop, endPoint, stickyOffsetTop, stickyOffsetBottom); 187 } 188 }); 189 190 $(window).trigger('scroll'); 191 192 $('a[href="#"],a[href="#!"]').on('click', function() { 193 $self.killSticky($stickyBlock); 194 }); 195 196 //Add object to collection 197 collection = collection.add($stickyBlock); 198 }); 199 }, 200 201 addSticky: function (target, offsetTop, targetH, targetW, offsetLeft, startPoint, endPoint, offsetTargetH, stickyOffsetTop) { 202 if (offsetTop >= startPoint - stickyOffsetTop && offsetTop < endPoint) { 203 target 204 .not('.die-sticky') 205 .removeClass('position-relative') 206 .css({ 207 'top': '', 208 'left': '', 209 'width': '', 210 'height': '' 211 }) 212 .addClass('position-fixed m-0') 213 .css({ 214 'top': offsetTargetH + stickyOffsetTop, 215 'left': offsetLeft, 216 'width': targetW, 217 'height': targetH 218 }); 219 } 220 }, 221 222 removeSticky: function (target, offsetTop, startPoint, stickyOffsetTop) { 223 if (offsetTop <= startPoint - stickyOffsetTop) { 224 target 225 .not('.die-sticky') 226 .removeClass('position-fixed m-0') 227 .css({ 228 'left': '' 229 }); 230 } 231 }, 232 233 addAbsolute: function (target, targetH, targetI, targetOffsetTop, offsetTop, endPoint, stickyOffsetTop, stickyOffsetBottom) { 234 if (target.hasClass('position-relative')) return; 235 236 if (offsetTop >= endPoint - targetH - stickyOffsetTop - stickyOffsetBottom) { 237 target 238 .not('.die-sticky') 239 .removeClass('position-fixed m-0') 240 .addClass('position-relative') 241 .css({ 242 'top': endPoint - targetH - targetOffsetTop - stickyOffsetBottom, 243 'left': '' 244 }); 245 } 246 }, 247 248 addShadow: function (target, offsetTop, targetH, targetW, targetI, targetClasses, startPoint, endPoint, stickyOffsetTop, stickyOffsetBottom) { 249 if (offsetTop > startPoint - stickyOffsetTop && offsetTop < endPoint - targetH - stickyOffsetBottom) { 250 if ($('#shadow' + targetI).length) return; 251 252 //Add shadow block 253 target 254 .not('.die-sticky') 255 .before('<div id="shadow' + targetI + '" class="' + targetClasses + '" style="height: ' + targetH + 'px; width: ' + targetW + 'px; margin-top: ' + stickyOffsetTop + 'px; background-color: transparent !important;"></div>'); 256 } else { 257 if (!$('#shadow' + targetI).length) return; 258 259 //Remove shadow block 260 $('#shadow' + targetI).remove(); 261 } 262 }, 263 264 killSticky: function (target) { 265 target 266 .removeClass('position-fixed m-0') 267 .css({ 268 'top': '', 269 'left': '', 270 'width': '', 271 'height': '', 272 'z-index': '1' 273 }); 274 } 275 } 276})(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.