File tree Expand file tree Collapse file tree 1 file changed +19
-1
lines changed
Expand file tree Collapse file tree 1 file changed +19
-1
lines changed Original file line number Diff line number Diff line change @@ -13,9 +13,27 @@ const breadcrumbs = window.location.pathname
1313 . replace ( ".html" , "" )
1414 . split ( "-" ) ;
1515
16+ /**
17+ * Asynchronously loads an HTML fragment into the given element.
18+ *
19+ * If the element matching `selector` exists, its content will be replaced
20+ * with the contents of the file at `url`. The returned Promise resolves
21+ * when the load succeeds, and rejects if the request fails. If no matching
22+ * element is found, the Promise resolves immediately with no action taken.
23+ *
24+ * @param {string } selector - jQuery selector for the target element.
25+ * @param {string } url - Path or URL of the HTML file to load.
26+ * @returns {Promise<void> } Promise that resolves when the section is loaded.
27+ */
1628function loadSection ( selector , url ) {
1729 return new Promise ( ( resolve , reject ) => {
18- $ ( selector ) . load ( url , function ( response , status ) {
30+ const $el = $ ( selector ) ;
31+ if ( $el . length === 0 ) {
32+ resolve ( ) ; // nothing to do
33+ return ;
34+ }
35+
36+ $el . load ( url , function ( response , status ) {
1937 if ( status === "error" ) {
2038 reject ( new Error ( `Failed to load ${ url } ` ) ) ;
2139 } else {
You can’t perform that action at this time.
0 commit comments