Skip to content

Instantly share code, notes, and snippets.

Avatar
🎯
Focusing

Alisson Carvalho alissoncs

🎯
Focusing
View GitHub Profile
View event.js
var Event = function() {
var callbacks = {};
function emit(name, params) {
if (callbacks[name]) {
callbacks[name].map(function(item) {
item(params);
});
}
}
View main.js
window.onload = function () {
Application.listAllAwards(function (awards) {
console.log(awards);
document.getElementById('awards-list').innerHTML = '';
for (var i in awards) {
var award = awards[i];
var div = document.createElement('div');
div.id = 'award-' + award.id;
var text = 'Name: ' + award.name + ', Price: $' + award.price;
div.appendChild(document.createTextNode(text));
View Application.js
var Application = {
listAllAwards: function (success, err) {
return http.Connection('/Awards', {}, function () {
return success(mockAwardsList);
}, err);
},
BuyTicket: function (awardId, success, err) {
return http.Connection('/BuyTicket', {
awardId: awardId,
}, success, err);
View http.js
var http = {
Connection: function (url, data, success, err) {
setTimeout(function () {
success();
}, 3000); // fake request time
}
}
View awardshtml.html
<h1>
Awards List
</h1>
<div id='awards-list'>
Loading...
</div>
<h2>
My cart
</h2>
View mockAwardsList.js
var mockAwardsList = [
{
id: 1,
name: 'The Game Awards 2019',
price: 199,
},
{
id: 2,
name: 'New York Game Awards ',
price: 99,
View updateTotal.js
var total = 0;
function updateTotal() {
document.getElementById('total').innerHTML = total;
}
View addAwardToCart.js
function addAwardToCart(award) {
var div = document.createElement('div');
div.id = 'cart-item-' + award.id;
if (document.getElementById(div.id)) {
return;
}
div.appendChild(document.createTextNode('Added: ' + award.name + ', Price: $' + award.price));
var button = document.createElement('button');
@alissoncs
alissoncs / Application.js
Last active May 9, 2020
Legacy Javascript DOM Oriented
View Application.js
var Application = {
listAllAwards: function (success, err) {
console.info('ListAll Awards');
return http.Connection('/Awards', {}, function () {
return success(mockAwardsList);
}, err);
},
BuyTicket: function (awardId, success, err) {
return http.Connection('/BuyTicket', {
awardId: awardId,
You can’t perform that action at this time.