Permalink
Browse files

Merge fixes from number #32 & #33

1 parent 29833fa commit 470d7bb7ccd369a96ff0e9938292094ffe545010 @jaridmargolin jaridmargolin committed Feb 28, 2014
Showing with 63 additions and 65 deletions.
  1. +3 −2 Gruntfile.js
  2. +11 −11 lib/formatter.js
  3. +1 −1 lib/formatter.min.js
  4. +16 −17 lib/jquery.formatter.js
  5. +1 −1 lib/jquery.formatter.min.js
  6. +11 −11 src/formatter.js
  7. +5 −6 src/tmpls/jquery.outro.js
  8. +11 −12 test/fake-user/keys.js
  9. +4 −4 test/fake-user/user.js
View
@@ -18,6 +18,7 @@ module.exports = function(grunt) {
'src/tmpls/jquery.intro.js',
'src/tmpls/jquery.outro.js'
],
+ force: true,
es3: true,
smarttabs: true,
// Bad line breaking before '?'.
@@ -92,5 +93,5 @@ module.exports = function(grunt) {
grunt.loadNpmTasks('grunt-contrib-uglify');
// Tasks
- grunt.registerTask('default', ['jshint', 'concat', 'uglify']);
-};
+ grunt.registerTask('default', ['concat', 'uglify', 'jshint']);
+};
View
@@ -38,7 +38,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');
}
@@ -94,8 +94,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;
};
//
@@ -106,7 +106,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;
@@ -181,14 +181,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) {
@@ -285,7 +285,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
@@ -361,7 +361,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)) {
@@ -393,8 +393,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
@@ -415,7 +415,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
View

Some generated files are not rendered by default. Learn more.

Oops, something went wrong.
View
@@ -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);
Oops, something went wrong.

0 comments on commit 470d7bb

Please sign in to comment.