mirror of
https://gerrit.wikimedia.org/r/mediawiki/extensions/VisualEditor
synced 2024-11-12 09:09:25 +00:00
Change custom .getHash functions to .getHashObject
As described in the bug, ve.getHash performs JSON.stringify so to customise a hash the object should just return an object to be hashed, not the hash string itself. Bug: 46895 Change-Id: If11071d4b04a01e25102ffb57240882f650ee10d
This commit is contained in:
parent
60de496201
commit
277c4f6c28
|
@ -67,7 +67,7 @@ ve.dm.LinkAnnotation.prototype.toHTML = function () {
|
|||
};
|
||||
|
||||
/**
|
||||
* Get a hash of the link annotation.
|
||||
* Get the hash object of the link annotation.
|
||||
*
|
||||
* This extends the basic annotation hash by adding htmlAttributes.rel
|
||||
* if it present.
|
||||
|
@ -75,9 +75,9 @@ ve.dm.LinkAnnotation.prototype.toHTML = function () {
|
|||
* This is a custom hash function for ve#getHash.
|
||||
*
|
||||
* @method
|
||||
* @returns {string} Hash string
|
||||
* @returns {Object} Object to hash
|
||||
*/
|
||||
ve.dm.LinkAnnotation.prototype.getHash = function () {
|
||||
ve.dm.LinkAnnotation.prototype.getHashObject = function () {
|
||||
var keys = [ 'name', 'data' ], obj = {}, i;
|
||||
for ( i = 0; i < keys.length; i++ ) {
|
||||
if ( this[keys[i]] !== undefined ) {
|
||||
|
@ -88,7 +88,7 @@ ve.dm.LinkAnnotation.prototype.getHash = function () {
|
|||
obj.htmlAttributes = {};
|
||||
obj.htmlAttributes.rel = this.htmlAttributes.rel;
|
||||
}
|
||||
return ve.getHash( obj );
|
||||
return obj;
|
||||
};
|
||||
|
||||
/* Registration */
|
||||
|
|
|
@ -160,19 +160,19 @@ ve.dm.Annotation.prototype.renderHTML = function () {
|
|||
};
|
||||
|
||||
/**
|
||||
* Get a hash of the annotation.
|
||||
* Get the hash object of the annotation.
|
||||
*
|
||||
* This is a custom hash function for ve#getHash.
|
||||
*
|
||||
* @method
|
||||
* @returns {string} Hash string
|
||||
* @returns {Object} Object to hash
|
||||
*/
|
||||
ve.dm.Annotation.prototype.getHash = function () {
|
||||
ve.dm.Annotation.prototype.getHashObject = function () {
|
||||
var keys = [ 'name', 'data' ], obj = {}, i;
|
||||
for ( i = 0; i < keys.length; i++ ) {
|
||||
if ( this[keys[i]] !== undefined ) {
|
||||
obj[keys[i]] = this[keys[i]];
|
||||
}
|
||||
}
|
||||
return ve.getHash( obj );
|
||||
return obj;
|
||||
};
|
|
@ -114,7 +114,7 @@ ve.ui.LinkInspector.prototype.onOpen = function () {
|
|||
// Wait for animation to complete
|
||||
setTimeout( ve.bind( function () {
|
||||
// Setup annotation
|
||||
this.initialAnnotationHash = annotation && annotation.getHash();
|
||||
this.initialAnnotationHash = annotation && ve.getHash( annotation );
|
||||
this.targetInput.setAnnotation( annotation );
|
||||
this.targetInput.$input.focus().select();
|
||||
}, this ), 200 );
|
||||
|
@ -148,7 +148,7 @@ ve.ui.LinkInspector.prototype.onClose = function ( remove ) {
|
|||
if ( this.initialSelection.isCollapsed() ) {
|
||||
insert = true;
|
||||
}
|
||||
if ( annotation.getHash() !== this.initialAnnotationHash ) {
|
||||
if ( ve.getHash( annotation ) !== this.initialAnnotationHash ) {
|
||||
if ( this.isNewAnnotation ) {
|
||||
undo = true;
|
||||
} else {
|
||||
|
|
|
@ -317,9 +317,9 @@
|
|||
*/
|
||||
ve.getHash.keySortReplacer = function ( key, val ) {
|
||||
var normalized, keys, i, len;
|
||||
if ( val && typeof val.getHash === 'function' ) {
|
||||
if ( val && typeof val.getHashObject === 'function' ) {
|
||||
// This object has its own custom hash function, use it
|
||||
return val.getHash();
|
||||
return val.getHashObject();
|
||||
}
|
||||
if ( !ve.isArray( val ) && Object( val ) === val ) {
|
||||
// Only normalize objects when the key-order is ambiguous
|
||||
|
|
Loading…
Reference in a new issue