@internetstiftelsen/styleguide 2.24.43 → 2.25.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.
- package/dist/assets/js/Events.js +80 -0
- package/dist/molecules/form/Form.js +8 -0
- package/dist/molecules/form/index.js +1 -1
- package/package.json +1 -1
- package/src/app.js +10 -0
- package/src/assets/js/Events.js +47 -0
- package/src/molecules/form/Form.js +5 -0
- package/src/molecules/form/index.js +3 -1
- package/src/organisms/hero/_hero.scss +1 -0
|
@@ -0,0 +1,80 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
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;
|
|
@@ -14,6 +14,10 @@ var _lodash = require('lodash.template');
|
|
|
14
14
|
|
|
15
15
|
var _lodash2 = _interopRequireDefault(_lodash);
|
|
16
16
|
|
|
17
|
+
var _Events = require('../../assets/js/Events');
|
|
18
|
+
|
|
19
|
+
var _Events2 = _interopRequireDefault(_Events);
|
|
20
|
+
|
|
17
21
|
var _Button = require('../../atoms/button/Button');
|
|
18
22
|
|
|
19
23
|
var _Button2 = _interopRequireDefault(_Button);
|
|
@@ -60,6 +64,7 @@ var Form = function () {
|
|
|
60
64
|
};
|
|
61
65
|
|
|
62
66
|
this.displayError = function (error) {
|
|
67
|
+
_this.events.emit('error', error);
|
|
63
68
|
_this.setLoading(false);
|
|
64
69
|
|
|
65
70
|
if ('response' in error) {
|
|
@@ -131,6 +136,8 @@ var Form = function () {
|
|
|
131
136
|
|
|
132
137
|
_this.success.classList.remove('is-hidden');
|
|
133
138
|
_this.success.innerHTML = tmpl(json);
|
|
139
|
+
|
|
140
|
+
_this.events.emit('success', json);
|
|
134
141
|
};
|
|
135
142
|
|
|
136
143
|
this.captchaCallback = function () {
|
|
@@ -154,6 +161,7 @@ var Form = function () {
|
|
|
154
161
|
this.submit = new _Button2.default(this.element.querySelector('button[type="submit"]'));
|
|
155
162
|
this.error = this.element.querySelector('[data-form-error]');
|
|
156
163
|
this.success = this.element.querySelector('[data-form-success]');
|
|
164
|
+
this.events = new _Events2.default();
|
|
157
165
|
|
|
158
166
|
if (this.success) {
|
|
159
167
|
var tpl = document.getElementById(this.success.getAttribute('data-form-success'));
|
package/package.json
CHANGED
package/src/app.js
CHANGED
|
@@ -73,3 +73,13 @@ const unsubscribeOpen = onOpen((el, id) => {
|
|
|
73
73
|
});
|
|
74
74
|
|
|
75
75
|
// Call unsubscribe to remove callback
|
|
76
|
+
|
|
77
|
+
const demoForms = document.querySelectorAll('[data-form]');
|
|
78
|
+
|
|
79
|
+
[].forEach.call(demoForms, (el) => {
|
|
80
|
+
if ('form' in el) {
|
|
81
|
+
el.form.events.on('success', (data) => {
|
|
82
|
+
console.log('Form success', data);
|
|
83
|
+
});
|
|
84
|
+
}
|
|
85
|
+
});
|
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
export default class Events {
|
|
2
|
+
constructor(listeners = {}) {
|
|
3
|
+
this.listeners = listeners;
|
|
4
|
+
}
|
|
5
|
+
|
|
6
|
+
hasListeners(event) {
|
|
7
|
+
return event in this.listeners;
|
|
8
|
+
}
|
|
9
|
+
|
|
10
|
+
on(event, cb) {
|
|
11
|
+
if (!(event in this.listeners)) {
|
|
12
|
+
this.listeners[event] = [];
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
if (!this.listeners[event].includes(cb)) {
|
|
16
|
+
this.listeners[event].push(cb);
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
return {
|
|
20
|
+
unsubscribe: () => this.off(event, cb),
|
|
21
|
+
};
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
off(event, cb) {
|
|
25
|
+
if (!this.hasListeners(event)) {
|
|
26
|
+
return;
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
this.listeners[event] = this.listeners[event].filter(
|
|
30
|
+
(subCb) => subCb !== cb,
|
|
31
|
+
);
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
removeAll(event) {
|
|
35
|
+
this.listeners[event] = [];
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
emit(event, ...args) {
|
|
39
|
+
if (!this.hasListeners(event)) {
|
|
40
|
+
return;
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
this.listeners[event].forEach((cb) => {
|
|
44
|
+
cb.call(null, ...args);
|
|
45
|
+
});
|
|
46
|
+
}
|
|
47
|
+
}
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import template from 'lodash.template';
|
|
2
|
+
import Events from '../../assets/js/Events';
|
|
2
3
|
import Button from '../../atoms/button/Button';
|
|
3
4
|
import className from '../../assets/js/className';
|
|
4
5
|
import validationMessage from '../../assets/js/validationMessage';
|
|
@@ -10,6 +11,7 @@ export default class Form {
|
|
|
10
11
|
this.submit = new Button(this.element.querySelector('button[type="submit"]'));
|
|
11
12
|
this.error = this.element.querySelector('[data-form-error]');
|
|
12
13
|
this.success = this.element.querySelector('[data-form-success]');
|
|
14
|
+
this.events = new Events();
|
|
13
15
|
|
|
14
16
|
if (this.success) {
|
|
15
17
|
const tpl = document.getElementById(this.success.getAttribute('data-form-success'));
|
|
@@ -163,6 +165,7 @@ export default class Form {
|
|
|
163
165
|
}
|
|
164
166
|
|
|
165
167
|
displayError = (error) => {
|
|
168
|
+
this.events.emit('error', error);
|
|
166
169
|
this.setLoading(false);
|
|
167
170
|
|
|
168
171
|
if ('response' in error) {
|
|
@@ -274,6 +277,8 @@ export default class Form {
|
|
|
274
277
|
|
|
275
278
|
this.success.classList.remove('is-hidden');
|
|
276
279
|
this.success.innerHTML = tmpl(json);
|
|
280
|
+
|
|
281
|
+
this.events.emit('success', json);
|
|
277
282
|
};
|
|
278
283
|
|
|
279
284
|
captchaCallback = () => {
|