Skip to content

Commit bfd9346

Browse files
committed
Release v5.0.4: Dynamic resize functionality, enhanced tablet support, improved error handling
✨ New Features: - Dynamic resize functionality with autoResize(), resizeToFit(), and resizeModal() methods - autoResizeOnContentChange option with MutationObserver integration - Enhanced tablet button sizing for better touch interaction (451px-1024px) - Global resize methods: $.autoResize(), $.resizeToFit(), $.resizeModal() 🔧 Technical Improvements: - Robust defensive programming with proper guards in animateAlert() and closeAlert() - Enhanced AJAX error handling with proper type checking - Standardized API access patterns using .jAlert() method consistently - Better async scenario handling and race condition prevention 🐛 Bug Fixes: - Fixed blurBackground access errors in async scenarios - Improved test stability in JSDOM environment - Enhanced memory management with proper MutationObserver cleanup 📚 Documentation: - Comprehensive resize API documentation with interactive demos - Enhanced technical documentation covering error handling improvements - Updated responsive design documentation with tablet enhancements 🧪 Testing: - Improved test coverage for resize functionality - Enhanced test reliability with proper JSDOM compatibility - Added defensive test patterns for edge cases All changes maintain 100% backward compatibility.
1 parent 4bffd03 commit bfd9346

File tree

7 files changed

+482
-14
lines changed

7 files changed

+482
-14
lines changed

CHANGELOG.md

Lines changed: 65 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,71 @@
22

33
All notable changes to jAlert will be documented in this file.
44

5+
## [5.0.4] - 2025-06-27
6+
7+
### ✨ New Features
8+
9+
- **🔄 Dynamic Resize Functionality**: Added comprehensive modal resizing capabilities
10+
- `autoResize()` method to automatically resize modal to fit content
11+
- `resizeToFit()` alias method for content-based resizing
12+
- `resizeModal(width, height)` method for manual sizing
13+
- `autoResizeOnContentChange` option for automatic resizing when content changes
14+
- Global resize methods: `$.autoResize()`, `$.resizeToFit()`, `$.resizeModal(height)`
15+
- MutationObserver integration for detecting content changes
16+
- Comprehensive API documentation and interactive demos
17+
18+
- **📱 Enhanced Mobile/Tablet Support**: Improved button sizing and layout
19+
- Optimized button sizing for tablet devices (451px - 1024px viewport)
20+
- Better touch-friendly button padding and font sizes
21+
- Improved responsive layout for button containers
22+
- Enhanced user experience on touch devices
23+
24+
### 🔧 Technical Improvements
25+
26+
- **🛡️ Enhanced Error Handling**: Added defensive programming patterns
27+
- Robust guards in `animateAlert()` method to prevent undefined access errors
28+
- Improved error handling in `closeAlert()` method
29+
- Enhanced AJAX error handling with proper type checking
30+
- Better async scenario handling to prevent race conditions
31+
32+
- **🔗 API Consistency**: Standardized method access patterns
33+
- Consistent use of `.jAlert()` method instead of `.data('jAlert')` for API access
34+
- Better encapsulation and error prevention
35+
- Improved method chaining support
36+
37+
### 🐛 Bug Fixes
38+
39+
- **Async Safety**: Fixed `blurBackground` access errors in async scenarios
40+
- **Test Reliability**: Improved test stability in JSDOM environment
41+
- **AJAX Handling**: Enhanced error handling for AJAX content loading
42+
- **Memory Management**: Better cleanup of MutationObserver instances
43+
44+
### 📚 Documentation
45+
46+
- **Comprehensive Resize Documentation**: Added detailed API documentation
47+
- Usage examples for all resize methods
48+
- Configuration options and parameters
49+
- Advanced usage patterns and best practices
50+
- Interactive demos with real-time content changes
51+
52+
- **Enhanced Examples**: Added interactive resize demonstrations
53+
- Manual resize demo with dynamic content changes
54+
- Auto-resize demo with MutationObserver integration
55+
- Real-time content transformation examples
56+
57+
### 🧪 Testing
58+
59+
- **Improved Test Coverage**: Enhanced unit tests for resize functionality
60+
- **JSDOM Compatibility**: Fixed test compatibility issues with layout calculations
61+
- **Async Test Handling**: Better handling of async scenarios in test environment
62+
- **Defensive Test Patterns**: Added robust test patterns for edge cases
63+
64+
### 🔄 Breaking Changes
65+
66+
**None!** All changes maintain 100% backward compatibility.
67+
68+
---
69+
570
## [5.0.3] - 2025-06-26
671

