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
38 * Create a new Modal Dialog
39 * @param {Object} config The config object
42 Roo.bootstrap.Modal = function(config){
43 Roo.bootstrap.Modal.superclass.constructor.call(this, config);
48 * The raw btnclick event for the button
49 * @param {Roo.EventObject} e
53 this.buttons = this.buttons || [];
56 Roo.extend(Roo.bootstrap.Modal, Roo.bootstrap.Component, {
58 title : 'test dialog',
67 buttonPosition: 'right',
69 onRender : function(ct, position)
71 Roo.bootstrap.Component.superclass.onRender.call(this, ct, position);
74 var cfg = Roo.apply({}, this.getAutoCreate());
77 // cfg.name = typeof(this.name) == 'undefined' ? this.id : this.name;
79 //if (!cfg.name.length) {
83 cfg.cls += ' ' + this.cls;
86 cfg.style = this.style;
88 this.el = Roo.get(document.body).createChild(cfg, position);
90 //var type = this.el.dom.type;
92 if(this.tabIndex !== undefined){
93 this.el.dom.setAttribute('tabIndex', this.tabIndex);
98 this.maskEl = Roo.DomHelper.append(document.body, {tag: "div", cls:"x-dlg-mask"}, true);
99 this.maskEl.enableDisplayMode("block");
101 //this.el.addClass("x-dlg-modal");
103 if (this.buttons.length) {
104 Roo.each(this.buttons, function(bb) {
105 b = Roo.apply({}, bb);
106 b.xns = b.xns || Roo.bootstrap;
107 b.xtype = b.xtype || 'Button';
108 if (typeof(b.listeners) == 'undefined') {
109 b.listeners = { click : this.onButtonClick.createDelegate(this) };
112 var btn = Roo.factory(b);
114 btn.onRender(this.el.select('.modal-footer div').first());
118 // render the children.
121 if(typeof(this.items) != 'undefined'){
122 var items = this.items;
125 for(var i =0;i < items.length;i++) {
126 nitems.push(this.addxtype(Roo.apply({}, items[i])));
132 this.body = this.el.select('.modal-body',true).first();
133 this.close = this.el.select('.modal-header .close', true).first();
134 this.footer = this.el.select('.modal-footer',true).first();
136 //this.el.addClass([this.fieldClass, this.cls]);
139 getAutoCreate : function(){
144 html : this.html || ''
153 if(this.specificTitle){
159 style : 'display: none',
165 cls : "modal-content",
168 cls : 'modal-header',
180 cls : 'modal-footer',
184 cls: 'btn-' + this.buttonPosition
203 getChildContainer : function() {
205 return this.el.select('.modal-body',true).first();
208 getButtonContainer : function() {
209 return this.el.select('.modal-footer div',true).first();
212 initEvents : function()
214 this.el.select('.modal-header .close').on('click', this.hide, this);
216 // this.addxtype(this);
220 if (!this.rendered) {
223 this.el.setStyle('display', 'block');
224 (function(){ this.el.addClass('in'); }).defer(100);
225 // this.el.removeClass('fade');
226 // this.el.setStyle('display', 'block');
227 // Roo.get(document.body).addClass("x-body-masked");
228 // this.maskEl.setSize(Roo.lib.Dom.getViewWidth(true), Roo.lib.Dom.getViewHeight(true));
229 // this.maskEl.show();
230 // this.el.setStyle('zIndex', '10001');
231 // this.fireEvent('show', this);
237 Roo.log('Modal hide?!');
238 // this.maskEl.hide();
239 // Roo.get(document.body).removeClass("x-body-masked");
240 this.el.removeClass('in');
241 // this.el.addClass('fade');
242 this.el.setStyle('display', 'none');
243 this.fireEvent('hide', this);
246 addButton : function(str, cb)
250 var b = Roo.apply({}, { html : str } );
251 b.xns = b.xns || Roo.bootstrap;
252 b.xtype = b.xtype || 'Button';
253 if (typeof(b.listeners) == 'undefined') {
254 b.listeners = { click : cb.createDelegate(this) };
257 var btn = Roo.factory(b);
259 btn.onRender(this.el.select('.modal-footer div').first());
265 setDefaultButton : function(btn)
267 //this.el.select('.modal-footer').()
269 resizeTo: function(w,h)
273 setContentSize : function(w, h)
277 onButtonClick: function(btn,e)
280 this.fireEvent('btnclick', btn.name, e);
282 setTitle: function(str) {
283 this.el.select('.modal-title',true).first().dom.innerHTML = str;
289 Roo.apply(Roo.bootstrap.Modal, {
291 * Button config that displays a single OK button
300 * Button config that displays Yes and No buttons
316 * Button config that displays OK and Cancel buttons
331 * Button config that displays Yes, No and Cancel buttons