35 lines
1.1 KiB
JavaScript
35 lines
1.1 KiB
JavaScript
/**
|
|
* Build lazy-image attributes for dynamically rendered AKSRT markup.
|
|
* Zibll owns the lazySizes runtime; this file only provides the shared bridge.
|
|
*/
|
|
(function (window) {
|
|
'use strict';
|
|
|
|
function escapeAttribute(value) {
|
|
return String(value == null ? '' : value)
|
|
.replace(/&/g, '&')
|
|
.replace(/"/g, '"')
|
|
.replace(/</g, '<')
|
|
.replace(/>/g, '>');
|
|
}
|
|
|
|
window.aksrtGetLazyImageAttr = function (key, src, className, size) {
|
|
var config = window.aksrtData || {};
|
|
var scopes = config.lazyScopes || {};
|
|
var classes = String(className || '').trim();
|
|
var realSrc = escapeAttribute(src);
|
|
|
|
if (!src || scopes[key] === false) {
|
|
return ' class="' + escapeAttribute(classes) + '" src="' + realSrc + '"';
|
|
}
|
|
|
|
var thumbs = config.lazyThumbs || {};
|
|
var placeholder = key === 'lazy_avatar'
|
|
? (config.lazyAvatar || thumbs.sm || '')
|
|
: (thumbs[size || 'default'] || thumbs.default || '');
|
|
|
|
return ' class="lazyload ' + escapeAttribute(classes) + '" src="' +
|
|
escapeAttribute(placeholder) + '" data-src="' + realSrc + '"';
|
|
};
|
|
})(window);
|