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 / 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: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: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: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: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"));
@replete
replete / gist:2385046
Created Apr 14, 2012
iOS like scrollbars (requires nicescroll)
View gist:2385046
/* -------------------------------------- */
//iOS-like scrollbar
var $niceScrollContainers = $("[data-ios-scroll]");
$niceScrollContainers.each(function () {
var $container = $(this),
scrollClass = $container.attr("data-ios-scroll"),
cursorWidth = "6px",
$contentsLastChild = $container.children("*:last-child");
@replete
replete / gist:2385061
Created Apr 14, 2012
Text entry character count and truncate contenteditable
View gist:2385061
/* -------------------------------------- */
//Char count & truncate
var $charCount = $("[data-char-count]");
$charCount.each(function () {
var $this = $(this),
$charSelector = $($this.attr("data-char-count")),
charMax = $this.attr("data-char-count-max") || false;
You can’t perform that action at this time.