summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorNathan Dinsmore <nathan@users.noreply.github.com>2015-06-17 21:08:12 -0400
committerNathan Dinsmore <nathan@users.noreply.github.com>2015-06-17 21:08:12 -0400
commitf20ea6792688b97a8d9b50e9eed783e4773d9a86 (patch)
tree2ac462d89d14268d886a50d16221bc8aad884e56
parent6a82960cf77f9eac16c9a1ce13f360d80469799d (diff)
downloadsnap-f20ea6792688b97a8d9b50e9eed783e4773d9a86.tar.gz
snap-f20ea6792688b97a8d9b50e9eed783e4773d9a86.zip
Provide a fallback for browsers that don't support Map
-rw-r--r--morphic.js34
1 files changed, 34 insertions, 0 deletions
diff --git a/morphic.js b/morphic.js
index 5cc4062..fe2cc8b 100644
--- a/morphic.js
+++ b/morphic.js
@@ -3077,6 +3077,40 @@ Morph.prototype.updateReferences = function (map) {
}
};
+if (typeof Map === 'undefined') {
+ // use normal objects + stringification if Map doesn't exist
+
+ Morph.prototype.fullCopy = function () {
+ var dict = {}, c;
+ c = this.copyRecordingReferences(dict);
+ c.forAllChildren(function (m) {
+ m.updateReferences(dict);
+ });
+ return c;
+ };
+
+ Morph.prototype.copyRecordingReferences = function (dict) {
+ var c = this.copy();
+ dict[this] = c;
+ this.children.forEach(function (m) {
+ c.add(m.copyRecordingReferences(dict));
+ });
+ return c;
+ };
+
+ Morph.prototype.updateReferences = function (dict) {
+ var property, value, reference;
+ for (var properties = Object.keys(this), l = properties.length, i = 0; i < l; ++i) {
+ property = properties[i];
+ value = this[property];
+ if (value && value.isMorph) {
+ reference = dict[value];
+ if (reference) this[property] = reference;
+ }
+ }
+ };
+}
+
// Morph dragging and dropping:
Morph.prototype.rootForGrab = function () {