PageRenderTime 53ms CodeModel.GetById 14ms RepoModel.GetById 1ms app.codeStats 0ms

/app/js/angular.js

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