filters: remove_filter function fixed in manifold.js
authorLoic Baron <loic.baron@lip6.fr>
Thu, 24 Jul 2014 13:42:18 +0000 (15:42 +0200)
committerLoic Baron <loic.baron@lip6.fr>
Thu, 24 Jul 2014 13:42:18 +0000 (15:42 +0200)
manifoldapi/static/js/manifold.js

index d96deed..e0454a5 100644 (file)
@@ -17,6 +17,32 @@ function debug_query (msg, query) {
     else messages.debug ("debug_query: " + msg + " query= " + query);
 }
 
+// http://stackoverflow.com/questions/7837456/comparing-two-arrays-in-javascript
+// attach the .equals method to Array's prototype to call it on any array
+Array.prototype.equals = function (array) {
+    // if the other array is a falsy value, return
+    if (!array)
+        return false;
+
+    // compare lengths - can save a lot of time 
+    if (this.length != array.length)
+        return false;
+
+    for (var i = 0, l=this.length; i < l; i++) {
+        // Check if we have nested arrays
+        if (this[i] instanceof Array && array[i] instanceof Array) {
+            // recurse into the nested arrays
+            if (!this[i].equals(array[i]))
+                return false;
+        }
+        else if (this[i] != array[i]) {
+            // Warning - two different object instances will never be equal: {x:20} != {x:20}
+            return false;
+        }
+    }
+    return true;
+}
+
 // http://javascriptweblog.wordpress.com/2011/08/08/fixing-the-javascript-typeof-operator/
 Object.toType = (function toType(global) {
   return function(obj) {
@@ -462,7 +488,7 @@ function QueryStore() {
     {
         var query_ext = this.find_analyzed_query_ext(query_uuid);
         query_ext.filters = $.grep(query_ext.filters, function(x) {
-            return x != filter;
+            return !(x.equals(filter));
         });
 
         this.apply_filters(query_uuid);