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',
70 onRender : function(ct, position)
72 Roo.bootstrap.Component.superclass.onRender.call(this, ct, position);
75 var cfg = Roo.apply({}, this.getAutoCreate());
78 // cfg.name = typeof(this.name) == 'undefined' ? this.id : this.name;
80 //if (!cfg.name.length) {
84 cfg.cls += ' ' + this.cls;
87 cfg.style = this.style;
89 this.el = Roo.get(document.body).createChild(cfg, position);
91 //var type = this.el.dom.type;
93 if(this.tabIndex !== undefined){
94 this.el.dom.setAttribute('tabIndex', this.tabIndex);
99 this.maskEl = Roo.DomHelper.append(document.body, {tag: "div", cls:"x-dlg-mask"}, true);
100 this.maskEl.enableDisplayMode("block");
102 //this.el.addClass("x-dlg-modal");
104 if (this.buttons.length) {
105 Roo.each(this.buttons, function(bb) {
106 b = Roo.apply({}, bb);
107 b.xns = b.xns || Roo.bootstrap;
108 b.xtype = b.xtype || 'Button';
109 if (typeof(b.listeners) == 'undefined') {
110 b.listeners = { click : this.onButtonClick.createDelegate(this) };
113 var btn = Roo.factory(b);
115 btn.onRender(this.el.select('.modal-footer div').first());
119 // render the children.
122 if(typeof(this.items) != 'undefined'){
123 var items = this.items;
126 for(var i =0;i < items.length;i++) {
127 nitems.push(this.addxtype(Roo.apply({}, items[i])));
133 this.body = this.el.select('.modal-body',true).first();
134 this.close = this.el.select('.modal-header .close', true).first();
135 this.footer = this.el.select('.modal-footer',true).first();
137 //this.el.addClass([this.fieldClass, this.cls]);
140 getAutoCreate : function(){
145 html : this.html || ''
154 if(this.specificTitle){
160 style : 'display: none',
166 cls : "modal-content",
169 cls : 'modal-header',
181 cls : 'modal-footer',
185 cls: 'btn-' + this.buttonPosition
204 getChildContainer : function() {
206 return this.el.select('.modal-body',true).first();
209 getButtonContainer : function() {
210 return this.el.select('.modal-footer div',true).first();
213 initEvents : function()
215 this.el.select('.modal-header .close').on('click', this.hide, this);
217 // this.addxtype(this);
221 if (!this.rendered) {
225 this.el.setStyle('display', 'block');
226 (function(){ _this.el.addClass('in'); }).defer(150);
227 // this.el.removeClass('fade');
228 // this.el.setStyle('display', 'block');
229 // Roo.get(document.body).addClass("x-body-masked");
230 // this.maskEl.setSize(Roo.lib.Dom.getViewWidth(true), Roo.lib.Dom.getViewHeight(true));
231 // this.maskEl.show();
232 // this.el.setStyle('zIndex', '10001');
233 // this.fireEvent('show', this);
239 Roo.log('Modal hide?!');
240 // this.maskEl.hide();
241 // Roo.get(document.body).removeClass("x-body-masked");
242 this.el.removeClass('in');
243 // this.el.addClass('fade');
245 (function(){ _this.el.setStyle('display', 'none'); }).defer(150);
247 this.fireEvent('hide', this);
250 addButton : function(str, cb)
254 var b = Roo.apply({}, { html : str } );
255 b.xns = b.xns || Roo.bootstrap;
256 b.xtype = b.xtype || 'Button';
257 if (typeof(b.listeners) == 'undefined') {
258 b.listeners = { click : cb.createDelegate(this) };
261 var btn = Roo.factory(b);
263 btn.onRender(this.el.select('.modal-footer div').first());
269 setDefaultButton : function(btn)
271 //this.el.select('.modal-footer').()
273 resizeTo: function(w,h)
277 setContentSize : function(w, h)
281 onButtonClick: function(btn,e)
284 this.fireEvent('btnclick', btn.name, e);
286 setTitle: function(str) {
287 this.el.select('.modal-title',true).first().dom.innerHTML = str;
293 Roo.apply(Roo.bootstrap.Modal, {
295 * Button config that displays a single OK button
304 * Button config that displays Yes and No buttons
320 * Button config that displays OK and Cancel buttons
335 * Button config that displays Yes, No and Cancel buttons