You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@couchdb.apache.org by cm...@apache.org on 2009/01/21 20:40:19 UTC

svn commit: r736387 - in /couchdb/trunk/share/www: script/futon.browse.js script/jquery.suggest.js style/layout.css

Author: cmlenz
Date: Wed Jan 21 11:40:19 2009
New Revision: 736387

URL: http://svn.apache.org/viewvc?rev=736387&view=rev
Log:
Add caching to the Futon autocompletion feature, and fix the positioning code.

Modified:
    couchdb/trunk/share/www/script/futon.browse.js
    couchdb/trunk/share/www/script/jquery.suggest.js
    couchdb/trunk/share/www/style/layout.css

Modified: couchdb/trunk/share/www/script/futon.browse.js
URL: http://svn.apache.org/viewvc/couchdb/trunk/share/www/script/futon.browse.js?rev=736387&r1=736386&r2=736387&view=diff
==============================================================================
--- couchdb/trunk/share/www/script/futon.browse.js [utf-8] (original)
+++ couchdb/trunk/share/www/script/futon.browse.js [utf-8] Wed Jan 21 11:40:19 2009
@@ -335,7 +335,7 @@
                   var matches = [];
                   for (var i = 0; i < docs.rows.length; i++) {
                     var docName = docs.rows[i].id.substr(8);
-                    if (docName.substr(0, text.length) == text) {
+                    if (docName.indexOf(text) == 0) {
                       matches[i] = docName;
                     }
                   }
@@ -350,7 +350,7 @@
                   var matches = [];
                   if (!doc.views) return;
                   for (var viewName in doc.views) {
-                    if (viewName.substr(0, text.length) == text) {
+                    if (viewName.indexOf(text) == 0) {
                       matches.push(viewName);
                     }
                   }

Modified: couchdb/trunk/share/www/script/jquery.suggest.js
URL: http://svn.apache.org/viewvc/couchdb/trunk/share/www/script/jquery.suggest.js?rev=736387&r1=736386&r2=736387&view=diff
==============================================================================
--- couchdb/trunk/share/www/script/jquery.suggest.js [utf-8] (original)
+++ couchdb/trunk/share/www/script/jquery.suggest.js [utf-8] Wed Jan 21 11:40:19 2009
@@ -15,13 +15,15 @@
   suggest = function(elem, options) {
     var timer = null;
     var prevVal = null;
+    var cache = {};
+    var cacheKeys = [];
 
     var input = $(elem).attr("autocomplete", "off");
-    var offset = input.offset();
-    var dropdown = $('<ul style="z-index: 10000"></ul>')
-      .addClass(options.dropdownClass).appendTo("body").css({
-        top: (offset.top + elem.offsetHeight) + "px",
-        left: offset.left + "px",
+    var pos = input.position();
+    var dropdown = $('<ul style="display: none; position: absolute; z-index: 10000"></ul>')
+      .addClass(options.dropdownClass).insertAfter(input).css({
+        top: (pos.top + input.outerHeight()) + "px",
+        left: pos.left + "px",
         minWidth: input.css("width")
       });
 
@@ -65,9 +67,20 @@
       var newVal = $.trim(input.val());
       if (force || newVal != prevVal) {
         if (force || newVal.length >= options.minChars) {
-          options.callback.apply(elem, [$.trim(input.val()), function(items, render) {
-            show(items, render);
-          }]);
+          if (options.cache && cache.hasOwnProperty(newVal)) {
+            show(cache[newVal].items, cache[newVal].render);
+          } else {
+            options.callback.apply(elem, [newVal, function(items, render) {
+              if (options.cache) {
+                if (cacheKeys.length >= options.cacheLimit) {
+                  delete cache[cacheKeys.shift()];
+                }
+                cache[newVal] = {items: items, render: render};
+                cacheKeys.push(newVal);
+              }
+              show(items, render);
+            }]);
+          }
         } else {
           dropdown.hide();
         }
@@ -91,7 +104,7 @@
         item.appendTo(dropdown);
       }
       dropdown.slideDown("fast");
-      dropdown.children('li').click(function(e) {
+      dropdown.children("li").click(function(e) {
         $(this).addClass("selected");
         commit();
       });
@@ -133,8 +146,10 @@
 
   $.fn.suggest = function(callback, options) {
     options = $.extend({
+      cache: true,
+      cacheLimit: 10,
       callback: callback,
-      delay: 100,
+      delay: 250,
       dropdownClass: "suggest-dropdown",
       minChars: 1,
       select: null

Modified: couchdb/trunk/share/www/style/layout.css
URL: http://svn.apache.org/viewvc/couchdb/trunk/share/www/style/layout.css?rev=736387&r1=736386&r2=736387&view=diff
==============================================================================
--- couchdb/trunk/share/www/style/layout.css (original)
+++ couchdb/trunk/share/www/style/layout.css Wed Jan 21 11:40:19 2009
@@ -142,8 +142,8 @@
 /* Suggest results */
 
 ul.suggest-dropdown { border: 1px solid #999; background-color: #eee;
-  padding: 0; margin: 0; list-style: none; opacity: .85; position: absolute;
-  z-index: 10000; display: none; -webkit-box-shadow: 2px 2px 10px #333;
+  padding: 0; margin: 0; list-style: none; opacity: .85;
+  -webkit-box-shadow: 2px 2px 10px #333;
 }
 ul.suggest-dropdown li { padding: 2px 5px; white-space: nowrap; color: #101010;
   text-align: left;
@@ -256,8 +256,8 @@
 #dialog fieldset th { color: #999; font-weight: bold;
   text-align: right;
 }
-#dialog fieldset input { background: #e9e9e9; vertical-align: middle; }
-#dialog fieldset input.error { background: #f9e4e4; }
+#dialog fieldset input { background-color: #e9e9e9; vertical-align: middle; }
+#dialog fieldset input.error { background-color: #f9e4e4; }
 #dialog fieldset div.error { padding-top: .3em; color: #b33; }
 #dialog .buttons { padding: 0 .5em .5em; text-align: right; }
 #dialog .buttons button { background: #444; border: 1px solid #aaa;