OLD | NEW |
1 // Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file |
2 // for details. All rights reserved. Use of this source code is governed by a | 2 // for details. All rights reserved. Use of this source code is governed by a |
3 // BSD-style license that can be found in the LICENSE file. | 3 // BSD-style license that can be found in the LICENSE file. |
4 | 4 |
5 part of $LIBRARYNAME; | 5 part of $LIBRARYNAME; |
6 | 6 |
7 class _ChildrenElementList extends ListBase<Element> | 7 class _ChildrenElementList extends ListBase<Element> |
8 implements NodeListWrapper { | 8 implements NodeListWrapper { |
9 // Raw Element. | 9 // Raw Element. |
10 final Element _element; | 10 final Element _element; |
(...skipping 709 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
720 * Adds the specified text after the last child of this element. | 720 * Adds the specified text after the last child of this element. |
721 */ | 721 */ |
722 void appendText(String text) { | 722 void appendText(String text) { |
723 this.append(new Text(text)); | 723 this.append(new Text(text)); |
724 } | 724 } |
725 | 725 |
726 /** | 726 /** |
727 * Parses the specified text as HTML and adds the resulting node after the | 727 * Parses the specified text as HTML and adds the resulting node after the |
728 * last child of this element. | 728 * last child of this element. |
729 */ | 729 */ |
730 void appendHtml(String text) { | 730 void appendHtml(String text, {NodeValidator validator, |
731 this.insertAdjacentHtml('beforeend', text); | 731 NodeTreeSanitizer treeSanitizer}) { |
| 732 this.insertAdjacentHtml('beforeend', text, validator: validator, |
| 733 treeSanitizer: treeSanitizer); |
732 } | 734 } |
733 | 735 |
734 /** | 736 /** |
735 * Checks to see if the tag name is supported by the current platform. | 737 * Checks to see if the tag name is supported by the current platform. |
736 * | 738 * |
737 * The tag should be a valid HTML tag name. | 739 * The tag should be a valid HTML tag name. |
738 */ | 740 */ |
739 static bool isTagSupported(String tag) { | 741 static bool isTagSupported(String tag) { |
740 var e = _ElementFactoryProvider.createElement_tag(tag, null); | 742 var e = _ElementFactoryProvider.createElement_tag(tag, null); |
741 return e is Element && !(e is UnknownElement); | 743 return e is Element && !(e is UnknownElement); |
(...skipping 235 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
977 void insertAdjacentText(String where, String text) { | 979 void insertAdjacentText(String where, String text) { |
978 if (JS('bool', '!!#.insertAdjacentText', this)) { | 980 if (JS('bool', '!!#.insertAdjacentText', this)) { |
979 _insertAdjacentText(where, text); | 981 _insertAdjacentText(where, text); |
980 } else { | 982 } else { |
981 _insertAdjacentNode(where, new Text(text)); | 983 _insertAdjacentNode(where, new Text(text)); |
982 } | 984 } |
983 } | 985 } |
984 | 986 |
985 @JSName('insertAdjacentText') | 987 @JSName('insertAdjacentText') |
986 void _insertAdjacentText(String where, String text) native; | 988 void _insertAdjacentText(String where, String text) native; |
| 989 |
| 990 $else |
| 991 $endif |
987 | 992 |
988 /** | 993 /** |
989 * Parses text as an HTML fragment and inserts it into the DOM at the | 994 * Parses text as an HTML fragment and inserts it into the DOM at the |
990 * specified location. | 995 * specified location. |
991 * | 996 * |
992 * The [where] parameter indicates where to insert the HTML fragment: | 997 * The [where] parameter indicates where to insert the HTML fragment: |
993 * | 998 * |
994 * * 'beforeBegin': Immediately before this element. | 999 * * 'beforeBegin': Immediately before this element. |
995 * * 'afterBegin': As the first child of this element. | 1000 * * 'afterBegin': As the first child of this element. |
996 * * 'beforeEnd': As the last child of this element. | 1001 * * 'beforeEnd': As the last child of this element. |
997 * * 'afterEnd': Immediately after this element. | 1002 * * 'afterEnd': Immediately after this element. |
998 * | 1003 * |
999 * var html = '<div class="something">content</div>'; | 1004 * var html = '<div class="something">content</div>'; |
1000 * // Inserts as the first child | 1005 * // Inserts as the first child |
1001 * document.body.insertAdjacentHtml('afterBegin', html); | 1006 * document.body.insertAdjacentHtml('afterBegin', html); |
1002 * var createdElement = document.body.children[0]; | 1007 * var createdElement = document.body.children[0]; |
1003 * print(createdElement.classes[0]); // Prints 'something' | 1008 * print(createdElement.classes[0]); // Prints 'something' |
1004 * | 1009 * |
1005 * See also: | 1010 * See also: |
1006 * | 1011 * |
1007 * * [insertAdjacentText] | 1012 * * [insertAdjacentText] |
1008 * * [insertAdjacentElement] | 1013 * * [insertAdjacentElement] |
1009 */ | 1014 */ |
1010 void insertAdjacentHtml(String where, String html) { | 1015 void insertAdjacentHtml(String where, String html, {NodeValidator validator, |
1011 if (JS('bool', '!!#.insertAdjacentHTML', this)) { | 1016 NodeTreeSanitizer treeSanitizer}) { |
1012 _insertAdjacentHtml(where, html); | 1017 _insertAdjacentNode(where, new DocumentFragment.html(html, |
1013 } else { | 1018 validator: validator, treeSanitizer: treeSanitizer)); |
1014 _insertAdjacentNode(where, new DocumentFragment.html(html)); | |
1015 } | |
1016 } | 1019 } |
1017 | 1020 |
| 1021 $if DART2JS |
| 1022 |
1018 @JSName('insertAdjacentHTML') | 1023 @JSName('insertAdjacentHTML') |
1019 void _insertAdjacentHtml(String where, String text) native; | 1024 void _insertAdjacentHtml(String where, String text) native; |
1020 | 1025 |
1021 /** | 1026 /** |
1022 * Inserts [element] into the DOM at the specified location. | 1027 * Inserts [element] into the DOM at the specified location. |
1023 * | 1028 * |
1024 * To see the possible values for [where], read the doc for | 1029 * To see the possible values for [where], read the doc for |
1025 * [insertAdjacentHtml]. | 1030 * [insertAdjacentHtml]. |
1026 * | 1031 * |
1027 * See also: | 1032 * See also: |
(...skipping 24 matching lines...) Expand all Loading... |
1052 case 'beforeend': | 1057 case 'beforeend': |
1053 this.append(node); | 1058 this.append(node); |
1054 break; | 1059 break; |
1055 case 'afterend': | 1060 case 'afterend': |
1056 this.parentNode.insertBefore(node, this.nextNode); | 1061 this.parentNode.insertBefore(node, this.nextNode); |
1057 break; | 1062 break; |
1058 default: | 1063 default: |
1059 throw new ArgumentError("Invalid position ${where}"); | 1064 throw new ArgumentError("Invalid position ${where}"); |
1060 } | 1065 } |
1061 } | 1066 } |
| 1067 $else |
| 1068 void _insertAdjacentNode(String where, Node node) { |
| 1069 insertAdjacentElement(where, node); |
| 1070 } |
| 1071 $endif |
1062 | 1072 |
| 1073 $if DART2JS |
1063 /** | 1074 /** |
1064 * Checks if this element matches the CSS selectors. | 1075 * Checks if this element matches the CSS selectors. |
1065 */ | 1076 */ |
1066 @Experimental() | 1077 @Experimental() |
1067 bool matches(String selectors) { | 1078 bool matches(String selectors) { |
1068 if (JS('bool', '!!#.matches', this)) { | 1079 if (JS('bool', '!!#.matches', this)) { |
1069 return JS('bool', '#.matches(#)', this, selectors); | 1080 return JS('bool', '#.matches(#)', this, selectors); |
1070 } else if (JS('bool', '!!#.webkitMatchesSelector', this)) { | 1081 } else if (JS('bool', '!!#.webkitMatchesSelector', this)) { |
1071 return JS('bool', '#.webkitMatchesSelector(#)', this, selectors); | 1082 return JS('bool', '#.webkitMatchesSelector(#)', this, selectors); |
1072 } else if (JS('bool', '!!#.mozMatchesSelector', this)) { | 1083 } else if (JS('bool', '!!#.mozMatchesSelector', this)) { |
(...skipping 493 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1566 const ScrollAlignment._internal(this._value); | 1577 const ScrollAlignment._internal(this._value); |
1567 toString() => 'ScrollAlignment.$_value'; | 1578 toString() => 'ScrollAlignment.$_value'; |
1568 | 1579 |
1569 /// Attempt to align the element to the top of the scrollable area. | 1580 /// Attempt to align the element to the top of the scrollable area. |
1570 static const TOP = const ScrollAlignment._internal('TOP'); | 1581 static const TOP = const ScrollAlignment._internal('TOP'); |
1571 /// Attempt to center the element in the scrollable area. | 1582 /// Attempt to center the element in the scrollable area. |
1572 static const CENTER = const ScrollAlignment._internal('CENTER'); | 1583 static const CENTER = const ScrollAlignment._internal('CENTER'); |
1573 /// Attempt to align the element to the bottom of the scrollable area. | 1584 /// Attempt to align the element to the bottom of the scrollable area. |
1574 static const BOTTOM = const ScrollAlignment._internal('BOTTOM'); | 1585 static const BOTTOM = const ScrollAlignment._internal('BOTTOM'); |
1575 } | 1586 } |
OLD | NEW |