Total Complexity | 5 |
Complexity/F | 1.67 |
Lines of Code | 49 |
Function Count | 3 |
Duplicated Lines | 0 |
Ratio | 0 % |
Changes | 0 |
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') { |
||
|
|||
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 |
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.