772
### 🐛 Bug Fixes

dist/jAlert.min.css

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

dist/jAlert.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.

index.html

Lines changed: 195 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -132,7 +132,7 @@ <h4 class="align-center font-open-sans-normal-italic">jAlert is really easy, and
132132
<div class="row features">
133133
<div class="span4">
134134
<h3><i class="fa fa-expand"></i> Plenty-o Sizes</h3>
135-
<p>Completely responsive (just under full width on small screens), but for tablets and desktops, you have a lot of control over how large the alert is.</p>
135+
<p>Completely responsive (just under full width on small screens), but for tablets and desktops, you have a lot of control over how large the alert is. Enhanced tablet support with optimized button sizing for better touch interaction.</p>
136136
<a href='#' class='btn btn-primary jsize'>xsm</a>
137137
<a href='#' class='btn btn-primary jsize'>sm</a>
138138
<a href='#' class='btn btn-primary jsize'>md</a>
@@ -275,6 +275,10 @@ <h4><i class="fa fa-images"></i> Slideshow</h4>
275275
<a href='#' class='jslideshow-no-controls btn btn-primary'>No Controls</a>
276276
<a href='#' class='jslideshow-keyboard btn btn-primary'>Keyboard Only</a>
277277
<a href='#' class='jslideshow-dots-arrows btn btn-primary'>Dots + Arrows</a>
278+
<br><br>
279+
<h4><i class="fa fa-expand"></i> Dynamic Resize</h4>
280+
<a href='#' class='jresize btn btn-primary'>Manual Resize</a>
281+
<a href='#' class='jresize-auto btn btn-primary'>Auto-Resize on Change</a>
278282

