[ Index ]

PHP Cross Reference of WordPress

title

Body

[close]

/wp-admin/js/ -> editor.js (summary)

(no description)

File Size: 1414 lines (45 kb)
Included or required:0 times
Referenced: 0 times
Includes or requires: 0 files

Defines 21 functions

  SwitchEditors()
  init()
  getToolbarHeight()
  switchEditor()
  getContainingTagInfo()
  getShortcodeWrapperInfo()
  getShortcodesInText()
  getShortCodePositionsInText()
  getCursorMarkerSpan()
  adjustTextAreaSelectionCursors()
  addHTMLBookmarkInTextAreaContent()
  focusHTMLBookmarkInVisualEditor()
  removeSelectionMarker()
  scrollVisualModeToStartElement()
  fixTextAreaContent()
  findBookmarkedPosition()
  selectTextInTextArea()
  removep()
  autop()
  pre_wpautop()
  wpautop()

Functions
Functions that are not part of a class:

SwitchEditors()   X-Ref
Utility functions for the editor.

since: 2.5.0

init()   X-Ref
No description

getToolbarHeight( editor )   X-Ref
Returns the height of the editor toolbar(s) in px.

returns: {number} If the height is between 10 and 200 return the height,
since: 3.9.0
param: {Object} editor The TinyMCE editor.

switchEditor( id, mode )   X-Ref
Switches the editor between Visual and Text mode.

returns: {void}
since: 2.5.0
param: {string} id The id of the editor you want to change the editor mode for. Default: `content`.
param: {string} mode The mode you want to switch to. Default: `toggle`.

getContainingTagInfo( content, cursorPosition )   X-Ref
Checks if a cursor is inside an HTML tag or comment.

In order to prevent breaking HTML tags when selecting text, the cursor
must be moved to either the start or end of the tag.

This will prevent the selection marker to be inserted in the middle of an HTML tag.

This function gives information whether the cursor is inside a tag or not, as well as
the tag type, if it is a closing tag and check if the HTML tag is inside a shortcode tag,
e.g. `[caption]<img.../>..`.

returns: {(null|Object)} Null if cursor is not in a tag, Object if the cursor is inside a tag.
param: {string} content The test content where the cursor is.
param: {number} cursorPosition The cursor position inside the content.

getShortcodeWrapperInfo( content, cursorPosition )   X-Ref
Checks if the cursor is inside a shortcode

If the cursor is inside a shortcode wrapping tag, e.g. `[caption]` it's better to
move the selection marker to before or after the shortcode.

For example `[caption]` rewrites/removes anything that's between the `[caption]` tag and the
`<img/>` tag inside.

`[caption]<span>ThisIsGone</span><img .../>[caption]`

Moving the selection to before or after the short code is better, since it allows to select
something, instead of just losing focus and going to the start of the content.

return: {(undefined|Object)} Undefined if the cursor is not wrapped in a shortcode tag.
param: {string} content The text content to check against.
param: {number} cursorPosition    The cursor position to check.

getShortcodesInText( content )   X-Ref
Gets a list of unique shortcodes or shortcode-look-alikes in the content.

param: {string} content The content we want to scan for shortcodes.

getShortCodePositionsInText( content )   X-Ref
Gets all shortcodes and their positions in the content

This function returns all the shortcodes that could be found in the textarea content
along with their character positions and boundaries.

This is used to check if the selection cursor is inside the boundaries of a shortcode
and move it accordingly, to avoid breakage.

param: {string} content The content we want to scan for shortcodes

getCursorMarkerSpan( domLib, content )   X-Ref
Generate a cursor marker element to be inserted in the content.

`span` seems to be the least destructive element that can be used.

Using DomQuery syntax to create it, since it's used as both text and as a DOM element.

param: {Object} domLib DOM library instance.
param: {string} content The content to insert into the cusror marker element.

adjustTextAreaSelectionCursors( content, cursorPositions )   X-Ref
Gets adjusted selection cursor positions according to HTML tags, comments, and shortcodes.

