Edit File by line
/home/barbar84/public_h.../wp-admin/js
File: editor.js
/**
[0] Fix | Delete
* @output wp-admin/js/editor.js
[1] Fix | Delete
*/
[2] Fix | Delete
[3] Fix | Delete
window.wp = window.wp || {};
[4] Fix | Delete
[5] Fix | Delete
( function( $, wp ) {
[6] Fix | Delete
wp.editor = wp.editor || {};
[7] Fix | Delete
[8] Fix | Delete
/**
[9] Fix | Delete
* Utility functions for the editor.
[10] Fix | Delete
*
[11] Fix | Delete
* @since 2.5.0
[12] Fix | Delete
*/
[13] Fix | Delete
function SwitchEditors() {
[14] Fix | Delete
var tinymce, $$,
[15] Fix | Delete
exports = {};
[16] Fix | Delete
[17] Fix | Delete
function init() {
[18] Fix | Delete
if ( ! tinymce && window.tinymce ) {
[19] Fix | Delete
tinymce = window.tinymce;
[20] Fix | Delete
$$ = tinymce.$;
[21] Fix | Delete
[22] Fix | Delete
/**
[23] Fix | Delete
* Handles onclick events for the Visual/Text tabs.
[24] Fix | Delete
*
[25] Fix | Delete
* @since 4.3.0
[26] Fix | Delete
*
[27] Fix | Delete
* @return {void}
[28] Fix | Delete
*/
[29] Fix | Delete
$$( document ).on( 'click', function( event ) {
[30] Fix | Delete
var id, mode,
[31] Fix | Delete
target = $$( event.target );
[32] Fix | Delete
[33] Fix | Delete
if ( target.hasClass( 'wp-switch-editor' ) ) {
[34] Fix | Delete
id = target.attr( 'data-wp-editor-id' );
[35] Fix | Delete
mode = target.hasClass( 'switch-tmce' ) ? 'tmce' : 'html';
[36] Fix | Delete
switchEditor( id, mode );
[37] Fix | Delete
}
[38] Fix | Delete
});
[39] Fix | Delete
}
[40] Fix | Delete
}
[41] Fix | Delete
[42] Fix | Delete
/**
[43] Fix | Delete
* Returns the height of the editor toolbar(s) in px.
[44] Fix | Delete
*
[45] Fix | Delete
* @since 3.9.0
[46] Fix | Delete
*
[47] Fix | Delete
* @param {Object} editor The TinyMCE editor.
[48] Fix | Delete
* @return {number} If the height is between 10 and 200 return the height,
[49] Fix | Delete
* else return 30.
[50] Fix | Delete
*/
[51] Fix | Delete
function getToolbarHeight( editor ) {
[52] Fix | Delete
var node = $$( '.mce-toolbar-grp', editor.getContainer() )[0],
[53] Fix | Delete
height = node && node.clientHeight;
[54] Fix | Delete
[55] Fix | Delete
if ( height && height > 10 && height < 200 ) {
[56] Fix | Delete
return parseInt( height, 10 );
[57] Fix | Delete
}
[58] Fix | Delete
[59] Fix | Delete
return 30;
[60] Fix | Delete
}
[61] Fix | Delete
[62] Fix | Delete
/**
[63] Fix | Delete
* Switches the editor between Visual and Text mode.
[64] Fix | Delete
*
[65] Fix | Delete
* @since 2.5.0
[66] Fix | Delete
*
[67] Fix | Delete
* @memberof switchEditors
[68] Fix | Delete
*
[69] Fix | Delete
* @param {string} id The id of the editor you want to change the editor mode for. Default: `content`.
[70] Fix | Delete
* @param {string} mode The mode you want to switch to. Default: `toggle`.
[71] Fix | Delete
* @return {void}
[72] Fix | Delete
*/
[73] Fix | Delete
function switchEditor( id, mode ) {
[74] Fix | Delete
id = id || 'content';
[75] Fix | Delete
mode = mode || 'toggle';
[76] Fix | Delete
[77] Fix | Delete
var editorHeight, toolbarHeight, iframe,
[78] Fix | Delete
editor = tinymce.get( id ),
[79] Fix | Delete
wrap = $$( '#wp-' + id + '-wrap' ),
[80] Fix | Delete
$textarea = $$( '#' + id ),
[81] Fix | Delete
textarea = $textarea[0];
[82] Fix | Delete
[83] Fix | Delete
if ( 'toggle' === mode ) {
[84] Fix | Delete
if ( editor && ! editor.isHidden() ) {
[85] Fix | Delete
mode = 'html';
[86] Fix | Delete
} else {
[87] Fix | Delete
mode = 'tmce';
[88] Fix | Delete
}
[89] Fix | Delete
}
[90] Fix | Delete
[91] Fix | Delete
if ( 'tmce' === mode || 'tinymce' === mode ) {
[92] Fix | Delete
// If the editor is visible we are already in `tinymce` mode.
[93] Fix | Delete
if ( editor && ! editor.isHidden() ) {
[94] Fix | Delete
return false;
[95] Fix | Delete
}
[96] Fix | Delete
[97] Fix | Delete
// Insert closing tags for any open tags in QuickTags.
[98] Fix | Delete
if ( typeof( window.QTags ) !== 'undefined' ) {
[99] Fix | Delete
window.QTags.closeAllTags( id );
[100] Fix | Delete
}
[101] Fix | Delete
[102] Fix | Delete
editorHeight = parseInt( textarea.style.height, 10 ) || 0;
[103] Fix | Delete
[104] Fix | Delete
var keepSelection = false;
[105] Fix | Delete
if ( editor ) {
[106] Fix | Delete
keepSelection = editor.getParam( 'wp_keep_scroll_position' );
[107] Fix | Delete
} else {
[108] Fix | Delete
keepSelection = window.tinyMCEPreInit.mceInit[ id ] &&
[109] Fix | Delete
window.tinyMCEPreInit.mceInit[ id ].wp_keep_scroll_position;
[110] Fix | Delete
}
[111] Fix | Delete
[112] Fix | Delete
if ( keepSelection ) {
[113] Fix | Delete
// Save the selection.
[114] Fix | Delete
addHTMLBookmarkInTextAreaContent( $textarea );
[115] Fix | Delete
}
[116] Fix | Delete
[117] Fix | Delete
if ( editor ) {
[118] Fix | Delete
editor.show();
[119] Fix | Delete
[120] Fix | Delete
// No point to resize the iframe in iOS.
[121] Fix | Delete
if ( ! tinymce.Env.iOS && editorHeight ) {
[122] Fix | Delete
toolbarHeight = getToolbarHeight( editor );
[123] Fix | Delete
editorHeight = editorHeight - toolbarHeight + 14;
[124] Fix | Delete
[125] Fix | Delete
// Sane limit for the editor height.
[126] Fix | Delete
if ( editorHeight > 50 && editorHeight < 5000 ) {
[127] Fix | Delete
editor.theme.resizeTo( null, editorHeight );
[128] Fix | Delete
}
[129] Fix | Delete
}
[130] Fix | Delete
[131] Fix | Delete
if ( editor.getParam( 'wp_keep_scroll_position' ) ) {
[132] Fix | Delete
// Restore the selection.
[133] Fix | Delete
focusHTMLBookmarkInVisualEditor( editor );
[134] Fix | Delete
}
[135] Fix | Delete
} else {
[136] Fix | Delete
tinymce.init( window.tinyMCEPreInit.mceInit[ id ] );
[137] Fix | Delete
}
[138] Fix | Delete
[139] Fix | Delete
wrap.removeClass( 'html-active' ).addClass( 'tmce-active' );
[140] Fix | Delete
$textarea.attr( 'aria-hidden', true );
[141] Fix | Delete
window.setUserSetting( 'editor', 'tinymce' );
[142] Fix | Delete
[143] Fix | Delete
} else if ( 'html' === mode ) {
[144] Fix | Delete
// If the editor is hidden (Quicktags is shown) we don't need to switch.
[145] Fix | Delete
if ( editor && editor.isHidden() ) {
[146] Fix | Delete
return false;
[147] Fix | Delete
}
[148] Fix | Delete
[149] Fix | Delete
if ( editor ) {
[150] Fix | Delete
// Don't resize the textarea in iOS.
[151] Fix | Delete
// The iframe is forced to 100% height there, we shouldn't match it.
[152] Fix | Delete
if ( ! tinymce.Env.iOS ) {
[153] Fix | Delete
iframe = editor.iframeElement;
[154] Fix | Delete
editorHeight = iframe ? parseInt( iframe.style.height, 10 ) : 0;
[155] Fix | Delete
[156] Fix | Delete
if ( editorHeight ) {
[157] Fix | Delete
toolbarHeight = getToolbarHeight( editor );
[158] Fix | Delete
editorHeight = editorHeight + toolbarHeight - 14;
[159] Fix | Delete
[160] Fix | Delete
// Sane limit for the textarea height.
[161] Fix | Delete
if ( editorHeight > 50 && editorHeight < 5000 ) {
[162] Fix | Delete
textarea.style.height = editorHeight + 'px';
[163] Fix | Delete
}
[164] Fix | Delete
}
[165] Fix | Delete
}
[166] Fix | Delete
[167] Fix | Delete
var selectionRange = null;
[168] Fix | Delete
[169] Fix | Delete
if ( editor.getParam( 'wp_keep_scroll_position' ) ) {
[170] Fix | Delete
selectionRange = findBookmarkedPosition( editor );
[171] Fix | Delete
}
[172] Fix | Delete
[173] Fix | Delete
editor.hide();
[174] Fix | Delete
[175] Fix | Delete
if ( selectionRange ) {
[176] Fix | Delete
selectTextInTextArea( editor, selectionRange );
[177] Fix | Delete
}
[178] Fix | Delete
} else {
[179] Fix | Delete
// There is probably a JS error on the page.
[180] Fix | Delete
// The TinyMCE editor instance doesn't exist. Show the textarea.
[181] Fix | Delete
$textarea.css({ 'display': '', 'visibility': '' });
[182] Fix | Delete
}
[183] Fix | Delete
[184] Fix | Delete
wrap.removeClass( 'tmce-active' ).addClass( 'html-active' );
[185] Fix | Delete
$textarea.attr( 'aria-hidden', false );
[186] Fix | Delete
window.setUserSetting( 'editor', 'html' );
[187] Fix | Delete
}
[188] Fix | Delete
}
[189] Fix | Delete
[190] Fix | Delete
/**
[191] Fix | Delete
* Checks if a cursor is inside an HTML tag or comment.
[192] Fix | Delete
*
[193] Fix | Delete
* In order to prevent breaking HTML tags when selecting text, the cursor
[194] Fix | Delete
* must be moved to either the start or end of the tag.
[195] Fix | Delete
*
[196] Fix | Delete
* This will prevent the selection marker to be inserted in the middle of an HTML tag.
[197] Fix | Delete
*
[198] Fix | Delete
* This function gives information whether the cursor is inside a tag or not, as well as
[199] Fix | Delete
* the tag type, if it is a closing tag and check if the HTML tag is inside a shortcode tag,
[200] Fix | Delete
* e.g. `[caption]<img.../>..`.
[201] Fix | Delete
*
[202] Fix | Delete
* @param {string} content The test content where the cursor is.
[203] Fix | Delete
* @param {number} cursorPosition The cursor position inside the content.
[204] Fix | Delete
*
[205] Fix | Delete
* @return {(null|Object)} Null if cursor is not in a tag, Object if the cursor is inside a tag.
[206] Fix | Delete
*/
[207] Fix | Delete
function getContainingTagInfo( content, cursorPosition ) {
[208] Fix | Delete
var lastLtPos = content.lastIndexOf( '<', cursorPosition - 1 ),
[209] Fix | Delete
lastGtPos = content.lastIndexOf( '>', cursorPosition );
[210] Fix | Delete
[211] Fix | Delete
if ( lastLtPos > lastGtPos || content.substr( cursorPosition, 1 ) === '>' ) {
[212] Fix | Delete
// Find what the tag is.
[213] Fix | Delete
var tagContent = content.substr( lastLtPos ),
[214] Fix | Delete
tagMatch = tagContent.match( /<\s*(\/)?(\w+|\!-{2}.*-{2})/ );
[215] Fix | Delete
[216] Fix | Delete
if ( ! tagMatch ) {
[217] Fix | Delete
return null;
[218] Fix | Delete
}
[219] Fix | Delete
[220] Fix | Delete
var tagType = tagMatch[2],
[221] Fix | Delete
closingGt = tagContent.indexOf( '>' );
[222] Fix | Delete
[223] Fix | Delete
return {
[224] Fix | Delete
ltPos: lastLtPos,
[225] Fix | Delete
gtPos: lastLtPos + closingGt + 1, // Offset by one to get the position _after_ the character.
[226] Fix | Delete
tagType: tagType,
[227] Fix | Delete
isClosingTag: !! tagMatch[1]
[228] Fix | Delete
};
[229] Fix | Delete
}
[230] Fix | Delete
return null;
[231] Fix | Delete
}
[232] Fix | Delete
[233] Fix | Delete
/**
[234] Fix | Delete
* Checks if the cursor is inside a shortcode
[235] Fix | Delete
*
[236] Fix | Delete
* If the cursor is inside a shortcode wrapping tag, e.g. `[caption]` it's better to
[237] Fix | Delete
* move the selection marker to before or after the shortcode.
[238] Fix | Delete
*
[239] Fix | Delete
* For example `[caption]` rewrites/removes anything that's between the `[caption]` tag and the
[240] Fix | Delete
* `<img/>` tag inside.
[241] Fix | Delete
*
[242] Fix | Delete
* `[caption]<span>ThisIsGone</span><img .../>[caption]`
[243] Fix | Delete
*
[244] Fix | Delete
* Moving the selection to before or after the short code is better, since it allows to select
[245] Fix | Delete
* something, instead of just losing focus and going to the start of the content.
[246] Fix | Delete
*
[247] Fix | Delete
* @param {string} content The text content to check against.
[248] Fix | Delete
* @param {number} cursorPosition The cursor position to check.
[249] Fix | Delete
*
[250] Fix | Delete
* @return {(undefined|Object)} Undefined if the cursor is not wrapped in a shortcode tag.
[251] Fix | Delete
* Information about the wrapping shortcode tag if it's wrapped in one.
[252] Fix | Delete
*/
[253] Fix | Delete
function getShortcodeWrapperInfo( content, cursorPosition ) {
[254] Fix | Delete
var contentShortcodes = getShortCodePositionsInText( content );
[255] Fix | Delete
[256] Fix | Delete
for ( var i = 0; i < contentShortcodes.length; i++ ) {
[257] Fix | Delete
var element = contentShortcodes[ i ];
[258] Fix | Delete
[259] Fix | Delete
if ( cursorPosition >= element.startIndex && cursorPosition <= element.endIndex ) {
[260] Fix | Delete
return element;
[261] Fix | Delete
}
[262] Fix | Delete
}
[263] Fix | Delete
}
[264] Fix | Delete
[265] Fix | Delete
/**
[266] Fix | Delete
* Gets a list of unique shortcodes or shortcode-look-alikes in the content.
[267] Fix | Delete
*
[268] Fix | Delete
* @param {string} content The content we want to scan for shortcodes.
[269] Fix | Delete
*/
[270] Fix | Delete
function getShortcodesInText( content ) {
[271] Fix | Delete
var shortcodes = content.match( /\[+([\w_-])+/g ),
[272] Fix | Delete
result = [];
[273] Fix | Delete
[274] Fix | Delete
if ( shortcodes ) {
[275] Fix | Delete
for ( var i = 0; i < shortcodes.length; i++ ) {
[276] Fix | Delete
var shortcode = shortcodes[ i ].replace( /^\[+/g, '' );
[277] Fix | Delete
[278] Fix | Delete
if ( result.indexOf( shortcode ) === -1 ) {
[279] Fix | Delete
result.push( shortcode );
[280] Fix | Delete
}
[281] Fix | Delete
}
[282] Fix | Delete
}
[283] Fix | Delete
[284] Fix | Delete
return result;
[285] Fix | Delete
}
[286] Fix | Delete
[287] Fix | Delete
/**
[288] Fix | Delete
* Gets all shortcodes and their positions in the content
[289] Fix | Delete
*
[290] Fix | Delete
* This function returns all the shortcodes that could be found in the textarea content
[291] Fix | Delete
* along with their character positions and boundaries.
[292] Fix | Delete
*
[293] Fix | Delete
* This is used to check if the selection cursor is inside the boundaries of a shortcode
[294] Fix | Delete
* and move it accordingly, to avoid breakage.
[295] Fix | Delete
*
[296] Fix | Delete
* @link adjustTextAreaSelectionCursors
[297] Fix | Delete
*
[298] Fix | Delete
* The information can also be used in other cases when we need to lookup shortcode data,
[299] Fix | Delete
* as it's already structured!
[300] Fix | Delete
*
[301] Fix | Delete
* @param {string} content The content we want to scan for shortcodes
[302] Fix | Delete
*/
[303] Fix | Delete
function getShortCodePositionsInText( content ) {
[304] Fix | Delete
var allShortcodes = getShortcodesInText( content ), shortcodeInfo;
[305] Fix | Delete
[306] Fix | Delete
if ( allShortcodes.length === 0 ) {
[307] Fix | Delete
return [];
[308] Fix | Delete
}
[309] Fix | Delete
[310] Fix | Delete
var shortcodeDetailsRegexp = wp.shortcode.regexp( allShortcodes.join( '|' ) ),
[311] Fix | Delete
shortcodeMatch, // Define local scope for the variable to be used in the loop below.
[312] Fix | Delete
shortcodesDetails = [];
[313] Fix | Delete
[314] Fix | Delete
while ( shortcodeMatch = shortcodeDetailsRegexp.exec( content ) ) {
[315] Fix | Delete
/**
[316] Fix | Delete
* Check if the shortcode should be shown as plain text.
[317] Fix | Delete
*
[318] Fix | Delete
* This corresponds to the [[shortcode]] syntax, which doesn't parse the shortcode
[319] Fix | Delete
* and just shows it as text.
[320] Fix | Delete
*/
[321] Fix | Delete
var showAsPlainText = shortcodeMatch[1] === '[';
[322] Fix | Delete
[323] Fix | Delete
shortcodeInfo = {
[324] Fix | Delete
shortcodeName: shortcodeMatch[2],
[325] Fix | Delete
showAsPlainText: showAsPlainText,
[326] Fix | Delete
startIndex: shortcodeMatch.index,
[327] Fix | Delete
endIndex: shortcodeMatch.index + shortcodeMatch[0].length,
[328] Fix | Delete
length: shortcodeMatch[0].length
[329] Fix | Delete
};
[330] Fix | Delete
[331] Fix | Delete
shortcodesDetails.push( shortcodeInfo );
[332] Fix | Delete
}
[333] Fix | Delete
[334] Fix | Delete
/**
[335] Fix | Delete
* Get all URL matches, and treat them as embeds.
[336] Fix | Delete
*
[337] Fix | Delete
* Since there isn't a good way to detect if a URL by itself on a line is a previewable
[338] Fix | Delete
* object, it's best to treat all of them as such.
[339] Fix | Delete
*
[340] Fix | Delete
* This means that the selection will capture the whole URL, in a similar way shrotcodes
[341] Fix | Delete
* are treated.
[342] Fix | Delete
*/
[343] Fix | Delete
var urlRegexp = new RegExp(
[344] Fix | Delete
'(^|[\\n\\r][\\n\\r]|<p>)(https?:\\/\\/[^\s"]+?)(<\\/p>\s*|[\\n\\r][\\n\\r]|$)', 'gi'
[345] Fix | Delete
);
[346] Fix | Delete
[347] Fix | Delete
while ( shortcodeMatch = urlRegexp.exec( content ) ) {
[348] Fix | Delete
shortcodeInfo = {
[349] Fix | Delete
shortcodeName: 'url',
[350] Fix | Delete
showAsPlainText: false,
[351] Fix | Delete
startIndex: shortcodeMatch.index,
[352] Fix | Delete
endIndex: shortcodeMatch.index + shortcodeMatch[ 0 ].length,
[353] Fix | Delete
length: shortcodeMatch[ 0 ].length,
[354] Fix | Delete
urlAtStartOfContent: shortcodeMatch[ 1 ] === '',
[355] Fix | Delete
urlAtEndOfContent: shortcodeMatch[ 3 ] === ''
[356] Fix | Delete
};
[357] Fix | Delete
[358] Fix | Delete
shortcodesDetails.push( shortcodeInfo );
[359] Fix | Delete
}
[360] Fix | Delete
[361] Fix | Delete
return shortcodesDetails;
[362] Fix | Delete
}
[363] Fix | Delete
[364] Fix | Delete
/**
[365] Fix | Delete
* Generate a cursor marker element to be inserted in the content.
[366] Fix | Delete
*
[367] Fix | Delete
* `span` seems to be the least destructive element that can be used.
[368] Fix | Delete
*
[369] Fix | Delete
* Using DomQuery syntax to create it, since it's used as both text and as a DOM element.
[370] Fix | Delete
*
[371] Fix | Delete
* @param {Object} domLib DOM library instance.
[372] Fix | Delete
* @param {string} content The content to insert into the cursor marker element.
[373] Fix | Delete
*/
[374] Fix | Delete
function getCursorMarkerSpan( domLib, content ) {
[375] Fix | Delete
return domLib( '<span>' ).css( {
[376] Fix | Delete
display: 'inline-block',
[377] Fix | Delete
width: 0,
[378] Fix | Delete
overflow: 'hidden',
[379] Fix | Delete
'line-height': 0
[380] Fix | Delete
} )
[381] Fix | Delete
.html( content ? content : '' );
[382] Fix | Delete
}
[383] Fix | Delete
[384] Fix | Delete
/**
[385] Fix | Delete
* Gets adjusted selection cursor positions according to HTML tags, comments, and shortcodes.
[386] Fix | Delete
*
[387] Fix | Delete
* Shortcodes and HTML codes are a bit of a special case when selecting, since they may render
[388] Fix | Delete
* content in Visual mode. If we insert selection markers somewhere inside them, it's really possible
[389] Fix | Delete
* to break the syntax and render the HTML tag or shortcode broken.
[390] Fix | Delete
*
[391] Fix | Delete
* @link getShortcodeWrapperInfo
[392] Fix | Delete
*
[393] Fix | Delete
* @param {string} content Textarea content that the cursors are in
[394] Fix | Delete
* @param {{cursorStart: number, cursorEnd: number}} cursorPositions Cursor start and end positions
[395] Fix | Delete
*
[396] Fix | Delete
* @return {{cursorStart: number, cursorEnd: number}}
[397] Fix | Delete
*/
[398] Fix | Delete
function adjustTextAreaSelectionCursors( content, cursorPositions ) {
[399] Fix | Delete
var voidElements = [
[400] Fix | Delete
'area', 'base', 'br', 'col', 'embed', 'hr', 'img', 'input',
[401] Fix | Delete
'keygen', 'link', 'meta', 'param', 'source', 'track', 'wbr'
[402] Fix | Delete
];
[403] Fix | Delete
[404] Fix | Delete
var cursorStart = cursorPositions.cursorStart,
[405] Fix | Delete
cursorEnd = cursorPositions.cursorEnd,
[406] Fix | Delete
// Check if the cursor is in a tag and if so, adjust it.
[407] Fix | Delete
isCursorStartInTag = getContainingTagInfo( content, cursorStart );
[408] Fix | Delete
[409] Fix | Delete
if ( isCursorStartInTag ) {
[410] Fix | Delete
/**
[411] Fix | Delete
* Only move to the start of the HTML tag (to select the whole element) if the tag
[412] Fix | Delete
* is part of the voidElements list above.
[413] Fix | Delete
*
[414] Fix | Delete
* This list includes tags that are self-contained and don't need a closing tag, according to the
[415] Fix | Delete
* HTML5 specification.
[416] Fix | Delete
*
[417] Fix | Delete
* This is done in order to make selection of text a bit more consistent when selecting text in
[418] Fix | Delete
* `<p>` tags or such.
[419] Fix | Delete
*
[420] Fix | Delete
* In cases where the tag is not a void element, the cursor is put to the end of the tag,
[421] Fix | Delete
* so it's either between the opening and closing tag elements or after the closing tag.
[422] Fix | Delete
*/
[423] Fix | Delete
if ( voidElements.indexOf( isCursorStartInTag.tagType ) !== -1 ) {
[424] Fix | Delete
cursorStart = isCursorStartInTag.ltPos;
[425] Fix | Delete
} else {
[426] Fix | Delete
cursorStart = isCursorStartInTag.gtPos;
[427] Fix | Delete
}
[428] Fix | Delete
}
[429] Fix | Delete
[430] Fix | Delete
var isCursorEndInTag = getContainingTagInfo( content, cursorEnd );
[431] Fix | Delete
if ( isCursorEndInTag ) {
[432] Fix | Delete
cursorEnd = isCursorEndInTag.gtPos;
[433] Fix | Delete
}
[434] Fix | Delete
[435] Fix | Delete
var isCursorStartInShortcode = getShortcodeWrapperInfo( content, cursorStart );
[436] Fix | Delete
if ( isCursorStartInShortcode && ! isCursorStartInShortcode.showAsPlainText ) {
[437] Fix | Delete
/**
[438] Fix | Delete
* If a URL is at the start or the end of the content,
[439] Fix | Delete
* the selection doesn't work, because it inserts a marker in the text,
[440] Fix | Delete
* which breaks the embedURL detection.
[441] Fix | Delete
*
[442] Fix | Delete
* The best way to avoid that and not modify the user content is to
[443] Fix | Delete
* adjust the cursor to either after or before URL.
[444] Fix | Delete
*/
[445] Fix | Delete
if ( isCursorStartInShortcode.urlAtStartOfContent ) {
[446] Fix | Delete
cursorStart = isCursorStartInShortcode.endIndex;
[447] Fix | Delete
} else {
[448] Fix | Delete
cursorStart = isCursorStartInShortcode.startIndex;
[449] Fix | Delete
}
[450] Fix | Delete
}
[451] Fix | Delete
[452] Fix | Delete
var isCursorEndInShortcode = getShortcodeWrapperInfo( content, cursorEnd );
[453] Fix | Delete
if ( isCursorEndInShortcode && ! isCursorEndInShortcode.showAsPlainText ) {
[454] Fix | Delete
if ( isCursorEndInShortcode.urlAtEndOfContent ) {
[455] Fix | Delete
cursorEnd = isCursorEndInShortcode.startIndex;
[456] Fix | Delete
} else {
[457] Fix | Delete
cursorEnd = isCursorEndInShortcode.endIndex;
[458] Fix | Delete
}
[459] Fix | Delete
}
[460] Fix | Delete
[461] Fix | Delete
return {
[462] Fix | Delete
cursorStart: cursorStart,
[463] Fix | Delete
cursorEnd: cursorEnd
[464] Fix | Delete
};
[465] Fix | Delete
}
[466] Fix | Delete
[467] Fix | Delete
/**
[468] Fix | Delete
* Adds text selection markers in the editor textarea.
[469] Fix | Delete
*
[470] Fix | Delete
* Adds selection markers in the content of the editor `textarea`.
[471] Fix | Delete
* The method directly manipulates the `textarea` content, to allow TinyMCE plugins
[472] Fix | Delete
* to run after the markers are added.
[473] Fix | Delete
*
[474] Fix | Delete
* @param {Object} $textarea TinyMCE's textarea wrapped as a DomQuery object
[475] Fix | Delete
*/
[476] Fix | Delete
function addHTMLBookmarkInTextAreaContent( $textarea ) {
[477] Fix | Delete
if ( ! $textarea || ! $textarea.length ) {
[478] Fix | Delete
// If no valid $textarea object is provided, there's nothing we can do.
[479] Fix | Delete
return;
[480] Fix | Delete
}
[481] Fix | Delete
[482] Fix | Delete
var textArea = $textarea[0],
[483] Fix | Delete
textAreaContent = textArea.value,
[484] Fix | Delete
[485] Fix | Delete
adjustedCursorPositions = adjustTextAreaSelectionCursors( textAreaContent, {
[486] Fix | Delete
cursorStart: textArea.selectionStart,
[487] Fix | Delete
cursorEnd: textArea.selectionEnd
[488] Fix | Delete
} ),
[489] Fix | Delete
[490] Fix | Delete
htmlModeCursorStartPosition = adjustedCursorPositions.cursorStart,
[491] Fix | Delete
htmlModeCursorEndPosition = adjustedCursorPositions.cursorEnd,
[492] Fix | Delete
[493] Fix | Delete
mode = htmlModeCursorStartPosition !== htmlModeCursorEndPosition ? 'range' : 'single',
[494] Fix | Delete
[495] Fix | Delete
selectedText = null,
[496] Fix | Delete
cursorMarkerSkeleton = getCursorMarkerSpan( $$, '&#65279;' ).attr( 'data-mce-type','bookmark' );
[497] Fix | Delete
[498] Fix | Delete
if ( mode === 'range' ) {
[499] Fix | Delete
It is recommended that you Edit text format, this type of Fix handles quite a lot in one request
Function