Index: trunk/extensions/VisualEditor/demos/ce/index.php |
— | — | @@ -118,6 +118,7 @@ |
119 | 119 | <script src="../../modules/ve/dm/serializers/ve.dm.WikitextSerializer.js"></script> |
120 | 120 | |
121 | 121 | <!-- es --> |
| 122 | + <script src="../../modules/ve/ce/ve.ce.js"></script> |
122 | 123 | <script src="../../modules/ve/es/ve.es.js"></script> |
123 | 124 | <script src="../../modules/ve/es/ve.es.Node.js"></script> |
124 | 125 | <script src="../../modules/ve/es/ve.es.BranchNode.js"></script> |
Index: trunk/extensions/VisualEditor/modules/ve/ce/ve.es.LeafNode.js |
— | — | @@ -35,6 +35,10 @@ |
36 | 36 | this.contentView.render(); |
37 | 37 | }; |
38 | 38 | |
| 39 | +ve.es.LeafNode.prototype.getDOMText = function() { |
| 40 | + return ve.ce.getDOMText( this.$[0] ); |
| 41 | +}; |
| 42 | + |
39 | 43 | /* Inheritance */ |
40 | 44 | |
41 | 45 | ve.extendClass( ve.es.LeafNode, ve.LeafNode ); |
Index: trunk/extensions/VisualEditor/modules/ve/ce/ve.ce.js |
— | — | @@ -6,3 +6,27 @@ |
7 | 7 | ve.ce = { |
8 | 8 | |
9 | 9 | }; |
| 10 | + |
| 11 | +ve.ce.getDOMText = function( elem ) { |
| 12 | + var nodeType = elem.nodeType, |
| 13 | + ret = ''; |
| 14 | + |
| 15 | + if ( nodeType === 1 || nodeType === 9 ) { |
| 16 | + // Use textContent || innerText for elements |
| 17 | + if ( typeof elem.textContent === 'string' ) { |
| 18 | + return elem.textContent; |
| 19 | + } else if ( typeof elem.innerText === 'string' ) { |
| 20 | + // Replace IE's carriage returns |
| 21 | + return elem.innerText.replace( /\r\n/g, '' ); |
| 22 | + } else { |
| 23 | + // Traverse it's children |
| 24 | + for ( elem = elem.firstChild; elem; elem = elem.nextSibling) { |
| 25 | + ret += ve.ce.getDOMText( elem ); |
| 26 | + } |
| 27 | + } |
| 28 | + } else if ( nodeType === 3 || nodeType === 4 ) { |
| 29 | + return elem.nodeValue; |
| 30 | + } |
| 31 | + |
| 32 | + return ret; |
| 33 | +}; |
\ No newline at end of file |