|
|
@@ -5,7 +5,7 @@
|
|
|
|
|
|
'use strict';
|
|
|
|
|
|
-CKEDITOR.define( [ 'document/operation', 'ckeditorerror' ], function( Operation, CKEditorError ) {
|
|
|
+CKEDITOR.define( [ 'document/operation', 'ckeditorerror', 'utils' ], function( Operation, CKEditorError, utils ) {
|
|
|
/**
|
|
|
*
|
|
|
*
|
|
|
@@ -15,97 +15,103 @@ CKEDITOR.define( [ 'document/operation', 'ckeditorerror' ], function( Operation,
|
|
|
/**
|
|
|
*
|
|
|
*/
|
|
|
- constructor( range, oldAttr, newAttr, baseVersion ) {
|
|
|
+ constructor( ranges, oldAttr, newAttr, baseVersion ) {
|
|
|
super( baseVersion );
|
|
|
|
|
|
- this.range = range;
|
|
|
+ this.ranges = utils.isArray( ranges ) ? ranges : [ ranges ];
|
|
|
this.oldAttr = oldAttr;
|
|
|
this.newAttr = newAttr;
|
|
|
}
|
|
|
|
|
|
_execute() {
|
|
|
- var range = this.range;
|
|
|
+ var ranges = this.ranges;
|
|
|
var oldAttr = this.oldAttr;
|
|
|
var newAttr = this.newAttr;
|
|
|
|
|
|
- var value;
|
|
|
+ var value, range;
|
|
|
|
|
|
// Remove.
|
|
|
if ( newAttr === null ) {
|
|
|
- for ( value of range ) {
|
|
|
- if ( !value.node.hasAttr( oldAttr ) ) {
|
|
|
- /**
|
|
|
- * The attribute which should be removed does not exists.
|
|
|
- *
|
|
|
- * @error operation-change-no-attr-to-remove
|
|
|
- * @param {document.ChangeOperation} changeOperation
|
|
|
- * @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.',
|
|
|
- { changeOperation: this, node: value.node, attr: oldAttr } );
|
|
|
+ for ( range of ranges ) {
|
|
|
+ for ( value of range ) {
|
|
|
+ if ( !value.node.hasAttr( oldAttr ) ) {
|
|
|
+ /**
|
|
|
+ * The attribute which should be removed does not exists.
|
|
|
+ *
|
|
|
+ * @error operation-change-no-attr-to-remove
|
|
|
+ * @param {document.ChangeOperation} changeOperation
|
|
|
+ * @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.',
|
|
|
+ { changeOperation: this, node: value.node, attr: oldAttr } );
|
|
|
+ }
|
|
|
+
|
|
|
+ doRemove( value.node.attrs, oldAttr );
|
|
|
}
|
|
|
-
|
|
|
- doRemove( value.node.attrs, oldAttr );
|
|
|
}
|
|
|
}
|
|
|
// Insert.
|
|
|
else if ( oldAttr === null ) {
|
|
|
- for ( value of range ) {
|
|
|
- if ( value.node.hasAttr( newAttr.key ) ) {
|
|
|
- /**
|
|
|
- * The attribute with given key already exists.
|
|
|
- *
|
|
|
- * @error operation-change-attr-exists
|
|
|
- * @param {document.ChangeOperation} changeOperation
|
|
|
- * @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 } );
|
|
|
+ for ( range of ranges ) {
|
|
|
+ for ( value of range ) {
|
|
|
+ if ( value.node.hasAttr( newAttr.key ) ) {
|
|
|
+ /**
|
|
|
+ * The attribute with given key already exists.
|
|
|
+ *
|
|
|
+ * @error operation-change-attr-exists
|
|
|
+ * @param {document.ChangeOperation} changeOperation
|
|
|
+ * @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 } );
|
|
|
+ }
|
|
|
+
|
|
|
+ doInsert( value.node.attrs, newAttr );
|
|
|
}
|
|
|
-
|
|
|
- doInsert( value.node.attrs, newAttr );
|
|
|
}
|
|
|
}
|
|
|
// Change.
|
|
|
else {
|
|
|
- for ( value of range ) {
|
|
|
- if ( oldAttr.key != newAttr.key ) {
|
|
|
- /**
|
|
|
- * Old and new attributes should have the same keys.
|
|
|
- *
|
|
|
- * @error operation-change-different-keys
|
|
|
- * @param {document.ChangeOperation} changeOperation
|
|
|
- * @param {document.Node} node
|
|
|
- * @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, node: value.node, oldAttr: oldAttr, newAttr: newAttr } );
|
|
|
- }
|
|
|
-
|
|
|
- if ( !value.node.hasAttr( oldAttr ) ) {
|
|
|
- /**
|
|
|
- * The attribute which should be changed does not exists.
|
|
|
- *
|
|
|
- * @error operation-change-no-attr-to-change
|
|
|
- * @param {document.ChangeOperation} changeOperation
|
|
|
- * @param {document.Node} node
|
|
|
- * @param {document.Attribute} oldAttr
|
|
|
- * @param {document.Attribute} newAttr
|
|
|
- */
|
|
|
- throw new CKEditorError(
|
|
|
- 'operation-change-no-attr-to-change: The attribute which should be changed does not exists.',
|
|
|
- { changeOperation: this, node: value.node, oldAttr: oldAttr, newAttr: newAttr } );
|
|
|
+ for ( range of ranges ) {
|
|
|
+ for ( value of range ) {
|
|
|
+ if ( oldAttr.key != newAttr.key ) {
|
|
|
+ /**
|
|
|
+ * Old and new attributes should have the same keys.
|
|
|
+ *
|
|
|
+ * @error operation-change-different-keys
|
|
|
+ * @param {document.ChangeOperation} changeOperation
|
|
|
+ * @param {document.Node} node
|
|
|
+ * @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, node: value.node, oldAttr: oldAttr, newAttr: newAttr } );
|
|
|
+ }
|
|
|
+
|
|
|
+ if ( !value.node.hasAttr( oldAttr ) ) {
|
|
|
+ /**
|
|
|
+ * The attribute which should be changed does not exists.
|
|
|
+ *
|
|
|
+ * @error operation-change-no-attr-to-change
|
|
|
+ * @param {document.ChangeOperation} changeOperation
|
|
|
+ * @param {document.Node} node
|
|
|
+ * @param {document.Attribute} oldAttr
|
|
|
+ * @param {document.Attribute} newAttr
|
|
|
+ */
|
|
|
+ throw new CKEditorError(
|
|
|
+ 'operation-change-no-attr-to-change: The attribute which should be changed does not exists.',
|
|
|
+ { changeOperation: this, node: value.node, oldAttr: oldAttr, newAttr: newAttr } );
|
|
|
+ }
|
|
|
+
|
|
|
+ doRemove( value.node.attrs, oldAttr );
|
|
|
+
|
|
|
+ doInsert( value.node.attrs, newAttr );
|
|
|
}
|
|
|
-
|
|
|
- doRemove( value.node.attrs, oldAttr );
|
|
|
-
|
|
|
- doInsert( value.node.attrs, newAttr );
|
|
|
}
|
|
|
}
|
|
|
|
|
|
@@ -127,7 +133,7 @@ CKEDITOR.define( [ 'document/operation', 'ckeditorerror' ], function( Operation,
|
|
|
}
|
|
|
|
|
|
reverseOperation() {
|
|
|
- return new ChangeOperation( this.range, this.newAttr, this.oldAttr, this.baseVersion + 1 );
|
|
|
+ return new ChangeOperation( this.ranges, this.newAttr, this.oldAttr, this.baseVersion + 1 );
|
|
|
}
|
|
|
}
|
|
|
|