Debian Codegraph @

dijit/form/_ButtonMixin.js

raw symbols SCIP
1 define([
2 "dojo/_base/declare", // declare
3 "dojo/dom", // dom.setSelectable
4 "dojo/has",
5 "../registry" // registry.byNode
6 ], function(declare, dom, has, registry){
7
8 // module:
9 // dijit/form/_ButtonMixin
10
11 var ButtonMixin = declare("dijit.form._ButtonMixin" + (has("dojo-bidi") ? "_NoBidi" : ""), 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 divert the real click onto the hidden INPUT that has a native default action associated with it
39 // type:
40 // private
41 e.stopPropagation();
42 e.preventDefault();
43 if(!this.disabled){
44 // cannot use on.emit since button default actions won't occur
45 this.valueNode.click(e);
46 }
47 return false;
48 },
49
50 _onClick: function(/*Event*/ e){
51 // summary:
52 // Internal function to handle click actions
53 if(this.disabled){
54 e.stopPropagation();
55 e.preventDefault();
56 return false;
57 }
58 if(this.onClick(e) === false){
59 e.preventDefault();
60 }
61 var cancelled = e.defaultPrevented;
62
63 // Signal Form/Dialog to submit/close. For 2.0, consider removing this code and instead making the Form/Dialog
64 // listen for bubbled click events where evt.target.type == "submit" && !evt.defaultPrevented.
65 if(!cancelled && this.type == "submit" && !(this.valueNode || this.focusNode).form){
66 for(var node = this.domNode; node.parentNode; node = node.parentNode){
67 var widget = registry.byNode(node);
68 if(widget && typeof widget._onSubmit == "function"){
69 widget._onSubmit(e);
70 e.preventDefault(); // action has already occurred
71 cancelled = true;
72 break;
73 }
74 }
75 }
76
77 return !cancelled;
78 },
79
80 postCreate: function(){
81 this.inherited(arguments);
82 dom.setSelectable(this.focusNode, false);
83 },
84
85 onClick: function(/*Event*/ /*===== e =====*/){
86 // summary:
87 // Callback for when button is clicked.
88 // If type="submit", return true to perform submit, or false to cancel it.
89 // type:
90 // callback
91 return true; // Boolean
92 },
93
94 _setLabelAttr: function(/*String*/ content){
95 // summary:
96 // Hook for set('label', ...) to work.
97 // description:
98 // Set the label (text) of the button; takes an HTML string.
99 this._set("label", content);
100 var labelNode = this.containerNode || this.focusNode;
101 labelNode.innerHTML = content;
102 this.onLabelSet();
103 },
104
105 onLabelSet: function(){
106 }
107 });
108
109 if(has("dojo-bidi")){
110 ButtonMixin = declare("dijit.form._ButtonMixin", ButtonMixin, {
111 onLabelSet: function(){
112 this.inherited(arguments);
113 var labelNode = this.containerNode || this.focusNode;
114 this.applyTextDir(labelNode);
115 }
116 });
117 }
118
119 return ButtonMixin;
120 });