forked from LRNWebComponents/hax-body
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathhax-text-context.html
231 lines (225 loc) · 7.36 KB
/
hax-text-context.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
<link rel="import" href="../polymer/polymer.html">
<link rel="import" href="../md-extra-icons/md-extra-icons.html">
<link rel="import" href="../app-layout/app-toolbar/app-toolbar.html">
<link rel="import" href="../paper-input/paper-textarea.html">
<link rel="import" href="../paper-input/paper-input.html">
<link rel="import" href="../paper-checkbox/paper-checkbox.html">
<link rel="import" href="../paper-swatch-picker/paper-swatch-picker.html">
<link rel="import" href="../paper-slider/paper-slider.html">
<link rel="import" href="../paper-tooltip/paper-tooltip.html">
<link rel="import" href="../paper-item/paper-item.html">
<link rel="import" href="../iron-icons/iron-icons.html">
<link rel="import" href="hax-context-item-menu.html">
<link rel="import" href="hax-context-item.html">
<!--
`hax-text-context`
A context menu that provides common text based authoring options.
@demo demo/index.html
@microcopy - the mental model for this element
- context menu - this is a menu of text based buttons and events for use in a larger solution.
-->
<dom-module id="hax-text-context">
<template>
<style>
:host {
display: block;
}
app-toolbar {
background-color: white;
padding: 0;
height: 40px;
}
hax-context-item {
margin: 0;
width: 40px;
height: 40px;
}
.close-cap {
margin: 0;
padding: 0;
border-right: 1px solid black;
}
</style>
<app-toolbar>
<hax-context-item
icon="close"
label="Close menu"
event-name="close-menu"
class="close-cap"
direction="left"></hax-context-item>
<hax-context-item-menu
selected-value="{{selectedValue}}"
id="formatsize"
icon="text-format"
label="Text style"
event-name="text-tag">
<paper-item value="p">Normal text</paper-item>
<paper-item value="h2">Title</paper-item>
<paper-item value="h3">Content heading</paper-item>
<paper-item value="h4">Subheading</paper-item>
<paper-item value="h5">Deeper subheading</paper-item>
<paper-item value="blockquote">Quote</paper-item>
<paper-item value="code">Code</paper-item>
</hax-context-item-menu>
<hax-context-item
icon="editor:format-bold"
label="Bold"
event-name="text-bold"></hax-context-item>
<hax-context-item
icon="editor:format-italic"
label="Italic"
event-name="text-italic"></hax-context-item>
<hax-context-item-menu
selected-value="{{justifyValue}}"
id="justify"
icon="[[justifyIcon]]"
label="Alignment">
<paper-item value="text-align-left">
<iron-icon icon="editor:format-align-left"></iron-icon>
</paper-item>
<paper-item value="text-align-right">
<iron-icon icon="editor:format-align-right"></iron-icon>
</paper-item>
</hax-context-item-menu>
<hax-context-item
icon="editor:format-list-numbered"
label="Numbered list"
event-name="text-list-numbered"></hax-context-item>
<hax-context-item
icon="editor:format-list-bulleted"
label="Bulleted list"
event-name="text-list-bulleted"></hax-context-item>
<hax-context-item
icon="editor:format-indent-increase"
label="Indent"
event-name="text-indent"></hax-context-item>
<hax-context-item
icon="editor:format-indent-decrease"
label="Outdent"
event-name="text-outdent"></hax-context-item>
<hax-context-item
icon="editor:format-strikethrough"
label="Cross out"
event-name="text-strikethrough"></hax-context-item>
<hax-context-item
icon="mdextra:subscript"
label="Subscript"
event-name="text-subscript"></hax-context-item>
<hax-context-item
icon="mdextra:superscript"
label="Superscript"
event-name="text-superscript"></hax-context-item>
<hax-context-item
icon="editor:insert-link"
label="Link"
event-name="text-link"></hax-context-item>
<hax-context-item
icon="mdextra:unlink"
label="Unlink"
event-name="text-unlink"></hax-context-item>
<hax-context-item
icon="editor:format-clear"
label="Remove format"
event-name="text-remove-format"></hax-context-item>
</app-toolbar>
</template>
<script>
Polymer({
is: 'hax-text-context',
listeners: {
'hax-context-item-selected': '_haxContextOperation',
},
properties: {
/**
* Justify icon to reflect state.
*/
justifyIcon: {
type: String,
value: 'editor:format-align-left',
},
/**
* Selected value to match format of the tag currently.
*/
selectedValue: {
type: String,
value: 'p',
notify: true,
},
/**
* Selected value to match text direction currently.
*/
justifyValue: {
type: String,
value: 'text-align-left',
notify: true,
},
},
/**
* Respond to simple modifications.
*/
_haxContextOperation: function(e) {
let detail = e.detail;
// support a simple insert event to bubble up or everything else
switch(detail.eventName) {
// wow these are way too easy
case 'text-bold':
document.execCommand('bold');
break;
case 'text-italic':
document.execCommand('italic');
break;
case 'text-list-numbered':
document.execCommand('insertOrderedList');
break;
case 'text-list-bulleted':
document.execCommand('insertUnorderedList');
break;
case 'text-underline':
document.execCommand('underline');
break;
case 'text-indent':
document.execCommand('indent');
break;
case 'text-outdent':
document.execCommand('outdent');
break;
case 'text-subscript':
document.execCommand('subscript');
break;
case 'text-superscript':
document.execCommand('superscript');
break;
case 'text-remove-format':
document.execCommand('removeFormat');
break;
case 'text-strikethrough':
document.execCommand('strikeThrough');
break;
case 'text-link':
let url = prompt("Enter a URL:");
document.execCommand('createLink', false, url);
break;
case 'text-unlink':
document.execCommand('unlink');
break;
case 'text-align-left':
this.justifyIcon = detail.target.children[0].attributes[0].nodeValue;
break;
case 'text-align-center':
this.justifyIcon = detail.target.children[0].attributes[0].nodeValue;
break;
case 'text-align-right':
this.justifyIcon = detail.target.children[0].attributes[0].nodeValue;
break;
case 'text-justify-full':
this.justifyIcon = detail.target.children[0].attributes[0].nodeValue;
break;
case 'close-menu':
this.$.justify.hideMenu();
this.$.formatsize.hideMenu();
break;
}
},
});
</script>
</dom-module>