[ Index ] |
PHP Cross Reference of WordPress Trunk (Updated Daily) |
[Source view] [Print] [Project Stats]
(no description)
File Size: | 1404 lines (45 kb) |
Included or required: | 0 times |
Referenced: | 0 times |
Includes or requires: | 0 files |
SwitchEditors() X-Ref |
Utility functions for the editor. |
init() X-Ref |
No description |
getToolbarHeight( editor ) X-Ref |
Returns the height of the editor toolbar(s) in px. param: {Object} editor The TinyMCE editor. return: {number} If the height is between 10 and 200 return the height, |
switchEditor( id, mode ) X-Ref |
Switches the editor between Visual and Text mode. 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`. return: {void} |
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.../>..`. param: {string} content The test content where the cursor is. param: {number} cursorPosition The cursor position inside the content. return: {(null|Object)} Null if cursor is not in a tag, Object if the cursor is inside a tag. |
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. param: {string} content The text content to check against. param: {number} cursorPosition The cursor position to check. return: {(undefined|Object)} Undefined if the cursor is not wrapped in a shortcode tag. |
getShortcodesInText( content ) X-Ref |
Gets a list of unique shortcodes or shortcode-lookalikes 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 cursor 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. param: {string} content Textarea content that the cursors are in param: {{cursorStart: number, cursorEnd: number}} cursorPositions Cursor start and end positions return: {{cursorStart: number, cursorEnd: number}} |
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 instance 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. param: {Object} editor The editor where we must find the selection. return: {(null|Object)} The selection range position in the editor. |
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. param: {string} html The content from the editor. return: {string} The content with stripped paragraph tags. |
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. param: {string} text The text input. return: {string} The formatted text. |
pre_wpautop( html ) X-Ref |
Fires custom jQuery events `beforePreWpautop` and `afterPreWpautop` when jQuery is available. param: {string} html The content from the visual editor. return: {string} the filtered content. |
wpautop( text ) X-Ref |
Fires custom jQuery events `beforeWpautop` and `afterWpautop` when jQuery is available. param: {string} text The content from the text editor. return: {string} filtered content. |
Generated : Thu Nov 21 08:20:01 2024 | Cross-referenced by PHPXref |