@ministryofjustice/frontend 4.0.1 → 5.1.0

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 (256) hide show
  1. package/govuk-prototype-kit.config.json +19 -4
  2. package/moj/_base.scss +2 -0
  3. package/moj/_base.scss.map +1 -0
  4. package/moj/all.bundle.js +3010 -0
  5. package/moj/all.bundle.js.map +1 -0
  6. package/moj/all.bundle.mjs +3293 -0
  7. package/moj/all.bundle.mjs.map +1 -0
  8. package/moj/all.mjs +17 -110
  9. package/moj/all.mjs.map +1 -1
  10. package/moj/all.scss +3 -0
  11. package/moj/all.scss.map +1 -0
  12. package/moj/common/index.mjs +57 -0
  13. package/moj/common/index.mjs.map +1 -0
  14. package/moj/common/moj-frontend-version.mjs +14 -0
  15. package/moj/common/moj-frontend-version.mjs.map +1 -0
  16. package/moj/components/_all.scss +2 -0
  17. package/moj/components/_all.scss.map +1 -0
  18. package/moj/components/action-bar/_action-bar.scss +2 -0
  19. package/moj/components/action-bar/_action-bar.scss.map +1 -0
  20. package/moj/components/add-another/_add-another.scss +2 -0
  21. package/moj/components/add-another/_add-another.scss.map +1 -0
  22. package/moj/components/add-another/add-another.bundle.js +157 -0
  23. package/moj/components/add-another/add-another.bundle.js.map +1 -0
  24. package/moj/components/add-another/add-another.bundle.mjs +271 -0
  25. package/moj/components/add-another/add-another.bundle.mjs.map +1 -0
  26. package/moj/components/add-another/add-another.mjs +135 -91
  27. package/moj/components/add-another/add-another.mjs.map +1 -1
  28. package/moj/components/alert/_alert.scss +4 -0
  29. package/moj/components/alert/_alert.scss.map +1 -0
  30. package/moj/components/alert/alert.bundle.js +254 -0
  31. package/moj/components/alert/alert.bundle.js.map +1 -0
  32. package/moj/components/alert/alert.bundle.mjs +490 -0
  33. package/moj/components/alert/alert.bundle.mjs.map +1 -0
  34. package/moj/components/alert/alert.mjs +97 -218
  35. package/moj/components/alert/alert.mjs.map +1 -1
  36. package/moj/components/alert/{alert.spec.helper.js → alert.spec.helper.bundle.js} +1 -1
  37. package/moj/components/alert/alert.spec.helper.bundle.js.map +1 -0
  38. package/moj/components/alert/alert.spec.helper.bundle.mjs +67 -0
  39. package/moj/components/alert/alert.spec.helper.bundle.mjs.map +1 -0
  40. package/moj/components/alert/alert.spec.helper.mjs.map +1 -1
  41. package/moj/components/badge/_badge.scss +2 -0
  42. package/moj/components/badge/_badge.scss.map +1 -0
  43. package/moj/components/banner/_banner.scss +2 -0
  44. package/moj/components/banner/_banner.scss.map +1 -0
  45. package/moj/components/button-menu/README.md +12 -6
  46. package/moj/components/button-menu/_button-menu.scss +4 -1
  47. package/moj/components/button-menu/_button-menu.scss.map +1 -0
  48. package/moj/components/button-menu/button-menu.bundle.js +270 -0
  49. package/moj/components/button-menu/button-menu.bundle.js.map +1 -0
  50. package/moj/components/button-menu/button-menu.bundle.mjs +506 -0
  51. package/moj/components/button-menu/button-menu.bundle.mjs.map +1 -0
  52. package/moj/components/button-menu/button-menu.mjs +214 -280
  53. package/moj/components/button-menu/button-menu.mjs.map +1 -1
  54. package/moj/components/cookie-banner/_cookie-banner.scss +2 -0
  55. package/moj/components/cookie-banner/_cookie-banner.scss.map +1 -0
  56. package/moj/components/currency-input/_currency-input.scss +2 -0
  57. package/moj/components/currency-input/_currency-input.scss.map +1 -0
  58. package/moj/components/date-picker/_date-picker.scss +2 -0
  59. package/moj/components/date-picker/_date-picker.scss.map +1 -0
  60. package/moj/components/date-picker/date-picker.bundle.js +804 -0
  61. package/moj/components/date-picker/date-picker.bundle.js.map +1 -0
  62. package/moj/components/date-picker/date-picker.bundle.mjs +1040 -0
  63. package/moj/components/date-picker/date-picker.bundle.mjs.map +1 -0
  64. package/moj/components/date-picker/date-picker.mjs +663 -827
  65. package/moj/components/date-picker/date-picker.mjs.map +1 -1
  66. package/moj/components/filter/_filter.scss +2 -0
  67. package/moj/components/filter/_filter.scss.map +1 -0
  68. package/moj/components/filter/template.njk +1 -1
  69. package/moj/components/filter-toggle-button/filter-toggle-button.bundle.js +185 -0
  70. package/moj/components/filter-toggle-button/filter-toggle-button.bundle.js.map +1 -0
  71. package/moj/components/filter-toggle-button/filter-toggle-button.bundle.mjs +421 -0
  72. package/moj/components/filter-toggle-button/filter-toggle-button.bundle.mjs.map +1 -0
  73. package/moj/components/filter-toggle-button/filter-toggle-button.mjs +166 -81
  74. package/moj/components/filter-toggle-button/filter-toggle-button.mjs.map +1 -1
  75. package/moj/components/form-validator/form-validator.bundle.js +288 -0
  76. package/moj/components/form-validator/form-validator.bundle.js.map +1 -0
  77. package/moj/components/form-validator/form-validator.bundle.mjs +524 -0
  78. package/moj/components/form-validator/form-validator.bundle.mjs.map +1 -0
  79. package/moj/components/form-validator/form-validator.mjs +226 -149
  80. package/moj/components/form-validator/form-validator.mjs.map +1 -1
  81. package/moj/components/header/_header.scss +2 -0
  82. package/moj/components/header/_header.scss.map +1 -0
  83. package/moj/components/identity-bar/_identity-bar.scss +2 -0
  84. package/moj/components/identity-bar/_identity-bar.scss.map +1 -0
  85. package/moj/components/interruption-card/_interruption-card.scss +2 -0
  86. package/moj/components/interruption-card/_interruption-card.scss.map +1 -0
  87. package/moj/components/messages/_messages.scss +2 -0
  88. package/moj/components/messages/_messages.scss.map +1 -0
  89. package/moj/components/multi-file-upload/_multi-file-upload.scss +2 -0
  90. package/moj/components/multi-file-upload/_multi-file-upload.scss.map +1 -0
  91. package/moj/components/multi-file-upload/multi-file-upload.bundle.js +397 -0
  92. package/moj/components/multi-file-upload/multi-file-upload.bundle.js.map +1 -0
  93. package/moj/components/multi-file-upload/multi-file-upload.bundle.mjs +633 -0
  94. package/moj/components/multi-file-upload/multi-file-upload.bundle.mjs.map +1 -0
  95. package/moj/components/multi-file-upload/multi-file-upload.mjs +384 -213
  96. package/moj/components/multi-file-upload/multi-file-upload.mjs.map +1 -1
  97. package/moj/components/multi-file-upload/template.njk +1 -1
  98. package/moj/components/multi-select/_multi-select.scss +2 -0
  99. package/moj/components/multi-select/_multi-select.scss.map +1 -0
  100. package/moj/components/multi-select/multi-select.bundle.js +143 -0
  101. package/moj/components/multi-select/multi-select.bundle.js.map +1 -0
  102. package/moj/components/multi-select/multi-select.bundle.mjs +379 -0
  103. package/moj/components/multi-select/multi-select.bundle.mjs.map +1 -0
  104. package/moj/components/multi-select/multi-select.mjs +123 -64
  105. package/moj/components/multi-select/multi-select.mjs.map +1 -1
  106. package/moj/components/notification-badge/_notification-badge.scss +2 -0
  107. package/moj/components/notification-badge/_notification-badge.scss.map +1 -0
  108. package/moj/components/organisation-switcher/_organisation-switcher.scss +2 -0
  109. package/moj/components/organisation-switcher/_organisation-switcher.scss.map +1 -0
  110. package/moj/components/page-header-actions/_page-header-actions.scss +2 -0
  111. package/moj/components/page-header-actions/_page-header-actions.scss.map +1 -0
  112. package/moj/components/pagination/_pagination.scss +2 -2
  113. package/moj/components/pagination/_pagination.scss.map +1 -0
  114. package/moj/components/password-reveal/_password-reveal.scss +5 -1
  115. package/moj/components/password-reveal/_password-reveal.scss.map +1 -0
  116. package/moj/components/password-reveal/password-reveal.bundle.js +52 -0
  117. package/moj/components/password-reveal/password-reveal.bundle.js.map +1 -0
  118. package/moj/components/password-reveal/password-reveal.bundle.mjs +166 -0
  119. package/moj/components/password-reveal/password-reveal.bundle.mjs.map +1 -0
  120. package/moj/components/password-reveal/password-reveal.mjs +39 -29
  121. package/moj/components/password-reveal/password-reveal.mjs.map +1 -1
  122. package/moj/components/primary-navigation/_primary-navigation.scss +2 -0
  123. package/moj/components/primary-navigation/_primary-navigation.scss.map +1 -0
  124. package/moj/components/progress-bar/_progress-bar.scss +2 -0
  125. package/moj/components/progress-bar/_progress-bar.scss.map +1 -0
  126. package/moj/components/rich-text-editor/README.md +16 -9
  127. package/moj/components/rich-text-editor/_rich-text-editor.scss +2 -0
  128. package/moj/components/rich-text-editor/_rich-text-editor.scss.map +1 -0
  129. package/moj/components/rich-text-editor/rich-text-editor.bundle.js +210 -0
  130. package/moj/components/rich-text-editor/rich-text-editor.bundle.js.map +1 -0
  131. package/moj/components/rich-text-editor/rich-text-editor.bundle.mjs +446 -0
  132. package/moj/components/rich-text-editor/rich-text-editor.bundle.mjs.map +1 -0
  133. package/moj/components/rich-text-editor/rich-text-editor.mjs +186 -140
  134. package/moj/components/rich-text-editor/rich-text-editor.mjs.map +1 -1
  135. package/moj/components/search/_search.scss +2 -0
  136. package/moj/components/search/_search.scss.map +1 -0
  137. package/moj/components/search-toggle/{search-toggle.scss → _search-toggle.scss} +2 -0
  138. package/moj/components/search-toggle/_search-toggle.scss.map +1 -0
  139. package/moj/components/search-toggle/search-toggle.bundle.js +122 -0
  140. package/moj/components/search-toggle/search-toggle.bundle.js.map +1 -0
  141. package/moj/components/search-toggle/search-toggle.bundle.mjs +358 -0
  142. package/moj/components/search-toggle/search-toggle.bundle.mjs.map +1 -0
  143. package/moj/components/search-toggle/search-toggle.mjs +104 -43
  144. package/moj/components/search-toggle/search-toggle.mjs.map +1 -1
  145. package/moj/components/side-navigation/_side-navigation.scss +2 -0
  146. package/moj/components/side-navigation/_side-navigation.scss.map +1 -0
  147. package/moj/components/sortable-table/_sortable-table.scss +2 -2
  148. package/moj/components/sortable-table/_sortable-table.scss.map +1 -0
  149. package/moj/components/sortable-table/sortable-table.bundle.js +202 -0
  150. package/moj/components/sortable-table/sortable-table.bundle.js.map +1 -0
  151. package/moj/components/sortable-table/sortable-table.bundle.mjs +438 -0
  152. package/moj/components/sortable-table/sortable-table.bundle.mjs.map +1 -0
  153. package/moj/components/sortable-table/sortable-table.mjs +179 -122
  154. package/moj/components/sortable-table/sortable-table.mjs.map +1 -1
  155. package/moj/components/sub-navigation/_sub-navigation.scss +2 -0
  156. package/moj/components/sub-navigation/_sub-navigation.scss.map +1 -0
  157. package/moj/components/tag/_tag.scss +2 -0
  158. package/moj/components/tag/_tag.scss.map +1 -0
  159. package/moj/components/task-list/_task-list.scss +2 -0
  160. package/moj/components/task-list/_task-list.scss.map +1 -0
  161. package/moj/components/ticket-panel/_ticket-panel.scss +2 -0
  162. package/moj/components/ticket-panel/_ticket-panel.scss.map +1 -0
  163. package/moj/components/timeline/_timeline.scss +2 -0
  164. package/moj/components/timeline/_timeline.scss.map +1 -0
  165. package/moj/core/_all.scss +3 -0
  166. package/moj/core/_all.scss.map +1 -0
  167. package/moj/core/_moj-frontend-properties.scss +7 -0
  168. package/moj/core/_moj-frontend-properties.scss.map +1 -0
  169. package/moj/filters/all.js +44 -22
  170. package/moj/filters/prototype-kit-13-filters.js +4 -3
  171. package/moj/helpers/_all.scss +2 -0
  172. package/moj/helpers/_all.scss.map +1 -0
  173. package/moj/helpers/_hidden.scss +2 -0
  174. package/moj/helpers/_hidden.scss.map +1 -0
  175. package/moj/helpers/_links.scss +2 -0
  176. package/moj/helpers/_links.scss.map +1 -0
  177. package/moj/helpers.bundle.js +140 -0
  178. package/moj/helpers.bundle.js.map +1 -0
  179. package/moj/helpers.bundle.mjs +128 -0
  180. package/moj/helpers.bundle.mjs.map +1 -0
  181. package/moj/helpers.mjs +50 -77
  182. package/moj/helpers.mjs.map +1 -1
  183. package/moj/init.js +11 -2
  184. package/moj/moj-frontend.min.css +1 -1
  185. package/moj/moj-frontend.min.css.map +1 -1
  186. package/moj/moj-frontend.min.js +1 -1
  187. package/moj/moj-frontend.min.js.map +1 -1
  188. package/moj/objects/_all.scss +2 -0
  189. package/moj/objects/_all.scss.map +1 -0
  190. package/moj/objects/_button-group.scss +2 -0
  191. package/moj/objects/_button-group.scss.map +1 -0
  192. package/moj/objects/_filter-layout.scss +2 -0
  193. package/moj/objects/_filter-layout.scss.map +1 -0
  194. package/moj/objects/_scrollable-pane.scss +2 -0
  195. package/moj/objects/_scrollable-pane.scss.map +1 -0
  196. package/moj/objects/_width-container.scss +2 -0
  197. package/moj/objects/_width-container.scss.map +1 -0
  198. package/moj/settings/_all.scss +2 -0
  199. package/moj/settings/_all.scss.map +1 -0
  200. package/moj/settings/_assets.scss +2 -0
  201. package/moj/settings/_assets.scss.map +1 -0
  202. package/moj/settings/_colours.scss +2 -0
  203. package/moj/settings/_colours.scss.map +1 -0
  204. package/moj/settings/_measurements.scss +2 -0
  205. package/moj/settings/_measurements.scss.map +1 -0
  206. package/moj/settings/_typography.scss +2 -0
  207. package/moj/settings/_typography.scss.map +1 -0
  208. package/moj/template.njk +13 -0
  209. package/moj/utilities/_all.scss +2 -0
  210. package/moj/utilities/_all.scss.map +1 -0
  211. package/moj/utilities/_hidden.scss +2 -0
  212. package/moj/utilities/_hidden.scss.map +1 -0
  213. package/moj/utilities/_width-container.scss +2 -0
  214. package/moj/utilities/_width-container.scss.map +1 -0
  215. package/moj/vendor/govuk-frontend/_base.scss +2 -0
  216. package/moj/vendor/govuk-frontend/_base.scss.map +1 -0
  217. package/moj/vendor/govuk-frontend/_index.scss +2 -0
  218. package/moj/vendor/govuk-frontend/_index.scss.map +1 -0
  219. package/package.json +5 -6
  220. package/moj/all.jquery.min.js +0 -1
  221. package/moj/all.jquery.min.js.map +0 -1
  222. package/moj/all.js +0 -2662
  223. package/moj/all.js.map +0 -1
  224. package/moj/components/add-another/add-another.js +0 -115
  225. package/moj/components/add-another/add-another.js.map +0 -1
  226. package/moj/components/alert/alert.js +0 -356
  227. package/moj/components/alert/alert.js.map +0 -1
  228. package/moj/components/alert/alert.spec.helper.js.map +0 -1
  229. package/moj/components/button-menu/button-menu.js +0 -338
  230. package/moj/components/button-menu/button-menu.js.map +0 -1
  231. package/moj/components/date-picker/date-picker.js +0 -970
  232. package/moj/components/date-picker/date-picker.js.map +0 -1
  233. package/moj/components/filter-toggle-button/filter-toggle-button.js +0 -102
  234. package/moj/components/filter-toggle-button/filter-toggle-button.js.map +0 -1
  235. package/moj/components/form-validator/form-validator.js +0 -205
  236. package/moj/components/form-validator/form-validator.js.map +0 -1
  237. package/moj/components/multi-file-upload/multi-file-upload.js +0 -241
  238. package/moj/components/multi-file-upload/multi-file-upload.js.map +0 -1
  239. package/moj/components/multi-select/multi-select.js +0 -86
  240. package/moj/components/multi-select/multi-select.js.map +0 -1
  241. package/moj/components/password-reveal/password-reveal.js +0 -44
  242. package/moj/components/password-reveal/password-reveal.js.map +0 -1
  243. package/moj/components/rich-text-editor/rich-text-editor.js +0 -166
  244. package/moj/components/rich-text-editor/rich-text-editor.js.map +0 -1
  245. package/moj/components/search-toggle/search-toggle.js +0 -63
  246. package/moj/components/search-toggle/search-toggle.js.map +0 -1
  247. package/moj/components/sortable-table/sortable-table.js +0 -147
  248. package/moj/components/sortable-table/sortable-table.js.map +0 -1
  249. package/moj/helpers.js +0 -200
  250. package/moj/helpers.js.map +0 -1
  251. package/moj/vendor/html5shiv.js +0 -326
  252. package/moj/vendor/jquery.js +0 -9300
  253. package/moj/version.js +0 -12
  254. package/moj/version.js.map +0 -1
  255. package/moj/version.mjs +0 -4
  256. package/moj/version.mjs.map +0 -1
