-
Notifications
You must be signed in to change notification settings - Fork 31
/
sc-suttaplex.html
439 lines (374 loc) · 13.9 KB
/
sc-suttaplex.html
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
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
<link rel="import" href="/bower_components/polymer/polymer.html">
<link rel="import" href="/bower_components/paper-icon-button/paper-icon-button.html">
<link rel="import" href="/bower_components/iron-collapse/iron-collapse.html">
<link rel="import" href="/bower_components/paper-menu-button/paper-menu-button.html">
<link rel="import" href="/bower_components/paper-styles/paper-styles.html">
<link rel="import" href="/bower_components/paper-listbox/paper-listbox.html">
<link rel="import" href="/bower_components/paper-item/paper-item.html">
<link rel="import" href="/bower_components/paper-button/paper-button.html">
<link rel="import" href="/bower_components/iron-icons/iron-icons.html">
<link rel="import" href="/bower_components/paper-card/paper-card.html">
<link rel="import" href="/bower_components/iron-ajax/iron-ajax.html">
<link rel="import" href="/bower_components/paper-badge/paper-badge.html">
<link rel="import" href="/bower_components/paper-badge/paper-badge.html">
<link rel="import" href="/bower_components/paper-toast/paper-toast.html">
<link rel="import" href="/img/sc-svg-icons.html">
<link rel="import" href="/elements/addons/sc-sutta-note.html">
<link rel="import" href="/elements/menus/language-menu.html">
<link rel="import" href="/elements/menus/more-par-menu.html">
<link rel="import" href="/elements/suttaplex/sc-view-parallels.html">
<!--
Suttaplex card
-->
<dom-module id="sc-suttaplex" attributes="open url">
<template>
<style include="sc-suttaplex-styles">
.heading {
cursor: pointer;
}
.suttaplex-head-container {
display: flex;
justify-content: space-between;
align-items: center;
}
h1, h2, h3 {
margin: 0;
}
paper-card.suttaplex {
border-radius: 0;
border-top: 1px solid var(--paper-grey-300);
display: block;
}
paper-card.suttaplex .card-content {
padding-top: 24px;
padding-bottom: 1px;
}
.suttaplex-heading {
@apply --paper-font-headline;
@apply --sc-serif-font;
}
.suttaplex-nerdy-row {
@apply --paper-font-body2;
color: var(--secondary-text-color);
font-weight: normal;
white-space: nowrap;
overflow: hidden;
}
.suttaplex-nerdy-row span {
margin-right: 24px;
}
.suttaplex-description {
@apply --sc-paper-font-body;
overflow: hidden;
}
paper-card.suttaplex .card-actions {
padding: 0 16px 8px;
display: flex;
justify-content: space-between;
align-items: baseline;
border-top: 0;
}
.card-actions-left {
display: inline-block;
}
.card-actions-right {
display: inline-block;
}
.languagedrop {
display: inline-block;
vertical-align: middle;
margin: -18px 4px 0;
padding: 0 8px;
}
paper-badge {
--paper-badge-background: var(--paper-green-a700);
}
#moremenu {
visibility: hidden;
}
summary::-webkit-details-marker {
color: var(--paper-grey-300);
}
details {
display: inline-block;
}
details p {
@apply --paper-font-body1;
@apply --shadow-elevation-3dp;
position: absolute;
z-index: 200;
background-color: #fff;
padding: 12px;
border-top: 1px solid rgba(0, 0, 0, 0.12);
margin: 0 48px 0 0;
white-space: normal;
}
paper-menu-button {
padding: 0;
}
.notfound {
@apply --paper-font-display1;
}
.hide-element {
display: none;
}
.difficulty-icon {
padding-right: 8px;
}
.toggle-button {
min-width: 40px;
align-self: flex-end;
}
.more-info {
align-self: flex-end;
}
.paper-badge {
--paper-badge-margin-left: -15px;
--paper-badge-margin-bottom: -10px;
}
.segmented-border {
padding: 5px;
border: 1px dashed var(--paper-grey-700);
border-radius: 5px;
}
.display-inline {
display: inline-block;
}
.volpage-biblio-info-summary {
outline: none;
cursor: pointer;
}
.volpage-biblio-info {
@apply --paper-font-body1;
position: absolute;
z-index: 200;
background-color: #fff;
@apply --shadow-elevation-3dp;
padding: 12px;
border-top: 1px solid rgba(0, 0, 0, 0.12);
margin: 0 48px 0 0;
white-space: normal;
}
.no-margin {
margin: 0;
}
.toast {
--paper-toast-color: white;
text-align: center;
font-size: 20px;
margin-left: calc(50vw - 150px);
}
.success-toast {
--paper-toast-background-color: green;
}
.error-toast {
--paper-toast-background-color: red;
}
@media screen and (max-width: 596px) {
.right-elements {
display: flex;
flex-flow: column;
}
#copy_menu {
order: 1;
}
#parallels_toggle {
order: 0;
}
}
</style>
<paper-card class="suttaplex" id="[[item.uid]]">
<div class="card-content">
<div class="suttaplex-head-container">
<h3 class="suttaplex-heading">[[_computeMainHeading(item)]]</h3>
<div class$="difficulty-icon [[item.difficulty.name]]"
title="Recommended for [[item.difficulty.name]] students">
<iron-icon icon="[[_computeLevel(item.difficulty.name)]]"></iron-icon>
</div>
</div>
<div class="suttaplex-nerdy-row">
<span title="Original title" class$="[[_computeHideOriginalTitle(item)]]">[[item.original_title]]</span>
<span title="SuttaCentral ID" class$="[[_computeHideUID(item)]]">[[item.acronym]]</span>
<template is="dom-if" if="[[item.volpages]]">
<template is="dom-if" if=[[!item.biblio]]>
<span class="book" class="no-margin"><iron-icon icon="book"></iron-icon></span>
<span class="vol-page" title="Volume and page">[[item.volpages]]</span>
</template>
<template is="dom-if" if=[[item.biblio]]>
<details class="display-inline">
<summary class="volpage-biblio-info-summary">
<span class="book" class="no-margin"><iron-icon icon="book"></iron-icon></span>
<span class="vol-page" title="Volume and page">[[item.volpages]]</span>
</summary>
<p class="volpage-biblio-info" inner-h-t-m-l="[[item.biblio]]"></p>
</details>
</template>
</template>
</div>
<p class$="suttaplex-description [[_computeHide(item.blurb)]]" title="Description"
inner-h-t-m-l="[[item.blurb]]"></p>
</div>
<div class="card-actions">
<div class="card-actions-left">
<template is="dom-repeat" items="[[item.translations]]" as="translation">
<template is="dom-if" if="{{ _isChosenLang(translation.lang) }}">
<paper-button flat title$="Go to a translation by [[translation.author]]">
<a href="[[_computeApiUrlEndpoint(item.uid, translation.author)]]"
class$="{{ _translationBorder(translation.segmented) }}">[[translation.author]]</a>
</paper-button>
</template>
</template>
<div class="languagedrop">
<language-menu language-choice="[[item.translations]]" title-label="More"
input-language="[[inputLanguage]]" original-language="[[item.root_lang]]"
root-id="[[item.uid]]" on-paper-dropdown-close="_changeItemZIndex"
on-paper-dropdown-open="_changeItemZIndex"></language-menu>
</div>
</div>
<div class="right-elements">
<template is="dom-if" if="[[parallelsOpened]]">
<paper-menu-button id="copy_menu" horizontal-align="right" role="group" aria-haspopup="true"
vertical-align="top" aria-disabled="false">
<paper-icon-button class="more-info" slot="dropdown-trigger" icon="icons:more-vert" role="button"
tabindex="0" aria-disabled="false"></paper-icon-button>
<div slot="dropdown-content"></div>
<paper-listbox slot="dropdown-content" tabindex="0" role="listbox">
<more-par-menu tabindex="0" item="[[item]]" ></more-par-menu>
</paper-listbox>
</paper-menu-button>
</template>
<paper-icon-button id="parallels_toggle" class="toggle-button" icon="[[toggleIcon]]"
on-tap="_toggleParallelsOpened">
</paper-icon-button>
<paper-badge for="parallels_toggle" label="[[item.parallel_count]]" class="paper-badge"
title="Number of parallels"></paper-badge>
</div>
</div>
<template is="dom-if" if="[[parallelsOpened]]">
<iron-collapse no-animation id="collapse" opened="{{ parallelsOpened }}">
<sc-view-parallels root-lang="[[item.root_lang]]" item-uid="[[item.uid]]"></sc-view-parallels>
</iron-collapse>
</template>
</paper-card>
<paper-toast id="success_toast" class="toast success-toast" text="[[toastMessage]]" duration=3000></paper-toast>
<paper-toast id="error_toast" class="toast error-toast" text="[[toastMessage]]" duration=3000></paper-toast>
</template>
<script>
class SCSuttaplex extends Polymer.Element {
static get is() {
return 'sc-suttaplex'
}
static get properties() {
return {
toggleIcon: {
type: String,
computed: '_computeToggleIcon(parallelsOpened)'
},
parallelsOpened: {
type: Boolean,
value: false,
observer: '_parallelsOpenedChanged'
},
opened: {
type: Boolean,
reflectToAttribute: true,
notify: true
},
_toggleIcon: {
type: String,
computed: '_computeToggleIcon(opened)'
},
_toggleMoreIcon: {
type: String,
computed: '_computeToggleMoreIcon(opened)'
},
inputLanguage: {
type: String,
value: 'en' // Temporary hardcoded
},
level: String,
// The suttaplex item
item: Object,
toastMessage: {
type: String
}
}
}
ready() {
super.ready();
this.addEventListener('par-menu-copied', (e) => {
this.toastMessage = e.detail.message;
const success = e.detail.success;
if (success) {
this.$.success_toast.open();
} else {
this.$.error_toast.open();
}
copy_menu.opened = false; // Close dropdown after the copy action.
})
}
_changeItemZIndex(e) {
let node = this.parentNode;
if(node.style === undefined){
return;
}
if (e.type.endsWith('open')) {
node.style['z-index'] = 100;
} else if (node.style['z-index'] == 100 && this.parallelsOpened === false) {
node.style['z-index'] = null;
}
}
_parallelsOpenedChanged(e) {
const type = e ? 'open' : 'close';
const event_mock = { type: type };
this._changeItemZIndex(event_mock);
}
// general function to hide or display various elements.
_computeHide(checkText) {
return (!checkText) ? 'hide-element' : '';
}
_computeHideUID(item) {
return (item.translated_title || item.original_title) ? '' : 'hide-element'
}
_computeHideOriginalTitle(item) {
return item.translated_title ? '' : 'hide-element'
}
// returns the relevant icon for the expander
_computeToggleIcon(parallelsOpened) {
return parallelsOpened ? 'icons:expand-less' : 'icons:expand-more';
}
// shows the more-par menu when the expander is opened.
_computeToggleMoreIcon(opened) {
return opened ? '' : 'moremenu';
}
// adds the 'tree'-icons to denote difficulty level if any.
_computeLevel(level) {
return level ? 'sc-svg-icons:' + level : '';
}
// Computes API endpoint URL for given translation
_computeApiUrlEndpoint(uid, author) {
return `/sutta/${uid}/?author=${author}`;
}
_isChosenLang(lang) {
return lang === this.inputLanguage;
}
_toggleParallelsOpened() {
this.parallelsOpened = !this.parallelsOpened;
this.dispatchEvent(new CustomEvent('iron-resize', {composed: true, bubbles: true}));
}
_computeMainHeading(item) {
if (item.translated_title) {
return item.translated_title;
} else if (item.original_title) {
return item.original_title;
} else {
return item.acronym;
}
}
_translationBorder(segmented) {
return segmented ? 'segmented-border' : '';
}
}
customElements.define(SCSuttaplex.is, SCSuttaplex);
</script>
</dom-module>