One modal to rule them all
Parameter | Description | Type | Default | Options |
---|---|---|---|---|
id | Modal identificator | string | iModal | Valid id string |
size | Size of the modal | string | 'sm', 'lg', 'xl' | |
title | Title of the modal | string | Any text | |
closeText | Text of the close button | string | Close | Any text |
body | Default body to show | text or scaped HTML | Loading... |
|
headerClass | Header background color | string | 'success', 'primary', 'info', 'warning', 'danger', 'secondary' | |
footerClass | Footer background color | string | 'success', 'primary', 'info', 'warning', 'danger', 'secondary' | |
header | Show/hide header | boolean | true | true, false |
footer | Show/hide footer | boolean | true | true, false |
backdrop | Includes a modal-backdrop element | boolean or the string 'static' | true | true, false, 'static' |
backdropColor | Modal-backdrop color | false or string | false | false, 'success', 'primary', 'info', 'warning', 'danger', 'secondary' |
keyboard | Closes the modal when escape key is pressed | boolean | true | true, false |
dialogScrollable | Scroll the modal body | boolean | false | true, false |
dialogCentered | Modal vertically center | boolean | false | true, false |
fade | Fade animation | boolean | true | true, false |
onShow | Function to execute before show modal | function | ||
onShowed | Function to execute after show modal | function | ||
onHide | Function to execute before hide modal | function | ||
onHidden | Function to execute after hide modal | function | ||
onHidePrevented | Function to execute on click backdrop static | function |
iModal();
iModal(); $('#iModal .modal-body').html('Custom html');
iModal({id:'my_modal'});
iModal({size:'sm'}); iModal(); iModal({size:'lg'}); iModal({size:'xl'});
iModal({title:'Hello world'}); iModal({title:'Hola mundo'});
iModal({closeText:'Cerrar'});
iModal({body:''}); iModal({body:'Loading'}); iModal({body:`<div class='text-center'>Loading</div>`});
iModal({headerClass:'success',title:'Success'}); iModal({headerClass:'primary',title:'Primary'}); iModal({headerClass:'info',title:'Info'}); iModal({headerClass:'warning',title:'Warning'}); iModal({headerClass:'danger',title:'Danger'}); iModal({headerClass:'secondary',title:'Secondary'});
iModal({footerClass:'success'}); iModal({footerClass:'primary'}); iModal({footerClass:'info'}); iModal({footerClass:'warning'}); iModal({footerClass:'danger'}); iModal({footerClass:'secondary'});
iModal({header:false}); iModal({footer:false}); iModal({header:false,footer:false});
iModal({backdrop:false}); iModal({backdrop:'static'});
iModal({backdropColor:'success'}); iModal({backdropColor:'primary'}); iModal({backdropColor:'info'}); iModal({backdropColor:'warning'}); iModal({backdropColor:'danger'}); iModal({backdropColor:'secondary'});
iModal({keyboard:false});
iModal({dialogScrollable:true});
iModal({dialogCentered:true});
iModal({fade:false});
iModal({ onShow: function(){ alert('Show'); } }); iModal({ onShowed: function(){ alert('Showed'); } }); iModal({ onHide: function(){ alert('Hide'); } }); iModal({ onHidden: function(){ alert('Hidden'); } }); iModal({ backdrop: 'static', onHidePrevented: function(){ alert('Hide Prevented'); } });
iModal({ id:'my_modal', size:'sm', title:'Custom modal', closeText:'Cerrar', body:'Cargando...', headerClass:'success', footerClass:'success', backdrop:false, keyboard:false, dialogCentered:true, fade:false });
iModalSettings = { id: 'my_modal', size: 'lg', title: 'My project', backdrop: false, };
iModalSettings.closeText = 'Cerrar'; iModalSettings.body = 'Loading...';
// HTML <button type="button" onclick="muFunction();">Button</button> // JavaScript function muFunction(){ $.ajax({ type: 'POST', url: '/url/to', beforeSend: function(){ iModal({title:'My title'}); }, success: function(response){ $("#iModal .modal-body").html(response); }, }); }
let myComponent; iModal({ title: 'My Component', body: `<div id="async-div"></div>`, onShow: () => { myComponent = new AnotherComponent().$mount('#async-div'); myComponent.someData = 123; myComponent.someMethod(); }, // Recomended: destroy component on modal hide onHidden: () => { myComponent.$destroy(); }, });