-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy patheditor.js
87 lines (85 loc) · 2.66 KB
/
editor.js
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
import { PolymerElement, html } from "@polymer/polymer/polymer-element";
import { afterNextRender } from "@polymer/polymer/lib/utils/render-status";
import '@polymer/iron-pages';
import '@polymer/paper-tabs';
import '@polymer/paper-fab';
import '@polymer/iron-icons';
import './editor-tabs';
class EditorElement extends PolymerElement{
constructor(){
super();
this.tabCount = 3;
}
static get properties(){
return {
selected: {
type: Number,
value: 0,
notify: true,
reflectToAttribute: true
}
};
}
static get template(){
return html`
<style>
:host {
display: block;
}
paper-tabs, editor-tabs {
background-color: var(--tabs-background-colour, mediumslateblue);
--paper-tabs-selection-bar-color: var(--tabs-colour, white);
color: var(--tabs-colour, white);
}
paper-fab {
position: fixed;
top: 20px;
right: 24px;
}
</style>
<editor-tabs id="tabs" selected="{{selected}}" on-closeclicked="close_tab">
<editor-tab>Tab 1</editor-tab>
<editor-tab>Tab 2</editor-tab>
<editor-tab>Tab 3</editor-tab>
</editor-tabs>
<iron-pages id="pages" selected="{{selected}}">
<div>Page 1</div>
<div>Page 2</div>
<div>Page 3</div>
</iron-pages>
<paper-fab icon="add" on-click="add_tab"></paper-fab>
`;
}
add_tab(){
let n = ++this.tabCount;
let newTab = `<editor-tab>Tab ${n}</editor-tab>`;
let newPage = `<div>Page ${n}</div>`;
//if there are no pages selected aka no pages left
if(!(this.selectedTab || this.selectedPage)){
this.$.tabs.innerHTML += newTab;
this.$.pages.innerHTML += newPage;
this.selected = 0;
}
else {
this.selectedTab.insertAdjacentHTML('afterend', newTab);
this.selectedPage.insertAdjacentHTML('afterend', newPage);
this.selected++;
}
}
/**
* @param {CustomEvent} ev
*/
close_tab(ev){
let i = ev.detail.index;
this.$.tabs.children[i].remove();
this.$.pages.children[i].remove();
this.selected = Math.max(this.selected - 1, 0);
}
get selectedTab(){
return this.$.tabs.children[this.selected];
}
get selectedPage(){
return this.$.pages.children[this.selected];
}
}
customElements.define('scorm-editor', EditorElement);