js/tinymce/tinymce.jquery.js
function moveToCaretPosition(root) {
          var walker, node, rng, lastNode = root, tempElm;

          if (!root) {
            return;
          }

          // Old IE versions doesn't properly render blocks with br elements in them
          // For example <p><br></p> wont be rendered correctly in a contentEditable area
          // until you remove the br producing <p></p>
          if (Env.ie && Env.ie < 9 && parentBlock && parentBlock.firstChild) {
            if (parentBlock.firstChild == parentBlock.lastChild && parentBlock.firstChild.tagName == 'BR') {
              dom.remove(parentBlock.firstChild);
            }
          }

          if (/^(LI|DT|DD)$/.test(root.nodeName)) {
            var firstChild = firstNonWhiteSpaceNodeSibling(root.firstChild);

            if (firstChild && /^(UL|OL|DL)$/.test(firstChild.nodeName)) {
              root.insertBefore(dom.doc.createTextNode('\u00a0'), root.firstChild);
            }
          }

          rng = dom.createRng();

          // Normalize whitespace to remove empty text nodes. Fix for: #6904
          // Gecko will be able to place the caret in empty text nodes but it won't render propery
          // Older IE versions will sometimes crash so for now ignore all IE versions
          if (!Env.ie) {
            root.normalize();
          }

          if (root.hasChildNodes()) {
            walker = new TreeWalker(root, root);

            while ((node = walker.current())) {
              if (node.nodeType == 3) {
                rng.setStart(node, 0);
                rng.setEnd(node, 0);
                break;
              }

              if (moveCaretBeforeOnEnterElementsMap[node.nodeName.toLowerCase()]) {
                rng.setStartBefore(node);
                rng.setEndBefore(node);
                break;
              }

              lastNode = node;
              node = walker.next();
            }

            if (!node) {
              rng.setStart(lastNode, 0);
              rng.setEnd(lastNode, 0);
            }
          } else {
            if (root.nodeName == 'BR') {
              if (root.nextSibling && dom.isBlock(root.nextSibling)) {
                // Trick on older IE versions to render the caret before the BR between two lists
                if (!documentMode || documentMode < 9) {
                  tempElm = dom.create('br');
                  root.parentNode.insertBefore(tempElm, root);
                }

                rng.setStartBefore(root);
                rng.setEndBefore(root);
              } else {
                rng.setStartAfter(root);
                rng.setEndAfter(root);
              }
            } else {
              rng.setStart(root, 0);
              rng.setEnd(root, 0);
            }
          }

          selection.setRng(rng);

          // Remove tempElm created for old IE:s
          dom.remove(tempElm);
          selection.scrollIntoView(root);
        }
function moveToCaretPosition(root) {
          var walker, node, rng, lastNode = root, tempElm;

          if (!root) {
            return;
          }

          // Old IE versions doesn't properly render blocks with br elements in them
          // For example <p><br></p> wont be rendered correctly in a contentEditable area
          // until you remove the br producing <p></p>
          if (Env.ie && Env.ie < 9 && parentBlock && parentBlock.firstChild) {
            if (parentBlock.firstChild == parentBlock.lastChild && parentBlock.firstChild.tagName == 'BR') {
              dom.remove(parentBlock.firstChild);
            }
          }

          if (/^(LI|DT|DD)$/.test(root.nodeName)) {
            var firstChild = firstNonWhiteSpaceNodeSibling(root.firstChild);

            if (firstChild && /^(UL|OL|DL)$/.test(firstChild.nodeName)) {
              root.insertBefore(dom.doc.createTextNode('\u00a0'), root.firstChild);
            }
          }

          rng = dom.createRng();

          // Normalize whitespace to remove empty text nodes. Fix for: #6904
          // Gecko will be able to place the caret in empty text nodes but it won't render propery
          // Older IE versions will sometimes crash so for now ignore all IE versions
          if (!Env.ie) {
            root.normalize();
          }

          if (root.hasChildNodes()) {
            walker = new TreeWalker(root, root);

            while ((node = walker.current())) {
              if (node.nodeType == 3) {
                rng.setStart(node, 0);
                rng.setEnd(node, 0);
                break;
              }

              if (moveCaretBeforeOnEnterElementsMap[node.nodeName.toLowerCase()]) {
                rng.setStartBefore(node);
                rng.setEndBefore(node);
                break;
              }

              lastNode = node;
              node = walker.next();
            }

            if (!node) {
              rng.setStart(lastNode, 0);
              rng.setEnd(lastNode, 0);
            }
          } else {
            if (root.nodeName == 'BR') {
              if (root.nextSibling && dom.isBlock(root.nextSibling)) {
                // Trick on older IE versions to render the caret before the BR between two lists
                if (!documentMode || documentMode < 9) {
                  tempElm = dom.create('br');
                  root.parentNode.insertBefore(tempElm, root);
                }

                rng.setStartBefore(root);
                rng.setEndBefore(root);
              } else {
                rng.setStartAfter(root);
                rng.setEndAfter(root);
              }
            } else {
              rng.setStart(root, 0);
              rng.setEnd(root, 0);
            }
          }

          selection.setRng(rng);

          // Remove tempElm created for old IE:s
          dom.remove(tempElm);
          selection.scrollIntoView(root);
        }
