Skip to content

Commit

Permalink
update squarespace instructions to handle ajax loading
Browse files Browse the repository at this point in the history
  • Loading branch information
twhiteaker committed Aug 2, 2019
1 parent 6a68c8c commit 2ca31d0
Showing 1 changed file with 30 additions and 0 deletions.
30 changes: 30 additions & 0 deletions squarespace.md
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,36 @@ search features, you can delete those elements from the HTML.
</script>
```

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
Expand Down

0 comments on commit 2ca31d0

Please sign in to comment.