26 lines
9.2 KiB
JavaScript
26 lines
9.2 KiB
JavaScript
![]() |
/**
|
||
|
* JQuery Searchable DropDown Plugin
|
||
|
*
|
||
|
* @required jQuery 1.3.x
|
||
|
* @author Sascha Wolski <hagman@gmx.de>
|
||
|
* $Id: jquery.searchabledropdown.js 47 2010-04-07 08:57:05Z xhaggi $
|
||
|
*
|
||
|
* Based up on the AddIncSearch plugin published by Tobias Oetiker
|
||
|
* http://plugins.jquery.com/project/AddIncSearch
|
||
|
*
|
||
|
*
|
||
|
* This program is free software; you can redistribute it and/or modify
|
||
|
* it under the terms of the GNU General Public License as published by
|
||
|
* the Free Software Foundation; either version 2 of the License, or
|
||
|
* (at your option) any later version.
|
||
|
*
|
||
|
* This program is distributed in the hope that it will be useful,
|
||
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||
|
* GNU General Public License for more details.
|
||
|
*
|
||
|
* You should have received a copy of the GNU General Public License
|
||
|
* along with this program; if not, write to the Free Software
|
||
|
* Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
|
||
|
*/
|
||
|
(function($){var B=register("searchable");B.defaults={maxListSize:100,maxMultiMatch:50,exactMatch:false,wildcards:true,ignoreCase:true,warnMultiMatch:"top {0} matches ...",warnNoMatch:"no matches ...",latency:200,zIndex:"auto"};B.execute=function(g,h){if($.browser.msie&&parseInt(jQuery.browser.version)<7)return this;if(this.nodeName!="SELECT"||this.size>1)return this;var j=$(this);var k={index:-1,options:null};var l="lang";var m=false;$.browser.chrome=/chrome/.test(navigator.userAgent.toLowerCase());if($.browser.chrome)$.browser.safari=false;if($.meta){g=$.extend({},options,j.data())}var n=$("<div/>");var o=$("<div/>");var p=$("<input/>");var q=$("<select/>");var r=$("<option>"+g.warnMultiMatch.replace(/\{0\}/g,g.maxMultiMatch)+"</option>").attr("disabled","true");var t=$("<option>"+g.warnNoMatch+"</option>").attr("disabled","true");var u={option:function(a){return $(q.get(0).options[a])},selected:function(){return q.find(":selected")},selectedIndex:function(a){if(a>-1)q.get(0).selectedIndex=a;return q.get(0).selectedIndex},size:function(a){q.attr("size",Math.max(2,Math.min(a,20)))},reset:function(){if((j.get(0).selectedIndex-1)==j.data("index"))return;var a=j.get(0).selectedIndex;var b=j.get(0).length;var c=Math.floor(g.maxMultiMatch/2);var d=Math.max(1,(a-c));var e=Math.min(b,Math.max(g.maxMultiMatch,(a+c)));var f=a-d;q.empty();u.size(e-d);for(var i=d;i<e;i++)q.append($(j.get(0).options[i]).clone().attr(l,i-1));if(e>g.maxMultiMatch)q.append(r);q.get(0).selectedIndex=f}};draw();var x=false;o.mouseover(function(){x=true});o.mouseout(function(){x=false});q.mouseover(function(){x=true});q.mouseout(function(){x=false});p.click(function(e){if(!m)enable(e,true);else disable(e,true)});p.blur(function(e){if(!x&&m)disable(e,true)});j.keydown(function(e){if(e.keyCode!=9)enable(e,false,true)});j.click(function(e){q.focus()});q.click(function(e){if(u.selectedIndex()<0)return;disable(e)});q.focus(function(e){p.focus()});q.blur(function(e){if(!x)disable(e,true)});q.mousemove(function(e){if($.browser.opera&&parseFloat(jQuery.browser.version)>=9.8)return true;var a=Math.floor(parseFloat(/([0-9\.]+)px/.exec(u.option(0).css("font-size"))));var b=4;if($.browser.opera)b=2.5;if($.browser.safari||$.browser.chrome)b=3;a+=Math.round(a/b);u.selectedIndex(Math.floor((e.pageY-q.offset().top+this.scrollTop)/a))});o.click(function(e){p.click()});p.keyup(function(e){if(jQuery.inArray(e.keyCode,new Array(9,13,16,33,34,35,36,38,40))>-1)return true;A=$.trim(p.val().toLowerCase());clearSearchTimer();y=setTimeout(searching,g.latency)});p.keydown(function(e){if(e.shiftKey||e.ctrlKey||e.altKey)return;switch(e.keyCode){case 9:disable(e);moveTab(j,e.shiftKey?-1:1);break;case 13:disable(e);j.focus();break;case 27:disable(e,true);j.focus();break;case 33:if(u.selectedIndex()-q.attr("size")>0){u.selectedIndex(u.selectedIndex()-=q.attr("size"))}else{u.selectedIndex(0)}synchronize();break;case 34:if(u.selectedIndex()+q.attr("size")<q.get(0).options.length-1){u.selectedIndex(u.selectedIndex()+=q.attr("size"))}else{u.selectedIndex(q.get(0).options.length-1)}synchronize();break;case 38:if(u.selectedIndex()>0){u.selectedIndex(u.selectedIndex()-1);synchronize()}break;case 40:if(u.selectedIndex()<q.get(0).options.length-1){u.selectedIndex(u.selectedIndex()+1);synchronize()}break;default:return true}return false});function draw(){j.css("text-decoration","none");j.width(j.outerWidth());j.height(j.outerHeight());n.css("position","relative");n.css("width",j.outerWidth());if($.browser.msie)n.css("z-index",h);o.css({"position":"absolute","top":0,"left":0,"width":j.outerWidth(),"height":j.outerHeight(),"background-color":"#FFFFFF","opacity":"0.01"});p.attr("type","text");p.hide();p.height(j.outerHeight());p.css({"position":"absolute","top":0,"left":0,"margin":"0px","padding":"0px","outline-style":"none","border-style":"solid","border-bottom-style":"none","border-color":"transparent","background-color":"transparent"});var a=new Array();a.push("border-left-width");a.push("border-top-width");a.push("font-size");a.push("font-stretch");a.push("font-variant");a.push("font-weight");
|