2

The standard collapsable HTML5 semantic markup <detail> and <summary> work finally flawlessly in FireFox and Chrome, but not in IE and Edge.

Any ideas how to fix this with (a tiny bit of light code) for IE and Edge?

jQuery 3.x is already loaded in my site so if the fix involves using something from that library to strealine the transition (linear or easing) then that would be great. Also nice would be a userselectable default setting to toggle weather the detail should appear "open" or "closed" at pageload. Thanks!

if (/MSIE 10/i.test(navigator.userAgent) || /MSIE 9/i.test(navigator.userAgent) || /rv:11.0/i.test(navigator.userAgent) || /Edge/i.test(navigator.userAgent)){

$(function(){
 $('summary').click(function(){
  $(this).parent().find('article').slideToggle();
 });
});

}
details{
}
summary{
 cursor: pointer; cursor: hand;
 background-color: blue;
 display: block;
 padding: 10px;
 margin: 0 0 20px 0;
}

summary:after {
  background: yellow;
  content: "+";
  float: left;
  margin: 0 5px 0 0;
  padding: 0;
  text-align: center;
  width: 20px;
}
details[open] summary:after {
 content: "-";
}

details summary::-webkit-details-marker {
 display:none; /* hides the standard > sign */
}
summary:focus {outline:0 !important;} /* hides the blue borderin chrome, once clicked */

@keyframes slideDown {
    0% {
        opacity: 0;
        height: 0;
    }
    100% {
        opacity: 1;
        height: 100%;
    }
}

details[open] {
    animation-name: slideDown;
    animation-duration: 500ms;
    animation-timing-function:lineair;
}

article {display: block;} 
@media screen and (max-width: 767px) { 
    article {display:none;} 
}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<details>
<summary>Testing Testing</summary>
<article class="project">
<p>Ventilatie is noodzakelijk voor een gezond binnenklimaat in ruimten waar mensen verblijven en gebeurt door koolzuurgas, vocht en verontreiniging af te voeren en verse lucht aan te voeren. De luchtverontreiniging kan van verschillende aard zijn (bijvoorbeeld sigarettenrook, bacteriën en schimmelsporen, chemische stoffen, stof, geurstoffen). De noodzakelijke hoeveelheid te verversen lucht (debiet) hangt af van de productie van vocht, koolstofdioxide (CO²) en verontreiniging en de aard van de verontreiniging, en van het aantal mensen die in die ruimten verblijven. Spuiventilatie of luchten is niet hetzelfde als de hier genoemde ventilatie, maar heeft ten doel in korte tijd sterk verontreinigde binnenlucht af te voeren of te spuien. Dit kan worden bereikt door ramen en/of deuren tegen elkaar open te zetten. Bij de meeste woningen gebeurt de ventilatie ongecontroleerd: doordat de wind in kieren en spleten waait, ververst de lucht. Dit zorgt in vele gevallen voor overbodige ventilatie, een onaangenaam binnenklimaat en dus ook voor warmteverliezen. Men kan dit verminderen door tijdens het bouwen en onderhoud aandacht te besteden aan luchtdichtheid.  Meestal wordt daarvoor een dampscherm geplaatst tegen de isolatie. Men dient rekening te houden met de vochthuishouding: als de warme vochtige binnenlucht kan doordringen tot in de isolatie zal deze lucht afkoelen naarmate de buitenmuur benaderd wordt, waardoor er condensatie kan optreden die de isolatiewaarde weer doet verminderen en is een dampdichte laag nodig om het damptransport te verminderen. Om dit makkelijker te onthouden zijn de dampremmende folies meestal rood (warm; binnenkant) en de damp-open folies blauw.</p>
</article>
</details>
Sam
  • 15,254
  • 25
  • 90
  • 145

2 Answers2

1

The open attribute is simply not supported in those browsers, neither are some of the semantic tags (e.g. <summary>). I think this is why your css rules are not being applied.

https://www.w3schools.com/tags/att_details_open.asp https://www.w3schools.com/tags/tag_summary.asp

Maybe change the jQuery to toggle a class - like in the good old days :)

ne1410s
  • 6,864
  • 6
  • 55
  • 61
  • Thanks and +1 for technology that worked well like in the the old days! Do you have suggesions how to? Please see my comments underneath the other answer mate. +1 – Sam May 05 '17 at 15:29
