Subversion Repositories wimsdev

Rev

Blame | Last modification | View Log | RSS feed

  1. /*
  2.         DynAPI Distribution
  3.         FocusManager Class
  4.  
  5.         The DynAPI Distribution is distributed under the terms of the GNU LGPL license.
  6.  
  7.         requires: DynLayer
  8. */
  9.  
  10. FocusManager={};
  11.  
  12. // usage: FocusManager.enableFocus('auto',true,'click',lyr1,lyr2,...lyrN);
  13. FocusManager.enableFocus=function(b,bubble,type){
  14.         var lyr,arg=arguments;
  15.         for (var i=3;i<arg.length;i++){
  16.                 lyr=arg[i];
  17.                 if(lyr) lyr.setFocus(b,bubble,type);
  18.         }
  19. };
  20.  
  21. DynLayer.prototype.setFocus = function(b,bubble,type){
  22.         var i,topchild;
  23.         //var d=this.design;
  24.         bubble=(bubble==null)? true:bubble;
  25.         if(b!=='auto' && !this.parent) return;
  26.         if(b=='auto' && !this._hasFocusEvents) {
  27.                 if(type!='hover') type='click';
  28.                 this._focusType=type;
  29.                 this._focusBubble=bubble;
  30.                 this._hasFocusEvents=true;
  31.                 this.addEventListener(DynLayer.FocusEvent);
  32.         }
  33.         else if (b && !this._focused) {
  34.                 topchild=this.parent._topMostChild;
  35.                 //i = this.parent.children.length;
  36.                 if(topchild && topchild!=this) topchild.setFocus(false,bubble);
  37.                 if(this._hasTabManager) this.updateTabManager();
  38.                 this.setZIndex({topmost:true});
  39.                 this.parent._topMostChild=this;
  40.                 this._focused=true;
  41.                 this.invokeEvent('focus');
  42.                 var o=this.parent;
  43.                 if(bubble) while (o && o!=dynapi.document) {
  44.                         o.setFocus(b,bubble);
  45.                         o=o.parent;
  46.                 };
  47.         }else if(!b && this._focused){
  48.                 topchild=this.parent._topMostChild;
  49.                 if (topchild) this.setZIndex({below:topchild});
  50.                 else this.setZIndex(thiz.z-1);
  51.                 this._focused=false;
  52.                 this.invokeEvent('blur');
  53.                 var o=this.parent;
  54.                 var ch=this.children;
  55.                 // blur children with focus
  56.                 for(var i=0;i<ch.length;i++) if(ch[i]._focused) ch[i].setFocus(false,bubble);
  57.                 if(o && o!=dynapi.document) o.setFocus(false,bubble);
  58.         }
  59. };
  60.  
  61. //DynLayer.prototype.setTabIndex = function(n){
  62. //};
  63.  
  64. DynLayer.FocusEvent = {
  65.         onclick : function(e){
  66.                 var o=e.getSource();
  67.                 if(o._focusType=='click') {
  68.                         o.setFocus(true,o._focusBubble);
  69.                 }
  70.         },
  71.         onmouseover : function(e){
  72.                 var o=e.getSource();
  73.                 if(o._focusType=='hover') {
  74.                         o.setFocus(true,o._focusBubble);
  75.                 }
  76.         }
  77. };
  78.