Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 10 additions & 7 deletions src/js/_enqueues/lib/list-revisions.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,8 @@
(function(w) {
var init = function() {
var pr = document.getElementById('post-revisions'),
inputs = pr ? pr.getElementsByTagName('input') : [];
pr.onclick = function() {
inputs = pr ? pr.getElementsByTagName('input') : [],
update = function() {
var i, checkCount = 0, side;
for ( i = 0; i < inputs.length; i++ ) {
checkCount += inputs[i].checked ? 1 : 0;
Expand All @@ -25,10 +25,13 @@
inputs[i].style.visibility = 'visible';
}
};
pr.onclick();

if ( ! pr ) {
return;
}
Comment on lines +29 to +31

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This could be moved up right after the assignment to the pr variable. In fact, let's get rid of var altogether. We can freely use const, without reusing the one statement. So like:

const pr = document.getElementById('post-revisions');
if ( ! pr ) {
    return;
}
const inputs = pr ? pr.getElementsByTagName('input') : [];
update = function() {
    // ...

However, I wonder: why does this code still run if pr doesn't exist? It creates an update function that loops over inputs when it is an empty array. It seems like it was written this way to try to enforce the JSLint constraint to have one var, which is obsolete. So it should be changed as follows:

const pr = document.getElementById('post-revisions');
if ( ! pr ) {
    return;
}
const inputs = pr.getElementsByTagName('input');
if ( inputs.length === 0 ) {
    return;
}
update = function() {
    // ...


pr.onclick = update;

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why not so?

Suggested change
pr.onclick = update;
pr.addEventListener( 'click', update );

update();
};
if ( w && w.addEventListener )
w.addEventListener('load', init, false);
else if ( w && w.attachEvent )
w.attachEvent('onload', init);
Comment on lines -32 to -33

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good. Byebye IE.

w.addEventListener('load', init, false);
})(window);
1 change: 1 addition & 0 deletions tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@
"src/js/_enqueues/lib/codemirror/htmlhint-kses.js",
"src/js/_enqueues/lib/codemirror/javascript-lint.js",
"src/js/_enqueues/lib/emoji-loader.js",
"src/js/_enqueues/lib/list-revisions.js",
"src/js/_enqueues/wp/code-editor.js",
"src/js/_enqueues/wp/emoji.js",
"src/js/_enqueues/wp/wp-tooltip.js",
Expand Down
Loading