Button.js 4.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126
  1. require({cache:{
  2. 'url:dijit/form/templates/Button.html':"<span class=\"dijit dijitReset dijitInline\" role=\"presentation\"\n\t><span class=\"dijitReset dijitInline dijitButtonNode\"\n\t\tdata-dojo-attach-event=\"ondijitclick:_onClick\" role=\"presentation\"\n\t\t><span class=\"dijitReset dijitStretch dijitButtonContents\"\n\t\t\tdata-dojo-attach-point=\"titleNode,focusNode\"\n\t\t\trole=\"button\" aria-labelledby=\"${id}_label\"\n\t\t\t><span class=\"dijitReset dijitInline dijitIcon\" data-dojo-attach-point=\"iconNode\"></span\n\t\t\t><span class=\"dijitReset dijitToggleButtonIconChar\">&#x25CF;</span\n\t\t\t><span class=\"dijitReset dijitInline dijitButtonText\"\n\t\t\t\tid=\"${id}_label\"\n\t\t\t\tdata-dojo-attach-point=\"containerNode\"\n\t\t\t></span\n\t\t></span\n\t></span\n\t><input ${!nameAttrSetting} type=\"${type}\" value=\"${value}\" class=\"dijitOffScreen\"\n\t\ttabIndex=\"-1\" role=\"presentation\" data-dojo-attach-point=\"valueNode\"\n/></span>\n"}});
  3. define("dijit/form/Button", [
  4. "require",
  5. "dojo/_base/declare", // declare
  6. "dojo/dom-class", // domClass.toggle
  7. "dojo/_base/kernel", // kernel.deprecated
  8. "dojo/_base/lang", // lang.trim
  9. "dojo/ready",
  10. "./_FormWidget",
  11. "./_ButtonMixin",
  12. "dojo/text!./templates/Button.html"
  13. ], function(require, declare, domClass, kernel, lang, ready, _FormWidget, _ButtonMixin, template){
  14. /*=====
  15. var _FormWidget = dijit.form._FormWidget;
  16. var _ButtonMixin = dijit.form._ButtonMixin;
  17. =====*/
  18. // module:
  19. // dijit/form/Button
  20. // summary:
  21. // Button widget
  22. // Back compat w/1.6, remove for 2.0
  23. if(!kernel.isAsync){
  24. ready(0, function(){
  25. var requires = ["dijit/form/DropDownButton", "dijit/form/ComboButton", "dijit/form/ToggleButton"];
  26. require(requires); // use indirection so modules not rolled into a build
  27. });
  28. }
  29. return declare("dijit.form.Button", [_FormWidget, _ButtonMixin], {
  30. // summary:
  31. // Basically the same thing as a normal HTML button, but with special styling.
  32. // description:
  33. // Buttons can display a label, an icon, or both.
  34. // A label should always be specified (through innerHTML) or the label
  35. // attribute. It can be hidden via showLabel=false.
  36. // example:
  37. // | <button data-dojo-type="dijit.form.Button" onClick="...">Hello world</button>
  38. //
  39. // example:
  40. // | var button1 = new dijit.form.Button({label: "hello world", onClick: foo});
  41. // | dojo.body().appendChild(button1.domNode);
  42. // showLabel: Boolean
  43. // Set this to true to hide the label text and display only the icon.
  44. // (If showLabel=false then iconClass must be specified.)
  45. // Especially useful for toolbars.
  46. // If showLabel=true, the label will become the title (a.k.a. tooltip/hint) of the icon.
  47. //
  48. // The exception case is for computers in high-contrast mode, where the label
  49. // will still be displayed, since the icon doesn't appear.
  50. showLabel: true,
  51. // iconClass: String
  52. // Class to apply to DOMNode in button to make it display an icon
  53. iconClass: "dijitNoIcon",
  54. _setIconClassAttr: { node: "iconNode", type: "class" },
  55. baseClass: "dijitButton",
  56. templateString: template,
  57. // Map widget attributes to DOMNode attributes.
  58. _setValueAttr: "valueNode",
  59. _onClick: function(/*Event*/ e){
  60. // summary:
  61. // Internal function to handle click actions
  62. var ok = this.inherited(arguments);
  63. if(ok){
  64. if(this.valueNode){
  65. this.valueNode.click();
  66. e.preventDefault(); // cancel BUTTON click and continue with hidden INPUT click
  67. // leave ok = true so that subclasses can do what they need to do
  68. }
  69. }
  70. return ok;
  71. },
  72. _fillContent: function(/*DomNode*/ source){
  73. // Overrides _Templated._fillContent().
  74. // If button label is specified as srcNodeRef.innerHTML rather than
  75. // this.params.label, handle it here.
  76. // TODO: remove the method in 2.0, parser will do it all for me
  77. if(source && (!this.params || !("label" in this.params))){
  78. var sourceLabel = lang.trim(source.innerHTML);
  79. if(sourceLabel){
  80. this.label = sourceLabel; // _applyAttributes will be called after buildRendering completes to update the DOM
  81. }
  82. }
  83. },
  84. _setShowLabelAttr: function(val){
  85. if(this.containerNode){
  86. domClass.toggle(this.containerNode, "dijitDisplayNone", !val);
  87. }
  88. this._set("showLabel", val);
  89. },
  90. setLabel: function(/*String*/ content){
  91. // summary:
  92. // Deprecated. Use set('label', ...) instead.
  93. kernel.deprecated("dijit.form.Button.setLabel() is deprecated. Use set('label', ...) instead.", "", "2.0");
  94. this.set("label", content);
  95. },
  96. _setLabelAttr: function(/*String*/ content){
  97. // summary:
  98. // Hook for set('label', ...) to work.
  99. // description:
  100. // Set the label (text) of the button; takes an HTML string.
  101. // If the label is hidden (showLabel=false) then and no title has
  102. // been specified, then label is also set as title attribute of icon.
  103. this.inherited(arguments);
  104. if(!this.showLabel && !("title" in this.params)){
  105. this.titleNode.title = lang.trim(this.containerNode.innerText || this.containerNode.textContent || '');
  106. }
  107. }
  108. });
  109. });