9 * @class Roo.bootstrap.Button
10 * @extends Roo.bootstrap.Component
11 * Bootstrap Button class
12 * @cfg {String} html The button content
13 * @cfg {String} weight (default | primary | secondary | success | info | warning | danger | link ) default
14 * @cfg {String} badge_weight (default | primary | secondary | success | info | warning | danger | link ) default (same as button)
15 * @cfg {Boolean} outline default false (except for weight=default which emulates old behaveiour with an outline)
16 * @cfg {String} size ( lg | sm | xs)
17 * @cfg {String} tag ( a | input | submit)
18 * @cfg {String} href empty or href
19 * @cfg {Boolean} disabled default false;
20 * @cfg {Boolean} isClose default false;
21 * @cfg {String} glyphicon (| adjust | align-center | align-justify | align-left | align-right | arrow-down | arrow-left | arrow-right | arrow-up | asterisk | backward | ban-circle | barcode | bell | bold | book | bookmark | briefcase | bullhorn | calendar | camera | certificate | check | chevron-down | chevron-left | chevron-right | chevron-up | circle-arrow-down | circle-arrow-left | circle-arrow-right | circle-arrow-up | cloud | cloud-download | cloud-upload | cog | collapse-down | collapse-up | comment | compressed | copyright-mark | credit-card | cutlery | dashboard | download | download-alt | earphone | edit | eject | envelope | euro | exclamation-sign | expand | export | eye-close | eye-open | facetime-video | fast-backward | fast-forward | file | film | filter | fire | flag | flash | floppy-disk | floppy-open | floppy-remove | floppy-save | floppy-saved | folder-close | folder-open | font | forward | fullscreen | gbp | gift | glass | globe | hand-down | hand-left | hand-right | hand-up | hd-video | hdd | header | headphones | heart | heart-empty | home | import | inbox | indent-left | indent-right | info-sign | italic | leaf | link | list | list-alt | lock | log-in | log-out | magnet | map-marker | minus | minus-sign | move | music | new-window | off | ok | ok-circle | ok-sign | open | paperclip | pause | pencil | phone | phone-alt | picture | plane | play | play-circle | plus | plus-sign | print | pushpin | qrcode | question-sign | random | record | refresh | registration-mark | remove | remove-circle | remove-sign | repeat | resize-full | resize-horizontal | resize-small | resize-vertical | retweet | road | save | saved | screenshot | sd-video | search | send | share | share-alt | shopping-cart | signal | sort | sort-by-alphabet | sort-by-alphabet-alt | sort-by-attributes | sort-by-attributes-alt | sort-by-order | sort-by-order-alt | sound-5-1 | sound-6-1 | sound-7-1 | sound-dolby | sound-stereo | star | star-empty | stats | step-backward | step-forward | stop | subtitles | tag | tags | tasks | text-height | text-width | th | th-large | th-list | thumbs-down | thumbs-up | time | tint | tower | transfer | trash | tree-conifer | tree-deciduous | unchecked | upload | usd | user | volume-down | volume-off | volume-up | warning-sign | wrench | zoom-in | zoom-out)
22 * @cfg {String} badge text for badge
23 * @cfg {String} theme (default|glow)
24 * @cfg {Boolean} inverse dark themed version
25 * @cfg {Boolean} toggle is it a slidy toggle button
26 * @cfg {Boolean} pressed (true|false) default null - if the button ahs active state
27 * @cfg {String} ontext text for on slidy toggle state
28 * @cfg {String} offtext text for off slidy toggle state
29 * @cfg {Boolean} preventDefault default true (stop click event triggering the URL if it's a link.)
30 * @cfg {Boolean} removeClass remove the standard class..
31 * @cfg {String} target target for a href. (_self|_blank|_parent|_top| other)
35 * @param {Object} config The config object
39 Roo.bootstrap.Button = function(config){
40 Roo.bootstrap.Button.superclass.constructor.call(this, config);
41 this.weightClass = ["btn-default btn-outline-secondary",
53 * When a butotn is pressed
54 * @param {Roo.bootstrap.Button} btn
55 * @param {Roo.EventObject} e
60 * After the button has been toggles
61 * @param {Roo.bootstrap.Button} btn
62 * @param {Roo.EventObject} e
63 * @param {boolean} pressed (also available as button.pressed)
69 Roo.extend(Roo.bootstrap.Button, Roo.bootstrap.Component, {
97 getAutoCreate : function(){
105 if (['a', 'button', 'input', 'submit'].indexOf(this.tag) < 0) {
106 throw "Invalid value for tag: " + this.tag + ". must be a, button, input or submit.";
111 cfg.html = '<span class="roo-button-text">' + (this.html || cfg.html) + '</span>';
113 if (this.toggle == true) {
116 cls: 'slider-frame roo-button',
121 'data-off-text':'OFF',
122 cls: 'slider-button',
128 if (['default', 'secondary' , 'primary', 'success', 'info', 'warning', 'danger', 'link'].indexOf(this.weight) > -1) {
129 cfg.cls += ' '+this.weight;
138 cfg["aria-hidden"] = true;
140 cfg.html = "×";
146 if (this.theme==='default') {
147 cfg.cls = 'btn roo-button';
149 //if (this.parentType != 'Navbar') {
150 this.weight = this.weight.length ? this.weight : 'default';
152 if (['default', 'primary', 'secondary', 'success', 'info', 'warning', 'danger', 'link'].indexOf(this.weight) > -1) {
154 var outline = this.outline || this.weight == 'default' ? 'outline-' : '';
155 var weight = this.weight == 'default' ? 'secondary' : this.weight;
156 cfg.cls += ' btn-' + outline + weight;
157 if (this.weight == 'default') {
159 cfg.cls += ' btn-' + this.weight;
162 } else if (this.theme==='glow') {
165 cfg.cls = 'btn-glow roo-button';
167 if (['default', 'primary', 'success', 'info', 'warning', 'danger', 'link'].indexOf(this.weight) > -1) {
169 cfg.cls += ' ' + this.weight;
175 this.cls += ' inverse';
179 if (this.active || this.pressed === true) {
180 cfg.cls += ' active';
184 cfg.disabled = 'disabled';
188 Roo.log('changing to ul' );
190 this.glyphicon = 'caret';
193 cfg.cls += this.size.length ? (' btn-' + this.size) : '';
195 //gsRoo.log(this.parentType);
196 if (this.parentType === 'Navbar' && !this.parent().bar) {
197 Roo.log('changing to li?');
206 href : this.href || '#'
209 cfg.cn[0].html = this.html + ' <span class="caret"></span>';
210 cfg.cls += ' dropdown';
217 cfg.cls += this.parentType === 'Navbar' ? ' navbar-btn' : '';
219 if (this.glyphicon) {
220 cfg.html = ' ' + cfg.html;
225 cls: 'glyphicon glyphicon-' + this.glyphicon
235 // cfg.cls='btn roo-button';
239 var value = cfg.html;
244 cls: 'glyphicon glyphicon-' + this.glyphicon,
249 var bw = this.badge_weight.length ? this.badge_weight :
250 (this.weight.length ? this.weight : 'secondary');
251 bw = bw == 'default' ? 'secondary' : bw;
257 cls: 'badge badge-' + bw,
266 cfg.cls += ' dropdown';
267 cfg.html = typeof(cfg.html) != 'undefined' ?
268 cfg.html + ' <span class="caret"></span>' : '<span class="caret"></span>';
271 if (cfg.tag !== 'a' && this.href !== '') {
272 throw "Tag must be a to set href.";
273 } else if (this.href.length > 0) {
274 cfg.href = this.href;
277 if(this.removeClass){
282 cfg.target = this.target;
287 initEvents: function() {
288 // Roo.log('init events?');
289 // Roo.log(this.el.dom);
292 if (typeof (this.menu) != 'undefined') {
293 this.menu.parentType = this.xtype;
294 this.menu.triggerEl = this.el;
295 this.addxtype(Roo.apply({}, this.menu));
299 if (this.el.hasClass('roo-button')) {
300 this.el.on('click', this.onClick, this);
302 this.el.select('.roo-button').on('click', this.onClick, this);
305 if(this.removeClass){
306 this.el.on('click', this.onClick, this);
309 this.el.enableDisplayMode();
312 onClick : function(e)
318 Roo.log('button on click ');
319 if(this.preventDefault){
323 if (this.pressed === true || this.pressed === false) {
324 this.toggleActive(e);
328 this.fireEvent('click', this, e);
332 * Enables this button
336 this.disabled = false;
337 this.el.removeClass('disabled');
341 * Disable this button
345 this.disabled = true;
346 this.el.addClass('disabled');
349 * sets the active state on/off,
350 * @param {Boolean} state (optional) Force a particular state
352 setActive : function(v) {
354 this.el[v ? 'addClass' : 'removeClass']('active');
358 * toggles the current active state
360 toggleActive : function(e)
362 this.setActive(!this.pressed);
363 this.fireEvent('toggle', this, e, !this.pressed);
366 * get the current active state
367 * @return {boolean} true if it's active
369 isActive : function()
371 return this.el.hasClass('active');
374 * set the text of the first selected button
376 setText : function(str)
378 this.el.select('.roo-button-text',true).first().dom.innerHTML = str;
381 * get the text of the first selected button
385 return this.el.select('.roo-button-text',true).first().dom.innerHTML;
388 setWeight : function(str)
390 this.el.removeClass(this.weightClass);
392 var outline = this.outline ? 'outline-' : '';
393 if (str == 'default') {
394 this.el.addClass('btn-default btn-outline-secondary');
397 this.el.addClass('btn-' + outline + str);