source: Dev/trunk/src/client/dijit/_base/place.js @ 529

Last change on this file since 529 was 483, checked in by hendrikvanantwerpen, 11 years ago

Added Dojo 1.9.3 release.

File size: 4.4 KB
Line 
1define([
2        "dojo/_base/array", // array.forEach
3        "dojo/_base/lang", // lang.isArray, lang.mixin
4        "dojo/window", // windowUtils.getBox
5        "../place",
6        "../main"       // export to dijit namespace
7], function(array, lang, windowUtils, place, dijit){
8
9        // module:
10        //              dijit/_base/place
11
12
13        var exports = {
14                // summary:
15                //              Deprecated back compatibility module, new code should use dijit/place directly instead of using this module.
16        };
17
18        exports.getViewport = function(){
19                // summary:
20                //              Deprecated method to return the dimensions and scroll position of the viewable area of a browser window.
21                //              New code should use windowUtils.getBox()
22
23                return windowUtils.getBox();
24        };
25
26        exports.placeOnScreen = place.at;
27
28        exports.placeOnScreenAroundElement = function(node, aroundNode, aroundCorners, layoutNode){
29                // summary:
30                //              Like dijit.placeOnScreenAroundNode(), except it accepts an arbitrary object
31                //              for the "around" argument and finds a proper processor to place a node.
32                //              Deprecated, new code should use dijit/place.around() instead.
33
34                // Convert old style {"BL": "TL", "BR": "TR"} type argument
35                // to style needed by dijit.place code:
36                //              [
37                //                      {aroundCorner: "BL", corner: "TL" },
38                //                      {aroundCorner: "BR", corner: "TR" }
39                //              ]
40                var positions;
41                if(lang.isArray(aroundCorners)){
42                        positions = aroundCorners;
43                }else{
44                        positions = [];
45                        for(var key in aroundCorners){
46                                positions.push({aroundCorner: key, corner: aroundCorners[key]});
47                        }
48                }
49
50                return place.around(node, aroundNode, positions, true, layoutNode);
51        };
52
53        exports.placeOnScreenAroundNode = exports.placeOnScreenAroundElement;
54        /*=====
55        exports.placeOnScreenAroundNode = function(node, aroundNode, aroundCorners, layoutNode){
56                // summary:
57                //              Position node adjacent or kitty-corner to aroundNode
58                //              such that it's fully visible in viewport.
59                //              Deprecated, new code should use dijit/place.around() instead.
60        };
61        =====*/
62
63        exports.placeOnScreenAroundRectangle = exports.placeOnScreenAroundElement;
64        /*=====
65        exports.placeOnScreenAroundRectangle = function(node, aroundRect, aroundCorners, layoutNode){
66                // summary:
67                //              Like dijit.placeOnScreenAroundNode(), except that the "around"
68                //              parameter is an arbitrary rectangle on the screen (x, y, width, height)
69                //              instead of a dom node.
70                //              Deprecated, new code should use dijit/place.around() instead.
71        };
72        =====*/
73
74        exports.getPopupAroundAlignment = function(/*Array*/ position, /*Boolean*/ leftToRight){
75                // summary:
76                //              Deprecated method, unneeded when using dijit/place directly.
77                //              Transforms the passed array of preferred positions into a format suitable for
78                //              passing as the aroundCorners argument to dijit/place.placeOnScreenAroundElement.
79                // position: String[]
80                //              This variable controls the position of the drop down.
81                //              It's an array of strings with the following values:
82                //
83                //              - before: places drop down to the left of the target node/widget, or to the right in
84                //                the case of RTL scripts like Hebrew and Arabic
85                //              - after: places drop down to the right of the target node/widget, or to the left in
86                //                the case of RTL scripts like Hebrew and Arabic
87                //              - above: drop down goes above target node
88                //              - below: drop down goes below target node
89                //
90                //              The list is positions is tried, in order, until a position is found where the drop down fits
91                //              within the viewport.
92                // leftToRight: Boolean
93                //              Whether the popup will be displaying in leftToRight mode.
94
95                var align = {};
96                array.forEach(position, function(pos){
97                        var ltr = leftToRight;
98                        switch(pos){
99                                case "after":
100                                        align[leftToRight ? "BR" : "BL"] = leftToRight ? "BL" : "BR";
101                                        break;
102                                case "before":
103                                        align[leftToRight ? "BL" : "BR"] = leftToRight ? "BR" : "BL";
104                                        break;
105                                case "below-alt":
106                                        ltr = !ltr;
107                                        // fall through
108                                case "below":
109                                        // first try to align left borders, next try to align right borders (or reverse for RTL mode)
110                                        align[ltr ? "BL" : "BR"] = ltr ? "TL" : "TR";
111                                        align[ltr ? "BR" : "BL"] = ltr ? "TR" : "TL";
112                                        break;
113                                case "above-alt":
114                                        ltr = !ltr;
115                                        // fall through
116                                case "above":
117                                default:
118                                        // first try to align left borders, next try to align right borders (or reverse for RTL mode)
119                                        align[ltr ? "TL" : "TR"] = ltr ? "BL" : "BR";
120                                        align[ltr ? "TR" : "TL"] = ltr ? "BR" : "BL";
121                                        break;
122                        }
123                });
124                return align;
125        };
126
127        lang.mixin(dijit, exports);
128
129        /*===== return exports; =====*/
130        return dijit;   // for back compat :-(
131});
Note: See TracBrowser for help on using the repository browser.