Skip to content

Instantly share code, notes, and snippets.

@noahrc
noahrc / config.json
Last active September 5, 2018 15:14
Example of a feature toggle
{
"featureToggles": {
"releaseTheKraken": true,
}
}
@noahrc
noahrc / jwplayer.loader.js
Created March 7, 2013 19:57
jwplayer loader using require.js and data attributes
define(['jquery', 'require'], function($, require) {
'use strict';
// Test for jwplayer videos
if ($('.jwplayer-video[data-video-url]')[0]) {
require(['jwplayerjs'], function(jwplayer) {
$('.jwplayer-video').each(function(i) {
// add a child dom node with a unique id
@noahrc
noahrc / jquery.sticky-nav.js
Created March 6, 2013 22:53
Adds 'back to top' links to the page and makes a navigation bar stick to the top of the page
// Create a sticky widget
var STICKY = {}
// Start a timer on window scroll to prevent firing lots of extra functions
STICKY.timer = setTimeout(function(){})
// Only do the following if the browser isn't IE 6
if(!$('html.ie6')[0]) {
// Add 'back to top' links, except in IE 6
@noahrc
noahrc / animate-anchors.js
Created March 6, 2013 22:50
Animate transition to anchor links
/* Animate transitions to links on the same page */
var ANIMATEANCHORS = {}
ANIMATEANCHORS.initialize = function() {
$('a[href*=#]').not('.fancybox').click(function() {
if (location.pathname.replace(/^\//,'') == this.pathname.replace(/^\//,'') && location.hostname == this.hostname) {
var $target = $(this.hash)
$target = $target.length && $target || $('[name=' + this.hash.slice(1) +']')
var targetOffset = $target.length ? $target.offset().top - 20 : 0 // Offset the target distance to have some margin at the top
$('html, body').animate({scrollTop: targetOffset}, 700)
@noahrc
noahrc / console.log.alertFallback.js
Created March 6, 2013 22:49
Console.log for IE with alert fallback
// Enable console.log fallback for IE
var alertFallback = true;
if (typeof console === "undefined" || typeof console.log === "undefined") {
console = {};
if (alertFallback) {
console.log = function(msg) {
alert(msg);
};
} else {
console.log = function() {};
@noahrc
noahrc / ie-edge-meta-tag.html
Created March 5, 2013 16:19
metatag to force IE not to use compatability mode
<meta http-equiv="X-UA-Compatible" content="IE=edge" />
@noahrc
noahrc / console.js
Created February 22, 2013 19:36
Define a console object to prevent errors in IE
// Define a console object to prevent errors in IE
if(typeof window.console === 'undefined' ) {
window.console = {
log: function(){}
};
}
@noahrc
noahrc / Gruntfile.js
Created January 16, 2013 04:08
My yeoman Gruntfile.js with support for jade templates added and the js/css hashes removed
module.exports = function( grunt ) {
'use strict';
//
// Grunt configuration:
//
// https://github.com/cowboy/grunt/blob/master/docs/getting_started.md
//
grunt.loadNpmTasks('grunt-jade');