annotate WebContent/jscripts/tiny_mce/plugins/paste/editor_plugin_src.js @ 6:5bb7cc86069c

restlet.jar
author dwinter
date Wed, 14 Mar 2012 16:21:45 +0100
parents 0be9d53a6967
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
5
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
1 /**
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
2 * editor_plugin_src.js
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
3 *
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
4 * Copyright 2009, Moxiecode Systems AB
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
5 * Released under LGPL License.
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
6 *
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
7 * License: http://tinymce.moxiecode.com/license
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
8 * Contributing: http://tinymce.moxiecode.com/contributing
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
9 */
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
10
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
11 (function() {
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
12 var each = tinymce.each,
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
13 defs = {
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
14 paste_auto_cleanup_on_paste : true,
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
15 paste_enable_default_filters : true,
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
16 paste_block_drop : false,
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
17 paste_retain_style_properties : "none",
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
18 paste_strip_class_attributes : "mso",
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
19 paste_remove_spans : false,
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
20 paste_remove_styles : false,
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
21 paste_remove_styles_if_webkit : true,
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
22 paste_convert_middot_lists : true,
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
23 paste_convert_headers_to_strong : false,
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
24 paste_dialog_width : "450",
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
25 paste_dialog_height : "400",
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
26 paste_text_use_dialog : false,
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
27 paste_text_sticky : false,
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
28 paste_text_sticky_default : false,
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
29 paste_text_notifyalways : false,
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
30 paste_text_linebreaktype : "combined",
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
31 paste_text_replacements : [
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
32 [/\u2026/g, "..."],
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
33 [/[\x93\x94\u201c\u201d]/g, '"'],
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
34 [/[\x60\x91\x92\u2018\u2019]/g, "'"]
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
35 ]
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
36 };
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
37
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
38 function getParam(ed, name) {
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
39 return ed.getParam(name, defs[name]);
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
40 }
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
41
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
42 tinymce.create('tinymce.plugins.PastePlugin', {
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
43 init : function(ed, url) {
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
44 var t = this;
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
45
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
46 t.editor = ed;
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
47 t.url = url;
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
48
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
49 // Setup plugin events
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
50 t.onPreProcess = new tinymce.util.Dispatcher(t);
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
51 t.onPostProcess = new tinymce.util.Dispatcher(t);
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
52
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
53 // Register default handlers
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
54 t.onPreProcess.add(t._preProcess);
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
55 t.onPostProcess.add(t._postProcess);
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
56
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
57 // Register optional preprocess handler
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
58 t.onPreProcess.add(function(pl, o) {
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
59 ed.execCallback('paste_preprocess', pl, o);
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
60 });
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
61
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
62 // Register optional postprocess
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
63 t.onPostProcess.add(function(pl, o) {
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
64 ed.execCallback('paste_postprocess', pl, o);
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
65 });
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
66
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
67 ed.onKeyDown.addToTop(function(ed, e) {
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
68 // Block ctrl+v from adding an undo level since the default logic in tinymce.Editor will add that
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
69 if (((tinymce.isMac ? e.metaKey : e.ctrlKey) && e.keyCode == 86) || (e.shiftKey && e.keyCode == 45))
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
70 return false; // Stop other listeners
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
71 });
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
72
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
73 // Initialize plain text flag
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
74 ed.pasteAsPlainText = getParam(ed, 'paste_text_sticky_default');
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
75
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
76 // This function executes the process handlers and inserts the contents
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
77 // force_rich overrides plain text mode set by user, important for pasting with execCommand
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
78 function process(o, force_rich) {
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
79 var dom = ed.dom, rng;
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
80
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
81 // Execute pre process handlers
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
82 t.onPreProcess.dispatch(t, o);
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
83
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
84 // Create DOM structure
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
85 o.node = dom.create('div', 0, o.content);
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
86
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
87 // If pasting inside the same element and the contents is only one block
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
88 // remove the block and keep the text since Firefox will copy parts of pre and h1-h6 as a pre element
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
89 if (tinymce.isGecko) {
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
90 rng = ed.selection.getRng(true);
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
91 if (rng.startContainer == rng.endContainer && rng.startContainer.nodeType == 3) {
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
92 // Is only one block node and it doesn't contain word stuff
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
93 if (o.node.childNodes.length === 1 && /^(p|h[1-6]|pre)$/i.test(o.node.firstChild.nodeName) && o.content.indexOf('__MCE_ITEM__') === -1)
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
94 dom.remove(o.node.firstChild, true);
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
95 }
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
96 }
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
97
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
98 // Execute post process handlers
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
99 t.onPostProcess.dispatch(t, o);
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
100
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
101 // Serialize content
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
102 o.content = ed.serializer.serialize(o.node, {getInner : 1, forced_root_block : ''});
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
103
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
104 // Plain text option active?
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
105 if ((!force_rich) && (ed.pasteAsPlainText)) {
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
106 t._insertPlainText(o.content);
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
107
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
108 if (!getParam(ed, "paste_text_sticky")) {
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
109 ed.pasteAsPlainText = false;
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
110 ed.controlManager.setActive("pastetext", false);
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
111 }
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
112 } else {
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
113 t._insert(o.content);
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
114 }
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
115 }
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
116
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
117 // Add command for external usage
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
118 ed.addCommand('mceInsertClipboardContent', function(u, o) {
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
119 process(o, true);
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
120 });
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
121
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
122 if (!getParam(ed, "paste_text_use_dialog")) {
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
123 ed.addCommand('mcePasteText', function(u, v) {
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
124 var cookie = tinymce.util.Cookie;
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
125
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
126 ed.pasteAsPlainText = !ed.pasteAsPlainText;
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
127 ed.controlManager.setActive('pastetext', ed.pasteAsPlainText);
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
128
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
129 if ((ed.pasteAsPlainText) && (!cookie.get("tinymcePasteText"))) {
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
130 if (getParam(ed, "paste_text_sticky")) {
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
131 ed.windowManager.alert(ed.translate('paste.plaintext_mode_sticky'));
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
132 } else {
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
133 ed.windowManager.alert(ed.translate('paste.plaintext_mode'));
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
134 }
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
135
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
136 if (!getParam(ed, "paste_text_notifyalways")) {
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
137 cookie.set("tinymcePasteText", "1", new Date(new Date().getFullYear() + 1, 12, 31))
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
138 }
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
139 }
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
140 });
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
141 }
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
142
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
143 ed.addButton('pastetext', {title: 'paste.paste_text_desc', cmd: 'mcePasteText'});
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
144 ed.addButton('selectall', {title: 'paste.selectall_desc', cmd: 'selectall'});
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
145
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
146 // This function grabs the contents from the clipboard by adding a
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
147 // hidden div and placing the caret inside it and after the browser paste
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
148 // is done it grabs that contents and processes that
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
149 function grabContent(e) {
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
150 var n, or, rng, oldRng, sel = ed.selection, dom = ed.dom, body = ed.getBody(), posY, textContent;
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
151
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
152 // Check if browser supports direct plaintext access
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
153 if (e.clipboardData || dom.doc.dataTransfer) {
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
154 textContent = (e.clipboardData || dom.doc.dataTransfer).getData('Text');
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
155
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
156 if (ed.pasteAsPlainText) {
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
157 e.preventDefault();
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
158 process({content : dom.encode(textContent).replace(/\r?\n/g, '<br />')});
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
159 return;
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
160 }
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
161 }
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
162
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
163 if (dom.get('_mcePaste'))
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
164 return;
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
165
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
166 // Create container to paste into
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
167 n = dom.add(body, 'div', {id : '_mcePaste', 'class' : 'mcePaste', 'data-mce-bogus' : '1'}, '\uFEFF\uFEFF');
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
168
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
169 // If contentEditable mode we need to find out the position of the closest element
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
170 if (body != ed.getDoc().body)
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
171 posY = dom.getPos(ed.selection.getStart(), body).y;
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
172 else
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
173 posY = body.scrollTop + dom.getViewPort(ed.getWin()).y;
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
174
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
175 // Styles needs to be applied after the element is added to the document since WebKit will otherwise remove all styles
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
176 // If also needs to be in view on IE or the paste would fail
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
177 dom.setStyles(n, {
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
178 position : 'absolute',
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
179 left : tinymce.isGecko ? -40 : 0, // Need to move it out of site on Gecko since it will othewise display a ghost resize rect for the div
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
180 top : posY - 25,
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
181 width : 1,
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
182 height : 1,
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
183 overflow : 'hidden'
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
184 });
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
185
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
186 if (tinymce.isIE) {
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
187 // Store away the old range
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
188 oldRng = sel.getRng();
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
189
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
190 // Select the container
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
191 rng = dom.doc.body.createTextRange();
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
192 rng.moveToElementText(n);
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
193 rng.execCommand('Paste');
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
194
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
195 // Remove container
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
196 dom.remove(n);
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
197
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
198 // Check if the contents was changed, if it wasn't then clipboard extraction failed probably due
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
199 // to IE security settings so we pass the junk though better than nothing right
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
200 if (n.innerHTML === '\uFEFF\uFEFF') {
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
201 ed.execCommand('mcePasteWord');
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
202 e.preventDefault();
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
203 return;
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
204 }
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
205
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
206 // Restore the old range and clear the contents before pasting
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
207 sel.setRng(oldRng);
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
208 sel.setContent('');
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
209
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
210 // For some odd reason we need to detach the the mceInsertContent call from the paste event
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
211 // It's like IE has a reference to the parent element that you paste in and the selection gets messed up
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
212 // when it tries to restore the selection
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
213 setTimeout(function() {
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
214 // Process contents
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
215 process({content : n.innerHTML});
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
216 }, 0);
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
217
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
218 // Block the real paste event
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
219 return tinymce.dom.Event.cancel(e);
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
220 } else {
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
221 function block(e) {
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
222 e.preventDefault();
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
223 };
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
224
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
225 // Block mousedown and click to prevent selection change
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
226 dom.bind(ed.getDoc(), 'mousedown', block);
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
227 dom.bind(ed.getDoc(), 'keydown', block);
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
228
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
229 or = ed.selection.getRng();
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
230
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
231 // Move select contents inside DIV
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
232 n = n.firstChild;
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
233 rng = ed.getDoc().createRange();
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
234 rng.setStart(n, 0);
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
235 rng.setEnd(n, 2);
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
236 sel.setRng(rng);
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
237
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
238 // Wait a while and grab the pasted contents
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
239 window.setTimeout(function() {
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
240 var h = '', nl;
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
241
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
242 // Paste divs duplicated in paste divs seems to happen when you paste plain text so lets first look for that broken behavior in WebKit
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
243 if (!dom.select('div.mcePaste > div.mcePaste').length) {
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
244 nl = dom.select('div.mcePaste');
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
245
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
246 // WebKit will split the div into multiple ones so this will loop through then all and join them to get the whole HTML string
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
247 each(nl, function(n) {
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
248 var child = n.firstChild;
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
249
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
250 // WebKit inserts a DIV container with lots of odd styles
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
251 if (child && child.nodeName == 'DIV' && child.style.marginTop && child.style.backgroundColor) {
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
252 dom.remove(child, 1);
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
253 }
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
254
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
255 // Remove apply style spans
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
256 each(dom.select('span.Apple-style-span', n), function(n) {
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
257 dom.remove(n, 1);
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
258 });
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
259
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
260 // Remove bogus br elements
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
261 each(dom.select('br[data-mce-bogus]', n), function(n) {
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
262 dom.remove(n);
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
263 });
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
264
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
265 // WebKit will make a copy of the DIV for each line of plain text pasted and insert them into the DIV
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
266 if (n.parentNode.className != 'mcePaste')
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
267 h += n.innerHTML;
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
268 });
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
269 } else {
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
270 // Found WebKit weirdness so force the content into paragraphs this seems to happen when you paste plain text from Nodepad etc
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
271 // So this logic will replace double enter with paragraphs and single enter with br so it kind of looks the same
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
272 h = '<p>' + dom.encode(textContent).replace(/\r?\n\r?\n/g, '</p><p>').replace(/\r?\n/g, '<br />') + '</p>';
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
273 }
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
274
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
275 // Remove the nodes
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
276 each(dom.select('div.mcePaste'), function(n) {
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
277 dom.remove(n);
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
278 });
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
279
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
280 // Restore the old selection
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
281 if (or)
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
282 sel.setRng(or);
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
283
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
284 process({content : h});
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
285
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
286 // Unblock events ones we got the contents
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
287 dom.unbind(ed.getDoc(), 'mousedown', block);
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
288 dom.unbind(ed.getDoc(), 'keydown', block);
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
289 }, 0);
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
290 }
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
291 }
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
292
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
293 // Check if we should use the new auto process method
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
294 if (getParam(ed, "paste_auto_cleanup_on_paste")) {
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
295 // Is it's Opera or older FF use key handler
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
296 if (tinymce.isOpera || /Firefox\/2/.test(navigator.userAgent)) {
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
297 ed.onKeyDown.addToTop(function(ed, e) {
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
298 if (((tinymce.isMac ? e.metaKey : e.ctrlKey) && e.keyCode == 86) || (e.shiftKey && e.keyCode == 45))
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
299 grabContent(e);
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
300 });
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
301 } else {
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
302 // Grab contents on paste event on Gecko and WebKit
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
303 ed.onPaste.addToTop(function(ed, e) {
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
304 return grabContent(e);
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
305 });
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
306 }
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
307 }
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
308
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
309 ed.onInit.add(function() {
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
310 ed.controlManager.setActive("pastetext", ed.pasteAsPlainText);
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
311
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
312 // Block all drag/drop events
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
313 if (getParam(ed, "paste_block_drop")) {
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
314 ed.dom.bind(ed.getBody(), ['dragend', 'dragover', 'draggesture', 'dragdrop', 'drop', 'drag'], function(e) {
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
315 e.preventDefault();
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
316 e.stopPropagation();
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
317
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
318 return false;
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
319 });
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
320 }
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
321 });
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
322
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
323 // Add legacy support
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
324 t._legacySupport();
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
325 },
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
326
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
327 getInfo : function() {
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
328 return {
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
329 longname : 'Paste text/word',
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
330 author : 'Moxiecode Systems AB',
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
331 authorurl : 'http://tinymce.moxiecode.com',
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
332 infourl : 'http://wiki.moxiecode.com/index.php/TinyMCE:Plugins/paste',
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
333 version : tinymce.majorVersion + "." + tinymce.minorVersion
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
334 };
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
335 },
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
336
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
337 _preProcess : function(pl, o) {
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
338 var ed = this.editor,
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
339 h = o.content,
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
340 grep = tinymce.grep,
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
341 explode = tinymce.explode,
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
342 trim = tinymce.trim,
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
343 len, stripClass;
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
344
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
345 //console.log('Before preprocess:' + o.content);
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
346
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
347 function process(items) {
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
348 each(items, function(v) {
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
349 // Remove or replace
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
350 if (v.constructor == RegExp)
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
351 h = h.replace(v, '');
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
352 else
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
353 h = h.replace(v[0], v[1]);
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
354 });
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
355 }
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
356
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
357 if (ed.settings.paste_enable_default_filters == false) {
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
358 return;
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
359 }
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
360
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
361 // IE9 adds BRs before/after block elements when contents is pasted from word or for example another browser
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
362 if (tinymce.isIE && document.documentMode >= 9) {
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
363 // IE9 adds BRs before/after block elements when contents is pasted from word or for example another browser
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
364 process([[/(?:<br>&nbsp;[\s\r\n]+|<br>)*(<\/?(h[1-6r]|p|div|address|pre|form|table|tbody|thead|tfoot|th|tr|td|li|ol|ul|caption|blockquote|center|dl|dt|dd|dir|fieldset)[^>]*>)(?:<br>&nbsp;[\s\r\n]+|<br>)*/g, '$1']]);
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
365
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
366 // IE9 also adds an extra BR element for each soft-linefeed and it also adds a BR for each word wrap break
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
367 process([
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
368 [/<br><br>/g, '<BR><BR>'], // Replace multiple BR elements with uppercase BR to keep them intact
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
369 [/<br>/g, ' '], // Replace single br elements with space since they are word wrap BR:s
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
370 [/<BR><BR>/g, '<br>'] // Replace back the double brs but into a single BR
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
371 ]);
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
372 }
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
373
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
374 // Detect Word content and process it more aggressive
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
375 if (/class="?Mso|style="[^"]*\bmso-|w:WordDocument/i.test(h) || o.wordContent) {
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
376 o.wordContent = true; // Mark the pasted contents as word specific content
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
377 //console.log('Word contents detected.');
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
378
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
379 // Process away some basic content
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
380 process([
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
381 /^\s*(&nbsp;)+/gi, // &nbsp; entities at the start of contents
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
382 /(&nbsp;|<br[^>]*>)+\s*$/gi // &nbsp; entities at the end of contents
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
383 ]);
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
384
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
385 if (getParam(ed, "paste_convert_headers_to_strong")) {
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
386 h = h.replace(/<p [^>]*class="?MsoHeading"?[^>]*>(.*?)<\/p>/gi, "<p><strong>$1</strong></p>");
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
387 }
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
388
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
389 if (getParam(ed, "paste_convert_middot_lists")) {
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
390 process([
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
391 [/<!--\[if !supportLists\]-->/gi, '$&__MCE_ITEM__'], // Convert supportLists to a list item marker
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
392 [/(<span[^>]+(?:mso-list:|:\s*symbol)[^>]+>)/gi, '$1__MCE_ITEM__'], // Convert mso-list and symbol spans to item markers
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
393 [/(<p[^>]+(?:MsoListParagraph)[^>]+>)/gi, '$1__MCE_ITEM__'] // Convert mso-list and symbol paragraphs to item markers (FF)
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
394 ]);
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
395 }
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
396
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
397 process([
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
398 // Word comments like conditional comments etc
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
399 /<!--[\s\S]+?-->/gi,
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
400
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
401 // Remove comments, scripts (e.g., msoShowComment), XML tag, VML content, MS Office namespaced tags, and a few other tags
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
402 /<(!|script[^>]*>.*?<\/script(?=[>\s])|\/?(\?xml(:\w+)?|img|meta|link|style|\w:\w+)(?=[\s\/>]))[^>]*>/gi,
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
403
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
404 // Convert <s> into <strike> for line-though
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
405 [/<(\/?)s>/gi, "<$1strike>"],
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
406
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
407 // Replace nsbp entites to char since it's easier to handle
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
408 [/&nbsp;/gi, "\u00a0"]
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
409 ]);
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
410
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
411 // Remove bad attributes, with or without quotes, ensuring that attribute text is really inside a tag.
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
412 // If JavaScript had a RegExp look-behind, we could have integrated this with the last process() array and got rid of the loop. But alas, it does not, so we cannot.
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
413 do {
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
414 len = h.length;
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
415 h = h.replace(/(<[a-z][^>]*\s)(?:id|name|language|type|on\w+|\w+:\w+)=(?:"[^"]*"|\w+)\s?/gi, "$1");
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
416 } while (len != h.length);
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
417
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
418 // Remove all spans if no styles is to be retained
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
419 if (getParam(ed, "paste_retain_style_properties").replace(/^none$/i, "").length == 0) {
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
420 h = h.replace(/<\/?span[^>]*>/gi, "");
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
421 } else {
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
422 // We're keeping styles, so at least clean them up.
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
423 // CSS Reference: http://msdn.microsoft.com/en-us/library/aa155477.aspx
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
424
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
425 process([
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
426 // Convert <span style="mso-spacerun:yes">___</span> to string of alternating breaking/non-breaking spaces of same length
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
427 [/<span\s+style\s*=\s*"\s*mso-spacerun\s*:\s*yes\s*;?\s*"\s*>([\s\u00a0]*)<\/span>/gi,
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
428 function(str, spaces) {
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
429 return (spaces.length > 0)? spaces.replace(/./, " ").slice(Math.floor(spaces.length/2)).split("").join("\u00a0") : "";
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
430 }
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
431 ],
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
432
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
433 // Examine all styles: delete junk, transform some, and keep the rest
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
434 [/(<[a-z][^>]*)\sstyle="([^"]*)"/gi,
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
435 function(str, tag, style) {
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
436 var n = [],
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
437 i = 0,
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
438 s = explode(trim(style).replace(/&quot;/gi, "'"), ";");
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
439
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
440 // Examine each style definition within the tag's style attribute
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
441 each(s, function(v) {
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
442 var name, value,
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
443 parts = explode(v, ":");
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
444
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
445 function ensureUnits(v) {
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
446 return v + ((v !== "0") && (/\d$/.test(v)))? "px" : "";
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
447 }
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
448
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
449 if (parts.length == 2) {
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
450 name = parts[0].toLowerCase();
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
451 value = parts[1].toLowerCase();
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
452
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
453 // Translate certain MS Office styles into their CSS equivalents
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
454 switch (name) {
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
455 case "mso-padding-alt":
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
456 case "mso-padding-top-alt":
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
457 case "mso-padding-right-alt":
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
458 case "mso-padding-bottom-alt":
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
459 case "mso-padding-left-alt":
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
460 case "mso-margin-alt":
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
461 case "mso-margin-top-alt":
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
462 case "mso-margin-right-alt":
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
463 case "mso-margin-bottom-alt":
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
464 case "mso-margin-left-alt":
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
465 case "mso-table-layout-alt":
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
466 case "mso-height":
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
467 case "mso-width":
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
468 case "mso-vertical-align-alt":
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
469 n[i++] = name.replace(/^mso-|-alt$/g, "") + ":" + ensureUnits(value);
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
470 return;
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
471
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
472 case "horiz-align":
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
473 n[i++] = "text-align:" + value;
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
474 return;
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
475
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
476 case "vert-align":
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
477 n[i++] = "vertical-align:" + value;
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
478 return;
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
479
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
480 case "font-color":
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
481 case "mso-foreground":
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
482 n[i++] = "color:" + value;
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
483 return;
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
484
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
485 case "mso-background":
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
486 case "mso-highlight":
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
487 n[i++] = "background:" + value;
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
488 return;
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
489
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
490 case "mso-default-height":
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
491 n[i++] = "min-height:" + ensureUnits(value);
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
492 return;
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
493
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
494 case "mso-default-width":
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
495 n[i++] = "min-width:" + ensureUnits(value);
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
496 return;
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
497
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
498 case "mso-padding-between-alt":
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
499 n[i++] = "border-collapse:separate;border-spacing:" + ensureUnits(value);
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
500 return;
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
501
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
502 case "text-line-through":
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
503 if ((value == "single") || (value == "double")) {
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
504 n[i++] = "text-decoration:line-through";
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
505 }
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
506 return;
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
507
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
508 case "mso-zero-height":
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
509 if (value == "yes") {
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
510 n[i++] = "display:none";
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
511 }
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
512 return;
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
513 }
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
514
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
515 // Eliminate all MS Office style definitions that have no CSS equivalent by examining the first characters in the name
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
516 if (/^(mso|column|font-emph|lang|layout|line-break|list-image|nav|panose|punct|row|ruby|sep|size|src|tab-|table-border|text-(?!align|decor|indent|trans)|top-bar|version|vnd|word-break)/.test(name)) {
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
517 return;
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
518 }
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
519
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
520 // If it reached this point, it must be a valid CSS style
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
521 n[i++] = name + ":" + parts[1]; // Lower-case name, but keep value case
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
522 }
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
523 });
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
524
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
525 // If style attribute contained any valid styles the re-write it; otherwise delete style attribute.
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
526 if (i > 0) {
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
527 return tag + ' style="' + n.join(';') + '"';
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
528 } else {
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
529 return tag;
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
530 }
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
531 }
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
532 ]
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
533 ]);
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
534 }
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
535 }
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
536
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
537 // Replace headers with <strong>
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
538 if (getParam(ed, "paste_convert_headers_to_strong")) {
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
539 process([
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
540 [/<h[1-6][^>]*>/gi, "<p><strong>"],
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
541 [/<\/h[1-6][^>]*>/gi, "</strong></p>"]
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
542 ]);
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
543 }
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
544
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
545 process([
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
546 // Copy paste from Java like Open Office will produce this junk on FF
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
547 [/Version:[\d.]+\nStartHTML:\d+\nEndHTML:\d+\nStartFragment:\d+\nEndFragment:\d+/gi, '']
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
548 ]);
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
549
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
550 // Class attribute options are: leave all as-is ("none"), remove all ("all"), or remove only those starting with mso ("mso").
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
551 // Note:- paste_strip_class_attributes: "none", verify_css_classes: true is also a good variation.
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
552 stripClass = getParam(ed, "paste_strip_class_attributes");
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
553
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
554 if (stripClass !== "none") {
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
555 function removeClasses(match, g1) {
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
556 if (stripClass === "all")
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
557 return '';
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
558
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
559 var cls = grep(explode(g1.replace(/^(["'])(.*)\1$/, "$2"), " "),
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
560 function(v) {
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
561 return (/^(?!mso)/i.test(v));
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
562 }
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
563 );
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
564
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
565 return cls.length ? ' class="' + cls.join(" ") + '"' : '';
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
566 };
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
567
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
568 h = h.replace(/ class="([^"]+)"/gi, removeClasses);
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
569 h = h.replace(/ class=([\-\w]+)/gi, removeClasses);
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
570 }
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
571
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
572 // Remove spans option
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
573 if (getParam(ed, "paste_remove_spans")) {
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
574 h = h.replace(/<\/?span[^>]*>/gi, "");
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
575 }
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
576
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
577 //console.log('After preprocess:' + h);
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
578
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
579 o.content = h;
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
580 },
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
581
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
582 /**
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
583 * Various post process items.
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
584 */
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
585 _postProcess : function(pl, o) {
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
586 var t = this, ed = t.editor, dom = ed.dom, styleProps;
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
587
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
588 if (ed.settings.paste_enable_default_filters == false) {
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
589 return;
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
590 }
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
591
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
592 if (o.wordContent) {
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
593 // Remove named anchors or TOC links
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
594 each(dom.select('a', o.node), function(a) {
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
595 if (!a.href || a.href.indexOf('#_Toc') != -1)
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
596 dom.remove(a, 1);
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
597 });
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
598
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
599 if (getParam(ed, "paste_convert_middot_lists")) {
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
600 t._convertLists(pl, o);
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
601 }
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
602
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
603 // Process styles
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
604 styleProps = getParam(ed, "paste_retain_style_properties"); // retained properties
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
605
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
606 // Process only if a string was specified and not equal to "all" or "*"
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
607 if ((tinymce.is(styleProps, "string")) && (styleProps !== "all") && (styleProps !== "*")) {
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
608 styleProps = tinymce.explode(styleProps.replace(/^none$/i, ""));
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
609
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
610 // Retains some style properties
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
611 each(dom.select('*', o.node), function(el) {
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
612 var newStyle = {}, npc = 0, i, sp, sv;
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
613
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
614 // Store a subset of the existing styles
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
615 if (styleProps) {
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
616 for (i = 0; i < styleProps.length; i++) {
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
617 sp = styleProps[i];
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
618 sv = dom.getStyle(el, sp);
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
619
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
620 if (sv) {
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
621 newStyle[sp] = sv;
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
622 npc++;
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
623 }
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
624 }
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
625 }
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
626
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
627 // Remove all of the existing styles
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
628 dom.setAttrib(el, 'style', '');
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
629
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
630 if (styleProps && npc > 0)
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
631 dom.setStyles(el, newStyle); // Add back the stored subset of styles
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
632 else // Remove empty span tags that do not have class attributes
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
633 if (el.nodeName == 'SPAN' && !el.className)
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
634 dom.remove(el, true);
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
635 });
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
636 }
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
637 }
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
638
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
639 // Remove all style information or only specifically on WebKit to avoid the style bug on that browser
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
640 if (getParam(ed, "paste_remove_styles") || (getParam(ed, "paste_remove_styles_if_webkit") && tinymce.isWebKit)) {
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
641 each(dom.select('*[style]', o.node), function(el) {
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
642 el.removeAttribute('style');
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
643 el.removeAttribute('data-mce-style');
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
644 });
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
645 } else {
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
646 if (tinymce.isWebKit) {
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
647 // We need to compress the styles on WebKit since if you paste <img border="0" /> it will become <img border="0" style="... lots of junk ..." />
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
648 // Removing the mce_style that contains the real value will force the Serializer engine to compress the styles
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
649 each(dom.select('*', o.node), function(el) {
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
650 el.removeAttribute('data-mce-style');
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
651 });
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
652 }
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
653 }
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
654 },
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
655
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
656 /**
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
657 * Converts the most common bullet and number formats in Office into a real semantic UL/LI list.
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
658 */
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
659 _convertLists : function(pl, o) {
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
660 var dom = pl.editor.dom, listElm, li, lastMargin = -1, margin, levels = [], lastType, html;
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
661
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
662 // Convert middot lists into real semantic lists
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
663 each(dom.select('p', o.node), function(p) {
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
664 var sib, val = '', type, html, idx, parents;
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
665
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
666 // Get text node value at beginning of paragraph
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
667 for (sib = p.firstChild; sib && sib.nodeType == 3; sib = sib.nextSibling)
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
668 val += sib.nodeValue;
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
669
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
670 val = p.innerHTML.replace(/<\/?\w+[^>]*>/gi, '').replace(/&nbsp;/g, '\u00a0');
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
671
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
672 // Detect unordered lists look for bullets
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
673 if (/^(__MCE_ITEM__)+[\u2022\u00b7\u00a7\u00d8o\u25CF]\s*\u00a0*/.test(val))
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
674 type = 'ul';
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
675
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
676 // Detect ordered lists 1., a. or ixv.
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
677 if (/^__MCE_ITEM__\s*\w+\.\s*\u00a0+/.test(val))
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
678 type = 'ol';
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
679
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
680 // Check if node value matches the list pattern: o&nbsp;&nbsp;
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
681 if (type) {
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
682 margin = parseFloat(p.style.marginLeft || 0);
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
683
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
684 if (margin > lastMargin)
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
685 levels.push(margin);
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
686
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
687 if (!listElm || type != lastType) {
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
688 listElm = dom.create(type);
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
689 dom.insertAfter(listElm, p);
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
690 } else {
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
691 // Nested list element
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
692 if (margin > lastMargin) {
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
693 listElm = li.appendChild(dom.create(type));
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
694 } else if (margin < lastMargin) {
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
695 // Find parent level based on margin value
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
696 idx = tinymce.inArray(levels, margin);
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
697 parents = dom.getParents(listElm.parentNode, type);
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
698 listElm = parents[parents.length - 1 - idx] || listElm;
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
699 }
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
700 }
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
701
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
702 // Remove middot or number spans if they exists
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
703 each(dom.select('span', p), function(span) {
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
704 var html = span.innerHTML.replace(/<\/?\w+[^>]*>/gi, '');
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
705
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
706 // Remove span with the middot or the number
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
707 if (type == 'ul' && /^__MCE_ITEM__[\u2022\u00b7\u00a7\u00d8o\u25CF]/.test(html))
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
708 dom.remove(span);
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
709 else if (/^__MCE_ITEM__[\s\S]*\w+\.(&nbsp;|\u00a0)*\s*/.test(html))
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
710 dom.remove(span);
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
711 });
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
712
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
713 html = p.innerHTML;
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
714
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
715 // Remove middot/list items
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
716 if (type == 'ul')
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
717 html = p.innerHTML.replace(/__MCE_ITEM__/g, '').replace(/^[\u2022\u00b7\u00a7\u00d8o\u25CF]\s*(&nbsp;|\u00a0)+\s*/, '');
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
718 else
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
719 html = p.innerHTML.replace(/__MCE_ITEM__/g, '').replace(/^\s*\w+\.(&nbsp;|\u00a0)+\s*/, '');
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
720
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
721 // Create li and add paragraph data into the new li
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
722 li = listElm.appendChild(dom.create('li', 0, html));
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
723 dom.remove(p);
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
724
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
725 lastMargin = margin;
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
726 lastType = type;
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
727 } else
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
728 listElm = lastMargin = 0; // End list element
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
729 });
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
730
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
731 // Remove any left over makers
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
732 html = o.node.innerHTML;
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
733 if (html.indexOf('__MCE_ITEM__') != -1)
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
734 o.node.innerHTML = html.replace(/__MCE_ITEM__/g, '');
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
735 },
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
736
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
737 /**
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
738 * Inserts the specified contents at the caret position.
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
739 */
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
740 _insert : function(h, skip_undo) {
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
741 var ed = this.editor, r = ed.selection.getRng();
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
742
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
743 // First delete the contents seems to work better on WebKit when the selection spans multiple list items or multiple table cells.
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
744 if (!ed.selection.isCollapsed() && r.startContainer != r.endContainer)
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
745 ed.getDoc().execCommand('Delete', false, null);
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
746
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
747 ed.execCommand('mceInsertContent', false, h, {skip_undo : skip_undo});
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
748 },
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
749
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
750 /**
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
751 * Instead of the old plain text method which tried to re-create a paste operation, the
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
752 * new approach adds a plain text mode toggle switch that changes the behavior of paste.
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
753 * This function is passed the same input that the regular paste plugin produces.
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
754 * It performs additional scrubbing and produces (and inserts) the plain text.
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
755 * This approach leverages all of the great existing functionality in the paste
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
756 * plugin, and requires minimal changes to add the new functionality.
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
757 * Speednet - June 2009
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
758 */
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
759 _insertPlainText : function(content) {
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
760 var ed = this.editor,
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
761 linebr = getParam(ed, "paste_text_linebreaktype"),
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
762 rl = getParam(ed, "paste_text_replacements"),
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
763 is = tinymce.is;
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
764
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
765 function process(items) {
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
766 each(items, function(v) {
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
767 if (v.constructor == RegExp)
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
768 content = content.replace(v, "");
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
769 else
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
770 content = content.replace(v[0], v[1]);
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
771 });
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
772 };
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
773
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
774 if ((typeof(content) === "string") && (content.length > 0)) {
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
775 // If HTML content with line-breaking tags, then remove all cr/lf chars because only tags will break a line
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
776 if (/<(?:p|br|h[1-6]|ul|ol|dl|table|t[rdh]|div|blockquote|fieldset|pre|address|center)[^>]*>/i.test(content)) {
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
777 process([
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
778 /[\n\r]+/g
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
779 ]);
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
780 } else {
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
781 // Otherwise just get rid of carriage returns (only need linefeeds)
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
782 process([
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
783 /\r+/g
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
784 ]);
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
785 }
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
786
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
787 process([
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
788 [/<\/(?:p|h[1-6]|ul|ol|dl|table|div|blockquote|fieldset|pre|address|center)>/gi, "\n\n"], // Block tags get a blank line after them
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
789 [/<br[^>]*>|<\/tr>/gi, "\n"], // Single linebreak for <br /> tags and table rows
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
790 [/<\/t[dh]>\s*<t[dh][^>]*>/gi, "\t"], // Table cells get tabs betweem them
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
791 /<[a-z!\/?][^>]*>/gi, // Delete all remaining tags
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
792 [/&nbsp;/gi, " "], // Convert non-break spaces to regular spaces (remember, *plain text*)
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
793 [/(?:(?!\n)\s)*(\n+)(?:(?!\n)\s)*/gi, "$1"],// Cool little RegExp deletes whitespace around linebreak chars.
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
794 [/\n{3,}/g, "\n\n"] // Max. 2 consecutive linebreaks
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
795 ]);
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
796
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
797 content = ed.dom.decode(tinymce.html.Entities.encodeRaw(content));
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
798
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
799 // Perform default or custom replacements
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
800 if (is(rl, "array")) {
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
801 process(rl);
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
802 } else if (is(rl, "string")) {
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
803 process(new RegExp(rl, "gi"));
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
804 }
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
805
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
806 // Treat paragraphs as specified in the config
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
807 if (linebr == "none") {
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
808 // Convert all line breaks to space
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
809 process([
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
810 [/\n+/g, " "]
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
811 ]);
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
812 } else if (linebr == "br") {
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
813 // Convert all line breaks to <br />
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
814 process([
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
815 [/\n/g, "<br />"]
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
816 ]);
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
817 } else if (linebr == "p") {
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
818 // Convert all line breaks to <p>...</p>
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
819 process([
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
820 [/\n+/g, "</p><p>"],
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
821 [/^(.*<\/p>)(<p>)$/, '<p>$1']
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
822 ]);
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
823 } else {
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
824 // defaults to "combined"
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
825 // Convert single line breaks to <br /> and double line breaks to <p>...</p>
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
826 process([
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
827 [/\n\n/g, "</p><p>"],
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
828 [/^(.*<\/p>)(<p>)$/, '<p>$1'],
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
829 [/\n/g, "<br />"]
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
830 ]);
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
831 }
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
832
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
833 ed.execCommand('mceInsertContent', false, content);
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
834 }
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
835 },
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
836
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
837 /**
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
838 * This method will open the old style paste dialogs. Some users might want the old behavior but still use the new cleanup engine.
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
839 */
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
840 _legacySupport : function() {
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
841 var t = this, ed = t.editor;
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
842
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
843 // Register command(s) for backwards compatibility
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
844 ed.addCommand("mcePasteWord", function() {
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
845 ed.windowManager.open({
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
846 file: t.url + "/pasteword.htm",
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
847 width: parseInt(getParam(ed, "paste_dialog_width")),
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
848 height: parseInt(getParam(ed, "paste_dialog_height")),
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
849 inline: 1
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
850 });
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
851 });
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
852
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
853 if (getParam(ed, "paste_text_use_dialog")) {
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
854 ed.addCommand("mcePasteText", function() {
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
855 ed.windowManager.open({
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
856 file : t.url + "/pastetext.htm",
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
857 width: parseInt(getParam(ed, "paste_dialog_width")),
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
858 height: parseInt(getParam(ed, "paste_dialog_height")),
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
859 inline : 1
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
860 });
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
861 });
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
862 }
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
863
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
864 // Register button for backwards compatibility
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
865 ed.addButton("pasteword", {title : "paste.paste_word_desc", cmd : "mcePasteWord"});
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
866 }
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
867 });
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
868
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
869 // Register plugin
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
870 tinymce.PluginManager.add("paste", tinymce.plugins.PastePlugin);
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
871 })();