Easier more than you might think, included all possible scenarios with examples for each case.
script
inside your page
<script type="text/javascript" src="/bscom.modals.js"></script>
Please make sure that bootstrap version 4 and also jquery library both are already referenced in
your pages before start using this library
data-toggle="modal"
, data-title
and
data-message|data-body
<a
data-toggle="modal"
data-title="Simple"
data-body="Hello World"
href="#"
class="btn btn-primary">Simple</a>
Simple
data-body
atribute
<a
data-toggle="modal"
data-title="Styled"
data-body="<h3>Hello World</h3><div class='bg bg-info'>this is styled content</div>"
href="#"
class="btn btn-primary">Simple</a>
Styled Content
Call backs can be added easily via data elements: data-callback
and data-hidden-callback
,
both displayed
and completed
functions should be defined in the page
in script
tag
<a data-toggle="modal"
data-title="Simple"
data-callback="displayed"
data-hidden-callback="completed"
data-body="<h3>Hello World</h3>" href="#"
class="btn btn-primary">Callbacks
<script>
function displayed() {
alert("I am displayed");
}
function completed() {
alert("I am done");
}
</script>
Callbacks
<a
data-toggle="modal" data-title="Callback"
data-body="<h5>Close me now and It will fire a function named completed_params with passing this form back to parent or caller</h5>"
data-hidden-callback="completed_params"
href="#" class="btn btn-primary">Simple</a>
<script>
function completed_params($mw) {
alert("I am done, all form: " + $($mw).find(".modal-body").html());
}
</script>
Callback [access to form]
data-sz
or data-size
<a data-toggle="modal" data-title="Small" data-body="Small, just use data-size='sm'
" data-sz="sm"
href="#" class="btn btn-primary">Simple</a>
<a data-toggle="modal" data-title="Medium" data-body="Medium, just use data-size='md'" data-sz="md"
href="#" class="btn btn-primary">Medium</a>
<a data-toggle="modal" data-title="Large" data-body="Large, just use data-size='lg'" data-sz="lg"
href="#" class="btn btn-primary">Large</a>
Small
Medium
large
Ajax Simplified via data-ajax
, it will implicitly get the resource from remote
server using jquery and display it as the body of the modal.
<a data-toggle="modal" data-title="Ajax"
data-ajax="../resource.html"
href="#" class="btn btn-primary">Simple</a>
Simple Ajax
bscom.modals
, just pass only the title
and body of your message you want to display, the body of your message to be displayed inside modal
window can have full html along with javascript to be handled
<a id="simple" href="#" class="btn btn-primary">Simple JS</a>
<script>
$("#simple").click(function (e) {
e.preventDefault();
bscom.modals.simple("Title", "Here I'm simple <button class='btn btn-danger'
onclick='bscom.modals.close();'>Close Me!</button>");
});
</script>
Simple JS
$("#ajax").click(function (e) {
e.preventDefault();
$.get("./resource.html", function (response) {
bscom.modals.open("Remote Resource", response, "md", {} ,
function(){
alert("test");
},
function($mw){
alert("I am done, " + $mw.find(".modal-body").html());
}
);
});
});
Ajax Call with CallbacksBy default size is small when calling simple()
function however if you called show()
or open()
default size is medium
$("#ajax_simple").click(function (e) {
e.preventDefault();
$.get("//raw.githubusercontent.com/msolimans/BSComponents/master/cresource.html", function (data) {
bscom.modals.simple("Remote", data);
});
});
Different types and styles for modals are also supported, suppose you want to warn your users or to inform them with a notification, give them an error or confirm to do some action like deleting an item or doing some critical action
bscom.modals.simple("Simple", "Simple Msg")
bscom.modals.success("Success", "Success Msg")
//inform or info (just naming)
bscom.modals.info("Info!", "Info goes here!");
bscom.modals.inform("Info!", "Info goes here!");
//warn or warning (just naming)
bscom.modals.warn("Warning!", "My Warning");
bscom.modals.warning("Warning!", "My Warning");
//error or err (just naming)
bscom.modals.err("Err!", "Error goes here");
bscom.modals.error("Error!", "Error goes here");
bscom.modals.confirm("Confirm?",
"Are you sure?",
function(){ alert("Okay"); });'>
This should display a popup window periodically, by default it is ticking/poping up after 3 seconds and counts for 10 seconds more then redirecting to redirect
url
bscom.modals.timeout("Timeout",
"Should redirect to 'redirect' after {{c}}, you can 'Stay Connected'/'Logout'")
Want more configuration options, please check this