1 | <?php |
||
24 | class LazyLoad extends Widget |
||
25 | { |
||
26 | const JS_ASSET_KEY = 'lazyload.js.register'; |
||
27 | |||
28 | const CSS_ASSET_KEY = 'lazyload.css.register'; |
||
29 | const CSS_ASSET_KEY_PLACEHOLDER = 'lazyload.placeholder.css.register'; |
||
30 | |||
31 | /** |
||
32 | * @var string The path to the image you want to lazy load. |
||
33 | */ |
||
34 | public $src; |
||
35 | |||
36 | /** |
||
37 | * @var string Path for the placeholder image that will be base64 encoded. |
||
38 | * @since 1.0.14 |
||
39 | */ |
||
40 | public $placeholderSrc; |
||
41 | |||
42 | /** |
||
43 | * @var boolean Inline the placeholder source as base64 encoded string |
||
44 | * @since 1.0.14 |
||
45 | */ |
||
46 | public $placeholderAsBase64 = false; |
||
47 | |||
48 | /** |
||
49 | * @var integer The width of the image, this information should be provided in order to display a placeholder. |
||
50 | */ |
||
51 | public $width; |
||
52 | |||
53 | /** |
||
54 | * @var integer The height of the image, this information should be provided in order to display a placeholder. |
||
55 | */ |
||
56 | public $height; |
||
57 | |||
58 | /** |
||
59 | * @var boolean Define whether a full image tag should be return or only the attributes. This can be applied when using the lazy loader in background images. |
||
60 | */ |
||
61 | public $attributesOnly = false; |
||
62 | |||
63 | /** |
||
64 | * @var string Additional classes for the lazy load image. |
||
65 | */ |
||
66 | public $extraClass; |
||
67 | |||
68 | /** |
||
69 | * @var array Options array for the html tag. This array can be used to pass e.g. a `title` or `alt` tag. |
||
70 | * @since 1.6.0 |
||
71 | */ |
||
72 | public $options = []; |
||
73 | |||
74 | /** |
||
75 | * @var array Legacy support for older Browsers (Adds the IntersectionOberserver Polyfill, default: true) |
||
76 | * @since 1.6.0 |
||
77 | */ |
||
78 | public $legacySupport = true; |
||
79 | |||
80 | /** |
||
81 | * @var array Optionally disable the automatic init of the lazyload function so you can override the JS options |
||
82 | * @since 1.6.0 |
||
83 | */ |
||
84 | public $initJs = true; |
||
85 | |||
86 | /** |
||
87 | * @var string The default classes which will be registered. |
||
88 | * @since 1.6.1 |
||
89 | */ |
||
90 | public $defaultCss = '.lazyimage-wrapper { |
||
91 | display: block; |
||
92 | width: 100%; |
||
93 | position: relative; |
||
94 | overflow: hidden; |
||
95 | } |
||
96 | .lazyimage { |
||
97 | position: absolute; |
||
98 | top: 50%; |
||
99 | left: 50%; |
||
100 | bottom: 0; |
||
101 | right: 0; |
||
102 | opacity: 0; |
||
103 | height: 100%; |
||
104 | width: 100%; |
||
105 | -webkit-transition: .5s ease-in-out opacity; |
||
106 | transition: .5s ease-in-out opacity; |
||
107 | -webkit-transform: translate(-50%,-50%); |
||
108 | transform: translate(-50%,-50%); |
||
109 | -o-object-fit: cover; |
||
110 | object-fit: cover; |
||
111 | -o-object-position: center center; |
||
112 | object-position: center center; |
||
113 | z-index: 20; |
||
114 | } |
||
115 | .lazyimage.loaded { |
||
116 | opacity: 1; |
||
117 | } |
||
118 | .lazyimage-placeholder { |
||
119 | display: block; |
||
120 | width: 100%; |
||
121 | height: auto; |
||
122 | background-color: #f0f0f0; |
||
123 | } |
||
124 | .nojs .lazyimage, |
||
125 | .nojs .lazyimage-placeholder, |
||
126 | .no-js .lazyimage, |
||
127 | .no-js .lazyimage-placeholder { |
||
128 | display: none; |
||
129 | }'; |
||
130 | |||
131 | /** |
||
132 | * @inheritdoc |
||
133 | */ |
||
134 | public function init() |
||
155 | |||
156 | /** |
||
157 | * Returns the aspect ration based on height or width. |
||
158 | * |
||
159 | * If no width or height is provided, the default value 56.25 will be returned. |
||
160 | * |
||
161 | * @return float A dot seperated ratio value |
||
162 | * @since 1.6.1 |
||
163 | */ |
||
164 | protected function generateAspectRation() |
||
168 | |||
169 | /** |
||
170 | * @inheritdoc |
||
171 | */ |
||
172 | public function run() |
||
194 | } |
||
195 |
This check marks implicit conversions of arrays to boolean values in a comparison. While in PHP an empty array is considered to be equal (but not identical) to false, this is not always apparent.
Consider making the comparison explicit by using
empty(..)
or! empty(...)
instead.