首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >聚合物1.0扩展元件.带自定义元件的纸对话框

聚合物1.0扩展元件.带自定义元件的纸对话框
EN

Stack Overflow用户
提问于 2015-07-16 01:52:10
回答 1查看 1.8K关注 0票数 3

我正在尝试创建一个自定义元素,在paper-dialog中播放youtube视频。因此,videoPlayer = Polymer.dom(this.root).querySelector('video-player');继承/访问了paper-dialogopen方法,我正在尝试扩展我的自定义元素。它不起作用,但希望我在正确的轨道上,有人可以正确地告诉我。

我使用的是Polymer 1.0,但是我只需要使用https://www.polymer-project.org/0.5/docs/polymer/polymer.html#extending-other-elements来扩展元素。

代码语言:javascript
复制
<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>
代码语言:javascript
复制
<paper-dialog name="video-player" extends="video-player">
  <template>
    <shadow></shadow>
  </template>
  <script>
     Polymer();
  </script>
</paper-dialog>
代码语言:javascript
复制
<video-player></video-player>
EN

回答 1

Stack Overflow用户

发布于 2016-01-16 22:41:22

正如注释中提到的那样,您还不能扩展自定义元素,因此现有的模式(至少是我使用的模式)是尽可能地使用行为,而包装则是在不使用的地方使用。

例如:

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

现在,您可以像使用<popup-video-player>一样使用paper-dialog

我知道这很糟糕,因为如果video-player有很多您想要访问的属性,就必须将它们复制到popup-video-player元素的API中,这并不完全是干的。

如果你看一下 source,你会看到他们在做同样的事情。很明显,他们想要扩展iron-input,但是他们不能这样做:

代码语言:javascript
复制
  <input is="iron-input" id="input"
    aria-labelledby$="[[_ariaLabelledBy]]"
    aria-describedby$="[[_ariaDescribedBy]]"
    disabled$="[[disabled]]"
    title$="[[title]]"
    ... >

顺便提一句,您可以始终连接到<video-player>的“属性”属性,并通过编程方式添加API。

也许像这样的东西会起作用:(未经测试!)

代码语言:javascript
复制
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;
  }()),

});
票数 3
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/31444119

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档