Edit File by line
/home/barbar84/public_h.../wp-inclu.../js
File: wplink.js
/**
[0] Fix | Delete
* @output wp-includes/js/wplink.js
[1] Fix | Delete
*/
[2] Fix | Delete
[3] Fix | Delete
/* global wpLink */
[4] Fix | Delete
[5] Fix | Delete
( function( $, wpLinkL10n, wp ) {
[6] Fix | Delete
var editor, searchTimer, River, Query, correctedURL,
[7] Fix | Delete
emailRegexp = /^[A-Z0-9._%+-]+@[A-Z0-9.-]+\.[A-Z]{2,63}$/i,
[8] Fix | Delete
urlRegexp = /^(https?|ftp):\/\/[A-Z0-9.-]+\.[A-Z]{2,63}[^ "]*$/i,
[9] Fix | Delete
inputs = {},
[10] Fix | Delete
rivers = {},
[11] Fix | Delete
isTouch = ( 'ontouchend' in document );
[12] Fix | Delete
[13] Fix | Delete
function getLink() {
[14] Fix | Delete
if ( editor ) {
[15] Fix | Delete
return editor.$( 'a[data-wplink-edit="true"]' );
[16] Fix | Delete
}
[17] Fix | Delete
[18] Fix | Delete
return null;
[19] Fix | Delete
}
[20] Fix | Delete
[21] Fix | Delete
window.wpLink = {
[22] Fix | Delete
timeToTriggerRiver: 150,
[23] Fix | Delete
minRiverAJAXDuration: 200,
[24] Fix | Delete
riverBottomThreshold: 5,
[25] Fix | Delete
keySensitivity: 100,
[26] Fix | Delete
lastSearch: '',
[27] Fix | Delete
textarea: '',
[28] Fix | Delete
modalOpen: false,
[29] Fix | Delete
[30] Fix | Delete
init: function() {
[31] Fix | Delete
inputs.wrap = $('#wp-link-wrap');
[32] Fix | Delete
inputs.dialog = $( '#wp-link' );
[33] Fix | Delete
inputs.backdrop = $( '#wp-link-backdrop' );
[34] Fix | Delete
inputs.submit = $( '#wp-link-submit' );
[35] Fix | Delete
inputs.close = $( '#wp-link-close' );
[36] Fix | Delete
[37] Fix | Delete
// Input.
[38] Fix | Delete
inputs.text = $( '#wp-link-text' );
[39] Fix | Delete
inputs.url = $( '#wp-link-url' );
[40] Fix | Delete
inputs.nonce = $( '#_ajax_linking_nonce' );
[41] Fix | Delete
inputs.openInNewTab = $( '#wp-link-target' );
[42] Fix | Delete
inputs.search = $( '#wp-link-search' );
[43] Fix | Delete
[44] Fix | Delete
// Build rivers.
[45] Fix | Delete
rivers.search = new River( $( '#search-results' ) );
[46] Fix | Delete
rivers.recent = new River( $( '#most-recent-results' ) );
[47] Fix | Delete
rivers.elements = inputs.dialog.find( '.query-results' );
[48] Fix | Delete
[49] Fix | Delete
// Get search notice text.
[50] Fix | Delete
inputs.queryNotice = $( '#query-notice-message' );
[51] Fix | Delete
inputs.queryNoticeTextDefault = inputs.queryNotice.find( '.query-notice-default' );
[52] Fix | Delete
inputs.queryNoticeTextHint = inputs.queryNotice.find( '.query-notice-hint' );
[53] Fix | Delete
[54] Fix | Delete
// Bind event handlers.
[55] Fix | Delete
inputs.dialog.on( 'keydown', wpLink.keydown );
[56] Fix | Delete
inputs.dialog.on( 'keyup', wpLink.keyup );
[57] Fix | Delete
inputs.submit.on( 'click', function( event ) {
[58] Fix | Delete
event.preventDefault();
[59] Fix | Delete
wpLink.update();
[60] Fix | Delete
});
[61] Fix | Delete
[62] Fix | Delete
inputs.close.add( inputs.backdrop ).add( '#wp-link-cancel button' ).on( 'click', function( event ) {
[63] Fix | Delete
event.preventDefault();
[64] Fix | Delete
wpLink.close();
[65] Fix | Delete
});
[66] Fix | Delete
[67] Fix | Delete
rivers.elements.on( 'river-select', wpLink.updateFields );
[68] Fix | Delete
[69] Fix | Delete
// Display 'hint' message when search field or 'query-results' box are focused.
[70] Fix | Delete
inputs.search.on( 'focus.wplink', function() {
[71] Fix | Delete
inputs.queryNoticeTextDefault.hide();
[72] Fix | Delete
inputs.queryNoticeTextHint.removeClass( 'screen-reader-text' ).show();
[73] Fix | Delete
} ).on( 'blur.wplink', function() {
[74] Fix | Delete
inputs.queryNoticeTextDefault.show();
[75] Fix | Delete
inputs.queryNoticeTextHint.addClass( 'screen-reader-text' ).hide();
[76] Fix | Delete
} );
[77] Fix | Delete
[78] Fix | Delete
inputs.search.on( 'keyup input', function() {
[79] Fix | Delete
window.clearTimeout( searchTimer );
[80] Fix | Delete
searchTimer = window.setTimeout( function() {
[81] Fix | Delete
wpLink.searchInternalLinks();
[82] Fix | Delete
}, 500 );
[83] Fix | Delete
});
[84] Fix | Delete
[85] Fix | Delete
inputs.url.on( 'paste', function() {
[86] Fix | Delete
setTimeout( wpLink.correctURL, 0 );
[87] Fix | Delete
} );
[88] Fix | Delete
[89] Fix | Delete
inputs.url.on( 'blur', wpLink.correctURL );
[90] Fix | Delete
},
[91] Fix | Delete
[92] Fix | Delete
// If URL wasn't corrected last time and doesn't start with http:, https:, ? # or /, prepend http://.
[93] Fix | Delete
correctURL: function () {
[94] Fix | Delete
var url = $.trim( inputs.url.val() );
[95] Fix | Delete
[96] Fix | Delete
if ( url && correctedURL !== url && ! /^(?:[a-z]+:|#|\?|\.|\/)/.test( url ) ) {
[97] Fix | Delete
inputs.url.val( 'http://' + url );
[98] Fix | Delete
correctedURL = url;
[99] Fix | Delete
}
[100] Fix | Delete
},
[101] Fix | Delete
[102] Fix | Delete
open: function( editorId, url, text ) {
[103] Fix | Delete
var ed,
[104] Fix | Delete
$body = $( document.body );
[105] Fix | Delete
[106] Fix | Delete
$body.addClass( 'modal-open' );
[107] Fix | Delete
wpLink.modalOpen = true;
[108] Fix | Delete
[109] Fix | Delete
wpLink.range = null;
[110] Fix | Delete
[111] Fix | Delete
if ( editorId ) {
[112] Fix | Delete
window.wpActiveEditor = editorId;
[113] Fix | Delete
}
[114] Fix | Delete
[115] Fix | Delete
if ( ! window.wpActiveEditor ) {
[116] Fix | Delete
return;
[117] Fix | Delete
}
[118] Fix | Delete
[119] Fix | Delete
this.textarea = $( '#' + window.wpActiveEditor ).get( 0 );
[120] Fix | Delete
[121] Fix | Delete
if ( typeof window.tinymce !== 'undefined' ) {
[122] Fix | Delete
// Make sure the link wrapper is the last element in the body,
[123] Fix | Delete
// or the inline editor toolbar may show above the backdrop.
[124] Fix | Delete
$body.append( inputs.backdrop, inputs.wrap );
[125] Fix | Delete
[126] Fix | Delete
ed = window.tinymce.get( window.wpActiveEditor );
[127] Fix | Delete
[128] Fix | Delete
if ( ed && ! ed.isHidden() ) {
[129] Fix | Delete
editor = ed;
[130] Fix | Delete
} else {
[131] Fix | Delete
editor = null;
[132] Fix | Delete
}
[133] Fix | Delete
}
[134] Fix | Delete
[135] Fix | Delete
if ( ! wpLink.isMCE() && document.selection ) {
[136] Fix | Delete
this.textarea.focus();
[137] Fix | Delete
this.range = document.selection.createRange();
[138] Fix | Delete
}
[139] Fix | Delete
[140] Fix | Delete
inputs.wrap.show();
[141] Fix | Delete
inputs.backdrop.show();
[142] Fix | Delete
[143] Fix | Delete
wpLink.refresh( url, text );
[144] Fix | Delete
[145] Fix | Delete
$( document ).trigger( 'wplink-open', inputs.wrap );
[146] Fix | Delete
},
[147] Fix | Delete
[148] Fix | Delete
isMCE: function() {
[149] Fix | Delete
return editor && ! editor.isHidden();
[150] Fix | Delete
},
[151] Fix | Delete
[152] Fix | Delete
refresh: function( url, text ) {
[153] Fix | Delete
var linkText = '';
[154] Fix | Delete
[155] Fix | Delete
// Refresh rivers (clear links, check visibility).
[156] Fix | Delete
rivers.search.refresh();
[157] Fix | Delete
rivers.recent.refresh();
[158] Fix | Delete
[159] Fix | Delete
if ( wpLink.isMCE() ) {
[160] Fix | Delete
wpLink.mceRefresh( url, text );
[161] Fix | Delete
} else {
[162] Fix | Delete
// For the Text editor the "Link text" field is always shown.
[163] Fix | Delete
if ( ! inputs.wrap.hasClass( 'has-text-field' ) ) {
[164] Fix | Delete
inputs.wrap.addClass( 'has-text-field' );
[165] Fix | Delete
}
[166] Fix | Delete
[167] Fix | Delete
if ( document.selection ) {
[168] Fix | Delete
// Old IE.
[169] Fix | Delete
linkText = document.selection.createRange().text || text || '';
[170] Fix | Delete
} else if ( typeof this.textarea.selectionStart !== 'undefined' &&
[171] Fix | Delete
( this.textarea.selectionStart !== this.textarea.selectionEnd ) ) {
[172] Fix | Delete
// W3C.
[173] Fix | Delete
text = this.textarea.value.substring( this.textarea.selectionStart, this.textarea.selectionEnd ) || text || '';
[174] Fix | Delete
}
[175] Fix | Delete
[176] Fix | Delete
inputs.text.val( text );
[177] Fix | Delete
wpLink.setDefaultValues();
[178] Fix | Delete
}
[179] Fix | Delete
[180] Fix | Delete
if ( isTouch ) {
[181] Fix | Delete
// Close the onscreen keyboard.
[182] Fix | Delete
inputs.url.trigger( 'focus' ).trigger( 'blur' );
[183] Fix | Delete
} else {
[184] Fix | Delete
/*
[185] Fix | Delete
* Focus the URL field and highlight its contents.
[186] Fix | Delete
* If this is moved above the selection changes,
[187] Fix | Delete
* IE will show a flashing cursor over the dialog.
[188] Fix | Delete
*/
[189] Fix | Delete
window.setTimeout( function() {
[190] Fix | Delete
inputs.url[0].select();
[191] Fix | Delete
inputs.url.trigger( 'focus' );
[192] Fix | Delete
} );
[193] Fix | Delete
}
[194] Fix | Delete
[195] Fix | Delete
// Load the most recent results if this is the first time opening the panel.
[196] Fix | Delete
if ( ! rivers.recent.ul.children().length ) {
[197] Fix | Delete
rivers.recent.ajax();
[198] Fix | Delete
}
[199] Fix | Delete
[200] Fix | Delete
correctedURL = inputs.url.val().replace( /^http:\/\//, '' );
[201] Fix | Delete
},
[202] Fix | Delete
[203] Fix | Delete
hasSelectedText: function( linkNode ) {
[204] Fix | Delete
var node, nodes, i, html = editor.selection.getContent();
[205] Fix | Delete
[206] Fix | Delete
// Partial html and not a fully selected anchor element.
[207] Fix | Delete
if ( /</.test( html ) && ( ! /^<a [^>]+>[^<]+<\/a>$/.test( html ) || html.indexOf('href=') === -1 ) ) {
[208] Fix | Delete
return false;
[209] Fix | Delete
}
[210] Fix | Delete
[211] Fix | Delete
if ( linkNode.length ) {
[212] Fix | Delete
nodes = linkNode[0].childNodes;
[213] Fix | Delete
[214] Fix | Delete
if ( ! nodes || ! nodes.length ) {
[215] Fix | Delete
return false;
[216] Fix | Delete
}
[217] Fix | Delete
[218] Fix | Delete
for ( i = nodes.length - 1; i >= 0; i-- ) {
[219] Fix | Delete
node = nodes[i];
[220] Fix | Delete
[221] Fix | Delete
if ( node.nodeType != 3 && ! window.tinymce.dom.BookmarkManager.isBookmarkNode( node ) ) {
[222] Fix | Delete
return false;
[223] Fix | Delete
}
[224] Fix | Delete
}
[225] Fix | Delete
}
[226] Fix | Delete
[227] Fix | Delete
return true;
[228] Fix | Delete
},
[229] Fix | Delete
[230] Fix | Delete
mceRefresh: function( searchStr, text ) {
[231] Fix | Delete
var linkText, href,
[232] Fix | Delete
linkNode = getLink(),
[233] Fix | Delete
onlyText = this.hasSelectedText( linkNode );
[234] Fix | Delete
[235] Fix | Delete
if ( linkNode.length ) {
[236] Fix | Delete
linkText = linkNode.text();
[237] Fix | Delete
href = linkNode.attr( 'href' );
[238] Fix | Delete
[239] Fix | Delete
if ( ! $.trim( linkText ) ) {
[240] Fix | Delete
linkText = text || '';
[241] Fix | Delete
}
[242] Fix | Delete
[243] Fix | Delete
if ( searchStr && ( urlRegexp.test( searchStr ) || emailRegexp.test( searchStr ) ) ) {
[244] Fix | Delete
href = searchStr;
[245] Fix | Delete
}
[246] Fix | Delete
[247] Fix | Delete
if ( href !== '_wp_link_placeholder' ) {
[248] Fix | Delete
inputs.url.val( href );
[249] Fix | Delete
inputs.openInNewTab.prop( 'checked', '_blank' === linkNode.attr( 'target' ) );
[250] Fix | Delete
inputs.submit.val( wpLinkL10n.update );
[251] Fix | Delete
} else {
[252] Fix | Delete
this.setDefaultValues( linkText );
[253] Fix | Delete
}
[254] Fix | Delete
[255] Fix | Delete
if ( searchStr && searchStr !== href ) {
[256] Fix | Delete
// The user has typed something in the inline dialog. Trigger a search with it.
[257] Fix | Delete
inputs.search.val( searchStr );
[258] Fix | Delete
} else {
[259] Fix | Delete
inputs.search.val( '' );
[260] Fix | Delete
}
[261] Fix | Delete
[262] Fix | Delete
// Always reset the search.
[263] Fix | Delete
window.setTimeout( function() {
[264] Fix | Delete
wpLink.searchInternalLinks();
[265] Fix | Delete
} );
[266] Fix | Delete
} else {
[267] Fix | Delete
linkText = editor.selection.getContent({ format: 'text' }) || text || '';
[268] Fix | Delete
this.setDefaultValues( linkText );
[269] Fix | Delete
}
[270] Fix | Delete
[271] Fix | Delete
if ( onlyText ) {
[272] Fix | Delete
inputs.text.val( linkText );
[273] Fix | Delete
inputs.wrap.addClass( 'has-text-field' );
[274] Fix | Delete
} else {
[275] Fix | Delete
inputs.text.val( '' );
[276] Fix | Delete
inputs.wrap.removeClass( 'has-text-field' );
[277] Fix | Delete
}
[278] Fix | Delete
},
[279] Fix | Delete
[280] Fix | Delete
close: function( reset ) {
[281] Fix | Delete
$( document.body ).removeClass( 'modal-open' );
[282] Fix | Delete
wpLink.modalOpen = false;
[283] Fix | Delete
[284] Fix | Delete
if ( reset !== 'noReset' ) {
[285] Fix | Delete
if ( ! wpLink.isMCE() ) {
[286] Fix | Delete
wpLink.textarea.focus();
[287] Fix | Delete
[288] Fix | Delete
if ( wpLink.range ) {
[289] Fix | Delete
wpLink.range.moveToBookmark( wpLink.range.getBookmark() );
[290] Fix | Delete
wpLink.range.select();
[291] Fix | Delete
}
[292] Fix | Delete
} else {
[293] Fix | Delete
if ( editor.plugins.wplink ) {
[294] Fix | Delete
editor.plugins.wplink.close();
[295] Fix | Delete
}
[296] Fix | Delete
[297] Fix | Delete
editor.focus();
[298] Fix | Delete
}
[299] Fix | Delete
}
[300] Fix | Delete
[301] Fix | Delete
inputs.backdrop.hide();
[302] Fix | Delete
inputs.wrap.hide();
[303] Fix | Delete
[304] Fix | Delete
correctedURL = false;
[305] Fix | Delete
[306] Fix | Delete
$( document ).trigger( 'wplink-close', inputs.wrap );
[307] Fix | Delete
},
[308] Fix | Delete
[309] Fix | Delete
getAttrs: function() {
[310] Fix | Delete
wpLink.correctURL();
[311] Fix | Delete
[312] Fix | Delete
return {
[313] Fix | Delete
href: $.trim( inputs.url.val() ),
[314] Fix | Delete
target: inputs.openInNewTab.prop( 'checked' ) ? '_blank' : null
[315] Fix | Delete
};
[316] Fix | Delete
},
[317] Fix | Delete
[318] Fix | Delete
buildHtml: function(attrs) {
[319] Fix | Delete
var html = '<a href="' + attrs.href + '"';
[320] Fix | Delete
[321] Fix | Delete
if ( attrs.target ) {
[322] Fix | Delete
html += ' rel="noopener" target="' + attrs.target + '"';
[323] Fix | Delete
}
[324] Fix | Delete
[325] Fix | Delete
return html + '>';
[326] Fix | Delete
},
[327] Fix | Delete
[328] Fix | Delete
update: function() {
[329] Fix | Delete
if ( wpLink.isMCE() ) {
[330] Fix | Delete
wpLink.mceUpdate();
[331] Fix | Delete
} else {
[332] Fix | Delete
wpLink.htmlUpdate();
[333] Fix | Delete
}
[334] Fix | Delete
},
[335] Fix | Delete
[336] Fix | Delete
htmlUpdate: function() {
[337] Fix | Delete
var attrs, text, html, begin, end, cursor, selection,
[338] Fix | Delete
textarea = wpLink.textarea;
[339] Fix | Delete
[340] Fix | Delete
if ( ! textarea ) {
[341] Fix | Delete
return;
[342] Fix | Delete
}
[343] Fix | Delete
[344] Fix | Delete
attrs = wpLink.getAttrs();
[345] Fix | Delete
text = inputs.text.val();
[346] Fix | Delete
[347] Fix | Delete
var parser = document.createElement( 'a' );
[348] Fix | Delete
parser.href = attrs.href;
[349] Fix | Delete
[350] Fix | Delete
if ( 'javascript:' === parser.protocol || 'data:' === parser.protocol ) { // jshint ignore:line
[351] Fix | Delete
attrs.href = '';
[352] Fix | Delete
}
[353] Fix | Delete
[354] Fix | Delete
// If there's no href, return.
[355] Fix | Delete
if ( ! attrs.href ) {
[356] Fix | Delete
return;
[357] Fix | Delete
}
[358] Fix | Delete
[359] Fix | Delete
html = wpLink.buildHtml(attrs);
[360] Fix | Delete
[361] Fix | Delete
// Insert HTML.
[362] Fix | Delete
if ( document.selection && wpLink.range ) {
[363] Fix | Delete
// IE.
[364] Fix | Delete
// Note: If no text is selected, IE will not place the cursor
[365] Fix | Delete
// inside the closing tag.
[366] Fix | Delete
textarea.focus();
[367] Fix | Delete
wpLink.range.text = html + ( text || wpLink.range.text ) + '</a>';
[368] Fix | Delete
wpLink.range.moveToBookmark( wpLink.range.getBookmark() );
[369] Fix | Delete
wpLink.range.select();
[370] Fix | Delete
[371] Fix | Delete
wpLink.range = null;
[372] Fix | Delete
} else if ( typeof textarea.selectionStart !== 'undefined' ) {
[373] Fix | Delete
// W3C.
[374] Fix | Delete
begin = textarea.selectionStart;
[375] Fix | Delete
end = textarea.selectionEnd;
[376] Fix | Delete
selection = text || textarea.value.substring( begin, end );
[377] Fix | Delete
html = html + selection + '</a>';
[378] Fix | Delete
cursor = begin + html.length;
[379] Fix | Delete
[380] Fix | Delete
// If no text is selected, place the cursor inside the closing tag.
[381] Fix | Delete
if ( begin === end && ! selection ) {
[382] Fix | Delete
cursor -= 4;
[383] Fix | Delete
}
[384] Fix | Delete
[385] Fix | Delete
textarea.value = (
[386] Fix | Delete
textarea.value.substring( 0, begin ) +
[387] Fix | Delete
html +
[388] Fix | Delete
textarea.value.substring( end, textarea.value.length )
[389] Fix | Delete
);
[390] Fix | Delete
[391] Fix | Delete
// Update cursor position.
[392] Fix | Delete
textarea.selectionStart = textarea.selectionEnd = cursor;
[393] Fix | Delete
}
[394] Fix | Delete
[395] Fix | Delete
wpLink.close();
[396] Fix | Delete
textarea.focus();
[397] Fix | Delete
$( textarea ).trigger( 'change' );
[398] Fix | Delete
[399] Fix | Delete
// Audible confirmation message when a link has been inserted in the Editor.
[400] Fix | Delete
wp.a11y.speak( wpLinkL10n.linkInserted );
[401] Fix | Delete
},
[402] Fix | Delete
[403] Fix | Delete
mceUpdate: function() {
[404] Fix | Delete
var attrs = wpLink.getAttrs(),
[405] Fix | Delete
$link, text, hasText;
[406] Fix | Delete
[407] Fix | Delete
var parser = document.createElement( 'a' );
[408] Fix | Delete
parser.href = attrs.href;
[409] Fix | Delete
[410] Fix | Delete
if ( 'javascript:' === parser.protocol || 'data:' === parser.protocol ) { // jshint ignore:line
[411] Fix | Delete
attrs.href = '';
[412] Fix | Delete
}
[413] Fix | Delete
[414] Fix | Delete
if ( ! attrs.href ) {
[415] Fix | Delete
editor.execCommand( 'unlink' );
[416] Fix | Delete
wpLink.close();
[417] Fix | Delete
return;
[418] Fix | Delete
}
[419] Fix | Delete
[420] Fix | Delete
$link = getLink();
[421] Fix | Delete
[422] Fix | Delete
editor.undoManager.transact( function() {
[423] Fix | Delete
if ( ! $link.length ) {
[424] Fix | Delete
editor.execCommand( 'mceInsertLink', false, { href: '_wp_link_placeholder', 'data-wp-temp-link': 1 } );
[425] Fix | Delete
$link = editor.$( 'a[data-wp-temp-link="1"]' ).removeAttr( 'data-wp-temp-link' );
[426] Fix | Delete
hasText = $.trim( $link.text() );
[427] Fix | Delete
}
[428] Fix | Delete
[429] Fix | Delete
if ( ! $link.length ) {
[430] Fix | Delete
editor.execCommand( 'unlink' );
[431] Fix | Delete
} else {
[432] Fix | Delete
if ( inputs.wrap.hasClass( 'has-text-field' ) ) {
[433] Fix | Delete
text = inputs.text.val();
[434] Fix | Delete
[435] Fix | Delete
if ( text ) {
[436] Fix | Delete
$link.text( text );
[437] Fix | Delete
} else if ( ! hasText ) {
[438] Fix | Delete
$link.text( attrs.href );
[439] Fix | Delete
}
[440] Fix | Delete
}
[441] Fix | Delete
[442] Fix | Delete
attrs['data-wplink-edit'] = null;
[443] Fix | Delete
attrs['data-mce-href'] = attrs.href;
[444] Fix | Delete
$link.attr( attrs );
[445] Fix | Delete
}
[446] Fix | Delete
} );
[447] Fix | Delete
[448] Fix | Delete
wpLink.close( 'noReset' );
[449] Fix | Delete
editor.focus();
[450] Fix | Delete
[451] Fix | Delete
if ( $link.length ) {
[452] Fix | Delete
editor.selection.select( $link[0] );
[453] Fix | Delete
[454] Fix | Delete
if ( editor.plugins.wplink ) {
[455] Fix | Delete
editor.plugins.wplink.checkLink( $link[0] );
[456] Fix | Delete
}
[457] Fix | Delete
}
[458] Fix | Delete
[459] Fix | Delete
editor.nodeChanged();
[460] Fix | Delete
[461] Fix | Delete
// Audible confirmation message when a link has been inserted in the Editor.
[462] Fix | Delete
wp.a11y.speak( wpLinkL10n.linkInserted );
[463] Fix | Delete
},
[464] Fix | Delete
[465] Fix | Delete
updateFields: function( e, li ) {
[466] Fix | Delete
inputs.url.val( li.children( '.item-permalink' ).val() );
[467] Fix | Delete
[468] Fix | Delete
if ( inputs.wrap.hasClass( 'has-text-field' ) && ! inputs.text.val() ) {
[469] Fix | Delete
inputs.text.val( li.children( '.item-title' ).text() );
[470] Fix | Delete
}
[471] Fix | Delete
},
[472] Fix | Delete
[473] Fix | Delete
getUrlFromSelection: function( selection ) {
[474] Fix | Delete
if ( ! selection ) {
[475] Fix | Delete
if ( this.isMCE() ) {
[476] Fix | Delete
selection = editor.selection.getContent({ format: 'text' });
[477] Fix | Delete
} else if ( document.selection && wpLink.range ) {
[478] Fix | Delete
selection = wpLink.range.text;
[479] Fix | Delete
} else if ( typeof this.textarea.selectionStart !== 'undefined' ) {
[480] Fix | Delete
selection = this.textarea.value.substring( this.textarea.selectionStart, this.textarea.selectionEnd );
[481] Fix | Delete
}
[482] Fix | Delete
}
[483] Fix | Delete
[484] Fix | Delete
selection = $.trim( selection );
[485] Fix | Delete
[486] Fix | Delete
if ( selection && emailRegexp.test( selection ) ) {
[487] Fix | Delete
// Selection is email address.
[488] Fix | Delete
return 'mailto:' + selection;
[489] Fix | Delete
} else if ( selection && urlRegexp.test( selection ) ) {
[490] Fix | Delete
// Selection is URL.
[491] Fix | Delete
return selection.replace( /&amp;|&#0?38;/gi, '&' );
[492] Fix | Delete
}
[493] Fix | Delete
[494] Fix | Delete
return '';
[495] Fix | Delete
},
[496] Fix | Delete
[497] Fix | Delete
setDefaultValues: function( selection ) {
[498] Fix | Delete
inputs.url.val( this.getUrlFromSelection( selection ) );
[499] Fix | Delete
12
It is recommended that you Edit text format, this type of Fix handles quite a lot in one request
Function