Skip to content

Commit 2889205

Browse files
committed
Refactor home.js file
Signed-off-by: Maurício Meneghini Fauth <mauricio@fauth.dev>
1 parent 11c9458 commit 2889205

2 files changed

Lines changed: 40 additions & 20 deletions

File tree

.jshintrc

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
11
{
2+
"esversion" : 6,
3+
24
// Show more errors
35
"maxerr" : 1000,
46

js/src/home.js

Lines changed: 38 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ const GitInfo = {
44
* @param {string} str
55
* @return {number | false}
66
*/
7-
parseVersionString: function (str) {
7+
parseVersionString: str => {
88
if (typeof(str) !== 'string') {
99
return false;
1010
}
@@ -37,7 +37,7 @@ const GitInfo = {
3737
* Indicates current available version on main page.
3838
* @param {object} data
3939
*/
40-
currentVersion: function (data) {
40+
currentVersion: data => {
4141
if (data && data.version && data.date) {
4242
const current = GitInfo.parseVersionString($('span.version').text());
4343
const latest = GitInfo.parseVersionString(data.version);
@@ -96,7 +96,7 @@ const GitInfo = {
9696
/**
9797
* Loads Git revision data from ajax for index.php
9898
*/
99-
displayGitRevision: function () {
99+
displayGitRevision: () => {
100100
$('#is_git_revision').remove();
101101
$('#li_pma_version_git').remove();
102102
$.get(
@@ -106,30 +106,22 @@ const GitInfo = {
106106
'ajax_request': true,
107107
'no_debug': true
108108
},
109-
function (data) {
109+
data => {
110110
if (typeof data !== 'undefined' && data.success === true) {
111111
$(data.message).insertAfter('#li_pma_version');
112112
}
113113
}
114114
);
115-
}
116-
};
117-
118-
AJAX.registerTeardown('home.js', function () {
119-
$('#themesModal').off('show.bs.modal');
120-
});
121-
122-
AJAX.registerOnload('home.js', function () {
123-
$('#themesModal').on('show.bs.modal', function () {
124-
$.get('index.php?route=/themes', function (data) {
125-
$('#themesModal .modal-body').html(data.themes);
126-
});
127-
});
115+
},
128116

129117
/**
130118
* Load version information asynchronously.
131119
*/
132-
if ($('li.jsversioncheck').length > 0) {
120+
loadVersion: () => {
121+
if ($('li.jsversioncheck').length === 0) {
122+
return;
123+
}
124+
133125
$.ajax({
134126
dataType: 'json',
135127
url: 'index.php?route=/version-check',
@@ -139,9 +131,35 @@ AJAX.registerOnload('home.js', function () {
139131
},
140132
success: GitInfo.currentVersion
141133
});
142-
}
134+
},
135+
136+
showVersion: () => {
137+
GitInfo.loadVersion();
138+
if ($('#is_git_revision').length === 0) {
139+
return;
140+
}
143141

144-
if ($('#is_git_revision').length > 0) {
145142
setTimeout(GitInfo.displayGitRevision, 10);
146143
}
144+
};
145+
146+
/**
147+
* @implements EventListener
148+
*/
149+
const ThemesManager = {
150+
handleEvent: () => {
151+
$.get('index.php?route=/themes', data => {
152+
$('#themesModal .modal-body').html(data.themes);
153+
});
154+
}
155+
};
156+
157+
AJAX.registerTeardown('home.js', () => {
158+
$('#themesModal').off('show.bs.modal');
159+
});
160+
161+
AJAX.registerOnload('home.js', () => {
162+
$('#themesModal').on('show.bs.modal', ThemesManager.handleEvent);
163+
164+
GitInfo.showVersion();
147165
});

0 commit comments

Comments
 (0)