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 | success | info | warning | danger | link ) default
14 * @cfg {String} size ( lg | sm | xs)
15 * @cfg {String} tag ( a | input | submit)
16 * @cfg {String} href empty or href
17 * @cfg {Boolean} disabled default false;
18 * @cfg {Boolean} isClose default false;
19 * @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)
20 * @cfg {String} badge text for badge
21 * @cfg {String} theme (default|glow)
22 * @cfg {Boolean} inverse dark themed version
23 * @cfg {Boolean} toggle is it a slidy toggle button
24 * @cfg {Boolean} pressed (true|false) default null - if the button ahs active state
25 * @cfg {String} ontext text for on slidy toggle state
26 * @cfg {String} offtext text for off slidy toggle state
27 * @cfg {Boolean} preventDefault default true (stop click event triggering the URL if it's a link.)
28 * @cfg {Boolean} removeClass remove the standard class..
29 * @cfg {String} target target for a href. (_self|_blank|_parent|_top| other)
33 * @param {Object} config The config object
37 Roo.bootstrap.Button = function(config){
38 Roo.bootstrap.Button.superclass.constructor.call(this, config);
39 this.weightClass = ["btn-default",
51 * When a butotn is pressed
52 * @param {Roo.bootstrap.Button} btn
53 * @param {Roo.EventObject} e
58 * After the button has been toggles
59 * @param {Roo.bootstrap.Button} btn
60 * @param {Roo.EventObject} e
61 * @param {boolean} pressed (also available as button.pressed)
67 Roo.extend(Roo.bootstrap.Button, Roo.bootstrap.Component, {
94 getAutoCreate : function(){
102 if (['a', 'button', 'input', 'submit'].indexOf(this.tag) < 0) {
103 throw "Invalid value for tag: " + this.tag + ". must be a, button, input or submit.";
108 cfg.html = '<span class="roo-button-text">' + (this.html || cfg.html) + '</span>';
110 if (this.toggle == true) {
113 cls: 'slider-frame roo-button',
118 'data-off-text':'OFF',
119 cls: 'slider-button',
125 if (['default', 'primary', 'success', 'info', 'warning', 'danger', 'link'].indexOf(this.weight) > -1) {
126 cfg.cls += ' '+this.weight;
135 cfg["aria-hidden"] = true;
137 cfg.html = "×";
143 if (this.theme==='default') {
144 cfg.cls = 'btn roo-button';
146 //if (this.parentType != 'Navbar') {
147 this.weight = this.weight.length ? this.weight : 'default';
149 if (['default', 'primary', 'success', 'info', 'warning', 'danger', 'link'].indexOf(this.weight) > -1) {
151 cfg.cls += ' btn-' + this.weight;
153 } else if (this.theme==='glow') {
156 cfg.cls = 'btn-glow roo-button';
158 if (['default', 'primary', 'success', 'info', 'warning', 'danger', 'link'].indexOf(this.weight) > -1) {
160 cfg.cls += ' ' + this.weight;
166 this.cls += ' inverse';
170 if (this.active || this.pressed === true) {
171 cfg.cls += ' active';
175 cfg.disabled = 'disabled';
179 Roo.log('changing to ul' );
181 this.glyphicon = 'caret';
184 cfg.cls += this.size.length ? (' btn-' + this.size) : '';
186 //gsRoo.log(this.parentType);
187 if (this.parentType === 'Navbar' && !this.parent().bar) {
188 Roo.log('changing to li?');
197 href : this.href || '#'
200 cfg.cn[0].html = this.html + ' <span class="caret"></span>';
201 cfg.cls += ' dropdown';
208 cfg.cls += this.parentType === 'Navbar' ? ' navbar-btn' : '';
210 if (this.glyphicon) {
211 cfg.html = ' ' + cfg.html;
216 cls: 'glyphicon glyphicon-' + this.glyphicon
226 // cfg.cls='btn roo-button';
230 var value = cfg.html;
235 cls: 'glyphicon glyphicon-' + this.glyphicon,
254 cfg.cls += ' dropdown';
255 cfg.html = typeof(cfg.html) != 'undefined' ? cfg.html + ' <span class="caret"></span>' : '<span class="caret"></span>';
258 if (cfg.tag !== 'a' && this.href !== '') {
259 throw "Tag must be a to set href.";
260 } else if (this.href.length > 0) {
261 cfg.href = this.href;
264 if(this.removeClass){
269 cfg.target = this.target;
274 initEvents: function() {
275 // Roo.log('init events?');
276 // Roo.log(this.el.dom);
279 if (typeof (this.menu) != 'undefined') {
280 this.menu.parentType = this.xtype;
281 this.menu.triggerEl = this.el;
282 this.addxtype(Roo.apply({}, this.menu));
286 if (this.el.hasClass('roo-button')) {
287 this.el.on('click', this.onClick, this);
289 this.el.select('.roo-button').on('click', this.onClick, this);
292 if(this.removeClass){
293 this.el.on('click', this.onClick, this);
296 this.el.enableDisplayMode();
299 onClick : function(e)
306 Roo.log('button on click ');
307 if(this.preventDefault){
311 if (this.pressed === true || this.pressed === false) {
312 this.pressed = !this.pressed;
313 this.el[this.pressed ? 'addClass' : 'removeClass']('active');
314 this.fireEvent('toggle', this, e, this.pressed);
318 this.fireEvent('click', this, e);
322 * Enables this button
326 this.disabled = false;
327 this.el.removeClass('disabled');
331 * Disable this button
335 this.disabled = true;
336 this.el.addClass('disabled');
339 * sets the active state on/off,
340 * @param {Boolean} state (optional) Force a particular state
342 setActive : function(v) {
344 this.el[v ? 'addClass' : 'removeClass']('active');
348 * toggles the current active state
350 toggleActive : function()
352 var active = this.el.hasClass('active');
353 this.setActive(!active);
358 * get the current active state
359 * @return {boolean} true if it's active
361 isActive : function()
363 return this.el.hasClass('active');
366 * set the text of the first selected button
368 setText : function(str)
370 this.el.select('.roo-button-text',true).first().dom.innerHTML = str;
373 * get the text of the first selected button
377 return this.el.select('.roo-button-text',true).first().dom.innerHTML;
388 setWeight : function(str)
390 this.el.removeClass(this.weightClass);
391 this.el.addClass('btn-' + str);