TinyMCE:API/tinymce.dom.Selection
From Moxiecode Documentation Wiki
Contents |
[edit]
Class: tinymce.dom.Selection
This class handles text and control selection - it's a crossbrowser utility class. Consult the TinyMCE Wiki API for more details and examples on how to use this class.
[edit]
Constructor
- Selection
- Constructs a new selection instance.
[edit]
Events
- onBeforeGetContent
- Content extraction event.
- onBeforeSetContent
- Content insertion event.
- onGetContent
- Content extraction event.
- onSetContent
- Content insertion event.
[edit]
Methods
- collapse
- Collapse the selection to start or end of range.
- getBookmark
- Returns a bookmark location for the current selection.
- getContent
- Returns the selected contents using the DOM serializer passed in to this class.
- getEnd
- Returns the end element of a selection range.
- getNode
- Returns the currently selected element or the common ancestor element for both start and end of the selection.
- getRng
- Returns the browser's internal range object.
- getSel
- Returns the browser's internal selection object.
- getStart
- Returns the start element of a selection range.
- isCollapsed
- Returns true if the selection range is collapsed and false otherwise.
- moveToBookmark
- Restores the selection to the specified bookmark.
- select
- Selects the specified element.
- setContent
- Replaces the current selection with the specified content.
- setNode
- Sets the current selection to the specified DOM element.
- setRng
- Changes the selection to the specified DOM range.
[edit]
Example
(function() {
tinymce.create('tinymce.plugins.customtag', {
init : function(ed, url) {
ed.addCommand('CustomTag', function() {
var sel = ed.selection.getContent();
sel = '<customTag>' + sel + '</customTag>';
ed.selection.setContent(sel);
});
ed.addButton('customtag', {
title : 'wraps selected text with custom tag',
cmd : 'CustomTag',
image : url + '/img/button.png'
});
},
getInfo : function() {
return {
longname : 'wraps selected text with custom tag',
author : '',
authorurl : '',
infourl : '',
version : ''
};
}
});
tinymce.PluginManager.add('customtag', tinymce.plugins.customtag);
})();
