lws-common.js 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125
  1. /*
  2. * This section around grayOut came from here:
  3. * http://www.codingforums.com/archive/index.php/t-151720.html
  4. * Assumed public domain
  5. *
  6. * Init like this in your main html script, this also reapplies the gray
  7. *
  8. * lws_gray_out(true,{'zindex':'499'});
  9. *
  10. * To remove the gray
  11. *
  12. * lws_gray_out(false);
  13. *
  14. */
  15. function gsize(ptype)
  16. {
  17. var h = document.compatMode === "CSS1Compat" &&
  18. !window.opera ?
  19. document.documentElement.clientHeight :
  20. document.body.clientHeight;
  21. var w = document.compatMode === "CSS1Compat" &&
  22. !window.opera ?
  23. document.documentElement.clientWidth :
  24. document.body.clientWidth;
  25. var pageWidth, pageHeight, t;
  26. if (document.body &&
  27. (document.body.scrollWidth || document.body.scrollHeight)) {
  28. t = document.body.scrollWidth;
  29. pageWidth = (w > t) ? ("" + w + "px") : ("" + (t) + "px");
  30. t = document.body.scrollHeight;
  31. pageHeight = (h > t) ? ("" + h + "px") : ("" + (t) + "px");
  32. } else if (document.body.offsetWidth) {
  33. t = document.body.offsetWidth;
  34. pageWidth = (w > t) ? ("" + w + "px") : ("" + (t) + "px");
  35. t = document.body.offsetHeight;
  36. pageHeight =(h > t) ? ("" + h + "px") : ("" + (t) + "px");
  37. } else {
  38. pageWidth = "100%";
  39. pageHeight = "100%";
  40. }
  41. return (ptype === 1) ? pageWidth : pageHeight;
  42. }
  43. function addEvent( obj, type, fn ) {
  44. if ( obj.attachEvent ) {
  45. obj["e" + type + fn] = fn;
  46. obj[type+fn] = function() { obj["e" + type + fn]( window.event );};
  47. obj.attachEvent("on" + type, obj[type + fn]);
  48. } else
  49. obj.addEventListener(type, fn, false);
  50. }
  51. function removeEvent( obj, type, fn ) {
  52. if ( obj.detachEvent ) {
  53. obj.detachEvent("on" + type, obj[type + fn]);
  54. obj[type + fn] = null;
  55. } else
  56. obj.removeEventListener(type, fn, false);
  57. }
  58. function lws_gray_out(vis, _options) {
  59. var options = _options || {};
  60. var zindex = options.zindex || 50;
  61. var opacity = options.opacity || 70;
  62. var opaque = (opacity / 100);
  63. var bgcolor = options.bgcolor || "#000000";
  64. var dark = document.getElementById("darkenScreenObject");
  65. if (!dark) {
  66. var tbody = document.getElementsByTagName("body")[0];
  67. var tnode = document.createElement("div");
  68. tnode.style.position = "absolute";
  69. tnode.style.top = "0px";
  70. tnode.style.left = "0px";
  71. tnode.style.overflow = "hidden";
  72. tnode.style.display ="none";
  73. tnode.id = "darkenScreenObject";
  74. tbody.appendChild(tnode);
  75. dark = document.getElementById("darkenScreenObject");
  76. }
  77. if (vis) {
  78. dark.style.opacity = opaque;
  79. dark.style.MozOpacity = opaque;
  80. // dark.style.filter ='alpha(opacity='+opacity+')';
  81. dark.style.zIndex = zindex;
  82. dark.style.backgroundColor = bgcolor;
  83. dark.style.width = gsize(1);
  84. dark.style.height = gsize(0);
  85. dark.style.display = "block";
  86. addEvent(window, "resize",
  87. function() {
  88. dark.style.height = gsize(0);
  89. dark.style.width = gsize(1);
  90. }
  91. );
  92. } else {
  93. dark.style.display = "none";
  94. removeEvent(window, "resize",
  95. function() {
  96. dark.style.height = gsize(0);
  97. dark.style.width = gsize(1);
  98. }
  99. );
  100. }
  101. }
  102. /*
  103. * end of grayOut related stuff
  104. */
  105. function new_ws(urlpath, protocol)
  106. {
  107. return new WebSocket(urlpath, protocol);
  108. }
  109. function lws_san(s)
  110. {
  111. if (s.search("<") !== -1)
  112. return "invalid string";
  113. return s;
  114. }