home *** CD-ROM | disk | FTP | other *** search
/ Hackers Magazine 57 / CdHackersMagazineNr57.iso / Software / Programming / dhtmlxMenu.exe / dhtmlxMenu / libCompiler / dhtmlxcontainer.js < prev    next >
Encoding:
JavaScript  |  2009-10-06  |  30.0 KB  |  879 lines

  1. function dhtmlXContainer(obj) {
  2.     
  3.     var that = this;
  4.     
  5.     this.obj = obj;
  6.     this.dhxcont = null;
  7.     
  8.     this.setContent = function(data) {
  9.         this.dhxcont = data;
  10.         this.dhxcont.innerHTML = "<div id='dhxMainCont' style='position: relative; left: 0px; top: 0px; overflow: hidden;'></div>"+
  11.                      "<div id='dhxContBlocker' class='dhxcont_content_blocker' style='display: none;'></div>";
  12.         this.dhxcont.mainCont = this.dhxcont.childNodes[0];
  13.         this.obj.dhxcont = this.dhxcont;
  14.     }
  15.     
  16.     this.obj._genStr = function(w) {
  17.         var s = ""; var z = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789";
  18.         for (var q=0; q<w; q++) { s = s + z.charAt(Math.round(Math.random() * z.length)); }
  19.         return s;
  20.     }
  21.     
  22.     this.obj.setMinContentSize = function(w, h) {
  23.         this._minDataSizeW = w;
  24.         this._minDataSizeH = h;
  25.     }
  26.     
  27.     this.obj.moveContentTo = function(cont) {
  28.         
  29.         
  30.         // move dhtmlx components
  31.         
  32.         var pref = null;
  33.         if (this.grid) pref = "grid";
  34.         if (this.tree) pref = "tree";
  35.         if (this.tabbar) pref = "tabbar";
  36.         if (this.folders) pref = "folders";
  37.         if (this.layout) pref = "layout";
  38.         
  39.         if (pref != null) {
  40.             if (pref == "layout" && this._isCell && cont._isWindow) {
  41.                 var aDim = this.layout._defineWindowMinDimension(this, true);
  42.                 var bDim = cont.getDimension();
  43.                 cont.setDimension((aDim[1]>bDim[0]?aDim[1]:null), (aDim[2]>bDim[1]?aDim[2]:null));
  44.             }
  45.             if (pref == "tabbar" && cont._isCell) cont.hideHeader();
  46.             cont.attachObject(this[pref+"Id"]);
  47.             cont[pref] = this[pref];
  48.             cont[pref+"Id"] = this[pref+"Id"];
  49.             cont[pref+"Obj"] = this[pref+"Obj"];
  50.             if (pref == "layout") {
  51.                 cont.layout._baseWFix = -2;
  52.                 cont.layout._baseHFix = -2;
  53.                 // from layout to window, attach event
  54.                 if (cont._isWindow) cont.attachEvent("_onBeforeTryResize", cont.layout._defineWindowMinDimension);
  55.             }
  56.             this[pref] = null;
  57.             this[pref+"Id"] = null;
  58.             this[pref+"Obj"] = null;
  59.             if (pref == "tabbar" && this._isCell) this.showHeader();
  60.         }
  61.         
  62.         // menu/toolbar/statusbar should be after any object
  63.         if (this.menu != null) {
  64.             cont.dhxcont.insertBefore(document.getElementById(this.menuId), cont.dhxcont.childNodes[0]);
  65.             cont.menu = this.menu;
  66.             cont.menuId = this.menuId;
  67.             cont.menuHeight = this.menuHeight;
  68.             this.menu = null;
  69.             this.menuId = null;
  70.             this.menuHeight = null;
  71.             if (this._doOnAttachMenu) this._doOnAttachMenu("unload");
  72.             if (cont._doOnAttachMenu) cont._doOnAttachMenu("move");
  73.         }
  74.         if (this.toolbar != null) {
  75.             cont.dhxcont.insertBefore(document.getElementById(this.toolbarId), cont.dhxcont.childNodes[(cont.menu != null?1:0)]);
  76.             cont.toolbar = this.toolbar;
  77.             cont.toolbarId = this.toolbarId;
  78.             cont.toolbarHeight = this.toolbarHeight;
  79.             this.toolbar = null;
  80.             this.toolbarId = null;
  81.             this.toolbarHeight = null;
  82.             if (this._doOnAttachToolbar) this._doOnAttachToolbar("unload");
  83.             if (cont._doOnAttachToolbar) cont._doOnAttachToolbar("move");
  84.         }
  85.         if (this.sb != null) {
  86.             cont.dhxcont.insertBefore(document.getElementById(this.sbId), cont.dhxcont.childNodes[cont.dhxcont.childNodes.length-1]);
  87.             cont.sb = this.sb;
  88.             cont.sbId = this.sbId;
  89.             cont.sbHeight = this.sbHeight;
  90.             this.sb = null;
  91.             this.sbId = null;
  92.             this.sbHeight = null;
  93.             if (this._doOnAttachToolbar) this._doOnAttachToolbar("unload");
  94.             if (cont._doOnAttachToolbar) cont._doOnAttachToolbar("move");
  95.         }
  96.         
  97.         // other objects
  98.         var objA = this.dhxcont.childNodes[0];
  99.         var objB = cont.dhxcont.childNodes[0];
  100.         while (objA.childNodes.length > 0) objB.appendChild(objA.childNodes[0]);
  101.         //
  102.         cont.updateNestedObjects();
  103.     }
  104.     
  105.     this.obj.adjustContent = function(parentObj, offsetTop, marginTop, notCalcWidth, offsetBottom) {
  106.         
  107.         this.dhxcont.style.left = (this._offsetLeft||0)+"px";
  108.         this.dhxcont.style.top = (this._offsetTop||0)+offsetTop+"px";
  109.         //
  110.         var cw = parentObj.clientWidth+(this._offsetWidth||0);
  111.         if (notCalcWidth !== true) this.dhxcont.style.width = Math.max(0, cw)+"px";
  112.         if (notCalcWidth !== true) if (this.dhxcont.offsetWidth > cw) this.dhxcont.style.width = Math.max(0, cw*2-this.dhxcont.offsetWidth)+"px";
  113.         //
  114.         var ch = parentObj.clientHeight+(this._offsetHeight||0);
  115.         this.dhxcont.style.height = Math.max(0, ch-offsetTop)+(marginTop!=null?marginTop:0)+"px";
  116.         if (this.dhxcont.offsetHeight > ch - offsetTop) this.dhxcont.style.height = Math.max(0, (ch-offsetTop)*2-this.dhxcont.offsetHeight)+"px";
  117.         if (offsetBottom) if (!isNaN(offsetBottom)) this.dhxcont.style.height = Math.max(0, parseInt(this.dhxcont.style.height)-offsetBottom)+"px";
  118.         
  119.         // main window content
  120.         if (this._minDataSizeH != null) {
  121.             // height for menu/toolbar/status bar should be included
  122.             if (parseInt(this.dhxcont.style.height) < this._minDataSizeH) this.dhxcont.style.height = this._minDataSizeH+"px";
  123.         }
  124.         if (this._minDataSizeW != null) {
  125.             if (parseInt(this.dhxcont.style.width) < this._minDataSizeW) this.dhxcont.style.width = this._minDataSizeW+"px";
  126.         }
  127.         
  128.         if (notCalcWidth !== true) {
  129.             this.dhxcont.mainCont.style.width = this.dhxcont.clientWidth+"px";
  130.             // allow border to this.dhxcont.mainCont
  131.             if (this.dhxcont.mainCont.offsetWidth > this.dhxcont.clientWidth) this.dhxcont.mainCont.style.width = Math.max(0, this.dhxcont.clientWidth*2-this.dhxcont.mainCont.offsetWidth)+"px";
  132.         }
  133.         
  134.         var menuOffset = (this.menu!=null?(!this.menuHidden?this.menuHeight:0):0);
  135.         var toolbarOffset = (this.toolbar!=null?(!this.toolbarHidden?this.toolbarHeight:0):0);
  136.         var statusOffset = (this.sb!=null?(!this.sbHidden?this.sbHeight:0):0);
  137.         
  138.         // allow border to this.dhxcont.mainCont
  139.         this.dhxcont.mainCont.style.height = this.dhxcont.clientHeight+"px";
  140.         if (this.dhxcont.mainCont.offsetHeight > this.dhxcont.clientHeight) this.dhxcont.mainCont.style.height = Math.max(0, this.dhxcont.clientHeight*2-this.dhxcont.mainCont.offsetHeight)+"px";
  141.         this.dhxcont.mainCont.style.height = Math.max(0, parseInt(this.dhxcont.mainCont.style.height)-menuOffset-toolbarOffset-statusOffset)+"px";
  142.         
  143.     }
  144.     this.obj.coverBlocker = function() {
  145.         return this.dhxcont.childNodes[this.dhxcont.childNodes.length-1];
  146.     }
  147.     this.obj.showCoverBlocker = function() {
  148.         this.coverBlocker().style.display = "";
  149.     }
  150.     this.obj.hideCoverBlocker = function() {
  151.         this.coverBlocker().style.display = "none";
  152.     }
  153.     this.obj.updateNestedObjects = function() {
  154.         if (this.grid) { this.grid.setSizes(); }
  155.         if (this.tabbar) { this.tabbar.adjustOuterSize(); }
  156.         if (this.folders) { this.folders.setSizes(); }
  157.         if (this.editor) {
  158.             if (!_isIE) this.editor._prepareContent(true);
  159.             this.editor.setSizes();
  160.         }
  161.          //if (_isOpera) { var t = this; window.setTimeout(function(){t.editor.adjustSize();},10); } else { this.editor.adjustSize(); } }
  162.         if (this.layout) {
  163.             this.layoutObj.style.width = this.dhxcont.mainCont.style.width;
  164.             this.layoutObj.style.height = this.dhxcont.mainCont.style.height;
  165.             
  166.             if (this._isAcc && this.skin == "dhx_skyblue") {
  167.                 this.layoutObj.style.width = parseInt(this.dhxcont.mainCont.style.width)+2+"px";
  168.                 this.layoutObj.style.height = parseInt(this.dhxcont.mainCont.style.height)+2+"px";
  169.             }
  170.             
  171.             this.layout.setSizes();
  172.         }
  173.         if (this.accordion != null) {
  174.             this.accordionObj.style.width = parseInt(this.dhxcont.mainCont.style.width)+2+"px";
  175.             this.accordionObj.style.height = parseInt(this.dhxcont.mainCont.style.height)+2+"px";
  176.             this.accordion.setSizes();
  177.         }
  178.         // docked layout's cell
  179.         if (this.dockedCell) { this.dockedCell.updateNestedObjects(); }
  180.         /*
  181.         if (win.accordion != null) { win.accordion.setSizes(); }
  182.         if (win.layout != null) { win.layout.setSizes(win); }
  183.         */
  184.     }
  185.     /**
  186.     *   @desc: attaches a status bar to a window
  187.     *   @type: public
  188.     */
  189.     this.obj.attachStatusBar = function() {
  190.         var sbObj = document.createElement("DIV");
  191.         
  192.         if (this._isCell) {
  193.             sbObj.className = "dhxcont_sb_container_layoutcell";
  194.         } else {
  195.             sbObj.className = "dhxcont_sb_container";
  196.         }
  197.         sbObj.id = "sbobj_"+this._genStr(12);
  198.         sbObj.innerHTML = "<div class='dhxcont_statusbar'></div>";
  199.         this.dhxcont.insertBefore(sbObj, this.dhxcont.childNodes[this.dhxcont.childNodes.length-1]);
  200.         
  201.         sbObj.setText = function(text) { this.childNodes[0].innerHTML = text; }
  202.         sbObj.getText = function() { return this.childNodes[0].innerHTML; }
  203.         sbObj.onselectstart = function(e) { e=e||event; e.returnValue=false; return false; }
  204.         this.sb = sbObj;
  205.         this.sbHeight = sbObj.offsetHeight;
  206.         this.sbId = sbObj.id;
  207.         
  208.         if (this._doOnAttachStatusBar) this._doOnAttachStatusBar("init");
  209.         this.adjust();
  210.         return this.sb;
  211.     }
  212.     /**
  213.     *   @desc: detaches a status bar from a window
  214.     *   @type: public
  215.     */
  216.     this.obj.detachStatusBar = function() {
  217.         if (!this.sb) return;
  218.         this.sb.setText = null;
  219.         this.sb.getText = null;
  220.         this.sb.onselectstart = null;
  221.         this.sb.parentNode.removeChild(this.sb);
  222.         this.sb = null;
  223.         this.sbHeight = null;
  224.         this.sbId = null;
  225.         if (this._doOnAttachStatusBar) this._doOnAttachStatusBar("unload");
  226.     }
  227.     /**
  228.     *   @desc: attaches a dhtmlxMenu to a window
  229.     *   @type: public
  230.     */
  231.     this.obj.attachMenu = function() {
  232.         var menuObj = document.createElement("DIV");
  233.         menuObj.style.position = "relative";
  234.         menuObj.style.overflow = "hidden";
  235.         
  236.         menuObj.id = "dhxmenu_"+this._genStr(12);
  237.         this.dhxcont.insertBefore(menuObj, this.dhxcont.childNodes[0]);
  238.         
  239.         this.menu = new dhtmlXMenuObject(menuObj.id, this.skin);
  240.         
  241.         this.menuHeight = menuObj.offsetHeight;
  242.         this.menuId = menuObj.id;
  243.         
  244.         if (this._doOnAttachMenu) this._doOnAttachMenu("init");
  245.         
  246.         this.adjust();
  247.         return this.menu;
  248.     }
  249.     /**
  250.     *   @desc: detaches a dhtmlxMenu from a window
  251.     *   @type: public
  252.     */
  253.     this.obj.detachMenu = function() {
  254.         if (!this.menu) return;
  255.         var menuObj = document.getElementById(this.menuId);
  256.         this.menu.unload();
  257.         this.menu = null;
  258.         this.menuId = null;
  259.         this.menuHeight = null;
  260.         menuObj.parentNode.removeChild(menuObj);
  261.         menuObj = null;
  262.         if (this._doOnAttachMenu) this._doOnAttachMenu("unload");
  263.     }
  264.     /**
  265.     *   @desc: attaches a dhtmlxToolbar to a window
  266.     *   @type: public
  267.     */
  268.     this.obj.attachToolbar = function() {
  269.         var toolbarObj = document.createElement("DIV");
  270.         toolbarObj.style.position = "relative";
  271.         toolbarObj.style.overflow = "hidden";
  272.         toolbarObj.id = "dhxtoolbar_"+this._genStr(12);
  273.         this.dhxcont.insertBefore(toolbarObj, this.dhxcont.childNodes[(this.menu!=null?1:0)]);
  274.         this.toolbar = new dhtmlXToolbarObject(toolbarObj.id, this.skin);
  275.         this.toolbarHeight = toolbarObj.offsetHeight+(this._isLayout&&this.skin=="dhx_skyblue"?2:0);
  276.         this.toolbarId = toolbarObj.id;
  277.         if (this._doOnAttachToolbar) this._doOnAttachToolbar("init");
  278.         this.adjust();
  279.         return this.toolbar;
  280.     }
  281.     /**
  282.     *   @desc: detaches a dhtmlxToolbar from a window
  283.     *   @type: public
  284.     */
  285.     this.obj.detachToolbar = function() {
  286.         if (!this.toolbar) return;
  287.         var toolbarObj = document.getElementById(this.toolbarId);
  288.         this.toolbar.unload();
  289.         this.toolbar = null;
  290.         this.toolbarId = null;
  291.         this.toolbarHeight = null;
  292.         toolbarObj.parentNode.removeChild(toolbarObj);
  293.         toolbarObj = null;
  294.         if (this._doOnAttachToolbar) this._doOnAttachToolbar("unload");
  295.     }
  296.     /**
  297.     *   @desc: attaches a dhtmlxGrid to a window
  298.     *   @type: public
  299.     */
  300.     this.obj.attachGrid = function() {
  301.         if (this._isWindow && this.skin == "dhx_skyblue") {
  302.             this.dhxcont.mainCont.style.border = "#a4bed4 1px solid";
  303.             this._redraw();
  304.         }
  305.         var obj = document.createElement("DIV");
  306.         obj.id = "dhxGridObj_"+this._genStr(12);
  307.         obj.style.width = "100%";
  308.         obj.style.height = "100%";
  309.         obj.cmp = "grid";
  310.         document.body.appendChild(obj);
  311.         this.attachObject(obj.id);
  312.         this.grid = new dhtmlXGridObject(obj.id);
  313.         this.grid.setSkin(this.skin);
  314.         this.grid.entBox.style.border = "0px solid white";
  315.         this.grid._sizeFix=0;
  316.         
  317.         this.gridId = obj.id;
  318.         this.gridObj = obj;
  319.         
  320.         return this.grid;
  321.     }
  322.     /**
  323.     *   @desc: attaches a dhtmlxScheduler to a window
  324.     *   @type: public
  325.     */    
  326.     this.obj.attachScheduler = function(day,mode) {
  327.         var obj = document.createElement("DIV");
  328.         obj.innerHTML='<div id="scheduler_here" class="dhx_cal_container" style="width:100%; height:100%;"><div class="dhx_cal_navline"><div class="dhx_cal_prev_button"> </div><div class="dhx_cal_next_button"> </div><div class="dhx_cal_today_button"></div><div class="dhx_cal_date"></div><div class="dhx_cal_tab" name="day_tab" style="right:204px;"></div><div class="dhx_cal_tab" name="week_tab" style="right:140px;"></div><div class="dhx_cal_tab" name="month_tab" style="right:76px;"></div></div><div class="dhx_cal_header"></div><div class="dhx_cal_data"></div></div>';
  329.         
  330.         document.body.appendChild(obj.firstChild);
  331.         this.attachObject("scheduler_here");
  332.         
  333.         this.grid = scheduler;
  334.         scheduler.setSizes = scheduler.update_view;
  335.         scheduler.destructor=function(){};
  336.         scheduler.init("scheduler_here",day,mode);
  337.         
  338.         //this.grid.entBox.style.border = "0px solid white";
  339.         
  340.  
  341.         return this.grid;
  342.     }    
  343.     /**
  344.     *   @desc: attaches a dhtmlxTree to a window
  345.     *   @param: rootId - not mandatory, tree super root, see dhtmlxTree documentation for details
  346.     *   @type: public
  347.     */
  348.     this.obj.attachTree = function(rootId) {
  349.         if (this._isWindow && this.skin == "dhx_skyblue") {
  350.             this.dhxcont.mainCont.style.border = "#a4bed4 1px solid";
  351.             this._redraw();
  352.         }
  353.         var obj = document.createElement("DIV");
  354.         obj.id = "dhxTreeObj_"+this._genStr(12);
  355.         obj.style.width = "100%";
  356.         obj.style.height = "100%";
  357.         obj.cmp = "tree";
  358.         document.body.appendChild(obj);
  359.         this.attachObject(obj.id);
  360.         this.tree = new dhtmlXTreeObject(obj.id, "100%", "100%", (rootId||0));
  361.         this.tree.setSkin(this.skin);
  362.         // this.tree.allTree.style.paddingTop = "2px";
  363.         this.tree.allTree.childNodes[0].style.marginTop = "2px";
  364.         this.tree.allTree.childNodes[0].style.marginBottom = "2px";
  365.         
  366.         this.treeId = obj.id;
  367.         this.treeObj = obj;
  368.         
  369.         return this.tree;
  370.     }
  371.     /**
  372.     *   @desc: attaches a dhtmlxTabbar to a window
  373.     *   @type: public
  374.     */
  375.     this.obj.attachTabbar = function(mode) {
  376.         
  377.         if (this._isWindow && this.skin == "dhx_skyblue") {
  378.             this.dhxcont.style.border = "none";
  379.             this.setDimension(this.w, this.h);
  380.         }
  381.         
  382.         var obj = document.createElement("DIV");
  383.         obj.id = "dhxTabbarObj_"+this._genStr(12);
  384.         obj.style.width = "100%";
  385.         obj.style.height = "100%";
  386.         obj.style.overflow = "hidden";
  387.         obj.cmp = "tabbar";
  388.         document.body.appendChild(obj);
  389.         this.attachObject(obj.id);
  390.         
  391.         // manage dockcell if exists
  392.         /*
  393.         if (this._dockCell != null && that.dhxLayout != null) {
  394.             var dockCell = that.dhxLayout.polyObj[this._dockCell];
  395.             if (dockCell != null) {
  396.                 dockCell.childNodes[0]._tabbarMode = true;
  397.                 that.dhxLayout.hidePanel(this._dockCell);
  398.                 dockCell.className = "dhtmlxLayoutSinglePolyTabbar";
  399.                 // dockCell.childNodes[0]._h = -2;
  400.                 // dockCell.childNodes[1].style.height = parseInt(dockCell.childNodes[1].style.height) - dockCell.childNodes[0]._h + "px";
  401.                 // dockCell.className = "dhtmlxLayoutSinglePolyTabbar";
  402.                 // fix panel
  403.                 // that.dhxLayout._panelForTabs(this._dockCell);
  404.             }
  405.         }
  406.         */
  407.         if (this.className == "dhtmlxLayoutSinglePoly") { this.hideHeader(); }
  408.         //
  409.         this.tabbar = new dhtmlXTabBar(obj.id, mode||"top", 20);
  410.         if (!this._isWindow)
  411.             this.tabbar._s.expand = true;
  412.         this.tabbar.setSkin(this.skin);
  413.         /*
  414.         if ((_isIE)&&(document.compatMode == "BackCompat")){
  415.             this.tabbar._lineAHeight=this.tabbar._lineA.style.height="6px";
  416.             this.tabbar._bFix=5;
  417.         } else{
  418.             this.tabbar._lineAHeight=this.tabbar._lineA.style.height="4px";
  419.             this.tabbar._bFix=4;
  420.         }
  421.         */
  422.         //this.tabbar.setSkin("dhx_blue");
  423.         //this.tabbar.enableScroll(false)
  424.         //this.tabbar._conZone.style.borderWidth="0px";
  425.         //this.tabbar._EARS = true;
  426.         //this.tabbar.setMargin(-1)
  427.         //this.tabbar.setOffset(0)
  428.         this.tabbar.adjustOuterSize();
  429.         this.tabbarId = obj.id;
  430.         this.tabbarObj = obj;
  431.         
  432.         return this.tabbar;
  433.     }
  434.     /**
  435.     *   @desc: attaches a dhtmlxFolders to a window
  436.     *   @type: public
  437.     */
  438.     this.obj.attachFolders = function() {
  439.         if (this._isWindow && this.skin == "dhx_skyblue") {
  440.             this.dhxcont.mainCont.style.border = "#a4bed4 1px solid";
  441.             this._redraw();
  442.         }
  443.         var obj = document.createElement("DIV");
  444.         obj.id = "dhxFoldersObj_"+this._genStr(12);
  445.         obj.style.width = "100%";
  446.         obj.style.height = "100%";
  447.         obj.style.overflow = "hidden";
  448.         obj.cmp = "folders";
  449.         document.body.appendChild(obj);
  450.         this.attachObject(obj.id);
  451.         this.folders = new dhtmlxFolders(obj.id);
  452.         this.folders.setSizes();
  453.         
  454.         this.foldersId = obj.id;
  455.         this.foldersObj = obj;
  456.         
  457.         return this.folders;
  458.     }
  459.     /**
  460.     *   @desc: attaches a dhtmlxAccordion to a window
  461.     *   @type: public
  462.     */
  463.     this.obj.attachAccordion = function() {
  464.         if (this._isWindow && this.skin == "dhx_skyblue") {
  465.             this.dhxcont.mainCont.style.border = "#a4bed4 1px solid";
  466.             this._redraw();
  467.         }
  468.         
  469.         var obj = document.createElement("DIV");
  470.         obj.id = "dhxAccordionObj_"+this._genStr(12);
  471.         
  472.         obj.style.left = "-1px";
  473.         obj.style.top = "-1px";
  474.         obj.style.width = parseInt(this.dhxcont.mainCont.style.width)+2+"px";
  475.         obj.style.height = parseInt(this.dhxcont.mainCont.style.height)+2+"px";
  476.         //
  477.         obj.style.position = "relative";
  478.         obj.cmp = "accordion";
  479.         document.body.appendChild(obj);
  480.         this.attachObject(obj.id);
  481.         this.accordion = new dhtmlXAccordion(obj.id, this.skin);
  482.         
  483.         // win._content.childNodes[2].className += " dhtmlxAccordionAttached";
  484.         this.accordion.setSizes();
  485.         
  486.         this.accordionId = obj.id;
  487.         this.accordionObj = obj;
  488.         
  489.         return this.accordion;
  490.     }
  491.     /**
  492.     *   @desc: attaches a dhtmlxLayout to a window
  493.     *   @param: view - layout's pattern
  494.     *   @param: skin - layout's skin
  495.     *   @type: public
  496.     */
  497.     this.obj.attachLayout = function(view, skin) {
  498.         
  499.         // attach layout to layout
  500.         if (this._isCell && this.skin == "dhx_skyblue") {
  501.             this.hideHeader();
  502.             this.dhxcont.style.border = "0px solid white";
  503.             this.adjustContent(this.childNodes[0], 0);
  504.         }
  505.         
  506.         var obj = document.createElement("DIV");
  507.         obj.id = "dhxLayoutObj_"+this._genStr(12);
  508.         obj.style.overflow = "hidden";
  509.         obj.style.position = "absolute";
  510.         
  511.         obj.style.left = "0px";
  512.         obj.style.top = "0px";
  513.         obj.style.width = parseInt(this.dhxcont.mainCont.style.width)+"px";
  514.         obj.style.height = parseInt(this.dhxcont.mainCont.style.height)+"px";
  515.         
  516.         if (this._isAcc && this.skin == "dhx_skyblue") {
  517.             obj.style.left = "-1px";
  518.             obj.style.top = "-1px";
  519.             obj.style.width = parseInt(this.dhxcont.mainCont.style.width)+2+"px";
  520.             obj.style.height = parseInt(this.dhxcont.mainCont.style.height)+2+"px";
  521.         }
  522.         
  523.         // needed for layout's init
  524.         obj.dhxContExists = true;
  525.         obj.cmp = "layout";
  526.         document.body.appendChild(obj);
  527.         this.attachObject(obj.id);
  528.         
  529.         this.layout = new dhtmlXLayoutObject(obj, view, this.skin);
  530.         
  531.         // window/layout events configuration
  532.         
  533.         if (this._isWindow) this.attachEvent("_onBeforeTryResize", this.layout._defineWindowMinDimension);
  534.         
  535.         this.layoutId = obj.id;
  536.         this.layoutObj = obj;
  537.         
  538.         // this.adjust();
  539.         return this.layout;
  540.     }
  541.     /**
  542.     *   @desc: attaches a dhtmlxEditor to a window
  543.     *   @param: skin - not mandatory, editor's skin
  544.     *   @type: public
  545.     */
  546.     this.obj.attachEditor = function(skin) {
  547.         if (this._isWindow && this.skin == "dhx_skyblue") {
  548.             this.dhxcont.mainCont.style.border = "#a4bed4 1px solid";
  549.             this._redraw();
  550.         }
  551.         var obj = document.createElement("DIV");
  552.         obj.id = "dhxEditorObj_"+this._genStr(12);
  553.         obj.style.position = "relative";
  554.         obj.style.display = "none";
  555.         obj.style.overflow = "hidden";
  556.         obj.style.width = "100%";
  557.         obj.style.height = "100%";
  558.         obj.cmp = "editor";
  559.         document.body.appendChild(obj);
  560.         //
  561.         this.attachObject(obj.id);
  562.         //
  563.         this.editor = new dhtmlXEditor(obj.id, this.skin);
  564.         
  565.         this.editorId = obj.id;
  566.         this.editorObj = obj;
  567.         return this.editor;
  568.         
  569.     }
  570.     
  571.     /**
  572.     *   @desc: attaches an object into a window
  573.     *   @param: obj - object or object id
  574.     *   @param: autoSize - set true to adjust a window to object's dimension
  575.     *   @type: public
  576.     */
  577.     this.obj.attachObject = function(obj, autoSize) {
  578.         if (typeof(obj) == "string") obj = document.getElementById(obj);
  579.         if (autoSize) {
  580.             obj.style.visibility = "hidden";
  581.             obj.style.display = "";
  582.             var objW = obj.offsetWidth;
  583.             var objH = obj.offsetHeight;
  584.         }
  585.         this._attachContent("obj", obj);
  586.         if (autoSize && this._isWindow) {
  587.             obj.style.visibility = "visible";
  588.             this._adjustToContent(objW, objH);
  589.             /* this._engineAdjustWindowToContent(this, objW, objH); */
  590.         }
  591.     }
  592.     /**
  593.     *
  594.     *
  595.     */
  596.     this.obj.detachObject = function(remove) {
  597.         
  598.         // detach dhtmlx components
  599.         
  600.         var pref = null;
  601.         
  602.         if (this.tree) pref = "tree";
  603.         if (this.grid) pref = "grid";
  604.         if (this.layout) pref = "layout";
  605.         if (this.tabbar) pref = "tabbar";
  606.         if (this.accordion) pref = "accordion";
  607.         if (this.folders) pref = "folders";
  608.         
  609.         if (pref != null) {
  610.             var objHandler = null;
  611.             var objLink = null;
  612.             if (remove == true) {
  613.                 // completely remove
  614.                 if (this[pref].unload) this[pref].unload();
  615.                 if (this[pref].destructor) this[pref].destructor();
  616.                 while (this[pref+"Obj"].childNodes.length > 0) this[pref+"Obj"].removeChild(this[pref+"Obj"].childNodes[0]);
  617.             } else {
  618.                 // attach to body
  619.                 document.body.appendChild(this[pref+"Obj"]);
  620.                 this[pref+"Obj"].style.display = "none";
  621.                 objHandler = this[pref];
  622.                 objLink = this[pref+"Obj"];
  623.             }
  624.             this[pref] = null;
  625.             this[pref+"Id"] = null;
  626.             this[pref+"Obj"] = null;
  627.             return new Array(objHandler, objLink);
  628.         }
  629.         
  630.         // detach any other content
  631.         var objA = this.dhxcont.childNodes[0];
  632.         while (objA.childNodes.length > 0) {
  633.             if (remove == true) {
  634.                 objA.removeChild(objA.childNodes[0]);
  635.             } else {
  636.                 var obj = objA.childNodes[0];
  637.                 document.body.appendChild(obj);
  638.                 obj.style.display = "none";
  639.             }
  640.         }
  641.     }
  642.     
  643.     /**
  644.     *   @desc: appends an object into a window
  645.     *   @param: obj - object or object id
  646.     *   @type: public
  647.     */
  648.     this.obj.appendObject = function(obj) {
  649.         if (typeof(obj) == "string") { obj = document.getElementById(obj); }
  650.         this._attachContent("obj", obj, true);
  651.     }
  652.     /**
  653.     *   @desc: attaches an html string as an object into a window
  654.     *   @param: str - html string
  655.     *   @type: public
  656.     */
  657.     this.obj.attachHTMLString = function(str) {
  658.         this._attachContent("str", str);
  659.         var z=str.match(/<script[^>]*>[^\f]*?<\/script>/g)||[];
  660.         for (var i=0; i<z.length; i++){
  661.             var s=z[i].replace(/<([\/]{0,1})script[^>]*>/g,"")
  662.             if (window.execScript) window.execScript(s);
  663.             else window.eval(s);
  664.         }
  665.     }
  666.     /**
  667.     *   @desc: attaches an url into a window
  668.     *   @param: url
  669.     *   @param: ajax - loads an url with ajax
  670.     *   @type: public
  671.     */
  672.     this.obj.attachURL = function(url, ajax) {
  673.         this._attachContent((ajax==true?"urlajax":"url"), url, false);
  674.     }
  675.     this.obj.adjust = function() {
  676.         if (this.skin == "dhx_skyblue") {
  677.             if (this.menu) {
  678.                 if (this._isWindow || this._isLayout) {
  679.                     this.menu._topLevelOffsetLeft = 0;
  680.                     document.getElementById(this.menuId).style.height = "26px";
  681.                     this.menuHeight = document.getElementById(this.menuId).offsetHeight;
  682.                     if (this._doOnAttachMenu) this._doOnAttachMenu("show");
  683.                 }
  684.                 if (this._isCell) {
  685.                     document.getElementById(this.menuId).className += " in_layoutcell";
  686.                     // document.getElementById(this.menuId).style.height = "25px";
  687.                     this.menuHeight = 25;
  688.                 }
  689.                 if (this._isAcc) {
  690.                     document.getElementById(this.menuId).className += " in_acccell";
  691.                     // document.getElementById(this.menuId).style.height = "25px";
  692.                     this.menuHeight = 25;
  693.                 }
  694.                 if (this._doOnAttachMenu) this._doOnAttachMenu("adjust");
  695.             }
  696.             if (this.toolbar) {
  697.                 if (this._isWindow || this._isLayout) {
  698.                     document.getElementById(this.toolbarId).style.height = "29px";
  699.                     this.toolbarHeight = document.getElementById(this.toolbarId).offsetHeight;
  700.                     if (this._doOnAttachToolbar) this._doOnAttachToolbar("show");
  701.                 }
  702.                 if (this._isCell) {
  703.                     document.getElementById(this.toolbarId).className += " in_layoutcell";
  704.                 }
  705.                 if (this._isAcc) {
  706.                     document.getElementById(this.toolbarId).className += " in_acccell";
  707.                 }
  708.             }
  709.         }
  710.     }
  711.     // attach content obj|url
  712.     this.obj._attachContent = function(type, obj, append) {
  713.         // clear old content
  714.         if (append !== true) {
  715.             while (that.dhxcont.mainCont.childNodes.length > 0) { that.dhxcont.mainCont.removeChild(that.dhxcont.mainCont.childNodes[0]); }
  716.         }
  717.         // attach
  718.         if (type == "url") {
  719.             if (this._isWindow && obj.cmp == null && this.skin == "dhx_skyblue") {
  720.                 this.dhxcont.mainCont.style.border = "#a4bed4 1px solid";
  721.                 this._redraw();
  722.             }
  723.             var fr = document.createElement("IFRAME");
  724.             fr.frameBorder = 0;
  725.             fr.border = 0;
  726.             fr.style.width = "100%";
  727.             fr.style.height = "100%";
  728.             fr.setAttribute("src","javascript:false;");
  729.             that.dhxcont.mainCont.appendChild(fr);
  730.             fr.src = obj;
  731.             this._frame = fr;
  732.             if (this._doOnAttachURL) this._doOnAttachURL(true);
  733.         } else if (type == "urlajax") {
  734.             if (this._isWindow && obj.cmp == null && this.skin == "dhx_skyblue") {
  735.                 this.dhxcont.mainCont.style.border = "#a4bed4 1px solid";
  736.                 this.dhxcont.mainCont.style.backgroundColor = "#FFFFFF";
  737.                 this._redraw();
  738.             }
  739.             var t = this;
  740.             var xmlParser = function(){
  741.                 t.attachHTMLString(this.xmlDoc.responseText,this);
  742.                 if (t._doOnAttachURL) t._doOnAttachURL(false);
  743.                 this.destructor();
  744.             }
  745.             var xmlLoader = new dtmlXMLLoaderObject(xmlParser, window);
  746.             xmlLoader.dhxWindowObject = this;
  747.             xmlLoader.loadXML(obj);
  748.         } else if (type == "obj") {
  749.             if (this._isWindow && obj.cmp == null && this.skin == "dhx_skyblue") {
  750.                 this.dhxcont.mainCont.style.border = "#a4bed4 1px solid";
  751.                 this.dhxcont.mainCont.style.backgroundColor = "#FFFFFF";
  752.                 this._redraw();
  753.             }
  754.             that.dhxcont._frame = null;
  755.             that.dhxcont.mainCont.appendChild(obj);
  756.             // this._engineGetWindowContent(win).style.overflow = (append===true?"auto":"hidden");
  757.             // win._content.childNodes[2].appendChild(obj);
  758.             that.dhxcont.mainCont.style.overflow = (append===true?"auto":"hidden");
  759.             obj.style.display = "";
  760.         } else if (type == "str") {
  761.             if (this._isWindow && obj.cmp == null && this.skin == "dhx_skyblue") {
  762.                 this.dhxcont.mainCont.style.border = "#a4bed4 1px solid";
  763.                 this.dhxcont.mainCont.style.backgroundColor = "#FFFFFF";
  764.                 this._redraw();
  765.             }
  766.             that.dhxcont._frame = null;
  767.             that.dhxcont.mainCont.innerHTML = obj;
  768.         }
  769.     }
  770.     
  771.     this.obj.showMenu = function() {
  772.         if (!(this.menu && this.menuId)) return;
  773.         if (document.getElementById(this.menuId).style.display != "none") return;
  774.         this.menuHidden = false;
  775.         if (this._doOnAttachMenu) this._doOnAttachMenu("show");
  776.         document.getElementById(this.menuId).style.display = "";
  777.     }
  778.     
  779.     this.obj.hideMenu = function() {
  780.         if (!(this.menu && this.menuId)) return;
  781.         if (document.getElementById(this.menuId).style.display == "none") return;
  782.         document.getElementById(this.menuId).style.display = "none";
  783.         this.menuHidden = true;
  784.         if (this._doOnAttachMenu) this._doOnAttachMenu("hide");
  785.     }
  786.     
  787.     this.obj.showToolbar = function() {
  788.         if (!(this.toolbar && this.toolbarId)) return;
  789.         if (document.getElementById(this.toolbarId).style.display != "none") return;
  790.         this.toolbarHidden = false;
  791.         if (this._doOnAttachToolbar) this._doOnAttachToolbar("show");
  792.         document.getElementById(this.toolbarId).style.display = "";
  793.     }
  794.     
  795.     this.obj.hideToolbar = function() {
  796.         if (!(this.toolbar && this.toolbarId)) return;
  797.         if (document.getElementById(this.toolbarId).style.display == "none") return;
  798.         this.toolbarHidden = true;
  799.         document.getElementById(this.toolbarId).style.display = "none";
  800.         if (this._doOnAttachToolbar) this._doOnAttachToolbar("hide");
  801.     }
  802.     
  803.     this.obj.showStatusBar = function() {
  804.         if (!(this.sb && this.sbId)) return;
  805.         if (document.getElementById(this.sbId).style.display != "none") return;
  806.         this.sbHidden = false;
  807.         if (this._doOnAttachStatusBar) this._doOnAttachStatusBar("show");
  808.         document.getElementById(this.sbId).style.display = "";
  809.     }
  810.     
  811.     this.obj.hideStatusBar = function() {
  812.         if (!(this.sb && this.sbId)) return;
  813.         if (document.getElementById(this.sbId).style.display == "none") return;
  814.         this.sbHidden = true;
  815.         document.getElementById(this.sbId).style.display = "none";
  816.         if (this._doOnAttachStatusBar) this._doOnAttachStatusBar("hide");
  817.     }
  818.     
  819.     this.obj._dhxContDestruct = function() {
  820.         
  821.         // clear attached objects
  822.         this.detachMenu();
  823.         this.detachToolbar();
  824.         this.detachStatusBar();
  825.         
  826.         // remove any attached object
  827.         this.detachObject(true);
  828.         
  829.         // remove attached components
  830.         if (this.layout) this.layout.unlaod();
  831.         if (this.accordion) this.accordion.unlaod();
  832.         if (this.grid) this.grid.destructor();
  833.         if (this.tree) this.tree.destructor();
  834.         if (this.tabbar) this.tabbar.destructor();
  835.         this.layout = null;
  836.         this.accordion = null;
  837.         this.grid = null;
  838.         this.tree = null;
  839.         this.tabbar = null;
  840.         
  841.         // clear methods
  842.         this.adjust = null;
  843.         this._genStr = null;
  844.         this.setMinContentSize = null;
  845.         this.moveContentTo = null;
  846.         this.adjustContent = null;
  847.         this.coverBlocker = null;
  848.         this.showCoverBlocker = null;
  849.         this.hideCoverBlocker = null;
  850.         this.updateNestedObjects = null;
  851.         this.attachStatusBar = null;
  852.         this.detachStatusBar = null;
  853.         this.attachMenu = null;
  854.         this.detachMenu = null;
  855.         this.attachToolbar = null;
  856.         this.detachToolbar = null;
  857.         
  858.         this.attachGrid = this.attachTree = this.attachTabbar = this.attachFolders = this.attachAccordion = this.attachLayout = this.attachEditor = this.attachObject = this.detachObject = this.appendObject = this.attachHTMLString =  this.attachURL = this._attachContent = this.attachScheduler = null;
  859.         
  860.         this.showMenu = null;
  861.         this.hideMenu = null;
  862.         this.showToolbar = null;
  863.         this.hideToolbar = null;
  864.         this.showStatusBar = null;
  865.         this.hideStatusBar = null;
  866.         
  867.         while (this.dhxcont.mainCont.childNodes.length > 0) this.dhxcont.mainCont.removeChild(this.dhxcont.mainCont.childNodes[0]);
  868.         this.dhxcont.mainCont.innerHTML = "";
  869.         this.dhxcont.mainCont = null;
  870.         try { delete this.dhxcont["mainCont"]; } catch(e){};
  871.         
  872.         while (this.dhxcont.childNodes.length > 0) this.dhxcont.removeChild(this.dhxcont.childNodes[0]);
  873.         this.dhxcont.innerHTML = "";
  874.         this.dhxcont = null;
  875.         try { delete this["dhxcont"]; } catch(e){};
  876.     }
  877.     
  878. }
  879.