diff --git a/index.html b/index.html index 9207fce..11e394b 100755 --- a/index.html +++ b/index.html @@ -7,10 +7,6 @@ Relevant Dropdown - - - - @@ -78,10 +74,28 @@

A HTML5 datalist polyfill that depends on jQuery and Modernizr.

+

+ + + +

GitHub

+ + + + - \ No newline at end of file diff --git a/js/jquery.relevant-dropdown.js b/js/jquery.relevant-dropdown.js new file mode 100644 index 0000000..20bffa0 --- /dev/null +++ b/js/jquery.relevant-dropdown.js @@ -0,0 +1,188 @@ +(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 + change: null + }, options); + + return this.each(function() { + + var $input = $(this), + list_id = $input.attr('list'), + $datalist = $("#" + list_id), + 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 + $("