を分離するために:私は、ボタンをラップ(または私の場合にはFAB)したいどのように彼らは、このようなコードを持つポリマーダイアログのデモでは、ポリマーボタンとダイアログ
<script src=
https://github.com/webcomponents/webcomponentsjs/blob/master/webcomponents.js>
<link rel="import" href="https://github.com/Polymer/polymer/blob/master/polymer.html">
<link rel="import" href="https://github.com/PolymerElements/paper-button/blob/master/paper-button.html">
<link rel="import" href="https://github.com/PolymerElements/paper-dialog/blob/master/paper-dialog.html">
<section onclick="clickHandler(event)">
<h4>Transitions</h4>
<paper-button data-dialog="animated">transitions</paper-button>
<paper-dialog id="animated" entry-animation="scale-up-animation" exit-animation="fade-out-animation" with-backdrop>
<h2>Dialog Title</h2>
<p>Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure
dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.</p>
</paper-dialog>
</section>
<script>
function clickHandler(e) {
var button = e.target;
while (!button.hasAttribute('data-dialog') && button !== document.body) {
button = button.parentElement;
}
if (!button.hasAttribute('data-dialog')) {
return;
}
var id = button.getAttribute('data-dialog');
var dialog = document.getElementById(id);
if (dialog) {
dialog.open();
}
}
</script>
とダイアログ私自身の別個のWebコンポーネントに変換します。動作するように、次の
<paper-fab class="addbutton" icon="add" onclick="clickHandler(event)"></paper-fab>
</template>
<script>
Polymer({
is: 'my-dialog-button',
properties: {
dialog_id: {
type: String
},
}
})
function clickHandler(e) {
var button = e.target;
while (!button.hasAttribute('dialog_id') && button !== document.body) {
button = button.parentElement;
}
if (!button.hasAttribute('dialog_id')) {
console.log("you have no element with 'dialog_id' defined")
return;
}
var id = button.getAttribute('dialog_id');
console.log("dialog " + id + " requested")
var dialog = document.getElementById(id);
if (dialog) {
dialog.open();
} else {
console.log("dialog " + id + " does not exist")
}
}
</script>
私ができます:
<thor-dialog-button dialog_id="add-button"></thor-dialog-button>
<paper-dialog id="add-button">
<h2>"Hello"</h2>
<p>"World"</p>
</paper-dialog>
しかし、自分のコンポーネントにダイアログをラップすると、その "id"はそのDOMコンテキストでは使用できなくなります。それで、うまくいきません。
私はIDのアプローチdoesntのは本当に仕事を考えていたと私は「onclickの」ボタンに「オープン」ダイアログをバインドする必要がありますが、私はそれを行う方法を見当がつかない、私が発見した:
https://www.polymer-project.org/1.0/docs/devguide/templates.html
をしかし、これをラップされた要素にどのように適用するかはわかりません(少なくとも私はこれまでのアプローチでは驚異的に失敗しました)。
要約すると、2つのラップされたWebコンポーネントを分離する正しい方法は何ですか?
このパターンに続いて、私のダイアログが見つかりますが、何らかの理由でdialog.openが存在しないという例外がスローされます。オープンな宣言で何かが欠けているはずです:(https://codedump.io/share/3amWTwQwL5nn/1/dialog-problem – chrispepper1989
スニペットを参照してください。 – Snekw
あなたは、悲しいことに、悲しいことに、私の主なプロジェクトではうまく動作しません...しかし、 JSbinは、別々のファイルに分割し、それが私のための掘り出し物のビットを動作参照してください! – chrispepper1989