1.0.1 • Published 7 months ago

@oggeh/web-component v1.0.1

Weekly downloads
-
License
MIT
Repository
github
Last release
7 months ago

OGGEH Web Component

License: MIT

This is a free Web Component that introduces our custom element <oggeh-content></oggeh-content> for automating our Content Delivery API. Perfect for skills limited to HTML only.

You need a Developer Account to obtain your App API Keys, if you don't have an account, create one now.

Getting Started

  1. First, you need to configure your App API Key at the end of the <head> tag:
<script>
  window.oggeh = window.oggeh || {
    api_key: "YOUR_OGGEH_APP_API_KEY", // Required
    // api_secret: "YOUR_OGGEH_APP_API_SECRET", // Use only in mobile/desktop/nodejs apps
    // sandbox_key: "YOUR_OGGEH_APP_SANDBOX_KEY", // Use only in a development environment
    // domain: "YOUR_OGGEH_HOSTNAME", // Use only in mobile/desktop/nodejs apps
  };
</script>
  1. Next, you need to install our web component after the above script, also at the <head> tag:
<script src="https://unpkg.com/@oggeh/web-component/dist/oggeh.min.js"></script>
  1. Finally, use the custom element for loading your dynamic content anywhere at the <body> tag. Example navigation tag:
<oggeh-content get="app" render="nav">
  <!-- Template for a leaf navigation item (a single link in a list item) -->
  <template id="oggeh-nav-leaf">
    <li>
      <a href="/page/key={{ key }}">{{ subject }}</a>
    </li>
  </template>
  <!-- Template for a branch navigation item (with nested children) -->
  <template id="oggeh-nav-branch">
    <li class="dropdown">
      <a href="/page/key={{ key }}">{{ subject }}</a>
      <ul>
        <!-- This slot is where child navigation items (leaf or branch) will be inserted -->
        <slot></slot>
      </ul>
    </li>
  </template>
  <!-- Template for the overall navigation container -->
  <template id="oggeh-nav">
    <div class="navbar-collapse collapse clearfix">
      <ul class="navigation">
        <!-- All navigation items will be slotted into this list -->
        <slot></slot>
        <!-- Predefined routes -->
        <li>
          <a href="/news">News</a>
        </li>
        <li>
          <a href="/contact">Contact</a>
        </li>
      </ul>
    </div>
  </template>
</oggeh-content>

Supported Properties

  1. config: Accepts one of the following values:

    ValueRequired PropetriesDescriptionExample
    anti-flickerHides page until all content is loaded<oggeh-content config="anti-flicket"></oggeh-content>
    routerEnforcing history state (SPA mode)<oggeh-content config="router"></oggeh-content>
    scriptstype="text/oggeh-defer"Defer template javascript after loading all content<oggeh-content config="scripts"></oggeh-content>
  2. get (required): Accepts one of the following values:

    ValueRequired PropetriesOptional PropetriesExample
    apprender (options: meta, nav, slider, locations, contact, social )<oggeh-content get="app" render="nav"></oggeh-content>
    modelstart-key<oggeh-content get="mode" start-key=""></oggeh-content>
    pagesstart-key<oggeh-content get="pages" start-key="" limit=""></oggeh-content>
    pagekey<oggeh-content get="page" key=""></oggeh-content>
    page-relatedkey, model (options: *, product, event, or a custom model key)<oggeh-content get="page-related" key="" model=""></oggeh-content>
    search-resultskeyword<oggeh-content get="search-results" keyword=""></oggeh-content>
    newsstart-date, limit<oggeh-content get="news" start-date="" limit="4"></oggeh-content>
    news-articletimestamp<oggeh-content get="news-article" timestamp=""></oggeh-content>
    news-relatedtimestamp, limit<oggeh-content get="news-related" timestamp=""></oggeh-content>
  3. custom: Accepts a custom method defined at the global oggeh object (see Custom Methods).

Supported Templates

  1. oggeh-container (required): A template for the loaded content inside our custom element.
  2. oggeh-repeat: A template for repeated parts of the content, works when using a <slot> tag inside oggeh-container. Example:
<oggeh-content get="app" render="social">
  <template id="oggeh-container">
    <ul class="footer-social-links">
      <slot></slot>
    </ul>
  </template>

  <template id="oggeh-repeat">
    <li>
      <a href="{{ url }}">
        <i aria-hidden="true" class="fa fa-{{ provider }}"></i>
      </a>
    </li>
  </template>
