ext-bootstrap.js 2.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465
  1. /**
  2. * Load the library located at the same path with this file
  3. *
  4. * Will automatically load ext-all-debug.js if any of these conditions is true:
  5. * - Current hostname is localhost
  6. * - Current hostname is an IP v4 address
  7. * - Current protocol is "file:"
  8. * - Query string has `debug` parameter passed (http://foo/test.html?debug)
  9. *
  10. * If none of the above is true or the `nodebug` query string parameter is present (http://foo/test.html?nodebug),
  11. * ext-all.js will be loaded.
  12. */
  13. (function() {
  14. var scripts = document.getElementsByTagName('script'),
  15. localhostTests = [
  16. /^localhost$/,
  17. /\b(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)(:\d{1,5})?\b/ // IP v4
  18. ],
  19. host = window.location.hostname,
  20. isDevelopment = null,
  21. queryString = window.location.search,
  22. test, path, i, ln, scriptSrc, match;
  23. for (i = 0, ln = scripts.length; i < ln; i++) {
  24. scriptSrc = scripts[i].src;
  25. match = scriptSrc.match(/ext-bootstrap\.js$/);
  26. if (match) {
  27. /**
  28. * use a path without the ext-bootstrap.js file on it. http://path/to/ext/ext-bootstrap.js will become
  29. * http://path/to/ext/
  30. */
  31. path = scriptSrc.substring(0, scriptSrc.length - match[0].length);
  32. break;
  33. }
  34. }
  35. if (isDevelopment === null) {
  36. for (i = 0, ln = localhostTests.length; i < ln; i++) {
  37. test = localhostTests[i];
  38. if (host.search(test) !== -1) {
  39. //host is localhost or an IP address
  40. isDevelopment = true;
  41. break;
  42. }
  43. }
  44. }
  45. if (isDevelopment === null && window.location.protocol === 'file:') {
  46. isDevelopment = true;
  47. }
  48. if (!isDevelopment && queryString.match('(\\?|&)debug') !== null) {
  49. //debug is present in the query string
  50. isDevelopment = true;
  51. } else if (isDevelopment && queryString.match('(\\?|&)nodebug') !== null) {
  52. //nodebug is present in the query string
  53. isDevelopment = false;
  54. }
  55. document.write('<script type="text/javascript" charset="UTF-8" src="' +
  56. path + 'build/ext-all' + (isDevelopment ? '-debug' : '') + '.js"></script>');
  57. })();