couchdb-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From cml...@apache.org
Subject svn commit: r735146 - in /couchdb/trunk/share/www/script: futon.browse.js futon.format.js jquery.editinline.js jquery.suggest.js
Date Fri, 16 Jan 2009 21:27:44 GMT
Author: cmlenz
Date: Fri Jan 16 13:27:43 2009
New Revision: 735146

URL: http://svn.apache.org/viewvc?rev=735146&view=rev
Log:
Some cleanup of the suggest and editinline jQuery plugins.

Modified:
    couchdb/trunk/share/www/script/futon.browse.js
    couchdb/trunk/share/www/script/futon.format.js
    couchdb/trunk/share/www/script/jquery.editinline.js
    couchdb/trunk/share/www/script/jquery.suggest.js

Modified: couchdb/trunk/share/www/script/futon.browse.js
URL: http://svn.apache.org/viewvc/couchdb/trunk/share/www/script/futon.browse.js?rev=735146&r1=735145&r2=735146&view=diff
==============================================================================
--- couchdb/trunk/share/www/script/futon.browse.js [utf-8] (original)
+++ couchdb/trunk/share/www/script/futon.browse.js [utf-8] Fri Jan 16 13:27:43 2009
@@ -251,7 +251,6 @@
                   var optGroup = $(document.createElement("optgroup"))
                     .attr("label", doc._id.substr(8));
                   for (var name in doc.views) {
-                    if (!doc.views.hasOwnProperty(name)) continue;
                     var option = $(document.createElement("option"))
                       .attr("value", doc._id + "/" + name).text(name)
                       .appendTo(optGroup);
@@ -684,7 +683,6 @@
           page.doc = doc;
           var propNames = [];
           for (var prop in doc) {
-            if (!doc.hasOwnProperty(prop)) continue;
             propNames.push(prop);
           }
           // Order properties alphabetically, but put internal fields first
@@ -904,7 +902,6 @@
           if (type == "object" && val !== null) {
             var list = $("<dl></dl>");
             for (var i in val) {
-              if (!value.hasOwnProperty(i)) continue;
               $("<dt></dt>").text(i).appendTo(list);
               $("<dd></dd>").append(_renderValue(val[i])).appendTo(list);
             }

Modified: couchdb/trunk/share/www/script/futon.format.js
URL: http://svn.apache.org/viewvc/couchdb/trunk/share/www/script/futon.format.js?rev=735146&r1=735145&r2=735146&view=diff
==============================================================================
--- couchdb/trunk/share/www/script/futon.format.js [utf-8] (original)
+++ couchdb/trunk/share/www/script/futon.format.js [utf-8] Fri Jan 16 13:27:43 2009
@@ -71,7 +71,6 @@
               buf.push("{");
               var index = 0;
               for (var key in val) {
-                if (!val.hasOwnProperty(key)) continue;
                 buf.push(index > 0 ? itemsep : options.linesep);
                 var keyDisplay = options.quoteKeys ? JSON.stringify(key) : key;
                 if (options.html) {

Modified: couchdb/trunk/share/www/script/jquery.editinline.js
URL: http://svn.apache.org/viewvc/couchdb/trunk/share/www/script/jquery.editinline.js?rev=735146&r1=735145&r2=735146&view=diff
==============================================================================
--- couchdb/trunk/share/www/script/jquery.editinline.js (original)
+++ couchdb/trunk/share/www/script/jquery.editinline.js Fri Jan 16 13:27:43 2009
@@ -12,6 +12,74 @@
 
 (function($) {
 
+  function startEditing(elem, options) {
+    var editable = $(elem);
+    var origHtml = editable.html();
+    var origText = options.populate($.trim(editable.text()));
+
+    if (!options.begin.apply(elem, [origText])) {
+      return;
+    }
+
+    var input = options.createInput.apply(elem, [origText])
+      .addClass("editinline").val(origText)
+      .dblclick(function() { return false; })
+      .keydown(function(evt) {
+        switch (evt.keyCode) {
+          case 13: { // return
+            if (!input.is("textarea")) applyChange(evt.keyCode);
+            break;
+          }
+          case 27: { // escape
+            cancelChange(evt.keyCode);
+            break;
+          }
+          case 9: { // tab
+            if (!input.is("textarea")) {
+              applyChange(evt.keyCode);
+              return false;
+            }
+          }
+        }
+      });
+
+    function applyChange(keyCode) {
+      var newText = input.val();
+      if (newText == origText) {
+        cancelChange(keyCode);
+        return true;
+      }
+      if ((!options.allowEmpty && !newText.length) ||
+          !options.validate.apply(elem, [newText])) {
+        input.addClass("invalid");
+        return false;
+      }
+      input.remove();
+      tools.remove();
+      options.accept.apply(elem, [newText, origText]);
+      editable.removeClass("editinline-container")
+      options.end.apply(elem, [keyCode]);
+      return true;
+    }
+
+    function cancelChange(keyCode) {
+      options.cancel.apply(elem, [origText]);
+      editable.html(origHtml).removeClass("editinline-container");
+      options.end.apply(elem, [keyCode]);
+    }
+
+    var tools = $("<span class='editinline-tools'></span>");
+    $("<button type='button' class='apply'></button>")
+      .text(options.acceptLabel).click(applyChange).appendTo(tools);
+    $("<button type='button' class='cancel'></button>")
+      .text(options.cancelLabel).click(cancelChange).appendTo(tools)
+
+    editable.html("").append(tools).append(input)
+      .addClass("editinline-container");
+    options.prepareInput.apply(elem, [input[0]]);
+    input.each(function() { this.focus(); this.select(); });
+  }
+
   $.fn.makeEditable = function(options) {
     options = $.extend({
       allowEmpty: true,
@@ -31,72 +99,8 @@
     }, options || {});
 
     return this.each(function() {
-      var elem = $(this);
-      elem.attr("title", options.toolTip).dblclick(function() {
-        var oldHtml = elem.html();
-        var oldText = options.populate($.trim(elem.text()));
-
-        if (!options.begin.apply(elem[0], [oldText])) {
-          return;
-        }
-
-        var input = options.createInput.apply(elem[0], [oldText])
-          .addClass("editinline").val(oldText)
-          .dblclick(function() { return false; })
-          .keydown(function(evt) {
-            switch (evt.keyCode) {
-              case 13: { // return
-                if (!input.is("textarea")) applyChange(evt.keyCode);
-                break;
-              }
-              case 27: { // escape
-                cancelChange(evt.keyCode);
-                break;
-              }
-              case 9: { // tab
-                if (!input.is("textarea")) {
-                  applyChange(evt.keyCode);
-                  return false;
-                }
-              }
-            }
-          });
-
-        function applyChange(keyCode) {
-          var newText = input.val();
-          if (newText == oldText) {
-            cancelChange(keyCode);
-            return true;
-          }
-          if ((!options.allowEmpty && !newText.length) ||
-              !options.validate.apply(elem[0], [newText])) {
-            input.addClass("invalid");
-            return false;
-          }
-          input.remove();
-          tools.remove();
-          options.accept.apply(elem[0], [newText, oldText]);
-          elem.removeClass("editinline-container")
-          options.end.apply(elem[0], [keyCode]);
-          return true;
-        }
-
-        function cancelChange(keyCode) {
-          options.cancel.apply(elem[0], [oldText]);
-          elem.html(oldHtml).removeClass("editinline-container");
-          options.end.apply(elem[0], [keyCode]);
-        }
-
-        var tools = $("<span class='editinline-tools'></span>");
-        $("<button type='button' class='apply'></button>")
-          .text(options.acceptLabel).click(applyChange).appendTo(tools);
-        $("<button type='button' class='cancel'></button>")
-          .text(options.cancelLabel).click(cancelChange).appendTo(tools)
-
-        elem.html("").append(tools).append(input)
-          .addClass("editinline-container");
-        options.prepareInput.apply(elem[0], [input[0]]);
-        input.each(function() { this.focus(); this.select(); });
+      $(this).attr("title", options.toolTip).dblclick(function() {
+        startEditing(this, options);
       });
     });
   }

Modified: couchdb/trunk/share/www/script/jquery.suggest.js
URL: http://svn.apache.org/viewvc/couchdb/trunk/share/www/script/jquery.suggest.js?rev=735146&r1=735145&r2=735146&view=diff
==============================================================================
--- couchdb/trunk/share/www/script/jquery.suggest.js [utf-8] (original)
+++ couchdb/trunk/share/www/script/jquery.suggest.js [utf-8] Fri Jan 16 13:27:43 2009
@@ -65,9 +65,9 @@
       var newVal = $.trim(input.val());
       if (force || newVal != prevVal) {
         if (force || newVal.length >= options.minChars) {
-          options.callback($.trim(input.val()), function(items) {
-            show(items);
-          });
+          options.callback.apply(elem, [$.trim(input.val()), function(items, render) {
+            show(items, render);
+          }]);
         } else {
           dropdown.hide();
         }
@@ -75,14 +75,22 @@
       }
     }
 
-    function show(items) {
+    function show(items, render) {
       if (!items) return;
       if (!items.length) { dropdown.hide(); return; }
-      var html = [];
+      render = render || function(idx, value) { return value; }
+      dropdown.empty();
       for (var i = 0; i < items.length; i++) {
-        html.push('<li>' + items[i] + '</li>');
+        var item = $("<li></li>").data("value", items[i]);
+        var rendered = render(i, items[i]);
+        if (typeof(rendered) == "string") {
+          item.text(rendered);
+        } else {
+          item.append(rendered);
+        }
+        item.appendTo(dropdown);
       }
-      dropdown.html(html.join("")).slideDown("fast");
+      dropdown.slideDown("fast");
       dropdown.children('li').click(function(e) {
         $(this).addClass("selected");
         commit();
@@ -92,7 +100,7 @@
     function commit() {
       var sel = getSelection();
       if (sel) {
-        prevVal = sel.text();
+        prevVal = sel.data("value");
         input.val(prevVal);
         dropdown.hide();
       }



Mime
View raw message