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 {Boolean} specificTitle (true|false) default false
34 * @cfg {Array} buttons Array of buttons or standard button set..
37 * Create a new Modal Dialog
38 * @param {Object} config The config object
41 Roo.bootstrap.Modal = function(config){
42 Roo.bootstrap.Modal.superclass.constructor.call(this, config);
47 * The raw btnclick event for the button
48 * @param {Roo.EventObject} e
52 this.buttons = this.buttons || [];
55 Roo.extend(Roo.bootstrap.Modal, Roo.bootstrap.Component, {
57 title : 'test dialog',
66 onRender : function(ct, position)
68 Roo.bootstrap.Component.superclass.onRender.call(this, ct, position);
71 var cfg = Roo.apply({}, this.getAutoCreate());
74 // cfg.name = typeof(this.name) == 'undefined' ? this.id : this.name;
76 //if (!cfg.name.length) {
80 cfg.cls += ' ' + this.cls;
83 cfg.style = this.style;
85 this.el = Roo.get(document.body).createChild(cfg, position);
87 //var type = this.el.dom.type;
89 if(this.tabIndex !== undefined){
90 this.el.dom.setAttribute('tabIndex', this.tabIndex);
95 this.maskEl = Roo.DomHelper.append(document.body, {tag: "div", cls:"x-dlg-mask"}, true);
96 this.maskEl.enableDisplayMode("block");
98 //this.el.addClass("x-dlg-modal");
100 if (this.buttons.length) {
101 Roo.each(this.buttons, function(bb) {
102 b = Roo.apply({}, bb);
103 b.xns = b.xns || Roo.bootstrap;
104 b.xtype = b.xtype || 'Button';
105 if (typeof(b.listeners) == 'undefined') {
106 b.listeners = { click : this.onButtonClick.createDelegate(this) };
109 var btn = Roo.factory(b);
111 btn.onRender(this.el.select('.modal-footer').first());
115 // render the children.
118 if(typeof(this.items) != 'undefined'){
119 var items = this.items;
122 for(var i =0;i < items.length;i++) {
123 nitems.push(this.addxtype(Roo.apply({}, items[i])));
129 this.body = this.el.select('.modal-body',true).first();
130 this.close = this.el.select('.modal-header .close', true).first();
131 this.footer = this.el.select('.modal-footer',true).first();
133 //this.el.addClass([this.fieldClass, this.cls]);
136 getAutoCreate : function(){
141 html : this.html || ''
150 if(this.specificTitle){
159 style : 'display: none',
165 cls : "modal-content",
168 cls : 'modal-header',
201 getChildContainer : function() {
203 return this.el.select('.modal-body',true).first();
206 getButtonContainer : function() {
207 return this.el.select('.modal-footer',true).first();
210 initEvents : function()
212 this.el.select('.modal-header .close').on('click', this.hide, this);
214 // this.addxtype(this);
218 if (!this.rendered) {
222 this.el.addClass('on');
223 this.el.removeClass('fade');
224 this.el.setStyle('display', 'block');
225 Roo.get(document.body).addClass("x-body-masked");
226 this.maskEl.setSize(Roo.lib.Dom.getViewWidth(true), Roo.lib.Dom.getViewHeight(true));
228 this.el.setStyle('zIndex', '10001');
229 this.fireEvent('show', this);
235 Roo.log('Modal hide?!');
237 Roo.get(document.body).removeClass("x-body-masked");
238 this.el.removeClass('on');
239 this.el.addClass('fade');
240 this.el.setStyle('display', 'none');
241 this.fireEvent('hide', this);
244 addButton : function(str, cb)
248 var b = Roo.apply({}, { html : str } );
249 b.xns = b.xns || Roo.bootstrap;
250 b.xtype = b.xtype || 'Button';
251 if (typeof(b.listeners) == 'undefined') {
252 b.listeners = { click : cb.createDelegate(this) };
255 var btn = Roo.factory(b);
257 btn.onRender(this.el.select('.modal-footer').first());
263 setDefaultButton : function(btn)
265 //this.el.select('.modal-footer').()
267 resizeTo: function(w,h)
271 setContentSize : function(w, h)
275 onButtonClick: function(btn,e)
278 this.fireEvent('btnclick', btn.name, e);
280 setTitle: function(str) {
281 this.el.select('.modal-title',true).first().dom.innerHTML = str;
287 Roo.apply(Roo.bootstrap.Modal, {
289 * Button config that displays a single OK button
298 * Button config that displays Yes and No buttons
314 * Button config that displays OK and Cancel buttons
329 * Button config that displays Yes, No and Cancel buttons