Skip to content

Instantly share code, notes, and snippets.

Phil Ricketts replete

Block or report user

Report or block replete

Hide content and notifications from this user.

Learn more about blocking users

Contact Support about this user’s behavior.

Learn more about reporting abuse

Report abuse
View GitHub Profile
@replete
replete / FindDynamicUnCSSClasses.js
Created May 11, 2015
Add this code to your site. Open your console. Click everything interactive. Copy CSS classes into UnCSS ignore list.
View FindDynamicUnCSSClasses.js
(function(){
'use strict';
// Feature Detection
var MutationObserver = (function () {
var prefixes = ['WebKit', 'Moz', 'O', 'Ms', ''];
for(var i=0; i < prefixes.length; i++) {
if(prefixes[i] + 'MutationObserver' in window) {
return window[prefixes[i] + 'MutationObserver'];
}
View gist:d70820808bf94f8763da
/*
* Minimal classList shim for IE 9
* By Devon Govett
* MIT LICENSE
*/
if (!("classList" in document.documentElement) && Object.defineProperty && typeof HTMLElement !== 'undefined') {
Object.defineProperty(HTMLElement.prototype, 'classList', {
get: function() {
@replete
replete / gist:2384908
Created Apr 14, 2012
Check domain before running domain-specific code, e.g. analytics
View gist:2384908
if (document.location.hostname.indexOf("mydomain.com") > -1) {
//GA: Event Tracking, for example
$("a[href$=pdf]").click(function () {
var name = $(this).attr("title") || "";
_gaq.push(['_trackEvent', 'PDF', 'Download', name]);
});
//etc
@replete
replete / gist:2384987
Created Apr 14, 2012
Change <body> background url through data-attribute
View gist:2384987
/* -------------------------------------- */
//Body background
var $bodyBackground = $("[data-body-background]:eq(0)"),
backgroundURL = $bodyBackground.attr("data-body-background");
if ($bodyBackground.length > 0) {
$body
.css("background", "url(" + backgroundURL + ") no-repeat top center #000");
}
@replete
replete / gist:2384817
Created Apr 14, 2012
Detect IE version 5-9 (based on conditional comments)
View gist:2384817
/* Don't forget, the currently unreleased IE10 is supposedly dropping support for conditional comments
so we'll need something else in this function to detect IE10 (hopefully, we'll never need to) */
var ie = (function(){
var undef,
v = 3,
div = document.createElement('div'),
all = div.getElementsByTagName('i');
while (
div.innerHTML = '<!--[if gt IE ' + (++v) + ']><i></i><![endif]-->',
@replete
replete / gist:2384841
Created Apr 14, 2012
Get elements by class name - getElementsByClassName
View gist:2384841
/* Example usage:
var widgets = getElementsByClassName(document, "a-css-classname");
for (var i = 0; i < widgets.length; i++) {
//Do something with widgets[i]
}
*/
function getElementsByClassName(node,classname) {
if (node.getElementsByClassName) {
return node.getElementsByClassName(classname);
@replete
replete / gist:2384895
Created Apr 14, 2012
Insert UA/platform strings into html data attribute
View gist:2384895
/*
!! DANGER DANGER WILL ROBINSON
*/
document.documentElement.setAttribute('data-ua',navigator.userAgent);
document.documentElement.setAttribute('data-platform',navigator.platform);
@replete
replete / gist:2384974
Created Apr 14, 2012
Once-only sequential 'animation' (css classes) of element children on page load
View gist:2384974
/*
After the page loads, highlight important parts on the page (e.g. navigation),
by sequentially applying a css class to each, once.
Styles/animation handled by CSS.
*/
var $delayHoverAnims = $("[data-delay-hover-anim]");
@replete
replete / gist:2384996
Created Apr 14, 2012
Simple rotating content children
View gist:2384996
/* -------------------------------------- */
//Simple Rotator
var $rotatorContainers = $("[data-rotator]");
$rotatorContainers.each(function () {
var $container = $(this),
$items = $container.children($container.attr("data-rotator")),
itemTotal = $items.length - 1,
autoplay = $container.attr("data-rotator-autoplay");
@replete
replete / gist:2385033
Created Apr 14, 2012
Simple content panes with navigation
View gist:2385033
/* -------------------------------------- */
//Content panes with navigation
var $panesContainers = $("[data-panes]");
$panesContainers.each(function () {
var $container = $(this),
$items = $container.children($container.attr("data-panes")),
itemTotal = $items.length - 1,
$navigation = $container.find($container.attr("data-panes-navigation"));
You can’t perform that action at this time.