Button.js 2.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677
  1. define("dojox/mobile/Button", [
  2. "dojo/_base/array",
  3. "dojo/_base/declare",
  4. "dojo/dom-class",
  5. "dojo/dom-construct",
  6. "dijit/_WidgetBase",
  7. "dijit/form/_ButtonMixin",
  8. "dijit/form/_FormWidgetMixin"
  9. ],
  10. function(array, declare, domClass, domConstruct, WidgetBase, ButtonMixin, FormWidgetMixin){
  11. /*=====
  12. WidgetBase = dijit._WidgetBase;
  13. FormWidgetMixin = dijit.form._FormWidgetMixin;
  14. ButtonMixin = dijit.form._ButtonMixin;
  15. =====*/
  16. return declare("dojox.mobile.Button", [WidgetBase, FormWidgetMixin, ButtonMixin], {
  17. // summary:
  18. // Non-templated BUTTON widget with a thin API wrapper for click events and setting the label
  19. //
  20. // description:
  21. // Buttons can display a label, an icon, or both.
  22. // A label should always be specified (through innerHTML) or the label
  23. // attribute. It can be hidden via showLabel=false.
  24. // example:
  25. // | <button dojoType="dijit.form.Button" onClick="...">Hello world</button>
  26. baseClass: "mblButton",
  27. // Override automatic assigning type --> node, it causes exception on IE.
  28. // Instead, type must be specified as this.type when the node is created, as part of the original DOM
  29. _setTypeAttr: null,
  30. // duration: Number
  31. // duration of selection, milliseconds or -1 for no post-click CSS styling
  32. duration: 1000,
  33. _onClick: function(e){
  34. var ret = this.inherited(arguments);
  35. if(ret && this.duration >= 0){ // if its not a button with a state, then emulate press styles
  36. var button = this.focusNode || this.domNode;
  37. var newStateClasses = (this.baseClass+' '+this["class"]).split(" ");
  38. newStateClasses = array.map(newStateClasses, function(c){ return c+"Selected"; });
  39. domClass.add(button, newStateClasses);
  40. setTimeout(function(){
  41. domClass.remove(button, newStateClasses);
  42. }, this.duration);
  43. }
  44. return ret;
  45. },
  46. isFocusable: function(){ return false; },
  47. buildRendering: function(){
  48. if(!this.srcNodeRef){
  49. this.srcNodeRef = domConstruct.create("button", {"type": this.type});
  50. }else if(this._cv){
  51. var n = this.srcNodeRef.firstChild;
  52. if(n && n.nodeType === 3){
  53. n.nodeValue = this._cv(n.nodeValue);
  54. }
  55. }
  56. this.inherited(arguments);
  57. this.focusNode = this.domNode;
  58. },
  59. postCreate: function(){
  60. this.inherited(arguments);
  61. this.connect(this.domNode, "onclick", "_onClick");
  62. },
  63. _setLabelAttr: function(/*String*/ content){
  64. this.inherited(arguments, [this._cv ? this._cv(content) : content]);
  65. }
  66. });
  67. });