Skip to content
This repository has been archived by the owner on Jul 22, 2020. It is now read-only.

Commit

Permalink
update Sugar to 1.3.6
Browse files Browse the repository at this point in the history
  • Loading branch information
phlipper committed Nov 2, 2012
1 parent baee462 commit ae6a132
Show file tree
Hide file tree
Showing 24 changed files with 549 additions and 443 deletions.
2 changes: 1 addition & 1 deletion lib/sugar/rails/version.rb
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
module Sugar
module Rails
VERSION = "1.3.5"
SUGARJS_VERSION = "1.3.5"
SUGARJS_VERSION = "1.3.6"
end
end
35 changes: 19 additions & 16 deletions vendor/assets/javascripts/precompiled/development/array.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
} else if(isRegExp(match) && isString(el)) {
// Match against a regexp
return regexp(match).test(el);
} else if(isFunction(match) && !isFunction(el)) {
} else if(isFunction(match)) {
// Match against a filtering function
return match.apply(scope, params);
} else if(isObject(match) && isObjectPrimitive(el)) {
Expand Down Expand Up @@ -317,10 +317,12 @@
var result = [], tmp;
multiArgs(arguments, function(a) {
if(isObjectPrimitive(a)) {
tmp = array.prototype.slice.call(a);
if(tmp.length > 0) {
a = tmp;
}
try {
tmp = array.prototype.slice.call(a, 0);
if(tmp.length > 0) {
a = tmp;
}
} catch(e) {}
}
result = result.concat(a);
});
Expand Down Expand Up @@ -905,15 +907,8 @@
*
***/
'sample': function(num) {
var result = [], arr = this.clone(), index;
if(isUndefined(num)) num = 1;
while(result.length < num) {
index = floor(math.random() * (arr.length - 1));
result.push(arr[index]);
arr.removeAt(index);
if(arr.length == 0) break;
}
return arguments.length > 0 ? result : result[0];
var arr = this.randomize();
return arguments.length > 0 ? arr.slice(0, num) : arr[0];
},

/***
Expand Down Expand Up @@ -1102,6 +1097,7 @@
* @extra In cases where a callback is used, instead of %element, index%, the callback will instead be passed %key, value%. Enumerable methods are also available to extended objects as instance methods.
*
* @set
* each
* map
* any
* all
Expand Down Expand Up @@ -1131,7 +1127,8 @@
extendSimilar(object, false, false, names, function(methods, name) {
methods[name] = function(obj, arg1, arg2) {
var result;
result = array.prototype[name].call(keysWithCoercion(obj), function(key) {
var x = keysWithCoercion(obj);
result = array.prototype[name].call(x, function(key) {
if(mapping) {
return transformArgument(obj[key], arg1, obj, [key, obj[key], obj]);
} else {
Expand Down Expand Up @@ -1168,6 +1165,12 @@
return values.reduce.apply(values, multiArgs(arguments).slice(1));
},

'each': function(obj, fn) {
checkCallback(fn);
iterateOverObject(obj, fn);
return obj;
},

/***
* @method size(<obj>)
* @returns Number
Expand All @@ -1186,7 +1189,7 @@

buildEnhancements();
buildAlphanumericSort();
buildEnumerableMethods('each,any,all,none,count,find,findAll,isEmpty');
buildEnumerableMethods('any,all,none,count,find,findAll,isEmpty');
buildEnumerableMethods('sum,average,min,max,least,most', true);
buildObjectInstanceMethods('map,reduce,size', Hash);

8 changes: 7 additions & 1 deletion vendor/assets/javascripts/precompiled/development/core.js
Original file line number Diff line number Diff line change
Expand Up @@ -120,6 +120,12 @@
return result;
}

function checkCallback(fn) {
if(!fn || !fn.call) {
throw new TypeError('Callback is not callable');
}
}


// General helpers

Expand Down Expand Up @@ -154,7 +160,7 @@
var key;
for(key in obj) {
if(!hasOwnProperty(obj, key)) continue;
if(fn.call(obj, key, obj[key]) === false) break;
if(fn.call(obj, key, obj[key], obj) === false) break;
}
}

Expand Down
59 changes: 44 additions & 15 deletions vendor/assets/javascripts/precompiled/development/date.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,10 @@
var CurrentLocalization;

var TimeFormat = ['ampm','hour','minute','second','ampm','utc','offset_sign','offset_hours','offset_minutes','ampm']
var FloatReg = '\\d{1,2}(?:[,.]\\d+)?';
var RequiredTime = '({t})?\\s*('+FloatReg+')(?:{h}('+FloatReg+')?{m}(?::?('+FloatReg+'){s})?\\s*(?:({t})|(Z)|(?:([+-])(\\d{2,2})(?::?(\\d{2,2}))?)?)?|\\s*({t}))';
var DecimalReg = '(?:[,.]\\d+)?';
var HoursReg = '\\d{1,2}' + DecimalReg;
var SixtyReg = '[0-5]\\d' + DecimalReg;
var RequiredTime = '({t})?\\s*('+HoursReg+')(?:{h}('+SixtyReg+')?{m}(?::?('+SixtyReg+'){s})?\\s*(?:({t})|(Z)|(?:([+-])(\\d{2,2})(?::?(\\d{2,2}))?)?)?|\\s*({t}))';

var KanjiDigits = '〇一二三四五六七八九十百千万';
var FullWidthDigits = '0123456789';
Expand Down Expand Up @@ -411,6 +413,10 @@
return arrayToAlternates(arr);
}

function setDefault(name, value) {
loc[name] = loc[name] || value;
}

function setModifiers() {
var arr = [];
loc.modifiersByName = {};
Expand Down Expand Up @@ -439,10 +445,10 @@
setArray('units', false, 8);
setArray('numbers', false, 10);

loc['code'] = localeCode;
loc['date'] = getDigit(1,2, loc['digitDate']);
loc['year'] = getDigit(4,4);
loc['num'] = getNum();
setDefault('code', localeCode);
setDefault('date', getDigit(1,2, loc['digitDate']));
setDefault('year', "'\\d{2}|" + getDigit(4,4));
setDefault('num', getNum());

setModifiers();

Expand Down Expand Up @@ -537,8 +543,10 @@
arr.forEach(function(key, i) {
value = match[i + 1];
if(isUndefined(value) || value === '') return;
if(key === 'year') obj.yearAsString = value;
num = parseFloat(value.replace(/,/, '.'));
if(key === 'year') {
obj.yearAsString = value.replace(/'/, '');
}
num = parseFloat(value.replace(/'/, '').replace(/,/, '.'));
obj[key] = !isNaN(num) ? num : value.toLowerCase();
});
return obj;
Expand Down Expand Up @@ -855,7 +863,8 @@
// Date comparison helpers

function compareDate(d, find, buffer, forceUTC) {
var p = getExtendedDate(find, null, null, forceUTC), accuracy = 0, loBuffer = 0, hiBuffer = 0, override, capitalized;
var p, t, min, max, minOffset, maxOffset, override, capitalized, accuracy = 0, loBuffer = 0, hiBuffer = 0;
p = getExtendedDate(find, null, null, forceUTC);
if(buffer > 0) {
loBuffer = hiBuffer = buffer;
override = true;
Expand All @@ -881,12 +890,27 @@
hiBuffer = -50;
}
}
var t = d.getTime();
var min = p.date.getTime();
var max = max || (min + accuracy);
t = d.getTime();
min = p.date.getTime();
max = max || (min + accuracy);
max = compensateForTimezoneTraversal(d, min, max);
return t >= (min - loBuffer) && t <= (max + hiBuffer);
}

function compensateForTimezoneTraversal(d, min, max) {
var dMin, dMax, minOffset, maxOffset;
dMin = new Date(min);
dMax = new Date(max).utc(d.isUTC());
if(callDateGet(dMax, 'Hours') !== 23) {
minOffset = dMin.getTimezoneOffset();
maxOffset = dMax.getTimezoneOffset();
if(minOffset !== maxOffset) {
max += (maxOffset - minOffset).minutes();
}
}
return max;
}

function updateDate(d, params, reset, advance, prefer) {
var weekday, specificityIndex;

Expand Down Expand Up @@ -917,7 +941,9 @@
}

// "date" can also be passed for the day
if(params['date']) params['day'] = params['date'];
if(isDefined(params['date'])) {
params['day'] = params['date'];
}

// Reset any unit lower than the least specific unit set. Do not do this for weeks
// or for years. This needs to be performed before the acutal setting of the date
Expand Down Expand Up @@ -1030,7 +1056,9 @@
// (or 29th in the case of a leap year).

function checkMonthTraversal(date, targetMonth) {
if(targetMonth < 0) targetMonth += 12;
if(targetMonth < 0) {
targetMonth = targetMonth % 12 + 12;
}
if(targetMonth % 12 != callDateGet(date, 'Month')) {
callDateSet(date, 'Date', 0);
}
Expand Down Expand Up @@ -2152,7 +2180,7 @@
'units': 'millisecond:|s,second:|s,minute:|s,hour:|s,day:|s,week:|s,month:|s,year:|s',
'numbers': 'one,two,three,four,five,six,seven,eight,nine,ten',
'articles': 'a,an,the',
'tokens': 'the,st|nd|rd|th,of',
'tokens': 'the,st|nd|rd|th,of',
'short': '{Month} {d}, {yyyy}',
'long': '{Month} {d}, {yyyy} {h}:{mm}{tt}',
'full': '{Weekday} {Month} {d}, {yyyy} {h}:{mm}:{ss}{tt}',
Expand Down Expand Up @@ -2184,6 +2212,7 @@
'{0} {num}{1} {day} of {month} {year?}',
'{weekday?} {month} {date}{1?} {year?}',
'{date} {month} {year}',
'{date} {month}',
'{shift} {weekday}',
'{shift} week {weekday}',
'{weekday} {2?} {shift} week',
Expand Down
6 changes: 0 additions & 6 deletions vendor/assets/javascripts/precompiled/development/es5.js
Original file line number Diff line number Diff line change
Expand Up @@ -84,12 +84,6 @@
}
}

function checkCallback(fn) {
if(!fn || !fn.call) {
throw new TypeError('Callback is not callable');
}
}

function checkFirstArgumentExists(args) {
if(args.length === 0) {
throw new TypeError('First argument must be defined');
Expand Down
34 changes: 20 additions & 14 deletions vendor/assets/javascripts/precompiled/development/number.js
Original file line number Diff line number Diff line change
Expand Up @@ -146,7 +146,7 @@
*
***/
'isOdd': function() {
return !this.isMultipleOf(2);
return !isNaN(this) && !this.isMultipleOf(2);
},

/***
Expand Down Expand Up @@ -194,21 +194,27 @@
*
***/
'format': function(place, thousands, decimal) {
var str, split, method, after, r = /(\d+)(\d{3})/;
if(string(thousands).match(/\d/)) throw new TypeError('Thousands separator cannot contain numbers.');
str = isNumber(place) ? round(this, place || 0).toFixed(math.max(place, 0)) : this.toString();
thousands = thousands || ',';
decimal = decimal || '.';
split = str.split('.');
str = split[0];
after = split[1] || '';
while (str.match(r)) {
str = str.replace(r, '$1' + thousands + '$2');
var i, str, split, integer, fraction, result = '';
if(isUndefined(thousands)) {
thousands = ',';
}
if(after.length > 0) {
str += decimal + repeatString((place || 0) - after.length, '0') + after;
if(isUndefined(decimal)) {
decimal = '.';
}
return str;
str = (isNumber(place) ? round(this, place || 0).toFixed(math.max(place, 0)) : this.toString()).replace(/^-/, '');
split = str.split('.');
integer = split[0];
fraction = split[1];
for(i = integer.length; i > 0; i -= 3) {
if(i < integer.length) {
result = thousands + result;
}
result = integer.slice(math.max(0, i - 3), i) + result;
}
if(fraction) {
result += decimal + repeatString((place || 0) - fraction.length, '0') + fraction;
}
return (this < 0 ? '-' : '') + result;
},

/***
Expand Down
7 changes: 4 additions & 3 deletions vendor/assets/javascripts/precompiled/development/object.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@

/***
* @package Object
* @dependency core
Expand Down Expand Up @@ -28,7 +27,7 @@
});
if(!key && paramIsArray) key = obj.length.toString();
setParamsObject(obj, key, value);
} else if(value.match(/^[\d.]+$/)) {
} else if(value.match(/^[+-]?\d+(\.\d+)?$/)) {
obj[param] = parseFloat(value);
} else if(value === 'true') {
obj[param] = true;
Expand Down Expand Up @@ -308,7 +307,9 @@
* @example
*
* Object.extend();
* [2,4,6].map(Math.exp).tap(function(){ arr.pop(); }).map(Math.round); -> [7,55]
* [2,4,6].map(Math.exp).tap(function(arr) {
* arr.pop()
* });
* [2,4,6].map(Math.exp).tap('pop').map(Math.round); -> [7,55]
*
***/
Expand Down
Loading

0 comments on commit ae6a132

Please sign in to comment.