From 08465b4d267f4a7244921b5fccd1244ab4adaa09 Mon Sep 17 00:00:00 2001 From: Baylor Rae Date: Sun, 4 Dec 2011 16:40:23 -0600 Subject: [PATCH 01/23] Turned the JS into a plugin - Turned the original javascript into a plugin. - Changed the :contains expression to :RD_contains --- js/jquery.relevant-dropdown.js | 181 +++++++++++++++++++++++++++++++++ 1 file changed, 181 insertions(+) create mode 100644 js/jquery.relevant-dropdown.js diff --git a/js/jquery.relevant-dropdown.js b/js/jquery.relevant-dropdown.js new file mode 100644 index 0000000..633663d --- /dev/null +++ b/js/jquery.relevant-dropdown.js @@ -0,0 +1,181 @@ +(function($) { + + // Make jQuery's :contains case insensitive (like HTML5 datalist) + // Changed the name to prevent overriding original functionality + $.expr[':'].RD_contains = function(a, i, m) { + return $(a).text().toUpperCase().indexOf(m[3].toUpperCase()) >= 0; + }; + + + $.fn.relevantDropdown = function(options) { + + options = $.extend({ + fadeOutSpeed: 'normal' // speed to fade out the dataList Popup + }, options); + + + return this.each(function() { + + var doc = $(document), + $searchInput = $(this), + $datalist = $("#" + $searchInput.attr("list")), + datalistItems = $datalist.find("option"), + + searchPosition, + scrollValue = 0; + + // Makes sure the browser doesn't already support the list attribute + // todo: I couldn't figure out how to make an opposite `if statement` without Safari acting up + if( !Modernizr.input.list || (parseInt($.browser.version) > 400) ) { + + // Insert home for new fake datalist + $("