Skip to content

Instantly share code, notes, and snippets.

@kara-ryli
kara-ryli / Modernizr.TextOverflow.js
Created September 3, 2010 18:38
Adds a test to Modernizr to detect support for text-overflow.
Modernizr.addTest('textoverflow', function () {
var s = document.documentElement.style;
return 'textOverflow' in s || 'OTextOverflow' in s;
});
@kara-ryli
kara-ryli / AvoidIECacheProblems.as
Created September 2, 2010 18:57
This document class avoids some initialization problems I've encountered in IE when Flash is loaded from cache
package {
import flash.display.MovieClip;
import flash.events.Event;
/**
* Sometimes, when the SWF is pulled from cache, the first frame is
* is played before the Flash player is actually initialized. Many
* functions do not yet exist at this point. In addition, stage.stageWidth
@kara-ryli
kara-ryli / 1.url.js
Created July 27, 2010 21:53
How to convert text into HTML links in JavaScript, based on http://daringfireball.net/2010/07/improved_regex_for_matching_urls
var GRUBERS_URL_RE = /\b((?:[a-z][\w-]+:(?:\/{1,3}|[a-z0-9%])|www\d{0,3}[.]|[a-z0-9.\-]+[.][a-z]{2,4}\/)(?:[^\s()<>]+|\(([^\s()<>]+|(\([^\s()<>]+\)))*\))+(?:\(([^\s()<>]+|(\([^\s()<>]+\)))*\)|[^\s`!()\[\]{};:'".,<>?«»“”‘’]))/i;
@kara-ryli
kara-ryli / 1-fyoubitches.js
Created July 23, 2010 19:28
More helpful JavaScript Object.toString() implementation
// c.f. http://twitter.com/trek/status/19360844819
Object.prototype.toString = function() {
return "Fuck you, bitches";
};
alert({ foo: 'bar' });
@kara-ryli
kara-ryli / email.regexp.js
Created March 25, 2010 17:17
The HTML5 e-mail address syntax.
/^(?:[a-z\d!#\$%&'\*\+\-\/=\?\^_`\{\|\}~]+|\.)+@[a-z\d\-]+(?:\.[a-z\d\-]+)*$/i
@kara-ryli
kara-ryli / Geo.js
Created July 28, 2009 02:22
A primer for using the W3C geolocation API supported in Firefox 3.5 and MobileSafari
var Geo = navigator.geolocation, // {Object|null} a shortcut to the geolocation static class
options = { // {Object} options available to calls for position
enableHighAccuracy: false, // {Boolean} Whether or not to use more resources to get a more accurate position
maximumAge: 0, // {Number|Infinity} The maximum number of milliseconds since the last check.
timeout: null // {Number|null} The maximum number of milliseconds to wait for a fix
},
watchId; // {Number} an ID to a watch timeout
// handles an error finding the user's position
function onError(error) {