Property changes on: trunk/extensions/VisualEditor/tests/es/es.TransactionProcessor.test.js |
___________________________________________________________________ |
Deleted: svn:eol-style |
1 | 1 | - native |
Index: trunk/extensions/VisualEditor/tests/es/index.html |
— | — | @@ -18,7 +18,6 @@ |
19 | 19 | <script src="../../modules/qunit/qunit.js"></script> |
20 | 20 | <script src="../../modules/es/es.js"></script> |
21 | 21 | <script src="../../modules/es/es.Range.js"></script> |
22 | | - <script src="../../modules/es/es.Transaction.js"></script> |
23 | 22 | <script src="../../modules/es/es.TransactionProcessor.js"></script> |
24 | 23 | |
25 | 24 | <!-- Bases --> |
— | — | @@ -38,6 +37,7 @@ |
39 | 38 | <script src="../../modules/es/models/es.TableCellModel.js"></script> |
40 | 39 | <script src="../../modules/es/models/es.TableModel.js"></script> |
41 | 40 | <script src="../../modules/es/models/es.TableRowModel.js"></script> |
| 41 | + <script src="../../modules/es/models/es.TransactionModel.js"></script> |
42 | 42 | |
43 | 43 | <!-- Tests --> |
44 | 44 | <script src="es.testData.js"></script> |
Index: trunk/extensions/VisualEditor/demo/index.html |
— | — | @@ -58,7 +58,6 @@ |
59 | 59 | <script src="../modules/es/es.Html.js"></script> |
60 | 60 | <script src="../modules/es/es.Position.js"></script> |
61 | 61 | <script src="../modules/es/es.Range.js"></script> |
62 | | - <script src="../modules/es/es.Transaction.js"></script> |
63 | 62 | <script src="../modules/es/es.TransactionProcessor.js"></script> |
64 | 63 | |
65 | 64 | <!-- Serializers --> |
— | — | @@ -90,6 +89,7 @@ |
91 | 90 | <script src="../modules/es/models/es.TableRowModel.js"></script> |
92 | 91 | <script src="../modules/es/models/es.TableCellModel.js"></script> |
93 | 92 | <script src="../modules/es/models/es.HeadingModel.js"></script> |
| 93 | + <script src="../modules/es/models/es.TransactionModel.js"></script> |
94 | 94 | |
95 | 95 | <!-- Views --> |
96 | 96 | <script src="../modules/es/views/es.SurfaceView.js"></script> |
Index: trunk/extensions/VisualEditor/modules/es/es.Transaction.js |
— | — | @@ -1,137 +0,0 @@ |
2 | | -/** |
3 | | - * Creates an es.Transaction object. |
4 | | - * |
5 | | - * @class |
6 | | - * @constructor |
7 | | - * @param {Object[]} operations List of operations |
8 | | - */ |
9 | | -es.Transaction = function( operations ) { |
10 | | - this.operations = es.isArray( operations ) ? operations : []; |
11 | | -}; |
12 | | - |
13 | | -/* Methods */ |
14 | | - |
15 | | -/** |
16 | | - * Gets a list of all operations. |
17 | | - * |
18 | | - * @method |
19 | | - * @returns {Object[]} List of operations |
20 | | - */ |
21 | | -es.Transaction.prototype.getOperations = function() { |
22 | | - return this.operations; |
23 | | -}; |
24 | | - |
25 | | -/** |
26 | | - * Merges consecutive operations of the same type. |
27 | | - * |
28 | | - * @method |
29 | | - */ |
30 | | -es.Transaction.prototype.optimize = function() { |
31 | | - for ( var i = 0; i < this.operations.length - 1; i++ ) { |
32 | | - var a = this.operations[i]; |
33 | | - var b = this.operations[i + 1]; |
34 | | - if ( a.type === b.type ) { |
35 | | - switch ( a.type ) { |
36 | | - case 'retain': |
37 | | - a.length += b.length; |
38 | | - this.operations.splice( i + 1, 1 ); |
39 | | - i--; |
40 | | - break; |
41 | | - case 'insert': |
42 | | - case 'remove': |
43 | | - a.data = a.data.concat( b.data ); |
44 | | - this.operations.splice( i + 1, 1 ); |
45 | | - i--; |
46 | | - break; |
47 | | - } |
48 | | - } |
49 | | - } |
50 | | -}; |
51 | | - |
52 | | -/** |
53 | | - * Adds a retain operation. |
54 | | - * |
55 | | - * @method |
56 | | - * @param {Integer} length Length of content data to retain |
57 | | - */ |
58 | | -es.Transaction.prototype.pushRetain = function( length ) { |
59 | | - this.operations.push( { |
60 | | - 'type': 'retain', |
61 | | - 'length': length |
62 | | - } ); |
63 | | -}; |
64 | | - |
65 | | -/** |
66 | | - * Adds an insertion operation. |
67 | | - * |
68 | | - * @method |
69 | | - * @param {Array} data Data to retain |
70 | | - */ |
71 | | -es.Transaction.prototype.pushInsert = function( data ) { |
72 | | - this.operations.push( { |
73 | | - 'type': 'insert', |
74 | | - 'data': data |
75 | | - } ); |
76 | | -}; |
77 | | - |
78 | | -/** |
79 | | - * Adds a removal operation. |
80 | | - * |
81 | | - * @method |
82 | | - * @param {Array} data Data to remove |
83 | | - */ |
84 | | -es.Transaction.prototype.pushRemove = function( data ) { |
85 | | - this.operations.push( { |
86 | | - 'type': 'remove', |
87 | | - 'data': data |
88 | | - } ); |
89 | | -}; |
90 | | - |
91 | | -/** |
92 | | - * Adds an element attribute change operation. |
93 | | - * |
94 | | - * @method |
95 | | - * @param {String} method Method to use, either "set" or "clear" |
96 | | - * @param {String} key Name of attribute to change |
97 | | - * @param {Mixed} value Value to set attribute to, or value of attribute being cleared |
98 | | - */ |
99 | | -es.Transaction.prototype.pushChangeElementAttribute = function( method, key, value ) { |
100 | | - this.operations.push( { |
101 | | - 'type': 'attribute', |
102 | | - 'method': method, |
103 | | - 'key': key, |
104 | | - 'value': value |
105 | | - } ); |
106 | | -}; |
107 | | - |
108 | | -/** |
109 | | - * Adds a start annotating operation. |
110 | | - * |
111 | | - * @method |
112 | | - * @param {String} method Method to use, either "set" or "clear" |
113 | | - * @param {Object} annotation Annotation object to start setting or clearing from content data |
114 | | - */ |
115 | | -es.Transaction.prototype.pushStartAnnotating = function( method, annotation ) { |
116 | | - this.operations.push( { |
117 | | - 'type': 'annotate', |
118 | | - 'method': method, |
119 | | - 'bias': 'start', |
120 | | - 'annotation': annotation |
121 | | - } ); |
122 | | -}; |
123 | | - |
124 | | -/** |
125 | | - * Adds a stop annotating operation. |
126 | | - * |
127 | | - * @method |
128 | | - * @param {String} method Method to use, either "set" or "clear" |
129 | | - * @param {Object} annotation Annotation object to stop setting or clearing from content data |
130 | | - */ |
131 | | -es.Transaction.prototype.pushStopAnnotating = function( method, annotation ) { |
132 | | - this.operations.push( { |
133 | | - 'type': 'annotate', |
134 | | - 'method': method, |
135 | | - 'bias': 'stop', |
136 | | - 'annotation': annotation |
137 | | - } ); |
138 | | -}; |
Index: trunk/extensions/VisualEditor/modules/es/models/es.DocumentModel.js |
— | — | @@ -665,7 +665,7 @@ |
666 | 666 | * @method |
667 | 667 | * @param {Integer} offset |
668 | 668 | * @param {Array} data |
669 | | - * @returns {es.Transaction} |
| 669 | + * @returns {es.TransactionModel} |
670 | 670 | */ |
671 | 671 | es.DocumentModel.prototype.prepareInsertion = function( offset, data ) { |
672 | 672 | /** |
— | — | @@ -719,7 +719,7 @@ |
720 | 720 | return workingData || data; |
721 | 721 | } |
722 | 722 | |
723 | | - var tx = new es.Transaction(), |
| 723 | + var tx = new es.TransactionModel(), |
724 | 724 | insertedData = data, // may be cloned and modified |
725 | 725 | isStructuralLoc, |
726 | 726 | wrappingElementType; |
— | — | @@ -823,7 +823,7 @@ |
824 | 824 | * |
825 | 825 | * @method |
826 | 826 | * @param {es.Range} range |
827 | | - * @returns {es.Transaction} |
| 827 | + * @returns {es.TransactionModel} |
828 | 828 | */ |
829 | 829 | |
830 | 830 | es.DocumentModel.prototype.prepareRemoval = function( range ) { |
— | — | @@ -857,7 +857,7 @@ |
858 | 858 | return true; |
859 | 859 | } |
860 | 860 | |
861 | | - var tx = new es.Transaction(), selectedNodes, selectedNode, startNode, endNode, i; |
| 861 | + var tx = new es.TransactionModel(), selectedNodes, selectedNode, startNode, endNode, i; |
862 | 862 | range.normalize(); |
863 | 863 | if ( range.start === range.end ) { |
864 | 864 | // Empty range, nothing to do |
— | — | @@ -920,10 +920,10 @@ |
921 | 921 | * Generates a transaction which annotates content within a given range. |
922 | 922 | * |
923 | 923 | * @method |
924 | | - * @returns {es.Transaction} |
| 924 | + * @returns {es.TransactionModel} |
925 | 925 | */ |
926 | 926 | es.DocumentModel.prototype.prepareContentAnnotation = function( range, method, annotation ) { |
927 | | - var tx = new es.Transaction(); |
| 927 | + var tx = new es.TransactionModel(); |
928 | 928 | range.normalize(); |
929 | 929 | if ( annotation.hash === undefined ) { |
930 | 930 | annotation.hash = es.DocumentModel.getAnnotationHash( annotation ); |
— | — | @@ -983,10 +983,10 @@ |
984 | 984 | * Generates a transaction which changes attributes on an element at a given offset. |
985 | 985 | * |
986 | 986 | * @method |
987 | | - * @returns {es.Transaction} |
| 987 | + * @returns {es.TransactionModel} |
988 | 988 | */ |
989 | 989 | es.DocumentModel.prototype.prepareElementAttributeChange = function( offset, method, key, value ) { |
990 | | - var tx = new es.Transaction(); |
| 990 | + var tx = new es.TransactionModel(); |
991 | 991 | if ( offset ) { |
992 | 992 | tx.pushRetain( offset ); |
993 | 993 | } |
— | — | @@ -1008,7 +1008,7 @@ |
1009 | 1009 | * Applies a transaction to the content data. |
1010 | 1010 | * |
1011 | 1011 | * @method |
1012 | | - * @param {es.Transaction} |
| 1012 | + * @param {es.TransactionModel} |
1013 | 1013 | */ |
1014 | 1014 | es.DocumentModel.prototype.commit = function( transaction ) { |
1015 | 1015 | es.TransactionProcessor.commit( this, transaction ); |
— | — | @@ -1018,7 +1018,7 @@ |
1019 | 1019 | * Reverses a transaction's effects on the content data. |
1020 | 1020 | * |
1021 | 1021 | * @method |
1022 | | - * @param {es.Transaction} |
| 1022 | + * @param {es.TransactionModel} |
1023 | 1023 | */ |
1024 | 1024 | es.DocumentModel.prototype.rollback = function( transaction ) { |
1025 | 1025 | es.TransactionProcessor.rollback( this, transaction ); |
Index: trunk/extensions/VisualEditor/modules/es/models/es.TransactionModel.js |
— | — | @@ -0,0 +1,150 @@ |
| 2 | +/** |
| 3 | + * Creates an es.TransactionModel object. |
| 4 | + * |
| 5 | + * @class |
| 6 | + * @constructor |
| 7 | + * @param {Object[]} operations List of operations |
| 8 | + */ |
| 9 | +es.TransactionModel = function( operations ) { |
| 10 | + this.operations = es.isArray( operations ) ? operations : []; |
| 11 | + this.lengthDiff = 0; |
| 12 | +}; |
| 13 | + |
| 14 | +/* Methods */ |
| 15 | + |
| 16 | +/** |
| 17 | + * Gets a list of all operations. |
| 18 | + * |
| 19 | + * @method |
| 20 | + * @returns {Object[]} List of operations |
| 21 | + */ |
| 22 | +es.TransactionModel.prototype.getOperations = function() { |
| 23 | + return this.operations; |
| 24 | +}; |
| 25 | + |
| 26 | +/** |
| 27 | + * Gets the difference in content length this transaction will cause if applied. |
| 28 | + * |
| 29 | + * @method |
| 30 | + * @returns {Integer} Difference in content length |
| 31 | + */ |
| 32 | +es.TransactionModel.prototype.getLengthDiff = function() { |
| 33 | + return this.lengthDiff; |
| 34 | +}; |
| 35 | + |
| 36 | +/** |
| 37 | + * Merges consecutive operations of the same type. |
| 38 | + * |
| 39 | + * @method |
| 40 | + */ |
| 41 | +es.TransactionModel.prototype.optimize = function() { |
| 42 | + for ( var i = 0; i < this.operations.length - 1; i++ ) { |
| 43 | + var a = this.operations[i]; |
| 44 | + var b = this.operations[i + 1]; |
| 45 | + if ( a.type === b.type ) { |
| 46 | + switch ( a.type ) { |
| 47 | + case 'retain': |
| 48 | + a.length += b.length; |
| 49 | + this.operations.splice( i + 1, 1 ); |
| 50 | + i--; |
| 51 | + break; |
| 52 | + case 'insert': |
| 53 | + case 'remove': |
| 54 | + a.data = a.data.concat( b.data ); |
| 55 | + this.operations.splice( i + 1, 1 ); |
| 56 | + i--; |
| 57 | + break; |
| 58 | + } |
| 59 | + } |
| 60 | + } |
| 61 | +}; |
| 62 | + |
| 63 | +/** |
| 64 | + * Adds a retain operation. |
| 65 | + * |
| 66 | + * @method |
| 67 | + * @param {Integer} length Length of content data to retain |
| 68 | + */ |
| 69 | +es.TransactionModel.prototype.pushRetain = function( length ) { |
| 70 | + this.operations.push( { |
| 71 | + 'type': 'retain', |
| 72 | + 'length': length |
| 73 | + } ); |
| 74 | +}; |
| 75 | + |
| 76 | +/** |
| 77 | + * Adds an insertion operation. |
| 78 | + * |
| 79 | + * @method |
| 80 | + * @param {Array} data Data to retain |
| 81 | + */ |
| 82 | +es.TransactionModel.prototype.pushInsert = function( data ) { |
| 83 | + this.operations.push( { |
| 84 | + 'type': 'insert', |
| 85 | + 'data': data |
| 86 | + } ); |
| 87 | + this.lengthDiff += data.length; |
| 88 | +}; |
| 89 | + |
| 90 | +/** |
| 91 | + * Adds a removal operation. |
| 92 | + * |
| 93 | + * @method |
| 94 | + * @param {Array} data Data to remove |
| 95 | + */ |
| 96 | +es.TransactionModel.prototype.pushRemove = function( data ) { |
| 97 | + this.operations.push( { |
| 98 | + 'type': 'remove', |
| 99 | + 'data': data |
| 100 | + } ); |
| 101 | + this.lengthDiff -= data.length; |
| 102 | +}; |
| 103 | + |
| 104 | +/** |
| 105 | + * Adds an element attribute change operation. |
| 106 | + * |
| 107 | + * @method |
| 108 | + * @param {String} method Method to use, either "set" or "clear" |
| 109 | + * @param {String} key Name of attribute to change |
| 110 | + * @param {Mixed} value Value to set attribute to, or value of attribute being cleared |
| 111 | + */ |
| 112 | +es.TransactionModel.prototype.pushChangeElementAttribute = function( method, key, value ) { |
| 113 | + this.operations.push( { |
| 114 | + 'type': 'attribute', |
| 115 | + 'method': method, |
| 116 | + 'key': key, |
| 117 | + 'value': value |
| 118 | + } ); |
| 119 | +}; |
| 120 | + |
| 121 | +/** |
| 122 | + * Adds a start annotating operation. |
| 123 | + * |
| 124 | + * @method |
| 125 | + * @param {String} method Method to use, either "set" or "clear" |
| 126 | + * @param {Object} annotation Annotation object to start setting or clearing from content data |
| 127 | + */ |
| 128 | +es.TransactionModel.prototype.pushStartAnnotating = function( method, annotation ) { |
| 129 | + this.operations.push( { |
| 130 | + 'type': 'annotate', |
| 131 | + 'method': method, |
| 132 | + 'bias': 'start', |
| 133 | + 'annotation': annotation |
| 134 | + } ); |
| 135 | +}; |
| 136 | + |
| 137 | +/** |
| 138 | + * Adds a stop annotating operation. |
| 139 | + * |
| 140 | + * @method |
| 141 | + * @param {String} method Method to use, either "set" or "clear" |
| 142 | + * @param {Object} annotation Annotation object to stop setting or clearing from content data |
| 143 | + */ |
| 144 | +es.TransactionModel.prototype.pushStopAnnotating = function( method, annotation ) { |
| 145 | + this.operations.push( { |
| 146 | + 'type': 'annotate', |
| 147 | + 'method': method, |
| 148 | + 'bias': 'stop', |
| 149 | + 'annotation': annotation |
| 150 | + } ); |
| 151 | +}; |
Property changes on: trunk/extensions/VisualEditor/modules/es/models/es.TransactionModel.js |
___________________________________________________________________ |
Added: svn:eol-style |
1 | 152 | + native |
Property changes on: trunk/extensions/VisualEditor/modules/es/es.TransactionProcessor.js |
___________________________________________________________________ |
Deleted: svn:eol-style |
2 | 153 | - native |