]>
Commit | Line | Data |
---|---|---|
1354d172 AD |
1 | define("dijit/form/_ButtonMixin", [ |
2 | "dojo/_base/declare", // declare | |
3 | "dojo/dom", // dom.setSelectable | |
4 | "dojo/_base/event", // event.stop | |
5 | "../registry" // registry.byNode | |
6 | ], function(declare, dom, event, registry){ | |
7 | ||
8 | // module: | |
9 | // dijit/form/_ButtonMixin | |
10 | // summary: | |
11 | // A mixin to add a thin standard API wrapper to a normal HTML button | |
12 | ||
13 | return declare("dijit.form._ButtonMixin", null, { | |
14 | // summary: | |
15 | // A mixin to add a thin standard API wrapper to a normal HTML button | |
16 | // description: | |
17 | // A label should always be specified (through innerHTML) or the label attribute. | |
18 | // Attach points: | |
19 | // focusNode (required): this node receives focus | |
20 | // valueNode (optional): this node's value gets submitted with FORM elements | |
21 | // containerNode (optional): this node gets the innerHTML assignment for label | |
22 | // example: | |
23 | // | <button data-dojo-type="dijit.form.Button" onClick="...">Hello world</button> | |
24 | // | |
25 | // example: | |
26 | // | var button1 = new dijit.form.Button({label: "hello world", onClick: foo}); | |
27 | // | dojo.body().appendChild(button1.domNode); | |
28 | ||
29 | // label: HTML String | |
30 | // Content to display in button. | |
31 | label: "", | |
32 | ||
33 | // type: [const] String | |
34 | // Type of button (submit, reset, button, checkbox, radio) | |
35 | type: "button", | |
36 | ||
37 | _onClick: function(/*Event*/ e){ | |
38 | // summary: | |
39 | // Internal function to handle click actions | |
40 | if(this.disabled){ | |
41 | event.stop(e); | |
42 | return false; | |
43 | } | |
44 | var preventDefault = this.onClick(e) === false; // user click actions | |
45 | if(!preventDefault && this.type == "submit" && !(this.valueNode||this.focusNode).form){ // see if a non-form widget needs to be signalled | |
46 | for(var node=this.domNode; node.parentNode; node=node.parentNode){ | |
47 | var widget=registry.byNode(node); | |
48 | if(widget && typeof widget._onSubmit == "function"){ | |
49 | widget._onSubmit(e); | |
50 | preventDefault = true; | |
51 | break; | |
52 | } | |
53 | } | |
54 | } | |
55 | if(preventDefault){ | |
56 | e.preventDefault(); | |
57 | } | |
58 | return !preventDefault; | |
59 | }, | |
60 | ||
61 | postCreate: function(){ | |
62 | this.inherited(arguments); | |
63 | dom.setSelectable(this.focusNode, false); | |
64 | }, | |
65 | ||
66 | onClick: function(/*Event*/ /*===== e =====*/){ | |
67 | // summary: | |
68 | // Callback for when button is clicked. | |
69 | // If type="submit", return true to perform submit, or false to cancel it. | |
70 | // type: | |
71 | // callback | |
72 | return true; // Boolean | |
73 | }, | |
74 | ||
75 | _setLabelAttr: function(/*String*/ content){ | |
76 | // summary: | |
77 | // Hook for set('label', ...) to work. | |
78 | // description: | |
79 | // Set the label (text) of the button; takes an HTML string. | |
80 | this._set("label", content); | |
81 | (this.containerNode||this.focusNode).innerHTML = content; | |
82 | } | |
83 | }); | |
84 | ||
85 | }); |