Author
|
zPlus <->
2017-03-27 19:40:03
|
Committer
|
zPlus <->
2017-03-27 19:40:03
|
Commit
|
7431799
(patch)
|
Tree
|
da00a68
|
Parent(s)
|
|
freepost.js: Do not bind "click" event to vote buttons if user is not
logged in.
commits diff:
9e783bb..7431799
1 file changed,
9 insertions,
4 deletions
—
download
Diffstat
Diff options
+9/-4
M javascript/freepost.js
103
|
103
|
|
* - up arrow
|
104
|
104
|
|
* - votes sum
|
105
|
105
|
|
* - down arrow
|
|
106
|
+ |
*
|
|
107
|
+ |
* However, if the user is not logged in, there's only a text
|
|
108
|
+ |
* with the sum of votes, eg. "2 votes" (no <tag> children).
|
106
|
109
|
|
*/
|
107
|
110
|
|
let vote_sections = document.querySelectorAll ('.vote');
|
108
|
111
|
|
|
109
|
112
|
|
// Bind vote() event to up/down vote arrows
|
110
|
113
|
|
for (let i = 0; i < vote_sections.length; i++)
|
111
|
|
- |
{
|
112
|
|
- |
vote_sections[i].children[0].addEventListener ('click', function () { vote ('up', this.parentNode) });
|
113
|
|
- |
vote_sections[i].children[2].addEventListener ('click', function () { vote ('down', this.parentNode) });
|
114
|
|
- |
}
|
|
114
|
+ |
// See comment above on the "vote_sections" declaration.
|
|
115
|
+ |
if (vote_sections[i].children.length > 0)
|
|
116
|
+ |
{
|
|
117
|
+ |
vote_sections[i].children[0].addEventListener ('click', function () { vote ('up', this.parentNode) });
|
|
118
|
+ |
vote_sections[i].children[2].addEventListener ('click', function () { vote ('down', this.parentNode) });
|
|
119
|
+ |
}
|
115
|
120
|
|
|
116
|
121
|
|
// Bind onkeydown()/onkeyup() event to keys
|
117
|
122
|
|
document.onkeydown = document.onkeyup = function(e) {
|