forked from zuohahaha/tinymce-plugin-letterspacing
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathplugin.js
More file actions
78 lines (76 loc) · 2.22 KB
/
plugin.js
File metadata and controls
78 lines (76 loc) · 2.22 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
(function(tinymce) {
tinymce.PluginManager.add('letterspacing', function(editor, url, $) {
editor.on('init', function() {
editor.formatter.register({
letterspacing: {
inline: 'span',
styles: {
'letter-spacing': '%value'
}
}
})
})
editor.addButton('letterspacingselect', function() {
var items = [],
defaultLetterSpacingFormats = '0 0.5pt 1pt 1.5pt 2pt 3pt'
var letterspacing_formats = editor.settings.letterspacing_formats || defaultLetterSpacingFormats
letterspacing_formats.split(' ').forEach(function(item) {
var text = item,
value = item
// Allow text=value for line-height formats
var values = item.split('=')
if (values.length > 1) {
text = values[0]
value = values[1]
}
items.push({
text: text,
value: value
})
})
return {
type: 'listbox',
text: '字间距',
tooltip: '字间距',
values: items,
fixedWidth: true,
onPostRender: function() {
var self = this
editor.on('nodeChange', function(e) {
var formatName = 'letterspacing'
var formatter = editor.formatter
var value = null
e.parents.forEach(function(node) {
items.forEach(function(item) {
if (formatName) {
if (formatter.matchNode(node, formatName, {
value: item.value
})) {
value = item.value
}
} else {
if (formatter.matchNode(node, item.value)) {
value = item.value
}
}
if (value) {
return false
}
})
if (value) {
return false
}
})
self.value(value)
})
},
onselect: function(e) {
tinymce.activeEditor.formatter.apply('letterspacing', {
value: this.value()
})
}
}
})
})
tinymce.PluginManager.requireLangPack('letterspacing', 'de')
})(tinymce)