8000 Upgrade jQuery to 3.5.1 · viggo-devries/python-stdnum@992dc20 · GitHub
[go: up one dir, main page]

Skip to content

Commit 992dc20

Browse files
committed
Upgrade jQuery to 3.5.1
This also runs eslint over check.js and fixes an issue from the upgrade.
1 parent 3373938 commit 992dc20

File tree

7 files changed

+10944
-9342
lines changed

7 files changed

+10944
-9342
lines changed

online_check/check.js

Lines changed: 68 additions & 71 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
/*
22
# check.js - simple application to check numbers
33
#
4-
# Copyright (C) 2017-2018 Arthur de Jong.
4+
# Copyright (C) 2017-2020 Arthur de Jong.
55
#
66
# This library is free software; you can redistribute it and/or
77
# modify it under the terms of the GNU Lesser General Public
@@ -19,13 +19,12 @@
1919
# 02110-1301 USA
2020
*/
2121

22-
$( document ).ready(function() {
23-
22+
$(document).ready(function () {
2423
function format(value) {
25-
return $("<div/>").text(value).html().replace(
26-
/\n\n/g, "<br/>\n"
24+
return $('<div/>').text(value).html().replace(
25+
/\n\n/g, '<br/>\n'
2726
).replace(
28-
/^[*] (.*)$/gm, "<ul><li>$1</li></ul>"
27+
/^[*] (.*)$/gm, '<ul><li>$1</li></ul>'
2928
).replace(
3029
/(\b(https?|ftp):\/\/[^\s<]*[-\w+&@#/%=~_|])/ig,
3130
"<a href='$1'>$1</a>"
@@ -34,98 +33,96 @@ $( document ).ready(function() {
3433

3534
function updateresults(field, results) {
3635
// build HTML to present
37-
var h = ["<ul>"];
38-
$.each(results, function(index, result) {
36+
var h = ['<ul>']
37+
$.each(results, function (index, result) {
3938
h.push(
40-
"<li>",
41-
$("<div/>").text(result["number"]).html(),
42-
": <b>",
43-
$("<div/>").text(result["name"]).html(),
44-
"</b>",
45-
"<p>",
46-
format(result["description"]),
47-
$.map(result["conversions"], function(value, key){
39+
'<li>',
40+
$('<div/>').text(result.number).html(),
41+
': <b>',
42+
$('<div/>').text(result.name).html(),
43+
'</b>',
44+
'<p>',
45+
format(result.description),
46+
$.map(result.conversions, function (value, key) {
4847
return [
49-
"<br/><b><i>",
50-
$("<div/>").text(key).html(),
51-
"</i></b>: ",
52-
$("<div/>").text(value).html()].join('')
48+
'<br/><b><i>',
49+
$('<div/>').text(key).html(),
50+
'</i></b>: ',
51+
$('<div/>').text(value).html()].join('')
5352
}).join(''),
54-
"</p></li>")
55-
});
56-
h.push("</ul>");
53+
'</p></li>')
54+
})
55+
h.push('</ul>')
5756
// replace the results div
58-
$("#" + $(field).attr("id") + "_results").html(h.join(""));
57+
$('#' + $(field).attr('id') + '_results').html(h.join(''))
5958
}
6059

6160
function checkfield(field) {
62-
var value = field.val();
61+
var value = field.val()
6362
// only trigger update if value changed from previous validation
64-
if (value != field.data("oldvalue")) {
65-
field.data("oldvalue", value);
66-
$("#" + $(field).attr("id") + "_results").slideUp(200, function() {
67-
$.get('', {"number": value}, function(data) {
68-
window.history.pushState({"value": value, "data": data}, $(document).find("title").text(), "?number=" + encodeURIComponent(value));
69-
updateresults(field, data);
70-
});
71-
$(this).slideDown(300);
72-
});
63+
if (value !== field.data('oldvalue')) {
64+
field.data('oldvalue', value)
65+
$('#' + $(field).attr('id') + '_results').slideUp(200, function () {
66+
$.get('.', {number: value}, function (data) {
67+
window.history.pushState({value: value, data: data}, $(document).find('title').text(), '?number=' + encodeURIComponent(value))
68+
updateresults(field, data)
69+
})
70+
$(this).slideDown(300)
71+
})
7372
}
7473
}
7574

7675
// update results based on history navigation
77-
window.onpopstate = function(e) {
78-
var field = $(".stdnum_check");
76+
window.onpopstate = function (e) {
77+
var field = $('.stdnum_check')
7978
if (e.state) {
80-
var value = e.state.value;
81-
var data = e.state.data;
79+
var value = e.state.value
80+
var data = e.state.data
8281
field.val(value)
83-
field.data("oldvalue", value);
84-
updateresults(field, data);
82+
field.data('oldvalue', value)
83+
updateresults(field, data)
8584
} else {
86-
field.val("")
87-
field.data("oldvalue", "");
88-
updateresults(field, []);
85+
field.val('')
86+
field.data('oldvalue', '')
87+
updateresults(field, [])
8988
}
90-
};
89+
}
9190

9291
// trigger a check when user stopped typing
93-
$(".stdnum_check").on("input propertychange", function (event) {
94-
if (window.event && event.type == "propertychange" && event.propertyName != "value")
95-
return;
96-
var field = $(this);
97-
window.clearTimeout($(this).data("timeout"));
98-
$(this).data("timeout", setTimeout(function () {
99-
checkfield(field);
100-
}, 2000));
101-
});
92+
$('.stdnum_check').on('input propertychange', function (event) {
93+
if (window.event && event.type === 'propertychange' && event.propertyName !== 'value') { return }
94+
var field = $(this)
95+
window.clearTimeout($(this).data('timeout'))
96+
$(this).data('timeout', setTimeout(function () {
97+
checkfield(field)
98+
}, 2000))
99+
})
102100

103101
// trigger a check when losing focus
104-
$(".stdnum_check").on("blur", function() {
105-
window.clearTimeout($(this).data("timeout"));
106-
checkfield($(this));
107-
});
102+
$('.stdnum_check').on('blur', function () {
103+
window.clearTimeout($(this).data('timeout'))
104+
checkfield($(this))
105+
})
108106

109107
// prevent enter from submitting the form
110-
$(".stdnum_check").keydown(function(event) {
111-
if(event.keyCode == 13) {
112-
event.preventDefault();
113-
checkfield($(this));
114-
return false;
108+
$('.stdnum_check').keydown(function (event) {
109+
if (event.keyCode === 13) {
110+
event.preventDefault()
111+
checkfield($(this))
112+
return false
115113
}
116-
});
114+
})
117115

118116
// hide the submit button
119-
$(".stdnum_hide").hide();
117+
$('.stdnum_hide').hide()
120118

121119
// focus the text field
122-
$(".stdnum_check").focus();
120+
$('.stdnum_check').focus()
123121

124122
// save current state
125-
var value = $(".stdnum_check").val();
126-
$(".stdnum_check").data("oldvalue", value);
127-
$.get('', {number: value}, function(data) {
128-
window.history.replaceState({"value": value, "data": data}, $(document).find("title").text(), "?number=" + encodeURIComponent(value));
123+
var value = $('.stdnum_check').val()
124+
$('.stdnum_check').data('oldvalue', value)
125+
$.get('', {number: value}, function (data) {
126+
window.history.replaceState({value: value, data: data}, $(document).find('title').text(), '?number=' + encodeURIComponent(value))
129127
})
130-
131-
});
128+
})

0 commit comments

Comments
 (0)
0