@ons/design-system 70.0.7 → 70.0.9

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (454) hide show
  1. package/README.md +11 -17
  2. package/components/access-code/_macro.njk +31 -25
  3. package/components/access-code/_macro.spec.js +145 -145
  4. package/components/access-code/access-code.dom.js +5 -5
  5. package/components/access-code/access-code.js +16 -16
  6. package/components/access-code/access-code.scss +22 -22
  7. package/components/access-code/access-code.spec.js +17 -17
  8. package/components/access-code/example-access-code-error.njk +49 -37
  9. package/components/access-code/example-access-code.njk +40 -30
  10. package/components/accordion/_macro.njk +7 -6
  11. package/components/accordion/_macro.spec.js +154 -154
  12. package/components/accordion/accordion.dom.js +10 -10
  13. package/components/accordion/accordion.js +50 -50
  14. package/components/accordion/accordion.spec.js +104 -104
  15. package/components/accordion/example-accordion-open.njk +0 -1
  16. package/components/address-input/_macro.njk +23 -11
  17. package/components/address-input/_macro.spec.js +420 -420
  18. package/components/address-input/autosuggest.address.dom.js +5 -5
  19. package/components/address-input/autosuggest.address.error.js +77 -77
  20. package/components/address-input/autosuggest.address.js +354 -359
  21. package/components/address-input/autosuggest.address.setter.js +95 -95
  22. package/components/address-input/autosuggest.address.spec.js +668 -651
  23. package/components/address-input/example-address-input-editable.njk +52 -50
  24. package/components/address-input/example-address-input-manual.njk +23 -21
  25. package/components/address-input/example-address-input.njk +40 -38
  26. package/components/address-output/_address-output.scss +3 -3
  27. package/components/address-output/_macro.njk +6 -6
  28. package/components/address-output/_macro.spec.js +84 -84
  29. package/components/autosuggest/_autosuggest.scss +114 -114
  30. package/components/autosuggest/_macro.njk +57 -37
  31. package/components/autosuggest/_macro.spec.js +255 -255
  32. package/components/autosuggest/autosuggest.dom.js +5 -5
  33. package/components/autosuggest/autosuggest.helpers.js +11 -11
  34. package/components/autosuggest/autosuggest.helpers.spec.js +73 -73
  35. package/components/autosuggest/autosuggest.js +20 -20
  36. package/components/autosuggest/autosuggest.spec.js +542 -536
  37. package/components/autosuggest/autosuggest.ui.js +478 -475
  38. package/components/autosuggest/example-autosuggest-country-multiple.njk +26 -26
  39. package/components/autosuggest/example-autosuggest-country.njk +24 -24
  40. package/components/autosuggest/fuse-config.js +17 -17
  41. package/components/back-to-top/_back-to-top.scss +27 -27
  42. package/components/back-to-top/_macro.spec.js +49 -49
  43. package/components/back-to-top/back-to-top.dom.js +5 -5
  44. package/components/back-to-top/back-to-top.js +52 -52
  45. package/components/back-to-top/back-to-top.spec.js +106 -106
  46. package/components/back-to-top/example-back-to-top.njk +183 -6
  47. package/components/back-to-top/example-full-page-back-to-top.njk +135 -123
  48. package/components/breadcrumbs/_breadcrumbs.scss +63 -65
  49. package/components/breadcrumbs/_macro.njk +12 -4
  50. package/components/breadcrumbs/_macro.spec.js +91 -91
  51. package/components/browser-banner/_browser-banner.scss +23 -23
  52. package/components/browser-banner/_macro.njk +6 -3
  53. package/components/browser-banner/_macro.spec.js +92 -92
  54. package/components/button/_button.scss +525 -491
  55. package/components/button/_macro.njk +63 -62
  56. package/components/button/_macro.spec.js +363 -363
  57. package/components/button/button.dom.js +15 -15
  58. package/components/button/button.js +53 -53
  59. package/components/button/button.spec.js +248 -240
  60. package/components/button/example-button-ghost.njk +1 -0
  61. package/components/call-to-action/_call-to-action.scss +5 -5
  62. package/components/call-to-action/_macro.njk +7 -5
  63. package/components/call-to-action/_macro.spec.js +28 -28
  64. package/components/call-to-action/example-call-to-action-default.njk +3 -2
  65. package/components/card/_card.scss +23 -23
  66. package/components/card/_macro.njk +26 -10
  67. package/components/card/_macro.spec.js +180 -180
  68. package/components/card/example-card-set-with-images.njk +31 -29
  69. package/components/card/example-card-set-with-lists.njk +58 -56
  70. package/components/card/example-card-set.njk +28 -26
  71. package/components/card/example-card.njk +9 -7
  72. package/components/char-check-limit/_macro.njk +1 -3
  73. package/components/char-check-limit/_macro.spec.js +48 -48
  74. package/components/char-check-limit/character-check.js +58 -58
  75. package/components/char-check-limit/character-check.spec.js +173 -173
  76. package/components/char-check-limit/character-limit.js +40 -40
  77. package/components/checkboxes/_checkbox-macro.njk +19 -15
  78. package/components/checkboxes/_checkbox-macro.spec.js +355 -355
  79. package/components/checkboxes/_checkbox.scss +180 -180
  80. package/components/checkboxes/_checkboxes.scss +37 -27
  81. package/components/checkboxes/_macro.njk +81 -72
  82. package/components/checkboxes/_macro.spec.js +261 -261
  83. package/components/checkboxes/checkbox-with-autoselect.js +32 -32
  84. package/components/checkboxes/checkbox-with-fieldset.js +21 -21
  85. package/components/checkboxes/checkboxes-with-reveal.js +10 -10
  86. package/components/checkboxes/checkboxes.dom.js +27 -27
  87. package/components/checkboxes/checkboxes.spec.js +183 -183
  88. package/components/checkboxes/example-checkboxes-disabled.njk +30 -30
  89. package/components/checkboxes/example-checkboxes-error.njk +0 -1
  90. package/components/checkboxes/example-checkboxes-with-descriptions.njk +7 -5
  91. package/components/checkboxes/example-checkboxes-with-hidden-label.njk +162 -170
  92. package/components/checkboxes/example-checkboxes-with-revealed-checkboxes-expanded.njk +81 -81
  93. package/components/checkboxes/example-checkboxes-with-revealed-checkboxes.njk +79 -79
  94. package/components/checkboxes/example-checkboxes-with-revealed-select-expanded.njk +7 -5
  95. package/components/checkboxes/example-checkboxes-with-revealed-select.njk +7 -5
  96. package/components/checkboxes/example-checkboxes-with-revealed-text-input-expanded.njk +7 -5
  97. package/components/checkboxes/example-checkboxes-with-revealed-text-input.njk +7 -5
  98. package/components/checkboxes/example-checkboxes-with-select-all-button.njk +7 -5
  99. package/components/checkboxes/example-checkboxes-with-visible-text-input.njk +7 -5
  100. package/components/checkboxes/example-checkboxes.njk +7 -5
  101. package/components/content-pagination/_content-pagination.scss +41 -41
  102. package/components/content-pagination/_macro.njk +34 -32
  103. package/components/content-pagination/_macro.spec.js +159 -159
  104. package/components/content-pagination/example-content-pagination.njk +17 -17
  105. package/components/cookies-banner/_cookies-banner.scss +22 -22
  106. package/components/cookies-banner/_macro.njk +19 -6
  107. package/components/cookies-banner/_macro.spec.js +177 -177
  108. package/components/cookies-banner/cookies-banner.dom.js +7 -7
  109. package/components/cookies-banner/cookies-banner.js +76 -76
  110. package/components/cookies-banner/cookies-banner.spec.js +72 -68
  111. package/components/cookies-banner/example-cookies-banner-cymraeg.njk +2 -1
  112. package/components/cookies-banner/example-cookies-banner.njk +3 -4
  113. package/components/date-input/_macro.njk +71 -63
  114. package/components/date-input/_macro.spec.js +338 -338
  115. package/components/date-input/example-date-input-error-for-single-field.njk +0 -1
  116. package/components/date-input/example-date-input-error.njk +0 -1
  117. package/components/description-list/_description-list.scss +23 -23
  118. package/components/description-list/_macro.njk +20 -11
  119. package/components/description-list/_macro.spec.js +144 -144
  120. package/components/details/_details.scss +109 -109
  121. package/components/details/_macro.njk +18 -11
  122. package/components/details/_macro.spec.js +132 -132
  123. package/components/details/details.dom.js +6 -6
  124. package/components/details/details.js +60 -60
  125. package/components/details/details.spec.js +106 -106
  126. package/components/details/example-details-with-warning.njk +15 -10
  127. package/components/document-list/_macro.njk +102 -93
  128. package/components/document-list/_macro.spec.js +444 -444
  129. package/components/document-list/document-list.scss +145 -149
  130. package/components/document-list/example-document-list-article-featured.njk +27 -25
  131. package/components/document-list/example-document-list-articles.njk +55 -53
  132. package/components/document-list/example-document-list-downloads.njk +49 -47
  133. package/components/document-list/example-document-list-search-result-featured.njk +19 -17
  134. package/components/document-list/example-document-list-search-results.njk +60 -58
  135. package/components/download-resources/_download-resources.scss +109 -108
  136. package/components/download-resources/download-resources.js +907 -900
  137. package/components/download-resources/download-resources.spec.js +461 -461
  138. package/components/duration/_macro.njk +61 -55
  139. package/components/duration/_macro.spec.js +291 -291
  140. package/components/duration/example-duration-error-for-single-field.njk +28 -26
  141. package/components/duration/example-duration-single-field.njk +23 -19
  142. package/components/duration/example-duration.njk +33 -29
  143. package/components/error/_macro.njk +8 -6
  144. package/components/error/_macro.spec.js +72 -72
  145. package/components/external-link/_external-link.scss +19 -19
  146. package/components/external-link/_macro.njk +7 -5
  147. package/components/external-link/_macro.spec.js +68 -68
  148. package/components/external-link/example-external-link.njk +9 -6
  149. package/components/feedback/_feedback.scss +31 -31
  150. package/components/feedback/_macro.njk +7 -5
  151. package/components/feedback/_macro.spec.js +72 -72
  152. package/components/field/_field-group.scss +10 -10
  153. package/components/field/_field.scss +16 -16
  154. package/components/field/_macro.njk +2 -2
  155. package/components/field/_macro.spec.js +80 -80
  156. package/components/fieldset/_fieldset.scss +27 -27
  157. package/components/fieldset/_macro.njk +23 -16
  158. package/components/fieldset/_macro.spec.js +161 -161
  159. package/components/footer/_footer.scss +45 -45
  160. package/components/footer/_macro.njk +28 -21
  161. package/components/footer/_macro.spec.js +452 -452
  162. package/components/footer/example-footer-cymraeg.njk +2 -1
  163. package/components/footer/example-footer-default.njk +3 -4
  164. package/components/footer/example-footer-transactional.njk +2 -1
  165. package/components/footer/example-footer-warning.njk +2 -1
  166. package/components/footer/example-footer-with-alternative-organisation.njk +2 -1
  167. package/components/footer/example-footer-with-coat-of-arms.njk +2 -1
  168. package/components/footer/example-footer-with-copyright.njk +2 -1
  169. package/components/footer/example-footer.njk +2 -1
  170. package/components/header/_header.scss +207 -202
  171. package/components/header/_macro.njk +183 -141
  172. package/components/header/_macro.spec.js +833 -829
  173. package/components/header/example-header-default.njk +2 -1
  174. package/components/header/example-header-external-for-survey-with-description.njk +2 -1
  175. package/components/header/example-header-external-for-surveys.njk +2 -1
  176. package/components/header/example-header-external-welsh.njk +7 -7
  177. package/components/header/example-header-external-with-navigation-and-search.njk +3 -2
  178. package/components/header/example-header-external-with-navigation.njk +2 -1
  179. package/components/header/example-header-external-with-service-links.njk +2 -1
  180. package/components/header/example-header-external-with-sub-navigation-removed.njk +2 -1
  181. package/components/header/example-header-external-with-sub-navigation.njk +3 -2
  182. package/components/header/example-header-internal.njk +2 -1
  183. package/components/header/example-header-multiple-logos.njk +2 -1
  184. package/components/header/{example-header-neutral-for-multicoloured-logo.njk → example-header-neutral.njk} +2 -1
  185. package/components/helpers/_grid.scss +4 -4
  186. package/components/helpers/grid.njk +17 -16
  187. package/components/hero/_hero.scss +48 -48
  188. package/components/hero/_macro.njk +6 -11
  189. package/components/hero/_macro.spec.js +59 -59
  190. package/components/hero/example-hero-dark.njk +2 -1
  191. package/components/hero/example-hero-default.njk +2 -1
  192. package/components/icon/_icon.scss +44 -44
  193. package/components/icon/_macro.njk +601 -168
  194. package/components/icon/_macro.spec.js +110 -110
  195. package/components/image/_image.scss +11 -11
  196. package/components/image/_macro.njk +7 -5
  197. package/components/image/_macro.spec.js +81 -81
  198. package/components/input/_input-type.scss +86 -89
  199. package/components/input/_input.scss +123 -124
  200. package/components/input/_macro.njk +114 -95
  201. package/components/input/_macro.spec.js +604 -604
  202. package/components/input/character-check.dom.js +5 -5
  203. package/components/input/example-input-search-with-character-check.njk +1 -1
  204. package/components/input/example-input-search-with-placeholder.njk +1 -1
  205. package/components/input/example-input-search.njk +1 -1
  206. package/components/input/input.dom.js +5 -5
  207. package/components/input/input.js +10 -10
  208. package/components/input/input.spec.js +18 -18
  209. package/components/label/_label.scss +24 -24
  210. package/components/label/_macro.njk +32 -26
  211. package/components/label/_macro.spec.js +173 -170
  212. package/components/language-selector/_macro.njk +11 -2
  213. package/components/language-selector/_macro.spec.js +97 -97
  214. package/components/language-selector/language.scss +7 -7
  215. package/components/list/_list.scss +110 -97
  216. package/components/list/_macro.njk +93 -73
  217. package/components/list/_macro.spec.js +583 -583
  218. package/components/message/_macro.njk +20 -7
  219. package/components/message/_macro.spec.js +74 -74
  220. package/components/message/_message.scss +39 -39
  221. package/components/message-list/_macro.njk +26 -20
  222. package/components/message-list/_macro.spec.js +86 -86
  223. package/components/message-list/_message-list.scss +16 -16
  224. package/components/modal/_macro.njk +11 -12
  225. package/components/modal/_macro.spec.js +69 -69
  226. package/components/modal/_modal.scss +36 -36
  227. package/components/modal/modal.dom.js +6 -6
  228. package/components/modal/modal.js +89 -89
  229. package/components/modal/modal.spec.js +50 -50
  230. package/components/multiple-input-fields/_macro.njk +30 -28
  231. package/components/mutually-exclusive/_macro.njk +20 -13
  232. package/components/mutually-exclusive/_macro.spec.js +140 -140
  233. package/components/mutually-exclusive/example-mutually-exclusive-checkboxes.njk +6 -4
  234. package/components/mutually-exclusive/example-mutually-exclusive-date.njk +7 -5
  235. package/components/mutually-exclusive/example-mutually-exclusive-duration.njk +44 -40
  236. package/components/mutually-exclusive/example-mutually-exclusive-email.njk +7 -5
  237. package/components/mutually-exclusive/example-mutually-exclusive-multiple-options.njk +6 -4
  238. package/components/mutually-exclusive/example-mutually-exclusive-number.njk +6 -4
  239. package/components/mutually-exclusive/example-mutually-exclusive-textarea.njk +6 -4
  240. package/components/mutually-exclusive/mutually-exclusive.checkboxes.spec.js +188 -188
  241. package/components/mutually-exclusive/mutually-exclusive.date.spec.js +211 -211
  242. package/components/mutually-exclusive/mutually-exclusive.dom.js +5 -5
  243. package/components/mutually-exclusive/mutually-exclusive.duration.spec.js +210 -210
  244. package/components/mutually-exclusive/mutually-exclusive.email.spec.js +90 -90
  245. package/components/mutually-exclusive/mutually-exclusive.js +137 -137
  246. package/components/mutually-exclusive/mutually-exclusive.multiple-options.checkboxes.spec.js +197 -197
  247. package/components/mutually-exclusive/mutually-exclusive.number.spec.js +96 -96
  248. package/components/mutually-exclusive/mutually-exclusive.textarea.spec.js +102 -102
  249. package/components/navigation/_macro.njk +133 -67
  250. package/components/navigation/_macro.spec.js +360 -354
  251. package/components/navigation/_navigation.scss +112 -122
  252. package/components/navigation/navigation.dom.js +35 -35
  253. package/components/navigation/navigation.js +49 -49
  254. package/components/navigation/navigation.spec.js +249 -249
  255. package/components/pagination/_macro.njk +42 -20
  256. package/components/pagination/_macro.spec.js +342 -335
  257. package/components/pagination/_pagination.scss +58 -58
  258. package/components/panel/_macro.njk +27 -16
  259. package/components/panel/_macro.spec.js +372 -372
  260. package/components/panel/_panel.scss +200 -199
  261. package/components/panel/example-panel-bare.njk +6 -4
  262. package/components/panel/example-panel-with-announcement.njk +7 -4
  263. package/components/panel/example-panel-with-error-summary.njk +6 -4
  264. package/components/panel/example-panel-with-warning.njk +5 -3
  265. package/components/password/_macro.njk +7 -5
  266. package/components/password/_macro.spec.js +95 -95
  267. package/components/password/password.dom.js +5 -5
  268. package/components/password/password.js +10 -10
  269. package/components/password/password.spec.js +26 -26
  270. package/components/phase-banner/_macro.njk +3 -3
  271. package/components/phase-banner/_macro.spec.js +86 -86
  272. package/components/phase-banner/_phase-banner.scss +16 -16
  273. package/components/phase-banner/example-phase-banner-alpha.njk +2 -1
  274. package/components/phase-banner/example-phase-banner-beta.njk +4 -3
  275. package/components/question/_macro.njk +62 -47
  276. package/components/question/_macro.spec.js +235 -235
  277. package/components/question/_question.scss +24 -24
  278. package/components/question/example-question-ccs.njk +40 -35
  279. package/components/question/example-question-fieldset.njk +84 -80
  280. package/components/question/example-question-interviewer-note.njk +27 -24
  281. package/components/question/example-question-no-fieldset.njk +39 -33
  282. package/components/quote/_macro.njk +3 -1
  283. package/components/quote/_macro.spec.js +52 -52
  284. package/components/quote/_quote.scss +24 -24
  285. package/components/radios/_macro.njk +54 -36
  286. package/components/radios/_macro.spec.js +545 -524
  287. package/components/radios/_radio.scss +49 -48
  288. package/components/radios/_radios.scss +14 -20
  289. package/components/radios/check-radios.js +21 -21
  290. package/components/radios/clear-radios.js +45 -45
  291. package/components/radios/example-radios-with-clear-button-expanded.njk +6 -4
  292. package/components/radios/example-radios-with-clear-button.njk +6 -4
  293. package/components/radios/example-radios-with-descriptions.njk +7 -5
  294. package/components/radios/example-radios-with-revealed-select-expanded.njk +6 -4
  295. package/components/radios/example-radios-with-revealed-select.njk +6 -4
  296. package/components/radios/example-radios-with-revealed-text-area-expanded.njk +7 -5
  297. package/components/radios/example-radios-with-revealed-text-area.njk +7 -5
  298. package/components/radios/example-radios-with-revealed-text-input-expanded.njk +7 -5
  299. package/components/radios/example-radios-with-revealed-text-input.njk +7 -5
  300. package/components/radios/example-radios-with-separator.njk +6 -4
  301. package/components/radios/example-radios-with-visible-text-input.njk +7 -5
  302. package/components/radios/example-radios-without-border.njk +0 -1
  303. package/components/radios/example-radios.njk +7 -5
  304. package/components/radios/radio-with-fieldset.js +22 -22
  305. package/components/radios/radios.dom.js +32 -32
  306. package/components/radios/radios.spec.js +251 -251
  307. package/components/related-content/_macro.njk +10 -11
  308. package/components/related-content/_macro.spec.js +109 -109
  309. package/components/related-content/_related-content.scss +12 -12
  310. package/components/related-content/_section-macro.njk +7 -7
  311. package/components/related-content/_section-macro.spec.js +20 -20
  312. package/components/related-content/example-related-content-general.njk +5 -3
  313. package/components/related-content/example-related-content-multiple-rows-of-links.njk +51 -49
  314. package/components/related-content/example-related-content-social-media.njk +40 -38
  315. package/components/relationships/_macro.njk +10 -8
  316. package/components/relationships/_macro.spec.js +94 -94
  317. package/components/relationships/_relationships.scss +9 -9
  318. package/components/relationships/example-relationships-error.njk +176 -168
  319. package/components/relationships/example-relationships-you.njk +169 -163
  320. package/components/relationships/example-relationships.njk +167 -161
  321. package/components/relationships/relationships.dom.js +5 -5
  322. package/components/relationships/relationships.js +18 -18
  323. package/components/relationships/relationships.spec.js +71 -71
  324. package/components/reply/_macro.spec.js +47 -47
  325. package/components/reply/reply-input.js +15 -15
  326. package/components/reply/reply.dom.js +5 -5
  327. package/components/reply/reply.spec.js +57 -57
  328. package/components/section-navigation/_macro.njk +34 -12
  329. package/components/section-navigation/_macro.spec.js +210 -210
  330. package/components/section-navigation/_section-navigation.scss +76 -76
  331. package/components/select/_macro.njk +21 -18
  332. package/components/select/_macro.spec.js +166 -166
  333. package/components/share-page/_macro.njk +10 -5
  334. package/components/share-page/_macro.spec.js +68 -68
  335. package/components/skip-to-content/_macro.njk +1 -1
  336. package/components/skip-to-content/_macro.spec.js +54 -54
  337. package/components/skip-to-content/_skip.scss +30 -30
  338. package/components/skip-to-content/example-skip-to-content.njk +1 -0
  339. package/components/skip-to-content/skip-to-content.dom.js +6 -6
  340. package/components/skip-to-content/skip-to-content.js +7 -7
  341. package/components/skip-to-content/skip-to-content.spec.js +21 -21
  342. package/components/status/_macro.njk +1 -1
  343. package/components/status/_macro.spec.js +53 -53
  344. package/components/status/_status.scss +32 -32
  345. package/components/summary/_macro.njk +53 -23
  346. package/components/summary/_macro.spec.js +551 -535
  347. package/components/summary/_summary.scss +191 -195
  348. package/components/summary/example-summary-household-no-rows.njk +18 -16
  349. package/components/summary/example-summary-household.njk +75 -73
  350. package/components/summary/example-summary-hub-minimal.njk +74 -72
  351. package/components/summary/example-summary-hub.njk +169 -167
  352. package/components/table/_macro.njk +72 -45
  353. package/components/table/_macro.spec.js +499 -499
  354. package/components/table/_table.scss +204 -201
  355. package/components/table/scrollable-table.dom.js +5 -5
  356. package/components/table/scrollable-table.js +60 -60
  357. package/components/table/sortable-table.dom.js +5 -5
  358. package/components/table/sortable-table.js +135 -135
  359. package/components/table/table.spec.js +144 -140
  360. package/components/table-of-contents/_macro.njk +34 -32
  361. package/components/table-of-contents/_macro.spec.js +125 -125
  362. package/components/table-of-contents/_toc.scss +9 -9
  363. package/components/table-of-contents/example-table-of-contents-grouped.njk +1 -1
  364. package/components/table-of-contents/example-table-of-contents-single.njk +1 -1
  365. package/components/table-of-contents/example-table-of-contents-sticky-full-page.njk +79 -38
  366. package/components/table-of-contents/example-table-of-contents-sticky.njk +50 -13
  367. package/components/table-of-contents/toc.dom.js +5 -5
  368. package/components/table-of-contents/toc.js +30 -30
  369. package/components/table-of-contents/toc.spec.js +88 -88
  370. package/components/tabs/_macro.njk +12 -6
  371. package/components/tabs/_macro.spec.js +92 -92
  372. package/components/tabs/_tabs.scss +120 -115
  373. package/components/tabs/example-tabs-details.njk +5 -6
  374. package/components/tabs/tabs.dom.js +5 -5
  375. package/components/tabs/tabs.js +266 -266
  376. package/components/tabs/tabs.spec.js +268 -268
  377. package/components/text-indent/_macro.njk +1 -3
  378. package/components/text-indent/_macro.spec.js +33 -33
  379. package/components/text-indent/_text-indent.scss +3 -3
  380. package/components/textarea/_macro.njk +49 -46
  381. package/components/textarea/_macro.spec.js +227 -238
  382. package/components/textarea/textarea.dom.js +5 -5
  383. package/components/textarea/textarea.spec.js +78 -74
  384. package/components/timeline/_macro.njk +4 -6
  385. package/components/timeline/_macro.spec.js +83 -83
  386. package/components/timeline/_timeline.scss +26 -26
  387. package/components/timeout-modal/_macro.njk +21 -19
  388. package/components/timeout-modal/_macro.spec.js +47 -47
  389. package/components/timeout-modal/example-timeout-modal.njk +16 -14
  390. package/components/timeout-modal/timeout-modal.dom.js +9 -9
  391. package/components/timeout-modal/timeout-modal.js +66 -66
  392. package/components/timeout-modal/timeout-modal.spec.js +157 -157
  393. package/components/timeout-panel/_macro.njk +19 -17
  394. package/components/timeout-panel/_macro.spec.js +41 -41
  395. package/components/timeout-panel/example-panel-with-timeout-warning.njk +13 -11
  396. package/components/timeout-panel/timeout-panel.dom.js +8 -8
  397. package/components/timeout-panel/timeout-panel.spec.js +118 -118
  398. package/components/upload/_macro.njk +20 -16
  399. package/components/upload/_macro.spec.js +52 -52
  400. package/components/upload/_upload.scss +28 -28
  401. package/components/video/_macro.njk +16 -2
  402. package/components/video/_macro.spec.js +42 -42
  403. package/components/video/_video.scss +16 -16
  404. package/components/video/example-video.njk +2 -2
  405. package/components/video/video.dom.js +5 -5
  406. package/components/video/video.js +32 -32
  407. package/components/video/video.spec.js +103 -97
  408. package/css/main.css +1 -1
  409. package/favicons/manifest.json +25 -25
  410. package/js/abortable-fetch.js +23 -23
  411. package/js/analytics.js +53 -53
  412. package/js/cookies-functions.js +135 -135
  413. package/js/cookies-settings.dom.js +7 -7
  414. package/js/cookies-settings.js +77 -77
  415. package/js/cookies-settings.spec.js +106 -106
  416. package/js/domready.js +8 -8
  417. package/js/fetch.js +14 -14
  418. package/js/inpagelink.dom.js +5 -5
  419. package/js/inpagelink.js +19 -19
  420. package/js/polyfills.js +0 -1
  421. package/js/print-button.js +6 -6
  422. package/js/timeout.js +211 -211
  423. package/layout/_dsTemplate.njk +22 -20
  424. package/layout/_template.njk +63 -51
  425. package/package.json +132 -128
  426. package/scripts/main.es5.js +1 -1
  427. package/scripts/main.js +1 -1
  428. package/scss/base/_forms.scss +10 -10
  429. package/scss/base/_global.scss +45 -44
  430. package/scss/base/_typography.scss +20 -20
  431. package/scss/helpers/_functions.scss +18 -15
  432. package/scss/helpers/_mixins.scss +59 -53
  433. package/scss/helpers/_mq.scss +62 -65
  434. package/scss/objects/_container.scss +20 -20
  435. package/scss/objects/_page.scss +33 -33
  436. package/scss/objects/_spacing.scss +10 -10
  437. package/scss/overrides/hcm.scss +237 -237
  438. package/scss/overrides/rtl.scss +95 -95
  439. package/scss/print.scss +47 -47
  440. package/scss/utilities/_border.scss +7 -7
  441. package/scss/utilities/_colors.scss +6 -6
  442. package/scss/utilities/_display.scss +8 -8
  443. package/scss/utilities/_float.scss +7 -7
  444. package/scss/utilities/_grid.scss +144 -144
  445. package/scss/utilities/_highlight.scss +4 -4
  446. package/scss/utilities/_margin.scss +17 -17
  447. package/scss/utilities/_pad.scss +15 -15
  448. package/scss/utilities/_typography.scss +35 -33
  449. package/scss/utilities/_utilities.scss +8 -8
  450. package/scss/utilities/_visibility.scss +25 -25
  451. package/scss/vars/_colors.scss +116 -116
  452. package/scss/vars/_forms.scss +22 -22
  453. package/scss/vars/_grid.scss +11 -9
  454. package/scss/vars/_typography.scss +54 -54
