Skip to content

Commit

Permalink
added some data, and the ability to make a function a value
Browse files Browse the repository at this point in the history
  • Loading branch information
Ehren Murdick committed Sep 28, 2009
1 parent 0dbee3e commit 84d9020
Showing 1 changed file with 35 additions and 2 deletions.
37 changes: 35 additions & 2 deletions src/populate.jquery.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,12 @@
var Populate = {
getValue: function(kind) {
return {firstName: 'Ehren',
lastName: 'Murdick'}[kind];
if (Populate.Data[kind]) {
if (typeof(Populate.Data[kind]) == 'function') {
return Populate.Data[kind]();
} else {
return Populate.Data[kind].random();
}
}
},

getName: function(element) {
Expand All @@ -15,6 +20,20 @@ var Populate = {
}
};

Populate.Data = {
firstName: ['Aaron', 'Bob', 'Steve', 'Hugh', 'Jon', 'Jessica', 'Thais', 'Amadeus', 'Wolfgang', 'Alabaster'],
lastName: ['Hancock', 'Jass', 'Mozart'],
domain: ['google.com', 'yahoo.com', 'msn.com'],
username: function() {
return Populate.getValue('firstName') +
Math.randInt(1000);
},
email: function() {
return Populate.getValue('username') + '@' + Populate.getValue('domain');
},
password: ['password']
}

$.fn.pop = function(kind) {
return $(this).each(function() {
if (kind == undefined) {
Expand Down Expand Up @@ -42,3 +61,17 @@ String.prototype.camelize = function() {

return camelized;
}



Array.prototype.random = function() {
return this[Math.randInt(this.length)];
}


Math.randInt = function(size){
var rNum = Math.floor(Math.random()*size);

return rNum;
}

0 comments on commit 84d9020

Please sign in to comment.