function moveToCaretPosition ( root ) { var walker , node , rng , lastNode = root , tempElm ; if ( ! root ) { return ; } // Old IE versions doesn't properly render blocks with br elements in them // For example <p><br></p> wont be rendered correctly in a contentEditable area // until you remove the br producing <p></p> if ( Env . ie && Env . ie < 9 && parentBlock && parentBlock . firstChild ) { if ( parentBlock . firstChild == parentBlock . lastChild && parentBlock . firstChild . tagName == 'BR' ) { dom . remove ( parentBlock . firstChild ) ; } } if ( / ^(LI|DT|DD)$ / . test ( root . nodeName ) ) { var firstChild = firstNonWhiteSpaceNodeSibling ( root . firstChild ) ; if ( firstChild && / ^(UL|OL|DL)$ / . test ( firstChild . nodeName ) ) { root . insertBefore ( dom . doc . createTextNode ( '\u00a0' ) , root . firstChild ) ; } } rng = dom . createRng ( ) ; // Normalize whitespace to remove empty text nodes. Fix for: #6904 // Gecko will be able to place the caret in empty text nodes but it won't render propery // Older IE versions will sometimes crash so for now ignore all IE versions if ( ! Env . ie ) { root . normalize ( ) ; } if ( root . hasChildNodes ( ) ) { walker = new TreeWalker ( root , root ) ; while ( ( node = walker . current ( ) ) ) { if ( node . nodeType == 3 ) { rng . setStart ( node , 0 ) ; rng . setEnd ( node , 0 ) ; break ; } if ( moveCaretBeforeOnEnterElementsMap [ node . nodeName . toLowerCase ( ) ] ) { rng . setStartBefore ( node ) ; rng . setEndBefore ( node ) ; break ; } lastNode = node ; node = walker . next ( ) ; } if ( ! node ) { rng . setStart ( lastNode , 0 ) ; rng . setEnd ( lastNode , 0 ) ; } } else { if ( root . nodeName == 'BR' ) { if ( root . nextSibling && dom . isBlock ( root . nextSibling ) ) { // Trick on older IE versions to render the caret before the BR between two lists if ( ! documentMode || documentMode < 9 ) { tempElm = dom . create ( 'br' ) ; root . parentNode . insertBefore ( tempElm , root ) ; } rng . setStartBefore ( root ) ; rng . setEndBefore ( root ) ; } else { rng . setStartAfter ( root ) ; rng . setEndAfter ( root ) ; } } else { rng . setStart ( root , 0 ) ; rng . setEnd ( root , 0 ) ; } } selection . setRng ( rng ) ; // Remove tempElm created for old IE:s dom . remove ( tempElm ) ; selection . scrollIntoView ( root ) ; }
Moves the caret to a suitable position within the root for example in the first non pure whitespace text node or before an image
Moves the caret to a suitable position within the root for example in the first non pure whitespace text node or before an image