headroom.js
Advanced tools
Comparing version 0.7.1 to 0.8.0
/*! | ||
* headroom.js v0.7.0 - Give your page some headroom. Hide your header until you need it | ||
* Copyright (c) 2015 Nick Williams - http://wicky.nillia.ms/headroom.js | ||
* headroom.js v0.8.0 - Give your page some headroom. Hide your header until you need it | ||
* Copyright (c) 2016 Nick Williams - http://wicky.nillia.ms/headroom.js | ||
* License: MIT | ||
@@ -32,3 +32,3 @@ */ | ||
if (options.scroller) { | ||
options.scroller = angular.element(options.scroller)[0]; | ||
options.scroller = document.querySelector(options.scroller); | ||
} | ||
@@ -35,0 +35,0 @@ var headroom = new Headroom(element[0], options); |
/*! | ||
* headroom.js v0.7.0 - Give your page some headroom. Hide your header until you need it | ||
* Copyright (c) 2015 Nick Williams - http://wicky.nillia.ms/headroom.js | ||
* headroom.js v0.8.0 - Give your page some headroom. Hide your header until you need it | ||
* Copyright (c) 2016 Nick Williams - http://wicky.nillia.ms/headroom.js | ||
* License: MIT | ||
*/ | ||
!function(a){a&&a.module("headroom",[]).directive("headroom",function(){return{restrict:"EA",scope:{tolerance:"=",offset:"=",classes:"=",scroller:"@"},link:function(b,c){var d={};a.forEach(Headroom.options,function(a,c){d[c]=b[c]||Headroom.options[c]}),d.scroller&&(d.scroller=a.element(d.scroller)[0]);var e=new Headroom(c[0],d);e.init(),b.$on("$destroy",function(){e.destroy()})}}})}(window.angular); | ||
!function(a){a&&a.module("headroom",[]).directive("headroom",function(){return{restrict:"EA",scope:{tolerance:"=",offset:"=",classes:"=",scroller:"@"},link:function(b,c){var d={};a.forEach(Headroom.options,function(a,c){d[c]=b[c]||Headroom.options[c]}),d.scroller&&(d.scroller=document.querySelector(d.scroller));var e=new Headroom(c[0],d);e.init(),b.$on("$destroy",function(){e.destroy()})}}})}(window.angular); |
/*! | ||
* headroom.js v0.7.0 - Give your page some headroom. Hide your header until you need it | ||
* Copyright (c) 2015 Nick Williams - http://wicky.nillia.ms/headroom.js | ||
* headroom.js v0.8.0 - Give your page some headroom. Hide your header until you need it | ||
* Copyright (c) 2016 Nick Williams - http://wicky.nillia.ms/headroom.js | ||
* License: MIT | ||
@@ -131,3 +131,2 @@ */ | ||
this.elem = elem; | ||
this.debouncer = new Debouncer(this.update.bind(this)); | ||
this.tolerance = normalizeTolerance(options.tolerance); | ||
@@ -142,2 +141,4 @@ this.classes = options.classes; | ||
this.onNotTop = options.onNotTop; | ||
this.onBottom = options.onBottom; | ||
this.onNotBottom = options.onNotBottom; | ||
} | ||
@@ -155,2 +156,3 @@ Headroom.prototype = { | ||
this.debouncer = new Debouncer(this.update.bind(this)); | ||
this.elem.classList.add(this.classes.initial); | ||
@@ -172,3 +174,3 @@ | ||
this.initialised = false; | ||
this.elem.classList.remove(classes.unpinned, classes.pinned, classes.top, classes.initial); | ||
this.elem.classList.remove(classes.unpinned, classes.pinned, classes.top, classes.notTop, classes.initial); | ||
this.scroller.removeEventListener('scroll', this.debouncer, false); | ||
@@ -247,3 +249,28 @@ }, | ||
bottom : function() { | ||
var classList = this.elem.classList, | ||
classes = this.classes; | ||
if(!classList.contains(classes.bottom)) { | ||
classList.add(classes.bottom); | ||
classList.remove(classes.notBottom); | ||
this.onBottom && this.onBottom.call(this); | ||
} | ||
}, | ||
/** | ||
* Handles the not top state | ||
*/ | ||
notBottom : function() { | ||
var classList = this.elem.classList, | ||
classes = this.classes; | ||
if(!classList.contains(classes.notBottom)) { | ||
classList.add(classes.notBottom); | ||
classList.remove(classes.bottom); | ||
this.onNotBottom && this.onNotBottom.call(this); | ||
} | ||
}, | ||
/** | ||
* Gets the Y scroll position | ||
@@ -273,2 +300,24 @@ * @see https://developer.mozilla.org/en-US/docs/Web/API/Window.scrollY | ||
/** | ||
* Gets the physical height of the DOM element | ||
* @param {Object} elm the element to calculate the physical height of which | ||
* @return {int} the physical height of the element in pixels | ||
*/ | ||
getElementPhysicalHeight : function (elm) { | ||
return Math.max( | ||
elm.offsetHeight, | ||
elm.clientHeight | ||
); | ||
}, | ||
/** | ||
* Gets the physical height of the scroller element | ||
* @return {int} the physical height of the scroller element in pixels | ||
*/ | ||
getScrollerPhysicalHeight : function () { | ||
return (this.scroller === window || this.scroller === document.body) | ||
? this.getViewportHeight() | ||
: this.getElementPhysicalHeight(this.scroller); | ||
}, | ||
/** | ||
* Gets the height of the document | ||
@@ -319,3 +368,3 @@ * @see http://james.padolsey.com/javascript/get-document-height-cross-browser/ | ||
var pastTop = currentScrollY < 0, | ||
pastBottom = currentScrollY + this.getViewportHeight() > this.getScrollerHeight(); | ||
pastBottom = currentScrollY + this.getScrollerPhysicalHeight() > this.getScrollerHeight(); | ||
@@ -378,2 +427,9 @@ return pastTop || pastBottom; | ||
if(currentScrollY + this.getViewportHeight() >= this.getScrollerHeight()) { | ||
this.bottom(); | ||
} | ||
else { | ||
this.notBottom(); | ||
} | ||
if(this.shouldUnpin(currentScrollY, toleranceExceeded)) { | ||
@@ -405,2 +461,4 @@ this.unpin(); | ||
notTop : 'headroom--not-top', | ||
bottom : 'headroom--bottom', | ||
notBottom : 'headroom--not-bottom', | ||
initial : 'headroom' | ||
@@ -407,0 +465,0 @@ } |
/*! | ||
* headroom.js v0.7.0 - Give your page some headroom. Hide your header until you need it | ||
* Copyright (c) 2015 Nick Williams - http://wicky.nillia.ms/headroom.js | ||
* headroom.js v0.8.0 - Give your page some headroom. Hide your header until you need it | ||
* Copyright (c) 2016 Nick Williams - http://wicky.nillia.ms/headroom.js | ||
* License: MIT | ||
*/ | ||
!function(a,b){"use strict";"function"==typeof define&&define.amd?define([],b):"object"==typeof exports?module.exports=b():a.Headroom=b()}(this,function(){"use strict";function a(a){this.callback=a,this.ticking=!1}function b(a){return a&&"undefined"!=typeof window&&(a===window||a.nodeType)}function c(a){if(arguments.length<=0)throw new Error("Missing arguments in extend function");var d,e,f=a||{};for(e=1;e<arguments.length;e++){var g=arguments[e]||{};for(d in g)"object"!=typeof f[d]||b(f[d])?f[d]=f[d]||g[d]:f[d]=c(f[d],g[d])}return f}function d(a){return a===Object(a)?a:{down:a,up:a}}function e(b,f){f=c(f,e.options),this.lastKnownScrollY=0,this.elem=b,this.debouncer=new a(this.update.bind(this)),this.tolerance=d(f.tolerance),this.classes=f.classes,this.offset=f.offset,this.scroller=f.scroller,this.initialised=!1,this.onPin=f.onPin,this.onUnpin=f.onUnpin,this.onTop=f.onTop,this.onNotTop=f.onNotTop}var f={bind:!!function(){}.bind,classList:"classList"in document.documentElement,rAF:!!(window.requestAnimationFrame||window.webkitRequestAnimationFrame||window.mozRequestAnimationFrame)};return window.requestAnimationFrame=window.requestAnimationFrame||window.webkitRequestAnimationFrame||window.mozRequestAnimationFrame,a.prototype={constructor:a,update:function(){this.callback&&this.callback(),this.ticking=!1},requestTick:function(){this.ticking||(requestAnimationFrame(this.rafCallback||(this.rafCallback=this.update.bind(this))),this.ticking=!0)},handleEvent:function(){this.requestTick()}},e.prototype={constructor:e,init:function(){return e.cutsTheMustard?(this.elem.classList.add(this.classes.initial),setTimeout(this.attachEvent.bind(this),100),this):void 0},destroy:function(){var a=this.classes;this.initialised=!1,this.elem.classList.remove(a.unpinned,a.pinned,a.top,a.initial),this.scroller.removeEventListener("scroll",this.debouncer,!1)},attachEvent:function(){this.initialised||(this.lastKnownScrollY=this.getScrollY(),this.initialised=!0,this.scroller.addEventListener("scroll",this.debouncer,!1),this.debouncer.handleEvent())},unpin:function(){var a=this.elem.classList,b=this.classes;(a.contains(b.pinned)||!a.contains(b.unpinned))&&(a.add(b.unpinned),a.remove(b.pinned),this.onUnpin&&this.onUnpin.call(this))},pin:function(){var a=this.elem.classList,b=this.classes;a.contains(b.unpinned)&&(a.remove(b.unpinned),a.add(b.pinned),this.onPin&&this.onPin.call(this))},top:function(){var a=this.elem.classList,b=this.classes;a.contains(b.top)||(a.add(b.top),a.remove(b.notTop),this.onTop&&this.onTop.call(this))},notTop:function(){var a=this.elem.classList,b=this.classes;a.contains(b.notTop)||(a.add(b.notTop),a.remove(b.top),this.onNotTop&&this.onNotTop.call(this))},getScrollY:function(){return void 0!==this.scroller.pageYOffset?this.scroller.pageYOffset:void 0!==this.scroller.scrollTop?this.scroller.scrollTop:(document.documentElement||document.body.parentNode||document.body).scrollTop},getViewportHeight:function(){return window.innerHeight||document.documentElement.clientHeight||document.body.clientHeight},getDocumentHeight:function(){var a=document.body,b=document.documentElement;return Math.max(a.scrollHeight,b.scrollHeight,a.offsetHeight,b.offsetHeight,a.clientHeight,b.clientHeight)},getElementHeight:function(a){return Math.max(a.scrollHeight,a.offsetHeight,a.clientHeight)},getScrollerHeight:function(){return this.scroller===window||this.scroller===document.body?this.getDocumentHeight():this.getElementHeight(this.scroller)},isOutOfBounds:function(a){var b=0>a,c=a+this.getViewportHeight()>this.getScrollerHeight();return b||c},toleranceExceeded:function(a,b){return Math.abs(a-this.lastKnownScrollY)>=this.tolerance[b]},shouldUnpin:function(a,b){var c=a>this.lastKnownScrollY,d=a>=this.offset;return c&&d&&b},shouldPin:function(a,b){var c=a<this.lastKnownScrollY,d=a<=this.offset;return c&&b||d},update:function(){var a=this.getScrollY(),b=a>this.lastKnownScrollY?"down":"up",c=this.toleranceExceeded(a,b);this.isOutOfBounds(a)||(a<=this.offset?this.top():this.notTop(),this.shouldUnpin(a,c)?this.unpin():this.shouldPin(a,c)&&this.pin(),this.lastKnownScrollY=a)}},e.options={tolerance:{up:0,down:0},offset:0,scroller:window,classes:{pinned:"headroom--pinned",unpinned:"headroom--unpinned",top:"headroom--top",notTop:"headroom--not-top",initial:"headroom"}},e.cutsTheMustard="undefined"!=typeof f&&f.rAF&&f.bind&&f.classList,e}); | ||
!function(a,b){"use strict";"function"==typeof define&&define.amd?define([],b):"object"==typeof exports?module.exports=b():a.Headroom=b()}(this,function(){"use strict";function a(a){this.callback=a,this.ticking=!1}function b(a){return a&&"undefined"!=typeof window&&(a===window||a.nodeType)}function c(a){if(arguments.length<=0)throw new Error("Missing arguments in extend function");var d,e,f=a||{};for(e=1;e<arguments.length;e++){var g=arguments[e]||{};for(d in g)"object"!=typeof f[d]||b(f[d])?f[d]=f[d]||g[d]:f[d]=c(f[d],g[d])}return f}function d(a){return a===Object(a)?a:{down:a,up:a}}function e(a,b){b=c(b,e.options),this.lastKnownScrollY=0,this.elem=a,this.tolerance=d(b.tolerance),this.classes=b.classes,this.offset=b.offset,this.scroller=b.scroller,this.initialised=!1,this.onPin=b.onPin,this.onUnpin=b.onUnpin,this.onTop=b.onTop,this.onNotTop=b.onNotTop,this.onBottom=b.onBottom,this.onNotBottom=b.onNotBottom}var f={bind:!!function(){}.bind,classList:"classList"in document.documentElement,rAF:!!(window.requestAnimationFrame||window.webkitRequestAnimationFrame||window.mozRequestAnimationFrame)};return window.requestAnimationFrame=window.requestAnimationFrame||window.webkitRequestAnimationFrame||window.mozRequestAnimationFrame,a.prototype={constructor:a,update:function(){this.callback&&this.callback(),this.ticking=!1},requestTick:function(){this.ticking||(requestAnimationFrame(this.rafCallback||(this.rafCallback=this.update.bind(this))),this.ticking=!0)},handleEvent:function(){this.requestTick()}},e.prototype={constructor:e,init:function(){return e.cutsTheMustard?(this.debouncer=new a(this.update.bind(this)),this.elem.classList.add(this.classes.initial),setTimeout(this.attachEvent.bind(this),100),this):void 0},destroy:function(){var a=this.classes;this.initialised=!1,this.elem.classList.remove(a.unpinned,a.pinned,a.top,a.notTop,a.initial),this.scroller.removeEventListener("scroll",this.debouncer,!1)},attachEvent:function(){this.initialised||(this.lastKnownScrollY=this.getScrollY(),this.initialised=!0,this.scroller.addEventListener("scroll",this.debouncer,!1),this.debouncer.handleEvent())},unpin:function(){var a=this.elem.classList,b=this.classes;!a.contains(b.pinned)&&a.contains(b.unpinned)||(a.add(b.unpinned),a.remove(b.pinned),this.onUnpin&&this.onUnpin.call(this))},pin:function(){var a=this.elem.classList,b=this.classes;a.contains(b.unpinned)&&(a.remove(b.unpinned),a.add(b.pinned),this.onPin&&this.onPin.call(this))},top:function(){var a=this.elem.classList,b=this.classes;a.contains(b.top)||(a.add(b.top),a.remove(b.notTop),this.onTop&&this.onTop.call(this))},notTop:function(){var a=this.elem.classList,b=this.classes;a.contains(b.notTop)||(a.add(b.notTop),a.remove(b.top),this.onNotTop&&this.onNotTop.call(this))},bottom:function(){var a=this.elem.classList,b=this.classes;a.contains(b.bottom)||(a.add(b.bottom),a.remove(b.notBottom),this.onBottom&&this.onBottom.call(this))},notBottom:function(){var a=this.elem.classList,b=this.classes;a.contains(b.notBottom)||(a.add(b.notBottom),a.remove(b.bottom),this.onNotBottom&&this.onNotBottom.call(this))},getScrollY:function(){return void 0!==this.scroller.pageYOffset?this.scroller.pageYOffset:void 0!==this.scroller.scrollTop?this.scroller.scrollTop:(document.documentElement||document.body.parentNode||document.body).scrollTop},getViewportHeight:function(){return window.innerHeight||document.documentElement.clientHeight||document.body.clientHeight},getElementPhysicalHeight:function(a){return Math.max(a.offsetHeight,a.clientHeight)},getScrollerPhysicalHeight:function(){return this.scroller===window||this.scroller===document.body?this.getViewportHeight():this.getElementPhysicalHeight(this.scroller)},getDocumentHeight:function(){var a=document.body,b=document.documentElement;return Math.max(a.scrollHeight,b.scrollHeight,a.offsetHeight,b.offsetHeight,a.clientHeight,b.clientHeight)},getElementHeight:function(a){return Math.max(a.scrollHeight,a.offsetHeight,a.clientHeight)},getScrollerHeight:function(){return this.scroller===window||this.scroller===document.body?this.getDocumentHeight():this.getElementHeight(this.scroller)},isOutOfBounds:function(a){var b=0>a,c=a+this.getScrollerPhysicalHeight()>this.getScrollerHeight();return b||c},toleranceExceeded:function(a,b){return Math.abs(a-this.lastKnownScrollY)>=this.tolerance[b]},shouldUnpin:function(a,b){var c=a>this.lastKnownScrollY,d=a>=this.offset;return c&&d&&b},shouldPin:function(a,b){var c=a<this.lastKnownScrollY,d=a<=this.offset;return c&&b||d},update:function(){var a=this.getScrollY(),b=a>this.lastKnownScrollY?"down":"up",c=this.toleranceExceeded(a,b);this.isOutOfBounds(a)||(a<=this.offset?this.top():this.notTop(),a+this.getViewportHeight()>=this.getScrollerHeight()?this.bottom():this.notBottom(),this.shouldUnpin(a,c)?this.unpin():this.shouldPin(a,c)&&this.pin(),this.lastKnownScrollY=a)}},e.options={tolerance:{up:0,down:0},offset:0,scroller:window,classes:{pinned:"headroom--pinned",unpinned:"headroom--unpinned",top:"headroom--top",notTop:"headroom--not-top",bottom:"headroom--bottom",notBottom:"headroom--not-bottom",initial:"headroom"}},e.cutsTheMustard="undefined"!=typeof f&&f.rAF&&f.bind&&f.classList,e}); |
/*! | ||
* headroom.js v0.7.0 - Give your page some headroom. Hide your header until you need it | ||
* Copyright (c) 2015 Nick Williams - http://wicky.nillia.ms/headroom.js | ||
* headroom.js v0.8.0 - Give your page some headroom. Hide your header until you need it | ||
* Copyright (c) 2016 Nick Williams - http://wicky.nillia.ms/headroom.js | ||
* License: MIT | ||
@@ -32,2 +32,6 @@ */ | ||
data[option](); | ||
if(option === 'destroy'){ | ||
$this.removeData('headroom'); | ||
} | ||
} | ||
@@ -34,0 +38,0 @@ }); |
/*! | ||
* headroom.js v0.7.0 - Give your page some headroom. Hide your header until you need it | ||
* Copyright (c) 2015 Nick Williams - http://wicky.nillia.ms/headroom.js | ||
* headroom.js v0.8.0 - Give your page some headroom. Hide your header until you need it | ||
* Copyright (c) 2016 Nick Williams - http://wicky.nillia.ms/headroom.js | ||
* License: MIT | ||
*/ | ||
!function(a){a&&(a.fn.headroom=function(b){return this.each(function(){var c=a(this),d=c.data("headroom"),e="object"==typeof b&&b;e=a.extend(!0,{},Headroom.options,e),d||(d=new Headroom(this,e),d.init(),c.data("headroom",d)),"string"==typeof b&&d[b]()})},a("[data-headroom]").each(function(){var b=a(this);b.headroom(b.data())}))}(window.Zepto||window.jQuery); | ||
!function(a){a&&(a.fn.headroom=function(b){return this.each(function(){var c=a(this),d=c.data("headroom"),e="object"==typeof b&&b;e=a.extend(!0,{},Headroom.options,e),d||(d=new Headroom(this,e),d.init(),c.data("headroom",d)),"string"==typeof b&&(d[b](),"destroy"===b&&c.removeData("headroom"))})},a("[data-headroom]").each(function(){var b=a(this);b.headroom(b.data())}))}(window.Zepto||window.jQuery); |
{ | ||
"name": "headroom.js", | ||
"version": "0.7.1", | ||
"version": "0.8.0", | ||
"description": "Give your page some headroom. Hide your header until you need it", | ||
"main": "dist/headroom.js", | ||
"files": [ | ||
"dist" | ||
], | ||
"scripts": { | ||
"test": "grunt test --verbose" | ||
"start": "grunt", | ||
"test": "grunt test --verbose", | ||
"build": "grunt dist", | ||
"version": "npm run build", | ||
"postversion": "git push origin master --tags && npm publish" | ||
}, | ||
@@ -21,5 +28,2 @@ "repository": { | ||
"homepage": "http://wicky.nillia.ms/headroom.js", | ||
"contributors": [ | ||
{ "name": "Dominik Schmidt", "email": "nick@kreativgebiet.com", "url": "http://kreativgebiet.com" } | ||
], | ||
"license": "MIT", | ||
@@ -30,5 +34,5 @@ "bugs": { | ||
"devDependencies": { | ||
"grunt": "~0.4.1", | ||
"grunt-contrib-jshint": "~0.6.2", | ||
"grunt-contrib-uglify": "~0.2.2", | ||
"grunt": "^0.4.5", | ||
"grunt-contrib-jshint": "^1.0.0", | ||
"grunt-contrib-uglify": "^0.11.1", | ||
"grunt-contrib-watch": "~0.5.1", | ||
@@ -35,0 +39,0 @@ "grunt-karma": "~0.6.2", |
@@ -143,3 +143,7 @@ # [Headroom.js](http://wicky.nillia.ms/headroom.js) | ||
// when below offset | ||
notTop : "headroom--not-top" | ||
notTop : "headroom--not-top", | ||
// when at bottom of scoll area | ||
bottom : "headroom--bottom", | ||
// when not at bottom of scroll area | ||
notBottom : "headroom--not-bottom" | ||
}, | ||
@@ -146,0 +150,0 @@ // callback when pinned, `this` is headroom object |
Major refactor
Supply chain riskPackage has recently undergone a major refactor. It may be unstable or indicate significant internal changes. Use caution when updating to versions that include significant changes.
Found 1 instance in 1 package
New author
Supply chain riskA new npm collaborator published a version of the package for the first time. New collaborators are usually benign additions to a project, but do indicate a change to the security surface area of a package.
Found 1 instance in 1 package
183
31567
9
492
2