X-Git-Url: http://git.roojs.org/?a=blobdiff_plain;f=Roo%2Fbootstrap%2FButton.js;h=feb0fdb1a5297811eece2ac34adcb2dc32a1235c;hb=00d29b20df5ed2be31bdfa9cb82a33963b96a0f0;hp=29beaf86a1fe5f9c6ac83c8631a6ac28283e49cd;hpb=55e8f1fdec206f0c77329f7f732abf48a13f5842;p=roojs1 diff --git a/Roo/bootstrap/Button.js b/Roo/bootstrap/Button.js index 29beaf86a1..feb0fdb1a5 100644 --- a/Roo/bootstrap/Button.js +++ b/Roo/bootstrap/Button.js @@ -10,23 +10,27 @@ * @extends Roo.bootstrap.Component * Bootstrap Button class * @cfg {String} html The button content - * @cfg {String} weight default (or empty) | primary | success | info | warning | danger | link - * @cfg {String} size empty | lg | sm | xs - * @cfg {String} tag empty | a | input | submit + * @cfg {String} weight (default|primary|secondary|success|info|warning|danger|link|light|dark) default + * @cfg {String} badge_weight (default|primary|secondary|success|info|warning|danger|link|light|dark) default (same as button) + * @cfg {Boolean} outline default false (except for weight=default which emulates old behaveiour with an outline) + * @cfg {String} size (lg|sm|xs) + * @cfg {String} tag (a|input|submit) * @cfg {String} href empty or href - * @cfg {Boolean} disabled false | true - * @cfg {Boolean} isClose false | true - * @cfg {String} glyphicon empty | 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 + * @cfg {Boolean} disabled default false; + * @cfg {Boolean} isClose default false; + * @cfg {String} glyphicon depricated - use fa + * @cfg {String} fa fontawesome icon - eg. 'comment' - without the fa/fas etc.. * @cfg {String} badge text for badge - * @cfg {String} theme default (or empty) | glow - * @cfg {Boolean} inverse false | true - * @cfg {Boolean} toggle false | true - * @cfg {String} ontext text for on toggle state - * @cfg {String} offtext text for off toggle state - * @cfg {Boolean} defaulton true | false - * @cfg {Boolean} preventDefault (true | false) default true - * @cfg {Boolean} removeClass true | false remove the standard class.. - * @cfg {String} target (_self|_blank|_parent|_top)target for a href. + * @cfg {String} theme (default|glow) + * @cfg {Boolean} inverse dark themed version + * @cfg {Boolean} toggle is it a slidy toggle button + * @cfg {Boolean} pressed  default null - if the button ahs active state + * @cfg {String} ontext text for on slidy toggle state + * @cfg {String} offtext text for off slidy toggle state + * @cfg {Boolean} preventDefault default true (stop click event triggering the URL if it's a link.) + * @cfg {Boolean} removeClass remove the standard class.. + * @cfg {String} target (_self|_blank|_parent|_top|other) target for a href. + * @cfg {Boolean} grpup if parent is a btn group - then it turns it into a toogleGroup. * * @constructor * Create a new button @@ -36,17 +40,27 @@ Roo.bootstrap.Button = function(config){ Roo.bootstrap.Button.superclass.constructor.call(this, config); + this.addEvents({ // raw events /** * @event click - * When a butotn is pressed + * When a button is pressed + * @param {Roo.bootstrap.Button} btn * @param {Roo.EventObject} e */ "click" : true, + /** + * @event dblclick + * When a button is double clicked + * @param {Roo.bootstrap.Button} btn + * @param {Roo.EventObject} e + */ + "dblclick" : true, /** * @event toggle * After the button has been toggles + * @param {Roo.bootstrap.Button} btn * @param {Roo.EventObject} e * @param {boolean} pressed (also available as button.pressed) */ @@ -58,12 +72,15 @@ Roo.extend(Roo.bootstrap.Button, Roo.bootstrap.Component, { html: false, active: false, weight: '', + badge_weight: '', + outline : false, size: '', tag: 'button', href: '', disabled: false, isClose: false, glyphicon: '', + fa: '', badge: '', theme: 'default', inverse: false, @@ -76,8 +93,8 @@ Roo.extend(Roo.bootstrap.Button, Roo.bootstrap.Component, { removeClass: false, name: false, target: false, - - + group : false, + pressed : null, @@ -111,9 +128,9 @@ Roo.extend(Roo.bootstrap.Button, Roo.bootstrap.Component, { } ] }; - - if (['default', 'primary', 'success', 'info', 'warning', 'danger', 'link'].indexOf(this.weight) > -1) { - cfg.cls += ' '+this.weight; + // why are we validating the weights? + if (Roo.bootstrap.Button.weights.indexOf(this.weight) > -1) { + cfg.cls += ' ' + this.weight; } return cfg; @@ -128,24 +145,30 @@ Roo.extend(Roo.bootstrap.Button, Roo.bootstrap.Component, { return cfg; } + - if (this.theme==='default') { cfg.cls = 'btn roo-button'; //if (this.parentType != 'Navbar') { this.weight = this.weight.length ? this.weight : 'default'; //} - if (['default', 'primary', 'success', 'info', 'warning', 'danger', 'link'].indexOf(this.weight) > -1) { + if (Roo.bootstrap.Button.weights.indexOf(this.weight) > -1) { - cfg.cls += ' btn-' + this.weight; + var outline = this.outline || this.weight == 'default' ? 'outline-' : ''; + var weight = this.weight == 'default' ? 'secondary' : this.weight; + cfg.cls += ' btn-' + outline + weight; + if (this.weight == 'default') { + // BC + cfg.cls += ' btn-' + this.weight; + } } } else if (this.theme==='glow') { cfg.tag = 'a'; cfg.cls = 'btn-glow roo-button'; - if (['default', 'primary', 'success', 'info', 'warning', 'danger', 'link'].indexOf(this.weight) > -1) { + if (Roo.bootstrap.Button.weights.indexOf(this.weight) > -1) { cfg.cls += ' ' + this.weight; } @@ -157,7 +180,7 @@ Roo.extend(Roo.bootstrap.Button, Roo.bootstrap.Component, { } - if (this.active) { + if (this.active || this.pressed === true) { cfg.cls += ' active'; } @@ -169,6 +192,10 @@ Roo.extend(Roo.bootstrap.Button, Roo.bootstrap.Component, { Roo.log('changing to ul' ); cfg.tag = 'ul'; this.glyphicon = 'caret'; + if (Roo.bootstrap.version == 4) { + this.fa = 'caret-down'; + } + } cfg.cls += this.size.length ? (' btn-' + this.size) : ''; @@ -207,6 +234,16 @@ Roo.extend(Roo.bootstrap.Button, Roo.bootstrap.Component, { } ]; } + if (this.fa) { + cfg.html = ' ' + cfg.html; + + cfg.cn = [ + { + tag: 'i', + cls: 'fa fas fa-' + this.fa + } + ]; + } if (this.badge) { cfg.html += ' '; @@ -221,18 +258,28 @@ Roo.extend(Roo.bootstrap.Button, Roo.bootstrap.Component, { if(this.glyphicon){ value = { - tag: 'span', - cls: 'glyphicon glyphicon-' + this.glyphicon, - html: this.html - }; - + tag: 'span', + cls: 'glyphicon glyphicon-' + this.glyphicon, + html: this.html + }; + } + if(this.fa){ + value = { + tag: 'i', + cls: 'fa fas fa-' + this.fa, + html: this.html + }; } + var bw = this.badge_weight.length ? this.badge_weight : + (this.weight.length ? this.weight : 'secondary'); + bw = bw == 'default' ? 'secondary' : bw; + cfg.cn = [ value, { tag: 'span', - cls: 'badge', + cls: 'badge badge-' + bw, html: this.badge } ]; @@ -242,7 +289,8 @@ Roo.extend(Roo.bootstrap.Button, Roo.bootstrap.Component, { if (this.menu) { cfg.cls += ' dropdown'; - cfg.html = typeof(cfg.html) != 'undefined' ? cfg.html + ' ' : ''; + cfg.html = typeof(cfg.html) != 'undefined' ? + cfg.html + ' ' : ''; } if (cfg.tag !== 'a' && this.href !== '') { @@ -273,17 +321,30 @@ Roo.extend(Roo.bootstrap.Button, Roo.bootstrap.Component, { } - if (this.el.hasClass('roo-button')) { + if (this.el.hasClass('roo-button')) { + this.el.on('click', this.onClick, this); + this.el.on('dblclick', this.onDblClick, this); + } else { + this.el.select('.roo-button').on('click', this.onClick, this); + this.el.select('.roo-button').on('dblclick', this.onDblClick, this); + + } + // why? + if(this.removeClass){ this.el.on('click', this.onClick, this); - } else { - this.el.select('.roo-button').on('click', this.onClick, this); - } - - if(this.removeClass){ - this.el.on('click', this.onClick, this); - } - - this.el.enableDisplayMode(); + } + + if (this.group === true) { + if (this.pressed === false || this.pressed === true) { + // nothing + } else { + this.pressed = false; + this.setActive(this.pressed); + } + + } + + this.el.enableDisplayMode(); }, onClick : function(e) @@ -296,16 +357,43 @@ Roo.extend(Roo.bootstrap.Button, Roo.bootstrap.Component, { if(this.preventDefault){ e.preventDefault(); } + + if (this.group) { + if (this.pressed) { + // do nothing - + return; + } + this.setActive(true); + var pi = this.parent().items; + for (var i = 0;i < pi.length;i++) { + if (this == pi[i]) { + continue; + } + if (pi[i].el.hasClass('roo-button')) { + pi[i].setActive(false); + } + } + this.fireEvent('click', this, e); + return; + } + if (this.pressed === true || this.pressed === false) { - this.pressed = !this.pressed; - this.el[this.pressed ? 'addClass' : 'removeClass']('active'); - this.fireEvent('toggle', this, e, this.pressed); + this.toggleActive(e); } this.fireEvent('click', this, e); }, - + onDblClick: function(e) + { + if (this.disabled) { + return; + } + if(this.preventDefault){ + e.preventDefault(); + } + this.fireEvent('dblclick', this, e); + }, /** * Enables this button */ @@ -313,6 +401,7 @@ Roo.extend(Roo.bootstrap.Button, Roo.bootstrap.Component, { { this.disabled = false; this.el.removeClass('disabled'); + this.el.dom.removeAttribute("disabled"); }, /** @@ -322,6 +411,7 @@ Roo.extend(Roo.bootstrap.Button, Roo.bootstrap.Component, { { this.disabled = true; this.el.addClass('disabled'); + this.el.attr("disabled", "disabled") }, /** * sets the active state on/off, @@ -330,36 +420,66 @@ Roo.extend(Roo.bootstrap.Button, Roo.bootstrap.Component, { setActive : function(v) { this.el[v ? 'addClass' : 'removeClass']('active'); + this.pressed = v; }, /** * toggles the current active state */ - toggleActive : function() + toggleActive : function(e) { - var active = this.el.hasClass('active'); - this.setActive(!active); - - + this.setActive(!this.pressed); // this modifies pressed... + this.fireEvent('toggle', this, e, this.pressed); + }, + /** + * get the current active state + * @return {boolean} true if it's active + */ + isActive : function() + { + return this.el.hasClass('active'); }, + /** + * set the text of the first selected button + */ setText : function(str) { this.el.select('.roo-button-text',true).first().dom.innerHTML = str; }, + /** + * get the text of the first selected button + */ getText : function() { return this.el.select('.roo-button-text',true).first().dom.innerHTML; }, - hide: function() { - - - this.el.hide(); - }, - show: function() { - - this.el.show(); + + setWeight : function(str) + { + this.el.removeClass(Roo.bootstrap.Button.weights.map(function(w) { return 'btn-' + w; } ) ); + this.el.removeClass(Roo.bootstrap.Button.weights.map(function(w) { return 'btn-outline-' + w; } ) ); + this.weight = str; + var outline = this.outline ? 'outline-' : ''; + if (str == 'default') { + this.el.addClass('btn-default btn-outline-secondary'); + return; + } + this.el.addClass('btn-' + outline + str); } }); +// fixme - this is probably generic bootstrap - should go in some kind of enum file.. - like sizes. - \ No newline at end of file +Roo.bootstrap.Button.weights = [ + 'default', + 'secondary' , + 'primary', + 'success', + 'info', + 'warning', + 'danger', + 'link', + 'light', + 'dark' + +]; \ No newline at end of file