Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

@odopod/odo-affix

Package Overview
Dependencies
Maintainers
3
Versions
6
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@odopod/odo-affix - npm Package Compare versions

Comparing version 1.0.0 to 1.0.1

22

dist/odo-affix.js

@@ -10,2 +10,4 @@ (function (global, factory) {

var babelHelpers = {};
var classCallCheck = function (instance, Constructor) {

@@ -35,2 +37,10 @@ if (!(instance instanceof Constructor)) {

babelHelpers;
/**

@@ -356,7 +366,7 @@ * @fileoverview Emulates `position:sticky` to make an element fixed position

if (Affix._updateId) {
cancelAnimationFrame(Affix._updateId);
window.cancelAnimationFrame(Affix._updateId);
}
// Throttle updates to once per frame.
Affix._updateId = requestAnimationFrame(Affix._handleImageLoad);
Affix._updateId = window.requestAnimationFrame(Affix._handleImageLoad);
};

@@ -428,3 +438,3 @@

key: 'uiOverlap',
get: function get$$1() {
get: function get() {
if (this._customOverlap) {

@@ -442,3 +452,3 @@ return this._customOverlap();

,
set: function set$$1(fn) {
set: function set(fn) {
this._customOverlap = fn;

@@ -455,3 +465,3 @@ this.update();

key: 'top',
get: function get$$1() {
get: function get() {
return this._top - this._overlap;

@@ -467,3 +477,3 @@ }

key: 'bottom',
get: function get$$1() {
get: function get() {
return this._bottom - this._marginBottom;

@@ -470,0 +480,0 @@ }

@@ -1,2 +0,2 @@

!function(t,e){"object"==typeof exports&&"undefined"!=typeof module?module.exports=e(require("@odopod/odo-window-events"),require("@odopod/odo-scroll-animation")):"function"==typeof define&&define.amd?define(["@odopod/odo-window-events","@odopod/odo-scroll-animation"],e):t.OdoAffix=e(t.OdoWindowEvents,t.OdoScrollAnimation)}(this,function(t,e){"use strict";t=t&&t.hasOwnProperty("default")?t.default:t,e=e&&e.hasOwnProperty("default")?e.default:e;var i=function(t,e){if(!(t instanceof e))throw new TypeError("Cannot call a class as a function")},o=function(){function t(t,e){for(var i=0;i<e.length;i++){var o=e[i];o.enumerable=o.enumerable||!1,o.configurable=!0,"value"in o&&(o.writable=!0),Object.defineProperty(t,o.key,o)}}return function(e,i,o){return i&&t(e.prototype,i),o&&t(e,o),e}}(),s=function(){function s(t){if(i(this,s),this.element=t,this._anchor=document.getElementById(t.getAttribute("data-anchor")),!this._anchor)throw new Error('Unable to find element with id="'+t.getAttribute("data-anchor")+'"');this.isStuck=!1,this.isAtBottom=!1,this.isPromoted=!1,this._customOverlap=null,this._overlap=0,this._maxHeight=0,this._marginTop=0,this._marginBottom=0,this._top=0,this._bottom=0,this.containerHeight=0,this._scrollId=e.add(this.process.bind(this)),this.element.classList.add(s.Classes.BASE),this.element.style.overflowY="auto",s.instances.push(this),this.update()}return s.prototype.read=function(){var t=this._anchor.getBoundingClientRect(),e=window.pageYOffset,i=window.innerHeight,o=this.element.offsetHeight;this._asideWidth=this.element.offsetWidth;var s=getComputedStyle(this.element,null);this._marginTop=parseFloat(s.marginTop),this._marginBottom=parseFloat(s.marginBottom),this._overlap=this.uiOverlap,this._maxHeight=i-this._overlap-this._marginTop-this._marginBottom,this.containerHeight=Math.round(t.height),this._top=t.top+e,this._bottom=t.bottom+e-Math.min(o,this._maxHeight)},s.prototype.write=function(){this.element.style.maxHeight=this._maxHeight+"px",this.element.style.width=this._asideWidth+"px"},s.prototype.process=function(){var t=arguments.length>0&&void 0!==arguments[0]?arguments[0]:window.pageYOffset;!this.isStuck&&t>=this.top&&t<this.bottom||this.isAtBottom&&t<this.bottom?this.stick():!this.isAtBottom&&t>=this.bottom?this.stickToBottom():this.isStuck&&t<this.top&&this.unstick();var e=this.isInPromotionRange(t);!this.isPromoted&&e?this.layerPromote():this.isPromoted&&!e&&this.layerDemote()},s.prototype.isInPromotionRange=function(t){return t>=this.top-s.PROMOTION_RANGE&&t<=this.bottom+s.PROMOTION_RANGE},s.prototype.stick=function(){this.element.style.position="fixed",this.element.style.top=Math.round(this._overlap)+"px",this.element.classList.remove(s.Classes.AT_BOTTOM),this.element.classList.remove(s.Classes.AT_TOP),this.isStuck=!0,this.isAtBottom=!1},s.prototype.stickToBottom=function(){this.element.style.position="absolute",this.element.style.top=Math.round(this._bottom-this._top-this._marginBottom)+"px",this.element.classList.remove(s.Classes.AT_TOP),this.element.classList.add(s.Classes.AT_BOTTOM),this.isAtBottom=!0},s.prototype.unstick=function(){this.element.style.position="",this.element.classList.add(s.Classes.AT_TOP),this.element.classList.remove(s.Classes.AT_BOTTOM),this.isStuck=!1,this.isAtBottom=!1},s.prototype.layerPromote=function(){this.element.style.willChange="position",this.element.style.transform="translateZ(0)",this.isPromoted=!0},s.prototype.layerDemote=function(){this.element.style.willChange="",this.element.style.transform="",this.isPromoted=!1},s.prototype.reset=function(){this.element.style.maxHeight="",this.element.style.width=""},s.prototype.update=function(){var t=this.element.scrollTop;this.unstick(),this.reset(),this.read(),this.write(),this.process(),this.element.scrollTop=t},s.prototype.dispose=function(){this.layerDemote(),this.element.classList.remove(s.Classes.BASE),this.element.style.position="",this.element.style.top="",this.element.style.maxHeight="",this.element.style.width="",this.element.style.overflowY="",this.element=null,this._anchor=null,t.remove(this._resizeId),e.remove(this._scrollId),s.arrayRemove(s.instances,this)},s._addImageLoadHandlers=function(){for(var t=document.getElementsByTagName("img"),e=0,i=t.length;e<i;e++)t[e].addEventListener("load",s._scheduleUpdate,!1)},s._scheduleUpdate=function(){window.removeEventListener("load",s._scheduleUpdate),s._updateId&&cancelAnimationFrame(s._updateId),s._updateId=requestAnimationFrame(s._handleImageLoad)},s._handleImageLoad=function(){s._updateId=null,s.documentHeight=document.body.offsetHeight,s.viewportHeight=window.innerHeight,s.update()},s.update=function(){var t=window.pageYOffset,e=s.instances.map(function(t){return t.element.scrollTop});s.instances.forEach(function(t){t.unstick(),t.reset()}),s.instances.forEach(function(t){t.read()}),s.instances.forEach(function(e){e.write(),e.process(t)}),s.instances.forEach(function(t,i){t.element.scrollTop=e[i]})},s.arrayRemove=function(t,e){var i=t.indexOf(e);return t.splice(i,1),e},o(s,[{key:"uiOverlap",get:function(){return this._customOverlap?this._customOverlap():0},set:function(t){this._customOverlap=t,this.update()}},{key:"top",get:function(){return this._top-this._overlap}},{key:"bottom",get:function(){return this._bottom-this._marginBottom}}]),s}();return s.PROMOTION_RANGE=200,s.instances=[],s._updateId=null,s.documentHeight=document.body.offsetHeight,s.viewportHeight=window.innerHeight,s._addImageLoadHandlers(),s._resizeId=t.onResize(s._scheduleUpdate),window.addEventListener("load",s._scheduleUpdate),s.Classes={BASE:"odo-affix",AT_TOP:"odo-affix--at-top",AT_BOTTOM:"odo-affix--at-bottom"},s});
!function(t,e){"object"==typeof exports&&"undefined"!=typeof module?module.exports=e(require("@odopod/odo-window-events"),require("@odopod/odo-scroll-animation")):"function"==typeof define&&define.amd?define(["@odopod/odo-window-events","@odopod/odo-scroll-animation"],e):t.OdoAffix=e(t.OdoWindowEvents,t.OdoScrollAnimation)}(this,function(t,e){"use strict";t=t&&t.hasOwnProperty("default")?t.default:t,e=e&&e.hasOwnProperty("default")?e.default:e;var i=function(t,e){if(!(t instanceof e))throw new TypeError("Cannot call a class as a function")},o=function(){function t(t,e){for(var i=0;i<e.length;i++){var o=e[i];o.enumerable=o.enumerable||!1,o.configurable=!0,"value"in o&&(o.writable=!0),Object.defineProperty(t,o.key,o)}}return function(e,i,o){return i&&t(e.prototype,i),o&&t(e,o),e}}(),s=function(){function s(t){if(i(this,s),this.element=t,this._anchor=document.getElementById(t.getAttribute("data-anchor")),!this._anchor)throw new Error('Unable to find element with id="'+t.getAttribute("data-anchor")+'"');this.isStuck=!1,this.isAtBottom=!1,this.isPromoted=!1,this._customOverlap=null,this._overlap=0,this._maxHeight=0,this._marginTop=0,this._marginBottom=0,this._top=0,this._bottom=0,this.containerHeight=0,this._scrollId=e.add(this.process.bind(this)),this.element.classList.add(s.Classes.BASE),this.element.style.overflowY="auto",s.instances.push(this),this.update()}return s.prototype.read=function(){var t=this._anchor.getBoundingClientRect(),e=window.pageYOffset,i=window.innerHeight,o=this.element.offsetHeight;this._asideWidth=this.element.offsetWidth;var s=getComputedStyle(this.element,null);this._marginTop=parseFloat(s.marginTop),this._marginBottom=parseFloat(s.marginBottom),this._overlap=this.uiOverlap,this._maxHeight=i-this._overlap-this._marginTop-this._marginBottom,this.containerHeight=Math.round(t.height),this._top=t.top+e,this._bottom=t.bottom+e-Math.min(o,this._maxHeight)},s.prototype.write=function(){this.element.style.maxHeight=this._maxHeight+"px",this.element.style.width=this._asideWidth+"px"},s.prototype.process=function(){var t=arguments.length>0&&void 0!==arguments[0]?arguments[0]:window.pageYOffset;!this.isStuck&&t>=this.top&&t<this.bottom||this.isAtBottom&&t<this.bottom?this.stick():!this.isAtBottom&&t>=this.bottom?this.stickToBottom():this.isStuck&&t<this.top&&this.unstick();var e=this.isInPromotionRange(t);!this.isPromoted&&e?this.layerPromote():this.isPromoted&&!e&&this.layerDemote()},s.prototype.isInPromotionRange=function(t){return t>=this.top-s.PROMOTION_RANGE&&t<=this.bottom+s.PROMOTION_RANGE},s.prototype.stick=function(){this.element.style.position="fixed",this.element.style.top=Math.round(this._overlap)+"px",this.element.classList.remove(s.Classes.AT_BOTTOM),this.element.classList.remove(s.Classes.AT_TOP),this.isStuck=!0,this.isAtBottom=!1},s.prototype.stickToBottom=function(){this.element.style.position="absolute",this.element.style.top=Math.round(this._bottom-this._top-this._marginBottom)+"px",this.element.classList.remove(s.Classes.AT_TOP),this.element.classList.add(s.Classes.AT_BOTTOM),this.isAtBottom=!0},s.prototype.unstick=function(){this.element.style.position="",this.element.classList.add(s.Classes.AT_TOP),this.element.classList.remove(s.Classes.AT_BOTTOM),this.isStuck=!1,this.isAtBottom=!1},s.prototype.layerPromote=function(){this.element.style.willChange="position",this.element.style.transform="translateZ(0)",this.isPromoted=!0},s.prototype.layerDemote=function(){this.element.style.willChange="",this.element.style.transform="",this.isPromoted=!1},s.prototype.reset=function(){this.element.style.maxHeight="",this.element.style.width=""},s.prototype.update=function(){var t=this.element.scrollTop;this.unstick(),this.reset(),this.read(),this.write(),this.process(),this.element.scrollTop=t},s.prototype.dispose=function(){this.layerDemote(),this.element.classList.remove(s.Classes.BASE),this.element.style.position="",this.element.style.top="",this.element.style.maxHeight="",this.element.style.width="",this.element.style.overflowY="",this.element=null,this._anchor=null,t.remove(this._resizeId),e.remove(this._scrollId),s.arrayRemove(s.instances,this)},s._addImageLoadHandlers=function(){for(var t=document.getElementsByTagName("img"),e=0,i=t.length;e<i;e++)t[e].addEventListener("load",s._scheduleUpdate,!1)},s._scheduleUpdate=function(){window.removeEventListener("load",s._scheduleUpdate),s._updateId&&window.cancelAnimationFrame(s._updateId),s._updateId=window.requestAnimationFrame(s._handleImageLoad)},s._handleImageLoad=function(){s._updateId=null,s.documentHeight=document.body.offsetHeight,s.viewportHeight=window.innerHeight,s.update()},s.update=function(){var t=window.pageYOffset,e=s.instances.map(function(t){return t.element.scrollTop});s.instances.forEach(function(t){t.unstick(),t.reset()}),s.instances.forEach(function(t){t.read()}),s.instances.forEach(function(e){e.write(),e.process(t)}),s.instances.forEach(function(t,i){t.element.scrollTop=e[i]})},s.arrayRemove=function(t,e){var i=t.indexOf(e);return t.splice(i,1),e},o(s,[{key:"uiOverlap",get:function(){return this._customOverlap?this._customOverlap():0},set:function(t){this._customOverlap=t,this.update()}},{key:"top",get:function(){return this._top-this._overlap}},{key:"bottom",get:function(){return this._bottom-this._marginBottom}}]),s}();return s.PROMOTION_RANGE=200,s.instances=[],s._updateId=null,s.documentHeight=document.body.offsetHeight,s.viewportHeight=window.innerHeight,s._addImageLoadHandlers(),s._resizeId=t.onResize(s._scheduleUpdate),window.addEventListener("load",s._scheduleUpdate),s.Classes={BASE:"odo-affix",AT_TOP:"odo-affix--at-top",AT_BOTTOM:"odo-affix--at-bottom"},s});
//# sourceMappingURL=odo-affix.min.js.map
{
"name": "@odopod/odo-affix",
"description": "Makes an element fixed position while its within a container.",
"version": "1.0.0",
"version": "1.0.1",
"main": "dist/odo-affix.js",

@@ -15,6 +15,5 @@ "odoModule": "src/affix.js",

"dependencies": {
"@odopod/odo-scroll-animation": "^1.0.0",
"@odopod/odo-window-events": "^1.0.0"
"@odopod/odo-scroll-animation": "^1.0.1",
"@odopod/odo-window-events": "^1.0.1"
},
"devDependencies": {},
"homepage": "https://github.com/odopod/code-library/tree/master/packages/odo-affix",

@@ -40,5 +39,4 @@ "files": [

"scripts": {
"link-local": "node ../../scripts/link-local-packages.js",
"test": "gulp code-quality test"
}
}

@@ -23,2 +23,2 @@ # Odo Affix

[permalink]: https://odopod.github.io/odo/odo-affix/
[permalink]: https://code.odopod.com/odo-affix/

@@ -329,7 +329,7 @@ /**

if (Affix._updateId) {
cancelAnimationFrame(Affix._updateId);
window.cancelAnimationFrame(Affix._updateId);
}
// Throttle updates to once per frame.
Affix._updateId = requestAnimationFrame(Affix._handleImageLoad);
Affix._updateId = window.requestAnimationFrame(Affix._handleImageLoad);
}

@@ -336,0 +336,0 @@

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc