3 <div class="modal fade">
4 <div class="modal-dialog">
5 <div class="modal-content">
6 <div class="modal-header">
7 <button type="button" class="close" data-dismiss="modal" aria-hidden="true">×</button>
8 <h4 class="modal-title">Modal title</h4>
10 <div class="modal-body">
11 <p>One fine body…</p>
13 <div class="modal-footer">
14 <button type="button" class="btn btn-default" data-dismiss="modal">Close</button>
15 <button type="button" class="btn btn-primary">Save changes</button>
17 </div><!-- /.modal-content -->
18 </div><!-- /.modal-dialog -->
19 </div><!-- /.modal -->
29 * @class Roo.bootstrap.Modal
30 * @extends Roo.bootstrap.Component
31 * Bootstrap Modal class
32 * @cfg {String} title Title of dialog
33 * @cfg {Array} buttons Array of buttons or standard button set..
36 * Create a new Modal Dialog
37 * @param {Object} config The config object
40 Roo.bootstrap.Modal = function(config){
41 Roo.bootstrap.Modal.superclass.constructor.call(this, config);
46 * The raw btnclick event for the button
47 * @param {Roo.EventObject} e
51 this.buttons = this.buttons || [];
54 Roo.extend(Roo.bootstrap.Modal, Roo.bootstrap.Component, {
56 title : 'test dialog',
63 onRender : function(ct, position)
65 Roo.bootstrap.Component.superclass.onRender.call(this, ct, position);
68 var cfg = Roo.apply({}, this.getAutoCreate());
71 // cfg.name = typeof(this.name) == 'undefined' ? this.id : this.name;
73 //if (!cfg.name.length) {
77 cfg.cls += ' ' + this.cls;
80 cfg.style = this.style;
82 this.el = Roo.get(document.body).createChild(cfg, position);
84 //var type = this.el.dom.type;
86 if(this.tabIndex !== undefined){
87 this.el.dom.setAttribute('tabIndex', this.tabIndex);
92 this.maskEl = Roo.DomHelper.append(document.body, {tag: "div", cls:"x-dlg-mask"}, true);
93 this.maskEl.enableDisplayMode("block");
95 //this.el.addClass("x-dlg-modal");
97 if (this.buttons.legnth) {
98 Roo.each(this.buttons, function(bb) {
99 b = Roo.apply({}, bb);
100 b.xns = b.xns || Roo.bootstrap;
101 b.xtype = b.xtype || 'Button';
102 if (typeof(b.listeners) == 'undefined') {
103 b.listeners = { click : this.onButtonClick.createDelegate(this) };
106 var btn = Roo.factory(b);
108 btn.onRender(this.el.select('.modal-footer').first());
112 // render the children.
115 if(typeof(this.items) != 'undefined'){
116 var items = this.items;
119 for(var i =0;i < items.length;i++) {
120 nitems.push(this.addxtype(Roo.apply({}, items[i])));
126 this.body = this.el.select('.modal-body',true).first();
127 this.close = this.el.select('.modal-header .close', true).first();
130 //this.el.addClass([this.fieldClass, this.cls]);
133 getAutoCreate : function(){
138 html : this.html || ''
149 cls : "modal-content",
152 cls : 'modal-header',
185 getChildContainer : function() {
187 return this.el.select('.modal-body',true).first();
190 getButtonContainer : function() {
191 return this.el.select('.modal-footer',true).first();
194 initEvents : function()
196 this.el.select('.modal-header .close').on('click', this.hide, this);
198 // this.addxtype(this);
202 if (!this.rendered) {
206 this.el.addClass('on');
207 this.el.removeClass('fade');
208 this.el.setStyle('display', 'block');
209 Roo.get(document.body).addClass("x-body-masked");
210 this.maskEl.setSize(Roo.lib.Dom.getViewWidth(true), Roo.lib.Dom.getViewHeight(true));
212 this.el.setStyle('zIndex', '10001');
213 this.fireEvent('show', this);
219 Roo.log('Modal hide?!');
221 Roo.get(document.body).removeClass("x-body-masked");
222 this.el.removeClass('on');
223 this.el.addClass('fade');
224 this.el.setStyle('display', 'none');
225 this.fireEvent('hide', this);
228 addButton : function(str, cb)
232 var b = Roo.apply({}, { html : str } );
233 b.xns = b.xns || Roo.bootstrap;
234 b.xtype = b.xtype || 'Button';
235 if (typeof(b.listeners) == 'undefined') {
236 b.listeners = { click : cb.createDelegate(this) };
239 var btn = Roo.factory(b);
241 btn.onRender(this.el.select('.modal-footer').first());
247 setDefaultButton : function(btn)
252 onButtonClick: function(btn,e)
255 this.fireEvent('btnclick', btn.name, e);
257 setTitle: function(str) {
258 this.el.select('.modal-title',true).first().dom.innterHTML = str;
264 Roo.apply(Roo.bootstrap.Modal, {
266 * Button config that displays a single OK button
275 * Button config that displays Yes and No buttons
291 * Button config that displays OK and Cancel buttons
306 * Button config that displays Yes, No and Cancel buttons