This documentation provides instructions on how to use the Project Endings staticSearch Generator to provide a fully-functional search ‘engine’ to your website without any dependency on server-side code such as a database.
If you are a programmer, you may want to write your own code to interact with staticSearch in some way. To make it easier to work with the JavaScript that runs on the search page, the StaticSearch object dispatches a number of CustomEvents which you can listen for in your own code. These are the events:
ssInstantiated: This event is dispatched at the end of the constructor for the StaticSearch object,
indicating that it is instantiated and you may access its properties and methods.ssJsonRetrieved: This is dispatched when the StaticSearch object has completed its initial retrieval
of the core JSON required to handle searches.ssSearchStarting: This is dispatched when the user has initiated a search operation.ssFormCleared: This is dispatched when the user has cleared the search form.ssSearchCompleted: This is dispatched when a search has been completed and the results displayed on
the search page. This event carries additional information in its detail property: an integer which is the count of the number of hit documents found.You can use these events in your code in the following way:
var showMessage = function(){ alert('The StaticSearch instance has been constructed!'); } window.addEventListener('ssInstantiated', showMessage); ⚓
In the case of the ssSearchCompleted event, you could do this:
var showMessage = function(evt){ alert(evt.detail.hits + ' documents found!'); } window.addEventListener('ssSearchCompleted', showMessage); ⚓