/
jquery.lazyloadxt.script.js
59 lines (48 loc) · 1.79 KB
/
jquery.lazyloadxt.script.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
/*! Lazy Load XT v0.8.10 2014-01-07
* http://ressio.github.io/lazy-load-xt
* (C) 2014 RESS.io
* Licensed under MIT */
(function ($, window, document) {
var options = $.lazyLoadXT,
dataLazyTag = options.dataLazyTag || 'data-lazy-tag';
window.L = function (tag) {
document.write('<br ' + dataLazyTag + '="' + (tag || 'img') + '" ');
};
window.Lb = function (tag) {
document.write('<span ' + dataLazyTag + '="' + (tag || 'video') + '" ');
};
window.Le = function () {
document.write('</span>');
};
$(document).ready(function () {
var srcAttr = options.srcAttr;
if ($.isFunction(srcAttr)) {
srcAttr = 'data-src';
}
$('br[' + dataLazyTag + '],span[' + dataLazyTag + ']').each(function () {
var attrs = this.attributes,
el = document.createElement($(this).attr(dataLazyTag)),
i;
for (i = 0; i < attrs.length; i++) {
var attr = attrs[i];
if (attr.specified) {
var attrName = attr.nodeName,
attrValue = attr.nodeValue;
if (attrName.charAt(0) !== '<') {
if (attrName === 'src') {
el.setAttribute(srcAttr, attrValue);
} else {
el.setAttribute(attrName, attrValue);
}
}
}
}
while (this.hasChildNodes()) {
var child = this.removeChild(this.firstChild);
el.appendChild(child);
}
this.parentNode.replaceChild(el, this);
});
$(window).lazyLoadXT();
});
})(window.jQuery || window.Zepto, window, document);