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

ispin

Package Overview
Dependencies
Maintainers
1
Versions
10
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

ispin - npm Package Compare versions

Comparing version 1.0.4 to 1.0.5

6

dist/ispin.es.js

@@ -94,16 +94,18 @@ var _extends = Object.assign || function (target) {

_onKeyDown(e) {
e.preventDefault();
switch (e.keyCode) {
case 38:
// arrow up
e.preventDefault();
return this.spin(this.options.step);
case 40:
// arrow down
e.preventDefault();
return this.spin(-this.options.step);
case 33:
// page up
e.preventDefault();
return this.spin(this.options.pageStep);
case 34:
// page down
e.preventDefault();
return this.spin(-this.options.pageStep);

@@ -110,0 +112,0 @@ }

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

var _extends=Object.assign||function(t){for(var s=1;s<arguments.length;s++){var e=arguments[s];for(var i in e)Object.prototype.hasOwnProperty.call(e,i)&&(t[i]=e[i])}return t};class ISpin{constructor(t,s){this.el=t,this.options={},this._onKeyDown=this._onKeyDown.bind(this),this._onMouseDown=this._onMouseDown.bind(this),this._onMouseUp=this._onMouseUp.bind(this),this._onMouseLeave=this._onMouseLeave.bind(this),this._onWheel=this._onWheel.bind(this),this.build(),this.update(s)}build(){this._wrapper=document.createElement("div"),this.el.parentNode&&this.el.parentNode.appendChild(this._wrapper),this._wrapper.appendChild(this.el),this._buttons={inc:document.createElement("button"),dec:document.createElement("button")},Object.keys(this._buttons).forEach(t=>{const s=this._buttons[t];this._wrapper.appendChild(s),s.setAttribute("type","button"),s.addEventListener("mousedown",this._onMouseDown),s.addEventListener("mouseup",this._onMouseUp),s.addEventListener("mouseleave",this._onMouseLeave)}),this.el.addEventListener("keydown",this._onKeyDown),this.el.addEventListener("wheel",this._onWheel)}update(t){(t=_extends({},ISpin.DEFAULTS,this.options,t)).wrapperClass!==this.options.wrapperClass&&(this.options.wrapperClass&&this._wrapper.classList.remove(this.options.wrapperClass),t.wrapperClass&&this._wrapper.classList.add(t.wrapperClass)),t.buttonsClass!==this.options.buttonsClass&&(this.options.buttonsClass&&Object.keys(this._buttons).forEach(t=>{this._buttons[t].classList.remove(this.options.buttonsClass),this._buttons[t].classList.remove(this.options.buttonsClass+"-"+t)}),t.buttonsClass&&Object.keys(this._buttons).forEach(s=>{this._buttons[s].classList.add(t.buttonsClass),this._buttons[s].classList.add(t.buttonsClass+"-"+s)})),this.disabled=t.disabled,Object.assign(this.options,t)}destroy(){this._wrapper.parentNode&&this._wrapper.parentNode.replaceChild(this.el,this._wrapper),delete this.el,delete this._wrapper,delete this._buttons}_onKeyDown(t){switch(t.preventDefault(),t.keyCode){case 38:return this.spin(this.options.step);case 40:return this.spin(-this.options.step);case 33:return this.spin(this.options.pageStep);case 34:return this.spin(-this.options.pageStep)}}_onMouseDown(t){t.preventDefault();const s=t.currentTarget===this._buttons.inc?1:-1;this.spin(s*this.options.step),this.el.focus(),this._startSpinning(s)}_onMouseUp(){this._stopSpinning()}_onMouseLeave(){this._stopSpinning()}_startSpinning(t){this._stopSpinning(),this._spinTimer=setInterval(()=>this.spin(t*this.options.step),this.options.repeatInterval)}_stopSpinning(){clearInterval(this._spinTimer)}_onWheel(t){if(document.activeElement!==this.el)return;t.preventDefault();const s=t.deltaY>0?-1:1;this.spin(s*this.options.step)}get value(){return this.options.parse(this.el.value)}set value(t){const s=this.options.format(this.options.parse(String(t)));this.el.value=s,this.options.onChange&&this.options.onChange(s)}get disabled(){return this._buttons.inc.disabled}set disabled(t){this.disabled!==t&&(this._buttons.inc.disabled=this._buttons.dec.disabled=t)}get precision(){return Math.max(...[this.options.step,this.options.min].filter(t=>null!=t).map(precision))}adjustValue(t){return t=Number(t.toFixed(this.precision)),null!=this.options.max&&t>this.options.max&&(t=this.options.max),null!=this.options.min&&t<this.options.min&&(t=this.options.min),t}wrapValue(t){return this.options.wrapOverflow&&null!=this.options.max&&null!=this.options.min&&(t<this.options.min?t=this.options.max:t>this.options.max&&(t=this.options.min)),t}spin(t){this.value=this.adjustValue(this.wrapValue(this.value+t))}}function precision(t){return(String(t).split(".")[1]||"").length}ISpin.DEFAULTS={wrapperClass:"spin-wrapper",buttonsClass:"spin-button",step:1,pageStep:10,disabled:!1,repeatInterval:200,wrapOverflow:!1,parse:Number,format:String};export default ISpin;
var _extends=Object.assign||function(t){for(var s=1;s<arguments.length;s++){var e=arguments[s];for(var i in e)Object.prototype.hasOwnProperty.call(e,i)&&(t[i]=e[i])}return t};class ISpin{constructor(t,s){this.el=t,this.options={},this._onKeyDown=this._onKeyDown.bind(this),this._onMouseDown=this._onMouseDown.bind(this),this._onMouseUp=this._onMouseUp.bind(this),this._onMouseLeave=this._onMouseLeave.bind(this),this._onWheel=this._onWheel.bind(this),this.build(),this.update(s)}build(){this._wrapper=document.createElement("div"),this.el.parentNode&&this.el.parentNode.appendChild(this._wrapper),this._wrapper.appendChild(this.el),this._buttons={inc:document.createElement("button"),dec:document.createElement("button")},Object.keys(this._buttons).forEach(t=>{const s=this._buttons[t];this._wrapper.appendChild(s),s.setAttribute("type","button"),s.addEventListener("mousedown",this._onMouseDown),s.addEventListener("mouseup",this._onMouseUp),s.addEventListener("mouseleave",this._onMouseLeave)}),this.el.addEventListener("keydown",this._onKeyDown),this.el.addEventListener("wheel",this._onWheel)}update(t){(t=_extends({},ISpin.DEFAULTS,this.options,t)).wrapperClass!==this.options.wrapperClass&&(this.options.wrapperClass&&this._wrapper.classList.remove(this.options.wrapperClass),t.wrapperClass&&this._wrapper.classList.add(t.wrapperClass)),t.buttonsClass!==this.options.buttonsClass&&(this.options.buttonsClass&&Object.keys(this._buttons).forEach(t=>{this._buttons[t].classList.remove(this.options.buttonsClass),this._buttons[t].classList.remove(this.options.buttonsClass+"-"+t)}),t.buttonsClass&&Object.keys(this._buttons).forEach(s=>{this._buttons[s].classList.add(t.buttonsClass),this._buttons[s].classList.add(t.buttonsClass+"-"+s)})),this.disabled=t.disabled,Object.assign(this.options,t)}destroy(){this._wrapper.parentNode&&this._wrapper.parentNode.replaceChild(this.el,this._wrapper),delete this.el,delete this._wrapper,delete this._buttons}_onKeyDown(t){switch(t.keyCode){case 38:return t.preventDefault(),this.spin(this.options.step);case 40:return t.preventDefault(),this.spin(-this.options.step);case 33:return t.preventDefault(),this.spin(this.options.pageStep);case 34:return t.preventDefault(),this.spin(-this.options.pageStep)}}_onMouseDown(t){t.preventDefault();const s=t.currentTarget===this._buttons.inc?1:-1;this.spin(s*this.options.step),this.el.focus(),this._startSpinning(s)}_onMouseUp(){this._stopSpinning()}_onMouseLeave(){this._stopSpinning()}_startSpinning(t){this._stopSpinning(),this._spinTimer=setInterval(()=>this.spin(t*this.options.step),this.options.repeatInterval)}_stopSpinning(){clearInterval(this._spinTimer)}_onWheel(t){if(document.activeElement!==this.el)return;t.preventDefault();const s=t.deltaY>0?-1:1;this.spin(s*this.options.step)}get value(){return this.options.parse(this.el.value)}set value(t){const s=this.options.format(this.options.parse(String(t)));this.el.value=s,this.options.onChange&&this.options.onChange(s)}get disabled(){return this._buttons.inc.disabled}set disabled(t){this.disabled!==t&&(this._buttons.inc.disabled=this._buttons.dec.disabled=t)}get precision(){return Math.max(...[this.options.step,this.options.min].filter(t=>null!=t).map(precision))}adjustValue(t){return t=Number(t.toFixed(this.precision)),null!=this.options.max&&t>this.options.max&&(t=this.options.max),null!=this.options.min&&t<this.options.min&&(t=this.options.min),t}wrapValue(t){return this.options.wrapOverflow&&null!=this.options.max&&null!=this.options.min&&(t<this.options.min?t=this.options.max:t>this.options.max&&(t=this.options.min)),t}spin(t){this.value=this.adjustValue(this.wrapValue(this.value+t))}}function precision(t){return(String(t).split(".")[1]||"").length}ISpin.DEFAULTS={wrapperClass:"spin-wrapper",buttonsClass:"spin-button",step:1,pageStep:10,disabled:!1,repeatInterval:200,wrapOverflow:!1,parse:Number,format:String};export default ISpin;
//# sourceMappingURL=ispin.es.min.js.map

@@ -184,16 +184,18 @@ (function (global, factory) {

value: function _onKeyDown(e) {
e.preventDefault();
switch (e.keyCode) {
case 38:
// arrow up
e.preventDefault();
return this.spin(this.options.step);
case 40:
// arrow down
e.preventDefault();
return this.spin(-this.options.step);
case 33:
// page up
e.preventDefault();
return this.spin(this.options.pageStep);
case 34:
// page down
e.preventDefault();
return this.spin(-this.options.pageStep);

@@ -200,0 +202,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.ISpin=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 s=0;s<e.length;s++){var n=e[s];n.enumerable=n.enumerable||!1,n.configurable=!0,"value"in n&&(n.writable=!0),Object.defineProperty(t,n.key,n)}}return function(e,s,n){return s&&t(e.prototype,s),n&&t(e,n),e}}(),s=Object.assign||function(t){for(var e=1;e<arguments.length;e++){var s=arguments[e];for(var n in s)Object.prototype.hasOwnProperty.call(s,n)&&(t[n]=s[n])}return t},n=function(){function n(e,s){t(this,n),this.el=e,this.options={},this._onKeyDown=this._onKeyDown.bind(this),this._onMouseDown=this._onMouseDown.bind(this),this._onMouseUp=this._onMouseUp.bind(this),this._onMouseLeave=this._onMouseLeave.bind(this),this._onWheel=this._onWheel.bind(this),this.build(),this.update(s)}return e(n,[{key:"build",value:function(){var t=this;this._wrapper=document.createElement("div"),this.el.parentNode&&this.el.parentNode.appendChild(this._wrapper),this._wrapper.appendChild(this.el),this._buttons={inc:document.createElement("button"),dec:document.createElement("button")},Object.keys(this._buttons).forEach(function(e){var s=t._buttons[e];t._wrapper.appendChild(s),s.setAttribute("type","button"),s.addEventListener("mousedown",t._onMouseDown),s.addEventListener("mouseup",t._onMouseUp),s.addEventListener("mouseleave",t._onMouseLeave)}),this.el.addEventListener("keydown",this._onKeyDown),this.el.addEventListener("wheel",this._onWheel)}},{key:"update",value:function(t){var e=this;(t=s({},n.DEFAULTS,this.options,t)).wrapperClass!==this.options.wrapperClass&&(this.options.wrapperClass&&this._wrapper.classList.remove(this.options.wrapperClass),t.wrapperClass&&this._wrapper.classList.add(t.wrapperClass)),t.buttonsClass!==this.options.buttonsClass&&(this.options.buttonsClass&&Object.keys(this._buttons).forEach(function(t){e._buttons[t].classList.remove(e.options.buttonsClass),e._buttons[t].classList.remove(e.options.buttonsClass+"-"+t)}),t.buttonsClass&&Object.keys(this._buttons).forEach(function(s){e._buttons[s].classList.add(t.buttonsClass),e._buttons[s].classList.add(t.buttonsClass+"-"+s)})),this.disabled=t.disabled,s(this.options,t)}},{key:"destroy",value:function(){this._wrapper.parentNode&&this._wrapper.parentNode.replaceChild(this.el,this._wrapper),delete this.el,delete this._wrapper,delete this._buttons}},{key:"_onKeyDown",value:function(t){switch(t.preventDefault(),t.keyCode){case 38:return this.spin(this.options.step);case 40:return this.spin(-this.options.step);case 33:return this.spin(this.options.pageStep);case 34:return this.spin(-this.options.pageStep)}}},{key:"_onMouseDown",value:function(t){t.preventDefault();var e=t.currentTarget===this._buttons.inc?1:-1;this.spin(e*this.options.step),this.el.focus(),this._startSpinning(e)}},{key:"_onMouseUp",value:function(){this._stopSpinning()}},{key:"_onMouseLeave",value:function(){this._stopSpinning()}},{key:"_startSpinning",value:function(t){var e=this;this._stopSpinning(),this._spinTimer=setInterval(function(){return e.spin(t*e.options.step)},this.options.repeatInterval)}},{key:"_stopSpinning",value:function(){clearInterval(this._spinTimer)}},{key:"_onWheel",value:function(t){if(document.activeElement===this.el){t.preventDefault();var e=t.deltaY>0?-1:1;this.spin(e*this.options.step)}}},{key:"adjustValue",value:function(t){return t=Number(t.toFixed(this.precision)),null!=this.options.max&&t>this.options.max&&(t=this.options.max),null!=this.options.min&&t<this.options.min&&(t=this.options.min),t}},{key:"wrapValue",value:function(t){return this.options.wrapOverflow&&null!=this.options.max&&null!=this.options.min&&(t<this.options.min?t=this.options.max:t>this.options.max&&(t=this.options.min)),t}},{key:"spin",value:function(t){this.value=this.adjustValue(this.wrapValue(this.value+t))}},{key:"value",get:function(){return this.options.parse(this.el.value)},set:function(t){var e=this.options.format(this.options.parse(String(t)));this.el.value=e,this.options.onChange&&this.options.onChange(e)}},{key:"disabled",get:function(){return this._buttons.inc.disabled},set:function(t){this.disabled!==t&&(this._buttons.inc.disabled=this._buttons.dec.disabled=t)}},{key:"precision",get:function(){return Math.max.apply(Math,function(t){if(Array.isArray(t)){for(var e=0,s=Array(t.length);e<t.length;e++)s[e]=t[e];return s}return Array.from(t)}([this.options.step,this.options.min].filter(function(t){return null!=t}).map(i)))}}]),n}();function i(t){return(String(t).split(".")[1]||"").length}return n.DEFAULTS={wrapperClass:"spin-wrapper",buttonsClass:"spin-button",step:1,pageStep:10,disabled:!1,repeatInterval:200,wrapOverflow:!1,parse:Number,format:String},n});
!function(t,e){"object"==typeof exports&&"undefined"!=typeof module?module.exports=e():"function"==typeof define&&define.amd?define(e):t.ISpin=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 s=e[n];s.enumerable=s.enumerable||!1,s.configurable=!0,"value"in s&&(s.writable=!0),Object.defineProperty(t,s.key,s)}}return function(e,n,s){return n&&t(e.prototype,n),s&&t(e,s),e}}(),n=Object.assign||function(t){for(var e=1;e<arguments.length;e++){var n=arguments[e];for(var s in n)Object.prototype.hasOwnProperty.call(n,s)&&(t[s]=n[s])}return t},s=function(){function s(e,n){t(this,s),this.el=e,this.options={},this._onKeyDown=this._onKeyDown.bind(this),this._onMouseDown=this._onMouseDown.bind(this),this._onMouseUp=this._onMouseUp.bind(this),this._onMouseLeave=this._onMouseLeave.bind(this),this._onWheel=this._onWheel.bind(this),this.build(),this.update(n)}return e(s,[{key:"build",value:function(){var t=this;this._wrapper=document.createElement("div"),this.el.parentNode&&this.el.parentNode.appendChild(this._wrapper),this._wrapper.appendChild(this.el),this._buttons={inc:document.createElement("button"),dec:document.createElement("button")},Object.keys(this._buttons).forEach(function(e){var n=t._buttons[e];t._wrapper.appendChild(n),n.setAttribute("type","button"),n.addEventListener("mousedown",t._onMouseDown),n.addEventListener("mouseup",t._onMouseUp),n.addEventListener("mouseleave",t._onMouseLeave)}),this.el.addEventListener("keydown",this._onKeyDown),this.el.addEventListener("wheel",this._onWheel)}},{key:"update",value:function(t){var e=this;(t=n({},s.DEFAULTS,this.options,t)).wrapperClass!==this.options.wrapperClass&&(this.options.wrapperClass&&this._wrapper.classList.remove(this.options.wrapperClass),t.wrapperClass&&this._wrapper.classList.add(t.wrapperClass)),t.buttonsClass!==this.options.buttonsClass&&(this.options.buttonsClass&&Object.keys(this._buttons).forEach(function(t){e._buttons[t].classList.remove(e.options.buttonsClass),e._buttons[t].classList.remove(e.options.buttonsClass+"-"+t)}),t.buttonsClass&&Object.keys(this._buttons).forEach(function(n){e._buttons[n].classList.add(t.buttonsClass),e._buttons[n].classList.add(t.buttonsClass+"-"+n)})),this.disabled=t.disabled,n(this.options,t)}},{key:"destroy",value:function(){this._wrapper.parentNode&&this._wrapper.parentNode.replaceChild(this.el,this._wrapper),delete this.el,delete this._wrapper,delete this._buttons}},{key:"_onKeyDown",value:function(t){switch(t.keyCode){case 38:return t.preventDefault(),this.spin(this.options.step);case 40:return t.preventDefault(),this.spin(-this.options.step);case 33:return t.preventDefault(),this.spin(this.options.pageStep);case 34:return t.preventDefault(),this.spin(-this.options.pageStep)}}},{key:"_onMouseDown",value:function(t){t.preventDefault();var e=t.currentTarget===this._buttons.inc?1:-1;this.spin(e*this.options.step),this.el.focus(),this._startSpinning(e)}},{key:"_onMouseUp",value:function(){this._stopSpinning()}},{key:"_onMouseLeave",value:function(){this._stopSpinning()}},{key:"_startSpinning",value:function(t){var e=this;this._stopSpinning(),this._spinTimer=setInterval(function(){return e.spin(t*e.options.step)},this.options.repeatInterval)}},{key:"_stopSpinning",value:function(){clearInterval(this._spinTimer)}},{key:"_onWheel",value:function(t){if(document.activeElement===this.el){t.preventDefault();var e=t.deltaY>0?-1:1;this.spin(e*this.options.step)}}},{key:"adjustValue",value:function(t){return t=Number(t.toFixed(this.precision)),null!=this.options.max&&t>this.options.max&&(t=this.options.max),null!=this.options.min&&t<this.options.min&&(t=this.options.min),t}},{key:"wrapValue",value:function(t){return this.options.wrapOverflow&&null!=this.options.max&&null!=this.options.min&&(t<this.options.min?t=this.options.max:t>this.options.max&&(t=this.options.min)),t}},{key:"spin",value:function(t){this.value=this.adjustValue(this.wrapValue(this.value+t))}},{key:"value",get:function(){return this.options.parse(this.el.value)},set:function(t){var e=this.options.format(this.options.parse(String(t)));this.el.value=e,this.options.onChange&&this.options.onChange(e)}},{key:"disabled",get:function(){return this._buttons.inc.disabled},set:function(t){this.disabled!==t&&(this._buttons.inc.disabled=this._buttons.dec.disabled=t)}},{key:"precision",get:function(){return Math.max.apply(Math,function(t){if(Array.isArray(t)){for(var e=0,n=Array(t.length);e<t.length;e++)n[e]=t[e];return n}return Array.from(t)}([this.options.step,this.options.min].filter(function(t){return null!=t}).map(i)))}}]),s}();function i(t){return(String(t).split(".")[1]||"").length}return s.DEFAULTS={wrapperClass:"spin-wrapper",buttonsClass:"spin-button",step:1,pageStep:10,disabled:!1,repeatInterval:200,wrapOverflow:!1,parse:Number,format:String},s});
//# sourceMappingURL=ispin.min.js.map
{
"name": "ispin",
"version": "1.0.4",
"version": "1.0.5",
"description": "vanilla javascript number spinner",

@@ -5,0 +5,0 @@ "main": "dist/ispin.js",

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

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