sugar-rails 1.3.0 → 1.3.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (25) hide show
  1. data/lib/sugar/rails/version.rb +2 -2
  2. data/vendor/assets/javascripts/precompiled/development/array.js +50 -15
  3. data/vendor/assets/javascripts/precompiled/development/core.js +39 -13
  4. data/vendor/assets/javascripts/precompiled/development/date.js +137 -152
  5. data/vendor/assets/javascripts/precompiled/development/date_ranges.js +22 -10
  6. data/vendor/assets/javascripts/precompiled/development/es5.js +1 -1
  7. data/vendor/assets/javascripts/precompiled/development/function.js +7 -5
  8. data/vendor/assets/javascripts/precompiled/development/object.js +2 -2
  9. data/vendor/assets/javascripts/precompiled/minified/array.js +16 -16
  10. data/vendor/assets/javascripts/precompiled/minified/core.js +9 -8
  11. data/vendor/assets/javascripts/precompiled/minified/date.js +41 -39
  12. data/vendor/assets/javascripts/precompiled/minified/date_locales.js +9 -9
  13. data/vendor/assets/javascripts/precompiled/minified/date_ranges.js +3 -3
  14. data/vendor/assets/javascripts/precompiled/minified/es5.js +8 -7
  15. data/vendor/assets/javascripts/precompiled/minified/function.js +4 -4
  16. data/vendor/assets/javascripts/precompiled/minified/inflections.js +7 -7
  17. data/vendor/assets/javascripts/precompiled/minified/language.js +9 -9
  18. data/vendor/assets/javascripts/precompiled/minified/number.js +5 -5
  19. data/vendor/assets/javascripts/precompiled/minified/object.js +6 -6
  20. data/vendor/assets/javascripts/precompiled/minified/regexp.js +2 -2
  21. data/vendor/assets/javascripts/precompiled/minified/string.js +12 -12
  22. data/vendor/assets/javascripts/sugar-development.js +259 -199
  23. data/vendor/assets/javascripts/sugar-full.js +132 -128
  24. data/vendor/assets/javascripts/sugar.js +107 -103
  25. metadata +4 -4
@@ -1,6 +1,6 @@
1
1
  module Sugar
2
2
  module Rails
3
- VERSION = "1.3.0"
4
- SUGARJS_VERSION = "1.3"
3
+ VERSION = "1.3.1"
4
+ SUGARJS_VERSION = "1.3.1"
5
5
  end
6
6
  end
@@ -1,6 +1,5 @@
1
1
 
2
2
 
