Skip to content

Commit

Permalink
Move avatars javascript to external file for better development exper…
Browse files Browse the repository at this point in the history
…ience
  • Loading branch information
Munter committed May 21, 2020
1 parent 10bb5d4 commit a84ad17
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 32 deletions.
33 changes: 1 addition & 32 deletions docs/_includes/supporters.md
Original file line number Diff line number Diff line change
Expand Up @@ -34,35 +34,4 @@ Find Mocha helpful? Become a [backer](https://opencollective.com/mochajs#support
{%- endfor -%}
</ul>

<script>
(function() {
'use strict';

var imageLists = document.querySelectorAll('.image-list');

function getListItem(img) {
var parent = img.parentNode;
while (parent && parent.nodeName !== 'LI') {
parent = parent.parentNode;
}

return parent;
}

function onloadHandler() {
getListItem(this).classList.add('is-loaded');
}

Array.prototype.forEach.call(imageLists, function(imageList) {
var images = imageList.querySelectorAll('img');

for (var i = 0; i < images.length; i += 1) {
if (!images[i].complete) {
getListItem(images[i]).classList.add('faded-image');
images[i].onload = onloadHandler;
images[i].onerror = onloadHandler;
}
}
});
})();
</script>
<script src="/js/avatars.js"></script>
30 changes: 30 additions & 0 deletions docs/js/avatars.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
(function() {
'use strict';

var imageLists = document.querySelectorAll('.image-list');

function getListItem(img) {
var parent = img.parentNode;
while (parent && parent.nodeName !== 'LI') {
parent = parent.parentNode;
}

return parent;
}

function onloadHandler() {
getListItem(this).classList.add('is-loaded');
}

Array.prototype.forEach.call(imageLists, function(imageList) {
var images = imageList.querySelectorAll('img');

for (var i = 0; i < images.length; i += 1) {
if (!images[i].complete) {
getListItem(images[i]).classList.add('faded-image');
images[i].onload = onloadHandler;
images[i].onerror = onloadHandler;
}
}
});
})();

0 comments on commit a84ad17

Please sign in to comment.