@ministryofjustice/frontend 3.4.0 → 3.6.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 (50) hide show
  1. package/moj/all.jquery.js +13378 -0
  2. package/moj/all.jquery.min.js +1 -144
  3. package/moj/all.js +2266 -2551
  4. package/moj/all.mjs +126 -0
  5. package/moj/components/add-another/add-another.js +110 -100
  6. package/moj/components/add-another/add-another.mjs +106 -0
  7. package/moj/components/alert/alert.js +319 -211
  8. package/moj/components/alert/alert.mjs +251 -0
  9. package/moj/components/alert/alert.spec.helper.js +12 -5
  10. package/moj/components/alert/alert.spec.helper.mjs +66 -0
  11. package/moj/components/button-menu/button-menu.js +302 -292
  12. package/moj/components/button-menu/button-menu.mjs +329 -0
  13. package/moj/components/date-picker/date-picker.js +850 -842
  14. package/moj/components/date-picker/date-picker.mjs +961 -0
  15. package/moj/components/filter-toggle-button/filter-toggle-button.js +98 -88
  16. package/moj/components/filter-toggle-button/filter-toggle-button.mjs +93 -0
  17. package/moj/components/form-validator/form-validator.js +195 -155
  18. package/moj/components/form-validator/form-validator.mjs +168 -0
  19. package/moj/components/multi-file-upload/multi-file-upload.js +158 -137
  20. package/moj/components/multi-file-upload/multi-file-upload.mjs +219 -0
  21. package/moj/components/multi-select/multi-select.js +75 -65
  22. package/moj/components/multi-select/multi-select.mjs +77 -0
  23. package/moj/components/password-reveal/password-reveal.js +40 -30
  24. package/moj/components/password-reveal/password-reveal.mjs +35 -0
  25. package/moj/components/rich-text-editor/rich-text-editor.js +92 -80
  26. package/moj/components/rich-text-editor/rich-text-editor.mjs +157 -0
  27. package/moj/components/search-toggle/search-toggle.js +55 -45
  28. package/moj/components/search-toggle/search-toggle.mjs +54 -0
  29. package/moj/components/sortable-table/sortable-table.js +141 -141
  30. package/moj/components/sortable-table/sortable-table.mjs +138 -0
  31. package/moj/helpers/_links.scss +1 -1
  32. package/moj/helpers.js +171 -152
  33. package/moj/helpers.mjs +123 -0
  34. package/moj/moj-frontend.min.js +1 -144
  35. package/moj/version.js +11 -1
  36. package/moj/version.mjs +3 -0
  37. package/package.json +13 -1
  38. package/moj/all.spec.js +0 -24
  39. package/moj/components/add-another/add-another.spec.js +0 -165
  40. package/moj/components/alert/alert.spec.js +0 -229
  41. package/moj/components/button-menu/button-menu.spec.js +0 -360
  42. package/moj/components/date-picker/date-picker.spec.js +0 -1178
  43. package/moj/components/filter-toggle-button/filter-toggle-button.spec.js +0 -302
  44. package/moj/components/multi-file-upload/multi-file-upload.spec.js +0 -510
  45. package/moj/components/multi-select/multi-select.spec.js +0 -128
  46. package/moj/components/password-reveal/password-reveal.spec.js +0 -57
  47. package/moj/components/search-toggle/search-toggle.spec.js +0 -129
  48. package/moj/components/sortable-table/sortable-table.spec.js +0 -362
  49. package/moj/helpers.spec.js +0 -235
  50. package/moj/namespace.js +0 -2
