place.js 4.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137
  1. define("dijit/_base/place", [
  2. "dojo/_base/array", // array.forEach
  3. "dojo/_base/lang", // lang.isArray
  4. "dojo/window", // windowUtils.getBox
  5. "../place",
  6. ".." // export to dijit namespace
  7. ], function(array, lang, windowUtils, place, dijit){
  8. // module:
  9. // dijit/_base/place
  10. // summary:
  11. // Back compatibility module, new code should use dijit/place directly instead of using this module.
  12. dijit.getViewport = function(){
  13. // summary:
  14. // Deprecated method to return the dimensions and scroll position of the viewable area of a browser window.
  15. // New code should use windowUtils.getBox()
  16. return windowUtils.getBox();
  17. };
  18. /*=====
  19. dijit.placeOnScreen = function(node, pos, corners, padding){
  20. // summary:
  21. // Positions one of the node's corners at specified position
  22. // such that node is fully visible in viewport.
  23. // Deprecated, new code should use dijit.place.at() instead.
  24. };
  25. =====*/
  26. dijit.placeOnScreen = place.at;
  27. /*=====
  28. dijit.placeOnScreenAroundElement = function(node, aroundElement, 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. ====*/
  35. dijit.placeOnScreenAroundElement = function(node, aroundNode, aroundCorners, layoutNode){
  36. // Convert old style {"BL": "TL", "BR": "TR"} type argument
  37. // to style needed by dijit.place code:
  38. // [
  39. // {aroundCorner: "BL", corner: "TL" },
  40. // {aroundCorner: "BR", corner: "TR" }
  41. // ]
  42. var positions;
  43. if(lang.isArray(aroundCorners)){
  44. positions = aroundCorners;
  45. }else{
  46. positions = [];
  47. for(var key in aroundCorners){
  48. positions.push({aroundCorner: key, corner: aroundCorners[key]});
  49. }
  50. }
  51. return place.around(node, aroundNode, positions, true, layoutNode);
  52. };
  53. /*=====
  54. dijit.placeOnScreenAroundNode = function(node, aroundNode, aroundCorners, layoutNode){
  55. // summary:
  56. // Position node adjacent or kitty-corner to aroundNode
  57. // such that it's fully visible in viewport.
  58. // Deprecated, new code should use dijit.place.around() instead.
  59. };
  60. =====*/
  61. dijit.placeOnScreenAroundNode = dijit.placeOnScreenAroundElement;
  62. /*=====
  63. dijit.placeOnScreenAroundRectangle = function(node, aroundRect, aroundCorners, layoutNode){
  64. // summary:
  65. // Like dijit.placeOnScreenAroundNode(), except that the "around"
  66. // parameter is an arbitrary rectangle on the screen (x, y, width, height)
  67. // instead of a dom node.
  68. // Deprecated, new code should use dijit.place.around() instead.
  69. };
  70. =====*/
  71. dijit.placeOnScreenAroundRectangle = dijit.placeOnScreenAroundElement;
  72. dijit.getPopupAroundAlignment = function(/*Array*/ position, /*Boolean*/ leftToRight){
  73. // summary:
  74. // Deprecated method, unneeded when using dijit/place directly.
  75. // Transforms the passed array of preferred positions into a format suitable for
  76. // passing as the aroundCorners argument to dijit.placeOnScreenAroundElement.
  77. //
  78. // position: String[]
  79. // This variable controls the position of the drop down.
  80. // It's an array of strings with the following values:
  81. //
  82. // * before: places drop down to the left of the target node/widget, or to the right in
  83. // the case of RTL scripts like Hebrew and Arabic
  84. // * after: places drop down to the right of the target node/widget, or to the left in
  85. // the case of RTL scripts like Hebrew and Arabic
  86. // * above: drop down goes above target node
  87. // * below: drop down goes below target node
  88. //
  89. // The list is positions is tried, in order, until a position is found where the drop down fits
  90. // within the viewport.
  91. //
  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. return dijit;
  127. });