Skip to content

Instantly share code, notes, and snippets.

View cms's full-sized avatar

Christian C. Salvadó cms

View GitHub Profile
@cms
cms / besenSliceCall.js
Created July 29, 2010 07:26
Besen `Array.prototype.slice` bug
var slice = Array.prototype.slice,
arrayLike = {0: 'a', 1: 'b', 2: 'c', 3: 'd', length:4},
a = slice.call(arrayLike), // undefined
b = slice.call(arrayLike, undefined); // the array as expected
print(a); // undefined
print(b); // "a,b,c,d"
@cms
cms / besenTest.js
Created July 29, 2010 06:16
BESEN undefined accessor properties bug
// BESEN strange behavior on named accessor property
// Tested on r77
var obj = Object.defineProperty({}, 'foo', { set: undefined }),
desc = Object.getOwnPropertyDescriptor(obj, 'foo');
// Definning a setter just to make the property a named accessor property.
// (`undefined` is a valid value for the [[Set]] and [[Get]] property attributes)
// the getter is correctly `undefined`, the FromPropertyDescriptor
@cms
cms / parseDate.js
Created June 2, 2010 07:16
parseDate
function parseDate(str, format) {
format = format || 'yyyy-mm-dd'; // default format
// build a regular expression to match the format
var i = 0, fmt = {},
re = new RegExp('^'+format.replace(/(yyyy|dd|mm)/g, function (match) {
fmt[match] = ++i; // store format position
return '(\\d{'+match.length+'})'; // make a capturing group
})+'$'), parts = str.match(re); // match the date parts
if (!parts) return null; // input didn't match the format pattern
(function () {
var frameworks = {
'MooTools Core': 'MooTools.version',
'MooTools More': 'MooTools.More.version',
'Base2': 'base2.version',
'Dojo': 'dojo.version',
'Ext JS': 'Ext.version',
'jQuery': 'jQuery.fn.jquery',
'jQuery UI': 'jQuery.ui.version',
'MochKit': 'MochiKit.MochiKit.VERSION',
@cms
cms / getStyle.js
Created April 17, 2010 00:48
Get computed styles
function getStyle(el, styleProp) {
var value, defaultView = el.ownerDocument.defaultView;
// W3C standard way:
if (defaultView && defaultView.getComputedStyle) {
// sanitize property name to css notation (hypen separated words eg. font-Size)
styleProp = styleProp.replace(/([A-Z])/g, "-$1").toLowerCase();
return defaultView.getComputedStyle(el, null).getPropertyValue(styleProp);
} else if (el.currentStyle) { // IE
// sanitize property name to camelCase
styleProp = styleProp.replace(/\-(\w)/g, function(str, letter) {