Skip to content

Commit 3c3322d

Browse files
author
mesut talebi
committed
Added Disable Closing modal, And now when lazyload modal opened it is in top of all other modals.
1 parent 6d860d2 commit 3c3322d

File tree

4 files changed

+38
-16
lines changed

4 files changed

+38
-16
lines changed

README.md

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -41,13 +41,14 @@ C1) For Using MT.BoostrapLazyloader with modals, add **.lazyload** and **.showMo
4141

4242
C2) add **data-header** to define the Modal's Header.
4343

44-
C3) add **data-size** to define the Modal's size. (Example: data-size="modal-lg", don't set it you want default size.)
44+
C3) add **data-size** to define the Modal's size. (Example: data-size="modal-lg", don't set it if you want default size.)
4545

4646
C4) If you are using lazyload modal on an Anchor element, the **href** attribute will be used as **url** and you don't need to add extra data-url.
4747

4848
C5) By Default the Id For lazyload modal is *"LazyloadModal"*, but you can add **id** attribute to the tag that will used to toggle modal, so the id for modal will be
4949
Id + "Modal". with adding id to the toggle you can open multiple inner modals.
5050

51+
C6) **(New)** to prevent modal from closing by clicking the close button, pressing 'Esc' key or by clicking outside of the modal, you just need to add **data-closedisabled='false'**.
5152

5253
**Note: Modal's Markup will automatically append to body, and you don't need to add Modal's markup to body manually.**
5354

@@ -104,5 +105,7 @@ note: If you are lazy loading your initial tab, you can add a trigger('shown.bs.
104105
<!--footer buttons goes here-->
105106
<button type="button" class="btn btn-default" data-dismiss="modal">Close</button>
106107
<button type="submit" class="btn btn-primary">Save changes</button>
107-
</div>
108-
```
108+
</div >
109+
110+
```
111+

Scripts/MT.BootstrapLazyloader.js

Lines changed: 29 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
/*
22
Nuget Package: MT.BootstrapLazyLoader.js
3-
Version: 1.2.3
3+
Version: 1.2.4
44
55
Created By: Mesut Talebi (mesut.talebi@gmail.com)
66
@@ -89,31 +89,42 @@ $(function () {
8989
currHandleId += "Modal";
9090
}
9191

92+
93+
var disableClose = $(currHandle).data('closedisabled');
94+
9295
var modalHtml = "<!--Lazyloaded Modal -->" +
9396
"<div class='modal fade' id='" + currHandleId + "' role='dialog' aria-labelledby='" + currHandleId + "'>" +
9497
"<div class='modal-dialog' role='document'>" +
9598
"<div class='modal-content'>" +
96-
"<div class='modal-header'>" +
97-
"<button type='button' class='close' data-dismiss='modal' aria-label='Close'><span aria-hidden='true'>&times;</span></button>" +
98-
"<h4 class='modal-title' id='LazyloadModalLabel'>Modal Header</h4>" +
99-
"</div>" +
100-
"<div id='LazyloadModalContent'></div>" +
101-
"</div>" +
102-
"</div>" +
103-
"</div>";
99+
"<div class='modal-header'>";
100+
101+
if (disableClose == undefined || disableClose === 'false') {
102+
modalHtml += "<button type='button' class='close' data-dismiss='modal' aria-label='Close'><span aria-hidden='true'>&times;</span></button>";
103+
}
104+
105+
modalHtml += "<h4 class='modal-title' id='LazyloadModalLabel'>Modal Header</h4>" +
106+
"</div>" +
107+
"<div id='LazyloadModalContent'></div>" +
108+
"</div>" +
109+
"</div>" +
110+
"</div>";
104111

105112

106113

107114
var modalHeader = $(currHandle).data('header');
108115
var modalClass = $(currHandle).data('size');
109116
var callback = $(currHandle).data('callback');
110117

118+
111119
var modal = $('#' + currHandleId);
112120
if (modal.length == 0) {
113121
$('body').append(modalHtml);
114122

115123
modal = $('#' + currHandleId);
116124
}
125+
else {
126+
$('body').append(modal);
127+
}
117128

118129
$(modal).find('.modal-header #LazyloadModalLabel').html(modalHeader);
119130
$(modal).find('.modal-dialog').removeAttr("class").addClass('modal-dialog').addClass(modalClass);
@@ -123,7 +134,15 @@ $(function () {
123134
$(currHandle).append(loader);
124135
$.get(url, function (data) {
125136
$(modal).find('#LazyloadModalContent').html(data);
126-
$(modal).modal('show');
137+
if (disableClose == undefined) {
138+
$(modal).modal('show');
139+
}
140+
else {
141+
$(modal).modal({
142+
keyboard: false,
143+
backdrop: 'static'
144+
});
145+
}
127146
}).fail(function () {
128147
var alertDiv = '<div class="alert alert-danger"><i class="fa fa-exclamation-triangle"></i> Error!!!</div>';
129148
$(modal).find('#LazyloadModalContent').html(alertDiv);

Scripts/MT.BootstrapLazyloader.min.js

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

bundleconfig.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
[
22
{
3-
"outputFileName": "Scripts/MT.BootstrapLazyloader.js",
3+
"outputFileName": "Scripts/MT.BootstrapLazyloader.min.js",
44
"inputFiles": [
55
"Scripts/MT.BootstrapLazyloader.js"
66
]
77
}
8-
]
8+
]

0 commit comments

Comments
 (0)