yzt
2023-05-26 de4278af2fd46705a40bac58ec01122db6b7f3d7
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
define([
    "dojo/_base/declare", // declare
    "dojo/dom", // dom.setSelectable
    "dojo/has",
    "../registry"        // registry.byNode
], function(declare, dom, has, registry){
 
    // module:
    //      dijit/form/_ButtonMixin
 
    var ButtonMixin = declare("dijit.form._ButtonMixin" + (has("dojo-bidi") ? "_NoBidi" : ""), null, {
        // summary:
        //      A mixin to add a thin standard API wrapper to a normal HTML button
        // description:
        //      A label should always be specified (through innerHTML) or the label attribute.
        //
        //      Attach points:
        //
        //      - focusNode (required): this node receives focus
        //      - valueNode (optional): this node's value gets submitted with FORM elements
        //      - containerNode (optional): this node gets the innerHTML assignment for label
        // example:
        // |    <button data-dojo-type="dijit/form/Button" onClick="...">Hello world</button>
        // example:
        // |    var button1 = new Button({label: "hello world", onClick: foo});
        // |    dojo.body().appendChild(button1.domNode);
 
        // label: HTML String
        //      Content to display in button.
        label: "",
 
        // type: [const] String
        //      Type of button (submit, reset, button, checkbox, radio)
        type: "button",
 
        __onClick: function(/*Event*/ e){
            // summary:
            //      Internal function to divert the real click onto the hidden INPUT that has a native default action associated with it
            // type:
            //      private
            e.stopPropagation();
            e.preventDefault();
            if(!this.disabled){
                // cannot use on.emit since button default actions won't occur
                this.valueNode.click(e);
            }
            return false;
        },
 
        _onClick: function(/*Event*/ e){
            // summary:
            //      Internal function to handle click actions
            if(this.disabled){
                e.stopPropagation();
                e.preventDefault();
                return false;
            }
            if(this.onClick(e) === false){
                e.preventDefault();
            }
            var cancelled = e.defaultPrevented;
 
            // Signal Form/Dialog to submit/close.  For 2.0, consider removing this code and instead making the Form/Dialog
            // listen for bubbled click events where evt.target.type == "submit" && !evt.defaultPrevented.
            if(!cancelled && this.type == "submit" && !(this.valueNode || this.focusNode).form){
                for(var node = this.domNode; node.parentNode; node = node.parentNode){
                    var widget = registry.byNode(node);
                    if(widget && typeof widget._onSubmit == "function"){
                        widget._onSubmit(e);
                        e.preventDefault(); // action has already occurred
                        cancelled = true;
                        break;
                    }
                }
            }
 
            return !cancelled;
        },
 
        postCreate: function(){
            this.inherited(arguments);
            dom.setSelectable(this.focusNode, false);
        },
 
        onClick: function(/*Event*/ /*===== e =====*/){
            // summary:
            //      Callback for when button is clicked.
            //      If type="submit", return true to perform submit, or false to cancel it.
            // type:
            //      callback
            return true;        // Boolean
        },
 
        _setLabelAttr: function(/*String*/ content){
            // summary:
            //      Hook for set('label', ...) to work.
            // description:
            //      Set the label (text) of the button; takes an HTML string.
            this._set("label", content);
            var labelNode = this.containerNode || this.focusNode;
            labelNode.innerHTML = content;
        }
    });
 
    if(has("dojo-bidi")){
        ButtonMixin = declare("dijit.form._ButtonMixin", ButtonMixin, {
            _setLabelAttr: function(){
                this.inherited(arguments);
                var labelNode = this.containerNode || this.focusNode;
                this.applyTextDir(labelNode);
            }
        });
    }
 
    return ButtonMixin;
});