Project Status
Use case
Building blocks for single page websites as a web component: wrap your page into "website-utilities" and get a loading cover, start-up animations, hash based navigation between sections, a scroll to top button, a navigation which moves overflowing items into a menu and optional tracking. Base styles with theme variables and the Open Sans fonts are included.
Content
Quick start
npm install website-utilities clientnode core-js web-component-wrapper
import {api} from 'website-utilities'
import 'website-utilities/dist/fonts.css'
import 'website-utilities/dist/index.css'
api.register()
Without a package manager load the bundle, which contains all dependencies, together with its styles. With npm it is available as "website-utilities/bundle":
<link
href="https://unpkg.com/website-utilities@latest/dist/bundle/fonts.css"
rel="stylesheet"
/>
<link
href="https://unpkg.com/website-utilities@latest/dist/bundle/index.css"
rel="stylesheet"
/>
<script type="module">
import {
api
} from 'https://unpkg.com/website-utilities@latest/dist/bundle/index.js'
api.register()
</script>
Then wrap your page:
<div class="wu-window-loading-cover">Loading…</div>
<website-utilities
class="wu"
options="{sectionNames: {managed: ['about']}}"
>
<header>
<a href="#">Home</a>
<a href="#about">About</a>
</header>
<main class="wu-router-outlet">
<section data-website-utilities-section>
<h1 class="wu-start-up-animation-number-1">Welcome</h1>
<p class="wu-start-up-animation-number-2">Nice to see you.</p>
</section>
<section data-website-utilities-section="about">About us</section>
</main>
<a class="wu-scroll-to-top" href="#top">Top</a>
</website-utilities>
Sections
The children of ".wu-router-outlet" are sections. The one with an empty "data-website-utilities-section" attribute is the default, the others are named. Names listed in "sectionNames.managed" are shown when the location hash matches, e.g. "#about", the active one gets the class "wu-section-active" and all others "wu-section-inactive" (hidden by the included styles). Switches fade the sections and scroll back to top.
Names in "sectionNames.unmanaged" are known hashes without own section, e.g. anchors inside a page. Switching between them neither fades nor scrolls. Navigation links to the current section get the class "wu-priority-navigation__link--active".
Loading and start-up animations
".wu-window-loading-cover" covers the page until it has been loaded and then fades out. Afterwards elements with the classes "wu-start-up-animation-number-1", "wu-start-up-animation-number-2" and so on fade in one after another. Scrolling is disabled until the cover is gone.
Navigation
- ".wu-scroll-to-top": Scrolls smoothly to the top on click. It gets the class "wu-scroll-down" when the page leaves the top, "wu-scroll-up" when it returns and "wu-top-settled" once it is back at the top.
- ".wu-priority-navigation": A navigation which moves items that do not fit into an overflow menu. It contains a ".wu-priority-navigation__list" of links with the class "wu-priority-navigation__link", ending with an item ".wu-priority-navigation__list__overflow-indicator", followed by an empty ".wu-priority-navigation__overflow-list".
<nav class="wu-priority-navigation">
<ul class="wu-priority-navigation__list">
<li><a class="wu-priority-navigation__link" href="#">Home</a></li>
<li>
<a class="wu-priority-navigation__link" href="#about">About</a>
</li>
<li class="wu-priority-navigation__list__overflow-indicator">
<div
class="wu-priority-navigation__list__overflow-indicator__title"
>
<div
class="wu-priority-navigation__list__overflow-indicator__title__icon"
></div>
</div>
</li>
</ul>
<ul class="wu-priority-navigation__overflow-list"></ul>
</nav>
Configuration
Pass options as JavaScript object in the "options" attribute:
- "sectionNames": "default", "managed" and "unmanaged" section names.
- "additionalPageLoadingTimeInMilliseconds": Keeps the loading cover longer.
- "startUpAnimationElementDelayInMilliseconds": Delay between start-up animation steps, 100 by default.
- "windowLoadedTimeoutAfterDocLoadedInMSec": Removes the cover at the latest this long after the document is ready, 2000 by default.
- "minimumNumberOfMenuItems": Items always kept in the priority navigation, 3 by default.
- "selectors": Alternative selectors and class names for all elements above.
- "tracking": Enables tracking, see below.
Callbacks
Set them as properties or as attributes like "on-section-switch", where "parameters" holds the arguments:
- "onSectionSwitch(sectionName, oldSectionName, event)": After a section switch.
- "onLoaded" and "onStartUpAnimationComplete": When the cover is gone and when all start-up animations have finished.
- "onViewportMovesAwayFromTop" and "onViewportMovesToTop": When the page is scrolled away from or back to the very top.
- "onLinkClick", "onButtonClick" and "onTrack": With tracking enabled.
<website-utilities
on-section-switch="document.title = parameters[0] || 'Home'"
>
...
</website-utilities>
Tracking
With "tracking": true, link and button clicks inside the component and section switches are pushed as items with "event", "label", "reference" and "subject" to "window.dataLayer", e.g. for Google Tag Manager. Returning false from "onSectionSwitch", "onLinkClick", "onButtonClick" or "onTrack" skips the corresponding item. "track(item)" adds own ones.
Styles
"dist/index.css" contains the styles for all elements above and the theme as CSS custom properties like "--wu-theme-primary", "dist/fonts.css" the Open Sans fonts. With Sass you can configure the theme variables:
@use "website-utilities/src/variables" with ($theme-primary: #d55e5d);
@use "website-utilities/src/index";
Deployment
The command "website-utilities" publishes a built website to a GitHub Pages repository: it pulls the repository, runs "yarn clear" and "yarn build", replaces the repository's content (except ".git", ".github", "CNAME" and "readme.md") with "dist" and commits and pushes the result. The repository is expected next to the project as "<GIT_PRIVATE_AUTHOR_NAME>.github.io" or at "PUBLIC_REPOSITORY_PATH" and has to contain a "CNAME" file. "USER_NAME_GITHUB" and "USER_EMAIL_GITHUB" set the commit author.
The same is available as GitHub action. It installs the dependencies, checks out the target repository and runs "yarn update:website", so the website's "package.json" needs this script calling "website-utilities":
steps:
- uses: thaibault/website-utilities@main
with:
pat-token: ${{ secrets.PAT_TOKEN_GITHUB }}
repository: ${{ github.repository_owner }}/${{ github.repository_owner }}.github.io
user_email_github: ${{ secrets.USER_EMAIL_GITHUB }}
user_name_github: ${{ github.repository_owner }}
Development
yarn install
yarn start
yarn test
"yarn start" serves a playground with all features.
About this website
Provider ofhttps://tsickert.com/website-utilities:
Torben Sickert
Waldstraße 29
79194 Gundelfingen i.Br.
Phone: +49 (0) 176 / 10 248 185
Email: [email protected]
Website: https://tsickert.com
Disclaimer
Liability for content
The content of our pages has been prepared with the utmost care. However, we cannot guarantee the accuracy, completeness or timeliness of the content. As a service provider, we are responsible for our own content on these pages under general law. However, we are not obliged to monitor transmitted or stored third-party information or investigate circumstances that indicate illegal activity. Obligations to remove or block the use of information under general law remain unaffected. Liability in this respect is only possible from the time we become aware of a specific infringement. Upon becoming aware of any such legal violations, we will remove this content immediately.
Liability for links
Our website contains links to external third-party websites whose content is beyond our control. We therefore cannot accept any responsibility for such third-party content. The respective provider or operator of each linked site is always responsible for its content. The linked sites were checked for possible legal violations when the links were created. No illegal content was apparent at that time. However, continuous monitoring of linked sites is not reasonable without specific evidence of a legal violation. If we become aware of any legal violations, we will remove the relevant links immediately.
Copyright
Content and works on these pages created by the site operators are subject to German copyright law. Reproduction, adaptation, distribution and any use beyond the scope of copyright law require the written consent of the respective author or creator. Downloads and copies of this site are permitted for private, non-commercial use only. Where content on this site was not created by the operator, third-party copyrights are respected. In particular, third-party content is identified as such. If you become aware of a copyright infringement, please notify us. Upon becoming aware of any legal violations, we will remove the relevant content immediately.
Privacy Policy
You can generally use our website without providing personal data. Where personal data (such as names, addresses or email addresses) is collected on our pages, this is, wherever possible, always done on a voluntary basis. This data will not be passed on to third parties without your express consent. Please note that data transmission over the internet (for example, when communicating by email) may have security vulnerabilities. It is not possible to completely protect data against access by third parties. We expressly object to the use by third parties of contact details published to meet legal notice requirements for sending unsolicited advertising or information. The site operators expressly reserve the right to take legal action if unsolicited advertising, such as spam emails, is sent.
Content Delivery Network (Cloudflare)
We use Cloudflare (Cloudflare, Inc., 101 Townsend St., San Francisco, CA 94107, USA) to protect and speed up our website. This constitutes a legitimate interest within the meaning of Art. 6(1)(f) GDPR. Cloudflare processes log data (including IP addresses) and sets technically necessary cookies to defend against malicious bot traffic. We have concluded a Data Processing Addendum (DPA) with Cloudflare based on the EU Standard Contractual Clauses. Cloudflare is certified under the EU-U.S. Data Privacy Framework.
Privacy Statement for a possible use of Google Analytics
This website may use Google Analytics 4, a web analytics service provided by Google Ireland Limited ("Google", Gordon House, Barrow Street, Dublin 4, Ireland). If it is used, data is processed solely on the basis of your express consent (Art. 6(1)(a) GDPR). Google Analytics uses cookies that enable analysis of how you use the website. Information generated by these cookies about your use of this website is transmitted to and stored on a Google server; transfer of data to third countries (such as the United States) cannot be ruled out. IP anonymization is enabled by default on this website, so Google truncates your IP address within a member state of the European Union or another state party to the Agreement on the European Economic Area before transmission. You may withdraw your consent at any time with effect for the future through the cookie settings (our consent tool), or prevent data collection by using the official Google browser add-on.
Copyright Statement
Unless noted otherwise, all artwork on this website is protected property of the website author. Any use for commercial purpose, reproduction and publication requires the author's written permission. Commercial work created in cooperation or bound by contract with third parties are specifically marked. Respective copyrights apply.