-
Notifications
You must be signed in to change notification settings - Fork 4
/
responsive-image.js
80 lines (74 loc) · 2.38 KB
/
responsive-image.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
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
import ResponsiveImageService from 'ember-responsive-image/services/responsive-image';
import { assert } from '@ember/debug';
/**
* Service class to provides images generated by the responsive images package
* with additional inline support
*
* @class ResponsiveImageService
* @namespace Services
* @module responsive-image
* @public
*/
export default ResponsiveImageService.extend({
/**
* returns the inline image data as base64 encoded string
*
* @method getInlineImage
* @param {String} imageName The origin name of the Image
* @returns {String} the base64 encoded string
* @public
*/
getInlineImage(imageName) {
assert(`There is no inline image data for image ${imageName}`, this.getLqip(imageName).hasOwnProperty('image'));
return this.getLqip(imageName).image;
},
/**
* returns whether there's an inline image for given image name
*
* @method hasInlineImage
* @param {String} imageName The origin name of the Image
* @returns bool true if there's an inline image
* @public
*/
hasInlineImage(imageName) {
let meta = this.get('meta');
return !!(meta[imageName] && meta[imageName].lqip && meta[imageName].lqip.image);
},
/**
* returns whether this image has LQIP
*
* @method hasLqip
* @param {String} imageName The origin name of the Image
* @returns bool true if LQIP is enabled for this image
* @public
*/
hasLqip(imageName) {
let meta = this.get('meta');
return !!(meta[imageName] && meta[imageName].lqip);
},
/**
* returns the LQIP width for this image
*
* @method getLqipWidth
* @param {String} imageName The origin name of the Image
* @returns bool true if LQIP is enabled for this image
* @public
*/
getLqipWidth(imageName) {
assert(`There is no inline image data for image ${imageName}`, this.getLqip(imageName).hasOwnProperty('width'));
return this.getLqip(imageName).width;
},
/**
* returns LQIP part from meta for this image
*
* @method getLqip
* @param {String} imageName The origin name of the Image
* @returns {*} the lqip part of the meta infos
* @private
*/
getLqip(imageName) {
assert(`There is no data for image ${imageName}`, this.get('meta').hasOwnProperty(imageName));
assert(`There is no lqip data for image ${imageName}`, this.get('meta')[imageName].hasOwnProperty('lqip'));
return this.get('meta')[imageName].lqip;
}
});