Problem/Motivation

The checkWidthBreakpoint method was put in place before we started using matchMedia in core. The checkWidthBreakpoint method is an idiosyncratic solution that already has a standard approach.

Proposed resolution

Remove Drupal.checkWidthBreakpoint from core and replace with window.matchMedia

Remaining tasks

Propose an initial patch
Review the attached patch

User interface changes

None

API changes

The Drupal.checkWidthBreakpoint method will no longer be available. This is a good thing. We don't want contrib to depend on this unneeded method.

Original report by @jessebeach

Comments

nod_’s picture

oh yes please, never got around to getting rid of it.

( edit ) and guess which module we had to introduce it for initially? Overlay :þ

mile23’s picture

Issue summary: View changes
Issue tags: +@deprecated

Drupal.checkWidthBreakpoint is marked as @deprecated, but doesn't specify a version for removal.

At this point in the release cycle for PHP code we'd say D9.0.0, but I'm not sure about JS.

jesse.voogt’s picture

Hi,

It appears that Drupal 8 is supposed to support IE9, according to https://www.drupal.org/node/61509 , and it doesn't look like matchMedia is supported by IE9 according to http://caniuse.com/#feat=matchmedia. I haven't personally used the deprecated Drupal.checkWidthBreakpoint method, but I suggest if it is an alternative for window.matchMedia that we wait until at least D9.

droplet’s picture

@jesse.voogt

we have matchmedia polyfill in core.

cdog’s picture

Status: Active » Needs review
StatusFileSize
new1.18 KB

The attached patch replaces all occurences of the Drupal.checkWidthBreakpoint method with window.matchMedia. To look for files where it's being used you can use the following grep command:

$ grep -iRl "Drupal.checkWidthBreakpoint" .
./core/misc/drupal.js
./core/misc/vertical-tabs.js
./core/modules/ckeditor/js/ckeditor.js

The patch doesn't remove yet the Drupal.checkWidthBreakpoint function definition from ./core/misc/drupal.js as it's marked as deprecated.

cdog’s picture

Issue summary: View changes
nod_’s picture

You can remove the function from drupal.js, it doesn't exist in D7 so it was to make sure people didn't start using it in D8.

for vertical tabs the backbone folks are ok with us copying the responsive vtabs they got so it'll go away eventually.

nod_’s picture

Status: Needs review » Needs work
cdog’s picture

Status: Needs work » Needs review
StatusFileSize
new2 KB

@nod_ ok, thanks for your feedback. The new patch removes Drupal.checkWidthBreakpoint entirely from core. Regarding vertical tabs, I'm not aware about those changes. Can you point me in the right direction if there's anything more that should be done related to this issue?

nod_’s picture

Status: Needs review » Reviewed & tested by the community

This works fine, vtabs still work as expected. Hope it makes it, wouldn't want to ship D8 with new-already-deprecated APIs.

Status: Reviewed & tested by the community » Needs work

The last submitted patch, 9: drupal-matchMedia-2118663-9.patch, failed testing.

Status: Needs work » Needs review
nod_’s picture

Status: Needs review » Reviewed & tested by the community

Status: Reviewed & tested by the community » Needs work

The last submitted patch, 9: drupal-matchMedia-2118663-9.patch, failed testing.

cdog’s picture

@nod_ failed tests doesn't seem related to the patch itself. Is this a normal behavior? Should we queue it for re-testing and update the status every time this happens?

nod_’s picture

Status: Needs work » Reviewed & tested by the community

Probably some testbot snafu.

This is a JS-only patch so testbot has nothing to say that's relevant here.

droplet’s picture

Status: Reviewed & tested by the community » Needs work

I set it back to "Needs work" anyway, it would need to patch core.libraries.yml and add matchmedia polyfill as dependencies

cdog’s picture

Status: Needs work » Needs review
StatusFileSize
new2.98 KB

@nod_, @droplet thanks for helping out!

cdog’s picture

StatusFileSize
new2.83 KB

Oops, core/misc/drupal.js doesn't require the matchmedia dependency.

nod_’s picture

Status: Needs review » Reviewed & tested by the community

Good call :) forgot that it was even a polyfill.

Old browsers…

alexpott’s picture

Status: Reviewed & tested by the community » Needs work

Needs a reroll :(

nod_’s picture

on it.

nod_’s picture

Status: Needs work » Needs review
StatusFileSize
new2.8 KB
nod_’s picture

Status: Needs review » Reviewed & tested by the community

looks green enough

alexpott’s picture

How green is green enough for a JS patch?

alexpott’s picture

Status: Reviewed & tested by the community » Fixed

Given the low number of usages, the odd functionality and the fact it has been deprecated for ages... Committed c8f4690 and pushed to 8.0.x. Thanks!

  • alexpott committed c8f4690 on 8.0.x
    Issue #2118663 by cdog, nod_: Remove the Drupal.checkWidthBreakpoint...

Status: Fixed » Needs work

The last submitted patch, 23: core-js-matchmedia-2118663-23.patch, failed testing.

nod_’s picture

Status: Needs work » Fixed
cdog’s picture

Woohoo! We made it! This is my first contribution to Drupal core and I really enjoyed it, thanks everyone! :D

Status: Fixed » Closed (fixed)

Automatically closed - issue fixed for 2 weeks with no activity.