@@ -2,1079 +2,1086 @@
2
2
  function Util() {}
3
3
 
4
4
  /*
5
- Class manipulation functions
5
+ Class manipulation functions
6
6
  */
7
7
 
8
8
  Util.hasClass = function (el, className) {
9
- if (el.classList) return el.classList.contains(className);
10
- else return !!el.className.match(new RegExp('(\\s|^)' + className + '(\\s|$)'));
9
+ if (el.classList) return el.classList.contains(className);
10
+ else return !!el.className.match(new RegExp('(\\s|^)' + className + '(\\s|$)'));
11
11
  };
12
12
 
13
13
  Util.addClass = function (el, className) {
14
- let classList = className.split(' ');
15
- if (el.classList) el.classList.add(classList[0]);
16
- else if (!Util.hasClass(el, classList[0])) el.className += ' ' + classList[0];
17
- if (classList.length > 1) Util.addClass(el, classList.slice(1).join(' '));
14
+ let classList = className.split(' ');
15
+ if (el.classList) el.classList.add(classList[0]);
16
+ else if (!Util.hasClass(el, classList[0])) el.className += ' ' + classList[0];
17
+ if (classList.length > 1) Util.addClass(el, classList.slice(1).join(' '));
18
18
  };
19
19
 
20
20
  Util.removeClass = function (el, className) {
21
- let classList = className.split(' ');
22
- if (el.classList) el.classList.remove(classList[0]);
23
- else if (Util.hasClass(el, classList[0])) {
24
- let reg = new RegExp('(\\s|^)' + classList[0] + '(\\s|$)');
25
- el.className = el.className.replace(reg, ' ');
26
- }
27
- if (classList.length > 1) Util.removeClass(el, classList.slice(1).join(' '));
21
+ let classList = className.split(' ');
22
+ if (el.classList) el.classList.remove(classList[0]);
23
+ else if (Util.hasClass(el, classList[0])) {
24
+ let reg = new RegExp('(\\s|^)' + classList[0] + '(\\s|$)');
25
+ el.className = el.className.replace(reg, ' ');
26
+ }
27
+ if (classList.length > 1) Util.removeClass(el, classList.slice(1).join(' '));
28
28
  };
