1// Generated by CoffeeScript 1.7.1 2(function() { 3 var $, cardFromNumber, cardFromType, cards, defaultFormat, formatBackCardNumber, formatBackExpiry, formatCardNumber, formatExpiry, formatForwardExpiry, formatForwardSlashAndSpace, hasTextSelected, luhnCheck, reFormatCVC, reFormatCardNumber, reFormatExpiry, reFormatNumeric, replaceFullWidthChars, restrictCVC, restrictCardNumber, restrictExpiry, restrictNumeric, safeVal, setCardType, 4 __slice = [].slice, 5 __indexOf = [].indexOf || function(item) { for (var i = 0, l = this.length; i < l; i++) { if (i in this && this[i] === item) return i; } return -1; }; 6 7 $ = window.jQuery || window.Zepto || window.$; 8 9 $.payment = {}; 10 11 $.payment.fn = {}; 12 13 $.fn.payment = function() { 14 var args, method; 15 method = arguments[0], args = 2 <= arguments.length ? __slice.call(arguments, 1) : []; 16 return $.payment.fn[method].apply(this, args); 17 }; 18 19 defaultFormat = /(\d{1,4})/g; 20 21 $.payment.cards = cards = [ 22 { 23 type: 'visaelectron', 24 patterns: [4026, 417500, 4405, 4508, 4844, 4913, 4917], 25 format: defaultFormat, 26 length: [16], 27 cvcLength: [3], 28 luhn: true 29 }, { 30 type: 'maestro', 31 patterns: [5018, 502, 503, 56, 58, 639, 6220, 67], 32 format: defaultFormat, 33 length: [12, 13, 14, 15, 16, 17, 18, 19], 34 cvcLength: [3], 35 luhn: true 36 }, { 37 type: 'forbrugsforeningen', 38 patterns: [600], 39 format: defaultFormat, 40 length: [16], 41 cvcLength: [3], 42 luhn: true 43 }, { 44 type: 'dankort', 45 patterns: [5019], 46 format: defaultFormat, 47 length: [16], 48 cvcLength: [3], 49 luhn: true 50 }, { 51 type: 'visa', 52 patterns: [4], 53 format: defaultFormat, 54 length: [13, 16], 55 cvcLength: [3], 56 luhn: true 57 }, { 58 type: 'mastercard', 59 patterns: [51, 52, 53, 54, 55, 22, 23, 24, 25, 26, 27], 60 format: defaultFormat, 61 length: [16], 62 cvcLength: [3], 63 luhn: true 64 }, { 65 type: 'amex', 66 patterns: [34, 37], 67 format: /(\d{1,4})(\d{1,6})?(\d{1,5})?/, 68 length: [15], 69 cvcLength: [3, 4], 70 luhn: true 71 }, { 72 type: 'dinersclub', 73 patterns: [30, 36, 38, 39], 74 format: /(\d{1,4})(\d{1,6})?(\d{1,4})?/, 75 length: [14], 76 cvcLength: [3], 77 luhn: true 78 }, { 79 type: 'discover', 80 patterns: [60, 64, 65, 622], 81 format: defaultFormat, 82 length: [16], 83 cvcLength: [3], 84 luhn: true 85 }, { 86 type: 'unionpay', 87 patterns: [62, 88], 88 format: defaultFormat, 89 length: [16, 17, 18, 19], 90 cvcLength: [3], 91 luhn: false 92 }, {
93 type: 'jcb', 94 patterns: [35], 95 format: defaultFormat, 96 length: [16], 97 cvcLength: [3], 98 luhn: true 99 } 100 ]; 101 102 cardFromNumber = function(num) { 103 var card, p, pattern, _i, _j, _len, _len1, _ref; 104 num = (num + '').replace(/\D/g, ''); 105 for (_i = 0, _len = cards.length; _i < _len; _i++) { 106 card = cards[_i]; 107 _ref = card.patterns; 108 for (_j = 0, _len1 = _ref.length; _j < _len1; _j++) { 109 pattern = _ref[_j]; 110 p = pattern + ''; 111 if (num.substr(0, p.length) === p) { 112 return card; 113 } 114 } 115 } 116 }; 117 118 cardFromType = function(type) { 119 var card, _i, _len; 120 for (_i = 0, _len = cards.length; _i < _len; _i++) { 121 card = cards[_i]; 122 if (card.type === type) { 123 return card; 124 } 125 } 126 }; 127 128 luhnCheck = function(num) { 129 var digit, digits, odd, sum, _i, _len; 130 odd = true; 131 sum = 0; 132 digits = (num + '').split('').reverse(); 133 for (_i = 0, _len = digits.length; _i < _len; _i++) { 134 digit = digits[_i]; 135 digit = parseInt(digit, 10); 136 if ((odd = !odd)) { 137 digit *= 2; 138 } 139 if (digit > 9) { 140 digit -= 9; 141 } 142 sum += digit; 143 } 144 return sum % 10 === 0; 145 }; 146 147 hasTextSelected = function($target) { 148 var _ref; 149 if (($target.prop('selectionStart') != null) && $target.prop('selectionStart') !== $target.prop('selectionEnd')) { 150 return true; 151 } 152 if ((typeof document !== "undefined" && document !== null ? (_ref = document.selection) != null ? _ref.createRange : void 0 : void 0) != null) { 153 if (document.selection.createRange().text) { 154 return true; 155 } 156 } 157 return false; 158 }; 159 160 safeVal = function(value, $target) { 161 var cursor, error, last; 162 try { 163 cursor = $target.prop('selectionStart'); 164 } catch (_error) { 165 error = _error; 166 cursor = null; 167 } 168 last = $target.val(); 169 $target.val(value); 170 if (cursor !== null && $target.is(":focus")) { 171 if (cursor === last.length) { 172 cursor = value.length; 173 } 174 $target.prop('selectionStart', cursor); 175 return $target.prop('selectionEnd', cursor); 176 } 177 }; 178 179 replaceFullWidthChars = function(str) { 180 var chars, chr, fullWidth, halfWidth, idx, value, _i, _len; 181 if (str == null) { 182 str = ''; 183 } 184 fullWidth = '\uff10\uff11\uff12\uff13\uff14\uff15\uff16\uff17\uff18\uff19'; 185 halfWidth = '0123456789'; 186 value = ''; 187 chars = str.split(''); 188 for (_i = 0, _len = chars.length; _i < _len; _i++) { 189 chr = chars[_i]; 190 idx = fullWidth.indexOf(chr); 191 if (idx > -1) { 192 chr = halfWidth[idx]; 193 } 194 value += chr; 195 } 196 return value; 197 }; 198 199 reFormatNumeric = function(e) { 200 var $target; 201 $target = $(e.currentTarget); 202 return setTimeout(function() { 203 var value; 204 value = $target.val(); 205 value = replaceFullWidthChars(value); 206 value = value.replace(/\D/g, ''); 207 return safeVal(value, $target); 208 }); 209 }; 210 211 reFormatCardNumber = function(e) { 212 var $target; 213 $target = $(e.currentTarget); 214 return setTimeout(function() { 215 var value; 216 value = $target.val(); 217 value = replaceFullWidthChars(value); 218 value = $.payment.formatCardNumber(value); 219 return safeVal(value, $target); 220 }); 221 }; 222 223 formatCardNumber = function(e) { 224 var $target, card, digit, length, re, upperLength, value; 225 digit = String.fromCharCode(e.which); 226 if (!/^\d+$/.test(digit)) { 227 return; 228 } 229 $target = $(e.currentTarget); 230 value = $target.val(); 231 card = cardFromNumber(value + digit); 232 length = (value.replace(/\D/g, '') + digit).length; 233 upperLength = 16; 234 if (card) { 235 upperLength = card.length[card.length.length - 1]; 236 } 237 if (length >= upperLength) { 238 return; 239 } 240 if (($target.prop('selectionStart') != null) && $target.prop('selectionStart') !== value.length) { 241 return; 242 } 243 if (card && card.type === 'amex') { 244 re = /^(\d{4}|\d{4}\s\d{6})$/; 245 } else { 246 re = /(?:^|\s)(\d{4})$/; 247 } 248 if (re.test(value)) { 249 e.preventDefault(); 250 return setTimeout(function() { 251 return $target.val(value + ' ' + digit); 252 }); 253 } else if (re.test(value + digit)) { 254 e.preventDefault(); 255 return setTimeout(function() { 256 return $target.val(value + digit + ' '); 257 }); 258 } 259 }; 260 261 formatBackCardNumber = function(e) { 262 var $target, value; 263 $target = $(e.currentTarget); 264 value = $target.val(); 265 if (e.which !== 8) { 266 return; 267 } 268 if (($target.prop('selectionStart') != null) && $target.prop('selectionStart') !== value.length) { 269 return; 270 } 271 if (/\d\s$/.test(value)) { 272 e.preventDefault(); 273 return setTimeout(function() { 274 return $target.val(value.replace(/\d\s$/, '')); 275 }); 276 } else if (/\s\d?$/.test(value)) { 277 e.preventDefault(); 278 return setTimeout(function() { 279 return $target.val(value.replace(/\d$/, '')); 280 }); 281 } 282 }; 283 284 reFormatExpiry = function(e) { 285 var $target; 286 $target = $(e.currentTarget); 287 return setTimeout(function() { 288 var value; 289 value = $target.val(); 290 value = replaceFullWidthChars(value); 291 value = $.payment.formatExpiry(value); 292 return safeVal(value, $target); 293 }); 294 }; 295 296 formatExpiry = function(e) { 297 var $target, digit, val; 298 digit = String.fromCharCode(e.which); 299 if (!/^\d+$/.test(digit)) { 300 return; 301 } 302 $target = $(e.currentTarget); 303 val = $target.val() + digit; 304 if (/^\d$/.test(val) && (val !== '0' && val !== '1')) { 305 e.preventDefault(); 306 return setTimeout(function() { 307 return $target.val("0" + val + " / "); 308 }); 309 } else if (/^\d\d$/.test(val)) { 310 e.preventDefault(); 311 return setTimeout(function() { 312 var m1, m2; 313 m1 = parseInt(val[0], 10); 314 m2 = parseInt(val[1], 10); 315 if (m2 > 2 && m1 !== 0) { 316 return $target.val("0" + m1 + " / " + m2); 317 } else { 318 return $target.val("" + val + " / "); 319 } 320 }); 321 } 322 }; 323 324 formatForwardExpiry = function(e) { 325 var $target, digit, val; 326 digit = String.fromCharCode(e.which); 327 if (!/^\d+$/.test(digit)) { 328 return; 329 } 330 $target = $(e.currentTarget); 331 val = $target.val(); 332 if (/^\d\d$/.test(val)) { 333 return $target.val("" + val + " / "); 334 } 335 }; 336 337 formatForwardSlashAndSpace = function(e) { 338 var $target, val, which; 339 which = String.fromCharCode(e.which); 340 if (!(which === '/' || which === ' ')) { 341 return; 342 } 343 $target = $(e.currentTarget); 344 val = $target.val(); 345 if (/^\d$/.test(val) && val !== '0') { 346 return $target.val("0" + val + " / "); 347 } 348 }; 349 350 formatBackExpiry = function(e) { 351 var $target, value; 352 $target = $(e.currentTarget); 353 value = $target.val(); 354 if (e.which !== 8) { 355 return; 356 } 357 if (($target.prop('selectionStart') != null) && $target.prop('selectionStart') !== value.length) { 358 return; 359 } 360 if (/\d\s\/\s$/.test(value)) { 361 e.preventDefault(); 362 return setTimeout(function() { 363 return $target.val(value.replace(/\d\s\/\s$/, '')); 364 }); 365 } 366 }; 367 368 reFormatCVC = function(e) { 369 var $target; 370 $target = $(e.currentTarget); 371 return setTimeout(function() { 372 var value; 373 value = $target.val(); 374 value = replaceFullWidthChars(value); 375 value = value.replace(/\D/g, '').slice(0, 4); 376 return safeVal(value, $target); 377 }); 378 }; 379 380 restrictNumeric = function(e) { 381 var input; 382 if (e.metaKey || e.ctrlKey) { 383 return true; 384 } 385 if (e.which === 32) { 386 return false;
387 } 388 if (e.which === 0) { 389 return true; 390 } 391 if (e.which < 33) { 392 return true; 393 } 394 input = String.fromCharCode(e.which); 395 return !!/[\d\s]/.test(input); 396 }; 397 398 restrictCardNumber = function(e) { 399 var $target, card, digit, value; 400 $target = $(e.currentTarget); 401 digit = String.fromCharCode(e.which); 402 if (!/^\d+$/.test(digit)) { 403 return; 404 } 405 if (hasTextSelected($target)) { 406 return; 407 } 408 value = ($target.val() + digit).replace(/\D/g, ''); 409 card = cardFromNumber(value); 410 if (card) { 411 return value.length <= card.length[card.length.length - 1]; 412 } else { 413 return value.length <= 16; 414 } 415 }; 416 417 restrictExpiry = function(e) { 418 var $target, digit, value; 419 $target = $(e.currentTarget); 420 digit = String.fromCharCode(e.which); 421 if (!/^\d+$/.test(digit)) { 422 return; 423 } 424 if (hasTextSelected($target)) { 425 return; 426 } 427 value = $target.val() + digit; 428 value = value.replace(/\D/g, ''); 429 if (value.length > 6) { 430 return false; 431 } 432 }; 433 434 restrictCVC = function(e) { 435 var $target, digit, val; 436 $target = $(e.currentTarget); 437 digit = String.fromCharCode(e.which); 438 if (!/^\d+$/.test(digit)) { 439 return; 440 } 441 if (hasTextSelected($target)) { 442 return; 443 } 444 val = $target.val() + digit; 445 return val.length <= 4; 446 }; 447 448 setCardType = function(e) { 449 var $target, allTypes, card, cardType, val; 450 $target = $(e.currentTarget); 451 val = $target.val(); 452 cardType = $.payment.cardType(val) || 'unknown'; 453 if (!$target.hasClass(cardType)) { 454 allTypes = (function() { 455 var _i, _len, _results; 456 _results = []; 457 for (_i = 0, _len = cards.length; _i < _len; _i++) { 458 card = cards[_i]; 459 _results.push(card.type); 460 } 461 return _results; 462 })(); 463 $target.removeClass('unknown'); 464 $target.removeClass(allTypes.join(' ')); 465 $target.addClass(cardType); 466 $target.toggleClass('identified', cardType !== 'unknown'); 467 return $target.trigger('payment.cardType', cardType); 468 } 469 }; 470 471 $.payment.fn.formatCardCVC = function() { 472 this.on('keypress', restrictNumeric); 473 this.on('keypress', restrictCVC); 474 this.on('paste', reFormatCVC); 475 this.on('change', reFormatCVC); 476 this.on('input', reFormatCVC); 477 return this; 478 }; 479 480 $.payment.fn.formatCardExpiry = function() { 481 this.on('keypress', restrictNumeric); 482 this.on('keypress', restrictExpiry); 483 this.on('keypress', formatExpiry); 484 this.on('keypress', formatForwardSlashAndSpace); 485 this.on('keypress', formatForwardExpiry); 486 this.on('keydown', formatBackExpiry); 487 this.on('change', reFormatExpiry); 488 this.on('input', reFormatExpiry); 489 return this; 490 }; 491 492 $.payment.fn.formatCardNumber = function() { 493 this.on('keypress', restrictNumeric); 494 this.on('keypress', restrictCardNumber); 495 this.on('keypress', formatCardNumber); 496 this.on('keydown', formatBackCardNumber); 497 this.on('keyup', setCardType); 498 this.on('paste', reFormatCardNumber); 499 this.on('change', reFormatCardNumber); 500 this.on('input', reFormatCardNumber); 501 this.on('input', setCardType); 502 return this; 503 }; 504 505 $.payment.fn.restrictNumeric = function() { 506 this.on('keypress', restrictNumeric); 507 this.on('paste', reFormatNumeric); 508 this.on('change', reFormatNumeric); 509 this.on('input', reFormatNumeric); 510 return this; 511 }; 512 513 $.payment.fn.cardExpiryVal = function() { 514 return $.payment.cardExpiryVal($(this).val()); 515 }; 516 517 $.payment.cardExpiryVal = function(value) { 518 var month, prefix, year, _ref; 519 _ref = value.split(/[\s\/]+/, 2), month = _ref[0], year = _ref[1]; 520 if ((year != null ? year.length : void 0) === 2 && /^\d+$/.test(year)) { 521 prefix = (new Date).getFullYear(); 522 prefix = prefix.toString().slice(0, 2); 523 year = prefix + year; 524 } 525 month = parseInt(month, 10); 526 year = parseInt(year, 10); 527 return { 528 month: month, 529 year: year 530 }; 531 }; 532 533 $.payment.validateCardNumber = function(num) { 534 var card, _ref; 535 num = (num + '').replace(/\s+|-/g, ''); 536 if (!/^\d+$/.test(num)) { 537 return false;
538 } 539 card = cardFromNumber(num); 540 if (!card) { 541 return false; 542 } 543 return (_ref = num.length, __indexOf.call(card.length, _ref) >= 0) && (card.luhn === false || luhnCheck(num)); 544 }; 545 546 $.payment.validateCardExpiry = function(month, year) { 547 var currentTime, expiry, _ref; 548 if (typeof month === 'object' && 'month' in month) { 549 _ref = month, month = _ref.month, year = _ref.year; 550 } 551 if (!(month && year)) { 552 return false; 553 } 554 month = $.trim(month); 555 year = $.trim(year); 556 if (!/^\d+$/.test(month)) { 557 return false; 558 } 559 if (!/^\d+$/.test(year)) { 560 return false; 561 } 562 if (!((1 <= month && month <= 12))) { 563 return false; 564 } 565 if (year.length === 2) { 566 if (year < 70) { 567 year = "20" + year; 568 } else { 569 year = "19" + year; 570 } 571 } 572 if (year.length !== 4) { 573 return false; 574 } 575 expiry = new Date(year, month); 576 currentTime = new Date; 577 expiry.setMonth(expiry.getMonth() - 1); 578 expiry.setMonth(expiry.getMonth() + 1, 1); 579 return expiry > currentTime; 580 }; 581 582 $.payment.validateCardCVC = function(cvc, type) { 583 var card, _ref; 584 cvc = $.trim(cvc); 585 if (!/^\d+$/.test(cvc)) { 586 return false; 587 } 588 card = cardFromType(type); 589 if (card != null) { 590 return _ref = cvc.length, __indexOf.call(card.cvcLength, _ref) >= 0; 591 } else { 592 return cvc.length >= 3 && cvc.length <= 4; 593 } 594 }; 595 596 $.payment.cardType = function(num) { 597 var _ref; 598 if (!num) { 599 return null; 600 } 601 return ((_ref = cardFromNumber(num)) != null ? _ref.type : void 0) || null; 602 }; 603 604 $.payment.formatCardNumber = function(num) { 605 var card, groups, upperLength, _ref; 606 num = num.replace(/\D/g, ''); 607 card = cardFromNumber(num); 608 if (!card) { 609 return num; 610 } 611 upperLength = card.length[card.length.length - 1]; 612 num = num.slice(0, upperLength); 613 if (card.format.global) { 614 return (_ref = num.match(card.format)) != null ? _ref.join(' ') : void 0; 615 } else { 616 groups = card.format.exec(num); 617 if (groups == null) { 618 return; 619 } 620 groups.shift(); 621 groups = $.grep(groups, function(n) { 622 return n; 623 }); 624 return groups.join(' '); 625 } 626 }; 627 628 $.payment.formatExpiry = function(expiry) { 629 var mon, parts, sep, year; 630 parts = expiry.match(/^\D*(\d{1,2})(\D+)?(\d{1,4})?/); 631 if (!parts) { 632 return ''; 633 } 634 mon = parts[1] || ''; 635 sep = parts[2] || ''; 636 year = parts[3] || ''; 637 if (year.length > 0) { 638 sep = ' / '; 639 } else if (sep === ' /') { 640 mon = mon.substring(0, 1); 641 sep = ''; 642 } else if (mon.length === 2 || sep.length > 0) { 643 sep = ' / '; 644 } else if (mon.length === 1 && (mon !== '0' && mon !== '1')) { 645 mon = "0" + mon; 646 sep = ' / '; 647 } 648 return mon + sep + year; 649 }; 650 651}).call(this);
Line numbers count LF bytes from the start of the resource, as the search results do. Vendor segments are library code the classifier recognised; they are stored but not indexed. Bytes are shown as Latin1 characters, one per byte.