@@ -15,38 +15,32 @@ document.addEventListener('DOMContentLoaded', function () {
1515 const downloadBtn = document . getElementById ( 'download-img' ) ;
1616 const shareBtn = document . getElementById ( 'share-btn' ) ;
1717
18- // Event listeners
1918 form . addEventListener ( 'submit' , handleFormSubmit ) ;
2019 displayCheckbox . addEventListener ( 'change' , convert ) ;
2120 closeButton . addEventListener ( 'click' , ( ) => {
2221 document . getElementById ( 'mobile-notice' ) . style . display = 'none' ;
2322 } ) ;
2423 shareBtn . addEventListener ( 'click' , handleShare ) ;
2524
26- // Load state from URL if present (wait for MathJax to be ready)
2725 loadStateFromURL ( ) ;
2826
2927 function loadStateFromURL ( ) {
3028 const state = getStateFromURL ( ) ;
3129 if ( state ) {
32- // Set input value
3330 inputField . value = state . number ;
34-
35- // Set checkboxes
31+
3632 document . getElementById ( 'gamma-function' ) . checked = state . config . gammaFunction ;
3733 document . getElementById ( 'eulers-identity' ) . checked = state . config . eulersIdentity ;
3834 document . getElementById ( 'limits-exponential' ) . checked = state . config . limitExponential ;
3935 document . getElementById ( 'limits-polynomial' ) . checked = state . config . limitPolynomial ;
4036 document . getElementById ( 'trig' ) . checked = state . config . trig ;
4137 document . getElementById ( 'geometric-series' ) . checked = state . config . geometricSeries ;
42-
43- // Wait for MathJax to be ready before rendering
38+
4439 if ( window . MathJax && window . MathJax . startup ) {
4540 MathJax . startup . promise . then ( ( ) => {
4641 convert ( ) ;
4742 } ) ;
4843 } else {
49- // MathJax not loaded yet, wait for it
5044 window . addEventListener ( 'load' , ( ) => {
5145 if ( window . MathJax && window . MathJax . startup ) {
5246 MathJax . startup . promise . then ( ( ) => {
@@ -66,14 +60,12 @@ document.addEventListener('DOMContentLoaded', function () {
6660 function convert ( ) {
6761 const number = inputField . value ;
6862
69- // Validate input
7063 const validation = validateInput ( number ) ;
7164 if ( ! validation . valid ) {
7265 showError ( validation . error ) ;
7366 return ;
7467 }
7568
76- // Get configuration from checkboxes
7769 const config = {
7870 gammaFunction : document . getElementById ( 'gamma-function' ) . checked ,
7971 eulersIdentity : document . getElementById ( 'eulers-identity' ) . checked ,
@@ -83,20 +75,17 @@ document.addEventListener('DOMContentLoaded', function () {
8375 geometricSeries : document . getElementById ( 'geometric-series' ) . checked ,
8476 } ;
8577
86- // Generate the LaTeX expression
8778 const input = generateEquation ( Number ( number ) , config ) ;
8879
89- // Render with MathJax
9080 renderEquation ( input ) ;
91-
92- // Update URL with current state (for sharing)
81+
9382 updateURL ( Number ( number ) , config ) ;
9483 }
9584
9685 function handleShare ( ) {
9786 const number = inputField . value ;
9887 const validation = validateInput ( number ) ;
99-
88+
10089 if ( ! validation . valid ) {
10190 showError ( 'Please generate an equation first before sharing!' ) ;
10291 return ;
@@ -112,7 +101,7 @@ document.addEventListener('DOMContentLoaded', function () {
112101 } ;
113102
114103 const shareableURL = generateShareableURL ( Number ( number ) , config ) ;
115-
104+
116105 // Try to use native share API if available (mobile devices)
117106 if ( navigator . share ) {
118107 navigator . share ( {
@@ -125,24 +114,21 @@ document.addEventListener('DOMContentLoaded', function () {
125114 }
126115 } ) ;
127116 } else {
128- // Fallback to clipboard
129117 copyToClipboard ( shareableURL ) ;
130118 }
131119 }
132120
133121 function copyToClipboard ( text ) {
134122 navigator . clipboard . writeText ( text ) . then ( ( ) => {
135- // Show feedback
136123 const originalText = shareBtn . textContent ;
137124 shareBtn . textContent = '✓ Link copied!' ;
138125 shareBtn . style . backgroundColor = '#28a745' ;
139-
126+
140127 setTimeout ( ( ) => {
141128 shareBtn . textContent = originalText ;
142129 shareBtn . style . backgroundColor = '' ;
143130 } , 2000 ) ;
144131 } ) . catch ( ( ) => {
145- // Fallback for older browsers
146132 const textarea = document . createElement ( 'textarea' ) ;
147133 textarea . value = text ;
148134 textarea . style . position = 'fixed' ;
@@ -151,7 +137,7 @@ document.addEventListener('DOMContentLoaded', function () {
151137 textarea . select ( ) ;
152138 document . execCommand ( 'copy' ) ;
153139 document . body . removeChild ( textarea ) ;
154-
140+
155141 const originalText = shareBtn . textContent ;
156142 shareBtn . textContent = '✓ Link copied!' ;
157143 setTimeout ( ( ) => {
@@ -165,18 +151,13 @@ document.addEventListener('DOMContentLoaded', function () {
165151 }
166152
167153 function renderEquation ( latexExpression ) {
168- // Disable buttons while rendering
169154 renderButton . disabled = displayCheckbox . disabled = true ;
170155
171- // Clear previous output
172156 outputDiv . innerHTML = '' ;
173157
174- // Configure MathJax rendering
175158 MathJax . texReset ( ) ;
176159 const options = MathJax . getMetricsFor ( outputDiv ) ;
177160 options . display = displayCheckbox . checked ;
178-
179- // Render the LaTeX expression
180161 MathJax . tex2svgPromise ( latexExpression , options )
181162 . then ( ( node ) => {
182163 outputDiv . appendChild ( node ) ;
0 commit comments