|
|
@@ -7,7 +7,7 @@
|
|
|
|
|
|
CKEDITOR.define( [ 'document/operations/operation', 'ckeditorerror' ], function( Operation, CKEditorError ) {
|
|
|
/**
|
|
|
- * Operation to change nodes attribute. Using this class you can add, remove or change value of the attribute.
|
|
|
+ * Operation to change nodes' attribute. Using this class you can add, remove or change value of the attribute.
|
|
|
*
|
|
|
* @class document.operations.ChangeOperation
|
|
|
*/
|
|
|
@@ -15,19 +15,19 @@ CKEDITOR.define( [ 'document/operations/operation', 'ckeditorerror' ], function(
|
|
|
/**
|
|
|
* Creates a change operation.
|
|
|
*
|
|
|
- * If only new attribute is set it will be inserted. Note that there must be no attributes with the same key as
|
|
|
- * a new attribute in all nodes in ranges.
|
|
|
+ * If only the new attribute is set, then it will be inserted. Note that in all nodes in ranges there must be
|
|
|
+ * no attributes with the same key as the new attribute.
|
|
|
*
|
|
|
- * If only old attribute is set it will be removed. Note that this attribute must be present in all nodes in
|
|
|
+ * If only the old attribute is set, then it will be removed. Note that this attribute must be present in all nodes in
|
|
|
* ranges.
|
|
|
*
|
|
|
- * If both new and old attributes are set the operation will change the attribute value. Node that both new and
|
|
|
+ * If both new and old attributes are set, then the operation will change the attribute value. Note that both new and
|
|
|
* old attributes have to have the same key and the old attribute must be present in all nodes in ranges.
|
|
|
*
|
|
|
- * @param {document.Range} range Range on which operation should be applied.
|
|
|
- * @param {document.Attribute|null} oldAttr Attribute to be removed. Null if operation just inserts a new attribute.
|
|
|
- * @param {document.Attribute|null} newAttr Attribute to be added. Null if operation just removes an attribute.
|
|
|
- * @param {Number} baseVersion {@link document.Document#version} on which operation can be applied.
|
|
|
+ * @param {document.Range} range Range on which the operation should be applied.
|
|
|
+ * @param {document.Attribute|null} oldAttr Attribute to be removed. If `null`, then the operation just inserts a new attribute.
|
|
|
+ * @param {document.Attribute|null} newAttr Attribute to be added. If `null`, then the operation just removes the attribute.
|
|
|
+ * @param {Number} baseVersion {@link document.Document#version} on which the operation can be applied.
|
|
|
* @constructor
|
|
|
*/
|
|
|
constructor( range, oldAttr, newAttr, baseVersion ) {
|
|
|
@@ -42,7 +42,7 @@ CKEDITOR.define( [ 'document/operations/operation', 'ckeditorerror' ], function(
|
|
|
this.range = range;
|
|
|
|
|
|
/**
|
|
|
- * Old attribute to change. Null if operation inserts new attribute.
|
|
|
+ * Old attribute to change. Set to `null` if operation inserts a new attribute.
|
|
|
*
|
|
|
* @readonly
|
|
|
* @type {document.Attribute|null}
|
|
|
@@ -50,7 +50,7 @@ CKEDITOR.define( [ 'document/operations/operation', 'ckeditorerror' ], function(
|
|
|
this.oldAttr = oldAttr;
|
|
|
|
|
|
/**
|
|
|
- * New attribute. Null if operation removes attribute.
|
|
|
+ * New attribute. Set to `null` if operation removes the attribute.
|
|
|
*
|
|
|
* @readonly
|
|
|
* @type {document.Attribute|null}
|
|
|
@@ -58,9 +58,6 @@ CKEDITOR.define( [ 'document/operations/operation', 'ckeditorerror' ], function(
|
|
|
this.newAttr = newAttr;
|
|
|
}
|
|
|
|
|
|
- /**
|
|
|
- * See {@link document.operations.Operation#_execute}.
|
|
|
- */
|
|
|
_execute() {
|
|
|
var oldAttr = this.oldAttr;
|
|
|
var newAttr = this.newAttr;
|
|
|
@@ -71,13 +68,13 @@ CKEDITOR.define( [ 'document/operations/operation', 'ckeditorerror' ], function(
|
|
|
* Old and new attributes should have the same keys.
|
|
|
*
|
|
|
* @error operation-change-different-keys
|
|
|
- * @param {document.operations.ChangeOperation} changeOperation
|
|
|
+ * @param {document.operations.ChangeOperation} op
|
|
|
* @param {document.Attribute} oldAttr
|
|
|
* @param {document.Attribute} newAttr
|
|
|
*/
|
|
|
throw new CKEditorError(
|
|
|
'operation-change-different-keys: Old and new attributes should have the same keys.',
|
|
|
- { changeOperation: this, oldAttr: oldAttr, newAttr: newAttr } );
|
|
|
+ { op: this, oldAttr: oldAttr, newAttr: newAttr } );
|
|
|
}
|
|
|
|
|
|
// Remove or change.
|
|
|
@@ -85,20 +82,20 @@ CKEDITOR.define( [ 'document/operations/operation', 'ckeditorerror' ], function(
|
|
|
for ( value of this.range ) {
|
|
|
if ( !value.node.hasAttr( oldAttr ) ) {
|
|
|
/**
|
|
|
- * The attribute which should be removed does not exists for given node.
|
|
|
+ * The attribute which should be removed does not exists for the given node.
|
|
|
*
|
|
|
* @error operation-change-no-attr-to-remove
|
|
|
- * @param {document.operations.ChangeOperation} changeOperation
|
|
|
+ * @param {document.operations.ChangeOperation} op
|
|
|
* @param {document.Node} node
|
|
|
* @param {document.Attribute} attr
|
|
|
*/
|
|
|
throw new CKEditorError(
|
|
|
'operation-change-no-attr-to-remove: The attribute which should be removed does not exists for given node.',
|
|
|
- { changeOperation: this, node: value.node, attr: oldAttr } );
|
|
|
+ { op: this, node: value.node, attr: oldAttr } );
|
|
|
}
|
|
|
|
|
|
// There is no use in removing attribute if we will overwrite it later.
|
|
|
- // Still it is profitable to run throw the loop to check if all nodes in the range has old attribute.
|
|
|
+ // Still it is profitable to run through the loop to check if all nodes in the range has old attribute.
|
|
|
if ( newAttr === null ) {
|
|
|
value.node.removeAttr( oldAttr.key );
|
|
|
}
|
|
|
@@ -110,16 +107,16 @@ CKEDITOR.define( [ 'document/operations/operation', 'ckeditorerror' ], function(
|
|
|
for ( value of this.range ) {
|
|
|
if ( oldAttr === null && value.node.hasAttr( newAttr.key ) ) {
|
|
|
/**
|
|
|
- * The attribute with given key already exists for given node.
|
|
|
+ * The attribute with given key already exists for the given node.
|
|
|
*
|
|
|
* @error operation-change-attr-exists
|
|
|
- * @param {document.operations.ChangeOperation} changeOperation
|
|
|
+ * @param {document.operations.ChangeOperation} op
|
|
|
* @param {document.Node} node
|
|
|
* @param {document.Attribute} attr
|
|
|
*/
|
|
|
throw new CKEditorError(
|
|
|
'operation-change-attr-exists: The attribute with given key already exists.',
|
|
|
- { changeOperation: this, node: value.node, attr: newAttr } );
|
|
|
+ { op: this, node: value.node, attr: newAttr } );
|
|
|
}
|
|
|
|
|
|
value.node.setAttr( newAttr );
|
|
|
@@ -127,9 +124,6 @@ CKEDITOR.define( [ 'document/operations/operation', 'ckeditorerror' ], function(
|
|
|
}
|
|
|
}
|
|
|
|
|
|
- /**
|
|
|
- * See {@link document.operations.Operation#getReversed}.
|
|
|
- */
|
|
|
getReversed() {
|
|
|
return new ChangeOperation( this.range, this.newAttr, this.oldAttr, this.baseVersion + 1 );
|
|
|
}
|