Skip to content
Browse files

Change string[] access to string.charAt() access

Resolves IE <= 7 issues where string character access through array
notation is invalid
  • Loading branch information...
1 parent 047e560 commit 584c69cc019dcf6ba4311d54022276312037cd31 hpshelton committed
Showing with 5 additions and 9 deletions.
  1. +4 −4 src/jquery.mailcheck.js
  2. +1 −5 src/jquery.mailcheck.min.js
View
8 src/jquery.mailcheck.js
@@ -128,17 +128,17 @@ var Kicksend = {
var maxOffset = 5;
while ((c + offset1 < s1.length) && (c + offset2 < s2.length)) {
- if (s1[c + offset1] == s2[c + offset2]) {
+ if (s1.charAt(c + offset1) == s2.charAt(c + offset2)) {
lcs++;
} else {
offset1 = 0;
offset2 = 0;
for (var i = 0; i < maxOffset; i++) {
- if ((c + i < s1.length) && (s1[c + i] == s2[c])) {
+ if ((c + i < s1.length) && (s1.charAt(c + i) == s2.charAt(c))) {
offset1 = i;
break;
}
- if ((c + i < s2.length) && (s1[c] == s2[c + i])) {
+ if ((c + i < s2.length) && (s1.charAt(c) == s2.charAt(c + i))) {
offset2 = i;
break;
}
@@ -174,7 +174,7 @@ var Kicksend = {
// Determine substring distances
for (var j = 1; j <= n; j++) {
for (var i = 1; i <= m; i++) {
- if (s[i-1] == t[j-1]) { // Subtract one to start at strings' index zero instead of index one
+ if (s.charAt(i-1) == t.charAt(j-1)) { // Subtract one to start at strings' index zero instead of index one
d[i][j] = d[i-1][j-1];
} else {
d[i][j] = Math.min(d[i-1][j] + 1, // deletion
View
6 src/jquery.mailcheck.min.js
@@ -1,5 +1 @@
-/* v1.1.1 */(function(b){b.fn.mailcheck=function(a,b){var f="yahoo.com,google.com,hotmail.com,gmail.com,me.com,aol.com,mac.com,live.com,comcast.net,googlemail.com,msn.com,hotmail.co.uk,yahoo.co.uk,facebook.com,verizon.net,sbcglobal.net,att.net,gmx.com,mail.com".split(","),d="co.uk,com,net,org,info,edu,gov,mil".split(",");if("object"===typeof a&&void 0===b)a.domains=a.domains||f;else{var g=a,a=b;a.domains=g||f}a.topLevelDomains=a.topLevelDomains||d;a.distanceFunction=Kicksend.sift3Distance;(f=Kicksend.mailcheck.suggest(encodeURI(this.val()),
-a.domains,a.topLevelDomains,a.distanceFunction))?a.suggested&&a.suggested(this,f):a.empty&&a.empty(this)}})(jQuery); var Kicksend={mailcheck:{threshold:3,suggest:function(b,a,c,f){b=b.toLowerCase();b=this.splitEmail(b);if(a=this.findClosestDomain(b.domain,a,f)){if(a!=b.domain)return{address:b.address,domain:a,full:b.address+"@"+a}}else if(c=this.findClosestDomain(b.topLevelDomain,c),b.domain&&c&&c!=b.topLevelDomain)return a=b.domain,a=a.substring(0,a.lastIndexOf(b.topLevelDomain))+c,{address:b.address,domain:a,full:b.address+"@"+a};return!1},findClosestDomain:function(b,a,c){var f,d=99,g=null;if(!b||!a)return!1;
-c||(c=this.sift3Distance);for(var e=0;e<a.length;e++){if(b===a[e])return b;f=c(b,a[e]);f<d&&(d=f,g=a[e])}return d<=this.threshold&&null!==g?g:!1},sift3Distance:function(b,a){if(null==b||0===b.length)return null==a||0===a.length?0:a.length;if(null==a||0===a.length)return b.length;for(var c=0,f=0,d=0,g=0;c+f<b.length&&c+d<a.length;){if(b[c+f]==a[c+d])g++;else for(var e=d=f=0;5>e;e++){if(c+e<b.length&&b[c+e]==a[c]){f=e;break}if(c+e<a.length&&b[c]==a[c+e]){d=e;break}}c++}return(b.length+a.length)/2-g},
-levenshteinDistance:function(b,a){if(!b||!a)return 99;for(var c=b.length,f=a.length,d=[],g=0;g<=c;g++)d[g]=[],d[g][0]=g;for(var e=0;e<=f;e++)d[0][e]=e;for(e=1;e<=f;e++)for(g=1;g<=c;g++)d[g][e]=b[g-1]==a[e-1]?d[g-1][e-1]:Math.min(d[g-1][e]+1,Math.min(d[g][e-1]+1,d[g-1][e-1]+1));return d[c][f]},splitEmail:function(b){b=b.split("@");if(2>b.length)return!1;for(var a=0;a<b.length;a++)if(""===b[a])return!1;var c=b.pop(),f=c.split("."),d="";if(0==f.length)return!1;if(1==f.length)d=f[0];else{for(a=1;a<f.length;a++)d+=
-f[a]+".";2<=f.length&&(d=d.substring(0,d.length-1))}return{topLevelDomain:d,domain:c,address:b.join("@")}}}};
+/* v1.1.1 */(function(b){b.fn.mailcheck=function(a,b){var f="yahoo.com,google.com,hotmail.com,gmail.com,me.com,aol.com,mac.com,live.com,comcast.net,googlemail.com,msn.com,hotmail.co.uk,yahoo.co.uk,facebook.com,verizon.net,sbcglobal.net,att.net,gmx.com,mail.com".split(","),d="co.uk,com,net,org,info,edu,gov,mil".split(",");if("object"===typeof a&&void 0===b)a.domains=a.domains||f;else{var g=a,a=b;a.domains=g||f}a.topLevelDomains=a.topLevelDomains||d;a.distanceFunction=Kicksend.sift3Distance;(f=Kicksend.mailcheck.suggest(encodeURI(this.val()),a.domains,a.topLevelDomains,a.distanceFunction))?a.suggested&&a.suggested(this,f):a.empty&&a.empty(this)}})(jQuery);var Kicksend={mailcheck:{threshold:3,suggest:function(b,a,c,f){b=b.toLowerCase();b=this.splitEmail(b);if(a=this.findClosestDomain(b.domain,a,f)){if(a!=b.domain)return{address:b.address,domain:a,full:b.address+"@"+a}}else if(c=this.findClosestDomain(b.topLevelDomain,c),b.domain&&c&&c!=b.topLevelDomain)return a=b.domain,a=a.substring(0,a.lastIndexOf(b.topLevelDomain))+c,{address:b.address,domain:a,full:b.address+"@"+a};return!1},findClosestDomain:function(b,a,c){var f,d=99,g=null;if(!b||!a)return!1;c||(c=this.sift3Distance);for(var e=0;e<a.length;e++){if(b===a[e])return b;f=c(b,a[e]);f<d&&(d=f,g=a[e])}return d<=this.threshold&&null!==g?g:!1},sift3Distance:function(b,a){if(null==b||0===b.length)return null==a||0===a.length?0:a.length;if(null==a||0===a.length)return b.length;for(var c=0,f=0,d=0,g=0;c+f<b.length&&c+d<a.length;){if(b.charAt(c+f)==a.charAt(c+d))g++;else for(var e=d=f=0;5>e;e++){if(c+e<b.length&&b.charAt(c+e)==a.charAt(c)){f=e;break}if(c+e<a.length&&b.charAt(c)==a.charAt(c+e)){d=e;break}}c++}return(b.length+a.length)/2-g},levenshteinDistance:function(b,a){if(!b||!a)return 99;for(var c=b.length,f=a.length,d=[],g=0;g<=c;g++)d[g]=[],d[g][0]=g;for(var e=0;e<=f;e++)d[0][e]=e;for(e=1;e<=f;e++)for(g=1;g<=c;g++)d[g][e]=b.charAt(g-1)==a.charAt(e-1)?d[g-1][e-1]:Math.min(d[g-1][e]+1,Math.min(d[g][e-1]+1,d[g-1][e-1]+1));return d[c][f]},splitEmail:function(b){b=b.split("@");if(2>b.length)return!1;for(var a=0;a<b.length;a++)if(""===b[a])return!1;var c=b.pop(),f=c.split("."),d="";if(0==f.length)return!1;if(1==f.length)d=f[0];else{for(a=1;a<f.length;a++)d+=f[a]+".";2<=f.length&&(d=d.substring(0,d.length-1))}return{topLevelDomain:d,domain:c,address:b.join("@")}}}};

0 comments on commit 584c69c

Please sign in to comment.
Something went wrong with that request. Please try again.