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 {String} html - the body of the dialog (for simple ones) - you can also use template..
34 * @cfg {Roo.Template} tmpl - a template with variables.
35 * @cfg {Boolean} specificTitle default false
36 * @cfg {Array} buttons Array of buttons or standard button set..
37 * @cfg {String} buttonPosition (left|right|center) default right
38 * @cfg {Boolean} animate default true
39 * @cfg {Boolean} allow_close default true
42 * Create a new Modal Dialog
43 * @param {Object} config The config object
46 Roo.bootstrap.Modal = function(config){
47 Roo.bootstrap.Modal.superclass.constructor.call(this, config);
52 * The raw btnclick event for the button
53 * @param {Roo.EventObject} e
57 this.buttons = this.buttons || [];
60 this.tmpl = Roo.factory(this.tmpl);
65 Roo.extend(Roo.bootstrap.Modal, Roo.bootstrap.Component, {
67 title : 'test dialog',
80 buttonPosition: 'right',
86 onRender : function(ct, position)
88 Roo.bootstrap.Component.superclass.onRender.call(this, ct, position);
91 var cfg = Roo.apply({}, this.getAutoCreate());
94 // cfg.name = typeof(this.name) == 'undefined' ? this.id : this.name;
96 //if (!cfg.name.length) {
100 cfg.cls += ' ' + this.cls;
103 cfg.style = this.style;
105 this.el = Roo.get(document.body).createChild(cfg, position);
107 //var type = this.el.dom.type;
109 if(this.tabIndex !== undefined){
110 this.el.dom.setAttribute('tabIndex', this.tabIndex);
115 this.maskEl = Roo.DomHelper.append(document.body, {tag: "div", cls:"x-dlg-mask"}, true);
116 this.maskEl.enableDisplayMode("block");
118 //this.el.addClass("x-dlg-modal");
120 if (this.buttons.length) {
121 Roo.each(this.buttons, function(bb) {
122 b = Roo.apply({}, bb);
123 b.xns = b.xns || Roo.bootstrap;
124 b.xtype = b.xtype || 'Button';
125 if (typeof(b.listeners) == 'undefined') {
126 b.listeners = { click : this.onButtonClick.createDelegate(this) };
129 var btn = Roo.factory(b);
131 btn.onRender(this.el.select('.modal-footer div').first());
135 // render the children.
138 if(typeof(this.items) != 'undefined'){
139 var items = this.items;
142 for(var i =0;i < items.length;i++) {
143 nitems.push(this.addxtype(Roo.apply({}, items[i])));
149 this.body = this.el.select('.modal-body',true).first();
150 this.close = this.el.select('.modal-header .close', true).first();
151 this.footer = this.el.select('.modal-footer',true).first();
153 //this.el.addClass([this.fieldClass, this.cls]);
156 getAutoCreate : function(){
161 html : this.html || ''
170 if(this.specificTitle){
176 if (this.allow_close) {
187 style : 'display: none',
193 cls : "modal-content",
196 cls : 'modal-header',
201 cls : 'modal-footer',
205 cls: 'btn-' + this.buttonPosition
222 modal.cls += ' fade';
228 getChildContainer : function() {
230 return this.el.select('.modal-body',true).first();
233 getButtonContainer : function() {
234 return this.el.select('.modal-footer div',true).first();
237 initEvents : function()
239 this.el.select('.modal-header .close').on('click', this.hide, this);
241 // this.addxtype(this);
245 if (!this.rendered) {
249 this.el.setStyle('display', 'block');
253 (function(){ _this.el.addClass('in'); }).defer(50);
255 this.el.addClass('in');
259 this.getChildContainer().dom.innerHTML = this.tmpl.applyTemplate(this);
262 Roo.get(document.body).addClass("x-body-masked");
263 this.maskEl.setSize(Roo.lib.Dom.getViewWidth(true), Roo.lib.Dom.getViewHeight(true));
265 this.el.setStyle('zIndex', '10001');
267 this.fireEvent('show', this);
274 Roo.get(document.body).removeClass("x-body-masked");
275 this.el.removeClass('in');
279 (function(){ _this.el.setStyle('display', 'none'); }).defer(150);
281 this.el.setStyle('display', 'none');
284 this.fireEvent('hide', this);
287 addButton : function(str, cb)
291 var b = Roo.apply({}, { html : str } );
292 b.xns = b.xns || Roo.bootstrap;
293 b.xtype = b.xtype || 'Button';
294 if (typeof(b.listeners) == 'undefined') {
295 b.listeners = { click : cb.createDelegate(this) };
298 var btn = Roo.factory(b);
300 btn.onRender(this.el.select('.modal-footer div').first());
306 setDefaultButton : function(btn)
308 //this.el.select('.modal-footer').()
310 resizeTo: function(w,h)
314 setContentSize : function(w, h)
318 onButtonClick: function(btn,e)
321 this.fireEvent('btnclick', btn.name, e);
323 setTitle: function(str) {
324 this.el.select('.modal-title',true).first().dom.innerHTML = str;
330 Roo.apply(Roo.bootstrap.Modal, {
332 * Button config that displays a single OK button
341 * Button config that displays Yes and No buttons
357 * Button config that displays OK and Cancel buttons
372 * Button config that displays Yes, No and Cancel buttons