@internetstiftelsen/styleguide 5.0.18 → 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 (92) hide show
  1. package/dist/app.js +71 -0
  2. package/dist/assets/js/Events.js +43 -77
  3. package/dist/assets/js/RequestError.js +16 -31
  4. package/dist/assets/js/anchorScroll.js +22 -15
  5. package/dist/assets/js/charCounter.js +100 -142
  6. package/dist/assets/js/className.js +19 -20
  7. package/dist/assets/js/conditional.js +96 -152
  8. package/dist/assets/js/debounce.js +15 -22
  9. package/dist/assets/js/el.js +108 -159
  10. package/dist/assets/js/getCookieByName.js +13 -11
  11. package/dist/assets/js/hasCookieConsent.js +30 -40
  12. package/dist/assets/js/htmlTextLength.js +12 -10
  13. package/dist/assets/js/iconToggle.js +16 -20
  14. package/dist/assets/js/nodeAdded.js +40 -53
  15. package/dist/assets/js/objToQuery.js +25 -41
  16. package/dist/assets/js/offset.js +29 -25
  17. package/dist/assets/js/ot.js +10 -13
  18. package/dist/assets/js/parallax.js +23 -23
  19. package/dist/assets/js/queryToObj.js +16 -22
  20. package/dist/assets/js/readSpeakerHandling.js +26 -28
  21. package/dist/assets/js/request.js +43 -52
  22. package/dist/assets/js/responsivePosition.js +46 -74
  23. package/dist/assets/js/stringToNode.js +11 -10
  24. package/dist/assets/js/template.js +15 -21
  25. package/dist/assets/js/textToggle.js +19 -24
  26. package/dist/assets/js/track.js +14 -12
  27. package/dist/assets/js/uid.js +10 -6
  28. package/dist/assets/js/utmGenerator.js +27 -33
  29. package/dist/assets/js/validationMessage.js +18 -25
  30. package/dist/assets/js/youtube.js +134 -170
  31. package/dist/atoms/button/Button.js +42 -55
  32. package/dist/atoms/file/file.js +25 -29
  33. package/dist/atoms/file/filePreview.js +27 -31
  34. package/dist/atoms/grid-toggle/grid-toggle.js +6 -9
  35. package/dist/atoms/height-limiter/height-limiter.js +37 -50
  36. package/dist/atoms/password-toggle/password-toggle.js +9 -11
  37. package/dist/atoms/range/range.js +32 -39
  38. package/dist/atoms/textarea/rich-text.js +223 -205
  39. package/dist/atoms/tooltip/tooltip.js +13 -17
  40. package/dist/components.js +42 -77
  41. package/dist/focusTrap.js +66 -77
  42. package/dist/molecules/alert/alert.js +15 -20
  43. package/dist/molecules/context-menu/context-menu.js +11 -16
  44. package/dist/molecules/continue-video-guide/continue-video-guide.js +90 -101
  45. package/dist/molecules/cookie-disclaimer/cookie-disclaimer.js +24 -33
  46. package/dist/molecules/form/Form.js +242 -352
  47. package/dist/molecules/form/index.js +15 -14
  48. package/dist/molecules/glider/glider-course.js +62 -75
  49. package/dist/molecules/glider/glider-hero.js +88 -101
  50. package/dist/molecules/glider/glider.js +49 -45
  51. package/dist/molecules/modal/modal.js +256 -325
  52. package/dist/molecules/multi-select/multi-select.js +198 -304
  53. package/dist/molecules/natural-language-form/natural-language-form.js +32 -46
  54. package/dist/molecules/overview-navigation/overview-navigation.js +90 -141
  55. package/dist/molecules/share/share.js +15 -20
  56. package/dist/molecules/system-error/system-error.js +6 -9
  57. package/dist/organisms/accordion/accordion.js +44 -50
  58. package/dist/organisms/footer/footer.js +1 -1
  59. package/dist/organisms/haveibeenpwned/haveibeenpwned.js +17 -16
  60. package/dist/organisms/mailchimp/mailchimp.js +72 -89
  61. package/dist/organisms/map-box/map-box.js +3 -4
  62. package/dist/organisms/mega-menu/mega-menu.js +177 -212
  63. package/dist/organisms/podcast/podcast.js +192 -215
  64. package/dist/organisms/schedule/schedule-filter.js +9 -15
  65. package/dist/organisms/tabs/tabs.js +194 -253
  66. package/dist/organisms/timeline/openTimelineItem.js +38 -51
  67. package/dist/organisms/timeline/timeline.js +111 -128
  68. package/dist/organisms/video-guide/VideoGuidePlayback.js +210 -286
  69. package/dist/organisms/video-guide/VideoGuideSubtitles.js +57 -80
  70. package/dist/organisms/video-guide/VideoGuideTimeline.js +74 -108
  71. package/dist/organisms/video-guide/getCurrentCueIndex.js +11 -9
  72. package/dist/organisms/video-guide/video-guide.js +66 -103
  73. package/dist/utilities/tab-highlighting/tab-highlighting.js +14 -22
  74. package/dist/vendor/toggle/a11y.toggle-switcher.js +10 -16
  75. package/package.json +78 -99
  76. package/src/app.js +5 -5
  77. package/src/assets/js/anchorScroll.js +1 -1
  78. package/src/assets/js/offset.js +1 -1
  79. package/src/atoms/button/Button.js +1 -1
  80. package/src/atoms/icon/richtext-ordered-list.svg +1 -1
  81. package/src/atoms/icon/sprite.svg +6 -5
  82. package/src/molecules/glider/glider-course.js +0 -2
  83. package/src/molecules/glider/glider.js +2 -2
  84. package/src/organisms/accordion/accordion.js +1 -2
  85. package/src/organisms/timeline/timeline.js +2 -3
  86. package/dist/atoms/timeline/anchorScroll.js +0 -13
  87. package/dist/atoms/toggle-high-contrast/toggle-high-contrast.js +0 -12
  88. package/dist/molecules/glider/glider-single.js +0 -68
  89. package/dist/molecules/modal/modal-graph.js +0 -40
  90. package/dist/molecules/timeline-navigation/timeline-navigation.js +0 -34
  91. /package/src/atoms/icon/{heading-3.svg → richtext-heading-3.svg} +0 -0
  92. /package/src/molecules/alert/{_alert.scss → alert.scss} +0 -0
