home *** CD-ROM | disk | FTP | other *** search
/ Cricao de Sites - 650 Layouts Prontos / WebMasters.iso / Blogs / wordpress2.6.exe / wordpress2.6 / wp-includes / js / tinymce / utils / mclayer.js < prev    next >
Encoding:
JavaScript  |  2008-01-17  |  4.0 KB  |  211 lines

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