A tumblelog CMS built on AJAX, PHP and MySQL.

mclayer.js 4.2KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211
  1. /**
  2. * $Id: mclayer.js 162 2007-01-03 16:16:52Z spocke $
  3. *
  4. * Moxiecode floating layer script.
  5. *
  6. * @author Moxiecode
  7. * @copyright Copyright © 2004-2007, Moxiecode Systems AB, All rights reserved.
  8. */
  9. function MCLayer(id) {
  10. this.id = id;
  11. this.settings = new Array();
  12. this.blockerElement = null;
  13. this.isMSIE = navigator.appName == "Microsoft Internet Explorer";
  14. this.events = false;
  15. this.autoHideCallback = null;
  16. }
  17. MCLayer.prototype = {
  18. moveRelativeTo : function(re, p, a) {
  19. var rep = this.getAbsPosition(re);
  20. var w = parseInt(re.offsetWidth);
  21. var h = parseInt(re.offsetHeight);
  22. var x, y;
  23. switch (p) {
  24. case "tl":
  25. break;
  26. case "tr":
  27. x = rep.absLeft + w;
  28. y = rep.absTop;
  29. break;
  30. case "bl":
  31. break;
  32. case "br":
  33. break;
  34. }
  35. this.moveTo(x, y);
  36. },
  37. moveBy : function(dx, dy) {
  38. var e = this.getElement();
  39. var x = parseInt(e.style.left);
  40. var y = parseInt(e.style.top);
  41. e.style.left = (x + dx) + "px";
  42. e.style.top = (y + dy) + "px";
  43. this.updateBlocker();
  44. },
  45. moveTo : function(x, y) {
  46. var e = this.getElement();
  47. e.style.left = x + "px";
  48. e.style.top = y + "px";
  49. this.updateBlocker();
  50. },
  51. show : function() {
  52. MCLayer.visibleLayer = this;
  53. this.getElement().style.display = 'block';
  54. this.updateBlocker();
  55. },
  56. hide : function() {
  57. this.getElement().style.display = 'none';
  58. this.updateBlocker();
  59. },
  60. setAutoHide : function(s, cb) {
  61. this.autoHideCallback = cb;
  62. this.registerEventHandlers();
  63. },
  64. getElement : function() {
  65. return document.getElementById(this.id);
  66. },
  67. updateBlocker : function() {
  68. if (!this.isMSIE)
  69. return;
  70. var e = this.getElement();
  71. var b = this.getBlocker();
  72. var x = this.parseInt(e.style.left);
  73. var y = this.parseInt(e.style.top);
  74. var w = this.parseInt(e.offsetWidth);
  75. var h = this.parseInt(e.offsetHeight);
  76. b.style.left = x + 'px';
  77. b.style.top = y + 'px';
  78. b.style.width = w + 'px';
  79. b.style.height = h + 'px';
  80. b.style.display = e.style.display;
  81. },
  82. getBlocker : function() {
  83. if (!this.blockerElement) {
  84. var d = document, b = d.createElement("iframe");
  85. b.style.cssText = 'display: none; left: 0px; position: absolute; top: 0';
  86. b.src = 'javascript:false;';
  87. b.frameBorder = '0';
  88. b.scrolling = 'no';
  89. d.body.appendChild(b);
  90. this.blockerElement = b;
  91. }
  92. return this.blockerElement;
  93. },
  94. getAbsPosition : function(n) {
  95. var p = {absLeft : 0, absTop : 0};
  96. while (n) {
  97. p.absLeft += n.offsetLeft;
  98. p.absTop += n.offsetTop;
  99. n = n.offsetParent;
  100. }
  101. return p;
  102. },
  103. registerEventHandlers : function() {
  104. if (!this.events) {
  105. var d = document;
  106. this.addEvent(d, 'mousedown', MCLayer.prototype.onMouseDown);
  107. this.events = true;
  108. }
  109. },
  110. addEvent : function(o, n, h) {
  111. if (o.attachEvent)
  112. o.attachEvent("on" + n, h);
  113. else
  114. o.addEventListener(n, h, false);
  115. },
  116. onMouseDown : function(e) {
  117. e = typeof(e) == "undefined" ? window.event : e;
  118. var b = document.body;
  119. var l = MCLayer.visibleLayer;
  120. if (l) {
  121. var mx = l.isMSIE ? e.clientX + b.scrollLeft : e.pageX;
  122. var my = l.isMSIE ? e.clientY + b.scrollTop : e.pageY;
  123. var el = l.getElement();
  124. var x = parseInt(el.style.left);
  125. var y = parseInt(el.style.top);
  126. var w = parseInt(el.offsetWidth);
  127. var h = parseInt(el.offsetHeight);
  128. if (!(mx > x && mx < x + w && my > y && my < y + h)) {
  129. MCLayer.visibleLayer = null;
  130. if (l.autoHideCallback && l.autoHideCallback(l, e, mx, my))
  131. return true;
  132. l.hide();
  133. }
  134. }
  135. },
  136. addCSSClass : function(e, c) {
  137. this.removeCSSClass(e, c);
  138. var a = this.explode(' ', e.className);
  139. a[a.length] = c;
  140. e.className = a.join(' ');
  141. },
  142. removeCSSClass : function(e, c) {
  143. var a = this.explode(' ', e.className), i;
  144. for (i=0; i<a.length; i++) {
  145. if (a[i] == c)
  146. a[i] = '';
  147. }
  148. e.className = a.join(' ');
  149. },
  150. explode : function(d, s) {
  151. var ar = s.split(d);
  152. var oar = new Array();
  153. for (var i = 0; i<ar.length; i++) {
  154. if (ar[i] != "")
  155. oar[oar.length] = ar[i];
  156. }
  157. return oar;
  158. },
  159. parseInt : function(s) {
  160. if (s == null || s == '')
  161. return 0;
  162. return parseInt(s);
  163. }
  164. }