brandocms / jupiter

Frontend helpers
Other
0 stars 0 forks source link

«Earth people, I was born on»

npm version


NOTICE

This package is not compiled with Babel, which means that your build step should babelify it. Meaning, if your bundler's babel config excludes node_modules, you should add jupiter as an exception. In your webpack babel loader config:

exclude: [
  /node_modules([\\]+|\/)+(?!@univers-agency\/jupiter)/
]

Application

Config

Available CSS vars

Methods/functions

Dom

Some utility functions for dealing with the DOM.

Events (application)

Called before initialization

Called after initialization

Called when application/dom ready

Called after #fader removed

Called on opening mobile navigation menu

Called on closing mobile navigation menu

Called on application scrolling

Called on application resizing

Called when scrollbar is locked with app.scrollLock()

Called when scrollbar is released with app.scrollRelease()

Called when application is forced to scroll, for instance on clicking anchors, triggering scrollTo

Called at end of forced scroll.

Called if user presses <tab>. Tells us the user is using tabbed navigation

Called when application becomes hidden or visible

Called when application becomes hidden

Called when application becomes visible

Events (other)

IMAGE:LAZYLOADED

Called when an image marked for lazyloading finishes loading. Gets called on the element itself:

import * as Events from jupiter
const image = document.querySelector('.my-image')
image.addEventListener(Events.IMAGE_LAZYLOADED, () => { console.log('lazyloaded') })

SECTION:LAZYLOADED

Called when a section enters the viewport and its pictures are done loading

import * as Events from jupiter
const section = document.querySelector('.my-section[data-lazyload-section]')
section.addEventListener(Events.SECTION_LAZYLOADED, () => { console.log('lazyloaded') })

Lightbox

Can be initiated with a sectioned name data-lightbox-section. The lightbox will only include images from this section. Otherwise, all lightboxed images will be included.

<div
  data-lightbox="/media/images/site/posts/xlarge/2gmk2h1d8d4q.jpg"
  data-lightbox-section="intro"
  aria-hidden="true">
  <figure>
    <img
      alt="Text"
      src="https://github.com/brandocms/jupiter/raw/master/media/images/site/posts/small/2gmk2h1d8d4q.jpg"
      height="1667"
      width="2210">

      <div data-lightbox-trigger>Click to trigger</div>
  </figure>
</div>

Options

Toggler

Example

HTML

<div data-toggle>
  <button data-toggle-trigger>Click to expand <span class="arrow icon">&darr;</span></button>
  <div class="panel" data-toggle-content>
    <div class="panel-content">
      Content goes here
    </div>
  </div>
</div>

CSS

[data-toggle-trigger] {
  .arrow {
    display: inline-block;
    transform: scaleY(1);
    transition: transform 250ms ease;
    &.active {
      transform: scaleY(-1);
    }
  }
}

[data-toggle-content] {
  height: 0;
  overflow: hidden;
  opacity: 1;
  position: relative;
}

JS

import { Toggler } from '@brandocms/jupiter'

app.togglers = []

const togglers = Dom.all('[data-toggle]')
togglers.forEach(toggleEl => {
  app.togglers.push(new Toggler(app, toggleEl))
})

Options

Links

Options

By default anchor links get added to the browser history. You can skip this by setting data-skip-history on the link target:

<a id="content" name="content" data-skip-history></a>

Moonwalk

Moonwalks are divided into sections that are run in a timeline. Multiple timelines can run at the same time.

You reference the configured walks by the data-moonwalk="walkname" syntax. If no value is provided, we run the default walk.

Options

Sample code

<div data-moonwalk-section>
  <div data-moonwalk>
    Default walk
  </div>
  <div data-moonwalk="fast">
    `Fast` walk
  </div>
</div>

Named sections

A named section will autoplay its children when intersecting with the viewport. Needs the sectionTargets key in config. If sectionTargets is not provided, the section's immediate children are used instead.

You can force a custom order of the staggered reveal by adding data-moonwalk-order="1" etc to the targeted elements.

Named sections can have startDelay, a delay added before the first staggered tween.

Sample code

<div class="slideshow" data-moonwalk-section="slider">
  <div class="slides-wrapper">
    <picture class="image">
      ...
    </picture>
    <picture class="image">
      ...
    </picture>
  </div>
</div>

Sample config:

slider: {
  sectionTargets: '.image',
  interval: 0.2,
  duration: 1.2,
  alphaTween: true,
  transition: {
    from: {
      autoAlpha: 0,
      y: 21
    },
    to: {
      ease: 'sine.out',
      y: 0
    }
  }
}

Stages

A stage will run a transition on itself before introducing the rest of the moonwalks. For instance, if a section should be animated to "open" by scaling Y from 0 to 100. When the stage's tween is finished, the rest are called as they intersect.

Sample code

<div class="slideshow" data-moonwalk-section data-moonwalk-stage="scaleup">
  <div data-moonwalk="slow">...</div>
  <div data-moonwalk>...</div>
  <div data-moonwalk="slow">...</div>