29
29
 
30
30
  Util.toggleClass = function (el, className, bool) {
31
- if (bool) Util.addClass(el, className);
32
- else Util.removeClass(el, className);
31
+ if (bool) Util.addClass(el, className);
32
+ else Util.removeClass(el, className);
33
33
  };
34
34
 
35
35
  Util.setAttributes = function (el, attrs) {
36
- for (let key in attrs) {
37
- el.setAttribute(key, attrs[key]);
38
- }
36
+ for (let key in attrs) {
37
+ el.setAttribute(key, attrs[key]);
38
+ }
39
39
  };
40
40
 
41
41
  /*
42
- DOM manipulation
42
+ DOM manipulation
43
43
  */
44
44
 
45
45
  Util.getChildrenByClassName = function (el, className) {
46
- let childrenByClass = [];
47
- for (let i = 0; i < el.children.length; i++) {
48
- if (Util.hasClass(el.children[i], className)) childrenByClass.push(el.children[i]);
49
- }
50
- return childrenByClass;
46
+ let childrenByClass = [];
47
+ for (let i = 0; i < el.children.length; i++) {
48
+ if (Util.hasClass(el.children[i], className)) childrenByClass.push(el.children[i]);
49
+ }
50
+ return childrenByClass;
51
51
  };
52
52
 
