achievements.js 7.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220
  1. import { getDeviceState } from '../core'
  2. function fourColumnRow (gallery, entries, i) {
  3. const entry1 = document.createElement('div')
  4. entry1.classList.add('col-lg-6', 'm-0', 'p-0')
  5. entry1.appendChild(entries[i].cloneNode(true))
  6. entry1.children[0].classList.add('img-type-1')
  7. gallery.appendChild(entry1)
  8. i++
  9. const entry2 = document.createElement('div')
  10. entry2.classList.add('col-lg-3', 'm-0', 'p-0')
  11. entry2.appendChild(entries[i].cloneNode(true))
  12. entry2.children[0].classList.add('img-type-1')
  13. gallery.appendChild(entry2)
  14. i++
  15. const entry3 = document.createElement('div')
  16. entry3.classList.add('col-lg-3', 'm-0', 'p-0')
  17. entry3.appendChild(entries[i].cloneNode(true))
  18. entry3.children[0].classList.add('img-type-2')
  19. i++
  20. entry3.appendChild(entries[i].cloneNode(true))
  21. entry3.children[1].classList.add('img-type-2')
  22. gallery.appendChild(entry3)
  23. i++
  24. }
  25. function fourColumnReversedRow (gallery, entries, i) {
  26. const entry1 = document.createElement('div')
  27. entry1.classList.add('col-lg-3', 'm-0', 'p-0')
  28. entry1.appendChild(entries[i].cloneNode(true))
  29. entry1.children[0].classList.add('img-type-2')
  30. i++
  31. entry1.appendChild(entries[i].cloneNode(true))
  32. entry1.children[1].classList.add('img-type-2')
  33. gallery.appendChild(entry1)
  34. i++
  35. const entry2 = document.createElement('div')
  36. entry2.classList.add('col-lg-3', 'm-0', 'p-0')
  37. entry2.appendChild(entries[i].cloneNode(true))
  38. entry2.children[0].classList.add('img-type-1')
  39. gallery.appendChild(entry2)
  40. i++
  41. const entry3 = document.createElement('div')
  42. entry3.classList.add('col-lg-6', 'm-0', 'p-0')
  43. entry3.appendChild(entries[i].cloneNode(true))
  44. entry3.children[0].classList.add('img-type-1')
  45. gallery.appendChild(entry3)
  46. i++
  47. }
  48. function threeColumnRow (gallery, entries, i) {
  49. console.log(i)
  50. const entry1 = document.createElement('div')
  51. entry1.classList.add('col-lg-6', 'col-md-6', 'm-0', 'p-0')
  52. entry1.appendChild(entries[i].cloneNode(true))
  53. entry1.children[0].classList.add('img-type-1')
  54. gallery.appendChild(entry1)
  55. i++
  56. const entry2 = document.createElement('div')
  57. entry2.classList.add('col-lg-3', 'col-md-3', 'm-0', 'p-0')
  58. entry2.appendChild(entries[i].cloneNode(true))
  59. entry2.children[0].classList.add('img-type-1')
  60. gallery.appendChild(entry2)
  61. i++
  62. const entry3 = document.createElement('div')
  63. entry3.classList.add('col-lg-3', 'col-md-3', 'm-0', 'p-0')
  64. entry3.appendChild(entries[i].cloneNode(true))
  65. entry3.children[0].classList.add('img-type-1')
  66. gallery.appendChild(entry3)
  67. i++
  68. }
  69. function threeColumnReversedRow (gallery, entries, i) {
  70. const entry1 = document.createElement('div')
  71. entry1.classList.add('col-lg-3', 'col-md-3', 'm-0', 'p-0')
  72. entry1.appendChild(entries[i].cloneNode(true))
  73. entry1.children[0].classList.add('img-type-1')
  74. gallery.appendChild(entry1)
  75. i++
  76. const entry2 = document.createElement('div')
  77. entry2.classList.add('col-lg-3', 'col-md-3', 'm-0', 'p-0')
  78. entry2.appendChild(entries[i].cloneNode(true))
  79. entry2.children[0].classList.add('img-type-1')
  80. gallery.appendChild(entry2)
  81. i++
  82. const entry3 = document.createElement('div')
  83. entry3.classList.add('col-lg-6', 'col-md-3', 'm-0', 'p-0')
  84. entry3.appendChild(entries[i].cloneNode(true))
  85. entry3.children[0].classList.add('img-type-1')
  86. gallery.appendChild(entry3)
  87. i++
  88. }
  89. function twoColumnRow (gallery, entries, i) {
  90. const entry1 = document.createElement('div')
  91. entry1.classList.add('col-6', 'm-0', 'p-0')
  92. entry1.appendChild(entries[i].cloneNode(true))
  93. entry1.children[0].classList.add('img-type-1')
  94. gallery.appendChild(entry1)
  95. i++
  96. const entry2 = document.createElement('div')
  97. entry2.classList.add('col-6', 'm-0', 'p-0')
  98. entry2.appendChild(entries[i].cloneNode(true))
  99. entry2.children[0].classList.add('img-type-1')
  100. gallery.appendChild(entry2)
  101. i++
  102. }
  103. function singleColumnRow (gallery, entries, i) {
  104. const entry1 = document.createElement('div')
  105. entry1.classList.add('col-12', 'm-0', 'p-0')
  106. entry1.appendChild(entries[i].cloneNode(true))
  107. entry1.children[0].classList.add('img-type-1')
  108. gallery.appendChild(entry1)
  109. i++
  110. }
  111. function showAchievements () {
  112. const { isLaptop, isTablet } = getDeviceState()
  113. // show achievements from achievements-holder div
  114. const gallery = document.getElementById('gallery')
  115. if (gallery == null) {
  116. return
  117. }
  118. gallery.innerHTML = ''
  119. const entries = document.getElementById('achievements-holder').children
  120. let len = entries.length
  121. let i = 0
  122. let rowNumber = 1
  123. while (i < len) {
  124. if (isLaptop) {
  125. if (i + 4 <= len) {
  126. if (rowNumber % 2) {
  127. fourColumnRow(gallery, entries, i)
  128. } else {
  129. fourColumnReversedRow(gallery, entries, i)
  130. }
  131. i += 4
  132. } else if (i + 3 <= len) {
  133. if (rowNumber % 2) {
  134. threeColumnRow(gallery, entries, i)
  135. } else {
  136. threeColumnReversedRow(gallery, entries, i)
  137. }
  138. i += 3
  139. } else if (i + 2 <= len) {
  140. twoColumnRow(gallery, entries, i)
  141. i += 2
  142. } else {
  143. singleColumnRow(gallery, entries, i)
  144. i++
  145. }
  146. } else if (isTablet) {
  147. if (i + 2 <= len) {
  148. twoColumnRow(gallery, entries, i)
  149. i += 2
  150. } else {
  151. singleColumnRow(gallery, entries, i)
  152. i++
  153. }
  154. } else {
  155. singleColumnRow(gallery, entries, i)
  156. i++
  157. }
  158. rowNumber++
  159. }
  160. // show full image on click
  161. const elements = document.getElementsByClassName('achievement-entry')
  162. len = elements.length
  163. for (let i = 0; i < len; i++) {
  164. elements[i].onclick = function () {
  165. const achievements = document.getElementsByClassName('achievement-entry')
  166. const len2 = achievements.length
  167. for (let j = 0; j < len2; j++) {
  168. achievements[j].classList.toggle('hidden')
  169. }
  170. this.classList.toggle('achievement-details')
  171. this.classList.toggle('hidden')
  172. this.parentElement.classList.toggle('col-lg-12')
  173. this.parentElement.classList.toggle('col-md-12')
  174. this.parentElement.classList.toggle('col-sm-12')
  175. if (this.children.SmallImage.hasAttribute('active')) {
  176. const mainLogo = this.children.LargeImage.getAttribute('Style')
  177. this.children.LargeImage.setAttribute('active', true)
  178. this.children.SmallImage.removeAttribute('active')
  179. this.setAttribute('Style', mainLogo)
  180. } else {
  181. const mainLogo = this.children.SmallImage.getAttribute('Style')
  182. this.children.SmallImage.setAttribute('active', true)
  183. this.children.LargeImage.removeAttribute('active')
  184. this.setAttribute('Style', mainLogo)
  185. }
  186. if (this.children.caption !== undefined) {
  187. this.children.caption.classList.toggle('hidden')
  188. }
  189. if (this.children['enlarge-icon'] !== undefined) {
  190. this.getElementsByClassName('fa-xmark')[0].classList.toggle('hidden')
  191. this.getElementsByClassName('fa-magnifying-glass-plus')[0].classList.toggle('hidden')
  192. }
  193. if (this.children['achievement-title'] !== undefined) {
  194. this.children['achievement-title'].classList.toggle('hidden')
  195. }
  196. }
  197. }
  198. }
  199. ['DOMContentLoaded', 'resize'].forEach((event) =>
  200. document.addEventListener(event, showAchievements))