Changeset 3296434
- Timestamp:
- 05/19/2025 12:16:45 PM (11 months ago)
- Location:
- oow-pjax
- Files:
-
- 46 added
- 2 edited
-
tags/1.5 (added)
-
tags/1.5/assets (added)
-
tags/1.5/assets/css (added)
-
tags/1.5/assets/css/oow-extensions.css (added)
-
tags/1.5/assets/css/oow-pjax-admin.css (added)
-
tags/1.5/assets/css/oow-pjax.css (added)
-
tags/1.5/assets/js (added)
-
tags/1.5/assets/js/oow-pjax-admin.js (added)
-
tags/1.5/assets/js/oow-pjax.js (added)
-
tags/1.5/includes (added)
-
tags/1.5/includes/class-oow-extensions.php (added)
-
tags/1.5/includes/class-oow-pjax.php (added)
-
tags/1.5/languages (added)
-
tags/1.5/languages/oow-pjax-ar.l10n.php (added)
-
tags/1.5/languages/oow-pjax-ar.mo (added)
-
tags/1.5/languages/oow-pjax-ar.po (added)
-
tags/1.5/languages/oow-pjax-en_US.l10n.php (added)
-
tags/1.5/languages/oow-pjax-en_US.mo (added)
-
tags/1.5/languages/oow-pjax-en_US.po (added)
-
tags/1.5/languages/oow-pjax-es_ES.l10n.php (added)
-
tags/1.5/languages/oow-pjax-es_ES.mo (added)
-
tags/1.5/languages/oow-pjax-es_ES.po (added)
-
tags/1.5/languages/oow-pjax-fr_FR.l10n.php (added)
-
tags/1.5/languages/oow-pjax-fr_FR.mo (added)
-
tags/1.5/languages/oow-pjax-fr_FR.po (added)
-
tags/1.5/languages/oow-pjax-hi_IN.l10n.php (added)
-
tags/1.5/languages/oow-pjax-hi_IN.mo (added)
-
tags/1.5/languages/oow-pjax-hi_IN.po (added)
-
tags/1.5/languages/oow-pjax-ja.l10n.php (added)
-
tags/1.5/languages/oow-pjax-ja.mo (added)
-
tags/1.5/languages/oow-pjax-ja.po (added)
-
tags/1.5/languages/oow-pjax-pt_BR.l10n.php (added)
-
tags/1.5/languages/oow-pjax-pt_BR.mo (added)
-
tags/1.5/languages/oow-pjax-pt_BR.po (added)
-
tags/1.5/languages/oow-pjax-pt_PT.l10n.php (added)
-
tags/1.5/languages/oow-pjax-pt_PT.mo (added)
-
tags/1.5/languages/oow-pjax-pt_PT.po (added)
-
tags/1.5/languages/oow-pjax-ru_RU.l10n.php (added)
-
tags/1.5/languages/oow-pjax-ru_RU.mo (added)
-
tags/1.5/languages/oow-pjax-ru_RU.po (added)
-
tags/1.5/languages/oow-pjax-zh_CN.l10n.php (added)
-
tags/1.5/languages/oow-pjax-zh_CN.mo (added)
-
tags/1.5/languages/oow-pjax-zh_CN.po (added)
-
tags/1.5/languages/oow-pjax.pot (added)
-
tags/1.5/oow-pjax.php (added)
-
tags/1.5/readme.txt (added)
-
trunk/assets/js/oow-pjax.js (modified) (6 diffs)
-
trunk/readme.txt (modified) (8 diffs)
Legend:
- Unmodified
- Added
- Removed
-
oow-pjax/trunk/assets/js/oow-pjax.js
r3282551 r3296434 2 2 * OOW PJAX JavaScript - Handles PJAX (PushState + AJAX) navigation with space-separated selectors and custom JS support. 3 3 * @module OOWPJAX 4 * @credits Special thanks to @long-dotcom for identifying the btoa InvalidCharacterError issue with Unicode characters 5 * and suggesting a safeBase64Encode solution to handle non-Latin1 characters in inline styles. 4 6 */ 5 7 … … 221 223 } 222 224 223 224 225 /** 225 226 * Extracts stylesheets (<link> and <style>) from an HTML document. … … 230 231 const stylesheets = []; 231 232 232 // R écupérer les balises <link rel="stylesheet">233 // Retrieve <link rel="stylesheet"> tags 233 234 const linkElements = doc.querySelectorAll('link[rel="stylesheet"]'); 234 235 linkElements.forEach((link) => { … … 239 240 }); 240 241 241 // R écupérer les balises <style>242 // Retrieve <style> tags 242 243 const styleElements = doc.querySelectorAll('style'); 243 244 styleElements.forEach((style) => { … … 250 251 log('Stylesheets extracted:', stylesheets); 251 252 return stylesheets; 253 } 254 255 /** 256 * Encodes a string to base64, safely handling Unicode characters. 257 * @param {string} str - String to encode. 258 * @returns {string} Base64-encoded string. 259 * @credits Inspired by @long-dotcom's suggestion to handle Unicode characters in btoa. 260 */ 261 function safeBase64Encode(str) { 262 try { 263 return btoa( 264 encodeURIComponent(str).replace(/%([0-9A-F]{2})/g, (match, p1) => 265 String.fromCharCode(parseInt(p1, 16)) 266 ) 267 ); 268 } catch (error) { 269 log('Error during base64 encoding for stylesheet:', error.message); 270 console.error('Error during base64 encoding:', error); 271 return btoa(''); // Fallback value 272 } 252 273 } 253 274 … … 291 312 } 292 313 } else if (stylesheet.tag === 'style') { 293 if (!document.querySelector(`style[data-content="${btoa(stylesheet.content)}"]`)) { 314 // Check if style already exists using safeBase64Encode 315 const encodedContent = safeBase64Encode(stylesheet.content); 316 if (!document.querySelector(`style[data-content="${encodedContent}"]`)) { 294 317 const style = document.createElement('style'); 295 318 style.textContent = stylesheet.content; 296 style.setAttribute('data-content', btoa(stylesheet.content));319 style.setAttribute('data-content', encodedContent); 297 320 document.head.appendChild(style); 298 321 log('Inline style added'); -
oow-pjax/trunk/readme.txt
r3282551 r3296434 1 1 === OOW PJAX === 2 Contributors: oowpress 2 Contributors: oowpress, long-dotcom 3 3 Donate link: https://profiles.wordpress.org/oowpress/ 4 4 Tags: pjax, ajax navigation, persistent player, page transition, vanilla javascript 5 5 Requires at least: 5.0 6 6 Tested up to: 6.8 7 Stable tag: 1. 47 Stable tag: 1.5 8 8 Requires PHP: 5.2 9 9 License: GPLv2 or later … … 27 27 - **Interactive Landing Pages**: Deliver immersive experiences for marketing campaigns or event sites with uninterrupted navigation. 28 28 29 Version 1. 4 enhances security with dynamic nonce refreshing, improves style management with asynchronous stylesheet handling, and refines form redirect handling, making OOW PJAX more robustfor complex WordPress sites.29 Version 1.5 introduces a critical fix for handling Unicode characters (e.g., Chinese, emojis) in inline styles, preventing `InvalidCharacterError` issues with `btoa`. This update, contributed by **@long-dotcom**, ensures robust style management for multilingual and emoji-rich sites. It also enhances security with dynamic nonce refreshing, improves asynchronous stylesheet handling, and refines form redirect handling, making OOW PJAX more reliable for complex WordPress sites. 30 30 31 31 ### Key Features … … 43 43 - **Secure Implementation**: Uses dynamic nonces, sanitization, and strict validation for all settings and AJAX requests. 44 44 - **Script Priority Control**: Customize the loading order of `oow-pjax.js` in the footer for compatibility. 45 - **Dynamic Style Management**: Injects and manages page-specific stylesheets and inline styles asynchronously during PJAX transitions.45 - **Dynamic Style Management**: Injects and manages page-specific stylesheets and inline styles asynchronously, now with Unicode support. 46 46 - **Advanced Script Execution**: Re-executes scripts in updated containers or footer, with control over inline scripts and validation. 47 47 - **CodeMirror Integration**: Edit Custom JS with syntax highlighting and a Dracula theme. 48 - **Unicode Support for Styles**: Safely handles non-Latin1 characters (e.g., Chinese, emojis) in inline styles without errors (new in 1.5). 48 49 49 50 ### Who Needs OOW PJAX? … … 69 70 7. **Form Handling**: Submits forms via AJAX, supporting explicit comment nonces and server-side redirects (e.g., 301, 302). 70 71 8. **Script Management**: Re-executes scripts in updated containers or footer, with custom JS execution before/after navigation. 71 9. **Style Injection**: Asynchronously injects page-specific stylesheets and inline styles for consistent rendering.72 9. **Style Injection**: Asynchronously injects page-specific stylesheets and inline styles, now with robust Unicode support. 72 73 73 74 ### Getting Started … … 121 122 122 123 = Does it support AJAX form submissions? = 123 Yes, enable **Enable Form Handling** to submit forms (e.g., comments, login, contact) via AJAX. Version 1. 4enhances this with explicit comment nonce support, dynamic nonce refreshing, and robust redirect handling (e.g., 301, 302).124 Yes, enable **Enable Form Handling** to submit forms (e.g., comments, login, contact) via AJAX. Version 1.5 enhances this with explicit comment nonce support, dynamic nonce refreshing, and robust redirect handling (e.g., 301, 302). 124 125 125 126 = How do I style the loading animation? = … … 141 142 Yes, use the **Custom JS** tab to add JavaScript before or after PJAX navigation with CodeMirror’s syntax highlighting. 142 143 143 = How does version 1. 4 improve formhandling? =144 Version 1. 4 builds on version 1.3 by adding dynamic nonce refreshing for form submissions and improved redirect handling, ensuring compatibility with complex forms and reducing nonce expiration errors.144 = How does version 1.5 improve style handling? = 145 Version 1.5 adds support for Unicode characters (e.g., Chinese, emojis) in inline styles, fixing `InvalidCharacterError` issues with `btoa`. Thanks to @long-dotcom for the contribution. 145 146 146 147 = How does OOW PJAX handle page-specific styles? = 147 Version 1. 4 introduces asynchronous stylesheet management, extracting and applying `<link>` and `<style>` tags during PJAX transitions to ensure consistent rendering without duplicates.148 149 = Why are nonces refreshed dynamically in version 1.4? =148 Version 1.5 enhances asynchronous stylesheet management, extracting and applying `<link>` and `<style>` tags during PJAX transitions, with full Unicode support for consistent rendering. 149 150 = Why are nonces refreshed dynamically? = 150 151 Dynamic nonce refreshing prevents errors from expired nonces during long sessions or high-traffic scenarios, enhancing security and reliability for AJAX requests. 151 152 … … 159 160 160 161 == Changelog == 162 163 = 1.5 = 164 * **Fixed**: `InvalidCharacterError` in `btoa` when handling Unicode characters (e.g., Chinese, emojis) in inline styles by adding `safeBase64Encode` function. Credits to @long-dotcom for identifying the issue and suggesting a solution. 165 * **Improved**: Enhanced `applyStylesheetsAsync` to use `safeBase64Encode` for robust style management with non-Latin1 characters. 166 * **Fixed**: Minor JSDoc typo in `isCacheValid` for improved documentation clarity. 161 167 162 168 = 1.4 = … … 209 215 == Upgrade Notice == 210 216 217 = 1.5 = 218 Upgrade to version 1.5 for robust Unicode support in inline styles, fixing `InvalidCharacterError` with `btoa`. This update, contributed by @long-dotcom, enhances compatibility with multilingual and emoji-rich sites, alongside improved style management. Recommended for all users. 219 211 220 = 1.4 = 212 221 Upgrade to version 1.4 for dynamic nonce refreshing, asynchronous stylesheet management, and improved form redirect handling. This update enhances security, compatibility with dynamic styles, and debugging capabilities. Recommended for all users.
Note: See TracChangeset
for help on using the changeset viewer.