Changeset 12477

Show
Ignore:
Timestamp:
02/15/08 21:47:35 (11 months ago)
Author:
peller
Message:

Move lookups out of mouseover event. Fix keyboard control. Refs #4117, fixes #5874 !strict

Files:
1 modified

Legend:

Unmodified
Added
Removed
  • dijit/trunk/layout/BorderContainer.js

    r12473 r12477  
    8080                                this._splitters[region] = splitter.domNode; 
    8181                                dojo.place(splitter.domNode, child.domNode, "after"); 
    82                                 this._splitterThickness[region] = dojo.marginBox(this._splitters[region])[/top|bottom/.test(region) ? 'h' : 'w']; 
     82                                this._splitterThickness[region] = dojo.marginBox(this._splitters[region])[/top|bottom/.test(region) ? 'h' : 'w']; //TODO 
    8383                        } 
    8484                        child.region = region; 
     
    341341                this._minSize = this.child.minSize; 
    342342 
     343                var dim = this.horizontal ? 'h' : 'w'; 
     344                var available = dojo.contentBox(this.container.domNode)[dim] - (this.oppNode ? dojo.marginBox(this.oppNode)[dim] : 0); //FIXME: what if this.oppNode is undefined? 
     345                this._maxSize = Math.min(this.child.maxSize, available); 
     346 
    343347                this._cookieName = this.container.id + "_" + this.region; 
    344348                if(this.container.persist){ 
     
    369373                } 
    370374                dojo.addClass(this.domNode, "dijitSplitterActive"); 
    371                 var horizontal = this.horizontal; 
    372                 this._pageStart = horizontal ? e.pageY : e.pageX; 
    373                 var dim = horizontal ? 'h' : 'w'; 
    374                 this._childStart = dojo.marginBox(this.child.domNode)[dim]; 
    375                 this._splitterStart = parseInt(this.domNode.style[this.region]); 
     375 
     376                //Performance: load data info local vars for onmousevent function closure 
     377                var factor = this._factor, 
     378                        max = this._maxSize, 
     379                        min = this._minSize || 10, 
     380                        axis = this.horizontal ? "pageY" : "pageX", 
     381                        pageStart = e[axis], 
     382                        splitterStyle = this.domNode.style, 
     383                        dim = this.horizontal ? 'h' : 'w', 
     384                        childStart = dojo.marginBox(this.child.domNode)[dim], 
     385                        splitterStart = parseInt(this.domNode.style[this.region]), 
     386                        resize = this._resize, 
     387                        region = this.region, 
     388                        mb = {}, 
     389                        childNode = this.child.domNode, 
     390                        layoutFunc = dojo.hitch(this.container, this.container._layoutChildren); 
     391 
    376392                var de = dojo.doc.body; 
    377393                this._handlers = (this._handlers || []).concat([ 
    378                         dojo.connect(de, "onmousemove", this, "_drag"), 
     394                        dojo.connect(de, "onmousemove", this._drag = function(e, forceResize){ 
     395                                var delta = e[axis] - pageStart; 
     396                                var childSize = factor * delta + childStart; 
     397                                var boundChildSize = Math.max(Math.min(childSize, max), min); 
     398                                if(resize || forceResize){ 
     399                                        mb[dim] = boundChildSize; 
     400                                        dojo.marginBox(childNode, mb); 
     401                                        layoutFunc(region); 
     402                                } 
     403                                splitterStyle[region] = factor * delta + splitterStart + (boundChildSize - childSize) + "px"; 
     404                                dojo.stopEvent(e); 
     405                        }), 
    379406                        dojo.connect(de, "onmouseup", this, "_stopDrag") 
    380407                ]); 
    381                 this._computeMaxSize(); 
    382408                dojo.stopEvent(e); 
    383         }, 
    384  
    385         _computeMaxSize: function(){ 
    386                 var dim = this.horizontal ? 'h' : 'w'; 
    387                 var available = dojo.contentBox(this.container.domNode)[dim] - (this.oppNode ? dojo.marginBox(this.oppNode)[dim] : 0); //FIXME: what if this.oppNode is undefined? 
    388                 this._maxSize = Math.min(this.child.maxSize, available); 
    389         }, 
    390  
    391         _drag: function(e){ 
    392                 var delta = (this.horizontal ? e.pageY : e.pageX) - this._pageStart; 
    393                 var childSize = this._factor * delta + this._childStart; 
    394                 var boundChildSize = Math.max(Math.min(childSize, this._maxSize), this._minSize || 10); 
    395                 if(this._resize){ 
    396                         this._move(delta, boundChildSize); 
    397                 } 
    398                 var splitterEdge = this._factor * delta + this._splitterStart + (boundChildSize - childSize); 
    399                 this.domNode.style[this.region] = splitterEdge + "px"; 
    400                 dojo.stopEvent(e); 
    401         }, 
    402  
    403         _move: function(/*Number*/delta, childSize){ 
    404                 var mb = {}; 
    405                 mb[ this.horizontal ? "h" : "w"] = childSize; 
    406                 dojo.marginBox(this.child.domNode, mb); 
    407                 this.container._layoutChildren(this.region); 
    408409        }, 
    409410 
     
    414415                        dojo.removeClass(this.domNode, "dijitSplitterActive"); 
    415416                        dojo.removeClass(this.domNode, "dijitSplitterShadow"); 
    416                         this._drag(e); 
    417                         this._resize = true; 
    418                         this._drag(e); 
     417                        this._drag(e); //TODO: redundant with onmousemove? 
     418                        this._drag(e, true); 
    419419                }finally{ 
    420420                        this._cleanupHandlers(); 
     421                        delete this._drag; 
    421422                } 
    422423 
     
    447448                                return; 
    448449                } 
    449                 this._computeMaxSize(); 
    450                 var childSize = dojo.marginBox(this.child.domNode)[ horizontal ? 'h' : 'w' ]; 
    451                 childSize = Math.max(Math.min(childSize, this._maxSize), this._minSize); 
    452                 this._move(tick, childSize); 
     450                var childSize = dojo.marginBox(this.child.domNode)[ horizontal ? 'h' : 'w' ] + this._factor * tick; 
     451                var mb = {}; 
     452                mb[ this.horizontal ? "h" : "w"] = Math.max(Math.min(childSize, this._maxSize), this._minSize); 
     453                dojo.marginBox(this.child.domNode, mb); 
     454                this.container._layoutChildren(this.region); 
    453455                dojo.stopEvent(e); 
    454456        },