- Timestamp:
- 10/23/2014 02:07:15 AM (10 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/wp-includes/js/tinymce/plugins/paste/plugin.js
r29570 r29994 346 346 } 347 347 348 /** 349 * Returns the rect of the current caret if the caret is in an empty block before a 350 * BR we insert a temporary invisible character that we get the rect this way we always get a proper rect. 351 * 352 * TODO: This might be useful in core. 353 */ 354 function getCaretRect(rng) { 355 var rects, textNode, node, container = rng.startContainer; 356 357 rects = rng.getClientRects(); 358 if (rects.length) { 359 return rects[0]; 360 } 361 362 if (!rng.collapsed || container.nodeType != 1) { 363 return; 364 } 365 366 node = container.childNodes[lastRng.startOffset]; 367 368 // Skip empty whitespace nodes 369 while (node && node.nodeType == 3 && !node.data.length) { 370 node = node.nextSibling; 371 } 372 373 if (!node) { 374 return; 375 } 376 377 // Check if the location is |<br> 378 // TODO: Might need to expand this to say |<table> 379 if (node.tagName == 'BR') { 380 textNode = dom.doc.createTextNode('\uFEFF'); 381 node.parentNode.insertBefore(textNode, node); 382 383 rng = dom.createRng(); 384 rng.setStartBefore(textNode); 385 rng.setEndAfter(textNode); 386 387 rects = rng.getClientRects(); 388 dom.remove(textNode); 389 } 390 391 if (rects.length) { 392 return rects[0]; 393 } 394 } 395 348 396 // Calculate top cordinate this is needed to avoid scrolling to top of document 349 397 // We want the paste bin to be as close to the caret as possible to avoid scrolling 350 398 if (lastRng.getClientRects) { 351 var rect s = lastRng.getClientRects();352 353 if (rect s.length) {399 var rect = getCaretRect(lastRng); 400 401 if (rect) { 354 402 // Client rects gets us closes to the actual 355 403 // caret location in for example a wrapped paragraph block 356 top = scrollTop + (rect s[0].top - dom.getPos(body).y);404 top = scrollTop + (rect.top - dom.getPos(body).y); 357 405 } else { 358 406 top = scrollTop; … … 532 580 533 581 /** 534 * Chrome on And oid doesn't support proper clipboard access so we have no choice but to allow the browser default behavior.582 * Chrome on Android doesn't support proper clipboard access so we have no choice but to allow the browser default behavior. 535 583 * 536 584 * @param {Event} e Paste event object to check if it contains any data. 537 585 * @return {Boolean} true/false if the clipboard is empty or not. 538 586 */ 539 function isBrokenAnd oidClipboardEvent(e) {587 function isBrokenAndroidClipboardEvent(e) { 540 588 var clipboardData = e.clipboardData; 541 589 … … 631 679 keyboardPastePlainTextState = false; 632 680 633 if (e.isDefaultPrevented() || isBrokenAnd oidClipboardEvent(e)) {681 if (e.isDefaultPrevented() || isBrokenAndroidClipboardEvent(e)) { 634 682 removePasteBin(); 635 683 return; … … 985 1033 } 986 1034 987 var paragraphs = node.getAll('p'); 988 989 for (var i = 0; i < paragraphs.length; i++) { 990 node = paragraphs[i]; 1035 // Build a list of all root level elements before we start 1036 // altering them in the loop below. 1037 var elements = [], child = node.firstChild; 1038 while (typeof child !== 'undefined' && child !== null) { 1039 elements.push(child); 1040 1041 child = child.walk(); 1042 if (child !== null) { 1043 while (typeof child !== 'undefined' && child.parent !== node) { 1044 child = child.walk(); 1045 } 1046 } 1047 } 1048 1049 for (var i = 0; i < elements.length; i++) { 1050 node = elements[i]; 991 1051 992 1052 if (node.name == 'p' && node.firstChild) { … … 1003 1063 if (isNumericList(nodeText)) { 1004 1064 // Parse OL start number 1005 var matches = /([0-9] )\./.exec(nodeText);1065 var matches = /([0-9]+)\./.exec(nodeText); 1006 1066 var start = 1; 1007 1067 if (matches) { … … 1019 1079 } 1020 1080 1081 currentListNode = null; 1082 } else { 1083 // If the root level element isn't a p tag which can be 1084 // processed by convertParagraphToLi, it interrupts the 1085 // lists, causing a new list to start instead of having 1086 // elements from the next list inserted above this tag. 1087 prevListNode = currentListNode; 1021 1088 currentListNode = null; 1022 1089 } … … 1153 1220 var validElements = settings.paste_word_valid_elements; 1154 1221 if (!validElements) { 1155 validElements = '-strong/b,-em/i,-span,-p,-ol,-ul,-li,-h1,-h2,-h3,-h4,-h5,-h6,-p/div,' + 1156 '-table[width],-tr,-td[colspan|rowspan|width],-th,-thead,-tfoot,-tbody,-a[href|name],sub,sup,strike,br,del'; 1222 validElements = ( 1223 '-strong/b,-em/i,-u,-span,-p,-ol,-ul,-li,-h1,-h2,-h3,-h4,-h5,-h6,' + 1224 '-p/div,-a[href|name],sub,sup,strike,br,del,table[width],tr,' + 1225 'td[colspan|rowspan|width],th[colspan|rowspan|width],thead,tfoot,tbody' 1226 ); 1157 1227 } 1158 1228
Note: See TracChangeset
for help on using the changeset viewer.