r111207 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r111206‎ | r111207 | r111208 >
Date:22:19, 10 February 2012
Author:inez
Status:deferred
Tags:
Comment:
Add new method: getDOMText
Modified paths:
  • /trunk/extensions/VisualEditor/demos/ce/index.php (modified) (history)
  • /trunk/extensions/VisualEditor/modules/ve/ce/ve.ce.js (modified) (history)
  • /trunk/extensions/VisualEditor/modules/ve/ce/ve.es.LeafNode.js (modified) (history)

Diff [purge]

Index: trunk/extensions/VisualEditor/demos/ce/index.php
@@ -118,6 +118,7 @@
119119 <script src="../../modules/ve/dm/serializers/ve.dm.WikitextSerializer.js"></script>
120120
121121 <!-- es -->
 122+ <script src="../../modules/ve/ce/ve.ce.js"></script>
122123 <script src="../../modules/ve/es/ve.es.js"></script>
123124 <script src="../../modules/ve/es/ve.es.Node.js"></script>
124125 <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 @@
3636 this.contentView.render();
3737 };
3838
 39+ve.es.LeafNode.prototype.getDOMText = function() {
 40+ return ve.ce.getDOMText( this.$[0] );
 41+};
 42+
3943 /* Inheritance */
4044
4145 ve.extendClass( ve.es.LeafNode, ve.LeafNode );
Index: trunk/extensions/VisualEditor/modules/ve/ce/ve.ce.js
@@ -6,3 +6,27 @@
77 ve.ce = {
88
99 };
 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

Status & tagging log