279283
<script>
280284
// Image alerts
@@ -459,6 +463,60 @@ <h4><i class="fa fa-images"></i> Slideshow</h4>
459463
'size': 'lg'
460464
});
461465
</script>
466+
467+
<!-- Resize Demo Scripts -->
468+
<script>
469+
// Manual Resize Demo
470+
$('.jresize').on('click', function(e) {
471+
e.preventDefault();
472+
var modalContent = 'Short content.';
473+
$.jAlert({
474+
title: 'Manual Resize Demo',
475+
content: '<div id="manual-resize-content">' + modalContent + '</div>',
476+
size: 'sm',
477+
theme: 'blue',
478+
onOpen: function(alert) {
479+
window.currentManualResizeAlert = alert.data('jAlert');
480+
// Auto-change content after 3 seconds and trigger resize
481+
setTimeout(function() {
482+
$('#manual-resize-content').text('This is a much longer content that should trigger a resize when we call autoResize() manually.');
483+
window.currentManualResizeAlert.autoResize();
484+
}, 3000);
485+
}
486+
});
487+
});
488+
489+
// Auto-Resize on Change Demo
490+
$('.jresize-auto').on('click', function(e) {
491+
e.preventDefault();
492+
var modalContent = 'Small content.';
493+
$.jAlert({
494+
title: 'Auto-Resize on Change Demo',
495+
content: '<div id="auto-resize-content">' + modalContent + '</div>',
496+
size: 'sm',
497+
theme: 'green',
498+
autoResizeOnContentChange: true,
499+
onOpen: function(alert) {
500+
// Change content multiple times with varying sizes
501+
setTimeout(function() {
502+
$('#auto-resize-content').html('<h3>HUGE Content!</h3><p>This is a much larger content with multiple paragraphs and lots of text to demonstrate how the modal automatically resizes to fit the content. The autoResizeOnContentChange option is enabled, so the modal will automatically adjust its size whenever the content changes.</p><p>This should make the modal quite large to accommodate all this text.</p>');
503+
}, 2000);
504+
505+
setTimeout(function() {
506+
$('#auto-resize-content').text('Medium content with some additional text to make it a reasonable size.');
507+
}, 5000);
508+
509+
setTimeout(function() {
510+
$('#auto-resize-content').html('<h4>Large Content</h4><p>This is a large content block with a heading and some paragraphs. It should be bigger than medium but smaller than huge.</p><ul><li>List item 1</li><li>List item 2</li><li>List item 3</li></ul>');
511+
}, 8000);
512+
513+
setTimeout(function() {
514+
$('#auto-resize-content').text('Back to small content.');
515+
}, 11000);
516+
}
517+
});
518+
});
519+
</script>
462520
<h3 style="margin-top:20px"><i class="fa fa-adjust"></i>Blurred Background</h3>
463521
Popup an alert and blur all the background elements:<br><br>
464522
<a href='#' class='jblur btn btn-primary'>Image</a>
@@ -1306,6 +1364,142 @@ <h4>Utility Function</h4>
13061364
autoAdvanceInterval: 2000,
13071365
loop: true
13081366
});</code></pre>
1367+
1368+
<h3 class="font-bree-serif">Dynamic Resize Functionality</h3>
1369+
<p>jAlert now supports dynamic resizing of modals to fit content changes. This is particularly useful for modals with dynamic content that changes after the modal is opened.</p>
1370+
1371+
<h4>Basic Usage</h4>
1372+
<pre><code>// Manual resize to fit content
1373+
$.jAlert({
1374+
title: 'Dynamic Content',
1375+
content: '&lt;div id="dynamic-content"&gt;Short content&lt;/div&gt;'
1376+
});
1377+
1378+
// Later, after content changes
1379+
$('#dynamic-content').text('Much longer content that needs more space');
1380+
$('.jAlert').autoResize();
1381+
1382+
// Or use the global function
1383+
$.autoResize();</code></pre>
1384+
1385+
<h4>Auto-Resize on Content Changes</h4>
1386+
<pre><code>// Enable automatic resizing when content changes
1387+
$.jAlert({
1388+
title: 'Auto-Resize Demo',
1389+
content: '&lt;div id="auto-content"&gt;Initial content&lt;/div&gt;',
1390+
autoResizeOnContentChange: true
1391+
});
1392+
1393+
// Content changes will automatically trigger resize
1394+
$('#auto-content').html('&lt;h3&gt;New Content&lt;/h3&gt;&lt;p&gt;This will automatically resize the modal&lt;/p&gt;');</code></pre>
1395+
1396+
<h4>Resize Options</h4>
1397+
<table class="table table-bordered">
1398+
<thead>
1399+
<tr>
1400+
<th><strong>Option</strong></th>
1401+
<th><strong>Type</strong></th>
1402+
<th><strong>Default</strong></th>
1403+
<th><strong>Description</strong></th>
1404+
</tr>
1405+
</thead>
1406+
<tbody>
1407+
<tr>
1408+
<td>autoResizeOnContentChange</td>
1409+
<td>boolean</td>
1410+
<td>false</td>
1411+
<td>Automatically resize the modal when content changes (uses MutationObserver)</td>
1412+
</tr>
1413+
</tbody>
1414+
</table>
1415+
1416+
<h4>Resize Methods</h4>
1417+
<table class="table table-bordered">
1418+
<thead>
1419+
<tr>
1420+
<th><strong>Method</strong></th>
1421+
<th><strong>Sample</strong></th>
1422+
<th><strong>Params</strong></th>
1423+
<th><strong>Description</strong></th>
1424+
</tr>
1425+
</thead>
1426+
<tbody>
1427+
<tr>
1428+
<td>autoResize</td>
1429+
<td>$('.jAlert').autoResize();<br>OR<br>$.autoResize();</td>
1430+
<td>none</td>
1431+
<td>Automatically resize the modal to fit its current content (height only)</td>
1432+
</tr>
1433+
<tr>
1434+
<td>resizeToFit</td>
1435+
<td>$('.jAlert').resizeToFit();<br>OR<br>$.resizeToFit();</td>
1436+
<td>none</td>
1437+
<td>Alias for autoResize() - resize modal to fit content</td>
1438+
</tr>
1439+
<tr>
1440+
<td>resizeModal</td>
1441+
<td>$('.jAlert').resizeModal(null, 300);<br>OR<br>$.resizeModal(300);</td>
1442+
<td>height (optional)</td>
1443+
<td>Resize modal to specific height (in pixels) or auto-fit if no height provided</td>
1444+
</tr>
1445+
</tbody>
1446+
</table>
1447+
1448+
<h4>Advanced Usage</h4>
1449+
<pre><code>// Get the alert instance and call methods
1450+
const alert = $.jAlert('current');
1451+
if (alert) {
1452+
alert.autoResize();
1453+
alert.resizeModal(null, 400); // Set specific height
1454+
}
1455+
1456+
// Resize after AJAX content loads
1457+
$.jAlert({
1458+
ajax: 'dynamic-content.html',
1459+
onOpen: function(alert) {
1460+
// Content is loaded, now resize to fit
1461+
alert.autoResize();
1462+
}
1463+
});
1464+
1465+
// Resize after dynamic content changes
1466+
$('#dynamic-content').load('new-content.html', function() {
1467+
$('.jAlert').autoResize();
1468+
});</code></pre>
1469+
1470+
<h4>Notes</h4>
1471+
<ul>
1472+
<li>Resize functionality only adjusts <strong>height</strong> - width is controlled by the size option (sm, md, lg, etc.)</li>
1473+
<li>Auto-resize uses MutationObserver to detect content changes</li>
1474+
<li>Manual resize methods should be called after content changes are complete</li>
1475+
<li>Resize works with all content types: text, HTML, AJAX-loaded content, etc.</li>
1476+
</ul>
1477+
1478+
<h3 class="font-bree-serif">Enhanced Reliability & Performance</h3>
1479+
<p>jAlert v5.0.4 includes significant improvements to error handling and API consistency for better reliability in production environments.</p>
1480+
1481+
<h4>Enhanced Error Handling</h4>
1482+
<ul>
1483+
<li><strong>Defensive Programming</strong>: Added robust guards to prevent undefined access errors in async scenarios</li>
1484+
<li><strong>AJAX Error Handling</strong>: Improved error handling for AJAX content loading with proper type checking</li>
1485+
<li><strong>Async Safety</strong>: Better handling of race conditions and DOM removal timing</li>
1486+
<li><strong>Memory Management</strong>: Proper cleanup of MutationObserver instances and event handlers</li>
1487+
</ul>
1488+
1489+
<h4>API Consistency</h4>
1490+
<ul>
1491+
<li><strong>Standardized Access</strong>: Consistent use of <code>.jAlert()</code> method for API access</li>
1492+
<li><strong>Method Chaining</strong>: All methods return <code>this</code> for better chaining support</li>
1493+
<li><strong>Better Encapsulation</strong>: Improved error prevention through proper method access patterns</li>
1494+
<li><strong>Backward Compatibility</strong>: All changes maintain 100% compatibility with existing code</li>
1495+
</ul>
1496+
1497+
<h4>Mobile & Tablet Enhancements</h4>
1498+
<ul>
1499+
<li><strong>Optimized Button Sizing</strong>: Better touch-friendly button dimensions for tablet devices (451px - 1024px)</li>
1500+
<li><strong>Improved Layout</strong>: Enhanced responsive design for button containers and spacing</li>
1501+
<li><strong>Touch Interaction</strong>: Better padding and font sizes for improved user experience on touch devices</li>
1502+
</ul>
13091503
</section>
13101504
</div><!--end documentation-content-->
13111505

src/jAlert.css

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3821,4 +3821,26 @@ body.ja_blur > *:not(.ja_wrap) {
38213821
font-size: 12px;
38223822
padding: 8px;
38233823
}
3824+
}
3825+
3826+
/* Tablet button sizing */
3827+
@media (min-width: 451px) and (max-width: 1024px) {
3828+
.ja_btn {
3829+
padding: 8px 16px !important;
3830+
font-size: 16px !important;
3831+
display: inline-flex;
3832+
align-items: center;
3833+
justify-content: center;
3834+
}
3835+
3836+
.ja_btn_wrap {
3837+
margin-top: 15px;
3838+
margin-bottom: -15px;
3839+
}
3840+
3841+
.ja_btn_wrap.optBack {
3842+
margin-top: 30px;
3843+
margin: 30px -20px -20px -20px;
3844+
padding: 10px 0px;
3845+
}
38243846
}

0 commit comments

Comments
 (0)