Skip to content

Commit 472405f

Browse files
committed
Fix JSHint static analysis warnings
1 parent 2585c09 commit 472405f

File tree

1 file changed

+15
-17
lines changed

1 file changed

+15
-17
lines changed

files/snippets.js

Lines changed: 15 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
// Copyright (c) 2012 - 2021 MantisBT Team - [email protected]
33
// Licensed under the MIT license
44

5-
jQuery(document).ready(function($) {
5+
jQuery(function($) {
66
"use strict";
77

88
/**
@@ -34,13 +34,13 @@ jQuery(document).ready(function($) {
3434
*/
3535
function SnippetsUI(data) {
3636
$(data.selector).each(function() {
37-
var textarea = $(this);
37+
const textarea = $(this);
3838

3939
// Only display snippets selector if there are any
4040
if (Array.isArray(data.snippets) && data.snippets.length > 0) {
4141
try {
4242
// Create Snippets select
43-
var select = $("<select></select>");
43+
const select = $("<select></select>");
4444

4545
// Set the Tab index equal to the associated textareas
4646
select.attr('tabindex', textarea.attr('tabindex'));
@@ -49,26 +49,26 @@ jQuery(document).ready(function($) {
4949

5050
$.each(data.snippets, function(key, snippet) {
5151
// Escape single quotes
52-
var value = snippet.value.replace(/'/g, "&#39;");
52+
const value = snippet.value.replace(/'/g, "&#39;");
5353

5454
select.append(
5555
"<option value='" + value + "' title='" + value + "'>" + snippet.name + "</option>"
5656
);
5757
});
5858

59-
select.change(function() {
60-
var text = $(this).val();
59+
select.on('change', function() {
60+
const text = $(this).val();
6161
textarea.textrange('replace', text);
6262
$(this).val("");
6363
});
6464

65-
var label = $("<label>" + data.label + " </label>");
65+
const label = $("<label>" + data.label + " </label>");
6666
label.append(select);
6767

6868
textarea.before(label);
6969
textarea.before('<div class="space-4"></div>');
7070
} catch(e) {
71-
console.error('Error occured while generating Snippets UI', e);
71+
console.error('Error occurred while generating Snippets UI', e);
7272
}
7373
}
7474
});
@@ -77,27 +77,25 @@ jQuery(document).ready(function($) {
7777
// If we have any textareas (excluding those in the plugin's own
7878
// edit pages) then fetch Snippets
7979
if ($("textarea").not(".snippetspatternhelp textarea").length > 0) {
80-
var bug_id = 0;
81-
8280
// Retrieve the bug id from the known forms where we know
8381
// Snippets-supported textareas exist.
84-
var selector = '';
85-
var known_forms = ['bug_update.php', 'bugnote_add.php', 'bug_reminder.php'];
82+
const known_forms = ['bug_update.php', 'bugnote_add.php', 'bug_reminder.php'];
83+
let selector = '';
8684
known_forms.forEach(function (value) {
8785
selector += "form[action='" + value + "'], ";
8886
});
8987
selector = selector.replace(/, $/, '');
90-
bug_id = $(selector).find("input[name='bug_id']").val();
88+
const bug_id = $('input[name="bug_id"]', selector).val();
9189

92-
var url = rest_api('data');
90+
let url = rest_api('data');
9391
if (bug_id > 0) {
9492
url += "/" + bug_id;
9593
}
9694

9795
$.getJSON(url)
9896
.done(SnippetsUI)
9997
.fail(function() {
100-
console.error('Error occured while retrieving Snippets');
98+
console.error('Error occurred while retrieving Snippets');
10199
});
102100
}
103101
}
@@ -137,12 +135,12 @@ jQuery(document).ready(function($) {
137135
}
138136

139137
// Snippet list behaviors
140-
$("input.snippets_select_all").change(function() {
138+
$("input.snippets_select_all").on('change', function() {
141139
$("input[name='snippet_list[]']").prop("checked", $(this).prop("checked"));
142140
});
143141

144142
// Snippet pattern help
145-
var selector = $(".snippetspatternhelp");
143+
const selector = $(".snippetspatternhelp");
146144
if (selector.length > 0 ) {
147145
$.get(rest_api('help'))
148146
.done(function (data) {

0 commit comments

Comments
 (0)