package/dist/app.js ADDED
@@ -0,0 +1,71 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", {
3
+ value: true
4
+ });
5
+ require("./app.scss");
6
+ require("a11y-toggle");
7
+ require("./focusTrap");
8
+ require("./assets/js/conditional");
9
+ require("./atoms/grid-toggle/grid-toggle");
10
+ require("./components");
11
+ const _Button = /*#__PURE__*/ _interop_require_default(require("./atoms/button/Button"));
12
+ const _modal = require("./molecules/modal/modal");
13
+ function _interop_require_default(obj) {
14
+ return obj && obj.__esModule ? obj : {
15
+ default: obj
16
+ };
17
+ }
18
+ const demoButtons = document.querySelectorAll('button.a-button.has-loader');
19
+ if (demoButtons.length) {
20
+ demoButtons.forEach((button)=>{
21
+ const b = new _Button.default(button);
22
+ button.addEventListener('click', ()=>{
23
+ if (b.isLoading()) {
24
+ return;
25
+ }
26
+ b.start();
27
+ setTimeout(()=>{
28
+ b.stop();
29
+ }, 2000);
30
+ });
31
+ });
32
+ }
33
+ const demoModal = document.querySelector('[data-open-demo-modal]');
34
+ if (demoModal) {
35
+ demoModal.addEventListener('click', ()=>{
36
+ (0, _modal.open)({
37
+ title: 'My modal title',
38
+ content: '<p>My modal content.</p>',
39
+ actions: [
40
+ {
41
+ text: 'Close modal',
42
+ color: 'peacock-light',
43
+ modifier: 'primary',
44
+ attrs: {
45
+ 'data-modal-close': null
46
+ }
47
+ },
48
+ {
49
+ text: 'Replace modal',
50
+ color: 'ruby-light',
51
+ modifier: 'secondary',
52
+ attrs: {
53
+ 'data-modal-open': 'modal-container',
54
+ 'data-modal-replace': true
55
+ }
56
+ }
57
+ ]
58
+ }, {
59
+ onClose: (id)=>console.log('close', id),
60
+ onOpen: (id)=>console.log('open', id)
61
+ });
62
+ });
63
+ }
64
+ const demoForms = document.querySelectorAll('[data-form]');
65
+ [].forEach.call(demoForms, (el)=>{
66
+ if ('form' in el) {
67
+ el.form.events.on('success', (data)=>{
68
+ console.log('Form success', data);
69
+ });
70
+ }
71
+ });
@@ -1,80 +1,46 @@
1
1
  "use strict";
