Passed
Push — v3 ( 1e51d3...178405 )
by Andrew
25:46
created

assetbundles/seomatic/src/js/seomatic-tokens.js (2 issues)

1
/**
2
 * SEOmatic plugin for Craft CMS 3.x
3
 *
4
 * A turnkey SEO implementation for Craft CMS that is comprehensive, powerful,
5
 * and flexible
6
 *
7
 * @link      https://nystudio107.com
8
 * @copyright Copyright (c) 2017 nystudio107
9
 */
10
11
/**
12
 * @author    nystudio107
13
 * @package   SEOmatic
14
 * @since     3.0.0
15
 */
16
17
// JavaScript
18
import Tokenfield from 'tokenfield';
19
20
// Tokenize any seomatic-keywords fields
21
for (const el of document.querySelectorAll('.seomatic-keywords')) {
22
    let keywords = undefined;
23
24
    if (el.value) {
25
        keywords = el.value.split(',').map((value, index) => {
26
            if (value !== '') {
27
                return {id: index, name: value};
28
            }
29
        });
30
    }
31
    let options = {
32
        el: el,
33
        addItemOnBlur: true,
34
        addItemsOnPaste: true,
35
        delimiters: [','],
36
    };
37
    if (keywords !== undefined && keywords[0] !== undefined) {
38
        options.setItems = keywords;
39
    }
40
    let tf = new Tokenfield(options);
41
    let resetting = false;
42
    tf.on('change', (tokenField) => {
43
        if (!resetting && el.disabled) {
44
            resetting = true;
45
            tokenField._onReset();
46
            resetting = false;
47
            return;
48
        }
49
0 ignored issues
show
There should be no empty lines in a multi-line function call.
Loading history...
50
        let values = tokenField._vars.setItems.map((value) => {
51
            return value.name;
52
        });
53
        
0 ignored issues
show
There should be no empty lines in a multi-line function call.
Loading history...
54
        tokenField.el.value = values.join(',');
55
    });
56
}
57