</oggeh-content>
  1. Page blocks templates also available (learn more).

Notes:

  1. All templates accept placeholder tokens inside double-curly braces. Example: {{ subject }}
  2. Nested properties can be chained using dot . Example: {{ conver.regular.url }}

Supported Modifiers

ModifierDescriptionExample
isDecides to display token value if it exists or is empty{{ fax | is(fax) }}
fallbackDecides to display an alternative value if the token does not exist or is empty{{ cover.maximum.url | fallback('data:image/gif;base64,R0lGODlhAQABAIAAAAAAAP///ywAAAAAAQABAAACAUwAOw==') }}
joinConcatenates token list using the provided separator{{ tags | join(', ') }}
formatDateDisplays unix timestamp in the following format MMM DD, YYYY{{ timestamp | formatDate }}
formatTimeDisplays unix timestamp in the following format HH:MM:SS AM/PM{{ timestamp | formatTime }}

Supported Events

EventDescriptionExample
oggeh.readyTriggers when a single tag is done with loading contentdocument.addEventListener('oggeh.ready', console.log)
oggeh.navigateTriggers when history state changes (SPA mode)document.addEventListener('oggeh.navigate', console.log)
oggeh.errorTriggers when a single tag fails to load contentdocument.addEventListener('oggeh.error', console.log)

Example

<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="UTF-8" />
    <meta http-equiv="X-UA-Compatible" content="IE=edge" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <title>OGGEH Demo</title>

    <!-- Begin of OGGEH Web Component -->
    <script>
      window.oggeh = window.oggeh || {
        api_key: "YOUR_OGGEH_APP_API_KEY", // Required
        // api_secret: "YOUR_OGGEH_APP_API_SECRET", // Use only in mobile/desktop/nodejs apps
        // sandbox_key: "YOUR_OGGEH_APP_SANDBOX_KEY", // Use only in development environment
        // domain: "YOUR_OGGEH_HOSTNAME", // Use only in mobile/desktop/nodejs apps
      };
      document.addEventListener('oggeh.error', (event) => {
        console.error('OGGEH Error:', event.detail.error);
      });
      document.addEventListener('oggeh.ready', (event) => {
        console.log('OGGEH Response:', event.detail.data);
      });
      document.addEventListener('oggeh.navigate', (event) => {
        console.log('OGGEH Navigate:', event.detail.path);
      });
    </script>
    <script src="https://unpkg.com/@oggeh/web-component/dist/oggeh.min.js"></script>
    <!-- End of OGGEH Web Component -->

  </head>
  <body>

    <oggeh-content config="anti-flicker"></oggeh-content>
    <oggeh-content config="router"></oggeh-content>

    <oggeh-content get="app" render="nav">
      <!-- Template for a leaf navigation item (a single link in a list item) -->
      <template id="oggeh-nav-leaf">
        <li>
          <a href="/page/key={{ key }}">{{ subject }}</a>
        </li>
      </template>
      <!-- Template for a branch navigation item (with nested children) -->
      <template id="oggeh-nav-branch">
        <li class="dropdown">
          <a href="/page/key={{ key }}">{{ subject }}</a>
          <ul>
            <!-- This slot is where child navigation items (leaf or branch) will be inserted -->
            <slot></slot>
          </ul>
        </li>
      </template>
      <!-- Template for the overall navigation container -->
      <template id="oggeh-nav">
        <div class="navbar-collapse collapse clearfix">
          <ul class="navigation">
            <!-- All navigation items will be slotted into this list -->
            <slot></slot>
            <!-- Predefined routes -->
            <li>
              <a href="/news">News</a>
            </li>
            <li>
              <a href="/contact">Contact</a>
            </li>
          </ul>
        </div>
      </template>
    </oggeh-content>

    <oggeh-content config="scripts">
      <script type="text/oggeh-defer" src="/js/script.js"></script>
    </oggeh-content>

  </body>
</html>

API Documentation

See API Reference for additional details on available values for select attribute on each API Method.

Credits

Copyright(c) 2025 OGGEH, Inc

1.0.1

7 months ago

1.0.0

7 months ago