2
-
3
2
  Object.defineProperty(exports, "__esModule", {
4
- value: true
3
+ value: true
5
4
  });
6
-
7
- var _createClass = function () { function defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } } return function (Constructor, protoProps, staticProps) { if (protoProps) defineProperties(Constructor.prototype, protoProps); if (staticProps) defineProperties(Constructor, staticProps); return Constructor; }; }();
8
-
9
- function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
10
-
11
- var Events = function () {
12
- function Events() {
13
- var listeners = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
14
-
15
- _classCallCheck(this, Events);
16
-
17
- this.listeners = listeners;
18
- }
19
-
20
- _createClass(Events, [{
21
- key: "hasListeners",
22
- value: function hasListeners(event) {
23
- return event in this.listeners;
24
- }
25
- }, {
26
- key: "on",
27
- value: function on(event, cb) {
28
- var _this = this;
29
-
30
- if (!(event in this.listeners)) {
31
- this.listeners[event] = [];
32
- }
33
-
34
- if (!this.listeners[event].includes(cb)) {
35
- this.listeners[event].push(cb);
36
- }
37
-
38
- return {
39
- unsubscribe: function unsubscribe() {
40
- return _this.off(event, cb);
41
- }
42
- };
43
- }
44
- }, {
45
- key: "off",
46
- value: function off(event, cb) {
47
- if (!this.hasListeners(event)) {
48
- return;
49
- }
50
-
51
- this.listeners[event] = this.listeners[event].filter(function (subCb) {
52
- return subCb !== cb;
53
- });
54
- }
55
- }, {
56
- key: "removeAll",
57
- value: function removeAll(event) {
58
- this.listeners[event] = [];
59
- }
60
- }, {
61
- key: "emit",
62
- value: function emit(event) {
63
- for (var _len = arguments.length, args = Array(_len > 1 ? _len - 1 : 0), _key = 1; _key < _len; _key++) {
64
- args[_key - 1] = arguments[_key];
65
- }
66
-
67
- if (!this.hasListeners(event)) {
68
- return;
69
- }
70
-
71
- this.listeners[event].forEach(function (cb) {
72
- cb.call.apply(cb, [null].concat(args));
73
- });
74
- }
75
- }]);
76
-
77
- return Events;
78
- }();
79
-
80
- exports.default = Events;
5
+ Object.defineProperty(exports, "default", {
6
+ enumerable: true,
7
+ get: function() {
8
+ return Events;
9
+ }
10
+ });
11
+ class Events {
12
+ hasListeners(event) {
13
+ return event in this.listeners;
14
+ }
15
+ on(event, cb) {
16
+ if (!(event in this.listeners)) {
17
+ this.listeners[event] = [];
18
+ }
19
+ if (!this.listeners[event].includes(cb)) {
20
+ this.listeners[event].push(cb);
21
+ }
22
+ return {
23
+ unsubscribe: ()=>this.off(event, cb)
24
+ };
25
+ }
26
+ off(event, cb) {
27
+ if (!this.hasListeners(event)) {
28
+ return;
29
+ }
30
+ this.listeners[event] = this.listeners[event].filter((subCb)=>subCb !== cb);
31
+ }
32
+ removeAll(event) {
33
+ this.listeners[event] = [];
34
+ }
35
+ emit(event, ...args) {
36
+ if (!this.hasListeners(event)) {
37
+ return;
38
+ }
39
+ this.listeners[event].forEach((cb)=>{
40
+ cb.call(null, ...args);
41
+ });
42
+ }
43
+ constructor(listeners = {}){
44
+ this.listeners = listeners;
45
+ }
46
+ }
@@ -1,33 +1,18 @@
1
- 'use strict';
2
-
1
+ "use strict";
3
2
  Object.defineProperty(exports, "__esModule", {
4
- value: true
3
+ value: true
5
4
  });
