1(function (global, factory) { 2 typeof exports === 'object' && typeof module !== 'undefined' ? module.exports = factory() : 3 typeof define === 'function' && define.amd ? define(factory) : 4 (global.Headspace = factory()); 5}(this, function () { 'use strict'; 6 7 function Headspace(element) { 8 var opts = arguments.length <= 1 || arguments[1] === undefined ? {} : arguments[1]; 9 10 if (!(this instanceof Headspace)) { 11 return new (Function.prototype.bind.apply(Headspace, [null].concat(Array.prototype.slice.call(arguments))))(); 12 } 13 14 this.element = element; 15 this.startOffset = optionOrDefault(opts.startOffset, element && element.offsetHeight); 16 this.tolerance = optionOrDefault(opts.tolerance, 8); 17 this.showAtBottom = optionOrDefault(opts.showAtBottom, true); 18 this.classNames = opts.classNames || { 19 base: 'headspace', 20 fixed: 'headspace--fixed', 21 hidden: 'headspace--hidden' 22 }; 23 24 this._scrollLast = 0; 25 if (typeof window !== 'undefined') { 26 this.init(); 27 } 28 } 29 30 Headspace.prototype = { 31 init: function init() { 32 var _this = this; 33 34 this.addClass(this.classNames.base); 35 window.addEventListener('scroll', function () { 36 return _this.debounce(function () { 37 return handleScroll(_this); 38 }); 39 }); 40 }, 41 reset: function reset() { 42 var classNames = this.classNames; 43 this.removeClass(classNames.fixed, classNames.hidden); 44 }, 45 fix: function fix() { 46 var classNames = this.classNames; 47 this.addClass(classNames.fixed); 48 this.removeClass(classNames.hidden); 49 }, 50 hide: function hide() { 51 this.addClass(this.classNames.hidden); 52 }, 53 54 // Accessible for shimming 55 addClass: function addClass() { 56 var _element$classList; 57 58 (_element$classList = this.element.classList).add.apply(_element$classList, arguments); 59 }, 60 removeClass: function removeClass() { 61 var _element$classList2; 62 63 (_element$classList2 = this.element.classList).remove.apply(_element$classList2, arguments); 64 }, 65 debounce: function debounce(callback) { 66 window.requestAnimationFrame(callback); 67 } 68 }; 69 70 Headspace.isSupported = function () { 71 return !!(typeof window !== 'undefined' && window.requestAnimationFrame && 'classList' in document.documentElement); 72 }; 73 74 function optionOrDefault(opt, def) { 75 return typeof opt !== 'undefined' ? opt : def; 76 } 77 78 function handleScroll(instance) { 79 var scrollCurrent = window.pageYOffset; 80 var scrollLast = instance._scrollLast; 81 82 if (scrollCurrent <= 0) { 83 instance.reset(); 84 } else if (instance.showAtBottom && window.innerHeight + scrollCurrent >= document.body.offsetHeight) { 85 instance.fix(); 86 } else if (scrollCurrent > instance.startOffset && Math.abs(scrollCurrent - scrollLast) >= instance.tolerance) { 87 instance[scrollCurrent > scrollLast ? 'hide' : 'fix'](); 88 } 89 90 instance._scrollLast = scrollCurrent; 91 } 92 93 return Headspace; 94 95}));
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.