Skip to content

Commit 1f32ccd

Browse files
authored
Merge pull request #556 from wenzhixin/fix/jquery
Replace jQuery utility methods with native JavaScript
2 parents f3ddcb0 + b44de61 commit 1f32ccd

16 files changed

Lines changed: 42 additions & 42 deletions

assets/js/index.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
const isDebug = ['localhost', '127.0.0.1'].indexOf(location.hostname) > -1
1+
const isDebug = ['localhost', '127.0.0.1'].includes(location.hostname)
22
const { computed, createApp, onMounted, ref } = window.Vue
33

44
const Utils = {
@@ -74,7 +74,7 @@ const Utils = {
7474
$('.view-example, .view-source').off('click').click(function () {
7575
if (isSource) {
7676
location.hash = location.hash.replace('#view-source', '')
77-
} else if (location.hash.indexOf('view-source') === -1) {
77+
} else if (!location.hash.includes('view-source')) {
7878
location.hash += '#view-source'
7979
}
8080
})

assets/js/template.js

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
window._config = {
22
isDebug: location.hash.slice(1) === 'is-debug' ||
3-
['localhost', '127.0.0.1', 'dev.bootstrap-table.com'].indexOf(location.hostname) > -1,
3+
['localhost', '127.0.0.1', 'dev.bootstrap-table.com'].includes(location.hostname),
44
cdnUrl: 'https://cdn.jsdelivr.net/npm/bootstrap-table@1.26.0/dist/',
55
localUrl: '../bootstrap-table/src/',
66
testUrl: '/src/'
@@ -169,9 +169,9 @@ function _beautifySource (data) {
169169
}
170170
}
171171

172-
result = result.concat($.map(obj.links, _getLink))
172+
result = result.concat(obj.links.map(_getLink))
173173
addEmptyLine()
174-
result = result.concat($.map(obj.scripts, function (script) {
174+
result = result.concat(obj.scripts.map(function (script) {
175175
return _getScript(script, true)
176176
}))
177177
addEmptyLine()
@@ -282,7 +282,7 @@ window.init = function (options_) {
282282
if ($('.bd-lead').length) {
283283
$('.bd-lead').html(window.marked(options.desc)).find('a').attr('target', '_blank')
284284
}
285-
$.each(options.links, function (i, file) {
285+
options.links.forEach(function (file) {
286286
_link(file)
287287
})
288288
_scripts(options.scripts, options.callback)

extensions/custom-view.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -219,7 +219,7 @@ <h3 class="mb-0">%SNIPPETS%</h3>
219219
const template = $('#profileTemplate').html()
220220
let view = ''
221221

222-
$.each(data, function (i, row) {
222+
data.forEach(function (row) {
223223
view += template.replace('%NAME%', row.name)
224224
.replace('%IMAGE%', row.image)
225225
.replace('%FOLLOWER%', row.follower)

issues/395.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@
5252
$remove.prop('disabled', !$table.bootstrapTable('getSelections').length)
5353
})
5454
$remove.click(function () {
55-
const ids = $.map($table.bootstrapTable('getSelections'), function (row) {
55+
const ids = $table.bootstrapTable('getSelections').map(function (row) {
5656
return row.id
5757
})
5858

issues/917.html

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -44,8 +44,8 @@
4444
let selections = []
4545

4646
window.responseHandler = res => {
47-
$.each(res.rows, function (i, row) {
48-
row.state = $.inArray(row.id, selections) !== -1
47+
res.rows.forEach(function (row) {
48+
row.state = selections.includes(row.id)
4949
})
5050
return res
5151
}
@@ -59,11 +59,11 @@
5959
rows = rowsBefore
6060
}
6161

62-
const ids = $.map(!$.isArray(rows) ? [rows] : rows, function (row) {
62+
const ids = (!Array.isArray(rows) ? [rows] : rows).map(function (row) {
6363
return row.id
6464
})
6565

66-
const func = $.inArray(e.type, ['check', 'check-all']) > -1 ? 'union' : 'difference'
66+
const func = ['check', 'check-all'].includes(e.type) ? 'union' : 'difference'
6767

6868
selections = window._[func](selections, ids)
6969
})

methods/expand-collapse-all-rows.html

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -64,9 +64,9 @@
6464
window.detailFormatter = (index, row) => {
6565
const html = []
6666

67-
$.each(row, function (key, value) {
68-
html.push(`<p><b>${key}:</b> ${value}</p>`)
69-
})
67+
for (const key in row) {
68+
html.push(`<p><b>${key}:</b> ${row[key]}</p>`)
69+
}
7070
return html.join('')
7171
}
7272
</script>

methods/expand-collapse-row-by-uniqueid.html

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -66,9 +66,9 @@
6666
window.detailFormatter = (index, row) => {
6767
const html = []
6868

69-
$.each(row, function (key, value) {
70-
html.push(`<p><b>${key}:</b> ${value}</p>`)
71-
})
69+
for (const key in row) {
70+
html.push(`<p><b>${key}:</b> ${row[key]}</p>`)
71+
}
7272
return html.join('')
7373
}
7474
</script>

methods/expand-collapse-row.html

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -64,9 +64,9 @@
6464
window.detailFormatter = (index, row) => {
6565
const html = []
6666

67-
$.each(row, function (key, value) {
68-
html.push(`<p><b>${key}:</b> ${value}</p>`)
69-
})
67+
for (const key in row) {
68+
html.push(`<p><b>${key}:</b> ${row[key]}</p>`)
69+
}
7070
return html.join('')
7171
}
7272
</script>

methods/remove.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@
5656

5757
function mounted () {
5858
$button.click(function () {
59-
const ids = $.map($table.bootstrapTable('getSelections'), function (row) {
59+
const ids = $table.bootstrapTable('getSelections').map(function (row) {
6060
return row.id
6161
})
6262

methods/toggle-detail-view.html

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -56,9 +56,9 @@
5656
window.detailFormatter = (index, row) => {
5757
const html = []
5858

59-
$.each(row, function (key, value) {
60-
html.push(`<p><b>${key}:</b> ${value}</p>`)
61-
})
59+
for (const key in row) {
60+
html.push(`<p><b>${key}:</b> ${row[key]}</p>`)
61+
}
6262
return html.join('')
6363
}
6464
</script>

0 commit comments

Comments
 (0)