visual_condition_builder 0.0.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +7 -0
- data/MIT-LICENSE +20 -0
- data/README.md +155 -0
- data/Rakefile +34 -0
- data/app/assets/javascripts/visual_condition_builder/Sortable.js +1385 -0
- data/app/assets/javascripts/visual_condition_builder/autoNumeric-2.0-BETA.js +2156 -0
- data/app/assets/javascripts/visual_condition_builder/autonumeric_ujs.js +94 -0
- data/app/assets/javascripts/visual_condition_builder/condition_builder.js +633 -0
- data/app/assets/javascripts/visual_condition_builder/diacritics.js +116 -0
- data/app/assets/javascripts/visual_condition_builder/select2.full.js +6436 -0
- data/app/assets/javascripts/visual_condition_builder/select2_i18n/ar.js +3 -0
- data/app/assets/javascripts/visual_condition_builder/select2_i18n/az.js +3 -0
- data/app/assets/javascripts/visual_condition_builder/select2_i18n/bg.js +3 -0
- data/app/assets/javascripts/visual_condition_builder/select2_i18n/ca.js +3 -0
- data/app/assets/javascripts/visual_condition_builder/select2_i18n/cs.js +3 -0
- data/app/assets/javascripts/visual_condition_builder/select2_i18n/da.js +3 -0
- data/app/assets/javascripts/visual_condition_builder/select2_i18n/de.js +3 -0
- data/app/assets/javascripts/visual_condition_builder/select2_i18n/el.js +3 -0
- data/app/assets/javascripts/visual_condition_builder/select2_i18n/en.js +3 -0
- data/app/assets/javascripts/visual_condition_builder/select2_i18n/es.js +3 -0
- data/app/assets/javascripts/visual_condition_builder/select2_i18n/et.js +3 -0
- data/app/assets/javascripts/visual_condition_builder/select2_i18n/eu.js +3 -0
- data/app/assets/javascripts/visual_condition_builder/select2_i18n/fa.js +3 -0
- data/app/assets/javascripts/visual_condition_builder/select2_i18n/fi.js +3 -0
- data/app/assets/javascripts/visual_condition_builder/select2_i18n/fr.js +3 -0
- data/app/assets/javascripts/visual_condition_builder/select2_i18n/gl.js +3 -0
- data/app/assets/javascripts/visual_condition_builder/select2_i18n/he.js +3 -0
- data/app/assets/javascripts/visual_condition_builder/select2_i18n/hi.js +3 -0
- data/app/assets/javascripts/visual_condition_builder/select2_i18n/hr.js +3 -0
- data/app/assets/javascripts/visual_condition_builder/select2_i18n/hu.js +3 -0
- data/app/assets/javascripts/visual_condition_builder/select2_i18n/id.js +3 -0
- data/app/assets/javascripts/visual_condition_builder/select2_i18n/is.js +3 -0
- data/app/assets/javascripts/visual_condition_builder/select2_i18n/it.js +3 -0
- data/app/assets/javascripts/visual_condition_builder/select2_i18n/ja.js +3 -0
- data/app/assets/javascripts/visual_condition_builder/select2_i18n/km.js +3 -0
- data/app/assets/javascripts/visual_condition_builder/select2_i18n/ko.js +3 -0
- data/app/assets/javascripts/visual_condition_builder/select2_i18n/lt.js +3 -0
- data/app/assets/javascripts/visual_condition_builder/select2_i18n/lv.js +3 -0
- data/app/assets/javascripts/visual_condition_builder/select2_i18n/mk.js +3 -0
- data/app/assets/javascripts/visual_condition_builder/select2_i18n/ms.js +3 -0
- data/app/assets/javascripts/visual_condition_builder/select2_i18n/nb.js +3 -0
- data/app/assets/javascripts/visual_condition_builder/select2_i18n/nl.js +3 -0
- data/app/assets/javascripts/visual_condition_builder/select2_i18n/pl.js +3 -0
- data/app/assets/javascripts/visual_condition_builder/select2_i18n/pt-BR.js +3 -0
- data/app/assets/javascripts/visual_condition_builder/select2_i18n/pt.js +3 -0
- data/app/assets/javascripts/visual_condition_builder/select2_i18n/ro.js +3 -0
- data/app/assets/javascripts/visual_condition_builder/select2_i18n/ru.js +3 -0
- data/app/assets/javascripts/visual_condition_builder/select2_i18n/sk.js +3 -0
- data/app/assets/javascripts/visual_condition_builder/select2_i18n/sr-Cyrl.js +3 -0
- data/app/assets/javascripts/visual_condition_builder/select2_i18n/sr.js +3 -0
- data/app/assets/javascripts/visual_condition_builder/select2_i18n/sv.js +3 -0
- data/app/assets/javascripts/visual_condition_builder/select2_i18n/th.js +3 -0
- data/app/assets/javascripts/visual_condition_builder/select2_i18n/tr.js +3 -0
- data/app/assets/javascripts/visual_condition_builder/select2_i18n/uk.js +3 -0
- data/app/assets/javascripts/visual_condition_builder/select2_i18n/vi.js +3 -0
- data/app/assets/javascripts/visual_condition_builder/select2_i18n/zh-CN.js +3 -0
- data/app/assets/javascripts/visual_condition_builder/select2_i18n/zh-TW.js +3 -0
- data/app/assets/javascripts/visual_condition_builder.js +6 -0
- data/app/assets/stylesheets/visual_condition_builder/condition_builder.css +87 -0
- data/app/assets/stylesheets/visual_condition_builder/select2-bootstrap.css +722 -0
- data/app/assets/stylesheets/visual_condition_builder/select2.css +484 -0
- data/app/assets/stylesheets/visual_condition_builder.css +5 -0
- data/app/controllers/application_widget.rb +56 -0
- data/app/controllers/visual_condition_builder/application_controller.rb +5 -0
- data/app/controllers/visual_condition_builder/widgets_controller.rb +45 -0
- data/app/helpers/visual_condition_builder/application_helper.rb +74 -0
- data/app/models/visual_condition_builder/user.rb +10 -0
- data/app/views/visual_condition_builder/widgets/_widgets_list.html.erb +24 -0
- data/app/views/visual_condition_builder/widgets/index.html.erb +25 -0
- data/config/initializers/assets.rb +1 -0
- data/config/initializers/visual_condition_builder.rb +7 -0
- data/config/routes.rb +19 -0
- data/lib/generators/templates/create_taxweb_widgets_users.rb +18 -0
- data/lib/generators/templates/generic_widget.erb +12 -0
- data/lib/generators/templates/generic_widget.html.erb +2 -0
- data/lib/generators/visual_condition_builder/install_generator.rb +26 -0
- data/lib/generators/visual_condition_builder/view_generator.rb +11 -0
- data/lib/generators/visual_condition_builder/widget_generator.rb +25 -0
- data/lib/visual_condition_builder/converter.rb +22 -0
- data/lib/visual_condition_builder/dictionary.rb +166 -0
- data/lib/visual_condition_builder/engine.rb +6 -0
- data/lib/visual_condition_builder/helper.rb +19 -0
- data/lib/visual_condition_builder/version.rb +3 -0
- data/lib/visual_condition_builder.rb +9 -0
- metadata +127 -0
@@ -0,0 +1,2156 @@
|
|
1
|
+
/**
|
2
|
+
* autoNumeric.js
|
3
|
+
* @author: Bob Knothe
|
4
|
+
* @contributor: Sokolov Yura
|
5
|
+
* @version: 2.0-beta - 2016-09-11 GMT 10:00 PM / 22:00
|
6
|
+
*
|
7
|
+
* Created by Robert J. Knothe on 2009-08-09. Please report any bugs to https://github.com/BobKnothe/autoNumeric
|
8
|
+
*
|
9
|
+
* Copyright (c) 2009 Robert J. Knothe http://www.decorplanit.com/plugin/
|
10
|
+
*
|
11
|
+
* The MIT License (http://www.opensource.org/licenses/mit-license.php)
|
12
|
+
*
|
13
|
+
* Permission is hereby granted, free of charge, to any person
|
14
|
+
* obtaining a copy of this software and associated documentation
|
15
|
+
* files (the "Software"), to deal in the Software without
|
16
|
+
* restriction, including without limitation the rights to use,
|
17
|
+
* copy, modify, merge, publish, distribute, sub license, and/or sell
|
18
|
+
* copies of the Software, and to permit persons to whom the
|
19
|
+
* Software is furnished to do so, subject to the following
|
20
|
+
* conditions:
|
21
|
+
*
|
22
|
+
* The above copyright notice and this permission notice shall be
|
23
|
+
* included in all copies or substantial portions of the Software.
|
24
|
+
*
|
25
|
+
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
26
|
+
* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
|
27
|
+
* OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
28
|
+
* NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
|
29
|
+
* HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
|
30
|
+
* WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
|
31
|
+
* FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
|
32
|
+
* OTHER DEALINGS IN THE SOFTWARE.
|
33
|
+
*/
|
34
|
+
(function (factory) {
|
35
|
+
if (typeof define === "function" && define.amd) {
|
36
|
+
/** AMD. Register as an anonymous module. */
|
37
|
+
define(["jquery"], factory);
|
38
|
+
} else if (typeof module === "object" && module.exports) {
|
39
|
+
/** Node/CommonJS */
|
40
|
+
module.exports = factory(require("jquery"));
|
41
|
+
} else {
|
42
|
+
/** Browser globals */
|
43
|
+
factory(window.jQuery);
|
44
|
+
}
|
45
|
+
}(function ($) {
|
46
|
+
"use strict";
|
47
|
+
/*jslint browser: true, bitwise: true*/
|
48
|
+
/*global jQuery: false, sessionStorage: false*/
|
49
|
+
|
50
|
+
/**
|
51
|
+
* Cross browser routine for getting selected range/cursor position
|
52
|
+
*/
|
53
|
+
|
54
|
+
function getElementSelection(that) {
|
55
|
+
var position = {};
|
56
|
+
if (that.selectionStart === undefined) {
|
57
|
+
that.focus();
|
58
|
+
var select = document.selection.createRange();
|
59
|
+
position.length = select.text.length;
|
60
|
+
select.moveStart('character', -that.value.length);
|
61
|
+
position.end = select.text.length;
|
62
|
+
position.start = position.end - position.length;
|
63
|
+
} else {
|
64
|
+
position.start = that.selectionStart;
|
65
|
+
position.end = that.selectionEnd;
|
66
|
+
position.length = position.end - position.start;
|
67
|
+
}
|
68
|
+
return position;
|
69
|
+
}
|
70
|
+
|
71
|
+
/**
|
72
|
+
* Cross browser routine for setting selected range/cursor position
|
73
|
+
*/
|
74
|
+
|
75
|
+
function setElementSelection(that, start, end) {
|
76
|
+
if (that.selectionStart === undefined) {
|
77
|
+
that.focus();
|
78
|
+
var r = that.createTextRange();
|
79
|
+
r.collapse(true);
|
80
|
+
r.moveEnd('character', end);
|
81
|
+
r.moveStart('character', start);
|
82
|
+
r.select();
|
83
|
+
} else {
|
84
|
+
that.selectionStart = start;
|
85
|
+
that.selectionEnd = end;
|
86
|
+
}
|
87
|
+
}
|
88
|
+
|
89
|
+
/**
|
90
|
+
* Function to handle errors messages
|
91
|
+
*/
|
92
|
+
|
93
|
+
function throwErr(message, debug) {
|
94
|
+
if (debug) {
|
95
|
+
var err = new Error(message);
|
96
|
+
throw err;
|
97
|
+
}
|
98
|
+
}
|
99
|
+
|
100
|
+
/**
|
101
|
+
* run callbacks in parameters if any
|
102
|
+
* any parameter could be a callback:
|
103
|
+
* - a function, which invoked with jQuery element, parameters and this parameter name and returns parameter value
|
104
|
+
* - a name of function, attached to $(selector).autoNumeric.functionName(){} - which was called previously
|
105
|
+
*/
|
106
|
+
|
107
|
+
function runCallbacks($this, settings) {
|
108
|
+
/**
|
109
|
+
* loops through the settings object (option array) to find the following
|
110
|
+
* k = option name example k=aNum
|
111
|
+
* val = option value example val=0123456789
|
112
|
+
*/
|
113
|
+
$.each(settings, function (k, val) {
|
114
|
+
if (typeof val === 'function') {
|
115
|
+
settings[k] = val($this, settings, k);
|
116
|
+
} else if (typeof $this.autoNumeric[val] === 'function') {
|
117
|
+
/**
|
118
|
+
* calls the attached function from the html5 data example: data-a-sign="functionName"
|
119
|
+
*/
|
120
|
+
settings[k] = $this.autoNumeric[val]($this, settings, k);
|
121
|
+
}
|
122
|
+
});
|
123
|
+
}
|
124
|
+
|
125
|
+
/**
|
126
|
+
* Preparing user defined options for further usage
|
127
|
+
* merge them with defaults appropriately
|
128
|
+
*/
|
129
|
+
|
130
|
+
function autoCode($this, settings) {
|
131
|
+
runCallbacks($this, settings);
|
132
|
+
var vmax = settings.vMax.toString().split('.'),
|
133
|
+
vmin = (!settings.vMin && settings.vMin !== 0) ? [] : settings.vMin.toString().split('.');
|
134
|
+
settings.aNeg = settings.vMin < 0 ? '-' : '';
|
135
|
+
vmax[0] = vmax[0].replace('-', '');
|
136
|
+
vmin[0] = vmin[0].replace('-', '');
|
137
|
+
settings.mIntPos = Math.max(vmax[0].length, 1);
|
138
|
+
settings.mIntNeg = Math.max(vmin[0].length, 1);
|
139
|
+
if (settings.mDec === null) {
|
140
|
+
var vmaxLength = 0,
|
141
|
+
vminLength = 0;
|
142
|
+
if (vmax[1]) {
|
143
|
+
vmaxLength = vmax[1].length;
|
144
|
+
}
|
145
|
+
if (vmin[1]) {
|
146
|
+
vminLength = vmin[1].length;
|
147
|
+
}
|
148
|
+
settings.mDec = Math.max(vmaxLength, vminLength);
|
149
|
+
settings.oDec = settings.mDec;
|
150
|
+
} else {
|
151
|
+
settings.mDec = Number(settings.mDec);
|
152
|
+
}
|
153
|
+
/** set alternative decimal separator key */
|
154
|
+
if (settings.altDec === null && settings.mDec > 0) {
|
155
|
+
if (settings.aDec === '.' && settings.aSep !== ',') {
|
156
|
+
settings.altDec = ',';
|
157
|
+
} else if (settings.aDec === ',' && settings.aSep !== '.') {
|
158
|
+
settings.altDec = '.';
|
159
|
+
}
|
160
|
+
}
|
161
|
+
/** cache regexps for autoStrip */
|
162
|
+
var aNegReg = settings.aNeg ? '([-\\' + settings.aNeg + ']?)' : '(-?)';
|
163
|
+
settings.aNegRegAutoStrip = aNegReg;
|
164
|
+
settings.skipFirstAutoStrip = new RegExp(aNegReg + '[^-' + (settings.aNeg ? '\\' + settings.aNeg : '') + '\\' + settings.aDec + '\\d]' + '.*?(\\d|\\' + settings.aDec + '\\d)');
|
165
|
+
settings.skipLastAutoStrip = new RegExp('(\\d\\' + settings.aDec + '?)[^\\' + settings.aDec + '\\d]\\D*$');
|
166
|
+
var allowed = '-' + settings.aNum + '\\' + settings.aDec;
|
167
|
+
settings.allowedAutoStrip = new RegExp('[^' + allowed + ']', 'gi');
|
168
|
+
settings.numRegAutoStrip = new RegExp(aNegReg + '(?:\\' + settings.aDec + '?(\\d+\\' + settings.aDec + '\\d+)|(\\d*(?:\\' + settings.aDec + '\\d*)?))');
|
169
|
+
return settings;
|
170
|
+
}
|
171
|
+
|
172
|
+
/**
|
173
|
+
* strip all unwanted characters and leave only a number alert
|
174
|
+
*/
|
175
|
+
|
176
|
+
function autoStrip(s, settings) {
|
177
|
+
if (settings.aSign !== '') { /** remove currency sign */
|
178
|
+
s = s.replace(settings.aSign, '');
|
179
|
+
}
|
180
|
+
if (settings.aSuffix) { /** remove suffix */
|
181
|
+
while (s.indexOf(settings.aSuffix) > -1) {
|
182
|
+
s = s.replace(settings.aSuffix, '');
|
183
|
+
}
|
184
|
+
}
|
185
|
+
s = s.replace(settings.skipFirstAutoStrip, '$1$2'); /** first replace anything before digits */
|
186
|
+
if ((settings.pNeg === 's' || (settings.pSign === 's' && settings.pNeg !== 'p')) && s.indexOf('-') > -1 && s !== '') {
|
187
|
+
settings.trailingNegative = true;
|
188
|
+
}
|
189
|
+
s = s.replace(settings.skipLastAutoStrip, '$1'); /** then replace anything after digits */
|
190
|
+
s = s.replace(settings.allowedAutoStrip, ''); /** then remove any uninterested characters */
|
191
|
+
if (settings.altDec) {
|
192
|
+
s = s.replace(settings.altDec, settings.aDec);
|
193
|
+
} /** get only number string */
|
194
|
+
var m = s.match(settings.numRegAutoStrip);
|
195
|
+
s = m ? [m[1], m[2], m[3]].join('') : '';
|
196
|
+
if (settings.lZero === 'allow' || settings.lZero === 'keep') {
|
197
|
+
var parts = [],
|
198
|
+
nSign = '';
|
199
|
+
parts = s.split(settings.aDec);
|
200
|
+
if (parts[0].indexOf(settings.aNeg) !== -1) {
|
201
|
+
nSign = settings.aNeg;
|
202
|
+
parts[0] = parts[0].replace(settings.aNeg, '');
|
203
|
+
}
|
204
|
+
if (nSign === "" && parts[0].length > settings.mIntPos && parts[0].charAt(0) === '0') { /** strip leading zero if need */
|
205
|
+
parts[0] = parts[0].slice(1);
|
206
|
+
}
|
207
|
+
if (nSign !== '' && parts[0].length > settings.mIntNeg && parts[0].charAt(0) === '0') { /** strip leading zero if need */
|
208
|
+
parts[0] = parts[0].slice(1);
|
209
|
+
}
|
210
|
+
s = nSign + parts.join(settings.aDec);
|
211
|
+
}
|
212
|
+
if ((settings.onOff && settings.lZero === 'deny') || (settings.lZero === 'allow' && settings.onOff === false)) {
|
213
|
+
var strip_reg = '^' + settings.aNegRegAutoStrip + '0*(\\d|$)';
|
214
|
+
strip_reg = new RegExp(strip_reg);
|
215
|
+
s = s.replace(strip_reg, '$1$2');
|
216
|
+
}
|
217
|
+
return s;
|
218
|
+
}
|
219
|
+
|
220
|
+
/**
|
221
|
+
* places or removes brackets on negative values
|
222
|
+
*/
|
223
|
+
|
224
|
+
function negativeBracket(s, settings) {
|
225
|
+
if ((settings.pSign === 'p' && settings.pNeg === 'l') || (settings.pSign === 's' && settings.pNeg === 'p')) {
|
226
|
+
var brackets = settings.nBracket.split(',');
|
227
|
+
if (!settings.onOff) {
|
228
|
+
s = s.replace(settings.aNeg, '');
|
229
|
+
s = brackets[0] + s + brackets[1];
|
230
|
+
} else if (settings.onOff && s.charAt(0) === brackets[0]) {
|
231
|
+
s = s.replace(brackets[0], settings.aNeg);
|
232
|
+
s = s.replace(brackets[1], '');
|
233
|
+
}
|
234
|
+
}
|
235
|
+
return s;
|
236
|
+
}
|
237
|
+
|
238
|
+
/**
|
239
|
+
* convert locale format to javaSript numeric string
|
240
|
+
* allows locale decimal separator to be a period or comma - no thousand separator allowed of currency signs allowed
|
241
|
+
* '1234.56' OK
|
242
|
+
* '-1234.56' OK
|
243
|
+
* '1234.56-' OK
|
244
|
+
* '1234,56' OK
|
245
|
+
* '-1234,56' OK
|
246
|
+
* '1234,56-' OK
|
247
|
+
*/
|
248
|
+
|
249
|
+
function convertLocale(s) {
|
250
|
+
s = s.replace(',', '.');
|
251
|
+
if (s.lastIndexOf('-') !== -1 && s.lastIndexOf('-') === s.length - 1) {
|
252
|
+
s = s.replace('-', '');
|
253
|
+
s = '-' + s;
|
254
|
+
}
|
255
|
+
return s;
|
256
|
+
}
|
257
|
+
|
258
|
+
/**
|
259
|
+
* prepare number string to be converted to real number
|
260
|
+
*/
|
261
|
+
|
262
|
+
function fixNumber(s, aDec, aNeg) {
|
263
|
+
if (aDec && aDec !== '.') {
|
264
|
+
s = s.replace(aDec, '.');
|
265
|
+
}
|
266
|
+
if (aNeg && aNeg !== '-') {
|
267
|
+
s = s.replace(aNeg, '-');
|
268
|
+
}
|
269
|
+
if (!s.match(/\d/)) {
|
270
|
+
s += '0';
|
271
|
+
}
|
272
|
+
return s;
|
273
|
+
}
|
274
|
+
|
275
|
+
/**
|
276
|
+
* prepare real number to be converted to our format
|
277
|
+
*/
|
278
|
+
|
279
|
+
function presentNumber(s, aDec, aNeg) {
|
280
|
+
if (aNeg && aNeg !== '-') {
|
281
|
+
s = s.replace('-', aNeg);
|
282
|
+
}
|
283
|
+
if (aDec && aDec !== '.') {
|
284
|
+
s = s.replace('.', aDec);
|
285
|
+
}
|
286
|
+
return s;
|
287
|
+
}
|
288
|
+
|
289
|
+
/**
|
290
|
+
* private function to check for empty value
|
291
|
+
*/
|
292
|
+
|
293
|
+
function checkEmpty(iv, settings, signOnEmpty) {
|
294
|
+
if (iv === '' || iv === settings.aNeg) {
|
295
|
+
if (settings.wEmpty === 'always' || signOnEmpty) {
|
296
|
+
return (settings.pNeg === 'l') ? iv + settings.aSign + settings.aSuffix : settings.aSign + iv + settings.aSuffix;
|
297
|
+
}
|
298
|
+
return iv;
|
299
|
+
}
|
300
|
+
return null;
|
301
|
+
}
|
302
|
+
|
303
|
+
/**
|
304
|
+
* private function that formats our number
|
305
|
+
*/
|
306
|
+
function autoGroup(iv, settings) {
|
307
|
+
iv = autoStrip(iv, settings);
|
308
|
+
if (settings.trailingNegative && iv.indexOf('-') === -1) {
|
309
|
+
iv = '-' + iv;
|
310
|
+
}
|
311
|
+
var empty = checkEmpty(iv, settings, true),
|
312
|
+
isNeg = iv.indexOf('-') > -1;
|
313
|
+
if (isNeg) {
|
314
|
+
iv = iv.replace('-', '');
|
315
|
+
}
|
316
|
+
if (empty !== null) {
|
317
|
+
return empty;
|
318
|
+
}
|
319
|
+
var digitalGroup = '';
|
320
|
+
settings.dGroup = settings.dGroup.toString();
|
321
|
+
if (settings.dGroup === '2') {
|
322
|
+
digitalGroup = /(\d)((\d)(\d{2}?)+)$/;
|
323
|
+
} else if (settings.dGroup === '2s') {
|
324
|
+
digitalGroup = /(\d)((?:\d{2}){0,2}\d{3}(?:(?:\d{2}){2}\d{3})*?)$/;
|
325
|
+
} else if (settings.dGroup === '4') {
|
326
|
+
digitalGroup = /(\d)((\d{4}?)+)$/;
|
327
|
+
} else {
|
328
|
+
digitalGroup = /(\d)((\d{3}?)+)$/;
|
329
|
+
} /** splits the string at the decimal string */
|
330
|
+
var ivSplit = iv.split(settings.aDec);
|
331
|
+
if (settings.altDec && ivSplit.length === 1) {
|
332
|
+
ivSplit = iv.split(settings.altDec);
|
333
|
+
} /** assigns the whole number to the a variable (s) */
|
334
|
+
var s = ivSplit[0];
|
335
|
+
if (settings.aSep !== '') {
|
336
|
+
while (digitalGroup.test(s)) { /** re-inserts the thousand separator via a regular expression */
|
337
|
+
s = s.replace(digitalGroup, '$1' + settings.aSep + '$2');
|
338
|
+
}
|
339
|
+
}
|
340
|
+
if (settings.mDec !== 0 && ivSplit.length > 1) {
|
341
|
+
if (ivSplit[1].length > settings.mDec) {
|
342
|
+
ivSplit[1] = ivSplit[1].substring(0, settings.mDec);
|
343
|
+
} /** joins the whole number with the decimal value */
|
344
|
+
iv = s + settings.aDec + ivSplit[1];
|
345
|
+
} else { /** if whole numbers only */
|
346
|
+
iv = s;
|
347
|
+
}
|
348
|
+
if (settings.pSign === 'p') {
|
349
|
+
if (isNeg && settings.pNeg === 'l') {
|
350
|
+
iv = settings.aNeg + settings.aSign + iv;
|
351
|
+
}
|
352
|
+
if (isNeg && settings.pNeg === 'r') {
|
353
|
+
iv = settings.aSign + settings.aNeg + iv;
|
354
|
+
}
|
355
|
+
if (isNeg && settings.pNeg === 's') {
|
356
|
+
iv = settings.aSign + iv + settings.aNeg;
|
357
|
+
}
|
358
|
+
if (!isNeg) {
|
359
|
+
iv = settings.aSign + iv;
|
360
|
+
}
|
361
|
+
}
|
362
|
+
if (settings.pSign === 's') {
|
363
|
+
if (isNeg && settings.pNeg === 'r') {
|
364
|
+
iv = iv + settings.aSign + settings.aNeg;
|
365
|
+
}
|
366
|
+
if (isNeg && settings.pNeg === 'l') {
|
367
|
+
iv = iv + settings.aNeg + settings.aSign;
|
368
|
+
}
|
369
|
+
if (isNeg && settings.pNeg === 'p') {
|
370
|
+
iv = settings.aNeg + iv + settings.aSign;
|
371
|
+
}
|
372
|
+
if (!isNeg) {
|
373
|
+
iv = iv + settings.aSign;
|
374
|
+
}
|
375
|
+
}
|
376
|
+
if (settings.rawValue < 0 && settings.nBracket !== null) { /** removes the negative sign and places brackets */
|
377
|
+
iv = negativeBracket(iv, settings);
|
378
|
+
}
|
379
|
+
settings.trailingNegative = false;
|
380
|
+
return iv + settings.aSuffix;
|
381
|
+
}
|
382
|
+
|
383
|
+
/**
|
384
|
+
* round number after setting by pasting or $().autoNumericSet()
|
385
|
+
* private function for round the number
|
386
|
+
* please note this handled as text - JavaScript math function can return inaccurate values
|
387
|
+
* also this offers multiple rounding methods that are not easily accomplished in JavaScript
|
388
|
+
*/
|
389
|
+
|
390
|
+
function autoRound(iv, settings) { /** value to string */
|
391
|
+
iv = (iv === '') ? '0' : iv.toString();
|
392
|
+
if (settings.mRound === 'N05' || settings.mRound === 'U05' || settings.mRound === 'D05') {
|
393
|
+
iv = (settings.mRound === 'N05') ? (Math.round(iv * 20) / 20).toString() : (settings.mRound === 'U05') ? (Math.ceil(iv * 20) / 20).toString() : (Math.floor(iv * 20) / 20).toString();
|
394
|
+
return (iv.indexOf('.') === -1) ? iv + '.00' : (iv.length - iv.indexOf('.') < 3) ? iv + '0' : iv;
|
395
|
+
}
|
396
|
+
var ivRounded = '',
|
397
|
+
i = 0,
|
398
|
+
nSign = '',
|
399
|
+
rDec = (typeof(settings.aPad) === 'boolean' || settings.aPad === null) ? (settings.aPad ? settings.mDec : 0) : Number(settings.aPad);
|
400
|
+
var truncateZeros = function (ivRounded) { /** truncate not needed zeros */
|
401
|
+
var regex = rDec === 0 ? (/(\.(?:\d*[1-9])?)0*$/) : rDec === 1 ? (/(\.\d(?:\d*[1-9])?)0*$/) : new RegExp('(\\.\\d{' + rDec + '}(?:\\d*[1-9])?)0*');
|
402
|
+
ivRounded = ivRounded.replace(regex, '$1'); /** If there are no decimal places, we don't need a decimal point at the end */
|
403
|
+
if (rDec === 0) {
|
404
|
+
ivRounded = ivRounded.replace(/\.$/, '');
|
405
|
+
}
|
406
|
+
return ivRounded;
|
407
|
+
};
|
408
|
+
if (iv.charAt(0) === '-') { /** Checks if the iv (input Value)is a negative value */
|
409
|
+
nSign = '-';
|
410
|
+
iv = iv.replace('-', ''); /** removes the negative sign will be added back later if required */
|
411
|
+
}
|
412
|
+
if (!iv.match(/^\d/)) { /** append a zero if first character is not a digit (then it is likely to be a dot)*/
|
413
|
+
iv = '0' + iv;
|
414
|
+
}
|
415
|
+
if (nSign === '-' && Number(iv) === 0) { /** determines if the value is zero - if zero no negative sign */
|
416
|
+
nSign = '';
|
417
|
+
}
|
418
|
+
if ((Number(iv) > 0 && settings.lZero !== 'keep') || (iv.length > 0 && settings.lZero === 'allow')) { /** trims leading zero's if needed */
|
419
|
+
iv = iv.replace(/^0*(\d)/, '$1');
|
420
|
+
}
|
421
|
+
var dPos = iv.lastIndexOf('.'),
|
422
|
+
/** virtual decimal position */
|
423
|
+
vdPos = (dPos === -1) ? iv.length - 1 : dPos,
|
424
|
+
/** checks decimal places to determine if rounding is required */
|
425
|
+
cDec = (iv.length - 1) - vdPos; /** check if no rounding is required */
|
426
|
+
if (cDec <= settings.mDec) {
|
427
|
+
ivRounded = iv; /** check if we need to pad with zeros */
|
428
|
+
if (cDec < rDec) {
|
429
|
+
if (dPos === -1) {
|
430
|
+
//ivRounded += '.';
|
431
|
+
ivRounded += settings.aDec;
|
432
|
+
}
|
433
|
+
var zeros = '000000';
|
434
|
+
while (cDec < rDec) {
|
435
|
+
zeros = zeros.substring(0, rDec - cDec);
|
436
|
+
ivRounded += zeros;
|
437
|
+
cDec += zeros.length;
|
438
|
+
}
|
439
|
+
} else if (cDec > rDec) {
|
440
|
+
ivRounded = truncateZeros(ivRounded);
|
441
|
+
} else if (cDec === 0 && rDec === 0) {
|
442
|
+
ivRounded = ivRounded.replace(/\.$/, '');
|
443
|
+
}
|
444
|
+
return (Number(ivRounded) === 0) ? ivRounded : nSign + ivRounded;
|
445
|
+
} /** rounded length of the string after rounding */
|
446
|
+
var rLength = dPos + settings.mDec,
|
447
|
+
tRound = Number(iv.charAt(rLength + 1)),
|
448
|
+
ivArray = iv.substring(0, rLength + 1).split(''),
|
449
|
+
odd = (iv.charAt(rLength) === '.') ? (iv.charAt(rLength - 1) % 2) : (iv.charAt(rLength) % 2);
|
450
|
+
/*jslint white: true*/
|
451
|
+
if ((tRound > 4 && settings.mRound === 'S') || /** Round half up symmetric */
|
452
|
+
(tRound > 4 && settings.mRound === 'A' && nSign === '') || /** Round half up asymmetric positive values */
|
453
|
+
(tRound > 5 && settings.mRound === 'A' && nSign === '-') || /** Round half up asymmetric negative values */
|
454
|
+
(tRound > 5 && settings.mRound === 's') || /** Round half down symmetric */
|
455
|
+
(tRound > 5 && settings.mRound === 'a' && nSign === '') || /** Round half down asymmetric positive values */
|
456
|
+
(tRound > 4 && settings.mRound === 'a' && nSign === '-') || /** Round half down asymmetric negative values */
|
457
|
+
(tRound > 5 && settings.mRound === 'B') || /** Round half even "Banker's Rounding" */
|
458
|
+
(tRound === 5 && settings.mRound === 'B' && odd === 1) || /** Round half even "Banker's Rounding" */
|
459
|
+
(tRound > 0 && settings.mRound === 'C' && nSign === '') || /** Round to ceiling toward positive infinite */
|
460
|
+
(tRound > 0 && settings.mRound === 'F' && nSign === '-') || /** Round to floor toward negative infinite */
|
461
|
+
(tRound > 0 && settings.mRound === 'U')) { /** Round up away from zero */
|
462
|
+
/*jslint white: false*/
|
463
|
+
for (i = (ivArray.length - 1); i >= 0; i -= 1) { /** Round up the last digit if required, and continue until no more 9's are found */
|
464
|
+
if (ivArray[i] !== '.') {
|
465
|
+
ivArray[i] = +ivArray[i] + 1;
|
466
|
+
if (ivArray[i] < 10) {
|
467
|
+
break;
|
468
|
+
}
|
469
|
+
if (i > 0) {
|
470
|
+
ivArray[i] = '0';
|
471
|
+
}
|
472
|
+
}
|
473
|
+
}
|
474
|
+
}
|
475
|
+
ivArray = ivArray.slice(0, rLength + 1); /** Reconstruct the string, converting any 10's to 0's */
|
476
|
+
ivRounded = truncateZeros(ivArray.join('')); /** return rounded value */
|
477
|
+
return (Number(ivRounded) === 0) ? ivRounded : nSign + ivRounded;
|
478
|
+
}
|
479
|
+
|
480
|
+
/**
|
481
|
+
* truncate decimal part of a number
|
482
|
+
*/
|
483
|
+
|
484
|
+
function truncateDecimal(s, settings, paste) {
|
485
|
+
var aDec = settings.aDec,
|
486
|
+
mDec = settings.mDec;
|
487
|
+
s = (paste === 'paste') ? autoRound(s, settings) : s;
|
488
|
+
if (aDec && mDec) {
|
489
|
+
var parts = s.split(aDec);
|
490
|
+
/** truncate decimal part to satisfying length
|
491
|
+
* cause we would round it anyway */
|
492
|
+
if (parts[1] && parts[1].length > mDec) {
|
493
|
+
if (mDec > 0) {
|
494
|
+
parts[1] = parts[1].substring(0, mDec);
|
495
|
+
s = parts.join(aDec);
|
496
|
+
} else {
|
497
|
+
s = parts[0];
|
498
|
+
}
|
499
|
+
}
|
500
|
+
}
|
501
|
+
return s;
|
502
|
+
}
|
503
|
+
|
504
|
+
/**
|
505
|
+
* Function to parse vMin, vMax & the input value to prepare for testing to determine if the value falls within the min / max range
|
506
|
+
* Return an object example: vMin: "999999999999999.99" returns the following "{s: -1, e: 12, c: Array[15]}"
|
507
|
+
* This function is adapted from Big.js https://github.com/MikeMcl/big.js/
|
508
|
+
* Many thanks to Mike
|
509
|
+
*/
|
510
|
+
|
511
|
+
function parseStr(n) {
|
512
|
+
var x = {},
|
513
|
+
e,
|
514
|
+
i,
|
515
|
+
nL,
|
516
|
+
j;
|
517
|
+
/** Minus zero? */
|
518
|
+
if (n === 0 && 1 / n < 0) {
|
519
|
+
n = '-0';
|
520
|
+
}
|
521
|
+
/** Determine sign. 1 positive, -1 negative */
|
522
|
+
if (n.charAt(0) === '-') {
|
523
|
+
n = n.slice(1);
|
524
|
+
x.s = -1;
|
525
|
+
} else {
|
526
|
+
x.s = 1;
|
527
|
+
}
|
528
|
+
/** Decimal point? */
|
529
|
+
e = n.indexOf('.');
|
530
|
+
if (e > -1) {
|
531
|
+
n = n.replace('.', '');
|
532
|
+
}
|
533
|
+
/** length of string if no decimal character */
|
534
|
+
if (e < 0) {
|
535
|
+
/** Integer. */
|
536
|
+
e = n.length;
|
537
|
+
}
|
538
|
+
/** Determine leading zeros. */
|
539
|
+
i = (n.search(/[1-9]/i) === -1) ? n.length : n.search(/[1-9]/i);
|
540
|
+
nL = n.length;
|
541
|
+
if (i === nL) {
|
542
|
+
/** Zero. */
|
543
|
+
x.e = 0;
|
544
|
+
x.c = [0];
|
545
|
+
} else {
|
546
|
+
/** Determine trailing zeros. */
|
547
|
+
for (j = nL - 1; n.charAt(j) === '0'; j -= 1) {
|
548
|
+
nL -= 1;
|
549
|
+
}
|
550
|
+
nL -= 1;
|
551
|
+
/** Decimal location. */
|
552
|
+
x.e = e - i - 1;
|
553
|
+
x.c = [];
|
554
|
+
/** Convert string to array of digits without leading/trailing zeros. */
|
555
|
+
for (e = 0; i <= nL; i += 1) {
|
556
|
+
x.c[e] = +n.charAt(i);
|
557
|
+
e += 1;
|
558
|
+
}
|
559
|
+
}
|
560
|
+
return x;
|
561
|
+
}
|
562
|
+
|
563
|
+
/**
|
564
|
+
* Function to test if the input value falls with the Min / Max settings
|
565
|
+
* This uses the parsed strings for the above parseStr function
|
566
|
+
* This function is adapted from Big.js https://github.com/MikeMcl/big.js/
|
567
|
+
* Many thanks to Mike
|
568
|
+
*/
|
569
|
+
|
570
|
+
function testMinMax(y, x) {
|
571
|
+
var xNeg,
|
572
|
+
xc = x.c,
|
573
|
+
yc = y.c,
|
574
|
+
i = x.s,
|
575
|
+
j = y.s,
|
576
|
+
k = x.e,
|
577
|
+
l = y.e;
|
578
|
+
/** Either zero? */
|
579
|
+
if (!xc[0] || !yc[0]) {
|
580
|
+
return !xc[0] ? !yc[0] ? 0 : -j : i;
|
581
|
+
}
|
582
|
+
/** Signs differ? */
|
583
|
+
if (i !== j) {
|
584
|
+
return i;
|
585
|
+
}
|
586
|
+
xNeg = i < 0;
|
587
|
+
/** Compare exponents. */
|
588
|
+
if (k !== l) {
|
589
|
+
return k > l ^ xNeg ? 1 : -1;
|
590
|
+
}
|
591
|
+
i = -1;
|
592
|
+
k = xc.length;
|
593
|
+
l = yc.length;
|
594
|
+
j = (k < l) ? k : l;
|
595
|
+
/** Compare digit by digit. */
|
596
|
+
for (i += 1; i < j; i += 1) {
|
597
|
+
if (xc[i] !== yc[i]) {
|
598
|
+
return xc[i] > yc[i] ^ xNeg ? 1 : -1;
|
599
|
+
}
|
600
|
+
}
|
601
|
+
/** Compare lengths */
|
602
|
+
return k === l ? 0 : k > l ^ xNeg ? 1 : -1;
|
603
|
+
}
|
604
|
+
|
605
|
+
/**
|
606
|
+
* checking that number satisfy format conditions
|
607
|
+
* and lays between settings.vMin and settings.vMax
|
608
|
+
* and the string length does not exceed the digits in settings.vMin and settings.vMax
|
609
|
+
*/
|
610
|
+
|
611
|
+
function autoCheck(s, settings) {
|
612
|
+
s = s.toString();
|
613
|
+
s = s.replace(',', '.');
|
614
|
+
var minParse = parseStr(settings.vMin),
|
615
|
+
maxParse = parseStr(settings.vMax),
|
616
|
+
valParse = parseStr(s);
|
617
|
+
return testMinMax(minParse, valParse) > -1 && testMinMax(maxParse, valParse) < 1;
|
618
|
+
}
|
619
|
+
|
620
|
+
/**
|
621
|
+
* Holder object for field properties
|
622
|
+
*/
|
623
|
+
|
624
|
+
function AutoNumericHolder(that, settings) {
|
625
|
+
this.settings = settings;
|
626
|
+
this.that = that;
|
627
|
+
this.$that = $(that);
|
628
|
+
this.formatted = false;
|
629
|
+
this.settingsClone = autoCode(this.$that, this.settings);
|
630
|
+
this.value = that.value;
|
631
|
+
}
|
632
|
+
AutoNumericHolder.prototype = {
|
633
|
+
init: function (e) {
|
634
|
+
this.value = this.that.value;
|
635
|
+
this.settingsClone = autoCode(this.$that, this.settings);
|
636
|
+
this.ctrlKey = e.ctrlKey;
|
637
|
+
this.cmdKey = e.metaKey;
|
638
|
+
this.shiftKey = e.shiftKey;
|
639
|
+
this.selection = getElementSelection(this.that); /** keypress event overwrites meaningful value of e.keyCode */
|
640
|
+
if (e.type === 'keydown' || e.type === 'keyup') {
|
641
|
+
this.kdCode = e.keyCode;
|
642
|
+
}
|
643
|
+
this.which = e.which;
|
644
|
+
this.processed = false;
|
645
|
+
this.formatted = false;
|
646
|
+
},
|
647
|
+
setSelection: function (start, end, setReal) {
|
648
|
+
start = Math.max(start, 0);
|
649
|
+
end = Math.min(end, this.that.value.length);
|
650
|
+
this.selection = {
|
651
|
+
start: start,
|
652
|
+
end: end,
|
653
|
+
length: end - start
|
654
|
+
};
|
655
|
+
if (setReal === undefined || setReal) {
|
656
|
+
setElementSelection(this.that, start, end);
|
657
|
+
}
|
658
|
+
},
|
659
|
+
setPosition: function (pos, setReal) {
|
660
|
+
this.setSelection(pos, pos, setReal);
|
661
|
+
},
|
662
|
+
getBeforeAfter: function () {
|
663
|
+
var value = this.value,
|
664
|
+
left = value.substring(0, this.selection.start),
|
665
|
+
right = value.substring(this.selection.end, value.length);
|
666
|
+
return [left, right];
|
667
|
+
},
|
668
|
+
getBeforeAfterStriped: function () {
|
669
|
+
var settingsClone = this.settingsClone,
|
670
|
+
parts = this.getBeforeAfter();
|
671
|
+
parts[0] = autoStrip(parts[0], this.settingsClone);
|
672
|
+
parts[1] = autoStrip(parts[1], this.settingsClone);
|
673
|
+
if (settingsClone.trailingNegative && parts[0].indexOf('-') === -1) {
|
674
|
+
parts[0] = '-' + parts[0];
|
675
|
+
parts[1] = (parts[1] === '-') ? '' : parts[1];
|
676
|
+
}
|
677
|
+
settingsClone.trailingNegative = false;
|
678
|
+
return parts;
|
679
|
+
},
|
680
|
+
|
681
|
+
/**
|
682
|
+
* strip parts from excess characters and leading zeroes
|
683
|
+
*/
|
684
|
+
normalizeParts: function (left, right) {
|
685
|
+
var settingsClone = this.settingsClone;
|
686
|
+
left = autoStrip(left, settingsClone); /** prevents multiple leading zeros from being entered */
|
687
|
+
right = autoStrip(right, settingsClone); /** if right is not empty and first character is not aDec, */
|
688
|
+
if (settingsClone.trailingNegative && left.indexOf('-') === -1) {
|
689
|
+
left = '-' + left;
|
690
|
+
settingsClone.trailingNegative = false;
|
691
|
+
}
|
692
|
+
if ((left === '' || left === settingsClone.aNeg) && settingsClone.lZero === 'deny') {
|
693
|
+
if (right > '') {
|
694
|
+
right = right.replace(/^0*(\d)/, '$1');
|
695
|
+
}
|
696
|
+
}
|
697
|
+
var new_value = left + right; /** insert zero if has leading dot */
|
698
|
+
if (settingsClone.aDec) {
|
699
|
+
var m = new_value.match(new RegExp('^' + settingsClone.aNegRegAutoStrip + '\\' + settingsClone.aDec));
|
700
|
+
if (m) {
|
701
|
+
left = left.replace(m[1], m[1] + '0');
|
702
|
+
new_value = left + right;
|
703
|
+
}
|
704
|
+
}
|
705
|
+
return [left, right];
|
706
|
+
},
|
707
|
+
|
708
|
+
/**
|
709
|
+
* set part of number to value keeping position of cursor
|
710
|
+
*/
|
711
|
+
setValueParts: function (left, right, paste) {
|
712
|
+
var settingsClone = this.settingsClone,
|
713
|
+
parts = this.normalizeParts(left, right),
|
714
|
+
new_value = parts.join(''),
|
715
|
+
position = parts[0].length;
|
716
|
+
if (autoCheck(new_value, settingsClone)) {
|
717
|
+
new_value = truncateDecimal(new_value, settingsClone, paste);
|
718
|
+
var test_value = (new_value.indexOf(',') !== -1) ? new_value.replace(',', '.') : new_value,
|
719
|
+
text_value = test_value;
|
720
|
+
if (test_value === '' || test_value === settingsClone.aNeg) {
|
721
|
+
settingsClone.rawValue = '';
|
722
|
+
} else {
|
723
|
+
settingsClone.rawValue = text_value;
|
724
|
+
}
|
725
|
+
if (position > new_value.length) {
|
726
|
+
position = new_value.length;
|
727
|
+
}
|
728
|
+
this.value = new_value;
|
729
|
+
this.setPosition(position, false);
|
730
|
+
return true;
|
731
|
+
}
|
732
|
+
return false;
|
733
|
+
},
|
734
|
+
|
735
|
+
/**
|
736
|
+
* helper function for expandSelectionOnSign
|
737
|
+
* returns sign position of a formatted value
|
738
|
+
*/
|
739
|
+
signPosition: function () {
|
740
|
+
var settingsClone = this.settingsClone,
|
741
|
+
aSign = settingsClone.aSign,
|
742
|
+
that = this.that;
|
743
|
+
if (aSign) {
|
744
|
+
var aSignLen = aSign.length;
|
745
|
+
if (settingsClone.pSign === 'p') {
|
746
|
+
var hasNeg = settingsClone.aNeg && that.value && that.value.charAt(0) === settingsClone.aNeg;
|
747
|
+
return hasNeg ? [1, aSignLen + 1] : [0, aSignLen];
|
748
|
+
}
|
749
|
+
var valueLen = that.value.length;
|
750
|
+
return [valueLen - aSignLen, valueLen];
|
751
|
+
}
|
752
|
+
return [1000, -1];
|
753
|
+
},
|
754
|
+
|
755
|
+
/**
|
756
|
+
* expands selection to cover whole sign
|
757
|
+
* prevents partial deletion/copying/overwriting of a sign
|
758
|
+
*/
|
759
|
+
expandSelectionOnSign: function (setReal) {
|
760
|
+
var sign_position = this.signPosition(),
|
761
|
+
selection = this.selection;
|
762
|
+
if (selection.start < sign_position[1] && selection.end > sign_position[0]) { /** if selection catches something except sign and catches only space from sign */
|
763
|
+
if ((selection.start < sign_position[0] || selection.end > sign_position[1]) && this.value.substring(Math.max(selection.start, sign_position[0]), Math.min(selection.end, sign_position[1])).match(/^\s*$/)) { /** then select without empty space */
|
764
|
+
if (selection.start < sign_position[0]) {
|
765
|
+
this.setSelection(selection.start, sign_position[0], setReal);
|
766
|
+
} else {
|
767
|
+
this.setSelection(sign_position[1], selection.end, setReal);
|
768
|
+
}
|
769
|
+
} else { /** else select with whole sign */
|
770
|
+
this.setSelection(Math.min(selection.start, sign_position[0]), Math.max(selection.end, sign_position[1]), setReal);
|
771
|
+
}
|
772
|
+
}
|
773
|
+
},
|
774
|
+
|
775
|
+
/**
|
776
|
+
* try to strip pasted value to digits
|
777
|
+
*/
|
778
|
+
checkPaste: function () {
|
779
|
+
if (this.valuePartsBeforePaste !== undefined) {
|
780
|
+
var parts = this.getBeforeAfter(),
|
781
|
+
oldParts = this.valuePartsBeforePaste;
|
782
|
+
delete this.valuePartsBeforePaste; /** try to strip pasted value first */
|
783
|
+
parts[0] = parts[0].substr(0, oldParts[0].length) + autoStrip(parts[0].substr(oldParts[0].length), this.settingsClone);
|
784
|
+
if (!this.setValueParts(parts[0], parts[1], 'paste')) {
|
785
|
+
this.value = oldParts.join('');
|
786
|
+
this.setPosition(oldParts[0].length, false);
|
787
|
+
}
|
788
|
+
}
|
789
|
+
},
|
790
|
+
|
791
|
+
/**
|
792
|
+
* process pasting, cursor moving and skipping of not interesting keys
|
793
|
+
* if returns true, further processing is not performed
|
794
|
+
*/
|
795
|
+
skipAllways: function (e) {
|
796
|
+
var kdCode = this.kdCode,
|
797
|
+
which = this.which,
|
798
|
+
ctrlKey = this.ctrlKey,
|
799
|
+
cmdKey = this.cmdKey,
|
800
|
+
shiftKey = this.shiftKey; /** catch the ctrl up on ctrl-v */
|
801
|
+
if (((ctrlKey || cmdKey) && e.type === 'keyup' && this.valuePartsBeforePaste !== undefined) || (shiftKey && kdCode === 45)) {
|
802
|
+
this.checkPaste();
|
803
|
+
return false;
|
804
|
+
}
|
805
|
+
/** codes are taken from http://www.cambiaresearch.com/c4/702b8cd1-e5b0-42e6-83ac-25f0306e3e25/Javascript-Char-Codes-Key-Codes.aspx
|
806
|
+
* skip Fx keys, windows keys, other special keys
|
807
|
+
*/
|
808
|
+
if ((kdCode >= keyCode.F1 && kdCode <= keyCode.F12) ||
|
809
|
+
(kdCode >= keyCode.Windows && kdCode <= keyCode.RightClick) ||
|
810
|
+
(kdCode >= keyCode.Tab && kdCode < keyCode.Space) ||
|
811
|
+
(kdCode < keyCode.Backspace &&
|
812
|
+
(which === 0 || which === kdCode)) ||
|
813
|
+
kdCode === keyCode.NumLock ||
|
814
|
+
kdCode === keyCode.ScrollLock ||
|
815
|
+
kdCode === keyCode.Insert ||
|
816
|
+
kdCode === keyCode.Command) {
|
817
|
+
return true;
|
818
|
+
}
|
819
|
+
if ((ctrlKey || cmdKey) && kdCode === keyCode.a) { /** if select all (a)*/
|
820
|
+
if (this.settings.sNumber) {
|
821
|
+
e.preventDefault();
|
822
|
+
var valueLen = this.that.value.length,
|
823
|
+
aSignLen = this.settings.aSign.length,
|
824
|
+
negLen = (this.that.value.indexOf('-') === -1) ? 0 : 1,
|
825
|
+
aSuffixLen = this.settings.aSuffix.length,
|
826
|
+
pSign = this.settings.pSign,
|
827
|
+
pNeg = this.settings.pNeg,
|
828
|
+
start = (pSign === 's') ? 0 : (pNeg === 'l' && negLen === 1 && aSignLen > 0) ? aSignLen + 1 : aSignLen,
|
829
|
+
end = (pSign === 'p') ? valueLen - aSuffixLen : (pNeg === 'l') ? valueLen - (aSuffixLen + aSignLen) : (pNeg === 'r') ? (aSignLen > 0) ? valueLen - (aSignLen + negLen + aSuffixLen) : valueLen - (aSignLen + aSuffixLen) : valueLen - (aSignLen + aSuffixLen);
|
830
|
+
setElementSelection(this.that, start, end);
|
831
|
+
}
|
832
|
+
return true;
|
833
|
+
}
|
834
|
+
if ((ctrlKey || cmdKey) && (kdCode === keyCode.c || kdCode === keyCode.v || kdCode === keyCode.x)) { /** if copy (c) paste (v) or cut (x) */
|
835
|
+
if (e.type === 'keydown') {
|
836
|
+
this.expandSelectionOnSign();
|
837
|
+
}
|
838
|
+
if (kdCode === keyCode.v || kdCode === keyCode.Insert) { /** try to prevent wrong paste */
|
839
|
+
if (e.type === 'keydown' || e.type === 'keypress') {
|
840
|
+
if (this.valuePartsBeforePaste === undefined) {
|
841
|
+
this.valuePartsBeforePaste = this.getBeforeAfter();
|
842
|
+
}
|
843
|
+
} else {
|
844
|
+
this.checkPaste();
|
845
|
+
}
|
846
|
+
}
|
847
|
+
return e.type === 'keydown' || e.type === 'keypress' || kdCode === keyCode.c;
|
848
|
+
}
|
849
|
+
if (ctrlKey || cmdKey) {
|
850
|
+
return true;
|
851
|
+
}
|
852
|
+
if (kdCode === keyCode.LeftArrow || kdCode === keyCode.RightArrow) { /** jump over thousand separator */
|
853
|
+
var aSep = this.settingsClone.aSep,
|
854
|
+
aDec = this.settingsClone.aDec,
|
855
|
+
startJump = this.selection.start,
|
856
|
+
value = this.that.value;
|
857
|
+
if (e.type === 'keydown' && !this.shiftKey) {
|
858
|
+
if (kdCode === keyCode.LeftArrow && (value.charAt(startJump - 2) === aSep || value.charAt(startJump - 2) === aDec)) {
|
859
|
+
this.setPosition(startJump - 1);
|
860
|
+
} else if (kdCode === keyCode.RightArrow && (value.charAt(startJump + 1) === aSep || value.charAt(startJump + 1) === aDec)) {
|
861
|
+
this.setPosition(startJump + 1);
|
862
|
+
}
|
863
|
+
}
|
864
|
+
return true;
|
865
|
+
}
|
866
|
+
if (kdCode >= keyCode.PageDown && kdCode <= keyCode.DownArrow) {
|
867
|
+
return true;
|
868
|
+
}
|
869
|
+
return false;
|
870
|
+
},
|
871
|
+
|
872
|
+
/**
|
873
|
+
* process deletion of characters when the minus sign is to the right of the numeric characters
|
874
|
+
*/
|
875
|
+
processTrailing: function (parts) {
|
876
|
+
var settingsClone = this.settingsClone;
|
877
|
+
if (settingsClone.pSign === 'p' && settingsClone.pNeg === 's') {
|
878
|
+
if (this.kdCode === 8) {
|
879
|
+
settingsClone.caretFix = (this.selection.start >= this.value.indexOf(settingsClone.aSuffix) && settingsClone.aSuffix !== '') ? true : false;
|
880
|
+
if (this.value.charAt(this.selection.start - 1) === '-') {
|
881
|
+
parts[0] = parts[0].substring(1);
|
882
|
+
} else if (this.selection.start <= this.value.length - settingsClone.aSuffix.length) {
|
883
|
+
parts[0] = parts[0].substring(0, parts[0].length - 1);
|
884
|
+
}
|
885
|
+
} else {
|
886
|
+
settingsClone.caretFix = (this.selection.start >= this.value.indexOf(settingsClone.aSuffix) && settingsClone.aSuffix !== '') ? true : false;
|
887
|
+
if (this.selection.start >= this.value.indexOf(settingsClone.aSign) + settingsClone.aSign.length) {
|
888
|
+
parts[1] = parts[1].substring(1, parts[1].length);
|
889
|
+
}
|
890
|
+
if (parts[0].indexOf('-') > -1 && this.value.charAt(this.selection.start) === '-') {
|
891
|
+
parts[0] = parts[0].substring(1);
|
892
|
+
}
|
893
|
+
}
|
894
|
+
}
|
895
|
+
if (settingsClone.pSign === 's' && settingsClone.pNeg === 'l') {
|
896
|
+
settingsClone.caretFix = (this.selection.start >= this.value.indexOf(settingsClone.aNeg) + settingsClone.aNeg.length) ? true : false;
|
897
|
+
if (this.kdCode === 8) {
|
898
|
+
if (this.selection.start === (this.value.indexOf(settingsClone.aNeg) + settingsClone.aNeg.length) && this.value.indexOf(settingsClone.aNeg) !== -1) {
|
899
|
+
parts[0] = parts[0].substring(1);
|
900
|
+
} else if (parts[0] !== '-' && ((this.selection.start <= this.value.indexOf(settingsClone.aNeg)) || this.value.indexOf(settingsClone.aNeg) === -1)) {
|
901
|
+
parts[0] = parts[0].substring(0, parts[0].length - 1);
|
902
|
+
}
|
903
|
+
} else {
|
904
|
+
if (parts[0][0] === '-') {
|
905
|
+
parts[1] = parts[1].substring(1);
|
906
|
+
}
|
907
|
+
if (this.selection.start === this.value.indexOf(settingsClone.aNeg) && this.value.indexOf(settingsClone.aNeg) !== -1) {
|
908
|
+
parts[0] = parts[0].substring(1);
|
909
|
+
}
|
910
|
+
}
|
911
|
+
}
|
912
|
+
if (settingsClone.pSign === 's' && settingsClone.pNeg === 'r') {
|
913
|
+
settingsClone.caretFix = (this.selection.start >= this.value.indexOf(settingsClone.aNeg) + settingsClone.aNeg.length) ? true : false;
|
914
|
+
if (this.kdCode === 8) {
|
915
|
+
if (this.selection.start === (this.value.indexOf(settingsClone.aNeg) + settingsClone.aNeg.length)) {
|
916
|
+
parts[0] = parts[0].substring(1);
|
917
|
+
} else if (parts[0] !== '-' && this.selection.start <= (this.value.indexOf(settingsClone.aNeg) - settingsClone.aSign.length)) {
|
918
|
+
parts[0] = parts[0].substring(0, parts[0].length - 1);
|
919
|
+
} else if (parts[0] !== '' && this.value.indexOf(settingsClone.aNeg) === -1) {
|
920
|
+
parts[0] = parts[0].substring(0, parts[0].length - 1);
|
921
|
+
}
|
922
|
+
} else {
|
923
|
+
settingsClone.caretFix = (this.selection.start >= this.value.indexOf(settingsClone.aSign) && settingsClone.aSign !== '') ? true : false;
|
924
|
+
if (this.selection.start === this.value.indexOf(settingsClone.aNeg)) {
|
925
|
+
parts[0] = parts[0].substring(1);
|
926
|
+
}
|
927
|
+
parts[1] = parts[1].substring(1);
|
928
|
+
}
|
929
|
+
}
|
930
|
+
return parts;
|
931
|
+
},
|
932
|
+
|
933
|
+
/**
|
934
|
+
* process deletion of characters
|
935
|
+
* returns true if processing performed
|
936
|
+
*/
|
937
|
+
processAllways: function () {
|
938
|
+
var settingsClone = this.settingsClone,
|
939
|
+
parts = [];
|
940
|
+
if (this.kdCode === keyCode.Backspace || this.kdCode === keyCode.Delete) {
|
941
|
+
if (!this.selection.length) {
|
942
|
+
parts = this.getBeforeAfterStriped();
|
943
|
+
if (parts[0] === '' && parts[1] === '') {
|
944
|
+
settingsClone.throwInput = false;
|
945
|
+
}
|
946
|
+
if (((settingsClone.pSign === 'p' && settingsClone.pNeg === 's') || (settingsClone.pSign === 's' && (settingsClone.pNeg === 'l' || settingsClone.pNeg === 'r'))) && this.value.indexOf('-') !== -1) {
|
947
|
+
parts = this.processTrailing(parts);
|
948
|
+
} else {
|
949
|
+
if (this.kdCode === 8) {
|
950
|
+
parts[0] = parts[0].substring(0, parts[0].length - 1);
|
951
|
+
} else {
|
952
|
+
parts[1] = parts[1].substring(1, parts[1].length);
|
953
|
+
}
|
954
|
+
}
|
955
|
+
this.setValueParts(parts[0], parts[1]);
|
956
|
+
} else {
|
957
|
+
this.expandSelectionOnSign(false);
|
958
|
+
parts = this.getBeforeAfterStriped();
|
959
|
+
this.setValueParts(parts[0], parts[1]);
|
960
|
+
}
|
961
|
+
return true;
|
962
|
+
}
|
963
|
+
return false;
|
964
|
+
},
|
965
|
+
|
966
|
+
/**
|
967
|
+
* process insertion of characters
|
968
|
+
* returns true if processing performed
|
969
|
+
*/
|
970
|
+
processKeypress: function () {
|
971
|
+
var settingsClone = this.settingsClone,
|
972
|
+
cCode = String.fromCharCode(this.which),
|
973
|
+
parts = this.getBeforeAfterStriped(),
|
974
|
+
left = parts[0],
|
975
|
+
right = parts[1];
|
976
|
+
settingsClone.throwInput = true;
|
977
|
+
/** start rules when the decimal character key is pressed always use numeric pad dot to insert decimal separator */
|
978
|
+
if (cCode === settingsClone.aDec || (settingsClone.altDec && cCode === settingsClone.altDec) || ((cCode === '.' || cCode === ',') && this.kdCode === keyCode.DotNumpad)) { /** do not allow decimal character if no decimal part allowed */
|
979
|
+
if (!settingsClone.mDec || !settingsClone.aDec) {
|
980
|
+
return true;
|
981
|
+
} /** do not allow decimal character before aNeg character */
|
982
|
+
if (settingsClone.aNeg && right.indexOf(settingsClone.aNeg) > -1) {
|
983
|
+
return true;
|
984
|
+
} /** do not allow decimal character if other decimal character present */
|
985
|
+
if (left.indexOf(settingsClone.aDec) > -1) {
|
986
|
+
return true;
|
987
|
+
}
|
988
|
+
if (right.indexOf(settingsClone.aDec) > 0) {
|
989
|
+
return true;
|
990
|
+
}
|
991
|
+
if (right.indexOf(settingsClone.aDec) === 0) {
|
992
|
+
right = right.substr(1);
|
993
|
+
}
|
994
|
+
this.setValueParts(left + settingsClone.aDec, right, null);
|
995
|
+
return true;
|
996
|
+
}
|
997
|
+
if ((cCode === '-' || cCode === '+') && settingsClone.aNeg === '-') { /** prevent minus if not allowed */
|
998
|
+
if (!settingsClone) {
|
999
|
+
return true;
|
1000
|
+
} /** caret is always after minus */
|
1001
|
+
if ((settingsClone.pSign === 'p' && settingsClone.pNeg === 's') || (settingsClone.pSign === 's' && settingsClone.pNeg !== 'p')) {
|
1002
|
+
if (left === '' && right.indexOf(settingsClone.aNeg) > -1) {
|
1003
|
+
left = settingsClone.aNeg;
|
1004
|
+
right = right.substring(1, right.length);
|
1005
|
+
} /** change sign of number, remove part if should */
|
1006
|
+
if (left.charAt(0) === '-' || left.indexOf(settingsClone.aNeg) !== -1) {
|
1007
|
+
left = left.substring(1, left.length);
|
1008
|
+
} else {
|
1009
|
+
left = (cCode === '-') ? settingsClone.aNeg + left : left;
|
1010
|
+
}
|
1011
|
+
} else {
|
1012
|
+
if (left === '' && right.indexOf(settingsClone.aNeg) > -1) {
|
1013
|
+
left = settingsClone.aNeg;
|
1014
|
+
right = right.substring(1, right.length);
|
1015
|
+
} /** change sign of number, remove part if should */
|
1016
|
+
if (left.charAt(0) === settingsClone.aNeg) {
|
1017
|
+
left = left.substring(1, left.length);
|
1018
|
+
} else {
|
1019
|
+
left = (cCode === '-') ? settingsClone.aNeg + left : left;
|
1020
|
+
}
|
1021
|
+
}
|
1022
|
+
this.setValueParts(left, right, null);
|
1023
|
+
return true;
|
1024
|
+
}
|
1025
|
+
if (cCode >= '0' && cCode <= '9') { /** if try to insert digit before minus */
|
1026
|
+
if (settingsClone.aNeg && left === '' && right.indexOf(settingsClone.aNeg) > -1) {
|
1027
|
+
left = settingsClone.aNeg;
|
1028
|
+
right = right.substring(1, right.length);
|
1029
|
+
}
|
1030
|
+
if (settingsClone.vMax <= 0 && settingsClone.vMin < settingsClone.vMax && this.value.indexOf(settingsClone.aNeg) === -1 && cCode !== '0') {
|
1031
|
+
left = settingsClone.aNeg + left;
|
1032
|
+
}
|
1033
|
+
this.setValueParts(left + cCode, right, null);
|
1034
|
+
return true;
|
1035
|
+
} /** prevent any other character */
|
1036
|
+
settingsClone.throwInput = false;
|
1037
|
+
return true;
|
1038
|
+
},
|
1039
|
+
|
1040
|
+
/**
|
1041
|
+
* formatting of just processed value with keeping of cursor position
|
1042
|
+
*/
|
1043
|
+
formatQuick: function (e) {
|
1044
|
+
var settingsClone = this.settingsClone,
|
1045
|
+
parts = this.getBeforeAfterStriped(),
|
1046
|
+
leftLength = this.value,
|
1047
|
+
kuCode = e.keyCode;
|
1048
|
+
/** no grouping separator and no currency sign */
|
1049
|
+
if ((settingsClone.aSep === '' || (settingsClone.aSep !== '' && leftLength.indexOf(settingsClone.aSep) === -1)) && (settingsClone.aSign === '' || (settingsClone.aSign !== '' && leftLength.indexOf(settingsClone.aSign) === -1))) {
|
1050
|
+
var subParts = [],
|
1051
|
+
nSign = '';
|
1052
|
+
subParts = leftLength.split(settingsClone.aDec);
|
1053
|
+
if (subParts[0].indexOf('-') > -1) {
|
1054
|
+
nSign = '-';
|
1055
|
+
subParts[0] = subParts[0].replace('-', '');
|
1056
|
+
parts[0] = parts[0].replace('-', '');
|
1057
|
+
}
|
1058
|
+
if (nSign === '' && subParts[0].length > settingsClone.mIntPos && parts[0].charAt(0) === '0') { /** strip leading zero on positive value if need */
|
1059
|
+
parts[0] = parts[0].slice(1);
|
1060
|
+
}
|
1061
|
+
if (nSign === '-' && subParts[0].length > settingsClone.mIntNeg && parts[0].charAt(0) === '0') { /** strip leading zero on negative value if need */
|
1062
|
+
parts[0] = parts[0].slice(1);
|
1063
|
+
}
|
1064
|
+
parts[0] = nSign + parts[0];
|
1065
|
+
}
|
1066
|
+
var value = autoGroup(this.value, this.settingsClone);
|
1067
|
+
var position = value.length;
|
1068
|
+
if (value) {
|
1069
|
+
/** prepare regexp which searches for cursor position from unformatted left part */
|
1070
|
+
var left_ar = parts[0].split(''),
|
1071
|
+
i = 0;
|
1072
|
+
/** fixes caret position with trailing minus sign */
|
1073
|
+
if ((settingsClone.pNeg === 's' || (settingsClone.pSign === 's' && settingsClone.pNeg !== 'p')) && left_ar[0] === '-' && settingsClone.aNeg !== '') {
|
1074
|
+
left_ar.shift();
|
1075
|
+
if (settingsClone.pSign === 's' && settingsClone.pNeg === 'l' && (kuCode === keyCode.Backspace || this.kdCode === keyCode.Backspace || kuCode === keyCode.Delete || this.kdCode === keyCode.Delete) && settingsClone.caretFix) {
|
1076
|
+
left_ar.push('-');
|
1077
|
+
settingsClone.caretFix = (e.type === 'keydown') ? true : false;
|
1078
|
+
}
|
1079
|
+
if (settingsClone.pSign === 'p' && settingsClone.pNeg === 's' && (kuCode === keyCode.Backspace || this.kdCode === keyCode.Backspace || kuCode === keyCode.Delete || this.kdCode === keyCode.Delete) && settingsClone.caretFix) {
|
1080
|
+
left_ar.push('-');
|
1081
|
+
settingsClone.caretFix = (e.type === 'keydown') ? true : false;
|
1082
|
+
}
|
1083
|
+
if (settingsClone.pSign === 's' && settingsClone.pNeg === 'r' && (kuCode === keyCode.Backspace || this.kdCode === keyCode.Backspace || kuCode === keyCode.Delete || this.kdCode === keyCode.Delete) && settingsClone.caretFix) {
|
1084
|
+
var signParts = settingsClone.aSign.split(''),
|
1085
|
+
escapeChr = ['\\', '^', '$', '.', '|', '?', '*', '+', '(', ')', '['],
|
1086
|
+
escapedParts = [],
|
1087
|
+
escapedSign = '';
|
1088
|
+
$.each(signParts, function (i, miniParts) {
|
1089
|
+
miniParts = signParts[i];
|
1090
|
+
if ($.inArray(miniParts, escapeChr) !== -1) {
|
1091
|
+
escapedParts.push('\\' + miniParts);
|
1092
|
+
} else {
|
1093
|
+
escapedParts.push(miniParts);
|
1094
|
+
}
|
1095
|
+
});
|
1096
|
+
if (kuCode === keyCode.Backspace || this.kdCode === keyCode.Backspace) {
|
1097
|
+
escapedParts.push('-');
|
1098
|
+
}
|
1099
|
+
escapedSign = escapedParts.join('');
|
1100
|
+
left_ar.push(escapedSign);
|
1101
|
+
settingsClone.caretFix = (e.type === 'keydown') ? true : false;
|
1102
|
+
}
|
1103
|
+
}
|
1104
|
+
for (i; i < left_ar.length; i += 1) { /** thanks Peter Kovari */
|
1105
|
+
if (!left_ar[i].match('\\d')) {
|
1106
|
+
left_ar[i] = '\\' + left_ar[i];
|
1107
|
+
}
|
1108
|
+
}
|
1109
|
+
var leftReg = new RegExp('^.*?' + left_ar.join('.*?')),
|
1110
|
+
newLeft = value.match(leftReg); /** search cursor position in formatted value */
|
1111
|
+
if (newLeft) {
|
1112
|
+
position = newLeft[0].length;
|
1113
|
+
/** if we are just before sign which is in prefix position */
|
1114
|
+
if (((position === 0 && value.charAt(0) !== settingsClone.aNeg) || (position === 1 && value.charAt(0) === settingsClone.aNeg)) && settingsClone.aSign && settingsClone.pSign === 'p') {
|
1115
|
+
/** place caret after prefix sign */
|
1116
|
+
position = this.settingsClone.aSign.length + (value.charAt(0) === '-' ? 1 : 0);
|
1117
|
+
}
|
1118
|
+
} else {
|
1119
|
+
if (settingsClone.aSign && settingsClone.pSign === 's') {
|
1120
|
+
/** if we could not find a place for cursor and have a sign as a suffix */
|
1121
|
+
/** place caret before suffix currency sign */
|
1122
|
+
position -= settingsClone.aSign.length;
|
1123
|
+
}
|
1124
|
+
if (settingsClone.aSuffix) {
|
1125
|
+
/** if we could not find a place for cursor and have a suffix */
|
1126
|
+
/** place caret before suffix */
|
1127
|
+
position -= settingsClone.aSuffix.length;
|
1128
|
+
}
|
1129
|
+
}
|
1130
|
+
}
|
1131
|
+
if (this.that.value !== value) {
|
1132
|
+
this.that.value = value;
|
1133
|
+
this.setPosition(position);
|
1134
|
+
}
|
1135
|
+
this.formatted = true;
|
1136
|
+
}
|
1137
|
+
};
|
1138
|
+
|
1139
|
+
/**
|
1140
|
+
* thanks to Anthony & Evan C
|
1141
|
+
*/
|
1142
|
+
|
1143
|
+
function autoGet(obj) {
|
1144
|
+
if (typeof obj === 'string') {
|
1145
|
+
obj = obj.replace(/\[/g, "\\[").replace(/\]/g, "\\]");
|
1146
|
+
obj = '#' + obj.replace(/(:|\.)/g, '\\$1');
|
1147
|
+
/** obj = '#' + obj.replace(/([;&,\.\+\*\~':"\!\^#$%@\[\]\(\)=>\|])/g, '\\$1'); */
|
1148
|
+
/** possible modification to replace the above 2 lines */
|
1149
|
+
}
|
1150
|
+
return $(obj);
|
1151
|
+
}
|
1152
|
+
|
1153
|
+
/**
|
1154
|
+
* function to attach data to the element
|
1155
|
+
* and imitate the holder
|
1156
|
+
*/
|
1157
|
+
|
1158
|
+
function getHolder($that, settings, update) {
|
1159
|
+
var data = $that.data('autoNumeric');
|
1160
|
+
if (!data) {
|
1161
|
+
data = {};
|
1162
|
+
$that.data('autoNumeric', data);
|
1163
|
+
}
|
1164
|
+
var holder = data.holder;
|
1165
|
+
if ((holder === undefined && settings) || update) {
|
1166
|
+
holder = new AutoNumericHolder($that.get(0), settings);
|
1167
|
+
data.holder = holder;
|
1168
|
+
}
|
1169
|
+
return holder;
|
1170
|
+
}
|
1171
|
+
|
1172
|
+
/**
|
1173
|
+
* original settings saved for use when eDec & nSep options are being used
|
1174
|
+
*/
|
1175
|
+
|
1176
|
+
function originalSettings(settings) {
|
1177
|
+
settings.oDec = settings.mDec;
|
1178
|
+
settings.oPad = settings.aPad;
|
1179
|
+
settings.oBracket = settings.nBracket;
|
1180
|
+
settings.oSep = settings.aSep;
|
1181
|
+
settings.oSign = settings.aSign;
|
1182
|
+
return settings;
|
1183
|
+
}
|
1184
|
+
|
1185
|
+
/**
|
1186
|
+
* original settings saved for use when eDec & nSep options are being used
|
1187
|
+
* taken from Quirksmode
|
1188
|
+
*/
|
1189
|
+
|
1190
|
+
function readCookie(name) {
|
1191
|
+
var nameEQ = name + "=",
|
1192
|
+
ca = document.cookie.split(';'),
|
1193
|
+
i = 0,
|
1194
|
+
c = '';
|
1195
|
+
for (i; i < ca.length; i += 1) {
|
1196
|
+
c = ca[i];
|
1197
|
+
while (c.charAt(0) === ' ') {
|
1198
|
+
c = c.substring(1, c.length);
|
1199
|
+
}
|
1200
|
+
if (c.indexOf(nameEQ) === 0) {
|
1201
|
+
return c.substring(nameEQ.length, c.length);
|
1202
|
+
}
|
1203
|
+
}
|
1204
|
+
return null;
|
1205
|
+
}
|
1206
|
+
|
1207
|
+
/**
|
1208
|
+
* Test if sessionStorage is supported - taken from moderizr
|
1209
|
+
*/
|
1210
|
+
|
1211
|
+
function storageTest() {
|
1212
|
+
var mod = 'modernizr';
|
1213
|
+
try {
|
1214
|
+
sessionStorage.setItem(mod, mod);
|
1215
|
+
sessionStorage.removeItem(mod);
|
1216
|
+
return true;
|
1217
|
+
} catch (e) {
|
1218
|
+
return false;
|
1219
|
+
}
|
1220
|
+
}
|
1221
|
+
|
1222
|
+
/**
|
1223
|
+
* creates or removes sessionStorage or cookie depending on browser support
|
1224
|
+
*/
|
1225
|
+
|
1226
|
+
function autoSave($this, settings, toDo) {
|
1227
|
+
if (settings.aStor) {
|
1228
|
+
var storedName = ($this[0].name !== '' && $this[0].name !== undefined) ? 'AUTO_' + decodeURIComponent($this[0].name) : 'AUTO_' + $this[0].id;
|
1229
|
+
if (storageTest() === false) { /** sets cookie for browser that do not support sessionStorage IE 6 & ie7 */
|
1230
|
+
if (toDo === 'get') {
|
1231
|
+
return readCookie(storedName);
|
1232
|
+
}
|
1233
|
+
if (toDo === 'set') {
|
1234
|
+
document.cookie = storedName + '=' + settings.rawValue + '; expires= ; path=/';
|
1235
|
+
}
|
1236
|
+
if (toDo === 'wipe') {
|
1237
|
+
var date = new Date();
|
1238
|
+
date.setTime(date.getTime() + (-1 * 24 * 60 * 60 * 1000));
|
1239
|
+
var expires = "; expires=" + date.toGMTString();
|
1240
|
+
document.cookie = storedName + '="" ;' + expires + '; path=/';
|
1241
|
+
}
|
1242
|
+
} else {
|
1243
|
+
if (toDo === 'get') {
|
1244
|
+
return sessionStorage.getItem(storedName);
|
1245
|
+
}
|
1246
|
+
if (toDo === 'set') {
|
1247
|
+
sessionStorage.setItem(storedName, settings.rawValue);
|
1248
|
+
}
|
1249
|
+
if (toDo === 'wipe') {
|
1250
|
+
sessionStorage.removeItem(storedName);
|
1251
|
+
}
|
1252
|
+
}
|
1253
|
+
}
|
1254
|
+
return;
|
1255
|
+
}
|
1256
|
+
|
1257
|
+
/**
|
1258
|
+
* Object that give sense to numeric key codes.
|
1259
|
+
*/
|
1260
|
+
var keyCode = {
|
1261
|
+
'Backspace': 8,
|
1262
|
+
'Tab': 9,
|
1263
|
+
'Enter': 13,
|
1264
|
+
'Shift': 16,
|
1265
|
+
'Ctrl': 17,
|
1266
|
+
'Alt': 18,
|
1267
|
+
'PauseBreak': 19,
|
1268
|
+
'CapsLock': 20,
|
1269
|
+
'Esc': 27,
|
1270
|
+
'Space': 32,
|
1271
|
+
'PageUp': 33,
|
1272
|
+
'PageDown': 34,
|
1273
|
+
'End': 35,
|
1274
|
+
'Home': 36,
|
1275
|
+
'LeftArrow': 37,
|
1276
|
+
'UpArrow': 38,
|
1277
|
+
'RightArrow': 39,
|
1278
|
+
'DownArrow': 40,
|
1279
|
+
'Insert': 45,
|
1280
|
+
'Delete': 46,
|
1281
|
+
'num0': 48,
|
1282
|
+
'num1': 49,
|
1283
|
+
'num2': 50,
|
1284
|
+
'num3': 51,
|
1285
|
+
'num4': 52,
|
1286
|
+
'num5': 53,
|
1287
|
+
'num6': 54,
|
1288
|
+
'num7': 55,
|
1289
|
+
'num8': 56,
|
1290
|
+
'num9': 57,
|
1291
|
+
'a': 65,
|
1292
|
+
'b': 66,
|
1293
|
+
'c': 67,
|
1294
|
+
'd': 68,
|
1295
|
+
'e': 69,
|
1296
|
+
'f': 70,
|
1297
|
+
'g': 71,
|
1298
|
+
'h': 72,
|
1299
|
+
'i': 73,
|
1300
|
+
'j': 74,
|
1301
|
+
'k': 75,
|
1302
|
+
'l': 76,
|
1303
|
+
'm': 77,
|
1304
|
+
'n': 78,
|
1305
|
+
'o': 79,
|
1306
|
+
'p': 80,
|
1307
|
+
'q': 81,
|
1308
|
+
'r': 82,
|
1309
|
+
's': 83,
|
1310
|
+
't': 84,
|
1311
|
+
'u': 85,
|
1312
|
+
'v': 86,
|
1313
|
+
'w': 87,
|
1314
|
+
'x': 88,
|
1315
|
+
'y': 89,
|
1316
|
+
'z': 90,
|
1317
|
+
'Windows': 91,
|
1318
|
+
'RightClick': 93,
|
1319
|
+
'numpad0': 96,
|
1320
|
+
'numpad1': 97,
|
1321
|
+
'numpad2': 98,
|
1322
|
+
'numpad3': 99,
|
1323
|
+
'numpad4': 100,
|
1324
|
+
'numpad5': 101,
|
1325
|
+
'numpad6': 102,
|
1326
|
+
'numpad7': 103,
|
1327
|
+
'numpad8': 104,
|
1328
|
+
'numpad9': 105,
|
1329
|
+
'MultiplyNumpad': 106,
|
1330
|
+
'PlusNumpad': 107,
|
1331
|
+
'MinusNumpad': 109,
|
1332
|
+
'DotNumpad': 110,
|
1333
|
+
'SlashNumpad': 111,
|
1334
|
+
'F1': 112,
|
1335
|
+
'F2': 113,
|
1336
|
+
'F3': 114,
|
1337
|
+
'F4': 115,
|
1338
|
+
'F5': 116,
|
1339
|
+
'F6': 117,
|
1340
|
+
'F7': 118,
|
1341
|
+
'F8': 119,
|
1342
|
+
'F9': 120,
|
1343
|
+
'F10': 121,
|
1344
|
+
'F11': 122,
|
1345
|
+
'F12': 123,
|
1346
|
+
'NumLock': 144,
|
1347
|
+
'ScrollLock': 145,
|
1348
|
+
'MyComputer': 182,
|
1349
|
+
'MyCalculator': 183,
|
1350
|
+
'Semicolon': 186,
|
1351
|
+
'Equal': 187,
|
1352
|
+
'Comma': 188,
|
1353
|
+
'Hyphen': 189,
|
1354
|
+
'Dot': 190,
|
1355
|
+
'Slash': 191,
|
1356
|
+
'Backquote': 192,
|
1357
|
+
'LeftBracket': 219,
|
1358
|
+
'Backslash': 220,
|
1359
|
+
'RightBracket': 221,
|
1360
|
+
'Quote': 222,
|
1361
|
+
'Command': 224,
|
1362
|
+
};
|
1363
|
+
|
1364
|
+
/**
|
1365
|
+
* Methods supported by autoNumeric
|
1366
|
+
*/
|
1367
|
+
var methods = {
|
1368
|
+
|
1369
|
+
/**
|
1370
|
+
* Method to initiate autoNumeric and attached the settings (default and options passed as a parameter
|
1371
|
+
* $(someSelector).autoNumeric('init'); // initiate autoNumeric with defaults
|
1372
|
+
* $(someSelector).autoNumeric('init', {option}); // initiate autoNumeric with options
|
1373
|
+
* $(someSelector).autoNumeric(); // initiate autoNumeric with defaults
|
1374
|
+
* $(someSelector).autoNumeric({option}); // initiate autoNumeric with options
|
1375
|
+
* options passes as a parameter example '{aSep: '.', aDec: ',', aSign: '€ '}
|
1376
|
+
*/
|
1377
|
+
init: function (options) {
|
1378
|
+
return this.each(function () {
|
1379
|
+
var $this = $(this),
|
1380
|
+
/** attempt to grab 'autoNumeric' settings, if they don't exist returns "undefined". */
|
1381
|
+
settings = $this.data('autoNumeric'),
|
1382
|
+
/** attempt to grab HTML5 data, if they don't exist we'll get "undefined".*/
|
1383
|
+
tagData = $this.data(),
|
1384
|
+
/** supported input types*/
|
1385
|
+
$input = $this.is('input[type=text], input[type=hidden], input[type=tel], input:not([type])');
|
1386
|
+
$.each(tagData, function (key, value) {
|
1387
|
+
if (typeof value === 'number') {
|
1388
|
+
tagData[key] = value.toString();
|
1389
|
+
}
|
1390
|
+
});
|
1391
|
+
if (typeof settings !== 'object') { /** If we couldn't grab settings, create them from defaults and passed options. */
|
1392
|
+
settings = $.extend({}, $.fn.autoNumeric.defaults, tagData, options, {
|
1393
|
+
aNum: '0123456789',
|
1394
|
+
onOff: false,
|
1395
|
+
runOnce: false,
|
1396
|
+
rawValue: '',
|
1397
|
+
trailingNegative: false,
|
1398
|
+
caretFix: false,
|
1399
|
+
throwInput: true,
|
1400
|
+
tagList: ['b', 'caption', 'cite', 'code', 'dd', 'del', 'div', 'dfn', 'dt', 'em', 'h1', 'h2', 'h3', 'h4', 'h5', 'h6', 'ins', 'kdb', 'label', 'li', 'option', 'output', 'p', 'q', 's', 'sample', 'span', 'strong', 'td', 'th', 'u', 'var']
|
1401
|
+
}); /** Merge defaults, tagData and options */
|
1402
|
+
if (settings.aDec === settings.aSep) {
|
1403
|
+
throwErr('autoNumeric will not function properly when the decimal character aDec: "' + settings.aDec + '" and thousand separator aSep: "' + settings.aSep + '" are the same character', settings.debug);
|
1404
|
+
}
|
1405
|
+
$.each(settings, function (key, value) {
|
1406
|
+
if (value === 'true' || value === 'false') {
|
1407
|
+
settings[key] = (value === 'true') ? true : false;
|
1408
|
+
}
|
1409
|
+
});
|
1410
|
+
$this.data('autoNumeric', settings); /** Save our new settings */
|
1411
|
+
} else {
|
1412
|
+
return this;
|
1413
|
+
}
|
1414
|
+
settings = originalSettings(settings); /** original settings saved for use when eDec & nSep options are being used */
|
1415
|
+
var holder = getHolder($this, settings);
|
1416
|
+
if (!$input && $this.prop('tagName').toLowerCase() === 'input') { /** checks for non-supported input types */
|
1417
|
+
throwErr('The input type "' + $this.prop('type') + '" is not supported by autoNumeric()', settings.debug);
|
1418
|
+
}
|
1419
|
+
if ($.inArray($this.prop('tagName').toLowerCase(), settings.tagList) === -1 && $this.prop('tagName').toLowerCase() !== 'input') { /** checks for non-supported tags */
|
1420
|
+
throwErr('The "<' + $this.prop('tagName').toLowerCase() + '>" is not supported by autoNumeric()', settings.debug);
|
1421
|
+
}
|
1422
|
+
if (settings.aDec === settings.aSep) { /** checks if the decimal and thousand are characters are the same */
|
1423
|
+
throwErr('autoNumeric will not function properly when the decimal character aDec: "' + settings.aDec + '" and thousand separator aSep: "' + settings.aSep + '" are the same character', settings.debug);
|
1424
|
+
}
|
1425
|
+
if (settings.eDec < settings.mDec && settings.eDec !== null) { /** checks the extended decimal places "eDec" is greater than the normal decimal places "mDec" */
|
1426
|
+
throwErr('autoNumeric will not function properly when the extended decimal places "eDec: ' + settings.eDec + '" is greater than mDec: "' + settings.mDec + '" value', settings.debug);
|
1427
|
+
}
|
1428
|
+
/** routine to format default value on page load */
|
1429
|
+
if (settings.runOnce === false && settings.aForm) {
|
1430
|
+
var setValue = true;
|
1431
|
+
if ($input) {
|
1432
|
+
/** checks for page reload from back button
|
1433
|
+
* also checks for ASP.net form post back
|
1434
|
+
* the following HTML data attribute is REQUIRED (data-an-default="same value as the value attribute")
|
1435
|
+
* example: <asp:TextBox runat="server" id="someID" text="1234.56" data-an-default="1234.56">
|
1436
|
+
*/
|
1437
|
+
if ((settings.anDefault !== null && settings.anDefault.toString() !== $this.val()) || (settings.anDefault === null && $this.val() !== '' && $this.val() !== $this.attr('value')) || ($this.val() !== '' && $this.attr('type') === 'hidden' && !$.isNumeric($this.val().replace(',', '.')))) {
|
1438
|
+
if (settings.eDec !== null && settings.aStor) {
|
1439
|
+
settings.rawValue = autoSave($this, settings, 'get');
|
1440
|
+
}
|
1441
|
+
if (!settings.aStor) {
|
1442
|
+
var toStrip = '';
|
1443
|
+
if (settings.nBracket !== null && settings.aNeg !== '') {
|
1444
|
+
settings.onOff = true;
|
1445
|
+
toStrip = negativeBracket($this.val(), settings);
|
1446
|
+
} else {
|
1447
|
+
toStrip = $this.val();
|
1448
|
+
}
|
1449
|
+
settings.rawValue = ((settings.pNeg === 's' || (settings.pSign === 's' && settings.pNeg !== 'p')) && settings.aNeg !== '' && $this.val().indexOf('-') > -1) ? '-' + autoStrip(toStrip, settings) : autoStrip(toStrip, settings);
|
1450
|
+
}
|
1451
|
+
setValue = false;
|
1452
|
+
}
|
1453
|
+
if ($this.val() === '' && settings.wEmpty === 'focus') {
|
1454
|
+
setValue = false;
|
1455
|
+
}
|
1456
|
+
if ($this.val() === '' && settings.wEmpty === 'always') {
|
1457
|
+
$this.val(settings.aSign);
|
1458
|
+
setValue = false;
|
1459
|
+
}
|
1460
|
+
if (setValue && $this.val() !== '' && $this.val() === $this.attr('value')) {
|
1461
|
+
$this.autoNumeric('set', $this.val());
|
1462
|
+
}
|
1463
|
+
}
|
1464
|
+
if ($.inArray($this.prop('tagName').toLowerCase(), settings.tagList) !== -1 && $this.text() !== '') {
|
1465
|
+
if (settings.anDefault !== null) {
|
1466
|
+
if (settings.anDefault === $this.text()) {
|
1467
|
+
$this.autoNumeric('set', $this.text());
|
1468
|
+
}
|
1469
|
+
} else {
|
1470
|
+
$this.autoNumeric('set', $this.text());
|
1471
|
+
}
|
1472
|
+
}
|
1473
|
+
}
|
1474
|
+
settings.runOnce = true;
|
1475
|
+
if ($input) { /**input types supported "text", "hidden", "tel" and no type*/
|
1476
|
+
$this.on('focusin.autoNumeric', function () {
|
1477
|
+
holder = getHolder($this);
|
1478
|
+
var $settings = holder.settingsClone;
|
1479
|
+
$settings.onOff = true;
|
1480
|
+
if ($settings.nBracket !== null && $settings.aNeg !== '') {
|
1481
|
+
$this.val(negativeBracket($this.val(), $settings));
|
1482
|
+
}
|
1483
|
+
if ($settings.nSep === true) {
|
1484
|
+
$settings.aSep = '';
|
1485
|
+
$settings.aSign = '';
|
1486
|
+
}
|
1487
|
+
if ($settings.eDec !== null) {
|
1488
|
+
$settings.mDec = $settings.eDec;
|
1489
|
+
$this.autoNumeric('set', $settings.rawValue);
|
1490
|
+
} else {
|
1491
|
+
$this.autoNumeric('set', $settings.rawValue);
|
1492
|
+
}
|
1493
|
+
holder.inVal = $this.val();
|
1494
|
+
holder.lastVal = $this.val();
|
1495
|
+
var onEmpty = checkEmpty(holder.inVal, $settings, true);
|
1496
|
+
if ((onEmpty !== null && onEmpty !== '') && $settings.wEmpty === 'focus') {
|
1497
|
+
$this.val(onEmpty);
|
1498
|
+
}
|
1499
|
+
});
|
1500
|
+
$this.on('keydown.autoNumeric', function (e) {
|
1501
|
+
holder = getHolder($this);
|
1502
|
+
if (holder.that.readOnly) {
|
1503
|
+
holder.processed = true;
|
1504
|
+
return true;
|
1505
|
+
}
|
1506
|
+
/** The below streamed code / comment allows the "enter" keydown to throw a change() event */
|
1507
|
+
/** if (e.keyCode === keyCode.Enter && holder.inVal !== $this.val()){
|
1508
|
+
$this.change();
|
1509
|
+
holder.inVal = $this.val();
|
1510
|
+
}*/
|
1511
|
+
holder.init(e);
|
1512
|
+
if (holder.skipAllways(e)) {
|
1513
|
+
holder.processed = true;
|
1514
|
+
return true;
|
1515
|
+
}
|
1516
|
+
if (holder.processAllways()) {
|
1517
|
+
holder.processed = true;
|
1518
|
+
holder.formatQuick(e);
|
1519
|
+
if (($this.val() !== holder.lastVal) && holder.settingsClone.throwInput) {
|
1520
|
+
$this.trigger('input'); /** throws input event in deletion character */
|
1521
|
+
}
|
1522
|
+
holder.lastVal = $this.val();
|
1523
|
+
holder.settingsClone.throwInput = true;
|
1524
|
+
e.preventDefault();
|
1525
|
+
return false;
|
1526
|
+
}
|
1527
|
+
holder.formatted = false;
|
1528
|
+
return true;
|
1529
|
+
});
|
1530
|
+
$this.on('keypress.autoNumeric', function (e) {
|
1531
|
+
if (e.shiftKey && e.keyCode === keyCode.Insert) { /** FF fix for Shift && insert paste event */
|
1532
|
+
return;
|
1533
|
+
}
|
1534
|
+
holder = getHolder($this);
|
1535
|
+
var processed = holder.processed;
|
1536
|
+
holder.init(e);
|
1537
|
+
if (holder.skipAllways(e)) {
|
1538
|
+
return true;
|
1539
|
+
}
|
1540
|
+
if (processed) {
|
1541
|
+
e.preventDefault();
|
1542
|
+
return false;
|
1543
|
+
}
|
1544
|
+
if (holder.processAllways() || holder.processKeypress()) {
|
1545
|
+
holder.formatQuick(e);
|
1546
|
+
if (($this.val() !== holder.lastVal) && holder.settingsClone.throwInput) {
|
1547
|
+
$this.trigger('input'); /** throws input event on adding character */
|
1548
|
+
}
|
1549
|
+
holder.lastVal = $this.val();
|
1550
|
+
holder.settingsClone.throwInput = true;
|
1551
|
+
e.preventDefault();
|
1552
|
+
return;
|
1553
|
+
}
|
1554
|
+
holder.formatted = false;
|
1555
|
+
});
|
1556
|
+
$this.on('keyup.autoNumeric', function (e) {
|
1557
|
+
holder = getHolder($this);
|
1558
|
+
holder.init(e);
|
1559
|
+
var skip = holder.skipAllways(e),
|
1560
|
+
tab = holder.kdCode;
|
1561
|
+
holder.kdCode = 0;
|
1562
|
+
delete holder.valuePartsBeforePaste;
|
1563
|
+
if ($this[0].value === holder.settingsClone.aSign) { /** added to properly place the caret when only the currency sign is present */
|
1564
|
+
if (holder.settingsClone.pSign === 's') {
|
1565
|
+
setElementSelection(this, 0, 0);
|
1566
|
+
} else {
|
1567
|
+
setElementSelection(this, holder.settingsClone.aSign.length, holder.settingsClone.aSign.length);
|
1568
|
+
}
|
1569
|
+
} else if (tab === keyCode.Tab) {
|
1570
|
+
setElementSelection(this, 0, $this.val().length);
|
1571
|
+
}
|
1572
|
+
if ($this[0].value === holder.settingsClone.aSuffix) {
|
1573
|
+
setElementSelection(this, 0, 0);
|
1574
|
+
}
|
1575
|
+
if (holder.settingsClone.rawValue === '' && holder.settingsClone.aSign !== '' && holder.settingsClone.aSuffix !== '') {
|
1576
|
+
setElementSelection(this, 0, 0);
|
1577
|
+
}
|
1578
|
+
if (holder.settingsClone.eDec !== null && holder.settingsClone.aStor) { /** saves the extended decimal to preserve the data when navigating away from the page */
|
1579
|
+
autoSave($this, settings, 'set');
|
1580
|
+
}
|
1581
|
+
if (skip) {
|
1582
|
+
return true;
|
1583
|
+
}
|
1584
|
+
if (this.value === '') {
|
1585
|
+
return true;
|
1586
|
+
}
|
1587
|
+
if (!holder.formatted) {
|
1588
|
+
holder.formatQuick(e);
|
1589
|
+
}
|
1590
|
+
});
|
1591
|
+
$this.on('focusout.autoNumeric', function () {
|
1592
|
+
holder = getHolder($this);
|
1593
|
+
var value = $this.val(),
|
1594
|
+
origValue = value,
|
1595
|
+
$settings = holder.settingsClone;
|
1596
|
+
$settings.onOff = false;
|
1597
|
+
if ($settings.aStor) {
|
1598
|
+
autoSave($this, $settings, 'set');
|
1599
|
+
}
|
1600
|
+
if ($settings.nSep === true) {
|
1601
|
+
$settings.aSep = $settings.oSep;
|
1602
|
+
$settings.aSign = $settings.oSign;
|
1603
|
+
}
|
1604
|
+
if ($settings.eDec !== null) {
|
1605
|
+
$settings.mDec = $settings.oDec;
|
1606
|
+
$settings.aPad = $settings.oPad;
|
1607
|
+
$settings.nBracket = $settings.oBracket;
|
1608
|
+
}
|
1609
|
+
if (value !== '') {
|
1610
|
+
value = autoStrip(value, $settings);
|
1611
|
+
if ($settings.trailingNegative) {
|
1612
|
+
value = '-' + value;
|
1613
|
+
$settings.trailingNegative = false;
|
1614
|
+
}
|
1615
|
+
if (checkEmpty(value, $settings) === null && autoCheck(value, $settings, $this[0])) {
|
1616
|
+
value = fixNumber(value, $settings.aDec, $settings.aNeg);
|
1617
|
+
$settings.rawValue = value;
|
1618
|
+
value = autoRound(value, $settings);
|
1619
|
+
value = presentNumber(value, $settings.aDec, $settings.aNeg);
|
1620
|
+
} else {
|
1621
|
+
value = $settings.rawValue;
|
1622
|
+
}
|
1623
|
+
} else {
|
1624
|
+
$settings.rawValue = '';
|
1625
|
+
}
|
1626
|
+
var groupedValue = checkEmpty(value, $settings, false);
|
1627
|
+
if (groupedValue === null) {
|
1628
|
+
groupedValue = autoGroup(value, $settings);
|
1629
|
+
}
|
1630
|
+
if (groupedValue !== origValue) {
|
1631
|
+
$this.val(groupedValue);
|
1632
|
+
}
|
1633
|
+
if (groupedValue !== holder.inVal) {
|
1634
|
+
$this.change();
|
1635
|
+
delete holder.inVal;
|
1636
|
+
}
|
1637
|
+
});
|
1638
|
+
$this.closest('form').on('submit.autoNumeric', function () {
|
1639
|
+
holder = getHolder($this);
|
1640
|
+
if (holder) {
|
1641
|
+
var $settings = holder.settingsClone;
|
1642
|
+
if ($settings.unSetOnSubmit) {
|
1643
|
+
$this.val($settings.rawValue);
|
1644
|
+
}
|
1645
|
+
}
|
1646
|
+
});
|
1647
|
+
}
|
1648
|
+
});
|
1649
|
+
},
|
1650
|
+
|
1651
|
+
/**
|
1652
|
+
* method to remove settings and stop autoNumeric() - does not remove the formatting
|
1653
|
+
* $(someSelector).autoNumeric('destroy'); // destroys autoNumeric
|
1654
|
+
* no parameters accepted
|
1655
|
+
*/
|
1656
|
+
destroy: function () {
|
1657
|
+
return $(this).each(function () {
|
1658
|
+
var $this = autoGet($(this)),
|
1659
|
+
settings = $this.data('autoNumeric');
|
1660
|
+
if (typeof settings === 'object') {
|
1661
|
+
$this.val('');
|
1662
|
+
autoSave($this, settings, 'wipe');
|
1663
|
+
$this.removeData('autoNumeric');
|
1664
|
+
$this.off('.autoNumeric');
|
1665
|
+
}
|
1666
|
+
});
|
1667
|
+
},
|
1668
|
+
|
1669
|
+
/**
|
1670
|
+
* method to clear the value and sessionStorage or cookie depending on browser supports
|
1671
|
+
* $(someSelector).autoNumeric('wipe'); // removes session storage and cookies from memory
|
1672
|
+
* no parameters accepted
|
1673
|
+
*/
|
1674
|
+
wipe: function () {
|
1675
|
+
return $(this).each(function () {
|
1676
|
+
var $this = autoGet($(this)),
|
1677
|
+
settings = $this.data('autoNumeric');
|
1678
|
+
if (typeof settings === 'object') {
|
1679
|
+
$this.val('');
|
1680
|
+
settings.rawValue = '';
|
1681
|
+
autoSave($this, settings, 'wipe');
|
1682
|
+
}
|
1683
|
+
});
|
1684
|
+
},
|
1685
|
+
|
1686
|
+
/**
|
1687
|
+
* method to update settings - can be call as many times
|
1688
|
+
* $(someSelector).autoNumeric('update', {options}); // updates the settings
|
1689
|
+
* options passed as a parameter example '{aSep: '.', aDec: ',', aSign: '€ '}
|
1690
|
+
*/
|
1691
|
+
update: function (options) {
|
1692
|
+
return $(this).each(function () {
|
1693
|
+
var $this = autoGet($(this)),
|
1694
|
+
settings = $this.data('autoNumeric');
|
1695
|
+
if (typeof settings !== 'object') {
|
1696
|
+
throwErr('Initializing autoNumeric is required prior to calling the "update" method', true);
|
1697
|
+
}
|
1698
|
+
var strip = $this.autoNumeric('get');
|
1699
|
+
settings = $.extend(settings, options);
|
1700
|
+
settings = originalSettings(settings);
|
1701
|
+
getHolder($this, settings, true);
|
1702
|
+
if (settings.aDec === settings.aSep) {
|
1703
|
+
throwErr('autoNumeric will not function properly when the decimal character aDec: "' + settings.aDec + '" and thousand separator aSep: "' + settings.aSep + '" are the same character', settings.debug);
|
1704
|
+
}
|
1705
|
+
$this.data('autoNumeric', settings);
|
1706
|
+
if ($this.val() !== '' || $this.text() !== '') {
|
1707
|
+
return $this.autoNumeric('set', strip);
|
1708
|
+
}
|
1709
|
+
return;
|
1710
|
+
});
|
1711
|
+
},
|
1712
|
+
|
1713
|
+
/**
|
1714
|
+
* method to format value sent as a parameter ""
|
1715
|
+
* $(someSelector).autoNumeric('set', 'value'}); // formats the value being passed
|
1716
|
+
* value passed as a string - can be a integer '1234' or double '1234.56789'
|
1717
|
+
* must contain only numbers and one decimal (period) character
|
1718
|
+
*/
|
1719
|
+
set: function (valueIn) {
|
1720
|
+
return $(this).each(function () {
|
1721
|
+
if (valueIn === null || isNaN(valueIn)) {
|
1722
|
+
return;
|
1723
|
+
}
|
1724
|
+
var $this = autoGet($(this)),
|
1725
|
+
settings = $this.data('autoNumeric'),
|
1726
|
+
value = valueIn.toString(),
|
1727
|
+
$input = $this.is('input[type=text], input[type=hidden], input[type=tel], input:not([type])');
|
1728
|
+
if (typeof settings !== 'object') {
|
1729
|
+
throwErr('Initializing autoNumeric is required prior to calling the "set" method', true);
|
1730
|
+
}
|
1731
|
+
/** allows locale decimal separator to be a comma - no thousand separator allowed */
|
1732
|
+
value = convertLocale(value);
|
1733
|
+
/** Throws an error if the value being set is not numeric */
|
1734
|
+
if (!$.isNumeric(Number(value))) {
|
1735
|
+
throwErr('The value "' + value + '" being "set" is not numeric and has caused a error to be thrown', settings.debug);
|
1736
|
+
}
|
1737
|
+
if (value !== '') {
|
1738
|
+
if (autoCheck(value, settings)) {
|
1739
|
+
if ($input && settings.eDec !== null) {
|
1740
|
+
settings.rawValue = value;
|
1741
|
+
}
|
1742
|
+
if ($input || $.inArray($this.prop('tagName').toLowerCase(), settings.tagList) !== -1) { /** checks if the value falls within the min max range */
|
1743
|
+
value = autoRound(value, settings);
|
1744
|
+
if (settings.eDec === null) {
|
1745
|
+
settings.rawValue = value;
|
1746
|
+
}
|
1747
|
+
value = presentNumber(value, settings.aDec, settings.aNeg);
|
1748
|
+
value = autoGroup(value, settings);
|
1749
|
+
}
|
1750
|
+
if (settings.aStor && settings.eDec !== null) {
|
1751
|
+
autoSave($this, settings, 'set');
|
1752
|
+
}
|
1753
|
+
} else {
|
1754
|
+
settings.rawValue = '';
|
1755
|
+
autoSave($this, settings, 'wipe');
|
1756
|
+
value = '';
|
1757
|
+
throwErr('The value being set falls outside the min: "' + settings.vMin + ' max: "' + settings.vMax + '" ) settings for this element', settings.debug);
|
1758
|
+
return '';
|
1759
|
+
}
|
1760
|
+
} else {
|
1761
|
+
return '';
|
1762
|
+
}
|
1763
|
+
if ($input) {
|
1764
|
+
return $this.val(value);
|
1765
|
+
}
|
1766
|
+
if ($.inArray($this.prop('tagName').toLowerCase(), settings.tagList) !== -1) {
|
1767
|
+
return $this.text(value);
|
1768
|
+
}
|
1769
|
+
return false;
|
1770
|
+
});
|
1771
|
+
},
|
1772
|
+
|
1773
|
+
/**
|
1774
|
+
* method to un-format inputs - handy to use right before form submission
|
1775
|
+
* $(someSelector).autoNumeric('unSet'); // parameter optional
|
1776
|
+
* $(someSelector).autoNumeric('unSet', 'komma'); // returns string '1234,56' with a komma as the decimal character
|
1777
|
+
* $(someSelector).autoNumeric('unSet', 'checkOptions'); // returns string '1234.56' or '1234.56' depending of the format setting for the input
|
1778
|
+
*/
|
1779
|
+
unSet: function (outPut) {
|
1780
|
+
return $(this).each(function () {
|
1781
|
+
var $this = autoGet($(this)),
|
1782
|
+
settings = $this.data('autoNumeric');
|
1783
|
+
if (typeof settings === 'object') {
|
1784
|
+
settings.onOff = true;
|
1785
|
+
$this.val($this.autoNumeric('get', outPut));
|
1786
|
+
}
|
1787
|
+
});
|
1788
|
+
},
|
1789
|
+
|
1790
|
+
/**
|
1791
|
+
* method to re-format inputs - handy to use right after form submission
|
1792
|
+
* $(someSelector).autoNumeric('reSet'); // no parameters accepted
|
1793
|
+
* this is called after the 'unSet' method to reformat the input
|
1794
|
+
*/
|
1795
|
+
reSet: function () {
|
1796
|
+
return $(this).each(function () {
|
1797
|
+
var $this = autoGet($(this)),
|
1798
|
+
settings = $this.data('autoNumeric');
|
1799
|
+
if (typeof settings === 'object') {
|
1800
|
+
$this.autoNumeric('set', $this.val());
|
1801
|
+
}
|
1802
|
+
});
|
1803
|
+
},
|
1804
|
+
|
1805
|
+
/**
|
1806
|
+
* method to get the unformatted that accepts up to one parameter
|
1807
|
+
* $(someSelector).autoNumeric('get'); no parameter used - values returned as ISO numeric string "1234.56" where the decimal character is a period
|
1808
|
+
* $(someSelector).autoNumeric('get', 'asKomma'); values returned as strings "nnnn,nn" where the comma / komma is the decimal character
|
1809
|
+
* $(someSelector).autoNumeric('get', 'checkOptions'); values returned as strings - either as "nnnn.nn" or "nnnn,mm" depending of the format setting for the input
|
1810
|
+
* only the first element in the selector is returned
|
1811
|
+
*/
|
1812
|
+
get: function (outPut) {
|
1813
|
+
var $this = autoGet($(this)),
|
1814
|
+
settings = $this.data('autoNumeric'),
|
1815
|
+
$input = $this.is('input[type=text], input[type=hidden], input[type=tel], input:not([type])');
|
1816
|
+
if (typeof settings !== 'object') {
|
1817
|
+
throwErr('Initializing autoNumeric is required prior to calling the "get" method', true);
|
1818
|
+
}
|
1819
|
+
var getValue = '';
|
1820
|
+
/** determine the element type then use .eq(0) selector to grab the value of the first element in selector */
|
1821
|
+
if ($input) {
|
1822
|
+
getValue = $this.eq(0).val();
|
1823
|
+
} else if ($.inArray($this.prop('tagName').toLowerCase(), settings.tagList) !== -1) {
|
1824
|
+
getValue = $this.eq(0).text();
|
1825
|
+
} else {
|
1826
|
+
throwErr('The "<' + $this.prop('tagName').toLowerCase() + '>" is not supported by autoNumeric()', settings.debug);
|
1827
|
+
}
|
1828
|
+
if (settings.rawValue !== '') {
|
1829
|
+
getValue = settings.rawValue;
|
1830
|
+
}
|
1831
|
+
if (!((/\d/).test(getValue) || Number(getValue) === 0) && settings.wEmpty === 'focus') {
|
1832
|
+
return '';
|
1833
|
+
}
|
1834
|
+
if (getValue !== '' && settings.nBracket !== null) {
|
1835
|
+
settings.onOff = true;
|
1836
|
+
getValue = negativeBracket(getValue, settings);
|
1837
|
+
}
|
1838
|
+
getValue = fixNumber(getValue, settings.aDec, settings.aNeg);
|
1839
|
+
if (Number(getValue) === 0 && settings.lZero !== 'keep') {
|
1840
|
+
getValue = '0';
|
1841
|
+
}
|
1842
|
+
if (outPut === ',') {
|
1843
|
+
getValue = getValue.replace('.', ',');
|
1844
|
+
}
|
1845
|
+
if (outPut === '.-' && getValue.indexOf('-') > -1) {
|
1846
|
+
getValue = getValue.replace('-', '') + '-';
|
1847
|
+
}
|
1848
|
+
if (outPut === ',-' && getValue.indexOf('-') > -1) {
|
1849
|
+
getValue = getValue.replace('.', ',').replace('-', '') + '-';
|
1850
|
+
}
|
1851
|
+
return getValue; /** returned Numeric String */
|
1852
|
+
},
|
1853
|
+
|
1854
|
+
/**
|
1855
|
+
* The 'getString' method used jQuerys .serialize() method that creates a text string in standard URL-encoded notation
|
1856
|
+
* it then loops through the string and un-formats the inputs with autoNumeric
|
1857
|
+
* $(someSelector).autoNumeric('getString'); no parameter used - values returned as ISO numeric string "1234.56" where the decimal character is a period
|
1858
|
+
* $(someSelector).autoNumeric('getString', 'asKomma'); values returned as strings "nnnn,nn" where the comma / komma is the decimal character
|
1859
|
+
* $(someSelector).autoNumeric('getString', 'checkOptions'); values returned as strings - either as "nnnn.nn" or "nnnn,mm" depending of the format setting for the input
|
1860
|
+
*/
|
1861
|
+
getString: function (outPut) {
|
1862
|
+
var $this = autoGet($(this)),
|
1863
|
+
formFields = $this.serialize(),
|
1864
|
+
formParts = formFields.split('&'),
|
1865
|
+
formIndex = $('form').index($this),
|
1866
|
+
allFormElements = $('form:eq(' + formIndex + ')'),
|
1867
|
+
aiIndex = [],
|
1868
|
+
/** all input index */
|
1869
|
+
scIndex = [],
|
1870
|
+
/** successful control index */
|
1871
|
+
rsubmitterTypes = /^(?:submit|button|image|reset|file)$/i,
|
1872
|
+
/* from jQuery serialize method */
|
1873
|
+
rsubmittable = /^(?:input|select|textarea|keygen)/i,
|
1874
|
+
/* from jQuery serialize method */
|
1875
|
+
rcheckableType = /^(?:checkbox|radio)$/i,
|
1876
|
+
rnonAutoNumericTypes = /^(?:button|checkbox|color|date|datetime|datetime-local|email|file|image|month|number|password|radio|range|reset|search|submit|time|url|week)/i,
|
1877
|
+
count = 0;
|
1878
|
+
/*jslint unparam: true*/
|
1879
|
+
/** index of successful elements */
|
1880
|
+
$.each(allFormElements[0], function (i, field) {
|
1881
|
+
if (field.name !== '' && rsubmittable.test(field.localName) && !rsubmitterTypes.test(field.type) && !field.disabled && (field.checked || !rcheckableType.test(field.type))) {
|
1882
|
+
scIndex.push(count);
|
1883
|
+
count = count + 1;
|
1884
|
+
} else {
|
1885
|
+
scIndex.push(-1);
|
1886
|
+
}
|
1887
|
+
});
|
1888
|
+
/** index of all inputs tags except checkbox */
|
1889
|
+
count = 0;
|
1890
|
+
$.each(allFormElements[0], function (i, field) {
|
1891
|
+
if (field.localName === 'input' && (field.type === '' || field.type === 'text' || field.type === 'hidden' || field.type === 'tel')) {
|
1892
|
+
aiIndex.push(count);
|
1893
|
+
count = count + 1;
|
1894
|
+
} else {
|
1895
|
+
aiIndex.push(-1);
|
1896
|
+
if (field.localName === 'input' && rnonAutoNumericTypes.test(field.type)) {
|
1897
|
+
count = count + 1;
|
1898
|
+
}
|
1899
|
+
}
|
1900
|
+
});
|
1901
|
+
$.each(formParts, function (i, miniParts) {
|
1902
|
+
miniParts = formParts[i].split('=');
|
1903
|
+
var scElement = $.inArray(i, scIndex);
|
1904
|
+
if (scElement > -1 && aiIndex[scElement] > -1) {
|
1905
|
+
var testInput = $('form:eq(' + formIndex + ') input:eq(' + aiIndex[scElement] + ')'),
|
1906
|
+
settings = testInput.data('autoNumeric');
|
1907
|
+
if (typeof settings === 'object') {
|
1908
|
+
if (miniParts[1] !== null) {
|
1909
|
+
miniParts[1] = $('form:eq(' + formIndex + ') input:eq(' + aiIndex[scElement] + ')').autoNumeric('get', outPut).toString();
|
1910
|
+
formParts[i] = miniParts.join('=');
|
1911
|
+
}
|
1912
|
+
}
|
1913
|
+
}
|
1914
|
+
});
|
1915
|
+
/*jslint unparam: false*/
|
1916
|
+
return formParts.join('&');
|
1917
|
+
},
|
1918
|
+
|
1919
|
+
/**
|
1920
|
+
* The 'getString' method used jQuerys .serializeArray() method that creates array or objects that can be encoded as a JSON string
|
1921
|
+
* it then loops through the string and un-formats the inputs with autoNumeric
|
1922
|
+
* $(someSelector).autoNumeric('getArray'); no parameter used - values returned as ISO numeric string "1234.56" where the decimal character is a period
|
1923
|
+
* $(someSelector).autoNumeric('getArray', 'asKomma'); values returned as strings "nnnn,nn" where the comma / komma is the decimal character
|
1924
|
+
* $(someSelector).autoNumeric('getArray', 'checkOptions'); values returned as strings - either as "nnnn.nn" or "nnnn,mm" depending of the format setting for the input
|
1925
|
+
*/
|
1926
|
+
getArray: function (outPut) {
|
1927
|
+
var $this = autoGet($(this)),
|
1928
|
+
formFields = $this.serializeArray(),
|
1929
|
+
formIndex = $('form').index($this),
|
1930
|
+
allFormElements = $('form:eq(' + formIndex + ')'),
|
1931
|
+
aiIndex = [],
|
1932
|
+
/* all input index */
|
1933
|
+
scIndex = [],
|
1934
|
+
/* successful control index */
|
1935
|
+
rsubmitterTypes = /^(?:submit|button|image|reset|file)$/i,
|
1936
|
+
/* from jQuery serialize method */
|
1937
|
+
rsubmittable = /^(?:input|select|textarea|keygen)/i,
|
1938
|
+
/* from jQuery serialize method */
|
1939
|
+
rcheckableType = /^(?:checkbox|radio)$/i,
|
1940
|
+
rnonAutoNumericTypes = /^(?:button|checkbox|color|date|datetime|datetime-local|email|file|image|month|number|password|radio|range|reset|search|submit|time|url|week)/i,
|
1941
|
+
count = 0;
|
1942
|
+
/*jslint unparam: true*/
|
1943
|
+
/* index of successful elements */
|
1944
|
+
$.each(allFormElements[0], function (i, field) {
|
1945
|
+
if (field.name !== '' && rsubmittable.test(field.localName) && !rsubmitterTypes.test(field.type) && !field.disabled && (field.checked || !rcheckableType.test(field.type))) {
|
1946
|
+
scIndex.push(count);
|
1947
|
+
count = count + 1;
|
1948
|
+
} else {
|
1949
|
+
scIndex.push(-1);
|
1950
|
+
}
|
1951
|
+
});
|
1952
|
+
/* index of all inputs tags */
|
1953
|
+
count = 0;
|
1954
|
+
$.each(allFormElements[0], function (i, field) {
|
1955
|
+
if (field.localName === 'input' && (field.type === '' || field.type === 'text' || field.type === 'hidden' || field.type === 'tel')) {
|
1956
|
+
aiIndex.push(count);
|
1957
|
+
count = count + 1;
|
1958
|
+
} else {
|
1959
|
+
aiIndex.push(-1);
|
1960
|
+
if (field.localName === 'input' && rnonAutoNumericTypes.test(field.type)) {
|
1961
|
+
count = count + 1;
|
1962
|
+
}
|
1963
|
+
}
|
1964
|
+
});
|
1965
|
+
$.each(formFields, function (i, field) {
|
1966
|
+
var scElement = $.inArray(i, scIndex);
|
1967
|
+
if (scElement > -1 && aiIndex[scElement] > -1) {
|
1968
|
+
var testInput = $('form:eq(' + formIndex + ') input:eq(' + aiIndex[scElement] + ')'),
|
1969
|
+
settings = testInput.data('autoNumeric');
|
1970
|
+
if (typeof settings === 'object') {
|
1971
|
+
field.value = $('form:eq(' + formIndex + ') input:eq(' + aiIndex[scElement] + ')').autoNumeric('get', outPut).toString();
|
1972
|
+
}
|
1973
|
+
}
|
1974
|
+
});
|
1975
|
+
/*jslint unparam: false*/
|
1976
|
+
return formFields;
|
1977
|
+
},
|
1978
|
+
|
1979
|
+
/**
|
1980
|
+
* The 'getSteetings returns the object with autoNumeric settings for those who need to look under the hood
|
1981
|
+
* $(someSelector).autoNumeric('getSettings'); // no parameters accepted
|
1982
|
+
* $(someSelector).autoNumeric('getSettings').aDec; // return the aDec setting as a string - ant valid setting can be used
|
1983
|
+
*/
|
1984
|
+
getSettings: function () {
|
1985
|
+
var $this = autoGet($(this));
|
1986
|
+
return $this.eq(0).data('autoNumeric');
|
1987
|
+
}
|
1988
|
+
};
|
1989
|
+
|
1990
|
+
/**
|
1991
|
+
* autoNumeric function
|
1992
|
+
*/
|
1993
|
+
$.fn.autoNumeric = function (method) {
|
1994
|
+
if (methods[method]) {
|
1995
|
+
return methods[method].apply(this, Array.prototype.slice.call(arguments, 1));
|
1996
|
+
}
|
1997
|
+
if (typeof method === 'object' || !method) {
|
1998
|
+
return methods.init.apply(this, arguments);
|
1999
|
+
}
|
2000
|
+
throwErr('Method "' + method + '" is not supported by autoNumeric()', true);
|
2001
|
+
};
|
2002
|
+
|
2003
|
+
/**
|
2004
|
+
* Defaults are public - these can be overridden by the following:
|
2005
|
+
* HTML5 data attributes
|
2006
|
+
* Options passed by the 'init' or 'update' methods
|
2007
|
+
* Use jQuery's $.extend method for global changes - also a great way to pass ASP.NET current culture settings
|
2008
|
+
*/
|
2009
|
+
$.fn.autoNumeric.defaults = {
|
2010
|
+
/** allowed thousand separator characters
|
2011
|
+
* comma = ','
|
2012
|
+
* period "full stop" = '.'
|
2013
|
+
* apostrophe is escaped = '\''
|
2014
|
+
* space = ' '
|
2015
|
+
* none = ''
|
2016
|
+
* NOTE: do not use numeric characters
|
2017
|
+
*/
|
2018
|
+
aSep: ',',
|
2019
|
+
/** when true => when the input has focus only the decimal character is visible
|
2020
|
+
*/
|
2021
|
+
nSep: false,
|
2022
|
+
/** digital grouping for the thousand separator used in Format
|
2023
|
+
* dGroup: '2', results in 99,99,99,999 India's lakhs
|
2024
|
+
* dGroup: '2s', results in 99,999,99,99,999 India's lakhs scaled
|
2025
|
+
* dGroup: '3', results in 999,999,999 default
|
2026
|
+
* dGroup: '4', results in 9999,9999,9999 used in some Asian countries
|
2027
|
+
*/
|
2028
|
+
dGroup: '3',
|
2029
|
+
/** allowed decimal separator characters
|
2030
|
+
* period "full stop" = '.'
|
2031
|
+
* comma = ','
|
2032
|
+
*/
|
2033
|
+
aDec: '.',
|
2034
|
+
/** allow to declare alternative decimal separator which is automatically replaced by aDec
|
2035
|
+
* developed for countries the use a comma ',' as the decimal character
|
2036
|
+
* and have keyboards\numeric pads that have a period 'full stop' as the decimal characters (Spain is an example)
|
2037
|
+
*/
|
2038
|
+
altDec: null,
|
2039
|
+
/** aSign = allowed currency symbol
|
2040
|
+
* Must be in quotes aSign: '$'
|
2041
|
+
* space to the right of the currency symbol aSign: '$ '
|
2042
|
+
* space to the left of the currency symbol aSign: ' $'
|
2043
|
+
*/
|
2044
|
+
aSign: '',
|
2045
|
+
/** pSign = placement of currency sign as a p=prefix or s=suffix
|
2046
|
+
* for prefix pSign: 'p' (default)
|
2047
|
+
* for suffix pSign: 's'
|
2048
|
+
*/
|
2049
|
+
pSign: 'p',
|
2050
|
+
/** placement of negative sign relative to the aSign option l=left, r=right, p=prefix & s=suffix
|
2051
|
+
* -1,234.56 => defaults no options required
|
2052
|
+
* 1,234.56- => {pNeg: 's'}
|
2053
|
+
* -$1,234.56 => {aSign: '$'}
|
2054
|
+
* $-1,234.56 => {aSign: '$', pNeg: 'r'}
|
2055
|
+
* $1,234.56- => {aSign: '$', pNeg: 's'}
|
2056
|
+
* 1,234.56-$ => {aSign: '$', pSign: 's'}
|
2057
|
+
* 1,234.56$- => {aSign: '$', pSign: 's', pNeg: 'r'}
|
2058
|
+
* -1,234.56$ => {aSign: '$', pSign: 's', pNeg: 'p'}
|
2059
|
+
*/
|
2060
|
+
pNeg: 'l',
|
2061
|
+
/** Additional suffix
|
2062
|
+
* Must be in quotes aSuffix: 'gross', a space is allowed aSuffix: ' dollars'
|
2063
|
+
* Numeric characters and negative sign not allowed'
|
2064
|
+
*/
|
2065
|
+
aSuffix: '',
|
2066
|
+
/** maximum possible value
|
2067
|
+
* value must be enclosed in quotes and use the period for the decimal point
|
2068
|
+
* value must be larger than vMin
|
2069
|
+
*/
|
2070
|
+
vMax: '9999999999999.99',
|
2071
|
+
/** minimum possible value
|
2072
|
+
* value must be enclosed in quotes and use the period for the decimal point
|
2073
|
+
* value must be smaller than vMax
|
2074
|
+
*/
|
2075
|
+
vMin: '-9999999999999.99',
|
2076
|
+
/** Maximum number of decimal places = used to override decimal places set by the vMin & vMax values
|
2077
|
+
* value must be enclosed in quotes example mDec: '3',
|
2078
|
+
*/
|
2079
|
+
mDec: null,
|
2080
|
+
/** Expanded decimal places visible when input has focus
|
2081
|
+
* value must be enclosed in quotes example mDec: '3',
|
2082
|
+
*/
|
2083
|
+
eDec: null,
|
2084
|
+
/** Set to true to allow the eDec value to be saved with sessionStorage
|
2085
|
+
* if ie 6 or 7 the value will be saved as a session cookie
|
2086
|
+
*/
|
2087
|
+
aStor: false,
|
2088
|
+
/** method used for rounding
|
2089
|
+
* mRound: 'S', Round-Half-Up Symmetric (default)
|
2090
|
+
* mRound: 'A', Round-Half-Up Asymmetric
|
2091
|
+
* mRound: 's', Round-Half-Down Symmetric (lower case s)
|
2092
|
+
* mRound: 'a', Round-Half-Down Asymmetric (lower case a)
|
2093
|
+
* mRound: 'B', Round-Half-Even "Bankers Rounding"
|
2094
|
+
* mRound: 'U', Round Up "Round-Away-From-Zero"
|
2095
|
+
* mRound: 'D', Round Down "Round-Toward-Zero" - same as truncate
|
2096
|
+
* mRound: 'C', Round to Ceiling "Toward Positive Infinity"
|
2097
|
+
* mRound: 'F', Round to Floor "Toward Negative Infinity"
|
2098
|
+
* mRound: 'N05' Rounds to the nearest .05
|
2099
|
+
* mRound: 'U05' Rounds up to next .05
|
2100
|
+
* mRound: 'D05' Rounds down to next .05
|
2101
|
+
*/
|
2102
|
+
mRound: 'S',
|
2103
|
+
/** controls decimal padding
|
2104
|
+
* aPad: true - always Pad decimals with zeros
|
2105
|
+
* aPad: false - does not pad with zeros.
|
2106
|
+
* aPad: `some number` - pad decimals with zero to number different from mDec
|
2107
|
+
* thanks to Jonas Johansson for the suggestion
|
2108
|
+
*/
|
2109
|
+
aPad: true,
|
2110
|
+
/** places brackets on negative value -$ 999.99 to (999.99)
|
2111
|
+
* visible only when the field does NOT have focus the left and right symbols should be enclosed in quotes and separated by a comma
|
2112
|
+
* nBracket: null - (default)
|
2113
|
+
* nBracket: '(,)', nBracket: '[,]', nBracket: '<,>' or nBracket: '{,}'
|
2114
|
+
*/
|
2115
|
+
nBracket: null,
|
2116
|
+
/** Displayed on empty string ""
|
2117
|
+
* wEmpty: 'focus' - (default) currency sign displayed and the input receives focus
|
2118
|
+
* wEmpty: 'press' - currency sign displays on any key being pressed
|
2119
|
+
* wEmpty: 'always' - always displays the currency sign
|
2120
|
+
*/
|
2121
|
+
wEmpty: 'focus',
|
2122
|
+
/** controls leading zero behavior
|
2123
|
+
* lZero: 'allow', - allows leading zeros to be entered. Zeros will be truncated when entering additional digits. On focusout zeros will be deleted.
|
2124
|
+
* lZero: 'deny', - allows only one leading zero on values less than one
|
2125
|
+
* lZero: 'keep', - allows leading zeros to be entered. on focusout zeros will be retained.
|
2126
|
+
*/
|
2127
|
+
lZero: 'allow',
|
2128
|
+
/** determine if the default value will be formatted on page ready.
|
2129
|
+
* true = automatically formats the default value on page ready
|
2130
|
+
* false = will not format the default value
|
2131
|
+
*/
|
2132
|
+
aForm: true,
|
2133
|
+
/** determine if the select all keyboard command will select
|
2134
|
+
* the complete input text or only the input numeric value
|
2135
|
+
* if the currency symbol is between the numeric value and the negative sign only the numeric value will selected
|
2136
|
+
*/
|
2137
|
+
sNumber: false,
|
2138
|
+
/** helper option for ASP.NET postback
|
2139
|
+
* should be the value of the unformatted default value
|
2140
|
+
* examples:
|
2141
|
+
* no default value='' {anDefault: ''}
|
2142
|
+
* value=1234.56 {anDefault: '1234.56'}
|
2143
|
+
*/
|
2144
|
+
anDefault: null,
|
2145
|
+
/** removes formatting on submit event
|
2146
|
+
* this output format: positive nnnn.nn, negative -nnnn.nn
|
2147
|
+
* review the 'unSet' method for other formats
|
2148
|
+
*/
|
2149
|
+
unSetOnSubmit: false,
|
2150
|
+
/** error handling function
|
2151
|
+
* true => all errors are thrown - helpful in site development
|
2152
|
+
* false => throws errors when calling methods prior to the supported element has been initialized be autoNumeric
|
2153
|
+
*/
|
2154
|
+
debug: true
|
2155
|
+
};
|
2156
|
+
}));
|