Skip to content

Commit 898ce22

Browse files
committed
Enhance AddToAny component by initializing script loading and reinitializing on updates for improved functionality
1 parent 93b25e3 commit 898ce22

File tree

1 file changed

+29
-1
lines changed

1 file changed

+29
-1
lines changed

themes/icarus/layout/share/addtoany.jsx

Lines changed: 29 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,20 @@ const { cacheComponent } = require('hexo-component-inferno/lib/util/cache');
1313
* <AddToAny />
1414
*/
1515
class AddToAny extends Component {
16+
componentDidMount() {
17+
// Initialize AddToAny after component mounts
18+
if (typeof window !== 'undefined' && window.a2a) {
19+
window.a2a.init_all();
20+
}
21+
}
22+
23+
componentDidUpdate() {
24+
// Reinitialize when component updates
25+
if (typeof window !== 'undefined' && window.a2a) {
26+
window.a2a.init_all();
27+
}
28+
}
29+
1630
render() {
1731
return <Fragment>
1832
<div class="a2a_kit a2a_kit_size_32 a2a_default_style" data-a2a-url="" data-a2a-title="">
@@ -25,7 +39,21 @@ class AddToAny extends Component {
2539
<a class="a2a_button_whatsapp"></a>
2640
<a class="a2a_dd" target="_blank" rel="noopener" href="https://www.addtoany.com/share"></a>
2741
</div>
28-
<script src="https://static.addtoany.com/menu/page.js"></script>
42+
<script dangerouslySetInnerHTML={{
43+
__html: `
44+
(function() {
45+
if (!window.a2aScriptLoaded) {
46+
window.a2aScriptLoaded = true;
47+
var script = document.createElement('script');
48+
script.async = true;
49+
script.src = 'https://static.addtoany.com/menu/page.js';
50+
document.head.appendChild(script);
51+
} else if (window.a2a) {
52+
window.a2a.init_all();
53+
}
54+
})();
55+
`
56+
}} />
2957
</Fragment>;
3058
}
3159
}

0 commit comments

Comments
 (0)