Skip to content

Commit 2dc5ace

Browse files
marevolclaude
andauthored
Modernize JavaScript screen implementations with ES5 compatibility (#2965)
* Modernize JavaScript screen implementations Improved all screen JavaScript files (advance.js, help.js, index.js, login.js, profile.js, search.js) with the following enhancements: - Replace var with const/let for better scoping and immutability - Use arrow functions for cleaner, more concise syntax - Remove obsolete vendor prefixes (-webkit-box-shadow, -moz-box-shadow) - Replace deprecated .hover() with .on('mouseenter'/'mouseleave') - Use .prop() instead of .attr() for disabled property - Fix incorrect AJAX timeout parameter (timeoutNumber → timeout) - Replace document.location with window.location.href - Extract duplicated suggestor configuration into reusable constant - Add named constants for magic numbers (durations, timeouts) - Improve error handling with console.error instead of commented alerts - Use template literals for cleaner string concatenation - Optimize favorites loading with Set for O(1) lookup performance - Fix submit button click to properly trigger form submission - Use classList.remove/add with multiple classes for better readability - Improve focus handling logic in login/profile pages - Add proper event.preventDefault() calls where needed These changes maintain full backward compatibility while improving code quality, readability, and maintainability. * Fix ES5 compatibility for yuicompressor Replace ES6 arrow functions and features with ES5-compatible syntax to fix build errors with yuicompressor which only supports ES5. Changes: - Replace all arrow functions (() => {}) with regular function expressions - Replace template literals with string concatenation - Remove ES6 default parameters - Remove ES6 Set and map() usage in favor of object literal and for loop - Replace .includes() method calls with .indexOf() checks Files affected: advance.js, help.js, index.js, search.js All other improvements from the previous commit are preserved: - const/let instead of var - Named constants for magic numbers - Extracted suggestor configuration - Bug fixes (timeout parameter, submit handler, etc.) * Replace const/let with var for full yuicompressor compatibility yuicompressor only supports ES5 syntax and does not recognize const/let keywords which were introduced in ES6. Replace all const and let declarations with var to ensure successful build. This completes the ES5 compatibility work. All JavaScript files now use only ES5-compatible syntax: - var instead of const/let - function() instead of arrow functions - String concatenation instead of template literals - for loops instead of Array.map() - Object literals instead of Set Files updated: - advance.js - help.js - index.js - login.js - profile.js - search.js * Improve variable naming for lookup map clarity Rename docIds to docIdsLookup to clarify that the object is being used as a lookup map for O(1) performance. This makes the code intent clearer while maintaining ES5 compatibility required by yuicompressor. Note: ES6 Set would be preferred but is not supported by yuicompressor. --------- Co-authored-by: Claude <[email protected]>
1 parent b5d036f commit 2dc5ace

File tree

6 files changed

+269
-343
lines changed

6 files changed

+269
-343
lines changed

src/main/webapp/js/advance.js

Lines changed: 32 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -1,43 +1,41 @@
11
$(function() {
2-
var $searchButton = $("#searchButton"),
3-
contextPath = $("#contextPath").val();
2+
var $searchButton = $("#searchButton");
3+
var contextPath = $("#contextPath").val();
4+
var BUTTON_DISABLE_DURATION = 3000;
45

5-
$("#searchForm").on("submit", function(e) {
6-
$searchButton.attr("disabled", true);
6+
var SUGGESTOR_CONFIG = {
7+
ajaxinfo: {
8+
url: contextPath + "/api/v1/suggest-words",
9+
fn: ["_default", "content", "title"],
10+
num: 10,
11+
lang: $("#langSearchOption").val()
12+
},
13+
boxCssInfo: {
14+
border: "1px solid rgba(82, 168, 236, 0.5)",
15+
"box-shadow": "0 1px 1px 0px rgba(0, 0, 0, 0.1), 0 3px 2px 0px rgba(82, 168, 236, 0.2)",
16+
"background-color": "#fff",
17+
"z-index": "10000"
18+
},
19+
listSelectedCssInfo: {
20+
"background-color": "rgba(82, 168, 236, 0.1)"
21+
},
22+
listDeselectedCssInfo: {
23+
"background-color": "#ffffff"
24+
},
25+
minterm: 1,
26+
adjustWidthVal: 11,
27+
searchForm: $("#searchForm")
28+
};
29+
30+
$("#searchForm").on("submit", function() {
31+
$searchButton.prop("disabled", true);
732
setTimeout(function() {
8-
$searchButton.attr("disabled", false);
9-
}, 3000);
33+
$searchButton.prop("disabled", false);
34+
}, BUTTON_DISABLE_DURATION);
1035
return true;
1136
});
1237

1338
if (typeof $.fn.suggestor === "function") {
14-
$("#as_q").suggestor({
15-
ajaxinfo: {
16-
url: contextPath + "/api/v1/suggest-words",
17-
fn: ["_default", "content", "title"],
18-
num: 10,
19-
lang: $("#langSearchOption").val()
20-
},
21-
boxCssInfo: {
22-
border: "1px solid rgba(82, 168, 236, 0.5)",
23-
"-webkit-box-shadow":
24-
"0 1px 1px 0px rgba(0, 0, 0, 0.1), 0 3px 2px 0px rgba(82, 168, 236, 0.2)",
25-
"-moz-box-shadow":
26-
"0 1px 1px 0px rgba(0, 0, 0, 0.1), 0 3px 2px 0px rgba(82, 168, 236, 0.2)",
27-
"box-shadow":
28-
"0 1px 1px 0px rgba(0, 0, 0, 0.1), 0 3px 2px 0px rgba(82, 168, 236, 0.2)",
29-
"background-color": "#fff",
30-
"z-index": "10000"
31-
},
32-
listSelectedCssInfo: {
33-
"background-color": "rgba(82, 168, 236, 0.1)"
34-
},
35-
listDeselectedCssInfo: {
36-
"background-color": "#ffffff"
37-
},
38-
minterm: 1,
39-
adjustWidthVal: 11,
40-
searchForm: $("#searchForm")
41-
});
39+
$("#as_q").suggestor(SUGGESTOR_CONFIG);
4240
}
4341
});

src/main/webapp/js/help.js

Lines changed: 34 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,37 @@
11
$(function() {
2-
var $searchButton = $("#searchButton"),
3-
contextPath = $("#contextPath").val();
2+
var $searchButton = $("#searchButton");
3+
var contextPath = $("#contextPath").val();
4+
var BUTTON_DISABLE_DURATION = 3000;
45

5-
$("#searchForm").on("submit", function(e) {
6-
$searchButton.attr("disabled", true);
6+
var SUGGESTOR_CONFIG = {
7+
ajaxinfo: {
8+
url: contextPath + "/api/v1/suggest-words",
9+
fn: ["_default", "content", "title"],
10+
num: 10,
11+
lang: $("#langSearchOption").val()
12+
},
13+
boxCssInfo: {
14+
border: "1px solid rgba(82, 168, 236, 0.5)",
15+
"box-shadow": "0 1px 1px 0px rgba(0, 0, 0, 0.1), 0 3px 2px 0px rgba(82, 168, 236, 0.2)",
16+
"background-color": "#fff",
17+
"z-index": "10000"
18+
},
19+
listSelectedCssInfo: {
20+
"background-color": "rgba(82, 168, 236, 0.1)"
21+
},
22+
listDeselectedCssInfo: {
23+
"background-color": "#ffffff"
24+
},
25+
minterm: 1,
26+
adjustWidthVal: 11,
27+
searchForm: $("#searchForm")
28+
};
29+
30+
$("#searchForm").on("submit", function() {
31+
$searchButton.prop("disabled", true);
732
setTimeout(function() {
8-
$searchButton.attr("disabled", false);
9-
}, 3000);
33+
$searchButton.prop("disabled", false);
34+
}, BUTTON_DISABLE_DURATION);
1035
return true;
1136
});
1237

@@ -16,7 +41,7 @@ $(function() {
1641
}
1742
});
1843

19-
$("[data-toggle='control-options']").click(function(e) {
44+
$("[data-toggle='control-options']").on("click", function(e) {
2045
e.preventDefault();
2146
var target = $(this).attr("data-target") || $(this).attr("href");
2247
if (target) {
@@ -25,41 +50,14 @@ $(function() {
2550
});
2651

2752
$("#searchOptionsClearButton").on("click", function(e) {
53+
e.preventDefault();
2854
$("#labelTypeSearchOption").prop("selectedIndex", -1);
2955
$("#langSearchOption").prop("selectedIndex", 0);
3056
$("#sortSearchOption").prop("selectedIndex", 0);
3157
$("#numSearchOption").prop("selectedIndex", 0);
32-
return false;
3358
});
3459

3560
if (typeof $.fn.suggestor === "function") {
36-
$("#query").suggestor({
37-
ajaxinfo: {
38-
url: contextPath + "/api/v1/suggest-words",
39-
fn: ["_default", "content", "title"],
40-
num: 10,
41-
lang: $("#langSearchOption").val()
42-
},
43-
boxCssInfo: {
44-
border: "1px solid rgba(82, 168, 236, 0.5)",
45-
"-webkit-box-shadow":
46-
"0 1px 1px 0px rgba(0, 0, 0, 0.1), 0 3px 2px 0px rgba(82, 168, 236, 0.2)",
47-
"-moz-box-shadow":
48-
"0 1px 1px 0px rgba(0, 0, 0, 0.1), 0 3px 2px 0px rgba(82, 168, 236, 0.2)",
49-
"box-shadow":
50-
"0 1px 1px 0px rgba(0, 0, 0, 0.1), 0 3px 2px 0px rgba(82, 168, 236, 0.2)",
51-
"background-color": "#fff",
52-
"z-index": "10000"
53-
},
54-
listSelectedCssInfo: {
55-
"background-color": "rgba(82, 168, 236, 0.1)"
56-
},
57-
listDeselectedCssInfo: {
58-
"background-color": "#ffffff"
59-
},
60-
minterm: 1,
61-
adjustWidthVal: 11,
62-
searchForm: $("#searchForm")
63-
});
61+
$("#query").suggestor(SUGGESTOR_CONFIG);
6462
}
6563
});

src/main/webapp/js/index.js

Lines changed: 35 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,39 @@
11
$(function() {
2-
$("#contentQuery").focus();
2+
var $searchButton = $("#searchButton");
3+
var contextPath = $("#contextPath").val();
4+
var BUTTON_DISABLE_DURATION = 3000;
5+
6+
var SUGGESTOR_CONFIG = {
7+
ajaxinfo: {
8+
url: contextPath + "/api/v1/suggest-words",
9+
fn: ["_default", "content", "title"],
10+
num: 10,
11+
lang: $("#langSearchOption").val()
12+
},
13+
boxCssInfo: {
14+
border: "1px solid rgba(82, 168, 236, 0.5)",
15+
"box-shadow": "0 1px 1px 0px rgba(0, 0, 0, 0.1), 0 3px 2px 0px rgba(82, 168, 236, 0.2)",
16+
"background-color": "#fff",
17+
"z-index": "10000"
18+
},
19+
listSelectedCssInfo: {
20+
"background-color": "rgba(82, 168, 236, 0.1)"
21+
},
22+
listDeselectedCssInfo: {
23+
"background-color": "#ffffff"
24+
},
25+
minterm: 1,
26+
adjustWidthVal: 11,
27+
searchForm: $("#searchForm")
28+
};
329

4-
var $searchButton = $("#searchButton"),
5-
contextPath = $("#contextPath").val();
30+
$("#contentQuery").focus();
631

7-
$("#searchForm").on("submit", function(e) {
8-
$searchButton.attr("disabled", true);
32+
$("#searchForm").on("submit", function() {
33+
$searchButton.prop("disabled", true);
934
setTimeout(function() {
10-
$searchButton.attr("disabled", false);
11-
}, 3000);
35+
$searchButton.prop("disabled", false);
36+
}, BUTTON_DISABLE_DURATION);
1237
return true;
1338
});
1439

@@ -18,7 +43,7 @@ $(function() {
1843
}
1944
});
2045

21-
$("[data-toggle='control-options']").click(function(e) {
46+
$("[data-toggle='control-options']").on("click", function(e) {
2247
e.preventDefault();
2348
var target = $(this).attr("data-target") || $(this).attr("href");
2449
if (target) {
@@ -27,41 +52,14 @@ $(function() {
2752
});
2853

2954
$("#searchOptionsClearButton").on("click", function(e) {
55+
e.preventDefault();
3056
$("#labelTypeSearchOption").prop("selectedIndex", -1);
3157
$("#langSearchOption").prop("selectedIndex", 0);
3258
$("#sortSearchOption").prop("selectedIndex", 0);
3359
$("#numSearchOption").prop("selectedIndex", 0);
34-
return false;
3560
});
3661

3762
if (typeof $.fn.suggestor === "function") {
38-
$("#contentQuery").suggestor({
39-
ajaxinfo: {
40-
url: contextPath + "/api/v1/suggest-words",
41-
fn: ["_default", "content", "title"],
42-
num: 10,
43-
lang: $("#langSearchOption").val()
44-
},
45-
boxCssInfo: {
46-
border: "1px solid rgba(82, 168, 236, 0.5)",
47-
"-webkit-box-shadow":
48-
"0 1px 1px 0px rgba(0, 0, 0, 0.1), 0 3px 2px 0px rgba(82, 168, 236, 0.2)",
49-
"-moz-box-shadow":
50-
"0 1px 1px 0px rgba(0, 0, 0, 0.1), 0 3px 2px 0px rgba(82, 168, 236, 0.2)",
51-
"box-shadow":
52-
"0 1px 1px 0px rgba(0, 0, 0, 0.1), 0 3px 2px 0px rgba(82, 168, 236, 0.2)",
53-
"background-color": "#fff",
54-
"z-index": "10000"
55-
},
56-
listSelectedCssInfo: {
57-
"background-color": "rgba(82, 168, 236, 0.1)"
58-
},
59-
listDeselectedCssInfo: {
60-
"background-color": "#ffffff"
61-
},
62-
minterm: 1,
63-
adjustWidthVal: 11,
64-
searchForm: $("#searchForm")
65-
});
63+
$("#contentQuery").suggestor(SUGGESTOR_CONFIG);
6664
}
6765
});

src/main/webapp/js/login.js

Lines changed: 29 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -1,54 +1,46 @@
11
$(function() {
2-
$('input[type="text"],select,textarea', ".login-box,section.content")
3-
.first()
4-
.focus();
5-
$(".form-group .has-error")
6-
.first()
7-
.next("input,select,textarea")
8-
.focus();
2+
var $firstInput = $('input[type="text"],select,textarea', ".login-box,section.content").first();
3+
var $errorInput = $(".form-group .has-error").first().next("input,select,textarea");
94

10-
$("section.content input").keypress(function(e) {
11-
var $submitButton;
5+
if ($errorInput.length) {
6+
$errorInput.focus();
7+
} else {
8+
$firstInput.focus();
9+
}
10+
11+
$("section.content input").on("keypress", function(e) {
1212
if (e.which === 13) {
13-
$submitButton = $("input#submit, button#submit");
13+
var $submitButton = $("input#submit, button#submit");
1414
if ($submitButton.length > 0) {
15-
$submitButton[0].submit();
15+
$submitButton.closest("form").trigger("submit");
1616
}
17-
// ignore enter key down
1817
return false;
1918
}
2019
});
2120

2221
$(".table tr[data-href]").each(function() {
23-
$(this)
24-
.css("cursor", "pointer")
25-
.hover(
26-
function() {
27-
$(this).addClass("active");
28-
},
29-
function() {
30-
$(this).removeClass("active");
31-
}
32-
)
33-
.click(function() {
34-
document.location = $(this).attr("data-href");
22+
var $row = $(this);
23+
$row.css("cursor", "pointer")
24+
.on("mouseenter", function() {
25+
$(this).addClass("active");
26+
})
27+
.on("mouseleave", function() {
28+
$(this).removeClass("active");
29+
})
30+
.on("click", function() {
31+
window.location.href = $(this).attr("data-href");
3532
});
3633
});
3734

3835
$("#confirmToDelete").on("show.bs.modal", function(event) {
39-
var button = $(event.relatedTarget),
40-
docId = button.data("docid"),
41-
title = button.data("title"),
42-
url = button.data("url");
36+
var button = $(event.relatedTarget);
37+
var docId = button.data("docid");
38+
var title = button.data("title");
39+
var url = button.data("url");
4340

44-
$(this)
45-
.find(".modal-body #delete-doc-title")
46-
.text(title);
47-
$(this)
48-
.find(".modal-body #delete-doc-url")
49-
.text(url);
50-
$(this)
51-
.find(".modal-footer input#docId")
52-
.val(docId);
41+
var $modal = $(this);
42+
$modal.find(".modal-body #delete-doc-title").text(title);
43+
$modal.find(".modal-body #delete-doc-url").text(url);
44+
$modal.find(".modal-footer input#docId").val(docId);
5345
});
5446
});

0 commit comments

Comments
 (0)