Esanders has uploaded a new change for review.
https://gerrit.wikimedia.org/r/58235
Change subject: Change custom .getHash functions to .getHashObject
......................................................................
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
---
M modules/ve/dm/annotations/ve.dm.LinkAnnotation.js
M modules/ve/dm/ve.dm.Annotation.js
M modules/ve/ui/inspectors/ve.ui.LinkInspector.js
M modules/ve/ve.js
4 files changed, 12 insertions(+), 12 deletions(-)
git pull ssh://gerrit.wikimedia.org:29418/mediawiki/extensions/VisualEditor
refs/changes/35/58235/1
diff --git a/modules/ve/dm/annotations/ve.dm.LinkAnnotation.js
b/modules/ve/dm/annotations/ve.dm.LinkAnnotation.js
index 2e138f7..09ef5d2 100644
--- a/modules/ve/dm/annotations/ve.dm.LinkAnnotation.js
+++ b/modules/ve/dm/annotations/ve.dm.LinkAnnotation.js
@@ -67,7 +67,7 @@
};
/**
- * 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 @@
* 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 @@
obj.htmlAttributes = {};
obj.htmlAttributes.rel = this.htmlAttributes.rel;
}
- return ve.getHash( obj );
+ return obj;
};
/* Registration */
diff --git a/modules/ve/dm/ve.dm.Annotation.js
b/modules/ve/dm/ve.dm.Annotation.js
index 01696a6..4476bae 100644
--- a/modules/ve/dm/ve.dm.Annotation.js
+++ b/modules/ve/dm/ve.dm.Annotation.js
@@ -160,19 +160,19 @@
};
/**
- * 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;
};
\ No newline at end of file
diff --git a/modules/ve/ui/inspectors/ve.ui.LinkInspector.js
b/modules/ve/ui/inspectors/ve.ui.LinkInspector.js
index b45a359..e1d86cc 100644
--- a/modules/ve/ui/inspectors/ve.ui.LinkInspector.js
+++ b/modules/ve/ui/inspectors/ve.ui.LinkInspector.js
@@ -114,7 +114,7 @@
// 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 @@
if ( this.initialSelection.isCollapsed() ) {
insert = true;
}
- if ( annotation.getHash() !== this.initialAnnotationHash ) {
+ if ( ve.getHash( annotation ) !== this.initialAnnotationHash ) {
if ( this.isNewAnnotation ) {
undo = true;
} else {
diff --git a/modules/ve/ve.js b/modules/ve/ve.js
index 7b15132..651b374 100644
--- a/modules/ve/ve.js
+++ b/modules/ve/ve.js
@@ -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
--
To view, visit https://gerrit.wikimedia.org/r/58235
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings
Gerrit-MessageType: newchange
Gerrit-Change-Id: If11071d4b04a01e25102ffb57240882f650ee10d
Gerrit-PatchSet: 1
Gerrit-Project: mediawiki/extensions/VisualEditor
Gerrit-Branch: master
Gerrit-Owner: Esanders <[email protected]>
_______________________________________________
MediaWiki-commits mailing list
[email protected]
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits