Skip to content

Instantly share code, notes, and snippets.

@derekjohnson
derekjohnson / nav.js
Created January 14, 2019 11:12
Accessible performant off canvas sliding nav
/* DOM nodes */
var mainNav = document.querySelector('.js-main-nav'),
navigationList = document.querySelector('.js-navigation-list'),
navigationLinks = document.querySelectorAll('.js-navigation-link'),
navDetector = document.querySelector('.js-nav-detection');
/* Let the browser know it might need to help with the paint perf */
var hintBrowser = function() {
navigationList.style.willChange = 'transform';
};

Keybase proof

I hereby claim:

  • I am derekjohnson on github.
  • I am derekjohnson (https://keybase.io/derekjohnson) on keybase.
  • I have a public key whose fingerprint is 10B5 B39A E83E B186 C767 87DB 2B08 64C6 F21B C2D1

To claim this, I am signing this object:

@derekjohnson
derekjohnson / nav.css
Last active August 29, 2015 14:04
Small viewport nav
.l-nav {
&--capable {
position: absolute;
right: 0;
top: -500%;
}
&--capable-open {
top: 0;
right: 5.46875%;
/* Lets not rely on paths in the database, they can be very wrong when moving between dev/stage/live environments */
/* The following two variables are backward to my thinking, but hey, what ya gonna do? */
define('WP_HOME', 'http://' . $_SERVER['HTTP_HOST'] . ''); // This is NOT the 'wordpress admin area' home, but the site's home
define('WP_SITEURL', 'http://' . $_SERVER['HTTP_HOST'] . '/SECRETDIRECTORY'); // This isn't the site's URL but the WordPress admin area URL
/* MySQL settings */
switch($_SERVER['SERVER_NAME']){
// Your local machine's settings
case 'mysite.local':
define('DB_NAME', 'dev_mysite');
@derekjohnson
derekjohnson / webfonts.js
Last active December 28, 2015 18:49
Font loader
(function(win, doc, undefined) {
// sanity check - is it a decent browser
if('addEventListener' in win && 'localStorage' in win && 'querySelector' in doc) {
// https://gist.github.com/scottjehl/5406853
var injectref = doc.getElementsByTagName('script')[0],
loadCSS = function(href) {
var fontslink = doc.createElement('link');
var connection = window.navigator.connection || window.navigator.mozConnection || window.navigator.webkitConnection || { type : 'unknown' },
slow = connection.type === 3 || connection.type === 4 || connection.bandwidth <= 0.25;
if(!slow) {
// load webfonts
}
@derekjohnson
derekjohnson / Here's my opinion
Created September 25, 2013 13:40
A handy copy and paste version of Holly Brockwell's perfect rant at https://twitter.com/hollybrocks/status/382587935347847168. Just replace dresses if you're not on a site that sells dresses.
Literally no one, in the world, anywhere, ever, likes these bloody pop up boxes that get in your way when you're trying to browse. I've been on your site for all of five seconds and already you're turning the lights out and demanding my opinion. Well, here it is. I'm closing this tab and going to shop on a website that understands I want to see dresses, not needy bullshit text boxes. Happy now?
@derekjohnson
derekjohnson / form.html
Last active December 23, 2015 19:09
Hide form labels visually when placeholder is supported. (Shows both in Blackberry OS 5 and under, placeholder support absent from <textarea> in Android 2.3)
<form>
<label class="js-placeholded" for="first-name">First name</label>
<input type="text" required aria-required="true" placeholder="First name" id="first-name">
<label class="js-placeholded" for="last-name">Last name</label>
<input type="text" required aria-required="true" placeholder="Last name" id="last-name">
<label class="js-placeholded" for="telephone">Telephone</label>
<input type="tel" required aria-required="true" placeholder="Telephone" id="telephone">
@derekjohnson
derekjohnson / markers.js
Last active December 14, 2015 05:59
Add markers to text to easily see line length when prototyping layouts.
(function(doc){
if(doc.querySelectorAll) { // This only works in IE 8+
var copy = doc.querySelectorAll('.string') // Element(s) with class="string" need to be in markup
, i = 0
, ii = copy.length
, replace_at = function(text, index, char) {
return text.substr(0, index) + char + text.substr(index + 1);
}
;
@derekjohnson
derekjohnson / resize-monitor.js
Last active December 14, 2015 05:38
Small snippet to log an event in Google Analytics when a browser window is resized. It's often assumed designers and developers are the only people who resize the browser to see responsive web design in action. Let's test that assumption.
if(window.addEventListener) { // correlates with media query support
var timer = false
, resize_monitor = function() {
if(timer) {
clearTimeout(timer);
}
timer = setTimeout(function() { _gaq.push(['_trackEvent', 'Resize', 'Resize', 'Resized']); }, 100);
// or log a pageview on a non-existant page if you prefer