@@ -1,153 +1,165 @@
1
- if ('contentEditable' in document.documentElement) {
2
- MOJFrontend.RichTextEditor = function (options) {
3
- this.options = options
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;
4
13
  this.options.toolbar = this.options.toolbar || {
5
14
  bold: false,
6
15
  italic: false,
7
16
  underline: false,
8
17
  bullets: true,
9
18
  numbers: true
10
- }
11
- this.textarea = this.options.textarea
12
- this.container = $(this.textarea).parent()
19
+ };
20
+ this.textarea = this.options.textarea;
21
+ this.container = window.jQuery(this.textarea).parent();
13
22
 
14
23
  if (this.container.data('moj-rich-text-editor-initialised')) {
15
24
  return
16
25
  }
17
26
 
18
- this.container.data('moj-rich-text-editor-initialised', true)
27
+ this.container.data('moj-rich-text-editor-initialised', true);
19
28
 
20
- this.createToolbar()
21
- this.hideDefault()
22
- this.configureToolbar()
29
+ this.createToolbar();
30
+ this.hideDefault();
31
+ this.configureToolbar();
23
32
  this.keys = {
24
33
  left: 37,
25
34
  right: 39,
26
35
  up: 38,
27
36
  down: 40
28
- }
37
+ };
29
38
  this.container.on(
30
39
  'click',
31
40
  '.moj-rich-text-editor__toolbar-button',
32
- $.proxy(this, 'onButtonClick')
33
- )
41
+ window.jQuery.proxy(this, 'onButtonClick')
42
+ );
34
43
  this.container
35
44
  .find('.moj-rich-text-editor__content')
36
- .on('input', $.proxy(this, 'onEditorInput'))
37
- this.container.find('label').on('click', $.proxy(this, 'onLabelClick'))
38
- this.toolbar.on('keydown', $.proxy(this, 'onToolbarKeydown'))
45
+ .on('input', window.jQuery.proxy(this, 'onEditorInput'));
46
+ this.container.find('label').on('click', window.jQuery.proxy(this, 'onLabelClick'));
47
+ this.toolbar.on('keydown', window.jQuery.proxy(this, 'onToolbarKeydown'));
39
48
  }
40
49
 
41
- MOJFrontend.RichTextEditor.prototype.onToolbarKeydown = function (e) {
42
- let focusableButton
50
+ RichTextEditor.prototype.onToolbarKeydown = function (e) {
51
+ let focusableButton;
43
52
  switch (e.keyCode) {
44
53
  case this.keys.right:
45
54
  case this.keys.down: {
46
- focusableButton = this.toolbar.find('button[tabindex=0]')
47
- const nextButton = focusableButton.next('button')
55
+ focusableButton = this.toolbar.find('button[tabindex=0]');
56
+ const nextButton = focusableButton.next('button');
48
57
  if (nextButton[0]) {
49
- nextButton.focus()
50
- focusableButton.attr('tabindex', '-1')
51
- nextButton.attr('tabindex', '0')
58
+ nextButton.focus();
59
+ focusableButton.attr('tabindex', '-1');
60
+ nextButton.attr('tabindex', '0');
52
61
  }
53
62
  break
54
63
  }
55
64
  case this.keys.left:
56
65
  case this.keys.up: {
57
- focusableButton = this.toolbar.find('button[tabindex=0]')
58
- const previousButton = focusableButton.prev('button')
66
+ focusableButton = this.toolbar.find('button[tabindex=0]');
67
+ const previousButton = focusableButton.prev('button');
59
68
  if (previousButton[0]) {
60
- previousButton.focus()
61
- focusableButton.attr('tabindex', '-1')
62
- previousButton.attr('tabindex', '0')
69
+ previousButton.focus();
70
+ focusableButton.attr('tabindex', '-1');
71
+ previousButton.attr('tabindex', '0');
63
72
  }
64
73
  break
65
74
  }
66
75
  }
67
- }
76
+ };
68
77
 
69
- MOJFrontend.RichTextEditor.prototype.getToolbarHtml = function () {
70
- let html = ''
78
+ RichTextEditor.prototype.getToolbarHtml = function () {
79
+ let html = '';
71
80
 
72
- html += '<div class="moj-rich-text-editor__toolbar" role="toolbar">'
81
+ html += '<div class="moj-rich-text-editor__toolbar" role="toolbar">';
73
82
 
74
83
  if (this.options.toolbar.bold) {
75
84
  html +=
76
- '<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>'
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>';
77
86
  }
78
87
 
79
88
  if (this.options.toolbar.italic) {
80
89
  html +=
81
- '<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>'
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>';
82
91
  }
83
92
 
84
93
  if (this.options.toolbar.underline) {
85
94
  html +=
86
- '<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>'
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>';
87
96
  }
88
97
 
89
98
  if (this.options.toolbar.bullets) {
90
99
  html +=
91
- '<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>'
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>';
92
101
  }
93
102
 
94
103
  if (this.options.toolbar.numbers) {
95
104
  html +=
96
- '<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>'
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>';
97
106
  }
98
107
 
99
- html += '</div>'
108
+ html += '</div>';
100
109
  return html
101
- }
110
+ };
102
111
 
