high res queries / window.matchMedia issue
-
Hi Kyle,
Regarding 1.3
So I have noticed that the actual high resolution queries in it’s current form didn’t work on iOSsafari and chrome.
After digging into subject it appeared to me that window.matchMedia wrongly evaluates query
data-media="(min-width: 920px) and (-webkit-min-device-pixel-ratio: 1.5),(min-resolution: 144dpi),(min-resolution: 1.5dppx)"
to true when screen width is smaller that query.https://developer.mozilla.org/en-US/docs/Web/CSS/resolution
Then it appeared that there are some inconsistencies in implementation of JS media queries between browsers. So to make the query work we would have to have query like that:
data-media="(min-width: 786px) and (min-resolution: 144dpi),(min-width: 786px) and (-webkit-min-device-pixel-ratio: 1.5)
I have modified class-view-picturefill function get_media_query to represent this syntax. Please bear in mind that I am nowhere close to being php haxor so Ithink you might like to take look at it.
public function get_media_query($image_size){ if('@2x' === substr($image_size, -3)){ $width = substr($image_size, 0, -3) === $this->image_attributes['size'][1] ? $this->image_attributes['width'] : $this->image_attachment_data[substr($image_size, 0, -3)][1]; $breakpoint = 0 === array_search(substr($image_size, 0, -3), $this->image_sizes) ? 1 : $width + 20; }else{ $width = $image_size === $this->image_attributes['size'][1] ? $this->image_attributes['width'] : $this->image_attachment_data[$image_size][1]; $breakpoint = 0 === array_search($image_size, $this->image_sizes) ? 1 : $width + 20; } $current_width = apply_filters('picturefill_wp_media_query_breakpoint', $breakpoint, $image_size, $width, $this->image_attributes, $this->image_attachment_data, $this->image_sizes) ; //firefox IE Opera $current_resolution_1 = " and (min-resolution: 144dpi)"; $current_resolution_1 = apply_filters('picturefill_wp_media_query_resolution_query', $current_resolution_1, $image_size); //firefox IE Opera // we do not need this query as (by w3) "1dppx is equivalent to 96dpi" $current_resolution_3 = " and (min-resolution: 1.5dppx)"; $current_resolution_3 = apply_filters('picturefill_wp_media_query_resolution_query', $current_resolution_3, $image_size); //Chorme Safari iOS Android $current_resolution_2 = " and (-webkit-min-device-pixel-ratio: 1.5)"; $current_resolution_2 = apply_filters('picturefill_wp_media_query_resolution_query', $current_resolution_2, $image_size); $resolution_query = '@2x' === substr($image_size, -3) ? ' and (-webkit-min-device-pixel-ratio: 1.5),(min-resolution: 144dpi),(min-resolution: 1.5dppx)' : ''; if ('@2x' === substr($image_size, -3)){ $end_query = '(min-width: ' . $current_width . 'px)' . $current_resolution_1 . ',(min-width: ' . $current_width . 'px)' . $current_resolution_2; return $end_query; } else{ return '(min-width: ' . apply_filters('picturefill_wp_media_query_breakpoint', $breakpoint, $image_size, $width, $this->image_attributes, $this->image_attachment_data, $this->image_sizes) . 'px)' . apply_filters('picturefill_wp_media_query_resolution_query', $resolution_query, $image_size); } }
Regards,
Filip
- The topic ‘high res queries / window.matchMedia issue’ is closed to new replies.