This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) { |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(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', |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// newApply: Invoke a consturctor function correctly, passing an arbitrary | |
// number of arguments | |
function newApply(fn, argsArray) { // (c) Christian C. Salvadó - MIT License | |
var F = newApply, obj, ret, t, isPrimitive; | |
if (this instanceof F) return; // this function is used as a dummy constructor | |
F.prototype = fn.prototype; // set up the prototype and constructor properties | |
F.prototype.constructor = fn; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Generic function to subclass an array in JavaScript | |
// (using the ECMAScript Harmony Proxy features) | |
// Structuring of code inspired by @kangax's | |
// array_subclassing (http://github.com/kangax/array_subclassing) | |
var makeSubArray = (function () { | |
var MAX_UINT32 = Math.pow(2, 32) - 1; | |
return function (properties) { | |
properties || (properties = {}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// BESEN wrong behavior of the logical && and || operators | |
// Tested on r111 | |
var obj = {}; | |
// Logical AND operator | |
print(obj && obj); // prints true, expected '[object Object]' | |
print(obj && 'foo'); // prints '[object Object]', expected 'foo' | |
print(obj && 4); // prints '[object Object]', expected 4 | |
print(obj && NaN); // prints false, expected NaN |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* BESEN bug on String index named properties | |
* | |
* There are some problems accessing the named properties of String | |
* objects that correspond to the individual characters of its | |
* [[PrimitiveValue]]. | |
* | |
* Tested on BESEN r117 | |
*/ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* Written by Asen Bozhilov | |
* http://code.google.com/p/js-examples/source/browse/trunk/JSON.js | |
*/ | |
if (!this.JSON) { | |
this.JSON = { | |
parse : (function (undefined) { | |
var JSON_GRAMMAR = { | |
STRING : '"([^"\\x00-\\x1F\\\\]|\\\\["\\\\\/bfnrt]|\\\\u[0-9A-Fa-f]{4})*"', |
OlderNewer