6
-
7
- function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
8
-
9
- function _possibleConstructorReturn(self, call) { if (!self) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return call && (typeof call === "object" || typeof call === "function") ? call : self; }
10
-
11
- function _inherits(subClass, superClass) { if (typeof superClass !== "function" && superClass !== null) { throw new TypeError("Super expression must either be null or a function, not " + typeof superClass); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, enumerable: false, writable: true, configurable: true } }); if (superClass) Object.setPrototypeOf ? Object.setPrototypeOf(subClass, superClass) : subClass.__proto__ = superClass; }
12
-
13
- var RequestError = function (_Error) {
14
- _inherits(RequestError, _Error);
15
-
16
- function RequestError(message) {
17
- var response = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
18
- var status = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : 500;
19
-
20
- _classCallCheck(this, RequestError);
21
-
22
- var _this = _possibleConstructorReturn(this, (RequestError.__proto__ || Object.getPrototypeOf(RequestError)).call(this, message));
23
-
24
- _this.name = 'RequestError';
25
- _this.status = status;
26
- _this.response = response;
27
- return _this;
28
- }
29
-
30
- return RequestError;
31
- }(Error);
32
-
33
- exports.default = RequestError;
5
+ Object.defineProperty(exports, "default", {
6
+ enumerable: true,
7
+ get: function() {
8
+ return RequestError;
9
+ }
10
+ });
11
+ class RequestError extends Error {
12
+ constructor(message, response = {}, status = 500){
13
+ super(message);
14
+ this.name = 'RequestError';
15
+ this.status = status;
16
+ this.response = response;
17
+ }
18
+ }
@@ -1,16 +1,23 @@
1
- 'use strict';
2
-
3
- var _smoothScroll = require('smooth-scroll');
4
-
5
- var _smoothScroll2 = _interopRequireDefault(_smoothScroll);
6
-
7
- function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
8
-
9
- var anchorScroll = new _smoothScroll2.default('a[href*="#"]', {
10
- speed: 1500,
11
- speedAsDuration: true,
12
- easing: 'easeOutCubic',
13
- ignore: '[data-scroll-ignore]'
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", {
3
+ value: true
14
4
  });
