Skip to content

Banner Navigator plugin

Use the banner navigator plugin to navigate between banners, manage banner state, and respond to navigation events. The navigator instance is bound to the Vue instance as $navigator. To access the banner navigation methods, use the this.$navigator context in a Vue file of your banner project.

The banner navigator plugin exposes its methods using this context:

js
this.$navigator

Usage

You can use the banner navigator plugin to navigate between banners, retrieve information about the current banner, register callbacks for navigation events, and get templated components. Use the banner navigator plugin with the this.$navigator context in a Vue file: for example, a banner index.vue file or the App.vue file in your banner project.

Methods

The banner navigator plugin provides the following methods to help you navigate between banners, access banner data, and monitor navigation events:

goTo

The goTo method navigates to a specific banner by its ID.

js
this.$navigator.goTo(bannerId)

Parameters of goTo

The goTo method has the following parameters.

ParameterTypeDefaultDescription
bannerIdStringNARequired parameter. The ID of the banner to navigate to. For example, goTo('skyscraper').

goToNext

The goToNext method navigates to the next banner in the list.

js
this.$navigator.goToNext()

goToPrev

The goToPrev method navigates to the previous banner in the list.

js
this.$navigator.goToPrev()

getCurrentBanner

The getCurrentBanner method returns information about the currently active banner.

js
this.$navigator.getCurrentBanner()

Return value

The method returns a BannerItem object with the following structure:

FieldTypeDescription
idStringThe unique identifier of the banner.
nameStringThe user-friendly name of the banner.
sizeObjectThe banner size information.
size.widthNumberThe banner width in pixels.
size.heightNumberThe banner height in pixels.
size.dprNumberThe device pixel ratio for the banner.
js
const currentBanner = this.$navigator.getCurrentBanner();
console.log(`Current banner: ${currentBanner.name}`);
console.log(`Size: ${currentBanner.size.width}x${currentBanner.size.height}`);

getTemplatedComponents

The getTemplatedComponents method returns an array of banner components that use templates.

js
this.$navigator.getTemplatedComponents()

Return value

The method returns an array of BannerComponent objects. Each component object contains information about templated components used in the banners.

Example usage

js
const components = this.$navigator.getTemplatedComponents();
console.log('Templated components:', components);

The banner navigator plugin provides hooks that allow you to register callbacks for navigation lifecycle events.

onenter

The onenter hook registers a callback function that is invoked when a banner is entered.

js
this.$navigator.onenter(handler, options)

Parameters of onenter

ParameterTypeDefaultDescription
handlerFunctionNARequired parameter. A callback function to be executed when a banner is entered.
optionsObject{}Optional parameter. Additional options for the hook.

Example usage

js
this.$navigator.onenter(() => {
  console.log('Banner entered:', this.$navigator.getCurrentBanner().id);
});

onleave

The onleave hook registers a callback function that is invoked when a banner is left.

js
this.$navigator.onleave(handler, options)

Parameters of onleave

ParameterTypeDefaultDescription
handlerFunctionNARequired parameter. A callback function to be executed when a banner is left.
optionsObject{}Optional parameter. Additional options for the hook.

Example usage

js
this.$navigator.onleave(() => {
  console.log('Banner left:', this.$navigator.getCurrentBanner().id);
});

onbeforeenter

The onbeforeenter hook registers a callback function that is invoked before a banner is entered.

js
this.$navigator.onbeforeenter(handler, options)

Parameters of onbeforeenter

ParameterTypeDefaultDescription
handlerFunctionNARequired parameter. A callback function to be executed before a banner is entered.
optionsObject{}Optional parameter. Additional options for the hook.

Example usage

js
this.$navigator.onbeforeenter(() => {
  console.log('About to enter banner:', this.$navigator.getCurrentBanner().id);
});

onbeforeleave

The onbeforeleave hook registers a callback function that is invoked before a banner is left.

js
this.$navigator.onbeforeleave(handler, options)

Parameters of onbeforeleave

ParameterTypeDefaultDescription
handlerFunctionNARequired parameter. A callback function to be executed before a banner is left.
optionsObject{}Optional parameter. Additional options for the hook.

Example usage

js
this.$navigator.onbeforeleave(() => {
  console.log('About to leave banner:', this.$navigator.getCurrentBanner().id);
});

Complete example

Here's a complete example showing how to use the banner navigator plugin:

js
export default {
  mounted() {
    // Register navigation hooks
    this.$navigator.onbeforeenter(() => {
      console.log('Before entering banner');
    });

    this.$navigator.onenter(() => {
      const current = this.$navigator.getCurrentBanner();
      console.log(`Entered banner: ${current.name}`);
      console.log(`Size: ${current.size.width}x${current.size.height}`);
    });

    this.$navigator.onbeforeleave(() => {
      console.log('Before leaving banner');
    });

    this.$navigator.onleave(() => {
      console.log('Left banner');
    });
  },

  methods: {
    navigateNext() {
      this.$navigator.goToNext();
    },

    navigatePrev() {
      this.$navigator.goToPrev();
    },

    navigateTo(bannerId) {
      this.$navigator.goTo(bannerId);
    }
  }
}