@@ -38,6 +38,36 @@ search features, you can delete those elements from the HTML.
38
38
</script >
39
39
```
40
40
41
+ 3 . If your Squarespace template has AJAX loading enabled (most modern ones do),
42
+ then you'll have to change the ` window.onload ` portion of pasta.js to use
43
+ ` Squarespace.onInitialize ` instead. Since that function can fire when you
44
+ navigate away from the data search page, it can throw errors that would be
45
+ visible in your browser console since your other pages don't have the same
46
+ elements as your data search page. To get around that, you can have the
47
+ pasta.js code only execute when a specific element id is found on the page,
48
+ such as the search form which has an id of ` dataSearchForm ` . The code edits
49
+ look like the example below.
50
+
51
+ ``` js
52
+ // We're toward the end of the pasta.js code here
53
+ // We commented out the window.onload function to replace it
54
+ // window.onload = function () {
55
+ window .Squarespace .onInitialize (Y , function () {
56
+ // This snippet prevents this code from running on other pages
57
+ var searchEl = document .getElementById (" dataSearchForm" );
58
+ if (! searchEl)
59
+ return ;
60
+
61
+ // Rest of code that was in the onload function goes here
62
+ function initApp (expanded ) {
63
+ // ...snip...
64
+
65
+ // The last line of the file was a close braket for the onload function.
66
+ // For Squarespace.onInitialize, we need a bracket AND a paren.
67
+ // }; // commented out the ending for onload
68
+ }); // New ending which fits Squarespace.onInitialize
69
+ ` ` `
70
+
41
71
## Task 4. Add CSS
42
72
43
73
The style rules for the application need to be added under custom CSS for the
0 commit comments