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 Roo.extend(Roo.bootstrap.Modal, Roo.bootstrap.Component, {
62 title : 'test dialog',
73 buttonPosition: 'right',
79 onRender : function(ct, position)
81 Roo.bootstrap.Component.superclass.onRender.call(this, ct, position);
84 var cfg = Roo.apply({}, this.getAutoCreate());
87 // cfg.name = typeof(this.name) == 'undefined' ? this.id : this.name;
89 //if (!cfg.name.length) {
93 cfg.cls += ' ' + this.cls;
96 cfg.style = this.style;
98 this.el = Roo.get(document.body).createChild(cfg, position);
100 //var type = this.el.dom.type;
102 if(this.tabIndex !== undefined){
103 this.el.dom.setAttribute('tabIndex', this.tabIndex);
108 this.maskEl = Roo.DomHelper.append(document.body, {tag: "div", cls:"x-dlg-mask"}, true);
109 this.maskEl.enableDisplayMode("block");
111 //this.el.addClass("x-dlg-modal");
113 if (this.buttons.length) {
114 Roo.each(this.buttons, function(bb) {
115 b = Roo.apply({}, bb);
116 b.xns = b.xns || Roo.bootstrap;
117 b.xtype = b.xtype || 'Button';
118 if (typeof(b.listeners) == 'undefined') {
119 b.listeners = { click : this.onButtonClick.createDelegate(this) };
122 var btn = Roo.factory(b);
124 btn.onRender(this.el.select('.modal-footer div').first());
128 // render the children.
131 if(typeof(this.items) != 'undefined'){
132 var items = this.items;
135 for(var i =0;i < items.length;i++) {
136 nitems.push(this.addxtype(Roo.apply({}, items[i])));
142 this.body = this.el.select('.modal-body',true).first();
143 this.close = this.el.select('.modal-header .close', true).first();
144 this.footer = this.el.select('.modal-footer',true).first();
146 //this.el.addClass([this.fieldClass, this.cls]);
149 getAutoCreate : function(){
154 html : this.html || ''
163 if(this.specificTitle){
169 if (this.allow_close) {
180 style : 'display: none',
186 cls : "modal-content",
189 cls : 'modal-header',
194 cls : 'modal-footer',
198 cls: 'btn-' + this.buttonPosition
215 modal.cls += ' fade';
221 getChildContainer : function() {
223 return this.el.select('.modal-body',true).first();
226 getButtonContainer : function() {
227 return this.el.select('.modal-footer div',true).first();
230 initEvents : function()
232 this.el.select('.modal-header .close').on('click', this.hide, this);
234 // this.addxtype(this);
238 if (!this.rendered) {
242 this.el.setStyle('display', 'block');
246 (function(){ _this.el.addClass('in'); }).defer(50);
248 this.el.addClass('in');
255 Roo.get(document.body).addClass("x-body-masked");
256 this.maskEl.setSize(Roo.lib.Dom.getViewWidth(true), Roo.lib.Dom.getViewHeight(true));
258 this.el.setStyle('zIndex', '10001');
260 this.fireEvent('show', this);
267 Roo.get(document.body).removeClass("x-body-masked");
268 this.el.removeClass('in');
272 (function(){ _this.el.setStyle('display', 'none'); }).defer(150);
274 this.el.setStyle('display', 'none');
277 this.fireEvent('hide', this);
280 addButton : function(str, cb)
284 var b = Roo.apply({}, { html : str } );
285 b.xns = b.xns || Roo.bootstrap;
286 b.xtype = b.xtype || 'Button';
287 if (typeof(b.listeners) == 'undefined') {
288 b.listeners = { click : cb.createDelegate(this) };
291 var btn = Roo.factory(b);
293 btn.onRender(this.el.select('.modal-footer div').first());
299 setDefaultButton : function(btn)
301 //this.el.select('.modal-footer').()
303 resizeTo: function(w,h)
307 setContentSize : function(w, h)
311 onButtonClick: function(btn,e)
314 this.fireEvent('btnclick', btn.name, e);
316 setTitle: function(str) {
317 this.el.select('.modal-title',true).first().dom.innerHTML = str;
323 Roo.apply(Roo.bootstrap.Modal, {
325 * Button config that displays a single OK button
334 * Button config that displays Yes and No buttons
350 * Button config that displays OK and Cancel buttons
365 * Button config that displays Yes, No and Cancel buttons