Skip to content

Instantly share code, notes, and snippets.

View scottjehl's full-sized avatar

Scott Jehl scottjehl

View GitHub Profile
@scottjehl
scottjehl / Check whether hash changes make history entries
Created January 20, 2011 17:23
Check whether hash changes make history entries
// potential test for whether changing location.hash creates a history entry
// in browsers where this isn't true (blackberry, nokia), hash changes can't be reached through the back/forward buttons
// just testing whether this approach is feasible...
var hashMakesHistory = function(){
var histLength = window.history.length,
prevHash = window.location.hash,
historyMade;
//change the hash to something unique
@scottjehl
scottjehl / delayedEnter, delayedLeave, and delayedHover.js
Created March 2, 2011 14:48
Hoverintent-like events using special events pattern so they can be used via bind and live
/*
* jQuery special events for delayedEnter, delayedLeave, and delayedHover
* Author: Scott Jehl, scott@filamentgroup.com
* Copyright (c) 2011 Filament Group
* licensed under MIT
* note: Each event can be used with bind or live event handling as you would use mouseenter,mouseleave, and hover
* events fire after 200ms timeout
*/
(function($){
//delayedEnter event
@scottjehl
scottjehl / emToPx.js
Created April 28, 2011 16:33
emToPx - convert global em-based values to pixels
/*
* emToPx: convert a global em-based value to pixels
* Copyright 2011, Scott Jehl, scottjehl.com
* MIT License
* Usage: emToPx function accepts a single number/float argument, returns a number
*/
var emToPx = (function( win ){
var doc = win.document,
body = doc.body,
prop = "fontSize",
@scottjehl
scottjehl / hasInternets.js
Created April 28, 2011 19:16
quick check for online status with jQuery
//quick online/offline check
function hasInternets() {
var s = $.ajax({
type: "HEAD",
url: window.location.href.split("?")[0] + "?" + Math.random(),
async: false
}).status;
//thx http://www.louisremi.com/2011/04/22/navigator-online-alternative-serverreachable/
return s >= 200 && s < 300 || s === 304;
};
@scottjehl
scottjehl / anchorinclude.js
Created May 20, 2011 17:04
Anchor-include Pattern
/*
* anchor-include pattern for already-functional links that work as a client-side include
* Copyright 2011, Scott Jehl, scottjehl.com
* Dual licensed under the MIT
* Idea from Scott Gonzalez
* to use, place attributes on an already-functional anchor pointing to content
* that should either replace, or insert before or after that anchor
* after the page has loaded
* Replace: <a href="..." data-replace="articles/latest/fragment">Latest Articles</a>
* Before: <a href="..." data-before="articles/latest/fragment">Latest Articles</a>
@scottjehl
scottjehl / jqm-simple-dynamic-page.js
Created June 21, 2011 14:08
jQuery Mobile: Simple dynamic page creation
/* Dynamically create a page and navigate to it.
(and include the page in browser history ) */
//create markup
var newPage = $("<div data-role=page data-url=yay><div data-role=header><h1>YAY!!!!</h1></div><div data-role=content><img src=http://bukk.it/yay.gif /></div></div");
//append it to the page container
newPage.appendTo( $.mobile.pageContainer );
//go to it
@scottjehl
scottjehl / jquery-bookmarklet.html
Created June 22, 2011 19:32 — forked from dcneiner/jquery-bookmarklet.html
jQuery Mobile View Source Bookmarklet Website
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8" />
<title>jQuery Mobile Original Source Bookmarklet for Firefox and Chrome</title>
<style type="text/css" media="screen">
body, html, h1 { margin: 0; padding: 0; }
html { padding: 20px; background: #ddd; }
body { max-width: 600px; margin: 0 auto; padding: 20px; box-sizing: border-box; background: #fff; font-family: Helvetica, arial; box-shadow: rgba(0,0,0,0.2) 0 0 5px }
@scottjehl
scottjehl / throttledresize.js
Created June 30, 2011 20:26
Simple throttled resize event
// throttled resize event
(function( $ ) {
$.event.special.throttledresize = {
setup: function() {
$( this ).bind( "resize", handler );
},
teardown: function(){
$( this ).unbind( "resize", handler );
}
@scottjehl
scottjehl / jqm-self-init-a-widget.js
Created July 8, 2011 14:29
Self-init a jQuery Mobile plugin
// First, let's define a widget/plugin called "foo"
// Either using jQuery's $.fn plugin namespace, for simple stateless plugins...
$.fn.foo = function(){
// In this scope, this refers to the element on which the plugin foo() was called
// manipulate it and return this at the end, so it can be chainable
};
@scottjehl
scottjehl / hideaddrbar.js
Created August 31, 2011 11:42
Normalized hide address bar for iOS & Android
/*
* Normalized hide address bar for iOS & Android
* (c) Scott Jehl, scottjehl.com
* MIT License
*/
(function( win ){
var doc = win.document;
// If there's a hash, or addEventListener is undefined, stop here
if( !location.hash && win.addEventListener ){