Completed
Push — master ( 16cf2a...23fe36 )
by greg
57s
created

src/cli/cms/editor/handlebars/printInput.js   B

Complexity

Total Complexity 49
Complexity/F 4.08

Size

Lines of Code 213
Function Count 12

Duplication

Duplicated Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 0
nc 1
dl 0
loc 213
rs 8.5454
c 0
b 0
f 0
wmc 49
mnd 6
bc 18
fnc 12
bpm 1.5
cpm 4.0833
noi 24

10 Functions

Rating   Name   Duplication   Size   Complexity  
A printInput.js ➔ getLabel 0 6 2
A printInput.js ➔ createInputFile 0 5 1
A printInput.js ➔ createInputImage 0 15 1
F printInput.js ➔ printInput 0 35 15
D printInput.js ➔ createInputSource 0 37 10
A printInput.js ➔ createInputText 0 8 1
A printInput.js ➔ createInputLink 0 8 1
A printInput.js ➔ createInputTextarea 0 3 1
C printInput.js ➔ getAttributes 0 17 14
A printInput.js ➔ createInputRich 0 58 1

How to fix   Complexity   

Complexity

Complex classes like src/cli/cms/editor/handlebars/printInput.js often do a lot of different things. To break such a class down, we need to identify a cohesive component within that class. A common approach to find such a component is to look for fields/methods that share the same prefixes, or suffixes.

Once you have determined the fields that belong together, you can apply the Extract Class refactoring. If the component makes sense as a sub-class, Extract Subclass is also a candidate, and is often faster.

