selection.js revision 9002d9b85f99bb503c702f12a20f829f732d22f8
2beebed98b4fc7f018fb224a1e4a3ab6103a4c0bCraig McDonnell * Wraps some common Selection/Range functionality into a simple object
2beebed98b4fc7f018fb224a1e4a3ab6103a4c0bCraig McDonnell * @module editor
2beebed98b4fc7f018fb224a1e4a3ab6103a4c0bCraig McDonnell * @submodule selection
2beebed98b4fc7f018fb224a1e4a3ab6103a4c0bCraig McDonnell * Wraps some common Selection/Range functionality into a simple object
2beebed98b4fc7f018fb224a1e4a3ab6103a4c0bCraig McDonnell * @class Selection
2beebed98b4fc7f018fb224a1e4a3ab6103a4c0bCraig McDonnell * @for Selection
2beebed98b4fc7f018fb224a1e4a3ab6103a4c0bCraig McDonnell * @constructor
2beebed98b4fc7f018fb224a1e4a3ab6103a4c0bCraig McDonnell //TODO This shouldn't be there, Y.Node doesn't normalize getting textnode content.
415243fbc81341293a852ff6aa14e9608d08685cCraig McDonnell Y.Selection = function() {
2beebed98b4fc7f018fb224a1e4a3ab6103a4c0bCraig McDonnell this.isCollapsed = (sel.compareEndPoints('StartToEnd', sel)) ? false : true;
2beebed98b4fc7f018fb224a1e4a3ab6103a4c0bCraig McDonnell this.anchorNode = this.focusNode = Y.one(sel.parentElement());
2beebed98b4fc7f018fb224a1e4a3ab6103a4c0bCraig McDonnell this.anchorNode = this.focusNode = Y.Selection.resolve(ieNode);
415243fbc81341293a852ff6aa14e9608d08685cCraig McDonnell this.anchorOffset = this.focusOffset = (this.anchorNode.nodeValue) ? this.anchorNode.nodeValue.length : 0 ;
2beebed98b4fc7f018fb224a1e4a3ab6103a4c0bCraig McDonnell this.anchorTextNode = this.focusTextNode = Y.one(ieNode);
415243fbc81341293a852ff6aa14e9608d08685cCraig McDonnell //var self = this;
415243fbc81341293a852ff6aa14e9608d08685cCraig McDonnell this.anchorNode = Y.Selection.resolve(sel.anchorNode);
415243fbc81341293a852ff6aa14e9608d08685cCraig McDonnell this.focusNode = Y.Selection.resolve(sel.focusNode);
2beebed98b4fc7f018fb224a1e4a3ab6103a4c0bCraig McDonnell this.anchorTextNode = Y.one(sel.anchorNode);
91f0e3cb60de3eba8cbb70c7e36cc0df22d71f5bRobert Wapshott * Performs a prefilter on all nodes in the editor. Looks for nodes with a style: fontFamily or font face
415243fbc81341293a852ff6aa14e9608d08685cCraig McDonnell * It then creates a dynamic class assigns it and removed the property. This is so that we don't lose
91f0e3cb60de3eba8cbb70c7e36cc0df22d71f5bRobert Wapshott * the fontFamily when selecting nodes.
91f0e3cb60de3eba8cbb70c7e36cc0df22d71f5bRobert Wapshott * @method filter
ls;
v.remove();
if (blocks) {
* Method attempts to replace all "orphined" text nodes in the main body by wrapping them with a <p>. Called from filter.
if (childs) {
doit = true;
doit = false;
if (doit) {
if (!wrapped) {
wrapped = [];
} catch (er) {}
if (wrapped) {
n.remove();
return html;
n = n.parentNode;
return Y.one(n);
text: null,
isCollapsed: null,
anchorNode: null,
anchorOffset: null,
anchorTextNode: null,
focusNode: null,
focusOffset: null,
focusTextNode: null,
_selection: null,
getSelected: function() {
items = [];
* Insert HTML at the current cursor position and return a Node instance of the newly inserted element.
* Insert HTML at the current cursor position, this method gives you control over the text node to insert into and the offset where to put it.
var cur = Y.Node.create('<' + Y.Selection.DEFAULT_TAG + ' class="yui-non"></' + Y.Selection.DEFAULT_TAG + '>'),
node = b;
if (inHTML) {
return newNode;
return newNode;
* Get all elements inside a selection and wrap them with a new element and return a NodeList of all elements touched.
if (!this.isCollapsed) {
return changed;
return Y.all([]);
return newNode;
remove: function() {
createRange: function() {
if (collapse) {
if (collapse) {
setCursor: function() {
getCursor: function() {
* @param {Boolean} keep Setting this to true will keep the node, but remove the unique parts that make it the cursor.
if (cur) {
if (keep) {
return cur;
if (collapse !== false) {
collapse = true;
if (end !== false) {
end = true;
if (cur) {
toString: function() {