forked from aFarkas/lazysizes
-
Notifications
You must be signed in to change notification settings - Fork 0
/
ls.print.js
36 lines (33 loc) · 1.01 KB
/
ls.print.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
/*
This lazySizes extension adds better support for print.
In case the user starts to print lazysizes will load all images.
*/
(function(window){
/*jshint eqnull:true */
'use strict';
var config, elements, onprint, printMedia;
// see also: http://tjvantoll.com/2012/06/15/detecting-print-requests-with-javascript/
if(window.addEventListener){
config = (window.lazySizes && lazySizes.cfg) || window.lazySizesConfig || {};
elements = config.lazyClass || 'lazyload';
onprint = function(){
var i, len;
if(typeof elements == 'string'){
elements = document.getElementsByClassName(elements);
}
if(window.lazySizes){
for(i = 0, len = elements.length; i < len; i++){
lazySizes.loader.unveil(elements[i]);
}
}
};
addEventListener('beforeprint', onprint, false);
if(!('onbeforeprint' in window) && window.matchMedia && (printMedia = matchMedia('print')) && printMedia.addListener){
printMedia.addListener(function(){
if(printMedia.matches){
onprint();
}
});
}
}
})(window);