JSFiddle - React, Tailwind, and code Playground
JavaScript
/*
created by Grimbode
- jquery required for it to work correctly
*/
(function () {
var kid = function () {
if (!(this instanceof kid)) {
return new kid();
}
//set attributes with this
this.participants = this.expenses = {};
},
//The id is also the key to participants list.
participant = function (o) {
if (!(this instanceof participant)) {
return new participant(o);
}
if (typeof o === 'undefined') {
o = {};
}
//set attributes with this
this.id = o.id || '-1';
this.nom = o.nom || 'unknown';
this.prenom = o.prenom || 'unknown';
this.email = o.email || 'unknown';
this.nbParts = o.nbParts || -1;
//list of html element id's -- should think of add events on them.
this.targets = [];
this.classNames = [
'.id',
'.nom',
'.prenom',
'.email',
'.nbParts'];
},
expense = function (o) {
if (!(this instanceof expense)) {
return new expense(o);
}
//set attributes with this
};
//using fn instead of prototype
kid.prototype = kid.fn = {
init: function () {}
}
participant.prototype = participant.fn = {
init: function () {}
}
expense.prototype = expense.fn = {
init: function () {}
};
//kid -- functions
kid.fn.addParticipant = function (participant) {
this.participants[participant.id] = participant;
return this;
};
kid.fn.addExpense = function (o) {
this.expenses[o.id] = expense(o);
return this;
};
//Function that attemps to find all existing participants/expenses on the page
//And will add them to the participants list
//NOTE ONLY CALL THIS WHEN THE PAGE LOADS OR PROBLEMS WILL OCCUR FOR SURE
kid.fn.load = function (type, callback) {
if...