sugar-rails 1.3.7 → 1.4.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.ruby-gemset +1 -0
- data/.ruby-version +1 -0
- data/README.md +3 -50
- data/{vendor → app}/assets/javascripts/sugar-development.js +1914 -1225
- data/app/assets/javascripts/sugar-full.js +200 -0
- data/app/assets/javascripts/sugar.js +132 -0
- data/copy_release.sh +4 -7
- data/lib/sugar/rails/version.rb +2 -2
- metadata +16 -58
- data/.rvmrc +0 -1
- data/lib/generators/sugar/build/build_generator.rb +0 -107
- data/lib/generators/sugar/install/install_generator.rb +0 -35
- data/vendor/assets/javascripts/precompiled/development/array.js +0 -1203
- data/vendor/assets/javascripts/precompiled/development/core.js +0 -365
- data/vendor/assets/javascripts/precompiled/development/date.js +0 -2267
- data/vendor/assets/javascripts/precompiled/development/date_locales.js +0 -1179
- data/vendor/assets/javascripts/precompiled/development/date_ranges.js +0 -208
- data/vendor/assets/javascripts/precompiled/development/es5.js +0 -474
- data/vendor/assets/javascripts/precompiled/development/function.js +0 -224
- data/vendor/assets/javascripts/precompiled/development/inflections.js +0 -410
- data/vendor/assets/javascripts/precompiled/development/language.js +0 -383
- data/vendor/assets/javascripts/precompiled/development/number.js +0 -428
- data/vendor/assets/javascripts/precompiled/development/object.js +0 -419
- data/vendor/assets/javascripts/precompiled/development/regexp.js +0 -92
- data/vendor/assets/javascripts/precompiled/development/string.js +0 -894
- data/vendor/assets/javascripts/precompiled/minified/array.js +0 -18
- data/vendor/assets/javascripts/precompiled/minified/core.js +0 -9
- data/vendor/assets/javascripts/precompiled/minified/date.js +0 -44
- data/vendor/assets/javascripts/precompiled/minified/date_locales.js +0 -49
- data/vendor/assets/javascripts/precompiled/minified/date_ranges.js +0 -4
- data/vendor/assets/javascripts/precompiled/minified/es5.js +0 -8
- data/vendor/assets/javascripts/precompiled/minified/function.js +0 -4
- data/vendor/assets/javascripts/precompiled/minified/inflections.js +0 -11
- data/vendor/assets/javascripts/precompiled/minified/language.js +0 -19
- data/vendor/assets/javascripts/precompiled/minified/number.js +0 -5
- data/vendor/assets/javascripts/precompiled/minified/object.js +0 -6
- data/vendor/assets/javascripts/precompiled/minified/regexp.js +0 -2
- data/vendor/assets/javascripts/precompiled/minified/string.js +0 -12
- data/vendor/assets/javascripts/precompiled/readme.txt +0 -3
- data/vendor/assets/javascripts/sugar-full.js +0 -199
- data/vendor/assets/javascripts/sugar.js +0 -120
@@ -1,208 +0,0 @@
|
|
1
|
-
|
2
|
-
/***
|
3
|
-
* @package DateRange
|
4
|
-
* @dependency date
|
5
|
-
* @description Date Ranges define a range of time. They can enumerate over specific points within that range, and be manipulated and compared.
|
6
|
-
*
|
7
|
-
***/
|
8
|
-
|
9
|
-
var DateRange = function(start, end) {
|
10
|
-
this.start = date.create(start);
|
11
|
-
this.end = date.create(end);
|
12
|
-
};
|
13
|
-
|
14
|
-
// 'toString' doesn't appear in a for..in loop in IE even though
|
15
|
-
// hasOwnProperty reports true, so extend() can't be used here.
|
16
|
-
// Also tried simply setting the prototype = {} up front for all
|
17
|
-
// methods but GCC very oddly started dropping properties in the
|
18
|
-
// object randomly (maybe because of the global scope?) hence
|
19
|
-
// the need for the split logic here.
|
20
|
-
DateRange.prototype.toString = function() {
|
21
|
-
/***
|
22
|
-
* @method toString()
|
23
|
-
* @returns String
|
24
|
-
* @short Returns a string representation of the DateRange.
|
25
|
-
* @example
|
26
|
-
*
|
27
|
-
* Date.range('2003', '2005').toString() -> January 1, 2003..January 1, 2005
|
28
|
-
*
|
29
|
-
***/
|
30
|
-
return this.isValid() ? this.start.full() + '..' + this.end.full() : 'Invalid DateRange';
|
31
|
-
};
|
32
|
-
|
33
|
-
extend(DateRange, true, false, {
|
34
|
-
|
35
|
-
/***
|
36
|
-
* @method isValid()
|
37
|
-
* @returns Boolean
|
38
|
-
* @short Returns true if the DateRange is valid, false otherwise.
|
39
|
-
* @example
|
40
|
-
*
|
41
|
-
* Date.range('2003', '2005').isValid() -> true
|
42
|
-
* Date.range('2005', '2003').isValid() -> false
|
43
|
-
*
|
44
|
-
***/
|
45
|
-
'isValid': function() {
|
46
|
-
return this.start < this.end;
|
47
|
-
},
|
48
|
-
|
49
|
-
/***
|
50
|
-
* @method duration()
|
51
|
-
* @returns Number
|
52
|
-
* @short Return the duration of the DateRange in milliseconds.
|
53
|
-
* @example
|
54
|
-
*
|
55
|
-
* Date.range('2003', '2005').duration() -> 94694400000
|
56
|
-
*
|
57
|
-
***/
|
58
|
-
'duration': function() {
|
59
|
-
return this.isValid() ? this.end.getTime() - this.start.getTime() : NaN;
|
60
|
-
},
|
61
|
-
|
62
|
-
/***
|
63
|
-
* @method contains(<d>)
|
64
|
-
* @returns Boolean
|
65
|
-
* @short Returns true if <d> is contained inside the DateRange. <d> may be a date or another DateRange.
|
66
|
-
* @example
|
67
|
-
*
|
68
|
-
* Date.range('2003', '2005').contains(Date.create('2004')) -> true
|
69
|
-
*
|
70
|
-
***/
|
71
|
-
'contains': function(obj) {
|
72
|
-
var self = this, arr = obj.start && obj.end ? [obj.start, obj.end] : [obj];
|
73
|
-
return arr.every(function(d) {
|
74
|
-
return d >= self.start && d <= self.end;
|
75
|
-
});
|
76
|
-
},
|
77
|
-
|
78
|
-
/***
|
79
|
-
* @method every(<increment>, [fn])
|
80
|
-
* @returns Array
|
81
|
-
* @short Iterates through the DateRange for every <increment>, calling [fn] if it is passed. Returns an array of each increment visited.
|
82
|
-
* @extra When <increment> is a number, increments will be to the exact millisecond. <increment> can also be a string in the format %{number} {unit}s%, in which case it will increment in the unit specified. Note that a discrepancy exists in the case of months, as %(2).months()% is an approximation. Stepping through the actual months by passing %"2 months"% is usually preferable in this case.
|
83
|
-
* @example
|
84
|
-
*
|
85
|
-
* Date.range('2003-01', '2003-03').every("2 months") -> [...]
|
86
|
-
*
|
87
|
-
***/
|
88
|
-
'every': function(increment, fn) {
|
89
|
-
var current = this.start.clone(), result = [], index = 0, params, isDay;
|
90
|
-
if(isString(increment)) {
|
91
|
-
current.advance(getDateParamsFromString(increment, 0), true);
|
92
|
-
params = getDateParamsFromString(increment);
|
93
|
-
isDay = increment.toLowerCase() === 'day';
|
94
|
-
} else {
|
95
|
-
params = { 'milliseconds': increment };
|
96
|
-
}
|
97
|
-
while(current <= this.end) {
|
98
|
-
result.push(current);
|
99
|
-
if(fn) fn(current, index);
|
100
|
-
if(isDay && callDateGet(current, 'Hours') === 23) {
|
101
|
-
// When DST traversal happens at 00:00 hours, the time is effectively
|
102
|
-
// pushed back to 23:00, meaning 1) 00:00 for that day does not exist,
|
103
|
-
// and 2) there is no difference between 23:00 and 00:00, as you are
|
104
|
-
// "jumping" around in time. Hours here will be reset before the date
|
105
|
-
// is advanced and the date will never in fact advance, so set the hours
|
106
|
-
// directly ahead to the next day to avoid this problem.
|
107
|
-
current = current.clone();
|
108
|
-
callDateSet(current, 'Hours', 48);
|
109
|
-
} else {
|
110
|
-
current = current.clone().advance(params, true);
|
111
|
-
}
|
112
|
-
index++;
|
113
|
-
}
|
114
|
-
return result;
|
115
|
-
},
|
116
|
-
|
117
|
-
/***
|
118
|
-
* @method union(<range>)
|
119
|
-
* @returns DateRange
|
120
|
-
* @short Returns a new DateRange with the earliest starting point as its start, and the latest ending point as its end. If the two ranges do not intersect this will effectively remove the "gap" between them.
|
121
|
-
* @example
|
122
|
-
*
|
123
|
-
* Date.range('2003=01', '2005-01').union(Date.range('2004-01', '2006-01')) -> Jan 1, 2003..Jan 1, 2006
|
124
|
-
*
|
125
|
-
***/
|
126
|
-
'union': function(range) {
|
127
|
-
return new DateRange(
|
128
|
-
this.start < range.start ? this.start : range.start,
|
129
|
-
this.end > range.end ? this.end : range.end
|
130
|
-
);
|
131
|
-
},
|
132
|
-
|
133
|
-
/***
|
134
|
-
* @method intersect(<range>)
|
135
|
-
* @returns DateRange
|
136
|
-
* @short Returns a new DateRange with the latest starting point as its start, and the earliest ending point as its end. If the two ranges do not intersect this will effectively produce an invalid range.
|
137
|
-
* @example
|
138
|
-
*
|
139
|
-
* Date.range('2003-01', '2005-01').intersect(Date.range('2004-01', '2006-01')) -> Jan 1, 2004..Jan 1, 2005
|
140
|
-
*
|
141
|
-
***/
|
142
|
-
'intersect': function(range) {
|
143
|
-
return new DateRange(
|
144
|
-
this.start > range.start ? this.start : range.start,
|
145
|
-
this.end < range.end ? this.end : range.end
|
146
|
-
);
|
147
|
-
},
|
148
|
-
|
149
|
-
/***
|
150
|
-
* @method clone()
|
151
|
-
* @returns DateRange
|
152
|
-
* @short Clones the DateRange.
|
153
|
-
* @example
|
154
|
-
*
|
155
|
-
* Date.range('2003-01', '2005-01').intersect(Date.range('2004-01', '2006-01')) -> Jan 1, 2004..Jan 1, 2005
|
156
|
-
*
|
157
|
-
***/
|
158
|
-
'clone': function(range) {
|
159
|
-
return new DateRange(this.start, this.end);
|
160
|
-
}
|
161
|
-
|
162
|
-
});
|
163
|
-
|
164
|
-
/***
|
165
|
-
* @method each[Unit]([fn])
|
166
|
-
* @returns Date
|
167
|
-
* @short Increments through the date range for each [unit], calling [fn] if it is passed. Returns an array of each increment visited.
|
168
|
-
*
|
169
|
-
* @set
|
170
|
-
* eachMillisecond
|
171
|
-
* eachSecond
|
172
|
-
* eachMinute
|
173
|
-
* eachHour
|
174
|
-
* eachDay
|
175
|
-
* eachWeek
|
176
|
-
* eachMonth
|
177
|
-
* eachYear
|
178
|
-
*
|
179
|
-
* @example
|
180
|
-
*
|
181
|
-
* Date.range('2003-01', '2003-02').eachMonth() -> [...]
|
182
|
-
* Date.range('2003-01-15', '2003-01-16').eachDay() -> [...]
|
183
|
-
*
|
184
|
-
***/
|
185
|
-
extendSimilar(DateRange, true, false, 'Millisecond,Second,Minute,Hour,Day,Week,Month,Year', function(methods, name) {
|
186
|
-
methods['each' + name] = function(fn) { return this.every(name, fn); }
|
187
|
-
});
|
188
|
-
|
189
|
-
|
190
|
-
/***
|
191
|
-
* Date module
|
192
|
-
***/
|
193
|
-
|
194
|
-
extend(date, false, false, {
|
195
|
-
|
196
|
-
/***
|
197
|
-
* @method Date.range([start], [end])
|
198
|
-
* @returns DateRange
|
199
|
-
* @short Creates a new date range.
|
200
|
-
* @extra If either [start] or [end] are null, they will default to the current date.
|
201
|
-
*
|
202
|
-
***/
|
203
|
-
'range': function(start, end) {
|
204
|
-
return new DateRange(start, end);
|
205
|
-
}
|
206
|
-
|
207
|
-
});
|
208
|
-
|
@@ -1,474 +0,0 @@
|
|
1
|
-
|
2
|
-
|
3
|
-
/***
|
4
|
-
* @package ES5
|
5
|
-
* @description Shim methods that provide ES5 compatible functionality. This package can be excluded if you do not require legacy browser support (IE8 and below).
|
6
|
-
*
|
7
|
-
***/
|
8
|
-
|
9
|
-
|
10
|
-
/***
|
11
|
-
* Object module
|
12
|
-
*
|
13
|
-
***/
|
14
|
-
|
15
|
-
extend(object, false, false, {
|
16
|
-
|
17
|
-
'keys': function(obj) {
|
18
|
-
var keys = [];
|
19
|
-
if(!isObjectPrimitive(obj) && !isRegExp(obj) && !isFunction(obj)) {
|
20
|
-
throw new TypeError('Object required');
|
21
|
-
}
|
22
|
-
iterateOverObject(obj, function(key, value) {
|
23
|
-
keys.push(key);
|
24
|
-
});
|
25
|
-
return keys;
|
26
|
-
}
|
27
|
-
|
28
|
-
});
|
29
|
-
|
30
|
-
|
31
|
-
/***
|
32
|
-
* Array module
|
33
|
-
*
|
34
|
-
***/
|
35
|
-
|
36
|
-
// ECMA5 methods
|
37
|
-
|
38
|
-
function arrayIndexOf(arr, search, fromIndex, increment) {
|
39
|
-
var length = arr.length,
|
40
|
-
fromRight = increment == -1,
|
41
|
-
start = fromRight ? length - 1 : 0,
|
42
|
-
index = toIntegerWithDefault(fromIndex, start);
|
43
|
-
if(index < 0) {
|
44
|
-
index = length + index;
|
45
|
-
}
|
46
|
-
if((!fromRight && index < 0) || (fromRight && index >= length)) {
|
47
|
-
index = start;
|
48
|
-
}
|
49
|
-
while((fromRight && index >= 0) || (!fromRight && index < length)) {
|
50
|
-
if(arr[index] === search) {
|
51
|
-
return index;
|
52
|
-
}
|
53
|
-
index += increment;
|
54
|
-
}
|
55
|
-
return -1;
|
56
|
-
}
|
57
|
-
|
58
|
-
function arrayReduce(arr, fn, initialValue, fromRight) {
|
59
|
-
var length = arr.length, count = 0, defined = isDefined(initialValue), result, index;
|
60
|
-
checkCallback(fn);
|
61
|
-
if(length == 0 && !defined) {
|
62
|
-
throw new TypeError('Reduce called on empty array with no initial value');
|
63
|
-
} else if(defined) {
|
64
|
-
result = initialValue;
|
65
|
-
} else {
|
66
|
-
result = arr[fromRight ? length - 1 : count];
|
67
|
-
count++;
|
68
|
-
}
|
69
|
-
while(count < length) {
|
70
|
-
index = fromRight ? length - count - 1 : count;
|
71
|
-
if(index in arr) {
|
72
|
-
result = fn(result, arr[index], index, arr);
|
73
|
-
}
|
74
|
-
count++;
|
75
|
-
}
|
76
|
-
return result;
|
77
|
-
}
|
78
|
-
|
79
|
-
function toIntegerWithDefault(i, d) {
|
80
|
-
if(isNaN(i)) {
|
81
|
-
return d;
|
82
|
-
} else {
|
83
|
-
return parseInt(i >> 0);
|
84
|
-
}
|
85
|
-
}
|
86
|
-
|
87
|
-
function checkFirstArgumentExists(args) {
|
88
|
-
if(args.length === 0) {
|
89
|
-
throw new TypeError('First argument must be defined');
|
90
|
-
}
|
91
|
-
}
|
92
|
-
|
93
|
-
|
94
|
-
|
95
|
-
|
96
|
-
extend(array, false, false, {
|
97
|
-
|
98
|
-
/***
|
99
|
-
*
|
100
|
-
* @method Array.isArray(<obj>)
|
101
|
-
* @returns Boolean
|
102
|
-
* @short Returns true if <obj> is an Array.
|
103
|
-
* @extra This method is provided for browsers that don't support it internally.
|
104
|
-
* @example
|
105
|
-
*
|
106
|
-
* Array.isArray(3) -> false
|
107
|
-
* Array.isArray(true) -> false
|
108
|
-
* Array.isArray('wasabi') -> false
|
109
|
-
* Array.isArray([1,2,3]) -> true
|
110
|
-
*
|
111
|
-
***/
|
112
|
-
'isArray': function(obj) {
|
113
|
-
return isArray(obj);
|
114
|
-
}
|
115
|
-
|
116
|
-
});
|
117
|
-
|
118
|
-
|
119
|
-
extend(array, true, false, {
|
120
|
-
|
121
|
-
/***
|
122
|
-
* @method every(<f>, [scope])
|
123
|
-
* @returns Boolean
|
124
|
-
* @short Returns true if all elements in the array match <f>.
|
125
|
-
* @extra [scope] is the %this% object. %all% is provided an alias. In addition to providing this method for browsers that don't support it natively, this method also implements @array_matching.
|
126
|
-
* @example
|
127
|
-
*
|
128
|
-
+ ['a','a','a'].every(function(n) {
|
129
|
-
* return n == 'a';
|
130
|
-
* });
|
131
|
-
* ['a','a','a'].every('a') -> true
|
132
|
-
* [{a:2},{a:2}].every({a:2}) -> true
|
133
|
-
***/
|
134
|
-
'every': function(fn, scope) {
|
135
|
-
var length = this.length, index = 0;
|
136
|
-
checkFirstArgumentExists(arguments);
|
137
|
-
while(index < length) {
|
138
|
-
if(index in this && !fn.call(scope, this[index], index, this)) {
|
139
|
-
return false;
|
140
|
-
}
|
141
|
-
index++;
|
142
|
-
}
|
143
|
-
return true;
|
144
|
-
},
|
145
|
-
|
146
|
-
/***
|
147
|
-
* @method some(<f>, [scope])
|
148
|
-
* @returns Boolean
|
149
|
-
* @short Returns true if any element in the array matches <f>.
|
150
|
-
* @extra [scope] is the %this% object. %any% is provided as an alias. In addition to providing this method for browsers that don't support it natively, this method also implements @array_matching.
|
151
|
-
* @example
|
152
|
-
*
|
153
|
-
+ ['a','b','c'].some(function(n) {
|
154
|
-
* return n == 'a';
|
155
|
-
* });
|
156
|
-
+ ['a','b','c'].some(function(n) {
|
157
|
-
* return n == 'd';
|
158
|
-
* });
|
159
|
-
* ['a','b','c'].some('a') -> true
|
160
|
-
* [{a:2},{b:5}].some({a:2}) -> true
|
161
|
-
***/
|
162
|
-
'some': function(fn, scope) {
|
163
|
-
var length = this.length, index = 0;
|
164
|
-
checkFirstArgumentExists(arguments);
|
165
|
-
while(index < length) {
|
166
|
-
if(index in this && fn.call(scope, this[index], index, this)) {
|
167
|
-
return true;
|
168
|
-
}
|
169
|
-
index++;
|
170
|
-
}
|
171
|
-
return false;
|
172
|
-
},
|
173
|
-
|
174
|
-
/***
|
175
|
-
* @method map(<map>, [scope])
|
176
|
-
* @returns Array
|
177
|
-
* @short Maps the array to another array containing the values that are the result of calling <map> on each element.
|
178
|
-
* @extra [scope] is the %this% object. In addition to providing this method for browsers that don't support it natively, this enhanced method also directly accepts a string, which is a shortcut for a function that gets that property (or invokes a function) on each element.
|
179
|
-
* @example
|
180
|
-
*
|
181
|
-
+ [1,2,3].map(function(n) {
|
182
|
-
* return n * 3;
|
183
|
-
* }); -> [3,6,9]
|
184
|
-
* ['one','two','three'].map(function(n) {
|
185
|
-
* return n.length;
|
186
|
-
* }); -> [3,3,5]
|
187
|
-
* ['one','two','three'].map('length') -> [3,3,5]
|
188
|
-
***/
|
189
|
-
'map': function(fn, scope) {
|
190
|
-
var length = this.length, index = 0, result = new Array(length);
|
191
|
-
checkFirstArgumentExists(arguments);
|
192
|
-
while(index < length) {
|
193
|
-
if(index in this) {
|
194
|
-
result[index] = fn.call(scope, this[index], index, this);
|
195
|
-
}
|
196
|
-
index++;
|
197
|
-
}
|
198
|
-
return result;
|
199
|
-
},
|
200
|
-
|
201
|
-
/***
|
202
|
-
* @method filter(<f>, [scope])
|
203
|
-
* @returns Array
|
204
|
-
* @short Returns any elements in the array that match <f>.
|
205
|
-
* @extra [scope] is the %this% object. In addition to providing this method for browsers that don't support it natively, this method also implements @array_matching.
|
206
|
-
* @example
|
207
|
-
*
|
208
|
-
+ [1,2,3].filter(function(n) {
|
209
|
-
* return n > 1;
|
210
|
-
* });
|
211
|
-
* [1,2,2,4].filter(2) -> 2
|
212
|
-
*
|
213
|
-
***/
|
214
|
-
'filter': function(fn, scope) {
|
215
|
-
var length = this.length, index = 0, result = [];
|
216
|
-
checkFirstArgumentExists(arguments);
|
217
|
-
while(index < length) {
|
218
|
-
if(index in this && fn.call(scope, this[index], index, this)) {
|
219
|
-
result.push(this[index]);
|
220
|
-
}
|
221
|
-
index++;
|
222
|
-
}
|
223
|
-
return result;
|
224
|
-
},
|
225
|
-
|
226
|
-
/***
|
227
|
-
* @method indexOf(<search>, [fromIndex])
|
228
|
-
* @returns Number
|
229
|
-
* @short Searches the array and returns the first index where <search> occurs, or -1 if the element is not found.
|
230
|
-
* @extra [fromIndex] is the index from which to begin the search. This method performs a simple strict equality comparison on <search>. It does not support enhanced functionality such as searching the contents against a regex, callback, or deep comparison of objects. For such functionality, use the %findIndex% method instead.
|
231
|
-
* @example
|
232
|
-
*
|
233
|
-
* [1,2,3].indexOf(3) -> 1
|
234
|
-
* [1,2,3].indexOf(7) -> -1
|
235
|
-
*
|
236
|
-
***/
|
237
|
-
'indexOf': function(search, fromIndex) {
|
238
|
-
if(isString(this)) return this.indexOf(search, fromIndex);
|
239
|
-
return arrayIndexOf(this, search, fromIndex, 1);
|
240
|
-
},
|
241
|
-
|
242
|
-
/***
|
243
|
-
* @method lastIndexOf(<search>, [fromIndex])
|
244
|
-
* @returns Number
|
245
|
-
* @short Searches the array and returns the last index where <search> occurs, or -1 if the element is not found.
|
246
|
-
* @extra [fromIndex] is the index from which to begin the search. This method performs a simple strict equality comparison on <search>.
|
247
|
-
* @example
|
248
|
-
*
|
249
|
-
* [1,2,1].lastIndexOf(1) -> 2
|
250
|
-
* [1,2,1].lastIndexOf(7) -> -1
|
251
|
-
*
|
252
|
-
***/
|
253
|
-
'lastIndexOf': function(search, fromIndex) {
|
254
|
-
if(isString(this)) return this.lastIndexOf(search, fromIndex);
|
255
|
-
return arrayIndexOf(this, search, fromIndex, -1);
|
256
|
-
},
|
257
|
-
|
258
|
-
/***
|
259
|
-
* @method forEach([fn], [scope])
|
260
|
-
* @returns Nothing
|
261
|
-
* @short Iterates over the array, calling [fn] on each loop.
|
262
|
-
* @extra This method is only provided for those browsers that do not support it natively. [scope] becomes the %this% object.
|
263
|
-
* @example
|
264
|
-
*
|
265
|
-
* ['a','b','c'].forEach(function(a) {
|
266
|
-
* // Called 3 times: 'a','b','c'
|
267
|
-
* });
|
268
|
-
*
|
269
|
-
***/
|
270
|
-
'forEach': function(fn, scope) {
|
271
|
-
var length = this.length, index = 0;
|
272
|
-
checkCallback(fn);
|
273
|
-
while(index < length) {
|
274
|
-
if(index in this) {
|
275
|
-
fn.call(scope, this[index], index, this);
|
276
|
-
}
|
277
|
-
index++;
|
278
|
-
}
|
279
|
-
},
|
280
|
-
|
281
|
-
/***
|
282
|
-
* @method reduce(<fn>, [init])
|
283
|
-
* @returns Mixed
|
284
|
-
* @short Reduces the array to a single result.
|
285
|
-
* @extra If [init] is passed as a starting value, that value will be passed as the first argument to the callback. The second argument will be the first element in the array. From that point, the result of the callback will then be used as the first argument of the next iteration. This is often refered to as "accumulation", and [init] is often called an "accumulator". If [init] is not passed, then <fn> will be called n - 1 times, where n is the length of the array. In this case, on the first iteration only, the first argument will be the first element of the array, and the second argument will be the second. After that callbacks work as normal, using the result of the previous callback as the first argument of the next. This method is only provided for those browsers that do not support it natively.
|
286
|
-
*
|
287
|
-
* @example
|
288
|
-
*
|
289
|
-
+ [1,2,3,4].reduce(function(a, b) {
|
290
|
-
* return a - b;
|
291
|
-
* });
|
292
|
-
+ [1,2,3,4].reduce(function(a, b) {
|
293
|
-
* return a - b;
|
294
|
-
* }, 100);
|
295
|
-
*
|
296
|
-
***/
|
297
|
-
'reduce': function(fn, init) {
|
298
|
-
return arrayReduce(this, fn, init);
|
299
|
-
},
|
300
|
-
|
301
|
-
/***
|
302
|
-
* @method reduceRight([fn], [init])
|
303
|
-
* @returns Mixed
|
304
|
-
* @short Identical to %Array#reduce%, but operates on the elements in reverse order.
|
305
|
-
* @extra This method is only provided for those browsers that do not support it natively.
|
306
|
-
*
|
307
|
-
*
|
308
|
-
*
|
309
|
-
*
|
310
|
-
* @example
|
311
|
-
*
|
312
|
-
+ [1,2,3,4].reduceRight(function(a, b) {
|
313
|
-
* return a - b;
|
314
|
-
* });
|
315
|
-
*
|
316
|
-
***/
|
317
|
-
'reduceRight': function(fn, init) {
|
318
|
-
return arrayReduce(this, fn, init, true);
|
319
|
-
}
|
320
|
-
|
321
|
-
|
322
|
-
});
|
323
|
-
|
324
|
-
|
325
|
-
|
326
|
-
|
327
|
-
/***
|
328
|
-
* String module
|
329
|
-
*
|
330
|
-
***/
|
331
|
-
|
332
|
-
|
333
|
-
function buildTrim() {
|
334
|
-
var support = getTrimmableCharacters().match(/^\s+$/);
|
335
|
-
try { string.prototype.trim.call([1]); } catch(e) { support = false; }
|
336
|
-
extend(string, true, !support, {
|
337
|
-
|
338
|
-
/***
|
339
|
-
* @method trim[Side]()
|
340
|
-
* @returns String
|
341
|
-
* @short Removes leading and/or trailing whitespace from the string.
|
342
|
-
* @extra Whitespace is defined as line breaks, tabs, and any character in the "Space, Separator" Unicode category, conforming to the the ES5 spec. The standard %trim% method is only added when not fully supported natively.
|
343
|
-
*
|
344
|
-
* @set
|
345
|
-
* trim
|
346
|
-
* trimLeft
|
347
|
-
* trimRight
|
348
|
-
*
|
349
|
-
* @example
|
350
|
-
*
|
351
|
-
* ' wasabi '.trim() -> 'wasabi'
|
352
|
-
* ' wasabi '.trimLeft() -> 'wasabi '
|
353
|
-
* ' wasabi '.trimRight() -> ' wasabi'
|
354
|
-
*
|
355
|
-
***/
|
356
|
-
'trim': function() {
|
357
|
-
return this.toString().trimLeft().trimRight();
|
358
|
-
},
|
359
|
-
|
360
|
-
'trimLeft': function() {
|
361
|
-
return this.replace(regexp('^['+getTrimmableCharacters()+']+'), '');
|
362
|
-
},
|
363
|
-
|
364
|
-
'trimRight': function() {
|
365
|
-
return this.replace(regexp('['+getTrimmableCharacters()+']+$'), '');
|
366
|
-
}
|
367
|
-
});
|
368
|
-
}
|
369
|
-
|
370
|
-
|
371
|
-
|
372
|
-
/***
|
373
|
-
* Function module
|
374
|
-
*
|
375
|
-
***/
|
376
|
-
|
377
|
-
|
378
|
-
extend(Function, true, false, {
|
379
|
-
|
380
|
-
/***
|
381
|
-
* @method bind(<scope>, [arg1], ...)
|
382
|
-
* @returns Function
|
383
|
-
* @short Binds <scope> as the %this% object for the function when it is called. Also allows currying an unlimited number of parameters.
|
384
|
-
* @extra "currying" means setting parameters ([arg1], [arg2], etc.) ahead of time so that they are passed when the function is called later. If you pass additional parameters when the function is actually called, they will be added will be added to the end of the curried parameters. This method is provided for browsers that don't support it internally.
|
385
|
-
* @example
|
386
|
-
*
|
387
|
-
+ (function() {
|
388
|
-
* return this;
|
389
|
-
* }).bind('woof')(); -> returns 'woof'; function is bound with 'woof' as the this object.
|
390
|
-
* (function(a) {
|
391
|
-
* return a;
|
392
|
-
* }).bind(1, 2)(); -> returns 2; function is bound with 1 as the this object and 2 curried as the first parameter
|
393
|
-
* (function(a, b) {
|
394
|
-
* return a + b;
|
395
|
-
* }).bind(1, 2)(3); -> returns 5; function is bound with 1 as the this object, 2 curied as the first parameter and 3 passed as the second when calling the function
|
396
|
-
*
|
397
|
-
***/
|
398
|
-
'bind': function(scope) {
|
399
|
-
var fn = this, args = multiArgs(arguments).slice(1), nop, bound;
|
400
|
-
if(!isFunction(this)) {
|
401
|
-
throw new TypeError('Function.prototype.bind called on a non-function');
|
402
|
-
}
|
403
|
-
bound = function() {
|
404
|
-
return fn.apply(fn.prototype && this instanceof fn ? this : scope, args.concat(multiArgs(arguments)));
|
405
|
-
}
|
406
|
-
bound.prototype = this.prototype;
|
407
|
-
return bound;
|
408
|
-
}
|
409
|
-
|
410
|
-
});
|
411
|
-
|
412
|
-
/***
|
413
|
-
* Date module
|
414
|
-
*
|
415
|
-
***/
|
416
|
-
|
417
|
-
/***
|
418
|
-
* @method toISOString()
|
419
|
-
* @returns String
|
420
|
-
* @short Formats the string to ISO8601 format.
|
421
|
-
* @extra This will always format as UTC time. Provided for browsers that do not support this method.
|
422
|
-
* @example
|
423
|
-
*
|
424
|
-
* Date.create().toISOString() -> ex. 2011-07-05 12:24:55.528Z
|
425
|
-
*
|
426
|
-
***
|
427
|
-
* @method toJSON()
|
428
|
-
* @returns String
|
429
|
-
* @short Returns a JSON representation of the date.
|
430
|
-
* @extra This is effectively an alias for %toISOString%. Will always return the date in UTC time. Provided for browsers that do not support this method.
|
431
|
-
* @example
|
432
|
-
*
|
433
|
-
* Date.create().toJSON() -> ex. 2011-07-05 12:24:55.528Z
|
434
|
-
*
|
435
|
-
***/
|
436
|
-
|
437
|
-
extend(date, false, false, {
|
438
|
-
|
439
|
-
/***
|
440
|
-
* @method Date.now()
|
441
|
-
* @returns String
|
442
|
-
* @short Returns the number of milliseconds since January 1st, 1970 00:00:00 (UTC time).
|
443
|
-
* @extra Provided for browsers that do not support this method.
|
444
|
-
* @example
|
445
|
-
*
|
446
|
-
* Date.now() -> ex. 1311938296231
|
447
|
-
*
|
448
|
-
***/
|
449
|
-
'now': function() {
|
450
|
-
return new date().getTime();
|
451
|
-
}
|
452
|
-
|
453
|
-
});
|
454
|
-
|
455
|
-
function buildISOString() {
|
456
|
-
var d = new date(date.UTC(1999, 11, 31)), target = '1999-12-31T00:00:00.000Z';
|
457
|
-
var support = d.toISOString && d.toISOString() === target;
|
458
|
-
extendSimilar(date, true, !support, 'toISOString,toJSON', function(methods, name) {
|
459
|
-
methods[name] = function() {
|
460
|
-
return padNumber(this.getUTCFullYear(), 4) + '-' +
|
461
|
-
padNumber(this.getUTCMonth() + 1, 2) + '-' +
|
462
|
-
padNumber(this.getUTCDate(), 2) + 'T' +
|
463
|
-
padNumber(this.getUTCHours(), 2) + ':' +
|
464
|
-
padNumber(this.getUTCMinutes(), 2) + ':' +
|
465
|
-
padNumber(this.getUTCSeconds(), 2) + '.' +
|
466
|
-
padNumber(this.getUTCMilliseconds(), 3) + 'Z';
|
467
|
-
}
|
468
|
-
});
|
469
|
-
}
|
470
|
-
|
471
|
-
// Initialize
|
472
|
-
buildTrim();
|
473
|
-
buildISOString();
|
474
|
-
|