103
- MOJFrontend.RichTextEditor.prototype.getEnhancedHtml = function (val) {
112
+ RichTextEditor.prototype.getEnhancedHtml = function (val) {
104
113
  return `${this.getToolbarHtml()}<div class="govuk-textarea moj-rich-text-editor__content" contenteditable="true" spellcheck="false"></div>`
105
- }
106
-
107
- MOJFrontend.RichTextEditor.prototype.hideDefault = function () {
108
- this.textarea = this.container.find('textarea')
109
- this.textarea.addClass('govuk-visually-hidden')
110
- this.textarea.attr('aria-hidden', true)
111
- this.textarea.attr('tabindex', '-1')
112
- }
113
-
114
- MOJFrontend.RichTextEditor.prototype.createToolbar = function () {
115
- this.toolbar = document.createElement('div')
116
- this.toolbar.className = 'moj-rich-text-editor'
117
- this.toolbar.innerHTML = this.getEnhancedHtml()
118
- this.container.append(this.toolbar)
119
- this.toolbar = this.container.find('.moj-rich-text-editor__toolbar')
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');
120
129
  this.container
121
130
  .find('.moj-rich-text-editor__content')
122
- .html(this.textarea.val())
123
- }
131
+ .html(this.textarea.val());
132
+ };
124
133
 
125
- MOJFrontend.RichTextEditor.prototype.configureToolbar = function () {
126
- this.buttons = this.container.find('.moj-rich-text-editor__toolbar-button')
127
- this.buttons.prop('tabindex', '-1')
128
- const firstTab = this.buttons.first()
129
- firstTab.prop('tabindex', '0')
130
- }
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
+ };
131
140
 
132
- MOJFrontend.RichTextEditor.prototype.onButtonClick = function (e) {
133
- document.execCommand($(e.currentTarget).data('command'), false, null)
134
- }
141
+ RichTextEditor.prototype.onButtonClick = function (e) {
142
+ document.execCommand(window.jQuery(e.currentTarget).data('command'), false, null);
143
+ };
135
144
 
136
- MOJFrontend.RichTextEditor.prototype.getContent = function () {
145
+ RichTextEditor.prototype.getContent = function () {
137
146
  return this.container.find('.moj-rich-text-editor__content').html()
138
- }
147
+ };
139
148
 
140
- MOJFrontend.RichTextEditor.prototype.onEditorInput = function (e) {
141
- this.updateTextarea()
142
- }
149
+ RichTextEditor.prototype.onEditorInput = function (e) {
150
+ this.updateTextarea();
151
+ };
143
152
 
144
- MOJFrontend.RichTextEditor.prototype.updateTextarea = function () {
145
- document.execCommand('defaultParagraphSeparator', false, 'p')
146
- this.textarea.val(this.getContent())
147
- }
153
+ RichTextEditor.prototype.updateTextarea = function () {
154
+ document.execCommand('defaultParagraphSeparator', false, 'p');
155
+ this.textarea.val(this.getContent());
156
+ };
148
157
 
