| 137 | | range = element.ownerDocument.createRange(); |
|---|
| 138 | | t.initializeRange(element, range); |
|---|
| 139 | | t.insert(element, range.createContextualFragment(content.stripScripts())); |
|---|
| | 137 | tagName = ((position == 'before' || position == 'after') |
|---|
| | 138 | ? element.parentNode : element).tagName.toUpperCase(); |
|---|
| | 139 | |
|---|
| | 140 | childNodes = Element._getContentFromAnonymousElement(tagName, content.stripScripts()); |
|---|
| | 141 | |
|---|
| | 142 | if (position == 'top' || position == 'after') childNodes.reverse(); |
|---|
| | 143 | childNodes.each(insert.curry(element)); |
|---|
| 665 | | |
|---|
| 666 | | |
|---|
| 667 | | if (!document.createRange || Prototype.Browser.Opera) { |
|---|
| 668 | | Element.Methods.insert = function(element, insertions) { |
|---|
| 669 | | element = $(element); |
|---|
| 670 | | |
|---|
| 671 | | if (Object.isString(insertions) || Object.isNumber(insertions) || |
|---|
| 672 | | Object.isElement(insertions) || (insertions && (insertions.toElement || insertions.toHTML))) |
|---|
| 673 | | insertions = { bottom: insertions }; |
|---|
| 674 | | |
|---|
| 675 | | var t = Element._insertionTranslations, content, position, pos, tagName; |
|---|
| 676 | | |
|---|
| 677 | | for (position in insertions) { |
|---|
| 678 | | content = insertions[position]; |
|---|
| 679 | | position = position.toLowerCase(); |
|---|
| 680 | | pos = t[position]; |
|---|
| 681 | | |
|---|
| 682 | | if (content && content.toElement) content = content.toElement(); |
|---|
| 683 | | if (Object.isElement(content)) { |
|---|
| 684 | | pos.insert(element, content); |
|---|
| 685 | | continue; |
|---|
| 686 | | } |
|---|
| 687 | | |
|---|
| 688 | | content = Object.toHTML(content); |
|---|
| 689 | | tagName = ((position == 'before' || position == 'after') |
|---|
| 690 | | ? element.parentNode : element).tagName.toUpperCase(); |
|---|
| 691 | | |
|---|
| 692 | | if (t.tags[tagName]) { |
|---|
| 693 | | var fragments = Element._getContentFromAnonymousElement(tagName, content.stripScripts()); |
|---|
| 694 | | if (position == 'top' || position == 'after') fragments.reverse(); |
|---|
| 695 | | fragments.each(pos.insert.curry(element)); |
|---|
| 696 | | } |
|---|
| 697 | | else element.insertAdjacentHTML(pos.adjacency, content.stripScripts()); |
|---|
| 698 | | |
|---|
| 699 | | content.evalScripts.bind(content).defer(); |
|---|
| 700 | | } |
|---|
| 701 | | |
|---|
| 702 | | return element; |
|---|
| 703 | | }; |
|---|
| 704 | | } |
|---|
| 1001 | | before: { |
|---|
| 1002 | | adjacency: 'beforeBegin', |
|---|
| 1003 | | insert: function(element, node) { |
|---|
| 1004 | | element.parentNode.insertBefore(node, element); |
|---|
| 1005 | | }, |
|---|
| 1006 | | initializeRange: function(element, range) { |
|---|
| 1007 | | range.setStartBefore(element); |
|---|
| 1008 | | } |
|---|
| 1009 | | }, |
|---|
| 1010 | | top: { |
|---|
| 1011 | | adjacency: 'afterBegin', |
|---|
| 1012 | | insert: function(element, node) { |
|---|
| 1013 | | element.insertBefore(node, element.firstChild); |
|---|
| 1014 | | }, |
|---|
| 1015 | | initializeRange: function(element, range) { |
|---|
| 1016 | | range.selectNodeContents(element); |
|---|
| 1017 | | range.collapse(true); |
|---|
| 1018 | | } |
|---|
| 1019 | | }, |
|---|
| 1020 | | bottom: { |
|---|
| 1021 | | adjacency: 'beforeEnd', |
|---|
| 1022 | | insert: function(element, node) { |
|---|
| 1023 | | element.appendChild(node); |
|---|
| 1024 | | } |
|---|
| 1025 | | }, |
|---|
| 1026 | | after: { |
|---|
| 1027 | | adjacency: 'afterEnd', |
|---|
| 1028 | | insert: function(element, node) { |
|---|
| 1029 | | element.parentNode.insertBefore(node, element.nextSibling); |
|---|
| 1030 | | }, |
|---|
| 1031 | | initializeRange: function(element, range) { |
|---|
| 1032 | | range.setStartAfter(element); |
|---|
| 1033 | | } |
|---|
| | 967 | before: function(element, node) { |
|---|
| | 968 | element.parentNode.insertBefore(node, element); |
|---|
| | 969 | }, |
|---|
| | 970 | top: function(element, node) { |
|---|
| | 971 | element.insertBefore(node, element.firstChild); |
|---|
| | 972 | }, |
|---|
| | 973 | bottom: function(element, node) { |
|---|
| | 974 | element.appendChild(node); |
|---|
| | 975 | }, |
|---|
| | 976 | after: function(element, node) { |
|---|
| | 977 | element.parentNode.insertBefore(node, element.nextSibling); |
|---|