diff options
author | Richard Beales <[email protected]> | 2013-03-18 07:32:01 +0000 |
---|---|---|
committer | Richard Beales <[email protected]> | 2013-03-18 07:32:01 +0000 |
commit | 7c97d17aaf373339a8bcd917ad59ca6018148f0d (patch) | |
tree | 5a3c04f0f9529be392c1263d3feb75806eb43797 /lib/dijit/form/_ButtonMixin.js.uncompressed.js | |
parent | 70db7424e7068701e60cc5bcdfe8f858be508179 (diff) | |
parent | c670a80ddd9b03bd4ea6d940a9ed682fd26248d7 (diff) |
Merge remote-tracking branch 'upstream/master'
Diffstat (limited to 'lib/dijit/form/_ButtonMixin.js.uncompressed.js')
-rw-r--r-- | lib/dijit/form/_ButtonMixin.js.uncompressed.js | 84 |
1 files changed, 84 insertions, 0 deletions
diff --git a/lib/dijit/form/_ButtonMixin.js.uncompressed.js b/lib/dijit/form/_ButtonMixin.js.uncompressed.js new file mode 100644 index 000000000..a38465804 --- /dev/null +++ b/lib/dijit/form/_ButtonMixin.js.uncompressed.js @@ -0,0 +1,84 @@ +define("dijit/form/_ButtonMixin", [ + "dojo/_base/declare", // declare + "dojo/dom", // dom.setSelectable + "dojo/_base/event", // event.stop + "../registry" // registry.byNode +], function(declare, dom, event, registry){ + +// module: +// dijit/form/_ButtonMixin + +return declare("dijit.form._ButtonMixin", 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 handle click actions + if(this.disabled){ + event.stop(e); + return false; + } + var preventDefault = this.onClick(e) === false; // user click actions + if(!preventDefault && this.type == "submit" && !(this.valueNode||this.focusNode).form){ // see if a non-form widget needs to be signalled + for(var node=this.domNode; node.parentNode; node=node.parentNode){ + var widget=registry.byNode(node); + if(widget && typeof widget._onSubmit == "function"){ + widget._onSubmit(e); + preventDefault = true; + break; + } + } + } + if(preventDefault){ + e.preventDefault(); + } + return !preventDefault; + }, + + 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); + (this.containerNode||this.focusNode).innerHTML = content; + } +}); + +}); |