Skip to content

Commit 5dfc4c4

Browse files
author
mesut talebi
committed
Added Ability to open multiple inner bootstrap modals,
And ability to open modal with anchor tag.
1 parent e2f51b1 commit 5dfc4c4

File tree

4 files changed

+43
-12
lines changed

4 files changed

+43
-12
lines changed

.gitignore

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
################################################################################
2+
# This .gitignore file was automatically created by Microsoft(R) Visual Studio.
3+
################################################################################
4+
5+
/.vs/config/applicationhost.config
6+
/.vs/Mt.BootstrapLazyload.js/v14/.suo
7+
/Mt.BootstrapLazyload.js.sln

README.md

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,12 @@ C2) add **data-header** to define the Modal's Header.
4343

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

46+
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.
47+
48+
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
49+
Id + "Modal". with adding id to the toggle you can open multiple inner modals.
50+
51+
4652
**Note: Modal's Markup will automatically append to body, and you don't need to add Modal's markup to body manually.**
4753

4854
**Callback function after Ajax Loaded**
@@ -86,16 +92,17 @@ note: If you are lazy loading your initial tab, you can add a trigger('shown.bs.
8692
data-header="Preview Product" data-size="modal-lg" data-callback="initProducts()">Preview</button>
8793
```
8894

95+
96+
8997
*The Returned Partial View Content:*
9098

9199
```
92100
<div class="modal-body">
93-
<!--Contents goes here-->
94-
95-
<div class="modal-footer">
101+
<!--Contents goes here-->
102+
</div>
103+
<div class="modal-footer">
96104
<!--footer buttons goes here-->
97105
<button type="button" class="btn btn-default" data-dismiss="modal">Close</button>
98106
<button type="submit" class="btn btn-primary">Save changes</button>
99-
</div>
100107
</div>
101108
```

Scripts/MT.BootstrapLazyloader.js

Lines changed: 24 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
/*
22
Nuget Package: MT.BootstrapLazyLoader.js
3-
Version: 1.2.0
3+
Version: 1.2.2
44
55
Created By: Mesut Talebi (mesut.talebi@gmail.com)
66
@@ -71,10 +71,26 @@ $(function () {
7171
});
7272

7373
$(document).on('click', '.lazyload.showModal', function (e) {
74-
var loader = '<i class="fa fa-spin fa-spinner fa-2x text-info modal-loader"></i>';
7574
var currHandle = $(this);
75+
var url = $(currHandle).data('url');
76+
if ($(this).prop("tagName") == "A" && url == undefined) {
77+
e.preventDefault();
78+
url = $(currHandle).attr('href');
79+
}
80+
81+
var loader = '<i class="fa fa-spin fa-spinner fa-lg text-info modal-loader"></i>';
82+
83+
//Get Id Of Current Handler to set as Modal Id, the id of modal will be #HandlerId + Modal
84+
var currHandleId = $(currHandle).attr('id');
85+
86+
if (currHandleId == undefined) {
87+
currHandleId = "LazyloadModal";
88+
} else {
89+
currHandleId += "Modal";
90+
}
91+
7692
var modalHtml = "<!--Lazyloaded Modal -->" +
77-
"<div class='modal fade' id='LazyloadModal' role='dialog' aria-labelledby='LazyloadModal'>" +
93+
"<div class='modal fade' id='" + currHandleId + "' role='dialog' aria-labelledby='" + currHandleId + "'>" +
7894
"<div class='modal-dialog' role='document'>" +
7995
"<div class='modal-content'>" +
8096
"<div class='modal-header'>" +
@@ -86,20 +102,21 @@ $(function () {
86102
"</div>" +
87103
"</div>";
88104

89-
var url = $(currHandle).data('url');
105+
106+
90107
var modalHeader = $(currHandle).data('header');
91108
var modalClass = $(currHandle).data('size');
92109
var callback = $(currHandle).data('callback');
93110

94-
var modal = $('#LazyloadModal');
111+
var modal = $('#' + currHandleId);
95112
if (modal.length == 0) {
96113
$('body').append(modalHtml);
97114

98-
modal = $('#LazyloadModal');
115+
modal = $('#' + currHandleId);
99116
}
100117

101118
$(modal).find('.modal-header #LazyloadModalLabel').html(modalHeader);
102-
$(modal).find('.modal-dialog').addClass(modalClass);
119+
$(modal).find('.modal-dialog').removeAttr("class").addClass('.modal-dialog').addClass(modalClass);
103120

104121
//Ajax Get
105122
$(modal).find('#LazyloadModalContent').html('');

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.

0 commit comments

Comments
 (0)