]> git.wh0rd.org - tt-rss.git/blob - lib/dijit/form/_ButtonMixin.js.uncompressed.js
upgrade dojo to 1.8.3 (refs #570)
[tt-rss.git] / lib / dijit / form / _ButtonMixin.js.uncompressed.js
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
11 return declare("dijit.form._ButtonMixin", null, {
12 // summary:
13 // A mixin to add a thin standard API wrapper to a normal HTML button
14 // description:
15 // A label should always be specified (through innerHTML) or the label attribute.
16 //
17 // Attach points:
18 //
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 // example:
25 // | var button1 = new Button({label: "hello world", onClick: foo});
26 // | dojo.body().appendChild(button1.domNode);
27
28 // label: HTML String
29 // Content to display in button.
30 label: "",
31
32 // type: [const] String
33 // Type of button (submit, reset, button, checkbox, radio)
34 type: "button",
35
36 _onClick: function(/*Event*/ e){
37 // summary:
38 // Internal function to handle click actions
39 if(this.disabled){
40 event.stop(e);
41 return false;
42 }
43 var preventDefault = this.onClick(e) === false; // user click actions
44 if(!preventDefault && this.type == "submit" && !(this.valueNode||this.focusNode).form){ // see if a non-form widget needs to be signalled
45 for(var node=this.domNode; node.parentNode; node=node.parentNode){
46 var widget=registry.byNode(node);
47 if(widget && typeof widget._onSubmit == "function"){
48 widget._onSubmit(e);
49 preventDefault = true;
50 break;
51 }
52 }
53 }
54 if(preventDefault){
55 e.preventDefault();
56 }
57 return !preventDefault;
58 },
59
60 postCreate: function(){
61 this.inherited(arguments);
62 dom.setSelectable(this.focusNode, false);
63 },
64
65 onClick: function(/*Event*/ /*===== e =====*/){
66 // summary:
67 // Callback for when button is clicked.
68 // If type="submit", return true to perform submit, or false to cancel it.
69 // type:
70 // callback
71 return true; // Boolean
72 },
73
74 _setLabelAttr: function(/*String*/ content){
75 // summary:
76 // Hook for set('label', ...) to work.
77 // description:
78 // Set the label (text) of the button; takes an HTML string.
79 this._set("label", content);
80 (this.containerNode||this.focusNode).innerHTML = content;
81 }
82 });
83
84 });