Javascript API

The javascript API consists of two parts, one is the events triggered by the plugin, and methods, which you can use to trigger specific events.


Events list

You can get the actual events list by typing

ASP.printEventsList();

to your browser console. It will print out the event names with explanations and arguments list.

The events are fired on the main search container element which you can target with ".asp_main_container" class selector. For example attaching an event handler before the search starts:

$(".asp_main_container").on("asp_search_start", function(event, id, instance, phrase) { 
  console.log(id, instance, phrase); 
});

Common arguments

All of the events will always pass on these three arguments (+ additional if defined):

  • event (object) - a common javascript event object, always passed in event handlers
  • id (integer) - the search ID. This is the same as the one in the shortcode.
  • instance (integer) - the instance number of the current search ID. This will help if the same search shortcode is used multiple times on the same page.

Triggering Events/Functions

You can get the registered puglic functions list by typing

ASP.printFunctionsList();

to your browser console. It will print out the event names with explanations and arguments list.

To call a pre-defined event, use either version of the following function:

ASP.api( id, function_name);
ASP.api( id, instance, function_name);
ASP.api( id, function_name, args);
ASP.api( id, instance, function_name, args);

Function arguments

  • id (integer) - the search ID. This is the same as the one in the shortcode. If id=0, then the call applies to all visible search instances on the page.
  • instance (integer) - the instance number of the current search ID. This will help if the same search shortcode is used multiple times on the same page.
  • function_name - the event/function you want to trigger
  • args - arguments passed to the triggered function

Examples

Search for a specific phrase on search ID 1:

ASP.api(1, "searchFor", "search phrase");

Similarly, but only on instance 1:

ASP.api(1, 1, "searchFor", "search phrase");

Search all visible instances:

ASP.api(0, "searchFor", "search phrase");

Settings

Toggle search settings box on/off:

ASP.api(1, "toggleSettings");

// ..or specific instance with the same search ID only
ASP.api(1, 2, "toggleSettings");

Explicitly show/hide the settings:

// show
ASP.api(1, "toggleSettings", "show");

// hide
ASP.api(1, "toggleSettings", "hide");

// show-hide setting of all visible instances
ASP.api(0, "toggleSettings", "show");
ASP.api(0, "toggleSettings", "hide");

Results

To hide the results window:

ASP.api(1, "closeResults");

// close all open result boxes
ASP.api(0, "closeResults");

// ..or specific instance with the same search ID only
ASP.api(1, 2, "closeResults");

results matching ""

    No results matching ""