PluginProbe
Elementor Website Builder – more than just a page builder / 3.0.1
Elementor Website Builder – more than just a page builder v3.0.1
4.3.0-beta2 4.3.0-beta1 4.2.4 4.2.3 4.2.2 4.2.1 4.2.0 4.1.5 4.2.0-beta2 4.2.0-dev2 4.2.0-beta1 4.1.4 4.1.3 4.1.2 4.1.1 4.1.0 4.1.0-beta3 4.1.0-dev3 4.0.9 4.1.0-beta2 4.1.0-dev2 4.0.8 4.1.0-beta1 4.1.0-dev1 4.0.7 All 451 releases
← All changes | includes/stylesheet.php +35 -7 4.2.33.0.1 View file →
@@ -137,9 +137,9 @@
137 137 * @param array $query Optional. Media query. Default is `null`.
138 138 *
139 139 * @return Stylesheet The current stylesheet class instance.
140 140 */
141 - public function add_rules( $selector, $style_rules = null, ?array $query = null ) {
141 + public function add_rules( $selector, $style_rules = null, array $query = null ) {
142 142 $query_hash = 'all';
143 143
144 144 if ( $query ) {
145 145 $query_hash = $this->query_to_hash( $query );
@@ -275,8 +275,36 @@
275 275 return $style_text;
276 276 }
277 277
278 278 /**
279 + * Get device maximum value.
280 + *
281 + * Retrieve the maximum size of any given device.
282 + *
283 + * @since 1.2.0
284 + * @access private
285 + *
286 + * @throws \RangeException If max value for this device is out of range.
287 + *
288 + * @param string $device_name Device name.
289 + *
290 + * @return int
291 + */
292 + private function get_device_max_value( $device_name ) {
293 + $devices_names = array_keys( $this->devices );
294 +
295 + $device_name_index = array_search( $device_name, $devices_names );
296 +
297 + $next_index = $device_name_index + 1;
298 +
299 + if ( $next_index >= count( $devices_names ) ) {
300 + throw new \RangeException( 'Max value for this device is out of range.' );
301 + }
302 +
303 + return $this->devices[ $devices_names[ $next_index ] ] - 1;
304 + }
305 +
306 + /**
279 307 * Query to hash.
280 308 *
281 309 * Turns the media query into a hashed string that represents the query
282 310 * endpoint in the rules list.
@@ -316,15 +344,15 @@
316 344
317 345 $hash = array_filter( explode( '-', $hash ) );
318 346
319 347 foreach ( $hash as $single_query ) {
320 - preg_match( '/(min|max)_(.*)/', $single_query, $query_parts );
348 + $query_parts = explode( '_', $single_query );
321 349
322 - $end_point = $query_parts[1];
350 + $end_point = $query_parts[0];
323 351
324 - $device_name = $query_parts[2];
352 + $device_name = $query_parts[1];
325 353
326 - $query[ $end_point ] = 'max' === $end_point ? $this->devices[ $device_name ] : Plugin::$instance->breakpoints->get_device_min_breakpoint( $device_name );
354 + $query[ $end_point ] = 'max' === $end_point ? $this->get_device_max_value( $device_name ) : $this->devices[ $device_name ];
327 355 }
328 356
329 357 return $query;
330 358 }
@@ -387,12 +415,12 @@
387 415
388 416 /**
389 417 * Get query hash style format.
390 418 *
391 - * Retrieve formatted media query rule with the endpoint width settings.
419 + * Retrieve formated media query rule with the endpoint width settings.
392 420 *
393 421 * The method returns the CSS `@media` rule and supported viewport width in
394 - * pixels. It can also handle multiple width endpoints.
422 + * pixels. It can also handel multiple width endpoints.
395 423 *
396 424 * @since 1.2.0
397 425 * @access private
398 426 *