dman
dman

Reputation: 11064

Polymer 1.0 Extending Elements - paper-dialog with custom element

I am am trying to create a custom element that plays a youtube video in paper-dialog. So videoPlayer = Polymer.dom(this.root).querySelector('video-player'); inherits/has access to that paper-dialogs open method, I am trying to extend my custom element. It isn't working, but hopefully I am on the right track and someone can show me correctly.

I am using Polymer 1.0, but I only have https://www.polymer-project.org/0.5/docs/polymer/polymer.html#extending-other-elements to go by for extending elements.

<link rel="import" href="../bower_components/paper-dialog/paper-dialog.html">
<link rel="import" href="../bower_components/paper-icon-button/paper-icon-button.html">
<link rel="import" href="../bower_components/iron-icons/iron-icons.html">
<link rel="import" href="../bower_components/google-youtube/google-youtube.html">
<link rel="import" href="../bower_components/polymer/polymer.html">

<dom-module id="video-player">
  <template>
      <div class="layout horizontal">
        <paper-button dialog-dismiss>
          <paper-icon-button icon="arrow-back"></paper-icon-button>
        </paper-button>
      </div>
      <div style="height: 100%; width: 100%">
        <google-youtube style="height: 100%;"
          video-id="YMWd7QnXY8E"
          rel="1"
          start="5"
          playsinline="0"
          controls="2"
          showinfo="0"
          width="100%"
          height="100%"
          autoplay="1">
        </google-youtube>
      </div>
  </template>

  <script>
    Polymer({
      is: "video-player"
    });
  </script>

<paper-dialog name="video-player" extends="video-player">
  <template>
    <shadow></shadow>
  </template>
  <script>
     Polymer();
  </script>
</paper-dialog>

<video-player></video-player>

Upvotes: 3

Views: 1811

Answers (1)

Luke
Luke

Reputation: 5708

As was mentioned in the comments, you can't yet extend custom elements, so the existing pattern (or at least the one I use) is to make use of behaviors wherever possible and wrappers wherever not.

e.g.

<dom-module id="popup-video-player">
  <template>
    <video-player></video-player>
  </template>
  <script>
    Polymer({
      is: 'popup-video-player',
      behaviors: [Polymer.PaperDialogBehavior],
      ...
    });
  </script>
</dom-module>

Now you can use <popup-video-player> just like a paper-dialog.

I know it stinks because if video-player has a bunch of properties that you want access to, you have to copy them in the popup-video-player element's API, which is not exactly DRY.

If you look at the paper-input source, you'll see them doing the same thing. It's obvious that they want to extend iron-input, but they can't so you get things like this:

  <input is="iron-input" id="input"
    aria-labelledby$="[[_ariaLabelledBy]]"
    aria-describedby$="[[_ariaDescribedBy]]"
    disabled$="[[disabled]]"
    title$="[[title]]"
    ... >

As a side note, you could always hook into the <video-player>s "properties" property and make the API additions programatically.

maybe something like this would work: (untested!)

Polymer({
  ...
  properties: (function () {
    var prop = {
      //special properties specific to the pop up version of video-player
      //..obviously be careful to avoid name space conflicts.
    };
    var video_player = document.createElement('video-player');
    video_player.properties.keys().forEach( function(key) {
      props[key] = video_player[key];
    });
    return props;
  }()),

});

Upvotes: 3

Related Questions