Navigation Menu

Skip to content

Instantly share code, notes, and snippets.

View addyosmani's full-sized avatar
🎯
Focusing

Addy Osmani addyosmani

🎯
Focusing
View GitHub Profile
// Handles JavaScript history management and callbacks. To use, register a
// regexp that matches the history hash with its corresponding callback.
window.HashHistory = {
// The interval at which the window location is polled.
URL_CHECK_INTERVAL : 500,
// We need to use an iFrame to save history if we're in an old version of IE.
USE_IFRAME : jQuery.browser.msie && jQuery.browser.version < 8,
@mattmccray
mattmccray / backbone_helper.coffee
Created October 14, 2010 08:44
Use Backbone.js classes as native CoffeeScript classes
# Backbone CoffeeScript Helpers by M@ McCray.
# Source: http://gist.github.com/625893
#
# Use Backbone classes as native CoffeeScript classes:
#
# class TaskController extends Events
#
# class TaskView extends View
# tagName: 'li'
# @SRC: '<div class="icon">!</div><div class="name"><%= name %></div>'
/* View documents with Google Docs ...
* because my laptop can't handle Word and Chrome at the same time. */
$(document).ready(function(){
// I'm sure there's a more efficient selector for this.
$('a[href$=doc], a[href$=docx], a[href$=pdf], a[href$=rtf]').attr(
'href',
function(){
return 'http://docs.google.com/viewer?url=' + this.href;
}
@cowboy
cowboy / HEY-YOU.md
Last active April 9, 2024 15:54
jQuery Tiny Pub/Sub: A really, really, REALLY tiny pub/sub implementation for jQuery.
@jitter
jitter / gist:703467
Created November 17, 2010 15:01
Links to change on jquery.com

A - [jquery.com][1] site-wide:

  • Link for "Bug Tracker" in header (secondary) and footer navigation from http://dev.jquery.com/ to http://bugs.jquery.com

B - [jquery.com Startpage][2]

  • Linktext from "Source code/SVN" to "Source code/GIT"
  • Link for "Submit a New Bug Report" from http://dev.jquery.com/newticket/ to http://bugs.jquery.com/newticket

C - [Downloading_jQuery][3]

jQuery API.xml issues:

  • for replaceAll, :gt, :contains and :has
    the <argument> tag appears outside <signature>
  • for ajaxSuccess and ajaxSend
    the main <desc> appears inside <signature> (it should be a direct child of <entry>)

Due to these issues, some info on main api.jquery.com pages for these methods is missing.

@cowboy
cowboy / jquery.ba-nodetype.js
Created November 18, 2010 20:24
jQuery nodetype filter: Filter the selected elements by nodeType
/*!
* jQuery nodetype filter - v0.1pre - 11/18/2010
* http://benalman.com/
*
* Copyright (c) 2010 "Cowboy" Ben Alman
* Dual licensed under the MIT and GPL licenses.
* http://benalman.com/about/license/
*/
(function($){
(function($){
$.Class = function(code){
var klass = function() {
var instance = (arguments[0] !== null && this.__init__ && typeof this.__init__ == 'function') ? this.__init__.apply(this, arguments) : this;
return instance;
};
$.extend(klass, this);
$.extend(klass.prototype, {
'bind': function(type, fn) {
this.__events__ = this.__events__ || {};
@remy
remy / gist:726930
Created December 3, 2010 13:08
Quick sessionStorage polyfill
if (!sessionStorage && JSON) {
sessionStorage = (function () {
var data = window.name ? JSON.parse(window.name) : {};
return {
clear: function () {
data = {};
window.name = '';
},
getItem: function (key) {
@sstephenson
sstephenson / back_forward.js
Created December 13, 2010 21:55
How to detect whether a hash change came from the Back or Forward button
var detectBackOrForward = function(onBack, onForward) {
hashHistory = [window.location.hash];
historyLength = window.history.length;
return function() {
var hash = window.location.hash, length = window.history.length;
if (hashHistory.length && historyLength == length) {
if (hashHistory[hashHistory.length - 2] == hash) {
hashHistory = hashHistory.slice(0, -1);
onBack();