Blame view

bower_components/polymer-element-catalog/app/elements/pages/page-guide.html 5.4 KB
07d13c9c   isisadmin   polymer catalog
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
  <link rel="import" href="../../bower_components/iron-icon/iron-icon.html">
  <link rel="import" href="../../bower_components/paper-item/paper-item.html">
  <link rel="import" href="../../bower_components/paper-styles/paper-styles.html">
  <link rel="import" href="../../bower_components/paper-drawer-panel/paper-drawer-panel.html">
  
  <link rel="import" href="../catalog-guide/catalog-guide.html">
  <link rel="import" href="../catalog-data/catalog-data.html">
  
  <dom-module id="page-guide">
    <style>
      .content {
        display: block;
        padding: 12px 24px;
      }
  
      #main {
        background: #fafafa;
      }
  
      .guide-section {
        background: white;
        margin: 24px auto;
        max-width: 800px;
        padding-bottom: 1px;
        @apply(--shadow-elevation-2dp);
      }
  
      .guide-section .reference-link {
        float: right;
        margin: 12px 18px;
        color: #999;
      }
  
      .guide-section .reference-link:hover {
        color: #333;
      }
  
      .guide-section > h2 {
        border-bottom: 1px solid #e5e5e5;
        font-size: 20px;
        line-height: 28px;
        padding: 10px 18px;
        margin: 0;
      }
  
      .guide-section h3 {
        font-size: 18px;
        margin: 20px 20px 12px 20px;
        font-weight: bold;
      }
  
      .guide-section h4 {
        font-weight: bold;
        font-size: 16px;
        margin: 18px 20px 12px 20px;
      }
  
      .guide-section p {
        margin: 16px 20px;
      }
  
      .guide-section pre {
        padding: 20px;
        background: #fafafa;
        border: solid #e5e5e5;
        border-width: 1px 0;
      }
  
      #main > paper-toolbar {
        --paper-toolbar-background: #fafafa;
        font-size: 20px;
      }
  
      app-sidebar paper-toolbar {
        --paper-toolbar-background: white;
      }
  
      #guide-list .item {
        display: block;
        font-weight: 400;
        cursor: pointer;
        font-size: 14px;
        line-height: 24px;
        padding: 0 24px;
      }
  
      [paper-drawer-toggle] {
        margin: 0 10px;
        cursor: pointer;
      }
  
      app-sidebar h4 {
        font-size: 14px;
        font-weight: 500;
        margin: 12px 24px;
      }
    </style>
    <template>
      <prism-highlighter></prism-highlighter>
  
      <catalog-data guides="{{guides}}"></catalog-data>
      <catalog-guide name="[[name]]" data="{{guide}}" content="{{content}}" on-catalog-guide-error="_catalogGuideError"></catalog-guide>
  
      <paper-drawer-panel drawer-width="272px" disable-edge-swipe>
        <app-sidebar drawer>
          <paper-toolbar>
            <app-logo class="flex"></app-logo>
            <app-bar class="horizontal layout center end-justified"></app-bar>
          </paper-toolbar>
          <h4>Guides</h4>
          <nav id="guide-list" class="flex">
            <template is="dom-repeat" items="[[guides]]">
              <a class="item" is="app-link" href$="[[_guideUrl(item.name)]]">[[item.title]]</a>
            </template>
          </nav>
        </app-sidebar>
        <paper-header-panel mode="waterfall" class="vertical layout fit" id="main" main>
          <paper-toolbar class="paper-header flex-none">
            <iron-icon icon="menu" paper-drawer-toggle></iron-icon>
            <span class="flex">[[guide.title]]</span>
          </paper-toolbar>
  
          <div class="content fit">
            <div id="content"></div>
          </div>
        </paper-header-panel>
      </paper-drawer-panel>
    </template>
  </dom-module>
  
  <script>
    Polymer({
      is: 'page-guide',
      properties: {
        router: Object,
        guides: Array,
        guide: Object,
        name: {
          type: String,
          observer: '_nameChanged'
        },
        content: String
      },
      enableCustomStyleProperties: true,
      observers: [
        'contentChanged(content)',
        'updateMeta(guide)'
      ],
  
      contentChanged: function() {
        if (this.content.indexOf('<!doctype') >= 0) {
          this._catalogGuideError();
        } else { console.log( this.content);
          this.$.content.innerHTML = this.content;
          this._decorateHeadings();
          this._highlight();
          this.scopeSubtree(this.$.content);
          if (window.location.hash !== "") {
            var el = Polymer.dom(this.$.content).querySelector(window.location.hash);
            if (el) el.scrollIntoView();
          }
        }
      },
  
      _nameChanged: function() {
        this.$.content.innerHTML = '';
      },
  
      _decorateHeadings: function() {
        var h2s = this.$.content.querySelectorAll('h2');
        for (var i = 0; i < h2s.length; i++) {
          var link = document.createElement('a');
          link.className = "reference-link";
          link.href = "#" + h2s[i].id;
          var icon = document.createElement('iron-icon');
          icon.icon = 'link';
          link.appendChild(icon);
          h2s[i].parentNode.insertBefore(link, h2s[i]);
        }
      },
      _highlight: function() {
        var els = this.$.content.querySelectorAll('pre code');
        for (var i = 0; i < els.length; i++) {
          var code = els[i].textContent;
          var event = this.fire('syntax-highlight', {code: code});
          if (event.detail.code && !els[i].highlighted) {
            els[i].highlighted = true;
            els[i].innerHTML = event.detail.code;
          }
        }
      },
      _guideUrl: function(name) {
        return "/guides/" + name;
      },
      updateMeta: function() {
        this.fire('page-meta', {title: this.guide.title});
      },
      nav: function(e) {
        var name = e.currentTarget.getAttribute('name');
        if (this.name !== name) {
          this.router.go('/guides/' + name);
        }
      },
      _catalogGuideError: function() {
        this.router.go('/404');
      }
    });
  </script>