Skip to content

Commit 3081449

Browse files
author
Martii
committed
Move lazyIconScript to standard JavaScript
**NOTE** Since *jquery*s latest release has many breaking changes normalizing to standard ES5 but a bit of CSS3 transitions. Applies to OpenUserJS#904 ... post trial change for *jquery* incompatibilities.
1 parent 7a25e7e commit 3081449

File tree

2 files changed

+75
-21
lines changed

2 files changed

+75
-21
lines changed

public/css/common.css

+17
Original file line numberDiff line numberDiff line change
@@ -352,3 +352,20 @@ ul.flaggedList {
352352
border-radius: 0 3px 3px 0;
353353
text-shadow: 0 1px #045481;
354354
}
355+
356+
357+
.translucent-icon {
358+
opacity: 0;
359+
}
360+
361+
.hide-icon {
362+
display: none;
363+
}
364+
365+
.opaque-icon {
366+
opacity: 1;
367+
}
368+
369+
.fade-icon {
370+
transition: opacity 0.33s ease-in-out;
371+
}
+58-21
Original file line numberDiff line numberDiff line change
@@ -1,27 +1,64 @@
11
<script type="text/javascript">
22
(function () {
3+
'use strict';
34

4-
$(window).load(function () {
5-
window.setTimeout(function () {
6-
$('[data-icon-src]').each(function () {
7-
var container = $(this);
8-
var size = container.data('icon-size');
9-
var img = new Image();
10-
11-
if (size) {
12-
img.width = size;
13-
img.height = size;
14-
}
15-
16-
$(img).load(function () {
17-
var that = $(this).hide();
18-
19-
container.empty().append(that);
20-
that.fadeIn();
21-
}).attr('src', container.data('icon-src'));
22-
});
23-
}, 13);
24-
});
5+
function onShow(aImg) {
6+
aImg.classList.remove('translucent-icon');
7+
aImg.classList.add('opaque-icon');
8+
}
9+
10+
function onError(aEv) {
11+
var img = aEv.target;
12+
var container = img.parentNode;
13+
14+
container.removeChild(img);
15+
}
16+
17+
function onLoad(aEv) {
18+
var img = aEv.target;
19+
var container = img.parentNode;
20+
21+
var node = container.querySelector('i');
22+
23+
container.removeChild(node);
24+
img.classList.remove('hide-icon');
25+
26+
setTimeout(onShow, 250, img);
27+
}
28+
29+
function onTimeout() {
30+
var nodes = document.querySelectorAll('[data-icon-src]');
31+
var i = null;
32+
var container = null;
33+
var dataIconSrc = null;
34+
var node = null;
35+
var img = null;
36+
37+
for (i = 0; container = nodes[i]; i++) {
38+
dataIconSrc = container.getAttribute('data-icon-src');
39+
40+
node = container.querySelector('i');
41+
42+
img = new Image();
43+
44+
img.addEventListener('load', onLoad);
45+
img.addEventListener('error', onError);
46+
47+
img.classList.add('hide-icon');
48+
img.classList.add('fade-icon');
49+
img.classList.add('translucent-icon');
50+
51+
img.src = dataIconSrc;
52+
53+
container.appendChild(img);
54+
}
55+
}
56+
57+
function onDOMContentLoaded(aEv) {
58+
window.setTimeout(onTimeout, 13);
59+
}
60+
61+
document.addEventListener('DOMContentLoaded', onDOMContentLoaded);
2562

2663
})();
2764
</script>

0 commit comments

Comments
 (0)