-
Notifications
You must be signed in to change notification settings - Fork 9
Expand file tree
/
Copy pathpolymer-tinymce.html
More file actions
269 lines (221 loc) · 6.85 KB
/
Copy pathpolymer-tinymce.html
File metadata and controls
269 lines (221 loc) · 6.85 KB
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
<link rel="import" href="../polymer/polymer.html">
<link rel="import" href="../import-tinymce/import-tinymce.html">
<!--
HTML editor.
Example:
<polymer-tinymce></polymer-tinymce>
Example:
<polymer-tinymce id="editor" menubar="false"></polymer-tinymce>
Example:
<polymer-tinymce id="editor2"
tinytoolbar="insertfile undo redo | styleselect | bold italic | alignleft aligncenter alignright alignjustify | bullist numlist outdent indent | link image"
tinyplugins='["template advlist autolink lists link image charmap print preview anchor","searchreplace visualblocks code fullscreen","insertdatetime media table contextmenu paste"]'
templates='[
{"title": "Some title 1", "description": "Some desc 1", "content": "My content"},
{"title": "Some title 2", "description": "Some desc 2", "url": "http://google.com"}]'
></polymer-tinymce>
@group Seed Elements
@element polymer-tinymce
@demo demo/index.html
@hero hero.svg
-->
<dom-module id="polymer-tinymce">
<template>
<textarea id$="[[_textareaId]]" name="[[name]]" style="width:100%" class="te"></textarea>
</template>
</dom-module>
<script>
Polymer({
is: 'polymer-tinymce',
properties: {
/**
* The content of the editor.
* It is safer though to call getContent()
* whenever you need the content.
* Only updates on focus or node change.
*/
value: {
type: String,
readOnly: true,
},
/**
* Options are: "insertfile undo redo | styleselect | bold italic | alignleft aligncenter alignright alignjustify | bullist numlist outdent indent | link image"
*/
tinytoolbar:{
type:String,
value:"undo | bullist"
},
/**
* Options are: ["advlist autolink lists link image charmap print preview anchor","searchreplace visualblocks code fullscreen","insertdatetime media table contextmenu paste"]
*/
tinyplugins:{
type:Array,
value:["advlist autolink lists link image charmap preview anchor fullscreen"]
},
/**
* The menubar options.
*/
menubar: {
type: String,
value: 'file edit insert view format table tools',
},
/**
* If true, the status bar is hidden.
*/
noStatusbar: {
type: Boolean,
value: false,
},
/**
* Html or an url that can be loaded from the editor. e.g.
* [{title: 'Some title 1', description: 'Some desc 1', content: 'My content'},
* {title: 'Some title 2', description: 'Some desc 2', url: 'development.html'}]
*/
templates: {
type: Array,
value: function () { return [] }
},
/**
* The height of the editor.
*/
height: {
type: Number,
value: 168
},
/**
* Base URL of the root directory where TinyMCE is located.
*/
baseUrl: {
type: String,
value: ''
},
/**
* Options TinyMCE's init function.
* Some options are already exposed by this element's properties.
*/
initOptions: {
type: Object,
value() { return {} },
},
/**
* Only change this property if you know what you are doing.
* Attributes in this Array wont get overwritten by initOptions.
*/
protectedInitOptions: {
type: Array,
value() { return ['selector', 'setup'] },
},
_textareaId: {
type: String,
value: ''
},
/**
Fires after the editor has been initialized.
This is after the editor
has been filled with contents.
@event tiny-init
*/
/**
Fires when the editor gets focused.
@event tiny-focus
*/
/**
Fires when the selection
is moved to a new location
or is the DOM is updated by some command.
This event enables you to update the UI
based on the current selection etc.
@event tiny-node
*/
/**
Fires when contents is modified in the editor.
@event tiny-change
*/
},
observers: [
'_initEditor(_textareaId, initOptions, height, tinytoolbar, tinyplugins, menubar, noStatusbar, templates)'
],
attached: function(){
this._textareaId = this._getUniqueId();
},
_initEditor: function (_textareaId) {
if (!_textareaId || _textareaId === '') return;
if (this.baseUrl !== '') {
tinymce.baseURL = this.baseUrl;
}
var setup = function (ed) {
ed.on('init', function(args) {
this._updateValue();
this.fire('tiny-init', args);
}.bind(this));
ed.on('focus', function(e) {
this._updateValue();
this.fire('tiny-focus', e);
}.bind(this));
ed.on('NodeChange', function(e) {
this._updateValue();
this.fire('tiny-node', e);
}.bind(this));
ed.on('Change', function(e) {
this._updateValue();
this.fire('tiny-change', e);
}.bind(this));
}.bind(this)
var options = {
selector: '#' + this._textareaId,
templates: this.templates,
plugins: this.tinyplugins,
toolbar: this.tinytoolbar,
menubar: this.menubar,
statusbar: !this.noStatusbar,
height: this.height,
setup: setup
}
// Overwrite/Set defaultOptions with initOptions
for (var k in this.initOptions) {
if(this.protectedInitOptions.indexOf(k) === -1) options[k] = this.initOptions[k];
}
// Remove instance if exists
tinymce.remove(options['selector']);
// Initialize
tinymce.init(options);
},
_updateValue() {
this.getContent();
},
/**
* Executes a specific command on the currently active editor.
*/
execCommand: function(command){
tinyMCE.activeEditor.execCommand(command);
},
/**
* Gets the content from the editor instance, this will cleanup the content before it gets returned using
* the different cleanup rules options.
* Updates the value property.
*/
getContent: function(options){
if (!tinyMCE || !tinyMCE.get(this._textareaId)) return;
if (typeof options !== 'undefined') {
var content = tinyMCE.get(this._textareaId).getContent(options);
} else {
var content = tinyMCE.get(this._textareaId).getContent();
}
this._setValue(content);
return content;
},
/**
* Sets the content of the editor.
*/
setContent: function(content){
if (!tinyMCE || !tinyMCE.get(this._textareaId)) return;
tinyMCE.get(this._textareaId).setContent(content);
},
_getUniqueId: function() {
var S4 = function() {
return (((1+Math.random())*0x10000)|0).toString(16).substring(1);
};
return (S4()+S4()+"-"+S4()+"-"+S4()+"-"+S4()+"-"+S4()+S4()+S4());
}
});
</script>