forked from aFarkas/lazysizes
-
Notifications
You must be signed in to change notification settings - Fork 0
/
test-helper.js
62 lines (56 loc) · 1.55 KB
/
test-helper.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
60
61
62
(function(){
'use strict';
var source = document.createElement('source');
var requestAnimationFrame = window.requestAnimationFrame || setTimeout;
window.createBeforeEach = function(params){
params = $.param(params || {});
return function(){
var that = this;
this.promise = $.Deferred();
this.$iframe = $('#test-iframe');
this.$iframe.css({width: 300, height: 300});
this.$iframe.one('load', function(){
that.promise.resolveWith(that, [that.$iframe.prop('contentWindow').jQuery, that.$iframe.prop('contentWindow')]);
});
this.$iframe.prop('src', 'test-files/content-file.html?'+params);
};
};
window.createPicture = function($, srces){
var $picture = $('<picture />');
$.each(srces, function(i, attrs){
var $elem;
if(i >= srces.length -1){
$elem = 'img';
} else {
$elem = 'source';
}
$elem = $('<' + $elem + '/>');
$picture.append($elem);
$elem.attr(attrs);
});
return $picture;
};
window.cleanUpDensity = function(ar){
(ar || []).forEach(function(obj){
if(obj.d){
delete obj.d;
}
if(obj.cached){
delete obj.cached;
}
});
return ar;
};
window.isTrident = /rident/.test(navigator.userAgent);
window.bustedSrcset = (('srcset' in document.createElement('img')) && !('sizes' in document.createElement('img')));
window.supportsPicture = !window.bustedSrcset && window.HTMLPictureElement;
window.afterUnveil = (function(){
return function(fn, delay){
setTimeout(function(){
requestAnimationFrame(function(){
setTimeout(fn,0);
});
}, delay || 9);
};
})();
})();