Pen Settings

HTML

CSS

CSS Base

Vendor Prefixing

Add External Stylesheets/Pens

Any URLs added here will be added as <link>s in order, and before the CSS in the editor. You can use the CSS from another Pen by using its URL and the proper URL extension.

+ add another resource

JavaScript

Babel includes JSX processing.

Add External Scripts/Pens

Any URL's added here will be added as <script>s in order, and run before the JavaScript in the editor. You can use the URL of any other Pen and it will include the JavaScript from that Pen.

+ add another resource

Packages

Add Packages

Search for and use JavaScript packages from npm here. By selecting a package, an import statement will be added to the top of the JavaScript editor for this package.

Behavior

Auto Save

If active, Pens will autosave every 30 seconds after being saved once.

Auto-Updating Preview

If enabled, the preview panel updates automatically as you code. If disabled, use the "Run" button to update.

Format on Save

If enabled, your code will be formatted when you actively save your Pen. Note: your code becomes un-folded during formatting.

Editor Settings

Code Indentation

Want to change your Syntax Highlighting theme, Fonts and more?

Visit your global Editor Settings.

HTML

              
                <base href="https://raw-dot-custom-elements.appspot.com/PolymerElements/app-route/v2.0.0/app-route/">
<script src="../webcomponentsjs/webcomponents-lite.js"></script>

<link rel="import" href="../iron-demo-helpers/url-bar.html">
<link rel="import" href="../iron-pages/iron-pages.html">

<link rel="import" href="app-location.html">
<link rel="import" href="app-route.html">

<link rel="import" href="demo/youtube-demo/youtube-search.html">
<link rel="import" href="demo/youtube-demo/youtube-toolbar.html">
<link rel="import" href="demo/youtube-demo/video-viewer.html">
<link rel="import" href="demo/youtube-demo/search-results.html">

<url-bar></url-bar>

<app-router-demo></app-router-demo>

<dom-module id="app-router-demo">
  <template>
    <style>
      :host {
        display: block;
        position: relative;
        height: 100vh;
        @apply --paper-font-common-base;
      }
      :host([video-page-active]) {
        overflow: hidden;
      }
      :host([video-page-active]) iron-pages {
        transform: translateY(-170px);
      }
      iron-pages {
        transition: transform 0.3s;
      }
    </style>


    <!-- app-location binds with the URL and produces a route for app-route elements to consume. Since this demo needs to run without server cooperation (e.g. with polyserve, in the elements catalog, etc) we'll use the hash portion of the URL for our route paths. -->
    <app-location route="{{route}}" use-hash-as-path></app-location>

    <!-- app-routes parse route paths based on the their `pattern`. Parameters are extracted into the `data` object. The rest of the path that comes after the `pattern` is put into the `tail` object, which can be passed to the `route` property of downstream app-routes. -->
    <app-route route="{{route}}" pattern="/:page" data="{{data}}"></app-route>
    <app-route route="{{route}}" pattern="/search" tail="{{searchTail}}"></app-route>
    <app-route route="{{route}}" pattern="/video" tail="{{videoTail}}" active="{{videoPageActive}}"></app-route>

    <youtube-toolbar collapsed$="{{videoPageActive}}">
      <!-- The youtube-search has a app-route that consumes the tail of another route (`searchTail`) -->
      <youtube-search
          route="{{searchTail}}"
          video-data="{{videoData}}">
      </youtube-search>
    </youtube-toolbar>

    <iron-pages attr-for-selected="id" selected="{{data.page}}">
      <search-results id="search" items="{{videos}}"></search-results>

      <!-- The video-viewer has a app-route that consumes the tail of another route -->
      <video-viewer id="video" route="{{videoTail}}"></video-viewer>
    </iron-pages>

  </template>

  <script>
    window.addEventListener("WebComponentsReady", function() {
      Polymer({
        is: "app-router-demo",
        properties: {
          route: {
            type: Object
          },
          videoData: {
            type: Object,
            observer: "_videoDataChanged"
          },
          videoPageActive: {
            type: Boolean,
            reflectToAttribute: true,
            observer: "_videoPageActiveChanged"
          },
          searchTail: {
            type: Object,
            notify: true
          },
          videoTail: {
            type: Object,
            notify: true
          },
          newCategory: {
            type: String
          },
          videos: {
            type: Array,
            value: function() {
              return [];
            }
          },
          data: {
            type: Object,
            value: function() {
              return {
                page: "/search/"
              };
            }
          }
        },
        attached: function() {
          // If we do not have an initial URL, we redirect to /search
          if (!this.route || !this.route.path) {
            this.set("route.path", "/search/");
          }
        },
        _videoDataChanged: function(data) {
          var allVideos = [];
          var that = this;
          data.items.forEach(function(videoItem) {
            var youtubeVideo = {
              id: videoItem.id.videoId,
              title: videoItem.snippet.title,
              thumbnail: videoItem.snippet.thumbnails.high.url
            };
            allVideos.push(youtubeVideo);
          });
          this.set("videos", allVideos);
        },
        _videoPageActiveChanged: function(videoPageActive, previousValue) {
          // change color of page on page change
          var newColor;
          if (videoPageActive) {
            // black
            newColor = 0;
          } else {
            // white
            newColor = 255;
          }
          document.body.style.backgroundColor =
            "rgb(" + newColor + "," + newColor + "," + newColor + ")";
          // on first load, set the color then allow color transition animations
          if (previousValue === undefined) {
            document.body.style.transition = "background-color .2s linear";
            return;
          }
        }
      });
    });
  </script>
</dom-module>
              
            
!

CSS

              
                body {
  margin: 0;
  padding: 0;
}
url-bar {
  background-color: white;
}

              
            
!

JS

              
                
              
            
!
999px

Console