PageRenderTime 55ms CodeModel.GetById 15ms RepoModel.GetById 1ms app.codeStats 0ms

/client/jspm_packages/npm/angular@1.5.5/angular.js

https://gitlab.com/bahtou/started
JavaScript | 1682 lines | 641 code | 175 blank | 866 comment | 199 complexity | c078156919a8a06563260268647a62cc MD5 | raw file
  1. /* */
  2. "format global";
  3. "exports angular";
  4. /**
  5. * @license AngularJS v1.5.5
  6. * (c) 2010-2016 Google, Inc. http://angularjs.org
  7. * License: MIT
  8. */
  9. (function(window) {'use strict';
  10. /**
  11. * @description
  12. *
  13. * This object provides a utility for producing rich Error messages within
  14. * Angular. It can be called as follows:
  15. *
  16. * var exampleMinErr = minErr('example');
  17. * throw exampleMinErr('one', 'This {0} is {1}', foo, bar);
  18. *
  19. * The above creates an instance of minErr in the example namespace. The
  20. * resulting error will have a namespaced error code of example.one. The
  21. * resulting error will replace {0} with the value of foo, and {1} with the
  22. * value of bar. The object is not restricted in the number of arguments it can
  23. * take.
  24. *
  25. * If fewer arguments are specified than necessary for interpolation, the extra
  26. * interpolation markers will be preserved in the final string.
  27. *
  28. * Since data will be parsed statically during a build step, some restrictions
  29. * are applied with respect to how minErr instances are created and called.
  30. * Instances should have names of the form namespaceMinErr for a minErr created
  31. * using minErr('namespace') . Error codes, namespaces and template strings
  32. * should all be static strings, not variables or general expressions.
  33. *
  34. * @param {string} module The namespace to use for the new minErr instance.
  35. * @param {function} ErrorConstructor Custom error constructor to be instantiated when returning
  36. * error from returned function, for cases when a particular type of error is useful.
  37. * @returns {function(code:string, template:string, ...templateArgs): Error} minErr instance
  38. */
  39. function minErr(module, ErrorConstructor) {
  40. ErrorConstructor = ErrorConstructor || Error;
  41. return function() {
  42. var SKIP_INDEXES = 2;
  43. var templateArgs = arguments,
  44. code = templateArgs[0],
  45. message = '[' + (module ? module + ':' : '') + code + '] ',
  46. template = templateArgs[1],
  47. paramPrefix, i;
  48. message += template.replace(/\{\d+\}/g, function(match) {
  49. var index = +match.slice(1, -1),
  50. shiftedIndex = index + SKIP_INDEXES;
  51. if (shiftedIndex < templateArgs.length) {
  52. return toDebugString(templateArgs[shiftedIndex]);
  53. }
  54. return match;
  55. });
  56. message += '\nhttp://errors.angularjs.org/1.5.5/' +
  57. (module ? module + '/' : '') + code;
  58. for (i = SKIP_INDEXES, paramPrefix = '?'; i < templateArgs.length; i++, paramPrefix = '&') {
  59. message += paramPrefix + 'p' + (i - SKIP_INDEXES) + '=' +
  60. encodeURIComponent(toDebugString(templateArgs[i]));
  61. }
  62. return new ErrorConstructor(message);
  63. };
  64. }
  65. /* We need to tell jshint what variables are being exported */
  66. /* global angular: true,
  67. msie: true,
  68. jqLite: true,
  69. jQuery: true,
  70. slice: true,
  71. splice: true,
  72. push: true,
  73. toString: true,
  74. ngMinErr: true,
  75. angularModule: true,
  76. uid: true,
  77. REGEX_STRING_REGEXP: true,
  78. VALIDITY_STATE_PROPERTY: true,
  79. lowercase: true,
  80. uppercase: true,
  81. manualLowercase: true,
  82. manualUppercase: true,
  83. nodeName_: true,
  84. isArrayLike: true,
  85. forEach: true,
  86. forEachSorted: true,
  87. reverseParams: true,
  88. nextUid: true,
  89. setHashKey: true,
  90. extend: true,
  91. toInt: true,
  92. inherit: true,
  93. merge: true,
  94. noop: true,
  95. identity: true,
  96. valueFn: true,
  97. isUndefined: true,
  98. isDefined: true,
  99. isObject: true,
  100. isBlankObject: true,
  101. isString: true,
  102. isNumber: true,
  103. isDate: true,
  104. isArray: true,
  105. isFunction: true,
  106. isRegExp: true,
  107. isWindow: true,
  108. isScope: true,
  109. isFile: true,
  110. isFormData: true,
  111. isBlob: true,
  112. isBoolean: true,
  113. isPromiseLike: true,
  114. trim: true,
  115. escapeForRegexp: true,
  116. isElement: true,
  117. makeMap: true,
  118. includes: true,
  119. arrayRemove: true,
  120. copy: true,
  121. shallowCopy: true,
  122. equals: true,
  123. csp: true,
  124. jq: true,
  125. concat: true,
  126. sliceArgs: true,
  127. bind: true,
  128. toJsonReplacer: true,
  129. toJson: true,
  130. fromJson: true,
  131. convertTimezoneToLocal: true,
  132. timezoneToOffset: true,
  133. startingTag: true,
  134. tryDecodeURIComponent: true,
  135. parseKeyValue: true,
  136. toKeyValue: true,
  137. encodeUriSegment: true,
  138. encodeUriQuery: true,
  139. angularInit: true,
  140. bootstrap: true,
  141. getTestability: true,
  142. snake_case: true,
  143. bindJQuery: true,
  144. assertArg: true,
  145. assertArgFn: true,
  146. assertNotHasOwnProperty: true,
  147. getter: true,
  148. getBlockNodes: true,
  149. hasOwnProperty: true,
  150. createMap: true,
  151. NODE_TYPE_ELEMENT: true,
  152. NODE_TYPE_ATTRIBUTE: true,
  153. NODE_TYPE_TEXT: true,
  154. NODE_TYPE_COMMENT: true,
  155. NODE_TYPE_DOCUMENT: true,
  156. NODE_TYPE_DOCUMENT_FRAGMENT: true,
  157. */
  158. ////////////////////////////////////
  159. /**
  160. * @ngdoc module
  161. * @name ng
  162. * @module ng
  163. * @installation
  164. * @description
  165. *
  166. * # ng (core module)
  167. * The ng module is loaded by default when an AngularJS application is started. The module itself
  168. * contains the essential components for an AngularJS application to function. The table below
  169. * lists a high level breakdown of each of the services/factories, filters, directives and testing
  170. * components available within this core module.
  171. *
  172. * <div doc-module-components="ng"></div>
  173. */
  174. var REGEX_STRING_REGEXP = /^\/(.+)\/([a-z]*)$/;
  175. // The name of a form control's ValidityState property.
  176. // This is used so that it's possible for internal tests to create mock ValidityStates.
  177. var VALIDITY_STATE_PROPERTY = 'validity';
  178. var hasOwnProperty = Object.prototype.hasOwnProperty;
  179. var lowercase = function(string) {return isString(string) ? string.toLowerCase() : string;};
  180. var uppercase = function(string) {return isString(string) ? string.toUpperCase() : string;};
  181. var manualLowercase = function(s) {
  182. /* jshint bitwise: false */
  183. return isString(s)
  184. ? s.replace(/[A-Z]/g, function(ch) {return String.fromCharCode(ch.charCodeAt(0) | 32);})
  185. : s;
  186. };
  187. var manualUppercase = function(s) {
  188. /* jshint bitwise: false */
  189. return isString(s)
  190. ? s.replace(/[a-z]/g, function(ch) {return String.fromCharCode(ch.charCodeAt(0) & ~32);})
  191. : s;
  192. };
  193. // String#toLowerCase and String#toUpperCase don't produce correct results in browsers with Turkish
  194. // locale, for this reason we need to detect this case and redefine lowercase/uppercase methods
  195. // with correct but slower alternatives. See https://github.com/angular/angular.js/issues/11387
  196. if ('i' !== 'I'.toLowerCase()) {
  197. lowercase = manualLowercase;
  198. uppercase = manualUppercase;
  199. }
  200. var
  201. msie, // holds major version number for IE, or NaN if UA is not IE.
  202. jqLite, // delay binding since jQuery could be loaded after us.
  203. jQuery, // delay binding
  204. slice = [].slice,
  205. splice = [].splice,
  206. push = [].push,
  207. toString = Object.prototype.toString,
  208. getPrototypeOf = Object.getPrototypeOf,
  209. ngMinErr = minErr('ng'),
  210. /** @name angular */
  211. angular = window.angular || (window.angular = {}),
  212. angularModule,
  213. uid = 0;
  214. /**
  215. * documentMode is an IE-only property
  216. * http://msdn.microsoft.com/en-us/library/ie/cc196988(v=vs.85).aspx
  217. */
  218. msie = window.document.documentMode;
  219. /**
  220. * @private
  221. * @param {*} obj
  222. * @return {boolean} Returns true if `obj` is an array or array-like object (NodeList, Arguments,
  223. * String ...)
  224. */
  225. function isArrayLike(obj) {
  226. // `null`, `undefined` and `window` are not array-like
  227. if (obj == null || isWindow(obj)) return false;
  228. // arrays, strings and jQuery/jqLite objects are array like
  229. // * jqLite is either the jQuery or jqLite constructor function
  230. // * we have to check the existence of jqLite first as this method is called
  231. // via the forEach method when constructing the jqLite object in the first place
  232. if (isArray(obj) || isString(obj) || (jqLite && obj instanceof jqLite)) return true;
  233. // Support: iOS 8.2 (not reproducible in simulator)
  234. // "length" in obj used to prevent JIT error (gh-11508)
  235. var length = "length" in Object(obj) && obj.length;
  236. // NodeList objects (with `item` method) and
  237. // other objects with suitable length characteristics are array-like
  238. return isNumber(length) &&
  239. (length >= 0 && ((length - 1) in obj || obj instanceof Array) || typeof obj.item == 'function');
  240. }
  241. /**
  242. * @ngdoc function
  243. * @name angular.forEach
  244. * @module ng
  245. * @kind function
  246. *
  247. * @description
  248. * Invokes the `iterator` function once for each item in `obj` collection, which can be either an
  249. * object or an array. The `iterator` function is invoked with `iterator(value, key, obj)`, where `value`
  250. * is the value of an object property or an array element, `key` is the object property key or
  251. * array element index and obj is the `obj` itself. Specifying a `context` for the function is optional.
  252. *
  253. * It is worth noting that `.forEach` does not iterate over inherited properties because it filters
  254. * using the `hasOwnProperty` method.
  255. *
  256. * Unlike ES262's
  257. * [Array.prototype.forEach](http://www.ecma-international.org/ecma-262/5.1/#sec-15.4.4.18),
  258. * providing 'undefined' or 'null' values for `obj` will not throw a TypeError, but rather just
  259. * return the value provided.
  260. *
  261. ```js
  262. var values = {name: 'misko', gender: 'male'};
  263. var log = [];
  264. angular.forEach(values, function(value, key) {
  265. this.push(key + ': ' + value);
  266. }, log);
  267. expect(log).toEqual(['name: misko', 'gender: male']);
  268. ```
  269. *
  270. * @param {Object|Array} obj Object to iterate over.
  271. * @param {Function} iterator Iterator function.
  272. * @param {Object=} context Object to become context (`this`) for the iterator function.
  273. * @returns {Object|Array} Reference to `obj`.
  274. */
  275. function forEach(obj, iterator, context) {
  276. var key, length;
  277. if (obj) {
  278. if (isFunction(obj)) {
  279. for (key in obj) {
  280. // Need to check if hasOwnProperty exists,
  281. // as on IE8 the result of querySelectorAll is an object without a hasOwnProperty function
  282. if (key != 'prototype' && key != 'length' && key != 'name' && (!obj.hasOwnProperty || obj.hasOwnProperty(key))) {
  283. iterator.call(context, obj[key], key, obj);
  284. }
  285. }
  286. } else if (isArray(obj) || isArrayLike(obj)) {
  287. var isPrimitive = typeof obj !== 'object';
  288. for (key = 0, length = obj.length; key < length; key++) {
  289. if (isPrimitive || key in obj) {
  290. iterator.call(context, obj[key], key, obj);
  291. }
  292. }
  293. } else if (obj.forEach && obj.forEach !== forEach) {
  294. obj.forEach(iterator, context, obj);
  295. } else if (isBlankObject(obj)) {
  296. // createMap() fast path --- Safe to avoid hasOwnProperty check because prototype chain is empty
  297. for (key in obj) {
  298. iterator.call(context, obj[key], key, obj);
  299. }
  300. } else if (typeof obj.hasOwnProperty === 'function') {
  301. // Slow path for objects inheriting Object.prototype, hasOwnProperty check needed
  302. for (key in obj) {
  303. if (obj.hasOwnProperty(key)) {
  304. iterator.call(context, obj[key], key, obj);
  305. }
  306. }
  307. } else {
  308. // Slow path for objects which do not have a method `hasOwnProperty`
  309. for (key in obj) {
  310. if (hasOwnProperty.call(obj, key)) {
  311. iterator.call(context, obj[key], key, obj);
  312. }
  313. }
  314. }
  315. }
  316. return obj;
  317. }
  318. function forEachSorted(obj, iterator, context) {
  319. var keys = Object.keys(obj).sort();
  320. for (var i = 0; i < keys.length; i++) {
  321. iterator.call(context, obj[keys[i]], keys[i]);
  322. }
  323. return keys;
  324. }
  325. /**
  326. * when using forEach the params are value, key, but it is often useful to have key, value.
  327. * @param {function(string, *)} iteratorFn
  328. * @returns {function(*, string)}
  329. */
  330. function reverseParams(iteratorFn) {
  331. return function(value, key) {iteratorFn(key, value);};
  332. }
  333. /**
  334. * A consistent way of creating unique IDs in angular.
  335. *
  336. * Using simple numbers allows us to generate 28.6 million unique ids per second for 10 years before
  337. * we hit number precision issues in JavaScript.
  338. *
  339. * Math.pow(2,53) / 60 / 60 / 24 / 365 / 10 = 28.6M
  340. *
  341. * @returns {number} an unique alpha-numeric string
  342. */
  343. function nextUid() {
  344. return ++uid;
  345. }
  346. /**
  347. * Set or clear the hashkey for an object.
  348. * @param obj object
  349. * @param h the hashkey (!truthy to delete the hashkey)
  350. */
  351. function setHashKey(obj, h) {
  352. if (h) {
  353. obj.$$hashKey = h;
  354. } else {
  355. delete obj.$$hashKey;
  356. }
  357. }
  358. function baseExtend(dst, objs, deep) {
  359. var h = dst.$$hashKey;
  360. for (var i = 0, ii = objs.length; i < ii; ++i) {
  361. var obj = objs[i];
  362. if (!isObject(obj) && !isFunction(obj)) continue;
  363. var keys = Object.keys(obj);
  364. for (var j = 0, jj = keys.length; j < jj; j++) {
  365. var key = keys[j];
  366. var src = obj[key];
  367. if (deep && isObject(src)) {
  368. if (isDate(src)) {
  369. dst[key] = new Date(src.valueOf());
  370. } else if (isRegExp(src)) {
  371. dst[key] = new RegExp(src);
  372. } else if (src.nodeName) {
  373. dst[key] = src.cloneNode(true);
  374. } else if (isElement(src)) {
  375. dst[key] = src.clone();
  376. } else {
  377. if (!isObject(dst[key])) dst[key] = isArray(src) ? [] : {};
  378. baseExtend(dst[key], [src], true);
  379. }
  380. } else {
  381. dst[key] = src;
  382. }
  383. }
  384. }
  385. setHashKey(dst, h);
  386. return dst;
  387. }
  388. /**
  389. * @ngdoc function
  390. * @name angular.extend
  391. * @module ng
  392. * @kind function
  393. *
  394. * @description
  395. * Extends the destination object `dst` by copying own enumerable properties from the `src` object(s)
  396. * to `dst`. You can specify multiple `src` objects. If you want to preserve original objects, you can do so
  397. * by passing an empty object as the target: `var object = angular.extend({}, object1, object2)`.
  398. *
  399. * **Note:** Keep in mind that `angular.extend` does not support recursive merge (deep copy). Use
  400. * {@link angular.merge} for this.
  401. *
  402. * @param {Object} dst Destination object.
  403. * @param {...Object} src Source object(s).
  404. * @returns {Object} Reference to `dst`.
  405. */
  406. function extend(dst) {
  407. return baseExtend(dst, slice.call(arguments, 1), false);
  408. }
  409. /**
  410. * @ngdoc function
  411. * @name angular.merge
  412. * @module ng
  413. * @kind function
  414. *
  415. * @description
  416. * Deeply extends the destination object `dst` by copying own enumerable properties from the `src` object(s)
  417. * to `dst`. You can specify multiple `src` objects. If you want to preserve original objects, you can do so
  418. * by passing an empty object as the target: `var object = angular.merge({}, object1, object2)`.
  419. *
  420. * Unlike {@link angular.extend extend()}, `merge()` recursively descends into object properties of source
  421. * objects, performing a deep copy.
  422. *
  423. * @param {Object} dst Destination object.
  424. * @param {...Object} src Source object(s).
  425. * @returns {Object} Reference to `dst`.
  426. */
  427. function merge(dst) {
  428. return baseExtend(dst, slice.call(arguments, 1), true);
  429. }
  430. function toInt(str) {
  431. return parseInt(str, 10);
  432. }
  433. function inherit(parent, extra) {
  434. return extend(Object.create(parent), extra);
  435. }
  436. /**
  437. * @ngdoc function
  438. * @name angular.noop
  439. * @module ng
  440. * @kind function
  441. *
  442. * @description
  443. * A function that performs no operations. This function can be useful when writing code in the
  444. * functional style.
  445. ```js
  446. function foo(callback) {
  447. var result = calculateResult();
  448. (callback || angular.noop)(result);
  449. }
  450. ```
  451. */
  452. function noop() {}
  453. noop.$inject = [];
  454. /**
  455. * @ngdoc function
  456. * @name angular.identity
  457. * @module ng
  458. * @kind function
  459. *
  460. * @description
  461. * A function that returns its first argument. This function is useful when writing code in the
  462. * functional style.
  463. *
  464. ```js
  465. function transformer(transformationFn, value) {
  466. return (transformationFn || angular.identity)(value);
  467. };
  468. ```
  469. * @param {*} value to be returned.
  470. * @returns {*} the value passed in.
  471. */
  472. function identity($) {return $;}
  473. identity.$inject = [];
  474. function valueFn(value) {return function valueRef() {return value;};}
  475. function hasCustomToString(obj) {
  476. return isFunction(obj.toString) && obj.toString !== toString;
  477. }
  478. /**
  479. * @ngdoc function
  480. * @name angular.isUndefined
  481. * @module ng
  482. * @kind function
  483. *
  484. * @description
  485. * Determines if a reference is undefined.
  486. *
  487. * @param {*} value Reference to check.
  488. * @returns {boolean} True if `value` is undefined.
  489. */
  490. function isUndefined(value) {return typeof value === 'undefined';}
  491. /**
  492. * @ngdoc function
  493. * @name angular.isDefined
  494. * @module ng
  495. * @kind function
  496. *
  497. * @description
  498. * Determines if a reference is defined.
  499. *
  500. * @param {*} value Reference to check.
  501. * @returns {boolean} True if `value` is defined.
  502. */
  503. function isDefined(value) {return typeof value !== 'undefined';}
  504. /**
  505. * @ngdoc function
  506. * @name angular.isObject
  507. * @module ng
  508. * @kind function
  509. *
  510. * @description
  511. * Determines if a reference is an `Object`. Unlike `typeof` in JavaScript, `null`s are not
  512. * considered to be objects. Note that JavaScript arrays are objects.
  513. *
  514. * @param {*} value Reference to check.
  515. * @returns {boolean} True if `value` is an `Object` but not `null`.
  516. */
  517. function isObject(value) {
  518. // http://jsperf.com/isobject4
  519. return value !== null && typeof value === 'object';
  520. }
  521. /**
  522. * Determine if a value is an object with a null prototype
  523. *
  524. * @returns {boolean} True if `value` is an `Object` with a null prototype
  525. */
  526. function isBlankObject(value) {
  527. return value !== null && typeof value === 'object' && !getPrototypeOf(value);
  528. }
  529. /**
  530. * @ngdoc function
  531. * @name angular.isString
  532. * @module ng
  533. * @kind function
  534. *
  535. * @description
  536. * Determines if a reference is a `String`.
  537. *
  538. * @param {*} value Reference to check.
  539. * @returns {boolean} True if `value` is a `String`.
  540. */
  541. function isString(value) {return typeof value === 'string';}
  542. /**
  543. * @ngdoc function
  544. * @name angular.isNumber
  545. * @module ng
  546. * @kind function
  547. *
  548. * @description
  549. * Determines if a reference is a `Number`.
  550. *
  551. * This includes the "special" numbers `NaN`, `+Infinity` and `-Infinity`.
  552. *
  553. * If you wish to exclude these then you can use the native
  554. * [`isFinite'](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/isFinite)
  555. * method.
  556. *
  557. * @param {*} value Reference to check.
  558. * @returns {boolean} True if `value` is a `Number`.
  559. */
  560. function isNumber(value) {return typeof value === 'number';}
  561. /**
  562. * @ngdoc function
  563. * @name angular.isDate
  564. * @module ng
  565. * @kind function
  566. *
  567. * @description
  568. * Determines if a value is a date.
  569. *
  570. * @param {*} value Reference to check.
  571. * @returns {boolean} True if `value` is a `Date`.
  572. */
  573. function isDate(value) {
  574. return toString.call(value) === '[object Date]';
  575. }
  576. /**
  577. * @ngdoc function
  578. * @name angular.isArray
  579. * @module ng
  580. * @kind function
  581. *
  582. * @description
  583. * Determines if a reference is an `Array`.
  584. *
  585. * @param {*} value Reference to check.
  586. * @returns {boolean} True if `value` is an `Array`.
  587. */
  588. var isArray = Array.isArray;
  589. /**
  590. * @ngdoc function
  591. * @name angular.isFunction
  592. * @module ng
  593. * @kind function
  594. *
  595. * @description
  596. * Determines if a reference is a `Function`.
  597. *
  598. * @param {*} value Reference to check.
  599. * @returns {boolean} True if `value` is a `Function`.
  600. */
  601. function isFunction(value) {return typeof value === 'function';}
  602. /**
  603. * Determines if a value is a regular expression object.
  604. *
  605. * @private
  606. * @param {*} value Reference to check.
  607. * @returns {boolean} True if `value` is a `RegExp`.
  608. */
  609. function isRegExp(value) {
  610. return toString.call(value) === '[object RegExp]';
  611. }
  612. /**
  613. * Checks if `obj` is a window object.
  614. *
  615. * @private
  616. * @param {*} obj Object to check
  617. * @returns {boolean} True if `obj` is a window obj.
  618. */
  619. function isWindow(obj) {
  620. return obj && obj.window === obj;
  621. }
  622. function isScope(obj) {
  623. return obj && obj.$evalAsync && obj.$watch;
  624. }
  625. function isFile(obj) {
  626. return toString.call(obj) === '[object File]';
  627. }
  628. function isFormData(obj) {
  629. return toString.call(obj) === '[object FormData]';
  630. }
  631. function isBlob(obj) {
  632. return toString.call(obj) === '[object Blob]';
  633. }
  634. function isBoolean(value) {
  635. return typeof value === 'boolean';
  636. }
  637. function isPromiseLike(obj) {
  638. return obj && isFunction(obj.then);
  639. }
  640. var TYPED_ARRAY_REGEXP = /^\[object (?:Uint8|Uint8Clamped|Uint16|Uint32|Int8|Int16|Int32|Float32|Float64)Array\]$/;
  641. function isTypedArray(value) {
  642. return value && isNumber(value.length) && TYPED_ARRAY_REGEXP.test(toString.call(value));
  643. }
  644. function isArrayBuffer(obj) {
  645. return toString.call(obj) === '[object ArrayBuffer]';
  646. }
  647. var trim = function(value) {
  648. return isString(value) ? value.trim() : value;
  649. };
  650. // Copied from:
  651. // http://docs.closure-library.googlecode.com/git/local_closure_goog_string_string.js.source.html#line1021
  652. // Prereq: s is a string.
  653. var escapeForRegexp = function(s) {
  654. return s.replace(/([-()\[\]{}+?*.$\^|,:#<!\\])/g, '\\$1').
  655. replace(/\x08/g, '\\x08');
  656. };
  657. /**
  658. * @ngdoc function
  659. * @name angular.isElement
  660. * @module ng
  661. * @kind function
  662. *
  663. * @description
  664. * Determines if a reference is a DOM element (or wrapped jQuery element).
  665. *
  666. * @param {*} value Reference to check.
  667. * @returns {boolean} True if `value` is a DOM element (or wrapped jQuery element).
  668. */
  669. function isElement(node) {
  670. return !!(node &&
  671. (node.nodeName // we are a direct element
  672. || (node.prop && node.attr && node.find))); // we have an on and find method part of jQuery API
  673. }
  674. /**
  675. * @param str 'key1,key2,...'
  676. * @returns {object} in the form of {key1:true, key2:true, ...}
  677. */
  678. function makeMap(str) {
  679. var obj = {}, items = str.split(','), i;
  680. for (i = 0; i < items.length; i++) {
  681. obj[items[i]] = true;
  682. }
  683. return obj;
  684. }
  685. function nodeName_(element) {
  686. return lowercase(element.nodeName || (element[0] && element[0].nodeName));
  687. }
  688. function includes(array, obj) {
  689. return Array.prototype.indexOf.call(array, obj) != -1;
  690. }
  691. function arrayRemove(array, value) {
  692. var index = array.indexOf(value);
  693. if (index >= 0) {
  694. array.splice(index, 1);
  695. }
  696. return index;
  697. }
  698. /**
  699. * @ngdoc function
  700. * @name angular.copy
  701. * @module ng
  702. * @kind function
  703. *
  704. * @description
  705. * Creates a deep copy of `source`, which should be an object or an array.
  706. *
  707. * * If no destination is supplied, a copy of the object or array is created.
  708. * * If a destination is provided, all of its elements (for arrays) or properties (for objects)
  709. * are deleted and then all elements/properties from the source are copied to it.
  710. * * If `source` is not an object or array (inc. `null` and `undefined`), `source` is returned.
  711. * * If `source` is identical to 'destination' an exception will be thrown.
  712. *
  713. * @param {*} source The source that will be used to make a copy.
  714. * Can be any type, including primitives, `null`, and `undefined`.
  715. * @param {(Object|Array)=} destination Destination into which the source is copied. If
  716. * provided, must be of the same type as `source`.
  717. * @returns {*} The copy or updated `destination`, if `destination` was specified.
  718. *
  719. * @example
  720. <example module="copyExample">
  721. <file name="index.html">
  722. <div ng-controller="ExampleController">
  723. <form novalidate class="simple-form">
  724. Name: <input type="text" ng-model="user.name" /><br />
  725. E-mail: <input type="email" ng-model="user.email" /><br />
  726. Gender: <input type="radio" ng-model="user.gender" value="male" />male
  727. <input type="radio" ng-model="user.gender" value="female" />female<br />
  728. <button ng-click="reset()">RESET</button>
  729. <button ng-click="update(user)">SAVE</button>
  730. </form>
  731. <pre>form = {{user | json}}</pre>
  732. <pre>master = {{master | json}}</pre>
  733. </div>
  734. <script>
  735. angular.module('copyExample', [])
  736. .controller('ExampleController', ['$scope', function($scope) {
  737. $scope.master= {};
  738. $scope.update = function(user) {
  739. // Example with 1 argument
  740. $scope.master= angular.copy(user);
  741. };
  742. $scope.reset = function() {
  743. // Example with 2 arguments
  744. angular.copy($scope.master, $scope.user);
  745. };
  746. $scope.reset();
  747. }]);
  748. </script>
  749. </file>
  750. </example>
  751. */
  752. function copy(source, destination) {
  753. var stackSource = [];
  754. var stackDest = [];
  755. if (destination) {
  756. if (isTypedArray(destination) || isArrayBuffer(destination)) {
  757. throw ngMinErr('cpta', "Can't copy! TypedArray destination cannot be mutated.");
  758. }
  759. if (source === destination) {
  760. throw ngMinErr('cpi', "Can't copy! Source and destination are identical.");
  761. }
  762. // Empty the destination object
  763. if (isArray(destination)) {
  764. destination.length = 0;
  765. } else {
  766. forEach(destination, function(value, key) {
  767. if (key !== '$$hashKey') {
  768. delete destination[key];
  769. }
  770. });
  771. }
  772. stackSource.push(source);
  773. stackDest.push(destination);
  774. return copyRecurse(source, destination);
  775. }
  776. return copyElement(source);
  777. function copyRecurse(source, destination) {
  778. var h = destination.$$hashKey;
  779. var key;
  780. if (isArray(source)) {
  781. for (var i = 0, ii = source.length; i < ii; i++) {
  782. destination.push(copyElement(source[i]));
  783. }
  784. } else if (isBlankObject(source)) {
  785. // createMap() fast path --- Safe to avoid hasOwnProperty check because prototype chain is empty
  786. for (key in source) {
  787. destination[key] = copyElement(source[key]);
  788. }
  789. } else if (source && typeof source.hasOwnProperty === 'function') {
  790. // Slow path, which must rely on hasOwnProperty
  791. for (key in source) {
  792. if (source.hasOwnProperty(key)) {
  793. destination[key] = copyElement(source[key]);
  794. }
  795. }
  796. } else {
  797. // Slowest path --- hasOwnProperty can't be called as a method
  798. for (key in source) {
  799. if (hasOwnProperty.call(source, key)) {
  800. destination[key] = copyElement(source[key]);
  801. }
  802. }
  803. }
  804. setHashKey(destination, h);
  805. return destination;
  806. }
  807. function copyElement(source) {
  808. // Simple values
  809. if (!isObject(source)) {
  810. return source;
  811. }
  812. // Already copied values
  813. var index = stackSource.indexOf(source);
  814. if (index !== -1) {
  815. return stackDest[index];
  816. }
  817. if (isWindow(source) || isScope(source)) {
  818. throw ngMinErr('cpws',
  819. "Can't copy! Making copies of Window or Scope instances is not supported.");
  820. }
  821. var needsRecurse = false;
  822. var destination = copyType(source);
  823. if (destination === undefined) {
  824. destination = isArray(source) ? [] : Object.create(getPrototypeOf(source));
  825. needsRecurse = true;
  826. }
  827. stackSource.push(source);
  828. stackDest.push(destination);
  829. return needsRecurse
  830. ? copyRecurse(source, destination)
  831. : destination;
  832. }
  833. function copyType(source) {
  834. switch (toString.call(source)) {
  835. case '[object Int8Array]':
  836. case '[object Int16Array]':
  837. case '[object Int32Array]':
  838. case '[object Float32Array]':
  839. case '[object Float64Array]':
  840. case '[object Uint8Array]':
  841. case '[object Uint8ClampedArray]':
  842. case '[object Uint16Array]':
  843. case '[object Uint32Array]':
  844. return new source.constructor(copyElement(source.buffer));
  845. case '[object ArrayBuffer]':
  846. //Support: IE10
  847. if (!source.slice) {
  848. var copied = new ArrayBuffer(source.byteLength);
  849. new Uint8Array(copied).set(new Uint8Array(source));
  850. return copied;
  851. }
  852. return source.slice(0);
  853. case '[object Boolean]':
  854. case '[object Number]':
  855. case '[object String]':
  856. case '[object Date]':
  857. return new source.constructor(source.valueOf());
  858. case '[object RegExp]':
  859. var re = new RegExp(source.source, source.toString().match(/[^\/]*$/)[0]);
  860. re.lastIndex = source.lastIndex;
  861. return re;
  862. case '[object Blob]':
  863. return new source.constructor([source], {type: source.type});
  864. }
  865. if (isFunction(source.cloneNode)) {
  866. return source.cloneNode(true);
  867. }
  868. }
  869. }
  870. /**
  871. * Creates a shallow copy of an object, an array or a primitive.
  872. *
  873. * Assumes that there are no proto properties for objects.
  874. */
  875. function shallowCopy(src, dst) {
  876. if (isArray(src)) {
  877. dst = dst || [];
  878. for (var i = 0, ii = src.length; i < ii; i++) {
  879. dst[i] = src[i];
  880. }
  881. } else if (isObject(src)) {
  882. dst = dst || {};
  883. for (var key in src) {
  884. if (!(key.charAt(0) === '$' && key.charAt(1) === '$')) {
  885. dst[key] = src[key];
  886. }
  887. }
  888. }
  889. return dst || src;
  890. }
  891. /**
  892. * @ngdoc function
  893. * @name angular.equals
  894. * @module ng
  895. * @kind function
  896. *
  897. * @description
  898. * Determines if two objects or two values are equivalent. Supports value types, regular
  899. * expressions, arrays and objects.
  900. *
  901. * Two objects or values are considered equivalent if at least one of the following is true:
  902. *
  903. * * Both objects or values pass `===` comparison.
  904. * * Both objects or values are of the same type and all of their properties are equal by
  905. * comparing them with `angular.equals`.
  906. * * Both values are NaN. (In JavaScript, NaN == NaN => false. But we consider two NaN as equal)
  907. * * Both values represent the same regular expression (In JavaScript,
  908. * /abc/ == /abc/ => false. But we consider two regular expressions as equal when their textual
  909. * representation matches).
  910. *
  911. * During a property comparison, properties of `function` type and properties with names
  912. * that begin with `$` are ignored.
  913. *
  914. * Scope and DOMWindow objects are being compared only by identify (`===`).
  915. *
  916. * @param {*} o1 Object or value to compare.
  917. * @param {*} o2 Object or value to compare.
  918. * @returns {boolean} True if arguments are equal.
  919. *
  920. * @example
  921. <example module="equalsExample" name="equalsExample">
  922. <file name="index.html">
  923. <div ng-controller="ExampleController">
  924. <form novalidate>
  925. <h3>User 1</h3>
  926. Name: <input type="text" ng-model="user1.name">
  927. Age: <input type="number" ng-model="user1.age">
  928. <h3>User 2</h3>
  929. Name: <input type="text" ng-model="user2.name">
  930. Age: <input type="number" ng-model="user2.age">
  931. <div>
  932. <br/>
  933. <input type="button" value="Compare" ng-click="compare()">
  934. </div>
  935. User 1: <pre>{{user1 | json}}</pre>
  936. User 2: <pre>{{user2 | json}}</pre>
  937. Equal: <pre>{{result}}</pre>
  938. </form>
  939. </div>
  940. </file>
  941. <file name="script.js">
  942. angular.module('equalsExample', []).controller('ExampleController', ['$scope', function($scope) {
  943. $scope.user1 = {};
  944. $scope.user2 = {};
  945. $scope.result;
  946. $scope.compare = function() {
  947. $scope.result = angular.equals($scope.user1, $scope.user2);
  948. };
  949. }]);
  950. </file>
  951. </example>
  952. */
  953. function equals(o1, o2) {
  954. if (o1 === o2) return true;
  955. if (o1 === null || o2 === null) return false;
  956. if (o1 !== o1 && o2 !== o2) return true; // NaN === NaN
  957. var t1 = typeof o1, t2 = typeof o2, length, key, keySet;
  958. if (t1 == t2 && t1 == 'object') {
  959. if (isArray(o1)) {
  960. if (!isArray(o2)) return false;
  961. if ((length = o1.length) == o2.length) {
  962. for (key = 0; key < length; key++) {
  963. if (!equals(o1[key], o2[key])) return false;
  964. }
  965. return true;
  966. }
  967. } else if (isDate(o1)) {
  968. if (!isDate(o2)) return false;
  969. return equals(o1.getTime(), o2.getTime());
  970. } else if (isRegExp(o1)) {
  971. if (!isRegExp(o2)) return false;
  972. return o1.toString() == o2.toString();
  973. } else {
  974. if (isScope(o1) || isScope(o2) || isWindow(o1) || isWindow(o2) ||
  975. isArray(o2) || isDate(o2) || isRegExp(o2)) return false;
  976. keySet = createMap();
  977. for (key in o1) {
  978. if (key.charAt(0) === '$' || isFunction(o1[key])) continue;
  979. if (!equals(o1[key], o2[key])) return false;
  980. keySet[key] = true;
  981. }
  982. for (key in o2) {
  983. if (!(key in keySet) &&
  984. key.charAt(0) !== '$' &&
  985. isDefined(o2[key]) &&
  986. !isFunction(o2[key])) return false;
  987. }
  988. return true;
  989. }
  990. }
  991. return false;
  992. }
  993. var csp = function() {
  994. if (!isDefined(csp.rules)) {
  995. var ngCspElement = (window.document.querySelector('[ng-csp]') ||
  996. window.document.querySelector('[data-ng-csp]'));
  997. if (ngCspElement) {
  998. var ngCspAttribute = ngCspElement.getAttribute('ng-csp') ||
  999. ngCspElement.getAttribute('data-ng-csp');
  1000. csp.rules = {
  1001. noUnsafeEval: !ngCspAttribute || (ngCspAttribute.indexOf('no-unsafe-eval') !== -1),
  1002. noInlineStyle: !ngCspAttribute || (ngCspAttribute.indexOf('no-inline-style') !== -1)
  1003. };
  1004. } else {
  1005. csp.rules = {
  1006. noUnsafeEval: noUnsafeEval(),
  1007. noInlineStyle: false
  1008. };
  1009. }
  1010. }
  1011. return csp.rules;
  1012. function noUnsafeEval() {
  1013. try {
  1014. /* jshint -W031, -W054 */
  1015. new Function('');
  1016. /* jshint +W031, +W054 */
  1017. return false;
  1018. } catch (e) {
  1019. return true;
  1020. }
  1021. }
  1022. };
  1023. /**
  1024. * @ngdoc directive
  1025. * @module ng
  1026. * @name ngJq
  1027. *
  1028. * @element ANY
  1029. * @param {string=} ngJq the name of the library available under `window`
  1030. * to be used for angular.element
  1031. * @description
  1032. * Use this directive to force the angular.element library. This should be
  1033. * used to force either jqLite by leaving ng-jq blank or setting the name of
  1034. * the jquery variable under window (eg. jQuery).
  1035. *
  1036. * Since angular looks for this directive when it is loaded (doesn't wait for the
  1037. * DOMContentLoaded event), it must be placed on an element that comes before the script
  1038. * which loads angular. Also, only the first instance of `ng-jq` will be used and all
  1039. * others ignored.
  1040. *
  1041. * @example
  1042. * This example shows how to force jqLite using the `ngJq` directive to the `html` tag.
  1043. ```html
  1044. <!doctype html>
  1045. <html ng-app ng-jq>
  1046. ...
  1047. ...
  1048. </html>
  1049. ```
  1050. * @example
  1051. * This example shows how to use a jQuery based library of a different name.
  1052. * The library name must be available at the top most 'window'.
  1053. ```html
  1054. <!doctype html>
  1055. <html ng-app ng-jq="jQueryLib">
  1056. ...
  1057. ...
  1058. </html>
  1059. ```
  1060. */
  1061. var jq = function() {
  1062. if (isDefined(jq.name_)) return jq.name_;
  1063. var el;
  1064. var i, ii = ngAttrPrefixes.length, prefix, name;
  1065. for (i = 0; i < ii; ++i) {
  1066. prefix = ngAttrPrefixes[i];
  1067. if (el = window.document.querySelector('[' + prefix.replace(':', '\\:') + 'jq]')) {
  1068. name = el.getAttribute(prefix + 'jq');
  1069. break;
  1070. }
  1071. }
  1072. return (jq.name_ = name);
  1073. };
  1074. function concat(array1, array2, index) {
  1075. return array1.concat(slice.call(array2, index));
  1076. }
  1077. function sliceArgs(args, startIndex) {
  1078. return slice.call(args, startIndex || 0);
  1079. }
  1080. /* jshint -W101 */
  1081. /**
  1082. * @ngdoc function
  1083. * @name angular.bind
  1084. * @module ng
  1085. * @kind function
  1086. *
  1087. * @description
  1088. * Returns a function which calls function `fn` bound to `self` (`self` becomes the `this` for
  1089. * `fn`). You can supply optional `args` that are prebound to the function. This feature is also
  1090. * known as [partial application](http://en.wikipedia.org/wiki/Partial_application), as
  1091. * distinguished from [function currying](http://en.wikipedia.org/wiki/Currying#Contrast_with_partial_function_application).
  1092. *
  1093. * @param {Object} self Context which `fn` should be evaluated in.
  1094. * @param {function()} fn Function to be bound.
  1095. * @param {...*} args Optional arguments to be prebound to the `fn` function call.
  1096. * @returns {function()} Function that wraps the `fn` with all the specified bindings.
  1097. */
  1098. /* jshint +W101 */
  1099. function bind(self, fn) {
  1100. var curryArgs = arguments.length > 2 ? sliceArgs(arguments, 2) : [];
  1101. if (isFunction(fn) && !(fn instanceof RegExp)) {
  1102. return curryArgs.length
  1103. ? function() {
  1104. return arguments.length
  1105. ? fn.apply(self, concat(curryArgs, arguments, 0))
  1106. : fn.apply(self, curryArgs);
  1107. }
  1108. : function() {
  1109. return arguments.length
  1110. ? fn.apply(self, arguments)
  1111. : fn.call(self);
  1112. };
  1113. } else {
  1114. // in IE, native methods are not functions so they cannot be bound (note: they don't need to be)
  1115. return fn;
  1116. }
  1117. }
  1118. function toJsonReplacer(key, value) {
  1119. var val = value;
  1120. if (typeof key === 'string' && key.charAt(0) === '$' && key.charAt(1) === '$') {
  1121. val = undefined;
  1122. } else if (isWindow(value)) {
  1123. val = '$WINDOW';
  1124. } else if (value && window.document === value) {
  1125. val = '$DOCUMENT';
  1126. } else if (isScope(value)) {
  1127. val = '$SCOPE';
  1128. }
  1129. return val;
  1130. }
  1131. /**
  1132. * @ngdoc function
  1133. * @name angular.toJson
  1134. * @module ng
  1135. * @kind function
  1136. *
  1137. * @description
  1138. * Serializes input into a JSON-formatted string. Properties with leading $$ characters will be
  1139. * stripped since angular uses this notation internally.
  1140. *
  1141. * @param {Object|Array|Date|string|number} obj Input to be serialized into JSON.
  1142. * @param {boolean|number} [pretty=2] If set to true, the JSON output will contain newlines and whitespace.
  1143. * If set to an integer, the JSON output will contain that many spaces per indentation.
  1144. * @returns {string|undefined} JSON-ified string representing `obj`.
  1145. */
  1146. function toJson(obj, pretty) {
  1147. if (isUndefined(obj)) return undefined;
  1148. if (!isNumber(pretty)) {
  1149. pretty = pretty ? 2 : null;
  1150. }
  1151. return JSON.stringify(obj, toJsonReplacer, pretty);
  1152. }
  1153. /**
  1154. * @ngdoc function
  1155. * @name angular.fromJson
  1156. * @module ng
  1157. * @kind function
  1158. *
  1159. * @description
  1160. * Deserializes a JSON string.
  1161. *
  1162. * @param {string} json JSON string to deserialize.
  1163. * @returns {Object|Array|string|number} Deserialized JSON string.
  1164. */
  1165. function fromJson(json) {
  1166. return isString(json)
  1167. ? JSON.parse(json)
  1168. : json;
  1169. }
  1170. var ALL_COLONS = /:/g;
  1171. function timezoneToOffset(timezone, fallback) {
  1172. // IE/Edge do not "understand" colon (`:`) in timezone
  1173. timezone = timezone.replace(ALL_COLONS, '');
  1174. var requestedTimezoneOffset = Date.parse('Jan 01, 1970 00:00:00 ' + timezone) / 60000;
  1175. return isNaN(requestedTimezoneOffset) ? fallback : requestedTimezoneOffset;
  1176. }
  1177. function addDateMinutes(date, minutes) {
  1178. date = new Date(date.getTime());
  1179. date.setMinutes(date.getMinutes() + minutes);
  1180. return date;
  1181. }
  1182. function convertTimezoneToLocal(date, timezone, reverse) {
  1183. reverse = reverse ? -1 : 1;
  1184. var dateTimezoneOffset = date.getTimezoneOffset();
  1185. var timezoneOffset = timezoneToOffset(timezone, dateTimezoneOffset);
  1186. return addDateMinutes(date, reverse * (timezoneOffset - dateTimezoneOffset));
  1187. }
  1188. /**
  1189. * @returns {string} Returns the string representation of the element.
  1190. */
  1191. function startingTag(element) {
  1192. element = jqLite(element).clone();
  1193. try {
  1194. // turns out IE does not let you set .html() on elements which
  1195. // are not allowed to have children. So we just ignore it.
  1196. element.empty();
  1197. } catch (e) {}
  1198. var elemHtml = jqLite('<div>').append(element).html();
  1199. try {
  1200. return element[0].nodeType === NODE_TYPE_TEXT ? lowercase(elemHtml) :
  1201. elemHtml.
  1202. match(/^(<[^>]+>)/)[1].
  1203. replace(/^<([\w\-]+)/, function(match, nodeName) {return '<' + lowercase(nodeName);});
  1204. } catch (e) {
  1205. return lowercase(elemHtml);
  1206. }
  1207. }
  1208. /////////////////////////////////////////////////
  1209. /**
  1210. * Tries to decode the URI component without throwing an exception.
  1211. *
  1212. * @private
  1213. * @param str value potential URI component to check.
  1214. * @returns {boolean} True if `value` can be decoded
  1215. * with the decodeURIComponent function.
  1216. */
  1217. function tryDecodeURIComponent(value) {
  1218. try {
  1219. return decodeURIComponent(value);
  1220. } catch (e) {
  1221. // Ignore any invalid uri component
  1222. }
  1223. }
  1224. /**
  1225. * Parses an escaped url query string into key-value pairs.
  1226. * @returns {Object.<string,boolean|Array>}
  1227. */
  1228. function parseKeyValue(/**string*/keyValue) {
  1229. var obj = {};
  1230. forEach((keyValue || "").split('&'), function(keyValue) {
  1231. var splitPoint, key, val;
  1232. if (keyValue) {
  1233. key = keyValue = keyValue.replace(/\+/g,'%20');
  1234. splitPoint = keyValue.indexOf('=');
  1235. if (splitPoint !== -1) {
  1236. key = keyValue.substring(0, splitPoint);
  1237. val = keyValue.substring(splitPoint + 1);
  1238. }
  1239. key = tryDecodeURIComponent(key);
  1240. if (isDefined(key)) {
  1241. val = isDefined(val) ? tryDecodeURIComponent(val) : true;
  1242. if (!hasOwnProperty.call(obj, key)) {
  1243. obj[key] = val;
  1244. } else if (isArray(obj[key])) {
  1245. obj[key].push(val);
  1246. } else {
  1247. obj[key] = [obj[key],val];
  1248. }
  1249. }
  1250. }
  1251. });
  1252. return obj;
  1253. }
  1254. function toKeyValue(obj) {
  1255. var parts = [];
  1256. forEach(obj, function(value, key) {
  1257. if (isArray(value)) {
  1258. forEach(value, function(arrayValue) {
  1259. parts.push(encodeUriQuery(key, true) +
  1260. (arrayValue === true ? '' : '=' + encodeUriQuery(arrayValue, true)));
  1261. });
  1262. } else {
  1263. parts.push(encodeUriQuery(key, true) +
  1264. (value === true ? '' : '=' + encodeUriQuery(value, true)));
  1265. }
  1266. });
  1267. return parts.length ? parts.join('&') : '';
  1268. }
  1269. /**
  1270. * We need our custom method because encodeURIComponent is too aggressive and doesn't follow
  1271. * http://www.ietf.org/rfc/rfc3986.txt with regards to the character set (pchar) allowed in path
  1272. * segments:
  1273. * segment = *pchar
  1274. * pchar = unreserved / pct-encoded / sub-delims / ":" / "@"
  1275. * pct-encoded = "%" HEXDIG HEXDIG
  1276. * unreserved = ALPHA / DIGIT / "-" / "." / "_" / "~"
  1277. * sub-delims = "!" / "$" / "&" / "'" / "(" / ")"
  1278. * / "*" / "+" / "," / ";" / "="
  1279. */
  1280. function encodeUriSegment(val) {
  1281. return encodeUriQuery(val, true).
  1282. replace(/%26/gi, '&').
  1283. replace(/%3D/gi, '=').
  1284. replace(/%2B/gi, '+');
  1285. }
  1286. /**
  1287. * This method is intended for encoding *key* or *value* parts of query component. We need a custom
  1288. * method because encodeURIComponent is too aggressive and encodes stuff that doesn't have to be
  1289. * encoded per http://tools.ietf.org/html/rfc3986:
  1290. * query = *( pchar / "/" / "?" )
  1291. * pchar = unreserved / pct-encoded / sub-delims / ":" / "@"
  1292. * unreserved = ALPHA / DIGIT / "-" / "." / "_" / "~"
  1293. * pct-encoded = "%" HEXDIG HEXDIG
  1294. * sub-delims = "!" / "$" / "&" / "'" / "(" / ")"
  1295. * / "*" / "+" / "," / ";" / "="
  1296. */
  1297. function encodeUriQuery(val, pctEncodeSpaces) {
  1298. return encodeURIComponent(val).
  1299. replace(/%40/gi, '@').
  1300. replace(/%3A/gi, ':').
  1301. replace(/%24/g, '$').
  1302. replace(/%2C/gi, ',').
  1303. replace(/%3B/gi, ';').
  1304. replace(/%20/g, (pctEncodeSpaces ? '%20' : '+'));
  1305. }
  1306. var ngAttrPrefixes = ['ng-', 'data-ng-', 'ng:', 'x-ng-'];
  1307. function getNgAttribute(element, ngAttr) {
  1308. var attr, i, ii = ngAttrPrefixes.length;
  1309. for (i = 0; i < ii; ++i) {
  1310. attr = ngAttrPrefixes[i] + ngAttr;
  1311. if (isString(attr = element.getAttribute(attr))) {
  1312. return attr;
  1313. }
  1314. }
  1315. return null;
  1316. }
  1317. /**
  1318. * @ngdoc directive
  1319. * @name ngApp
  1320. * @module ng
  1321. *
  1322. * @element ANY
  1323. * @param {angular.Module} ngApp an optional application
  1324. * {@link angular.module module} name to load.
  1325. * @param {boolean=} ngStrictDi if this attribute is present on the app element, the injector will be
  1326. * created in "strict-di" mode. This means that the application will fail to invoke functions which
  1327. * do not use explicit function annotation (and are thus unsuitable for minification), as described
  1328. * in {@link guide/di the Dependency Injection guide}, and useful debugging info will assist in
  1329. * tracking down the root of these bugs.
  1330. *
  1331. * @description
  1332. *
  1333. * Use this directive to **auto-bootstrap** an AngularJS application. The `ngApp` directive
  1334. * designates the **root element** of the application and is typically placed near the root element
  1335. * of the page - e.g. on the `<body>` or `<html>` tags.
  1336. *
  1337. * There are a few things to keep in mind when using `ngApp`:
  1338. * - only one AngularJS application can be auto-bootstrapped per HTML document. The first `ngApp`
  1339. * found in the document will be used to define the root element to auto-bootstrap as an
  1340. * application. To run multiple applications in an HTML document you must manually bootstrap them using
  1341. * {@link angular.bootstrap} instead.
  1342. * - AngularJS applications cannot be nested within each other.
  1343. * - Do not use a directive that uses {@link ng.$compile#transclusion transclusion} on the same element as `ngApp`.
  1344. * This includes directives such as {@link ng.ngIf `ngIf`}, {@link ng.ngInclude `ngInclude`} and
  1345. * {@link ngRoute.ngView `ngView`}.
  1346. * Doing this misplaces the app {@link ng.$rootElement `$rootElement`} and the app's {@link auto.$injector injector},
  1347. * causing animations to stop working and making the injector inaccessible from outside the app.
  1348. *
  1349. * You can specify an **AngularJS module** to be used as the root module for the application. This
  1350. * module will be loaded into the {@link auto.$injector} when the application is bootstrapped. It
  1351. * should contain the application code needed or have dependencies on other modules that will
  1352. * contain the code. See {@link angular.module} for more information.
  1353. *
  1354. * In the example below if the `ngApp` directive were not placed on the `html` element then the
  1355. * document would not be compiled, the `AppController` would not be instantiated and the `{{ a+b }}`
  1356. * would not be resolved to `3`.
  1357. *
  1358. * `ngApp` is the easiest, and most common way to bootstrap an application.
  1359. *
  1360. <example module="ngAppDemo">
  1361. <file name="index.html">
  1362. <div ng-controller="ngAppDemoController">
  1363. I can add: {{a}} + {{b}} = {{ a+b }}
  1364. </div>
  1365. </file>
  1366. <file name="script.js">
  1367. angular.module('ngAppDemo', []).controller('ngAppDemoController', function($scope) {
  1368. $scope.a = 1;
  1369. $scope.b = 2;
  1370. });
  1371. </file>
  1372. </example>
  1373. *
  1374. * Using `ngStrictDi`, you would see something like this:
  1375. *
  1376. <example ng-app-included="true">
  1377. <file name="index.html">
  1378. <div ng-app="ngAppStrictDemo" ng-strict-di>
  1379. <div ng-controller="GoodController1">
  1380. I can add: {{a}} + {{b}} = {{ a+b }}
  1381. <p>This renders because the controller does not fail to
  1382. instantiate, by using explicit annotation style (see
  1383. script.js for details)
  1384. </p>
  1385. </div>
  1386. <div ng-controller="GoodController2">
  1387. Name: <input ng-model="name"><br />
  1388. Hello, {{name}}!
  1389. <p>This renders because the controller does not fail to
  1390. instantiate, by using explicit annotation style
  1391. (see script.js for details)
  1392. </p>
  1393. </div>
  1394. <div ng-controller="BadController">
  1395. I can add: {{a}} + {{b}} = {{ a+b }}
  1396. <p>The controller could not be instantiated, due to relying
  1397. on automatic function annotations (which are disabled in
  1398. strict mode). As such, the content of this section is not
  1399. interpolated, and there should be an error in your web console.
  1400. </p>
  1401. </div>
  1402. </div>
  1403. </file>
  1404. <file name="script.js">
  1405. angular.module('ngAppStrictDemo', [])
  1406. // BadController will fail to instantiate, due to relying on automatic function annotation,
  1407. // rather than an explicit annotation
  1408. .controller('BadController', function($scope) {
  1409. $scope.a = 1;
  1410. $scope.b = 2;
  1411. })
  1412. // Unlike BadController, GoodController1 and GoodController2 will not fail to be instantiated,
  1413. // due to using explicit annotations using the array style and $inject property, respectively.
  1414. .controller('GoodController1', ['$scope', function($scope) {
  1415. $scope.a = 1;
  1416. $scope.b = 2;
  1417. }])
  1418. .controller('GoodController2', GoodController2);
  1419. function GoodController2($scope) {
  1420. $scope.name = "World";
  1421. }
  1422. GoodController2.$inject = ['$scope'];
  1423. </file>
  1424. <file name="style.css">
  1425. div[ng-controller] {
  1426. margin-bottom: 1em;
  1427. -webkit-border-radius: 4px;
  1428. border-radius: 4px;
  1429. border: 1px solid;
  1430. padding: .5em;
  1431. }
  1432. div[ng-controller^=Good] {
  1433. border-color: #d6e9c6;
  1434. background-color: #dff0d8;
  1435. color: #3c763d;
  1436. }
  1437. div[ng-controller^=Bad] {
  1438. border-color: #ebccd1;
  1439. background-color: #f2dede;
  1440. color: #a94442;
  1441. margin-bottom: 0;
  1442. }
  1443. </file>
  1444. </example>
  1445. */
  1446. function angularInit(element, bootstrap) {
  1447. var appElement,
  1448. module,
  1449. config = {};
  1450. // The element `element` has priority over any other element
  1451. forEach(ngAttrPrefixes, function(prefix) {
  1452. var name = prefix + 'app';
  1453. if (!appElement && element.hasAttribute && element.hasAttribute(name)) {
  1454. appElement = element;
  1455. module = element.getAttribute(name);
  1456. }
  1457. });
  1458. forEach(ngAttrPrefixes, function(prefix) {
  1459. var name = prefix + 'app';
  1460. var candidate;
  1461. if (!appElement && (candidate = element.querySelector('[' + name.replace(':', '\\:') + ']'))) {
  1462. appElement = candidate;
  1463. module = candidate.getAttribute(name);
  1464. }
  1465. });
  1466. if (appElement) {
  1467. config.strictDi = getNgAttribute(appElement, "strict-di") !== null;
  1468. bootstrap(appElement, module ? [module] : [], config);
  1469. }
  1470. }
  1471. /**
  1472. * @ngdoc function
  1473. * @name angular.bootstrap
  1474. * @module ng
  1475. * @description
  1476. * Use this function to manually start up angular application.
  1477. *
  1478. * For more information, see the {@link guide/bootstrap Bootstrap guide}.
  1479. *
  1480. * Angular will detect if it has been loaded into the browser more than once and only allow the
  1481. * first loaded script to be bootstrapped and will report a warning to the browser console for
  1482. * each of the subsequent scripts. This prevents strange results in applications, where otherwise
  1483. * multiple instances of Angular try to work on the DOM.
  1484. *
  1485. * <div class="alert alert-warning">
  1486. * **Note:** Protractor based end-to-end tests cannot use this function to bootstrap manually.
  1487. * They must use {@link ng.directive:ngApp ngApp}.
  1488. * </div>
  1489. *
  1490. * <div class="alert alert-warning">
  1491. * **Note:** Do not bootstrap the app on an element with a directive that uses {@link ng.$compile#transclusion transclusion},
  1492. * such as {@link ng.ngIf `ngIf`}, {@link ng.ngInclude `ngInclude`} and {@link ngRoute.ngView `ngView`}.
  1493. * Doing this misplaces the app {@link ng.$rootElement `$rootElement`} and the app's {@link auto.$injector injector},
  1494. * causing animations to stop working and making the injector inaccessible from