Polymer 1.x:使普通的<paper-dialog>工作

时间:2015-10-16 05:42:58

标签: polymer polymer-1.0 paper-elements

问题

  

How do I get this JSFiddle显示其<paper-dialog>元素?请提供有效的JSFiddle或JSBin示例。

代码

http://jsfiddle.net/gr3uhucf/2/
<!DOCTYPE html>
<html>  
<head>
  <meta charset="utf-8">
  <base href="http://element-party.xyz/">
  <script src="bower_components/webcomponentsjs/webcomponents-lite.js"></script>
  <link rel="import" href="all-elements.html">
</head>
<body>
  <paper-button data-dialog="dialog">Dialog</paper-button>
  <paper-dialog id="dialog">
    <h2>Dialog Title</h2>
    <p>Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua.</p>
  </paper-dialog>
</body>
</html>

3 个答案:

答案 0 :(得分:1)

如果您只想静态查看对话框,可以在HTML(fiddle)中添加openend属性。

<paper-dialog id="dialog" opened> 

要在点击时打开,请调用open函数(fiddle)。

<paper-button id="dialog-button" data-dialog="dialog">Dialog</paper-button>
<paper-dialog id="dialog">
    <h2>Dialog Title</h2>
</paper-dialog>

<script> 
    document.querySelector("#dialog-button").addEventListener("click", 
        function(){
            document.querySelector("#dialog").open();
        });
</script>

答案 1 :(得分:0)

Full code of accepted answer

代码

http://jsfiddle.net/6x2g4dc5/
<!DOCTYPE html>
<html>  
<head>
  <meta charset="utf-8">
  <title>Polymer Bin</title>
  <base href="http://element-party.xyz/">
  <script src="bower_components/webcomponentsjs/webcomponents-lite.js"></script>
  <link rel="import" href="all-elements.html">
</head>
<body>
  <paper-button id="dialog-button" data-dialog="dialog">Dialog</paper-button>
  <paper-dialog id="dialog" modal>
    <h2>Dialog Title</h2>
    <p>Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua.</p>
  </paper-dialog>
  <script> 
    document.querySelector("#dialog-button")
            .addEventListener("click", function(){
              document.querySelector("#dialog").open()
              });
  </script>
</body>
</html>

答案 2 :(得分:0)

这是使用聚合物CDN的工作方式。它基于上面的答案。脚本标签似乎不是惯用的聚合物代码。

https://jsfiddle.net/bncg3qy8/

def t_comment(self, t):
        r'(/\*(.|\n)*?\*/)|(//.*)'
        t.lineno += t.value.count('\n')