http://www.mediawiki.org/wiki/Special:Code/MediaWiki/94311
Revision: 94311
Author: tparscal
Date: 2011-08-12 00:25:15 +0000 (Fri, 12 Aug 2011)
Log Message:
-----------
Added rough sketch of operation and transaction classes
Modified Paths:
--------------
trunk/parsers/wikidom/lib/es/es.Content.js
Added Paths:
-----------
trunk/parsers/wikidom/lib/es/es.Content.Operation.js
trunk/parsers/wikidom/lib/es/es.Content.Transaction.js
Added: trunk/parsers/wikidom/lib/es/es.Content.Operation.js
===================================================================
--- trunk/parsers/wikidom/lib/es/es.Content.Operation.js
(rev 0)
+++ trunk/parsers/wikidom/lib/es/es.Content.Operation.js 2011-08-12
00:25:15 UTC (rev 94311)
@@ -0,0 +1,33 @@
+/**
+ * Creates an operation to be applied to a content object.
+ *
+ * @class
+ * @constructor
+ * @param type {String} Type of operation, e.g. insert, delete, annotate
+ * @param content {es.Content} Content being inserted or modified
+ * @param data {Object} Data of operation, e.g. range
+ * @property type {String} Type of operation
+ * @property content {es.Content} Content of operation
+ * @property data {Object} Data of operation
+ */
+es.Content.Operation = function( type, content, data ) {
+ this.type = type;
+ this.contents = contents;
+ this.data = data;
+};
+
+es.Content.Operation.prototype.getType = function() {
+ return this.type;
+};
+
+es.Content.Operation.prototype.getContent = function() {
+ return this.content;
+};
+
+es.Content.Operation.prototype.getLength = function() {
+ return this.content.getLength();;
+};
+
+es.Content.Operation.prototype.getData = function() {
+ return this.data;
+};
Property changes on: trunk/parsers/wikidom/lib/es/es.Content.Operation.js
___________________________________________________________________
Added: svn:mime-type
+ text/plain
Added: svn:eol-style
+ native
Added: trunk/parsers/wikidom/lib/es/es.Content.Transaction.js
===================================================================
--- trunk/parsers/wikidom/lib/es/es.Content.Transaction.js
(rev 0)
+++ trunk/parsers/wikidom/lib/es/es.Content.Transaction.js 2011-08-12
00:25:15 UTC (rev 94311)
@@ -0,0 +1,65 @@
+/**
+ * Creates an operation to be applied to a content object.
+ *
+ * @class
+ * @constructor
+ * @param operations {Array} List of operations
+ * @property operations {Array} List of operations
+ */
+es.Content.Transaction = function( operations ) {
+ this.operations = operations || [];
+};
+
+es.Content.Transaction.prototype.add = function( operation ) {
+ this.operations.push( operation );
+};
+
+es.Content.Transaction.prototype.commit = function( from ) {
+ var range = new es.Range(),
+ to = new es.Content();
+ for ( var i = 0; i < this.operations.length; i++ ) {
+ var operation = this.operations[i];
+ range.to = range.from + operation.getLength();
+ switch (operation.getType()) {
+ case 'retain':
+ to.insert( to.getLength(), from.getData( range
) );
+ range.from = range.to;
+ break;
+ case 'insert':
+ to.insert( to.getLength(),
operation.getContent() );
+ break;
+ case 'delete':
+ // TODO: Validate operation.getContent against
content being skipped
+ offset += operation.getLength();
+ break;
+ }
+ }
+ return to;
+};
+
+es.Content.Transaction.prototype.rollback = function( from ) {
+ var range = new es.Range(),
+ to = new es.Content();
+ for ( var i = 0; i < this.operations.length; i++ ) {
+ var operation = this.operations[i];
+ range.to = range.from + operation.getLength();
+ switch (operation.getType()) {
+ case 'retain':
+ to.insert( to.getLength(), from.getData( range
) );
+ range.from = range.to;
+ break;
+ case 'insert':
+ // TODO: Validate operation.getContent against
content being skipped
+ offset += operation.getLength();
+ break;
+ case 'delete':
+ to.insert( to.getLength(),
operation.getContent() );
+ break;
+ }
+ }
+ return to;
+};
+
+es.Content.Transaction.prototype.optimize = function() {
+ // reduce consecutive operations of the same type to single operations
if possible
+};
Property changes on: trunk/parsers/wikidom/lib/es/es.Content.Transaction.js
___________________________________________________________________
Added: svn:mime-type
+ text/plain
Added: svn:eol-style
+ native
Modified: trunk/parsers/wikidom/lib/es/es.Content.js
===================================================================
--- trunk/parsers/wikidom/lib/es/es.Content.js 2011-08-12 00:24:40 UTC (rev
94310)
+++ trunk/parsers/wikidom/lib/es/es.Content.js 2011-08-12 00:25:15 UTC (rev
94311)
@@ -375,6 +375,22 @@
};
/**
+ * Gets content data within a specific range.
+ *
+ * @method
+ * @param range {es.Range} Range of content to get
+ * @returns {Array} Array of plain text and annotated characters within range
+ */
+es.Content.prototype.getData = function( range ) {
+ if ( !range ) {
+ range = new es.Range( 0, this.data.length );
+ } else {
+ range.normalize();
+ }
+ return this.data.slice( range.start, range.end );
+};
+
+/**
* Inserts content data at a specific position.
*
* Inserted content will inherit annotations from neighboring content.
_______________________________________________
MediaWiki-CVS mailing list
[email protected]
https://lists.wikimedia.org/mailman/listinfo/mediawiki-cvs