Line 0
Link Here
|
0 |
- |
1 |
$(document).ready(function() { |
|
|
2 |
|
3 |
function modalPrint() { |
4 |
let title = $('.modal-dialog.focused .modal-title').html(); |
5 |
let contents = $('.modal-dialog.focused .modal-body').html(); |
6 |
let win = window.open('',''); |
7 |
win.document.write(` |
8 |
<style> |
9 |
table { |
10 |
background-color: #FFFFFF; |
11 |
border-bottom: 1px solid #CCCCCC; |
12 |
border-collapse: collapse; |
13 |
border-left: 1px solid #CCCCCC; |
14 |
margin: 3px 0 5px 0; |
15 |
padding: 0; |
16 |
width: 99%; |
17 |
} |
18 |
|
19 |
td { |
20 |
background-color: #FFF; |
21 |
border-bottom: 1px solid #CCCCCC; |
22 |
border-left: 0; |
23 |
border-right: 1px solid #CCCCCC; |
24 |
border-top: 0; |
25 |
font-size: 12px; |
26 |
padding: 5px 5px 5px 5px; |
27 |
} |
28 |
|
29 |
th { |
30 |
background-color: #E9E9E9; |
31 |
border-bottom: 1px solid #CCCCCC; |
32 |
border-left: 0; |
33 |
border-right: 1px solid #CCCCCC; |
34 |
border-top: 0; |
35 |
font-size: 14px; |
36 |
font-weight: bold; |
37 |
padding: 5px 5px 5px 5px; |
38 |
text-align: left; |
39 |
} |
40 |
</style> |
41 |
`) |
42 |
win.document.write( title ); |
43 |
win.document.write( contents ); |
44 |
win.print(); |
45 |
win.close(); |
46 |
} |
47 |
|
48 |
// Set focused on printable modals on open and autoprint if required |
49 |
$('.modal.printable').on('shown.bs.modal', function() { |
50 |
$('.modal-dialog', this).addClass('focused'); |
51 |
|
52 |
if ($(this).hasClass('autoprint')) { |
53 |
modalPrint(); |
54 |
} |
55 |
}).on('hidden.bs.modal', function() { |
56 |
$('.modal-dialog', this).removeClass('focused'); |
57 |
}); |
58 |
|
59 |
// Trigger print on button click |
60 |
$('.printModal').click(function() { |
61 |
modalPrint(); |
62 |
}); |
63 |
}); |