53
53
  Util.is = function (elem, selector) {
54
- if (selector.nodeType) {
55
- return elem === selector;
56
- }
54
+ if (selector.nodeType) {
55
+ return elem === selector;
56
+ }
57
57
 
58
- let qa = typeof selector === 'string' ? document.querySelectorAll(selector) : selector,
59
- length = qa.length;
58
+ let qa = typeof selector === 'string' ? document.querySelectorAll(selector) : selector,
59
+ length = qa.length;
60
60
 
61
- while (length--) {
62
- if (qa[length] === elem) {
63
- return true;
61
+ while (length--) {
62
+ if (qa[length] === elem) {
63
+ return true;
64
+ }
64
65
  }
65
- }
66
66
 
67
- return false;
67
+ return false;
68
68
  };
69
69
 
70
70
  // Animate height of an element
71
71
  Util.setHeight = function (start, to, element, duration, cb) {
72
- let change = to - start,
73
- currentTime = null;
74
-
75
- let animateHeight = function (timestamp) {
76
- if (!currentTime) currentTime = timestamp;
77
- let progress = timestamp - currentTime;
78
- let val = parseInt((progress / duration) * change + start);
79
- element.style.height = val + 'px';
80
- if (progress < duration) {
81
- window.requestAnimationFrame(animateHeight);
82
- } else {
83
- cb();
84
- }
85
- };
72
+ let change = to - start,
73
+ currentTime = null;
74
+
75
+ let animateHeight = function (timestamp) {
76
+ if (!currentTime) currentTime = timestamp;
77
+ let progress = timestamp - currentTime;
78
+ let val = parseInt((progress / duration) * change + start);
79
+ element.style.height = val + 'px';
80
+ if (progress < duration) {
81
+ window.requestAnimationFrame(animateHeight);
82
+ } else {
83
+ cb();
84
+ }
85
+ };
86
86
 
87
- // Set the height of the element before starting animation -> fix bug on Safari
88
- element.style.height = start + 'px';
89
- window.requestAnimationFrame(animateHeight);
87
+ // Set the height of the element before starting animation -> fix bug on Safari
88
+ element.style.height = start + 'px';
89
+ window.requestAnimationFrame(animateHeight);
90
90
  };
91
91
 
92
92
  // Smooth Scroll
93
93
  Util.scrollTo = function (final, duration, cb, scrollEl) {
94
- let element = scrollEl || window;
95
- let start = element.scrollTop || document.documentElement.scrollTop,
96
- currentTime = null;
97
-
98
- if (!scrollEl) start = window.scrollY || document.documentElement.scrollTop;
99
-
100
- let animateScroll = function (timestamp) {
101
- if (!currentTime) currentTime = timestamp;
102
- let progress = timestamp - currentTime;
103
- if (progress > duration) progress = duration;
104
- let val = Math.easeInOutQuad(progress, start, final - start, duration);
105
- element.scrollTo(0, val);
106
- if (progress < duration) {
107
- window.requestAnimationFrame(animateScroll);
108
- } else {
109
- cb && cb();
110
- }
111
- };
94
+ let element = scrollEl || window;
95
+ let start = element.scrollTop || document.documentElement.scrollTop,
96
+ currentTime = null;
97
+
98
+ if (!scrollEl) start = window.scrollY || document.documentElement.scrollTop;
99
+
100
+ let animateScroll = function (timestamp) {
101
+ if (!currentTime) currentTime = timestamp;
102
+ let progress = timestamp - currentTime;
103
+ if (progress > duration) progress = duration;
104
+ let val = Math.easeInOutQuad(progress, start, final - start, duration);
105
+ element.scrollTo(0, val);
106
+ if (progress < duration) {
107
+ window.requestAnimationFrame(animateScroll);
108
+ } else {
109
+ cb && cb();
110
+ }
111
+ };
112
112
 
113
- window.requestAnimationFrame(animateScroll);
113
+ window.requestAnimationFrame(animateScroll);
114
114
  };
115
115
 
116
116
  /*
117
- Focus utility classes
117
+ Focus utility classes
118
118
  */
119
119
 
120
120
  // Move focus to an element
121
121
  Util.moveFocus = function (element) {
122
- if (!element) element = document.getElementsByTagName('body')[0];
123
- element.focus();
124
- if (document.activeElement !== element) {
125
- element.setAttribute('tabindex', '-1');
122
+ if (!element) element = document.getElementsByTagName('body')[0];
126
123
  element.focus();
127
- }
124
+ if (document.activeElement !== element) {
125
+ element.setAttribute('tabindex', '-1');
126
+ element.focus();
127
+ }
128
128
  };
129
129
 
130
130
  // Misc
131
131
  Util.getIndexInArray = function (array, el) {
132
- return Array.prototype.indexOf.call(array, el);
132
+ return Array.prototype.indexOf.call(array, el);
133
133
  };
134
134
 
135
135
  Util.cssSupports = function (property, value) {
136
- if ('CSS' in window) {
137
- return CSS.supports(property, value);
138
- } else {
139
- let jsProperty = property.replace(/-([a-z])/g, function (g) {
140
- return g[1].toUpperCase();
141
- });
142
- return jsProperty in document.body.style;
143
- }
136
+ if ('CSS' in window) {
137
+ return CSS.supports(property, value);
138
+ } else {
139
+ let jsProperty = property.replace(/-([a-z])/g, function (g) {
140
+ return g[1].toUpperCase();
141
+ });
142
+ return jsProperty in document.body.style;
143
+ }
144
144
  };
145
145
 
146
146
  // Merge a set of user options into plugin defaults
147
147
  // https://gomakethings.com/vanilla-javascript-version-of-jquery-extend/
148
148
 
149
149
  Util.extend = function () {
150
- // Variables
151
- let extended = {};
152
- let deep = false;
153
- let i = 0;
154
- let length = arguments.length;
155
-
156
- // Check if a deep merge
157
- if (Object.prototype.toString.call(arguments[0]) === '[object Boolean]') {
158
- deep = arguments[0];
159
- i++;
160
- }
161
-
162
- // Merge the object into the extended object
163
- let merge = function (obj) {
164
- for (let prop in obj) {
165
- if (Object.prototype.hasOwnProperty.call(obj, prop)) {
166
- // If deep merge and property is an object, merge properties
167
- if (deep && Object.prototype.toString.call(obj[prop]) === '[object Object]') {
168
- extended[prop] = extend(true, extended[prop], obj[prop]);
169
- } else {
170
- extended[prop] = obj[prop];
171
- }
172
- }
150
+ // Variables
151
+ let extended = {};
152
+ let deep = false;
153
+ let i = 0;
154
+ let length = arguments.length;
155
+
156
+ // Check if a deep merge
157
+ if (Object.prototype.toString.call(arguments[0]) === '[object Boolean]') {
158
+ deep = arguments[0];
159
+ i++;
173
160
  }
174
- };
175
161
 
176
- // Loop through each object and conduct a merge
177
- for (; i < length; i++) {
178
- let obj = arguments[i];
179
- merge(obj);
180
- }
162
+ // Merge the object into the extended object
163
+ let merge = function (obj) {
164
+ for (let prop in obj) {
165
+ if (Object.prototype.hasOwnProperty.call(obj, prop)) {
166
+ // If deep merge and property is an object, merge properties
167
+ if (deep && Object.prototype.toString.call(obj[prop]) === '[object Object]') {
168
+ extended[prop] = extend(true, extended[prop], obj[prop]);
169
+ } else {
170
+ extended[prop] = obj[prop];
171
+ }
172
+ }
173
+ }
174
+ };
181
175
 
182
- return extended;
176
+ // Loop through each object and conduct a merge
177
+ for (; i < length; i++) {
178
+ let obj = arguments[i];
179
+ merge(obj);
180
+ }
181
+
182
+ return extended;
183
183
  };
184
184
 
185
185
  // Check if Reduced Motion is enabled
186
186
  Util.osHasReducedMotion = function () {
187
- if (!window.matchMedia) return false;
188
- let matchMediaObj = window.matchMedia('(prefers-reduced-motion: reduce)');
189
- if (matchMediaObj) return matchMediaObj.matches;
190
- return false; // Return false if not supported
187
+ if (!window.matchMedia) return false;
188
+ let matchMediaObj = window.matchMedia('(prefers-reduced-motion: reduce)');
189
+ if (matchMediaObj) return matchMediaObj.matches;
190
+ return false; // Return false if not supported
191
191
  };
192
192
 
193
193
  /*
194
- Polyfills
194
+ Polyfills
195
195
  */
196
196
 
197
197
  // Closest() method
198
198
  if (!Element.prototype.matches) {
199
- Element.prototype.matches = Element.prototype.msMatchesSelector || Element.prototype.webkitMatchesSelector;
199
+ Element.prototype.matches = Element.prototype.msMatchesSelector || Element.prototype.webkitMatchesSelector;
200
200
  }
201
201
 
202
202
  if (!Element.prototype.closest) {
203
- Element.prototype.closest = function (s) {
204
- let el = this;
205
- if (!document.documentElement.contains(el)) return null;
206
- do {
207
- if (el.matches(s)) return el;
208
- el = el.parentElement || el.parentNode;
209
- } while (el !== null && el.nodeType === 1);
210
- return null;
211
- };
203
+ Element.prototype.closest = function (s) {
204
+ let el = this;
205
+ if (!document.documentElement.contains(el)) return null;
206
+ do {
207
+ if (el.matches(s)) return el;
208
+ el = el.parentElement || el.parentNode;
209
+ } while (el !== null && el.nodeType === 1);
210
+ return null;
211
+ };
212
212
  }
213
213
 
214
214
  // Custom Event() constructor
215
215
  if (typeof window.CustomEvent !== 'function') {
216
- function CustomEvent(event, params) {
217
- params = params || { bubbles: false, cancelable: false, detail: undefined };
218
- let evt = document.createEvent('CustomEvent');
219
- evt.initCustomEvent(event, params.bubbles, params.cancelable, params.detail);
220
- return evt;
221
- }
216
+ function CustomEvent(event, params) {
217
+ params = params || { bubbles: false, cancelable: false, detail: undefined };
218
+ let evt = document.createEvent('CustomEvent');
219
+ evt.initCustomEvent(event, params.bubbles, params.cancelable, params.detail);
220
+ return evt;
221
+ }
222
222
 
223
- CustomEvent.prototype = window.Event.prototype;
223
+ CustomEvent.prototype = window.Event.prototype;
224
224
 
225
- window.CustomEvent = CustomEvent;
225
+ window.CustomEvent = CustomEvent;
226
226
  }
227
227
 
228
228
  /*
229
- Animation curves
229
+ Animation curves
230
230
  */
231
231
 
232
232
  Math.easeInOutQuad = function (t, b, c, d) {
233
- t /= d / 2;
234
- if (t < 1) return (c / 2) * t * t + b;
235
- t--;
236
- return (-c / 2) * (t * (t - 2) - 1) + b;
233
+ t /= d / 2;
234
+ if (t < 1) return (c / 2) * t * t + b;
235
+ t--;
236
+ return (-c / 2) * (t * (t - 2) - 1) + b;
237
237
  };
238
238
 
239
239
  // FILTERS
240
240
 
241
241
  (function () {
242
- let Filter = function (opts) {
243
- this.options = Util.extend(Filter.defaults, opts); // Used to store custom filter/sort functions
244
- this.element = this.options.element;
245
- this.elementId = this.element.getAttribute('id');
246
- this.items = this.element.querySelectorAll('.ons-js-filter__item');
247
- this.controllers = document.querySelectorAll('[aria-controls="' + this.elementId + '"]'); // Controllers wrappers
248
- this.fallbackMessage = document.querySelector('[data-fallback-gallery-id="' + this.elementId + '"]');
249
- this.filterString = []; // Combination of different filter values
250
- this.sortingString = ''; // Sort value - will include order and type of argument (e.g., number or string)
251
-
252
- // Store info about sorted/filtered items
253
- this.filterList = []; // List of boolean for each this.item -> true if still visible , otherwise false
254
- this.sortingList = []; // List of new ordered this.item -> each element is [item, originalIndex]
255
-
256
- // Store grid info for animation
257
- this.itemsGrid = []; // Grid coordinates
258
- this.itemsInitPosition = []; // Used to store coordinates of this.items before animation
259
- this.itemsIterPosition = []; // Used to store coordinates of this.items before animation - intermediate state
260
- this.itemsFinalPosition = []; // Used to store coordinates of this.items after filtering
261
-
262
- // Animation off
263
- this.animateOff = this.element.getAttribute('data-filter-animation') == 'off';
264
-
265
- // Used to update this.itemsGrid on resize
266
- this.resizingId = false;
267
-
268
- // Default acceleration style - improve animation
269
- this.accelerateStyle = 'will-change: transform, opacity; transform: translateZ(0); backface-visibility: hidden;';
270
-
271
- // Handle multiple changes
272
- this.animating = false;
273
- this.reanimate = false;
274
-
275
- initFilter(this);
276
- };
277
-
278
- function initFilter(filter) {
279
- resetFilterSortArray(filter, true, true); // Init array filter.filterList/filter.sortingList
280
- createGridInfo(filter); // Store grid coordinates in filter.itemsGrid
281
- initItemsOrder(filter); // Add data-orders so that we can reset the sorting
282
-
283
- // Events handling - filter update
284
- for (let i = 0; i < filter.controllers.length; i++) {
285
- filter.filterString[i] = ''; // Reset filtering
286
-
287
- // Get proper filter/sorting string based on selected controllers
288
- (function (i) {
289
- filter.controllers[i].addEventListener('change', function (event) {
290
- if (event.target.tagName.toLowerCase() == 'select') {
291
- // Select elements
292
- !event.target.getAttribute('data-filter')
293
- ? setSortingString(filter, event.target.value, event.target.options[event.target.selectedIndex])
294
- : setFilterString(filter, i, 'select');
295
- } else if (
296
- event.target.tagName.toLowerCase() == 'input' &&
297
- (event.target.getAttribute('type') == 'radio' || event.target.getAttribute('type') == 'checkbox')
298
- ) {
299
- // Input (radio/checkboxed) elements
300
- !event.target.getAttribute('data-filter')
301
- ? setSortingString(filter, event.target.getAttribute('data-sort'), event.target)
302
- : setFilterString(filter, i, 'input');
303
- } else {
304
- // Generic inout element
305
- !filter.controllers[i].getAttribute('data-filter')
306
- ? setSortingString(filter, filter.controllers[i].getAttribute('data-sort'), filter.controllers[i])
307
- : setFilterString(filter, i, 'custom');
308
- }
309
-
310
- updateFilterArray(filter);
242
+ let Filter = function (opts) {
243
+ this.options = Util.extend(Filter.defaults, opts); // Used to store custom filter/sort functions
244
+ this.element = this.options.element;
245
+ this.elementId = this.element.getAttribute('id');
246
+ this.items = this.element.querySelectorAll('.ons-js-filter__item');
247
+ this.controllers = document.querySelectorAll('[aria-controls="' + this.elementId + '"]'); // Controllers wrappers
248
+ this.fallbackMessage = document.querySelector('[data-fallback-gallery-id="' + this.elementId + '"]');
249
+ this.filterString = []; // Combination of different filter values
250
+ this.sortingString = ''; // Sort value - will include order and type of argument (e.g., number or string)
251
+
252
+ // Store info about sorted/filtered items
253
+ this.filterList = []; // List of boolean for each this.item -> true if still visible , otherwise false
254
+ this.sortingList = []; // List of new ordered this.item -> each element is [item, originalIndex]
255
+
256
+ // Store grid info for animation
257
+ this.itemsGrid = []; // Grid coordinates
258
+ this.itemsInitPosition = []; // Used to store coordinates of this.items before animation
259
+ this.itemsIterPosition = []; // Used to store coordinates of this.items before animation - intermediate state
260
+ this.itemsFinalPosition = []; // Used to store coordinates of this.items after filtering
261
+
262
+ // Animation off
263
+ this.animateOff = this.element.getAttribute('data-filter-animation') == 'off';
264
+
265
+ // Used to update this.itemsGrid on resize
266
+ this.resizingId = false;
267
+
268
+ // Default acceleration style - improve animation
269
+ this.accelerateStyle = 'will-change: transform, opacity; transform: translateZ(0); backface-visibility: hidden;';
270
+
271
+ // Handle multiple changes
272
+ this.animating = false;
273
+ this.reanimate = false;
274
+
275
+ initFilter(this);
276
+ };
277
+
278
+ function initFilter(filter) {
279
+ resetFilterSortArray(filter, true, true); // Init array filter.filterList/filter.sortingList
280
+ createGridInfo(filter); // Store grid coordinates in filter.itemsGrid
281
+ initItemsOrder(filter); // Add data-orders so that we can reset the sorting
282
+
283
+ // Events handling - filter update
284
+ for (let i = 0; i < filter.controllers.length; i++) {
285
+ filter.filterString[i] = ''; // Reset filtering
286
+
287
+ // Get proper filter/sorting string based on selected controllers
288
+ (function (i) {
289
+ filter.controllers[i].addEventListener('change', function (event) {
290
+ if (event.target.tagName.toLowerCase() == 'select') {
291
+ // Select elements
292
+ !event.target.getAttribute('data-filter')
293
+ ? setSortingString(filter, event.target.value, event.target.options[event.target.selectedIndex])
294
+ : setFilterString(filter, i, 'select');
295
+ } else if (
296
+ event.target.tagName.toLowerCase() == 'input' &&
297
+ (event.target.getAttribute('type') == 'radio' || event.target.getAttribute('type') == 'checkbox')
298
+ ) {
299
+ // Input (radio/checkboxed) elements
300
+ !event.target.getAttribute('data-filter')
301
+ ? setSortingString(filter, event.target.getAttribute('data-sort'), event.target)
302
+ : setFilterString(filter, i, 'input');
303
+ } else {
304
+ // Generic inout element
305
+ !filter.controllers[i].getAttribute('data-filter')
306
+ ? setSortingString(filter, filter.controllers[i].getAttribute('data-sort'), filter.controllers[i])
307
+ : setFilterString(filter, i, 'custom');
308
+ }
309
+
310
+ updateFilterArray(filter);
311
+ });
312
+
313
+ filter.controllers[i].addEventListener('click', function (event) {
314
+ // Return if target is select/input elements
315
+ let filterEl = event.target.closest('[data-filter]');
316
+ let sortEl = event.target.closest('[data-sort]');
317
+ if (!filterEl && !sortEl) return;
318
+ if (filterEl && (filterEl.tagName.toLowerCase() == 'input' || filterEl.tagName.toLowerCase() == 'select')) return;
319
+ if (sortEl && (sortEl.tagName.toLowerCase() == 'input' || sortEl.tagName.toLowerCase() == 'select')) return;
320
+ if (sortEl && Util.hasClass(sortEl, 'ons-js-filter__custom-control')) return;
321
+ if (filterEl && Util.hasClass(filterEl, 'ons-js-filter__custom-control')) return;
322
+
323
+ // This will be executed only for a list of buttons -> no inputs
324
+ event.preventDefault();
325
+ resetControllersList(filter, i, filterEl, sortEl);
326
+ sortEl ? setSortingString(filter, sortEl.getAttribute('data-sort'), sortEl) : setFilterString(filter, i, 'button');
327
+ updateFilterArray(filter);
328
+ });
329
+ })(i);
330
+ }
331
+
332
+ // Handle resize - update grid coordinates in filter.itemsGrid
333
+ window.addEventListener('resize', function () {
334
+ clearTimeout(filter.resizingId);
335
+ filter.resizingId = setTimeout(function () {
336
+ createGridInfo(filter);
337
+ }, 300);
311
338
  });
312
339
 
313
- filter.controllers[i].addEventListener('click', function (event) {
314
- // Return if target is select/input elements
315
- let filterEl = event.target.closest('[data-filter]');
316
- let sortEl = event.target.closest('[data-sort]');
317
- if (!filterEl && !sortEl) return;
318
- if (filterEl && (filterEl.tagName.toLowerCase() == 'input' || filterEl.tagName.toLowerCase() == 'select')) return;
319
- if (sortEl && (sortEl.tagName.toLowerCase() == 'input' || sortEl.tagName.toLowerCase() == 'select')) return;
320
- if (sortEl && Util.hasClass(sortEl, 'ons-js-filter__custom-control')) return;
321
- if (filterEl && Util.hasClass(filterEl, 'ons-js-filter__custom-control')) return;
322
-
323
- // This will be executed only for a list of buttons -> no inputs
324
- event.preventDefault();
325
- resetControllersList(filter, i, filterEl, sortEl);
326
- sortEl ? setSortingString(filter, sortEl.getAttribute('data-sort'), sortEl) : setFilterString(filter, i, 'button');
327
- updateFilterArray(filter);
340
+ // Check if there are filters/sorting values already set
341
+ checkInitialFiltering(filter);
342
+
343
+ // Reset filtering results if filter selection was changed by an external control (e.g., form reset)
344
+ filter.element.addEventListener('update-filter-results', function () {
345
+ // Reset filters first
346
+ for (let i = 0; i < filter.controllers.length; i++) filter.filterString[i] = '';
347
+ filter.sortingString = '';
348
+ checkInitialFiltering(filter);
328
349
  });
329
- })(i);
330
350
  }
331
351
 
332
- // Handle resize - update grid coordinates in filter.itemsGrid
333
- window.addEventListener('resize', function () {
334
- clearTimeout(filter.resizingId);
335
- filter.resizingId = setTimeout(function () {
336
- createGridInfo(filter);
337
- }, 300);
338
- });
339
-
340
- // Check if there are filters/sorting values already set
341
- checkInitialFiltering(filter);
342
-
343
- // Reset filtering results if filter selection was changed by an external control (e.g., form reset)
344
- filter.element.addEventListener('update-filter-results', function () {
345
- // Reset filters first
346
- for (let i = 0; i < filter.controllers.length; i++) filter.filterString[i] = '';
347
- filter.sortingString = '';
348
- checkInitialFiltering(filter);
349
- });
350
- }
351
-
352
- function checkInitialFiltering(filter) {
353
- for (let i = 0; i < filter.controllers.length; i++) {
354
- // Check if there’s a selected option
355
- // Buttons list
356
- let selectedButton = filter.controllers[i].getElementsByClassName('ons-js-filter-selected');
357
- if (selectedButton.length > 0) {
358
- let sort = selectedButton[0].getAttribute('data-sort');
359
- sort
360
- ? setSortingString(filter, selectedButton[0].getAttribute('data-sort'), selectedButton[0])
361
- : setFilterString(filter, i, 'button');
362
- continue;
363
- }
364
-
365
- // Input list
366
- let selectedInput = filter.controllers[i].querySelectorAll('input:checked');
367
- if (selectedInput.length > 0) {
368
- let sort = selectedInput[0].getAttribute('data-sort');
369
- sort ? setSortingString(filter, sort, selectedInput[0]) : setFilterString(filter, i, 'input');
370
- continue;
371
- }
372
-
373
- // Select item
374
- if (filter.controllers[i].tagName.toLowerCase() == 'select') {
375
- let sort = filter.controllers[i].getAttribute('data-sort');
376
- sort
377
- ? setSortingString(filter, filter.controllers[i].value, filter.controllers[i].options[filter.controllers[i].selectedIndex])
378
- : setFilterString(filter, i, 'select');
379
- continue;
380
- }
381
-
382
- // Check if there’s a generic custom input
383
- let radioInput = filter.controllers[i].querySelector('input[type="radio"]'),
384
- checkboxInput = filter.controllers[i].querySelector('input[type="checkbox"]');
385
- if (!radioInput && !checkboxInput) {
386
- let sort = filter.controllers[i].getAttribute('data-sort');
387
- let filterString = filter.controllers[i].getAttribute('data-filter');
388
- if (sort) setSortingString(filter, sort, filter.controllers[i]);
389
- else if (filterString) setFilterString(filter, i, 'custom');
390
- }
391
- }
352
+ function checkInitialFiltering(filter) {
353
+ for (let i = 0; i < filter.controllers.length; i++) {
354
+ // Check if there’s a selected option
355
+ // Buttons list
356
+ let selectedButton = filter.controllers[i].getElementsByClassName('ons-js-filter-selected');
357
+ if (selectedButton.length > 0) {
358
+ let sort = selectedButton[0].getAttribute('data-sort');
359
+ sort
360
+ ? setSortingString(filter, selectedButton[0].getAttribute('data-sort'), selectedButton[0])
361
+ : setFilterString(filter, i, 'button');
362
+ continue;
363
+ }
364
+
365
+ // Input list
366
+ let selectedInput = filter.controllers[i].querySelectorAll('input:checked');
367
+ if (selectedInput.length > 0) {
368
+ let sort = selectedInput[0].getAttribute('data-sort');
369
+ sort ? setSortingString(filter, sort, selectedInput[0]) : setFilterString(filter, i, 'input');
370
+ continue;
371
+ }
372
+
373
+ // Select item
374
+ if (filter.controllers[i].tagName.toLowerCase() == 'select') {
375
+ let sort = filter.controllers[i].getAttribute('data-sort');
376
+ sort
377
+ ? setSortingString(
378
+ filter,
379
+ filter.controllers[i].value,
380
+ filter.controllers[i].options[filter.controllers[i].selectedIndex],
381
+ )
382
+ : setFilterString(filter, i, 'select');
383
+ continue;
384
+ }
385
+
386
+ // Check if there’s a generic custom input
387
+ let radioInput = filter.controllers[i].querySelector('input[type="radio"]'),
388
+ checkboxInput = filter.controllers[i].querySelector('input[type="checkbox"]');
389
+ if (!radioInput && !checkboxInput) {
390
+ let sort = filter.controllers[i].getAttribute('data-sort');
391
+ let filterString = filter.controllers[i].getAttribute('data-filter');
392
+ if (sort) setSortingString(filter, sort, filter.controllers[i]);
393
+ else if (filterString) setFilterString(filter, i, 'custom');
394
+ }
395
+ }
392
396
 
393
- updateFilterArray(filter);
394
- }
395
-
396
- function setSortingString(filter, value, item) {
397
- // Get sorting string value-> sortName:order:type
398
- let order = item.getAttribute('data-sort-order') ? 'desc' : 'asc';
399
- let type = item.getAttribute('data-sort-number') ? 'number' : 'string';
400
- filter.sortingString = value + ':' + order + ':' + type;
401
- }
402
-
403
- function setFilterString(filter, index, type) {
404
- // Get filtering array -> [filter1:filter2, filter3, filter4:filter5]
405
- if (type == 'input') {
406
- let checkedInputs = filter.controllers[index].querySelectorAll('input:checked');
407
- filter.filterString[index] = '';
408
- for (let i = 0; i < checkedInputs.length; i++) {
409
- filter.filterString[index] = filter.filterString[index] + checkedInputs[i].getAttribute('data-filter') + ':';
410
- }
411
- } else if (type == 'select') {
412
- if (filter.controllers[index].multiple) {
413
- // Select with multiple options
414
- filter.filterString[index] = getMultipleSelectValues(filter.controllers[index]);
415
- } else {
416
- // Select with single option
417
- filter.filterString[index] = filter.controllers[index].value;
418
- }
419
- } else if (type == 'button') {
420
- let selectedButtons = filter.controllers[index].querySelectorAll('.ons-js-filter-selected');
421
- filter.filterString[index] = '';
422
- for (let i = 0; i < selectedButtons.length; i++) {
423
- filter.filterString[index] = filter.filterString[index] + selectedButtons[i].getAttribute('data-filter') + ':';
424
- }
425
- } else if (type == 'custom') {
426
- filter.filterString[index] = filter.controllers[index].getAttribute('data-filter');
427
- }
428
- }
429
-
430
- function resetControllersList(filter, index, target1, target2) {
431
- // For a <button>s list -> toggle js-filter-selected + custom classes
432
- let multi = filter.controllers[index].getAttribute('data-filter-checkbox'),
433
- customClass = filter.controllers[index].getAttribute('data-selected-class');
434
-
435
- customClass = customClass ? 'ons-js-filter-selected ' + customClass : 'ons-js-filter-selected';
436
- if (multi == 'true') {
437
- // Multiple options can be on
438
- target1
439
- ? Util.toggleClass(target1, customClass, !Util.hasClass(target1, 'ons-js-filter-selected'))
440
- : Util.toggleClass(target2, customClass, !Util.hasClass(target2, 'ons-js-filter-selected'));
441
- } else {
442
- // Only one element at the time
443
- // Remove the class from all siblings
444
- let selectedOption = filter.controllers[index].querySelector('.ons-js-filter-selected');
445
- if (selectedOption) Util.removeClass(selectedOption, customClass);
446
- target1 ? Util.addClass(target1, customClass) : Util.addClass(target2, customClass);
397
+ updateFilterArray(filter);
447
398
  }
448
- }
449
399
 
450
- function updateFilterArray(filter) {
451
- // Sort/filter strings have been updated -> so you can update the gallery
452
- if (filter.animating) {
453
- filter.reanimate = true;
454
- return;
455
- }
456
- filter.animating = true;
457
- filter.reanimate = false;
458
- createGridInfo(filter); // Get new grid coordinates
459
- sortingGallery(filter); // Update sorting list
460
- filteringGallery(filter); // Update filter list
461
- resetFallbackMessage(filter, true); // Toggle fallback message
462
- if (reducedMotion || filter.animateOff) {
463
- resetItems(filter);
464
- } else {
465
- updateItemsAttributes(filter);
466
- }
467
- }
468
-
469
- function sortingGallery(filter) {
470
- // Use sorting string to reorder gallery
471
- let sortOptions = filter.sortingString.split(':');
472
- if (sortOptions[0] == '' || sortOptions[0] == '*') {
473
- // No sorting needed
474
- restoreSortOrder(filter);
475
- } else {
476
- // Need to sort
477
- if (filter.options[sortOptions[0]]) {
478
- // Custom sort function -> user takes care of it
479
- filter.sortingList = filter.options[sortOptions[0]](filter.sortingList);
480
- } else {
481
- filter.sortingList.sort(function (left, right) {
482
- let leftVal = left[0].getAttribute('data-sort-' + sortOptions[0]),
483
- rightVal = right[0].getAttribute('data-sort-' + sortOptions[0]);
484
- if (sortOptions[2] == 'number') {
485
- leftVal = parseFloat(leftVal);
486
- rightVal = parseFloat(rightVal);
487
- }
488
- if (sortOptions[1] == 'desc') return leftVal <= rightVal ? 1 : -1;
489
- else return leftVal >= rightVal ? 1 : -1;
490
- });
491
- }
400
+ function setSortingString(filter, value, item) {
401
+ // Get sorting string value-> sortName:order:type
402
+ let order = item.getAttribute('data-sort-order') ? 'desc' : 'asc';
403
+ let type = item.getAttribute('data-sort-number') ? 'number' : 'string';
404
+ filter.sortingString = value + ':' + order + ':' + type;
492
405
  }
493
- }
494
-
495
- function filteringGallery(filter) {
496
- // Use filtering string to reorder gallery
497
- resetFilterSortArray(filter, true, false);
498
-
499
- // We can have multiple filters
500
- for (let i = 0; i < filter.filterString.length; i++) {
501
- // Check if multiple filters inside the same controller
502
- if (filter.filterString[i] != '' && filter.filterString[i] != '*' && filter.filterString[i] != ' ') {
503
- singleFilterGallery(filter, filter.filterString[i].split(':'));
504
- }
505
- }
506
- }
507
-
508
- function singleFilterGallery(filter, subfilter) {
509
- if (!subfilter || subfilter == '' || subfilter == '*') return;
510
-
511
- // Check if we have custom options
512
- let customFilterArray = [];
513
- for (let j = 0; j < subfilter.length; j++) {
514
- if (filter.options[subfilter[j]]) {
515
- // Custom function
516
- customFilterArray[subfilter[j]] = filter.options[subfilter[j]](filter.items);
517
- }
406
+
407
+ function setFilterString(filter, index, type) {
408
+ // Get filtering array -> [filter1:filter2, filter3, filter4:filter5]
409
+ if (type == 'input') {
410
+ let checkedInputs = filter.controllers[index].querySelectorAll('input:checked');
411
+ filter.filterString[index] = '';
412
+ for (let i = 0; i < checkedInputs.length; i++) {
413
+ filter.filterString[index] = filter.filterString[index] + checkedInputs[i].getAttribute('data-filter') + ':';
414
+ }
415
+ } else if (type == 'select') {
416
+ if (filter.controllers[index].multiple) {
417
+ // Select with multiple options
418
+ filter.filterString[index] = getMultipleSelectValues(filter.controllers[index]);
419
+ } else {
420
+ // Select with single option
421
+ filter.filterString[index] = filter.controllers[index].value;
422
+ }
423
+ } else if (type == 'button') {
424
+ let selectedButtons = filter.controllers[index].querySelectorAll('.ons-js-filter-selected');
425
+ filter.filterString[index] = '';
426
+ for (let i = 0; i < selectedButtons.length; i++) {
427
+ filter.filterString[index] = filter.filterString[index] + selectedButtons[i].getAttribute('data-filter') + ':';
428
+ }
429
+ } else if (type == 'custom') {
430
+ filter.filterString[index] = filter.controllers[index].getAttribute('data-filter');
431
+ }
518
432
  }
519
433
 
520
- for (let i = 0; i < filter.items.length; i++) {
521
- let filterValues = filter.items[i].getAttribute('data-filter').split(' ');
522
- let present = false;
523
- for (let j = 0; j < subfilter.length; j++) {
524
- if (filter.options[subfilter[j]] && customFilterArray[subfilter[j]][i]) {
525
- // Custom function
526
- present = true;
527
- break;
528
- } else if (subfilter[j] == '*' || filterValues.indexOf(subfilter[j]) > -1) {
529
- present = true;
530
- break;
434
+ function resetControllersList(filter, index, target1, target2) {
435
+ // For a <button>s list -> toggle js-filter-selected + custom classes
436
+ let multi = filter.controllers[index].getAttribute('data-filter-checkbox'),
437
+ customClass = filter.controllers[index].getAttribute('data-selected-class');
438
+
439
+ customClass = customClass ? 'ons-js-filter-selected ' + customClass : 'ons-js-filter-selected';
440
+ if (multi == 'true') {
441
+ // Multiple options can be on
442
+ target1
443
+ ? Util.toggleClass(target1, customClass, !Util.hasClass(target1, 'ons-js-filter-selected'))
444
+ : Util.toggleClass(target2, customClass, !Util.hasClass(target2, 'ons-js-filter-selected'));
445
+ } else {
446
+ // Only one element at the time
447
+ // Remove the class from all siblings
448
+ let selectedOption = filter.controllers[index].querySelector('.ons-js-filter-selected');
449
+ if (selectedOption) Util.removeClass(selectedOption, customClass);
450
+ target1 ? Util.addClass(target1, customClass) : Util.addClass(target2, customClass);
531
451
  }
532
- }
533
- filter.filterList[i] = !present ? false : filter.filterList[i];
534
452
  }
535
- }
536
-
537
- function updateItemsAttributes(filter) {
538
- // Set items before triggering the update animation
539
- // Get offset of all elements before animation
540
- storeOffset(filter, filter.itemsInitPosition);
541
-
542
- // Set height of container
543
- filter.element.setAttribute(
544
- 'style',
545
- 'height: ' + parseFloat(filter.element.offsetHeight) + 'px; width: ' + parseFloat(filter.element.offsetWidth) + 'px;',
546
- );
547
-
548
- for (let i = 0; i < filter.items.length; i++) {
549
- // Remove ons-u-hidden class from items now visible and scale to zero
550
- if (Util.hasClass(filter.items[i], 'ons-u-hidden') && filter.filterList[i]) {
551
- filter.items[i].setAttribute('data-scale', 'on');
552
- filter.items[i].setAttribute('style', filter.accelerateStyle + 'transform: scale(0.5); opacity: 0;');
553
- Util.removeClass(filter.items[i], 'ons-u-hidden');
554
- }
453
+
454
+ function updateFilterArray(filter) {
455
+ // Sort/filter strings have been updated -> so you can update the gallery
456
+ if (filter.animating) {
457
+ filter.reanimate = true;
458
+ return;
459
+ }
460
+ filter.animating = true;
461
+ filter.reanimate = false;
462
+ createGridInfo(filter); // Get new grid coordinates
463
+ sortingGallery(filter); // Update sorting list
464
+ filteringGallery(filter); // Update filter list
465
+ resetFallbackMessage(filter, true); // Toggle fallback message
466
+ if (reducedMotion || filter.animateOff) {
467
+ resetItems(filter);
468
+ } else {
469
+ updateItemsAttributes(filter);
470
+ }
555
471
  }
556
472
 
557
- // Get new elements offset
558
- storeOffset(filter, filter.itemsIterPosition);
559
-
560
- // Translate items so that they are in the right initial position
561
- for (let i = 0; i < filter.items.length; i++) {
562
- if (filter.items[i].getAttribute('data-scale') != 'on') {
563
- filter.items[i].setAttribute(
564
- 'style',
565
- filter.accelerateStyle +
566
- 'transform: translateX(' +
567
- parseInt(filter.itemsInitPosition[i][0] - filter.itemsIterPosition[i][0]) +
568
- 'px) translateY(' +
569
- parseInt(filter.itemsInitPosition[i][1] - filter.itemsIterPosition[i][1]) +
570
- 'px);',
571
- );
572
- }
473
+ function sortingGallery(filter) {
474
+ // Use sorting string to reorder gallery
475
+ let sortOptions = filter.sortingString.split(':');
476
+ if (sortOptions[0] == '' || sortOptions[0] == '*') {
477
+ // No sorting needed
478
+ restoreSortOrder(filter);
479
+ } else {
480
+ // Need to sort
481
+ if (filter.options[sortOptions[0]]) {
482
+ // Custom sort function -> user takes care of it
483
+ filter.sortingList = filter.options[sortOptions[0]](filter.sortingList);
484
+ } else {
485
+ filter.sortingList.sort(function (left, right) {
486
+ let leftVal = left[0].getAttribute('data-sort-' + sortOptions[0]),
487
+ rightVal = right[0].getAttribute('data-sort-' + sortOptions[0]);
488
+ if (sortOptions[2] == 'number') {
489
+ leftVal = parseFloat(leftVal);
490
+ rightVal = parseFloat(rightVal);
491
+ }
492
+ if (sortOptions[1] == 'desc') return leftVal <= rightVal ? 1 : -1;
493
+ else return leftVal >= rightVal ? 1 : -1;
494
+ });
495
+ }
496
+ }
573
497
  }
574
498
 
575
- animateItems(filter);
576
- }
499
+ function filteringGallery(filter) {
500
+ // Use filtering string to reorder gallery
501
+ resetFilterSortArray(filter, true, false);
577
502
 
578
- function animateItems(filter) {
579
- let transitionValue =
580
- 'transform ' + filter.options.duration + 'ms cubic-bezier(0.455, 0.03, 0.515, 0.955), opacity ' + filter.options.duration + 'ms';
503
+ // We can have multiple filters
504
+ for (let i = 0; i < filter.filterString.length; i++) {
505
+ // Check if multiple filters inside the same controller
506
+ if (filter.filterString[i] != '' && filter.filterString[i] != '*' && filter.filterString[i] != ' ') {
507
+ singleFilterGallery(filter, filter.filterString[i].split(':'));
508
+ }
509
+ }
510
+ }
581
511
 
582
- // Get new index of items in the list
583
- let j = 0;
584
- for (let i = 0; i < filter.sortingList.length; i++) {
585
- let item = filter.items[filter.sortingList[i][1]];
512
+ function singleFilterGallery(filter, subfilter) {
513
+ if (!subfilter || subfilter == '' || subfilter == '*') return;
586
514
 
587
- if (Util.hasClass(item, 'ons-u-hidden') || !filter.filterList[filter.sortingList[i][1]]) {
588
- // Item is hidden or was previously hidden -> final position equal to first one
589
- filter.itemsFinalPosition[filter.sortingList[i][1]] = filter.itemsIterPosition[filter.sortingList[i][1]];
590
- if (item.getAttribute('data-scale') == 'on') j = j + 1;
591
- } else {
592
- filter.itemsFinalPosition[filter.sortingList[i][1]] = [filter.itemsGrid[j][0], filter.itemsGrid[j][1]];
515
+ // Check if we have custom options
516
+ let customFilterArray = [];
517
+ for (let j = 0; j < subfilter.length; j++) {
518
+ if (filter.options[subfilter[j]]) {
519
+ // Custom function
520
+ customFilterArray[subfilter[j]] = filter.options[subfilter[j]](filter.items);
521
+ }
522
+ }
593
523
 
594
- // Left/top
595
- j = j + 1;
596
- }
524
+ for (let i = 0; i < filter.items.length; i++) {
525
+ let filterValues = filter.items[i].getAttribute('data-filter').split(' ');
526
+ let present = false;
527
+ for (let j = 0; j < subfilter.length; j++) {
528
+ if (filter.options[subfilter[j]] && customFilterArray[subfilter[j]][i]) {
529
+ // Custom function
530
+ present = true;
531
+ break;
532
+ } else if (subfilter[j] == '*' || filterValues.indexOf(subfilter[j]) > -1) {
533
+ present = true;
534
+ break;
535
+ }
536
+ }
537
+ filter.filterList[i] = !present ? false : filter.filterList[i];
538
+ }
597
539
  }
598
540
 
599
- setTimeout(function () {
600
- for (let i = 0; i < filter.items.length; i++) {
601
- if (filter.filterList[i] && filter.items[i].getAttribute('data-scale') == 'on') {
602
- // Scale up item
603
- filter.items[i].setAttribute(
604
- 'style',
605
- filter.accelerateStyle +
606
- 'transition: ' +
607
- transitionValue +
608
- '; transform: translateX(' +
609
- parseInt(filter.itemsFinalPosition[i][0] - filter.itemsIterPosition[i][0]) +
610
- 'px) translateY(' +
611
- parseInt(filter.itemsFinalPosition[i][1] - filter.itemsIterPosition[i][1]) +
612
- 'px) scale(1); opacity: 1;',
613
- );
614
- } else if (filter.filterList[i]) {
615
- // Translate item
616
- filter.items[i].setAttribute(
617
- 'style',
618
- filter.accelerateStyle +
619
- 'transition: ' +
620
- transitionValue +
621
- '; transform: translateX(' +
622
- parseInt(filter.itemsFinalPosition[i][0] - filter.itemsIterPosition[i][0]) +
623
- 'px) translateY(' +
624
- parseInt(filter.itemsFinalPosition[i][1] - filter.itemsIterPosition[i][1]) +
625
- 'px);',
626
- );
627
- } else {
628
- // Scale down item
629
- filter.items[i].setAttribute(
541
+ function updateItemsAttributes(filter) {
542
+ // Set items before triggering the update animation
543
+ // Get offset of all elements before animation
544
+ storeOffset(filter, filter.itemsInitPosition);
545
+
546
+ // Set height of container
547
+ filter.element.setAttribute(
630
548
  'style',
631
- filter.accelerateStyle + 'transition: ' + transitionValue + '; transform: scale(0.5); opacity: 0;',
632
- );
549
+ 'height: ' + parseFloat(filter.element.offsetHeight) + 'px; width: ' + parseFloat(filter.element.offsetWidth) + 'px;',
550
+ );
551
+
552
+ for (let i = 0; i < filter.items.length; i++) {
553
+ // Remove ons-u-hidden class from items now visible and scale to zero
554
+ if (Util.hasClass(filter.items[i], 'ons-u-hidden') && filter.filterList[i]) {
555
+ filter.items[i].setAttribute('data-scale', 'on');
556
+ filter.items[i].setAttribute('style', filter.accelerateStyle + 'transform: scale(0.5); opacity: 0;');
557
+ Util.removeClass(filter.items[i], 'ons-u-hidden');
558
+ }
633
559
  }
634
- }
635
- }, 50);
636
-
637
- // Wait for the end of transition of visible elements
638
- setTimeout(function () {
639
- resetItems(filter);
640
- }, filter.options.duration + 100);
641
- }
642
-
643
- function resetItems(filter) {
644
- // Animation was off or animation is over -> reset attributes
645
- for (let i = 0; i < filter.items.length; i++) {
646
- filter.items[i].removeAttribute('style');
647
- Util.toggleClass(filter.items[i], 'ons-u-hidden', !filter.filterList[i]);
648
- filter.items[i].removeAttribute('data-scale');
649
- }
650
560
 
651
- for (let i = 0; i < filter.items.length; i++) {
652
- // Reorder
653
- filter.element.appendChild(filter.items[filter.sortingList[i][1]]);
561
+ // Get new elements offset
562
+ storeOffset(filter, filter.itemsIterPosition);
563
+
564
+ // Translate items so that they are in the right initial position
565
+ for (let i = 0; i < filter.items.length; i++) {
566
+ if (filter.items[i].getAttribute('data-scale') != 'on') {
567
+ filter.items[i].setAttribute(
568
+ 'style',
569
+ filter.accelerateStyle +
570
+ 'transform: translateX(' +
571
+ parseInt(filter.itemsInitPosition[i][0] - filter.itemsIterPosition[i][0]) +
572
+ 'px) translateY(' +
573
+ parseInt(filter.itemsInitPosition[i][1] - filter.itemsIterPosition[i][1]) +
574
+ 'px);',
575
+ );
576
+ }
577
+ }
578
+
579
+ animateItems(filter);
654
580
  }
655
581
 
656
- filter.items = [];
657
- filter.items = filter.element.querySelectorAll('.ons-js-filter__item');
658
- resetFilterSortArray(filter, false, true);
659
- filter.element.removeAttribute('style');
660
- filter.animating = false;
661
- if (filter.reanimate) {
662
- updateFilterArray(filter);
582
+ function animateItems(filter) {
583
+ let transitionValue =
584
+ 'transform ' +
585
+ filter.options.duration +
586
+ 'ms cubic-bezier(0.455, 0.03, 0.515, 0.955), opacity ' +
587
+ filter.options.duration +
588
+ 'ms';
589
+
590
+ // Get new index of items in the list
591
+ let j = 0;
592
+ for (let i = 0; i < filter.sortingList.length; i++) {
593
+ let item = filter.items[filter.sortingList[i][1]];
594
+
595
+ if (Util.hasClass(item, 'ons-u-hidden') || !filter.filterList[filter.sortingList[i][1]]) {
596
+ // Item is hidden or was previously hidden -> final position equal to first one
597
+ filter.itemsFinalPosition[filter.sortingList[i][1]] = filter.itemsIterPosition[filter.sortingList[i][1]];
598
+ if (item.getAttribute('data-scale') == 'on') j = j + 1;
599
+ } else {
600
+ filter.itemsFinalPosition[filter.sortingList[i][1]] = [filter.itemsGrid[j][0], filter.itemsGrid[j][1]];
601
+
602
+ // Left/top
603
+ j = j + 1;
604
+ }
605
+ }
606
+
607
+ setTimeout(function () {
608
+ for (let i = 0; i < filter.items.length; i++) {
609
+ if (filter.filterList[i] && filter.items[i].getAttribute('data-scale') == 'on') {
610
+ // Scale up item
611
+ filter.items[i].setAttribute(
612
+ 'style',
613
+ filter.accelerateStyle +
614
+ 'transition: ' +
615
+ transitionValue +
616
+ '; transform: translateX(' +
617
+ parseInt(filter.itemsFinalPosition[i][0] - filter.itemsIterPosition[i][0]) +
618
+ 'px) translateY(' +
619
+ parseInt(filter.itemsFinalPosition[i][1] - filter.itemsIterPosition[i][1]) +
620
+ 'px) scale(1); opacity: 1;',
621
+ );
622
+ } else if (filter.filterList[i]) {
623
+ // Translate item
624
+ filter.items[i].setAttribute(
625
+ 'style',
626
+ filter.accelerateStyle +
627
+ 'transition: ' +
628
+ transitionValue +
629
+ '; transform: translateX(' +
630
+ parseInt(filter.itemsFinalPosition[i][0] - filter.itemsIterPosition[i][0]) +
631
+ 'px) translateY(' +
632
+ parseInt(filter.itemsFinalPosition[i][1] - filter.itemsIterPosition[i][1]) +
633
+ 'px);',
634
+ );
635
+ } else {
636
+ // Scale down item
637
+ filter.items[i].setAttribute(
638
+ 'style',
639
+ filter.accelerateStyle + 'transition: ' + transitionValue + '; transform: scale(0.5); opacity: 0;',
640
+ );
641
+ }
642
+ }
643
+ }, 50);
644
+
645
+ // Wait for the end of transition of visible elements
646
+ setTimeout(function () {
647
+ resetItems(filter);
648
+ }, filter.options.duration + 100);
663
649
  }
664
650
 
665
- resetFallbackMessage(filter, false);
651
+ function resetItems(filter) {
652
+ // Animation was off or animation is over -> reset attributes
653
+ for (let i = 0; i < filter.items.length; i++) {
654
+ filter.items[i].removeAttribute('style');
655
+ Util.toggleClass(filter.items[i], 'ons-u-hidden', !filter.filterList[i]);
656
+ filter.items[i].removeAttribute('data-scale');
657
+ }
658
+
659
+ for (let i = 0; i < filter.items.length; i++) {
660
+ // Reorder
661
+ filter.element.appendChild(filter.items[filter.sortingList[i][1]]);
662
+ }
663
+
664
+ filter.items = [];
665
+ filter.items = filter.element.querySelectorAll('.ons-js-filter__item');
666
+ resetFilterSortArray(filter, false, true);
667
+ filter.element.removeAttribute('style');
668
+ filter.animating = false;
669
+ if (filter.reanimate) {
670
+ updateFilterArray(filter);
671
+ }
666
672
 
667
- // Toggle fallback message
668
- // Emit custom event - end of filtering
669
- filter.element.dispatchEvent(new CustomEvent('filter-selection-updated'));
670
- }
673
+ resetFallbackMessage(filter, false);
671
674
 
672
- function resetFilterSortArray(filter, filtering, sorting) {
673
- for (let i = 0; i < filter.items.length; i++) {
674
- if (filtering) filter.filterList[i] = true;
675
- if (sorting) filter.sortingList[i] = [filter.items[i], i];
676
- }
677
- }
678
-
679
- function createGridInfo(filter) {
680
- let containerWidth = parseFloat(window.getComputedStyle(filter.element).getPropertyValue('width')),
681
- itemStyle,
682
- itemWidth,
683
- itemHeight,
684
- marginX,
685
- marginY,
686
- colNumber;
687
-
688
- // Get offset first visible element
689
- for (let i = 0; i < filter.items.length; i++) {
690
- if (!Util.hasClass(filter.items[i], 'ons-u-hidden')) {
691
- itemStyle = window.getComputedStyle(filter.items[i]);
692
- itemWidth = parseFloat(itemStyle.getPropertyValue('width'));
693
- itemHeight = parseFloat(itemStyle.getPropertyValue('height'));
694
- marginX = parseFloat(itemStyle.getPropertyValue('margin-left')) + parseFloat(itemStyle.getPropertyValue('margin-right'));
695
- marginY = parseFloat(itemStyle.getPropertyValue('margin-bottom')) + parseFloat(itemStyle.getPropertyValue('margin-top'));
696
- colNumber = parseInt((containerWidth + marginX) / (itemWidth + marginX));
697
- filter.itemsGrid[0] = [filter.items[i].offsetLeft, filter.items[i].offsetTop]; // Left, top
698
- break;
699
- }
675
+ // Toggle fallback message
676
+ // Emit custom event - end of filtering
677
+ filter.element.dispatchEvent(new CustomEvent('filter-selection-updated'));
700
678
  }
701
679
 
702
- for (let i = 1; i < filter.items.length; i++) {
703
- let x = i < colNumber ? i : i % colNumber,
704
- y = i < colNumber ? 0 : Math.floor(i / colNumber);
705
- filter.itemsGrid[i] = [filter.itemsGrid[0][0] + x * (itemWidth + marginX), filter.itemsGrid[0][1] + y * (itemHeight + marginY)];
680
+ function resetFilterSortArray(filter, filtering, sorting) {
681
+ for (let i = 0; i < filter.items.length; i++) {
682
+ if (filtering) filter.filterList[i] = true;
683
+ if (sorting) filter.sortingList[i] = [filter.items[i], i];
684
+ }
706
685
  }
707
- }
708
686
 
709
- function storeOffset(filter, array) {
710
- for (let i = 0; i < filter.items.length; i++) {
711
- array[i] = [filter.items[i].offsetLeft, filter.items[i].offsetTop];
687
+ function createGridInfo(filter) {
688
+ let containerWidth = parseFloat(window.getComputedStyle(filter.element).getPropertyValue('width')),
689
+ itemStyle,
690
+ itemWidth,
691
+ itemHeight,
692
+ marginX,
693
+ marginY,
694
+ colNumber;
695
+
696
+ // Get offset first visible element
697
+ for (let i = 0; i < filter.items.length; i++) {
698
+ if (!Util.hasClass(filter.items[i], 'ons-u-hidden')) {
699
+ itemStyle = window.getComputedStyle(filter.items[i]);
700
+ itemWidth = parseFloat(itemStyle.getPropertyValue('width'));
701
+ itemHeight = parseFloat(itemStyle.getPropertyValue('height'));
702
+ marginX = parseFloat(itemStyle.getPropertyValue('margin-left')) + parseFloat(itemStyle.getPropertyValue('margin-right'));
703
+ marginY = parseFloat(itemStyle.getPropertyValue('margin-bottom')) + parseFloat(itemStyle.getPropertyValue('margin-top'));
704
+ colNumber = parseInt((containerWidth + marginX) / (itemWidth + marginX));
705
+ filter.itemsGrid[0] = [filter.items[i].offsetLeft, filter.items[i].offsetTop]; // Left, top
706
+ break;
707
+ }
708
+ }
709
+
710
+ for (let i = 1; i < filter.items.length; i++) {
711
+ let x = i < colNumber ? i : i % colNumber,
712
+ y = i < colNumber ? 0 : Math.floor(i / colNumber);
713
+ filter.itemsGrid[i] = [filter.itemsGrid[0][0] + x * (itemWidth + marginX), filter.itemsGrid[0][1] + y * (itemHeight + marginY)];
714
+ }
712
715
  }
713
- }
714
716
 
715
- function initItemsOrder(filter) {
716
- for (let i = 0; i < filter.items.length; i++) {
717
- filter.items[i].setAttribute('data-init-sort-order', i);
717
+ function storeOffset(filter, array) {
718
+ for (let i = 0; i < filter.items.length; i++) {
719
+ array[i] = [filter.items[i].offsetLeft, filter.items[i].offsetTop];
720
+ }
718
721
  }
719
- }
720
722
 
721
- function restoreSortOrder(filter) {
722
- for (let i = 0; i < filter.items.length; i++) {
723
- filter.sortingList[parseInt(filter.items[i].getAttribute('data-init-sort-order'))] = [filter.items[i], i];
723
+ function initItemsOrder(filter) {
724
+ for (let i = 0; i < filter.items.length; i++) {
725
+ filter.items[i].setAttribute('data-init-sort-order', i);
726
+ }
724
727
  }
725
- }
726
-
727
- function resetFallbackMessage(filter, bool) {
728
- if (!filter.fallbackMessage) return;
729
- let show = true;
730
- for (let i = 0; i < filter.filterList.length; i++) {
731
- if (filter.filterList[i]) {
732
- show = false;
733
- break;
734
- }
728
+
729
+ function restoreSortOrder(filter) {
730
+ for (let i = 0; i < filter.items.length; i++) {
731
+ filter.sortingList[parseInt(filter.items[i].getAttribute('data-init-sort-order'))] = [filter.items[i], i];
732
+ }
735
733
  }
736
- if (bool) {
737
- // Reset visibility before animation is triggered
738
- if (!show) Util.addClass(filter.fallbackMessage, 'ons-u-hidden');
739
- return;
734
+
735
+ function resetFallbackMessage(filter, bool) {
736
+ if (!filter.fallbackMessage) return;
737
+ let show = true;
738
+ for (let i = 0; i < filter.filterList.length; i++) {
739
+ if (filter.filterList[i]) {
740
+ show = false;
741
+ break;
742
+ }
743
+ }
744
+ if (bool) {
745
+ // Reset visibility before animation is triggered
746
+ if (!show) Util.addClass(filter.fallbackMessage, 'ons-u-hidden');
747
+ return;
748
+ }
749
+ Util.toggleClass(filter.fallbackMessage, 'ons-u-hidden', !show);
740
750
  }
741
- Util.toggleClass(filter.fallbackMessage, 'ons-u-hidden', !show);
742
- }
743
-
744
- function getMultipleSelectValues(multipleSelect) {
745
- // Get selected options of a <select multiple> element
746
- let options = multipleSelect.options,
747
- value = '';
748
- for (let i = 0; i < options.length; i++) {
749
- if (options[i].selected) {
750
- if (value != '') value = value + ':';
751
- value = value + options[i].value;
752
- }
751
+
752
+ function getMultipleSelectValues(multipleSelect) {
753
+ // Get selected options of a <select multiple> element
754
+ let options = multipleSelect.options,
755
+ value = '';
756
+ for (let i = 0; i < options.length; i++) {
757
+ if (options[i].selected) {
758
+ if (value != '') value = value + ':';
759
+ value = value + options[i].value;
760
+ }
761
+ }
762
+ return value;
753
763
  }
754
- return value;
755
- }
756
-
757
- Filter.defaults = {
758
- element: false,
759
- duration: 400,
760
- };
761
-
762
- window.Filter = Filter;
763
-
764
- // Init Filter object
765
- let filterGallery = document.getElementsByClassName('ons-js-filter'),
766
- reducedMotion = Util.osHasReducedMotion();
767
- if (filterGallery.length > 0) {
768
- for (let i = 0; i < filterGallery.length; i++) {
769
- let duration = filterGallery[i].getAttribute('data-filter-duration');
770
- if (!duration) duration = Filter.defaults.duration;
771
- new Filter({ element: filterGallery[i], duration: duration });
764
+
765
+ Filter.defaults = {
766
+ element: false,
767
+ duration: 400,
768
+ };
769
+
770
+ window.Filter = Filter;
771
+
772
+ // Init Filter object
773
+ let filterGallery = document.getElementsByClassName('ons-js-filter'),
774
+ reducedMotion = Util.osHasReducedMotion();
775
+ if (filterGallery.length > 0) {
776
+ for (let i = 0; i < filterGallery.length; i++) {
777
+ let duration = filterGallery[i].getAttribute('data-filter-duration');
778
+ if (!duration) duration = Filter.defaults.duration;
779
+ new Filter({ element: filterGallery[i], duration: duration });
780
+ }
772
781
  }
773
- }
774
782
  })();
775
783
 
776
784
  // ADVANCED FILTERS
777
785
  (function () {
778
- // The Adv Filter object is used to handle:
779
-
780
- // - number of results
781
- // - form reset
782
- // - filtering sections label (to show a preview of the option selected by the users)
783
-
784
- let AdvFilter = function (element) {
785
- this.element = element;
786
- this.form = document.getElementsByClassName('ons-js-adv-filter__form');
787
- this.resultsList = this.element.getElementsByClassName('ons-js-adv-filter__gallery')[0];
788
- this.resultsCount = this.element.getElementsByClassName('ons-js-adv-filter__results-count');
789
- this.showCount = document.getElementsByClassName('ons-js-adv-filter__show-results');
790
-
791
- initAdvFilter(this);
792
- };
793
-
794
- function initAdvFilter(filter) {
795
- if (filter.form.length > 0) {
796
- // Reset form
797
- filter.form[0].addEventListener('reset', function () {
798
- setTimeout(function () {
799
- resetFilters(filter);
800
- resetGallery(filter);
801
- });
802
- });
803
-
804
- // Update section labels on form change
805
- filter.form[0].addEventListener('change', function (event) {
806
- let section = event.target.closest('.ons-js-adv-filter__item');
807
- if (section) resetSelection(filter, section);
808
- else if (Util.is(event.target, '.ons-js-adv-filter__form')) {
809
- // Reset the entire form lables
810
- let sections = filter.form[0].getElementsByClassName('ons-js-adv-filter__item');
811
- for (let i = 0; i < sections.length; i++) resetSelection(filter, sections[i]);
786
+ // The Adv Filter object is used to handle:
787
+ // - number of results
788
+ // - form reset
789
+ // - filtering sections label (to show a preview of the option selected by the users)
790
+
791
+ let AdvFilter = function (element) {
792
+ this.element = element;
793
+ this.form = document.getElementsByClassName('ons-js-adv-filter__form');
794
+ this.resultsList = this.element.getElementsByClassName('ons-js-adv-filter__gallery')[0];
795
+ this.resultsCount = this.element.getElementsByClassName('ons-js-adv-filter__results-count');
796
+ this.showCount = document.getElementsByClassName('ons-js-adv-filter__show-results');
797
+
798
+ initAdvFilter(this);
799
+ };
800
+
801
+ function initAdvFilter(filter) {
802
+ if (filter.form.length > 0) {
803
+ // Reset form
804
+ filter.form[0].addEventListener('reset', function () {
805
+ setTimeout(function () {
806
+ resetFilters(filter);
807
+ resetGallery(filter);
808
+ });
809
+ });
810
+
811
+ // Update section labels on form change
812
+ filter.form[0].addEventListener('change', function (event) {
813
+ let section = event.target.closest('.ons-js-adv-filter__item');
814
+ if (section) resetSelection(filter, section);
815
+ else if (Util.is(event.target, '.ons-js-adv-filter__form')) {
816
+ // Reset the entire form lables
817
+ let sections = filter.form[0].getElementsByClassName('ons-js-adv-filter__item');
818
+ for (let i = 0; i < sections.length; i++) resetSelection(filter, sections[i]);
819
+ }
820
+ });
812
821
  }
813
- });
814
- }
815
822
 
816
- // Reset results count
817
- if (filter.resultsCount.length > 0) {
818
- filter.resultsList.addEventListener('filter-selection-updated', function () {
819
- updateResultsCount(filter);
820
- });
821
- }
822
- }
823
-
824
- function resetFilters(filter) {
825
- // Check if there are custom form elemets - reset appearance
826
- // Custom select
827
- let customSelect = filter.element.getElementsByClassName('ons-js-select');
828
- if (customSelect.length > 0) {
829
- for (let i = 0; i < customSelect.length; i++) customSelect[i].dispatchEvent(new CustomEvent('select-updated'));
823
+ // Reset results count
824
+ if (filter.resultsCount.length > 0) {
825
+ filter.resultsList.addEventListener('filter-selection-updated', function () {
826
+ updateResultsCount(filter);
827
+ });
828
+ }
830
829
  }
831
830
 
832
- // Custom slider
833
- let customSlider = filter.element.getElementsByClassName('ons-js-slider');
834
- if (customSlider.length > 0) {
835
- for (let i = 0; i < customSlider.length; i++) customSlider[i].dispatchEvent(new CustomEvent('slider-updated'));
836
- }
837
- }
838
-
839
- function resetSelection(filter, section) {
840
- // Change label value based on input types
841
- let labelSelection = section.getElementsByClassName('ons-js-adv-filter__selection');
842
- if (labelSelection.length == 0) return;
843
-
844
- // Select
845
- let select = section.getElementsByTagName('select');
846
- if (select.length > 0) {
847
- labelSelection[0].textContent = getSelectLabel(section, select[0]);
848
- return;
849
- }
831
+ function resetFilters(filter) {
832
+ // Check if there are custom form elemets - reset appearance
833
+ // Custom select
834
+ let customSelect = filter.element.getElementsByClassName('ons-js-select');
835
+ if (customSelect.length > 0) {
836
+ for (let i = 0; i < customSelect.length; i++) customSelect[i].dispatchEvent(new CustomEvent('select-updated'));
837
+ }
850
838
 
851
- // Input number
852
- let number = section.querySelectorAll('input[type="number"]');
853
- if (number.length > 0) {
854
- labelSelection[0].textContent = getNumberLabel(section, number);
855
- return;
839
+ // Custom slider
840
+ let customSlider = filter.element.getElementsByClassName('ons-js-slider');
841
+ if (customSlider.length > 0) {
842
+ for (let i = 0; i < customSlider.length; i++) customSlider[i].dispatchEvent(new CustomEvent('slider-updated'));
843
+ }
856
844
  }
857
845
 
858
- // Input range
859
- let slider = section.querySelectorAll('input[type="range"]');
860
- if (slider.length > 0) {
861
- labelSelection[0].textContent = getSliderLabel(section, slider);
862
- return;
863
- }
846
+ function resetSelection(filter, section) {
847
+ // Change label value based on input types
848
+ let labelSelection = section.getElementsByClassName('ons-js-adv-filter__selection');
849
+ if (labelSelection.length == 0) return;
864
850
 
865
- // Radio/checkboxes
866
- let radio = section.querySelectorAll('input[type="radio"]'),
867
- checkbox = section.querySelectorAll('input[type="checkbox"]');
868
- if (radio.length > 0) {
869
- labelSelection[0].textContent = getInputListLabel(section, radio);
870
- return;
871
- } else if (checkbox.length > 0) {
872
- labelSelection[0].textContent = getInputListLabel(section, checkbox);
873
- return;
874
- }
875
- }
876
-
877
- function getSelectLabel(section, select) {
878
- if (select.multiple) {
879
- let label = '',
880
- counter = 0;
881
- for (let i = 0; i < select.options.length; i++) {
882
- if (select.options[i].selected) {
883
- label = label + '' + select.options[i].text;
884
- counter = counter + 1;
851
+ // Select
852
+ let select = section.getElementsByTagName('select');
853
+ if (select.length > 0) {
854
+ labelSelection[0].textContent = getSelectLabel(section, select[0]);
855
+ return;
856
+ }
857
+
858
+ // Input number
859
+ let number = section.querySelectorAll('input[type="number"]');
860
+ if (number.length > 0) {
861
+ labelSelection[0].textContent = getNumberLabel(section, number);
862
+ return;
863
+ }
864
+
865
+ // Input range
866
+ let slider = section.querySelectorAll('input[type="range"]');
867
+ if (slider.length > 0) {
868
+ labelSelection[0].textContent = getSliderLabel(section, slider);
869
+ return;
885
870
  }
886
- if (counter > 1) label = section.getAttribute('data-multi-select-text').replace('{n}', counter);
887
- }
888
- return label;
889
- } else {
890
- return select.options[select.selectedIndex].text;
891
- }
892
- }
893
871
 
894
- function getNumberLabel(section, number) {
895
- let counter = 0;
896
- for (let i = 0; i < number.length; i++) {
897
- if (number[i].value != number[i].min) counter = counter + 1;
872
+ // Radio/checkboxes
873
+ let radio = section.querySelectorAll('input[type="radio"]'),
874
+ checkbox = section.querySelectorAll('input[type="checkbox"]');
875
+ if (radio.length > 0) {
876
+ labelSelection[0].textContent = getInputListLabel(section, radio);
877
+ return;
878
+ } else if (checkbox.length > 0) {
879
+ labelSelection[0].textContent = getInputListLabel(section, checkbox);
880
+ return;
881
+ }
898
882
  }
899
- if (number.length > 1) {
900
- // Multiple input number in this section
901
- if (counter > 0) {
902
- return section.getAttribute('data-multi-select-text').replace('{n}', counter);
903
- } else {
904
- return section.getAttribute('data-default-text');
905
- }
906
- } else {
907
- if (number[0].value == number[0].min) return section.getAttribute('data-default-text');
908
- else return section.getAttribute('data-number-format').replace('{n}', number[0].value);
883
+
884
+ function getSelectLabel(section, select) {
885
+ if (select.multiple) {
886
+ let label = '',
887
+ counter = 0;
888
+ for (let i = 0; i < select.options.length; i++) {
889
+ if (select.options[i].selected) {
890
+ label = label + '' + select.options[i].text;
891
+ counter = counter + 1;
892
+ }
893
+ if (counter > 1) label = section.getAttribute('data-multi-select-text').replace('{n}', counter);
894
+ }
895
+ return label;
896
+ } else {
897
+ return select.options[select.selectedIndex].text;
898
+ }
909
899
  }
910
- }
911
-
912
- function getSliderLabel(section, slider) {
913
- let label = '',
914
- labelFormat = section.getAttribute('data-number-format');
915
- for (let i = 0; i < slider.length; i++) {
916
- if (i != 0) label = label + ' - ';
917
- label = label + labelFormat.replace('{n}', slider[i].value);
900
+
901
+ function getNumberLabel(section, number) {
902
+ let counter = 0;
903
+ for (let i = 0; i < number.length; i++) {
904
+ if (number[i].value != number[i].min) counter = counter + 1;
905
+ }
906
+ if (number.length > 1) {
907
+ // Multiple input number in this section
908
+ if (counter > 0) {
909
+ return section.getAttribute('data-multi-select-text').replace('{n}', counter);
910
+ } else {
911
+ return section.getAttribute('data-default-text');
912
+ }
913
+ } else {
914
+ if (number[0].value == number[0].min) return section.getAttribute('data-default-text');
915
+ else return section.getAttribute('data-number-format').replace('{n}', number[0].value);
916
+ }
918
917
  }
919
- return label;
920
- }
921
-
922
- function getInputListLabel(section, inputs) {
923
- let counter = 0,
924
- label = '';
925
- for (let i = 0; i < inputs.length; i++) {
926
- if (inputs[i].checked) {
927
- let labelElement = inputs[i].parentNode.getElementsByTagName('label');
928
- if (labelElement.length > 0) label = labelElement[0].textContent;
929
- counter = counter + 1;
930
- }
918
+
919
+ function getSliderLabel(section, slider) {
920
+ let label = '',
921
+ labelFormat = section.getAttribute('data-number-format');
922
+ for (let i = 0; i < slider.length; i++) {
923
+ if (i != 0) label = label + ' - ';
924
+ label = label + labelFormat.replace('{n}', slider[i].value);
925
+ }
926
+ return label;
931
927
  }
932
- if (counter > 1) return section.getAttribute('data-multi-select-text').replace('{n}', counter);
933
- else if (counter == 0) return section.getAttribute('data-default-text');
934
- else return label;
935
- }
936
-
937
- function resetGallery(filter) {
938
- // Emit change event + reset filtering
939
- filter.form[0].dispatchEvent(new CustomEvent('change'));
940
- filter.resultsList.dispatchEvent(new CustomEvent('update-filter-results'));
941
- }
942
-
943
- function updateResultsCount(filter) {
944
- let resultItems = filter.resultsList.children,
945
- counter = 0;
946
-
947
- for (let i = 0; i < resultItems.length; i++) {
948
- if (isVisible(resultItems[i])) counter = counter + 1;
928
+
929
+ function getInputListLabel(section, inputs) {
930
+ let counter = 0,
931
+ label = '';
932
+ for (let i = 0; i < inputs.length; i++) {
933
+ if (inputs[i].checked) {
934
+ let labelElement = inputs[i].parentNode.getElementsByTagName('label');
935
+ if (labelElement.length > 0) label = labelElement[0].textContent;
936
+ counter = counter + 1;
937
+ }
938
+ }
939
+ if (counter > 1) return section.getAttribute('data-multi-select-text').replace('{n}', counter);
940
+ else if (counter == 0) return section.getAttribute('data-default-text');
941
+ else return label;
949
942
  }
950
943
 
951
- filter.resultsCount[0].textContent = counter; // Update results count
952
- filter.showCount[0].textContent = counter; // Update show count
953
- }
954
-
955
- function isVisible(element) {
956
- return element.offsetWidth || element.offsetHeight || element.getClientRects().length;
957
- }
958
-
959
- // Initialize the AdvFilter objects
960
- let advFilter = document.getElementsByClassName('ons-js-adv-filter');
961
- if (advFilter.length > 0) {
962
- for (let i = 0; i < advFilter.length; i++) {
963
- (function (i) {
964
- new AdvFilter(advFilter[i]);
965
- })(i);
944
+ function resetGallery(filter) {
945
+ // Emit change event + reset filtering
946
+ filter.form[0].dispatchEvent(new CustomEvent('change'));
947
+ filter.resultsList.dispatchEvent(new CustomEvent('update-filter-results'));
966
948
  }
967
- }
968
949
 
969
- // Remove the code below if you want to use a custom filtering function (e.g., you need to fetch your results from a database)
950
+ function updateResultsCount(filter) {
951
+ let resultItems = filter.resultsList.children,
952
+ counter = 0;
970
953
 
971
- // The code below is used for filtering of page content (animation of DOM elements, no fetching results from database).
972
- // It uses the Filter component - you can modify the custom filtering functions based on your needs.
954
+ for (let i = 0; i < resultItems.length; i++) {
955
+ if (isVisible(resultItems[i])) counter = counter + 1;
956
+ }
973
957
 
974
- let gallery = document.getElementById('adv-filter-gallery');
958
+ filter.resultsCount[0].textContent = counter; // Update results count
959
+ filter.showCount[0].textContent = counter; // Update show count
960
+ }
975
961
 
976
- if (gallery) {
977
- new Filter({
978
- element: gallery,
962
+ function isVisible(element) {
963
+ return element.offsetWidth || element.offsetHeight || element.getClientRects().length;
964
+ }
979
965
 
980
- // This is your gallery element
981
- priceRange: function (items) {
982
- // This is the price custom function
983
- let filteredArray = [],
984
- minVal = document.getElementById('slider-min-value').value,
985
- maxVal = document.getElementById('slider-max-value').value;
986
- for (let i = 0; i < items.length; i++) {
987
- let price = parseInt(items[i].getAttribute('data-price'));
988
- filteredArray[i] = price >= minVal && price <= maxVal;
989
- }
990
- return filteredArray;
991
- },
992
- indexValue: function (items) {
993
- // This is the index custom function
994
- let filteredArray = [],
995
- value = document.getElementById('index-value').value;
996
- for (let i = 0; i < items.length; i++) {
997
- let index = parseInt(items[i].getAttribute('data-sort-index'));
998
- filteredArray[i] = index >= value;
966
+ // Initialize the AdvFilter objects
967
+ let advFilter = document.getElementsByClassName('ons-js-adv-filter');
968
+ if (advFilter.length > 0) {
969
+ for (let i = 0; i < advFilter.length; i++) {
970
+ (function (i) {
971
+ new AdvFilter(advFilter[i]);
972
+ })(i);
999
973
  }
1000
- return filteredArray;
1001
- },
1002
- });
1003
- }
974
+ }
975
+
976
+ // Remove the code below if you want to use a custom filtering function (e.g., you need to fetch your results from a database)
977
+
978
+ // The code below is used for filtering of page content (animation of DOM elements, no fetching results from database).
979
+ // It uses the Filter component - you can modify the custom filtering functions based on your needs.
980
+
981
+ let gallery = document.getElementById('adv-filter-gallery');
982
+
983
+ if (gallery) {
984
+ new Filter({
985
+ element: gallery,
986
+
987
+ // This is your gallery element
988
+ priceRange: function (items) {
989
+ // This is the price custom function
990
+ let filteredArray = [],
991
+ minVal = document.getElementById('slider-min-value').value,
992
+ maxVal = document.getElementById('slider-max-value').value;
993
+ for (let i = 0; i < items.length; i++) {
994
+ let price = parseInt(items[i].getAttribute('data-price'));
995
+ filteredArray[i] = price >= minVal && price <= maxVal;
996
+ }
997
+ return filteredArray;
998
+ },
999
+ indexValue: function (items) {
1000
+ // This is the index custom function
1001
+ let filteredArray = [],
1002
+ value = document.getElementById('index-value').value;
1003
+ for (let i = 0; i < items.length; i++) {
1004
+ let index = parseInt(items[i].getAttribute('data-sort-index'));
1005
+ filteredArray[i] = index >= value;
1006
+ }
1007
+ return filteredArray;
1008
+ },
1009
+ });
1010
+ }
1004
1011
  })();
1005
1012
 
1006
1013
  // TOGGLE FILTERS
1007
1014
  (function () {
1008
- let filters = document.getElementsByClassName('ons-js-adv-filter');
1009
-
1010
- if (filters.length > 0) {
1011
- let filtersTrigger = filters[0].getElementsByClassName('ons-js-adv-filter__trigger')[0];
1012
- let filtersClose = filters[0].getElementsByClassName('ons-js-adv-filter__close')[0];
1013
- let filtersShow = filters[0].getElementsByClassName('ons-js-adv-filter__show')[0];
1014
- let filtersWrap = filters[0].getElementsByClassName('ons-js-adv-filter__wrap')[0];
1015
- let filtersPanel = filters[0].getElementsByClassName('ons-js-adv-filter__panel')[0];
1016
- let body = document.getElementsByTagName('body')[0];
1017
- let page = document.getElementsByClassName('ons-page')[0];
1018
-
1019
- // Detect click on filters trigger
1020
- filtersTrigger.addEventListener('click', function (event) {
1021
- event.preventDefault();
1022
- toggleFilters(!Util.hasClass(filtersPanel, 'ons-adv-filter__panel--is-visible'));
1023
- });
1024
-
1025
- // Detect click on update
1026
- filtersShow.addEventListener('click', function (event) {
1027
- event.preventDefault();
1028
- filtersTrigger.click();
1029
- });
1030
-
1031
- // Detect click on close
1032
- filtersClose.addEventListener('click', function (event) {
1033
- event.preventDefault();
1034
- filtersTrigger.click();
1035
- });
1036
-
1037
- // Listen for key events
1038
- window.addEventListener('keyup', function (event) {
1039
- // Listen for ESC key
1040
- if ((event.keyCode && event.keyCode == 27) || (event.key && event.key.toLowerCase() == 'escape')) {
1041
- // Close filter panel on mobile if open
1042
- if (filtersTrigger.getAttribute('aria-expanded') == 'true' && isVisible(filtersTrigger)) {
1043
- filtersTrigger.click();
1044
- }
1045
- }
1046
- });
1015
+ let filters = document.getElementsByClassName('ons-js-adv-filter');
1016
+
1017
+ if (filters.length > 0) {
1018
+ let filtersTrigger = filters[0].getElementsByClassName('ons-js-adv-filter__trigger')[0];
1019
+ let filtersClose = filters[0].getElementsByClassName('ons-js-adv-filter__close')[0];
1020
+ let filtersShow = filters[0].getElementsByClassName('ons-js-adv-filter__show')[0];
1021
+ let filtersWrap = filters[0].getElementsByClassName('ons-js-adv-filter__wrap')[0];
1022
+ let filtersPanel = filters[0].getElementsByClassName('ons-js-adv-filter__panel')[0];
1023
+ let body = document.getElementsByTagName('body')[0];
1024
+ let page = document.getElementsByClassName('ons-page')[0];
1025
+
1026
+ // Detect click on filters trigger
1027
+ filtersTrigger.addEventListener('click', function (event) {
1028
+ event.preventDefault();
1029
+ toggleFilters(!Util.hasClass(filtersPanel, 'ons-adv-filter__panel--is-visible'));
1030
+ });
1047
1031
 
1048
- // Listen for resize
1049
- let resizingId = false;
1032
+ // Detect click on update
1033
+ filtersShow.addEventListener('click', function (event) {
1034
+ event.preventDefault();
1035
+ filtersTrigger.click();
1036
+ });
1050
1037
 
1051
- window.addEventListener('resize', function () {
1052
- clearTimeout(resizingId);
1053
- resizingId = setTimeout(doneResizing, 500);
1054
- });
1038
+ // Detect click on close
1039
+ filtersClose.addEventListener('click', function (event) {
1040
+ event.preventDefault();
1041
+ filtersTrigger.click();
1042
+ });
1055
1043
 
1056
- function doneResizing() {
1057
- if (!isVisible(filtersTrigger)) toggleFilters(false);
1058
- }
1044
+ // Listen for key events
1045
+ window.addEventListener('keyup', function (event) {
1046
+ // Listen for ESC key
1047
+ if ((event.keyCode && event.keyCode == 27) || (event.key && event.key.toLowerCase() == 'escape')) {
1048
+ // Close filter panel on mobile if open
1049
+ if (filtersTrigger.getAttribute('aria-expanded') == 'true' && isVisible(filtersTrigger)) {
1050
+ filtersTrigger.click();
1051
+ }
1052
+ }
1053
+ });
1059
1054
 
1060
- function isVisible(element) {
1061
- return element.offsetWidth || element.offsetHeight || element.getClientRects().length;
1062
- }
1055
+ // Listen for resize
1056
+ let resizingId = false;
1057
+
1058
+ window.addEventListener('resize', function () {
1059
+ clearTimeout(resizingId);
1060
+ resizingId = setTimeout(doneResizing, 500);
1061
+ });
1062
+
1063
+ function doneResizing() {
1064
+ if (!isVisible(filtersTrigger)) toggleFilters(false);
1065
+ }
1066
+
1067
+ function isVisible(element) {
1068
+ return element.offsetWidth || element.offsetHeight || element.getClientRects().length;
1069
+ }
1063
1070
 
1064
- // Toggle filters visibility on small devices
1065
- function toggleFilters(bool) {
1066
- if (bool === true) {
1067
- body.appendChild(filtersPanel);
1068
- } else {
1069
- filtersWrap.appendChild(filtersPanel);
1070
- }
1071
- Util.toggleClass(page, 'ons-u-d-no', bool);
1072
- Util.toggleClass(filtersPanel, 'ons-adv-filter__panel--is-visible', bool);
1073
- Util.toggleClass(body, 'ons-no-scroll', bool);
1074
- filtersTrigger.setAttribute('aria-expanded', bool);
1075
- filtersTrigger.setAttribute('aria-hidden', bool);
1076
- page.setAttribute('aria-hidden', bool);
1077
- Util.toggleClass(filtersTrigger, 'ons-u-d-no', bool);
1071
+ // Toggle filters visibility on small devices
1072
+ function toggleFilters(bool) {
1073
+ if (bool === true) {
1074
+ body.appendChild(filtersPanel);
1075
+ } else {
1076
+ filtersWrap.appendChild(filtersPanel);
1077
+ }
1078
+ Util.toggleClass(page, 'ons-u-d-no', bool);
1079
+ Util.toggleClass(filtersPanel, 'ons-adv-filter__panel--is-visible', bool);
1080
+ Util.toggleClass(body, 'ons-no-scroll', bool);
1081
+ filtersTrigger.setAttribute('aria-expanded', bool);
1082
+ filtersTrigger.setAttribute('aria-hidden', bool);
1083
+ page.setAttribute('aria-hidden', bool);
1084
+ Util.toggleClass(filtersTrigger, 'ons-u-d-no', bool);
1085
+ }
1078
1086
  }
1079
- }
1080
1087
  })();