aw-front-helpers 2.3.11 → 2.4.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/classes/formControl.js +203 -115
- package/package.json +1 -1
- package/utils/media/autoplay.js +4 -21
package/classes/formControl.js
CHANGED
|
@@ -1,9 +1,7 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import ScrollToPlugin
|
|
1
|
+
import { gsap } from 'gsap/all';
|
|
2
|
+
import ScrollToPlugin from 'gsap/ScrollToPlugin';
|
|
3
3
|
gsap.registerPlugin( ScrollToPlugin );
|
|
4
|
-
|
|
5
4
|
import create from 'dom-create-element';
|
|
6
|
-
|
|
7
5
|
import getClosest from '../utils/dom/getClosest';
|
|
8
6
|
import regex_email from '../utils/regex/email';
|
|
9
7
|
|
|
@@ -11,7 +9,7 @@ const defaultOptions = {
|
|
|
11
9
|
selectorGroup: '.form-group',
|
|
12
10
|
classErrorElement: 'form-error',
|
|
13
11
|
classIsError: 'is-error',
|
|
14
|
-
animateToFirstError:
|
|
12
|
+
animateToFirstError: false,
|
|
15
13
|
i18n: {
|
|
16
14
|
required: Translator ? Translator.trans('form_errors.pattern') : 'Ce champs est obligatoire',
|
|
17
15
|
same: Translator ? Translator.trans('form_errors.same') : 'Les champs ne correspondent pas.',
|
|
@@ -23,17 +21,36 @@ const defaultOptions = {
|
|
|
23
21
|
}
|
|
24
22
|
};
|
|
25
23
|
|
|
26
|
-
class FormControl {
|
|
24
|
+
export default class FormControl {
|
|
27
25
|
//________________________________________________________ constructor
|
|
28
26
|
// -
|
|
29
|
-
|
|
30
|
-
|
|
27
|
+
/**
|
|
28
|
+
* Add controls on your formulaire
|
|
29
|
+
* @param {Element} form formulaire need add control
|
|
30
|
+
* @param {Object} options define options of controls
|
|
31
|
+
* @param {string} options.selectorGroup - The name of the employee.
|
|
32
|
+
* @param {string} options.classErrorElement - The employee's department.
|
|
33
|
+
* @param {string} options.classIsError - The employee's department.
|
|
34
|
+
* @param {string} options.animateToFirstError - The employee's department.
|
|
35
|
+
* @param {Object} options.i18n - The employee's department.
|
|
36
|
+
* @param {Object} options.i18n.required - The employee's department.
|
|
37
|
+
* @param {Object} options.i18n.same - The employee's department.
|
|
38
|
+
* @param {Object} options.i18n.email - The employee's department.
|
|
39
|
+
* @param {Object} options.i18n.empty - The employee's department.
|
|
40
|
+
* @param {Object} options.i18n.checkbox - The employee's department.
|
|
41
|
+
* @param {Object} options.i18n.radio - The employee's department.
|
|
42
|
+
* @param {Object} options.i18n.pattern - The employee's department.
|
|
43
|
+
**/
|
|
44
|
+
constructor(form, options = {}) {
|
|
45
|
+
/** @private */
|
|
46
|
+
this._form = form;
|
|
47
|
+
/** @private */
|
|
31
48
|
this._dom = {};
|
|
49
|
+
/** @private */
|
|
32
50
|
this._options = {...defaultOptions, ...options};
|
|
33
51
|
|
|
52
|
+
this._form.setAttribute('novalidate', 'novalidate');
|
|
34
53
|
this._formCreateBound();
|
|
35
|
-
this._el.setAttribute('novalidate', 'novalidate');
|
|
36
|
-
|
|
37
54
|
this._formGrabDom();
|
|
38
55
|
this._formAddEvents();
|
|
39
56
|
}
|
|
@@ -45,39 +62,41 @@ class FormControl {
|
|
|
45
62
|
};
|
|
46
63
|
}
|
|
47
64
|
|
|
65
|
+
get form() {
|
|
66
|
+
return this._form;
|
|
67
|
+
}
|
|
68
|
+
|
|
48
69
|
get options() {
|
|
49
70
|
return this._options;
|
|
50
71
|
}
|
|
51
72
|
|
|
73
|
+
/**
|
|
74
|
+
* @deprecated use isValid
|
|
75
|
+
*/
|
|
52
76
|
get isValidate() {
|
|
53
|
-
return this.
|
|
77
|
+
return this._isValid();
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
get isValid() {
|
|
81
|
+
return this._isValid();
|
|
54
82
|
}
|
|
55
83
|
|
|
56
84
|
//________________________________________________________ public
|
|
57
85
|
// -
|
|
58
86
|
destroy() {
|
|
59
|
-
this.
|
|
87
|
+
this._form.removeEventListener('submit', this._onFormSubmit);
|
|
60
88
|
this._domForm.inputs.forEach( input => {
|
|
61
|
-
input.removeEventListener('keyup', this.
|
|
62
|
-
if (input.getAttribute('type') === 'checkbox' ||
|
|
63
|
-
input.getAttribute('type') === 'radio' ||
|
|
64
|
-
input.tagName === 'SELECT') {
|
|
65
|
-
input.removeEventListener('change', this._onFormKeyUp);
|
|
66
|
-
}
|
|
67
|
-
})
|
|
68
|
-
}
|
|
69
|
-
|
|
70
|
-
removeErrors() {
|
|
71
|
-
const isErrors = [...this._el.querySelectorAll(`${this._options.classIsError}`)];
|
|
72
|
-
const currentErrors = [...this._el.querySelectorAll(`.${this._options.classErrorElement}`)];
|
|
73
|
-
currentErrors.forEach(error => {
|
|
74
|
-
error.parentNode.removeChild(error);
|
|
89
|
+
input.removeEventListener('keyup', this._onChange);
|
|
75
90
|
});
|
|
76
|
-
|
|
77
|
-
|
|
91
|
+
this._domForm.choices.forEach( input => {
|
|
92
|
+
input.removeEventListener('change', this._onChange);
|
|
78
93
|
});
|
|
79
94
|
}
|
|
80
95
|
|
|
96
|
+
removeErrors(el = null) {
|
|
97
|
+
this._removeError(el);
|
|
98
|
+
}
|
|
99
|
+
|
|
81
100
|
setError(element, message = null) {
|
|
82
101
|
const parent = getClosest(element, this._options.selectorGroup);
|
|
83
102
|
if( parent) {
|
|
@@ -90,6 +109,11 @@ class FormControl {
|
|
|
90
109
|
parent.appendChild(error);
|
|
91
110
|
}
|
|
92
111
|
parent.classList.add(this._options.classIsError);
|
|
112
|
+
|
|
113
|
+
const previousErrors = [...error.querySelectorAll('li')];
|
|
114
|
+
for(let i = 0; i < previousErrors.length; i++) {
|
|
115
|
+
if(previousErrors[i].innerHTML === message) return;
|
|
116
|
+
}
|
|
93
117
|
if(message) {
|
|
94
118
|
const errorElement = document.createElement('li');
|
|
95
119
|
errorElement.innerHTML = message;
|
|
@@ -100,113 +124,177 @@ class FormControl {
|
|
|
100
124
|
|
|
101
125
|
//________________________________________________________ events
|
|
102
126
|
// -
|
|
127
|
+
/** @private */
|
|
103
128
|
_onFormSubmit(pEvt) {
|
|
104
|
-
if (!this.
|
|
129
|
+
if (!this._isValid()) {
|
|
105
130
|
pEvt.preventDefault();
|
|
106
131
|
}
|
|
107
132
|
}
|
|
108
133
|
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
const currentErrors = [...parent.querySelectorAll(`.${this._options.classErrorElement}`)];
|
|
114
|
-
currentErrors.forEach(error => {
|
|
115
|
-
error.classList.remove(this._options.classIsError);
|
|
116
|
-
error.parentNode.removeChild(error);
|
|
117
|
-
});
|
|
134
|
+
/** @private */
|
|
135
|
+
_onChange(pEvt) {
|
|
136
|
+
const el = pEvt.target;
|
|
137
|
+
this._removeError(el);
|
|
118
138
|
}
|
|
119
139
|
|
|
120
140
|
//________________________________________________________ private
|
|
121
141
|
// -
|
|
142
|
+
/** @private */
|
|
122
143
|
_formCreateBound() {
|
|
123
|
-
['
|
|
144
|
+
['_onChange', '_onFormSubmit']
|
|
124
145
|
.forEach((fn) => this[fn] = this[fn].bind(this));
|
|
125
146
|
}
|
|
126
147
|
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
if
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
}
|
|
191
|
-
if (!validate && errorEl === null) errorEl = el;
|
|
148
|
+
/** @private */
|
|
149
|
+
_removeError(el = null) {
|
|
150
|
+
if(el) {
|
|
151
|
+
const group = getClosest(el, this._options.selectorGroup);
|
|
152
|
+
group.classList.remove(this._options.classIsError);
|
|
153
|
+
const currentErrors = [...group.querySelectorAll(`.${this._options.classErrorElement}`)];
|
|
154
|
+
currentErrors.forEach(error => {
|
|
155
|
+
error.classList.remove(this._options.classIsError);
|
|
156
|
+
error.parentNode.removeChild(error);
|
|
157
|
+
});
|
|
158
|
+
} else {
|
|
159
|
+
const isErrors = [...this._form.querySelectorAll(`${this._options.classIsError}`)];
|
|
160
|
+
const currentErrors = [...this._form.querySelectorAll(`.${this._options.classErrorElement}`)];
|
|
161
|
+
currentErrors.forEach(error => {
|
|
162
|
+
error.parentNode.removeChild(error);
|
|
163
|
+
});
|
|
164
|
+
isErrors.forEach(error => {
|
|
165
|
+
error.classList.remove(this._options.classIsError);
|
|
166
|
+
});
|
|
167
|
+
}
|
|
168
|
+
}
|
|
169
|
+
|
|
170
|
+
/** @private */
|
|
171
|
+
_checkError(el) {
|
|
172
|
+
const group = getClosest(el, this._options.selectorGroup);
|
|
173
|
+
if (group === null) return false;
|
|
174
|
+
if (el.getAttribute('disabled') !== null) return false;
|
|
175
|
+
|
|
176
|
+
let invalid = false;
|
|
177
|
+
if( !testRequired(el, this._form) ) {
|
|
178
|
+
invalid = true;
|
|
179
|
+
const type = el.getAttribute('type');
|
|
180
|
+
if(type === 'radio') this.setError(el, this._options.i18n.radio);
|
|
181
|
+
else if(type === 'checkbox') this.setError(el, this._options.i18n.checkbox);
|
|
182
|
+
else if(type !== 'hidden') this.setError(el, this._options.i18n.empty);
|
|
183
|
+
}
|
|
184
|
+
if( !testEmail(el, this._form) ) {
|
|
185
|
+
invalid = true;
|
|
186
|
+
this.setError(el, this._options.i18n.email);
|
|
187
|
+
}
|
|
188
|
+
if( !testPattern(el, this._form) ) {
|
|
189
|
+
invalid = true;
|
|
190
|
+
this.setError(el, this._options.i18n.pattern);
|
|
191
|
+
}
|
|
192
|
+
if( !testSame(el, this._form) ) {
|
|
193
|
+
invalid = true;
|
|
194
|
+
this.setError(el, this._options.i18n.same);
|
|
195
|
+
}
|
|
196
|
+
|
|
197
|
+
return invalid;
|
|
198
|
+
}
|
|
199
|
+
|
|
200
|
+
/** @private */
|
|
201
|
+
_isValid() {
|
|
202
|
+
let isValid = true, firstErrorElement = null;
|
|
203
|
+
this._removeError();
|
|
204
|
+
|
|
205
|
+
for (let i = 0; i < this._domForm.els.length; i++) {
|
|
206
|
+
const el = this._domForm.els[i];
|
|
207
|
+
const error = this._checkError(el);
|
|
208
|
+
if( !error ) continue;
|
|
209
|
+
else isValid = false;
|
|
210
|
+
if (!isValid && firstErrorElement === null) firstErrorElement = el;
|
|
192
211
|
}
|
|
193
|
-
|
|
194
|
-
|
|
212
|
+
|
|
213
|
+
if (!isValid && firstErrorElement && this._options.animateToFirstError) {
|
|
214
|
+
gsap.to(window, {
|
|
215
|
+
duration: .6,
|
|
216
|
+
scrollTo: (window.pageYOffset + firstErrorElement.getBoundingClientRect().top - 150)
|
|
217
|
+
})
|
|
195
218
|
}
|
|
196
|
-
return
|
|
219
|
+
return isValid;
|
|
220
|
+
}
|
|
221
|
+
|
|
222
|
+
/** @private */
|
|
223
|
+
_formGrabDom() {
|
|
224
|
+
/** @private */
|
|
225
|
+
this._domForm = {};
|
|
226
|
+
this._domForm.inputs = [...this._form.querySelectorAll('input[type=text],input[type=number],input[type=password],input[type=hidden],input[type=search],input[type=email],input[type=email],input[type=tel],textarea')];
|
|
227
|
+
this._domForm.choices = [...this._form.querySelectorAll('select, input[type=radio],input[type=checkbox]')];
|
|
228
|
+
this._domForm.els = [...this._domForm.inputs, ...this._domForm.choices];
|
|
197
229
|
}
|
|
198
230
|
|
|
231
|
+
/** @private */
|
|
199
232
|
_formAddEvents() {
|
|
200
|
-
this.
|
|
233
|
+
this._form.addEventListener('submit', this._onFormSubmit);
|
|
201
234
|
this._domForm.inputs.forEach( input => {
|
|
202
|
-
input.addEventListener('keyup', this.
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
input.addEventListener('change', this._onFormKeyUp);
|
|
207
|
-
}
|
|
235
|
+
input.addEventListener('keyup', this._onChange);
|
|
236
|
+
});
|
|
237
|
+
this._domForm.choices.forEach( input => {
|
|
238
|
+
input.addEventListener('change', this._onChange);
|
|
208
239
|
});
|
|
209
240
|
}
|
|
210
241
|
}
|
|
211
242
|
|
|
212
|
-
|
|
243
|
+
/**
|
|
244
|
+
* Test required input/radio/checkbox is valid
|
|
245
|
+
* @param {Element} el Input to test
|
|
246
|
+
* @param {Element} form Formulaire
|
|
247
|
+
* @return {Boolean} Returns if element is valid or not
|
|
248
|
+
*/
|
|
249
|
+
export function testRequired(el, form) {
|
|
250
|
+
const isRequired = el.getAttribute('required');
|
|
251
|
+
if (isRequired === null) return true;
|
|
252
|
+
|
|
253
|
+
const type = el.getAttribute('type');
|
|
254
|
+
if(type === 'radio') {
|
|
255
|
+
const radios = [...form.querySelectorAll(`input[type="radio"][name="${el.getAttribute('name')}"]`)];
|
|
256
|
+
for (let i = 0; i < radios.length; i++) {
|
|
257
|
+
if (radios[i].checked) return true;
|
|
258
|
+
}
|
|
259
|
+
return false;
|
|
260
|
+
} else if( type === 'checkbox') return el.checked;
|
|
261
|
+
return el.value !== '';
|
|
262
|
+
}
|
|
263
|
+
|
|
264
|
+
/**
|
|
265
|
+
* Test input of email type is valid
|
|
266
|
+
* @param {Element} el Input to test
|
|
267
|
+
* @param {Element} form Formulaire
|
|
268
|
+
* @return {Boolean} Returns if element is valid or not
|
|
269
|
+
*/
|
|
270
|
+
export function testEmail(el, form) {
|
|
271
|
+
const type = el.getAttribute('type');
|
|
272
|
+
if(type !== 'email') return true;
|
|
273
|
+
return el.value === '' && !regex_email(el.value);
|
|
274
|
+
}
|
|
275
|
+
|
|
276
|
+
/**
|
|
277
|
+
* Test element with attribute data-formvalidate-same and his twin are same
|
|
278
|
+
* @param {Element} el Input to test
|
|
279
|
+
* @param {Element} form Formulaire
|
|
280
|
+
* @return {Boolean} Returns if element is valid or not
|
|
281
|
+
*/
|
|
282
|
+
export function testSame(el, form) {
|
|
283
|
+
const hasSame = el.getAttribute('data-formvalidate-same');
|
|
284
|
+
if(hasSame === null) return true;
|
|
285
|
+
const twinEl = form.querySelector(`[data-formvalidate-same=${el.getAttribute('data-formvalidate-same')}]`);
|
|
286
|
+
return twinEl.value === el.value;
|
|
287
|
+
}
|
|
288
|
+
|
|
289
|
+
/**
|
|
290
|
+
* Test element with pattern is valid
|
|
291
|
+
* @param {Element} el Input to test
|
|
292
|
+
* @param {Element} form Formulaire
|
|
293
|
+
* @return {Boolean} Returns if element is valid or not
|
|
294
|
+
*/
|
|
295
|
+
export function testPattern(el, form) {
|
|
296
|
+
const pattern = el.getAttribute('pattern');
|
|
297
|
+
if(pattern === null) return true;
|
|
298
|
+
const rgx = new RegExp(pattern);
|
|
299
|
+
return el.value === '' && !rgx.test(el.value);
|
|
300
|
+
}
|
package/package.json
CHANGED
package/utils/media/autoplay.js
CHANGED
|
@@ -1,13 +1,9 @@
|
|
|
1
1
|
export default (callback) => {
|
|
2
|
-
// Is the callback a function?
|
|
3
2
|
if (typeof callback !== 'function') {
|
|
4
|
-
console.
|
|
3
|
+
console.warn('Autoplay: Callback must be a function!');
|
|
5
4
|
return false;
|
|
6
5
|
}
|
|
7
|
-
// Check if sessionStorage exist for autoplaySupported,
|
|
8
|
-
// if so we don't need to check for support again
|
|
9
6
|
if (!sessionStorage.autoplaySupported) {
|
|
10
|
-
// Create video element to test autoplay
|
|
11
7
|
var video = document.createElement('video');
|
|
12
8
|
video.autoplay = true;
|
|
13
9
|
video.src = 'data:video/mp4;base64,AAAAIGZ0eXBtcDQyAAAAAG1wNDJtcDQxaXNvbWF2YzEAAATKbW9vdgAAAGxtdmhkAAAAANLEP5XSxD+VAAB1MAAAdU4AAQAAAQAAAAAAAAAAAAAAAAEAAAAAAAAAAAAAAAAAAAABAAAAAAAAAAAAAAAAAABAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAgAAACFpb2RzAAAAABCAgIAQAE////9//w6AgIAEAAAAAQAABDV0cmFrAAAAXHRraGQAAAAH0sQ/ldLEP5UAAAABAAAAAAAAdU4AAAAAAAAAAAAAAAAAAAAAAAEAAAAAAAAAAAAAAAAAAAABAAAAAAAAAAAAAAAAAABAAAAAAoAAAAFoAAAAAAAkZWR0cwAAABxlbHN0AAAAAAAAAAEAAHVOAAAH0gABAAAAAAOtbWRpYQAAACBtZGhkAAAAANLEP5XSxD+VAAB1MAAAdU5VxAAAAAAANmhkbHIAAAAAAAAAAHZpZGUAAAAAAAAAAAAAAABMLVNNQVNIIFZpZGVvIEhhbmRsZXIAAAADT21pbmYAAAAUdm1oZAAAAAEAAAAAAAAAAAAAACRkaW5mAAAAHGRyZWYAAAAAAAAAAQAAAAx1cmwgAAAAAQAAAw9zdGJsAAAAwXN0c2QAAAAAAAAAAQAAALFhdmMxAAAAAAAAAAEAAAAAAAAAAAAAAAAAAAAAAoABaABIAAAASAAAAAAAAAABCkFWQyBDb2RpbmcAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAP//AAAAOGF2Y0MBZAAf/+EAHGdkAB+s2UCgL/lwFqCgoKgAAB9IAAdTAHjBjLABAAVo6+yyLP34+AAAAAATY29scm5jbHgABQAFAAUAAAAAEHBhc3AAAAABAAAAAQAAABhzdHRzAAAAAAAAAAEAAAAeAAAD6QAAAQBjdHRzAAAAAAAAAB4AAAABAAAH0gAAAAEAAB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BXwAAAwAAAwAOmAAAABdBmqxJqEFsmUwIK//+tSqAAAADAAAdUAAAABFBnspFFSwV/wAAAwAAAwAOmQAAAA8Bnul0QV8AAAMAAAMADpgAAAAPAZ7rakFfAAADAAADAA6YAAAAF0Ga8EmoQWyZTAgr//61KoAAAAMAAB1RAAAAEUGfDkUVLBX/AAADAAADAA6ZAAAADwGfLXRBXwAAAwAAAwAOmQAAAA8Bny9qQV8AAAMAAAMADpgAAAAXQZs0SahBbJlMCCv//rUqgAAAAwAAHVAAAAARQZ9SRRUsFf8AAAMAAAMADpkAAAAPAZ9xdEFfAAADAAADAA6YAAAADwGfc2pBXwAAAwAAAwAOmAAAABdBm3hJqEFsmUwIK//+tSqAAAADAAAdUQAAABFBn5ZFFSwV/wAAAwAAAwAOmAAAAA8Bn7V0QV8AAAMAAAMADpkAAAAPAZ+3akFfAAADAAADAA6ZAAAAF0GbvEmoQWyZTAgr//61KoAAAAMAAB1QAAAAEUGf2kUVLBX/AAADAAADAA6ZAAAADwGf+XRBXwAAAwAAAwAOmAAAAA8Bn/tqQV8AAAMAAAMADpkAAAAXQZv9SahBbJlMCCv//rUqgAAAAwAAHVE=';
|
|
@@ -15,27 +11,14 @@ export default (callback) => {
|
|
|
15
11
|
video.style.display = 'none';
|
|
16
12
|
video.playing = false;
|
|
17
13
|
video.play();
|
|
18
|
-
// Check if video plays
|
|
19
14
|
video.onplay = function () {
|
|
20
15
|
this.playing = true;
|
|
21
16
|
};
|
|
22
|
-
// Video has loaded, check autoplay support
|
|
23
17
|
video.oncanplay = function () {
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
callback(true);
|
|
27
|
-
} else {
|
|
28
|
-
sessionStorage.autoplaySupported = 'false';
|
|
29
|
-
callback(false);
|
|
30
|
-
}
|
|
18
|
+
sessionStorage.autoplaySupported = video.playing ? 'true' : 'false';
|
|
19
|
+
callback(video.playing);
|
|
31
20
|
};
|
|
32
21
|
} else {
|
|
33
|
-
|
|
34
|
-
// use sessionStorage.autoplaySupported
|
|
35
|
-
if (sessionStorage.autoplaySupported === 'true') {
|
|
36
|
-
callback(true);
|
|
37
|
-
} else {
|
|
38
|
-
callback(false);
|
|
39
|
-
}
|
|
22
|
+
callback(sessionStorage.autoplaySupported === 'true');
|
|
40
23
|
}
|
|
41
24
|
}
|