annotate media/js/tiny_mce/plugins/paste/editor_plugin_src.js @ 232:a46788862737

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