- /**\r
- * This method will split the current block parent and insert the contents inside the split position.\r
- * This logic can be improved so text nodes at the start/end remain in the start/end block elements\r
- */\r
- _insertBlockContent : function(ed, dom, content) {\r
- var parentBlock, marker, sel = ed.selection, last, elm, vp, y, elmHeight, markerId = 'mce_marker';\r
-\r
- function select(n) {\r
- var r;\r
-\r
- if (tinymce.isIE) {\r
- r = ed.getDoc().body.createTextRange();\r
- r.moveToElementText(n);\r
- r.collapse(false);\r
- r.select();\r
- } else {\r
- sel.select(n, 1);\r
- sel.collapse(false);\r
- }\r
- }\r
-\r
- // Insert a marker for the caret position\r
- this._insert('<span id="' + markerId + '"> </span>', 1);\r
- marker = dom.get(markerId);\r
- parentBlock = dom.getParent(marker, 'p,h1,h2,h3,h4,h5,h6,ul,ol,th,td');\r
-\r
- // If it's a parent block but not a table cell\r
- if (parentBlock && !/TD|TH/.test(parentBlock.nodeName)) {\r
- // Split parent block\r
- marker = dom.split(parentBlock, marker);\r
-\r
- // Insert nodes before the marker\r
- each(dom.create('div', 0, content).childNodes, function(n) {\r
- last = marker.parentNode.insertBefore(n.cloneNode(true), marker);\r
- });\r
-\r
- // Move caret after marker\r
- select(last);\r
- } else {\r
- dom.setOuterHTML(marker, content);\r
- sel.select(ed.getBody(), 1);\r
- sel.collapse(0);\r
- }\r
-\r
- // Remove marker if it's left\r
- while (elm = dom.get(markerId))\r
- dom.remove(elm);\r
-\r
- // Get element, position and height\r
- elm = sel.getStart();\r
- vp = dom.getViewPort(ed.getWin());\r
- y = ed.dom.getPos(elm).y;\r
- elmHeight = elm.clientHeight;\r
-\r
- // Is element within viewport if not then scroll it into view\r
- if (y < vp.y || y + elmHeight > vp.y + vp.h)\r
- ed.getDoc().body.scrollTop = y < vp.y ? y : y - vp.h + 25;\r
- },\r
-\r