Commits

John Fuex committed 5e23661

Added minified version.

  • Participants
  • Parent commits 14ddcf0
  • Tags Version 1.0.5

Comments (0)

Files changed (1)

js/improvedDropDown_min.js

+/* 
+   ImprovedDropDown 
+   Copyright 2011 John Fuex
+   Licensed under the Apache License, Version 2.0 (the "License");
+   you may not use this file except in compliance with the License.
+   http://www.apache.org/licenses/LICENSE-2.0
+*/
+function processDelayedCall(a,b){if(a in delayedCalls){delete delayedCalls[a]}b()}function delayCall(a,b,c){if(a in delayedCalls){clearTimeout(delayedCalls[a])}delayedCalls[a]=setTimeout(function(){processDelayedCall(a,b)},c)}function stringContainsCaseInsensitive(a,b){return a.toLowerCase().indexOf(b.toLowerCase())>-1}function swapControlSuffix(a,b){var c=a.attr("id");var d=c.lastIndexOf("_");if(d<0){return $("#"+c+b)}else{return $("#"+c.substr(0,d)+b)}}function isOptGroup(a){return a.get(0).tagName.toUpperCase()=="OPTGROUP"}function getWrapperControlFromOtherControl(a){return swapControlSuffix(a,idd_wrap_suffix)}function getSelectControlFromOtherControl(a){return swapControlSuffix(a,"")}function getImageControlFromOtherControl(a){return swapControlSuffix(a,idd_icon_suffix)}function getListControlFromOtherControl(a){return swapControlSuffix(a,idd_list_suffix)}function getTextControlFromOtherControl(a){return swapControlSuffix(a,idd_text_suffix)}function makeListItemVisible(a,b){var c=a.innerHeight();var d=b.position().top;var e=b.position().top+a.scrollTop();var f=d+b.outerHeight();if(f>c||d<0){a.scrollTop(e+b.outerHeight()*2-c)}}function navItem(a,b){var c=b.toString().toLowerCase()=="forward";var d=getListControlFromOtherControl(a);var e=a.val();var f=d.find(".idd_listItem_Hover:eq(0)");var g=f.length>0;if(!g){showList(d);f=getBestMatch(e,d)}var h;if(f!=null&&f.length>0){if(g){if(c){h=f.nextAll(".idd_listItem:visible").eq(0)}else{h=f.prevAll(".idd_listItem:visible").eq(0)}}else{h=f}}else{clearFilter(a);positionList(d);h=d.find(".idd_listItem:visible").eq(0)}if(h!=null&&h.length>0){selectItem(h,Boolean(e!=h.text()),false,true);if(g){d.find(".idd_listItem_Hover").removeClass("idd_listItem_Hover")}h.addClass("idd_listItem_Hover")}}function setIsDirty(a,b){var c="";if(b){c="yes"}else{c=""}a.attr("isDirty",c)}function getIsDirty(a){return a.attr("isDirty")!=""}function doesListItemMach(a,b){return!a.hasClass("idd_listItem_Disabled")&&stringContainsCaseInsensitive(a.text(),b)}function updateListFilter(a){var b=a.val();var c=getListControlFromOtherControl(a);var d=getWrapperControlFromOtherControl(a);var e=d.data("options").hideHeadersForEmptyGroups;var f=c.children(".idd_listItem");setIsDirty(a,true);f.removeClass("idd_listItem_Hover");showList(c);f.each(function(){$(this).toggle(doesListItemMach($(this),b))});var g=Boolean(f.filter(":visible").length!=0);c.children(".idd_listItemGroupHeader").toggle(g);c.children(".grpHdrNoMatches").toggle(!g);if(e){var h=null;var i=c.children().filter(":visible").not(".grpHdrNoMatches");i.each(function(){if($(this).hasClass("idd_listItemGroupHeader")){if(h!=null&&h.hasClass("idd_listItemGroupHeader")){h.hide()}}h=$(this)});if(i.last().hasClass("idd_listItemGroupHeader")){i.last().hide()}}positionList(c)}function getElementsTotalHeightPx(a){var b=0;a.each(function(){b+=$(this).outerHeight()});return b}function getElementsLongestWidthPx(a){var b=0;a.each(function(){thisControl=$(this);b=Math.max(b,thisControl.outerWidth())});return b}function positionList(a){try{var b=getTextControlFromOtherControl(a);var c=getImageControlFromOtherControl(a);var d=b.position().top+b.outerHeight();var e=b.position().left;a.css("top",d+"px");a.css("left",e+"px");var f=a.children(".idd_listItem:visible,.idd_listItemGroupHeader:visible");var g=getElementsTotalHeightPx(f)+5;var h=$(window).height()+$(document).scrollTop()-a.position().top-20;var i=12;var j=Math.min(g,h);j=Math.max(j,i);a.css("height",j+"px");var k=getElementsLongestWidthPx(f.add(".idd_message"));var l=b.outerWidth()+c.outerWidth();var m=Math.max(l,k);var n=$(window).width()-a.position().left-30;m=Math.min(n,m);f.css("width",m+"px");a.css("width",m+"px")}catch(o){}}function showList(a){if(!a.is(":visible")){a.show();positionList(a)}}function clearFilter(a){var b=getListControlFromOtherControl(a);b.children(".idd_listItemGroupHeader").show();b.children(".grpHdrNoMatches").hide();b.children(".idd_listItem").show().removeClass("idd_listItem_Hover")}function closeListUndoTyping(a){var b=getListControlFromOtherControl(a);resetValue(a);b.hide()}function idd_windowResize(){$("div.idd_list:visible").each(function(){positionList($(this))})}function windowDismissOpenLists(a){$("div.idd_list:visible").each(function(){if($(this)!=a){var b=getTextControlFromOtherControl($(this));selectFirstMatch(b,true)}})}function selectFirstMatch(a,b){var c=getListControlFromOtherControl(a);var d="updatefilter_"+a[0].id;if(getIsDirty(a)||d in delayedCalls){var e=getBestMatch(a.val(),c);if(e==null){resetValue(a)}else{selectItem(e,true,b,false)}}if(d in delayedCalls){clearTimeout(delayedCalls[d])}if(b){c.hide()}return e}function getBestMatch(a,b){var c=b.find(".idd_listItem").filter(function(){if(doesListItemMach($(this),a)){return true}return false});var d;switch(c.length){case 0:d=null;break;case 1:d=c.first();break;default:var e=getTextControlFromOtherControl(b).val();var f=null;c.each(function(){if($(this).text().toLowerCase()==e.toLowerCase()){f=$(this);return false}});if(f!=null){d=f.first()}else{d=c.first()}}return d}function findItemByValue(a,b){var c=null;a.find(".idd_listItem").each(function(){var a=$(this);if(getItemValue(a)==b){c=a;return false}});return c}function resetValue(a){var b=getSelectControlFromOtherControl(a);a.val(b.find("option:selected").text());setIsDirty(a,false)}function selectItem(a,b,c,d){var e=a.parent();var f=getTextControlFromOtherControl(e);f.val(a.text());var g=getSelectControlFromOtherControl(f);g.val(getItemValue(a));if(b){setIsDirty(f,true)}if(getIsDirty(f)&&!d){g.change();setIsDirty(f,false)}if(c){e.hide()}else{makeListItemVisible(e,a)}}function setItemValue(a,b){a.attr("savedValue",b)}function getItemValue(a){return a.attr("savedValue")}function populateListItem(a,b){var c="";var d=$("<div>"+b.text()+"</div>");d.addClass("idd_listItem");if(isOptGroup(b.parent())){d.addClass("idd_listItem_Nested");c=b.parent().attr("label")+": "}c+=d.text();d.attr("savedValue",b.val()).attr("title",c).css("white-space","nowrap").css("cursor","pointer");a.append(d);if((b.attr("disabled")||"")==""){d.mouseover(function(){$(this).parent().find(".idd_listItem_Hover").removeClass("idd_listItem_Hover");$(this).addClass("idd_listItem_Hover")});d.mouseout(function(){$(this).removeClass("idd_listItem_Hover")});d.click(function(){selectItem($(this),true,true,false)})}else{d.addClass("idd_listItem_Disabled")}}function getListGroupItem(a,b){var c=$("<div>"+a+"</div>");c.addClass("idd_listItemGroupHeader");c.css("white-space","nowrap").css("cursor","default");if(!b){c.css("display","none")}return c}function populateListGroupItem(a,b,c){var d=b.children("OPTION");if(c&&d.length==0)return;var e=getListGroupItem(b.attr("label"),true);a.append(e);d.each(function(){populateListItem(a,$(this))})}function populateList(a,b,c,d,e){var f=getListGroupItem(c,false);f.addClass("grpHdrNoMatches").addClass("idd_message");b.append(f);var g=a.children("OPTGROUP, OPTION");if(g.length==0){var h=getListGroupItem(d,true).addClass("idd_message");b.append(h)}g.each(function(){if(isOptGroup($(this))){populateListGroupItem(b,$(this),e)}else{populateListItem(b,$(this))}})}function getListElement(a){var b=a.attr("id");var c=$("<div></div>");c.attr("id",b+idd_list_suffix).css("position","absolute").css("display","none").css("overflow","auto").css("overflow-y","auto").css("overflow-x","hidden").css("padding-right","20px").addClass("idd_list").mouseenter(function(){suspendTextBoxExitHandler=true}).mouseleave(function(){suspendTextBoxExitHandler=false});c.keydown(function(a){switch(a.which){case KEY_DOWNARROW:{navItem(getTextControlFromOtherControl($(this)),"forward");a.stopPropagation();return false};case KEY_UPARROW:{navItem(getTextControlFromOtherControl($(this)),"back");a.stopPropagation();return false}}});return c}function getImageElement(a,b){var c=a.attr("id");var d=$("<img />");var e=jQuery.support.boxModel?0:2;d.attr("id",c+idd_icon_suffix).attr("src",b).addClass("idd_icon").css("cursor","pointer").css("height",a.outerHeight()-e+"px").css("vertical-align","middle").css("overflow","hidden").css("display","inline-block").css("margin","0");d.mouseenter(function(){suspendTextBoxExitHandler=true});d.mouseleave(function(){suspendTextBoxExitHandler=false});d.click(function(a){var b=getListControlFromOtherControl($(this));var c=getTextControlFromOtherControl($(this));if(b.is(":visible")){selectFirstMatch(c,true)}else{windowDismissOpenLists(b);clearFilter(getTextControlFromOtherControl($(this)));showList(b);c.focus().select()}var d=getSelectControlFromOtherControl(b);var e=$("[savedValue='"+d.val()+"']");if(e.length!=0){e.addClass("idd_listItem_Hover");b.scrollTop(e.position().top+b.scrollTop()-30)}a.stopPropagation();return false});return d}function getTextElement(a,b){var c=a.attr("id");var d=$('<input type="text" />');var e=Math.max(a.innerWidth()-b.outerWidth(),40);d.attr("id",c+idd_text_suffix).addClass("idd_textbox").attr("value",a.find("option:selected").text()).css("height",a.outerHeight()+"px").css("font-family",a.css("font-family")).css("font-size",a.css("font-size")).css("border-width","1px").attr("autocomplete","off").attr("padding","0").width(e);setIsDirty(d,false);d.keydown(function(a){switch(a.which){case KEY_ENTER:{selectFirstMatch($(this),true);a.stopPropagation();return false};case KEY_TAB:if(a.which==KEY_TAB){selectFirstMatch($(this),true);break};case KEY_DOWNARROW:{navItem($(this),"forward");a.stopPropagation();return false};case KEY_UPARROW:{navItem($(this),"back");a.stopPropagation();return false}}});d.keyup(function(a){var b=$(this);switch(a.which){case KEY_ESCAPE:closeListUndoTyping(b);break;case KEY_TAB:break;case KEY_ENTER:break;case KEY_DOWNARROW:break;case KEY_UPARROW:break;case KEY_LEFTARROW:break;case KEY_RIGHTARROW:break;default:delayCall("updatefilter_"+this.id,function(){updateListFilter(b)},KEY_PRESS_FILTER_DELAY_MS)}});d.focusout(function(){if(!suspendTextBoxExitHandler){selectFirstMatch($(this),true)}});return d}function getWrapperElement(a,b){var c=a.attr("id");var d=$("<span></span>");d.attr("id",c+idd_wrap_suffix).css("border-style","none").css("white-space","nowrap").css("margin","0").css("padding","0").click(function(){return false});d.data("options",b);return d}var debugMode=0;var idd_list_suffix="_iddlist";var idd_icon_suffix="_iddicon";var idd_text_suffix="_iddtext";var idd_wrap_suffix="_iddwrap";var KEY_ESCAPE=27;var KEY_TAB=9;var KEY_ENTER=13;var KEY_UPARROW=38;var KEY_DOWNARROW=40;var KEY_LEFTARROW=37;var KEY_RIGHTARROW=39;var KEY_PRESS_FILTER_DELAY_MS=120;var resizeHandlerSet=false;var suspendTextBoxExitHandler=false;(function(a){a.fn.improveDropDown=function(b){if(!resizeHandlerSet){a(window).resize(function(){delayCall("windowResize",function(){idd_windowResize()},20)});a(document).click(windowDismissOpenLists);resizeHandlerSet=true}if(arguments.length==0||typeof b=="object"){var c={iconPath:"./img/dropIcon.png",noMatchesText:"No Matches",noItemsText:"No Items Available",hideHeadersForEmptyGroups:false};if(arguments.length==1){for(var d in c){if(d in b){c[d]=b[d]}}}this.each(function(){var b=a(this);var d=getWrapperElement(b,c);b.after(d);var e=getImageElement(b,c.iconPath);d.append(e);var f=getTextElement(b,e);d.prepend(f);var g=getListElement(b);d.append(g);populateList(b,g,c.noMatchesText,c.noItemsText,c.hideHeadersForEmptyGroups);if(document.activeElement==b[0]){f.focus().select()}if(debugMode!=1){b.hide()}})}else{this.each(function(){var c=getListControlFromOtherControl(a(this));if(c!=null){var d=findItemByValue(c,b);if(d!=null){selectItem(d,true,true,false)}}})}return this}})(jQuery);var delayedCalls=Object