15
-
16
- module.exports = anchorScroll;
5
+ Object.defineProperty(exports, "default", {
6
+ enumerable: true,
7
+ get: function() {
8
+ return _default;
9
+ }
10
+ });
11
+ const _smoothscroll = /*#__PURE__*/ _interop_require_default(require("smooth-scroll"));
12
+ function _interop_require_default(obj) {
13
+ return obj && obj.__esModule ? obj : {
14
+ default: obj
15
+ };
16
+ }
17
+ const anchorScroll = new _smoothscroll.default('a[href*="#"]', {
18
+ speed: 1500,
19
+ speedAsDuration: true,
20
+ easing: 'easeOutCubic',
21
+ ignore: '[data-scroll-ignore]'
22
+ });
23
+ const _default = anchorScroll;
@@ -1,142 +1,100 @@
1
- 'use strict';
2
-
3
- var _createClass = function () { function defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } } return function (Constructor, protoProps, staticProps) { if (protoProps) defineProperties(Constructor.prototype, protoProps); if (staticProps) defineProperties(Constructor, staticProps); return Constructor; }; }();
4
-
5
- var _className = require('./className');
6
-
7
- var _className2 = _interopRequireDefault(_className);
8
-
9
- var _htmlTextLength = require('./htmlTextLength');
10
-
11
- var _htmlTextLength2 = _interopRequireDefault(_htmlTextLength);
12
-
13
- function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
14
-
15
- function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
16
-
17
- var CharCounter = function () {
18
- function CharCounter(el) {
19
- _classCallCheck(this, CharCounter);
20
-
21
- this.el = el;
22
- this.counterEl = null;
23
- this.isRichText = this.el.dataset.richText !== undefined;
24
- this.min = parseInt(this.el.getAttribute('data-min') || 0, 10);
25
- this.max = parseInt(this.el.getAttribute('data-max') || 0, 10);
26
-
27
- if (!this.min && !this.max) {
28
- console.warn('Either min or max must be set and greater than 0.');
29
- return;
30
- }
31
-
32
- if (this.isRichText) {
33
- this.waitForEditor();
34
-
35
- return;
36
- }
37
-
38
- this.build();
39
- this.attach();
40
- }
41
-
42
- _createClass(CharCounter, [{
43
- key: 'waitForEditor',
44
- value: function waitForEditor() {
45
- var _this = this;
46
-
47
- if (this.el.editor) {
48
- this.build();
49
- this.attach();
50
- } else {
51
- this.el.addEventListener('editor-ready', function () {
52
- _this.build();
53
- _this.attach();
54
- });
55
- }
56
- }
57
- }, {
58
- key: 'count',
59
- value: function count() {
60
- if (this.isRichText) {
61
- return (0, _htmlTextLength2.default)(this.el.editor.getHTML());
62
- }
63
-
64
- return this.el.value.length;
65
- }
66
- }, {
67
- key: 'setCountText',
68
- value: function setCountText() {
69
- var count = this.count();
70
-
71
- if (this.min && count < this.min) {
72
- this.counterEl.textContent = count + '/' + this.min;
73
- this.counterEl.className = 'backgrond-ruby-light ' + (0, _className2.default)('a-meta');
74
- this.el.setAttribute('aria-invalid', 'true');
75
-
76
- return;
77
- }
78
-
79
- if (this.max && count > this.max) {
80
- this.counterEl.textContent = count + '/' + this.max;
81
- this.counterEl.className = 'background-ruby-light ' + (0, _className2.default)('a-meta');
82
- this.el.setAttribute('aria-invalid', 'true');
83
-
84
- return;
85
- }
86
-
87
- this.counterEl.textContent = count + '/' + (this.max || this.min);
88
- this.counterEl.className = 'background-jade-light ' + (0, _className2.default)('a-meta');
89
- this.el.removeAttribute('aria-invalid');
90
- this.counterEl.closest('.field-group').classList.remove('is-invalid');
91
- }
92
- }, {
93
- key: 'build',
94
- value: function build() {
95
- var counter = document.createElement('small');
96
- var wrapper = void 0;
97
-
98
- if (this.isRichText) {
99
- wrapper = this.el.editor.options.element;
100
- wrapper.style.paddingRight = '3.8333333333rem';
101
- } else {
102
- wrapper = document.createElement('div');
103
-
104
- wrapper.className = 'u-position-relative';
105
- this.el.parentNode.insertBefore(wrapper, this.el);
106
- wrapper.appendChild(this.el);
107
-
108
- this.el.style.paddingRight = '3.8333333333rem';
109
- }
110
-
111
- counter.className = 'color-cyberspace ' + (0, _className2.default)('a-meta');
112
- counter.style.cssText = 'position: absolute; top: .5rem; right: .5rem; z-index: 501;background-color: #ff9fb4; border-radius: 0.25rem; padding: .25rem; line-height: 1;margin: 0';
113
-
114
- wrapper.appendChild(counter);
115
-
116
- this.counterEl = counter;
117
- this.setCountText();
118
- }
119
- }, {
120
- key: 'attach',
121
- value: function attach() {
122
- var _this2 = this;
123
-
124
- if (this.isRichText) {
125
- this.el.editor.on('update', function () {
126
- _this2.setCountText();
127
- });
128
- } else {
129
- this.el.addEventListener('input', function () {
130
- _this2.setCountText();
131
- });
132
- }
133
- }
134
- }]);
135
-
136
- return CharCounter;
137
- }();
138
-
139
- var elements = document.querySelectorAll('[data-min], [data-max]');
140
- elements.forEach(function (el) {
141
- el.charCounter = new CharCounter(el);
142
- });
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", {
3
+ value: true
4
+ });
5
+ const _className = /*#__PURE__*/ _interop_require_default(require("./className"));
6
+ const _htmlTextLength = /*#__PURE__*/ _interop_require_default(require("./htmlTextLength"));
7
+ function _interop_require_default(obj) {
8
+ return obj && obj.__esModule ? obj : {
9
+ default: obj
10
+ };
11
+ }
12
+ class CharCounter {
13
+ waitForEditor() {
14
+ if (this.el.editor) {
15
+ this.build();
16
+ this.attach();
17
+ } else {
18
+ this.el.addEventListener('editor-ready', ()=>{
19
+ this.build();
20
+ this.attach();
21
+ });
22
+ }
23
+ }
24
+ count() {
25
+ if (this.isRichText) {
26
+ return (0, _htmlTextLength.default)(this.el.editor.getHTML());
27
+ }
28
+ return this.el.value.length;
29
+ }
30
+ setCountText() {
31
+ const count = this.count();
32
+ if (this.min && count < this.min) {
33
+ this.counterEl.textContent = `${count}/${this.min}`;
34
+ this.counterEl.className = `backgrond-ruby-light ${(0, _className.default)('a-meta')}`;
35
+ this.el.setAttribute('aria-invalid', 'true');
36
+ return;
37
+ }
38
+ if (this.max && count > this.max) {
39
+ this.counterEl.textContent = `${count}/${this.max}`;
40
+ this.counterEl.className = `background-ruby-light ${(0, _className.default)('a-meta')}`;
41
+ this.el.setAttribute('aria-invalid', 'true');
42
+ return;
43
+ }
44
+ this.counterEl.textContent = `${count}/${this.max || this.min}`;
45
+ this.counterEl.className = `background-jade-light ${(0, _className.default)('a-meta')}`;
46
+ this.el.removeAttribute('aria-invalid');
47
+ this.counterEl.closest('.field-group').classList.remove('is-invalid');
48
+ }
49
+ build() {
50
+ const counter = document.createElement('small');
51
+ let wrapper;
52
+ if (this.isRichText) {
53
+ wrapper = this.el.editor.options.element;
54
+ wrapper.style.paddingRight = '3.8333333333rem';
55
+ } else {
56
+ wrapper = document.createElement('div');
57
+ wrapper.className = 'u-position-relative';
58
+ this.el.parentNode.insertBefore(wrapper, this.el);
59
+ wrapper.appendChild(this.el);
60
+ this.el.style.paddingRight = '3.8333333333rem';
61
+ }
62
+ counter.className = `color-cyberspace ${(0, _className.default)('a-meta')}`;
63
+ counter.style.cssText = 'position: absolute; top: .5rem; right: .5rem; z-index: 501;background-color: #ff9fb4; border-radius: 0.25rem; padding: .25rem; line-height: 1;margin: 0';
64
+ wrapper.appendChild(counter);
65
+ this.counterEl = counter;
66
+ this.setCountText();
67
+ }
68
+ attach() {
69
+ if (this.isRichText) {
70
+ this.el.editor.on('update', ()=>{
71
+ this.setCountText();
72
+ });
73
+ } else {
74
+ this.el.addEventListener('input', ()=>{
75
+ this.setCountText();
76
+ });
77
+ }
78
+ }
79
+ constructor(el){
80
+ this.el = el;
81
+ this.counterEl = null;
82
+ this.isRichText = this.el.dataset.richText !== undefined;
83
+ this.min = parseInt(this.el.getAttribute('data-min') || 0, 10);
84
+ this.max = parseInt(this.el.getAttribute('data-max') || 0, 10);
85
+ if (!this.min && !this.max) {
86
+ console.warn('Either min or max must be set and greater than 0.');
87
+ return;
88
+ }
89
+ if (this.isRichText) {
90
+ this.waitForEditor();
91
+ return;
92
+ }
93
+ this.build();
94
+ this.attach();
95
+ }
96
+ }
97
+ const elements = document.querySelectorAll('[data-min], [data-max]');
98
+ elements.forEach((el)=>{
99
+ el.charCounter = new CharCounter(el);
100
+ });
@@ -1,23 +1,22 @@
1
- 'use strict';
2
-
1
+ "use strict";
3
2
  Object.defineProperty(exports, "__esModule", {
4
- value: true
3
+ value: true
5
4
  });
6
- exports.default = className;
7
- var namespace = null;
8
-
5
+ Object.defineProperty(exports, "default", {
6
+ enumerable: true,
7
+ get: function() {
8
+ return className;
9
+ }
10
+ });
11
+ let namespace = null;
9
12
  function className(classes) {
10
- if (!namespace) {
11
- var site = document.getElementById('site');
12
-
13
- if (site && site.hasAttribute('data-namespace')) {
14
- namespace = site.getAttribute('data-namespace');
15
- } else {
16
- namespace = '';
17
- }
18
- }
19
-
20
- return classes.split(' ').map(function (cls) {
21
- return '' + namespace + cls;
22
- }).join(' ');
23
- }
13
+ if (!namespace) {
14
+ const site = document.getElementById('site');
15
+ if (site && site.hasAttribute('data-namespace')) {
16
+ namespace = site.getAttribute('data-namespace');
17
+ } else {
18
+ namespace = '';
19
+ }
20
+ }
21
+ return classes.split(' ').map((cls)=>`${namespace}${cls}`).join(' ');
22
+ }