Changeset 36747
- Timestamp:
- 02/27/2016 09:32:02 PM (9 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
r36743 r36747 79 79 reset: function() { 80 80 var urlInput = this.getEl().firstChild; 81 81 82 urlInput.value = ''; 82 83 urlInput.nextSibling.value = ''; … … 89 90 var previewInstance; 90 91 var inputInstance; 92 var linkNode; 91 93 var $ = window.jQuery; 92 94 … … 108 110 if ( link ) { 109 111 editor.selection.select( link ); 110 editor.nodeChanged();111 112 } 112 113 } … … 153 154 if ( ! tinymce.$( document.body ).hasClass( 'modal-open' ) ) { 154 155 window.setTimeout( function() { 155 var element = editToolbar.$el.find( 'input.ui-autocomplete-input' )[0]; 156 var element = editToolbar.$el.find( 'input.ui-autocomplete-input' )[0], 157 selection = linkNode && ( linkNode.textContent || linkNode.innerText ); 156 158 157 159 if ( element ) { 160 if ( ! element.value && selection && typeof window.wpLink !== 'undefined' ) { 161 element.value = window.wpLink.getUrlFromSelection( selection ); 162 } 163 158 164 element.focus(); 159 165 element.select(); … … 172 178 173 179 editor.addCommand( 'WP_Link', function() { 174 var link = getSelectedLink();175 176 180 if ( tinymce.Env.ie && tinymce.Env.ie < 10 ) { 177 181 if ( typeof window.wpLink !== 'undefined' ) { … … 182 186 } 183 187 188 linkNode = getSelectedLink(); 184 189 editToolbar.tempHide = false; 185 190 186 if ( link ) {187 editor.dom.setAttribs( link , { 'data-wplink-edit': true } );191 if ( linkNode ) { 192 editor.dom.setAttribs( linkNode, { 'data-wplink-edit': true } ); 188 193 } else { 189 194 removePlaceholders(); 190 195 editor.execCommand( 'mceInsertLink', false, { href: '_wp_link_placeholder' } ); 191 196 192 if ( tinymce.Env.ie ) { 193 editor.windowManager.wplinkBookmark = editor.selection.getBookmark(); 194 } 195 197 linkNode = editor.$( 'a[href="_wp_link_placeholder"]' )[0]; 196 198 editor.nodeChanged(); 197 199 } … … 203 205 } 204 206 205 var href, text, 206 linkNode = getSelectedLink(); 207 var href, text; 207 208 208 209 if ( linkNode ) { … … 210 211 text = inputInstance.getLinkText(); 211 212 editor.focus(); 212 213 if ( tinymce.isIE ) {214 editor.selection.moveToBookmark( editor.windowManager.wplinkBookmark );215 editor.windowManager.wplinkBookmark = null;216 }217 213 218 214 if ( ! href ) { … … 241 237 removePlaceholders(); 242 238 editor.focus(); 243 244 if ( tinymce.isIE ) {245 editor.selection.moveToBookmark( editor.windowManager.wplinkBookmark );246 editor.windowManager.wplinkBookmark = null;247 }248 249 239 editToolbar.tempHide = false; 250 240 } … … 457 447 458 448 editor.focus(); // Needed for IE 459 window.wpLink.open( editor.id, url, text );449 window.wpLink.open( editor.id, url, text, linkNode ); 460 450 461 451 editToolbar.tempHide = true; -
trunk/src/wp-includes/js/wplink.js
r36743 r36747 3 3 4 4 ( function( $ ) { 5 var editor, correctedURL, 5 var editor, correctedURL, linkNode, 6 6 inputs = {}, 7 7 isTouch = ( 'ontouchend' in document ); 8 8 9 9 function getLink() { 10 return editor.dom.getParent( editor.selection.getNode(), 'a' );10 return linkNode || editor.dom.getParent( editor.selection.getNode(), 'a[href]' ); 11 11 } 12 12 … … 126 126 }, 127 127 128 open: function( editorId, url, text ) {128 open: function( editorId, url, text, node ) { 129 129 var ed, 130 130 $body = $( document.body ); 131 131 132 132 $body.addClass( 'modal-open' ); 133 linkNode = node; 133 134 134 135 wpLink.range = null; … … 259 260 url = url || editor.dom.getAttrib( linkNode, 'href' ); 260 261 261 if ( url === '_wp_link_placeholder' ) {262 url = '';263 }264 265 inputs.url.val( url );266 inputs.openInNewTab.prop( 'checked', '_blank' === editor.dom.getAttrib( linkNode, 'target' ));267 inputs.submit.val( wpLinkL10n.update );262 if ( url !== '_wp_link_placeholder' ) { 263 inputs.url.val( url ); 264 inputs.openInNewTab.prop( 'checked', '_blank' === editor.dom.getAttrib( linkNode, 'target' ) ); 265 inputs.submit.val( wpLinkL10n.update ); 266 } else { 267 this.setDefaultValues( linkText ); 268 } 268 269 } else { 269 text = editor.selection.getContent({ format: 'text' }) || text;270 this.setDefaultValues( );270 linkText = editor.selection.getContent({ format: 'text' }) || text || ''; 271 this.setDefaultValues( linkText ); 271 272 } 272 273 273 274 if ( onlyText ) { 274 inputs.text.val( linkText || '');275 inputs.text.val( linkText ); 275 276 inputs.wrap.addClass( 'has-text-field' ); 276 277 } else { … … 280 281 }, 281 282 282 close: function( ) {283 close: function( reset ) { 283 284 $( document.body ).removeClass( 'modal-open' ); 284 285 285 if ( ! wpLink.isMCE() ) { 286 wpLink.textarea.focus(); 287 288 if ( wpLink.range ) { 289 wpLink.range.moveToBookmark( wpLink.range.getBookmark() ); 290 wpLink.range.select(); 291 } 292 } else { 293 if ( editor.plugins.wplink ) { 294 editor.plugins.wplink.close(); 295 } 296 297 editor.focus(); 286 if ( reset !== 'noReset' ) { 287 if ( ! wpLink.isMCE() ) { 288 wpLink.textarea.focus(); 289 290 if ( wpLink.range ) { 291 wpLink.range.moveToBookmark( wpLink.range.getBookmark() ); 292 wpLink.range.select(); 293 } 294 } else { 295 if ( editor.plugins.wplink ) { 296 editor.plugins.wplink.close(); 297 } 298 299 editor.focus(); 300 } 298 301 } 299 302 … … 395 398 editor.focus(); 396 399 397 if ( tinymce.isIE ) {400 if ( tinymce.isIE && editor.windowManager.wplinkBookmark ) { 398 401 editor.selection.moveToBookmark( editor.windowManager.wplinkBookmark ); 399 402 editor.windowManager.wplinkBookmark = null; … … 402 405 if ( ! attrs.href ) { 403 406 editor.execCommand( 'unlink' ); 407 wpLink.close(); 404 408 return; 405 409 } … … 429 433 } 430 434 431 wpLink.close(); 435 wpLink.close( 'noReset' ); 436 editor.focus(); 432 437 editor.nodeChanged(); 433 438 }, … … 456 461 }, 457 462 458 setDefaultValues: function() {459 var selection,463 getUrlFromSelection: function( selection ) { 464 var url, 460 465 emailRegexp = /^[A-Z0-9._%+-]+@[A-Z0-9.-]+\.[A-Z]{2,4}$/i, 461 466 urlRegexp = /^(https?|ftp):\/\/[A-Z0-9.-]+\.[A-Z]{2,4}[^ "]*$/i; 462 467 463 if ( this.isMCE() ) { 464 selection = editor.selection.getContent(); 465 } else if ( document.selection && wpLink.range ) { 466 selection = wpLink.range.text; 467 } else if ( typeof this.textarea.selectionStart !== 'undefined' ) { 468 selection = this.textarea.value.substring( this.textarea.selectionStart, this.textarea.selectionEnd ); 469 } 468 if ( ! selection ) { 469 if ( this.isMCE() ) { 470 selection = editor.selection.getContent({ format: 'text' }); 471 } else if ( document.selection && wpLink.range ) { 472 selection = wpLink.range.text; 473 } else if ( typeof this.textarea.selectionStart !== 'undefined' ) { 474 selection = this.textarea.value.substring( this.textarea.selectionStart, this.textarea.selectionEnd ); 475 } 476 } 477 478 selection = tinymce.trim( selection ); 470 479 471 480 if ( selection && emailRegexp.test( selection ) ) { 472 481 // Selection is email address 473 inputs.url.val( 'mailto:' + selection );482 return 'mailto:' + selection; 474 483 } else if ( selection && urlRegexp.test( selection ) ) { 475 484 // Selection is URL 476 inputs.url.val( selection.replace( /&|�?38;/gi, '&' ) ); 477 } else { 478 // Set URL to default. 479 inputs.url.val( '' ); 480 } 485 return selection.replace( /&|�?38;/gi, '&' ); 486 } 487 488 return ''; 489 }, 490 491 setDefaultValues: function( selection ) { 492 inputs.url.val( this.getUrlFromSelection( selection ) ); 481 493 482 494 // Update save prompt.
Note: See TracChangeset
for help on using the changeset viewer.