-
-
Save matatk/c2104358b3365366a5d4 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
h { | |
display: block; | |
} | |
h6, h { | |
font-size: 0.67em; | |
margin: 2.33em 0; | |
} | |
h5, h[level="5"] { | |
font-size: 0.83em; | |
margin: 1.67em 0; | |
} | |
h4, h[level="4"] { | |
font-size: 1em; | |
margin: 1.33em 0; | |
} | |
h3, h[level="3"] { | |
font-size: 1.17em; | |
margin: 1em 0; | |
} | |
h2, h[level="2"] { | |
font-size: 1.5em; | |
margin: 0.83em 0; | |
} | |
h1, h[level="1"] { | |
font-size: 2em; | |
margin: 0.67em 0; | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(function (nodeName, sectionRE) { | |
function defineHeading(node) { | |
// initialize heading level as 1 | |
var level = 1, parent = node; | |
// while parent element exists | |
while (parent = parent.parentElement) { | |
// if parent element is a sectioning element | |
if (sectionRE.test(parent.nodeName)) { | |
// increase heading level | |
++level; | |
} | |
} | |
// IE9-11 DOMSubtreeModified needs a timeout | |
setTimeout(function () { | |
// define heading role | |
node.setAttribute('role', 'heading'); | |
// define heading level | |
node.setAttribute('level', level); | |
node.setAttribute('aria-level', level); | |
}); | |
} | |
function defineHeadings() { | |
Array.prototype.forEach.call(document.getElementsByTagName(nodeName), defineHeading); | |
} | |
// if heading is an unknown element | |
if (document.createElement(nodeName) instanceof HTMLUnknownElement) { | |
defineHeadings(); | |
document.addEventListener('DOMContentLoaded', defineHeadings); | |
document.addEventListener('DOMSubtreeModified', defineHeadings); | |
} | |
})('h', /^(article|aside|nav|section)$/i); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(function (nodeName, sectionRE) { | |
function defineHeading(node) { | |
// initialize heading level as 1 | |
var level = 1, parent = node; | |
// while parent element exists | |
while (parent = parent.parentElement) { | |
// if parent element is a sectioning element | |
if (sectionRE.test(parent.nodeName)) { | |
// increase heading level | |
++level; | |
} | |
} | |
// IE9-11 DOMSubtreeModified needs a timeout | |
setTimeout(function () { | |
// define heading role | |
node.setAttribute('role', 'heading'); | |
// define heading level | |
node.setAttribute('level', level); | |
node.setAttribute('aria-level', level); | |
}); | |
} | |
function defineHeadings() { | |
for (var all = document.getElementsByTagName(nodeName), index = 0; all[index]; ++index) { | |
defineHeading(all[index]); | |
} | |
} | |
// if heading is an unknown element | |
if (document.addEventListener) { | |
if (document.createElement(nodeName) instanceof HTMLUnknownElement) { | |
defineHeadings(); | |
document.addEventListener('DOMContentLoaded', defineHeadings); | |
document.addEventListener('DOMSubtreeModified', defineHeadings); | |
} | |
} | |
// or this is Internet Explorer | |
else { | |
document.createElement(nodeName); | |
document.attachEvent('onreadystatechange', defineHeadings); | |
document.attachEvent('onpropertychange', defineHeadings); | |
} | |
})('h', /^(article|aside|nav|section)$/i); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<!DOCTYPE html> | |
<html lang="en"> | |
<head> | |
<meta charset="UTF-8"> | |
<title>h Demo</title> | |
<script src="h.js"></script> | |
<link rel="stylesheet" href="h.css"> | |
</head> | |
<body unresolved> | |
<h>Ramones: Hey! Ho! Let's Go</h> | |
<div class="excode"> | |
<p><strong>code:</strong></p> | |
<pre><code><h>Ramones: Hey! Ho! Let's Go</h></code></pre> | |
</div> | |
<h>Heading text level 1</h> | |
<section><h>Heading text level 2</h> | |
<section><h>Heading text level 3</h> | |
<section><h>Heading text level 4</h> | |
<section><h>Heading text level 5</h> | |
<section><h>Heading text level 6</h> | |
</section> | |
</section> | |
</section> | |
</section> | |
</section> | |
<div class="excode"> | |
<p><strong>code:</strong></p> | |
<pre><code><h>Heading text level 1</h> | |
<section><h>Heading text level 2</h> | |
<section><h>Heading text level 3</h> | |
<section><h>Heading text level 4</h> | |
<section><h>Heading text level 5</h> | |
<section><h>Heading text level 6</h> | |
</section> | |
</section> | |
</section> | |
</section> | |
</section></code></pre> | |
</div> | |
</body> | |
</html> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment