html - 如何在另一个 HTML 文档中使用来自 Polymer Project Designer 的代码

标签 html github polymer polymer-designer-tool

<分区>

所以我在 Polymer Project Designer 中构建了一个小家伙:http://www.polymer-project.org/tools/designer/preview.html#ca22c086297bb41ee6e0

并且想在我本地计算机上的另一个 HTML 文件中使用它。我完全不知道该怎么做,我找了教程视频并尝试集成通过 github ( https://gist.githubusercontent.com/Superraptor/ca22c086297bb41ee6e0/raw/8543946b7e21a8fd2f1a8022e155622306fc549f/designer.html ) 生成的代码,但无济于事。我真的需要帮助!

非常感谢!

编辑:

这是我的代码:

<!DOCTYPE html>

<html lang="en">

<head>
    <meta charset="utf-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <script src="bower_components/platform/platform.js"></script>
    <link rel="import" href="bower_components/polymer/polymer.html">

<!-- These are the links I added -->
    <link rel="import" href="../paper-tabs/paper-tab.html">
<link rel="import" href="../core-drawer-panel/core-drawer-panel.html">
<link rel="import" href="../core-menu/core-submenu.html">
<link rel="import" href="../core-item/core-item.html">


</head>

<body>


<!-- This is the element I added -->
<polymer-element name="my-element">

  <template>
    <style>    
      :host {
        position: absolute;
        width: 100%;
        height: 100%;
        box-sizing: border-box;
      }
      #core_input {
        padding: 10px;
        display: none;
        background-color: rgb(255, 255, 255);
      }
      #core_drawer_panel {
        right: 0px;
        bottom: 0px;
        width: 100%;
        height: 100%;
      }
      #section1 {
        box-shadow: rgba(0, 0, 0, 0.0980392) 0px 2px 4px, rgba(0, 0, 0, 0.0980392) 0px 0px 3px;
        background-color: rgb(250, 250, 250);
      }
      #section2 {
        height: 100%;
        box-sizing: border-box;
        background-color: rgb(221, 221, 221);
      }
      #core_menu {
        font-size: 16px;
      }
      #core_header_panel {
        width: 100%;
        height: 100%;
        left: 0px;
        top: 0px;
        position: absolute;
      }
      #core_toolbar {
        color: rgb(255, 255, 255);
        background-color: rgb(79, 125, 201);
      }
      #section {
        height: 100%;
        background: linear-gradient(rgb(214, 227, 231), rgb(173, 216, 230));
      }
      #core_header_panel1 {
        width: 100%;
        height: 100%;
        position: absolute;
        top: 0px;
        left: 0px;
      }
      #section3 {
        width: 420px;
        height: 630px;
        border: 5px solid rgb(204, 204, 204);
        left: 1150px;
        top: 480px;
      }
      #paper_tabs {
        color: rgb(255, 255, 255);
        box-shadow: rgba(0, 0, 0, 0.2) 0px 3px 2px;
        background-color: rgb(0, 188, 212);
      }
      #paper_fab {
        left: 1170px;
        top: 480px;
      }
      #div1 {
        left: 1210px;
        top: 480px;
      }
      #paper_icon_button {
        left: 1240px;
        top: 490px;
      }
      #core_field {
        left: 1090px;
        top: 510px;
      }
      #core_input1 {
        padding: 10px;
        width: 100px;
        display: none;
        background-color: rgb(255, 255, 255);
      }
      #core_input2 {
        padding: 10px;
        width: 100px;
        display: none;
        background-color: rgb(255, 255, 255);
      }
    </style>
    <core-header-panel mode="standard" id="core_header_panel">
      <core-toolbar id="core_toolbar" wrap>
        <core-icon-button icon="menu" id="core_icon_button"></core-icon-button>
        <div id="div">KATELYN</div>
        <core-icon-button icon="account-circle" id="core_icon_button1" on-tap="{{ showUsernamePasswordFields }}" theme="core-light-theme"></core-icon-button>
        <core-input placeholder="User Name" id="core_input1" hidden="true"></core-input>
        <core-input placeholder="Password" id="core_input2" hidden="true"></core-input>
        <core-icon-button icon="search" id="core_icon_button2" on-tap="{{ showSearchField }}" theme="core-light-theme"></core-icon-button>
        <core-input placeholder="Search" id="core_input" hidden="true"></core-input>
        <paper-tabs selected="0" selectedindex="0" id="paper_tabs" end end-justified four flex>
          <paper-tab id="paper_tab" active>Top</paper-tab>
          <paper-tab id="paper_tab1">New</paper-tab>
          <paper-tab id="paper_tab2">Popular</paper-tab>
          <paper-tab id="paper_tab3">Disputed</paper-tab>
          <paper-tab id="paper_tab4">Expert</paper-tab>
        </paper-tabs>
      </core-toolbar>
      <section id="section">
        <core-drawer-panel selected="main" narrow id="core_drawer_panel">
          <section id="section1" drawer>
            <core-menu selected="0" selectedindex="0" id="core_menu">
              <core-submenu active selected="0" label="Options" icon="sort" valueattr="name" id="core_submenu">
                <core-item label="Type" size="24" id="core_item1" horizontal center layout active></core-item>
                <core-item label="View" size="24" id="core_item" horizontal center layout active></core-item>
              </core-submenu>
              <core-submenu label="Settings" icon="settings" valueattr="name" id="core_submenu1">
                <core-item label="Language" size="24" id="core_item3" horizontal center layout></core-item>
                <core-item label="Privacy" size="24" id="core_item4" horizontal center layout></core-item>
                <core-item label="Region" size="24" id="core_item2" horizontal center layout></core-item>
              </core-submenu>
            </core-menu>
          </section>
          <section id="section2" main>
            <core-header-panel mode="standard" id="core_header_panel1">

      </core-header-panel>
          </section>
        </core-drawer-panel>
      </section>
    </core-header-panel>
  </template>

  <script>

    Polymer('my-element', {
      showUsernamePasswordFields: function () {
        if(this.$.core_input1.hidden == true && this.$.core_input2.hidden == true) {
            this.$.core_input1.style.display = 'block';
            this.$.core_input2.style.display = 'block';

          this.$.core_input1.hidden = false;
            this.$.core_input2.hidden = false;

          this.$.core_input.style.display = 'hidden';
          this.$.core_input.hidden = true;
        }
        else {
          this.$.core_input1.style.display = 'hidden';
            this.$.core_input2.style.display = 'hidden';

          this.$.core_input1.hidden = true;
            this.$.core_input2.hidden = true;
        }
      },
      showSearchField: function () {
        if(this.$.core_input.hidden == true) {
            this.$.core_input.style.display = 'block';

          this.$.core_input.hidden = false;

          this.$.core_input1.style.display = 'hidden';
          this.$.core_input2.style.display = 'hidden';
          this.$.core_input1.hidden = true;
          this.$.core_input2.hidden = true;
        }
        else {
          this.$.core_input.style.display = 'hidden';

          this.$.core_input.hidden = true;
        }
      }
    });

  </script>

