Passed
Pull Request — master (#67)
by Michael
02:36
created

script/custom/paragraphButtons.js   A

Complexity

Total Complexity 5
Complexity/F 1.67

Size

Lines of Code 49
Function Count 3

Duplication

Duplicated Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 0
wmc 5
eloc 26
nc 1
mnd 1
bc 5
fnc 3
dl 0
loc 49
rs 10
bpm 1.6666
cpm 1.6666
noi 1
c 0
b 0
f 0

2 Functions

Rating   Name   Duplication   Size   Complexity  
A paragraphButtons.js ➔ initializeButtons 0 18 2
A paragraphButtons.js ➔ getButtonSpec 0 16 2
1
import { insertParagraphAtPos } from '../customCommands';
2
3
/**
4
 * Attach event handler to buttons for inserting a paragraph
5
 *
6
 * @return {void}
7
 */
8
export function initializeButtons() {
9
    if (window.Prosemirror.paragraphHandlingIsInitialized) {
10
        return;
11
    }
12
    window.Prosemirror.paragraphHandlingIsInitialized = true;
13
    jQuery(document).on('click', '.ProseMirror button.addParagraphButton', function insertParagraph(event) {
14
        event.stopPropagation();
15
        event.preventDefault();
16
        const $button = jQuery(this);
17
        const viewID = $button.data('viewid');
18
        const direction = $button.data('direction');
19
        const view = window.Prosemirror.views[viewID];
20
21
        const pos = view.posAtDOM(event.target.parentNode);
22
        const command = insertParagraphAtPos(pos, direction);
23
        command(view.state, view.dispatch);
24
    });
25
}
26
27
/**
28
 * Produce the spec for a button to insert a paragraph before or after the respective element
29
 *
30
 * @param viewID
31
 * @param direction
32
 * @return {array}
33
 */
34
export function getButtonSpec(viewID, direction) {
35
    if (typeof LANG === 'undefined') {
0 ignored issues
show
Bug introduced by
The variable LANG seems to be never declared. If this is a global, consider adding a /** global: LANG */ comment.

This checks looks for references to variables that have not been declared. This is most likey a typographical error or a variable has been renamed.

To learn more about declaring variables in Javascript, see the MDN.

Loading history...
36
        // early return during js schema testing
37
        return [];
38
    }
39
    return [
40
        'button',
41
        {
42
            class: 'addParagraphButton',
43
            type: 'button',
44
            'data-direction': direction,
45
            'data-viewid': viewID,
46
        },
47
        LANG.plugins.prosemirror['button:insert paragraph'],
48
    ];
49
}
50