Comparing version 0.0.3 to 0.0.4
{ | ||
"name": "movver", | ||
"version": "0.0.3", | ||
"version": "0.0.4", | ||
"homepage": "http://mcarter.me/movver", | ||
@@ -5,0 +5,0 @@ "authors": [ |
@@ -13,3 +13,2 @@ var Movver = (function() { | ||
Movver.prototype.EVENT_TIMEOUT = 1000; | ||
Movver.prototype.MOBILE_THRESHOLD = 490; | ||
@@ -21,3 +20,2 @@ function Movver(opts) { | ||
if (opts.eventTimeout) this.EVENT_TIMEOUT = opts.eventTimeout; | ||
if (opts.mobileThreshold) this.MOBILE_THRESHOLD = opts.mobileThreshold; | ||
if (!!opts.debug) this.DEBUG = true; | ||
@@ -90,4 +88,4 @@ | ||
Movver.prototype._onMobile = function() { | ||
return (Math.max(document.documentElement.clientWidth, window.innerWidth || 0) / window.devicePixelRatio <= this.MOBILE_THRESHOLD) | ||
Movver.prototype._onTouchDevice = function() { | ||
return ('ontouchstart' in window) || (navigator.MaxTouchPoints > 0) || (navigator.msMaxTouchPoints > 0); | ||
} | ||
@@ -174,3 +172,3 @@ | ||
Movver.prototype._onTouchStart = function(e) { | ||
if (!this._onMobile()) return; | ||
if (!this._onTouchDevice()) return; | ||
this.touchStartOffsets.push(e.touches[0].pageY - e.view.scrollY); | ||
@@ -182,3 +180,3 @@ if (this.touchStartOffsets.length > this.MAX_TOUCH_OFFSETS) this.touchStartOffsets.shift(); | ||
Movver.prototype._onTouchEnd = function(e) { | ||
if (!this._onMobile()) return; | ||
if (!this._onTouchDevice()) return; | ||
this.touchEndOffsets.push(e.changedTouches[0].pageY - e.view.scrollY); | ||
@@ -185,0 +183,0 @@ if (this.touchEndOffsets.length > this.MAX_TOUCH_OFFSETS) this.touchEndOffsets.shift(); |
@@ -1,2 +0,2 @@ | ||
!function t(e,o,n){function i(l,s){if(!o[l]){if(!e[l]){var c="function"==typeof require&&require;if(!s&&c)return c(l,!0);if(r)return r(l,!0);var u=new Error("Cannot find module '"+l+"'");throw u.code="MODULE_NOT_FOUND",u}var h=o[l]={exports:{}};e[l][0].call(h.exports,function(t){var o=e[l][1][t];return i(o?o:t)},h,h.exports,t,e,o,n)}return o[l].exports}for(var r="function"==typeof require&&require,l=0;l<n.length;l++)i(n[l]);return i}({1:[function(){var t=function(){function t(t){t||(t={}),t.touchAverage&&(this.MAX_TOUCH_OFFSETS=t.touchAverage),t.focusThreshold&&(this.FOCUS_PERCENTAGE_THRESHOLD=t.focusThreshold),t.eventTimeout&&(this.EVENT_TIMEOUT=t.eventTimeout),t.mobileThreshold&&(this.MOBILE_THRESHOLD=t.mobileThreshold),t.debug&&(this.DEBUG=!0),this.DEBUG&&(document.body.innerHTML+='<div id="thumbArea" style="background:rgba(255,0,0,0.5); position:fixed; width:100%; z-index:1;"></div>'),this._addListeners()}return t.prototype.watchedElements=[],t.prototype.touchStartOffsets=[],t.prototype.touchEndOffsets=[],t.prototype.elementTimeouts=[],t.prototype.viewableLowerBoundary=Math.max(document.documentElement.clientHeight,window.innerHeight||0),t.prototype.pollScrollCount=0,t.prototype.MAX_TOUCH_OFFSETS=2,t.prototype.FOCUS_PERCENTAGE_THRESHOLD=70,t.prototype.DEBUG=!1,t.prototype.EVENT_TIMEOUT=1e3,t.prototype.MOBILE_THRESHOLD=490,t.prototype.watch=function(t){if("object"!=typeof t)throw new Error("Element must be an object.");this.watchedElements.push(t)},t.prototype.unwatch=function(t){if("object"!=typeof t)throw new Error("Element must be an object.");var e=this.watchedElements.indexOf(t);return e>-1?(this.watchedElements.splice(e,1),!0):!1},t.prototype._arrayAverage=function(t){var e=t.reduce(function(t,e){return t+e});return e/t.length},t.prototype._calculateFocusPercentage=function(t){var e=t.getBoundingClientRect(),o=(e.top+e.bottom)/2,n=o/(this.viewableLowerBoundary/2)*100;return n>100&&(n=200-n),0>n?0:n},t.prototype._findElementTimeout=function(t){for(var e=0;e<this.elementTimeouts.length;e++)if(t===this.elementTimeouts[e].element)return this.elementTimeouts[e];return null},t.prototype._elementTimeoutExists=function(t){return!!this._findElementTimeout(t)},t.prototype._clearElementTimeout=function(t){var e=this._findElementTimeout(t),o=this.elementTimeouts.indexOf(e);return e&&window.clearTimeout(e.timeout),o>-1&&this.elementTimeouts.splice(o,1),!!e},t.prototype._onMobile=function(){return Math.max(document.documentElement.clientWidth,window.innerWidth||0)/window.devicePixelRatio<=this.MOBILE_THRESHOLD},t.prototype._scrollOffset=function(){return self.pageYOffset?self.pageYOffset:document.documentElement&&document.documentElement.scrollTop?document.documentElement.scrollTop:document.body?document.body.scrollTop:void 0},t.prototype._clearPollForScrolling=function(){this.pollScrollCount=0,this.lastScrollOffset=-1,window.clearInterval(this.scrollPoller),this.scrollPoller=!1},t.prototype._checkForScroll=function(){this.pollScrollCount+=1;var t=this._scrollOffset();this.lastScrollOffset===t||this.pollScrollCount>=50?this._clearPollForScrolling():(this._checkWatchedElementsFocus(),this.lastScrollOffset=t,this.pollScrollCount+=1)},t.prototype._pollForScrolling=function(){this.scrollPoller&&this._clearPollForScrolling(),this.scrollPoller=window.setInterval(this._checkForScroll.bind(this),100)},t.prototype._checkWatchedElementsFocus=function(){var t=this;this.watchedElements.forEach(function(e){var o=t._calculateFocusPercentage(e),n=t._elementTimeoutExists(e);o>=t.FOCUS_PERCENTAGE_THRESHOLD&&!n?t.elementTimeouts.push({element:e,timeout:window.setTimeout(function(){e.dispatchEvent(new Event("movver"))},t.EVENT_TIMEOUT)}):o<t.FOCUS_PERCENTAGE_THRESHOLD&&n&&t._clearElementTimeout(e),t.DEBUG&&t._fillRect(e,o)})},t.prototype._fillRect=function(t,e){var o=2.55*e;t.style.backgroundColor="rgb(0,"+Math.round(o)+",0)"},t.prototype._setVisibleBounds=function(){var t=document.getElementById("thumbArea");t.style.top=this.viewableLowerBoundary+"px",t.style.height=document.documentElement.clientHeight-this.viewableLowerBoundary+100+"px"},t.prototype._onTouchStart=function(t){this._onMobile()&&(this.touchStartOffsets.push(t.touches[0].pageY-t.view.scrollY),this.touchStartOffsets.length>this.MAX_TOUCH_OFFSETS&&this.touchStartOffsets.shift(),this._pollForScrolling())},t.prototype._onTouchEnd=function(t){this._onMobile()&&(this.touchEndOffsets.push(t.changedTouches[0].pageY-t.view.scrollY),this.touchEndOffsets.length>this.MAX_TOUCH_OFFSETS&&this.touchEndOffsets.shift(),this.viewableLowerBoundary=Math.min(Math.round(this._arrayAverage(this.touchEndOffsets)),Math.round(this._arrayAverage(this.touchStartOffsets))),this.DEBUG&&this._setVisibleBounds())},t.prototype._addListeners=function(){document.addEventListener("touchstart",this._onTouchStart.bind(this)),document.addEventListener("touchend",this._onTouchEnd.bind(this))},t}();"function"==typeof window.define&&window.define.amd?window.define("movver",[],function(){return t}):window.Movver=t},{}]},{},[1]); | ||
!function t(e,o,n){function r(s,l){if(!o[s]){if(!e[s]){var c="function"==typeof require&&require;if(!l&&c)return c(s,!0);if(i)return i(s,!0);var u=new Error("Cannot find module '"+s+"'");throw u.code="MODULE_NOT_FOUND",u}var h=o[s]={exports:{}};e[s][0].call(h.exports,function(t){var o=e[s][1][t];return r(o?o:t)},h,h.exports,t,e,o,n)}return o[s].exports}for(var i="function"==typeof require&&require,s=0;s<n.length;s++)r(n[s]);return r}({1:[function(){var t=function(){function t(t){t||(t={}),t.touchAverage&&(this.MAX_TOUCH_OFFSETS=t.touchAverage),t.focusThreshold&&(this.FOCUS_PERCENTAGE_THRESHOLD=t.focusThreshold),t.eventTimeout&&(this.EVENT_TIMEOUT=t.eventTimeout),t.debug&&(this.DEBUG=!0),this.DEBUG&&(document.body.innerHTML+='<div id="thumbArea" style="background:rgba(255,0,0,0.5); position:fixed; width:100%; z-index:1;"></div>'),this._addListeners()}return t.prototype.watchedElements=[],t.prototype.touchStartOffsets=[],t.prototype.touchEndOffsets=[],t.prototype.elementTimeouts=[],t.prototype.viewableLowerBoundary=Math.max(document.documentElement.clientHeight,window.innerHeight||0),t.prototype.pollScrollCount=0,t.prototype.MAX_TOUCH_OFFSETS=2,t.prototype.FOCUS_PERCENTAGE_THRESHOLD=70,t.prototype.DEBUG=!1,t.prototype.EVENT_TIMEOUT=1e3,t.prototype.watch=function(t){if("object"!=typeof t)throw new Error("Element must be an object.");this.watchedElements.push(t)},t.prototype.unwatch=function(t){if("object"!=typeof t)throw new Error("Element must be an object.");var e=this.watchedElements.indexOf(t);return e>-1?(this.watchedElements.splice(e,1),!0):!1},t.prototype._arrayAverage=function(t){var e=t.reduce(function(t,e){return t+e});return e/t.length},t.prototype._calculateFocusPercentage=function(t){var e=t.getBoundingClientRect(),o=(e.top+e.bottom)/2,n=o/(this.viewableLowerBoundary/2)*100;return n>100&&(n=200-n),0>n?0:n},t.prototype._findElementTimeout=function(t){for(var e=0;e<this.elementTimeouts.length;e++)if(t===this.elementTimeouts[e].element)return this.elementTimeouts[e];return null},t.prototype._elementTimeoutExists=function(t){return!!this._findElementTimeout(t)},t.prototype._clearElementTimeout=function(t){var e=this._findElementTimeout(t),o=this.elementTimeouts.indexOf(e);return e&&window.clearTimeout(e.timeout),o>-1&&this.elementTimeouts.splice(o,1),!!e},t.prototype._onTouchDevice=function(){return"ontouchstart"in window||navigator.MaxTouchPoints>0||navigator.msMaxTouchPoints>0},t.prototype._scrollOffset=function(){return self.pageYOffset?self.pageYOffset:document.documentElement&&document.documentElement.scrollTop?document.documentElement.scrollTop:document.body?document.body.scrollTop:void 0},t.prototype._clearPollForScrolling=function(){this.pollScrollCount=0,this.lastScrollOffset=-1,window.clearInterval(this.scrollPoller),this.scrollPoller=!1},t.prototype._checkForScroll=function(){this.pollScrollCount+=1;var t=this._scrollOffset();this.lastScrollOffset===t||this.pollScrollCount>=50?this._clearPollForScrolling():(this._checkWatchedElementsFocus(),this.lastScrollOffset=t,this.pollScrollCount+=1)},t.prototype._pollForScrolling=function(){this.scrollPoller&&this._clearPollForScrolling(),this.scrollPoller=window.setInterval(this._checkForScroll.bind(this),100)},t.prototype._checkWatchedElementsFocus=function(){var t=this;this.watchedElements.forEach(function(e){var o=t._calculateFocusPercentage(e),n=t._elementTimeoutExists(e);o>=t.FOCUS_PERCENTAGE_THRESHOLD&&!n?t.elementTimeouts.push({element:e,timeout:window.setTimeout(function(){e.dispatchEvent(new Event("movver"))},t.EVENT_TIMEOUT)}):o<t.FOCUS_PERCENTAGE_THRESHOLD&&n&&t._clearElementTimeout(e),t.DEBUG&&t._fillRect(e,o)})},t.prototype._fillRect=function(t,e){var o=2.55*e;t.style.backgroundColor="rgb(0,"+Math.round(o)+",0)"},t.prototype._setVisibleBounds=function(){var t=document.getElementById("thumbArea");t.style.top=this.viewableLowerBoundary+"px",t.style.height=document.documentElement.clientHeight-this.viewableLowerBoundary+100+"px"},t.prototype._onTouchStart=function(t){this._onTouchDevice()&&(this.touchStartOffsets.push(t.touches[0].pageY-t.view.scrollY),this.touchStartOffsets.length>this.MAX_TOUCH_OFFSETS&&this.touchStartOffsets.shift(),this._pollForScrolling())},t.prototype._onTouchEnd=function(t){this._onTouchDevice()&&(this.touchEndOffsets.push(t.changedTouches[0].pageY-t.view.scrollY),this.touchEndOffsets.length>this.MAX_TOUCH_OFFSETS&&this.touchEndOffsets.shift(),this.viewableLowerBoundary=Math.min(Math.round(this._arrayAverage(this.touchEndOffsets)),Math.round(this._arrayAverage(this.touchStartOffsets))),this.DEBUG&&this._setVisibleBounds())},t.prototype._addListeners=function(){document.addEventListener("touchstart",this._onTouchStart.bind(this)),document.addEventListener("touchend",this._onTouchEnd.bind(this))},t}();"function"==typeof window.define&&window.define.amd?window.define("movver",[],function(){return t}):window.Movver=t},{}]},{},[1]); | ||
//# sourceMappingURL=movver.min.js.map |
{ | ||
"name": "movver", | ||
"version": "v0.0.3", | ||
"version": "v0.0.4", | ||
"description": "The concept of hover on touch devices.", | ||
@@ -5,0 +5,0 @@ "keywords": [ |
@@ -1,2 +0,2 @@ | ||
# Movver.js (v0.0.3) | ||
# Movver.js (v0.0.4) | ||
@@ -23,3 +23,2 @@ ## Introduction: | ||
- **"eventTimeout":** The number of ms an element must be above the focus threshold before its `movver` event is triggered. Defaults to 1000ms. | ||
- **"mobileThreshold":** The screen width in pixels (factors in window.devicePixelRatio) under which the Movver library becomes active. This has no default and **is required**. | ||
@@ -26,0 +25,0 @@ ### 3. Watch elements |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
Manifest confusion
Supply chain riskThis package has inconsistent metadata. This could be malicious or caused by an error when publishing the package.
Found 1 instance in 1 package
Minified code
QualityThis package contains minified code. This may be harmless in some cases where minified code is included in packaged libraries, however packages on npm should not minify code.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
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
Manifest confusion
Supply chain riskThis package has inconsistent metadata. This could be malicious or caused by an error when publishing the package.
Found 1 instance in 1 package
654307
23
292
1
4
60
4