1

In your example, this should do the job. This makes it so it expands the article specificly, instead of the the container (details)

$(function(){
    $('summary').click(function(){
        $(this).parent().find('article').slideToggle();
    });
});

edit: In the comments, OP asked for managing the initial state of the article with css, with a different behaviour on mobile and desktop. The following CSS would make the detail article hidden by default on mobile (generally considered <768px width) and expanded on everything bigger.

article {display: block;} 
@media screen and (max-width: 767px) { 
    article {display:none;} 
}

if you would want the article to also be hidden on tablets (which are in practice a very small minority in users, so not that big of a concern usually), you would change the 767px to somewhere in the 900-1000 range, depending on your choice. Bootstrap uses 991px for example.

Kevin Sijbers
  • 814
  • 7
  • 19
  • Awesome +1 @Kevin Sijbers :D Quick comment: with your script added, it works perfectly in Edge (nice sliding transition!) but its now broken in FF 50 and Chrome 58! – Sam May 05 '17 at 14:08
  • Sadly that's the annoying reality of newer features like this. Your options are to either not use the details/summary types, or get a detection for IE/Edge and only add the event when that check passes. Many solutions to that second approach, none of them pretty http://stackoverflow.com/questions/33990206/how-to-detect-ie-edge-using-javascript http://stackoverflow.com/questions/31757852/how-can-i-detect-internet-explorer-ie-and-microsoft-edge-using-javascript – Kevin Sijbers May 05 '17 at 14:13
  • Thanks! Please see updated script! It does not work as it is in my Edge... – Sam May 05 '17 at 14:21
  • You probably don't need the 12 in the edge detection, /Edge/./i.test or navigator.userAgent.indexOf("Edge") should work. Current version for me is Edge/14 for example – Kevin Sijbers May 05 '17 at 15:00
  • Awesome mate thanks! Now it works in Edge as well as chrome and FF! Please add a toggle for default state "open" or "close" sothat I can change that later. – Sam May 05 '17 at 15:27
  • PS. Why does the script not work with FF and Chrome and only works in Edge?? If it can work in FF and Chrome then lets skip the entire html5 and just let the script to the beautiful transision for all browsers without exceptions!! – Sam May 05 '17 at 15:28
  • Your default state is display:none on the article element for closed, and display:block for open ;) Thats all SlideToggle does. Though if you want it fancier, you could make it ALSO toggle a data-attribute, that's a little overkill though – Kevin Sijbers May 05 '17 at 22:42
  • Hi i've tried everything but the open state at pageload doesnt work. What in my code (see question) needs be changed to allow in the CSS the option to have it shown in the open state? I want to use it in a way that for desktop browsing the css makes it always show, and in mobile browsing it should be hidden default. Thanks in advance! and meanwhile i accept your question as the one :-) – Sam May 25 '17 at 12:12
  • I've added an example of different default states in the answer, since css in comments gets hard to read (and media queries just dont work) – Kevin Sijbers May 26 '17 at 04:22
  • thanks! but that is exactly what I tried myself but it doesnt work. I also changed the property from width pixes to orientation (as all mobiles are vertical and destkops horizontal but thats not the point here: it doesnt work) What am I doing wrong here? See: https://jsfiddle.net/y3nbwghj/1/ thanks mate! – Sam May 26 '17 at 11:09
  • I cant seem to find a fix for this. Chrome just loads it hidden, no matter what css is applied. Is there any specific reason you are using summary/details/article instead of divs? – Kevin Sijbers May 26 '17 at 13:27
  • Welcome to the HTML5 era mate! :-) where semantic new meaningful elemtents such have replaced the old (!and to search engines!) meaningless divs from the past. For our project I cannot afford to go back to the html4
    main article so it must be within the html5 spec details and summary... At least I am happy that I am not so stupid as I though I was when you said : "its easy! just add display: block and or display: none" ;-) Its also a mystery to me...
    – Sam May 26 '17 at 14:40
  • The html5 era, where cross-browser programming is a nightmare once again. The only other option i can think of, is using javascript to assign the open attribute to the element if screenwidth > some value. – Kevin Sijbers May 26 '17 at 17:35