This file contains hidden or 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
| var Event = function() { | |
| var callbacks = {}; | |
| function emit(name, params) { | |
| if (callbacks[name]) { | |
| callbacks[name].map(function(item) { | |
| item(params); | |
| }); | |
| } | |
| } |
This file contains hidden or 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
| 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)); |
This file contains hidden or 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
| 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); |
This file contains hidden or 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
| var http = { | |
| Connection: function (url, data, success, err) { | |
| setTimeout(function () { | |
| success(); | |
| }, 3000); // fake request time | |
| } | |
| } |
This file contains hidden or 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
| <h1> | |
| Awards List | |
| </h1> | |
| <div id='awards-list'> | |
| Loading... | |
| </div> | |
| <h2> | |
| My cart | |
| </h2> |
This file contains hidden or 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
| var mockAwardsList = [ | |
| { | |
| id: 1, | |
| name: 'The Game Awards 2019', | |
| price: 199, | |
| }, | |
| { | |
| id: 2, | |
| name: 'New York Game Awards ', | |
| price: 99, |
This file contains hidden or 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
| var total = 0; | |
| function updateTotal() { | |
| document.getElementById('total').innerHTML = total; | |
| } |
This file contains hidden or 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
| 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'); |
This file contains hidden or 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
| 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, |