Because Chrome DevTools snippets don't get saved...boo
also, for good reference: http://anti-code.com/devtools-cheatsheet/
Because Chrome DevTools snippets don't get saved...boo
also, for good reference: http://anti-code.com/devtools-cheatsheet/
(function($) { | |
// what gets faked | |
var fields = { | |
names: [ | |
'billing.firstName', | |
'billing.lastName', | |
'billing.companyName' | |
], | |
emails: [ | |
'billing.email' | |
], | |
phones: [ | |
'billing.phone' | |
], | |
addresses: [ | |
{ | |
streetAddress: 'billing.address1', | |
secondaryAddress: 'billing.address2', | |
city: 'billing.city', | |
state: 'billing.state', | |
//country: 'billing.country', | |
zipCode: 'billing.zipCode' | |
} | |
] | |
}; | |
// how it gets selected | |
var grab = function(iden) { | |
return $('[data-ng-model="' + iden + '"]'); | |
} | |
// how it gets updated | |
var set = function(iden, valfn) { | |
grab(iden).each(function(i, o) { | |
var val = valfn(); | |
console.log('setting ', i, iden, 'ex:' + val); | |
$(o).val(val); | |
}); | |
} | |
var setop = function(valfn) { | |
return function(i,field) { | |
set(field, valfn); | |
} | |
} | |
// loop 'em | |
function execute(script, textStatus) { | |
console.log("Executing form faker", textStatus, script); | |
$.each(fields.names, setop(faker.name.firstName)); | |
$.each(fields.emails, setop(faker.internet.email)); | |
$.each(fields.phones, setop(faker.phone.phoneNumberFormat)); | |
$.each(fields.addresses, function(i, addr) { | |
$.each(addr, function(type, field) { | |
setop(faker.address[type])(0, field); | |
}); | |
}); | |
} | |
// load faker and run | |
// $.getScript('//cdnjs.cloudflare.com/ajax/libs/faker/0.7.2/Minfaker.js'); | |
if(!window.faker) $.getScript('http://marak.com/faker.js/js/faker.js').done(execute); | |
else execute(); | |
})(jQuery); |