@@ -1,241 +0,0 @@
1
- (function (global, factory) {
2
- typeof exports === 'object' && typeof module !== 'undefined' ? factory(exports) :
3
- typeof define === 'function' && define.amd ? define(['exports'], factory) :
4
- (global = typeof globalThis !== 'undefined' ? globalThis : global || self, factory(global.MOJFrontend = global.MOJFrontend || {}));
5
- })(this, (function (exports) { 'use strict';
6
-
7
- function dragAndDropSupported() {
8
- const div = document.createElement('div');
9
- return typeof div.ondrop !== 'undefined'
10
- }
11
-
12
- function formDataSupported() {
13
- return typeof FormData === 'function'
14
- }
15
-
16
- function fileApiSupported() {
17
- const input = document.createElement('input');
18
- input.type = 'file';
19
- return typeof input.files !== 'undefined'
20
- }
21
-
22
- function MultiFileUpload(params) {
23
- if (!(dragAndDropSupported() && formDataSupported() && fileApiSupported())) {
24
- return
25
- }
26
-
27
- this.defaultParams = {
28
- uploadFileEntryHook: $.noop,
29
- uploadFileExitHook: $.noop,
30
- uploadFileErrorHook: $.noop,
31
- fileDeleteHook: $.noop,
32
- uploadStatusText: 'Uploading files, please wait',
33
- dropzoneHintText: 'Drag and drop files here or',
34
- dropzoneButtonText: 'Choose files'
35
- };
36
-
37
- this.params = $.extend({}, this.defaultParams, params);
38
- this.container = $(this.params.container);
39
-
40
- this.container.addClass('moj-multi-file-upload--enhanced');
41
-
42
- this.feedbackContainer = this.container.find(
43
- '.moj-multi-file__uploaded-files'
44
- );
45
- this.setupFileInput();
46
- this.setupDropzone();
47
- this.setupLabel();
48
- this.setupStatusBox();
49
- this.container.on(
50
- 'click',
51
- '.moj-multi-file-upload__delete',
52
- $.proxy(this, 'onFileDeleteClick')
53
- );
54
- }
55
-
56
- MultiFileUpload.prototype.setupDropzone = function () {
57
- this.fileInput.wrap('<div class="moj-multi-file-upload__dropzone" />');
58
- this.dropzone = this.container.find('.moj-multi-file-upload__dropzone');
59
- this.dropzone.on('dragover', $.proxy(this, 'onDragOver'));
60
- this.dropzone.on('dragleave', $.proxy(this, 'onDragLeave'));
61
- this.dropzone.on('drop', $.proxy(this, 'onDrop'));
62
- };
63
-
64
- MultiFileUpload.prototype.setupLabel = function () {
65
- this.label = $(
66
- `<label for="${this.fileInput[0].id}" class="govuk-button govuk-button--secondary">${this.params.dropzoneButtonText}</label>`
67
- );
68
- this.dropzone.append(
69
- `<p class="govuk-body">${this.params.dropzoneHintText}</p>`
70
- );
71
- this.dropzone.append(this.label);
72
- };
73
-
74
- MultiFileUpload.prototype.setupFileInput = function () {
75
- this.fileInput = this.container.find('.moj-multi-file-upload__input');
76
- this.fileInput.on('change', $.proxy(this, 'onFileChange'));
77
- this.fileInput.on('focus', $.proxy(this, 'onFileFocus'));
78
- this.fileInput.on('blur', $.proxy(this, 'onFileBlur'));
79
- };
80
-
81
- MultiFileUpload.prototype.setupStatusBox = function () {
82
- this.status = $(
83
- '<div aria-live="polite" role="status" class="govuk-visually-hidden" />'
84
- );
85
- this.dropzone.append(this.status);
86
- };
87
-
88
- MultiFileUpload.prototype.onDragOver = function (e) {
89
- e.preventDefault();
90
- this.dropzone.addClass('moj-multi-file-upload--dragover');
91
- };
92
-
93
- MultiFileUpload.prototype.onDragLeave = function () {
94
- this.dropzone.removeClass('moj-multi-file-upload--dragover');
95
- };
96
-
97
- MultiFileUpload.prototype.onDrop = function (e) {
98
- e.preventDefault();
99
- this.dropzone.removeClass('moj-multi-file-upload--dragover');
100
- this.feedbackContainer.removeClass('moj-hidden');
101
- this.status.html(this.params.uploadStatusText);
102
- this.uploadFiles(e.originalEvent.dataTransfer.files);
103
- };
104
-
105
- MultiFileUpload.prototype.uploadFiles = function (files) {
106
- for (let i = 0; i < files.length; i++) {
107
- this.uploadFile(files[i]);
108
- }
109
- };
110
-
111
- MultiFileUpload.prototype.onFileChange = function (e) {
112
- this.feedbackContainer.removeClass('moj-hidden');
113
- this.status.html(this.params.uploadStatusText);
114
- this.uploadFiles(e.currentTarget.files);
115
- this.fileInput.replaceWith($(e.currentTarget).val('').clone(true));
116
- this.setupFileInput();
117
- this.fileInput.get(0).focus();
118
- };
119
-
120
- MultiFileUpload.prototype.onFileFocus = function (e) {
121
- this.label.addClass('moj-multi-file-upload--focused');
122
- };
123
-
124
- MultiFileUpload.prototype.onFileBlur = function (e) {
125
- this.label.removeClass('moj-multi-file-upload--focused');
126
- };
127
-
128
- MultiFileUpload.prototype.getSuccessHtml = function (success) {
129
- return `<span class="moj-multi-file-upload__success"> <svg class="moj-banner__icon" fill="currentColor" role="presentation" focusable="false" xmlns="http://www.w3.org/2000/svg" viewBox="0 0 25 25" height="25" width="25"><path d="M25,6.2L8.7,23.2L0,14.1l4-4.2l4.7,4.9L21,2L25,6.2z"/></svg>${success.messageHtml}</span>`
130
- };
131
-
132
- MultiFileUpload.prototype.getErrorHtml = function (error) {
133
- return `<span class="moj-multi-file-upload__error"> <svg class="moj-banner__icon" fill="currentColor" role="presentation" focusable="false" xmlns="http://www.w3.org/2000/svg" viewBox="0 0 25 25" height="25" width="25"><path d="M13.6,15.4h-2.3v-4.5h2.3V15.4z M13.6,19.8h-2.3v-2.2h2.3V19.8z M0,23.2h25L12.5,2L0,23.2z"/></svg>${error.message}</span>`
134
- };
135
-
136
- MultiFileUpload.prototype.getFileRowHtml = function (file) {
137
- const html = `
138
- <div class="govuk-summary-list__row moj-multi-file-upload__row">
139
- <div class="govuk-summary-list__value moj-multi-file-upload__message">
140
- <span class="moj-multi-file-upload__filename">${file.name}</span>
141
- <span class="moj-multi-file-upload__progress">0%</span>
142
- </div>
143
- <div class="govuk-summary-list__actions moj-multi-file-upload__actions"></div>
144
- </div>`;
145
- return html
146
- };
147
-
148
- MultiFileUpload.prototype.getDeleteButtonHtml = function (file) {
149
- return `<button class="moj-multi-file-upload__delete govuk-button govuk-button--secondary govuk-!-margin-bottom-0" type="button" name="delete" value="${file.filename}">
150
- Delete <span class="govuk-visually-hidden">${file.originalname}</span>
151
- </button>`
152
- };
153
-
154
- MultiFileUpload.prototype.uploadFile = function (file) {
155
- this.params.uploadFileEntryHook(this, file);
156
- const item = $(this.getFileRowHtml(file));
157
- const formData = new FormData();
158
- formData.append('documents', file);
159
- this.feedbackContainer.find('.moj-multi-file-upload__list').append(item);
160
-
161
- $.ajax({
162
- url: this.params.uploadUrl,
163
- type: 'post',
164
- data: formData,
165
- processData: false,
166
- contentType: false,
167
- success: $.proxy(function (response) {
168
- if (response.error) {
169
- item
170
- .find('.moj-multi-file-upload__message')
171
- .html(this.getErrorHtml(response.error));
172
- this.status.html(response.error.message);
173
- } else {
174
- item
175
- .find('.moj-multi-file-upload__message')
176
- .html(this.getSuccessHtml(response.success));
177
- this.status.html(response.success.messageText);
178
- }
179
- item
180
- .find('.moj-multi-file-upload__actions')
181
- .append(this.getDeleteButtonHtml(response.file));
182
- this.params.uploadFileExitHook(this, file, response);
183
- }, this),
184
- error: $.proxy(function (jqXHR, textStatus, errorThrown) {
185
- this.params.uploadFileErrorHook(
186
- this,
187
- file,
188
- jqXHR,
189
- textStatus,
190
- errorThrown
191
- );
192
- }, this),
193
- xhr: function () {
194
- const xhr = new XMLHttpRequest();
195
- xhr.upload.addEventListener(
196
- 'progress',
197
- function (e) {
198
- if (e.lengthComputable) {
199
- let percentComplete = e.loaded / e.total;
200
- percentComplete = parseInt(percentComplete * 100, 10);
201
- item
202
- .find('.moj-multi-file-upload__progress')
203
- .text(` ${percentComplete}%`);
204
- }
205
- },
206
- false
207
- );
208
- return xhr
209
- }
210
- });
211
- };
212
-
213
- MultiFileUpload.prototype.onFileDeleteClick = function (e) {
214
- e.preventDefault(); // if user refreshes page and then deletes
215
- const button = $(e.currentTarget);
216
- const data = {};
217
- data[button[0].name] = button[0].value;
218
- $.ajax({
219
- url: this.params.deleteUrl,
220
- type: 'post',
221
- dataType: 'json',
222
- data,
223
- success: $.proxy(function (response) {
224
- if (response.error) ; else {
225
- button.parents('.moj-multi-file-upload__row').remove();
226
- if (
227
- this.feedbackContainer.find('.moj-multi-file-upload__row').length ===
228
- 0
229
- ) {
230
- this.feedbackContainer.addClass('moj-hidden');
231
- }
232
- }
233
- this.params.fileDeleteHook(this, response);
234
- }, this)
235
- });
236
- };
237
-
238
- exports.MultiFileUpload = MultiFileUpload;
239
-
240
- }));
241
- //# sourceMappingURL=multi-file-upload.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"multi-file-upload.js","sources":["../../../../src/moj/helpers.mjs","../../../../src/moj/components/multi-file-upload/multi-file-upload.mjs"],"sourcesContent":["export function removeAttributeValue(el, attr, value) {\n let re, m\n if (el.getAttribute(attr)) {\n if (el.getAttribute(attr) === value) {\n el.removeAttribute(attr)\n } else {\n re = new RegExp(`(^|\\\\s)${value}(\\\\s|$)`)\n m = el.getAttribute(attr).match(re)\n if (m && m.length === 3) {\n el.setAttribute(\n attr,\n el.getAttribute(attr).replace(re, m[1] && m[2] ? ' ' : '')\n )\n }\n }\n }\n}\n\nexport function addAttributeValue(el, attr, value) {\n let re\n if (!el.getAttribute(attr)) {\n el.setAttribute(attr, value)\n } else {\n re = new RegExp(`(^|\\\\s)${value}(\\\\s|$)`)\n if (!re.test(el.getAttribute(attr))) {\n el.setAttribute(attr, `${el.getAttribute(attr)} ${value}`)\n }\n }\n}\n\nexport function dragAndDropSupported() {\n const div = document.createElement('div')\n return typeof div.ondrop !== 'undefined'\n}\n\nexport function formDataSupported() {\n return typeof FormData === 'function'\n}\n\nexport function fileApiSupported() {\n const input = document.createElement('input')\n input.type = 'file'\n return typeof input.files !== 'undefined'\n}\n\nexport function nodeListForEach(nodes, callback) {\n if (window.NodeList.prototype.forEach) {\n return nodes.forEach(callback)\n }\n for (let i = 0; i < nodes.length; i++) {\n callback.call(window, nodes[i], i, nodes)\n }\n}\n\n/**\n * Find an elements next sibling\n *\n * Utility function to find an elements next sibling matching the provided\n * selector.\n *\n * @param {HTMLElement} $element - Element to find siblings for\n * @param {string} selector - selector for required sibling\n */\nexport function getNextSibling($element, selector) {\n if (!$element) return\n // Get the next sibling element\n let $sibling = $element.nextElementSibling\n\n // If there's no selector, return the first sibling\n if (!selector) return $sibling\n\n // If the sibling matches our selector, use it\n // If not, jump to the next sibling and continue the loop\n while ($sibling) {\n if ($sibling.matches(selector)) return $sibling\n $sibling = $sibling.nextElementSibling\n }\n}\n\n/**\n * Find an elements preceding sibling\n *\n * Utility function to find an elements previous sibling matching the provided\n * selector.\n *\n * @param {HTMLElement} $element - Element to find siblings for\n * @param {string} selector - selector for required sibling\n */\nexport function getPreviousSibling($element, selector) {\n if (!$element) return\n // Get the previous sibling element\n let $sibling = $element.previousElementSibling\n\n // If there's no selector, return the first sibling\n if (!selector) return $sibling\n\n // If the sibling matches our selector, use it\n // If not, jump to the next sibling and continue the loop\n while ($sibling) {\n if ($sibling.matches(selector)) return $sibling\n $sibling = $sibling.previousElementSibling\n }\n}\n\nexport function findNearestMatchingElement($element, selector) {\n // If no element or selector is provided, return null\n if (!$element) return\n if (!selector) return\n\n // Start with the current element\n let $currentElement = $element\n\n while ($currentElement) {\n // First check the current element\n if ($currentElement.matches(selector)) {\n return $currentElement\n }\n\n // Check all previous siblings\n let $sibling = $currentElement.previousElementSibling\n while ($sibling) {\n // Check if the sibling itself is a heading\n if ($sibling.matches(selector)) {\n return $sibling\n }\n $sibling = $sibling.previousElementSibling\n }\n\n // If no match found in siblings, move up to parent\n $currentElement = $currentElement.parentElement\n }\n}\n\n/**\n * Move focus to element\n *\n * Sets tabindex to -1 to make the element programmatically focusable,\n * but removes it on blur as the element doesn't need to be focused again.\n *\n * @param {HTMLElement} $element - HTML element\n * @param {object} [options] - Handler options\n * @param {function(this: HTMLElement): void} [options.onBeforeFocus] - Callback before focus\n * @param {function(this: HTMLElement): void} [options.onBlur] - Callback on blur\n */\nexport function setFocus($element, options = {}) {\n const isFocusable = $element.getAttribute('tabindex')\n\n if (!isFocusable) {\n $element.setAttribute('tabindex', '-1')\n }\n\n /**\n * Handle element focus\n */\n function onFocus() {\n $element.addEventListener('blur', onBlur, { once: true })\n }\n\n /**\n * Handle element blur\n */\n function onBlur() {\n if (options.onBlur) {\n options.onBlur.call($element)\n }\n\n if (!isFocusable) {\n $element.removeAttribute('tabindex')\n }\n }\n\n // Add listener to reset element on blur, after focus\n $element.addEventListener('focus', onFocus, { once: true })\n\n // Focus element\n if (options.onBeforeFocus) {\n options.onBeforeFocus.call($element)\n }\n $element.focus()\n}\n","import $ from 'jquery'\n\nimport {\n dragAndDropSupported,\n fileApiSupported,\n formDataSupported\n} from '../../helpers.mjs'\n\nexport function MultiFileUpload(params) {\n if (!(dragAndDropSupported() && formDataSupported() && fileApiSupported())) {\n return\n }\n\n this.defaultParams = {\n uploadFileEntryHook: $.noop,\n uploadFileExitHook: $.noop,\n uploadFileErrorHook: $.noop,\n fileDeleteHook: $.noop,\n uploadStatusText: 'Uploading files, please wait',\n dropzoneHintText: 'Drag and drop files here or',\n dropzoneButtonText: 'Choose files'\n }\n\n this.params = $.extend({}, this.defaultParams, params)\n this.container = $(this.params.container)\n\n this.container.addClass('moj-multi-file-upload--enhanced')\n\n this.feedbackContainer = this.container.find(\n '.moj-multi-file__uploaded-files'\n )\n this.setupFileInput()\n this.setupDropzone()\n this.setupLabel()\n this.setupStatusBox()\n this.container.on(\n 'click',\n '.moj-multi-file-upload__delete',\n $.proxy(this, 'onFileDeleteClick')\n )\n}\n\nMultiFileUpload.prototype.setupDropzone = function () {\n this.fileInput.wrap('<div class=\"moj-multi-file-upload__dropzone\" />')\n this.dropzone = this.container.find('.moj-multi-file-upload__dropzone')\n this.dropzone.on('dragover', $.proxy(this, 'onDragOver'))\n this.dropzone.on('dragleave', $.proxy(this, 'onDragLeave'))\n this.dropzone.on('drop', $.proxy(this, 'onDrop'))\n}\n\nMultiFileUpload.prototype.setupLabel = function () {\n this.label = $(\n `<label for=\"${this.fileInput[0].id}\" class=\"govuk-button govuk-button--secondary\">${this.params.dropzoneButtonText}</label>`\n )\n this.dropzone.append(\n `<p class=\"govuk-body\">${this.params.dropzoneHintText}</p>`\n )\n this.dropzone.append(this.label)\n}\n\nMultiFileUpload.prototype.setupFileInput = function () {\n this.fileInput = this.container.find('.moj-multi-file-upload__input')\n this.fileInput.on('change', $.proxy(this, 'onFileChange'))\n this.fileInput.on('focus', $.proxy(this, 'onFileFocus'))\n this.fileInput.on('blur', $.proxy(this, 'onFileBlur'))\n}\n\nMultiFileUpload.prototype.setupStatusBox = function () {\n this.status = $(\n '<div aria-live=\"polite\" role=\"status\" class=\"govuk-visually-hidden\" />'\n )\n this.dropzone.append(this.status)\n}\n\nMultiFileUpload.prototype.onDragOver = function (e) {\n e.preventDefault()\n this.dropzone.addClass('moj-multi-file-upload--dragover')\n}\n\nMultiFileUpload.prototype.onDragLeave = function () {\n this.dropzone.removeClass('moj-multi-file-upload--dragover')\n}\n\nMultiFileUpload.prototype.onDrop = function (e) {\n e.preventDefault()\n this.dropzone.removeClass('moj-multi-file-upload--dragover')\n this.feedbackContainer.removeClass('moj-hidden')\n this.status.html(this.params.uploadStatusText)\n this.uploadFiles(e.originalEvent.dataTransfer.files)\n}\n\nMultiFileUpload.prototype.uploadFiles = function (files) {\n for (let i = 0; i < files.length; i++) {\n this.uploadFile(files[i])\n }\n}\n\nMultiFileUpload.prototype.onFileChange = function (e) {\n this.feedbackContainer.removeClass('moj-hidden')\n this.status.html(this.params.uploadStatusText)\n this.uploadFiles(e.currentTarget.files)\n this.fileInput.replaceWith($(e.currentTarget).val('').clone(true))\n this.setupFileInput()\n this.fileInput.get(0).focus()\n}\n\nMultiFileUpload.prototype.onFileFocus = function (e) {\n this.label.addClass('moj-multi-file-upload--focused')\n}\n\nMultiFileUpload.prototype.onFileBlur = function (e) {\n this.label.removeClass('moj-multi-file-upload--focused')\n}\n\nMultiFileUpload.prototype.getSuccessHtml = function (success) {\n return `<span class=\"moj-multi-file-upload__success\"> <svg class=\"moj-banner__icon\" fill=\"currentColor\" role=\"presentation\" focusable=\"false\" xmlns=\"http://www.w3.org/2000/svg\" viewBox=\"0 0 25 25\" height=\"25\" width=\"25\"><path d=\"M25,6.2L8.7,23.2L0,14.1l4-4.2l4.7,4.9L21,2L25,6.2z\"/></svg>${success.messageHtml}</span>`\n}\n\nMultiFileUpload.prototype.getErrorHtml = function (error) {\n return `<span class=\"moj-multi-file-upload__error\"> <svg class=\"moj-banner__icon\" fill=\"currentColor\" role=\"presentation\" focusable=\"false\" xmlns=\"http://www.w3.org/2000/svg\" viewBox=\"0 0 25 25\" height=\"25\" width=\"25\"><path d=\"M13.6,15.4h-2.3v-4.5h2.3V15.4z M13.6,19.8h-2.3v-2.2h2.3V19.8z M0,23.2h25L12.5,2L0,23.2z\"/></svg>${error.message}</span>`\n}\n\nMultiFileUpload.prototype.getFileRowHtml = function (file) {\n const html = `\n <div class=\"govuk-summary-list__row moj-multi-file-upload__row\">\n <div class=\"govuk-summary-list__value moj-multi-file-upload__message\">\n <span class=\"moj-multi-file-upload__filename\">${file.name}</span>\n <span class=\"moj-multi-file-upload__progress\">0%</span>\n </div>\n <div class=\"govuk-summary-list__actions moj-multi-file-upload__actions\"></div>\n </div>`\n return html\n}\n\nMultiFileUpload.prototype.getDeleteButtonHtml = function (file) {\n return `<button class=\"moj-multi-file-upload__delete govuk-button govuk-button--secondary govuk-!-margin-bottom-0\" type=\"button\" name=\"delete\" value=\"${file.filename}\">\n Delete <span class=\"govuk-visually-hidden\">${file.originalname}</span>\n </button>`\n}\n\nMultiFileUpload.prototype.uploadFile = function (file) {\n this.params.uploadFileEntryHook(this, file)\n const item = $(this.getFileRowHtml(file))\n const formData = new FormData()\n formData.append('documents', file)\n this.feedbackContainer.find('.moj-multi-file-upload__list').append(item)\n\n $.ajax({\n url: this.params.uploadUrl,\n type: 'post',\n data: formData,\n processData: false,\n contentType: false,\n success: $.proxy(function (response) {\n if (response.error) {\n item\n .find('.moj-multi-file-upload__message')\n .html(this.getErrorHtml(response.error))\n this.status.html(response.error.message)\n } else {\n item\n .find('.moj-multi-file-upload__message')\n .html(this.getSuccessHtml(response.success))\n this.status.html(response.success.messageText)\n }\n item\n .find('.moj-multi-file-upload__actions')\n .append(this.getDeleteButtonHtml(response.file))\n this.params.uploadFileExitHook(this, file, response)\n }, this),\n error: $.proxy(function (jqXHR, textStatus, errorThrown) {\n this.params.uploadFileErrorHook(\n this,\n file,\n jqXHR,\n textStatus,\n errorThrown\n )\n }, this),\n xhr: function () {\n const xhr = new XMLHttpRequest()\n xhr.upload.addEventListener(\n 'progress',\n function (e) {\n if (e.lengthComputable) {\n let percentComplete = e.loaded / e.total\n percentComplete = parseInt(percentComplete * 100, 10)\n item\n .find('.moj-multi-file-upload__progress')\n .text(` ${percentComplete}%`)\n }\n },\n false\n )\n return xhr\n }\n })\n}\n\nMultiFileUpload.prototype.onFileDeleteClick = function (e) {\n e.preventDefault() // if user refreshes page and then deletes\n const button = $(e.currentTarget)\n const data = {}\n data[button[0].name] = button[0].value\n $.ajax({\n url: this.params.deleteUrl,\n type: 'post',\n dataType: 'json',\n data,\n success: $.proxy(function (response) {\n if (response.error) {\n // handle error\n } else {\n button.parents('.moj-multi-file-upload__row').remove()\n if (\n this.feedbackContainer.find('.moj-multi-file-upload__row').length ===\n 0\n ) {\n this.feedbackContainer.addClass('moj-hidden')\n }\n }\n this.params.fileDeleteHook(this, response)\n }, this)\n })\n}\n"],"names":[],"mappings":";;;;;;EA8BO,SAAS,oBAAoB,GAAG;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A,EAAA,MAAA,IAAA,GAAA;EACA,EAAA,IAAA,CAAA,MAAA,CAAA,CAAA,CAAA,CAAA,IAAA,CAAA,GAAA,MAAA,CAAA,CAAA,CAAA,CAAA;EACA,EAAA,CAAA,CAAA,IAAA,CAAA;EACA,IAAA,GAAA,EAAA,IAAA,CAAA,MAAA,CAAA,SAAA;EACA,IAAA,IAAA,EAAA,MAAA;EACA,IAAA,QAAA,EAAA,MAAA;EACA,IAAA,IAAA;EACA,IAAA,OAAA,EAAA,CAAA,CAAA,KAAA,CAAA,UAAA,QAAA,EAAA;EACA,MAAA,IAAA,QAAA,CAAA,KAAA,EAAA,CAEA,MAAA;EACA,QAAA,MAAA,CAAA,OAAA,CAAA,6BAAA,CAAA,CAAA,MAAA;EACA,QAAA;EACA,UAAA,IAAA,CAAA,iBAAA,CAAA,IAAA,CAAA,6BAAA,CAAA,CAAA,MAAA;EACA,UAAA;EACA,UAAA;EACA,UAAA,IAAA,CAAA,iBAAA,CAAA,QAAA,CAAA,YAAA;EACA;EACA;EACA,MAAA,IAAA,CAAA,MAAA,CAAA,cAAA,CAAA,IAAA,EAAA,QAAA;EACA,KAAA,EAAA,IAAA;EACA,GAAA;EACA;;;;;;;;"}
@@ -1,86 +0,0 @@
1
- (function (global, factory) {
2
- typeof exports === 'object' && typeof module !== 'undefined' ? factory(exports) :
3
- typeof define === 'function' && define.amd ? define(['exports'], factory) :
4
- (global = typeof globalThis !== 'undefined' ? globalThis : global || self, factory(global.MOJFrontend = global.MOJFrontend || {}));
5
- })(this, (function (exports) { 'use strict';
6
-
7
- function MultiSelect(options) {
8
- this.container = $(options.container);
9
-
10
- if (this.container.data('moj-multi-select-initialised')) {
11
- return
12
- }
13
-
14
- this.container.data('moj-multi-select-initialised', true);
15
-
16
- const idPrefix = options.id_prefix;
17
- let allId = 'checkboxes-all';
18
- if (typeof idPrefix !== 'undefined') {
19
- allId = `${idPrefix}checkboxes-all`;
20
- }
21
-
22
- this.toggle = $(this.getToggleHtml(allId));
23
- this.toggleButton = this.toggle.find('input');
24
- this.toggleButton.on('click', $.proxy(this, 'onButtonClick'));
25
- this.container.append(this.toggle);
26
- this.checkboxes = $(options.checkboxes);
27
- this.checkboxes.on('click', $.proxy(this, 'onCheckboxClick'));
28
- this.checked = options.checked || false;
29
- }
30
-
31
- MultiSelect.prototype.getToggleHtml = function (allId) {
32
- let html = '';
33
- html +=
34
- '<div class="govuk-checkboxes__item govuk-checkboxes--small moj-multi-select__checkbox">';
35
- html += ` <input type="checkbox" class="govuk-checkboxes__input" id="${allId}">`;
36
- html += ` <label class="govuk-label govuk-checkboxes__label moj-multi-select__toggle-label" for="${allId}">`;
37
- html += ' <span class="govuk-visually-hidden">Select all</span>';
38
- html += ' </label>';
39
- html += '</div>';
40
- return html
41
- };
42
-
43
- MultiSelect.prototype.onButtonClick = function (e) {
44
- if (this.checked) {
45
- this.uncheckAll();
46
- this.toggleButton[0].checked = false;
47
- } else {
48
- this.checkAll();
49
- this.toggleButton[0].checked = true;
50
- }
51
- };
52
-
53
- MultiSelect.prototype.checkAll = function () {
54
- this.checkboxes.each(
55
- $.proxy(function (index, el) {
56
- el.checked = true;
57
- }, this)
58
- );
59
- this.checked = true;
60
- };
61
-
62
- MultiSelect.prototype.uncheckAll = function () {
63
- this.checkboxes.each(
64
- $.proxy(function (index, el) {
65
- el.checked = false;
66
- }, this)
67
- );
68
- this.checked = false;
69
- };
70
-
71
- MultiSelect.prototype.onCheckboxClick = function (e) {
72
- if (!e.target.checked) {
73
- this.toggleButton[0].checked = false;
74
- this.checked = false;
75
- } else {
76
- if (this.checkboxes.filter(':checked').length === this.checkboxes.length) {
77
- this.toggleButton[0].checked = true;
78
- this.checked = true;
79
- }
80
- }
81
- };
82
-
83
- exports.MultiSelect = MultiSelect;
84
-
85
- }));
86
- //# sourceMappingURL=multi-select.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"multi-select.js","sources":["../../../../src/moj/components/multi-select/multi-select.mjs"],"sourcesContent":["import $ from 'jquery'\n\nexport function MultiSelect(options) {\n this.container = $(options.container)\n\n if (this.container.data('moj-multi-select-initialised')) {\n return\n }\n\n this.container.data('moj-multi-select-initialised', true)\n\n const idPrefix = options.id_prefix\n let allId = 'checkboxes-all'\n if (typeof idPrefix !== 'undefined') {\n allId = `${idPrefix}checkboxes-all`\n }\n\n this.toggle = $(this.getToggleHtml(allId))\n this.toggleButton = this.toggle.find('input')\n this.toggleButton.on('click', $.proxy(this, 'onButtonClick'))\n this.container.append(this.toggle)\n this.checkboxes = $(options.checkboxes)\n this.checkboxes.on('click', $.proxy(this, 'onCheckboxClick'))\n this.checked = options.checked || false\n}\n\nMultiSelect.prototype.getToggleHtml = function (allId) {\n let html = ''\n html +=\n '<div class=\"govuk-checkboxes__item govuk-checkboxes--small moj-multi-select__checkbox\">'\n html += ` <input type=\"checkbox\" class=\"govuk-checkboxes__input\" id=\"${allId}\">`\n html += ` <label class=\"govuk-label govuk-checkboxes__label moj-multi-select__toggle-label\" for=\"${allId}\">`\n html += ' <span class=\"govuk-visually-hidden\">Select all</span>'\n html += ' </label>'\n html += '</div>'\n return html\n}\n\nMultiSelect.prototype.onButtonClick = function (e) {\n if (this.checked) {\n this.uncheckAll()\n this.toggleButton[0].checked = false\n } else {\n this.checkAll()\n this.toggleButton[0].checked = true\n }\n}\n\nMultiSelect.prototype.checkAll = function () {\n this.checkboxes.each(\n $.proxy(function (index, el) {\n el.checked = true\n }, this)\n )\n this.checked = true\n}\n\nMultiSelect.prototype.uncheckAll = function () {\n this.checkboxes.each(\n $.proxy(function (index, el) {\n el.checked = false\n }, this)\n )\n this.checked = false\n}\n\nMultiSelect.prototype.onCheckboxClick = function (e) {\n if (!e.target.checked) {\n this.toggleButton[0].checked = false\n this.checked = false\n } else {\n if (this.checkboxes.filter(':checked').length === this.checkboxes.length) {\n this.toggleButton[0].checked = true\n this.checked = true\n }\n }\n}\n"],"names":[],"mappings":";;;;;;EAEA,SAAA,WAAA,CAAA,OAAA,EAAA;EACA,EAAA,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,MAAA,EAAA;EACA,MAAA,IAAA,CAAA,YAAA,CAAA,CAAA,CAAA,CAAA,OAAA,GAAA;EACA,MAAA,IAAA,CAAA,OAAA,GAAA;EACA;EACA;EACA;;;;;;;;"}
@@ -1,44 +0,0 @@
1
- (function (global, factory) {
2
- typeof exports === 'object' && typeof module !== 'undefined' ? factory(exports) :
3
- typeof define === 'function' && define.amd ? define(['exports'], factory) :
4
- (global = typeof globalThis !== 'undefined' ? globalThis : global || self, factory(global.MOJFrontend = global.MOJFrontend || {}));
5
- })(this, (function (exports) { 'use strict';
6
-
7
- function PasswordReveal(element) {
8
- this.el = element;
9
- const $el = $(this.el);
10
-
11
- if ($el.data('moj-password-reveal-initialised')) {
12
- return
13
- }
14
-
15
- $el.data('moj-password-reveal-initialised', true);
16
- $el.attr('spellcheck', 'false');
17
-
18
- $el.wrap('<div class="moj-password-reveal"></div>');
19
- this.container = $(this.el).parent();
20
- this.createButton();
21
- }
22
-
23
- PasswordReveal.prototype.createButton = function () {
24
- this.button = $(
25
- '<button type="button" class="govuk-button govuk-button--secondary moj-password-reveal__button">Show <span class="govuk-visually-hidden">password</span></button>'
26
- );
27
- this.container.append(this.button);
28
- this.button.on('click', $.proxy(this, 'onButtonClick'));
29
- };
30
-
31
- PasswordReveal.prototype.onButtonClick = function () {
32
- if (this.el.type === 'password') {
33
- this.el.type = 'text';
34
- this.button.html('Hide <span class="govuk-visually-hidden">password</span>');
35
- } else {
36
- this.el.type = 'password';
37
- this.button.html('Show <span class="govuk-visually-hidden">password</span>');
38
- }
39
- };
40
-
41
- exports.PasswordReveal = PasswordReveal;
42
-
43
- }));
44
- //# sourceMappingURL=password-reveal.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"password-reveal.js","sources":["../../../../src/moj/components/password-reveal/password-reveal.mjs"],"sourcesContent":["import $ from 'jquery'\n\nexport function PasswordReveal(element) {\n this.el = element\n const $el = $(this.el)\n\n if ($el.data('moj-password-reveal-initialised')) {\n return\n }\n\n $el.data('moj-password-reveal-initialised', true)\n $el.attr('spellcheck', 'false')\n\n $el.wrap('<div class=\"moj-password-reveal\"></div>')\n this.container = $(this.el).parent()\n this.createButton()\n}\n\nPasswordReveal.prototype.createButton = function () {\n this.button = $(\n '<button type=\"button\" class=\"govuk-button govuk-button--secondary moj-password-reveal__button\">Show <span class=\"govuk-visually-hidden\">password</span></button>'\n )\n this.container.append(this.button)\n this.button.on('click', $.proxy(this, 'onButtonClick'))\n}\n\nPasswordReveal.prototype.onButtonClick = function () {\n if (this.el.type === 'password') {\n this.el.type = 'text'\n this.button.html('Hide <span class=\"govuk-visually-hidden\">password</span>')\n } else {\n this.el.type = 'password'\n this.button.html('Show <span class=\"govuk-visually-hidden\">password</span>')\n }\n}\n"],"names":[],"mappings":";;;;;;EAEA,SAAA,cAAA,CAAA,OAAA,EAAA;EACA,EAAA,IAAA,CAAA,EAAA,GAAA;EACA,EAAA,MAAA,GAAA,GAAA,CAAA,CAAA,IAAA,CAAA,EAAA;;EAEA,EAAA,IAAA,GAAA,CAAA,IAAA,CAAA,iCAAA,CAAA,EAAA;EACA,IAAA;EACA;;EAEA,EAAA,GAAA,CAAA,IAAA,CAAA,iCAAA,EAAA,IAAA;EACA,EAAA,GAAA,CAAA,IAAA,CAAA,YAAA,EAAA,OAAA;;EAEA,EAAA,GAAA,CAAA,IAAA,CAAA,yCAAA;EACA,EAAA,IAAA,CAAA,SAAA,GAAA,CAAA,CAAA,IAAA,CAAA,EAAA,CAAA,CAAA,MAAA;EACA,EAAA,IAAA,CAAA,YAAA;EACA;;EAEA,cAAA,CAAA,SAAA,CAAA,YAAA,GAAA,YAAA;EACA,EAAA,IAAA,CAAA,MAAA,GAAA,CAAA;EACA,IAAA;EACA;EACA,EAAA,IAAA,CAAA,SAAA,CAAA,MAAA,CAAA,IAAA,CAAA,MAAA;EACA,EAAA,IAAA,CAAA,MAAA,CAAA,EAAA,CAAA,OAAA,EAAA,CAAA,CAAA,KAAA,CAAA,IAAA,EAAA,eAAA,CAAA;EACA;;EAEA,cAAA,CAAA,SAAA,CAAA,aAAA,GAAA,YAAA;EACA,EAAA,IAAA,IAAA,CAAA,EAAA,CAAA,IAAA,KAAA,UAAA,EAAA;EACA,IAAA,IAAA,CAAA,EAAA,CAAA,IAAA,GAAA;EACA,IAAA,IAAA,CAAA,MAAA,CAAA,IAAA,CAAA,0DAAA;EACA,GAAA,MAAA;EACA,IAAA,IAAA,CAAA,EAAA,CAAA,IAAA,GAAA;EACA,IAAA,IAAA,CAAA,MAAA,CAAA,IAAA,CAAA,0DAAA;EACA;EACA;;;;;;;;"}
@@ -1,166 +0,0 @@
1
- (function (global, factory) {
2
- typeof exports === 'object' && typeof module !== 'undefined' ? factory(exports) :
3
- typeof define === 'function' && define.amd ? define(['exports'], factory) :
4
- (global = typeof globalThis !== 'undefined' ? globalThis : global || self, factory(global.MOJFrontend = global.MOJFrontend || {}));
5
- })(this, (function (exports) { 'use strict';
6
-
7
- function RichTextEditor(options) {
8
- if (!('contentEditable' in document.documentElement)) {
9
- return
10
- }
11
-
12
- this.options = options;
13
- this.options.toolbar = this.options.toolbar || {
14
- bold: false,
15
- italic: false,
16
- underline: false,
17
- bullets: true,
18
- numbers: true
19
- };
20
- this.textarea = this.options.textarea;
21
- this.container = $(this.textarea).parent();
22
-
23
- if (this.container.data('moj-rich-text-editor-initialised')) {
24
- return
25
- }
26
-
27
- this.container.data('moj-rich-text-editor-initialised', true);
28
-
29
- this.createToolbar();
30
- this.hideDefault();
31
- this.configureToolbar();
32
- this.keys = {
33
- left: 37,
34
- right: 39,
35
- up: 38,
36
- down: 40
37
- };
38
- this.container.on(
39
- 'click',
40
- '.moj-rich-text-editor__toolbar-button',
41
- $.proxy(this, 'onButtonClick')
42
- );
43
- this.container
44
- .find('.moj-rich-text-editor__content')
45
- .on('input', $.proxy(this, 'onEditorInput'));
46
- this.container.find('label').on('click', $.proxy(this, 'onLabelClick'));
47
- this.toolbar.on('keydown', $.proxy(this, 'onToolbarKeydown'));
48
- }
49
-
50
- RichTextEditor.prototype.onToolbarKeydown = function (e) {
51
- let focusableButton;
52
- switch (e.keyCode) {
53
- case this.keys.right:
54
- case this.keys.down: {
55
- focusableButton = this.toolbar.find('button[tabindex=0]');
56
- const nextButton = focusableButton.next('button');
57
- if (nextButton[0]) {
58
- nextButton.focus();
59
- focusableButton.attr('tabindex', '-1');
60
- nextButton.attr('tabindex', '0');
61
- }
62
- break
63
- }
64
- case this.keys.left:
65
- case this.keys.up: {
66
- focusableButton = this.toolbar.find('button[tabindex=0]');
67
- const previousButton = focusableButton.prev('button');
68
- if (previousButton[0]) {
69
- previousButton.focus();
70
- focusableButton.attr('tabindex', '-1');
71
- previousButton.attr('tabindex', '0');
72
- }
73
- break
74
- }
75
- }
76
- };
77
-
78
- RichTextEditor.prototype.getToolbarHtml = function () {
79
- let html = '';
80
-
81
- html += '<div class="moj-rich-text-editor__toolbar" role="toolbar">';
82
-
83
- if (this.options.toolbar.bold) {
84
- html +=
85
- '<button class="moj-rich-text-editor__toolbar-button moj-rich-text-editor__toolbar-button--bold" type="button" data-command="bold"><span class="govuk-visually-hidden">Bold</span></button>';
86
- }
87
-
88
- if (this.options.toolbar.italic) {
89
- html +=
90
- '<button class="moj-rich-text-editor__toolbar-button moj-rich-text-editor__toolbar-button--italic" type="button" data-command="italic"><span class="govuk-visually-hidden">Italic</span></button>';
91
- }
92
-
93
- if (this.options.toolbar.underline) {
94
- html +=
95
- '<button class="moj-rich-text-editor__toolbar-button moj-rich-text-editor__toolbar-button--underline" type="button" data-command="underline"><span class="govuk-visually-hidden">Underline</span></button>';
96
- }
97
-
98
- if (this.options.toolbar.bullets) {
99
- html +=
100
- '<button class="moj-rich-text-editor__toolbar-button moj-rich-text-editor__toolbar-button--unordered-list" type="button" data-command="insertUnorderedList"><span class="govuk-visually-hidden">Unordered list</span></button>';
101
- }
102
-
103
- if (this.options.toolbar.numbers) {
104
- html +=
105
- '<button class="moj-rich-text-editor__toolbar-button moj-rich-text-editor__toolbar-button--ordered-list" type="button" data-command="insertOrderedList"><span class="govuk-visually-hidden">Ordered list</span></button>';
106
- }
107
-
108
- html += '</div>';
109
- return html
110
- };
111
-
112
- RichTextEditor.prototype.getEnhancedHtml = function (val) {
113
- return `${this.getToolbarHtml()}<div class="govuk-textarea moj-rich-text-editor__content" contenteditable="true" spellcheck="false"></div>`
114
- };
115
-
116
- RichTextEditor.prototype.hideDefault = function () {
117
- this.textarea = this.container.find('textarea');
118
- this.textarea.addClass('govuk-visually-hidden');
119
- this.textarea.attr('aria-hidden', true);
120
- this.textarea.attr('tabindex', '-1');
121
- };
122
-
123
- RichTextEditor.prototype.createToolbar = function () {
124
- this.toolbar = document.createElement('div');
125
- this.toolbar.className = 'moj-rich-text-editor';
126
- this.toolbar.innerHTML = this.getEnhancedHtml();
127
- this.container.append(this.toolbar);
128
- this.toolbar = this.container.find('.moj-rich-text-editor__toolbar');
129
- this.container
130
- .find('.moj-rich-text-editor__content')
131
- .html(this.textarea.val());
132
- };
133
-
134
- RichTextEditor.prototype.configureToolbar = function () {
135
- this.buttons = this.container.find('.moj-rich-text-editor__toolbar-button');
136
- this.buttons.prop('tabindex', '-1');
137
- const firstTab = this.buttons.first();
138
- firstTab.prop('tabindex', '0');
139
- };
140
-
141
- RichTextEditor.prototype.onButtonClick = function (e) {
142
- document.execCommand($(e.currentTarget).data('command'), false, null);
143
- };
144
-
145
- RichTextEditor.prototype.getContent = function () {
146
- return this.container.find('.moj-rich-text-editor__content').html()
147
- };
148
-
149
- RichTextEditor.prototype.onEditorInput = function (e) {
150
- this.updateTextarea();
151
- };
152
-
153
- RichTextEditor.prototype.updateTextarea = function () {
154
- document.execCommand('defaultParagraphSeparator', false, 'p');
155
- this.textarea.val(this.getContent());
156
- };
157
-
158
- RichTextEditor.prototype.onLabelClick = function (e) {
159
- e.preventDefault();
160
- this.container.find('.moj-rich-text-editor__content').focus();
161
- };
162
-
163
- exports.RichTextEditor = RichTextEditor;
164
-
165
- }));
166
- //# sourceMappingURL=rich-text-editor.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"rich-text-editor.js","sources":["../../../../src/moj/components/rich-text-editor/rich-text-editor.mjs"],"sourcesContent":["import $ from 'jquery'\n\nexport function RichTextEditor(options) {\n if (!('contentEditable' in document.documentElement)) {\n return\n }\n\n this.options = options\n this.options.toolbar = this.options.toolbar || {\n bold: false,\n italic: false,\n underline: false,\n bullets: true,\n numbers: true\n }\n this.textarea = this.options.textarea\n this.container = $(this.textarea).parent()\n\n if (this.container.data('moj-rich-text-editor-initialised')) {\n return\n }\n\n this.container.data('moj-rich-text-editor-initialised', true)\n\n this.createToolbar()\n this.hideDefault()\n this.configureToolbar()\n this.keys = {\n left: 37,\n right: 39,\n up: 38,\n down: 40\n }\n this.container.on(\n 'click',\n '.moj-rich-text-editor__toolbar-button',\n $.proxy(this, 'onButtonClick')\n )\n this.container\n .find('.moj-rich-text-editor__content')\n .on('input', $.proxy(this, 'onEditorInput'))\n this.container.find('label').on('click', $.proxy(this, 'onLabelClick'))\n this.toolbar.on('keydown', $.proxy(this, 'onToolbarKeydown'))\n}\n\nRichTextEditor.prototype.onToolbarKeydown = function (e) {\n let focusableButton\n switch (e.keyCode) {\n case this.keys.right:\n case this.keys.down: {\n focusableButton = this.toolbar.find('button[tabindex=0]')\n const nextButton = focusableButton.next('button')\n if (nextButton[0]) {\n nextButton.focus()\n focusableButton.attr('tabindex', '-1')\n nextButton.attr('tabindex', '0')\n }\n break\n }\n case this.keys.left:\n case this.keys.up: {\n focusableButton = this.toolbar.find('button[tabindex=0]')\n const previousButton = focusableButton.prev('button')\n if (previousButton[0]) {\n previousButton.focus()\n focusableButton.attr('tabindex', '-1')\n previousButton.attr('tabindex', '0')\n }\n break\n }\n }\n}\n\nRichTextEditor.prototype.getToolbarHtml = function () {\n let html = ''\n\n html += '<div class=\"moj-rich-text-editor__toolbar\" role=\"toolbar\">'\n\n if (this.options.toolbar.bold) {\n html +=\n '<button class=\"moj-rich-text-editor__toolbar-button moj-rich-text-editor__toolbar-button--bold\" type=\"button\" data-command=\"bold\"><span class=\"govuk-visually-hidden\">Bold</span></button>'\n }\n\n if (this.options.toolbar.italic) {\n html +=\n '<button class=\"moj-rich-text-editor__toolbar-button moj-rich-text-editor__toolbar-button--italic\" type=\"button\" data-command=\"italic\"><span class=\"govuk-visually-hidden\">Italic</span></button>'\n }\n\n if (this.options.toolbar.underline) {\n html +=\n '<button class=\"moj-rich-text-editor__toolbar-button moj-rich-text-editor__toolbar-button--underline\" type=\"button\" data-command=\"underline\"><span class=\"govuk-visually-hidden\">Underline</span></button>'\n }\n\n if (this.options.toolbar.bullets) {\n html +=\n '<button class=\"moj-rich-text-editor__toolbar-button moj-rich-text-editor__toolbar-button--unordered-list\" type=\"button\" data-command=\"insertUnorderedList\"><span class=\"govuk-visually-hidden\">Unordered list</span></button>'\n }\n\n if (this.options.toolbar.numbers) {\n html +=\n '<button class=\"moj-rich-text-editor__toolbar-button moj-rich-text-editor__toolbar-button--ordered-list\" type=\"button\" data-command=\"insertOrderedList\"><span class=\"govuk-visually-hidden\">Ordered list</span></button>'\n }\n\n html += '</div>'\n return html\n}\n\nRichTextEditor.prototype.getEnhancedHtml = function (val) {\n return `${this.getToolbarHtml()}<div class=\"govuk-textarea moj-rich-text-editor__content\" contenteditable=\"true\" spellcheck=\"false\"></div>`\n}\n\nRichTextEditor.prototype.hideDefault = function () {\n this.textarea = this.container.find('textarea')\n this.textarea.addClass('govuk-visually-hidden')\n this.textarea.attr('aria-hidden', true)\n this.textarea.attr('tabindex', '-1')\n}\n\nRichTextEditor.prototype.createToolbar = function () {\n this.toolbar = document.createElement('div')\n this.toolbar.className = 'moj-rich-text-editor'\n this.toolbar.innerHTML = this.getEnhancedHtml()\n this.container.append(this.toolbar)\n this.toolbar = this.container.find('.moj-rich-text-editor__toolbar')\n this.container\n .find('.moj-rich-text-editor__content')\n .html(this.textarea.val())\n}\n\nRichTextEditor.prototype.configureToolbar = function () {\n this.buttons = this.container.find('.moj-rich-text-editor__toolbar-button')\n this.buttons.prop('tabindex', '-1')\n const firstTab = this.buttons.first()\n firstTab.prop('tabindex', '0')\n}\n\nRichTextEditor.prototype.onButtonClick = function (e) {\n document.execCommand($(e.currentTarget).data('command'), false, null)\n}\n\nRichTextEditor.prototype.getContent = function () {\n return this.container.find('.moj-rich-text-editor__content').html()\n}\n\nRichTextEditor.prototype.onEditorInput = function (e) {\n this.updateTextarea()\n}\n\nRichTextEditor.prototype.updateTextarea = function () {\n document.execCommand('defaultParagraphSeparator', false, 'p')\n this.textarea.val(this.getContent())\n}\n\nRichTextEditor.prototype.onLabelClick = function (e) {\n e.preventDefault()\n this.container.find('.moj-rich-text-editor__content').focus()\n}\n"],"names":[],"mappings":";;;;;;EAEA,SAAA,cAAA,CAAA,OAAA,EAAA;EACA,EAAA,IAAA,EAAA,iBAAA,IAAA,QAAA,CAAA,eAAA,CAAA,EAAA;EACA,IAAA;EACA;;EAEA,EAAA,IAAA,CAAA,OAAA,GAAA;EACA,EAAA,IAAA,CAAA,OAAA,CAAA,OAAA,GAAA,IAAA,CAAA,OAAA,CAAA,OAAA,IAAA;EACA,IAAA,IAAA,EAAA,KAAA;EACA,IAAA,MAAA,EAAA,KAAA;EACA,IAAA,SAAA,EAAA,KAAA;EACA,IAAA,OAAA,EAAA,IAAA;EACA,IAAA,OAAA,EAAA;EACA;EACA,EAAA,IAAA,CAAA,QAAA,GAAA,IAAA,CAAA,OAAA,CAAA;EACA,EAAA,IAAA,CAAA,SAAA,GAAA,CAAA,CAAA,IAAA,CAAA,QAAA,CAAA,CAAA,MAAA;;EAEA,EAAA,IAAA,IAAA,CAAA,SAAA,CAAA,IAAA,CAAA,kCAAA,CAAA,EAAA;EACA,IAAA;EACA;;EAEA,EAAA,IAAA,CAAA,SAAA,CAAA,IAAA,CAAA,kCAAA,EAAA,IAAA;;EAEA,EAAA,IAAA,CAAA,aAAA;EACA,EAAA,IAAA,CAAA,WAAA;EACA,EAAA,IAAA,CAAA,gBAAA;EACA,EAAA,IAAA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