使用addthis或外部javascript更新聚合元素shadowdom中的div

使用addthis或外部javascript更新聚合元素shadowdom中的div,javascript,polymer,shadow-dom,addthis,polymer-elements,Javascript,Polymer,Shadow Dom,Addthis,Polymer Elements,我正在尝试在polymer 2.0应用程序的元素中添加一些“addthis”按钮。我可以导入“addthis”javascript,但它需要脚本本身更新作为子元素一部分的“div”。addthis脚本正在查找class=“addthis\u inline\u share\u toolbox”这可能吗?我认为问题在于脚本无法在影子dom中找到类。如何使该类从shadowdom中可用,以便脚本可以找到它?有没有办法通过聚合物属性创建这种访问 <dom-module id="poem-card"

我正在尝试在polymer 2.0应用程序的元素中添加一些“addthis”按钮。我可以导入“addthis”javascript,但它需要脚本本身更新作为子元素一部分的“div”。addthis脚本正在查找
class=“addthis\u inline\u share\u toolbox”
这可能吗?我认为问题在于脚本无法在影子dom中找到类。如何使该类从shadowdom中可用,以便脚本可以找到它?有没有办法通过聚合物属性创建这种访问

<dom-module id="poem-card">
<template>
  <style>
    :host {
      display: block;
    }

    img {
      width: 100%
    }

    paper-card {
      --paper-card-header-text: {
        font-family: 'Fascinate Inline', cursive;
        color: yellow;
        font-size: xx-large;
      };
      --paper-card-header{
        position: 50%;
      };
    }
    .card-content *{
      margin: 8px 0;
      font-weight: bold;
      font-family: 'Alegreya Sans SC', sans-serif;

    }

  </style>
  <iron-ajax
    auto
    url="https://api.json"
    handle-as="json"
    last-response="{{response}}">
  </iron-ajax>
    <paper-card heading="{{response.items.0.title}}" image="https://placeimg.com/600/400/nature/sepia" alt="{{response.items.0.title}}">
      <div class="card-content">
        <p inner-h-t-m-l="{{response.items.0.content}}"></p>
      </div>
      <div class="card-actions">

        <div class="addthis_inline_share_toolbox"></div>
      </div>
    </paper-card>



</template>

<script>
  /**
   * `poem-card`
   * an individual poem in card form
   *
   * @customElement
   * @polymer
   * @demo demo/index.html
   */
  class PoemCard extends Polymer.Element {
    static get is() { return 'poem-card'; }
    static get properties() {
      return {
        prop1: {
          type: String,
          value: 'poem-card'
        }
      };
    }
  }

  window.customElements.define(PoemCard.is, PoemCard);
</script>

<script type="text/javascript" src="/addthis.js"></script>

:主持人{
显示:块;
}
img{
宽度:100%
}
纸卡{
--纸卡标题文本:{
字体系列:“迷人内联”,草书;
颜色:黄色;
字体大小:xx大号;
};
--纸卡头{
职位:50%;
};
}
.卡片内容*{
利润率:8px0;
字体大小:粗体;
字体系列:“Alegreya Sans SC”,无衬线;
}

/** *”“诗牌` *卡片形式的一首单独的诗 * *@customElement *@聚合物 *@demo/index.html */ 类PoemCard扩展了Polymer.Element{ 静态get是(){return'poem card';} 静态获取属性(){ 返回{ 建议1:{ 类型:字符串, 价值:'诗卡' } }; } } window.customElements.define(PoemCard.is,PoemCard);

这里的代码

来自Web组件的影子dom的思想是没有其他脚本可以更改Web组件网的dom。因此,为了实现这一点,您需要为外部脚本提供组件文档的一个实例,如
newaddthis(Polymer.dom(this.root))


这仅仅是事实的一半,因为这是针对polymer 2的,如果您使用polymer 1并告诉它使用shady dom,您的脚本可能会运行良好,因为此限制仅适用于shadow dom。

Web组件的shadow dom的思想是,没有其他脚本可以更改Web Compontnet的dom。因此,为了实现这一点,您需要为外部脚本提供组件文档的一个实例,如
newaddthis(Polymer.dom(this.root))


这仅仅是事实的一半,因为此anwser适用于polymer 2如果您使用polymer 1并告诉它使用shady dom,您的脚本可能会正常工作,因为此限制仅适用于shadow dom。

以下是有问题的应用供参考:以下是有问题的应用供参考: