]> git.ipfire.org Git - thirdparty/foundation/foundation-sites.git/commitdiff
Ensure all inserted searchTerms are unique 5741/head
authorDimitri Jorge <jorge.dimitri@gmail.com>
Thu, 4 Sep 2014 14:11:59 +0000 (16:11 +0200)
committerDimitri Jorge <jorge.dimitri@gmail.com>
Thu, 4 Sep 2014 14:11:59 +0000 (16:11 +0200)
doc/assets/js/docs.js

index 31d9edf2e398b239a4f318415d11365c749c6dfd..15dce1b58da107da208bdb97b30f5e36b184fdfc 100644 (file)
@@ -1,20 +1,29 @@
 var components = [];
+var unique_search_terms = {};
+
+function pushSearchTerm(searchTerm, data) {
+  if (!unique_search_terms[searchTerm]) {
+    components.push({
+      value: searchTerm,
+      data: data
+    });
+
+    unique_search_terms[searchTerm] = true
+  }
+}
+
 $("[data-search]")
   .each(function() {
     var self = $(this),
         searchTerm = self.text().trim(),
         otherSearchTerms = self.data("search").trim(),
         url = self.attr("href");
-    components.push({
-      value: searchTerm,
-      data: self.attr("href")
-    });
+
+    pushSearchTerm(searchTerm, self.attr("href"))
+
     if (otherSearchTerms !== "") {
       $.each(otherSearchTerms.split(","), function(idx, el) {
-        components.push({
-          value: el,
-          data: self.attr("href")
-        });
+        pushSearchTerm(el, self.attr("href"))
       });
     }
   });
@@ -84,4 +93,4 @@ if ($('[data-forum-posts]').length > 0) {
     dataType:'jsonp',
     success: cb
   });
-}
\ No newline at end of file
+}