Skip to content

Instantly share code, notes, and snippets.

View dmethvin's full-sized avatar

Dave Methvin dmethvin

View GitHub Profile
@dmethvin
dmethvin / gist:808592
Created February 2, 2011 22:28
holdReady
// jQuery.holdReady (true) --> don't fire ready until i say so
// jQuery.holdReady (false) --> ok go ahead (assuming nobody else delayed)
jQuery.holdReady = function( hold ) {
if ( hold ) {
jQuery.readyWait++;
} else {
jQuery.ready( true );
}
};
@dmethvin
dmethvin / jquery-cmd
Created February 4, 2011 19:20
cmd file for jquery make
set path=c:\nodejs\bin;%path%
c:\cygwin\bin\bash -c "cd c:/vstudio/jquery; make"
icacls dist\jquery.js /grant Everyone:RX
@dmethvin
dmethvin / gist:1099753
Created July 22, 2011 16:13
Better Simpsons
function createSimpsons() {
var theSimpsons = ['Bart', 'Homer', 'Marge', 'Maggy', 'Lisa'],
numberOfSeasons = 21,
avgEpisodesPerSeason = 22;
$("#title").append("The Simpson Family");
$("#details").append(
"<p>Number of seasons: " + numberOfSeasons + "</p>",
"<p>Episodes per season: " + avgEpisodesPerSeason + "</p>",
var originalEvent = event,
propHook = jQuery.event.propHooks[ event.type ];
event = jQuery.Event( originalEvent );
// If hook returns false, it doesn't want anything else done
if ( propHook && propHook( event, originalEvent ) === false ) {
return event;
}
@dmethvin
dmethvin / gist:1236358
Created September 22, 2011 23:39
yet another propHooks take
var originalEvent = event,
propHook = jQuery.event.propHooks[ event.type ],
copy = props;
event = jQuery.Event( originalEvent );
// propHook can return an array of props to copy
if ( propHook ) {
copy.concat( propHook( event, originalEvent) || [] );
}
@dmethvin
dmethvin / gist:1242388
Created September 26, 2011 14:43
Windows 8 api sample geting lat/lon
(new Windows.Devices.Geolocation.Geolocator()).getGeopositionAsync().then(function(pos){
// If lat/lon not available, just use a default
pos = pos || { coordinate: { latitude: 39, longitude: 76, accuracy: 42 } };
$("#latlon").text(
"lat=" + pos.coordinate.latitude + ", lon=" + pos.coordinate.longitude +
", accuracy=" + pos.coordinate.accuracy+
", addr=" + (pos.civicAddress.city || pos.civicAddress.state || pos.civicAddress.postalCode)
);
@dmethvin
dmethvin / deferreds_pipe
Created October 13, 2011 17:50
Use of deferreds and pipe
fetchCurrentPosition()
.then(updateLocationDisplay)
.pipe(fetchWeatherAtThisLocation)
.then(updateWeatherDisplay)
.pipe(determineWeatherType)
.then(updateRecommendations)
.then(updateAppTile);
function fetchCurrentPosition()
{
@dmethvin
dmethvin / gist:1481562
Created December 15, 2011 15:45
Test case for #9777
test("clone() attributes are independent (#9777)", function () {
expect(1);
var attrName = "quack",
orig = jQuery( '<button>hi</button>' ).appendTo( "#qunit-fixture" ),
clone1 = orig.clone().attr( attrName, "clone1" ).appendTo( "#qunit-fixture" ),
clone2 = clone1.clone().attr( attrName, "clone2" ).appendTo( "#qunit-fixture" );
equal( clone1.attr(attrName), "clone1", "First clone's attr is unmolested" );
});
@dmethvin
dmethvin / gist:1676346
Created January 25, 2012 13:51
Breakpoint on access to a property
function debugAccess(obj, prop, debugGet){
var origValue = obj[prop];
Object.defineProperty(obj, prop, {
get: function () {
if ( debugGet )
debugger;
return origValue;
},
/*!
* jQuery JavaScript Library v@VERSION
* http://jquery.com/
*
* Includes Sizzle.js
* http://sizzlejs.com/
*
* Copyright 2012 jQuery Foundation and other contributors
* Released under the MIT license.
* http://jquery.org/license