Commits

Kenneth Love  committed c2f6e6c

condensed updating keys to remove redundancy

  • Participants
  • Parent commits 5fefc6d

Comments (0)

Files changed (1)

File static/js/redbeard.js

+function update_keys(filter) {
+    var list = $("#keylist"),
+        search_location = '/search/';
+
+    if (filter) {
+        search_location += filter;
+    }
+
+    $(list).empty();
+
+    var jqxhr = $.getJSON(search_location)
+        .success(function(data) {
+            var items = [];
+            $.each(data['keys'], function(key, value) {
+                items.push('<li><a href="/key/' + value + '">' + value + '</a></li>');
+            });
+            $(list).html(items.join(''));
+        })
+        .error(function() {
+            $(list).html('<li>An error occurred. Make sure redis is running and reload the page.</li>');
+        });
+    $(window).hashchange();
+}
+
 function listFilter(header, list) {
     var form = $('<form>').attr({'class': 'filterform', 'action': '#'}),
         input = $('<input>').attr({
     $(input).change(function() {
         var filter = $(this).val();
         if (filter) {
-            $(list).empty();
-            var jqxhr = $.getJSON('/search/' + filter)
-                .success(function(data) {
-                    var items = [];
-                    $.each(data['keys'], function(key, value) {
-                        items.push('<li><a href="/key/' + value + '">' + value + '</a></li>');
-                    });
-                    $(list).html(items.join(''));
-                })
-                .error(function() {
-                    $(list).html('<li>An error occurred. Make sure redis is running and reload the page.</li>');
-                });
+            update_keys(filter);
         } else {
             update_keys();
         }
     });
 }
 
-function update_keys() {
-    list = $("#keylist");
-    $(list).empty();
-    var jqxhr = $.getJSON('/search/')
-        .success(function(data) {
-            var items = [];
-            $.each(data['keys'], function(key, value) {
-                items.push('<li><a href="/key/' + value + '">' + value + '</a></li>');
-            });
-            $(list).html(items.join(''));
-        })
-        .error(function() {
-            $(list).html('<li>An error occurred. Make sure redis is running and reload the page.</li>');
-        });
-    $(window).hashchange();
-}
-
 $(window).hashchange(function() {
     var hash = location.hash.replace('#', '');
     if (hash != '') {