Skip to content

Instantly share code, notes, and snippets.

@fstorr
fstorr / Navigation list to dropdown
Created March 19, 2013 19:20
Turn a navigation list into a dropdown. Uses jQuery and the JavaScript matchMedia command, which is still fairly new and so currently relegates this to prototypes only.
if (matchMedia) {
var mq = window.matchMedia("(max-device-width:320px)");
mq.addListener(WidthChange);
WidthChange(mq);
}
function WidthChange(mq) {
if (mq.matches) {
var $dropnav = $("<select id='respnav'></select>");
var $option = $("<option>Navigate to a section</option>").appendTo($dropnav);
@fstorr
fstorr / localStorage loop
Created March 12, 2013 19:41
loop through localStorage
for(var i = 0, len = localStorage.length; i < len; i++){
var key = localStorage.key(i);
var value = localStorage[key];
}
@fstorr
fstorr / Useful regular expressions
Last active December 14, 2015 13:38
Make brain hurt fewer
** Look arounds **
Positive lookahead: q(?=u) // find q followed by u
Negative lookahead: q(?!u) // find q not followed by u
Positive lookbehind: (?<=a)b // find b preceeded by a. CANNOT BE VARIBLE LENGTH
Negative lookbehind: (?<!a)b // find b not preceeded by a. CANNOT BE VARIBLE LENGTH
** Atomic grouping **
@fstorr
fstorr / Accessible radio buttons with aria-labelledby
Last active January 10, 2022 11:48
How to make the question related to radio button answers accessible to screen reader users by using the aria-labelledby attribute.
<!doctype html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Accessible radio buttons using aria-labelledby</title>
</head>
<body>
<main role="main">
<h1>Accessible radio buttons using aria-labelledby</h1>