diff --git a/README.md b/README.md index 1d3db40..6c6ee16 100644 --- a/README.md +++ b/README.md @@ -87,10 +87,17 @@ OR Available options: ```javascript interface ITouchSpinOptions { + buttonDownClass?: string; + buttonDownShow?: boolean; + buttonDownTxt?: string; + buttonUpClass?: string; + buttonUpShow?: boolean; + buttonUpTxt?: string; min?: number; max?: number; step?: number; decimals?: number; + decimalsDelimiter?: string; stepInterval?: number; forceStepDivisibility?: string; // none | floor | round | ceil stepIntervalDelay?: number; @@ -102,10 +109,6 @@ interface ITouchSpinOptions { prefixExtraClass?: string; postfixExtraClass?: string; mousewheel?: boolean; - buttonDownClass?: string; - buttonUpClass?: string; - buttonDownTxt?: string; - buttonUpTxt?: string; } ``` diff --git a/bower.json b/bower.json index 03ad0ff..f3c38e4 100644 --- a/bower.json +++ b/bower.json @@ -1,6 +1,6 @@ { "name": "angular-touchspin", - "version": "1.4.6", + "version": "1.5.0", "authors": [ "Niko Kovacic " ], diff --git a/dev/controllers/main.controller.ts b/dev/controllers/main.controller.ts index 6515ccd..8397df2 100644 --- a/dev/controllers/main.controller.ts +++ b/dev/controllers/main.controller.ts @@ -1,15 +1,21 @@ +import * as angular from 'angular'; +import { ITouchSpinOptions } from '../../src/angular-touchspin'; + export class MainController { - public touchSpinOptions: angular.touchspin.ITouchSpinOptions; - public touchSpinVerticalOptions: angular.touchspin.ITouchSpinOptions; + public touchSpinOptions: ITouchSpinOptions; + public touchSpinDelimiterOptions: ITouchSpinOptions; + public touchSpinVerticalOptions: ITouchSpinOptions; public currency: number; public currency1: number; public currency2: number; + public currency3: number; public touchSpinDisabled: boolean; constructor() { this.currency = 10; this.currency1 = 20; this.currency2 = 30; + this.currency3 = 50; this.touchSpinDisabled = false; this.touchSpinOptions = { decimals: 2, @@ -19,6 +25,10 @@ export class MainController { //postfix: '%' }; + this.touchSpinDelimiterOptions = angular.extend({}, this.touchSpinOptions, { + decimalsDelimiter: ',' + }); + this.touchSpinVerticalOptions = { decimals: 2, max: 100, @@ -29,7 +39,7 @@ export class MainController { }; } - onTouchSpinChange(value: number) { - console.log(value) + onTouchSpinChange(oldValue: number, value: number) { + console.log('OldValue: ' + oldValue + ', newValue: ' + value); } } \ No newline at end of file diff --git a/dev/index.html b/dev/index.html index 8f26fc8..30eb73f 100644 --- a/dev/index.html +++ b/dev/index.html @@ -41,7 +41,16 @@ Example 3:
- + + +
+ +
+ +
+
diff --git a/dev/main.module.ts b/dev/main.module.ts index 559923f..ea02fcf 100644 --- a/dev/main.module.ts +++ b/dev/main.module.ts @@ -1,13 +1,18 @@ +import { AngularES6 } from '../src/utilities/angular-es6'; +import { ITouchSpinConfigProvider, ITouchSpinOptions } from '../src/angular-touchspin'; + import './styles/vendor'; import 'font-awesome-webpack'; + let touchspinModule = require('../src/angular-touchspin.module'); + import { MainController } from './controllers/main.controller'; -export default angular +export default AngularES6 .module('nk.touchspin.test', [touchspinModule]) .controller('MainController', MainController) - .config(function(touchSpinConfigProvider: angular.touchspin.ITouchSpinConfigProvider) { - touchSpinConfigProvider.defaults({ + .config(function(touchSpinConfigProvider: ITouchSpinConfigProvider) { + touchSpinConfigProvider.defaults({ decimals: 2, verticalButtons: false }); diff --git a/dist/angular-touchspin.css b/dist/angular-touchspin.css index 64c6dc2..de1341c 100644 --- a/dist/angular-touchspin.css +++ b/dist/angular-touchspin.css @@ -1,5 +1,5 @@ /*! -* angular-touchspin JavaScript Library v1.4.6 +* angular-touchspin JavaScript Library v1.5.0 * * @license MIT * diff --git a/dist/angular-touchspin.js b/dist/angular-touchspin.js index 39ebc35..d4344e2 100644 --- a/dist/angular-touchspin.js +++ b/dist/angular-touchspin.js @@ -1,5 +1,5 @@ /*! -* angular-touchspin JavaScript Library v1.4.6 +* angular-touchspin JavaScript Library v1.5.0 * * @license MIT * @@ -7,14 +7,14 @@ */ (function webpackUniversalModuleDefinition(root, factory) { if(typeof exports === 'object' && typeof module === 'object') - module.exports = factory(); + module.exports = factory(require("angular")); else if(typeof define === 'function' && define.amd) - define([], factory); + define(["angular"], factory); else if(typeof exports === 'object') - exports["angular-touchspin"] = factory(); + exports["angular-touchspin"] = factory(require("angular")); else - root["angular-touchspin"] = factory(); -})(this, function() { + root["angular-touchspin"] = factory(root["angular"]); +})(this, function(__WEBPACK_EXTERNAL_MODULE_1__) { return /******/ (function(modules) { // webpackBootstrap /******/ // The module cache /******/ var installedModules = {}; @@ -61,39 +61,47 @@ return /******/ (function(modules) { // webpackBootstrap /* 0 */ /***/ function(module, exports, __webpack_require__) { - module.exports = __webpack_require__(3); + module.exports = __webpack_require__(4); /***/ }, /* 1 */ /***/ function(module, exports) { - // removed by extract-text-webpack-plugin + module.exports = __WEBPACK_EXTERNAL_MODULE_1__; /***/ }, /* 2 */ /***/ function(module, exports) { - module.exports = "
\r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n
\r\n"; + // removed by extract-text-webpack-plugin /***/ }, /* 3 */ +/***/ function(module, exports) { + + module.exports = "
\r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n
\r\n"; + +/***/ }, +/* 4 */ /***/ function(module, exports, __webpack_require__) { "use strict"; - var angular_es6_1 = __webpack_require__(11); - var touchspin_directive_1 = __webpack_require__(7); - var touchend_directive_1 = __webpack_require__(5); - var touchstart_directive_1 = __webpack_require__(9); - var touchspin_config_1 = __webpack_require__(10); + var angular_es6_1 = __webpack_require__(12); + var touchspin_directive_1 = __webpack_require__(8); + var touchend_directive_1 = __webpack_require__(6); + var touchstart_directive_1 = __webpack_require__(10); + var touchspin_config_1 = __webpack_require__(11); module.exports = angular_es6_1.AngularES6.module('nk.touchspin').directive('touchSpin', touchspin_directive_1.TouchSpinDirective).directive('nkTouchend', touchend_directive_1.TouchEndDirective).directive('nkTouchstart', touchstart_directive_1.TouchStartDirective).provider('touchSpinConfig', touchspin_config_1.TouchSpinConfig).name; /***/ }, -/* 4 */ -/***/ function(module, exports) { +/* 5 */ +/***/ function(module, exports, __webpack_require__) { "use strict"; - var TouchEndController = (function () { + Object.defineProperty(exports, "__esModule", { value: true }); + var angular = __webpack_require__(1); + var TouchEndController = /** @class */(function () { TouchEndController.$inject = ["$element", "$attrs", "$scope"]; function TouchEndController($element, $attrs, $scope) { 'ngInject'; @@ -110,7 +118,6 @@ return /******/ (function(modules) { // webpackBootstrap TouchEndController.prototype.initializeEvents = function () { var _this = this; this.$element.on('touchend', function (event) { - console.log('touchend'); _this.$scope.$apply(function () { _this.$scope.$eval(_this.$attrs['nkTouchend'], { $event: event }); }); @@ -121,12 +128,13 @@ return /******/ (function(modules) { // webpackBootstrap exports.TouchEndController = TouchEndController; /***/ }, -/* 5 */ +/* 6 */ /***/ function(module, exports, __webpack_require__) { "use strict"; - var touchend_controller_1 = __webpack_require__(4); - var TouchEndDirective = (function () { + Object.defineProperty(exports, "__esModule", { value: true }); + var touchend_controller_1 = __webpack_require__(5); + var TouchEndDirective = /** @class */(function () { function TouchEndDirective() { this.restrict = 'A'; this.controller = touchend_controller_1.TouchEndController; @@ -136,11 +144,13 @@ return /******/ (function(modules) { // webpackBootstrap exports.TouchEndDirective = TouchEndDirective; /***/ }, -/* 6 */ -/***/ function(module, exports) { +/* 7 */ +/***/ function(module, exports, __webpack_require__) { "use strict"; - var TouchSpinController = (function () { + Object.defineProperty(exports, "__esModule", { value: true }); + var angular = __webpack_require__(1); + var TouchSpinController = /** @class */(function () { TouchSpinController.$inject = ["$element", "$attrs", "$interval", "$timeout", "touchSpinConfig"]; function TouchSpinController($element, $attrs, $interval, $timeout, touchSpinConfig) { 'ngInject'; @@ -170,9 +180,6 @@ return /******/ (function(modules) { // webpackBootstrap this.stopSpin(true); this.clickStart = Date.now(); this.timeout = this.$timeout(function () { - // if (this.timer) { - // this.$interval.cancel(this.timer); - // } _this.timer = _this.$interval(function () { if (_this.touchSpinOptions.verticalButtons) { _this.decrement(); @@ -192,7 +199,7 @@ return /******/ (function(modules) { // webpackBootstrap } this.clickStart = Date.now(); this.stopSpin(); - this.$timeout(function () { + this.timeout = this.$timeout(function () { _this.timer = _this.$interval(function () { if (_this.touchSpinOptions.verticalButtons) { _this.increment(); @@ -207,7 +214,7 @@ return /******/ (function(modules) { // webpackBootstrap if (force || Date.now() - this.clickStart > this.touchSpinOptions.stepIntervalDelay) { this.$timeout.cancel(this.timeout); this.$interval.cancel(this.timer); - } else { + } else if (!this.isButtonTouching && !this.isMouseButtonDown) { this.$timeout(function () { _this.$timeout.cancel(_this.timeout); _this.$interval.cancel(_this.timer); @@ -217,14 +224,8 @@ return /******/ (function(modules) { // webpackBootstrap TouchSpinController.prototype.checkValue = function () { if (this.ngModelController.$isEmpty(this.val)) { this.changeValue(this.touchSpinOptions.min); - } else if (!this.val.match(/^-?(?:\d+|\d*\.\d+)$/i)) { - if (this.oldVal !== '') { - this.changeValue(parseFloat(this.oldVal)); - } else { - this.changeValue(this.touchSpinOptions.min); - } - } else { - var value = parseFloat(this.val); + } else if (this.numberRegex.test(this.val)) { + var value = this.getNumberValue(this.val); if (value > this.touchSpinOptions.max) { this.changeValue(this.touchSpinOptions.max); } else if (value < this.touchSpinOptions.min) { @@ -232,6 +233,12 @@ return /******/ (function(modules) { // webpackBootstrap } else { this.changeValue(value); } + } else { + if (this.oldVal !== '') { + this.changeValue(this.getNumberValue(this.oldVal)); + } else { + this.changeValue(this.touchSpinOptions.min); + } } this.focused = false; }; @@ -241,7 +248,7 @@ return /******/ (function(modules) { // webpackBootstrap TouchSpinController.prototype.keyUp = function (event) { var code = event.keyCode || event.which; if (code === 40 /* ArrowDown */ || code === 38 /* ArrowUp */) { - this.stopSpin(); + this.stopSpin(true); event.preventDefault(); } }; @@ -256,7 +263,6 @@ return /******/ (function(modules) { // webpackBootstrap } }; TouchSpinController.prototype.mouseDown = function (event, increment) { - console.log('mouse down: ' + event); this.isMouseButtonDown = true; if (increment) { this.startSpinUp(); @@ -265,12 +271,10 @@ return /******/ (function(modules) { // webpackBootstrap } }; TouchSpinController.prototype.mouseUp = function (event) { - console.log('mouse up: ' + event); this.isMouseButtonDown = false; - this.stopSpin(); + this.stopSpin(true); }; TouchSpinController.prototype.mouseLeave = function (event) { - console.log('mouse leave: ' + event); if (this.isMouseButtonDown) { this.mouseUp(event); } @@ -308,6 +312,7 @@ return /******/ (function(modules) { // webpackBootstrap this.ngModelController = this.$element.controller('ngModel'); this.ngModelController.$formatters.push(function (value) { if (angular.isNumber(value) && !_this.ngModelController.$isEmpty(value)) { + _this.oldVal = _this.val; _this.changeValue(value, true, true); } return value; @@ -315,6 +320,7 @@ return /******/ (function(modules) { // webpackBootstrap }; TouchSpinController.prototype.prepareOptions = function () { this.touchSpinOptions = angular.extend({}, this.touchSpinConfig, this.options); + this.numberRegex = new RegExp("^-?(?:\\d+|\\d*" + this.escapeRegExp(this.touchSpinOptions.decimalsDelimiter) + "\\d+)$", 'i'); var value = this.ngModelController.$modelValue || this.touchSpinOptions.min; this.changeValue(value, true, true); }; @@ -323,45 +329,58 @@ return /******/ (function(modules) { // webpackBootstrap var decimalValue = Math.pow(10, this.touchSpinOptions.decimals); value = Math.round(value * decimalValue) / decimalValue; this.val = value.toFixed(this.touchSpinOptions.decimals); + if (this.touchSpinOptions.decimalsDelimiter !== '.') { + this.val = this.val.replace('.', ','); + } if (!supressNgModel) { - this.ngModelController.$setViewValue(value); + this.ngModelController.$setViewValue(this.val); } if (!supressChangeEvent && this.$attrs.onChange) { this.$timeout(function () { - _this.onChange({ value: value }); + _this.onChange({ oldValue: _this.getNumberValue(_this.oldVal), value: value }); }); } }; TouchSpinController.prototype.decrement = function () { this.oldVal = this.val; - var value = parseFloat(this.val) - this.touchSpinOptions.step; + var value = this.getNumberValue(this.val) - this.touchSpinOptions.step; if (value < this.touchSpinOptions.min) { this.changeValue(this.touchSpinOptions.min); return; } this.changeValue(value); }; + TouchSpinController.prototype.escapeRegExp = function (stringToGoIntoTheRegex) { + return stringToGoIntoTheRegex.replace(/[-\/\\^$*+?.()|[\]{}]/g, '\\$&'); + }; TouchSpinController.prototype.increment = function () { this.oldVal = this.val; - var value = parseFloat(this.val) + this.touchSpinOptions.step; + var value = this.getNumberValue(this.val) + this.touchSpinOptions.step; if (value > this.touchSpinOptions.max) { this.changeValue(this.touchSpinOptions.max); return; } this.changeValue(value); }; + TouchSpinController.prototype.getNumberValue = function (value) { + if (this.touchSpinOptions.decimalsDelimiter !== '.') { + value = value.replace(this.touchSpinOptions.decimalsDelimiter, '.'); + } + return parseFloat(value); + }; return TouchSpinController; })(); exports.TouchSpinController = TouchSpinController; /***/ }, -/* 7 */ +/* 8 */ /***/ function(module, exports, __webpack_require__) { "use strict"; - __webpack_require__(1); - var touchspin_controller_1 = __webpack_require__(6); - var TouchSpinDirective = (function () { + Object.defineProperty(exports, "__esModule", { value: true }); + var touchspin_controller_1 = __webpack_require__(7); + __webpack_require__(2); + var TouchSpinDirective = /** @class */(function () { function TouchSpinDirective() { this.restrict = 'EA'; this.require = '^ngModel'; @@ -373,18 +392,20 @@ return /******/ (function(modules) { // webpackBootstrap }; this.controller = touchspin_controller_1.TouchSpinController; this.controllerAs = 'vm'; - this.template = __webpack_require__(2); + this.template = __webpack_require__(3); } return TouchSpinDirective; })(); exports.TouchSpinDirective = TouchSpinDirective; /***/ }, -/* 8 */ -/***/ function(module, exports) { +/* 9 */ +/***/ function(module, exports, __webpack_require__) { "use strict"; - var TouchStartController = (function () { + Object.defineProperty(exports, "__esModule", { value: true }); + var angular = __webpack_require__(1); + var TouchStartController = /** @class */(function () { TouchStartController.$inject = ["$element", "$attrs", "$scope"]; function TouchStartController($element, $attrs, $scope) { 'ngInject'; @@ -401,7 +422,6 @@ return /******/ (function(modules) { // webpackBootstrap TouchStartController.prototype.initializeEvents = function () { var _this = this; this.$element.on('touchstart', function (event) { - console.log('touchstart'); _this.$scope.$apply(function () { _this.$scope.$eval(_this.$attrs['nkTouchstart'], { $event: event }); }); @@ -412,12 +432,13 @@ return /******/ (function(modules) { // webpackBootstrap exports.TouchStartController = TouchStartController; /***/ }, -/* 9 */ +/* 10 */ /***/ function(module, exports, __webpack_require__) { "use strict"; - var touchstart_controller_1 = __webpack_require__(8); - var TouchStartDirective = (function () { + Object.defineProperty(exports, "__esModule", { value: true }); + var touchstart_controller_1 = __webpack_require__(9); + var TouchStartDirective = /** @class */(function () { function TouchStartDirective() { this.restrict = 'A'; this.controller = touchstart_controller_1.TouchStartController; @@ -427,16 +448,21 @@ return /******/ (function(modules) { // webpackBootstrap exports.TouchStartDirective = TouchStartDirective; /***/ }, -/* 10 */ -/***/ function(module, exports) { +/* 11 */ +/***/ function(module, exports, __webpack_require__) { "use strict"; - var TouchSpinConfig = (function () { + Object.defineProperty(exports, "__esModule", { value: true }); + var angular = __webpack_require__(1); + var TouchSpinConfig = /** @class */(function () { function TouchSpinConfig() { this.defaultTouchSpinOptions = { buttonDownClass: 'btn btn-default', + buttonDownShow: true, buttonUpClass: 'btn btn-default', + buttonUpShow: true, decimals: 0, + decimalsDelimiter: '.', max: 100, min: 0, step: 1, @@ -461,11 +487,13 @@ return /******/ (function(modules) { // webpackBootstrap exports.TouchSpinConfig = TouchSpinConfig; /***/ }, -/* 11 */ -/***/ function(module, exports) { +/* 12 */ +/***/ function(module, exports, __webpack_require__) { "use strict"; - var AngularES6 = (function () { + Object.defineProperty(exports, "__esModule", { value: true }); + var angular = __webpack_require__(1); + var AngularES6 = /** @class */(function () { function AngularES6(moduleName, dependancies) { dependancies = dependancies || []; this.name = moduleName; @@ -565,7 +593,7 @@ return /******/ (function(modules) { // webpackBootstrap factoryArray.push(function () { var args = []; for (var _i = 0; _i < arguments.length; _i++) { - args[_i - 0] = arguments[_i]; + args[_i] = arguments[_i]; } //return new constructorFn(...args); var instance = new (constructorFn.bind.apply(constructorFn, [void 0].concat(args)))(); @@ -586,7 +614,7 @@ return /******/ (function(modules) { // webpackBootstrap filterArray.push(function () { var args = []; for (var _i = 0; _i < arguments.length; _i++) { - args[_i - 0] = arguments[_i]; + args[_i] = arguments[_i]; } //return new constructorFn(...args); var instance = new (constructorFn.bind.apply(constructorFn, [void 0].concat(args)))(); diff --git a/dist/angular-touchspin.min.css b/dist/angular-touchspin.min.css index 5e50547..6c11402 100644 --- a/dist/angular-touchspin.min.css +++ b/dist/angular-touchspin.min.css @@ -1,2 +1,2 @@ -/*! angular-touchspin v1.4.6 | MIT | built with ♥ by Niko Kovačič */ +/*! angular-touchspin v1.5.0 | MIT | built with ♥ by Niko Kovačič */ .bootstrap-touchspin .input-group-btn-vertical{position:relative;white-space:nowrap;width:1%;vertical-align:middle;display:table-cell}.bootstrap-touchspin .input-group-btn-vertical>.btn{display:block;float:none;width:100%;max-width:100%;padding:8px 10px;margin-left:-1px;position:relative}.bootstrap-touchspin .input-group-btn-vertical .bootstrap-touchspin-up{border-radius:0;border-top-right-radius:4px}.bootstrap-touchspin .input-group-btn-vertical .bootstrap-touchspin-down{margin-top:-2px;border-radius:0;border-bottom-right-radius:4px}.bootstrap-touchspin .input-group-btn-vertical i{position:absolute;top:3px;left:5px;font-size:9px;font-weight:400} \ No newline at end of file diff --git a/dist/angular-touchspin.min.js b/dist/angular-touchspin.min.js index 9941e74..19314fb 100644 --- a/dist/angular-touchspin.min.js +++ b/dist/angular-touchspin.min.js @@ -1,2 +1,2 @@ -/*! angular-touchspin v1.4.6 | MIT | built with ♥ by Niko Kovačič */ -!function(t,n){"object"==typeof exports&&"object"==typeof module?module.exports=n():"function"==typeof define&&define.amd?define([],n):"object"==typeof exports?exports["angular-touchspin"]=n():t["angular-touchspin"]=n()}(this,function(){return function(t){function n(o){if(e[o])return e[o].exports;var i=e[o]={exports:{},id:o,loaded:!1};return t[o].call(i.exports,i,i.exports,n),i.loaded=!0,i.exports}var e={};return n.m=t,n.c=e,n.p="",n(0)}([function(t,n,e){t.exports=e(3)},function(t,n){},function(t,n){t.exports='
'},function(t,n,e){"use strict";var o=e(11),i=e(7),s=e(5),r=e(9),u=e(10);t.exports=o.AngularES6.module("nk.touchspin").directive("touchSpin",i.TouchSpinDirective).directive("nkTouchend",s.TouchEndDirective).directive("nkTouchstart",r.TouchStartDirective).provider("touchSpinConfig",u.TouchSpinConfig).name},function(t,n){"use strict";var e=function(){function t(t,n,e){"ngInject";this.$element=t,this.$attrs=n,this.$scope=e,1===angular.version.major&&angular.version.minor<5&&this.$onInit()}return t.$inject=["$element","$attrs","$scope"],t.prototype.$onInit=function(){this.initializeEvents()},t.prototype.initializeEvents=function(){var t=this;this.$element.on("touchend",function(n){console.log("touchend"),t.$scope.$apply(function(){t.$scope.$eval(t.$attrs.nkTouchend,{$event:n})})})},t}();n.TouchEndController=e},function(t,n,e){"use strict";var o=e(4),i=function(){function t(){this.restrict="A",this.controller=o.TouchEndController}return t}();n.TouchEndDirective=i},function(t,n){"use strict";var e=function(){function t(t,n,e,o,i){"ngInject";this.$element=t,this.$attrs=n,this.$interval=e,this.$timeout=o,this.touchSpinConfig=i,this.inputElement=this.$element.find("input"),1===angular.version.major&&angular.version.minor<5&&this.$onInit()}return t.$inject=["$element","$attrs","$interval","$timeout","touchSpinConfig"],t.prototype.$onInit=function(){this.prepareNgModel(),this.prepareOptions(),this.initializeEvents()},t.prototype.startSpinUp=function(){var t=this;this.checkValue(),this.touchSpinOptions.verticalButtons?this.decrement():this.increment(),this.stopSpin(!0),this.clickStart=Date.now(),this.timeout=this.$timeout(function(){t.timer=t.$interval(function(){t.touchSpinOptions.verticalButtons?t.decrement():t.increment()},t.touchSpinOptions.stepInterval)},this.touchSpinOptions.stepIntervalDelay)},t.prototype.startSpinDown=function(){var t=this;this.checkValue(),this.touchSpinOptions.verticalButtons?this.increment():this.decrement(),this.clickStart=Date.now(),this.stopSpin(),this.$timeout(function(){t.timer=t.$interval(function(){t.touchSpinOptions.verticalButtons?t.increment():t.decrement()},t.touchSpinOptions.stepInterval)},this.touchSpinOptions.stepIntervalDelay)},t.prototype.stopSpin=function(t){var n=this;t||Date.now()-this.clickStart>this.touchSpinOptions.stepIntervalDelay?(this.$timeout.cancel(this.timeout),this.$interval.cancel(this.timer)):this.$timeout(function(){n.$timeout.cancel(n.timeout),n.$interval.cancel(n.timer)},this.touchSpinOptions.stepIntervalDelay)},t.prototype.checkValue=function(){if(this.ngModelController.$isEmpty(this.val))this.changeValue(this.touchSpinOptions.min);else if(this.val.match(/^-?(?:\d+|\d*\.\d+)$/i)){var t=parseFloat(this.val);t>this.touchSpinOptions.max?this.changeValue(this.touchSpinOptions.max):te?t.decrement():t.increment()}})},t.prototype.prepareNgModel=function(){var t=this;this.ngModelController=this.$element.controller("ngModel"),this.ngModelController.$formatters.push(function(n){return angular.isNumber(n)&&!t.ngModelController.$isEmpty(n)&&t.changeValue(n,!0,!0),n})},t.prototype.prepareOptions=function(){this.touchSpinOptions=angular.extend({},this.touchSpinConfig,this.options);var t=this.ngModelController.$modelValue||this.touchSpinOptions.min;this.changeValue(t,!0,!0)},t.prototype.changeValue=function(t,n,e){var o=this,i=Math.pow(10,this.touchSpinOptions.decimals);t=Math.round(t*i)/i,this.val=t.toFixed(this.touchSpinOptions.decimals),n||this.ngModelController.$setViewValue(t),!e&&this.$attrs.onChange&&this.$timeout(function(){o.onChange({value:t})})},t.prototype.decrement=function(){this.oldVal=this.val;var t=parseFloat(this.val)-this.touchSpinOptions.step;return tthis.touchSpinOptions.max?void this.changeValue(this.touchSpinOptions.max):void this.changeValue(t)},t}();n.TouchSpinController=e},function(t,n,e){"use strict";e(1);var o=e(6),i=function(){function t(){this.restrict="EA",this.require="^ngModel",this.scope={},this.bindToController={disabled:"=?",onChange:"&",options:"=?"},this.controller=o.TouchSpinController,this.controllerAs="vm",this.template=e(2)}return t}();n.TouchSpinDirective=i},function(t,n){"use strict";var e=function(){function t(t,n,e){"ngInject";this.$element=t,this.$attrs=n,this.$scope=e,1===angular.version.major&&angular.version.minor<5&&this.$onInit()}return t.$inject=["$element","$attrs","$scope"],t.prototype.$onInit=function(){this.initializeEvents()},t.prototype.initializeEvents=function(){var t=this;this.$element.on("touchstart",function(n){console.log("touchstart"),t.$scope.$apply(function(){t.$scope.$eval(t.$attrs.nkTouchstart,{$event:n})})})},t}();n.TouchStartController=e},function(t,n,e){"use strict";var o=e(8),i=function(){function t(){this.restrict="A",this.controller=o.TouchStartController}return t}();n.TouchStartDirective=i},function(t,n){"use strict";var e=function(){function t(){this.defaultTouchSpinOptions={buttonDownClass:"btn btn-default",buttonUpClass:"btn btn-default",decimals:0,max:100,min:0,step:1,mousewheel:!0,prefix:"",postfix:"",stepInterval:100,stepIntervalDelay:500,verticalButtons:!1,verticalDownClass:"glyphicon glyphicon-chevron-down",verticalUpClass:"glyphicon glyphicon-chevron-up"}}return t.prototype.defaults=function(t){this.defaultTouchSpinOptions=angular.extend({},this.defaultTouchSpinOptions,t)},t.prototype.$get=function(){return this.defaultTouchSpinOptions},t}();n.TouchSpinConfig=e},function(t,n){"use strict";var e=function(){function t(t,n){n=n||[],this.name=t,this.angularModule=angular.module(t,n)}return t.module=function(n,e){return e=e||[],new t(n,e)},t.prototype.constant=function(t,n){return this.angularModule.constant(t,n),this},t.prototype.config=function(t){return this.angularModule.config(t),this},t.prototype.controller=function(t,n){return this.angularModule.controller(t,n),this},t.prototype.directive=function(t,n){var e=this.normalizeConstructor(n);e.prototype.compile||(e.prototype.compile=function(){});var o=this.cloneFunction(e.prototype.compile);this.override(e.prototype,"compile",function(){return function(){return o.apply(this,arguments),e.prototype.link?e.prototype.link.bind(this):void 0}});var i=this.createFactoryArray(n);return this.angularModule.directive(t,i),this},t.prototype.factory=function(t,n){n=this.normalizeConstructor(n);var e=this.createFactoryArray(n);return this.angularModule.factory(t,e),this},t.prototype.filter=function(t,n){var e=this.createFilterArray(n);return this.angularModule.filter(t,e),this},t.prototype.service=function(t,n){return this.angularModule.service(t,n),this},t.prototype.provider=function(t,n){return this.angularModule.provider(t,n),this},t.prototype.run=function(t){return this.angularModule.run(t),this},t.prototype.normalizeConstructor=function(t){var n;if(angular.isArray(t.constructor)){var e=t.slice(0,t.length-1);n=t[t.length-1],n.$inject=e}else n=t;return n},t.prototype.createFactoryArray=function(t){var n=t.$inject||[],e=n.slice();return e.push(function(){for(var n=[],e=0;e*/ +!function(t,n){"object"==typeof exports&&"object"==typeof module?module.exports=n(require("angular")):"function"==typeof define&&define.amd?define(["angular"],n):"object"==typeof exports?exports["angular-touchspin"]=n(require("angular")):t["angular-touchspin"]=n(t.angular)}(this,function(t){return function(t){function n(o){if(e[o])return e[o].exports;var i=e[o]={exports:{},id:o,loaded:!1};return t[o].call(i.exports,i,i.exports,n),i.loaded=!0,i.exports}var e={};return n.m=t,n.c=e,n.p="",n(0)}([function(t,n,e){t.exports=e(4)},function(n,e){n.exports=t},function(t,n){},function(t,n){t.exports='
'},function(t,n,e){"use strict";var o=e(12),i=e(8),s=e(6),u=e(10),r=e(11);t.exports=o.AngularES6.module("nk.touchspin").directive("touchSpin",i.TouchSpinDirective).directive("nkTouchend",s.TouchEndDirective).directive("nkTouchstart",u.TouchStartDirective).provider("touchSpinConfig",r.TouchSpinConfig).name},function(t,n,e){"use strict";Object.defineProperty(n,"__esModule",{value:!0});var o=e(1),i=function(){function t(t,n,e){"ngInject";this.$element=t,this.$attrs=n,this.$scope=e,1===o.version.major&&o.version.minor<5&&this.$onInit()}return t.$inject=["$element","$attrs","$scope"],t.prototype.$onInit=function(){this.initializeEvents()},t.prototype.initializeEvents=function(){var t=this;this.$element.on("touchend",function(n){t.$scope.$apply(function(){t.$scope.$eval(t.$attrs.nkTouchend,{$event:n})})})},t}();n.TouchEndController=i},function(t,n,e){"use strict";Object.defineProperty(n,"__esModule",{value:!0});var o=e(5),i=function(){function t(){this.restrict="A",this.controller=o.TouchEndController}return t}();n.TouchEndDirective=i},function(t,n,e){"use strict";Object.defineProperty(n,"__esModule",{value:!0});var o=e(1),i=function(){function t(t,n,e,i,s){"ngInject";this.$element=t,this.$attrs=n,this.$interval=e,this.$timeout=i,this.touchSpinConfig=s,this.inputElement=this.$element.find("input"),1===o.version.major&&o.version.minor<5&&this.$onInit()}return t.$inject=["$element","$attrs","$interval","$timeout","touchSpinConfig"],t.prototype.$onInit=function(){this.prepareNgModel(),this.prepareOptions(),this.initializeEvents()},t.prototype.startSpinUp=function(){var t=this;this.checkValue(),this.touchSpinOptions.verticalButtons?this.decrement():this.increment(),this.stopSpin(!0),this.clickStart=Date.now(),this.timeout=this.$timeout(function(){t.timer=t.$interval(function(){t.touchSpinOptions.verticalButtons?t.decrement():t.increment()},t.touchSpinOptions.stepInterval)},this.touchSpinOptions.stepIntervalDelay)},t.prototype.startSpinDown=function(){var t=this;this.checkValue(),this.touchSpinOptions.verticalButtons?this.increment():this.decrement(),this.clickStart=Date.now(),this.stopSpin(),this.timeout=this.$timeout(function(){t.timer=t.$interval(function(){t.touchSpinOptions.verticalButtons?t.increment():t.decrement()},t.touchSpinOptions.stepInterval)},this.touchSpinOptions.stepIntervalDelay)},t.prototype.stopSpin=function(t){var n=this;t||Date.now()-this.clickStart>this.touchSpinOptions.stepIntervalDelay?(this.$timeout.cancel(this.timeout),this.$interval.cancel(this.timer)):this.isButtonTouching||this.isMouseButtonDown||this.$timeout(function(){n.$timeout.cancel(n.timeout),n.$interval.cancel(n.timer)},this.touchSpinOptions.stepIntervalDelay)},t.prototype.checkValue=function(){if(this.ngModelController.$isEmpty(this.val))this.changeValue(this.touchSpinOptions.min);else if(this.numberRegex.test(this.val)){var t=this.getNumberValue(this.val);t>this.touchSpinOptions.max?this.changeValue(this.touchSpinOptions.max):te?t.decrement():t.increment()}})},t.prototype.prepareNgModel=function(){var t=this;this.ngModelController=this.$element.controller("ngModel"),this.ngModelController.$formatters.push(function(n){return o.isNumber(n)&&!t.ngModelController.$isEmpty(n)&&(t.oldVal=t.val,t.changeValue(n,!0,!0)),n})},t.prototype.prepareOptions=function(){this.touchSpinOptions=o.extend({},this.touchSpinConfig,this.options),this.numberRegex=new RegExp("^-?(?:\\d+|\\d*"+this.escapeRegExp(this.touchSpinOptions.decimalsDelimiter)+"\\d+)$","i");var t=this.ngModelController.$modelValue||this.touchSpinOptions.min;this.changeValue(t,!0,!0)},t.prototype.changeValue=function(t,n,e){var o=this,i=Math.pow(10,this.touchSpinOptions.decimals);t=Math.round(t*i)/i,this.val=t.toFixed(this.touchSpinOptions.decimals),"."!==this.touchSpinOptions.decimalsDelimiter&&(this.val=this.val.replace(".",",")),n||this.ngModelController.$setViewValue(this.val),!e&&this.$attrs.onChange&&this.$timeout(function(){o.onChange({oldValue:o.getNumberValue(o.oldVal),value:t})})},t.prototype.decrement=function(){this.oldVal=this.val;var t=this.getNumberValue(this.val)-this.touchSpinOptions.step;return tthis.touchSpinOptions.max?void this.changeValue(this.touchSpinOptions.max):void this.changeValue(t)},t.prototype.getNumberValue=function(t){return"."!==this.touchSpinOptions.decimalsDelimiter&&(t=t.replace(this.touchSpinOptions.decimalsDelimiter,".")),parseFloat(t)},t}();n.TouchSpinController=i},function(t,n,e){"use strict";Object.defineProperty(n,"__esModule",{value:!0});var o=e(7);e(2);var i=function(){function t(){this.restrict="EA",this.require="^ngModel",this.scope={},this.bindToController={disabled:"=?",onChange:"&",options:"=?"},this.controller=o.TouchSpinController,this.controllerAs="vm",this.template=e(3)}return t}();n.TouchSpinDirective=i},function(t,n,e){"use strict";Object.defineProperty(n,"__esModule",{value:!0});var o=e(1),i=function(){function t(t,n,e){"ngInject";this.$element=t,this.$attrs=n,this.$scope=e,1===o.version.major&&o.version.minor<5&&this.$onInit()}return t.$inject=["$element","$attrs","$scope"],t.prototype.$onInit=function(){this.initializeEvents()},t.prototype.initializeEvents=function(){var t=this;this.$element.on("touchstart",function(n){t.$scope.$apply(function(){t.$scope.$eval(t.$attrs.nkTouchstart,{$event:n})})})},t}();n.TouchStartController=i},function(t,n,e){"use strict";Object.defineProperty(n,"__esModule",{value:!0});var o=e(9),i=function(){function t(){this.restrict="A",this.controller=o.TouchStartController}return t}();n.TouchStartDirective=i},function(t,n,e){"use strict";Object.defineProperty(n,"__esModule",{value:!0});var o=e(1),i=function(){function t(){this.defaultTouchSpinOptions={buttonDownClass:"btn btn-default",buttonDownShow:!0,buttonUpClass:"btn btn-default",buttonUpShow:!0,decimals:0,decimalsDelimiter:".",max:100,min:0,step:1,mousewheel:!0,prefix:"",postfix:"",stepInterval:100,stepIntervalDelay:500,verticalButtons:!1,verticalDownClass:"glyphicon glyphicon-chevron-down",verticalUpClass:"glyphicon glyphicon-chevron-up"}}return t.prototype.defaults=function(t){this.defaultTouchSpinOptions=o.extend({},this.defaultTouchSpinOptions,t)},t.prototype.$get=function(){return this.defaultTouchSpinOptions},t}();n.TouchSpinConfig=i},function(t,n,e){"use strict";Object.defineProperty(n,"__esModule",{value:!0});var o=e(1),i=function(){function t(t,n){n=n||[],this.name=t,this.angularModule=o.module(t,n)}return t.module=function(n,e){return e=e||[],new t(n,e)},t.prototype.constant=function(t,n){return this.angularModule.constant(t,n),this},t.prototype.config=function(t){return this.angularModule.config(t),this},t.prototype.controller=function(t,n){return this.angularModule.controller(t,n),this},t.prototype.directive=function(t,n){var e=this.normalizeConstructor(n);e.prototype.compile||(e.prototype.compile=function(){});var o=this.cloneFunction(e.prototype.compile);this.override(e.prototype,"compile",function(){return function(){return o.apply(this,arguments),e.prototype.link?e.prototype.link.bind(this):void 0}});var i=this.createFactoryArray(n);return this.angularModule.directive(t,i),this},t.prototype.factory=function(t,n){n=this.normalizeConstructor(n);var e=this.createFactoryArray(n);return this.angularModule.factory(t,e),this},t.prototype.filter=function(t,n){var e=this.createFilterArray(n);return this.angularModule.filter(t,e),this},t.prototype.service=function(t,n){return this.angularModule.service(t,n),this},t.prototype.provider=function(t,n){return this.angularModule.provider(t,n),this},t.prototype.run=function(t){return this.angularModule.run(t),this},t.prototype.normalizeConstructor=function(t){var n;if(o.isArray(t.constructor)){var e=t.slice(0,t.length-1);n=t[t.length-1],n.$inject=e}else n=t;return n},t.prototype.createFactoryArray=function(t){var n=t.$inject||[],e=n.slice();return e.push(function(){for(var n=[],e=0;e", "title": "Angular Touchspin", "description": "A input spinner component for Bootstrap 3 and angular", @@ -17,7 +17,8 @@ "angular touchspin" ], "main": "./dist/angular-touchspin.js", - "licence": "MIT", + "types": "./src/angular-touchspin.d.ts", + "license": "MIT", "dependencies": { "angular": "~1.5" }, @@ -45,10 +46,12 @@ "style-loader": "~0.13", "tslint": "~3.7", "ts-loader": "~0.8", - "typescript": "~1.8", + "typescript": "~2.5", "url-loader": "~0.5", "webpack": "~1.13", "webpack-dev-server": "~1.14", - "wrench": "~1.5" + "wrench": "~1.5", + "@types/angular": "~1.5", + "@types/webpack-env": "~1.13" } } \ No newline at end of file diff --git a/src/angular-touchspin.d.ts b/src/angular-touchspin.d.ts index 7e83447..ccc897b 100644 --- a/src/angular-touchspin.d.ts +++ b/src/angular-touchspin.d.ts @@ -5,18 +5,28 @@ //// - declare module "angular-touchspin" { - let _: string; + let _: string; export = _; } -declare module angular.touchspin { +export type ITouchSpinOptions = angularTouchSpin.ITouchSpinOptions; +export type ITouchSpinConfig = angularTouchSpin.ITouchSpinConfig; +export type ITouchSpinConfigProvider = angularTouchSpin.ITouchSpinConfigProvider; + +declare namespace angularTouchSpin { interface ITouchSpinOptions { + buttonDownClass?: string; + buttonDownShow?: boolean; + buttonDownTxt?: string; + buttonUpClass?: string; + buttonUpShow?: boolean; + buttonUpTxt?: string; min?: number; max?: number; step?: number; decimals?: number; + decimalsDelimiter?: string; stepInterval?: number; forceStepDivisibility?: string; // none | floor | round | ceil stepIntervalDelay?: number; @@ -28,10 +38,6 @@ declare module angular.touchspin { prefixExtraClass?: string; postfixExtraClass?: string; mousewheel?: boolean; - buttonDownClass?: string; - buttonUpClass?: string; - buttonDownTxt?: string; - buttonUpTxt?: string; } interface ITouchSpinConfig extends ITouchSpinOptions { } diff --git a/src/components/touchend/touchend.controller.ts b/src/components/touchend/touchend.controller.ts index 134d045..c2471e8 100644 --- a/src/components/touchend/touchend.controller.ts +++ b/src/components/touchend/touchend.controller.ts @@ -1,7 +1,9 @@ +import * as angular from 'angular'; + export class TouchEndController { private - constructor(private $element: ng.IAugmentedJQuery, private $attrs: ng.IAttributes, private $scope: ng.IScope) { + constructor(private $element: ng.IAugmentedJQuery, private $attrs: angular.IAttributes, private $scope: ng.IScope) { 'ngInject'; if (angular.version.major === 1 && angular.version.minor < 5) { @@ -15,8 +17,6 @@ export class TouchEndController { private initializeEvents() { this.$element.on('touchend', (event) => { - console.log('touchend'); - this.$scope.$apply(() => { this.$scope.$eval(this.$attrs['nkTouchend'], { $event: event }); }); diff --git a/src/components/touchend/touchend.directive.ts b/src/components/touchend/touchend.directive.ts index 9596127..c7ee96d 100644 --- a/src/components/touchend/touchend.directive.ts +++ b/src/components/touchend/touchend.directive.ts @@ -1,6 +1,8 @@ +import { IDirective } from 'angular'; + import { TouchEndController } from './touchend.controller'; -export class TouchEndDirective implements ng.IDirective { +export class TouchEndDirective implements IDirective { public restrict = 'A'; public controller = TouchEndController; } \ No newline at end of file diff --git a/src/components/touchspin/touchspin.controller.ts b/src/components/touchspin/touchspin.controller.ts index 13956ba..0096203 100644 --- a/src/components/touchspin/touchspin.controller.ts +++ b/src/components/touchspin/touchspin.controller.ts @@ -1,3 +1,7 @@ +import * as angular from 'angular'; + +import { ITouchSpinOptions, ITouchSpinConfig } from '../../angular-touchspin'; + const enum Char { ArrowDown = 40, ArrowUp = 38 @@ -5,7 +9,7 @@ const enum Char { export class TouchSpinController { public disabled: boolean; - public options: angular.touchspin.ITouchSpinOptions; + public options: ITouchSpinOptions; public val: string; private clickStart: number; @@ -13,14 +17,15 @@ export class TouchSpinController { private inputElement: angular.IAugmentedJQuery; private isButtonTouching: boolean; private isMouseButtonDown: boolean; + private numberRegex: RegExp; private ngModelController: angular.INgModelController; private oldVal: string; private timeout: angular.IPromise; private timer: angular.IPromise; - private touchSpinOptions: angular.touchspin.ITouchSpinOptions; + private touchSpinOptions: ITouchSpinOptions; constructor(private $element: angular.IAugmentedJQuery, private $attrs: angular.IAttributes, - private $interval: angular.IIntervalService, private $timeout: angular.ITimeoutService, private touchSpinConfig: angular.touchspin.ITouchSpinConfig) { + private $interval: angular.IIntervalService, private $timeout: angular.ITimeoutService, private touchSpinConfig: ITouchSpinConfig) { 'ngInject'; this.inputElement = this.$element.find('input'); @@ -50,10 +55,6 @@ export class TouchSpinController { this.clickStart = Date.now(); this.timeout = this.$timeout(() => { - // if (this.timer) { - // this.$interval.cancel(this.timer); - // } - this.timer = this.$interval(() => { if (this.touchSpinOptions.verticalButtons) { this.decrement(); @@ -77,7 +78,7 @@ export class TouchSpinController { this.clickStart = Date.now(); this.stopSpin(); - this.$timeout(() => { + this.timeout = this.$timeout(() => { this.timer = this.$interval(() => { if (this.touchSpinOptions.verticalButtons) { this.increment(); @@ -92,7 +93,7 @@ export class TouchSpinController { if (force || Date.now() - this.clickStart > this.touchSpinOptions.stepIntervalDelay) { this.$timeout.cancel(this.timeout); this.$interval.cancel(this.timer); - } else { + } else if (!this.isButtonTouching && !this.isMouseButtonDown) { this.$timeout(() => { this.$timeout.cancel(this.timeout); this.$interval.cancel(this.timer); @@ -103,17 +104,9 @@ export class TouchSpinController { if (this.ngModelController.$isEmpty(this.val)) { this.changeValue(this.touchSpinOptions.min); } - else if (!this.val.match(/^-?(?:\d+|\d*\.\d+)$/i)) { - if (this.oldVal !== '') { - this.changeValue(parseFloat(this.oldVal)) - } - else { - this.changeValue(this.touchSpinOptions.min); - } - } - else { - let value = parseFloat(this.val); - + else if (this.numberRegex.test(this.val)) { + let value = this.getNumberValue(this.val); + if (value > this.touchSpinOptions.max) { this.changeValue(this.touchSpinOptions.max); } @@ -124,6 +117,14 @@ export class TouchSpinController { this.changeValue(value); } } + else { + if (this.oldVal !== '') { + this.changeValue(this.getNumberValue(this.oldVal)) + } + else { + this.changeValue(this.touchSpinOptions.min); + } + } this.focused = false; } @@ -134,7 +135,7 @@ export class TouchSpinController { let code = event.keyCode || event.which; if (code === Char.ArrowDown || code === Char.ArrowUp) { - this.stopSpin(); + this.stopSpin(true); event.preventDefault(); } @@ -154,8 +155,6 @@ export class TouchSpinController { } } public mouseDown(event: MouseEvent, increment: boolean) { - console.log('mouse down: ' + event); - this.isMouseButtonDown = true; if (increment) { @@ -166,14 +165,11 @@ export class TouchSpinController { } } public mouseUp(event: MouseEvent) { - console.log('mouse up: ' + event); this.isMouseButtonDown = false; - this.stopSpin(); + this.stopSpin(true); } public mouseLeave(event: MouseEvent) { - console.log('mouse leave: ' + event); - if (this.isMouseButtonDown) { this.mouseUp(event); } @@ -195,7 +191,7 @@ export class TouchSpinController { } private initializeEvents() { - this.inputElement.on('mousewheel DOMMouseScroll', (ev: JQueryMouseEventObject) => { + this.inputElement.on('mousewheel DOMMouseScroll', (ev: JQueryMouseEventObject) => { if (!this.touchSpinOptions.mousewheel || !this.focused) { return; } @@ -219,6 +215,8 @@ export class TouchSpinController { this.ngModelController.$formatters.push((value) => { if (angular.isNumber(value) && !this.ngModelController.$isEmpty(value)) { + this.oldVal = this.val; + this.changeValue(value, true, true); } @@ -227,6 +225,7 @@ export class TouchSpinController { } private prepareOptions() { this.touchSpinOptions = angular.extend({}, this.touchSpinConfig, this.options); + this.numberRegex = new RegExp(`^-?(?:\\d+|\\d*${this.escapeRegExp(this.touchSpinOptions.decimalsDelimiter)}\\d+)$`, 'i'); let value: number = this.ngModelController.$modelValue || this.touchSpinOptions.min; @@ -239,20 +238,24 @@ export class TouchSpinController { this.val = value.toFixed(this.touchSpinOptions.decimals); + if (this.touchSpinOptions.decimalsDelimiter !== '.') { + this.val = this.val.replace('.', ','); + } + if (!supressNgModel) { - this.ngModelController.$setViewValue(value); + this.ngModelController.$setViewValue(this.val); } if (!supressChangeEvent && (this.$attrs).onChange) { this.$timeout(() => { - (this).onChange({ value: value }); + (this).onChange({ oldValue: this.getNumberValue(this.oldVal), value: value }); }); } } private decrement () { this.oldVal = this.val; - let value = parseFloat(this.val) - this.touchSpinOptions.step; + let value = this.getNumberValue(this.val) - this.touchSpinOptions.step; if (value < this.touchSpinOptions.min) { this.changeValue(this.touchSpinOptions.min); @@ -262,10 +265,14 @@ export class TouchSpinController { this.changeValue(value); } + private escapeRegExp(stringToGoIntoTheRegex) { + return stringToGoIntoTheRegex.replace(/[-\/\\^$*+?.()|[\]{}]/g, '\\$&'); + } + private increment () { this.oldVal = this.val; - let value = parseFloat(this.val) + this.touchSpinOptions.step; + let value = this.getNumberValue(this.val) + this.touchSpinOptions.step; if (value > this.touchSpinOptions.max) { this.changeValue(this.touchSpinOptions.max); @@ -275,4 +282,11 @@ export class TouchSpinController { this.changeValue(value); } + private getNumberValue(value: string) { + if (this.touchSpinOptions.decimalsDelimiter !== '.') { + value = value.replace(this.touchSpinOptions.decimalsDelimiter, '.'); + } + + return parseFloat(value); + } } \ No newline at end of file diff --git a/src/components/touchspin/touchspin.directive.html b/src/components/touchspin/touchspin.directive.html index 3331e83..769184f 100644 --- a/src/components/touchspin/touchspin.directive.html +++ b/src/components/touchspin/touchspin.directive.html @@ -1,5 +1,5 @@
- + - - -