/* * - LGPL * * base class for bootstrap elements. * */ Roo.bootstrap = Roo.bootstrap || {}; /** * @class Roo.bootstrap.Component * @extends Roo.Component * Bootstrap Component base class * @cfg {String} cls css class * @cfg {String} style any extra css * @cfg {Object} xattr extra attributes to add to 'element' (used by builder to store stuff.) * * @constructor * Do not use directly - it does not do anything.. * @param {Object} config The config object */ Roo.bootstrap.Component = function(config){ Roo.bootstrap.Component.superclass.constructor.call(this, config); }; Roo.extend(Roo.bootstrap.Component, Roo.BoxComponent, { allowDomMove : false, // to stop relocations in parent onRender... cls : false, style : false, autoCreate : false, initEvents : function() { }, xattr : false, parentId : false, parent: function() { // returns the parent component.. return Roo.ComponentMgr.get(this.parentId) }, // private onRender : function(ct, position) { // Roo.log("Call onRender: " + this.xtype); Roo.bootstrap.Component.superclass.onRender.call(this, ct, position); if(this.el){ if (this.el.attr('xtype')) { this.el.attr('xtypex', this.el.attr('xtype')); this.el.dom.removeAttribute('xtype'); this.initEvents(); } return; } var cfg = Roo.apply({}, this.getAutoCreate()); cfg.id = Roo.id(); // fill in the extra attributes if (this.xattr && typeof(this.xattr) =='object') { for (var i in this.xattr) { cfg[i] = this.xattr[i]; } } if (this.cls) { cfg.cls += ' ' + this.cls; } if (this.style) { // fixme needs to support more complex style data. cfg.style = this.style; } this.el = ct.createChild(cfg, position); if(this.tabIndex !== undefined){ this.el.dom.setAttribute('tabIndex', this.tabIndex); } this.initEvents(); }, getChildContainer : function() { return this.el; }, addxtype : function (tree, cntr) { var cn = this; cntr = typeof(cntr == 'undefined' ) ? 'getChildContainer' : cntr; // render the element if it's not BODY. if (tree.xtype != 'Body') { cn = Roo.factory(tree); // Roo.log(cn); cn.parentType = this.xtype; //?? cn.parentId = this.id; // does the container contain child eleemnts with 'xtype' attributes. // that match this xtype.. // note - when we render we create these as well.. // so we should check to see if body has xtype set. if (Roo.get(document.body).attr('xtype') == 'Roo.bootstrap.Body') { var echild = Roo.get(this[cntr]()).child('*[xtype]'); if (echild && echild.attr('xtype').split('.').pop() == cn.xtype) { // Roo.log("found child for " + this.xtype +": " + echild.attr('xtype') ); cn.el = echild; //echild.dom.removeAttribute('xtype'); } else { Roo.log("looking for " + cn.xtype); Roo.log("missing child for " + this.xtype); Roo.log(this.el); Roo.log(cntr); Roo.log(cn); Roo.log(this); } } cn.render(this[cntr]()); // then add the element.. } // handle the kids.. var nitems = []; if (typeof (tree.menu) != 'undefined') { tree.menu.parentType = cn.xtype; tree.menu.triggerEl = cn.el; nitems.push(cn.addxtype(Roo.apply({}, tree.menu))); } if (!tree.items || !tree.items.length) { cn.items = nitems; return cn; } var items = tree.items; delete tree.items; //Roo.log(items.length); // add the items.. for(var i =0;i < items.length;i++) { nitems.push(cn.addxtype(Roo.apply({}, items[i]))); } cn.items = nitems; return cn; } }); /* * - LGPL * * page container. * */ Roo.bootstrap.Body = function(config){ Roo.bootstrap.Body.superclass.constructor.call(this, config); this.el = Roo.get(document.body); }; Roo.extend(Roo.bootstrap.Body, Roo.bootstrap.Component, { autoCreate : { cls: 'container' }, onRender : function(ct, position){ //this.el.addClass([this.fieldClass, this.cls]); } }); /* * - LGPL * * button group * */ /** * @class Roo.bootstrap.ButtonGroup * @extends Roo.bootstrap.Component * Bootstrap ButtonGroup class * @cfg {String} size lg | sm | xs (default empty normal) * @cfg {String} align vertical | justified (default none) * @cfg {String} direction up | down (default down) * @cfg {Boolean} toolbar false | true * @cfg {Boolean} btn true | false * * * @constructor * Create a new Input * @param {Object} config The config object */ Roo.bootstrap.ButtonGroup = function(config){ Roo.bootstrap.ButtonGroup.superclass.constructor.call(this, config); }; Roo.extend(Roo.bootstrap.ButtonGroup, Roo.bootstrap.Component, { size: '', align: '', direction: '', toolbar: false, btn: true, getAutoCreate : function(){ var cfg = { cls: 'btn-group', html : null } cfg.html = this.html || cfg.html; if (this.toolbar) { cfg = { cls: 'btn-toolbar', html: null } return cfg; } if (['vertical','justified'].indexOf(this.align)!==-1) { cfg.cls = 'btn-group-' + this.align; if (this.align == 'justified') { console.log(this.items); } } if (['lg','sm','xs'].indexOf(this.size)!==-1) { cfg.cls += ' btn-group-' + this.size; } if (this.direction == 'up') { cfg.cls += ' dropup' ; } return cfg; } }); /* * - LGPL * * button * */ /** * @class Roo.bootstrap.Button * @extends Roo.bootstrap.Component * Bootstrap Button class * @cfg {String} html The button content * @cfg {String} weight default (or empty) | primary | success | info | warning | danger * @cfg {String} size empty | lg | sm | xs * @cfg {String} tag empty | 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 {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 * * @constructor * Create a new button * @param {Object} config The config object */ Roo.bootstrap.Button = function(config){ Roo.bootstrap.Button.superclass.constructor.call(this, config); this.addEvents({ // raw events /** * @event click * The raw click event for the entire grid. * @param {Roo.EventObject} e */ "click" : true }); }; Roo.extend(Roo.bootstrap.Button, Roo.bootstrap.Component, { html: false, active: false, weight: '', size: '', tag: 'button', href: '', disabled: false, isClose: false, glyphicon: '', badge: '', theme: 'default', inverse: false, toggle: false, ontext: 'ON', offtext: 'OFF', defaulton: true, getAutoCreate : function(){ var cfg = { tag : 'button', cls : 'roo-button', html: 'hello' }; if (['a', 'button', 'input', 'submit'].indexOf(this.tag) < 0) { throw "Invalid value for tag: " + this.tag + ". must be a, button, input or submit."; this.tag = 'button'; } else { cfg.tag = this.tag; } cfg.html = this.html || cfg.html; if (this.toggle===true) { cfg={ tag: 'div', cls: 'slider-frame roo-button', cn: [ { tag: 'span', 'data-on-text':'ON', 'data-off-text':'OFF', cls: 'slider-button', html: this.offtext } ] }; if (['default', 'primary', 'success', 'info', 'warning', 'danger', 'link'].indexOf(this.weight) > -1) { cfg.cls += ' '+this.weight; } return cfg; } if (this.isClose) { cfg.cls += ' close'; cfg["aria-hidden"] = true; cfg.html = "×"; 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) { 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) { cfg.cls += ' ' + this.weight; } } if (this.inverse) { this.cls += ' inverse'; } if (this.active) { cfg.cls += ' active'; } cfg.cls += this.size.length ? (' btn-' + this.size) : ''; //gsRoo.log(this.parentType); if (this.parentType === 'Navbar') { cfg.tag = 'li'; cfg.cls = ''; cfg.cn = [{ tag : 'a', cls : 'roo-button', html : this.html, href : this.href || '#' }]; if (this.menu) { cfg.cn[0].html = this.html + ' '; cfg.cls += ' dropdown'; } delete cfg.html; } else if (this.menu) { cfg.tag = 'a'; cfg.cls += ' dropdown test'; } if (this.disabled) { cfg.disabled = 'disabled'; } //???? if (this.items) { Roo.log('changing to ul' ); cfg.tag = 'ul'; this.glyphicon = 'caret'; } if (this.glyphicon) { cfg.html = ' ' + cfg.html; cfg.cn = [ { tag: 'span', cls: 'glyphicon glyphicon-' + this.glyphicon } ]; } if (this.badge) { cfg.html += ' '; cfg.tag = 'a'; cfg.cls='btn roo-button'; cfg.href=this.href; cfg.cn = [ cfg.html, { tag: 'span', cls: 'badge', html: this.badge } ]; cfg.html=''; } if (cfg.tag !== 'a' && this.href !== '') { throw "Tag must be a to set href."; } else if (this.href.length > 0) { cfg.href = this.href; } return cfg; }, initEvents: function() { // Roo.log('init events?'); // Roo.log(this.el.dom); if (this.el.hasClass('roo-button')) { this.el.on('click', this.onClick, this); } else { this.el.select('.roo-button').on('click', this.onClick, this); } }, onClick : function(e) { Roo.log('button on click '); e.preventDefault(); this.fireEvent('click', this, e); } }); /* * - LGPL * * column * */ /** * @class Roo.bootstrap.Column * @extends Roo.bootstrap.Component * Bootstrap Column class * @cfg {Number} xs colspan out of 12 for mobile-sized screens * @cfg {Number} sm colspan out of 12 for tablet-sized screens * @cfg {Number} md colspan out of 12 for computer-sized screens * @cfg {Number} lg colspan out of 12 for large computer-sized screens * @cfg {String} html content of column. * * @constructor * Create a new Column * @param {Object} config The config object */ Roo.bootstrap.Column = function(config){ Roo.bootstrap.Column.superclass.constructor.call(this, config); }; Roo.extend(Roo.bootstrap.Column, Roo.bootstrap.Component, { xs: null, sm: null, md: null, lg: null, html: '', offset: 0, getAutoCreate : function(){ var cfg = Roo.apply({}, Roo.bootstrap.Column.superclass.getAutoCreate.call(this)); cfg = { tag: 'div', cls: 'column' }; var settings=this; ['xs','sm','md','lg'].map(function(size){ if (settings[size]) { cfg.cls += ' col-' + size + '-' + settings[size]; } }); if (this.html.length) { cfg.html = this.html; } return cfg; } }); /* * - LGPL * * page container. * */ /** * @class Roo.bootstrap.Container * @extends Roo.bootstrap.Component * Bootstrap Container class * @cfg {Boolean} jumbotron is it a jumbotron element * @cfg {String} html content of element * @cfg {String} well (lg|sm|md) a well, large, small or medium. * @cfg {String} panel (primary|success|info|warning|danger) render as a panel. * @cfg {String} header content of header (for panel) * @cfg {String} footer content of footer (for panel) * @cfg {String} sticky (footer|wrap|push) block to use as footer or body- needs css-bootstrap/sticky-footer.css * * @constructor * Create a new Container * @param {Object} config The config object */ Roo.bootstrap.Container = function(config){ Roo.bootstrap.Container.superclass.constructor.call(this, config); }; Roo.extend(Roo.bootstrap.Container, Roo.bootstrap.Component, { jumbotron : false, well: '', panel : '', header: '', footer : '', sticky: '', getChildContainer : function() { if (this.panel.length) { return this.el.select('.panel-body',true).first(); } return this.el; }, getAutoCreate : function(){ var cfg = { html : '', cls : '' }; if (this.jumbotron) { cfg.cls = 'jumbotron'; } if (this.cls) { cfg.cls = this.cls + ''; } if (this.sticky.length) { var bd = Roo.get(document.body); if (!bd.hasClass('bootstrap-sticky')) { bd.addClass('bootstrap-sticky'); Roo.select('html',true).setStyle('height', '100%'); } cfg.cls += 'bootstrap-sticky-' + this.sticky; } if (this.well.length) { switch (this.well) { case 'lg': case 'sm': cfg.cls +=' well well-' +this.well; break; default: cfg.cls +=' well'; break; } } var body = cfg; if (this.panel.length) { cfg.cls += 'panel panel-' + this.panel; cfg.cn = []; if (this.header.length) { cfg.cn.push({ cls : 'panel-heading', cn : [{ tag: 'h3', cls : 'panel-title', html : this.header }] }); } body = false; cfg.cn.push({ cls : 'panel-body', html : this.html }); if (this.footer.length) { cfg.cn.push({ cls : 'panel-footer', html : this.footer }); } } if (body) { body.html = this.html || cfg.html; } if (!cfg.cls.length) { cfg.cls = 'container'; } return cfg; } }); /* * - LGPL * * image * */ /** * @class Roo.bootstrap.Img * @extends Roo.bootstrap.Component * Bootstrap Img class * @cfg {Boolean} imgResponsive false | true * @cfg {String} border rounded | circle | thumbnail * @cfg {String} src image source * @cfg {String} alt image alternative text * * @constructor * Create a new Input * @param {Object} config The config object */ Roo.bootstrap.Img = function(config){ Roo.bootstrap.Img.superclass.constructor.call(this, config); }; Roo.extend(Roo.bootstrap.Img, Roo.bootstrap.Component, { imgResponsive: true, border: '', src: '', getAutoCreate : function(){ cfg = { tag: 'img', cls: 'img-responsive', html : null } cfg.html = this.html || cfg.html; cfg.src = this.src || cfg.src; if (['rounded','circle','thumbnail'].indexOf(this.border)>-1) { cfg.cls += ' img-' + this.border; } if(this.alt){ cfg.alt = this.alt; } return cfg; } }); /* * - LGPL * * header * */ /** * @class Roo.bootstrap.Header * @extends Roo.bootstrap.Component * Bootstrap Header class * @cfg {String} html content of header * @cfg {Number} level (1|2|3|4|5|6) default 1 * * @constructor * Create a new Header * @param {Object} config The config object */ Roo.bootstrap.Header = function(config){ Roo.bootstrap.Header.superclass.constructor.call(this, config); }; Roo.extend(Roo.bootstrap.Header, Roo.bootstrap.Component, { //href : false, html : false, level : 1, getAutoCreate : function(){ var cfg = { tag: 'h' + (1 *this.level), html: this.html || 'fill in html' } ; return cfg; } }); /* * - LGPL * * menu * */ /** * @class Roo.bootstrap.Menu * @extends Roo.bootstrap.Component * Bootstrap Menu class - container for MenuItems * @cfg {String} type type of menu * * @constructor * Create a new Menu * @param {Object} config The config object */ Roo.bootstrap.Menu = function(config){ Roo.bootstrap.Menu.superclass.constructor.call(this, config); }; Roo.extend(Roo.bootstrap.Menu, Roo.bootstrap.Component, { /// html : false, //align : '', triggerEl : false, type: false, getChildContainer : function() { return this.el; }, getAutoCreate : function(){ //if (['right'].indexOf(this.align)!==-1) { // cfg.cn[1].cls += ' pull-right' //} var cfg = { tag : 'ul', cls : 'dropdown-menu' } if (this.type==='submenu') { cfg.cls='submenu active' } return cfg; }, initEvents : function() { // Roo.log("ADD event"); // Roo.log(this.triggerEl.dom); this.triggerEl.on('click', this.toggle, this); this.triggerEl.addClass('dropdown-toggle'); }, toggle : function(e) { //Roo.log(e.getTarget()); // Roo.log(this.triggerEl.dom); if (Roo.get(e.getTarget()).findParent('.dropdown-menu')) { return; } var isActive = this.triggerEl.hasClass('open'); // if disabled.. ingore this.clearMenus(e); //if ('ontouchstart' in document.documentElement && !$parent.closest('.navbar-nav').length) { // if mobile we use a backdrop because click events don't delegate // $('