149
- MOJFrontend.RichTextEditor.prototype.onLabelClick = function (e) {
150
- e.preventDefault()
151
- this.container.find('.moj-rich-text-editor__content').focus()
152
- }
153
- }
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
+ }));
@@ -0,0 +1,157 @@
1
+ function RichTextEditor(options) {
2
+ if (!('contentEditable' in document.documentElement)) {
3
+ return
4
+ }
5
+
6
+ this.options = options;
7
+ this.options.toolbar = this.options.toolbar || {
8
+ bold: false,
9
+ italic: false,
10
+ underline: false,
11
+ bullets: true,
12
+ numbers: true
13
+ };
14
+ this.textarea = this.options.textarea;
15
+ this.container = window.jQuery(this.textarea).parent();
16
+
17
+ if (this.container.data('moj-rich-text-editor-initialised')) {
18
+ return
19
+ }
20
+
21
+ this.container.data('moj-rich-text-editor-initialised', true);
22
+
23
+ this.createToolbar();
24
+ this.hideDefault();
25
+ this.configureToolbar();
26
+ this.keys = {
27
+ left: 37,
28
+ right: 39,
29
+ up: 38,
30
+ down: 40
31
+ };
32
+ this.container.on(
33
+ 'click',
34
+ '.moj-rich-text-editor__toolbar-button',
35
+ window.jQuery.proxy(this, 'onButtonClick')
36
+ );
37
+ this.container
38
+ .find('.moj-rich-text-editor__content')
39
+ .on('input', window.jQuery.proxy(this, 'onEditorInput'));
40
+ this.container.find('label').on('click', window.jQuery.proxy(this, 'onLabelClick'));
41
+ this.toolbar.on('keydown', window.jQuery.proxy(this, 'onToolbarKeydown'));
42
+ }
43
+
44
+ RichTextEditor.prototype.onToolbarKeydown = function (e) {
45
+ let focusableButton;
46
+ switch (e.keyCode) {
47
+ case this.keys.right:
48
+ case this.keys.down: {
49
+ focusableButton = this.toolbar.find('button[tabindex=0]');
50
+ const nextButton = focusableButton.next('button');
51
+ if (nextButton[0]) {
52
+ nextButton.focus();
53
+ focusableButton.attr('tabindex', '-1');
54
+ nextButton.attr('tabindex', '0');
55
+ }
56
+ break
57
+ }
58
+ case this.keys.left:
59
+ case this.keys.up: {
60
+ focusableButton = this.toolbar.find('button[tabindex=0]');
61
+ const previousButton = focusableButton.prev('button');
62
+ if (previousButton[0]) {
63
+ previousButton.focus();
64
+ focusableButton.attr('tabindex', '-1');
65
+ previousButton.attr('tabindex', '0');
66
+ }
67
+ break
68
+ }
69
+ }
70
+ };
71
+
72
+ RichTextEditor.prototype.getToolbarHtml = function () {
73
+ let html = '';
74
+
75
+ html += '<div class="moj-rich-text-editor__toolbar" role="toolbar">';
76
+
77
+ if (this.options.toolbar.bold) {
78
+ html +=
79
+ '<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>';
80
+ }
81
+
82
+ if (this.options.toolbar.italic) {
83
+ html +=
84
+ '<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>';
85
+ }
86
+
87
+ if (this.options.toolbar.underline) {
88
+ html +=
89
+ '<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>';
90
+ }
91
+
92
+ if (this.options.toolbar.bullets) {
93
+ html +=
94
+ '<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>';
95
+ }
96
+
97
+ if (this.options.toolbar.numbers) {
98
+ html +=
99
+ '<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>';
100
+ }
101
+
102
+ html += '</div>';
103
+ return html
104
+ };
105
+
106
+ RichTextEditor.prototype.getEnhancedHtml = function (val) {
107
+ return `${this.getToolbarHtml()}<div class="govuk-textarea moj-rich-text-editor__content" contenteditable="true" spellcheck="false"></div>`
108
+ };
109
+
110
+ RichTextEditor.prototype.hideDefault = function () {
111
+ this.textarea = this.container.find('textarea');
112
+ this.textarea.addClass('govuk-visually-hidden');
113
+ this.textarea.attr('aria-hidden', true);
114
+ this.textarea.attr('tabindex', '-1');
115
+ };
116
+
117
+ RichTextEditor.prototype.createToolbar = function () {
118
+ this.toolbar = document.createElement('div');
119
+ this.toolbar.className = 'moj-rich-text-editor';
120
+ this.toolbar.innerHTML = this.getEnhancedHtml();
121
+ this.container.append(this.toolbar);
122
+ this.toolbar = this.container.find('.moj-rich-text-editor__toolbar');
123
+ this.container
124
+ .find('.moj-rich-text-editor__content')
125
+ .html(this.textarea.val());
126
+ };
127
+
128
+ RichTextEditor.prototype.configureToolbar = function () {
129
+ this.buttons = this.container.find('.moj-rich-text-editor__toolbar-button');
130
+ this.buttons.prop('tabindex', '-1');
131
+ const firstTab = this.buttons.first();
132
+ firstTab.prop('tabindex', '0');
133
+ };
134
+
135
+ RichTextEditor.prototype.onButtonClick = function (e) {
136
+ document.execCommand(window.jQuery(e.currentTarget).data('command'), false, null);
137
+ };
138
+
139
+ RichTextEditor.prototype.getContent = function () {
140
+ return this.container.find('.moj-rich-text-editor__content').html()
141
+ };
142
+
143
+ RichTextEditor.prototype.onEditorInput = function (e) {
144
+ this.updateTextarea();
145
+ };
146
+
147
+ RichTextEditor.prototype.updateTextarea = function () {
148
+ document.execCommand('defaultParagraphSeparator', false, 'p');
149
+ this.textarea.val(this.getContent());
150
+ };
151
+
152
+ RichTextEditor.prototype.onLabelClick = function (e) {
153
+ e.preventDefault();
154
+ this.container.find('.moj-rich-text-editor__content').focus();
155
+ };
156
+
157
+ export { RichTextEditor };
@@ -1,52 +1,62 @@
1
- MOJFrontend.SearchToggle = function (options) {
2
- this.options = options
3
- this.container = $(this.options.search.container)
4
- this.toggleButtonContainer = $(this.options.toggleButton.container)
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';
5
6
 
6
- if (this.container.data('moj-search-toggle-initialised')) {
7
- return
8
- }
7
+ function SearchToggle(options) {
8
+ this.options = options;
9
+ this.container = window.jQuery(this.options.search.container);
10
+ this.toggleButtonContainer = window.jQuery(this.options.toggleButton.container);
11
+
12
+ if (this.container.data('moj-search-toggle-initialised')) {
13
+ return
14
+ }
9
15
 
10
- this.container.data('moj-search-toggle-initialised', true)
16
+ this.container.data('moj-search-toggle-initialised', true);
11
17
 
12
- const svg =
13
- '<svg viewBox="0 0 20 20" version="1.1" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" class="moj-search-toggle__button__icon"><path d="M7.433,12.5790048 C6.06762625,12.5808611 4.75763941,12.0392925 3.79217348,11.0738265 C2.82670755,10.1083606 2.28513891,8.79837375 2.28699522,7.433 C2.28513891,6.06762625 2.82670755,4.75763941 3.79217348,3.79217348 C4.75763941,2.82670755 6.06762625,2.28513891 7.433,2.28699522 C8.79837375,2.28513891 10.1083606,2.82670755 11.0738265,3.79217348 C12.0392925,4.75763941 12.5808611,6.06762625 12.5790048,7.433 C12.5808611,8.79837375 12.0392925,10.1083606 11.0738265,11.0738265 C10.1083606,12.0392925 8.79837375,12.5808611 7.433,12.5790048 L7.433,12.5790048 Z M14.293,12.579 L13.391,12.579 L13.071,12.269 C14.2300759,10.9245158 14.8671539,9.20813198 14.866,7.433 C14.866,3.32786745 11.5381325,-1.65045755e-15 7.433,-1.65045755e-15 C3.32786745,-1.65045755e-15 -1.65045755e-15,3.32786745 -1.65045755e-15,7.433 C-1.65045755e-15,11.5381325 3.32786745,14.866 7.433,14.866 C9.208604,14.8671159 10.9253982,14.2296624 12.27,13.07 L12.579,13.39 L12.579,14.294 L18.296,20 L20,18.296 L14.294,12.579 L14.293,12.579 Z"></path></svg>'
18
+ const svg =
19
+ '<svg viewBox="0 0 20 20" version="1.1" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" class="moj-search-toggle__button__icon"><path d="M7.433,12.5790048 C6.06762625,12.5808611 4.75763941,12.0392925 3.79217348,11.0738265 C2.82670755,10.1083606 2.28513891,8.79837375 2.28699522,7.433 C2.28513891,6.06762625 2.82670755,4.75763941 3.79217348,3.79217348 C4.75763941,2.82670755 6.06762625,2.28513891 7.433,2.28699522 C8.79837375,2.28513891 10.1083606,2.82670755 11.0738265,3.79217348 C12.0392925,4.75763941 12.5808611,6.06762625 12.5790048,7.433 C12.5808611,8.79837375 12.0392925,10.1083606 11.0738265,11.0738265 C10.1083606,12.0392925 8.79837375,12.5808611 7.433,12.5790048 L7.433,12.5790048 Z M14.293,12.579 L13.391,12.579 L13.071,12.269 C14.2300759,10.9245158 14.8671539,9.20813198 14.866,7.433 C14.866,3.32786745 11.5381325,-1.65045755e-15 7.433,-1.65045755e-15 C3.32786745,-1.65045755e-15 -1.65045755e-15,3.32786745 -1.65045755e-15,7.433 C-1.65045755e-15,11.5381325 3.32786745,14.866 7.433,14.866 C9.208604,14.8671159 10.9253982,14.2296624 12.27,13.07 L12.579,13.39 L12.579,14.294 L18.296,20 L20,18.296 L14.294,12.579 L14.293,12.579 Z"></path></svg>';
14
20
 
15
- this.toggleButton = $(
16
- `<button class="moj-search-toggle__button" type="button" aria-haspopup="true" aria-expanded="false">
21
+ this.toggleButton = window.jQuery(
22
+ `<button class="moj-search-toggle__button" type="button" aria-haspopup="true" aria-expanded="false">
17
23
  ${this.options.toggleButton.text} ${svg}
18
24
  </button>`
19
- )
20
- this.toggleButton.on('click', $.proxy(this, 'onToggleButtonClick'))
21
- this.toggleButtonContainer.append(this.toggleButton)
22
- $(document).on('click', this.onDocumentClick.bind(this))
23
- $(document).on('focusin', this.onDocumentClick.bind(this))
24
- }
25
-
26
- MOJFrontend.SearchToggle.prototype.showMenu = function () {
27
- this.toggleButton.attr('aria-expanded', 'true')
28
- this.container.removeClass('moj-js-hidden')
29
- this.container.find('input').first().get(0).focus()
30
- }
31
-
32
- MOJFrontend.SearchToggle.prototype.hideMenu = function () {
33
- this.container.addClass('moj-js-hidden')
34
- this.toggleButton.attr('aria-expanded', 'false')
35
- }
36
-
37
- MOJFrontend.SearchToggle.prototype.onToggleButtonClick = function () {
38
- if (this.toggleButton.attr('aria-expanded') === 'false') {
39
- this.showMenu()
40
- } else {
41
- this.hideMenu()
25
+ );
26
+ this.toggleButton.on('click', window.jQuery.proxy(this, 'onToggleButtonClick'));
27
+ this.toggleButtonContainer.append(this.toggleButton);
28
+ window.jQuery(document).on('click', this.onDocumentClick.bind(this));
29
+ window.jQuery(document).on('focusin', this.onDocumentClick.bind(this));
42
30
  }
43
- }
44
-
45
- MOJFrontend.SearchToggle.prototype.onDocumentClick = function (e) {
46
- if (
47
- !$.contains(this.toggleButtonContainer[0], e.target) &&
48
- !$.contains(this.container[0], e.target)
49
- ) {
50
- this.hideMenu()
51
- }
52
- }
31
+
32
+ SearchToggle.prototype.showMenu = function () {
33
+ this.toggleButton.attr('aria-expanded', 'true');
34
+ this.container.removeClass('moj-js-hidden');
35
+ this.container.find('input').first().get(0).focus();
36
+ };
37
+
38
+ SearchToggle.prototype.hideMenu = function () {
39
+ this.container.addClass('moj-js-hidden');
40
+ this.toggleButton.attr('aria-expanded', 'false');
41
+ };
42
+
43
+ SearchToggle.prototype.onToggleButtonClick = function () {
44
+ if (this.toggleButton.attr('aria-expanded') === 'false') {
45
+ this.showMenu();
46
+ } else {
47
+ this.hideMenu();
48
+ }
49
+ };
50
+
51
+ SearchToggle.prototype.onDocumentClick = function (e) {
52
+ if (
53
+ !window.jQuery.contains(this.toggleButtonContainer[0], e.target) &&
54
+ !window.jQuery.contains(this.container[0], e.target)
55
+ ) {
56
+ this.hideMenu();
57
+ }
58
+ };
59
+
60
+ exports.SearchToggle = SearchToggle;
61
+
62
+ }));
@@ -0,0 +1,54 @@
1
+ function SearchToggle(options) {
2
+ this.options = options;
3
+ this.container = window.jQuery(this.options.search.container);
4
+ this.toggleButtonContainer = window.jQuery(this.options.toggleButton.container);
5
+
6
+ if (this.container.data('moj-search-toggle-initialised')) {
7
+ return
8
+ }
9
+
10
+ this.container.data('moj-search-toggle-initialised', true);
11
+
12
+ const svg =
13
+ '<svg viewBox="0 0 20 20" version="1.1" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" class="moj-search-toggle__button__icon"><path d="M7.433,12.5790048 C6.06762625,12.5808611 4.75763941,12.0392925 3.79217348,11.0738265 C2.82670755,10.1083606 2.28513891,8.79837375 2.28699522,7.433 C2.28513891,6.06762625 2.82670755,4.75763941 3.79217348,3.79217348 C4.75763941,2.82670755 6.06762625,2.28513891 7.433,2.28699522 C8.79837375,2.28513891 10.1083606,2.82670755 11.0738265,3.79217348 C12.0392925,4.75763941 12.5808611,6.06762625 12.5790048,7.433 C12.5808611,8.79837375 12.0392925,10.1083606 11.0738265,11.0738265 C10.1083606,12.0392925 8.79837375,12.5808611 7.433,12.5790048 L7.433,12.5790048 Z M14.293,12.579 L13.391,12.579 L13.071,12.269 C14.2300759,10.9245158 14.8671539,9.20813198 14.866,7.433 C14.866,3.32786745 11.5381325,-1.65045755e-15 7.433,-1.65045755e-15 C3.32786745,-1.65045755e-15 -1.65045755e-15,3.32786745 -1.65045755e-15,7.433 C-1.65045755e-15,11.5381325 3.32786745,14.866 7.433,14.866 C9.208604,14.8671159 10.9253982,14.2296624 12.27,13.07 L12.579,13.39 L12.579,14.294 L18.296,20 L20,18.296 L14.294,12.579 L14.293,12.579 Z"></path></svg>';
14
+
15
+ this.toggleButton = window.jQuery(
16
+ `<button class="moj-search-toggle__button" type="button" aria-haspopup="true" aria-expanded="false">
17
+ ${this.options.toggleButton.text} ${svg}
18
+ </button>`
19
+ );
20
+ this.toggleButton.on('click', window.jQuery.proxy(this, 'onToggleButtonClick'));
21
+ this.toggleButtonContainer.append(this.toggleButton);
22
+ window.jQuery(document).on('click', this.onDocumentClick.bind(this));
23
+ window.jQuery(document).on('focusin', this.onDocumentClick.bind(this));
24
+ }
25
+
26
+ SearchToggle.prototype.showMenu = function () {
27
+ this.toggleButton.attr('aria-expanded', 'true');
28
+ this.container.removeClass('moj-js-hidden');
29
+ this.container.find('input').first().get(0).focus();
30
+ };
31
+
32
+ SearchToggle.prototype.hideMenu = function () {
33
+ this.container.addClass('moj-js-hidden');
34
+ this.toggleButton.attr('aria-expanded', 'false');
35
+ };
36
+
37
+ SearchToggle.prototype.onToggleButtonClick = function () {
38
+ if (this.toggleButton.attr('aria-expanded') === 'false') {
39
+ this.showMenu();
40
+ } else {
41
+ this.hideMenu();
42
+ }
43
+ };
44
+
45
+ SearchToggle.prototype.onDocumentClick = function (e) {
46
+ if (
47
+ !window.jQuery.contains(this.toggleButtonContainer[0], e.target) &&
48
+ !window.jQuery.contains(this.container[0], e.target)
49
+ ) {
50
+ this.hideMenu();
51
+ }
52
+ };
53
+
54
+ export { SearchToggle };