Duplicate system.css classes: no-js and js-hide, add js-show and .hide

Dave Reid - November 17, 2008 - 02:07
Project:Drupal
Version:7.x-dev
Component:system.module
Category:task
Priority:minor
Assigned:Dave Reid
Status:needs work
Issue tags:CSS, JavaScript, Quick fix
Description

Right now we currently have two different CSS styles in modules/system/system.css to hide elements if JavaScript is enabled: no-js and js-hide:

html.js .no-js {
  display: none;
}

/*
** For anything you want to hide on page load when JS is enabled, so
** that you can use the JS to control visibility and avoid flicker.
*/
html.js .js-hide {
  display: none;
}

I think the .js-hide is a better description and easier to understand, so I propose that we remove the .no-js style. It's also too bad we don't have a way to do a 'js-show' class...

#1

Dave Reid - November 17, 2008 - 02:08
Status:active» needs review

Patch to remove the no-js style ready for review.

AttachmentSize
335185-remove-no-js-css-D7.patch 1.67 KB
Testbed results
335185-remove-no-js-css-D7.patchfailedFailed: 10267 passes, 1 fail, 0 exceptions Detailed results

#2

Dave Reid - November 17, 2008 - 02:52
Title:Duplicate system.css classes: no-js and js-hide» Duplicate system.css classes: no-js and js-hide, add general .hide class

There's also no good way just to use display: none on something I want hidden. Quick addition to #1 adds the class .hide in addition to .js-hide.

AttachmentSize
335185-remove-no-js-css-D7.patch 1.92 KB
Testbed results
335185-remove-no-js-css-D7.patchfailedFailed: Failed to install HEAD. Detailed results

#3

Dave Reid - November 17, 2008 - 03:05
Title:Duplicate system.css classes: no-js and js-hide, add general .hide class» Duplicate system.css classes: no-js and js-hide, add js-show and .hide

And a final revision that adds a 'js-show' that will hide items if JavaScript is disabled. Too bad CSS3 isn't widely adopted enough to just use:

html:not(.js) .js-show {
  display: none;
}

AttachmentSize
335185-remove-no-js-css-D7.patch 2.62 KB
Testbed results
335185-remove-no-js-css-D7.patchfailedFailed: Failed to apply patch. Detailed results

#4

System Message - November 23, 2008 - 03:20
Status:needs review» needs work

The last submitted patch failed testing.

#5

Dave Reid - November 23, 2008 - 05:02
Status:needs work» needs review

Re-rolled to HEAD.

AttachmentSize
335185-remove-no-js-css-D7.patch 2.67 KB
Testbed results
335185-remove-no-js-css-D7.patchfailedFailed: 9172 passes, 3 fails, 3 exceptions a href=http://testing.drupal.org/pifr/file/1/335185-remove-no-js-css-D7_2.patchDetailed results/a

#6

moshe weitzman - November 24, 2008 - 02:45
Status:needs review» reviewed & tested by the community

Works for me. Nice little cleanup. Thanks.

#7

Dries - November 24, 2008 - 05:59

It is not clear why we needed to introduce js-show? Care to explain?

#8

Dave Reid - November 24, 2008 - 17:34
Status:reviewed & tested by the community» needs review

It's provided to show an element if JavaScript is enabled, as an opposite to js-hide, which hides elements if JavaScript is enabled. I've improved the documentation for it.

AttachmentSize
335185-remove-no-js-css-D7.patch 3.03 KB
Testbed results
335185-remove-no-js-css-D7.patchfailedFailed: Failed to apply patch. Detailed results

#9

moshe weitzman - November 24, 2008 - 17:54

For example, the progress bar in upload or the teaser checkbox thing could be emitted with js-show class so that they are only visible if user has js enabled.

#10

dmitrig01 - November 25, 2008 - 04:00

Why not do this for js-show

.js-hide { display: none; }
html.js .js-show { display: block; }

#11

Dave Reid - November 29, 2008 - 01:28

I'm not sure how that would work with an element that had something like:
<div class="js-show" style="display: inline;">...</div>

#12

Dave Reid - January 6, 2009 - 21:40

#13

catch - January 17, 2009 - 20:52
Issue tags:+CSS, +JavaScript

#14

System Message - January 22, 2009 - 08:00
Status:needs review» needs work

The last submitted patch failed testing.

#15

Dave Reid - January 22, 2009 - 17:59
Status:needs work» needs review
Issue tags:+Quick fix

HEAD testing failure. Resetting.

#16

Arancaytar - April 25, 2009 - 21:29
Status:needs review» needs work

1.) Patch doesn't apply to system.js anymore, so a reroll is required.

Additional comments:

2.) The CSS spec tells browsers to ignore selectors it doesn't understand, if I remember correctly. Therefore, even if CSS3 is not widely supported, it may be not be a bad idea to add the html:not(.js) (properly documented, of course) to remove the "flicker" the comment mentions, at least for browsers that do support CSS3.

3.) <div class="js-show" style="display: inline;">...</div>

Shouldn't direct style attributes be avoided in favor of classes anyway?

#17

dereine - April 25, 2009 - 22:46

here is a fast rerole.

not sure about the inline stuff/css3, but what about creating a inline class?

AttachmentSize
335185-remove-no-js-css-D7_4.patch 3.24 KB
Testbed results
335185-remove-no-js-css-D7_4.patchfailedFailed: Failed to apply patch. Detailed results

#18

dereine - April 25, 2009 - 22:46
Status:needs work» needs review

needs review...

#19

Arancaytar - May 21, 2009 - 00:12
Status:needs review» reviewed & tested by the community

Those duplicate asterisks in the comment block are pretty odd. They were already in there though, so let's leave them for another issue to fix.

I'm sceptical as ever about relying on the html.js class to do anything serious (how can you trust the server to accurately tell the client whether the client is executing Javascript at the moment? What if you switch it off or on while browsing?). But as it seems to be done throughout core, we might as well do it here too.

#20

System Message - June 12, 2009 - 19:15
Status:reviewed & tested by the community» needs work

The last submitted patch failed testing.

 
 

Drupal is a registered trademark of Dries Buytaert.