PageRenderTime 39ms CodeModel.GetById 17ms RepoModel.GetById 0ms app.codeStats 0ms

/media/js/base/site.js

https://github.com/dpoirier/bedrock
JavaScript | 86 lines | 61 code | 0 blank | 25 comment | 15 complexity | e0bd313f50e3a386507d6ae04f711dba MD5 | raw file
Possible License(s): MPL-2.0-no-copyleft-exception, 0BSD, BSD-3-Clause
  1. /* This Source Code Form is subject to the terms of the Mozilla Public
  2. * License, v. 2.0. If a copy of the MPL was not distributed with this
  3. * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
  4. (function () {
  5. 'use strict';
  6. function getPlatform() {
  7. var ua = navigator.userAgent,
  8. pf = navigator.platform;
  9. if (/Win(16|9[x58]|NT( [1234]| 5\.0| [^0-9]|[^ -]|$))/.test(ua) ||
  10. /Windows ([MC]E|9[x58]|3\.1|4\.10|NT( [1234]| 5\.0| [^0-9]|[^ ]|$))/.test(ua) ||
  11. /Windows_95/.test(ua)) {
  12. /**
  13. * Officially unsupported platforms are Windows 95, 98, ME, NT 4.x, 2000
  14. * These regular expressions match:
  15. * - Win16
  16. * - Win9x
  17. * - Win95
  18. * - Win98
  19. * - WinNT (not followed by version or followed by version <= 5)
  20. * - Windows ME
  21. * - Windows CE
  22. * - Windows 9x
  23. * - Windows 95
  24. * - Windows 98
  25. * - Windows 3.1
  26. * - Windows 4.10
  27. * - Windows NT (not followed by version or followed by version <= 5)
  28. * - Windows_95
  29. */
  30. return 'oldwin';
  31. }
  32. if (ua.indexOf("MSIE 6.0") !== -1 &&
  33. ua.indexOf("Windows NT 5.1") !== -1 &&
  34. ua.indexOf("SV1") === -1) {
  35. // Windows XP SP1
  36. return 'oldwin';
  37. }
  38. if (pf.indexOf("Win32") !== -1 ||
  39. pf.indexOf("Win64") !== -1) {
  40. return 'windows';
  41. }
  42. if (/android/i.test(ua)) {
  43. return 'android';
  44. }
  45. if (/armv[6-7]l/.test(pf)) {
  46. return 'android';
  47. }
  48. if (pf.indexOf("Linux") !== -1) {
  49. return 'linux';
  50. }
  51. if (pf.indexOf("MacPPC") !== -1) {
  52. return 'oldmac';
  53. }
  54. if (/Mac OS X 10.[0-5]/.test(ua)) {
  55. return 'oldmac';
  56. }
  57. if (pf.indexOf('iPhone') !== -1 ||
  58. pf.indexOf('iPad') !== -1 ||
  59. pf.indexOf('iPod') !== -1 ) {
  60. return 'ios';
  61. }
  62. if (ua.indexOf("Mac OS X") !== -1) {
  63. return 'osx';
  64. }
  65. if (ua.indexOf("MSIE 5.2") !== -1) {
  66. return 'oldmac';
  67. }
  68. if (pf.indexOf("Mac") !== -1) {
  69. return 'oldmac';
  70. }
  71. return 'other';
  72. }
  73. (function () {
  74. // if other than 'windows', immediately replace the platform classname on the html-element
  75. // to avoid lots of flickering
  76. var h = document.documentElement;
  77. window.site = {
  78. platform : getPlatform()
  79. };
  80. if (window.site.platform !== 'windows') {
  81. h.className = h.className.replace("windows", window.site.platform);
  82. }
  83. // Add class to reflect javascript availability for CSS
  84. h.className = h.className.replace(/\bno-js\b/, 'js');
  85. })();
  86. })();