a zip code crypto-currency system good for red ONLY

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188
  1. var $ = document.querySelector.bind(document);
  2. var API_ROOT = '/ionic-lab/api/v1';
  3. var APP_CONFIG = {};
  4. function loadAppConfig() {
  5. var req = new XMLHttpRequest();
  6. req.addEventListener('load', function(e) {
  7. setAppConfig(JSON.parse(req.response));
  8. });
  9. req.open('GET', API_ROOT + '/app-config', true);
  10. req.send(null);
  11. }
  12. function setAppConfig(data) {
  13. APP_CONFIG = data;
  14. }
  15. function buildMenu() {
  16. buildComponentsMenu();
  17. var sidebar = $('#sidebar');
  18. var topLevels = sidebar.querySelectorAll('#menu > li > a');
  19. var lastMenuConfig = window.localStorage.getItem('ionic_labmenu');
  20. if (lastMenuConfig === 'true' || lastMenuConfig === null) {
  21. sidebar.classList.remove('hidden');
  22. }
  23. Array.prototype.map.call(topLevels, function(a) {
  24. if (!a.href) {
  25. a.addEventListener('click', function(e) {
  26. if (a.parentNode.classList.contains('expanded')) {
  27. a.parentNode.classList.remove('expanded');
  28. } else {
  29. a.parentNode.classList.add('expanded');
  30. }
  31. e.preventDefault();
  32. });
  33. }
  34. });
  35. $('#view-ad').addEventListener('click', function(e) {
  36. var win = window.open('http://view.ionic.io/', '_blank');
  37. win.focus();
  38. });
  39. var toggleMenu = function(e) {
  40. if (sidebar.classList.contains('hidden')) {
  41. sidebar.classList.remove('hidden');
  42. window.localStorage.setItem('ionic_labmenu', 'true');
  43. } else {
  44. sidebar.classList.add('hidden');
  45. window.localStorage.setItem('ionic_labmenu', 'false');
  46. }
  47. };
  48. $('#menu-toggle').addEventListener('click', toggleMenu);
  49. $('#sidebar .close').addEventListener('click', toggleMenu);
  50. }
  51. function buildComponentsMenu() {
  52. var items = [{"href":"http://ionicframework.com/docs/components/#overview","title":"Overview"},{"href":"http://ionicframework.com/docs/components/#action-sheets","title":"Action Sheets"},{"href":"http://ionicframework.com/docs/components/#alert","title":"Alerts"},{"href":"http://ionicframework.com/docs/components/#badges","title":"Badges"},{"href":"http://ionicframework.com/docs/components/#buttons","title":"Buttons"},{"href":"http://ionicframework.com/docs/components/#cards","title":"Cards"},{"href":"http://ionicframework.com/docs/components/#checkbox","title":"Checkbox"},{"href":"http://ionicframework.com/docs/components/#datetime","title":"DateTime"},{"href":"http://ionicframework.com/docs/components/#fabs","title":"FABs"},{"href":"http://ionicframework.com/docs/components/#gestures","title":"Gestures"},{"href":"http://ionicframework.com/docs/components/#grid","title":"Grid"},{"href":"http://ionicframework.com/docs/components/#icons","title":"Icons"},{"href":"http://ionicframework.com/docs/components/#inputs","title":"Inputs"},{"href":"http://ionicframework.com/docs/components/#lists","title":"Lists"},{"href":"http://ionicframework.com/docs/components/#loading","title":"Loading"},{"href":"http://ionicframework.com/docs/components/#menus","title":"Menus"},{"href":"http://ionicframework.com/docs/components/#modals","title":"Modals"},{"href":"http://ionicframework.com/docs/components/#navigation","title":"Navigation"},{"href":"http://ionicframework.com/docs/components/#popovers","title":"Popover"},{"href":"http://ionicframework.com/docs/components/#radio","title":"Radio"},{"href":"http://ionicframework.com/docs/components/#range","title":"Range"},{"href":"http://ionicframework.com/docs/components/#searchbar","title":"Searchbar"},{"href":"http://ionicframework.com/docs/components/#segment","title":"Segment"},{"href":"http://ionicframework.com/docs/components/#select","title":"Select"},{"href":"http://ionicframework.com/docs/components/#slides","title":"Slides"},{"href":"http://ionicframework.com/docs/components/#tabs","title":"Tabs"},{"href":"http://ionicframework.com/docs/components/#toast","title":"Toast"},{"href":"http://ionicframework.com/docs/components/#toggle","title":"Toggle"},{"href":"http://ionicframework.com/docs/components/#toolbar","title":"Toolbar"}];
  53. var componentsMenu = $('#components-menu');
  54. items.map(function (i) {
  55. var l = document.createElement('li');
  56. var a = document.createElement('a');
  57. a.href = i.href;
  58. a.target = "_blank";
  59. a.innerText = i.title;
  60. l.appendChild(a);
  61. componentsMenu.appendChild(l);
  62. });
  63. }
  64. function tryShowViewPopup() {
  65. var view = window.localStorage.getItem('ionic_viewpop');
  66. if (!view) {
  67. $('#view-popup').style.display = 'block';
  68. $('#view-popup .close').addEventListener('click', function(e) {
  69. window.localStorage.setItem('ionic_viewpop', true);
  70. $('#view-popup').style.opacity = 0;
  71. setTimeout(function() {
  72. $('#view-popup').style.display = 'none';
  73. }, 200);
  74. });
  75. window.requestAnimationFrame(function() {
  76. $('#view-popup').style.opacity = 1;
  77. });
  78. }
  79. }
  80. // Bind the dropdown platform toggles
  81. function bindToggles() {
  82. // Watch for changes on the checkboxes in the device dropdown
  83. var iphone = $('#device-iphone');
  84. var android = $('#device-android');
  85. var windows = $('#device-windows');
  86. var devices = [iphone, android, windows];
  87. for(var i in devices) {
  88. devices[i].addEventListener('change', function(e) {
  89. var device = this.name;
  90. console.log('Device changed', device, this.checked);
  91. showDevice(device, this.checked);
  92. saveLastDevices(device, this.checked);
  93. });
  94. }
  95. }
  96. // Show one of the devices
  97. function showDevice(device, isShowing) {
  98. $('#device-' + device).checked = isShowing;
  99. var rendered = $('#' + device);
  100. if(!rendered) {
  101. var template = $('#' + device + '-frame-template');
  102. var clone = document.importNode(template, true);
  103. $('preview').appendChild(clone.content);
  104. //check for extra params in location.url to pass on to iframes
  105. var params = document.location.href.split('?');
  106. if (params) {
  107. var newparams = params[params.length - 1];
  108. var oldsrc = $('preview .frame').getAttribute('src');
  109. $('preview .frame').setAttribute('src', oldsrc + '&' + newparams);
  110. }
  111. } else {
  112. rendered.style.display = isShowing ? '' : 'none';
  113. }
  114. }
  115. function saveLastDevices(newDevice, didAdd) {
  116. var last = window.localStorage.getItem('ionic_lastdevices');
  117. if(!last && didAdd) {
  118. window.localStorage.setItem('ionic_lastdevices', newDevice);
  119. return;
  120. }
  121. var devices = last.split(',');
  122. var di = devices.indexOf(newDevice);
  123. if(di == -1 && didAdd) {
  124. window.localStorage.setItem('ionic_lastdevices', devices.join(',') + ',' + newDevice);
  125. } else if(di >= 0) {
  126. devices.splice(di, 1);
  127. window.localStorage.setItem('ionic_lastdevices', devices.join(','));
  128. }
  129. }
  130. function showLastDevices() {
  131. var last = window.localStorage.getItem('ionic_lastdevices');
  132. if(!last) {
  133. showDevice('iphone', true);
  134. return;
  135. }
  136. var devices = last.split(',');
  137. for(var i = 0; i < devices.length; i++) {
  138. showDevice(devices[i], true);
  139. }
  140. }
  141. function setCordovaInfo(data) {
  142. var el = $('#app-info');
  143. el.innerHTML = data.name + ' - v' + data.version;
  144. if(data.name) {
  145. document.title = data.name + ' - Ionic Lab';
  146. }
  147. }
  148. function loadCordova() {
  149. var req = new XMLHttpRequest();
  150. req.addEventListener('load', function(e) {
  151. setCordovaInfo(JSON.parse(req.response));
  152. });
  153. req.open('GET', API_ROOT + '/cordova', true);
  154. req.send(null);
  155. }
  156. //loadSearchIndex();
  157. loadAppConfig();
  158. buildMenu();
  159. showLastDevices();
  160. loadCordova();
  161. bindToggles();
  162. //tryShowViewPopup();