New Case Study:See how Anthropic automated 95% of dependency reviews with Socket.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.7 to 2.0.0

80

dist/ispin.es.js

@@ -1,22 +0,40 @@

var _extends = Object.assign || function (target) {
function _defineProperty(obj, key, value) {
if (key in obj) {
Object.defineProperty(obj, key, {
value: value,
enumerable: true,
configurable: true,
writable: true
});
} else {
obj[key] = value;
}
return obj;
}
function _objectSpread(target) {
for (var i = 1; i < arguments.length; i++) {
var source = arguments[i];
var source = arguments[i] != null ? arguments[i] : {};
var ownKeys = Object.keys(source);
for (var key in source) {
if (Object.prototype.hasOwnProperty.call(source, key)) {
target[key] = source[key];
}
if (typeof Object.getOwnPropertySymbols === 'function') {
ownKeys = ownKeys.concat(Object.getOwnPropertySymbols(source).filter(function (sym) {
return Object.getOwnPropertyDescriptor(source, sym).enumerable;
}));
}
ownKeys.forEach(function (key) {
_defineProperty(target, key, source[key]);
});
}
return target;
};
}
class ISpin {
constructor(el, opts) {
this.el = el; // $FlowFixMe temporary assignment
constructor(el, opts) {
this.el = el;
// $FlowFixMe temporary assignment
this.options = {};
this._onKeyDown = this._onKeyDown.bind(this);

@@ -27,3 +45,2 @@ this._onMouseDown = this._onMouseDown.bind(this);

this._onWheel = this._onWheel.bind(this);
this.build();

@@ -37,14 +54,16 @@ this.update(opts);

if (this.el.parentNode) this.el.parentNode.replaceChild(this._wrapper, this.el);
this._wrapper.appendChild(this.el);
// add buttons
this._wrapper.appendChild(this.el); // add buttons
this._buttons = {
inc: document.createElement('button'),
dec: document.createElement('button')
};
}; // listen to events
// listen to events
Object.keys(this._buttons).forEach(k => {
const b = this._buttons[k];
this._wrapper.appendChild(b);
b.setAttribute('type', 'button');

@@ -60,5 +79,4 @@ b.addEventListener('mousedown', this._onMouseDown);

update(opts) {
opts = _extends({}, ISpin.DEFAULTS, this.options, opts);
opts = _objectSpread({}, ISpin.DEFAULTS, this.options, opts); // update wrapper class
// update wrapper class
if (opts.wrapperClass !== this.options.wrapperClass) {

@@ -73,8 +91,11 @@ if (this.options.wrapperClass) this._wrapper.classList.remove(this.options.wrapperClass);

this._buttons[k].classList.remove(this.options.buttonsClass);
this._buttons[k].classList.remove(this.options.buttonsClass + '-' + k);
});
}
if (opts.buttonsClass) {
Object.keys(this._buttons).forEach(k => {
this._buttons[k].classList.add(opts.buttonsClass);
this._buttons[k].classList.add(opts.buttonsClass + '-' + k);

@@ -86,3 +107,2 @@ });

this.disabled = opts.disabled;
Object.assign(this.options, opts);

@@ -104,2 +124,3 @@ }

return this.spin(this.options.step);
case 40:

@@ -109,2 +130,3 @@ // arrow down

return this.spin(-this.options.step);
case 33:

@@ -114,2 +136,3 @@ // page up

return this.spin(this.options.pageStep);
case 34:

@@ -124,3 +147,2 @@ // page down

e.preventDefault();
const direction = e.currentTarget === this._buttons.inc ? 1 : -1;

@@ -133,7 +155,7 @@ this.spin(direction * this.options.step);

_onMouseUp() {
_onMouseUp(e) {
this._stopSpinning();
}
_onMouseLeave() {
_onMouseLeave(e) {
this._stopSpinning();

@@ -144,2 +166,3 @@ }

this._stopSpinning();
this._spinTimer = setInterval(() => this.spin(direction * this.options.step), this.options.repeatInterval);

@@ -155,3 +178,2 @@ }

e.preventDefault();
const direction = e.deltaY > 0 ? -1 : 1;

@@ -177,3 +199,2 @@ this.spin(direction * this.options.step);

if (this.disabled === disabled) return;
this._buttons.inc.disabled = this._buttons.dec.disabled = disabled;

@@ -183,4 +204,3 @@ }

get precision() {
return Math.max(...[this.options.step, this.options.min].filter(v => v != null)
// $FlowFixMe already checked above
return Math.max(...[this.options.step, this.options.min].filter(v => v != null) // $FlowFixMe already checked above
.map(precision));

@@ -191,6 +211,4 @@ }

value = Number(value.toFixed(this.precision));
if (this.options.max != null && value > this.options.max) value = this.options.max;
if (this.options.min != null && value < this.options.min) value = this.options.min;
return value;

@@ -203,2 +221,3 @@ }

}
return value;

@@ -210,6 +229,7 @@ }

}
}
ISpin.DEFAULTS = {
wrapperClass: 'spin-wrapper',
buttonsClass: 'spin-button',
wrapperClass: 'ispin-wrapper',
buttonsClass: 'ispin-button',
step: 1,

@@ -216,0 +236,0 @@ pageStep: 10,

@@ -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.replaceChild(this._wrapper,this.el),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)||0}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;
function _defineProperty(t,s,e){return s in t?Object.defineProperty(t,s,{value:e,enumerable:!0,configurable:!0,writable:!0}):t[s]=e,t}function _objectSpread(t){for(var s=1;s<arguments.length;s++){var e=null!=arguments[s]?arguments[s]:{},i=Object.keys(e);"function"==typeof Object.getOwnPropertySymbols&&(i=i.concat(Object.getOwnPropertySymbols(e).filter(function(t){return Object.getOwnPropertyDescriptor(e,t).enumerable}))),i.forEach(function(s){_defineProperty(t,s,e[s])})}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.replaceChild(this._wrapper,this.el),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=_objectSpread({},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(t){this._stopSpinning()}_onMouseLeave(t){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)||0}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:"ispin-wrapper",buttonsClass:"ispin-button",step:1,pageStep:10,disabled:!1,repeatInterval:200,wrapOverflow:!1,parse:Number,format:String};export default ISpin;
//# sourceMappingURL=ispin.es.min.js.map
(function (global, factory) {
typeof exports === 'object' && typeof module !== 'undefined' ? module.exports = factory() :
typeof define === 'function' && define.amd ? define(factory) :
(global.ISpin = factory());
typeof exports === 'object' && typeof module !== 'undefined' ? module.exports = factory() :
typeof define === 'function' && define.amd ? define(factory) :
(global.ISpin = factory());
}(this, (function () { 'use strict';
var classCallCheck = function (instance, Constructor) {
if (!(instance instanceof Constructor)) {
throw new TypeError("Cannot call a class as a function");
function _classCallCheck(instance, Constructor) {
if (!(instance instanceof Constructor)) {
throw new TypeError("Cannot call a class as a function");
}
}
};
var createClass = function () {
function defineProperties(target, props) {
function _defineProperties(target, props) {
for (var i = 0; i < props.length; i++) {

@@ -24,301 +23,311 @@ var descriptor = props[i];

return function (Constructor, protoProps, staticProps) {
if (protoProps) defineProperties(Constructor.prototype, protoProps);
if (staticProps) defineProperties(Constructor, staticProps);
function _createClass(Constructor, protoProps, staticProps) {
if (protoProps) _defineProperties(Constructor.prototype, protoProps);
if (staticProps) _defineProperties(Constructor, staticProps);
return Constructor;
};
}();
}
function _defineProperty(obj, key, value) {
if (key in obj) {
Object.defineProperty(obj, key, {
value: value,
enumerable: true,
configurable: true,
writable: true
});
} else {
obj[key] = value;
}
return obj;
}
function _extends() {
_extends = Object.assign || function (target) {
for (var i = 1; i < arguments.length; i++) {
var source = arguments[i];
for (var key in source) {
if (Object.prototype.hasOwnProperty.call(source, key)) {
target[key] = source[key];
}
}
}
return target;
};
return _extends.apply(this, arguments);
}
var _extends = Object.assign || function (target) {
for (var i = 1; i < arguments.length; i++) {
var source = arguments[i];
function _objectSpread(target) {
for (var i = 1; i < arguments.length; i++) {
var source = arguments[i] != null ? arguments[i] : {};
var ownKeys = Object.keys(source);
for (var key in source) {
if (Object.prototype.hasOwnProperty.call(source, key)) {
target[key] = source[key];
if (typeof Object.getOwnPropertySymbols === 'function') {
ownKeys = ownKeys.concat(Object.getOwnPropertySymbols(source).filter(function (sym) {
return Object.getOwnPropertyDescriptor(source, sym).enumerable;
}));
}
ownKeys.forEach(function (key) {
_defineProperty(target, key, source[key]);
});
}
return target;
}
return target;
};
function _toConsumableArray(arr) {
return _arrayWithoutHoles(arr) || _iterableToArray(arr) || _nonIterableSpread();
}
function _arrayWithoutHoles(arr) {
if (Array.isArray(arr)) {
for (var i = 0, arr2 = new Array(arr.length); i < arr.length; i++) arr2[i] = arr[i];
return arr2;
}
}
function _iterableToArray(iter) {
if (Symbol.iterator in Object(iter) || Object.prototype.toString.call(iter) === "[object Arguments]") return Array.from(iter);
}
function _nonIterableSpread() {
throw new TypeError("Invalid attempt to spread non-iterable instance");
}
var ISpin =
/*#__PURE__*/
function () {
function ISpin(el, opts) {
_classCallCheck(this, ISpin);
this.el = el; // $FlowFixMe temporary assignment
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(opts);
}
_createClass(ISpin, [{
key: "build",
value: function build() {
var _this = this;
// wrap element
this._wrapper = document.createElement('div');
if (this.el.parentNode) this.el.parentNode.replaceChild(this._wrapper, this.el);
this._wrapper.appendChild(this.el); // add buttons
this._buttons = {
inc: document.createElement('button'),
dec: document.createElement('button')
}; // listen to events
Object.keys(this._buttons).forEach(function (k) {
var b = _this._buttons[k];
_this._wrapper.appendChild(b);
b.setAttribute('type', 'button');
b.addEventListener('mousedown', _this._onMouseDown);
b.addEventListener('mouseup', _this._onMouseUp);
b.addEventListener('mouseleave', _this._onMouseLeave);
});
this.el.addEventListener('keydown', this._onKeyDown);
this.el.addEventListener('wheel', this._onWheel);
}
}, {
key: "update",
value: function update(opts) {
var _this2 = this;
opts = _objectSpread({}, ISpin.DEFAULTS, this.options, opts); // update wrapper class
if (opts.wrapperClass !== this.options.wrapperClass) {
if (this.options.wrapperClass) this._wrapper.classList.remove(this.options.wrapperClass);
if (opts.wrapperClass) this._wrapper.classList.add(opts.wrapperClass);
}
if (opts.buttonsClass !== this.options.buttonsClass) {
if (this.options.buttonsClass) {
Object.keys(this._buttons).forEach(function (k) {
_this2._buttons[k].classList.remove(_this2.options.buttonsClass);
_this2._buttons[k].classList.remove(_this2.options.buttonsClass + '-' + k);
});
}
if (opts.buttonsClass) {
Object.keys(this._buttons).forEach(function (k) {
_this2._buttons[k].classList.add(opts.buttonsClass);
_this2._buttons[k].classList.add(opts.buttonsClass + '-' + k);
});
}
}
this.disabled = opts.disabled;
_extends(this.options, opts);
}
}, {
key: "destroy",
value: function destroy() {
if (this._wrapper.parentNode) this._wrapper.parentNode.replaceChild(this.el, this._wrapper);
delete this.el;
delete this._wrapper;
delete this._buttons;
}
}, {
key: "_onKeyDown",
value: function _onKeyDown(e) {
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);
}
}
}, {
key: "_onMouseDown",
value: function _onMouseDown(e) {
e.preventDefault();
var direction = e.currentTarget === this._buttons.inc ? 1 : -1;
this.spin(direction * this.options.step);
this.el.focus();
this._startSpinning(direction);
}
}, {
key: "_onMouseUp",
value: function _onMouseUp(e) {
this._stopSpinning();
}
}, {
key: "_onMouseLeave",
value: function _onMouseLeave(e) {
this._stopSpinning();
}
}, {
key: "_startSpinning",
value: function _startSpinning(direction) {
var _this3 = this;
this._stopSpinning();
var toConsumableArray = function (arr) {
if (Array.isArray(arr)) {
for (var i = 0, arr2 = Array(arr.length); i < arr.length; i++) arr2[i] = arr[i];
return arr2;
} else {
return Array.from(arr);
}
};
var ISpin = function () {
function ISpin(el, opts) {
classCallCheck(this, ISpin);
this.el = el;
// $FlowFixMe temporary assignment
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(opts);
}
createClass(ISpin, [{
key: 'build',
value: function build() {
var _this = this;
// wrap element
this._wrapper = document.createElement('div');
if (this.el.parentNode) this.el.parentNode.replaceChild(this._wrapper, this.el);
this._wrapper.appendChild(this.el);
// add buttons
this._buttons = {
inc: document.createElement('button'),
dec: document.createElement('button')
};
// listen to events
Object.keys(this._buttons).forEach(function (k) {
var b = _this._buttons[k];
_this._wrapper.appendChild(b);
b.setAttribute('type', 'button');
b.addEventListener('mousedown', _this._onMouseDown);
b.addEventListener('mouseup', _this._onMouseUp);
b.addEventListener('mouseleave', _this._onMouseLeave);
});
this.el.addEventListener('keydown', this._onKeyDown);
this.el.addEventListener('wheel', this._onWheel);
}
}, {
key: 'update',
value: function update(opts) {
var _this2 = this;
opts = _extends({}, ISpin.DEFAULTS, this.options, opts);
// update wrapper class
if (opts.wrapperClass !== this.options.wrapperClass) {
if (this.options.wrapperClass) this._wrapper.classList.remove(this.options.wrapperClass);
if (opts.wrapperClass) this._wrapper.classList.add(opts.wrapperClass);
this._spinTimer = setInterval(function () {
return _this3.spin(direction * _this3.options.step);
}, this.options.repeatInterval);
}
if (opts.buttonsClass !== this.options.buttonsClass) {
if (this.options.buttonsClass) {
Object.keys(this._buttons).forEach(function (k) {
_this2._buttons[k].classList.remove(_this2.options.buttonsClass);
_this2._buttons[k].classList.remove(_this2.options.buttonsClass + '-' + k);
});
}, {
key: "_stopSpinning",
value: function _stopSpinning() {
clearInterval(this._spinTimer);
}
}, {
key: "_onWheel",
value: function _onWheel(e) {
if (document.activeElement !== this.el) return;
e.preventDefault();
var direction = e.deltaY > 0 ? -1 : 1;
this.spin(direction * this.options.step);
}
}, {
key: "adjustValue",
value: function adjustValue(value) {
value = Number(value.toFixed(this.precision));
if (this.options.max != null && value > this.options.max) value = this.options.max;
if (this.options.min != null && value < this.options.min) value = this.options.min;
return value;
}
}, {
key: "wrapValue",
value: function wrapValue(value) {
if (this.options.wrapOverflow && this.options.max != null && this.options.min != null) {
if (value < this.options.min) value = this.options.max;else if (value > this.options.max) value = this.options.min;
}
if (opts.buttonsClass) {
Object.keys(this._buttons).forEach(function (k) {
_this2._buttons[k].classList.add(opts.buttonsClass);
_this2._buttons[k].classList.add(opts.buttonsClass + '-' + k);
});
}
}
this.disabled = opts.disabled;
_extends(this.options, opts);
}
}, {
key: 'destroy',
value: function destroy() {
if (this._wrapper.parentNode) this._wrapper.parentNode.replaceChild(this.el, this._wrapper);
delete this.el;
delete this._wrapper;
delete this._buttons;
}
}, {
key: '_onKeyDown',
value: function _onKeyDown(e) {
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);
return value;
}
}
}, {
key: '_onMouseDown',
value: function _onMouseDown(e) {
e.preventDefault();
}, {
key: "spin",
value: function spin(step) {
this.value = this.adjustValue(this.wrapValue(this.value + step));
}
}, {
key: "value",
get: function get() {
return this.options.parse(this.el.value) || 0;
},
set: function set(value) {
var strValue = this.options.format(this.options.parse(String(value)));
this.el.value = strValue;
if (this.options.onChange) this.options.onChange(strValue);
}
}, {
key: "disabled",
get: function get() {
return this._buttons.inc.disabled;
},
set: function set(disabled) {
if (this.disabled === disabled) return;
this._buttons.inc.disabled = this._buttons.dec.disabled = disabled;
}
}, {
key: "precision",
get: function get() {
return Math.max.apply(Math, _toConsumableArray([this.options.step, this.options.min].filter(function (v) {
return v != null;
}) // $FlowFixMe already checked above
.map(precision)));
}
}]);
var direction = e.currentTarget === this._buttons.inc ? 1 : -1;
this.spin(direction * this.options.step);
this.el.focus();
return ISpin;
}();
ISpin.DEFAULTS = {
wrapperClass: 'ispin-wrapper',
buttonsClass: 'ispin-button',
step: 1,
pageStep: 10,
disabled: false,
repeatInterval: 200,
wrapOverflow: false,
parse: Number,
format: String
};
this._startSpinning(direction);
}
}, {
key: '_onMouseUp',
value: function _onMouseUp() {
this._stopSpinning();
}
}, {
key: '_onMouseLeave',
value: function _onMouseLeave() {
this._stopSpinning();
}
}, {
key: '_startSpinning',
value: function _startSpinning(direction) {
var _this3 = this;
function precision(num) {
return (String(num).split('.')[1] || '').length;
}
this._stopSpinning();
this._spinTimer = setInterval(function () {
return _this3.spin(direction * _this3.options.step);
}, this.options.repeatInterval);
}
}, {
key: '_stopSpinning',
value: function _stopSpinning() {
clearInterval(this._spinTimer);
}
}, {
key: '_onWheel',
value: function _onWheel(e) {
if (document.activeElement !== this.el) return;
e.preventDefault();
var direction = e.deltaY > 0 ? -1 : 1;
this.spin(direction * this.options.step);
}
}, {
key: 'adjustValue',
value: function adjustValue(value) {
value = Number(value.toFixed(this.precision));
if (this.options.max != null && value > this.options.max) value = this.options.max;
if (this.options.min != null && value < this.options.min) value = this.options.min;
return value;
}
}, {
key: 'wrapValue',
value: function wrapValue(value) {
if (this.options.wrapOverflow && this.options.max != null && this.options.min != null) {
if (value < this.options.min) value = this.options.max;else if (value > this.options.max) value = this.options.min;
}
return value;
}
}, {
key: 'spin',
value: function spin(step) {
this.value = this.adjustValue(this.wrapValue(this.value + step));
}
}, {
key: 'value',
get: function get$$1() {
return this.options.parse(this.el.value) || 0;
},
set: function set$$1(value) {
var strValue = this.options.format(this.options.parse(String(value)));
this.el.value = strValue;
if (this.options.onChange) this.options.onChange(strValue);
}
}, {
key: 'disabled',
get: function get$$1() {
return this._buttons.inc.disabled;
},
set: function set$$1(disabled) {
if (this.disabled === disabled) return;
this._buttons.inc.disabled = this._buttons.dec.disabled = disabled;
}
}, {
key: 'precision',
get: function get$$1() {
return Math.max.apply(Math, toConsumableArray([this.options.step, this.options.min].filter(function (v) {
return v != null;
})
// $FlowFixMe already checked above
.map(precision)));
}
}]);
return ISpin;
}();
ISpin.DEFAULTS = {
wrapperClass: 'spin-wrapper',
buttonsClass: 'spin-button',
step: 1,
pageStep: 10,
disabled: false,
repeatInterval: 200,
wrapOverflow: false,
parse: Number,
format: String
};
function precision(num) {
return (String(num).split('.')[1] || '').length;
}
return ISpin;
})));
//# sourceMappingURL=ispin.js.map

@@ -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.replaceChild(this._wrapper,this.el),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.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)||0},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";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)}}function e(t,e,n){return e in t?Object.defineProperty(t,e,{value:n,enumerable:!0,configurable:!0,writable:!0}):t[e]=n,t}function n(){return(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}).apply(this,arguments)}function s(t){return function(t){if(Array.isArray(t)){for(var e=0,n=new Array(t.length);e<t.length;e++)n[e]=t[e];return n}}(t)||function(t){if(Symbol.iterator in Object(t)||"[object Arguments]"===Object.prototype.toString.call(t))return Array.from(t)}(t)||function(){throw new TypeError("Invalid attempt to spread non-iterable instance")}()}var i=function(){function i(t,e){!function(t,e){if(!(t instanceof e))throw new TypeError("Cannot call a class as a function")}(this,i),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(e)}var r,a,p;return r=i,(a=[{key:"build",value:function(){var t=this;this._wrapper=document.createElement("div"),this.el.parentNode&&this.el.parentNode.replaceChild(this._wrapper,this.el),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 s=this;(t=function(t){for(var n=1;n<arguments.length;n++){var s=null!=arguments[n]?arguments[n]:{},i=Object.keys(s);"function"==typeof Object.getOwnPropertySymbols&&(i=i.concat(Object.getOwnPropertySymbols(s).filter(function(t){return Object.getOwnPropertyDescriptor(s,t).enumerable}))),i.forEach(function(n){e(t,n,s[n])})}return t}({},i.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){s._buttons[t].classList.remove(s.options.buttonsClass),s._buttons[t].classList.remove(s.options.buttonsClass+"-"+t)}),t.buttonsClass&&Object.keys(this._buttons).forEach(function(e){s._buttons[e].classList.add(t.buttonsClass),s._buttons[e].classList.add(t.buttonsClass+"-"+e)})),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(t){this._stopSpinning()}},{key:"_onMouseLeave",value:function(t){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)||0},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,s([this.options.step,this.options.min].filter(function(t){return null!=t}).map(o)))}}])&&t(r.prototype,a),p&&t(r,p),i}();function o(t){return(String(t).split(".")[1]||"").length}return i.DEFAULTS={wrapperClass:"ispin-wrapper",buttonsClass:"ispin-button",step:1,pageStep:10,disabled:!1,repeatInterval:200,wrapOverflow:!1,parse:Number,format:String},i});
//# sourceMappingURL=ispin.min.js.map
{
"name": "ispin",
"version": "1.0.7",
"version": "2.0.0",
"description": "vanilla javascript number spinner",

@@ -8,23 +8,25 @@ "main": "dist/ispin.js",

"devDependencies": {
"babel-core": "^6.26.0",
"babel-eslint": "^8.2.1",
"@babel/core": "^7.1.2",
"@babel/plugin-proposal-object-rest-spread": "^7.0.0",
"@babel/plugin-transform-object-assign": "^7.0.0",
"@babel/plugin-transform-runtime": "^7.1.0",
"@babel/preset-env": "^7.1.0",
"@babel/preset-flow": "^7.0.0",
"babel-eslint": "^10.0.1",
"babel-plugin-external-helpers": "^6.22.0",
"babel-plugin-istanbul": "^4.1.5",
"babel-plugin-istanbul": "^5.1.0",
"babel-plugin-transform-object-assign": "^6.22.0",
"babel-plugin-transform-object-rest-spread": "^6.26.0",
"babel-plugin-transform-runtime": "^6.23.0",
"babel-preset-env": "^1.6.1",
"babel-preset-flow": "^6.23.0",
"eslint-plugin-flowtype": "^2.41.0",
"flow-bin": "^0.63.1",
"npm-run-all": "^4.1.2",
"postcss-cli": "^5.0.0",
"postcss-cssnext": "^3.1.0",
"rollup": "^0.54.1",
"rollup-plugin-babel": "^3.0.3",
"rollup-plugin-commonjs": "^8.2.6",
"rollup-plugin-eslint": "^4.0.0",
"rollup-plugin-node-resolve": "^3.0.2",
"rollup-plugin-uglify": "^2.0.1",
"uglify-es": "^3.3.7"
"eslint-plugin-flowtype": "^3.0.0",
"flow-bin": "^0.83.0",
"postcss-cli": "^6.0.0",
"postcss-preset-env": "^6.1.1",
"rollup": "^0.66.6",
"rollup-plugin-babel": "^4.0.3",
"rollup-plugin-commonjs": "^9.2.0",
"rollup-plugin-eslint": "^5.0.0",
"rollup-plugin-node-resolve": "^3.4.0",
"rollup-plugin-terser": "^3.0.0"
},

@@ -37,4 +39,4 @@ "engines": {

"build": "npm run build:dev && npm run build:prod && npm run css",
"build:dev": "npm-run-all -l build:dev:*",
"build:prod": "npm-run-all -l build:prod:*",
"build:dev": "npm run build:dev:es && npm run build:dev:umd",
"build:prod": "npm run build:prod:es && npm run build:prod:umd",
"build:dev:es": "rollup -c --environment format:es",

@@ -45,3 +47,3 @@ "build:dev:umd": "rollup -c --environment format:umd",

"flow": "flow",
"css": "postcss src/ispin.css -o dist/ispin.css --no-map --use postcss-cssnext",
"css": "postcss src/ispin.css -o dist/ispin.css",
"prepublishOnly": "flow check && npm run build"

@@ -48,0 +50,0 @@ },

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

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