forked from laurihy/angular-payments
-
Notifications
You must be signed in to change notification settings - Fork 0
Hotfix/firefox cvc #1
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -161,35 +161,35 @@ angular.module('angularPayments', []);angular.module('angularPayments') | |
|
|
||
| var _hasTextSelected = function($target) { | ||
| var ref; | ||
|
|
||
| if (($target.prop('selectionStart') != null) && $target.prop('selectionStart') !== $target.prop('selectionEnd')) { | ||
| return true; | ||
| } | ||
|
|
||
| if (typeof document !== "undefined" && document !== null ? (ref = document.selection) != null ? typeof ref.createRange === "function" ? ref.createRange().text : void 0 : void 0 : void 0) { | ||
| return true; | ||
| } | ||
|
|
||
| return false; | ||
| }; | ||
|
|
||
| // card formatting | ||
|
|
||
| var _formatCardNumber = function(e) { | ||
| var $target, card, digit, length, re, upperLength, value; | ||
|
|
||
| digit = String.fromCharCode(e.which); | ||
| $target = angular.element(e.currentTarget); | ||
| value = $target.val(); | ||
| card = Cards.fromNumber(value + digit); | ||
| length = (value.replace(/\D/g, '') + digit).length; | ||
|
|
||
| upperLength = 16; | ||
|
|
||
| if (card) { | ||
| upperLength = card.length[card.length.length - 1]; | ||
| } | ||
|
|
||
| if (length >= upperLength) { | ||
| return; | ||
| } | ||
|
|
@@ -221,21 +221,21 @@ angular.module('angularPayments', []);angular.module('angularPayments') | |
|
|
||
| var _restrictCardNumber = function(e) { | ||
| var $target, card, digit, value; | ||
|
|
||
| $target = angular.element(e.currentTarget); | ||
| digit = String.fromCharCode(e.which); | ||
|
|
||
| if(!/^\d+$/.test(digit)) { | ||
| return; | ||
| } | ||
|
|
||
| if(_hasTextSelected($target)) { | ||
| return; | ||
| } | ||
|
|
||
| value = ($target.val() + digit).replace(/\D/g, ''); | ||
| card = Cards.fromNumber(value); | ||
|
|
||
| if(card) { | ||
| if(!(value.length <= card.length[card.length.length - 1])){ | ||
| e.preventDefault(); | ||
|
|
@@ -249,22 +249,22 @@ angular.module('angularPayments', []);angular.module('angularPayments') | |
|
|
||
| var _formatBackCardNumber = function(e) { | ||
| var $target, value; | ||
|
|
||
| $target = angular.element(e.currentTarget); | ||
| value = $target.val(); | ||
|
|
||
| if(e.meta) { | ||
| return; | ||
| } | ||
|
|
||
| if(e.which !== 8) { | ||
| return; | ||
| } | ||
|
|
||
| if(($target.prop('selectionStart') != null) && $target.prop('selectionStart') !== value.length) { | ||
| return; | ||
| } | ||
|
|
||
| if(/\d\s$/.test(value) && !e.meta && e.keyCode >= 46) { | ||
| e.preventDefault(); | ||
| return $target.val(value.replace(/\d\s$/, '')); | ||
|
|
@@ -276,22 +276,22 @@ angular.module('angularPayments', []);angular.module('angularPayments') | |
|
|
||
| var _getFormattedCardNumber = function(num) { | ||
| var card, groups, upperLength, ref; | ||
|
|
||
| card = Cards.fromNumber(num); | ||
|
|
||
| if (!card) { | ||
| return num; | ||
| } | ||
|
|
||
| upperLength = card.length[card.length.length - 1]; | ||
| num = num.replace(/\D/g, ''); | ||
| num = num.slice(0, +upperLength + 1 || 9e9); | ||
|
|
||
| if(card.format.global) { | ||
| return (ref = num.match(card.format)) != null ? ref.join(' ') : void 0; | ||
| } else { | ||
| groups = card.format.exec(num); | ||
|
|
||
| if (groups != null) { | ||
| groups.shift(); | ||
| } | ||
|
|
@@ -304,7 +304,7 @@ angular.module('angularPayments', []);angular.module('angularPayments') | |
| return setTimeout(function() { | ||
| var $target, value; | ||
| $target = angular.element(e.target); | ||
|
|
||
| value = $target.val(); | ||
| value = _getFormattedCardNumber(value); | ||
| return $target.val(value); | ||
|
|
@@ -331,14 +331,19 @@ angular.module('angularPayments', []);angular.module('angularPayments') | |
| _formatCVC = function(e){ | ||
| $target = angular.element(e.currentTarget); | ||
| digit = String.fromCharCode(e.which); | ||
|
|
||
| if (!/^\d+$/.test(digit) && !e.meta && e.keyCode >= 46) { | ||
|
|
||
| // Allows backspace, delete and arrow keys when input length is 4 and the browser is Firefox | ||
| if (e.keyCode == 46 || e.keyCode == 8||(e.keyCode >=37 && e.keyCode <=40)) { | ||
| return; | ||
| } | ||
|
|
||
| if (!/^\d+$/.test(digit) && !e.meta && e.which >= 46) { | ||
| e.preventDefault(); | ||
| return; | ||
| } | ||
|
|
||
| val = $target.val() + digit; | ||
|
|
||
| if(val.length <= 4){ | ||
| return; | ||
| } else { | ||
|
|
@@ -355,22 +360,22 @@ angular.module('angularPayments', []);angular.module('angularPayments') | |
|
|
||
| _restrictExpiry = function(e) { | ||
| var $target, digit, value; | ||
|
|
||
| $target = angular.element(e.currentTarget); | ||
| digit = String.fromCharCode(e.which); | ||
|
|
||
| if (!/^\d+$/.test(digit) && !e.meta && e.keyCode >= 46) { | ||
| e.preventDefault(); | ||
| return; | ||
| } | ||
|
|
||
| if(_hasTextSelected($target)) { | ||
| return; | ||
| } | ||
|
|
||
| value = $target.val() + digit; | ||
| value = value.replace(/\D/g, ''); | ||
|
|
||
| if (value.length > 6) { | ||
| e.preventDefault() | ||
| return; | ||
|
|
@@ -379,17 +384,17 @@ angular.module('angularPayments', []);angular.module('angularPayments') | |
|
|
||
| _formatExpiry = function(e) { | ||
| var $target, digit, val; | ||
|
|
||
| digit = String.fromCharCode(e.which); | ||
|
|
||
| if (!/^\d+$/.test(digit) && !e.meta && e.keyCode >= 46) { | ||
| e.preventDefault(); | ||
| return; | ||
| } | ||
|
|
||
| $target = angular.element(e.currentTarget); | ||
| val = $target.val() + digit; | ||
|
|
||
| if (/^\d$/.test(val) && (val !== '0' && val !== '1')) { | ||
| e.preventDefault(); | ||
| return $target.val("0" + val + " / "); | ||
|
|
@@ -403,56 +408,56 @@ angular.module('angularPayments', []);angular.module('angularPayments') | |
|
|
||
| _formatForwardExpiry = function(e) { | ||
| var $target, digit, val; | ||
|
|
||
| digit = String.fromCharCode(e.which); | ||
|
|
||
| if (!/^\d+$/.test(digit) && !e.meta && e.keyCode >= 46) { | ||
| return; | ||
| } | ||
|
|
||
| $target = angular.element(e.currentTarget); | ||
| val = $target.val(); | ||
|
|
||
| if (/^\d\d$/.test(val)) { | ||
| return $target.val("" + val + " / "); | ||
| } | ||
| }; | ||
|
|
||
| _formatForwardSlash = function(e) { | ||
| var $target, slash, val; | ||
|
|
||
| slash = String.fromCharCode(e.which); | ||
|
|
||
| if (slash !== '/') { | ||
| return; | ||
| } | ||
|
|
||
| $target = angular.element(e.currentTarget); | ||
| val = $target.val(); | ||
|
|
||
| if (/^\d$/.test(val) && val !== '0') { | ||
| return $target.val("0" + val + " / "); | ||
| } | ||
| }; | ||
|
|
||
| _formatBackExpiry = function(e) { | ||
| var $target, value; | ||
|
|
||
| if (e.meta) { | ||
| return; | ||
| } | ||
|
|
||
| $target = angular.element(e.currentTarget); | ||
| value = $target.val(); | ||
|
|
||
| if (e.which !== 8) { | ||
| return; | ||
| } | ||
|
|
||
| if (($target.prop('selectionStart') != null) && $target.prop('selectionStart') !== value.length) { | ||
| return; | ||
| } | ||
|
|
||
| if (/\d(\s|\/)+$/.test(value)) { | ||
| e.preventDefault(); | ||
| return $target.val(value.replace(/\d(\s|\/)*$/, '')); | ||
|
|
@@ -517,7 +522,8 @@ angular.module('angularPayments', []);angular.module('angularPayments') | |
| _Format(attr.paymentsFormat, elem, ctrl); | ||
| } | ||
| } | ||
| }]);angular.module('angularPayments') | ||
| }]) | ||
| ;angular.module('angularPayments') | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. ?
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. ran grunt and I guess it changed the line. Didn't directly edit anything inside the |
||
|
|
||
|
|
||
|
|
||
|
|
||
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
how do you know that it is Firefox here?
Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@raphaeldieu IE / Chrome / Safari detects the "keypress" event only when an actual character input is added. Since backspace and arrow keys don't add a new character, the function doesn't run.
For Firefox, the "keypress" event is run even on backspace / arrow keys and so with the old code when
val.lengthis more than 4, it will always fall down to theelseblock which has ae.preventDefault()preventing the user from any form of input. The new code which detects arrow / delete / backspace keys therefore can only occur on firefox