From 95df9c29bb9aaa2b502bdbfc077f7136a0a3b8bf Mon Sep 17 00:00:00 2001 From: tkellogg Date: Wed, 31 Aug 2011 21:04:57 -0600 Subject: [PATCH] Adding first files It replaces the select with a text box and gathers the options into spans, but still doesn't display the options --- .gitignore | 1 + comboEditable.js | 35 +++++++++++++++++++++++++++++++++++ index.html | 19 +++++++++++++++++++ 3 files changed, 55 insertions(+) create mode 100644 .gitignore create mode 100644 comboEditable.js create mode 100644 index.html diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..4e8d50a --- /dev/null +++ b/.gitignore @@ -0,0 +1 @@ +*.swp diff --git a/comboEditable.js b/comboEditable.js new file mode 100644 index 0000000..17a6018 --- /dev/null +++ b/comboEditable.js @@ -0,0 +1,35 @@ +(function($) { + + $.fn.comboEditable = function(opts) { + var name = this.attr('name'); + var selectedValue = undefined, selectedText = undefined; + var data = $.map(this.find('option'), function(x) { + if (this.selected) { + selectedValue = this.value; + selectedText = this.innerHTML; + } + + return '' + + this.innerHTML + ''; + }); + + if (!selectedText) { + selectedValue = this.find('option').first().val(); + selectedText = this.find('option').first().text(); + } + + var elements = ''; + $.each(data, function(x) { elements += x; }); + + var $ret = $('
'); + $ret.append(''); + var $text = $ret.find(':text'); + $ret.append(''); + var $value = $ret.find(':hidden'); + + this.replaceWith($ret); + return $ret; + } + +})(jQuery); diff --git a/index.html b/index.html new file mode 100644 index 0000000..fc4ceb1 --- /dev/null +++ b/index.html @@ -0,0 +1,19 @@ + + + + + + + +
+ +
+ +