mstsc.js 1.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081
  1. /*
  2. * Copyright (c) 2015 Sylvain Peyrefitte
  3. *
  4. * This file is part of mstsc.js.
  5. *
  6. * mstsc.j is free software: you can redistribute it and/or modify
  7. * it under the terms of the GNU General Public License as published by
  8. * the Free Software Foundation, either version 3 of the License, or
  9. * (at your option) any later version.
  10. *
  11. * This program is distributed in the hope that it will be useful,
  12. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  13. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  14. * GNU General Public License for more details.
  15. *
  16. * You should have received a copy of the GNU General Public License
  17. * along with this program. If not, see <http://www.gnu.org/licenses/>.
  18. */
  19. (function() {
  20. /**
  21. * Use for domain declaration
  22. */
  23. Mstsc = function () {
  24. }
  25. Mstsc.prototype = {
  26. // shortcut
  27. $ : function (id) {
  28. return document.getElementById(id);
  29. },
  30. /**
  31. * Compute screen offset for a target element
  32. * @param el {DOM element}
  33. * @return {top : {integer}, left {integer}}
  34. */
  35. elementOffset : function (el) {
  36. var x = 0;
  37. var y = 0;
  38. while (el && !isNaN( el.offsetLeft ) && !isNaN( el.offsetTop )) {
  39. x += el.offsetLeft - el.scrollLeft;
  40. y += el.offsetTop - el.scrollTop;
  41. el = el.offsetParent;
  42. }
  43. return { top: y, left: x };
  44. },
  45. /**
  46. * Try to detect browser
  47. * @returns {String} [firefox|chrome|ie]
  48. */
  49. browser : function () {
  50. if (typeof InstallTrigger !== 'undefined') {
  51. return 'firefox';
  52. }
  53. if (!!window.chrome) {
  54. return 'chrome';
  55. }
  56. if (!!document.docuemntMode) {
  57. return 'ie';
  58. }
  59. return null;
  60. },
  61. /**
  62. * Try to detect language
  63. * @returns
  64. */
  65. locale : function () {
  66. return window.navigator.userLanguage || window.navigator.language;
  67. }
  68. }
  69. })();
  70. this.Mstsc = new Mstsc();