Library Reference
JS Library

Events

11min
dom events execute functions when dom is fully loaded klevu ready(object or functionsource) when the document is in ready state klevu isready will be true name name of the function to be executed – unique per event fire source code of the execution klevu interactive(object or functionsource) when the document enters the interactive state, if possible to detect or latest when the document is ready, when dom is in this state klevu isinteractive will be true name name of the function to be executed – unique per event fire source code of the execution example klevu ready( function(){ console log("document is loaded") } ); defined events (attach) bind an event handler to the javascript event klevu event attach function ( target , event , callback , usecapture ) target – dom node target event – js event name , refer to the mdn event reference list https //developer mozilla org/en us/docs/web/events for support callback – function to be executed when event is fired usecapture – default false – a boolean indicating whether events of this type will be dispatched to the registered listener before being dispatched to any eventtarget beneath it in the dom tree example klevu event attach( document getelementsbytagname("body")\[0], "click", function(){ console log("document is loaded") } ); search events a list of search events and functions that help the power up of the search box and landing page these are stored as part of the klevu searchevents formatted as follows box focus – responsible for preprocessing the focus event and executing the scope chain chains events focus keyup – responsible for preprocessing the keyup event and executing the scope chain chains events keyup submit – responsible for preprocessing the submit event and executing the scope chain chains events submit general documentclick – responsible for preprocessing the document click event and executing the global chain documentclick documentscroll – responsible for preprocessing the document scroll event and executing the global chain documentscroll functions bindallextraevents – activates the documentclick and documentscroll events bindallsearchboxes – selects all predefined boxes based on the selector and clones a base box for each one, also links the events for focus,keyup and submit we automatically add a coreevent named buildsearch that will execute when the document is in interactive state the base search instance is build this event will execute the bindallsearchboxes bindallextraevents core events core events are custom build and executed events the event will generate a klevuchain there is no data or scope on the created chain the chain will execute from the time of creation for maxcount times with an interval of delay or until the event evaluates to true via the fire function if the event has already executed any promise or attachment will be fired immediately interfaces build function ( object ) – used to build a core event and define its functionality fire function ( name ) – check if event chain can be executed and if yes execute it, stop the internal checking attach function ( name , object ) – attach a function to event chain name is the name of the even declared when building the event object contains name name of the function to be executed – unique per event fire source code of the execution a function can be sent instead of the object promise function ( name , object ) – promise function to event chain , same as attach elements a coreevent element has the following possible parameters name – event name, must be unique and will be used as reference in the attachments building a already defined event will override fire function and can lead to unforeseen situations delay – used to reference the delay between checks in ms default 0 ms maxcount – maximum number of repetitions until the event is abandoned default 100 fire – function source that returns true/false , will be used to check when event chain will fire example klevu coreevent build({ name "testklevuevent", fire function(){ if ( !klevu isready) { return false; } return true; }, maxcount 500, delay 30 }); klevu coreevent attach("testklevuevent", function(){ console log("klevu is ready"); } );