Advertisement
Guest User

nesting

a guest
Aug 12th, 2015
1,794
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1.     filter.update_queue_objects = function(updated_data)
  2.     {
  3.         if (updated_data instanceof Object)
  4.         {
  5.             // Make sure that the facets array actually exists in the new data
  6.             if (updated_data.facets instanceof Object)
  7.             {
  8.                 console.log('doing');
  9.                 console.log(updated_data.facets);
  10.                 console.log(filter.queue);
  11.                 // Iterate over each filter object in the queue
  12.                 for (var queue_index in filter.queue)
  13.                 {
  14.                     // If the filter object has a facet value
  15.                     if (filter.queue[queue_index] instanceof Object)
  16.                     {
  17.                         console.log('about to iterate activity values!');
  18.                         // Iterate over each activity value (inactive/active)
  19.                         for (var activity_value in updated_data.facets)
  20.                         {
  21.                             console.log('iterating activity values')
  22.                             // If the updated data object's facets object has an 'inactive' property
  23.                             if (updated_data.facets[activity_value] instanceof Object)
  24.                             {
  25.                                 console.log('it is an object!');
  26.                                 // Iterate over the updated data's inactive facets to find a facet that matches the facet for the current queued filter object
  27.                                 for (var inactive_facet_index in updated_data.facets[activity_value])
  28.                                 {
  29.                                     // If the current inactive facet is an Object and the title property is equivalent to the facet value of the current queued filter object
  30.                                     if ((updated_data.facets[activity_value][inactive_facet_index] instanceof Object) && (filter.queue[queue_index].facet === updated_data.facets[activity_value][inactive_facet_index].title))
  31.                                     {
  32.                                         var facet_buckets = updated_data.facets[activity_value][inactive_facet_index].buckets;
  33.  
  34.                                         // If the facet's buckets property is a valid array
  35.                                         if (facet_buckets instanceof Array)
  36.                                         {
  37.                                             // Iterate over each of the buckets
  38.                                             for (var facet_bucket_index in facet_buckets)
  39.                                             {
  40.                                                 // If the current bucket is a valid object and its value property matches the bucket value of the current queued filter object
  41.                                                 if ((facet_buckets[facet_bucket_index] instanceof Object) && (facet_buckets[facet_bucket_index].value === filter.queue[queue_index].bucket))
  42.                                                 {
  43.                                                     // Assign the updated href value to the queued filter object value
  44.                                                     filter.queue[queue_index].href = facet_buckets[facet_bucket_index].href;
  45.                                                    
  46.                                                     return true;
  47.                                                 }
  48.                                             }
  49.                                         }
  50.                                     }
  51.                                 }
  52.                             }
  53.                         }
  54.                     }
  55.                 }
  56.             }
  57.         }
  58.     }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement