Changeset 14269

Show
Ignore:
Timestamp:
07/04/08 13:17:53 (5 months ago)
Author:
elazutkin
Message:

Implementing the placement registry with AdapterRegistry? on Bill's suggestion. Refs #4721. !strict

Files:
1 modified

Legend:

Unmodified
Added
Removed
  • dijit/trunk/_base/place.js

    r14259 r14269  
    11dojo.provide("dijit._base.place"); 
     2 
     3dojo.require("dojo.AdapterRegistry"); 
    24 
    35// ported from dojo.html.util 
     
    275277}; 
    276278 
    277 (function(){ 
    278         // a closure for the internal registry 
    279          
    280         var registry = [ 
    281                 { 
    282                         guard:  function(x){ return typeof x == "object" && x.tagName && x.cloneNode; }, 
    283                         proc:   dijit.placeOnScreenAroundNode 
    284                 }, 
    285                 { 
    286                         guard:  function(x){ return typeof x == "object" && "x" in x && "y" in x && "width" in x && "height" in x; }, 
    287                         proc:   dijit.placeOnScreenAroundRectangle 
    288                 } 
    289         ]; 
    290          
    291         dijit.addAroundProcessor = function(/*Function*/ guard, /*Function*/ processor){ 
    292                 // summary: adds new placement processor to the registry 
    293                 // guard: Function 
    294                 //              a Boolean function, which takes an object and returns true, 
    295                 //              if the processor can accept this object 
    296                 // processor: Function 
    297                 //              a placement function for this object 
    298                 // returns: Object 
    299                 //              this object can be used to remove the processor later 
    300                  
    301                 return registry.push({guard: guard, proc: processor}) - 1;      // Object 
    302         }; 
    303          
    304         dijit.removeAroundProcessor = function(/*Object*/ id){ 
    305                 // summary: removes a placement processor from the registry, 
    306                 //      see dijit.addAroundProcessor for details 
    307                  
    308                 registry.splice(id, 1); 
    309         }; 
    310          
    311         dijit.placeOnScreenAroundElement = function( 
    312                 /* DomNode */           node, 
    313                 /* Object */            aroundElement, 
    314                 /* Object */            aroundCorners, 
    315                 /* Function */          layoutNode){ 
    316          
    317                 //      summary 
    318                 //      Like placeOnScreen, except it accepts an arbitrary object, 
    319                 //      and finds a proper processor to place a node. 
    320                 // 
    321                 //      aroundCorners 
    322                 //              specify Which corner of aroundNode should be 
    323                 //              used to place the node => which corner(s) of node to use (see the 
    324                 //              corners parameter in dijit.placeOnScreen) 
    325                 //              e.g. {'TL': 'BL', 'BL': 'TL'} 
    326                 // 
    327                 //      layoutNode: Function(node, aroundNodeCorner, nodeCorner) 
    328                 //              for things like tooltip, they are displayed differently (and have different dimensions) 
    329                 //              based on their orientation relative to the parent.   This adjusts the popup based on orientation. 
    330  
    331                 for(var i = 0; i < registry.length; ++i){ 
    332                         var v = registry[i]; 
    333                         if(v.guard(aroundElement)){ 
    334                                 return v.proc.apply(dijit, arguments); 
    335                         } 
    336                 } 
    337                 // the default 
    338                 return dijit.placeOnScreenAroundNode.apply(dijit, arguments); 
    339         }; 
    340 })(); 
     279dijit.placementRegistry = new dojo.AdapterRegistry(); 
     280dijit.placementRegistry.register("node", 
     281        function(n, x){ 
     282                return typeof x == "object" && 
     283                        typeof x.offsetWidth != "undefined" && typeof x.offsetHeight != "undefined"; 
     284        }, 
     285        dijit.placeOnScreenAroundNode); 
     286dijit.placementRegistry.register("rect", 
     287        function(n, x){ 
     288                return typeof x == "object" && 
     289                        "x" in x && "y" in x && "width" in x && "height" in x; 
     290        }, 
     291        dijit.placeOnScreenAroundRectangle); 
     292 
     293dijit.placeOnScreenAroundElement = function( 
     294        /* DomNode */           node, 
     295        /* Object */            aroundElement, 
     296        /* Object */            aroundCorners, 
     297        /* Function */          layoutNode){ 
     298 
     299        //      summary 
     300        //      Like placeOnScreen, except it accepts an arbitrary object, 
     301        //      and finds a proper processor to place a node. 
     302        // 
     303        //      aroundCorners 
     304        //              specify Which corner of aroundNode should be 
     305        //              used to place the node => which corner(s) of node to use (see the 
     306        //              corners parameter in dijit.placeOnScreen) 
     307        //              e.g. {'TL': 'BL', 'BL': 'TL'} 
     308        // 
     309        //      layoutNode: Function(node, aroundNodeCorner, nodeCorner) 
     310        //              for things like tooltip, they are displayed differently (and have different dimensions) 
     311        //              based on their orientation relative to the parent.   This adjusts the popup based on orientation. 
     312 
     313        return dijit.placementRegistry.match.apply(dijit.placementRegistry, arguments); 
     314};