Skip to content

Instantly share code, notes, and snippets.

Scott Jehl scottjehl

Block or report user

Report or block scottjehl

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
@scottjehl
scottjehl / Check whether hash changes make history entries
Created Jan 20, 2011
Check whether hash changes make history entries
View 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 Mar 2, 2011
Hoverintent-like events using special events pattern so they can be used via bind and live
View delayedEnter, delayedLeave, and delayedHover.js
/*
* 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 Apr 28, 2011
emToPx - convert global em-based values to pixels
View emToPx.js
/*
* 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 Apr 28, 2011
quick check for online status with jQuery
View hasInternets.js
//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
Anchor-include Pattern
View anchorinclude.js
/*
* 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 Jun 21, 2011
jQuery Mobile: Simple dynamic page creation
View jqm-simple-dynamic-page.js
/* 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 Jun 22, 2011 — forked from dcneiner/jquery-bookmarklet.html
jQuery Mobile View Source Bookmarklet Website
View jquery-bookmarklet.html
<!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 Jun 30, 2011
Simple throttled resize event
View throttledresize.js
// 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 Jul 8, 2011
Self-init a jQuery Mobile plugin
View jqm-self-init-a-widget.js
// 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 Aug 31, 2011
Normalized hide address bar for iOS & Android
View hideaddrbar.js
/*
* 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 ){
You can’t perform that action at this time.