PageRenderTime 32ms CodeModel.GetById 22ms RepoModel.GetById 0ms app.codeStats 1ms

/files/parse/1.2.9/parse.js

https://gitlab.com/Mirros/jsdelivr
JavaScript | 1507 lines | 1123 code | 125 blank | 259 comment | 272 complexity | ecde398a7897d029ce5b0ff07120ce77 MD5 | raw file
  1. /*!
  2. * Parse JavaScript SDK
  3. * Version: 1.2.9
  4. * Built: Tue Aug 13 2013 17:31:35
  5. * http://parse.com
  6. *
  7. * Copyright 2013 Parse, Inc.
  8. * The Parse JavaScript SDK is freely distributable under the MIT license.
  9. *
  10. * Includes: Underscore.js
  11. * Copyright 2009-2012 Jeremy Ashkenas, DocumentCloud Inc.
  12. * Released under the MIT license.
  13. */
  14. (function(root) {
  15. root.Parse = root.Parse || {};
  16. root.Parse.VERSION = "js1.2.9";
  17. }(this));
  18. // Underscore.js 1.4.4
  19. // http://underscorejs.org
  20. // (c) 2009-2013 Jeremy Ashkenas, DocumentCloud Inc.
  21. // Underscore may be freely distributed under the MIT license.
  22. (function() {
  23. // Baseline setup
  24. // --------------
  25. // Establish the root object, `window` in the browser, or `global` on the server.
  26. var root = this;
  27. // Save the previous value of the `_` variable.
  28. var previousUnderscore = root._;
  29. // Establish the object that gets returned to break out of a loop iteration.
  30. var breaker = {};
  31. // Save bytes in the minified (but not gzipped) version:
  32. var ArrayProto = Array.prototype, ObjProto = Object.prototype, FuncProto = Function.prototype;
  33. // Create quick reference variables for speed access to core prototypes.
  34. var push = ArrayProto.push,
  35. slice = ArrayProto.slice,
  36. concat = ArrayProto.concat,
  37. toString = ObjProto.toString,
  38. hasOwnProperty = ObjProto.hasOwnProperty;
  39. // All **ECMAScript 5** native function implementations that we hope to use
  40. // are declared here.
  41. var
  42. nativeForEach = ArrayProto.forEach,
  43. nativeMap = ArrayProto.map,
  44. nativeReduce = ArrayProto.reduce,
  45. nativeReduceRight = ArrayProto.reduceRight,
  46. nativeFilter = ArrayProto.filter,
  47. nativeEvery = ArrayProto.every,
  48. nativeSome = ArrayProto.some,
  49. nativeIndexOf = ArrayProto.indexOf,
  50. nativeLastIndexOf = ArrayProto.lastIndexOf,
  51. nativeIsArray = Array.isArray,
  52. nativeKeys = Object.keys,
  53. nativeBind = FuncProto.bind;
  54. // Create a safe reference to the Underscore object for use below.
  55. var _ = function(obj) {
  56. if (obj instanceof _) return obj;
  57. if (!(this instanceof _)) return new _(obj);
  58. this._wrapped = obj;
  59. };
  60. // Export the Underscore object for **Node.js**, with
  61. // backwards-compatibility for the old `require()` API. If we're in
  62. // the browser, add `_` as a global object via a string identifier,
  63. // for Closure Compiler "advanced" mode.
  64. if (typeof exports !== 'undefined') {
  65. if (typeof module !== 'undefined' && module.exports) {
  66. exports = module.exports = _;
  67. }
  68. exports._ = _;
  69. } else {
  70. root._ = _;
  71. }
  72. // Current version.
  73. _.VERSION = '1.4.4';
  74. // Collection Functions
  75. // --------------------
  76. // The cornerstone, an `each` implementation, aka `forEach`.
  77. // Handles objects with the built-in `forEach`, arrays, and raw objects.
  78. // Delegates to **ECMAScript 5**'s native `forEach` if available.
  79. var each = _.each = _.forEach = function(obj, iterator, context) {
  80. if (obj == null) return;
  81. if (nativeForEach && obj.forEach === nativeForEach) {
  82. obj.forEach(iterator, context);
  83. } else if (obj.length === +obj.length) {
  84. for (var i = 0, l = obj.length; i < l; i++) {
  85. if (iterator.call(context, obj[i], i, obj) === breaker) return;
  86. }
  87. } else {
  88. for (var key in obj) {
  89. if (_.has(obj, key)) {
  90. if (iterator.call(context, obj[key], key, obj) === breaker) return;
  91. }
  92. }
  93. }
  94. };
  95. // Return the results of applying the iterator to each element.
  96. // Delegates to **ECMAScript 5**'s native `map` if available.
  97. _.map = _.collect = function(obj, iterator, context) {
  98. var results = [];
  99. if (obj == null) return results;
  100. if (nativeMap && obj.map === nativeMap) return obj.map(iterator, context);
  101. each(obj, function(value, index, list) {
  102. results[results.length] = iterator.call(context, value, index, list);
  103. });
  104. return results;
  105. };
  106. var reduceError = 'Reduce of empty array with no initial value';
  107. // **Reduce** builds up a single result from a list of values, aka `inject`,
  108. // or `foldl`. Delegates to **ECMAScript 5**'s native `reduce` if available.
  109. _.reduce = _.foldl = _.inject = function(obj, iterator, memo, context) {
  110. var initial = arguments.length > 2;
  111. if (obj == null) obj = [];
  112. if (nativeReduce && obj.reduce === nativeReduce) {
  113. if (context) iterator = _.bind(iterator, context);
  114. return initial ? obj.reduce(iterator, memo) : obj.reduce(iterator);
  115. }
  116. each(obj, function(value, index, list) {
  117. if (!initial) {
  118. memo = value;
  119. initial = true;
  120. } else {
  121. memo = iterator.call(context, memo, value, index, list);
  122. }
  123. });
  124. if (!initial) throw new TypeError(reduceError);
  125. return memo;
  126. };
  127. // The right-associative version of reduce, also known as `foldr`.
  128. // Delegates to **ECMAScript 5**'s native `reduceRight` if available.
  129. _.reduceRight = _.foldr = function(obj, iterator, memo, context) {
  130. var initial = arguments.length > 2;
  131. if (obj == null) obj = [];
  132. if (nativeReduceRight && obj.reduceRight === nativeReduceRight) {
  133. if (context) iterator = _.bind(iterator, context);
  134. return initial ? obj.reduceRight(iterator, memo) : obj.reduceRight(iterator);
  135. }
  136. var length = obj.length;
  137. if (length !== +length) {
  138. var keys = _.keys(obj);
  139. length = keys.length;
  140. }
  141. each(obj, function(value, index, list) {
  142. index = keys ? keys[--length] : --length;
  143. if (!initial) {
  144. memo = obj[index];
  145. initial = true;
  146. } else {
  147. memo = iterator.call(context, memo, obj[index], index, list);
  148. }
  149. });
  150. if (!initial) throw new TypeError(reduceError);
  151. return memo;
  152. };
  153. // Return the first value which passes a truth test. Aliased as `detect`.
  154. _.find = _.detect = function(obj, iterator, context) {
  155. var result;
  156. any(obj, function(value, index, list) {
  157. if (iterator.call(context, value, index, list)) {
  158. result = value;
  159. return true;
  160. }
  161. });
  162. return result;
  163. };
  164. // Return all the elements that pass a truth test.
  165. // Delegates to **ECMAScript 5**'s native `filter` if available.
  166. // Aliased as `select`.
  167. _.filter = _.select = function(obj, iterator, context) {
  168. var results = [];
  169. if (obj == null) return results;
  170. if (nativeFilter && obj.filter === nativeFilter) return obj.filter(iterator, context);
  171. each(obj, function(value, index, list) {
  172. if (iterator.call(context, value, index, list)) results[results.length] = value;
  173. });
  174. return results;
  175. };
  176. // Return all the elements for which a truth test fails.
  177. _.reject = function(obj, iterator, context) {
  178. return _.filter(obj, function(value, index, list) {
  179. return !iterator.call(context, value, index, list);
  180. }, context);
  181. };
  182. // Determine whether all of the elements match a truth test.
  183. // Delegates to **ECMAScript 5**'s native `every` if available.
  184. // Aliased as `all`.
  185. _.every = _.all = function(obj, iterator, context) {
  186. iterator || (iterator = _.identity);
  187. var result = true;
  188. if (obj == null) return result;
  189. if (nativeEvery && obj.every === nativeEvery) return obj.every(iterator, context);
  190. each(obj, function(value, index, list) {
  191. if (!(result = result && iterator.call(context, value, index, list))) return breaker;
  192. });
  193. return !!result;
  194. };
  195. // Determine if at least one element in the object matches a truth test.
  196. // Delegates to **ECMAScript 5**'s native `some` if available.
  197. // Aliased as `any`.
  198. var any = _.some = _.any = function(obj, iterator, context) {
  199. iterator || (iterator = _.identity);
  200. var result = false;
  201. if (obj == null) return result;
  202. if (nativeSome && obj.some === nativeSome) return obj.some(iterator, context);
  203. each(obj, function(value, index, list) {
  204. if (result || (result = iterator.call(context, value, index, list))) return breaker;
  205. });
  206. return !!result;
  207. };
  208. // Determine if the array or object contains a given value (using `===`).
  209. // Aliased as `include`.
  210. _.contains = _.include = function(obj, target) {
  211. if (obj == null) return false;
  212. if (nativeIndexOf && obj.indexOf === nativeIndexOf) return obj.indexOf(target) != -1;
  213. return any(obj, function(value) {
  214. return value === target;
  215. });
  216. };
  217. // Invoke a method (with arguments) on every item in a collection.
  218. _.invoke = function(obj, method) {
  219. var args = slice.call(arguments, 2);
  220. var isFunc = _.isFunction(method);
  221. return _.map(obj, function(value) {
  222. return (isFunc ? method : value[method]).apply(value, args);
  223. });
  224. };
  225. // Convenience version of a common use case of `map`: fetching a property.
  226. _.pluck = function(obj, key) {
  227. return _.map(obj, function(value){ return value[key]; });
  228. };
  229. // Convenience version of a common use case of `filter`: selecting only objects
  230. // containing specific `key:value` pairs.
  231. _.where = function(obj, attrs, first) {
  232. if (_.isEmpty(attrs)) return first ? null : [];
  233. return _[first ? 'find' : 'filter'](obj, function(value) {
  234. for (var key in attrs) {
  235. if (attrs[key] !== value[key]) return false;
  236. }
  237. return true;
  238. });
  239. };
  240. // Convenience version of a common use case of `find`: getting the first object
  241. // containing specific `key:value` pairs.
  242. _.findWhere = function(obj, attrs) {
  243. return _.where(obj, attrs, true);
  244. };
  245. // Return the maximum element or (element-based computation).
  246. // Can't optimize arrays of integers longer than 65,535 elements.
  247. // See: https://bugs.webkit.org/show_bug.cgi?id=80797
  248. _.max = function(obj, iterator, context) {
  249. if (!iterator && _.isArray(obj) && obj[0] === +obj[0] && obj.length < 65535) {
  250. return Math.max.apply(Math, obj);
  251. }
  252. if (!iterator && _.isEmpty(obj)) return -Infinity;
  253. var result = {computed : -Infinity, value: -Infinity};
  254. each(obj, function(value, index, list) {
  255. var computed = iterator ? iterator.call(context, value, index, list) : value;
  256. computed >= result.computed && (result = {value : value, computed : computed});
  257. });
  258. return result.value;
  259. };
  260. // Return the minimum element (or element-based computation).
  261. _.min = function(obj, iterator, context) {
  262. if (!iterator && _.isArray(obj) && obj[0] === +obj[0] && obj.length < 65535) {
  263. return Math.min.apply(Math, obj);
  264. }
  265. if (!iterator && _.isEmpty(obj)) return Infinity;
  266. var result = {computed : Infinity, value: Infinity};
  267. each(obj, function(value, index, list) {
  268. var computed = iterator ? iterator.call(context, value, index, list) : value;
  269. computed < result.computed && (result = {value : value, computed : computed});
  270. });
  271. return result.value;
  272. };
  273. // Shuffle an array.
  274. _.shuffle = function(obj) {
  275. var rand;
  276. var index = 0;
  277. var shuffled = [];
  278. each(obj, function(value) {
  279. rand = _.random(index++);
  280. shuffled[index - 1] = shuffled[rand];
  281. shuffled[rand] = value;
  282. });
  283. return shuffled;
  284. };
  285. // An internal function to generate lookup iterators.
  286. var lookupIterator = function(value) {
  287. return _.isFunction(value) ? value : function(obj){ return obj[value]; };
  288. };
  289. // Sort the object's values by a criterion produced by an iterator.
  290. _.sortBy = function(obj, value, context) {
  291. var iterator = lookupIterator(value);
  292. return _.pluck(_.map(obj, function(value, index, list) {
  293. return {
  294. value : value,
  295. index : index,
  296. criteria : iterator.call(context, value, index, list)
  297. };
  298. }).sort(function(left, right) {
  299. var a = left.criteria;
  300. var b = right.criteria;
  301. if (a !== b) {
  302. if (a > b || a === void 0) return 1;
  303. if (a < b || b === void 0) return -1;
  304. }
  305. return left.index < right.index ? -1 : 1;
  306. }), 'value');
  307. };
  308. // An internal function used for aggregate "group by" operations.
  309. var group = function(obj, value, context, behavior) {
  310. var result = {};
  311. var iterator = lookupIterator(value || _.identity);
  312. each(obj, function(value, index) {
  313. var key = iterator.call(context, value, index, obj);
  314. behavior(result, key, value);
  315. });
  316. return result;
  317. };
  318. // Groups the object's values by a criterion. Pass either a string attribute
  319. // to group by, or a function that returns the criterion.
  320. _.groupBy = function(obj, value, context) {
  321. return group(obj, value, context, function(result, key, value) {
  322. (_.has(result, key) ? result[key] : (result[key] = [])).push(value);
  323. });
  324. };
  325. // Counts instances of an object that group by a certain criterion. Pass
  326. // either a string attribute to count by, or a function that returns the
  327. // criterion.
  328. _.countBy = function(obj, value, context) {
  329. return group(obj, value, context, function(result, key) {
  330. if (!_.has(result, key)) result[key] = 0;
  331. result[key]++;
  332. });
  333. };
  334. // Use a comparator function to figure out the smallest index at which
  335. // an object should be inserted so as to maintain order. Uses binary search.
  336. _.sortedIndex = function(array, obj, iterator, context) {
  337. iterator = iterator == null ? _.identity : lookupIterator(iterator);
  338. var value = iterator.call(context, obj);
  339. var low = 0, high = array.length;
  340. while (low < high) {
  341. var mid = (low + high) >>> 1;
  342. iterator.call(context, array[mid]) < value ? low = mid + 1 : high = mid;
  343. }
  344. return low;
  345. };
  346. // Safely convert anything iterable into a real, live array.
  347. _.toArray = function(obj) {
  348. if (!obj) return [];
  349. if (_.isArray(obj)) return slice.call(obj);
  350. if (obj.length === +obj.length) return _.map(obj, _.identity);
  351. return _.values(obj);
  352. };
  353. // Return the number of elements in an object.
  354. _.size = function(obj) {
  355. if (obj == null) return 0;
  356. return (obj.length === +obj.length) ? obj.length : _.keys(obj).length;
  357. };
  358. // Array Functions
  359. // ---------------
  360. // Get the first element of an array. Passing **n** will return the first N
  361. // values in the array. Aliased as `head` and `take`. The **guard** check
  362. // allows it to work with `_.map`.
  363. _.first = _.head = _.take = function(array, n, guard) {
  364. if (array == null) return void 0;
  365. return (n != null) && !guard ? slice.call(array, 0, n) : array[0];
  366. };
  367. // Returns everything but the last entry of the array. Especially useful on
  368. // the arguments object. Passing **n** will return all the values in
  369. // the array, excluding the last N. The **guard** check allows it to work with
  370. // `_.map`.
  371. _.initial = function(array, n, guard) {
  372. return slice.call(array, 0, array.length - ((n == null) || guard ? 1 : n));
  373. };
  374. // Get the last element of an array. Passing **n** will return the last N
  375. // values in the array. The **guard** check allows it to work with `_.map`.
  376. _.last = function(array, n, guard) {
  377. if (array == null) return void 0;
  378. if ((n != null) && !guard) {
  379. return slice.call(array, Math.max(array.length - n, 0));
  380. } else {
  381. return array[array.length - 1];
  382. }
  383. };
  384. // Returns everything but the first entry of the array. Aliased as `tail` and `drop`.
  385. // Especially useful on the arguments object. Passing an **n** will return
  386. // the rest N values in the array. The **guard**
  387. // check allows it to work with `_.map`.
  388. _.rest = _.tail = _.drop = function(array, n, guard) {
  389. return slice.call(array, (n == null) || guard ? 1 : n);
  390. };
  391. // Trim out all falsy values from an array.
  392. _.compact = function(array) {
  393. return _.filter(array, _.identity);
  394. };
  395. // Internal implementation of a recursive `flatten` function.
  396. var flatten = function(input, shallow, output) {
  397. each(input, function(value) {
  398. if (_.isArray(value)) {
  399. shallow ? push.apply(output, value) : flatten(value, shallow, output);
  400. } else {
  401. output.push(value);
  402. }
  403. });
  404. return output;
  405. };
  406. // Return a completely flattened version of an array.
  407. _.flatten = function(array, shallow) {
  408. return flatten(array, shallow, []);
  409. };
  410. // Return a version of the array that does not contain the specified value(s).
  411. _.without = function(array) {
  412. return _.difference(array, slice.call(arguments, 1));
  413. };
  414. // Produce a duplicate-free version of the array. If the array has already
  415. // been sorted, you have the option of using a faster algorithm.
  416. // Aliased as `unique`.
  417. _.uniq = _.unique = function(array, isSorted, iterator, context) {
  418. if (_.isFunction(isSorted)) {
  419. context = iterator;
  420. iterator = isSorted;
  421. isSorted = false;
  422. }
  423. var initial = iterator ? _.map(array, iterator, context) : array;
  424. var results = [];
  425. var seen = [];
  426. each(initial, function(value, index) {
  427. if (isSorted ? (!index || seen[seen.length - 1] !== value) : !_.contains(seen, value)) {
  428. seen.push(value);
  429. results.push(array[index]);
  430. }
  431. });
  432. return results;
  433. };
  434. // Produce an array that contains the union: each distinct element from all of
  435. // the passed-in arrays.
  436. _.union = function() {
  437. return _.uniq(concat.apply(ArrayProto, arguments));
  438. };
  439. // Produce an array that contains every item shared between all the
  440. // passed-in arrays.
  441. _.intersection = function(array) {
  442. var rest = slice.call(arguments, 1);
  443. return _.filter(_.uniq(array), function(item) {
  444. return _.every(rest, function(other) {
  445. return _.indexOf(other, item) >= 0;
  446. });
  447. });
  448. };
  449. // Take the difference between one array and a number of other arrays.
  450. // Only the elements present in just the first array will remain.
  451. _.difference = function(array) {
  452. var rest = concat.apply(ArrayProto, slice.call(arguments, 1));
  453. return _.filter(array, function(value){ return !_.contains(rest, value); });
  454. };
  455. // Zip together multiple lists into a single array -- elements that share
  456. // an index go together.
  457. _.zip = function() {
  458. var args = slice.call(arguments);
  459. var length = _.max(_.pluck(args, 'length'));
  460. var results = new Array(length);
  461. for (var i = 0; i < length; i++) {
  462. results[i] = _.pluck(args, "" + i);
  463. }
  464. return results;
  465. };
  466. // Converts lists into objects. Pass either a single array of `[key, value]`
  467. // pairs, or two parallel arrays of the same length -- one of keys, and one of
  468. // the corresponding values.
  469. _.object = function(list, values) {
  470. if (list == null) return {};
  471. var result = {};
  472. for (var i = 0, l = list.length; i < l; i++) {
  473. if (values) {
  474. result[list[i]] = values[i];
  475. } else {
  476. result[list[i][0]] = list[i][1];
  477. }
  478. }
  479. return result;
  480. };
  481. // If the browser doesn't supply us with indexOf (I'm looking at you, **MSIE**),
  482. // we need this function. Return the position of the first occurrence of an
  483. // item in an array, or -1 if the item is not included in the array.
  484. // Delegates to **ECMAScript 5**'s native `indexOf` if available.
  485. // If the array is large and already in sort order, pass `true`
  486. // for **isSorted** to use binary search.
  487. _.indexOf = function(array, item, isSorted) {
  488. if (array == null) return -1;
  489. var i = 0, l = array.length;
  490. if (isSorted) {
  491. if (typeof isSorted == 'number') {
  492. i = (isSorted < 0 ? Math.max(0, l + isSorted) : isSorted);
  493. } else {
  494. i = _.sortedIndex(array, item);
  495. return array[i] === item ? i : -1;
  496. }
  497. }
  498. if (nativeIndexOf && array.indexOf === nativeIndexOf) return array.indexOf(item, isSorted);
  499. for (; i < l; i++) if (array[i] === item) return i;
  500. return -1;
  501. };
  502. // Delegates to **ECMAScript 5**'s native `lastIndexOf` if available.
  503. _.lastIndexOf = function(array, item, from) {
  504. if (array == null) return -1;
  505. var hasIndex = from != null;
  506. if (nativeLastIndexOf && array.lastIndexOf === nativeLastIndexOf) {
  507. return hasIndex ? array.lastIndexOf(item, from) : array.lastIndexOf(item);
  508. }
  509. var i = (hasIndex ? from : array.length);
  510. while (i--) if (array[i] === item) return i;
  511. return -1;
  512. };
  513. // Generate an integer Array containing an arithmetic progression. A port of
  514. // the native Python `range()` function. See
  515. // [the Python documentation](http://docs.python.org/library/functions.html#range).
  516. _.range = function(start, stop, step) {
  517. if (arguments.length <= 1) {
  518. stop = start || 0;
  519. start = 0;
  520. }
  521. step = arguments[2] || 1;
  522. var len = Math.max(Math.ceil((stop - start) / step), 0);
  523. var idx = 0;
  524. var range = new Array(len);
  525. while(idx < len) {
  526. range[idx++] = start;
  527. start += step;
  528. }
  529. return range;
  530. };
  531. // Function (ahem) Functions
  532. // ------------------
  533. // Create a function bound to a given object (assigning `this`, and arguments,
  534. // optionally). Delegates to **ECMAScript 5**'s native `Function.bind` if
  535. // available.
  536. _.bind = function(func, context) {
  537. if (func.bind === nativeBind && nativeBind) return nativeBind.apply(func, slice.call(arguments, 1));
  538. var args = slice.call(arguments, 2);
  539. return function() {
  540. return func.apply(context, args.concat(slice.call(arguments)));
  541. };
  542. };
  543. // Partially apply a function by creating a version that has had some of its
  544. // arguments pre-filled, without changing its dynamic `this` context.
  545. _.partial = function(func) {
  546. var args = slice.call(arguments, 1);
  547. return function() {
  548. return func.apply(this, args.concat(slice.call(arguments)));
  549. };
  550. };
  551. // Bind all of an object's methods to that object. Useful for ensuring that
  552. // all callbacks defined on an object belong to it.
  553. _.bindAll = function(obj) {
  554. var funcs = slice.call(arguments, 1);
  555. if (funcs.length === 0) funcs = _.functions(obj);
  556. each(funcs, function(f) { obj[f] = _.bind(obj[f], obj); });
  557. return obj;
  558. };
  559. // Memoize an expensive function by storing its results.
  560. _.memoize = function(func, hasher) {
  561. var memo = {};
  562. hasher || (hasher = _.identity);
  563. return function() {
  564. var key = hasher.apply(this, arguments);
  565. return _.has(memo, key) ? memo[key] : (memo[key] = func.apply(this, arguments));
  566. };
  567. };
  568. // Delays a function for the given number of milliseconds, and then calls
  569. // it with the arguments supplied.
  570. _.delay = function(func, wait) {
  571. var args = slice.call(arguments, 2);
  572. return setTimeout(function(){ return func.apply(null, args); }, wait);
  573. };
  574. // Defers a function, scheduling it to run after the current call stack has
  575. // cleared.
  576. _.defer = function(func) {
  577. return _.delay.apply(_, [func, 1].concat(slice.call(arguments, 1)));
  578. };
  579. // Returns a function, that, when invoked, will only be triggered at most once
  580. // during a given window of time.
  581. _.throttle = function(func, wait) {
  582. var context, args, timeout, result;
  583. var previous = 0;
  584. var later = function() {
  585. previous = new Date;
  586. timeout = null;
  587. result = func.apply(context, args);
  588. };
  589. return function() {
  590. var now = new Date;
  591. var remaining = wait - (now - previous);
  592. context = this;
  593. args = arguments;
  594. if (remaining <= 0) {
  595. clearTimeout(timeout);
  596. timeout = null;
  597. previous = now;
  598. result = func.apply(context, args);
  599. } else if (!timeout) {
  600. timeout = setTimeout(later, remaining);
  601. }
  602. return result;
  603. };
  604. };
  605. // Returns a function, that, as long as it continues to be invoked, will not
  606. // be triggered. The function will be called after it stops being called for
  607. // N milliseconds. If `immediate` is passed, trigger the function on the
  608. // leading edge, instead of the trailing.
  609. _.debounce = function(func, wait, immediate) {
  610. var timeout, result;
  611. return function() {
  612. var context = this, args = arguments;
  613. var later = function() {
  614. timeout = null;
  615. if (!immediate) result = func.apply(context, args);
  616. };
  617. var callNow = immediate && !timeout;
  618. clearTimeout(timeout);
  619. timeout = setTimeout(later, wait);
  620. if (callNow) result = func.apply(context, args);
  621. return result;
  622. };
  623. };
  624. // Returns a function that will be executed at most one time, no matter how
  625. // often you call it. Useful for lazy initialization.
  626. _.once = function(func) {
  627. var ran = false, memo;
  628. return function() {
  629. if (ran) return memo;
  630. ran = true;
  631. memo = func.apply(this, arguments);
  632. func = null;
  633. return memo;
  634. };
  635. };
  636. // Returns the first function passed as an argument to the second,
  637. // allowing you to adjust arguments, run code before and after, and
  638. // conditionally execute the original function.
  639. _.wrap = function(func, wrapper) {
  640. return function() {
  641. var args = [func];
  642. push.apply(args, arguments);
  643. return wrapper.apply(this, args);
  644. };
  645. };
  646. // Returns a function that is the composition of a list of functions, each
  647. // consuming the return value of the function that follows.
  648. _.compose = function() {
  649. var funcs = arguments;
  650. return function() {
  651. var args = arguments;
  652. for (var i = funcs.length - 1; i >= 0; i--) {
  653. args = [funcs[i].apply(this, args)];
  654. }
  655. return args[0];
  656. };
  657. };
  658. // Returns a function that will only be executed after being called N times.
  659. _.after = function(times, func) {
  660. if (times <= 0) return func();
  661. return function() {
  662. if (--times < 1) {
  663. return func.apply(this, arguments);
  664. }
  665. };
  666. };
  667. // Object Functions
  668. // ----------------
  669. // Retrieve the names of an object's properties.
  670. // Delegates to **ECMAScript 5**'s native `Object.keys`
  671. _.keys = nativeKeys || function(obj) {
  672. if (obj !== Object(obj)) throw new TypeError('Invalid object');
  673. var keys = [];
  674. for (var key in obj) if (_.has(obj, key)) keys[keys.length] = key;
  675. return keys;
  676. };
  677. // Retrieve the values of an object's properties.
  678. _.values = function(obj) {
  679. var values = [];
  680. for (var key in obj) if (_.has(obj, key)) values.push(obj[key]);
  681. return values;
  682. };
  683. // Convert an object into a list of `[key, value]` pairs.
  684. _.pairs = function(obj) {
  685. var pairs = [];
  686. for (var key in obj) if (_.has(obj, key)) pairs.push([key, obj[key]]);
  687. return pairs;
  688. };
  689. // Invert the keys and values of an object. The values must be serializable.
  690. _.invert = function(obj) {
  691. var result = {};
  692. for (var key in obj) if (_.has(obj, key)) result[obj[key]] = key;
  693. return result;
  694. };
  695. // Return a sorted list of the function names available on the object.
  696. // Aliased as `methods`
  697. _.functions = _.methods = function(obj) {
  698. var names = [];
  699. for (var key in obj) {
  700. if (_.isFunction(obj[key])) names.push(key);
  701. }
  702. return names.sort();
  703. };
  704. // Extend a given object with all the properties in passed-in object(s).
  705. _.extend = function(obj) {
  706. each(slice.call(arguments, 1), function(source) {
  707. if (source) {
  708. for (var prop in source) {
  709. obj[prop] = source[prop];
  710. }
  711. }
  712. });
  713. return obj;
  714. };
  715. // Return a copy of the object only containing the whitelisted properties.
  716. _.pick = function(obj) {
  717. var copy = {};
  718. var keys = concat.apply(ArrayProto, slice.call(arguments, 1));
  719. each(keys, function(key) {
  720. if (key in obj) copy[key] = obj[key];
  721. });
  722. return copy;
  723. };
  724. // Return a copy of the object without the blacklisted properties.
  725. _.omit = function(obj) {
  726. var copy = {};
  727. var keys = concat.apply(ArrayProto, slice.call(arguments, 1));
  728. for (var key in obj) {
  729. if (!_.contains(keys, key)) copy[key] = obj[key];
  730. }
  731. return copy;
  732. };
  733. // Fill in a given object with default properties.
  734. _.defaults = function(obj) {
  735. each(slice.call(arguments, 1), function(source) {
  736. if (source) {
  737. for (var prop in source) {
  738. if (obj[prop] == null) obj[prop] = source[prop];
  739. }
  740. }
  741. });
  742. return obj;
  743. };
  744. // Create a (shallow-cloned) duplicate of an object.
  745. _.clone = function(obj) {
  746. if (!_.isObject(obj)) return obj;
  747. return _.isArray(obj) ? obj.slice() : _.extend({}, obj);
  748. };
  749. // Invokes interceptor with the obj, and then returns obj.
  750. // The primary purpose of this method is to "tap into" a method chain, in
  751. // order to perform operations on intermediate results within the chain.
  752. _.tap = function(obj, interceptor) {
  753. interceptor(obj);
  754. return obj;
  755. };
  756. // Internal recursive comparison function for `isEqual`.
  757. var eq = function(a, b, aStack, bStack) {
  758. // Identical objects are equal. `0 === -0`, but they aren't identical.
  759. // See the Harmony `egal` proposal: http://wiki.ecmascript.org/doku.php?id=harmony:egal.
  760. if (a === b) return a !== 0 || 1 / a == 1 / b;
  761. // A strict comparison is necessary because `null == undefined`.
  762. if (a == null || b == null) return a === b;
  763. // Unwrap any wrapped objects.
  764. if (a instanceof _) a = a._wrapped;
  765. if (b instanceof _) b = b._wrapped;
  766. // Compare `[[Class]]` names.
  767. var className = toString.call(a);
  768. if (className != toString.call(b)) return false;
  769. switch (className) {
  770. // Strings, numbers, dates, and booleans are compared by value.
  771. case '[object String]':
  772. // Primitives and their corresponding object wrappers are equivalent; thus, `"5"` is
  773. // equivalent to `new String("5")`.
  774. return a == String(b);
  775. case '[object Number]':
  776. // `NaN`s are equivalent, but non-reflexive. An `egal` comparison is performed for
  777. // other numeric values.
  778. return a != +a ? b != +b : (a == 0 ? 1 / a == 1 / b : a == +b);
  779. case '[object Date]':
  780. case '[object Boolean]':
  781. // Coerce dates and booleans to numeric primitive values. Dates are compared by their
  782. // millisecond representations. Note that invalid dates with millisecond representations
  783. // of `NaN` are not equivalent.
  784. return +a == +b;
  785. // RegExps are compared by their source patterns and flags.
  786. case '[object RegExp]':
  787. return a.source == b.source &&
  788. a.global == b.global &&
  789. a.multiline == b.multiline &&
  790. a.ignoreCase == b.ignoreCase;
  791. }
  792. if (typeof a != 'object' || typeof b != 'object') return false;
  793. // Assume equality for cyclic structures. The algorithm for detecting cyclic
  794. // structures is adapted from ES 5.1 section 15.12.3, abstract operation `JO`.
  795. var length = aStack.length;
  796. while (length--) {
  797. // Linear search. Performance is inversely proportional to the number of
  798. // unique nested structures.
  799. if (aStack[length] == a) return bStack[length] == b;
  800. }
  801. // Add the first object to the stack of traversed objects.
  802. aStack.push(a);
  803. bStack.push(b);
  804. var size = 0, result = true;
  805. // Recursively compare objects and arrays.
  806. if (className == '[object Array]') {
  807. // Compare array lengths to determine if a deep comparison is necessary.
  808. size = a.length;
  809. result = size == b.length;
  810. if (result) {
  811. // Deep compare the contents, ignoring non-numeric properties.
  812. while (size--) {
  813. if (!(result = eq(a[size], b[size], aStack, bStack))) break;
  814. }
  815. }
  816. } else {
  817. // Objects with different constructors are not equivalent, but `Object`s
  818. // from different frames are.
  819. var aCtor = a.constructor, bCtor = b.constructor;
  820. if (aCtor !== bCtor && !(_.isFunction(aCtor) && (aCtor instanceof aCtor) &&
  821. _.isFunction(bCtor) && (bCtor instanceof bCtor))) {
  822. return false;
  823. }
  824. // Deep compare objects.
  825. for (var key in a) {
  826. if (_.has(a, key)) {
  827. // Count the expected number of properties.
  828. size++;
  829. // Deep compare each member.
  830. if (!(result = _.has(b, key) && eq(a[key], b[key], aStack, bStack))) break;
  831. }
  832. }
  833. // Ensure that both objects contain the same number of properties.
  834. if (result) {
  835. for (key in b) {
  836. if (_.has(b, key) && !(size--)) break;
  837. }
  838. result = !size;
  839. }
  840. }
  841. // Remove the first object from the stack of traversed objects.
  842. aStack.pop();
  843. bStack.pop();
  844. return result;
  845. };
  846. // Perform a deep comparison to check if two objects are equal.
  847. _.isEqual = function(a, b) {
  848. return eq(a, b, [], []);
  849. };
  850. // Is a given array, string, or object empty?
  851. // An "empty" object has no enumerable own-properties.
  852. _.isEmpty = function(obj) {
  853. if (obj == null) return true;
  854. if (_.isArray(obj) || _.isString(obj)) return obj.length === 0;
  855. for (var key in obj) if (_.has(obj, key)) return false;
  856. return true;
  857. };
  858. // Is a given value a DOM element?
  859. _.isElement = function(obj) {
  860. return !!(obj && obj.nodeType === 1);
  861. };
  862. // Is a given value an array?
  863. // Delegates to ECMA5's native Array.isArray
  864. _.isArray = nativeIsArray || function(obj) {
  865. return toString.call(obj) == '[object Array]';
  866. };
  867. // Is a given variable an object?
  868. _.isObject = function(obj) {
  869. return obj === Object(obj);
  870. };
  871. // Add some isType methods: isArguments, isFunction, isString, isNumber, isDate, isRegExp.
  872. each(['Arguments', 'Function', 'String', 'Number', 'Date', 'RegExp'], function(name) {
  873. _['is' + name] = function(obj) {
  874. return toString.call(obj) == '[object ' + name + ']';
  875. };
  876. });
  877. // Define a fallback version of the method in browsers (ahem, IE), where
  878. // there isn't any inspectable "Arguments" type.
  879. if (!_.isArguments(arguments)) {
  880. _.isArguments = function(obj) {
  881. return !!(obj && _.has(obj, 'callee'));
  882. };
  883. }
  884. // Optimize `isFunction` if appropriate.
  885. if (typeof (/./) !== 'function') {
  886. _.isFunction = function(obj) {
  887. return typeof obj === 'function';
  888. };
  889. }
  890. // Is a given object a finite number?
  891. _.isFinite = function(obj) {
  892. return isFinite(obj) && !isNaN(parseFloat(obj));
  893. };
  894. // Is the given value `NaN`? (NaN is the only number which does not equal itself).
  895. _.isNaN = function(obj) {
  896. return _.isNumber(obj) && obj != +obj;
  897. };
  898. // Is a given value a boolean?
  899. _.isBoolean = function(obj) {
  900. return obj === true || obj === false || toString.call(obj) == '[object Boolean]';
  901. };
  902. // Is a given value equal to null?
  903. _.isNull = function(obj) {
  904. return obj === null;
  905. };
  906. // Is a given variable undefined?
  907. _.isUndefined = function(obj) {
  908. return obj === void 0;
  909. };
  910. // Shortcut function for checking if an object has a given property directly
  911. // on itself (in other words, not on a prototype).
  912. _.has = function(obj, key) {
  913. return hasOwnProperty.call(obj, key);
  914. };
  915. // Utility Functions
  916. // -----------------
  917. // Run Underscore.js in *noConflict* mode, returning the `_` variable to its
  918. // previous owner. Returns a reference to the Underscore object.
  919. _.noConflict = function() {
  920. root._ = previousUnderscore;
  921. return this;
  922. };
  923. // Keep the identity function around for default iterators.
  924. _.identity = function(value) {
  925. return value;
  926. };
  927. // Run a function **n** times.
  928. _.times = function(n, iterator, context) {
  929. var accum = Array(n);
  930. for (var i = 0; i < n; i++) accum[i] = iterator.call(context, i);
  931. return accum;
  932. };
  933. // Return a random integer between min and max (inclusive).
  934. _.random = function(min, max) {
  935. if (max == null) {
  936. max = min;
  937. min = 0;
  938. }
  939. return min + Math.floor(Math.random() * (max - min + 1));
  940. };
  941. // List of HTML entities for escaping.
  942. var entityMap = {
  943. escape: {
  944. '&': '&amp;',
  945. '<': '&lt;',
  946. '>': '&gt;',
  947. '"': '&quot;',
  948. "'": '&#x27;',
  949. '/': '&#x2F;'
  950. }
  951. };
  952. entityMap.unescape = _.invert(entityMap.escape);
  953. // Regexes containing the keys and values listed immediately above.
  954. var entityRegexes = {
  955. escape: new RegExp('[' + _.keys(entityMap.escape).join('') + ']', 'g'),
  956. unescape: new RegExp('(' + _.keys(entityMap.unescape).join('|') + ')', 'g')
  957. };
  958. // Functions for escaping and unescaping strings to/from HTML interpolation.
  959. _.each(['escape', 'unescape'], function(method) {
  960. _[method] = function(string) {
  961. if (string == null) return '';
  962. return ('' + string).replace(entityRegexes[method], function(match) {
  963. return entityMap[method][match];
  964. });
  965. };
  966. });
  967. // If the value of the named property is a function then invoke it;
  968. // otherwise, return it.
  969. _.result = function(object, property) {
  970. if (object == null) return null;
  971. var value = object[property];
  972. return _.isFunction(value) ? value.call(object) : value;
  973. };
  974. // Add your own custom functions to the Underscore object.
  975. _.mixin = function(obj) {
  976. each(_.functions(obj), function(name){
  977. var func = _[name] = obj[name];
  978. _.prototype[name] = function() {
  979. var args = [this._wrapped];
  980. push.apply(args, arguments);
  981. return result.call(this, func.apply(_, args));
  982. };
  983. });
  984. };
  985. // Generate a unique integer id (unique within the entire client session).
  986. // Useful for temporary DOM ids.
  987. var idCounter = 0;
  988. _.uniqueId = function(prefix) {
  989. var id = ++idCounter + '';
  990. return prefix ? prefix + id : id;
  991. };
  992. // By default, Underscore uses ERB-style template delimiters, change the
  993. // following template settings to use alternative delimiters.
  994. _.templateSettings = {
  995. evaluate : /<%([\s\S]+?)%>/g,
  996. interpolate : /<%=([\s\S]+?)%>/g,
  997. escape : /<%-([\s\S]+?)%>/g
  998. };
  999. // When customizing `templateSettings`, if you don't want to define an
  1000. // interpolation, evaluation or escaping regex, we need one that is
  1001. // guaranteed not to match.
  1002. var noMatch = /(.)^/;
  1003. // Certain characters need to be escaped so that they can be put into a
  1004. // string literal.
  1005. var escapes = {
  1006. "'": "'",
  1007. '\\': '\\',
  1008. '\r': 'r',
  1009. '\n': 'n',
  1010. '\t': 't',
  1011. '\u2028': 'u2028',
  1012. '\u2029': 'u2029'
  1013. };
  1014. var escaper = /\\|'|\r|\n|\t|\u2028|\u2029/g;
  1015. // JavaScript micro-templating, similar to John Resig's implementation.
  1016. // Underscore templating handles arbitrary delimiters, preserves whitespace,
  1017. // and correctly escapes quotes within interpolated code.
  1018. _.template = function(text, data, settings) {
  1019. var render;
  1020. settings = _.defaults({}, settings, _.templateSettings);
  1021. // Combine delimiters into one regular expression via alternation.
  1022. var matcher = new RegExp([
  1023. (settings.escape || noMatch).source,
  1024. (settings.interpolate || noMatch).source,
  1025. (settings.evaluate || noMatch).source
  1026. ].join('|') + '|$', 'g');
  1027. // Compile the template source, escaping string literals appropriately.
  1028. var index = 0;
  1029. var source = "__p+='";
  1030. text.replace(matcher, function(match, escape, interpolate, evaluate, offset) {
  1031. source += text.slice(index, offset)
  1032. .replace(escaper, function(match) { return '\\' + escapes[match]; });
  1033. if (escape) {
  1034. source += "'+\n((__t=(" + escape + "))==null?'':_.escape(__t))+\n'";
  1035. }
  1036. if (interpolate) {
  1037. source += "'+\n((__t=(" + interpolate + "))==null?'':__t)+\n'";
  1038. }
  1039. if (evaluate) {
  1040. source += "';\n" + evaluate + "\n__p+='";
  1041. }
  1042. index = offset + match.length;
  1043. return match;
  1044. });
  1045. source += "';\n";
  1046. // If a variable is not specified, place data values in local scope.
  1047. if (!settings.variable) source = 'with(obj||{}){\n' + source + '}\n';
  1048. source = "var __t,__p='',__j=Array.prototype.join," +
  1049. "print=function(){__p+=__j.call(arguments,'');};\n" +
  1050. source + "return __p;\n";
  1051. try {
  1052. render = new Function(settings.variable || 'obj', '_', source);
  1053. } catch (e) {
  1054. e.source = source;
  1055. throw e;
  1056. }
  1057. if (data) return render(data, _);
  1058. var template = function(data) {
  1059. return render.call(this, data, _);
  1060. };
  1061. // Provide the compiled function source as a convenience for precompilation.
  1062. template.source = 'function(' + (settings.variable || 'obj') + '){\n' + source + '}';
  1063. return template;
  1064. };
  1065. // Add a "chain" function, which will delegate to the wrapper.
  1066. _.chain = function(obj) {
  1067. return _(obj).chain();
  1068. };
  1069. // OOP
  1070. // ---------------
  1071. // If Underscore is called as a function, it returns a wrapped object that
  1072. // can be used OO-style. This wrapper holds altered versions of all the
  1073. // underscore functions. Wrapped objects may be chained.
  1074. // Helper function to continue chaining intermediate results.
  1075. var result = function(obj) {
  1076. return this._chain ? _(obj).chain() : obj;
  1077. };
  1078. // Add all of the Underscore functions to the wrapper object.
  1079. _.mixin(_);
  1080. // Add all mutator Array functions to the wrapper.
  1081. each(['pop', 'push', 'reverse', 'shift', 'sort', 'splice', 'unshift'], function(name) {
  1082. var method = ArrayProto[name];
  1083. _.prototype[name] = function() {
  1084. var obj = this._wrapped;
  1085. method.apply(obj, arguments);
  1086. if ((name == 'shift' || name == 'splice') && obj.length === 0) delete obj[0];
  1087. return result.call(this, obj);
  1088. };
  1089. });
  1090. // Add all accessor Array functions to the wrapper.
  1091. each(['concat', 'join', 'slice'], function(name) {
  1092. var method = ArrayProto[name];
  1093. _.prototype[name] = function() {
  1094. return result.call(this, method.apply(this._wrapped, arguments));
  1095. };
  1096. });
  1097. _.extend(_.prototype, {
  1098. // Start chaining a wrapped Underscore object.
  1099. chain: function() {
  1100. this._chain = true;
  1101. return this;
  1102. },
  1103. // Extracts the result from a wrapped and chained object.
  1104. value: function() {
  1105. return this._wrapped;
  1106. }
  1107. });
  1108. }).call(this);
  1109. /*global _: false, $: false, localStorage: false, process: true,
  1110. XMLHttpRequest: false, XDomainRequest: false, exports: false,
  1111. require: false */
  1112. (function(root) {
  1113. root.Parse = root.Parse || {};
  1114. /**
  1115. * Contains all Parse API classes and functions.
  1116. * @name Parse
  1117. * @namespace
  1118. *
  1119. * Contains all Parse API classes and functions.
  1120. */
  1121. var Parse = root.Parse;
  1122. // Import Parse's local copy of underscore.
  1123. if (typeof(exports) !== "undefined" && exports._) {
  1124. // We're running in Node.js. Pull in the dependencies.
  1125. Parse._ = exports._.noConflict();
  1126. Parse.localStorage = require('localStorage');
  1127. Parse.XMLHttpRequest = require('xmlhttprequest').XMLHttpRequest;
  1128. exports.Parse = Parse;
  1129. } else {
  1130. Parse._ = _.noConflict();
  1131. if (typeof(localStorage) !== "undefined") {
  1132. Parse.localStorage = localStorage;
  1133. }
  1134. if (typeof(XMLHttpRequest) !== "undefined") {
  1135. Parse.XMLHttpRequest = XMLHttpRequest;
  1136. }
  1137. }
  1138. // If jQuery or Zepto has been included, grab a reference to it.
  1139. if (typeof($) !== "undefined") {
  1140. Parse.$ = $;
  1141. }
  1142. // Helpers
  1143. // -------
  1144. // Shared empty constructor function to aid in prototype-chain creation.
  1145. var EmptyConstructor = function() {};
  1146. // Helper function to correctly set up the prototype chain, for subclasses.
  1147. // Similar to `goog.inherits`, but uses a hash of prototype properties and
  1148. // class properties to be extended.
  1149. var inherits = function(parent, protoProps, staticProps) {
  1150. var child;
  1151. // The constructor function for the new subclass is either defined by you
  1152. // (the "constructor" property in your `extend` definition), or defaulted
  1153. // by us to simply call the parent's constructor.
  1154. if (protoProps && protoProps.hasOwnProperty('constructor')) {
  1155. child = protoProps.constructor;
  1156. } else {
  1157. /** @ignore */
  1158. child = function(){ parent.apply(this, arguments); };
  1159. }
  1160. // Inherit class (static) properties from parent.
  1161. Parse._.extend(child, parent);
  1162. // Set the prototype chain to inherit from `parent`, without calling
  1163. // `parent`'s constructor function.
  1164. EmptyConstructor.prototype = parent.prototype;
  1165. child.prototype = new EmptyConstructor();
  1166. // Add prototype properties (instance properties) to the subclass,
  1167. // if supplied.
  1168. if (protoProps) {
  1169. Parse._.extend(child.prototype, protoProps);
  1170. }
  1171. // Add static properties to the constructor function, if supplied.
  1172. if (staticProps) {
  1173. Parse._.extend(child, staticProps);
  1174. }
  1175. // Correctly set child's `prototype.constructor`.
  1176. child.prototype.constructor = child;
  1177. // Set a convenience property in case the parent's prototype is
  1178. // needed later.
  1179. child.__super__ = parent.prototype;
  1180. return child;
  1181. };
  1182. // Set the server for Parse to talk to.
  1183. Parse.serverURL = "https://api.parse.com";
  1184. // Check whether we are running in Node.js.
  1185. if (typeof(process) !== "undefined" &&
  1186. process.versions &&
  1187. process.versions.node) {
  1188. Parse._isNode = true;
  1189. }
  1190. /**
  1191. * Call this method first to set up your authentication tokens for Parse.
  1192. * You can get your keys from the Data Browser on parse.com.
  1193. * @param {String} applicationId Your Parse Application ID.
  1194. * @param {String} javaScriptKey Your Parse JavaScript Key.
  1195. * @param {String} masterKey (optional) Your Parse Master Key. (Node.js only!)
  1196. */
  1197. Parse.initialize = function(applicationId, javaScriptKey, masterKey) {
  1198. if (masterKey) {
  1199. throw "Parse.initialize() was passed a Master Key, which is only " +
  1200. "allowed from within Node.js.";
  1201. }
  1202. Parse._initialize(applicationId, javaScriptKey);
  1203. };
  1204. /**
  1205. * Call this method first to set up master authentication tokens for Parse.
  1206. * This method is for Parse's own private use.
  1207. * @param {String} applicationId Your Parse Application ID.
  1208. * @param {String} javaScriptKey Your Parse JavaScript Key.
  1209. * @param {String} masterKey Your Parse Master Key.
  1210. */
  1211. Parse._initialize = function(applicationId, javaScriptKey, masterKey) {
  1212. Parse.applicationId = applicationId;
  1213. Parse.javaScriptKey = javaScriptKey;
  1214. Parse.masterKey = masterKey;
  1215. Parse._useMasterKey = false;
  1216. };
  1217. // If we're running in node.js, allow using the master key.
  1218. if (Parse._isNode) {
  1219. Parse.initialize = Parse._initialize;
  1220. Parse.Cloud = Parse.Cloud || {};
  1221. /**
  1222. * Switches the Parse SDK to using the Master key. The Master key grants
  1223. * priveleged access to the data in Parse and can be used to bypass ACLs and
  1224. * other restrictions that are applied to the client SDKs.
  1225. * <p><strong><em>Available in Cloud Code and Node.js only.</em></strong>
  1226. * </p>
  1227. */
  1228. Parse.Cloud.useMasterKey = function() {
  1229. Parse._useMasterKey = true;
  1230. };
  1231. }
  1232. /**
  1233. * Returns prefix for localStorage keys used by this instance of Parse.
  1234. * @param {String} path The relative suffix to append to it.
  1235. * null or undefined is treated as the empty string.
  1236. * @return {String} The full key name.
  1237. */
  1238. Parse._getParsePath = function(path) {
  1239. if (!Parse.applicationId) {
  1240. throw "You need to call Parse.initialize before using Parse.";
  1241. }
  1242. if (!path) {
  1243. path = "";
  1244. }
  1245. if (!Parse._.isString(path)) {
  1246. throw "Tried to get a localStorage path that wasn't a String.";
  1247. }
  1248. if (path[0] === "/") {
  1249. path = path.substring(1);
  1250. }
  1251. return "Parse/" + Parse.applicationId + "/" + path;
  1252. };
  1253. /**
  1254. * Returns the unique string for this app on this machine.
  1255. * Gets reset when localStorage is cleared.
  1256. */
  1257. Parse._installationId = null;
  1258. Parse._getInstallationId = function() {
  1259. // See if it's cached in RAM.
  1260. if (Parse._installationId) {
  1261. return Parse._installationId;
  1262. }
  1263. // Try to get it from localStorage.
  1264. var path = Parse._getParsePath("installationId");
  1265. Parse._installationId = Parse.localStorage.getItem(path);
  1266. if (!Parse._installationId || Parse._installationId === "") {
  1267. // It wasn't in localStorage, so create a new one.
  1268. var hexOctet = function() {
  1269. return Math.floor((1+Math.random())*0x10000).toString(16).substring(1);
  1270. };
  1271. Parse._installationId = (
  1272. hexOctet() + hexOctet() + "-" +
  1273. hexOctet() + "-" +
  1274. hexOctet() + "-" +
  1275. hexOctet() + "-" +
  1276. hexOctet() + hexOctet() + hexOctet());
  1277. Parse.localStorage.setItem(path, Parse._installationId);
  1278. }
  1279. return Parse._installationId;
  1280. };
  1281. Parse._parseDate = function(iso8601) {
  1282. var regexp = new RegExp(
  1283. "^([0-9]{1,4})-([0-9]{1,2})-([0-9]{1,2})" + "T" +
  1284. "([0-9]{1,2}):([0-9]{1,2}):([0-9]{1,2})" +
  1285. "(.([0-9]+))?" + "Z$");
  1286. var match = regexp.exec(iso8601);
  1287. if (!match) {
  1288. return null;
  1289. }
  1290. var year = match[1] || 0;
  1291. var month = (match[2] || 1) - 1;
  1292. var day = match[3] || 0;
  1293. var hour = match[4] || 0;
  1294. var minute = match[5] || 0;
  1295. var second = match[6] || 0;
  1296. var milli = match[8] || 0;
  1297. return new Date(Date.UTC(year, month, day, hour, minute, second, milli));
  1298. };
  1299. Parse._ajaxIE8 = function(method, url, data) {
  1300. var promise = new Parse.Promise();
  1301. var xdr = new XDomainRequest();
  1302. xdr.onload = function() {
  1303. var response;
  1304. try {
  1305. response = JSON.parse(xdr.responseText);
  1306. } catch (e) {
  1307. promise.reject(e);
  1308. }
  1309. if (response) {
  1310. promise.resolve(response);
  1311. }
  1312. };
  1313. xdr.onerror = xdr.ontimeout = function() {
  1314. promise.reject(xdr);
  1315. };
  1316. xdr.onprogress = function() {};
  1317. xdr.open(method, url);
  1318. xdr.send(data);
  1319. return promise;
  1320. };
  1321. Parse._ajax = function(method, url, data, success, error) {
  1322. var options = {
  1323. success: success,
  1324. error: error
  1325. };
  1326. if (typeof(XDomainRequest) !== "undefined") {
  1327. return Parse._ajaxIE8(method, url, data)._thenRunCallbacks(options);
  1328. }
  1329. var promise = new Parse.Promise();
  1330. var handled = false;
  1331. var xhr = new Parse.XMLHttpRequest();
  1332. xhr.onreadystatechange = function() {
  1333. if (xhr.readyState === 4) {
  1334. if (handled) {
  1335. return;
  1336. }