Skip to content

Commit 4a2c76e

Browse files
committed
Merge pull request #1 from ChrisDerrig/master
Added support for pill style tabs, and added callback functionality
2 parents 95e8740 + 0cfec14 commit 4a2c76e

File tree

2 files changed

+51
-3
lines changed

2 files changed

+51
-3
lines changed

README.md

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ If you don't use nuget package manager, just download source code, and copy MT.B
2424

2525
2- add class **.lazyload** to nav-tabs (bootstrap tabs ul tag)
2626

27-
3- add **data-url** to the **anchor** tag of every tab you want to lazyload. this attribute will contain the url of partial pages you want to load it into the tab.
27+
3- add **data-url** to the **anchor** tag of every tab you want to lazyload. this attribute will contain the url of partial pages you want to load it into the tab. The data-callback attribute can be used to specify a javascript function to be called once the load is done (on the .done() event of the $.get)
2828
**Example**
2929

3030

@@ -33,7 +33,19 @@ If you don't use nuget package manager, just download source code, and copy MT.B
3333
<li class="active"><a href="#fullDesc" data-toggle="tab">Description</a></li>
3434
<li><a href="#specificationDetails" data-toggle="tab">Specifications</a></li>
3535
<li><a href="#relatedProducts" data-toggle="tab" data-url="@Url.Action("relatedproducts", new { model.product.id})">Related Products</a></li>
36-
<li><a href="#files" data-toggle="tab" data-url="@Url.Action("getproductfiles", new { model.product.id })">Product Files</a></li>
36+
<li><a href="#files" data-toggle="tab" data-url="@Url.Action("getproductfiles", new { model.product.id })" data-callback="initProducts()">Product Files</a></li>
3737
<li><a href="#videos" data-toggle="tab" data-url="@Url.Action("getproductvideos", new { model.product.id })">Product Videos</a></li>
3838
</ul>
3939

40+
4- If you are lazy loading your initial tab, you can add a trigger('shown.bs.tab') on your initial tab.
41+
42+
**MVC Example on the same page as your tabs**
43+
```
44+
@section scripts {
45+
<script type="text/javascript">
46+
$(document).ready(function () {
47+
$('.nav-tabs a[href="#fullDesc"]').trigger('shown.bs.tab');
48+
});
49+
</script>
50+
}
51+
```

Scripts/MT.BootstrapTabsLazyloader.js

Lines changed: 37 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,14 +9,16 @@ Adds Lazy loading feature to bootstrap tabs
99
*/
1010

1111

12-
$(function() {
12+
$(function () {
1313
$(document).on('shown.bs.tab', '.nav-tabs.lazyload a[data-toggle="tab"]:not(.loaded)', function (e) {
1414
var loader = '<div class="text-center"><i class="fa fa-spin fa-spinner fa-2x text-muted"></i></div>';
1515

1616
var pane = $(e.target).attr('href');
1717

1818
var url = $(e.target).data('url');
1919

20+
var callback = $(e.target).data('callback');
21+
2022
if (url) {
2123
$(pane).html(loader);
2224

@@ -28,6 +30,40 @@ $(function() {
2830
.fail(function () {
2931
var alertDiv = '<div class="alert alert-danger"><i class="fa fa-exclamation-triangle"></i> Error!!!</div>';
3032
$(pane).html(alertDiv);
33+
})
34+
.done(function () {
35+
if (callback) {
36+
eval(callback);
37+
}
38+
});
39+
}
40+
});
41+
42+
$(document).on('shown.bs.tab', '.nav-pills.lazyload a[data-toggle="pill"]:not(.loaded)', function (e) {
43+
var loader = '<div class="text-center"><i class="fa fa-spin fa-spinner fa-2x text-muted"></i></div>';
44+
45+
var pane = $(e.target).attr('href');
46+
47+
var url = $(e.target).data('url');
48+
49+
var callback = $(e.target).data('callback');
50+
51+
if (url) {
52+
$(pane).html(loader);
53+
54+
var caller = $(this);
55+
$.get(url, function (data) {
56+
$(pane).html(data);
57+
$(caller).addClass('loaded');
58+
})
59+
.fail(function () {
60+
var alertDiv = '<div class="alert alert-danger"><i class="fa fa-exclamation-triangle"></i> Error!!!</div>';
61+
$(pane).html(alertDiv);
62+
})
63+
.done(function () {
64+
if (callback) {
65+
eval(callback);
66+
}
3167
});
3268
}
3369
});

0 commit comments

Comments
 (0)