drakosfire commited on
Commit
3bf0a70
1 Parent(s): 26d1f1c

print now function is a popup to prevent disruption of main page

Browse files
Files changed (1) hide show
  1. scripts.js +33 -12
scripts.js CHANGED
@@ -90,23 +90,44 @@ document.addEventListener("DOMContentLoaded", function() {
90
  .catch((error) => {
91
  console.error('Error:', error);
92
  });
93
- });
94
- // Print Function
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
95
  window.printPageContainer = function() {
96
  var pageContainer = document.getElementById('pages');
97
  if (pageContainer) {
98
- var printContents = pageContainer.innerHTML;
99
- var originalContents = document.body.innerHTML;
100
-
101
- document.body.innerHTML = printContents;
102
-
103
- window.print();
104
-
105
- document.body.innerHTML = originalContents;
 
 
 
 
106
  } else {
107
- console.error('Element with ID "pageContainer" not found.');
108
  }
109
- }
 
110
 
111
  // Store initial positions of the blocks
112
  function storeInitialPositions() {
 
90
  .catch((error) => {
91
  console.error('Error:', error);
92
  });
93
+ });
94
+
95
+ const headHTMLString = `<!DOCTYPE html>
96
+ <html lang="en">
97
+ <head>
98
+ <meta charset="UTF-8">
99
+ <meta name="viewport" content="width=device-width, initial-scale=1.0">
100
+ <link href="./dependencies/all.css" rel="stylesheet" />
101
+ <link href="./dependencies/css.css?family=Open+Sans:400,300,600,700" rel="stylesheet" type="text/css" />
102
+ <link href='./dependencies/bundle.css' rel='stylesheet' />
103
+ <link href="./dependencies/style.css" rel='stylesheet' />
104
+ <link href="./dependencies/5ePHBstyle.css" rel='stylesheet' />
105
+ <link href="./storeUI.css" rel='stylesheet' />
106
+ <title>DnD Stat Block</title>
107
+ <link rel="stylesheet" href="styles.css">
108
+ <script src="https://unpkg.com/htmx.org@1.7.0/dist/htmx.min.js"></script>
109
+ </head>
110
+ <body>`;
111
  window.printPageContainer = function() {
112
  var pageContainer = document.getElementById('pages');
113
  if (pageContainer) {
114
+ var printWindow = window.open('', '', 'height=800,width=600');
115
+ printWindow.document.write(headHTMLString);
116
+ printWindow.document.write(pageContainer.innerHTML);
117
+ printWindow.document.write('</body></html>');
118
+ printWindow.document.close();
119
+ printWindow.focus();
120
+
121
+ // Wait for the content to be fully loaded before printing
122
+ printWindow.onload = function() {
123
+ printWindow.print();
124
+ printWindow.close(); // Close the print window after printing
125
+ };
126
  } else {
127
+ console.error('Element with ID "pages" not found.');
128
  }
129
+ };
130
+
131
 
132
  // Store initial positions of the blocks
133
  function storeInitialPositions() {