8
0

env.js 2.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293
  1. /**
  2. * @license Copyright (c) 2003-2019, CKSource - Frederico Knabben. All rights reserved.
  3. * For licensing, see LICENSE.md or https://ckeditor.com/legal/ckeditor-oss-license
  4. */
  5. /* globals navigator:false */
  6. /**
  7. * @module utils/env
  8. */
  9. const userAgent = navigator.userAgent.toLowerCase();
  10. /**
  11. * A namespace containing environment and browser information.
  12. *
  13. * @namespace
  14. */
  15. const env = {
  16. /**
  17. * Indicates that the application is running on Macintosh.
  18. *
  19. * @static
  20. * @type {Boolean}
  21. */
  22. isMac: isMac( userAgent ),
  23. /**
  24. * Indicates that the application is running in Microsoft Edge.
  25. *
  26. * @static
  27. * @type {Boolean}
  28. */
  29. isEdge: isEdge( userAgent ),
  30. /**
  31. * Indicates that the application is running in Firefox (Gecko).
  32. *
  33. * @static
  34. * @type {Boolean}
  35. */
  36. isGecko: isGecko( userAgent ),
  37. /**
  38. * Indicates that the application is running in Safari.
  39. *
  40. * @static
  41. * @type {Boolean}
  42. */
  43. isSafari: isSafari( userAgent )
  44. };
  45. export default env;
  46. /**
  47. * Checks if User Agent represented by the string is running on Macintosh.
  48. *
  49. * @param {String} userAgent **Lowercase** `navigator.userAgent` string.
  50. * @returns {Boolean} Whether User Agent is running on Macintosh or not.
  51. */
  52. export function isMac( userAgent ) {
  53. return userAgent.indexOf( 'macintosh' ) > -1;
  54. }
  55. /**
  56. * Checks if User Agent represented by the string is Microsoft Edge.
  57. *
  58. * @param {String} userAgent **Lowercase** `navigator.userAgent` string.
  59. * @returns {Boolean} Whether User Agent is Edge or not.
  60. */
  61. export function isEdge( userAgent ) {
  62. return !!userAgent.match( /edge\/(\d+.?\d*)/ );
  63. }
  64. /**
  65. * Checks if User Agent represented by the string is Firefox (Gecko).
  66. *
  67. * @param {String} userAgent **Lowercase** `navigator.userAgent` string.
  68. * @returns {Boolean} Whether User Agent is Firefox or not.
  69. */
  70. export function isGecko( userAgent ) {
  71. return !!userAgent.match( /gecko\/\d+/ );
  72. }
  73. /**
  74. * Checks if User Agent represented by the string is Safari.
  75. *
  76. * @param {String} userAgent **Lowercase** `navigator.userAgent` string.
  77. * @returns {Boolean} Whether User Agent is Safari or not.
  78. */
  79. export function isSafari( userAgent ) {
  80. return userAgent.indexOf( ' applewebkit/' ) > -1 && userAgent.indexOf( 'chrome' ) === -1;
  81. }