|
1 /** |
|
2 * Plugin.js |
|
3 * |
|
4 * Copyright, Moxiecode Systems AB |
|
5 * Released under LGPL License. |
|
6 * |
|
7 * License: http://www.tinymce.com/license |
|
8 * Contributing: http://www.tinymce.com/contributing |
|
9 */ |
|
10 |
|
11 /** |
|
12 * This class contains the tinymce plugin logic for the paste plugin. |
|
13 * |
|
14 * @class tinymce.pasteplugin.Plugin |
|
15 * @private |
|
16 */ |
|
17 define("tinymce/pasteplugin/Plugin", [ |
|
18 "tinymce/PluginManager", |
|
19 "tinymce/pasteplugin/Clipboard", |
|
20 "tinymce/pasteplugin/WordFilter", |
|
21 "tinymce/pasteplugin/Quirks" |
|
22 ], function(PluginManager, Clipboard, WordFilter, Quirks) { |
|
23 var userIsInformed; |
|
24 |
|
25 PluginManager.add('paste', function(editor) { |
|
26 var self = this, clipboard, settings = editor.settings; |
|
27 |
|
28 function togglePlainTextPaste() { |
|
29 if (clipboard.pasteFormat == "text") { |
|
30 this.active(false); |
|
31 clipboard.pasteFormat = "html"; |
|
32 } else { |
|
33 clipboard.pasteFormat = "text"; |
|
34 this.active(true); |
|
35 |
|
36 if (!userIsInformed) { |
|
37 editor.windowManager.alert( |
|
38 'Paste is now in plain text mode. Contents will now ' + |
|
39 'be pasted as plain text until you toggle this option off.' |
|
40 ); |
|
41 |
|
42 userIsInformed = true; |
|
43 } |
|
44 } |
|
45 } |
|
46 |
|
47 self.clipboard = clipboard = new Clipboard(editor); |
|
48 self.quirks = new Quirks(editor); |
|
49 self.wordFilter = new WordFilter(editor); |
|
50 |
|
51 if (editor.settings.paste_as_text) { |
|
52 self.clipboard.pasteFormat = "text"; |
|
53 } |
|
54 |
|
55 if (settings.paste_preprocess) { |
|
56 editor.on('PastePreProcess', function(e) { |
|
57 settings.paste_preprocess.call(self, self, e); |
|
58 }); |
|
59 } |
|
60 |
|
61 if (settings.paste_postprocess) { |
|
62 editor.on('PastePostProcess', function(e) { |
|
63 settings.paste_postprocess.call(self, self, e); |
|
64 }); |
|
65 } |
|
66 |
|
67 editor.addCommand('mceInsertClipboardContent', function(ui, value) { |
|
68 if (value.content) { |
|
69 self.clipboard.pasteHtml(value.content); |
|
70 } |
|
71 |
|
72 if (value.text) { |
|
73 self.clipboard.pasteText(value.text); |
|
74 } |
|
75 }); |
|
76 |
|
77 // Block all drag/drop events |
|
78 if (editor.paste_block_drop) { |
|
79 editor.on('dragend dragover draggesture dragdrop drop drag', function(e) { |
|
80 e.preventDefault(); |
|
81 e.stopPropagation(); |
|
82 }); |
|
83 } |
|
84 |
|
85 // Prevent users from dropping data images on Gecko |
|
86 if (!editor.settings.paste_data_images) { |
|
87 editor.on('drop', function(e) { |
|
88 var dataTransfer = e.dataTransfer; |
|
89 |
|
90 if (dataTransfer && dataTransfer.files && dataTransfer.files.length > 0) { |
|
91 e.preventDefault(); |
|
92 } |
|
93 }); |
|
94 } |
|
95 |
|
96 editor.addButton('pastetext', { |
|
97 icon: 'pastetext', |
|
98 tooltip: 'Paste as text', |
|
99 onclick: togglePlainTextPaste, |
|
100 active: self.clipboard.pasteFormat == "text" |
|
101 }); |
|
102 |
|
103 editor.addMenuItem('pastetext', { |
|
104 text: 'Paste as text', |
|
105 selectable: true, |
|
106 active: clipboard.pasteFormat, |
|
107 onclick: togglePlainTextPaste |
|
108 }); |
|
109 }); |
|
110 }); |