This implements the Script Mode NATIVEADS_QUEUE
interface. This
obviates the need to have an onReady
callback. Client code must
initialize the queue to an empty array if it does not exist already:
window.NATIVEADS_QUEUE = window.NATIVEADS_QUEUE || [];
Queue up API functions by calling the push
function with an array argument.
The first item in the array is the name of the API function. Subsequent items
are the arguments for the function call:
window.NATIVEADS_QUEUE.push(["setPropertyID", "NA-TEST-11235814"]);
window.NATIVEADS_QUEUE.push(["logging.enable"]);
You can push multiple commands at once:
window.NATIVEADS_QUEUE.push(["setPropertyID", "NA-TEST-11235814"],
["logging.enable"]);
You can also push functions:
window.NATIVEADS_QUEUE.push(function() {
do_something();
});
When the plugin loads, it reads the queue and executes it; if the plugin has
already loaded, then calling the push function will execute the command
immediately. Client code may be written in such a way that it doesn't matter
if the native ads plugin has loaded yet or not. Do not assume that
NATIVEADS_QUEUE
is always an array; only call the push
function and
nothing else.
Methods
-
push(command)
-
Parameters:
Name Type Description command
array | function Execute one or more plugin commands. If the plugin has not yet loaded, then it will run your commands later.
Each command may be either an array or a function.
An array command will run a plugin
API
method. The first item in the array must be a string whose name is a method in theAPI
. The remaining array items will be the arguments passed to the method.A function command will simply be called. Do not assume any particular context (
this
).