Web Export
  • Introduction
  • Getting Started
  • Install the Plugin
  • Create or open a project
  • Export the Artboard
  • Export Artboard Dialog
    • File Name
    • Subdirectory
    • Page Title
    • Web Page Template
    • Expected HTML Output
    • Stylesheet Name
    • Artboard Stylesheet template
    • Expected Stylesheet output
    • Script Page options
    • Images
    • Export Folder
    • Server
    • Alternative Fonts
    • Scale to fit
    • Centering the page
    • Styles Inline
    • Style via Classes
    • Markup Only
    • Outline Elements
    • Keyboard Navigation
    • Add Data Name
    • Add Image Compare
    • Auto Refresh
    • Export type
    • Reset Artboard
  • Addressing Export Issues
  • Messages Console
  • Export types
    • Export to a Single Page
    • Export to Multiple Pages
    • Export Artboards and show by size (media query)
    • Export to a Slideshow
  • Keyboard Shortcuts
  • Responsive Pages
  • Dynamical page that grows in height
  • Modifying Individual Elements
  • Elements and Sub Elements
  • Styling elements
  • Element Options
    • Id field
    • Tag Name
    • Styles
    • Classes
    • Attributes
    • Hyperlink
    • Width and Height Size
    • Background
    • Markup Inside
    • Markup Before and Markup After
    • Text Ids
    • Text Tokens
    • Row Layout
    • Column Layout
    • Overflow
    • Script Template
    • CSS Template
    • HTML Template
    • Layout Section
      • Layout Position types
      • Layout Position Location Types
      • Layout sizing options
    • Centered, Constraint and Anchored Positioning
    • Debug Element
    • Show Outline
    • Export as Image
    • Export as String
    • Export element
    • Displayed
    • Auto Export
    • Export (artboard)
    • Show Markup
    • Show CSS
    • Show Property Changes
    • Reset All Property changes
    • Navigation Buttons
  • Changed Properties
  • How to section
    • Creating a hover menu
    • Centering a page or element
    • Showing Overlays
    • Embedding an HTML page
    • Linking to pages or views
    • Creating a download link
    • Creating List items
    • Embedding Fonts
    • Adding Hover Effects
    • Styling Hyperlinks
    • Showing elements by size
    • Creating a Fixed Header
    • Make a Stretchable Line
    • Blend Modes
  • Creating Code Blocks
  • How Exporting Works
  • Single Page Application API
  • Element Tokens
  • Template Tokens
  • Setting up a server
  • Putting your site online
  • Code Block Snippets
    • Adding a cursor over on hover
    • Go to next or previous artboard with swipe gesture
  • Other Features
    • Gradients
    • Blend Modes
    • Form Elements
  • Learning by Videos
  • WordPress Integration
    • Summary
    • Export the main page
  • Example Packages
  • Web Developers
  • Non Web Developers
  • Debugging
  • Version
  • Support
    • Forums
    • Discord Channel
  • License
  • Feature and Bug Reports
  • Related Plugins
Powered by GitBook
On this page

Was this helpful?

Single Page Application API

The API for the single page application

With a Single Page Application you can export multiple artboards to one page. Using the application API you can switch pages.

When an artboard or artboards are exported to a web page they become a view. That is the term we use to describe the artboard on the web page.

The documentation is a work in progress.

Settings using CSS Variables

In a Single Page Application the CSS in the root tag has the list of artboard views and options for that page:

:root {
    --web-view-ids: Cats,Whiskers,Mittens,Snowball,Ending;
    --web-view-name: Cats;
    --web-view-id: Cats;
    --web-scale-to-fit: false;
    --web-scale-to-fit-type: default;
    --web-enable-scale-up: false;
    --web-scale-on-resize: false;
    --web-show-scale-controls: false;
    --web-scale-on-double-click: false;
    --web-center-horizontally: false;
    --web-center-vertically: false;
    --web-actual-size-on-double-click: false;
    --web-navigate-on-keypress: false;
    --web-refresh-for-changes: false;
    --web-add-image-compare: false;
    --web-application: true;
    --web-show-navigation-controls: false;
    --web-enable-deep-linking: true;
}

When the page loads it looks for media queries that contains a rule with an ID that matches the name of the artboard:

@media (min-width: 0px) {
    #Cats {
        width: 960px;
        height: 630px;
        background-color: rgba(247,247,247,1);
        overflow: hidden;
        margin: 0;
        padding: 0;
        --web-view-name: Cats;
        --web-view-id: Cats;
        --web-center-horizontally: true;
        --web-application: true;
        --web-enable-deep-linking: true;
    }
}

When the page loads it shows the view defined in the root selector. This is usually the first artboard.

The order the artboards are displayed are based on their position in the layers panel. To reorder the artboards reorder the artboard layers.

You can show different views by using the goToState() method.

application.goToState("Cats");

To get a list of views use the getViewIds():

application.getViewIds();

To get a reference to a view use getViewById():

var view = application.getViewById("Whiskers")

To show a view (without hiding the others) use:

var view = application.getViewById("Whiskers")
application.showView(view);

The views contains a dictionary of the view name and element:

var views = application.views;
var view = views["Cats"];

To hide all views use the hideViews() method:

application.hideViews();

To get the current or selected view use getVisibleView():

var view = self.getVisibleView();

When you change views a viewChange event is dispatched.

window.addEventListener(self.NAVIGATION_CHANGE, myViewChangeHandler);

When the application is ready an applicationComplete event is dispatched:

window.dispatchEvent(new Event(self.APPLICATION_COMPLETE));

To update the URL fragment use the updateURL() method;

 var view = application.getViewById("Cats");
 application.updateURL(view);

Or use the syncronizeViewToURL() to load the view that is in the URL fragment:

 application.syncronizeViewToURL();

You can go to the next or previous view using the nextView() and previousView() methods. The views are ordered in the --web-view-ids CSS variable:

application.nextView();
application.previousView();

You may be able to add your own views or nest states via media queries.

You can use the showStateFunction(view, state)to choose if a view should be shown or hidden. This is called when the URL changes.

application.showStateFunction = function (view, state) {
    return true; // show state or view
}

If there is an API you'd like added or framework feature contact support.

PreviousHow Exporting WorksNextElement Tokens

Last updated 4 years ago

Was this helpful?