Skip to content

Instantly share code, notes, and snippets.

YUI().use('base', 'substitute', function(Y) {
function Example(config) {
Example.superclass.constructor.apply(this, arguments);
}
Example.NAME = 'Example';
Example.ATTRS = {
foo: {
value: 'bar'
}
@kara-ryli
kara-ryli / base-generate.js
Created May 27, 2010 19:31
Sugar method to generate YUI classes
/**
* Sugar method to generate classes
*
* @param {su Function} Superclass to the generated class
* @param {st Object} An Object dictionary of static properties for the class
* @param {im Object} An Object dictionary of instance methods for the class
*/
YUI.add('base-generate', function (Y) {
Y.Base.generate = function (su, st, im) {
function BuiltClass() {
@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 / 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.BAD-no-cachebust.js
Created August 14, 2010 01:33
Bust browser cache while polling with YUI
// this request will be cached by the browser
YUI.use('datasource-io', 'datasource-polling', function (Y) {
var request, datasource;
request = {
callback: {
success: function (e) {
// handle success
},
@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 / 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 / yui-widget-structure.js
Created October 13, 2010 17:46
Basic YUI Widget Structure.
/* global YUI */
YUI.add("my-module", function (Y) {
"use strict";
Y.MyWidget = Y.Base.create("my-module", Y.Widget, [], {
initializer: function () {
// publish any events
// do any instantiation that doesn't require DOM
},
renderUI: function () {
@kara-ryli
kara-ryli / 1.whatFlashBuilderGenerates.as
Created October 19, 2010 20:43
Flash Builder generates the following code whenever it tries to generate a function. I want this fixed.
public function functionName():void
{
}
@kara-ryli
kara-ryli / setbodyheight.js
Created November 6, 2010 06:14
How to set the <body> tag's height to the full window height and still get it right on the iPhone.
window.onload = function () {
var s = document.body.style;
s.height = window.screen.availHeight + 'px';
setTimeout(function () {
window.scrollTo(0, 0);
s.height = window.innerHeight + 'px';
}, 50);
};