Plugin.js
3.37 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
/**
* Plugin.js
*
* Released under LGPL License.
* Copyright (c) 1999-2015 Ephox Corp. All rights reserved
*
* License: http://www.tinymce.com/license
* Contributing: http://www.tinymce.com/contributing
*/
/**
* This class contains the tinymce plugin logic for the paste plugin.
*
* @class tinymce.pasteplugin.Plugin
* @private
*/
define("tinymce/pasteplugin/Plugin", [
"tinymce/PluginManager",
"tinymce/pasteplugin/Clipboard",
"tinymce/pasteplugin/WordFilter",
"tinymce/pasteplugin/Quirks"
], function(PluginManager, Clipboard, WordFilter, Quirks) {
var userIsInformed;
PluginManager.add('paste', function(editor) {
var self = this, clipboard, settings = editor.settings;
function isUserInformedAboutPlainText() {
return userIsInformed || editor.settings.paste_plaintext_inform === false;
}
function togglePlainTextPaste() {
if (clipboard.pasteFormat == "text") {
this.active(false);
clipboard.pasteFormat = "html";
editor.fire('PastePlainTextToggle', {state: false});
} else {
clipboard.pasteFormat = "text";
this.active(true);
if (!isUserInformedAboutPlainText()) {
var message = editor.translate('Paste is now in plain text mode. Contents will now ' +
'be pasted as plain text until you toggle this option off.');
editor.notificationManager.open({
text: message,
type: 'info'
});
userIsInformed = true;
editor.fire('PastePlainTextToggle', {state: true});
}
}
editor.focus();
}
// draw back if power version is requested and registered
if (/(^|[ ,])powerpaste([, ]|$)/.test(settings.plugins) && PluginManager.get('powerpaste')) {
/*eslint no-console:0 */
if (typeof console !== "undefined" && console.log) {
console.log("PowerPaste is incompatible with Paste plugin! Remove 'paste' from the 'plugins' option.");
}
return;
}
self.clipboard = clipboard = new Clipboard(editor);
self.quirks = new Quirks(editor);
self.wordFilter = new WordFilter(editor);
if (editor.settings.paste_as_text) {
self.clipboard.pasteFormat = "text";
}
if (settings.paste_preprocess) {
editor.on('PastePreProcess', function(e) {
settings.paste_preprocess.call(self, self, e);
});
}
if (settings.paste_postprocess) {
editor.on('PastePostProcess', function(e) {
settings.paste_postprocess.call(self, self, e);
});
}
editor.addCommand('mceInsertClipboardContent', function(ui, value) {
if (value.content) {
self.clipboard.pasteHtml(value.content);
}
if (value.text) {
self.clipboard.pasteText(value.text);
}
});
// Block all drag/drop events
if (editor.settings.paste_block_drop) {
editor.on('dragend dragover draggesture dragdrop drop drag', function(e) {
e.preventDefault();
e.stopPropagation();
});
}
// Prevent users from dropping data images on Gecko
if (!editor.settings.paste_data_images) {
editor.on('drop', function(e) {
var dataTransfer = e.dataTransfer;
if (dataTransfer && dataTransfer.files && dataTransfer.files.length > 0) {
e.preventDefault();
}
});
}
editor.addButton('pastetext', {
icon: 'pastetext',
tooltip: 'Paste as text',
onclick: togglePlainTextPaste,
active: self.clipboard.pasteFormat == "text"
});
editor.addMenuItem('pastetext', {
text: 'Paste as text',
selectable: true,
active: clipboard.pasteFormat,
onclick: togglePlainTextPaste
});
});
});