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

sonar-js

Package Overview
Dependencies
Maintainers
1
Versions
5
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

sonar-js - npm Package Compare versions

Comparing version 0.2.0 to 1.0.0

dist/sonar.m.js

37

dist/sonar.es.js

@@ -1,28 +0,8 @@

var classCallCheck = function (instance, Constructor) {
if (!(instance instanceof Constructor)) {
throw new TypeError("Cannot call a class as a function");
}
};
var _createClass = function () { function defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } } return function (Constructor, protoProps, staticProps) { if (protoProps) defineProperties(Constructor.prototype, protoProps); if (staticProps) defineProperties(Constructor, staticProps); return Constructor; }; }();
var createClass = function () {
function defineProperties(target, props) {
for (var i = 0; i < props.length; i++) {
var descriptor = props[i];
descriptor.enumerable = descriptor.enumerable || false;
descriptor.configurable = true;
if ("value" in descriptor) descriptor.writable = true;
Object.defineProperty(target, descriptor.key, descriptor);
}
}
function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
return function (Constructor, protoProps, staticProps) {
if (protoProps) defineProperties(Constructor.prototype, protoProps);
if (staticProps) defineProperties(Constructor, staticProps);
return Constructor;
};
}();
var Sonar = function () {
function Sonar(window) {
classCallCheck(this, Sonar);
_classCallCheck(this, Sonar);

@@ -33,3 +13,3 @@ this.window = window;

createClass(Sonar, [{
_createClass(Sonar, [{
key: "ping",

@@ -94,3 +74,3 @@ value: function ping(range, bottomFoundCallback, bottomLostCallback) {

key: "_pageHeight",
get: function get$$1() {
get: function get() {
return this.window.document.body.offsetHeight;

@@ -100,3 +80,3 @@ }

key: "_viewportBottomScrollPosition",
get: function get$$1() {
get: function get() {
return this._viewportHeight + this._viewportTopScrollPosition;

@@ -106,3 +86,3 @@ }

key: "_viewportTopScrollPosition",
get: function get$$1() {
get: function get() {
return this.window.scrollY;

@@ -112,6 +92,7 @@ }

key: "_viewportHeight",
get: function get$$1() {
get: function get() {
return this.window.innerHeight;
}
}]);
return Sonar;

@@ -118,0 +99,0 @@ }();

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

!function(t,e){"object"==typeof exports&&"undefined"!=typeof module?module.exports=e():"function"==typeof define&&define.amd?define(e):t.Sonar=e()}(this,function(){"use strict";var t=function(t,e){if(!(t instanceof e))throw new TypeError("Cannot call a class as a function")},e=function(){function t(t,e){for(var n=0;n<e.length;n++){var i=e[n];i.enumerable=i.enumerable||!1,i.configurable=!0,"value"in i&&(i.writable=!0),Object.defineProperty(t,i.key,i)}}return function(e,n,i){return n&&t(e.prototype,n),i&&t(e,i),e}}(),n=function(){function n(e){t(this,n),this.window=e,this.withinRangeOfPageBottom=void 0}return e(n,[{key:"ping",value:function(t,e,n){var i=this;if(!this._scroll){if(this.withinRangeOfPageBottom=this._withinRangeOfPageBottom(t),this.withinRangeOfPageBottom){if(e(),!n)return}else n&&n();this._scroll=function(){i._enteringRangeOfPageBottom(t)?(i.withinRangeOfPageBottom=!0,e(),n||i.stop()):i._leavingRangeOfPageBottom(t)&&(i.withinRangeOfPageBottom=!1,n())},this.window.addEventListener("scroll",this._scroll)}}},{key:"stop",value:function(){this.window.removeEventListener("scroll",this._scroll),this._scroll=null}},{key:"_withinRangeOfPageBottom",value:function(t){return this._viewportBottomScrollPosition>=this._pageHeight-t}},{key:"_enteringRangeOfPageBottom",value:function(t){return this.withinRangeOfPageBottom===!1&&this._withinRangeOfPageBottom(t)}},{key:"_leavingRangeOfPageBottom",value:function(t){return this.withinRangeOfPageBottom===!0&&!this._withinRangeOfPageBottom(t)}},{key:"_pageHeight",get:function(){return this.window.document.body.offsetHeight}},{key:"_viewportBottomScrollPosition",get:function(){return this._viewportHeight+this._viewportTopScrollPosition}},{key:"_viewportTopScrollPosition",get:function(){return this.window.scrollY}},{key:"_viewportHeight",get:function(){return this.window.innerHeight}}]),n}();return n});
var t=function(t){this.window=t,this.withinRangeOfPageBottom=void 0},o={_pageHeight:{configurable:!0},_viewportBottomScrollPosition:{configurable:!0},_viewportTopScrollPosition:{configurable:!0},_viewportHeight:{configurable:!0}};t.prototype.ping=function(t,o,i){var e=this;if(!this._scroll){if(this.withinRangeOfPageBottom=this._withinRangeOfPageBottom(t),this.withinRangeOfPageBottom){if(o(),!i)return}else i&&i();this._scroll=function(){e._enteringRangeOfPageBottom(t)?(e.withinRangeOfPageBottom=!0,o(),i||e.stop()):e._leavingRangeOfPageBottom(t)&&(e.withinRangeOfPageBottom=!1,i())},this.window.addEventListener("scroll",this._scroll)}},t.prototype.stop=function(){this.window.removeEventListener("scroll",this._scroll),this._scroll=null},t.prototype._withinRangeOfPageBottom=function(t){return this._viewportBottomScrollPosition>=this._pageHeight-t},t.prototype._enteringRangeOfPageBottom=function(t){return!1===this.withinRangeOfPageBottom&&this._withinRangeOfPageBottom(t)},t.prototype._leavingRangeOfPageBottom=function(t){return!0===this.withinRangeOfPageBottom&&!this._withinRangeOfPageBottom(t)},o._pageHeight.get=function(){return this.window.document.body.offsetHeight},o._viewportBottomScrollPosition.get=function(){return this._viewportHeight+this._viewportTopScrollPosition},o._viewportTopScrollPosition.get=function(){return this.window.scrollY},o._viewportHeight.get=function(){return this.window.innerHeight},Object.defineProperties(t.prototype,o),module.exports=t;
//# sourceMappingURL=sonar.js.map
{
"name": "sonar-js",
"version": "0.2.0",
"version": "1.0.0",
"description": "A tiny library for detecting when a browser is scrolled to the bottom of a web page.",
"main": "./dist/sonar.js",
"module": "./dist/sonar.es.js",
"jsnext:main": "./dist/sonar.es.js",
"main": "dist/sonar.js",
"umd:main": "dist/sonar.umd.js",
"module": "dist/sonar.m.js",
"scripts": {
"build": "rollup --config rollup.config.umd.js && rollup --config rollup.config.es.js",
"build": "microbundle --entry lib/sonar.js --name Sonar",
"eslint": "eslint --format=node_modules/eslint-formatter-pretty ./lib ./test; exit 0",

@@ -26,18 +26,12 @@ "prepublish": "npm run build",

"devDependencies": {
"ava": "^0.17.0",
"babel-eslint": "^7.1.1",
"babel-preset-es2015": "^6.18.0",
"babel-preset-es2015-rollup": "^3.0.0",
"babel-register": "^6.18.0",
"eslint": "^3.12.2",
"eslint-config-standard": "^6.2.1",
"eslint-formatter-pretty": "^1.1.0",
"eslint-plugin-promise": "^3.4.0",
"eslint-plugin-standard": "^2.0.1",
"jsdom": "^9.9.1",
"rollup": "^0.39.0",
"rollup-plugin-babel": "^2.7.1",
"rollup-plugin-cleanup": "^0.1.4",
"rollup-plugin-node-resolve": "^2.0.0",
"rollup-plugin-uglify": "^1.0.1"
"ava": "^0.25.0",
"eslint": "^5.4.0",
"eslint-config-standard": "^11.0.0",
"eslint-formatter-pretty": "^1.3.0",
"eslint-plugin-promise": "^4.0.0",
"eslint-plugin-standard": "^3.1.0",
"esm": "^3.0.80",
"jsdom": "^12.0.0",
"microbundle": "^0.6.0",
"np": "^3.0.4"
},

@@ -47,10 +41,5 @@ "dependencies": {},

"require": [
"babel-register"
"esm"
]
},
"babel": {
"presets": [
"es2015"
]
}
}
# Sonar.js
A tiny library for detecting when a browser is scrolled to the bottom of a web page.
![](https://cloud.githubusercontent.com/assets/4727/22095892/1b8ffeb8-ddcd-11e6-9f50-1116ff201553.png)
For example, you might use this on a blog to show a popover when a reader has finished a post, letting them know they can receive new posts by email if they submit their email address.
> A tiny library for detecting when a browser is scrolled to the bottom of a web page.
[![](https://badgen.net/npm/v/sonar-js?icon=npm)](https://www.npmjs.com/package/sonar-js)
[![](https://badgen.net/david/dep/brandonweiss/sonar-js)](https://david-dm.org/brandonweiss/sonar-js)
You could use this, for example, on a blog to show a popover when a reader has finished a post, letting them know they can receive new posts by email if they submit their email address.
## Installation

@@ -11,6 +16,9 @@

The package comes in two types of modules: UMD and ES6.
The package comes in three formats: CommonJS, Universal Module Definition, and ECMAScript Module.
* Universal Module Definition — ES5 wrapped in a UMD module; suitable for simpler build systems or even just dropping it directly onto a page. No transpiling necessary. Your build system can find it via the `main` key in `package.json` or in `dist/sonar.js`.
* ES6 Module — ES5 wrapped in an ES6 module; suitable for build systems that know how to handle ES6 modules. The code itself has already been transpiled to ES5 for convenience, but a build system will still have to transpile the module declaration as no browsers currently support ES6 modules. Your build system can find it via the `module` or `jsnext:main` keys in `package.json` or in `dist/sonar.es.js`.
| Format | package.json key | Path |
|--------|------------------|-------------------|
| CJS | main | dist/sonar.js |
| UMD | umd:main | dist/sonar.umd.js |
| ESM | module | dist/sonar.m.js |

@@ -39,3 +47,3 @@ The package is built on-the-fly before publishing to NPM so the `dist` folder is not in the repo. If you’d like the built files install it via `yarn` or `npm` and pluck the file you need out of `node_modules/sonar-js/dist/`.

This is useful for making a permanent, persistent change when someone scrolls to the bottom of the page.
This is useful for making a permanent change when someone scrolls to the bottom of the page.

@@ -60,3 +68,3 @@ ### Two callbacks

This is useful for making a permanent, temporary change when someone scrolls to the bottom of the page and then reversing it when they scroll away from the bottom of the page.
This is useful for making a temporary change when someone scrolls to the bottom of the page and then reversing it when they scroll away from the bottom of the page.

@@ -66,1 +74,13 @@ ## Tests

`yarn test`
## Credit
The icon is [Depth Sounder by Toni Bordoy](https://thenounproject.com/term/depth-sounder/172726).
## Contributing
1. Fork it ( https://github.com/brandonweiss/sonar-js/fork )
2. Create your feature branch (`git checkout -b my-new-feature`)
3. Commit your changes (`git commit -am "Add some feature"`)
4. Push to the branch (`git push origin my-new-feature`)
5. Create a new Pull Request
import test from "ava"
import jsdom from "jsdom"
import { JSDOM } from "jsdom"
import Sonar from "../../lib/sonar"
let createWindow = (options = {}) => {
let document = jsdom.jsdom("<html><body></body></html>")
let window = document.defaultView
let dom = new JSDOM("<html><body></body></html>")
let window = dom.window
window.document.body.offsetHeight = options.pageHeight
Object.defineProperties(window.HTMLElement.prototype, {
offsetHeight: {
get: () => options.pageHeight
},
})
window.innerHeight = options.windowHeight

@@ -11,0 +16,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