1
import sourceAutocomplete   from './sourceAutocomplete'
2
import sourceOption   from './sourceOption'
3
import {
4
  abeExtend
5
  ,User
6
} from '../../../'
7
8
export function getAttributes(params) {
9
  var attributes = ''
10
  if(params.key != null) attributes += `id="${params.key}" data-id="${params.key}"`
0 ignored issues
show
Coding Style Best Practice introduced by
Curly braces around statements make for more readable code and help prevent bugs when you add further statements.

Consider adding curly braces around all statements when they are executed conditionally. This is optional if there is only one statement, but leaving them out can lead to unexpected behaviour if another statement is added later.

Consider:

if (a > 0)
    b = 42;

If you or someone else later decides to put another statement in, only the first statement will be executed.

if (a > 0)
    console.log("a > 0");
    b = 42;

In this case the statement b = 42 will always be executed, while the logging statement will be executed conditionally.

if (a > 0) {
    console.log("a > 0");
    b = 42;
}

ensures that the proper code will be executed conditionally no matter how many statements are added or removed.

Loading history...
11
  if(params.value != null) attributes += ` value="${params.value}"`
0 ignored issues
show
Coding Style Best Practice introduced by
Curly braces around statements make for more readable code and help prevent bugs when you add further statements.

Consider adding curly braces around all statements when they are executed conditionally. This is optional if there is only one statement, but leaving them out can lead to unexpected behaviour if another statement is added later.

Consider:

if (a > 0)
    b = 42;

If you or someone else later decides to put another statement in, only the first statement will be executed.

if (a > 0)
    console.log("a > 0");
    b = 42;

In this case the statement b = 42 will always be executed, while the logging statement will be executed conditionally.

if (a > 0) {
    console.log("a > 0");
    b = 42;
}

ensures that the proper code will be executed conditionally no matter how many statements are added or removed.

Loading history...
12
  if(params['max-length'] != null) attributes += ` maxlength="${params['max-length']}" data-maxlength="${params['max-length']}"`
0 ignored issues
show
Coding Style Best Practice introduced by
Curly braces around statements make for more readable code and help prevent bugs when you add further statements.

Consider adding curly braces around all statements when they are executed conditionally. This is optional if there is only one statement, but leaving them out can lead to unexpected behaviour if another statement is added later.

Consider:

if (a > 0)
    b = 42;

If you or someone else later decides to put another statement in, only the first statement will be executed.

if (a > 0)
    console.log("a > 0");
    b = 42;

In this case the statement b = 42 will always be executed, while the logging statement will be executed conditionally.

if (a > 0) {
    console.log("a > 0");
    b = 42;
}

ensures that the proper code will be executed conditionally no matter how many statements are added or removed.

Loading history...
13
  if(params.reload != null) attributes += ` reload="${params.reload}"`
0 ignored issues
show
Coding Style Best Practice introduced by
Curly braces around statements make for more readable code and help prevent bugs when you add further statements.

Consider adding curly braces around all statements when they are executed conditionally. This is optional if there is only one statement, but leaving them out can lead to unexpected behaviour if another statement is added later.

Consider:

if (a > 0)
    b = 42;

If you or someone else later decides to put another statement in, only the first statement will be executed.

if (a > 0)
    console.log("a > 0");
    b = 42;

In this case the statement b = 42 will always be executed, while the logging statement will be executed conditionally.

if (a > 0) {
    console.log("a > 0");
    b = 42;
}

ensures that the proper code will be executed conditionally no matter how many statements are added or removed.

Loading history...
14
  if(params.order != null) attributes += ` tabIndex="${params.order}"`
0 ignored issues
show
Coding Style Best Practice introduced by
Curly braces around statements make for more readable code and help prevent bugs when you add further statements.

Consider adding curly braces around all statements when they are executed conditionally. This is optional if there is only one statement, but leaving them out can lead to unexpected behaviour if another statement is added later.

Consider:

if (a > 0)
    b = 42;

If you or someone else later decides to put another statement in, only the first statement will be executed.

if (a > 0)
    console.log("a > 0");
    b = 42;

In this case the statement b = 42 will always be executed, while the logging statement will be executed conditionally.

if (a > 0) {
    console.log("a > 0");
    b = 42;
}

ensures that the proper code will be executed conditionally no matter how many statements are added or removed.

Loading history...
15
  if(params.required != null) attributes += ` data-required="${params.required}"`
0 ignored issues
show
Coding Style Best Practice introduced by
Curly braces around statements make for more readable code and help prevent bugs when you add further statements.

Consider adding curly braces around all statements when they are executed conditionally. This is optional if there is only one statement, but leaving them out can lead to unexpected behaviour if another statement is added later.

Consider:

if (a > 0)
    b = 42;

If you or someone else later decides to put another statement in, only the first statement will be executed.

if (a > 0)
    console.log("a > 0");
    b = 42;

In this case the statement b = 42 will always be executed, while the logging statement will be executed conditionally.

if (a > 0) {
    console.log("a > 0");
    b = 42;
}

ensures that the proper code will be executed conditionally no matter how many statements are added or removed.

Loading history...
16
  if(params.display != null) attributes += ` data-display="${params.display}"`
0 ignored issues
show
Coding Style Best Practice introduced by
Curly braces around statements make for more readable code and help prevent bugs when you add further statements.

Consider adding curly braces around all statements when they are executed conditionally. This is optional if there is only one statement, but leaving them out can lead to unexpected behaviour if another statement is added later.

Consider:

if (a > 0)
    b = 42;

If you or someone else later decides to put another statement in, only the first statement will be executed.

if (a > 0)
    console.log("a > 0");
    b = 42;

In this case the statement b = 42 will always be executed, while the logging statement will be executed conditionally.

if (a > 0) {
    console.log("a > 0");
    b = 42;
}

ensures that the proper code will be executed conditionally no matter how many statements are added or removed.

Loading history...
17
  if(params.visible != null) attributes += ` data-visible="${params.visible}"`
0 ignored issues
show
Coding Style Best Practice introduced by
Curly braces around statements make for more readable code and help prevent bugs when you add further statements.

Consider adding curly braces around all statements when they are executed conditionally. This is optional if there is only one statement, but leaving them out can lead to unexpected behaviour if another statement is added later.

Consider:

if (a > 0)
    b = 42;

If you or someone else later decides to put another statement in, only the first statement will be executed.

if (a > 0)
    console.log("a > 0");
    b = 42;

In this case the statement b = 42 will always be executed, while the logging statement will be executed conditionally.

if (a > 0) {
    console.log("a > 0");
    b = 42;
}

ensures that the proper code will be executed conditionally no matter how many statements are added or removed.

Loading history...
18
  if(params.autocomplete != null) attributes += ` data-autocomplete="${params.autocomplete}"`
0 ignored issues
show
Coding Style Best Practice introduced by
Curly braces around statements make for more readable code and help prevent bugs when you add further statements.

Consider adding curly braces around all statements when they are executed conditionally. This is optional if there is only one statement, but leaving them out can lead to unexpected behaviour if another statement is added later.

Consider:

if (a > 0)
    b = 42;

If you or someone else later decides to put another statement in, only the first statement will be executed.

if (a > 0)
    console.log("a > 0");
    b = 42;

In this case the statement b = 42 will always be executed, while the logging statement will be executed conditionally.

if (a > 0) {
    console.log("a > 0");
    b = 42;
}

ensures that the proper code will be executed conditionally no matter how many statements are added or removed.

Loading history...
19
  if(params.placeholder != null) attributes += ` placeholder="${params.placeholder}"`
0 ignored issues
show
Coding Style Best Practice introduced by
Curly braces around statements make for more readable code and help prevent bugs when you add further statements.

Consider adding curly braces around all statements when they are executed conditionally. This is optional if there is only one statement, but leaving them out can lead to unexpected behaviour if another statement is added later.

Consider:

if (a > 0)
    b = 42;

If you or someone else later decides to put another statement in, only the first statement will be executed.

if (a > 0)
    console.log("a > 0");
    b = 42;

In this case the statement b = 42 will always be executed, while the logging statement will be executed conditionally.

if (a > 0) {
    console.log("a > 0");
    b = 42;
}

ensures that the proper code will be executed conditionally no matter how many statements are added or removed.

Loading history...
20
  if(params.thumbs != null) attributes += ` data-size="${params.thumbs}"`
0 ignored issues
show
Coding Style Best Practice introduced by
Curly braces around statements make for more readable code and help prevent bugs when you add further statements.

Consider adding curly braces around all statements when they are executed conditionally. This is optional if there is only one statement, but leaving them out can lead to unexpected behaviour if another statement is added later.

Consider:

if (a > 0)
    b = 42;

If you or someone else later decides to put another statement in, only the first statement will be executed.

if (a > 0)
    console.log("a > 0");
    b = 42;

In this case the statement b = 42 will always be executed, while the logging statement will be executed conditionally.

if (a > 0) {
    console.log("a > 0");
    b = 42;
}

ensures that the proper code will be executed conditionally no matter how many statements are added or removed.

Loading history...
21
  if(params.multiple != null) attributes += ` ${params.multiple}`
0 ignored issues
show
Coding Style Best Practice introduced by
Curly braces around statements make for more readable code and help prevent bugs when you add further statements.

Consider adding curly braces around all statements when they are executed conditionally. This is optional if there is only one statement, but leaving them out can lead to unexpected behaviour if another statement is added later.

Consider:

if (a > 0)
    b = 42;

If you or someone else later decides to put another statement in, only the first statement will be executed.

if (a > 0)
    console.log("a > 0");
    b = 42;

In this case the statement b = 42 will always be executed, while the logging statement will be executed conditionally.

if (a > 0) {
    console.log("a > 0");
    b = 42;
}

ensures that the proper code will be executed conditionally no matter how many statements are added or removed.

Loading history...
22
  if(params.disabled != null) attributes += ` ${params.disabled}`
0 ignored issues
show
Coding Style Best Practice introduced by
Curly braces around statements make for more readable code and help prevent bugs when you add further statements.

Consider adding curly braces around all statements when they are executed conditionally. This is optional if there is only one statement, but leaving them out can lead to unexpected behaviour if another statement is added later.

Consider:

if (a > 0)
    b = 42;

If you or someone else later decides to put another statement in, only the first statement will be executed.

if (a > 0)
    console.log("a > 0");
    b = 42;

In this case the statement b = 42 will always be executed, while the logging statement will be executed conditionally.

if (a > 0) {
    console.log("a > 0");
    b = 42;
}

ensures that the proper code will be executed conditionally no matter how many statements are added or removed.

Loading history...
23
  return attributes
24
}
25
26
export function getLabel(params) {
27
  var desc = params.desc + ((params.required) ? ' *' : '')
28
  return `<label class="control-label" for="${params.key}" >
29
            ${desc}
30
          </label>`
31
}
32
33
export function createInputSource(attributes, inputClass, params) {
34
  var inputSource = ''
35
  var lastValues
36
  if(params.autocomplete != null && params.autocomplete === 'true') {
37
    if(params.sourceString.indexOf('http') === 0) lastValues = params.source
0 ignored issues
show
Coding Style Best Practice introduced by
Curly braces around statements make for more readable code and help prevent bugs when you add further statements.

Consider adding curly braces around all statements when they are executed conditionally. This is optional if there is only one statement, but leaving them out can lead to unexpected behaviour if another statement is added later.

Consider:

if (a > 0)
    b = 42;

If you or someone else later decides to put another statement in, only the first statement will be executed.

if (a > 0)
    console.log("a > 0");
    b = 42;

In this case the statement b = 42 will always be executed, while the logging statement will be executed conditionally.

if (a > 0) {
    console.log("a > 0");
    b = 42;
}

ensures that the proper code will be executed conditionally no matter how many statements are added or removed.

Loading history...
38
    else lastValues = JSON.stringify(params.source).replace(/\'/g, '&quote;')
39
    inputSource += '<div class="autocomplete-result-wrapper">'
40
    if(params.autocomplete != null && params.autocomplete === 'true' && params.prefill === 'true') {
41
      inputSource += `<div  class="autocomplete-refresh" value=''
42
                            data-autocomplete-refresh="true"
43
                            data-autocomplete-refresh-sourcestring="${params.sourceString}"
44
                            data-autocomplete-refresh-prefill-quantity="${params['prefill-quantity']}"
45
                            data-autocomplete-refresh-key="${params.key}"
46
                            data-autocomplete-data-display="${params.display}" >
47
                        <span class="glyphicon glyphicon-refresh"></span>
48
                      </div>`
49
    }
50
    Array.prototype.forEach.call(params.value, (val) => {
51
      inputSource += sourceAutocomplete(val, params)
52
    })
53
    inputSource += `</div><input value="" type="text" autocomplete="off" data-value='${lastValues}' ${attributes} class="${inputClass}" />`
54
  }
55
  else {
56
    lastValues = JSON.stringify(params.value).replace(/\'/g, '&quote;')
57
    inputSource += `<select ${attributes} class="${inputClass}" last-values='${lastValues}'>`
58
59
    if (!params.required) inputSource += '<option value=\'\'></option>'
0 ignored issues
show
Coding Style Best Practice introduced by
Curly braces around statements make for more readable code and help prevent bugs when you add further statements.

Consider adding curly braces around all statements when they are executed conditionally. This is optional if there is only one statement, but leaving them out can lead to unexpected behaviour if another statement is added later.

Consider:

if (a > 0)
    b = 42;

If you or someone else later decides to put another statement in, only the first statement will be executed.

if (a > 0)
    console.log("a > 0");
    b = 42;

In this case the statement b = 42 will always be executed, while the logging statement will be executed conditionally.

if (a > 0) {
    console.log("a > 0");
    b = 42;
}

ensures that the proper code will be executed conditionally no matter how many statements are added or removed.

Loading history...
60
    if(typeof params.source === 'object' && Object.prototype.toString.call(params.source) === '[object Array]') {
61
      Array.prototype.forEach.call(params.source, (val) => {
62
        inputSource += sourceOption(val, params)
63
      })
64
    }
65
    else inputSource += sourceOption(params.source, params)
0 ignored issues
show
Coding Style Best Practice introduced by
Curly braces around statements make for more readable code and help prevent bugs when you add further statements.

Consider adding curly braces around all statements when they are executed conditionally. This is optional if there is only one statement, but leaving them out can lead to unexpected behaviour if another statement is added later.

Consider:

if (a > 0)
    b = 42;

If you or someone else later decides to put another statement in, only the first statement will be executed.

if (a > 0)
    console.log("a > 0");
    b = 42;

In this case the statement b = 42 will always be executed, while the logging statement will be executed conditionally.

if (a > 0) {
    console.log("a > 0");
    b = 42;
}

ensures that the proper code will be executed conditionally no matter how many statements are added or removed.

Loading history...
66
    inputSource += '</select>'
67
  }
68
  return inputSource
69
}
70
71
export function createInputRich(attributes, inputClass, params) {
72
  return `<div class="wysiwyg-container rich">
73
            <div class="wysiwyg-toolbar wysiwyg-toolbar-top">
74
              <a class="wysiwyg-toolbar-icon" href="#" title="Bold (Ctrl+B)" hotkey="b" data-action="bold" data-param="">
75
                <span class="glyphicon glyphicon-bold"></span>
76
              </a>
77
              <a class="wysiwyg-toolbar-icon" href="#" title="Italic (Ctrl+I)" hotkey="i" data-action="italic" data-param="">
78
                <span class="glyphicon glyphicon-italic"></span>
79
              </a>
80
              <a class="wysiwyg-toolbar-icon" href="#" title="Underline (Ctrl+U)" hotkey="u" data-action="underline" data-param="">
81
                <span class="glyphicon underline">U</span>
82
              </a>
83
              <a class="wysiwyg-toolbar-icon" href="#" title="Text color" data-action="forecolor" data-param="" data-popup="color">
84
                <span class="glyphicon glyphicon-text-color"></span>
85
              </a>
86
              <a class="wysiwyg-toolbar-icon" href="#" title="Background color" data-action="highlight" data-param="" data-popup="color">
87
                <span class="glyphicon glyphicon-text-background"></span>
88
              </a>
89
              <a class="wysiwyg-toolbar-icon" href="#" title="Left" data-action="align" data-param="left">
90
                <span class="glyphicon glyphicon-object-align-left"></span>
91
              </a>
92
              <a class="wysiwyg-toolbar-icon" href="#" title="Center" data-action="align" data-param="center">
93
                <span class="glyphicon glyphicon-object-align-vertical"></span>
94
              </a>
95
              <a class="wysiwyg-toolbar-icon" href="#" title="Right" data-action="align" data-param="right">
96
                <span class="glyphicon glyphicon-object-align-right"></span>
97
              </a>
98
              <a class="wysiwyg-toolbar-icon" href="#" title="Justify" data-action="justify" data-param="justify">
99
                <span class="glyphicon glyphicon-menu-hamburger"></span>
100
              </a>
101
              <a class="wysiwyg-toolbar-icon" href="#" title="Subscript" data-action="subscript" data-param="">
102
                <span class="glyphicon glyphicon-subscript"></span>
103
              </a>
104
              <a class="wysiwyg-toolbar-icon" href="#" title="Superscript" data-action="superscript" data-param="">
105
                <span class="glyphicon glyphicon-superscript"></span>
106
              </a>
107
              <a class="wysiwyg-toolbar-icon" href="#" title="Indent" data-action="indent" data-param="">
108
                <span class="glyphicon glyphicon-triangle-right"></span>
109
              </a>
110
              <a class="wysiwyg-toolbar-icon" href="#" title="Outdent" data-action="indent" data-param="outdent">
111
                <span class="glyphicon glyphicon-triangle-left"></span>
112
              </a>
113
              <a class="wysiwyg-toolbar-icon" href="#" title="Unordered list" data-action="insertList" data-param="">
114
                <span class="glyphicon glyphicon-th-list"></span>
115
              </a>
116
              <a class="wysiwyg-toolbar-icon" href="#" title="Remove format" data-action="removeFormat" data-param="">
117
                <span class="glyphicon glyphicon-remove"></span>
118
              </a>
119
              <a class="wysiwyg-toolbar-icon" href="#" title="Add link" data-action="insertLink" data-popup="link" data-param="">
120
                <span class="glyphicon glyphicon-link"></span>
121
              </a>
122
              <a class="wysiwyg-toolbar-icon" href="#" title="Code style" data-action="code" data-param="">
123
                <span class="glyphicon glyphicon-console"></span>
124
              </a>
125
            </div>
126
            <textarea class="${inputClass} form-rich" ${attributes} rows="4">${params.value}</textarea>
127
          </div>`
128
}
129
130
export function createInputFile(attributes, inputClass, params) {
131
  return `<input class="form-control" ${attributes} name="${params.key}" type="file" />
132
          <span class="percent"></span>
133
          <input type="text" ${attributes} class="${inputClass} hidden" />`
134
}
135
136
export function createInputTextarea(attributes, inputClass, params) {
137
  return `<textarea class="${inputClass}" ${attributes} rows="4">${params.value}</textarea>`
138
}
139
140
export function createInputLink(attributes, inputClass, params) {
0 ignored issues
show
Unused Code introduced by
The parameter params is not used and could be removed.

This check looks for parameters in functions that are not used in the function body and are not followed by other parameters which are used inside the function.

Loading history...
141
  return `<div class="input-group">
142
            <div class="input-group-addon link">
143
              <span class="glyphicon glyphicon-link" aria-hidden="true"></span>
144
            </div>
145
            <input type="text" ${attributes} class="${inputClass}" />
146
          </div>`
147
}
148
149
export function createInputImage(attributes, inputClass, params) {
150
  return `<div class="input-group img-upload">
151
            <div class="input-group-addon image">
152
              <span class="glyphicon glyphicon-picture" aria-hidden="true"></span>
153
            </div>
154
            <input type="text" ${attributes} class="${inputClass} image-input" />
155
            <div class="upload-wrapper">
156
              <input class="form-control" ${attributes} name="${params.key}" type="file" title="upload an image"/>
157
              <span class="percent">
158
                <span class="glyphicon glyphicon-upload" aria-hidden="true"></span>
159
              </span>
160
            </div>
161
          </div>
162
          <div class="input-error"></div>`
163
}
164
165
export function createInputText(attributes, inputClass, params) {
0 ignored issues
show
Unused Code introduced by
The parameter params is not used and could be removed.

This check looks for parameters in functions that are not used in the function body and are not followed by other parameters which are used inside the function.

Loading history...
166
  return `<div class="input-group">
167
          <div class="input-group-addon">
168
            <span class="glyphicon glyphicon-font" aria-hidden="true"></span>
169
            </div>
170
            <input type="text" ${attributes} class="${inputClass}" />
171
          </div>`
172
}
173
174
/**
175
 * Print form input based on input data type {Textarea | text | meta | link | image | ...}
176
 * && add appropriate attributs / data-attributs
177
 * @return {String|html} input / input group ...
178
 */
179
export function printInput (params, root) {
180
  params = abeExtend.hooks.instance.trigger('beforeEditorInput', params)
181
  var userWorkflow = (root.user != null) ? root.user.role.workflow : ''
182
  var res = `<div class="form-group" data-precontrib-templates="${params.precontribTemplate}">`
183
  var inputClass = 'form-control form-abe'
184
  res += getLabel(params)
185
186
  params.placeholder = params.placeholder || ''
187
  params.value = params.value || ''
188
  
189
  if(typeof params.value === 'string') params.value = params.value.replace(/\"/g, '&quot;')
0 ignored issues
show
Coding Style Best Practice introduced by
Curly braces around statements make for more readable code and help prevent bugs when you add further statements.

Consider adding curly braces around all statements when they are executed conditionally. This is optional if there is only one statement, but leaving them out can lead to unexpected behaviour if another statement is added later.

Consider:

if (a > 0)
    b = 42;

If you or someone else later decides to put another statement in, only the first statement will be executed.

if (a > 0)
    console.log("a > 0");
    b = 42;

In this case the statement b = 42 will always be executed, while the logging statement will be executed conditionally.

if (a > 0) {
    console.log("a > 0");
    b = 42;
}

ensures that the proper code will be executed conditionally no matter how many statements are added or removed.

Loading history...
190
191
  params.disabled = ''
192
  if (params.tab !== 'slug' && !User.utils.isUserAllowedOnRoute(userWorkflow, `/abe/operations/${params.status}/edit`)) {
193
    params.disabled = 'disabled="disabled"'
194
  }
195
  var attributes = getAttributes(params)
196
197
  if(params.source != null) {
198
    params.multiple = ((params['max-length'] == null || params['max-length'] > 1) && params.source.length > 0) ? 'multiple' : ''
199
    params.disabled = (params.source.length <= 0) ? 'disabled' : ''
200
    res += createInputSource(getAttributes(params), inputClass, params)
201
  }
202
  else if (params.type.indexOf('rich') >= 0) res += createInputRich(attributes, inputClass, params)
0 ignored issues
show
Coding Style Best Practice introduced by
Curly braces around statements make for more readable code and help prevent bugs when you add further statements.

Consider adding curly braces around all statements when they are executed conditionally. This is optional if there is only one statement, but leaving them out can lead to unexpected behaviour if another statement is added later.

Consider:

if (a > 0)
    b = 42;

If you or someone else later decides to put another statement in, only the first statement will be executed.

if (a > 0)
    console.log("a > 0");
    b = 42;

In this case the statement b = 42 will always be executed, while the logging statement will be executed conditionally.

if (a > 0) {
    console.log("a > 0");
    b = 42;
}

ensures that the proper code will be executed conditionally no matter how many statements are added or removed.

Loading history...
203
  else if (params.type.indexOf('file') >= 0) res += createInputFile(attributes, inputClass, params)
0 ignored issues
show
Coding Style Best Practice introduced by
Curly braces around statements make for more readable code and help prevent bugs when you add further statements.

Consider adding curly braces around all statements when they are executed conditionally. This is optional if there is only one statement, but leaving them out can lead to unexpected behaviour if another statement is added later.

Consider:

if (a > 0)
    b = 42;

If you or someone else later decides to put another statement in, only the first statement will be executed.

if (a > 0)
    console.log("a > 0");
    b = 42;

In this case the statement b = 42 will always be executed, while the logging statement will be executed conditionally.

if (a > 0) {
    console.log("a > 0");
    b = 42;
}

ensures that the proper code will be executed conditionally no matter how many statements are added or removed.

Loading history...
204
  else if (params.type.indexOf('textarea') >= 0) res += createInputTextarea(attributes, inputClass, params)
0 ignored issues
show
Coding Style Best Practice introduced by
Curly braces around statements make for more readable code and help prevent bugs when you add further statements.

Consider adding curly braces around all statements when they are executed conditionally. This is optional if there is only one statement, but leaving them out can lead to unexpected behaviour if another statement is added later.

Consider:

if (a > 0)
    b = 42;

If you or someone else later decides to put another statement in, only the first statement will be executed.

if (a > 0)
    console.log("a > 0");
    b = 42;

In this case the statement b = 42 will always be executed, while the logging statement will be executed conditionally.

if (a > 0) {
    console.log("a > 0");
    b = 42;
}

ensures that the proper code will be executed conditionally no matter how many statements are added or removed.

Loading history...
205
  else if (params.type.indexOf('link') >= 0) res += createInputLink(attributes, inputClass, params)
0 ignored issues
show
Coding Style Best Practice introduced by
Curly braces around statements make for more readable code and help prevent bugs when you add further statements.

Consider adding curly braces around all statements when they are executed conditionally. This is optional if there is only one statement, but leaving them out can lead to unexpected behaviour if another statement is added later.

Consider:

if (a > 0)
    b = 42;

If you or someone else later decides to put another statement in, only the first statement will be executed.

if (a > 0)
    console.log("a > 0");
    b = 42;

In this case the statement b = 42 will always be executed, while the logging statement will be executed conditionally.

if (a > 0) {
    console.log("a > 0");
    b = 42;
}

ensures that the proper code will be executed conditionally no matter how many statements are added or removed.

Loading history...
206
  else if (params.type.indexOf('image') >= 0) res += createInputImage(attributes, inputClass, params)
0 ignored issues
show
Coding Style Best Practice introduced by
Curly braces around statements make for more readable code and help prevent bugs when you add further statements.

Consider adding curly braces around all statements when they are executed conditionally. This is optional if there is only one statement, but leaving them out can lead to unexpected behaviour if another statement is added later.

Consider:

if (a > 0)
    b = 42;

If you or someone else later decides to put another statement in, only the first statement will be executed.

if (a > 0)
    console.log("a > 0");
    b = 42;

In this case the statement b = 42 will always be executed, while the logging statement will be executed conditionally.

if (a > 0) {
    console.log("a > 0");
    b = 42;
}

ensures that the proper code will be executed conditionally no matter how many statements are added or removed.

Loading history...
207
  else res += createInputText(attributes, inputClass, params)
208
209
  res += '</div>'
210
  res = abeExtend.hooks.instance.trigger('afterEditorInput', res, params)
211
212
  return res
213
}