</polymer-element>


<!-- This is where I declared my element -->
<my-element></my-element>

</body>

</html>

这是 Polymer Designer 显示的内容:http://imgur.com/5ys4ltM

这是我得到的:http://imgur.com/wwYlcYx

最佳答案

目前还没有从设计器到本地机器的超棒工作流程。 Designer 仍处于原型(prototype)/实验阶段。话虽如此,这就是我的处理方式:

  • 获取设计师生成的所有代码并将其放入本地文件。
  • 确保你有一个包含 platform.js 的脚本(我看到你有这个)
  • 查看所有为您生成的导入设计器,并将它们替换为:

我看到您几乎完成了这部分,但是您将路径保留为“../some-component/some-component.html”。您需要更新它们以指向您的 bower_components 目录。

最后,如果缺少某些东西,您可能需要bower install。因此,请检查控制台以确保您的导入没有出现 404 错误。如果出现这种情况,您需要安装缺少的依赖项。为了让这个 super 变得简单,我只需要运行这两个命令:

bower install --save Polymer/core-elements
bower install --save Polymer/paper-elements

这将使您获得设计师使用的大部分内容。如果您仍然缺少某些东西(例如 google-map),只需专门安装那个:bower install --save PolymerLabs/google-map 请注意,google-map 位于 PolymerLabs 组织中,而不是 Polymer 组织中;)

关于html - 如何在另一个 HTML 文档中使用来自 Polymer Project Designer 的代码,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24870356/

相关文章:

html - 如何将可下载文件添加到我的 Github.io 页面?

元素启动模板的polymer-cli 构建失败

cross-browser - 检测浏览器对Polymer的支持

html - CSS3 :hover effect for child element - Firefox and Explorer doesn't work

git - 使用所有分支更新 fork 的 Github 存储库

github - 在 github 上的 README.md 中添加 PDF 图

polymer - 如何使用Polymer web-component-tester进行特定测试?

javascript - 为什么我的像素操作脚本这么慢?

html - 将实时视频从网站流式传输到 restream-server

html - 如何使用 CSS3 自动在屏幕上显示一个巨大的图像?