Closed (outdated)
Project:
Drupal core
Version:
7.x-dev
Component:
system.module
Priority:
Minor
Category:
Task
Assigned:
Issue tags:
Reporter:
Created:
17 Nov 2008 at 02:07 UTC
Updated:
10 Dec 2015 at 16:12 UTC
Jump to comment: Most recent, Most recent file
Comments
Comment #1
dave reidPatch to remove the no-js style ready for review.
Comment #2
dave reidThere'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.
Comment #3
dave reidAnd 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:
Comment #5
dave reidRe-rolled to HEAD.
Comment #6
moshe weitzman commentedWorks for me. Nice little cleanup. Thanks.
Comment #7
dries commentedIt is not clear why we needed to introduce js-show? Care to explain?
Comment #8
dave reidIt'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.
Comment #9
moshe weitzman commentedFor 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.
Comment #10
dmitrig01 commentedWhy not do this for js-show
Comment #11
dave reidI'm not sure how that would work with an element that had something like:
<div class="js-show" style="display: inline;">...</div>Comment #12
dave reidComment #13
catchComment #15
dave reidHEAD testing failure. Resetting.
Comment #16
cburschka1.) 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?
Comment #17
dawehnerhere is a fast rerole.
not sure about the inline stuff/css3, but what about creating a inline class?
Comment #18
dawehnerneeds review...
Comment #19
cburschkaThose 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.
Comment #21
aspilicious commenteddoesn't exist anymore in system.css
Comment #22
dave reidWhat about .js-show?
Comment #23
aspilicious commentedThere aren't any js elements left...
is the only js thing you can find
Comment #24
dave reidsystem.behaviors.css:
This still needs a .js-show opposite. Clarifying title since part of the issue was taken care of.
Comment #25
aspilicious commentedOw fok srry opened wrong file (system.css), I'm so stupid!
Thnx dave... :(
Comment #26
aspilicious commentedCan't we do something easy as like dimitri said?
Comment #27
dave reidThat wouldn't work because the point would to be to hide the element if JavaScript is disabled. Also see my #11.
Comment #28
robloachOh, I've been trying to get this one in for a while.
Comment #29
dave reidBumping to D8.
Comment #30
robloachAdding to my ever growing things of things I'd like to eventually look at.
Comment #31
robloachThere we go!
Comment #32
robloachLooks like
system.jsis not included everywhere, so this should live indrupal.jsinstead.Comment #33
ohnobinki commented+1
Comment #34
mrfelton commentedThe title of this issue is "Add js-show CSS class for hiding elements when JavaScript is disabled". Yet what this patch does is to allow you to :
* Use the class 'js-hide' to hide an element if JavaScript is enabled.
* Use the class 'js-show' to show an element only if JavaScript is enabled.
What about hiding an element only if JavaScript is disabled, as per the issue title? For that, wouldn't you need a no-js-hide class, something like:
Comment #35
twod@mrfelton, that's your use case right there. Things with .js-show start out with
display: none;, which JavaScript switches to andisplay: block;style on the element itself, overriding the stylesheet. No script, no unhiding.Comment #36
ksenzeeThis looks correct to me.
I'm actually tempted to move it to a bug report, because currently we're showing the line about 'You can insert the delimiter "<!--break-->" (without the quotes) to fine-tune where your post gets split' even when JS is enabled, which is incorrect and confusing.
Comment #37
tim.plunkettAren't we doing
$(context).find('.js-show').show();now?Comment #38
nod_indeed.
Just to play the devil's advocate: a style tag with
.js-show {display:none;}wrapped in a noscript tag will work too (it's valid HTML). Not suggesting we do that, just bringing it up.Comment #39
ksenzeeHm. Wrapping
.js-show {display:none;}in a noscript tag would be a good approach. With the existing patch you have the slight possibility of users seeing the js-only content pop into place after the rest of the page structure is there already. It also adds yet more JS to Drupal.behaviors, and goodness knows we have enough already. The noscript tag avoids both those problems.So it sounds like a fine plan—except that I have no idea how to implement it sanely. All I can think of is adding another flag to the $options parameter in drupal_add_css(), which does not really appeal. That's such a complicated function already. Unless someone thinks that's actually a good idea, or has a better one, I'd say we stick with the existing patch.
Comment #40
zhangtaihao commentedNot that this is any more sane, but I presume
drupal_add_html_head()has been looked at and specifically ignored?Comment #41
robloachI'd rather not have this stuff presented inline within the HTML of the document. We would benefit of aggregation and performance if this was in .css and .js files.
Comment #42
tstoecklerThis is now being handled as part of #1848064: Allow to filter modules by arbitrary search strings on the Modules page. Since this has been inactive for quite a while, marking this as duplicate.
Comment #43
dave reidI hate when things get closed and fixed in Drupal 8 but never considered for backport to D7 which is where I want to be using this functionality *now*.
Comment #44
ksenzeeHere's a reroll for the js-show part, which is still sensible for D7.
Comment #47
dave reidRe-rolled for the D8-non-js solution.