</div>

Sample config

walks: {
  scaleup: {
    interval: 0,
    duration: 1,
    startDelay: 1,
    transition: {
      from: {
        scaleY: 0,
        transformOrigin: '50% 50%'
      },

      to: {
        scaleY: 1,
        ease: 'sine.out'
      }
    }
  }
}

Set children

Sometimes you might have a dynamic number of children that you want to moonwalk, for instance paragraphs in an article. You can do this by setting data-moonwalk-children on the parent element. You can also supply a value to this attribute if you want to set a specific walk to the children:

<article data-moonwalk-section data-moonwalk-children="slide">
  <p>Paragraph one</p>
  <p>Paragraph two</p>
  ...
</article>

Paragraph one and two will then get a data-moonwalk="slide" attribute.

Popup

Options

Example

Example HTML

<div class="newsletter-popup" data-popup>
  ...
  <button data-popup-close>
</div>

<button data-popup-trigger=".newsletter-popup">
  Open popup
</button>

Example CSS (PCSS)

[data-popup] {
  position: fixed;
  justify-self: center;
  align-self: center;
  background-color: white;
  top: 50%;
  left: 50%;
  z-index: 5000;
  padding: 3em;
  text-align: center;
  display: none;
  opacity: 0;

  @responsive mobile {
    width: 80%;
  }
}

[data-popup-backdrop] {
  z-index: 4999;
  display: none;
  opacity: 0;
  background-color: theme(colors.blue.100);
  position: fixed;
  top: 0;
  left: 0;
  height: 100%;
  width: 100%;
}

StackedBoxes

<div class="v-module" data-v="quote|image" data-moonwalk-section data-boxes-stacked>
  <aside data-boxes-stacked-size-target>
    <blockquote>
      Quote here
    </blockquote>
    <cite>
      Name
    </cite>
  </aside>
  <figure data-boxes-stacked-pull="2/3" data-boxes-stacked-size-src>
    <%= picture_tag Enum.at(@works, 2).cover, img_class: "img-fluid", alt: "--", key: :original, prefix: media_url() %>
  </figure>
</div>

StickyHeader

Options

FixedHeader

Options

HeroVideo

Set a cover image by supplying a data-cover element. Allow different srcs for mobile/desktop by setting data-src='{"phone": "<%= get_global("hero_link_phone") %>", "desktop": "<%= get_global("hero_link_desktop") %>"}'

Hero example:

<section class="hero stretch" data-section>
  <div class="hero-bg">
    <div data-hero-video data-object-fit="cover">
      <img src="https://github.com/brandocms/jupiter/raw/master/img/wide.jpg" data-object-fit="cover" data-cover />
      <div data-hero-video-content>
        <video tabindex="-1" role="presentation" preload="auto" muted loop playsinline src="https://github.com/brandocms/jupiter/raw/master/img/hero.mp4"></video>
      </div>
      <noscript>
        <video tabindex="-1" role="presentation" autoplay muted loop playsinline src="https://github.com/brandocms/jupiter/raw/master/img/hero.mp4"></video>
      </noscript>
    </div>
  </div>
  <article class="hero-content">
    <div class="container">
      <section class="main-text">
        <p>
          We specialise in branding<br>
          and identity design.
        </p>
      </section>
    </div>
    <section class="centered-arrow">
      <a href="#index-content">
        <span class="arrow-d mt-3">↓</span>
      </a>
    </section>
  </article>
</section>

Options

Parallax

Options

Example:

<style>
  [data-parallax] {
    position: relative;
    min-height: 100vh;
    overflow: hidden;
  }

  [data-parallax-figure] {
    position: absolute;
    top: 0;
    left: 0;
    height: 100%;
    width: 100%;
    max-height: 100%;
  }

  [data-parallax-figure] picture {
    height: 100%;
    width: 100%;
  }

  [data-parallax-figure] picture img {
    min-height: 100%;
    min-width: 100%;
    max-height: 100%;
    object-fit: cover;
  }

  [data-parallax-content] {
    position: absolute;
    top: 0;
    left: 0;
    height: 100%;
    width: 100%;
    display: flex;
    justify-content: center;
    align-items: center;
  }

  [data-parallax-content] div {
    color: #ffffff;
    font-size: 4rem;
  }
</style>

<section data-parallax>
  <div data-parallax-figure>
    <%= picture_tag(
      work.cover,
      placeholder: false,
      key: :original,
      lazyload: true,
      srcset: {Kunstnerforbundet.Artists.Work, :cover},
      prefix: media_url(),
      img_class: "img-fluid",
      alt: "#{work.title} (#{work.year}) - #{work.size} - #{work.technique}")
    %>
  </div>
  <div data-parallax-content>
    <div>
      Testing some parallax :)
    </div>
  </div>
</section>

CSS/JS Quirks