Coder Social home page Coder Social logo

byu-random-content's Introduction

byu-random-content

This is a simple Web Component that accepts any number of template tags and randomly selects a different one to display every time the page is loaded. Note that if an element other than a template tag is provided the component will show an error. This is to make sure that only the content that needs to be shown is loaded by the browser, preventing additional (potentially large) file downloads.

Usage

<link href="https://cdn.byu.edu/byu-random-content/latest/byu-random-content.min.css" rel="stylesheet" />
<script async src="https://cdn.byu.edu/byu-random-content/latest/byu-random-content.min.js"></script>
<byu-random-content id="random-content">
    <template>Slotted Item 1</template>
    <template>Slotted Item 2</template>
    <template>Slotted Item 3</template>
</byu-random-content>

Here's a more complicated example that chooses between various Hero Banners and displays a different one on page load (view the demo.html file in this repository for a working example). Note that because the component requires that these be template tags the content from the banners that are not selected (which could include large image and video files) is never downloaded. You can see this in action at https://cdn.byu.edu/byu-random-content/latest/demo/index.html.

<byu-random-content id="random-content">
    <template>
        <byu-hero-banner id="hero" image-source="https://admissions.byu.edu/sites/admissions1/files/winter.jpg" 
            video-source="https://www.youtube.com/watch?v=uTJAeSttacU"
            class="video-hero">
            <span slot="headline">This is the Headline</span>
            <span slot="intro-text">
                This is the intro text. I'm going to add more words here so it's not so short, resulting 
                in a longer piece of intro text.
            </span>
        <a slot="read-more" href="http://www.google.com">Custom "Read More" Text</a>
        </byu-hero-banner>
    </template>
    <template>
        <byu-hero-banner id="hero" image-source="dark-image2.jpg" video-source="websitehero.mp4" class="video-hero">
            <span slot="headline">This is the Headline</span>
            <span slot="intro-text">
                This is the intro text. I'm going to add more words here so it's not so short, 
                resulting in a longer piece of intro text.
            </span>
            <a slot="read-more" href="http://www.google.com">Custom "Read More" Text</a>
        </byu-hero-banner>
    </template>
    <template>
        <byu-hero-banner id="hero" image-source="sideimage.jpg" class="side-image">
            <span slot="headline">This is the Headline</span>
            <span slot="intro-text">
                This is the intro text. I'm going to add more words here so it's not so short, resulting 
                in a longer piece of intro text.
            </span>
        <a slot="read-more" href="http://www.google.com">Custom "Read More" Text</a>
        </byu-hero-banner>
    </template>
    <template>
        <byu-hero-banner id="hero" image-source="dark-image.jpg" class="transparent-overlay">
            <span slot="headline">This is the Headline</span>
            <span slot="intro-text">
                This is the intro text. I'm going to add more words here so it's not so short, resulting 
                in a longer piece of intro text.
            </span>
            <a slot="read-more" href="http://www.google.com">Custom "Read More" Text</a>
        </byu-hero-banner>
    </template>
    <template>
        <byu-hero-banner id="hero" image-source="dark-image.jpg" class="transparent-overlay byu-hero-right">
            <span slot="headline">This is the Headline</span>
            <span slot="intro-text">
                This is the intro text. I'm going to add more words here so it's not so short, resulting 
                in a longer piece of intro text.
            </span>
            <a slot="read-more" href="http://www.google.com">Custom "Read More" Text</a>
        </byu-hero-banner>
    </template>
</byu-random-content>

byu-random-content's People

Contributors

kevin-larry-bauer avatar lfsci-webteam avatar

Watchers

 avatar  avatar  avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.