diff options
-rw-r--r-- | share/www/script/futon.browse.js | 3 | ||||
-rw-r--r-- | share/www/script/futon.format.js | 1 | ||||
-rw-r--r-- | share/www/script/jquery.editinline.js | 136 | ||||
-rw-r--r-- | share/www/script/jquery.suggest.js | 24 |
4 files changed, 86 insertions, 78 deletions
diff --git a/share/www/script/futon.browse.js b/share/www/script/futon.browse.js index 9e8aba66..ee8da4e6 100644 --- a/share/www/script/futon.browse.js +++ b/share/www/script/futon.browse.js @@ -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); } diff --git a/share/www/script/futon.format.js b/share/www/script/futon.format.js index 028119ed..d301a373 100644 --- a/share/www/script/futon.format.js +++ b/share/www/script/futon.format.js @@ -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) { diff --git a/share/www/script/jquery.editinline.js b/share/www/script/jquery.editinline.js index bd91e7e1..3f1f85e3 100644 --- a/share/www/script/jquery.editinline.js +++ b/share/www/script/jquery.editinline.js @@ -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); }); }); } diff --git a/share/www/script/jquery.suggest.js b/share/www/script/jquery.suggest.js index cc8fe549..54217390 100644 --- a/share/www/script/jquery.suggest.js +++ b/share/www/script/jquery.suggest.js @@ -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(); } |