Changeset 36602
- Timestamp:
- 02/20/2016 09:35:54 PM (8 years ago)
- Location:
- trunk/src/wp-includes/js
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/wp-includes/js/tinymce/plugins/wplink/plugin.js
r36483 r36602 42 42 // If the beginning + ending are shorter that 40 chars, show more of the ending 43 43 if ( index + url.length - lastIndex < 40 ) { 44 lastIndex = 44 lastIndex = -( 40 - ( index + 1 ) ); 45 45 } 46 46 … … 75 75 76 76 function getSelectedLink() { 77 var href, 78 selectedNode = editor.selection.getNode(), 79 selectedText = editor.selection.getContent(), 80 link = editor.dom.getParent( selectedNode, 'a[href]' ); 81 82 if ( ! link && selectedText.indexOf( '</a>' ) !== -1 ) { 83 href = selectedText.match( /href="([^">]+)"/ ); 84 85 if ( href && href[1] ) { 86 link = editor.$( 'a[href="' + href[1] + '"]', selectedNode )[0]; 87 } 88 89 if ( link ) { 90 editor.selection.select( link ); 91 editor.nodeChanged(); 77 var href, html 78 node = editor.selection.getNode(); 79 link = editor.dom.getParent( node, 'a[href]' ); 80 81 if ( ! link ) { 82 html = editor.selection.getContent({ format: 'raw' }); 83 84 if ( html && html.indexOf( '</a>' ) !== -1 ) { 85 href = html.match( /href="([^">]+)"/ ); 86 87 if ( href && href[1] ) { 88 link = editor.$( 'a[href="' + href[1] + '"]', node )[0]; 89 } 90 91 if ( link ) { 92 editor.selection.select( link ); 93 editor.nodeChanged(); 94 } 92 95 } 93 96 } 94 97 95 98 return link; 99 } 100 101 function removePlaceholders() { 102 editor.$( 'a' ).each( function( i, element ) { 103 var $element = editor.$( element ); 104 105 if ( $element.attr( 'href' ) === '_wp_link_placeholder' ) { 106 editor.dom.remove( element, true ); 107 } else if ( $element.attr( 'data-wp-link-edit' ) ) { 108 $element.attr( 'data-wp-link-edit', null ); 109 } 110 }); 111 } 112 113 function removePlaceholderStrings( content, dataAttr ) { 114 if ( dataAttr ) { 115 content = content.replace( / data-wp-link-edit="true"/g, '' ); 116 } 117 118 return content.replace( /<a [^>]*?href="_wp_link_placeholder"[^>]*>([\s\S]+)<\/a>/g, '$1' ); 96 119 } 97 120 … … 127 150 128 151 if ( link ) { 129 editor.dom.setAttribs( link, { 'data-wp- edit': true } );152 editor.dom.setAttribs( link, { 'data-wp-link-edit': true } ); 130 153 } else { 154 removePlaceholders(); 155 131 156 editor.execCommand( 'mceInsertLink', false, { href: '_wp_link_placeholder' } ); 157 editor.selection.select( editor.$( 'a[href="_wp_link_placeholder"]' )[0] ); 132 158 editor.nodeChanged(); 133 159 } … … 151 177 152 178 if ( a ) { 153 editor.dom.setAttribs( a, { href: href, 'data-wp- edit': null } );179 editor.dom.setAttribs( a, { href: href, 'data-wp-link-edit': null } ); 154 180 } 155 181 … … 161 187 162 188 editor.addCommand( 'wp_link_cancel', function() { 163 if ( a ) { 164 if ( editor.$( a ).attr( 'href' ) === '_wp_link_placeholder' ) { 165 editor.dom.remove( a, true ); 166 } else { 167 editor.dom.setAttribs( a, { 'data-wp-edit': null } ); 168 } 169 } 170 189 removePlaceholders(); 171 190 a = false; 172 173 191 editor.nodeChanged(); 174 192 editor.focus(); … … 219 237 } 220 238 } ); 239 240 // Remove any remaining placeholders on saving. 241 editor.on( 'savecontent', function( event ) { 242 event.content = removePlaceholderStrings( event.content, true ); 243 }); 244 245 // Prevent adding undo levels on inserting link placeholder. 246 editor.on( 'BeforeAddUndo', function( event ) { 247 if ( event.level.content ) { 248 event.level.content = removePlaceholderStrings( event.level.content ); 249 } 250 }); 221 251 222 252 editor.addButton( 'wp_link_preview', { … … 236 266 inputInstance = this; 237 267 238 if ( $ ) {268 if ( $ && $.ui && $.ui.autocomplete ) { 239 269 $( input ) 240 270 .on( 'keydown', function() { … … 312 342 editor.on( 'wptoolbar', function( event ) { 313 343 var anchor = editor.dom.getParent( event.element, 'a' ), 314 $anchor, 315 href, edit; 344 $anchor, href, edit; 316 345 317 346 if ( anchor ) { 318 347 $anchor = editor.$( anchor ); 319 348 href = $anchor.attr( 'href' ); 320 edit = $anchor.attr( 'data-wp- edit' );349 edit = $anchor.attr( 'data-wp-link-edit' ); 321 350 322 351 if ( href === '_wp_link_placeholder' || edit ) { … … 349 378 icon: 'dashicon dashicons-admin-generic', 350 379 onclick: function() { 351 editor.execCommand( 'wp_link_apply' ); 352 window.wpLink && window.wpLink.open( editor.id ); 380 if ( typeof window.wpLink !== 'undefined' ) { 381 if ( inputInstance.getEl().firstChild.value ) { 382 editor.execCommand( 'wp_link_apply' ); 383 } 384 385 window.wpLink.open( editor.id ); 386 } 353 387 } 354 388 } ); -
trunk/src/wp-includes/js/wplink.js
r35728 r36602 220 220 221 221 mceRefresh: function() { 222 var text, 222 var text, url, 223 223 selectedNode = editor.selection.getNode(), 224 224 linkNode = editor.dom.getParent( selectedNode, 'a[href]' ), … … 227 227 if ( linkNode ) { 228 228 text = linkNode.innerText || linkNode.textContent; 229 inputs.url.val( editor.dom.getAttrib( linkNode, 'href' ) ); 229 url = editor.dom.getAttrib( linkNode, 'href' ); 230 231 if ( url === '_wp_link_placeholder' ) { 232 url = ''; 233 } 234 235 inputs.url.val( url ); 230 236 inputs.openInNewTab.prop( 'checked', '_blank' === editor.dom.getAttrib( linkNode, 'target' ) ); 231 237 inputs.submit.val( wpLinkL10n.update ); … … 245 251 246 252 close: function() { 253 var linkNode; 254 247 255 $( document.body ).removeClass( 'modal-open' ); 248 256 … … 255 263 } 256 264 } else { 265 linkNode = editor.dom.getParent( editor.selection.getNode(), 'a[href]' ); 266 267 if ( linkNode && editor.dom.getAttrib( linkNode, 'href' ) === '_wp_link_placeholder' ) { 268 editor.dom.remove( linkNode, true ); 269 } 270 257 271 editor.focus(); 258 272 } … … 353 367 link, text; 354 368 355 wpLink.close();356 369 editor.focus(); 357 370 … … 389 402 } 390 403 404 wpLink.close(); 391 405 editor.nodeChanged(); 392 406 },
Note: See TracChangeset
for help on using the changeset viewer.