Skip to content
This repository has been archived by the owner on Apr 8, 2020. It is now read-only.

Commit

Permalink
Merge pull request #18 from zcourts/master
Browse files Browse the repository at this point in the history
add support for complicated papers that can result in circular references
  • Loading branch information
AliasIO committed Sep 21, 2013
2 parents 14992d7 + 2e90059 commit 7d50f2a
Showing 1 changed file with 15 additions and 1 deletion.
16 changes: 15 additions & 1 deletion raphael.json.js
Expand Up @@ -24,7 +24,21 @@
});
}

return JSON.stringify(elements);
var cache = [];
var o = JSON.stringify(elements, function (key, value) {
//http://stackoverflow.com/a/11616993/400048
if (typeof value === 'object' && value !== null) {
if (cache.indexOf(value) !== -1) {
// Circular reference found, discard key
return;
}
// Store value in our collection
cache.push(value);
}
return value;
});
cache = null;
return o;
}

Raphael.fn.fromJSON = function(json, callback) {
Expand Down

0 comments on commit 7d50f2a

Please sign in to comment.