Skip to content

Commit e8448fa

Browse files
authored
Merge pull request #680 from wenzhixin/fix/issue-677-jquery-trim
Fix: Replace jQuery utilities with ES6+ in site templates
2 parents d789961 + e246aa7 commit e8448fa

2 files changed

Lines changed: 12 additions & 8 deletions

File tree

site/website/static/js/template.js

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -97,18 +97,18 @@ function _beautifySource(data) {
9797
var scriptStart = lines.indexOf('<script>')
9898
var scriptEnd = lines.indexOf('</script>', scriptStart)
9999
var strings = lines.slice(scriptStart + 1, scriptEnd)
100-
strings = $.map(strings, function (s) {
101-
return $.trim(s)
100+
strings = strings.map(function (s) {
101+
return s.trim()
102102
})
103103
/* eslint-disable no-control-regex */
104104
var obj = eval('(' + strings.join('').replace(/[^\u0000-\u007E]/g, '')
105105
.replace(/^init\((.*)\)$/, '$1') + ')')
106106

107107
var result = []
108-
result = result.concat($.map(obj.links, _getLink))
108+
result = result.concat(obj.links.map(_getLink))
109109
result.push('')
110110
result.push('<script src="https://cdn.jsdelivr.net/npm/jquery/dist/jquery.min.js"></script>')
111-
result = result.concat($.map(obj.scripts, function (script) {
111+
result = result.concat(obj.scripts.map(function (script) {
112112
return _getScript(script, true)
113113
}))
114114
lines = result.concat(lines.slice(scriptEnd + 1))
@@ -133,7 +133,11 @@ $(function () {
133133

134134
$.ajax({
135135
type: 'GET',
136-
url: url + '?' + $.param(query),
136+
url: url + '?' + Object.keys(query).filter(function(key) {
137+
return query[key] !== null && query[key] !== undefined
138+
}).map(function(key) {
139+
return encodeURIComponent(key) + '=' + encodeURIComponent(query[key])
140+
}).join('&'),
137141
dataType: 'html',
138142
global: false,
139143
cache: true, // (warning: setting it to false will cause a timestamp and will call the request twice)
@@ -154,7 +158,7 @@ $(function () {
154158
})
155159

156160
window.init = function (options_) {
157-
var options = $.extend({
161+
var options = Object.assign({
158162
title: '',
159163
desc: '',
160164
links: [],
@@ -169,7 +173,7 @@ window.init = function (options_) {
169173

170174
$('.bd-title span').html(options.title)
171175
$('.bd-lead').html(options.desc)
172-
$.each(options.links, function (i, file) {
176+
options.links.forEach(function (file) {
173177
_link(file)
174178
})
175179
_scripts(options.scripts, options.callback)

site/website/static/templates/refresh.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,7 @@
6969
var $input = $('#refreshInput')
7070
var $selected = $('#refreshSelected')
7171
var $disabled = $('#refreshDisabled')
72-
var value = $.trim($input.val())
72+
var value = $input.val().trim()
7373
var $opt = $('<option />', {
7474
value: value,
7575
text: value

0 commit comments

Comments
 (0)