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..
35 * @cfg {String} buttonPosition (left|right|center) default right
36 * @cfg {Boolean} animate (true | false) default true
39 * Create a new Modal Dialog
40 * @param {Object} config The config object
43 Roo.bootstrap.Modal = function(config){
44 Roo.bootstrap.Modal.superclass.constructor.call(this, config);
49 * The raw btnclick event for the button
50 * @param {Roo.EventObject} e
54 this.buttons = this.buttons || [];
57 Roo.extend(Roo.bootstrap.Modal, Roo.bootstrap.Component, {
59 title : 'test dialog',
68 buttonPosition: 'right',
72 onRender : function(ct, position)
74 Roo.bootstrap.Component.superclass.onRender.call(this, ct, position);
77 var cfg = Roo.apply({}, this.getAutoCreate());
80 // cfg.name = typeof(this.name) == 'undefined' ? this.id : this.name;
82 //if (!cfg.name.length) {
86 cfg.cls += ' ' + this.cls;
89 cfg.style = this.style;
91 this.el = Roo.get(document.body).createChild(cfg, position);
93 //var type = this.el.dom.type;
95 if(this.tabIndex !== undefined){
96 this.el.dom.setAttribute('tabIndex', this.tabIndex);
101 this.maskEl = Roo.DomHelper.append(document.body, {tag: "div", cls:"x-dlg-mask"}, true);
102 this.maskEl.enableDisplayMode("block");
104 //this.el.addClass("x-dlg-modal");
106 if (this.buttons.length) {
107 Roo.each(this.buttons, function(bb) {
108 b = Roo.apply({}, bb);
109 b.xns = b.xns || Roo.bootstrap;
110 b.xtype = b.xtype || 'Button';
111 if (typeof(b.listeners) == 'undefined') {
112 b.listeners = { click : this.onButtonClick.createDelegate(this) };
115 var btn = Roo.factory(b);
117 btn.onRender(this.el.select('.modal-footer div').first());
121 // render the children.
124 if(typeof(this.items) != 'undefined'){
125 var items = this.items;
128 for(var i =0;i < items.length;i++) {
129 nitems.push(this.addxtype(Roo.apply({}, items[i])));
135 this.body = this.el.select('.modal-body',true).first();
136 this.close = this.el.select('.modal-header .close', true).first();
137 this.footer = this.el.select('.modal-footer',true).first();
139 //this.el.addClass([this.fieldClass, this.cls]);
142 getAutoCreate : function(){
147 html : this.html || ''
156 if(this.specificTitle){
162 style : 'display: none',
168 cls : "modal-content",
171 cls : 'modal-header',
183 cls : 'modal-footer',
187 cls: 'btn-' + this.buttonPosition
204 modal.cls += ' fade';
210 getChildContainer : function() {
212 return this.el.select('.modal-body',true).first();
215 getButtonContainer : function() {
216 return this.el.select('.modal-footer div',true).first();
219 initEvents : function()
221 this.el.select('.modal-header .close').on('click', this.hide, this);
223 // this.addxtype(this);
227 if (!this.rendered) {
231 this.el.setStyle('display', 'block');
235 (function(){ _this.el.addClass('in'); }).defer(50);
237 this.el.addClass('in');
240 Roo.get(document.body).addClass("x-body-masked");
241 this.maskEl.setSize(Roo.lib.Dom.getViewWidth(true), Roo.lib.Dom.getViewHeight(true));
243 this.el.setStyle('zIndex', '10001');
244 this.fireEvent('show', this);
250 Roo.log('Modal hide?!');
251 // this.maskEl.hide();
252 // Roo.get(document.body).removeClass("x-body-masked");
253 this.el.removeClass('in');
254 // this.el.addClass('fade');
258 (function(){ _this.el.setStyle('display', 'none'); }).defer(150);
260 this.el.setStyle('display', 'none');
264 this.fireEvent('hide', this);
267 addButton : function(str, cb)
271 var b = Roo.apply({}, { html : str } );
272 b.xns = b.xns || Roo.bootstrap;
273 b.xtype = b.xtype || 'Button';
274 if (typeof(b.listeners) == 'undefined') {
275 b.listeners = { click : cb.createDelegate(this) };
278 var btn = Roo.factory(b);
280 btn.onRender(this.el.select('.modal-footer div').first());
286 setDefaultButton : function(btn)
288 //this.el.select('.modal-footer').()
290 resizeTo: function(w,h)
294 setContentSize : function(w, h)
298 onButtonClick: function(btn,e)
301 this.fireEvent('btnclick', btn.name, e);
303 setTitle: function(str) {
304 this.el.select('.modal-title',true).first().dom.innerHTML = str;
310 Roo.apply(Roo.bootstrap.Modal, {
312 * Button config that displays a single OK button
321 * Button config that displays Yes and No buttons
337 * Button config that displays OK and Cancel buttons
352 * Button config that displays Yes, No and Cancel buttons