|
@@ -34,7 +34,7 @@ function Formatter(el, opts) { |
|
|
|
|
|
// Make sure we have an element. Make accesible to instance
|
|
|
self.el = el;
|
|
|
- if (!self.el) {
|
|
|
+ if (!self.el) {
|
|
|
throw new TypeError('Must provide an existing element');
|
|
|
}
|
|
|
|
|
@@ -90,8 +90,8 @@ function Formatter(el, opts) { |
|
|
// @public
|
|
|
// Add new char
|
|
|
//
|
|
|
-Formatter.addInptType = function (char, reg) {
|
|
|
- inptRegs[char] = reg;
|
|
|
+Formatter.addInptType = function (chr, reg) {
|
|
|
+ inptRegs[chr] = reg;
|
|
|
};
|
|
|
|
|
|
//
|
|
@@ -102,7 +102,7 @@ Formatter.addInptType = function (char, reg) { |
|
|
Formatter.prototype.resetPattern = function (str) {
|
|
|
// Update opts to hold new pattern
|
|
|
this.opts.pattern = str;
|
|
|
-
|
|
|
+
|
|
|
// Get current state
|
|
|
this.sel = inptSel.get(this.el);
|
|
|
this.val = this.el.value;
|
|
@@ -177,14 +177,14 @@ Formatter.prototype._paste = function (evt) { |
|
|
// @private
|
|
|
// Handle called on focus event.
|
|
|
//
|
|
|
-Formatter.prototype._focus = function (evt) {
|
|
|
+Formatter.prototype._focus = function () {
|
|
|
// Wrapped in timeout so that we can grab input selection
|
|
|
var self = this;
|
|
|
setTimeout(function () {
|
|
|
// Grab selection
|
|
|
var selection = inptSel.get(self.el);
|
|
|
// Char check
|
|
|
- var isAfterStart = selection.end > self.focus;
|
|
|
+ var isAfterStart = selection.end > self.focus,
|
|
|
isFirstChar = selection.end === 0;
|
|
|
// If clicked in front of start, refocus to start
|
|
|
if (isAfterStart || isFirstChar) {
|
|
@@ -281,7 +281,7 @@ Formatter.prototype._formatValue = function () { |
|
|
// Add formatted characters
|
|
|
this._addChars();
|
|
|
|
|
|
- // Set vakye and adhere to maxLength
|
|
|
+ // Set vakye and adhere to maxLength
|
|
|
this.el.value = this.val.substr(0, this.mLength);
|
|
|
|
|
|
// Set new caret position
|
|
@@ -357,7 +357,7 @@ Formatter.prototype._validateInpts = function () { |
|
|
// Loop over val and add formatted chars as necessary
|
|
|
//
|
|
|
Formatter.prototype._addChars = function () {
|
|
|
- if (this.opts.persistent) {
|
|
|
+ if (this.opts.persistent) {
|
|
|
// Loop over all possible characters
|
|
|
for (var i = 0; i <= this.mLength; i++) {
|
|
|
if (!this.val.charAt(i)) {
|
|
@@ -389,8 +389,8 @@ Formatter.prototype._addChars = function () { |
|
|
//
|
|
|
Formatter.prototype._addChar = function (i) {
|
|
|
// If char exists at position
|
|
|
- var char = this.chars[i];
|
|
|
- if (!char) { return true; }
|
|
|
+ var chr = this.chars[i];
|
|
|
+ if (!chr) { return true; }
|
|
|
|
|
|
// If chars are added in between the old pos and new pos
|
|
|
// we need to increment pos and delta
|
|
@@ -411,7 +411,7 @@ Formatter.prototype._addChar = function (i) { |
|
|
}
|
|
|
|
|
|
// Update value
|
|
|
- this.val = utils.addChars(this.val, char, i);
|
|
|
+ this.val = utils.addChars(this.val, chr, i);
|
|
|
};
|
|
|
|
|
|
// Define module
|
|
@@ -644,7 +644,7 @@ utils.isSpecialKey = function (k) { |
|
|
utils.isModifier = function (evt) {
|
|
|
return evt.ctrlKey || evt.altKey || evt.metaKey;
|
|
|
};
|
|
|
-// A really lightweight plugin wrapper around the constructor,
|
|
|
+// A really lightweight plugin wrapper around the constructor,
|
|
|
// preventing against multiple instantiations
|
|
|
var pluginName = 'formatter';
|
|
|
|
|
@@ -654,7 +654,7 @@ $.fn[pluginName] = function (options) { |
|
|
if (typeof options == 'object') {
|
|
|
this.each(function () {
|
|
|
if (!$.data(this, 'plugin_' + pluginName)) {
|
|
|
- $.data(this, 'plugin_' + pluginName,
|
|
|
+ $.data(this, 'plugin_' + pluginName,
|
|
|
new Formatter(this, options));
|
|
|
}
|
|
|
});
|
|
@@ -668,16 +668,15 @@ $.fn[pluginName] = function (options) { |
|
|
if (formatted) { formatted.resetPattern(str); }
|
|
|
});
|
|
|
// Chainable please
|
|
|
- return this
|
|
|
+ return this;
|
|
|
};
|
|
|
|
|
|
// Chainable please
|
|
|
return this;
|
|
|
};
|
|
|
|
|
|
-$.fn[pluginName].addInptType = function (char, regexp) {
|
|
|
- Formatter.addInptType(char, regexp);
|
|
|
+$.fn[pluginName].addInptType = function (chr, regexp) {
|
|
|
+ Formatter.addInptType(chr, regexp);
|
|
|
};
|
|
|
|
|
|
-
|
|
|
})( jQuery, window, document);
|
0 comments on commit
470d7bb