Skip to content

Commit

Permalink
fixed undefined variables
Browse files Browse the repository at this point in the history
IMPORTANT: this branch builds upon PR vitmalina#2019

added eslint rule ``'no-undef': 'error',``

Hunted down most undefined variables.

improved docs on w2utils.parseColor
  • Loading branch information
mpf82 committed May 25, 2021
1 parent 85f4466 commit 1f57982
Show file tree
Hide file tree
Showing 6 changed files with 22 additions and 9 deletions.
5 changes: 5 additions & 0 deletions .eslintrc.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,10 @@ module.exports = {
'globals': {
'$': 'readonly',
'app': 'readonly',
'define': 'readonly',
'exports': 'readonly',
'jQuery': 'readonly',
'module': 'readonly',
'w2ui': 'readonly',
'w2obj': 'readonly',
'w2utils': 'readonly',
Expand Down Expand Up @@ -50,6 +54,7 @@ module.exports = {
'func-name-matching': 'warn',
// "func-names": ["warn", "always"],
'no-inner-declarations': 'off',
'no-undef': 'error',
'no-unreachable': 'off',
// PLUGIN rules
'align-assignments/align-assignments' : [ 2, { requiresOnly : false } ],
Expand Down
7 changes: 6 additions & 1 deletion docs/details/w2utils.parseColor.html
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,12 @@
Returns object.

<h4>Description</h4>
The <span class="argument">color</span> argument is a web color, for example:
The <span class="argument">color</span> argument is a web color.

Valid notations include 3, 6 or 8 hex digits with an optional leading hash symbol,
as well as rgb() or rgba() notations.

Example:

<textarea class="javascript">
w2utils.parseColor('49A4DF01')
Expand Down
2 changes: 1 addition & 1 deletion src/w2compat.js
Original file line number Diff line number Diff line change
Expand Up @@ -1404,7 +1404,7 @@ import { w2toolbar } from './w2toolbar'
if (index[1] < 0) index[1] = 0
if (index[1] > pal[0].length - 1) index[1] = pal[0].length - 1

color = pal[index[0]][index[1]]
let color = pal[index[0]][index[1]]
$(el).data('_color', color)
return color
}
Expand Down
1 change: 0 additions & 1 deletion src/w2form.js
Original file line number Diff line number Diff line change
Expand Up @@ -348,7 +348,6 @@ class w2form extends w2event {
// let the management of the error outside of the grid
let edata = this.trigger({ target: this.name, type: 'error', message: msg , xhr: this.last.xhr })
if (edata.isCancelled === true) {
if (typeof callBack === 'function') callBack()
return
}
// need a time out because message might be already up)
Expand Down
13 changes: 8 additions & 5 deletions src/w2grid.js
Original file line number Diff line number Diff line change
Expand Up @@ -1188,7 +1188,7 @@ class w2grid extends w2event {
break
case 'ends':
case 'ends with': // need for back compatibility
lastIndex = val1.lastIndexOf(val2)
let lastIndex = val1.lastIndexOf(val2)
if (lastIndex !== -1 && lastIndex == val1.length - val2.length) fl++ // do not hide record
break
}
Expand Down Expand Up @@ -2698,7 +2698,6 @@ class w2grid extends w2event {
// let the management of the error outside of the grid
let edata = this.trigger({ target: this.name, type: 'error', message: msg , xhr: this.last.xhr })
if (edata.isCancelled === true) {
if (typeof callBack == 'function') callBack({ status: 'error', message: 'Request aborted.' })
return
}
this.message(msg)
Expand Down Expand Up @@ -7655,7 +7654,7 @@ class w2grid extends w2event {
}
if ($.isPlainObject(data) /*&& col.editable*/) { //It can be an object btw
if (col.options && col.options.items) {
val = col.options.items.find((item) => { return item.id == data.id })
let val = col.options.items.find((item) => { return item.id == data.id })
if (val) data = val.text
else data = data.id
} else {
Expand Down Expand Up @@ -7759,7 +7758,9 @@ class w2grid extends w2event {
if (returnOnly !== true) {
// event before
let edata = this.trigger({ phase: 'before', type: 'stateSave', target: this.name, state: state })
if (edata.isCancelled === true) { if (typeof callBack == 'function') callBack({ status: 'error', message: 'Request aborted.' }); return }
if (edata.isCancelled === true) {
return
}
try {
let savedState = $.parseJSON(localStorage.w2ui || '{}')
if (!savedState) savedState = {}
Expand Down Expand Up @@ -7793,7 +7794,9 @@ class w2grid extends w2event {
}
// event before
let edata = this.trigger({ phase: 'before', type: 'stateRestore', target: this.name, state: newState })
if (edata.isCancelled === true) { if (typeof callBack == 'function') callBack({ status: 'error', message: 'Request aborted.' }); return }
if (edata.isCancelled === true) {
return
}
// default behavior
if ($.isPlainObject(newState)) {
$.extend(this.show, newState.show)
Expand Down
3 changes: 2 additions & 1 deletion src/w2toolbar.js
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,7 @@ class w2toolbar extends w2event {
this.items.push(newItem)
} else {
let middle = this.get(id, true)
this.items = this.items.slice(0, middle).concat([netItem], this.items.slice(middle))
this.items = this.items.slice(0, middle).concat([newItem], this.items.slice(middle))
}
this.refresh(newItem.id)
})
Expand Down Expand Up @@ -236,6 +236,7 @@ class w2toolbar extends w2event {
}

uncheck() {
let obj = this
let effected = []
Array.from(arguments).forEach(item => {
let it = this.get(item)
Expand Down

0 comments on commit 1f57982

Please sign in to comment.