PageRenderTime 30ms CodeModel.GetById 16ms RepoModel.GetById 0ms app.codeStats 0ms

/front/www/lib/angular/angular.js

https://gitlab.com/boxnia/NFU_MOVIL
JavaScript | 1691 lines | 642 code | 169 blank | 880 comment | 201 complexity | 5eb4e4259c11ee6bdcf6329c4f9a3d47 MD5 | raw file
  1. /**
  2. * @license AngularJS v1.4.3
  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.3/' +
  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 {
  384. if (!isObject(dst[key])) dst[key] = isArray(src) ? [] : {};
  385. baseExtend(dst[key], [src], true);
  386. }
  387. } else {
  388. dst[key] = src;
  389. }
  390. }
  391. }
  392. setHashKey(dst, h);
  393. return dst;
  394. }
  395. /**
  396. * @ngdoc function
  397. * @name angular.extend
  398. * @module ng
  399. * @kind function
  400. *
  401. * @description
  402. * Extends the destination object `dst` by copying own enumerable properties from the `src` object(s)
  403. * to `dst`. You can specify multiple `src` objects. If you want to preserve original objects, you can do so
  404. * by passing an empty object as the target: `var object = angular.extend({}, object1, object2)`.
  405. *
  406. * **Note:** Keep in mind that `angular.extend` does not support recursive merge (deep copy). Use
  407. * {@link angular.merge} for this.
  408. *
  409. * @param {Object} dst Destination object.
  410. * @param {...Object} src Source object(s).
  411. * @returns {Object} Reference to `dst`.
  412. */
  413. function extend(dst) {
  414. return baseExtend(dst, slice.call(arguments, 1), false);
  415. }
  416. /**
  417. * @ngdoc function
  418. * @name angular.merge
  419. * @module ng
  420. * @kind function
  421. *
  422. * @description
  423. * Deeply extends the destination object `dst` by copying own enumerable properties from the `src` object(s)
  424. * to `dst`. You can specify multiple `src` objects. If you want to preserve original objects, you can do so
  425. * by passing an empty object as the target: `var object = angular.merge({}, object1, object2)`.
  426. *
  427. * Unlike {@link angular.extend extend()}, `merge()` recursively descends into object properties of source
  428. * objects, performing a deep copy.
  429. *
  430. * @param {Object} dst Destination object.
  431. * @param {...Object} src Source object(s).
  432. * @returns {Object} Reference to `dst`.
  433. */
  434. function merge(dst) {
  435. return baseExtend(dst, slice.call(arguments, 1), true);
  436. }
  437. function toInt(str) {
  438. return parseInt(str, 10);
  439. }
  440. function inherit(parent, extra) {
  441. return extend(Object.create(parent), extra);
  442. }
  443. /**
  444. * @ngdoc function
  445. * @name angular.noop
  446. * @module ng
  447. * @kind function
  448. *
  449. * @description
  450. * A function that performs no operations. This function can be useful when writing code in the
  451. * functional style.
  452. ```js
  453. function foo(callback) {
  454. var result = calculateResult();
  455. (callback || angular.noop)(result);
  456. }
  457. ```
  458. */
  459. function noop() {}
  460. noop.$inject = [];
  461. /**
  462. * @ngdoc function
  463. * @name angular.identity
  464. * @module ng
  465. * @kind function
  466. *
  467. * @description
  468. * A function that returns its first argument. This function is useful when writing code in the
  469. * functional style.
  470. *
  471. ```js
  472. function transformer(transformationFn, value) {
  473. return (transformationFn || angular.identity)(value);
  474. };
  475. ```
  476. * @param {*} value to be returned.
  477. * @returns {*} the value passed in.
  478. */
  479. function identity($) {return $;}
  480. identity.$inject = [];
  481. function valueFn(value) {return function() {return value;};}
  482. function hasCustomToString(obj) {
  483. return isFunction(obj.toString) && obj.toString !== Object.prototype.toString;
  484. }
  485. /**
  486. * @ngdoc function
  487. * @name angular.isUndefined
  488. * @module ng
  489. * @kind function
  490. *
  491. * @description
  492. * Determines if a reference is undefined.
  493. *
  494. * @param {*} value Reference to check.
  495. * @returns {boolean} True if `value` is undefined.
  496. */
  497. function isUndefined(value) {return typeof value === 'undefined';}
  498. /**
  499. * @ngdoc function
  500. * @name angular.isDefined
  501. * @module ng
  502. * @kind function
  503. *
  504. * @description
  505. * Determines if a reference is defined.
  506. *
  507. * @param {*} value Reference to check.
  508. * @returns {boolean} True if `value` is defined.
  509. */
  510. function isDefined(value) {return typeof value !== 'undefined';}
  511. /**
  512. * @ngdoc function
  513. * @name angular.isObject
  514. * @module ng
  515. * @kind function
  516. *
  517. * @description
  518. * Determines if a reference is an `Object`. Unlike `typeof` in JavaScript, `null`s are not
  519. * considered to be objects. Note that JavaScript arrays are objects.
  520. *
  521. * @param {*} value Reference to check.
  522. * @returns {boolean} True if `value` is an `Object` but not `null`.
  523. */
  524. function isObject(value) {
  525. // http://jsperf.com/isobject4
  526. return value !== null && typeof value === 'object';
  527. }
  528. /**
  529. * Determine if a value is an object with a null prototype
  530. *
  531. * @returns {boolean} True if `value` is an `Object` with a null prototype
  532. */
  533. function isBlankObject(value) {
  534. return value !== null && typeof value === 'object' && !getPrototypeOf(value);
  535. }
  536. /**
  537. * @ngdoc function
  538. * @name angular.isString
  539. * @module ng
  540. * @kind function
  541. *
  542. * @description
  543. * Determines if a reference is a `String`.
  544. *
  545. * @param {*} value Reference to check.
  546. * @returns {boolean} True if `value` is a `String`.
  547. */
  548. function isString(value) {return typeof value === 'string';}
  549. /**
  550. * @ngdoc function
  551. * @name angular.isNumber
  552. * @module ng
  553. * @kind function
  554. *
  555. * @description
  556. * Determines if a reference is a `Number`.
  557. *
  558. * This includes the "special" numbers `NaN`, `+Infinity` and `-Infinity`.
  559. *
  560. * If you wish to exclude these then you can use the native
  561. * [`isFinite'](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/isFinite)
  562. * method.
  563. *
  564. * @param {*} value Reference to check.
  565. * @returns {boolean} True if `value` is a `Number`.
  566. */
  567. function isNumber(value) {return typeof value === 'number';}
  568. /**
  569. * @ngdoc function
  570. * @name angular.isDate
  571. * @module ng
  572. * @kind function
  573. *
  574. * @description
  575. * Determines if a value is a date.
  576. *
  577. * @param {*} value Reference to check.
  578. * @returns {boolean} True if `value` is a `Date`.
  579. */
  580. function isDate(value) {
  581. return toString.call(value) === '[object Date]';
  582. }
  583. /**
  584. * @ngdoc function
  585. * @name angular.isArray
  586. * @module ng
  587. * @kind function
  588. *
  589. * @description
  590. * Determines if a reference is an `Array`.
  591. *
  592. * @param {*} value Reference to check.
  593. * @returns {boolean} True if `value` is an `Array`.
  594. */
  595. var isArray = Array.isArray;
  596. /**
  597. * @ngdoc function
  598. * @name angular.isFunction
  599. * @module ng
  600. * @kind function
  601. *
  602. * @description
  603. * Determines if a reference is a `Function`.
  604. *
  605. * @param {*} value Reference to check.
  606. * @returns {boolean} True if `value` is a `Function`.
  607. */
  608. function isFunction(value) {return typeof value === 'function';}
  609. /**
  610. * Determines if a value is a regular expression object.
  611. *
  612. * @private
  613. * @param {*} value Reference to check.
  614. * @returns {boolean} True if `value` is a `RegExp`.
  615. */
  616. function isRegExp(value) {
  617. return toString.call(value) === '[object RegExp]';
  618. }
  619. /**
  620. * Checks if `obj` is a window object.
  621. *
  622. * @private
  623. * @param {*} obj Object to check
  624. * @returns {boolean} True if `obj` is a window obj.
  625. */
  626. function isWindow(obj) {
  627. return obj && obj.window === obj;
  628. }
  629. function isScope(obj) {
  630. return obj && obj.$evalAsync && obj.$watch;
  631. }
  632. function isFile(obj) {
  633. return toString.call(obj) === '[object File]';
  634. }
  635. function isFormData(obj) {
  636. return toString.call(obj) === '[object FormData]';
  637. }
  638. function isBlob(obj) {
  639. return toString.call(obj) === '[object Blob]';
  640. }
  641. function isBoolean(value) {
  642. return typeof value === 'boolean';
  643. }
  644. function isPromiseLike(obj) {
  645. return obj && isFunction(obj.then);
  646. }
  647. var TYPED_ARRAY_REGEXP = /^\[object (Uint8(Clamped)?)|(Uint16)|(Uint32)|(Int8)|(Int16)|(Int32)|(Float(32)|(64))Array\]$/;
  648. function isTypedArray(value) {
  649. return TYPED_ARRAY_REGEXP.test(toString.call(value));
  650. }
  651. var trim = function(value) {
  652. return isString(value) ? value.trim() : value;
  653. };
  654. // Copied from:
  655. // http://docs.closure-library.googlecode.com/git/local_closure_goog_string_string.js.source.html#line1021
  656. // Prereq: s is a string.
  657. var escapeForRegexp = function(s) {
  658. return s.replace(/([-()\[\]{}+?*.$\^|,:#<!\\])/g, '\\$1').
  659. replace(/\x08/g, '\\x08');
  660. };
  661. /**
  662. * @ngdoc function
  663. * @name angular.isElement
  664. * @module ng
  665. * @kind function
  666. *
  667. * @description
  668. * Determines if a reference is a DOM element (or wrapped jQuery element).
  669. *
  670. * @param {*} value Reference to check.
  671. * @returns {boolean} True if `value` is a DOM element (or wrapped jQuery element).
  672. */
  673. function isElement(node) {
  674. return !!(node &&
  675. (node.nodeName // we are a direct element
  676. || (node.prop && node.attr && node.find))); // we have an on and find method part of jQuery API
  677. }
  678. /**
  679. * @param str 'key1,key2,...'
  680. * @returns {object} in the form of {key1:true, key2:true, ...}
  681. */
  682. function makeMap(str) {
  683. var obj = {}, items = str.split(","), i;
  684. for (i = 0; i < items.length; i++) {
  685. obj[items[i]] = true;
  686. }
  687. return obj;
  688. }
  689. function nodeName_(element) {
  690. return lowercase(element.nodeName || (element[0] && element[0].nodeName));
  691. }
  692. function includes(array, obj) {
  693. return Array.prototype.indexOf.call(array, obj) != -1;
  694. }
  695. function arrayRemove(array, value) {
  696. var index = array.indexOf(value);
  697. if (index >= 0) {
  698. array.splice(index, 1);
  699. }
  700. return index;
  701. }
  702. /**
  703. * @ngdoc function
  704. * @name angular.copy
  705. * @module ng
  706. * @kind function
  707. *
  708. * @description
  709. * Creates a deep copy of `source`, which should be an object or an array.
  710. *
  711. * * If no destination is supplied, a copy of the object or array is created.
  712. * * If a destination is provided, all of its elements (for arrays) or properties (for objects)
  713. * are deleted and then all elements/properties from the source are copied to it.
  714. * * If `source` is not an object or array (inc. `null` and `undefined`), `source` is returned.
  715. * * If `source` is identical to 'destination' an exception will be thrown.
  716. *
  717. * @param {*} source The source that will be used to make a copy.
  718. * Can be any type, including primitives, `null`, and `undefined`.
  719. * @param {(Object|Array)=} destination Destination into which the source is copied. If
  720. * provided, must be of the same type as `source`.
  721. * @returns {*} The copy or updated `destination`, if `destination` was specified.
  722. *
  723. * @example
  724. <example module="copyExample">
  725. <file name="index.html">
  726. <div ng-controller="ExampleController">
  727. <form novalidate class="simple-form">
  728. Name: <input type="text" ng-model="user.name" /><br />
  729. E-mail: <input type="email" ng-model="user.email" /><br />
  730. Gender: <input type="radio" ng-model="user.gender" value="male" />male
  731. <input type="radio" ng-model="user.gender" value="female" />female<br />
  732. <button ng-click="reset()">RESET</button>
  733. <button ng-click="update(user)">SAVE</button>
  734. </form>
  735. <pre>form = {{user | json}}</pre>
  736. <pre>master = {{master | json}}</pre>
  737. </div>
  738. <script>
  739. angular.module('copyExample', [])
  740. .controller('ExampleController', ['$scope', function($scope) {
  741. $scope.master= {};
  742. $scope.update = function(user) {
  743. // Example with 1 argument
  744. $scope.master= angular.copy(user);
  745. };
  746. $scope.reset = function() {
  747. // Example with 2 arguments
  748. angular.copy($scope.master, $scope.user);
  749. };
  750. $scope.reset();
  751. }]);
  752. </script>
  753. </file>
  754. </example>
  755. */
  756. function copy(source, destination, stackSource, stackDest) {
  757. if (isWindow(source) || isScope(source)) {
  758. throw ngMinErr('cpws',
  759. "Can't copy! Making copies of Window or Scope instances is not supported.");
  760. }
  761. if (isTypedArray(destination)) {
  762. throw ngMinErr('cpta',
  763. "Can't copy! TypedArray destination cannot be mutated.");
  764. }
  765. if (!destination) {
  766. destination = source;
  767. if (isObject(source)) {
  768. var index;
  769. if (stackSource && (index = stackSource.indexOf(source)) !== -1) {
  770. return stackDest[index];
  771. }
  772. // TypedArray, Date and RegExp have specific copy functionality and must be
  773. // pushed onto the stack before returning.
  774. // Array and other objects create the base object and recurse to copy child
  775. // objects. The array/object will be pushed onto the stack when recursed.
  776. if (isArray(source)) {
  777. return copy(source, [], stackSource, stackDest);
  778. } else if (isTypedArray(source)) {
  779. destination = new source.constructor(source);
  780. } else if (isDate(source)) {
  781. destination = new Date(source.getTime());
  782. } else if (isRegExp(source)) {
  783. destination = new RegExp(source.source, source.toString().match(/[^\/]*$/)[0]);
  784. destination.lastIndex = source.lastIndex;
  785. } else {
  786. var emptyObject = Object.create(getPrototypeOf(source));
  787. return copy(source, emptyObject, stackSource, stackDest);
  788. }
  789. if (stackDest) {
  790. stackSource.push(source);
  791. stackDest.push(destination);
  792. }
  793. }
  794. } else {
  795. if (source === destination) throw ngMinErr('cpi',
  796. "Can't copy! Source and destination are identical.");
  797. stackSource = stackSource || [];
  798. stackDest = stackDest || [];
  799. if (isObject(source)) {
  800. stackSource.push(source);
  801. stackDest.push(destination);
  802. }
  803. var result, key;
  804. if (isArray(source)) {
  805. destination.length = 0;
  806. for (var i = 0; i < source.length; i++) {
  807. destination.push(copy(source[i], null, stackSource, stackDest));
  808. }
  809. } else {
  810. var h = destination.$$hashKey;
  811. if (isArray(destination)) {
  812. destination.length = 0;
  813. } else {
  814. forEach(destination, function(value, key) {
  815. delete destination[key];
  816. });
  817. }
  818. if (isBlankObject(source)) {
  819. // createMap() fast path --- Safe to avoid hasOwnProperty check because prototype chain is empty
  820. for (key in source) {
  821. destination[key] = copy(source[key], null, stackSource, stackDest);
  822. }
  823. } else if (source && typeof source.hasOwnProperty === 'function') {
  824. // Slow path, which must rely on hasOwnProperty
  825. for (key in source) {
  826. if (source.hasOwnProperty(key)) {
  827. destination[key] = copy(source[key], null, stackSource, stackDest);
  828. }
  829. }
  830. } else {
  831. // Slowest path --- hasOwnProperty can't be called as a method
  832. for (key in source) {
  833. if (hasOwnProperty.call(source, key)) {
  834. destination[key] = copy(source[key], null, stackSource, stackDest);
  835. }
  836. }
  837. }
  838. setHashKey(destination,h);
  839. }
  840. }
  841. return destination;
  842. }
  843. /**
  844. * Creates a shallow copy of an object, an array or a primitive.
  845. *
  846. * Assumes that there are no proto properties for objects.
  847. */
  848. function shallowCopy(src, dst) {
  849. if (isArray(src)) {
  850. dst = dst || [];
  851. for (var i = 0, ii = src.length; i < ii; i++) {
  852. dst[i] = src[i];
  853. }
  854. } else if (isObject(src)) {
  855. dst = dst || {};
  856. for (var key in src) {
  857. if (!(key.charAt(0) === '$' && key.charAt(1) === '$')) {
  858. dst[key] = src[key];
  859. }
  860. }
  861. }
  862. return dst || src;
  863. }
  864. /**
  865. * @ngdoc function
  866. * @name angular.equals
  867. * @module ng
  868. * @kind function
  869. *
  870. * @description
  871. * Determines if two objects or two values are equivalent. Supports value types, regular
  872. * expressions, arrays and objects.
  873. *
  874. * Two objects or values are considered equivalent if at least one of the following is true:
  875. *
  876. * * Both objects or values pass `===` comparison.
  877. * * Both objects or values are of the same type and all of their properties are equal by
  878. * comparing them with `angular.equals`.
  879. * * Both values are NaN. (In JavaScript, NaN == NaN => false. But we consider two NaN as equal)
  880. * * Both values represent the same regular expression (In JavaScript,
  881. * /abc/ == /abc/ => false. But we consider two regular expressions as equal when their textual
  882. * representation matches).
  883. *
  884. * During a property comparison, properties of `function` type and properties with names
  885. * that begin with `$` are ignored.
  886. *
  887. * Scope and DOMWindow objects are being compared only by identify (`===`).
  888. *
  889. * @param {*} o1 Object or value to compare.
  890. * @param {*} o2 Object or value to compare.
  891. * @returns {boolean} True if arguments are equal.
  892. */
  893. function equals(o1, o2) {
  894. if (o1 === o2) return true;
  895. if (o1 === null || o2 === null) return false;
  896. if (o1 !== o1 && o2 !== o2) return true; // NaN === NaN
  897. var t1 = typeof o1, t2 = typeof o2, length, key, keySet;
  898. if (t1 == t2) {
  899. if (t1 == 'object') {
  900. if (isArray(o1)) {
  901. if (!isArray(o2)) return false;
  902. if ((length = o1.length) == o2.length) {
  903. for (key = 0; key < length; key++) {
  904. if (!equals(o1[key], o2[key])) return false;
  905. }
  906. return true;
  907. }
  908. } else if (isDate(o1)) {
  909. if (!isDate(o2)) return false;
  910. return equals(o1.getTime(), o2.getTime());
  911. } else if (isRegExp(o1)) {
  912. return isRegExp(o2) ? o1.toString() == o2.toString() : false;
  913. } else {
  914. if (isScope(o1) || isScope(o2) || isWindow(o1) || isWindow(o2) ||
  915. isArray(o2) || isDate(o2) || isRegExp(o2)) return false;
  916. keySet = createMap();
  917. for (key in o1) {
  918. if (key.charAt(0) === '$' || isFunction(o1[key])) continue;
  919. if (!equals(o1[key], o2[key])) return false;
  920. keySet[key] = true;
  921. }
  922. for (key in o2) {
  923. if (!(key in keySet) &&
  924. key.charAt(0) !== '$' &&
  925. o2[key] !== undefined &&
  926. !isFunction(o2[key])) return false;
  927. }
  928. return true;
  929. }
  930. }
  931. }
  932. return false;
  933. }
  934. var csp = function() {
  935. if (isDefined(csp.isActive_)) return csp.isActive_;
  936. var active = !!(document.querySelector('[ng-csp]') ||
  937. document.querySelector('[data-ng-csp]'));
  938. if (!active) {
  939. try {
  940. /* jshint -W031, -W054 */
  941. new Function('');
  942. /* jshint +W031, +W054 */
  943. } catch (e) {
  944. active = true;
  945. }
  946. }
  947. return (csp.isActive_ = active);
  948. };
  949. /**
  950. * @ngdoc directive
  951. * @module ng
  952. * @name ngJq
  953. *
  954. * @element ANY
  955. * @param {string=} ngJq the name of the library available under `window`
  956. * to be used for angular.element
  957. * @description
  958. * Use this directive to force the angular.element library. This should be
  959. * used to force either jqLite by leaving ng-jq blank or setting the name of
  960. * the jquery variable under window (eg. jQuery).
  961. *
  962. * Since angular looks for this directive when it is loaded (doesn't wait for the
  963. * DOMContentLoaded event), it must be placed on an element that comes before the script
  964. * which loads angular. Also, only the first instance of `ng-jq` will be used and all
  965. * others ignored.
  966. *
  967. * @example
  968. * This example shows how to force jqLite using the `ngJq` directive to the `html` tag.
  969. ```html
  970. <!doctype html>
  971. <html ng-app ng-jq>
  972. ...
  973. ...
  974. </html>
  975. ```
  976. * @example
  977. * This example shows how to use a jQuery based library of a different name.
  978. * The library name must be available at the top most 'window'.
  979. ```html
  980. <!doctype html>
  981. <html ng-app ng-jq="jQueryLib">
  982. ...
  983. ...
  984. </html>
  985. ```
  986. */
  987. var jq = function() {
  988. if (isDefined(jq.name_)) return jq.name_;
  989. var el;
  990. var i, ii = ngAttrPrefixes.length, prefix, name;
  991. for (i = 0; i < ii; ++i) {
  992. prefix = ngAttrPrefixes[i];
  993. if (el = document.querySelector('[' + prefix.replace(':', '\\:') + 'jq]')) {
  994. name = el.getAttribute(prefix + 'jq');
  995. break;
  996. }
  997. }
  998. return (jq.name_ = name);
  999. };
  1000. function concat(array1, array2, index) {
  1001. return array1.concat(slice.call(array2, index));
  1002. }
  1003. function sliceArgs(args, startIndex) {
  1004. return slice.call(args, startIndex || 0);
  1005. }
  1006. /* jshint -W101 */
  1007. /**
  1008. * @ngdoc function
  1009. * @name angular.bind
  1010. * @module ng
  1011. * @kind function
  1012. *
  1013. * @description
  1014. * Returns a function which calls function `fn` bound to `self` (`self` becomes the `this` for
  1015. * `fn`). You can supply optional `args` that are prebound to the function. This feature is also
  1016. * known as [partial application](http://en.wikipedia.org/wiki/Partial_application), as
  1017. * distinguished from [function currying](http://en.wikipedia.org/wiki/Currying#Contrast_with_partial_function_application).
  1018. *
  1019. * @param {Object} self Context which `fn` should be evaluated in.
  1020. * @param {function()} fn Function to be bound.
  1021. * @param {...*} args Optional arguments to be prebound to the `fn` function call.
  1022. * @returns {function()} Function that wraps the `fn` with all the specified bindings.
  1023. */
  1024. /* jshint +W101 */
  1025. function bind(self, fn) {
  1026. var curryArgs = arguments.length > 2 ? sliceArgs(arguments, 2) : [];
  1027. if (isFunction(fn) && !(fn instanceof RegExp)) {
  1028. return curryArgs.length
  1029. ? function() {
  1030. return arguments.length
  1031. ? fn.apply(self, concat(curryArgs, arguments, 0))
  1032. : fn.apply(self, curryArgs);
  1033. }
  1034. : function() {
  1035. return arguments.length
  1036. ? fn.apply(self, arguments)
  1037. : fn.call(self);
  1038. };
  1039. } else {
  1040. // in IE, native methods are not functions so they cannot be bound (note: they don't need to be)
  1041. return fn;
  1042. }
  1043. }
  1044. function toJsonReplacer(key, value) {
  1045. var val = value;
  1046. if (typeof key === 'string' && key.charAt(0) === '$' && key.charAt(1) === '$') {
  1047. val = undefined;
  1048. } else if (isWindow(value)) {
  1049. val = '$WINDOW';
  1050. } else if (value && document === value) {
  1051. val = '$DOCUMENT';
  1052. } else if (isScope(value)) {
  1053. val = '$SCOPE';
  1054. }
  1055. return val;
  1056. }
  1057. /**
  1058. * @ngdoc function
  1059. * @name angular.toJson
  1060. * @module ng
  1061. * @kind function
  1062. *
  1063. * @description
  1064. * Serializes input into a JSON-formatted string. Properties with leading $$ characters will be
  1065. * stripped since angular uses this notation internally.
  1066. *
  1067. * @param {Object|Array|Date|string|number} obj Input to be serialized into JSON.
  1068. * @param {boolean|number} [pretty=2] If set to true, the JSON output will contain newlines and whitespace.
  1069. * If set to an integer, the JSON output will contain that many spaces per indentation.
  1070. * @returns {string|undefined} JSON-ified string representing `obj`.
  1071. */
  1072. function toJson(obj, pretty) {
  1073. if (typeof obj === 'undefined') return undefined;
  1074. if (!isNumber(pretty)) {
  1075. pretty = pretty ? 2 : null;
  1076. }
  1077. return JSON.stringify(obj, toJsonReplacer, pretty);
  1078. }
  1079. /**
  1080. * @ngdoc function
  1081. * @name angular.fromJson
  1082. * @module ng
  1083. * @kind function
  1084. *
  1085. * @description
  1086. * Deserializes a JSON string.
  1087. *
  1088. * @param {string} json JSON string to deserialize.
  1089. * @returns {Object|Array|string|number} Deserialized JSON string.
  1090. */
  1091. function fromJson(json) {
  1092. return isString(json)
  1093. ? JSON.parse(json)
  1094. : json;
  1095. }
  1096. function timezoneToOffset(timezone, fallback) {
  1097. var requestedTimezoneOffset = Date.parse('Jan 01, 1970 00:00:00 ' + timezone) / 60000;
  1098. return isNaN(requestedTimezoneOffset) ? fallback : requestedTimezoneOffset;
  1099. }
  1100. function addDateMinutes(date, minutes) {
  1101. date = new Date(date.getTime());
  1102. date.setMinutes(date.getMinutes() + minutes);
  1103. return date;
  1104. }
  1105. function convertTimezoneToLocal(date, timezone, reverse) {
  1106. reverse = reverse ? -1 : 1;
  1107. var timezoneOffset = timezoneToOffset(timezone, date.getTimezoneOffset());
  1108. return addDateMinutes(date, reverse * (timezoneOffset - date.getTimezoneOffset()));
  1109. }
  1110. /**
  1111. * @returns {string} Returns the string representation of the element.
  1112. */
  1113. function startingTag(element) {
  1114. element = jqLite(element).clone();
  1115. try {
  1116. // turns out IE does not let you set .html() on elements which
  1117. // are not allowed to have children. So we just ignore it.
  1118. element.empty();
  1119. } catch (e) {}
  1120. var elemHtml = jqLite('<div>').append(element).html();
  1121. try {
  1122. return element[0].nodeType === NODE_TYPE_TEXT ? lowercase(elemHtml) :
  1123. elemHtml.
  1124. match(/^(<[^>]+>)/)[1].
  1125. replace(/^<([\w\-]+)/, function(match, nodeName) { return '<' + lowercase(nodeName); });
  1126. } catch (e) {
  1127. return lowercase(elemHtml);
  1128. }
  1129. }
  1130. /////////////////////////////////////////////////
  1131. /**
  1132. * Tries to decode the URI component without throwing an exception.
  1133. *
  1134. * @private
  1135. * @param str value potential URI component to check.
  1136. * @returns {boolean} True if `value` can be decoded
  1137. * with the decodeURIComponent function.
  1138. */
  1139. function tryDecodeURIComponent(value) {
  1140. try {
  1141. return decodeURIComponent(value);
  1142. } catch (e) {
  1143. // Ignore any invalid uri component
  1144. }
  1145. }
  1146. /**
  1147. * Parses an escaped url query string into key-value pairs.
  1148. * @returns {Object.<string,boolean|Array>}
  1149. */
  1150. function parseKeyValue(/**string*/keyValue) {
  1151. var obj = {}, key_value, key;
  1152. forEach((keyValue || "").split('&'), function(keyValue) {
  1153. if (keyValue) {
  1154. key_value = keyValue.replace(/\+/g,'%20').split('=');
  1155. key = tryDecodeURIComponent(key_value[0]);
  1156. if (isDefined(key)) {
  1157. var val = isDefined(key_value[1]) ? tryDecodeURIComponent(key_value[1]) : true;
  1158. if (!hasOwnProperty.call(obj, key)) {
  1159. obj[key] = val;
  1160. } else if (isArray(obj[key])) {
  1161. obj[key].push(val);
  1162. } else {
  1163. obj[key] = [obj[key],val];
  1164. }
  1165. }
  1166. }
  1167. });
  1168. return obj;
  1169. }
  1170. function toKeyValue(obj) {
  1171. var parts = [];
  1172. forEach(obj, function(value, key) {
  1173. if (isArray(value)) {
  1174. forEach(value, function(arrayValue) {
  1175. parts.push(encodeUriQuery(key, true) +
  1176. (arrayValue === true ? '' : '=' + encodeUriQuery(arrayValue, true)));
  1177. });
  1178. } else {
  1179. parts.push(encodeUriQuery(key, true) +
  1180. (value === true ? '' : '=' + encodeUriQuery(value, true)));
  1181. }
  1182. });
  1183. return parts.length ? parts.join('&') : '';
  1184. }
  1185. /**
  1186. * We need our custom method because encodeURIComponent is too aggressive and doesn't follow
  1187. * http://www.ietf.org/rfc/rfc3986.txt with regards to the character set (pchar) allowed in path
  1188. * segments:
  1189. * segment = *pchar
  1190. * pchar = unreserved / pct-encoded / sub-delims / ":" / "@"
  1191. * pct-encoded = "%" HEXDIG HEXDIG
  1192. * unreserved = ALPHA / DIGIT / "-" / "." / "_" / "~"
  1193. * sub-delims = "!" / "$" / "&" / "'" / "(" / ")"
  1194. * / "*" / "+" / "," / ";" / "="
  1195. */
  1196. function encodeUriSegment(val) {
  1197. return encodeUriQuery(val, true).
  1198. replace(/%26/gi, '&').
  1199. replace(/%3D/gi, '=').
  1200. replace(/%2B/gi, '+');
  1201. }
  1202. /**
  1203. * This method is intended for encoding *key* or *value* parts of query component. We need a custom
  1204. * method because encodeURIComponent is too aggressive and encodes stuff that doesn't have to be
  1205. * encoded per http://tools.ietf.org/html/rfc3986:
  1206. * query = *( pchar / "/" / "?" )
  1207. * pchar = unreserved / pct-encoded / sub-delims / ":" / "@"
  1208. * unreserved = ALPHA / DIGIT / "-" / "." / "_" / "~"
  1209. * pct-encoded = "%" HEXDIG HEXDIG
  1210. * sub-delims = "!" / "$" / "&" / "'" / "(" / ")"
  1211. * / "*" / "+" / "," / ";" / "="
  1212. */
  1213. function encodeUriQuery(val, pctEncodeSpaces) {
  1214. return encodeURIComponent(val).
  1215. replace(/%40/gi, '@').
  1216. replace(/%3A/gi, ':').
  1217. replace(/%24/g, '$').
  1218. replace(/%2C/gi, ',').
  1219. replace(/%3B/gi, ';').
  1220. replace(/%20/g, (pctEncodeSpaces ? '%20' : '+'));
  1221. }
  1222. var ngAttrPrefixes = ['ng-', 'data-ng-', 'ng:', 'x-ng-'];
  1223. function getNgAttribute(element, ngAttr) {
  1224. var attr, i, ii = ngAttrPrefixes.length;
  1225. for (i = 0; i < ii; ++i) {
  1226. attr = ngAttrPrefixes[i] + ngAttr;
  1227. if (isString(attr = element.getAttribute(attr))) {
  1228. return attr;
  1229. }
  1230. }
  1231. return null;
  1232. }
  1233. /**
  1234. * @ngdoc directive
  1235. * @name ngApp
  1236. * @module ng
  1237. *
  1238. * @element ANY
  1239. * @param {angular.Module} ngApp an optional application
  1240. * {@link angular.module module} name to load.
  1241. * @param {boolean=} ngStrictDi if this attribute is present on the app element, the injector will be
  1242. * created in "strict-di" mode. This means that the application will fail to invoke functions which
  1243. * do not use explicit function annotation (and are thus unsuitable for minification), as described
  1244. * in {@link guide/di the Dependency Injection guide}, and useful debugging info will assist in
  1245. * tracking down the root of these bugs.
  1246. *
  1247. * @description
  1248. *
  1249. * Use this directive to **auto-bootstrap** an AngularJS application. The `ngApp` directive
  1250. * designates the **root element** of the application and is typically placed near the root element
  1251. * of the page - e.g. on the `<body>` or `<html>` tags.
  1252. *
  1253. * Only one AngularJS application can be auto-bootstrapped per HTML document. The first `ngApp`
  1254. * found in the document will be used to define the root element to auto-bootstrap as an
  1255. * application. To run multiple applications in an HTML document you must manually bootstrap them using
  1256. * {@link angular.bootstrap} instead. AngularJS applications cannot be nested within each other.
  1257. *
  1258. * You can specify an **AngularJS module** to be used as the root module for the application. This
  1259. * module will be loaded into the {@link auto.$injector} when the application is bootstrapped. It
  1260. * should contain the application code needed or have dependencies on other modules that will
  1261. * contain the code. See {@link angular.module} for more information.
  1262. *
  1263. * In the example below if the `ngApp` directive were not placed on the `html` element then the
  1264. * document would not be compiled, the `AppController` would not be instantiated and the `{{ a+b }}`
  1265. * would not be resolved to `3`.
  1266. *
  1267. * `ngApp` is the easiest, and most common way to bootstrap an application.
  1268. *
  1269. <example module="ngAppDemo">
  1270. <file name="index.html">
  1271. <div ng-controller="ngAppDemoController">
  1272. I can add: {{a}} + {{b}} = {{ a+b }}
  1273. </div>
  1274. </file>
  1275. <file name="script.js">
  1276. angular.module('ngAppDemo', []).controller('ngAppDemoController', function($scope) {
  1277. $scope.a = 1;
  1278. $scope.b = 2;
  1279. });
  1280. </file>
  1281. </example>
  1282. *
  1283. * Using `ngStrictDi`, you would see something like this:
  1284. *
  1285. <example ng-app-included="true">
  1286. <file name="index.html">
  1287. <div ng-app="ngAppStrictDemo" ng-strict-di>
  1288. <div ng-controller="GoodController1">
  1289. I can add: {{a}} + {{b}} = {{ a+b }}
  1290. <p>This renders because the controller does not fail to
  1291. instantiate, by using explicit annotation style (see
  1292. script.js for details)
  1293. </p>
  1294. </div>
  1295. <div ng-controller="GoodController2">
  1296. Name: <input ng-model="name"><br />
  1297. Hello, {{name}}!
  1298. <p>This renders because the controller does not fail to
  1299. instantiate, by using explicit annotation style
  1300. (see script.js for details)
  1301. </p>
  1302. </div>
  1303. <div ng-controller="BadController">
  1304. I can add: {{a}} + {{b}} = {{ a+b }}
  1305. <p>The controller could not be instantiated, due to relying
  1306. on automatic function annotations (which are disabled in
  1307. strict mode). As such, the content of this section is not
  1308. interpolated, and there should be an error in your web console.
  1309. </p>
  1310. </div>
  1311. </div>
  1312. </file>
  1313. <file name="script.js">
  1314. angular.module('ngAppStrictDemo', [])
  1315. // BadController will fail to instantiate, due to relying on automatic function annotation,
  1316. // rather than an explicit annotation
  1317. .controller('BadController', function($scope) {
  1318. $scope.a = 1;
  1319. $scope.b = 2;
  1320. })
  1321. // Unlike BadController, GoodController1 and GoodController2 will not fail to be instantiated,
  1322. // due to using explicit annotations using the array style and $inject property, respectively.
  1323. .controller('GoodController1', ['$scope', function($scope) {
  1324. $scope.a = 1;
  1325. $scope.b = 2;
  1326. }])
  1327. .controller('GoodController2', GoodController2);
  1328. function GoodController2($scope) {
  1329. $scope.name = "World";
  1330. }
  1331. GoodController2.$inject = ['$scope'];
  1332. </file>
  1333. <file name="style.css">
  1334. div[ng-controller] {
  1335. margin-bottom: 1em;
  1336. -webkit-border-radius: 4px;
  1337. border-radius: 4px;
  1338. border: 1px solid;
  1339. padding: .5em;
  1340. }
  1341. div[ng-controller^=Good] {
  1342. border-color: #d6e9c6;
  1343. background-color: #dff0d8;
  1344. color: #3c763d;
  1345. }
  1346. div[ng-controller^=Bad] {
  1347. border-color: #ebccd1;
  1348. background-color: #f2dede;
  1349. color: #a94442;
  1350. margin-bottom: 0;
  1351. }
  1352. </file>
  1353. </example>
  1354. */
  1355. function angularInit(element, bootstrap) {
  1356. var appElement,
  1357. module,
  1358. config = {};
  1359. // The element `element` has priority over any other element
  1360. forEach(ngAttrPrefixes, function(prefix) {
  1361. var name = prefix + 'app';
  1362. if (!appElement && element.hasAttribute && element.hasAttribute(name)) {
  1363. appElement = element;
  1364. module = element.getAttribute(name);
  1365. }
  1366. });
  1367. forEach(ngAttrPrefixes, function(prefix) {
  1368. var name = prefix + 'app';
  1369. var candidate;
  1370. if (!appElement && (candidate = element.querySelector('[' + name.replace(':', '\\:') + ']'))) {
  1371. appElement = candidate;
  1372. module = candidate.getAttribute(name);
  1373. }
  1374. });
  1375. if (appElement) {
  1376. config.strictDi = getNgAttribute(appElement, "strict-di") !== null;
  1377. bootstrap(appElement, module ? [module] : [], config);
  1378. }
  1379. }
  1380. /**
  1381. * @ngdoc function
  1382. * @name angular.bootstrap
  1383. * @module ng
  1384. * @description
  1385. * Use this function to manually start up angular application.
  1386. *
  1387. * See: {@link guide/bootstrap Bootstrap}
  1388. *
  1389. * Note that Protractor based end-to-end tests cannot use this function to bootstrap manually.
  1390. * They must use {@link ng.directive:ngApp ngApp}.
  1391. *
  1392. * Angular will detect if it has been loaded into the browser more than once and only allow the
  1393. * first loaded script to be bootstrapped and will report a warning to the browser console for
  1394. * each of the subsequent scripts. This prevents strange results in applications, where otherwise
  1395. * multiple instances of Angular try to work on the DOM.
  1396. *
  1397. * ```html
  1398. * <!doctype html>
  1399. * <html>
  1400. * <body>
  1401. * <div ng-controller="WelcomeController">
  1402. * {{greeting}}
  1403. * </div>
  1404. *
  1405. * <script src="angular.js"></script>
  1406. * <script>
  1407. * var app = angular.module('demo', [])
  1408. * .controller('WelcomeController', function($scope) {
  1409. * $scope.greeting = 'Welcome!';
  1410. * });
  1411. * angular.bootstrap(document, ['demo']);
  1412. * </script>
  1413. * </body>
  1414. * </html>
  1415. * ```
  1416. *
  1417. * @param {DOMElement} element DOM element which is the root of angular application.
  1418. * @param {Array<String|Function|Array>=} modules an array of modules to load into the application.
  1419. * Each item in the array should be the name of a predefined module or a (DI annotated)
  1420. * function that will be invoked by the injector as a `config` block.
  1421. * See: {@link angular.module modules}
  1422. * @param {Object=} config an object for defining configuration options for the application. The
  1423. * following keys are supported:
  1424. *
  1425. * * `strictDi` - disable automatic function annotation for the application. This is meant to
  1426. * assist in finding bugs which break minified code. Defaults to `false`.
  1427. *
  1428. * @returns {auto.$injector} Returns the newly created injector for this app.
  1429. */
  1430. function bootstrap(element, modules, config) {
  1431. if (!isObject(config)) config = {};
  1432. var defaultConfig = {
  1433. strictDi: false
  1434. };
  1435. config = extend(defaultConfig, config);
  1436. var doBootstrap = function() {
  1437. element = jqLite(element);
  1438. if (element.injector()) {
  1439. var tag = (element[0] === document) ? 'document' : startingTag(element);
  1440. //Encode angle brackets to prevent input from being sanitized to empty string #8683
  1441. throw ngMinErr(
  1442. 'btstrpd',
  1443. "App Already Bootstrapped with this Element '{0}'",
  1444. tag.replace(/</,'&lt;').replace(/>/,'&gt;'));
  1445. }
  1446. modules = modules || [];
  1447. modules.unshift(['$provide', function($provide) {
  1448. $provide.value('$rootElement', element);
  1449. }]);
  1450. if (config.debugInfoEnabled) {
  1451. // Pushing so that this overrides `debugInfoEnabled` setting defined in user's `modules`.
  1452. modules.push(['$compileProvider', function($compileProvider) {
  1453. $compileProvider.debugInfoEnabled(true);
  1454. }]);
  1455. }
  1456. modules.unshift('ng');
  1457. var injector = createInjector(modules, config.strictDi);
  1458. injector.invoke(['$rootScope', '$rootElement', '$compile', '$injector',
  1459. function bootstrapApply(scope, element, compile, injector) {
  1460. scope.$apply(function() {
  1461. element.data('$injector', injector);
  1462. compile(element)(scope);
  1463. });
  1464. }]
  1465. );
  1466. return injector;
  1467. };
  1468. var NG_ENABLE_DEBUG_INFO = /^NG_ENABLE_DEBUG_INFO!/;
  1469. var NG_DEFER_BOOTSTRAP = /^NG_DEFER_BOOTSTRAP!/;
  1470. if (window && NG_ENABLE_DEBUG_INFO.test(window.name)) {
  1471. config.debugInfoEnabled = true;
  1472. window.name = window.name.replace(NG_ENABLE_DEBUG_INFO, '');
  1473. }
  1474. if (window && !NG_DEFER_BOOTSTRAP.test(window.name)) {
  1475. return doBootstrap();
  1476. }
  1477. window.name = window.name.replace(NG_DEFER_BOOTSTRAP, '');
  1478. angular.resumeBootstrap = function(extraModules) {
  1479. forEach(extraModules, function(module) {
  1480. modules.push(module);
  1481. });
  1482. return doBootstrap();
  1483. };
  1484. if (isFunction(angular.resumeDeferredBootstrap)) {
  1485. angular.resumeDeferredBootstrap();
  1486. }
  1487. }
  1488. /**
  1489. * @ngdoc function
  1490. * @name angular.reloadWithDebugInfo
  1491. * @module ng
  1492. * @description
  1493. * Use this function to reload the current application with debug information turned on.
  1494. * This takes precedence over a call to `$compileProvider.debugInfoEnabled(false)`.
  1495. *
  1496. * See {@link ng.$compileProvider#debugInfoEnabled} for more.
  1497. */
  1498. function reloadWithDebugInfo() {
  1499. window.name = 'NG_ENABLE_DEBUG_INFO!' + window.name;
  1500. window.location.reload();
  1501. }
  1502. /**
  1503. * @name angular.getTestability
  1504. * @module ng
  1505. * @description
  1506. * Get the testability service for the instance of Angular on the given
  1507. * element.
  1508. * @param {DOMElement} element DOM element which is the root of angular application.
  1509. */
  1510. function getTestability(rootElement) {
  1511. var injector = angular.element(rootElement).