diff --git a/squarespace.md b/squarespace.md index 5d178b6..3867494 100644 --- a/squarespace.md +++ b/squarespace.md @@ -38,6 +38,36 @@ search features, you can delete those elements from the HTML. ``` +3. If your Squarespace template has AJAX loading enabled (most modern ones do), + then you'll have to change the `window.onload` portion of pasta.js to use + `Squarespace.onInitialize` instead. Since that function can fire when you + navigate away from the data search page, it can throw errors that would be + visible in your browser console since your other pages don't have the same + elements as your data search page. To get around that, you can have the + pasta.js code only execute when a specific element id is found on the page, + such as the search form which has an id of `dataSearchForm`. The code edits + look like the example below. + +```js +// We're toward the end of the pasta.js code here +// We commented out the window.onload function to replace it +// window.onload = function () { +window.Squarespace.onInitialize(Y, function() { + // This snippet prevents this code from running on other pages + var searchEl = document.getElementById("dataSearchForm"); + if (!searchEl) + return; + + // Rest of code that was in the onload function goes here + function initApp(expanded) { + // ...snip... + +// The last line of the file was a close braket for the onload function. +// For Squarespace.onInitialize, we need a bracket AND a paren. +// }; // commented out the ending for onload +}); // New ending which fits Squarespace.onInitialize +``` + ## Task 4. Add CSS The style rules for the application need to be added under custom CSS for the