-
-
Save AlexRiina/4852e1ac0979d71169b5 to your computer and use it in GitHub Desktop.
This file contains 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
// jQuery Plugin (Change Type) | |
(function ($) { | |
$.fn.cryptForm = function (key, toCryptSel) { | |
var form = $(this); | |
var braintree = Braintree.create(key); | |
form.submit(function () { | |
form.find(toCryptSel).each(function () { | |
this.type = 'password'; | |
$(this).val(braintree.encrypt($(this).val())); | |
}); | |
}); | |
}; | |
})(jQuery); | |
// jQuery Plugin (Clone Form) | |
(function ($) { | |
$.fn.cryptForm = function (key, toCryptSel) { | |
var form = $(this); | |
var braintree = Braintree.create(key); | |
form.submit(function (e) { | |
e.preventDefault(); | |
var new_form = form.clone(); | |
new_form.find(toCryptSel).each(function () { | |
$(this).val(braintree.encrypt($(this).val())); | |
}); | |
new_form.hide().appendTo('body').submit().remove(); | |
}); | |
}; | |
})(jQuery); | |
// Examples | |
//$("#f").cryptForm(clientSideEncryptionKey, '#cc, #cvv'); | |
//$("#f").cryptForm(clientSideEncryptionKey, '.crypt'); | |
//$("#f").cryptForm(clientSideEncryptionKey, '[name="cc"], [name="cvv"'); |
This file contains 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
// Pure JS (Change Type) | |
var cryptForm = function (key, formId, toCryptNames) { | |
var braintree = Braintree.create(key); | |
document.getElementById(formId).onsubmit = function () { | |
var els = this.getElementsByTagName("input"); | |
for (i in els) if (toCryptNames.indexOf(els[i].name) > -1) { | |
els[i].type = 'password'; | |
els[i].value = braintree.encrypt(els[i].value); | |
} | |
}; | |
}; | |
// Pure JS (Clone Form ) | |
var cryptForm = function (key, formId, toCryptNames) { | |
var braintree = Braintree.create(key); | |
document.getElementById(formId).onsubmit = function () { | |
var clonedForm = this.cloneNode(true); | |
var els = clonedForm.getElementsByTagName("input"); | |
for (i in els) if (toCryptNames.indexOf(els[i].name) > -1) | |
els[i].value = braintree.encrypt(els[i].value); | |
clonedForm.style.display = 'none'; | |
document.body.appendChild(clonedForm); | |
clonedForm.submit(); | |
return false; | |
}; | |
}; | |
// Examples | |
//cryptForm(clientSideEncryptionKey, 'f', ['cc', 'cvv']); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment