Soulsurv

Untitled

Oct 16th, 2016
85
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 8.50 KB | None | 0 0
  1. var sorterID = function(x,y)
  2. {
  3. var ans = x.ProductID-y.ProductID;
  4. return ans;
  5. if(ans > 0){
  6. ans = 1
  7. }
  8. if (ans < 1)
  9. {
  10. ans = -1
  11. }
  12. else{
  13. ans = 0;
  14. }
  15.  
  16. return ans
  17. }
  18.  
  19. var sorterIDDesc = function(x,y)
  20. {
  21. var ans = y.ProductID-x.ProductID;
  22. return ans;
  23. if(ans > 0){
  24. ans = -1
  25. }
  26. if (ans < 1)
  27. {
  28. ans = 1
  29. }
  30. else{
  31. ans = 0;
  32. }
  33.  
  34. return ans
  35. }
  36. var sorterPrice = function(x,y)
  37. {
  38. var ans = x.UnitPrice-y.UnitPrice;
  39. return ans;
  40. if(ans > 0){
  41. ans = 1
  42. }
  43. if (ans < 1)
  44. {
  45. ans = -1
  46. }
  47. else{
  48. ans = 0;
  49. }
  50.  
  51. return ans
  52. }
  53. var sorterPriceDesc = function(x,y)
  54. {
  55. var ans = y.unitPrice -x.UnitPrice;
  56. return ans;
  57. if(ans > 0){
  58. ans = -1
  59. }
  60. if (ans < 1)
  61. {
  62. ans = 1
  63. }
  64. else{
  65. ans = 0;
  66. }
  67.  
  68. return ans
  69. }
  70. function sortName(x,y){
  71. if (x.productName < y.productName){
  72. return 0;
  73. }
  74. else if (x.productName > y.productName)
  75. {
  76. return -1;
  77. }
  78. else{
  79. return 0;
  80. }
  81. }
  82.  
  83. function sortNameDesc(x,y){
  84. if (x.productName < y.productName){
  85. return -1;
  86. }
  87. else if (x.productName > y.productName)
  88. {
  89. return 1;
  90. }
  91. else{
  92. return 0;
  93. }
  94. }
  95.  
  96. var coolHot = function(){
  97. var trTags = document.getElementsByTagName("tr");
  98.  
  99. var i = 0;
  100.  
  101. while(i < trTags.length){
  102.  
  103. if(i % 2 == 0){
  104. trTags[i].className = "cool";
  105. }else{
  106. trTags[i].className = "hot";
  107. }
  108.  
  109. i++;
  110.  
  111. }
  112. }
  113.  
  114.  
  115. var stringFunc = function(){
  116. var desc = "";
  117. desc = desc+ "<tr>";
  118. desc = desc + "<td>" + this.ProductID + "</td>";
  119. desc = desc + "<td>" + this.ProductName + "</td>";
  120. desc = desc + "<td>" + this.UnitPrice + "</td>";
  121. desc = desc + "</tr>";
  122. return desc;
  123. }
  124.  
  125. function Product(aProductID, aProductName, anUnitPrice){
  126. this.ProductID = aProductID;
  127. this.ProductName = aProductName;
  128. this.UnitPrice = anUnitPrice;
  129. this.toString = stringFunc;
  130. }
  131.  
  132. var destroyChild = function(){
  133. var myNode = document.getElementById("message");
  134. while (myNode.firstChild) {
  135. myNode.removeChild(myNode.firstChild);
  136. }
  137. }
  138.  
  139. var createTable = function()
  140. {
  141. var myNode = document.getElementById("message");
  142. while (myNode.firstChild) {
  143. myNode.removeChild(myNode.firstChild);
  144. }
  145. }
  146.  
  147. var message = document.getElementById("message");
  148. var aListOfProducts = [];
  149. aListOfProducts[1] = new Product(1, "Chai", 18);
  150. aListOfProducts[2] = new Product(2, "Chang", 19);
  151. aListOfProducts[3] = new Product(3, "Aniseed Syrup", 10);
  152. aListOfProducts[4] = new Product(4, "Chef Anton's Cajun Seasoning", 22);
  153. aListOfProducts[5] = new Product(5, "Chef Anton's Gumbo Mix", 21.35);
  154. aListOfProducts[6] = new Product(6, "Grandma's Boysenberry Spread", 25);
  155. aListOfProducts[7] = new Product(7, "Uncle Bob's Organic Dried Pears", 30);
  156. aListOfProducts[8] = new Product(8, "Northwoods Cranberry Sauce", 40);
  157. aListOfProducts[9] = new Product(9, "Mishi Kobe Niku", 97);
  158. aListOfProducts[10] = new Product(10, "Ikura", 31);
  159. aListOfProducts[11] = new Product(11, "Queso Cabrales", 21);
  160. aListOfProducts[12] = new Product(12, "Queso Manchego La Pastora", 38);
  161. aListOfProducts[13] = new Product(13, "Konbu", 6);
  162. aListOfProducts[14] = new Product(14, "Tofu", 23.25);
  163. aListOfProducts[15] = new Product(15, "Genen Shouyu", 15.5);
  164. aListOfProducts[16] = new Product(16, "Pavlova", 17.45);
  165. aListOfProducts[17] = new Product(17, "Alice Mutton", 39);
  166. aListOfProducts[18] = new Product(18, "Carnarvon Tigers", 62.5);
  167. aListOfProducts[19] = new Product(19, "Teatime Chocolate Biscuits", 9.2);
  168. aListOfProducts[20] = new Product(20, "Sir Rodney's Marmalade", 81);
  169. aListOfProducts[21] = new Product(21, "Sir Rodney's Scones", 10);
  170. aListOfProducts[22] = new Product(22, "Gustaf's Knäckebröd", 21);
  171. aListOfProducts[23] = new Product(23, "Tunnbröd", 9);
  172. aListOfProducts[24] = new Product(24, "Guaraná Fantástica", 4.5);
  173. aListOfProducts[25] = new Product(25, "NuNuCa Nuß-Nougat-Creme", 14);
  174. aListOfProducts[26] = new Product(26, "Gumbär Gummibärchen", 31.23);
  175. aListOfProducts[27] = new Product(27, "Schoggi Schokolade", 43.9);
  176. aListOfProducts[28] = new Product(28, "Rössle Sauerkraut", 45.6);
  177. aListOfProducts[29] = new Product(29, "Thüringer Rostbratwurst", 123.79);
  178. aListOfProducts[30] = new Product(30, "Nord-Ost Matjeshering", 25.89);
  179. aListOfProducts[31] = new Product(31, "Gorgonzola Telino", 12.5);
  180. aListOfProducts[32] = new Product(32, "Mascarpone Fabioli", 32);
  181. aListOfProducts[33] = new Product(33, "Geitost", 2.5);
  182. aListOfProducts[34] = new Product(34, "Sasquatch Ale", 14);
  183. aListOfProducts[35] = new Product(35, "Steeleye Stout", 18);
  184. aListOfProducts[36] = new Product(36, "Inlagd Sill", 19);
  185. aListOfProducts[37] = new Product(37, "Gravad lax", 26);
  186. aListOfProducts[38] = new Product(38, "Côte de Blaye", 263.5);
  187. aListOfProducts[39] = new Product(39, "Chartreuse verte", 18);
  188. aListOfProducts[40] = new Product(40, "Boston Crab Meat", 18.4);
  189. aListOfProducts[41] = new Product(41, "Jack's New England Clam Chowder", 9.65);
  190. aListOfProducts[42] = new Product(42, "Singaporean Hokkien Fried Mee", 14);
  191. aListOfProducts[43] = new Product(43, "Ipoh Coffee", 46);
  192. aListOfProducts[44] = new Product(44, "Gula Malacca", 19.45);
  193. aListOfProducts[45] = new Product(45, "Røgede sild", 9.5);
  194. aListOfProducts[46] = new Product(46, "Spegesild", 12);
  195. aListOfProducts[47] = new Product(47, "Zaanse koeken", 9.5);
  196. aListOfProducts[48] = new Product(48, "Chocolade", 12.75);
  197. aListOfProducts[49] = new Product(49, "Maxilaku", 20);
  198. aListOfProducts[50] = new Product(50, "Valkoinen suklaa", 16.25);
  199. aListOfProducts[51] = new Product(51, "Manjimup Dried Apples", 53);
  200. aListOfProducts[52] = new Product(52, "Filo Mix", 7);
  201. aListOfProducts[53] = new Product(53, "Perth Pasties", 32.8);
  202. aListOfProducts[54] = new Product(54, "Tourtière", 7.45);
  203. aListOfProducts[55] = new Product(55, "Pâté chinois", 24);
  204. aListOfProducts[56] = new Product(56, "Gnocchi di nonna Alice", 38);
  205. aListOfProducts[57] = new Product(57, "Ravioli Angelo", 19.5);
  206. aListOfProducts[58] = new Product(58, "Escargots de Bourgogne", 13.25);
  207. aListOfProducts[59] = new Product(59, "Raclette Courdavault", 55);
  208. aListOfProducts[60] = new Product(60, "Camembert Pierrot", 34);
  209. aListOfProducts[61] = new Product(61, "Sirop d'érable", 28.5);
  210. aListOfProducts[62] = new Product(62, "Tarte au sucre", 49.3);
  211. aListOfProducts[63] = new Product(63, "Vegie-spread", 43.9);
  212. aListOfProducts[64] = new Product(64, "Wimmers gute Semmelknödel", 33.25);
  213. aListOfProducts[65] = new Product(65, "Louisiana Fiery Hot Pepper Sauce", 21.05);
  214. aListOfProducts[66] = new Product(66, "Louisiana Hot Spiced Okra", 17);
  215. aListOfProducts[67] = new Product(67, "Laughing Lumberjack Lager", 14);
  216. aListOfProducts[68] = new Product(68, "Scottish Longbreads", 12.5);
  217. aListOfProducts[69] = new Product(69, "Gudbrandsdalsost", 36);
  218. aListOfProducts[70] = new Product(70, "Outback Lager", 15);
  219. aListOfProducts[71] = new Product(71, "Fløtemysost", 21.5);
  220. aListOfProducts[72] = new Product(72, "Mozzarella di Giovanni", 34.8);
  221. aListOfProducts[73] = new Product(73, "Röd Kaviar", 15);
  222. aListOfProducts[74] = new Product(74, "Longlife Tofu", 10);
  223. aListOfProducts[75] = new Product(75, "Rhönbräu Klosterbier", 7.75);
  224. aListOfProducts[76] = new Product(76, "Lakkalikööri", 18);
  225. aListOfProducts[77] = new Product(77, "Original Frankfurter grüne Soße", 13);
  226.  
  227.  
  228. //message.innerHTML = aListOfProducts.toString();
  229. message.innerHTML = aListOfProducts;
  230.  
  231. var sortID = document.getElementById("sortID");
  232. sortID.addEventListener('click', function(){destroyChild();
  233. message.innerHTML = aListOfProducts.sort(sorterID)});
  234.  
  235. var sortIDdesc = document.getElementById("sortIDdesc");
  236. sortIDdesc.addEventListener('click', function(){destroyChild();
  237. message.innerHTML = aListOfProducts.sort(sorterIDDesc)});
  238.  
  239. var sortName = document.getElementById("sortName");
  240. sortName.addEventListener('click', function(){destroyChild();
  241. message.innerHTML = aListOfProducts.sort(sortName)});
  242.  
  243. var sortNamedesc = document.getElementById("sortNamedesc");
  244. sortNamedesc.addEventListener('click', function(){destroyChild();
  245. message.innerHTML = aListOfProducts.sort(sortNameDesc)});
  246.  
  247. var sortPrice = document.getElementById("sortPrice");
  248. sortPrice.addEventListener('click', function(){destroyChild();
  249. message.innerHTML = aListOfProducts.sort(sorterPrice)});
  250.  
  251. var sortPricedesc = document.getElementById("sortPricedesc");
  252. sortPricedesc.addEventListener('click', function(){destroyChild();
  253. message.innerHTML = aListOfProducts.sort(sorterPriceDesc)});
  254.  
  255. var trTags = document.getElementsByTagName("tr");
  256.  
  257. var i = 0;
  258.  
  259. while(i < trTags.length){
  260.  
  261. if(i % 2 == 0){
  262. trTags[i].className = "cool";
  263. }else{
  264. trTags[i].className = "hot";
  265. }
  266.  
  267. i++;
  268. }
Advertisement
Add Comment
Please, Sign In to add comment