Ticket #46071: 46071.diff
| File 46071.diff, 5.2 KB (added by , 7 years ago) |
|---|
-
src/js/_enqueues/lib/link.js
5 5 /* global wpLink */ 6 6 7 7 ( function( $, wpLinkL10n, wp ) { 8 var editor, searchTimer, River, Query, correctedURL, linkNode,8 var editor, searchTimer, River, Query, correctedURL, 9 9 emailRegexp = /^[A-Z0-9._%+-]+@[A-Z0-9.-]+\.[A-Z]{2,63}$/i, 10 10 urlRegexp = /^(https?|ftp):\/\/[A-Z0-9.-]+\.[A-Z]{2,63}[^ "]*$/i, 11 11 inputs = {}, … … 13 13 isTouch = ( 'ontouchend' in document ); 14 14 15 15 function getLink() { 16 return linkNode || editor.dom.getParent( editor.selection.getNode(), 'a[href]' ); 16 if ( editor ) { 17 return editor.$( 'a[data-wplink-edit="true"]' ); 18 } 19 20 return null; 17 21 } 18 22 19 23 window.wpLink = { … … 97 101 } 98 102 }, 99 103 100 open: function( editorId, url, text , node) {104 open: function( editorId, url, text ) { 101 105 var ed, 102 106 $body = $( document.body ); 103 107 104 108 $body.addClass( 'modal-open' ); 105 109 wpLink.modalOpen = true; 106 linkNode = node;107 110 108 111 wpLink.range = null; 109 112 … … 205 208 return false; 206 209 } 207 210 208 if ( linkNode ) {209 nodes = linkNode .childNodes;211 if ( linkNode.length ) { 212 nodes = linkNode[0].childNodes; 210 213 211 if ( nodes.length === 0) {214 if ( ! nodes || ! nodes.length ) { 212 215 return false; 213 216 } 214 217 … … 229 232 linkNode = getLink(), 230 233 onlyText = this.hasSelectedText( linkNode ); 231 234 232 if ( linkNode ) {233 linkText = linkNode.text Content || linkNode.innerText;234 href = editor.dom.getAttrib( linkNode,'href' );235 if ( linkNode.length ) { 236 linkText = linkNode.text(); 237 href = linkNode.attr( 'href' ); 235 238 236 239 if ( ! $.trim( linkText ) ) { 237 240 linkText = text || ''; … … 243 246 244 247 if ( href !== '_wp_link_placeholder' ) { 245 248 inputs.url.val( href ); 246 inputs.openInNewTab.prop( 'checked', '_blank' === editor.dom.getAttrib( linkNode,'target' ) );249 inputs.openInNewTab.prop( 'checked', '_blank' === linkNode.attr( 'target' ) ); 247 250 inputs.submit.val( wpLinkL10n.update ); 248 251 } else { 249 252 this.setDefaultValues( linkText ); … … 414 417 return; 415 418 } 416 419 417 $link = editor.$( getLink());420 $link = getLink(); 418 421 419 422 editor.undoManager.transact( function() { 420 423 if ( ! $link.length ) { … … 437 440 } 438 441 439 442 attrs['data-wplink-edit'] = null; 440 attrs['data-mce-href'] = null; // attrs.href443 attrs['data-mce-href'] = attrs.href; 441 444 $link.attr( attrs ); 442 445 } 443 446 } ); … … 446 449 editor.focus(); 447 450 448 451 if ( $link.length ) { 449 $mceCaret = $link.parent( '#_mce_caret' );450 451 if ( $mceCaret.length ) {452 $mceCaret.before( $link.removeAttr( 'data-mce-bogus' ) );453 }454 455 452 editor.selection.select( $link[0] ); 456 editor.selection.collapse();457 453 458 454 if ( editor.plugins.wplink ) { 459 455 editor.plugins.wplink.checkLink( $link[0] ); … … 468 464 469 465 updateFields: function( e, li ) { 470 466 inputs.url.val( li.children( '.item-permalink' ).val() ); 467 468 if ( inputs.wrap.hasClass( 'has-text-field' ) && ! inputs.text.val() ) { 469 inputs.text.val( li.children( '.item-title' ).text() ); 470 } 471 471 }, 472 472 473 473 getUrlFromSelection: function( selection ) { -
src/js/_enqueues/vendor/tinymce/plugins/wplink/plugin.js
226 226 linkNode = getSelectedLink(); 227 227 editToolbar.tempHide = false; 228 228 229 if ( linkNode ) { 230 editor.dom.setAttribs( linkNode, { 'data-wplink-edit': true } ); 231 } else { 229 if ( ! linkNode ) { 232 230 removePlaceholders(); 233 231 editor.execCommand( 'mceInsertLink', false, { href: '_wp_link_placeholder' } ); 234 232 … … 235 233 linkNode = editor.$( 'a[href="_wp_link_placeholder"]' )[0]; 236 234 editor.nodeChanged(); 237 235 } 236 237 editor.dom.setAttribs( linkNode, { 'data-wplink-edit': true } ); 238 238 } ); 239 239 240 240 editor.addCommand( 'wp_link_apply', function() { … … 284 284 } ); 285 285 286 286 editor.addCommand( 'wp_link_cancel', function() { 287 inputInstance.reset(); 288 287 289 if ( ! editToolbar.tempHide ) { 288 inputInstance.reset();289 290 removePlaceholders(); 290 291 } 291 292 } ); … … 583 584 var url = inputInstance.getURL() || null, 584 585 text = inputInstance.getLinkText() || null; 585 586 586 /* 587 * Accessibility note: moving focus back to the editor confuses 588 * screen readers. They will announce again the Editor ARIA role 589 * `application` and the iframe `title` attribute. 590 * 591 * Unfortunately IE looses the selection when the editor iframe 592 * looses focus, so without returning focus to the editor, the code 593 * in the modal will not be able to get the selection, place the caret 594 * at the same location, etc. 595 */ 596 if ( tinymce.Env.ie ) { 597 editor.focus(); // Needed for IE 598 } 587 window.wpLink.open( editor.id, url, text ); 599 588 600 589 editToolbar.tempHide = true; 601 window.wpLink.open( editor.id, url, text, linkNode ); 602 603 inputInstance.reset(); 590 editToolbar.hide(); 604 591 } 605 592 } 606 593 } );