Skip to content

Instantly share code, notes, and snippets.

View addyosmani's full-sized avatar
🎯
Focusing

Addy Osmani addyosmani

🎯
Focusing
View GitHub Profile
/* 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;
}
/*!
* jQuery Tiny Pub/Sub - v0.3pre - 11/4/2010
* http://benalman.com/
*
* Copyright (c) 2010 "Cowboy" Ben Alman
* Dual licensed under the MIT and GPL licenses.
* http://benalman.com/about/license/
*/
(function($){
/*!
* jQuery Tiny Pub/Sub - v0.3pre - 11/4/2010
* http://benalman.com/
*
* Copyright (c) 2010 "Cowboy" Ben Alman
* Dual licensed under the MIT and GPL licenses.
* http://benalman.com/about/license/
*/
(function($){
//For use on the jquery functions that except selectors
jQuery.fn.atLeastOne = function(prop, selectorsArr) {
var ret = 0, self = this,
testSelector = function(value){
return self[prop].apply(self, [value]).size() > 0;
};
$.each(selectorsArr, function(i, value){
ret = testSelector(value);
// break loop if found
if(ret) { return false }
(function($){
$.pubsub = (function(){
var mule = $({});
return {
subscribe:function(key, fn){
//Normalise
mule.bind(key, function(e, data){
fn.apply(null, [data]);
});
(function($) {
$.fn.recurse = function(closure, options) {
var self = this, settings = $.extend({}, $.fn.recurse.defaults, options);
self.queue(settings.queue, function(next){
if (!closure.apply(self, [self])) {
self.delay(settings.delay, settings.queue).queue(settings.queue, arguments.callee).trigger('queue').dequeue(settings.queue);
} else {
self.trigger('complete');
}
});
(function( $ ){
$.fn.pushTop = function() {
return this.each(function() {
var $this = $(this);
top_z_index = 0;
$('*').each(function() {
var this_z_index = $(this).css('z-index');
if (this_z_index != "auto" && this_z_index > top_z_index) {
top_z_index = this_z_index;
}
(function($) {
$.fn.enable = function() {
// Enable each selected element by removing its 'disabled' attribute.
return this.each(function() {
$(this).removeAttr('disabled');
});
};
$.fn.disable = 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__ || {};
var application = {
page_loaded : false,
page_init : function() {
var i;
application.page_loaded = true;
// Load scripts that have not already been loaded.
var script;
for (i=0; script = application.scripts_to_load[i]; i++) {