TooltipDialog.js 5.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146
  1. /*
  2. Copyright (c) 2004-2012, The Dojo Foundation All Rights Reserved.
  3. Available via Academic Free License >= 2.1 OR the modified BSD license.
  4. see: http://dojotoolkit.org/license for details
  5. */
  6. if(!dojo._hasResource["dijit.TooltipDialog"]){ //_hasResource checks added by build. Do not use _hasResource directly in your code.
  7. dojo._hasResource["dijit.TooltipDialog"] = true;
  8. dojo.provide("dijit.TooltipDialog");
  9. dojo.require("dijit.layout.ContentPane");
  10. dojo.require("dijit._Templated");
  11. dojo.require("dijit.form._FormMixin");
  12. dojo.require("dijit._DialogMixin");
  13. dojo.declare(
  14. "dijit.TooltipDialog",
  15. [dijit.layout.ContentPane, dijit._Templated, dijit.form._FormMixin, dijit._DialogMixin],
  16. {
  17. // summary:
  18. // Pops up a dialog that appears like a Tooltip
  19. // title: String
  20. // Description of tooltip dialog (required for a11y)
  21. title: "",
  22. // doLayout: [protected] Boolean
  23. // Don't change this parameter from the default value.
  24. // This ContentPane parameter doesn't make sense for TooltipDialog, since TooltipDialog
  25. // is never a child of a layout container, nor can you specify the size of
  26. // TooltipDialog in order to control the size of an inner widget.
  27. doLayout: false,
  28. // autofocus: Boolean
  29. // A Toggle to modify the default focus behavior of a Dialog, which
  30. // is to focus on the first dialog element after opening the dialog.
  31. // False will disable autofocusing. Default: true
  32. autofocus: true,
  33. // baseClass: [protected] String
  34. // The root className to use for the various states of this widget
  35. baseClass: "dijitTooltipDialog",
  36. // _firstFocusItem: [private] [readonly] DomNode
  37. // The pointer to the first focusable node in the dialog.
  38. // Set by `dijit._DialogMixin._getFocusItems`.
  39. _firstFocusItem: null,
  40. // _lastFocusItem: [private] [readonly] DomNode
  41. // The pointer to which node has focus prior to our dialog.
  42. // Set by `dijit._DialogMixin._getFocusItems`.
  43. _lastFocusItem: null,
  44. templateString: dojo.cache("dijit", "templates/TooltipDialog.html", "<div role=\"presentation\" tabIndex=\"-1\">\n\t<div class=\"dijitTooltipContainer\" role=\"presentation\">\n\t\t<div class =\"dijitTooltipContents dijitTooltipFocusNode\" dojoAttachPoint=\"containerNode\" role=\"dialog\"></div>\n\t</div>\n\t<div class=\"dijitTooltipConnector\" role=\"presentation\"></div>\n</div>\n"),
  45. _setTitleAttr: function(/*String*/ title){
  46. this.containerNode.title = title;
  47. this._set("title", title)
  48. },
  49. postCreate: function(){
  50. this.inherited(arguments);
  51. this.connect(this.containerNode, "onkeypress", "_onKey");
  52. },
  53. orient: function(/*DomNode*/ node, /*String*/ aroundCorner, /*String*/ corner){
  54. // summary:
  55. // Configure widget to be displayed in given position relative to the button.
  56. // This is called from the dijit.popup code, and should not be called
  57. // directly.
  58. // tags:
  59. // protected
  60. var newC = "dijitTooltipAB" + (corner.charAt(1) == 'L' ? "Left" : "Right")
  61. + " dijitTooltip"
  62. + (corner.charAt(0) == 'T' ? "Below" : "Above");
  63. dojo.replaceClass(this.domNode, newC, this._currentOrientClass || "");
  64. this._currentOrientClass = newC;
  65. },
  66. focus: function(){
  67. // summary:
  68. // Focus on first field
  69. this._getFocusItems(this.containerNode);
  70. dijit.focus(this._firstFocusItem);
  71. },
  72. onOpen: function(/*Object*/ pos){
  73. // summary:
  74. // Called when dialog is displayed.
  75. // This is called from the dijit.popup code, and should not be called directly.
  76. // tags:
  77. // protected
  78. this.orient(this.domNode,pos.aroundCorner, pos.corner);
  79. this._onShow(); // lazy load trigger
  80. },
  81. onClose: function(){
  82. // summary:
  83. // Called when dialog is hidden.
  84. // This is called from the dijit.popup code, and should not be called directly.
  85. // tags:
  86. // protected
  87. this.onHide();
  88. },
  89. _onKey: function(/*Event*/ evt){
  90. // summary:
  91. // Handler for keyboard events
  92. // description:
  93. // Keep keyboard focus in dialog; close dialog on escape key
  94. // tags:
  95. // private
  96. var node = evt.target;
  97. var dk = dojo.keys;
  98. if(evt.charOrCode === dk.TAB){
  99. this._getFocusItems(this.containerNode);
  100. }
  101. var singleFocusItem = (this._firstFocusItem == this._lastFocusItem);
  102. if(evt.charOrCode == dk.ESCAPE){
  103. // Use setTimeout to avoid crash on IE, see #10396.
  104. setTimeout(dojo.hitch(this, "onCancel"), 0);
  105. dojo.stopEvent(evt);
  106. }else if(node == this._firstFocusItem && evt.shiftKey && evt.charOrCode === dk.TAB){
  107. if(!singleFocusItem){
  108. dijit.focus(this._lastFocusItem); // send focus to last item in dialog
  109. }
  110. dojo.stopEvent(evt);
  111. }else if(node == this._lastFocusItem && evt.charOrCode === dk.TAB && !evt.shiftKey){
  112. if(!singleFocusItem){
  113. dijit.focus(this._firstFocusItem); // send focus to first item in dialog
  114. }
  115. dojo.stopEvent(evt);
  116. }else if(evt.charOrCode === dk.TAB){
  117. // we want the browser's default tab handling to move focus
  118. // but we don't want the tab to propagate upwards
  119. evt.stopPropagation();
  120. }
  121. }
  122. }
  123. );
  124. }