3
-
4
3
  /***
5
4
  * @package Array
6
5
  * @dependency core
@@ -27,9 +26,9 @@
27
26
  result = false;
28
27
  }
29
28
  });
30
- return object.keys(match).length > 0 && result;
29
+ return result;
31
30
  } else {
32
- return stringify(el) === stringify(match);
31
+ return isEqual(el, match);
33
32
  }
34
33
  }
35
34
 
@@ -97,12 +96,10 @@
97
96
  }
98
97
 
99
98
  function arrayUnique(arr, map) {
100
- var result = [], o = {}, stringified, transformed;
99
+ var result = [], o = {}, transformed;
101
100
  arrayEach(arr, function(el, i) {
102
101
  transformed = map ? transformArgument(el, map, arr, [el, i, arr]) : el;
103
- stringified = stringify(transformed);
104
- if(!arrayObjectExists(o, stringified, el)) {
105
- o[stringified] = transformed;
102
+ if(!checkForElementInHashAndSet(o, transformed)) {
106
103
  result.push(el);
107
104
  }
108
105
  })
@@ -112,15 +109,16 @@
112
109
  function arrayIntersect(arr1, arr2, subtract) {
113
110
  var result = [], o = {};
114
111
  arr2.each(function(el) {
115
- o[stringify(el)] = el;
112
+ checkForElementInHashAndSet(o, el);
116
113
  });
117
114
  arr1.each(function(el) {
118
- var stringified = stringify(el), exists = arrayObjectExists(o, stringified, el);
115
+ var stringified = stringify(el),
116
+ isReference = !objectIsMatchedByValue(el);
119
117
  // Add the result to the array if:
120
118
  // 1. We're subtracting intersections or it doesn't already exist in the result and
121
119
  // 2. It exists in the compared array and we're adding, or it doesn't exist and we're removing.
122
- if(exists != subtract) {
123
- delete o[stringified];
120
+ if(elementExistsInHash(o, stringified, el, isReference) != subtract) {
121
+ discardElementFromHash(o, stringified, el, isReference);
124
122
  result.push(el);
125
123
  }
126
124
  });
@@ -149,10 +147,44 @@
149
147
  return result;
150
148
  }
151
149
 
152
- function arrayObjectExists(hash, stringified, obj) {
153
- return stringified in hash && (typeof obj !== 'function' || obj === hash[stringified]);
150
+ function elementExistsInHash(hash, key, element, isReference) {
151
+ var exists = key in hash;
152
+ if(isReference) {
153
+ if(!hash[key]) {
154
+ hash[key] = [];
155
+ }
156
+ exists = hash[key].indexOf(element) !== -1;
157
+ }
158
+ return exists;
159
+ }
160
+
161
+ function checkForElementInHashAndSet(hash, element) {
162
+ var stringified = stringify(element),
163
+ isReference = !objectIsMatchedByValue(element),
164
+ exists = elementExistsInHash(hash, stringified, element, isReference);
165
+ if(isReference) {
166
+ hash[stringified].push(element);
167
+ } else {
168
+ hash[stringified] = element;
169
+ }
170
+ return exists;
154
171
  }
155
172
 
173
+ function discardElementFromHash(hash, key, element, isReference) {
174
+ var arr, i = 0;
175
+ if(isReference) {
176
+ arr = hash[key];
177
+ while(i < arr.length) {
178
+ if(arr[i] === element) {
179
+ arr.splice(i, 1);
180
+ } else {
181
+ i += 1;
182
+ }
183
+ }
184
+ } else {
185
+ delete hash[key];
186
+ }
187
+ }
156
188
 
157
189
  // Support methods
158
190
 
@@ -341,8 +373,11 @@
341
373
  'create': function() {
342
374
  var result = []
343
375
  multiArgs(arguments, function(a) {
344
- if(a && a.callee) a = multiArgs(a);
345
- result = result.concat(a);
376
+ if(isObjectPrimitive(a)) {
377
+ result = result.concat(array.prototype.slice.call(a));
378
+ } else {
379
+ result.push(a);
380
+ }
346
381
  });
347
382
  return result;
348
383
  }
@@ -16,7 +16,7 @@
16
16
  // native objects. IE8 does not have defineProperies, however, so this check saves a try/catch block.
17
17
  var definePropertySupport = object.defineProperty && object.defineProperties;
18
18
 
19
- // Class initializers and isClass type helpers
19
+ // Class initializers and class helpers
20
20
 
21
21
  var ClassNames = 'Array,Boolean,Date,Function,Number,String,RegExp'.split(',');
22
22
 
@@ -30,12 +30,12 @@
30
30
 
31
31
  function buildClassCheck(type) {
32
32
  return function(obj) {
33
- return isClass(obj, type);
33
+ return className(obj) === '[object '+type+']';
34
34
  }
35
35
  }
36
36
 
37
- function isClass(obj, str) {
38
- return object.prototype.toString.call(obj) === '[object '+str+']';
37
+ function className(obj) {
38
+ return object.prototype.toString.call(obj);
39
39
  }
40
40
 
41
41
  function initializeClasses() {
@@ -141,7 +141,9 @@
141
141
 
142
142
  function isObject(obj) {
143
143
  // === on the constructor is not safe across iframes
144
- return !!obj && isClass(obj, 'Object') && string(obj.constructor) === string(object);
144
+ // 'hasOwnProperty' ensures that the object also inherits
145
+ // from Object, which is false for DOMElements in IE.
146
+ return !!obj && className(obj) === '[object Object]' && 'hasOwnProperty' in obj;
145
147
  }
146
148
 
147
149
  function hasOwnProperty(obj, key) {
@@ -255,16 +257,20 @@
255
257
  // Used by Array#unique and Object.equal
256
258
 
257
259
  function stringify(thing, stack) {
258
- var value, klass, isObject, isArray, arr, i, key, type = typeof thing;
260
+ var type = typeof thing,
261
+ thingIsObject,
262
+ thingIsArray,
263
+ klass, value,
264
+ arr, key, i;
259
265
 
260
266
  // Return quickly if string to save cycles
261
267
  if(type === 'string') return thing;
262
268
 
263
- klass = object.prototype.toString.call(thing)
264
- isObject = klass === '[object Object]';
265
- isArray = klass === '[object Array]';
269
+ klass = object.prototype.toString.call(thing)
270
+ thingIsObject = isObject(thing);
271
+ thingIsArray = klass === '[object Array]';
266
272
 
267
- if(thing != null && isObject || isArray) {
273
+ if(thing != null && thingIsObject || thingIsArray) {
268
274
  // This method for checking for cyclic structures was egregiously stolen from
269
275
  // the ingenious method by @kitcambridge from the Underscore script:
270
276
  // https://github.com/documentcloud/underscore/issues/240
@@ -283,20 +289,40 @@
283
289
  }
284
290
  stack.push(thing);
285
291
  value = string(thing.constructor);
286
- arr = isArray ? thing : object.keys(thing).sort();
292
+ arr = thingIsArray ? thing : object.keys(thing).sort();
287
293
  for(i = 0; i < arr.length; i++) {
288
- key = isArray ? i : arr[i];
294
+ key = thingIsArray ? i : arr[i];
289
295
  value += key + stringify(thing[key], stack);
290
296
  }
291
297
  stack.pop();
292
298
  } else if(1 / thing === -Infinity) {
293
299
  value = '-0';
294
300
  } else {
295
- value = string(thing && thing.valueOf());
301
+ value = string(thing && thing.valueOf ? thing.valueOf() : thing);
296
302
  }
297
303
  return type + klass + value;
298
304
  }
299
305
 
306
+ function isEqual(a, b) {
307
+ if(objectIsMatchedByValue(a) && objectIsMatchedByValue(b)) {
308
+ return stringify(a) === stringify(b);
309
+ } else {
310
+ return a === b;
311
+ }
312
+ }
313
+
314
+ function objectIsMatchedByValue(obj) {
315
+ var klass = className(obj);
316
+ return klass === '[object Date]' ||
317
+ klass === '[object Array]' ||
318
+ klass === '[object String]' ||
319
+ klass === '[object Number]' ||
320
+ klass === '[object RegExp]' ||
321
+ klass === '[object Boolean]' ||
322
+ klass === '[object Arguments]' ||
323
+ isObject(obj);
324
+ }
325
+
300
326
 
301
327
  // Used by Array#at and String#at
302
328