cleavejs 0.1.0
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/.gitignore +11 -0
- data/.rspec +3 -0
- data/.travis.yml +5 -0
- data/CODE_OF_CONDUCT.md +74 -0
- data/Gemfile +6 -0
- data/LICENSE.txt +21 -0
- data/README.md +52 -0
- data/Rakefile +6 -0
- data/bin/console +14 -0
- data/bin/setup +8 -0
- data/cleavejs.gemspec +38 -0
- data/lib/cleavejs.rb +6 -0
- data/lib/cleavejs/version.rb +3 -0
- data/vendor/assets/javascripts/cleave.js +1434 -0
- metadata +101 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: 0beb7226fb24f2bc264cb6c6d911309976e48eb7ad9b67b74183e5613911cbf3
|
4
|
+
data.tar.gz: 82cd91ae0f1c3b7b647cc9de6dd5c1aaa558d23b860c8f34b2fa9944b47a4c0f
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 6a1d331f3a93f5194ad8a26e0f3dd049375e3854156de34dfe1e3898023e0f3fd840c62a414f5889b6b90de4b5ad6f865727a866ec0f8dbad883ddd604a08b68
|
7
|
+
data.tar.gz: ffa89e2f8771e27899449f4380f1dcfccedacfeabbdf251dee7213b6337bb3cb0019892bc3f78f9d3baff78b0d4ddde16a513ec034f6a276b35d75c1fe0b4ee8
|
data/.gitignore
ADDED
data/.rspec
ADDED
data/.travis.yml
ADDED
data/CODE_OF_CONDUCT.md
ADDED
@@ -0,0 +1,74 @@
|
|
1
|
+
# Contributor Covenant Code of Conduct
|
2
|
+
|
3
|
+
## Our Pledge
|
4
|
+
|
5
|
+
In the interest of fostering an open and welcoming environment, we as
|
6
|
+
contributors and maintainers pledge to making participation in our project and
|
7
|
+
our community a harassment-free experience for everyone, regardless of age, body
|
8
|
+
size, disability, ethnicity, gender identity and expression, level of experience,
|
9
|
+
nationality, personal appearance, race, religion, or sexual identity and
|
10
|
+
orientation.
|
11
|
+
|
12
|
+
## Our Standards
|
13
|
+
|
14
|
+
Examples of behavior that contributes to creating a positive environment
|
15
|
+
include:
|
16
|
+
|
17
|
+
* Using welcoming and inclusive language
|
18
|
+
* Being respectful of differing viewpoints and experiences
|
19
|
+
* Gracefully accepting constructive criticism
|
20
|
+
* Focusing on what is best for the community
|
21
|
+
* Showing empathy towards other community members
|
22
|
+
|
23
|
+
Examples of unacceptable behavior by participants include:
|
24
|
+
|
25
|
+
* The use of sexualized language or imagery and unwelcome sexual attention or
|
26
|
+
advances
|
27
|
+
* Trolling, insulting/derogatory comments, and personal or political attacks
|
28
|
+
* Public or private harassment
|
29
|
+
* Publishing others' private information, such as a physical or electronic
|
30
|
+
address, without explicit permission
|
31
|
+
* Other conduct which could reasonably be considered inappropriate in a
|
32
|
+
professional setting
|
33
|
+
|
34
|
+
## Our Responsibilities
|
35
|
+
|
36
|
+
Project maintainers are responsible for clarifying the standards of acceptable
|
37
|
+
behavior and are expected to take appropriate and fair corrective action in
|
38
|
+
response to any instances of unacceptable behavior.
|
39
|
+
|
40
|
+
Project maintainers have the right and responsibility to remove, edit, or
|
41
|
+
reject comments, commits, code, wiki edits, issues, and other contributions
|
42
|
+
that are not aligned to this Code of Conduct, or to ban temporarily or
|
43
|
+
permanently any contributor for other behaviors that they deem inappropriate,
|
44
|
+
threatening, offensive, or harmful.
|
45
|
+
|
46
|
+
## Scope
|
47
|
+
|
48
|
+
This Code of Conduct applies both within project spaces and in public spaces
|
49
|
+
when an individual is representing the project or its community. Examples of
|
50
|
+
representing a project or community include using an official project e-mail
|
51
|
+
address, posting via an official social media account, or acting as an appointed
|
52
|
+
representative at an online or offline event. Representation of a project may be
|
53
|
+
further defined and clarified by project maintainers.
|
54
|
+
|
55
|
+
## Enforcement
|
56
|
+
|
57
|
+
Instances of abusive, harassing, or otherwise unacceptable behavior may be
|
58
|
+
reported by contacting the project team at venturacontreras@icloud.com. All
|
59
|
+
complaints will be reviewed and investigated and will result in a response that
|
60
|
+
is deemed necessary and appropriate to the circumstances. The project team is
|
61
|
+
obligated to maintain confidentiality with regard to the reporter of an incident.
|
62
|
+
Further details of specific enforcement policies may be posted separately.
|
63
|
+
|
64
|
+
Project maintainers who do not follow or enforce the Code of Conduct in good
|
65
|
+
faith may face temporary or permanent repercussions as determined by other
|
66
|
+
members of the project's leadership.
|
67
|
+
|
68
|
+
## Attribution
|
69
|
+
|
70
|
+
This Code of Conduct is adapted from the [Contributor Covenant][homepage], version 1.4,
|
71
|
+
available at [http://contributor-covenant.org/version/1/4][version]
|
72
|
+
|
73
|
+
[homepage]: http://contributor-covenant.org
|
74
|
+
[version]: http://contributor-covenant.org/version/1/4/
|
data/Gemfile
ADDED
data/LICENSE.txt
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
The MIT License (MIT)
|
2
|
+
|
3
|
+
Copyright (c) 2018 Alejandro Ventura Contreras
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
7
|
+
in the Software without restriction, including without limitation the rights
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
10
|
+
furnished to do so, subject to the following conditions:
|
11
|
+
|
12
|
+
The above copyright notice and this permission notice shall be included in
|
13
|
+
all copies or substantial portions of the Software.
|
14
|
+
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
21
|
+
THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,52 @@
|
|
1
|
+
# Cleavejs
|
2
|
+
|
3
|
+
To have a simpler way to include the great features from [Cleave.js](https://nosir.github.io/cleave.js/) to your Rails app and have `input` texts masked with different formats.
|
4
|
+
|
5
|
+
## Installation
|
6
|
+
|
7
|
+
**1. Add this line to your application's Gemfile:**
|
8
|
+
|
9
|
+
```ruby
|
10
|
+
gem 'cleavejs'
|
11
|
+
```
|
12
|
+
|
13
|
+
**2. And then execute:**
|
14
|
+
|
15
|
+
$ bundle
|
16
|
+
|
17
|
+
**Or install it yourself as:**
|
18
|
+
|
19
|
+
$ gem install cleavejs
|
20
|
+
|
21
|
+
**3. Add the following to your `app/assets/javascripts/application.js`:**
|
22
|
+
```javascript
|
23
|
+
//= require cleave
|
24
|
+
```
|
25
|
+
|
26
|
+
## Usage
|
27
|
+
|
28
|
+
TODO: Write usage instructions here
|
29
|
+
|
30
|
+
## Plugin Documentation
|
31
|
+
|
32
|
+
- https://nosir.github.io/cleave.js/
|
33
|
+
- https://github.com/nosir/cleave.js
|
34
|
+
- https://github.com/nosir/cleave.js/blob/master/doc/js-api.md
|
35
|
+
|
36
|
+
## Development
|
37
|
+
|
38
|
+
After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake spec` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
|
39
|
+
|
40
|
+
To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and tags, and push the `.gem` file to [rubygems.org](https://rubygems.org).
|
41
|
+
|
42
|
+
## Contributing
|
43
|
+
|
44
|
+
Bug reports and pull requests are welcome on GitHub at https://github.com/[USERNAME]/cleavejs. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the [Contributor Covenant](http://contributor-covenant.org) code of conduct.
|
45
|
+
|
46
|
+
## License
|
47
|
+
|
48
|
+
The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
|
49
|
+
|
50
|
+
## Code of Conduct
|
51
|
+
|
52
|
+
Everyone interacting in the Cleavejs project’s codebases, issue trackers, chat rooms and mailing lists is expected to follow the [code of conduct](https://github.com/[USERNAME]/cleavejs/blob/master/CODE_OF_CONDUCT.md).
|
data/Rakefile
ADDED
data/bin/console
ADDED
@@ -0,0 +1,14 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
|
3
|
+
require "bundler/setup"
|
4
|
+
require "cleavejs"
|
5
|
+
|
6
|
+
# You can add fixtures and/or initialization code here to make experimenting
|
7
|
+
# with your gem easier. You can also use a different console, if you like.
|
8
|
+
|
9
|
+
# (If you use this, don't forget to add pry to your Gemfile!)
|
10
|
+
# require "pry"
|
11
|
+
# Pry.start
|
12
|
+
|
13
|
+
require "irb"
|
14
|
+
IRB.start(__FILE__)
|
data/bin/setup
ADDED
data/cleavejs.gemspec
ADDED
@@ -0,0 +1,38 @@
|
|
1
|
+
|
2
|
+
lib = File.expand_path("../lib", __FILE__)
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
+
require "cleavejs/version"
|
5
|
+
|
6
|
+
Gem::Specification.new do |spec|
|
7
|
+
spec.name = "cleavejs"
|
8
|
+
spec.version = Cleavejs::VERSION
|
9
|
+
spec.authors = ["Alejandro Ventura Contreras"]
|
10
|
+
spec.email = ["venturacontreras@icloud.com"]
|
11
|
+
|
12
|
+
spec.summary = %q{Integrate Cleave.js plugin into the Rails asset pipeline}
|
13
|
+
spec.description = %q{This gem makes it easier to use the benefits from the Cleave.js library to mask/format input text elements in Rails.}
|
14
|
+
spec.homepage = "https://github.com/AlexVentura/cleavejs-rails"
|
15
|
+
spec.license = "MIT"
|
16
|
+
|
17
|
+
# Prevent pushing this gem to RubyGems.org. To allow pushes either set the 'allowed_push_host'
|
18
|
+
# to allow pushing to a single host or delete this section to allow pushing to any host.
|
19
|
+
# if spec.respond_to?(:metadata)
|
20
|
+
# spec.metadata["allowed_push_host"] = "TODO: Set to 'http://mygemserver.com'"
|
21
|
+
# else
|
22
|
+
# raise "RubyGems 2.0 or newer is required to protect against " \
|
23
|
+
# "public gem pushes."
|
24
|
+
# end
|
25
|
+
|
26
|
+
# Specify which files should be added to the gem when it is released.
|
27
|
+
# The `git ls-files -z` loads the files in the RubyGem that have been added into git.
|
28
|
+
spec.files = Dir.chdir(File.expand_path('..', __FILE__)) do
|
29
|
+
`git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
|
30
|
+
end
|
31
|
+
spec.bindir = "exe"
|
32
|
+
spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
|
33
|
+
spec.require_paths = ["lib"]
|
34
|
+
|
35
|
+
spec.add_development_dependency "bundler", "~> 1.16"
|
36
|
+
spec.add_development_dependency "rake", "~> 10.0"
|
37
|
+
spec.add_development_dependency "rspec", "~> 3.0"
|
38
|
+
end
|
data/lib/cleavejs.rb
ADDED
@@ -0,0 +1,1434 @@
|
|
1
|
+
(function webpackUniversalModuleDefinition(root, factory) {
|
2
|
+
if(typeof exports === 'object' && typeof module === 'object')
|
3
|
+
module.exports = factory();
|
4
|
+
else if(typeof define === 'function' && define.amd)
|
5
|
+
define([], factory);
|
6
|
+
else if(typeof exports === 'object')
|
7
|
+
exports["Cleave"] = factory();
|
8
|
+
else
|
9
|
+
root["Cleave"] = factory();
|
10
|
+
})(this, function() {
|
11
|
+
return /******/ (function(modules) { // webpackBootstrap
|
12
|
+
/******/ // The module cache
|
13
|
+
/******/ var installedModules = {};
|
14
|
+
|
15
|
+
/******/ // The require function
|
16
|
+
/******/ function __webpack_require__(moduleId) {
|
17
|
+
|
18
|
+
/******/ // Check if module is in cache
|
19
|
+
/******/ if(installedModules[moduleId])
|
20
|
+
/******/ return installedModules[moduleId].exports;
|
21
|
+
|
22
|
+
/******/ // Create a new module (and put it into the cache)
|
23
|
+
/******/ var module = installedModules[moduleId] = {
|
24
|
+
/******/ exports: {},
|
25
|
+
/******/ id: moduleId,
|
26
|
+
/******/ loaded: false
|
27
|
+
/******/ };
|
28
|
+
|
29
|
+
/******/ // Execute the module function
|
30
|
+
/******/ modules[moduleId].call(module.exports, module, module.exports, __webpack_require__);
|
31
|
+
|
32
|
+
/******/ // Flag the module as loaded
|
33
|
+
/******/ module.loaded = true;
|
34
|
+
|
35
|
+
/******/ // Return the exports of the module
|
36
|
+
/******/ return module.exports;
|
37
|
+
/******/ }
|
38
|
+
|
39
|
+
|
40
|
+
/******/ // expose the modules object (__webpack_modules__)
|
41
|
+
/******/ __webpack_require__.m = modules;
|
42
|
+
|
43
|
+
/******/ // expose the module cache
|
44
|
+
/******/ __webpack_require__.c = installedModules;
|
45
|
+
|
46
|
+
/******/ // __webpack_public_path__
|
47
|
+
/******/ __webpack_require__.p = "";
|
48
|
+
|
49
|
+
/******/ // Load entry module and return exports
|
50
|
+
/******/ return __webpack_require__(0);
|
51
|
+
/******/ })
|
52
|
+
/************************************************************************/
|
53
|
+
/******/ ([
|
54
|
+
/* 0 */
|
55
|
+
/***/ (function(module, exports, __webpack_require__) {
|
56
|
+
|
57
|
+
/* WEBPACK VAR INJECTION */(function(global) {'use strict';
|
58
|
+
|
59
|
+
/**
|
60
|
+
* Construct a new Cleave instance by passing the configuration object
|
61
|
+
*
|
62
|
+
* @param {String | HTMLElement} element
|
63
|
+
* @param {Object} opts
|
64
|
+
*/
|
65
|
+
var Cleave = function (element, opts) {
|
66
|
+
var owner = this;
|
67
|
+
|
68
|
+
if (typeof element === 'string') {
|
69
|
+
owner.element = document.querySelector(element);
|
70
|
+
} else {
|
71
|
+
owner.element = ((typeof element.length !== 'undefined') && element.length > 0) ? element[0] : element;
|
72
|
+
}
|
73
|
+
|
74
|
+
if (!owner.element) {
|
75
|
+
throw new Error('[cleave.js] Please check the element');
|
76
|
+
}
|
77
|
+
|
78
|
+
opts.initValue = owner.element.value;
|
79
|
+
|
80
|
+
owner.properties = Cleave.DefaultProperties.assign({}, opts);
|
81
|
+
|
82
|
+
owner.init();
|
83
|
+
};
|
84
|
+
|
85
|
+
Cleave.prototype = {
|
86
|
+
init: function () {
|
87
|
+
var owner = this, pps = owner.properties;
|
88
|
+
|
89
|
+
// no need to use this lib
|
90
|
+
if (!pps.numeral && !pps.phone && !pps.creditCard && !pps.time && !pps.date && (pps.blocksLength === 0 && !pps.prefix)) {
|
91
|
+
owner.onInput(pps.initValue);
|
92
|
+
|
93
|
+
return;
|
94
|
+
}
|
95
|
+
|
96
|
+
pps.maxLength = Cleave.Util.getMaxLength(pps.blocks);
|
97
|
+
|
98
|
+
owner.isAndroid = Cleave.Util.isAndroid();
|
99
|
+
owner.lastInputValue = '';
|
100
|
+
|
101
|
+
owner.onChangeListener = owner.onChange.bind(owner);
|
102
|
+
owner.onKeyDownListener = owner.onKeyDown.bind(owner);
|
103
|
+
owner.onFocusListener = owner.onFocus.bind(owner);
|
104
|
+
owner.onCutListener = owner.onCut.bind(owner);
|
105
|
+
owner.onCopyListener = owner.onCopy.bind(owner);
|
106
|
+
|
107
|
+
owner.element.addEventListener('input', owner.onChangeListener);
|
108
|
+
owner.element.addEventListener('keydown', owner.onKeyDownListener);
|
109
|
+
owner.element.addEventListener('focus', owner.onFocusListener);
|
110
|
+
owner.element.addEventListener('cut', owner.onCutListener);
|
111
|
+
owner.element.addEventListener('copy', owner.onCopyListener);
|
112
|
+
|
113
|
+
|
114
|
+
owner.initPhoneFormatter();
|
115
|
+
owner.initDateFormatter();
|
116
|
+
owner.initTimeFormatter();
|
117
|
+
owner.initNumeralFormatter();
|
118
|
+
|
119
|
+
// avoid touch input field if value is null
|
120
|
+
// otherwise Firefox will add red box-shadow for <input required />
|
121
|
+
if (pps.initValue || (pps.prefix && !pps.noImmediatePrefix)) {
|
122
|
+
owner.onInput(pps.initValue);
|
123
|
+
}
|
124
|
+
},
|
125
|
+
|
126
|
+
initNumeralFormatter: function () {
|
127
|
+
var owner = this, pps = owner.properties;
|
128
|
+
|
129
|
+
if (!pps.numeral) {
|
130
|
+
return;
|
131
|
+
}
|
132
|
+
|
133
|
+
pps.numeralFormatter = new Cleave.NumeralFormatter(
|
134
|
+
pps.numeralDecimalMark,
|
135
|
+
pps.numeralIntegerScale,
|
136
|
+
pps.numeralDecimalScale,
|
137
|
+
pps.numeralThousandsGroupStyle,
|
138
|
+
pps.numeralPositiveOnly,
|
139
|
+
pps.stripLeadingZeroes,
|
140
|
+
pps.delimiter
|
141
|
+
);
|
142
|
+
},
|
143
|
+
|
144
|
+
initTimeFormatter: function() {
|
145
|
+
var owner = this, pps = owner.properties;
|
146
|
+
|
147
|
+
if (!pps.time) {
|
148
|
+
return;
|
149
|
+
}
|
150
|
+
|
151
|
+
pps.timeFormatter = new Cleave.TimeFormatter(pps.timePattern);
|
152
|
+
pps.blocks = pps.timeFormatter.getBlocks();
|
153
|
+
pps.blocksLength = pps.blocks.length;
|
154
|
+
pps.maxLength = Cleave.Util.getMaxLength(pps.blocks);
|
155
|
+
},
|
156
|
+
|
157
|
+
initDateFormatter: function () {
|
158
|
+
var owner = this, pps = owner.properties;
|
159
|
+
|
160
|
+
if (!pps.date) {
|
161
|
+
return;
|
162
|
+
}
|
163
|
+
|
164
|
+
pps.dateFormatter = new Cleave.DateFormatter(pps.datePattern);
|
165
|
+
pps.blocks = pps.dateFormatter.getBlocks();
|
166
|
+
pps.blocksLength = pps.blocks.length;
|
167
|
+
pps.maxLength = Cleave.Util.getMaxLength(pps.blocks);
|
168
|
+
},
|
169
|
+
|
170
|
+
initPhoneFormatter: function () {
|
171
|
+
var owner = this, pps = owner.properties;
|
172
|
+
|
173
|
+
if (!pps.phone) {
|
174
|
+
return;
|
175
|
+
}
|
176
|
+
|
177
|
+
// Cleave.AsYouTypeFormatter should be provided by
|
178
|
+
// external google closure lib
|
179
|
+
try {
|
180
|
+
pps.phoneFormatter = new Cleave.PhoneFormatter(
|
181
|
+
new pps.root.Cleave.AsYouTypeFormatter(pps.phoneRegionCode),
|
182
|
+
pps.delimiter
|
183
|
+
);
|
184
|
+
} catch (ex) {
|
185
|
+
throw new Error('[cleave.js] Please include phone-type-formatter.{country}.js lib');
|
186
|
+
}
|
187
|
+
},
|
188
|
+
|
189
|
+
onKeyDown: function (event) {
|
190
|
+
var owner = this, pps = owner.properties,
|
191
|
+
charCode = event.which || event.keyCode,
|
192
|
+
Util = Cleave.Util,
|
193
|
+
currentValue = owner.element.value;
|
194
|
+
|
195
|
+
if (charCode === 229
|
196
|
+
&& Util.isAndroidBackspaceKeydown(owner.lastInputValue, currentValue)
|
197
|
+
) {
|
198
|
+
charCode = 8;
|
199
|
+
}
|
200
|
+
|
201
|
+
owner.lastInputValue = currentValue;
|
202
|
+
|
203
|
+
// hit backspace when last character is delimiter
|
204
|
+
if (charCode === 8 && Util.isDelimiter(currentValue.slice(-pps.delimiterLength), pps.delimiter, pps.delimiters)) {
|
205
|
+
pps.backspace = true;
|
206
|
+
|
207
|
+
return;
|
208
|
+
}
|
209
|
+
|
210
|
+
pps.backspace = false;
|
211
|
+
},
|
212
|
+
|
213
|
+
onChange: function () {
|
214
|
+
this.onInput(this.element.value);
|
215
|
+
},
|
216
|
+
|
217
|
+
onFocus: function () {
|
218
|
+
var owner = this,
|
219
|
+
pps = owner.properties;
|
220
|
+
|
221
|
+
Cleave.Util.fixPrefixCursor(owner.element, pps.prefix, pps.delimiter, pps.delimiters);
|
222
|
+
},
|
223
|
+
|
224
|
+
onCut: function (e) {
|
225
|
+
this.copyClipboardData(e);
|
226
|
+
this.onInput('');
|
227
|
+
},
|
228
|
+
|
229
|
+
onCopy: function (e) {
|
230
|
+
this.copyClipboardData(e);
|
231
|
+
},
|
232
|
+
|
233
|
+
copyClipboardData: function (e) {
|
234
|
+
var owner = this,
|
235
|
+
pps = owner.properties,
|
236
|
+
Util = Cleave.Util,
|
237
|
+
inputValue = owner.element.value,
|
238
|
+
textToCopy = '';
|
239
|
+
|
240
|
+
if (!pps.copyDelimiter) {
|
241
|
+
textToCopy = Util.stripDelimiters(inputValue, pps.delimiter, pps.delimiters);
|
242
|
+
} else {
|
243
|
+
textToCopy = inputValue;
|
244
|
+
}
|
245
|
+
|
246
|
+
try {
|
247
|
+
if (e.clipboardData) {
|
248
|
+
e.clipboardData.setData('Text', textToCopy);
|
249
|
+
} else {
|
250
|
+
window.clipboardData.setData('Text', textToCopy);
|
251
|
+
}
|
252
|
+
|
253
|
+
e.preventDefault();
|
254
|
+
} catch (ex) {
|
255
|
+
// empty
|
256
|
+
}
|
257
|
+
},
|
258
|
+
|
259
|
+
onInput: function (value) {
|
260
|
+
var owner = this, pps = owner.properties,
|
261
|
+
Util = Cleave.Util;
|
262
|
+
|
263
|
+
// case 1: delete one more character "4"
|
264
|
+
// 1234*| -> hit backspace -> 123|
|
265
|
+
// case 2: last character is not delimiter which is:
|
266
|
+
// 12|34* -> hit backspace -> 1|34*
|
267
|
+
// note: no need to apply this for numeral mode
|
268
|
+
if (!pps.numeral && pps.backspace && !Util.isDelimiter(value.slice(-pps.delimiterLength), pps.delimiter, pps.delimiters)) {
|
269
|
+
value = Util.headStr(value, value.length - pps.delimiterLength);
|
270
|
+
}
|
271
|
+
|
272
|
+
// phone formatter
|
273
|
+
if (pps.phone) {
|
274
|
+
if (pps.prefix && (!pps.noImmediatePrefix || value.length)) {
|
275
|
+
pps.result = pps.prefix + pps.phoneFormatter.format(value).slice(pps.prefix.length);
|
276
|
+
} else {
|
277
|
+
pps.result = pps.phoneFormatter.format(value);
|
278
|
+
}
|
279
|
+
owner.updateValueState();
|
280
|
+
|
281
|
+
return;
|
282
|
+
}
|
283
|
+
|
284
|
+
// numeral formatter
|
285
|
+
if (pps.numeral) {
|
286
|
+
if (pps.prefix && (!pps.noImmediatePrefix || value.length)) {
|
287
|
+
pps.result = pps.prefix + pps.numeralFormatter.format(value);
|
288
|
+
} else {
|
289
|
+
pps.result = pps.numeralFormatter.format(value);
|
290
|
+
}
|
291
|
+
owner.updateValueState();
|
292
|
+
|
293
|
+
return;
|
294
|
+
}
|
295
|
+
|
296
|
+
// date
|
297
|
+
if (pps.date) {
|
298
|
+
value = pps.dateFormatter.getValidatedDate(value);
|
299
|
+
}
|
300
|
+
|
301
|
+
// time
|
302
|
+
if (pps.time) {
|
303
|
+
value = pps.timeFormatter.getValidatedTime(value);
|
304
|
+
}
|
305
|
+
|
306
|
+
// strip delimiters
|
307
|
+
value = Util.stripDelimiters(value, pps.delimiter, pps.delimiters);
|
308
|
+
|
309
|
+
// strip prefix
|
310
|
+
value = Util.getPrefixStrippedValue(value, pps.prefix, pps.prefixLength, pps.result);
|
311
|
+
|
312
|
+
// strip non-numeric characters
|
313
|
+
value = pps.numericOnly ? Util.strip(value, /[^\d]/g) : value;
|
314
|
+
|
315
|
+
// convert case
|
316
|
+
value = pps.uppercase ? value.toUpperCase() : value;
|
317
|
+
value = pps.lowercase ? value.toLowerCase() : value;
|
318
|
+
|
319
|
+
// prefix
|
320
|
+
if (pps.prefix && (!pps.noImmediatePrefix || value.length)) {
|
321
|
+
value = pps.prefix + value;
|
322
|
+
|
323
|
+
// no blocks specified, no need to do formatting
|
324
|
+
if (pps.blocksLength === 0) {
|
325
|
+
pps.result = value;
|
326
|
+
owner.updateValueState();
|
327
|
+
|
328
|
+
return;
|
329
|
+
}
|
330
|
+
}
|
331
|
+
|
332
|
+
// update credit card props
|
333
|
+
if (pps.creditCard) {
|
334
|
+
owner.updateCreditCardPropsByValue(value);
|
335
|
+
}
|
336
|
+
|
337
|
+
// strip over length characters
|
338
|
+
value = Util.headStr(value, pps.maxLength);
|
339
|
+
|
340
|
+
// apply blocks
|
341
|
+
pps.result = Util.getFormattedValue(
|
342
|
+
value,
|
343
|
+
pps.blocks, pps.blocksLength,
|
344
|
+
pps.delimiter, pps.delimiters, pps.delimiterLazyShow
|
345
|
+
);
|
346
|
+
|
347
|
+
owner.updateValueState();
|
348
|
+
},
|
349
|
+
|
350
|
+
updateCreditCardPropsByValue: function (value) {
|
351
|
+
var owner = this, pps = owner.properties,
|
352
|
+
Util = Cleave.Util,
|
353
|
+
creditCardInfo;
|
354
|
+
|
355
|
+
// At least one of the first 4 characters has changed
|
356
|
+
if (Util.headStr(pps.result, 4) === Util.headStr(value, 4)) {
|
357
|
+
return;
|
358
|
+
}
|
359
|
+
|
360
|
+
creditCardInfo = Cleave.CreditCardDetector.getInfo(value, pps.creditCardStrictMode);
|
361
|
+
|
362
|
+
pps.blocks = creditCardInfo.blocks;
|
363
|
+
pps.blocksLength = pps.blocks.length;
|
364
|
+
pps.maxLength = Util.getMaxLength(pps.blocks);
|
365
|
+
|
366
|
+
// credit card type changed
|
367
|
+
if (pps.creditCardType !== creditCardInfo.type) {
|
368
|
+
pps.creditCardType = creditCardInfo.type;
|
369
|
+
|
370
|
+
pps.onCreditCardTypeChanged.call(owner, pps.creditCardType);
|
371
|
+
}
|
372
|
+
},
|
373
|
+
|
374
|
+
updateValueState: function () {
|
375
|
+
var owner = this,
|
376
|
+
Util = Cleave.Util,
|
377
|
+
pps = owner.properties;
|
378
|
+
|
379
|
+
if (!owner.element) {
|
380
|
+
return;
|
381
|
+
}
|
382
|
+
|
383
|
+
var endPos = owner.element.selectionEnd;
|
384
|
+
var oldValue = owner.element.value;
|
385
|
+
var newValue = pps.result;
|
386
|
+
|
387
|
+
endPos = Util.getNextCursorPosition(endPos, oldValue, newValue, pps.delimiter, pps.delimiters);
|
388
|
+
|
389
|
+
// fix Android browser type="text" input field
|
390
|
+
// cursor not jumping issue
|
391
|
+
if (owner.isAndroid) {
|
392
|
+
window.setTimeout(function () {
|
393
|
+
owner.element.value = newValue;
|
394
|
+
Util.setSelection(owner.element, endPos, pps.document, false);
|
395
|
+
owner.callOnValueChanged();
|
396
|
+
}, 1);
|
397
|
+
|
398
|
+
return;
|
399
|
+
}
|
400
|
+
|
401
|
+
owner.element.value = newValue;
|
402
|
+
Util.setSelection(owner.element, endPos, pps.document, false);
|
403
|
+
owner.callOnValueChanged();
|
404
|
+
},
|
405
|
+
|
406
|
+
callOnValueChanged: function () {
|
407
|
+
var owner = this,
|
408
|
+
pps = owner.properties;
|
409
|
+
|
410
|
+
pps.onValueChanged.call(owner, {
|
411
|
+
target: {
|
412
|
+
value: pps.result,
|
413
|
+
rawValue: owner.getRawValue()
|
414
|
+
}
|
415
|
+
});
|
416
|
+
},
|
417
|
+
|
418
|
+
setPhoneRegionCode: function (phoneRegionCode) {
|
419
|
+
var owner = this, pps = owner.properties;
|
420
|
+
|
421
|
+
pps.phoneRegionCode = phoneRegionCode;
|
422
|
+
owner.initPhoneFormatter();
|
423
|
+
owner.onChange();
|
424
|
+
},
|
425
|
+
|
426
|
+
setRawValue: function (value) {
|
427
|
+
var owner = this, pps = owner.properties;
|
428
|
+
|
429
|
+
value = value !== undefined && value !== null ? value.toString() : '';
|
430
|
+
|
431
|
+
if (pps.numeral) {
|
432
|
+
value = value.replace('.', pps.numeralDecimalMark);
|
433
|
+
}
|
434
|
+
|
435
|
+
pps.backspace = false;
|
436
|
+
|
437
|
+
owner.element.value = value;
|
438
|
+
owner.onInput(value);
|
439
|
+
},
|
440
|
+
|
441
|
+
getRawValue: function () {
|
442
|
+
var owner = this,
|
443
|
+
pps = owner.properties,
|
444
|
+
Util = Cleave.Util,
|
445
|
+
rawValue = owner.element.value;
|
446
|
+
|
447
|
+
if (pps.rawValueTrimPrefix) {
|
448
|
+
rawValue = Util.getPrefixStrippedValue(rawValue, pps.prefix, pps.prefixLength, pps.result);
|
449
|
+
}
|
450
|
+
|
451
|
+
if (pps.numeral) {
|
452
|
+
rawValue = pps.numeralFormatter.getRawValue(rawValue);
|
453
|
+
} else {
|
454
|
+
rawValue = Util.stripDelimiters(rawValue, pps.delimiter, pps.delimiters);
|
455
|
+
}
|
456
|
+
|
457
|
+
return rawValue;
|
458
|
+
},
|
459
|
+
|
460
|
+
getISOFormatDate: function () {
|
461
|
+
var owner = this,
|
462
|
+
pps = owner.properties;
|
463
|
+
|
464
|
+
return pps.date ? pps.dateFormatter.getISOFormatDate() : '';
|
465
|
+
},
|
466
|
+
|
467
|
+
getFormattedValue: function () {
|
468
|
+
return this.element.value;
|
469
|
+
},
|
470
|
+
|
471
|
+
destroy: function () {
|
472
|
+
var owner = this;
|
473
|
+
|
474
|
+
owner.element.removeEventListener('input', owner.onChangeListener);
|
475
|
+
owner.element.removeEventListener('keydown', owner.onKeyDownListener);
|
476
|
+
owner.element.removeEventListener('focus', owner.onFocusListener);
|
477
|
+
owner.element.removeEventListener('cut', owner.onCutListener);
|
478
|
+
owner.element.removeEventListener('copy', owner.onCopyListener);
|
479
|
+
},
|
480
|
+
|
481
|
+
toString: function () {
|
482
|
+
return '[Cleave Object]';
|
483
|
+
}
|
484
|
+
};
|
485
|
+
|
486
|
+
Cleave.NumeralFormatter = __webpack_require__(1);
|
487
|
+
Cleave.DateFormatter = __webpack_require__(2);
|
488
|
+
Cleave.TimeFormatter = __webpack_require__(3);
|
489
|
+
Cleave.PhoneFormatter = __webpack_require__(4);
|
490
|
+
Cleave.CreditCardDetector = __webpack_require__(5);
|
491
|
+
Cleave.Util = __webpack_require__(6);
|
492
|
+
Cleave.DefaultProperties = __webpack_require__(7);
|
493
|
+
|
494
|
+
// for angular directive
|
495
|
+
((typeof global === 'object' && global) ? global : window)['Cleave'] = Cleave;
|
496
|
+
|
497
|
+
// CommonJS
|
498
|
+
module.exports = Cleave;
|
499
|
+
|
500
|
+
/* WEBPACK VAR INJECTION */}.call(exports, (function() { return this; }())))
|
501
|
+
|
502
|
+
/***/ }),
|
503
|
+
/* 1 */
|
504
|
+
/***/ (function(module, exports) {
|
505
|
+
|
506
|
+
'use strict';
|
507
|
+
|
508
|
+
var NumeralFormatter = function (numeralDecimalMark,
|
509
|
+
numeralIntegerScale,
|
510
|
+
numeralDecimalScale,
|
511
|
+
numeralThousandsGroupStyle,
|
512
|
+
numeralPositiveOnly,
|
513
|
+
stripLeadingZeroes,
|
514
|
+
delimiter) {
|
515
|
+
var owner = this;
|
516
|
+
|
517
|
+
owner.numeralDecimalMark = numeralDecimalMark || '.';
|
518
|
+
owner.numeralIntegerScale = numeralIntegerScale > 0 ? numeralIntegerScale : 0;
|
519
|
+
owner.numeralDecimalScale = numeralDecimalScale >= 0 ? numeralDecimalScale : 2;
|
520
|
+
owner.numeralThousandsGroupStyle = numeralThousandsGroupStyle || NumeralFormatter.groupStyle.thousand;
|
521
|
+
owner.numeralPositiveOnly = !!numeralPositiveOnly;
|
522
|
+
owner.stripLeadingZeroes = stripLeadingZeroes !== false;
|
523
|
+
owner.delimiter = (delimiter || delimiter === '') ? delimiter : ',';
|
524
|
+
owner.delimiterRE = delimiter ? new RegExp('\\' + delimiter, 'g') : '';
|
525
|
+
};
|
526
|
+
|
527
|
+
NumeralFormatter.groupStyle = {
|
528
|
+
thousand: 'thousand',
|
529
|
+
lakh: 'lakh',
|
530
|
+
wan: 'wan',
|
531
|
+
none: 'none'
|
532
|
+
};
|
533
|
+
|
534
|
+
NumeralFormatter.prototype = {
|
535
|
+
getRawValue: function (value) {
|
536
|
+
return value.replace(this.delimiterRE, '').replace(this.numeralDecimalMark, '.');
|
537
|
+
},
|
538
|
+
|
539
|
+
format: function (value) {
|
540
|
+
var owner = this, parts, partInteger, partDecimal = '';
|
541
|
+
|
542
|
+
// strip alphabet letters
|
543
|
+
value = value.replace(/[A-Za-z]/g, '')
|
544
|
+
// replace the first decimal mark with reserved placeholder
|
545
|
+
.replace(owner.numeralDecimalMark, 'M')
|
546
|
+
|
547
|
+
// strip non numeric letters except minus and "M"
|
548
|
+
// this is to ensure prefix has been stripped
|
549
|
+
.replace(/[^\dM-]/g, '')
|
550
|
+
|
551
|
+
// replace the leading minus with reserved placeholder
|
552
|
+
.replace(/^\-/, 'N')
|
553
|
+
|
554
|
+
// strip the other minus sign (if present)
|
555
|
+
.replace(/\-/g, '')
|
556
|
+
|
557
|
+
// replace the minus sign (if present)
|
558
|
+
.replace('N', owner.numeralPositiveOnly ? '' : '-')
|
559
|
+
|
560
|
+
// replace decimal mark
|
561
|
+
.replace('M', owner.numeralDecimalMark);
|
562
|
+
|
563
|
+
// strip any leading zeros
|
564
|
+
if (owner.stripLeadingZeroes) {
|
565
|
+
value = value.replace(/^(-)?0+(?=\d)/, '$1');
|
566
|
+
}
|
567
|
+
|
568
|
+
partInteger = value;
|
569
|
+
|
570
|
+
if (value.indexOf(owner.numeralDecimalMark) >= 0) {
|
571
|
+
parts = value.split(owner.numeralDecimalMark);
|
572
|
+
partInteger = parts[0];
|
573
|
+
partDecimal = owner.numeralDecimalMark + parts[1].slice(0, owner.numeralDecimalScale);
|
574
|
+
}
|
575
|
+
|
576
|
+
if (owner.numeralIntegerScale > 0) {
|
577
|
+
partInteger = partInteger.slice(0, owner.numeralIntegerScale + (value.slice(0, 1) === '-' ? 1 : 0));
|
578
|
+
}
|
579
|
+
|
580
|
+
switch (owner.numeralThousandsGroupStyle) {
|
581
|
+
case NumeralFormatter.groupStyle.lakh:
|
582
|
+
partInteger = partInteger.replace(/(\d)(?=(\d\d)+\d$)/g, '$1' + owner.delimiter);
|
583
|
+
|
584
|
+
break;
|
585
|
+
|
586
|
+
case NumeralFormatter.groupStyle.wan:
|
587
|
+
partInteger = partInteger.replace(/(\d)(?=(\d{4})+$)/g, '$1' + owner.delimiter);
|
588
|
+
|
589
|
+
break;
|
590
|
+
|
591
|
+
case NumeralFormatter.groupStyle.thousand:
|
592
|
+
partInteger = partInteger.replace(/(\d)(?=(\d{3})+$)/g, '$1' + owner.delimiter);
|
593
|
+
|
594
|
+
break;
|
595
|
+
}
|
596
|
+
|
597
|
+
return partInteger.toString() + (owner.numeralDecimalScale > 0 ? partDecimal.toString() : '');
|
598
|
+
}
|
599
|
+
};
|
600
|
+
|
601
|
+
module.exports = NumeralFormatter;
|
602
|
+
|
603
|
+
|
604
|
+
/***/ }),
|
605
|
+
/* 2 */
|
606
|
+
/***/ (function(module, exports) {
|
607
|
+
|
608
|
+
'use strict';
|
609
|
+
|
610
|
+
var DateFormatter = function (datePattern) {
|
611
|
+
var owner = this;
|
612
|
+
|
613
|
+
owner.date = [];
|
614
|
+
owner.blocks = [];
|
615
|
+
owner.datePattern = datePattern;
|
616
|
+
owner.initBlocks();
|
617
|
+
};
|
618
|
+
|
619
|
+
DateFormatter.prototype = {
|
620
|
+
initBlocks: function () {
|
621
|
+
var owner = this;
|
622
|
+
owner.datePattern.forEach(function (value) {
|
623
|
+
if (value === 'Y') {
|
624
|
+
owner.blocks.push(4);
|
625
|
+
} else {
|
626
|
+
owner.blocks.push(2);
|
627
|
+
}
|
628
|
+
});
|
629
|
+
},
|
630
|
+
|
631
|
+
getISOFormatDate: function () {
|
632
|
+
var owner = this,
|
633
|
+
date = owner.date;
|
634
|
+
|
635
|
+
return date[2] ? (
|
636
|
+
date[2] + '-' + owner.addLeadingZero(date[1]) + '-' + owner.addLeadingZero(date[0])
|
637
|
+
) : '';
|
638
|
+
},
|
639
|
+
|
640
|
+
getBlocks: function () {
|
641
|
+
return this.blocks;
|
642
|
+
},
|
643
|
+
|
644
|
+
getValidatedDate: function (value) {
|
645
|
+
var owner = this, result = '';
|
646
|
+
|
647
|
+
value = value.replace(/[^\d]/g, '');
|
648
|
+
|
649
|
+
owner.blocks.forEach(function (length, index) {
|
650
|
+
if (value.length > 0) {
|
651
|
+
var sub = value.slice(0, length),
|
652
|
+
sub0 = sub.slice(0, 1),
|
653
|
+
rest = value.slice(length);
|
654
|
+
|
655
|
+
switch (owner.datePattern[index]) {
|
656
|
+
case 'd':
|
657
|
+
if (sub === '00') {
|
658
|
+
sub = '01';
|
659
|
+
} else if (parseInt(sub0, 10) > 3) {
|
660
|
+
sub = '0' + sub0;
|
661
|
+
} else if (parseInt(sub, 10) > 31) {
|
662
|
+
sub = '31';
|
663
|
+
}
|
664
|
+
|
665
|
+
break;
|
666
|
+
|
667
|
+
case 'm':
|
668
|
+
if (sub === '00') {
|
669
|
+
sub = '01';
|
670
|
+
} else if (parseInt(sub0, 10) > 1) {
|
671
|
+
sub = '0' + sub0;
|
672
|
+
} else if (parseInt(sub, 10) > 12) {
|
673
|
+
sub = '12';
|
674
|
+
}
|
675
|
+
|
676
|
+
break;
|
677
|
+
}
|
678
|
+
|
679
|
+
result += sub;
|
680
|
+
|
681
|
+
// update remaining string
|
682
|
+
value = rest;
|
683
|
+
}
|
684
|
+
});
|
685
|
+
|
686
|
+
return this.getFixedDateString(result);
|
687
|
+
},
|
688
|
+
|
689
|
+
getFixedDateString: function (value) {
|
690
|
+
var owner = this, datePattern = owner.datePattern, date = [],
|
691
|
+
dayIndex = 0, monthIndex = 0, yearIndex = 0,
|
692
|
+
dayStartIndex = 0, monthStartIndex = 0, yearStartIndex = 0,
|
693
|
+
day, month, year, fullYearDone = false;
|
694
|
+
|
695
|
+
// mm-dd || dd-mm
|
696
|
+
if (value.length === 4 && datePattern[0].toLowerCase() !== 'y' && datePattern[1].toLowerCase() !== 'y') {
|
697
|
+
dayStartIndex = datePattern[0] === 'd' ? 0 : 2;
|
698
|
+
monthStartIndex = 2 - dayStartIndex;
|
699
|
+
day = parseInt(value.slice(dayStartIndex, dayStartIndex + 2), 10);
|
700
|
+
month = parseInt(value.slice(monthStartIndex, monthStartIndex + 2), 10);
|
701
|
+
|
702
|
+
date = this.getFixedDate(day, month, 0);
|
703
|
+
}
|
704
|
+
|
705
|
+
// yyyy-mm-dd || yyyy-dd-mm || mm-dd-yyyy || dd-mm-yyyy || dd-yyyy-mm || mm-yyyy-dd
|
706
|
+
if (value.length === 8) {
|
707
|
+
datePattern.forEach(function (type, index) {
|
708
|
+
switch (type) {
|
709
|
+
case 'd':
|
710
|
+
dayIndex = index;
|
711
|
+
break;
|
712
|
+
case 'm':
|
713
|
+
monthIndex = index;
|
714
|
+
break;
|
715
|
+
default:
|
716
|
+
yearIndex = index;
|
717
|
+
break;
|
718
|
+
}
|
719
|
+
});
|
720
|
+
|
721
|
+
yearStartIndex = yearIndex * 2;
|
722
|
+
dayStartIndex = (dayIndex <= yearIndex) ? dayIndex * 2 : (dayIndex * 2 + 2);
|
723
|
+
monthStartIndex = (monthIndex <= yearIndex) ? monthIndex * 2 : (monthIndex * 2 + 2);
|
724
|
+
|
725
|
+
day = parseInt(value.slice(dayStartIndex, dayStartIndex + 2), 10);
|
726
|
+
month = parseInt(value.slice(monthStartIndex, monthStartIndex + 2), 10);
|
727
|
+
year = parseInt(value.slice(yearStartIndex, yearStartIndex + 4), 10);
|
728
|
+
|
729
|
+
fullYearDone = value.slice(yearStartIndex, yearStartIndex + 4).length === 4;
|
730
|
+
|
731
|
+
date = this.getFixedDate(day, month, year);
|
732
|
+
}
|
733
|
+
|
734
|
+
owner.date = date;
|
735
|
+
|
736
|
+
return date.length === 0 ? value : datePattern.reduce(function (previous, current) {
|
737
|
+
switch (current) {
|
738
|
+
case 'd':
|
739
|
+
return previous + owner.addLeadingZero(date[0]);
|
740
|
+
case 'm':
|
741
|
+
return previous + owner.addLeadingZero(date[1]);
|
742
|
+
default:
|
743
|
+
return previous + (fullYearDone ? owner.addLeadingZeroForYear(date[2]) : '');
|
744
|
+
}
|
745
|
+
}, '');
|
746
|
+
},
|
747
|
+
|
748
|
+
getFixedDate: function (day, month, year) {
|
749
|
+
day = Math.min(day, 31);
|
750
|
+
month = Math.min(month, 12);
|
751
|
+
year = parseInt((year || 0), 10);
|
752
|
+
|
753
|
+
if ((month < 7 && month % 2 === 0) || (month > 8 && month % 2 === 1)) {
|
754
|
+
day = Math.min(day, month === 2 ? (this.isLeapYear(year) ? 29 : 28) : 30);
|
755
|
+
}
|
756
|
+
|
757
|
+
return [day, month, year];
|
758
|
+
},
|
759
|
+
|
760
|
+
isLeapYear: function (year) {
|
761
|
+
return ((year % 4 === 0) && (year % 100 !== 0)) || (year % 400 === 0);
|
762
|
+
},
|
763
|
+
|
764
|
+
addLeadingZero: function (number) {
|
765
|
+
return (number < 10 ? '0' : '') + number;
|
766
|
+
},
|
767
|
+
|
768
|
+
addLeadingZeroForYear: function (number) {
|
769
|
+
return (number < 10 ? '000' : (number < 100 ? '00' : (number < 1000 ? '0' : ''))) + number;
|
770
|
+
}
|
771
|
+
};
|
772
|
+
|
773
|
+
module.exports = DateFormatter;
|
774
|
+
|
775
|
+
|
776
|
+
|
777
|
+
/***/ }),
|
778
|
+
/* 3 */
|
779
|
+
/***/ (function(module, exports) {
|
780
|
+
|
781
|
+
'use strict';
|
782
|
+
|
783
|
+
var TimeFormatter = function (timePattern) {
|
784
|
+
var owner = this;
|
785
|
+
|
786
|
+
owner.time = [];
|
787
|
+
owner.blocks = [];
|
788
|
+
owner.timePattern = timePattern;
|
789
|
+
owner.initBlocks();
|
790
|
+
};
|
791
|
+
|
792
|
+
TimeFormatter.prototype = {
|
793
|
+
initBlocks: function () {
|
794
|
+
var owner = this;
|
795
|
+
owner.timePattern.forEach(function () {
|
796
|
+
owner.blocks.push(2);
|
797
|
+
});
|
798
|
+
},
|
799
|
+
|
800
|
+
getISOFormatTime: function () {
|
801
|
+
var owner = this,
|
802
|
+
time = owner.time;
|
803
|
+
|
804
|
+
return time[2] ? (
|
805
|
+
owner.addLeadingZero(time[0]) + ':' + owner.addLeadingZero(time[1]) + ':' + owner.addLeadingZero(time[2])
|
806
|
+
) : '';
|
807
|
+
},
|
808
|
+
|
809
|
+
getBlocks: function () {
|
810
|
+
return this.blocks;
|
811
|
+
},
|
812
|
+
|
813
|
+
getValidatedTime: function (value) {
|
814
|
+
var owner = this, result = '';
|
815
|
+
|
816
|
+
value = value.replace(/[^\d]/g, '');
|
817
|
+
|
818
|
+
owner.blocks.forEach(function (length, index) {
|
819
|
+
if (value.length > 0) {
|
820
|
+
var sub = value.slice(0, length),
|
821
|
+
sub0 = sub.slice(0, 1),
|
822
|
+
rest = value.slice(length);
|
823
|
+
|
824
|
+
switch (owner.timePattern[index]) {
|
825
|
+
|
826
|
+
case 'h':
|
827
|
+
if (parseInt(sub0, 10) > 2) {
|
828
|
+
sub = '0' + sub0;
|
829
|
+
} else if (parseInt(sub, 10) > 23) {
|
830
|
+
sub = '23';
|
831
|
+
}
|
832
|
+
|
833
|
+
break;
|
834
|
+
|
835
|
+
case 'm':
|
836
|
+
case 's':
|
837
|
+
if (parseInt(sub0, 10) > 5) {
|
838
|
+
sub = '0' + sub0;
|
839
|
+
} else if (parseInt(sub, 10) > 60) {
|
840
|
+
sub = '60';
|
841
|
+
}
|
842
|
+
break;
|
843
|
+
}
|
844
|
+
|
845
|
+
result += sub;
|
846
|
+
|
847
|
+
// update remaining string
|
848
|
+
value = rest;
|
849
|
+
}
|
850
|
+
});
|
851
|
+
|
852
|
+
return this.getFixedTimeString(result);
|
853
|
+
},
|
854
|
+
|
855
|
+
getFixedTimeString: function (value) {
|
856
|
+
var owner = this, timePattern = owner.timePattern, time = [],
|
857
|
+
secondIndex = 0, minuteIndex = 0, hourIndex = 0,
|
858
|
+
secondStartIndex = 0, minuteStartIndex = 0, hourStartIndex = 0,
|
859
|
+
second, minute, hour;
|
860
|
+
|
861
|
+
if (value.length === 6) {
|
862
|
+
timePattern.forEach(function (type, index) {
|
863
|
+
switch (type) {
|
864
|
+
case 's':
|
865
|
+
secondIndex = index * 2;
|
866
|
+
break;
|
867
|
+
case 'm':
|
868
|
+
minuteIndex = index * 2;
|
869
|
+
break;
|
870
|
+
case 'h':
|
871
|
+
hourIndex = index * 2;
|
872
|
+
break;
|
873
|
+
}
|
874
|
+
});
|
875
|
+
|
876
|
+
hourStartIndex = hourIndex;
|
877
|
+
minuteStartIndex = minuteIndex;
|
878
|
+
secondStartIndex = secondIndex;
|
879
|
+
|
880
|
+
second = parseInt(value.slice(secondStartIndex, secondStartIndex + 2), 10);
|
881
|
+
minute = parseInt(value.slice(minuteStartIndex, minuteStartIndex + 2), 10);
|
882
|
+
hour = parseInt(value.slice(hourStartIndex, hourStartIndex + 2), 10);
|
883
|
+
|
884
|
+
time = this.getFixedTime(hour, minute, second);
|
885
|
+
}
|
886
|
+
|
887
|
+
if (value.length === 4 && owner.timePattern.indexOf('s') < 0) {
|
888
|
+
timePattern.forEach(function (type, index) {
|
889
|
+
switch (type) {
|
890
|
+
case 'm':
|
891
|
+
minuteIndex = index * 2;
|
892
|
+
break;
|
893
|
+
case 'h':
|
894
|
+
hourIndex = index * 2;
|
895
|
+
break;
|
896
|
+
}
|
897
|
+
});
|
898
|
+
|
899
|
+
hourStartIndex = hourIndex;
|
900
|
+
minuteStartIndex = minuteIndex;
|
901
|
+
|
902
|
+
second = 0;
|
903
|
+
minute = parseInt(value.slice(minuteStartIndex, minuteStartIndex + 2), 10);
|
904
|
+
hour = parseInt(value.slice(hourStartIndex, hourStartIndex + 2), 10);
|
905
|
+
|
906
|
+
time = this.getFixedTime(hour, minute, second);
|
907
|
+
}
|
908
|
+
|
909
|
+
owner.time = time;
|
910
|
+
|
911
|
+
return time.length === 0 ? value : timePattern.reduce(function (previous, current) {
|
912
|
+
switch (current) {
|
913
|
+
case 's':
|
914
|
+
return previous + owner.addLeadingZero(time[2]);
|
915
|
+
case 'm':
|
916
|
+
return previous + owner.addLeadingZero(time[1]);
|
917
|
+
case 'h':
|
918
|
+
return previous + owner.addLeadingZero(time[0]);
|
919
|
+
}
|
920
|
+
}, '');
|
921
|
+
},
|
922
|
+
|
923
|
+
getFixedTime: function (hour, minute, second) {
|
924
|
+
second = Math.min(parseInt(second || 0, 10), 60);
|
925
|
+
minute = Math.min(minute, 60);
|
926
|
+
hour = Math.min(hour, 60);
|
927
|
+
|
928
|
+
return [hour, minute, second];
|
929
|
+
},
|
930
|
+
|
931
|
+
addLeadingZero: function (number) {
|
932
|
+
return (number < 10 ? '0' : '') + number;
|
933
|
+
}
|
934
|
+
};
|
935
|
+
|
936
|
+
module.exports = TimeFormatter;
|
937
|
+
|
938
|
+
|
939
|
+
/***/ }),
|
940
|
+
/* 4 */
|
941
|
+
/***/ (function(module, exports) {
|
942
|
+
|
943
|
+
'use strict';
|
944
|
+
|
945
|
+
var PhoneFormatter = function (formatter, delimiter) {
|
946
|
+
var owner = this;
|
947
|
+
|
948
|
+
owner.delimiter = (delimiter || delimiter === '') ? delimiter : ' ';
|
949
|
+
owner.delimiterRE = delimiter ? new RegExp('\\' + delimiter, 'g') : '';
|
950
|
+
|
951
|
+
owner.formatter = formatter;
|
952
|
+
};
|
953
|
+
|
954
|
+
PhoneFormatter.prototype = {
|
955
|
+
setFormatter: function (formatter) {
|
956
|
+
this.formatter = formatter;
|
957
|
+
},
|
958
|
+
|
959
|
+
format: function (phoneNumber) {
|
960
|
+
var owner = this;
|
961
|
+
|
962
|
+
owner.formatter.clear();
|
963
|
+
|
964
|
+
// only keep number and +
|
965
|
+
phoneNumber = phoneNumber.replace(/[^\d+]/g, '');
|
966
|
+
|
967
|
+
// strip non-leading +
|
968
|
+
phoneNumber = phoneNumber.replace(/^\+/, 'B').replace(/\+/g, '').replace('B', '+');
|
969
|
+
|
970
|
+
// strip delimiter
|
971
|
+
phoneNumber = phoneNumber.replace(owner.delimiterRE, '');
|
972
|
+
|
973
|
+
var result = '', current, validated = false;
|
974
|
+
|
975
|
+
for (var i = 0, iMax = phoneNumber.length; i < iMax; i++) {
|
976
|
+
current = owner.formatter.inputDigit(phoneNumber.charAt(i));
|
977
|
+
|
978
|
+
// has ()- or space inside
|
979
|
+
if (/[\s()-]/g.test(current)) {
|
980
|
+
result = current;
|
981
|
+
|
982
|
+
validated = true;
|
983
|
+
} else {
|
984
|
+
if (!validated) {
|
985
|
+
result = current;
|
986
|
+
}
|
987
|
+
// else: over length input
|
988
|
+
// it turns to invalid number again
|
989
|
+
}
|
990
|
+
}
|
991
|
+
|
992
|
+
// strip ()
|
993
|
+
// e.g. US: 7161234567 returns (716) 123-4567
|
994
|
+
result = result.replace(/[()]/g, '');
|
995
|
+
// replace library delimiter with user customized delimiter
|
996
|
+
result = result.replace(/[\s-]/g, owner.delimiter);
|
997
|
+
|
998
|
+
return result;
|
999
|
+
}
|
1000
|
+
};
|
1001
|
+
|
1002
|
+
module.exports = PhoneFormatter;
|
1003
|
+
|
1004
|
+
|
1005
|
+
/***/ }),
|
1006
|
+
/* 5 */
|
1007
|
+
/***/ (function(module, exports) {
|
1008
|
+
|
1009
|
+
'use strict';
|
1010
|
+
|
1011
|
+
var CreditCardDetector = {
|
1012
|
+
blocks: {
|
1013
|
+
uatp: [4, 5, 6],
|
1014
|
+
amex: [4, 6, 5],
|
1015
|
+
diners: [4, 6, 4],
|
1016
|
+
discover: [4, 4, 4, 4],
|
1017
|
+
mastercard: [4, 4, 4, 4],
|
1018
|
+
dankort: [4, 4, 4, 4],
|
1019
|
+
instapayment: [4, 4, 4, 4],
|
1020
|
+
jcb15: [4, 6, 5],
|
1021
|
+
jcb: [4, 4, 4, 4],
|
1022
|
+
maestro: [4, 4, 4, 4],
|
1023
|
+
visa: [4, 4, 4, 4],
|
1024
|
+
mir: [4, 4, 4, 4],
|
1025
|
+
unionPay: [4, 4, 4, 4],
|
1026
|
+
general: [4, 4, 4, 4],
|
1027
|
+
generalStrict: [4, 4, 4, 7]
|
1028
|
+
},
|
1029
|
+
|
1030
|
+
re: {
|
1031
|
+
// starts with 1; 15 digits, not starts with 1800 (jcb card)
|
1032
|
+
uatp: /^(?!1800)1\d{0,14}/,
|
1033
|
+
|
1034
|
+
// starts with 34/37; 15 digits
|
1035
|
+
amex: /^3[47]\d{0,13}/,
|
1036
|
+
|
1037
|
+
// starts with 6011/65/644-649; 16 digits
|
1038
|
+
discover: /^(?:6011|65\d{0,2}|64[4-9]\d?)\d{0,12}/,
|
1039
|
+
|
1040
|
+
// starts with 300-305/309 or 36/38/39; 14 digits
|
1041
|
+
diners: /^3(?:0([0-5]|9)|[689]\d?)\d{0,11}/,
|
1042
|
+
|
1043
|
+
// starts with 51-55/2221–2720; 16 digits
|
1044
|
+
mastercard: /^(5[1-5]\d{0,2}|22[2-9]\d{0,1}|2[3-7]\d{0,2})\d{0,12}/,
|
1045
|
+
|
1046
|
+
// starts with 5019/4175/4571; 16 digits
|
1047
|
+
dankort: /^(5019|4175|4571)\d{0,12}/,
|
1048
|
+
|
1049
|
+
// starts with 637-639; 16 digits
|
1050
|
+
instapayment: /^63[7-9]\d{0,13}/,
|
1051
|
+
|
1052
|
+
// starts with 2131/1800; 15 digits
|
1053
|
+
jcb15: /^(?:2131|1800)\d{0,11}/,
|
1054
|
+
|
1055
|
+
// starts with 2131/1800/35; 16 digits
|
1056
|
+
jcb: /^(?:35\d{0,2})\d{0,12}/,
|
1057
|
+
|
1058
|
+
// starts with 50/56-58/6304/67; 16 digits
|
1059
|
+
maestro: /^(?:5[0678]\d{0,2}|6304|67\d{0,2})\d{0,12}/,
|
1060
|
+
|
1061
|
+
// starts with 22; 16 digits
|
1062
|
+
mir: /^220[0-4]\d{0,12}/,
|
1063
|
+
|
1064
|
+
// starts with 4; 16 digits
|
1065
|
+
visa: /^4\d{0,15}/,
|
1066
|
+
|
1067
|
+
// starts with 62; 16 digits
|
1068
|
+
unionPay: /^62\d{0,14}/
|
1069
|
+
},
|
1070
|
+
|
1071
|
+
getInfo: function (value, strictMode) {
|
1072
|
+
var blocks = CreditCardDetector.blocks,
|
1073
|
+
re = CreditCardDetector.re;
|
1074
|
+
|
1075
|
+
// Some credit card can have up to 19 digits number.
|
1076
|
+
// Set strictMode to true will remove the 16 max-length restrain,
|
1077
|
+
// however, I never found any website validate card number like
|
1078
|
+
// this, hence probably you don't want to enable this option.
|
1079
|
+
strictMode = !!strictMode;
|
1080
|
+
|
1081
|
+
for (var key in re) {
|
1082
|
+
if (re[key].test(value)) {
|
1083
|
+
var block;
|
1084
|
+
|
1085
|
+
if (strictMode) {
|
1086
|
+
block = blocks.generalStrict;
|
1087
|
+
} else {
|
1088
|
+
block = blocks[key];
|
1089
|
+
}
|
1090
|
+
|
1091
|
+
return {
|
1092
|
+
type: key,
|
1093
|
+
blocks: block
|
1094
|
+
};
|
1095
|
+
}
|
1096
|
+
}
|
1097
|
+
|
1098
|
+
return {
|
1099
|
+
type: 'unknown',
|
1100
|
+
blocks: strictMode ? blocks.generalStrict : blocks.general
|
1101
|
+
};
|
1102
|
+
}
|
1103
|
+
};
|
1104
|
+
|
1105
|
+
module.exports = CreditCardDetector;
|
1106
|
+
|
1107
|
+
|
1108
|
+
/***/ }),
|
1109
|
+
/* 6 */
|
1110
|
+
/***/ (function(module, exports) {
|
1111
|
+
|
1112
|
+
'use strict';
|
1113
|
+
|
1114
|
+
var Util = {
|
1115
|
+
noop: function () {
|
1116
|
+
},
|
1117
|
+
|
1118
|
+
strip: function (value, re) {
|
1119
|
+
return value.replace(re, '');
|
1120
|
+
},
|
1121
|
+
|
1122
|
+
isDelimiter: function (letter, delimiter, delimiters) {
|
1123
|
+
// single delimiter
|
1124
|
+
if (delimiters.length === 0) {
|
1125
|
+
return letter === delimiter;
|
1126
|
+
}
|
1127
|
+
|
1128
|
+
// multiple delimiters
|
1129
|
+
return delimiters.some(function (current) {
|
1130
|
+
if (letter === current) {
|
1131
|
+
return true;
|
1132
|
+
}
|
1133
|
+
});
|
1134
|
+
},
|
1135
|
+
|
1136
|
+
getDelimiterREByDelimiter: function (delimiter) {
|
1137
|
+
return new RegExp(delimiter.replace(/([.?*+^$[\]\\(){}|-])/g, '\\$1'), 'g');
|
1138
|
+
},
|
1139
|
+
|
1140
|
+
getNextCursorPosition: function (prevPos, oldValue, newValue, delimiter, delimiters) {
|
1141
|
+
// If cursor was at the end of value, just place it back.
|
1142
|
+
// Because new value could contain additional chars.
|
1143
|
+
if (oldValue.length === prevPos) {
|
1144
|
+
return newValue.length;
|
1145
|
+
}
|
1146
|
+
|
1147
|
+
return prevPos + this.getPositionOffset(prevPos, oldValue, newValue, delimiter ,delimiters);
|
1148
|
+
},
|
1149
|
+
|
1150
|
+
getPositionOffset: function (prevPos, oldValue, newValue, delimiter, delimiters) {
|
1151
|
+
var oldRawValue, newRawValue, lengthOffset;
|
1152
|
+
|
1153
|
+
oldRawValue = this.stripDelimiters(oldValue.slice(0, prevPos), delimiter, delimiters);
|
1154
|
+
newRawValue = this.stripDelimiters(newValue.slice(0, prevPos), delimiter, delimiters);
|
1155
|
+
lengthOffset = oldRawValue.length - newRawValue.length;
|
1156
|
+
|
1157
|
+
return (lengthOffset !== 0) ? (lengthOffset / Math.abs(lengthOffset)) : 0;
|
1158
|
+
},
|
1159
|
+
|
1160
|
+
stripDelimiters: function (value, delimiter, delimiters) {
|
1161
|
+
var owner = this;
|
1162
|
+
|
1163
|
+
// single delimiter
|
1164
|
+
if (delimiters.length === 0) {
|
1165
|
+
var delimiterRE = delimiter ? owner.getDelimiterREByDelimiter(delimiter) : '';
|
1166
|
+
|
1167
|
+
return value.replace(delimiterRE, '');
|
1168
|
+
}
|
1169
|
+
|
1170
|
+
// multiple delimiters
|
1171
|
+
delimiters.forEach(function (current) {
|
1172
|
+
value = value.replace(owner.getDelimiterREByDelimiter(current), '');
|
1173
|
+
});
|
1174
|
+
|
1175
|
+
return value;
|
1176
|
+
},
|
1177
|
+
|
1178
|
+
headStr: function (str, length) {
|
1179
|
+
return str.slice(0, length);
|
1180
|
+
},
|
1181
|
+
|
1182
|
+
getMaxLength: function (blocks) {
|
1183
|
+
return blocks.reduce(function (previous, current) {
|
1184
|
+
return previous + current;
|
1185
|
+
}, 0);
|
1186
|
+
},
|
1187
|
+
|
1188
|
+
// strip value by prefix length
|
1189
|
+
// for prefix: PRE
|
1190
|
+
// (PRE123, 3) -> 123
|
1191
|
+
// (PR123, 3) -> 23 this happens when user hits backspace in front of "PRE"
|
1192
|
+
getPrefixStrippedValue: function (value, prefix, prefixLength, prevValue) {
|
1193
|
+
if (value.slice(0, prefixLength) !== prefix) {
|
1194
|
+
|
1195
|
+
// Check whether if it is a deletion
|
1196
|
+
if (value.length < prevValue.length) {
|
1197
|
+
value = value.length > prefixLength ? prevValue : prefix;
|
1198
|
+
} else {
|
1199
|
+
var diffIndex = this.getFirstDiffIndex(prefix, value.slice(0, prefixLength));
|
1200
|
+
value = prefix + value.slice(diffIndex, diffIndex + 1) + value.slice(prefixLength + 1);
|
1201
|
+
}
|
1202
|
+
}
|
1203
|
+
|
1204
|
+
return value.slice(prefixLength);
|
1205
|
+
},
|
1206
|
+
|
1207
|
+
getFirstDiffIndex: function (prev, current) {
|
1208
|
+
var index = 0;
|
1209
|
+
|
1210
|
+
while (prev.charAt(index) === current.charAt(index)) {
|
1211
|
+
if (prev.charAt(index++) === '') {
|
1212
|
+
return -1;
|
1213
|
+
}
|
1214
|
+
}
|
1215
|
+
|
1216
|
+
return index;
|
1217
|
+
},
|
1218
|
+
|
1219
|
+
getFormattedValue: function (value, blocks, blocksLength, delimiter, delimiters, delimiterLazyShow) {
|
1220
|
+
var result = '',
|
1221
|
+
multipleDelimiters = delimiters.length > 0,
|
1222
|
+
currentDelimiter;
|
1223
|
+
|
1224
|
+
// no options, normal input
|
1225
|
+
if (blocksLength === 0) {
|
1226
|
+
return value;
|
1227
|
+
}
|
1228
|
+
|
1229
|
+
blocks.forEach(function (length, index) {
|
1230
|
+
if (value.length > 0) {
|
1231
|
+
var sub = value.slice(0, length),
|
1232
|
+
rest = value.slice(length);
|
1233
|
+
|
1234
|
+
if (multipleDelimiters) {
|
1235
|
+
currentDelimiter = delimiters[delimiterLazyShow ? (index - 1) : index] || currentDelimiter;
|
1236
|
+
} else {
|
1237
|
+
currentDelimiter = delimiter;
|
1238
|
+
}
|
1239
|
+
|
1240
|
+
if (delimiterLazyShow) {
|
1241
|
+
if (index > 0) {
|
1242
|
+
result += currentDelimiter;
|
1243
|
+
}
|
1244
|
+
|
1245
|
+
result += sub;
|
1246
|
+
} else {
|
1247
|
+
result += sub;
|
1248
|
+
|
1249
|
+
if (sub.length === length && index < blocksLength - 1) {
|
1250
|
+
result += currentDelimiter;
|
1251
|
+
}
|
1252
|
+
}
|
1253
|
+
|
1254
|
+
// update remaining string
|
1255
|
+
value = rest;
|
1256
|
+
}
|
1257
|
+
});
|
1258
|
+
|
1259
|
+
return result;
|
1260
|
+
},
|
1261
|
+
|
1262
|
+
// move cursor to the end
|
1263
|
+
// the first time user focuses on an input with prefix
|
1264
|
+
fixPrefixCursor: function (el, prefix, delimiter, delimiters) {
|
1265
|
+
if (!el) {
|
1266
|
+
return;
|
1267
|
+
}
|
1268
|
+
|
1269
|
+
var val = el.value,
|
1270
|
+
appendix = delimiter || (delimiters[0] || ' ');
|
1271
|
+
|
1272
|
+
if (!el.setSelectionRange || !prefix || (prefix.length + appendix.length) < val.length) {
|
1273
|
+
return;
|
1274
|
+
}
|
1275
|
+
|
1276
|
+
var len = val.length * 2;
|
1277
|
+
|
1278
|
+
// set timeout to avoid blink
|
1279
|
+
setTimeout(function () {
|
1280
|
+
el.setSelectionRange(len, len);
|
1281
|
+
}, 1);
|
1282
|
+
},
|
1283
|
+
|
1284
|
+
setSelection: function (element, position, doc) {
|
1285
|
+
if (element !== this.getActiveElement(doc)) {
|
1286
|
+
return;
|
1287
|
+
}
|
1288
|
+
|
1289
|
+
// cursor is already in the end
|
1290
|
+
if (element && element.value.length <= position) {
|
1291
|
+
return;
|
1292
|
+
}
|
1293
|
+
|
1294
|
+
if (element.createTextRange) {
|
1295
|
+
var range = element.createTextRange();
|
1296
|
+
|
1297
|
+
range.move('character', position);
|
1298
|
+
range.select();
|
1299
|
+
} else {
|
1300
|
+
try {
|
1301
|
+
element.setSelectionRange(position, position);
|
1302
|
+
} catch (e) {
|
1303
|
+
// eslint-disable-next-line
|
1304
|
+
console.warn('The input element type does not support selection');
|
1305
|
+
}
|
1306
|
+
}
|
1307
|
+
},
|
1308
|
+
|
1309
|
+
getActiveElement: function(parent) {
|
1310
|
+
var activeElement = parent.activeElement;
|
1311
|
+
if (activeElement && activeElement.shadowRoot) {
|
1312
|
+
return this.getActiveElement(activeElement.shadowRoot);
|
1313
|
+
}
|
1314
|
+
return activeElement;
|
1315
|
+
},
|
1316
|
+
|
1317
|
+
isAndroid: function () {
|
1318
|
+
return navigator && /android/i.test(navigator.userAgent);
|
1319
|
+
},
|
1320
|
+
|
1321
|
+
// On Android chrome, the keyup and keydown events
|
1322
|
+
// always return key code 229 as a composition that
|
1323
|
+
// buffers the user’s keystrokes
|
1324
|
+
// see https://github.com/nosir/cleave.js/issues/147
|
1325
|
+
isAndroidBackspaceKeydown: function (lastInputValue, currentInputValue) {
|
1326
|
+
if (!this.isAndroid() || !lastInputValue || !currentInputValue) {
|
1327
|
+
return false;
|
1328
|
+
}
|
1329
|
+
|
1330
|
+
return currentInputValue === lastInputValue.slice(0, -1);
|
1331
|
+
}
|
1332
|
+
};
|
1333
|
+
|
1334
|
+
module.exports = Util;
|
1335
|
+
|
1336
|
+
|
1337
|
+
/***/ }),
|
1338
|
+
/* 7 */
|
1339
|
+
/***/ (function(module, exports) {
|
1340
|
+
|
1341
|
+
/* WEBPACK VAR INJECTION */(function(global) {'use strict';
|
1342
|
+
|
1343
|
+
/**
|
1344
|
+
* Props Assignment
|
1345
|
+
*
|
1346
|
+
* Separate this, so react module can share the usage
|
1347
|
+
*/
|
1348
|
+
var DefaultProperties = {
|
1349
|
+
// Maybe change to object-assign
|
1350
|
+
// for now just keep it as simple
|
1351
|
+
assign: function (target, opts) {
|
1352
|
+
target = target || {};
|
1353
|
+
opts = opts || {};
|
1354
|
+
|
1355
|
+
// credit card
|
1356
|
+
target.creditCard = !!opts.creditCard;
|
1357
|
+
target.creditCardStrictMode = !!opts.creditCardStrictMode;
|
1358
|
+
target.creditCardType = '';
|
1359
|
+
target.onCreditCardTypeChanged = opts.onCreditCardTypeChanged || (function () {});
|
1360
|
+
|
1361
|
+
// phone
|
1362
|
+
target.phone = !!opts.phone;
|
1363
|
+
target.phoneRegionCode = opts.phoneRegionCode || 'AU';
|
1364
|
+
target.phoneFormatter = {};
|
1365
|
+
|
1366
|
+
// time
|
1367
|
+
target.time = !!opts.time;
|
1368
|
+
target.timePattern = opts.timePattern || ['h', 'm', 's'];
|
1369
|
+
target.timeFormatter = {};
|
1370
|
+
|
1371
|
+
// date
|
1372
|
+
target.date = !!opts.date;
|
1373
|
+
target.datePattern = opts.datePattern || ['d', 'm', 'Y'];
|
1374
|
+
target.dateFormatter = {};
|
1375
|
+
|
1376
|
+
// numeral
|
1377
|
+
target.numeral = !!opts.numeral;
|
1378
|
+
target.numeralIntegerScale = opts.numeralIntegerScale > 0 ? opts.numeralIntegerScale : 0;
|
1379
|
+
target.numeralDecimalScale = opts.numeralDecimalScale >= 0 ? opts.numeralDecimalScale : 2;
|
1380
|
+
target.numeralDecimalMark = opts.numeralDecimalMark || '.';
|
1381
|
+
target.numeralThousandsGroupStyle = opts.numeralThousandsGroupStyle || 'thousand';
|
1382
|
+
target.numeralPositiveOnly = !!opts.numeralPositiveOnly;
|
1383
|
+
target.stripLeadingZeroes = opts.stripLeadingZeroes !== false;
|
1384
|
+
|
1385
|
+
// others
|
1386
|
+
target.numericOnly = target.creditCard || target.date || !!opts.numericOnly;
|
1387
|
+
|
1388
|
+
target.uppercase = !!opts.uppercase;
|
1389
|
+
target.lowercase = !!opts.lowercase;
|
1390
|
+
|
1391
|
+
target.prefix = (target.creditCard || target.date) ? '' : (opts.prefix || '');
|
1392
|
+
target.noImmediatePrefix = !!opts.noImmediatePrefix;
|
1393
|
+
target.prefixLength = target.prefix.length;
|
1394
|
+
target.rawValueTrimPrefix = !!opts.rawValueTrimPrefix;
|
1395
|
+
target.copyDelimiter = !!opts.copyDelimiter;
|
1396
|
+
|
1397
|
+
target.initValue = (opts.initValue !== undefined && opts.initValue !== null) ? opts.initValue.toString() : '';
|
1398
|
+
|
1399
|
+
target.delimiter =
|
1400
|
+
(opts.delimiter || opts.delimiter === '') ? opts.delimiter :
|
1401
|
+
(opts.date ? '/' :
|
1402
|
+
(opts.time ? ':' :
|
1403
|
+
(opts.numeral ? ',' :
|
1404
|
+
(opts.phone ? ' ' :
|
1405
|
+
' '))));
|
1406
|
+
target.delimiterLength = target.delimiter.length;
|
1407
|
+
target.delimiterLazyShow = !!opts.delimiterLazyShow;
|
1408
|
+
target.delimiters = opts.delimiters || [];
|
1409
|
+
|
1410
|
+
target.blocks = opts.blocks || [];
|
1411
|
+
target.blocksLength = target.blocks.length;
|
1412
|
+
|
1413
|
+
target.root = (typeof global === 'object' && global) ? global : window;
|
1414
|
+
target.document = opts.document || target.root.document;
|
1415
|
+
|
1416
|
+
target.maxLength = 0;
|
1417
|
+
|
1418
|
+
target.backspace = false;
|
1419
|
+
target.result = '';
|
1420
|
+
|
1421
|
+
target.onValueChanged = opts.onValueChanged || (function () {});
|
1422
|
+
|
1423
|
+
return target;
|
1424
|
+
}
|
1425
|
+
};
|
1426
|
+
|
1427
|
+
module.exports = DefaultProperties;
|
1428
|
+
|
1429
|
+
/* WEBPACK VAR INJECTION */}.call(exports, (function() { return this; }())))
|
1430
|
+
|
1431
|
+
/***/ })
|
1432
|
+
/******/ ])
|
1433
|
+
});
|
1434
|
+
;
|