Shortcodes and HTML codes are a bit of a special case when selecting, since they may render
content in Visual mode. If we insert selection markers somewhere inside them, it's really possible
to break the syntax and render the HTML tag or shortcode broken.

return: {{cursorStart: number, cursorEnd: number}}
param: {string} content Textarea content that the cursors are in
param: {{cursorStart: number, cursorEnd: number}} cursorPositions Cursor start and end positions

addHTMLBookmarkInTextAreaContent( $textarea )   X-Ref
Adds text selection markers in the editor textarea.

Adds selection markers in the content of the editor `textarea`.
The method directly manipulates the `textarea` content, to allow TinyMCE plugins
to run after the markers are added.

param: {object} $textarea TinyMCE's textarea wrapped as a DomQuery object

focusHTMLBookmarkInVisualEditor( editor )   X-Ref
Focuses the selection markers in Visual mode.

The method checks for existing selection markers inside the editor DOM (Visual mode)
and create a selection between the two nodes using the DOM `createRange` selection API

If there is only a single node, select only the single node through TinyMCE's selection API

param: {Object} editor TinyMCE editor instance.

removeSelectionMarker( $marker )   X-Ref
Removes selection marker and the parent node if it is an empty paragraph.

By default TinyMCE wraps loose inline tags in a `<p>`.
When removing selection markers an empty `<p>` may be left behind, remove it.

param: {object} $marker The marker to be removed from the editor DOM, wrapped in an instnce of `editor.$`

scrollVisualModeToStartElement( editor, element )   X-Ref
Scrolls the content to place the selected element in the center of the screen.

Takes an element, that is usually the selection start element, selected in
`focusHTMLBookmarkInVisualEditor()` and scrolls the screen so the element appears roughly
in the middle of the screen.

I order to achieve the proper positioning, the editor media bar and toolbar are subtracted
from the window height, to get the proper viewport window, that the user sees.

param: {Object} editor TinyMCE editor instance.
param: {Object} element HTMLElement that should be scrolled into view.

fixTextAreaContent( event )   X-Ref
This method was extracted from the `SaveContent` hook in
`wp-includes/js/tinymce/plugins/wordpress/plugin.js`.

It's needed here, since the method changes the content a bit, which confuses the cursor position.

param: {Object} event TinyMCE event object.

findBookmarkedPosition( editor )   X-Ref
Finds the current selection position in the Visual editor.

Find the current selection in the Visual editor by inserting marker elements at the start
and end of the selection.

Uses the standard DOM selection API to achieve that goal.

Check the notes in the comments in the code below for more information on some gotchas
and why this solution was chosen.

returns: {(null|Object)} The selection range position in the editor
param: {Object} editor The editor where we must find the selection

selectTextInTextArea( editor, selection )   X-Ref
Selects text in the TinyMCE `textarea`.

Selects the text in TinyMCE's textarea that's between `selection.start` and `selection.end`.

For `selection` parameter:
param: {Object} editor TinyMCE's editor instance.
param: {Object} selection Selection data.

removep( html )   X-Ref
Replaces <p> tags with two line breaks. "Opposite" of wpautop().

Replaces <p> tags with two line breaks except where the <p> has attributes.
Unifies whitespace.
Indents <li>, <dt> and <dd> for better readability.

return: {string} The content with stripped paragraph tags.
since: 2.5.0
param: {string} html The content from the editor.

autop( text )   X-Ref
Replaces two line breaks with a paragraph tag and one line break with a <br>.

Similar to `wpautop()` in formatting.php.

returns: {string} The formatted text.
since: 2.5.0
param: {string} text The text input.

pre_wpautop( html )   X-Ref
Fires custom jQuery events `beforePreWpautop` and `afterPreWpautop` when jQuery is available.

returns: {String} the filtered content.
since: 2.9.0
param: {String} html The content from the visual editor.

wpautop( text )   X-Ref
Fires custom jQuery events `beforeWpautop` and `afterWpautop` when jQuery is available.

returns: {String} filtered content.
since: 2.9.0
param: {String} text The content from the text editor.



Generated: Mon Sep 16 01:00:03 2019 Cross-referenced by PHPXref 0.7.1