Advertisement
Guest User

assssssssss2

a guest
Oct 31st, 2014
184
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 7.69 KB | None | 0 0
  1. function sortGame_OnClick() {
  2. sortMode = 1;
  3. sortEntries();
  4. }
  5.  
  6. function sortSystem_OnClick() {
  7. sortMode = 2;
  8. sortEntries();
  9. }
  10.  
  11. function sortRating_OnClick() {
  12. sortMode = 3;
  13. sortEntries();
  14. }
  15. var systemList = [
  16. 'Nintendo NES', // 0
  17. 'Nintendo SNES', // 1
  18. 'Nintendo 64', // 2
  19. 'Nintendo GameCube', // 3
  20. 'Nintendo Wii', // 4
  21. 'Nintendo Wii U', // 5
  22. 'Nintendo Game Boy', // 6
  23. 'Nintendo Game Boy Color', // 7
  24. 'Nintendo Game Boy Advance',// 8
  25. 'Nintendo DS', // 9
  26. 'Nintendo 3DS', // 10
  27. 'Sega Master System', // 11
  28. 'Sega Genesis', // 12
  29. 'Sega CD', // 13
  30. 'Sega 32x', // 14
  31. 'Sega Saturn', // 15
  32. 'Sega Dreamcast', // 16
  33. 'Sega Game Gear', // 17
  34. 'Playstation 1', // 18
  35. 'Playstation 2 ', // 19
  36. 'Playstation 3', // 20
  37. 'Playstation 4', // 21
  38. 'Playstation Portable', // 22
  39. 'Playstation Vita', // 23
  40. 'Xbox', // 24
  41. 'Xbox 360', // 25
  42. 'Xbox One', // 26
  43. 'PC', // 27
  44. 'Other' // 28
  45. ];
  46.  
  47. var ratingMaList = [
  48. 'A',
  49. 'B',
  50. 'C',
  51. 'D',
  52. 'E',
  53. 'F'
  54. ];
  55.  
  56. var ratingMiList = [
  57. '+',
  58. '',
  59. '-'
  60. ];
  61.  
  62. var entries = [];
  63.  
  64. var lastSortMode = sortMode = 0;
  65. var sortListA = [
  66. '',
  67. 'game',
  68. 'system',
  69. 'ratingmi'
  70. ]
  71.  
  72. var sortListB = [
  73. '',
  74. '',
  75. '',
  76. 'ratingma'
  77. ]
  78.  
  79. var elementList = [
  80. '',
  81. '#sortGameA',
  82. '#sortSystemA',
  83. '#sortRatingA'
  84. ]
  85.  
  86. function sortEntries() {
  87. var sortA = sortListA[sortMode];
  88. var sortB = sortListB[sortMode];
  89. if (typeof entries[0][sortA] == 'string') {
  90. if (lastSortMode != sortMode) {
  91. entries.sort(function(b, a){
  92. if(a[sortA] > b[sortA]) return -1;
  93. if(a[sortA] < b[sortA]) return 1;
  94. return 0;
  95. });
  96. } else {
  97. entries.sort(function(a, b){
  98. if(a[sortA] > b[sortA]) return -1;
  99. if(a[sortA] < b[sortA]) return 1;
  100. return 0;
  101. });
  102. }
  103. } else {
  104. if (lastSortMode != sortMode) {
  105. if (sortB != '') {
  106. entries.sort(function(a, b) {
  107. if (a[sortB] == b[sortB]) {
  108. return (a[sortA] < b[sortA]) ? -1 : (a[sortA] > b[sortA]) ? 1 : 0;
  109. } else {
  110. return (a[sortB] < b[sortB]) ? -1 : 1;
  111. }
  112. });
  113. } else {
  114. entries.sort(function(a, b){
  115. return a[sortA]-b[sortA];
  116. });
  117. }
  118. } else {
  119. if (sortB != '') {
  120. entries.sort(function(b, a) {
  121. if (a[sortB] == b[sortB]) {
  122. return (a[sortA] < b[sortA]) ? -1 : (a[sortA] > b[sortA]) ? 1 : 0;
  123. } else {
  124. return (a[sortB] < b[sortB]) ? -1 : 1;
  125. }
  126. });
  127. } else {
  128. entries.sort(function(b, a){
  129. return a[sortA]-b[sortA];
  130. });
  131. }
  132. }
  133. }
  134. headerRefresh();
  135. if (lastSortMode == sortMode) { sortMode = 0; }
  136. lastSortMode = sortMode;
  137. entriesRefresh();
  138. }
  139.  
  140. function headerRefresh() {
  141. for (var i=0;i<elementList.length;i++) {
  142. $(elementList[i]).css('visibility','hidden');
  143. }
  144. $(elementList[sortMode]).css('visibility','visible');
  145. if (sortMode == lastSortMode) {
  146. $(elementList[sortMode]).text('▲');
  147. } else {
  148. $(elementList[sortMode]).text('▼');
  149. }
  150. }
  151.  
  152. $(document).ready(function() {
  153. for (var i=0;i<systemList.length;i++) {
  154. $('#systemSelect').append('<option value="' + i + '">' + systemList[i] + '</option>');
  155. }
  156.  
  157. for (var i=0;i<ratingMaList.length;i++) {
  158. $('#ratingMaSelect').append('<option value="' + i + '">' + ratingMaList[i] + '</option>');
  159. }
  160.  
  161. for (var i=0;i<ratingMiList.length;i++) {
  162. $('#ratingMiSelect').append('<option value="' + i + '">' + ratingMiList[i] + '</option>');
  163. }
  164.  
  165. $("input[type=checkbox][value=all]").change(function(){checkboxAll()});
  166.  
  167. $('#buttonEdit').prop('disabled',true);
  168.  
  169. newFileInput();
  170. headerRefresh();
  171. });
  172.  
  173. function newFileInput() {
  174. $('#fileinputcont').html('<input id="fileinput" type="file" accept=".json">')
  175. $('#fileinput').change(function(e) {
  176. var file = $('#fileinput')[0].files[0];
  177. var reader = new FileReader();
  178. reader.onload = function(e) {
  179. if (confirm("Are you sure you want to overwrite the current table?")) {
  180. entries = JSON.parse(reader.result);
  181. entriesRefresh();
  182. lastSortMode = sortMode = 0;
  183. headerRefresh();
  184. }
  185. }
  186. reader.readAsText(file);
  187. newFileInput();
  188. });
  189. }
  190.  
  191. function entriesAdd() {
  192. entries.push({
  193. game: $('#gameSelect').val().toString(),
  194. system: parseInt($('#systemSelect').val()),
  195. ratingma: parseInt($('#ratingMaSelect').val()),
  196. ratingmi: parseInt($('#ratingMiSelect').val())
  197. });
  198. entriesRefresh();
  199. checkboxAll();
  200. lastSortMode = sortMode = 0;
  201. headerRefresh();
  202. }
  203.  
  204. function entriesRefresh() {
  205. $('#entries').html('');
  206. for (var i=0;i<entries.length;i++) {
  207. $('#entries').append('<tr class="entry" id="tr' + i + '"><td style="width:4%"><input type="checkbox" value="' + i + '"></td><td style="width:32%">' + entries[i].game + '</td><td style="width:32%">' + systemList[entries[i].system] + '</td><td style="width:32%">' + ratingMaList[entries[i].ratingma] + ratingMiList[entries[i].ratingmi] + '</td></tr>');
  208. $("input[type=checkbox][value=" + i + "]").change(function(){checkboxAny()});
  209. }
  210. }
  211.  
  212. function saveAsJSON() {
  213. // http://thiscouldbebetter.wordpress.com/2012/12/18/loading-editing-and-saving-a-text-file-in-html5-using-javascrip/
  214. var textFileAsBlob = new Blob([JSON.stringify(entries)], {type:'text/plain'});
  215. var fileNameToSaveAs = "gamelist.json";
  216.  
  217. var downloadLink = document.createElement("a");
  218. downloadLink.download = fileNameToSaveAs;
  219. downloadLink.innerHTML = "Download File";
  220. if (window.webkitURL != null)
  221. {
  222. // Chrome allows the link to be clicked
  223. // without actually adding it to the DOM.
  224. downloadLink.href = window.webkitURL.createObjectURL(textFileAsBlob);
  225. }
  226. else
  227. {
  228. // Firefox requires the link to be added to the DOM
  229. // before it can be clicked.
  230. downloadLink.href = window.URL.createObjectURL(textFileAsBlob);
  231. downloadLink.onclick = destroyClickedElement;
  232. downloadLink.style.display = "none";
  233. document.body.appendChild(downloadLink);
  234. }
  235.  
  236. downloadLink.click();
  237. }
  238.  
  239. function loadClick() {
  240. $('#loadfile').trigger('click')
  241. };
  242.  
  243. function deleteSelected() {
  244. for (var i=entries.length;i>=0;i--) {
  245. if ($("input[type=checkbox][value=" + i + "]").prop("checked")) {
  246. entries.splice(i,1);
  247. }
  248. }
  249. entriesRefresh();
  250. lastSortMode = sortMode = 0;
  251. headerRefresh();
  252. }
  253.  
  254. function editButton_onClick() {
  255. for (var i=0;i<entries.length;i++) {
  256. if ($("input[type=checkbox][value=" + i + "]").prop("checked")) {
  257. $('#gameSelect').val(entries[i].game);
  258. $('#systemSelect').val(entries[i].system);
  259. $('#ratingMaSelect').val(entries[i].ratingma);
  260. $('#ratingMiSelect').val(entries[i].ratingmi);
  261. entries.splice(i,1);
  262. entriesRefresh();
  263. checkboxAny();
  264. }
  265. }
  266.  
  267. }
  268.  
  269. function checkboxAll() {
  270. for (var i=0;i<entries.length;i++) {
  271. $("input[type=checkbox][value=" + i + "]").prop("checked",$("input[type=checkbox][value=all]").prop("checked"));
  272. }
  273. checkboxAny();
  274. }
  275.  
  276. function checkboxAny() {
  277. var checkedAmount = 0;
  278. for (var i=0;i<entries.length;i++) {
  279. checkedAmount += $("input[type=checkbox][value=" + i + "]").prop("checked");
  280. }
  281. $('#buttonEdit').prop('disabled',(checkedAmount == 0) || (checkedAmount > 1));
  282. if (entries.length != 0) {
  283. $("input[type=checkbox][value=all]").prop("checked",checkedAmount == entries.length);
  284. }
  285. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement