Advertisement
Guest User

Untitled

a guest
Nov 11th, 2019
134
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 5.47 KB | None | 0 0
  1. <!DOCTYPE html>
  2. <html lang="en">
  3. <head>
  4. <meta charset="utf-8">
  5. <link rel="stylesheet" href="../fontawesome-free-5.11.2-web/css/all.css">
  6. <!-- <link href="https://maxcdn.bootstrapcdn.com/font-awesome/4.6.3/css/font-awesome.min.css" rel="stylesheet" integrity="sha384-T8Gy5hrqNKT+hzMclPo118YTQO6cYprQmhrYwIiQ/3axmI1hQomh7Ud2hPOy8SP1" crossorigin="anonymous"> -->
  7. <link href="https://stackpath.bootstrapcdn.com/bootstrap/4.3.1/css/bootstrap.min.css" rel="stylesheet" integrity="sha384-ggOyR0iXCbMQv3Xipma34MD+dH/1fQ784/j6cY/iJTQUOhcWr7x9JvoRxT2MZw1T" crossorigin="anonymous">
  8. <title></title>
  9.  
  10. <style>
  11. .stars-outer{
  12. position: relative;
  13. display: inline-block;
  14. }
  15.  
  16. .stars-inner{
  17. position: absolute;
  18. top: 0;
  19. left: 0;
  20. white-space: nowrap;
  21. overflow: hidden;
  22. width: 0
  23. }
  24.  
  25. .stars-outer::before{
  26. content: "\f005 \f005 \f005 \f005 \f005";
  27. font-family: 'Font Awesome 5 Free';
  28. font-weight: 900;
  29. color: #ccc;
  30. }
  31.  
  32. .stars-inner::before{
  33. content: "\f005 \f005 \f005 \f005 \f005";
  34. font-family: 'Font Awesome 5 Free';
  35. font-weight: 900;
  36. color: #f8c;
  37. }
  38.  
  39. h1{
  40. text-align: center;
  41. padding-top: 20PX;
  42. font-family: 'Raleway-Regular', sans-serif;
  43. }
  44. </style>
  45. </head>
  46. <body>
  47. <h1>IMAGE</h1>
  48.  
  49. <div class="container mt-3">
  50. <div class="form-group">
  51. <select id="product-select" class="form-control
  52. costum-select">
  53. <option value="0" disabled selected>Pilih Item</option>
  54. <option value="kolektabilitas">Kolektabilitas</option>
  55. <option value="simpanan">Simpanan</option>
  56. <option value="pinjaman">Pinjaman</option>
  57. </select>
  58. </div>
  59.  
  60. <div class="form-group">
  61. <input type="number" id="rating-control"
  62. class="form-control" step="0.1" max="5" placeholder="Pilih 1 - 5" disabled>
  63. </div>
  64.  
  65. <table class="table table-striped">
  66. <thead>
  67. <tr>
  68. <th>Item</th>
  69. <th>Nilai</th>
  70. </tr>
  71. </thead>
  72. <tbody>
  73. <tr class="kolektabilitas">
  74. <td>Kolektabilitas</td>
  75. <td>
  76. <div class="stars-outer">
  77. <div class="stars-inner"></div>
  78. </div>
  79. <span class="number-rating"></span>
  80. </td>
  81. </tr>
  82. <tr class="simpanan">
  83. <td>Simpanan</td>
  84. <td>
  85. <div class="stars-outer">
  86. <div class="stars-inner"></div>
  87. </div>
  88. <span class="number-rating"></span>
  89. </td>
  90. </tr>
  91. <tr class="pinjaman">
  92. <td>Pinjaman</td>
  93. <td>
  94. <div class="stars-outer">
  95. <div class="stars-inner"></div>
  96. </div>
  97. <span class="number-rating"></span>
  98. </td>
  99. </tr>
  100. </tbody>
  101. </table>
  102. </div>
  103.  
  104.  
  105. <script>
  106. //Initial ratingControl
  107. const ratings = {
  108. kolektabilitas : 0,
  109. simpanan : 0,
  110. pinjaman : 0,
  111. }
  112.  
  113. //total stars
  114. const starsTotal = 5;
  115.  
  116. //run getRatings when Domloads
  117. document.addEventListener('DOMContentLoaded',getRatings);
  118.  
  119. const productSelect = document.getElementById
  120. ('product-select');
  121. const ratingControl = document.getElementById
  122. ('rating-control');
  123.  
  124. //init product
  125. let product;
  126.  
  127. //product select change
  128. productSelect.addEventListener('change', (e) => {
  129. product = e.target.value;
  130. //Enable rating control
  131. ratingControl.disabled = false;
  132. ratingControl.value = ratings[product]
  133. });
  134.  
  135. //Rating control
  136. ratingControl.addEventListener('blur', (e) => {
  137. const rating = e.target.value;
  138.  
  139. //make sure 5 or under
  140. if (rating > 5) {
  141. alert('Tolong Pilih 1 - 5')
  142. return;
  143. }
  144.  
  145. //change rating
  146. ratings[product] = rating;
  147.  
  148. getRatings();
  149. });
  150.  
  151. //GET Ratings
  152. function getRatings(){
  153. for (let rating in ratings){
  154. //get percentage
  155. const starPercentage = (ratings[rating] /
  156. starsTotal) * 100;
  157.  
  158. //Round to nearest 10
  159. const starPercentageRounded = `${Math.round
  160. (starPercentage / 10) * 10}%`;
  161.  
  162. //set width of stars - iner to percentage
  163. document.querySelector(`.${rating} .stars-inner`)
  164. .style.width = starPercentageRounded;
  165.  
  166. //add number percentage
  167. document.querySelector(`.${rating} .number-rating`)
  168. .innerHTML = ratings[rating];
  169. }
  170. }
  171. </script>
  172.  
  173. </body>
  174. </html>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement