// MSDropDown - jquery.dd.js // author: Marghoob Suleman // Date: 12th Aug, 2009 // Version: 2.1 {date: 3rd Sep 2009} // Revision: 25 // web: www.giftlelo.com | www.marghoobsuleman.com /* // msDropDown is free jQuery Plugin: 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 3 of the License, or // (at your option) any later version. // msDropDown 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, see . */ ;(function($) { var oldDiv = ""; $.fn.dd = function(options) { $this = this; options = $.extend({ height:120, visibleRows:7, rowHeight:23, showIcon:true, zIndex:9999, style:'' }, options); var selectedValue = ""; var actionSettings ={}; actionSettings.insideWindow = true; actionSettings.keyboardAction = false; actionSettings.currentKey = null; var ddList = false; config = {postElementHolder:'_msddHolder', postID:'_msdd', postTitleID:'_title',postTitleTextID:'_titletext',postChildID:'_child',postAID:'_msa',postOPTAID:'_msopta',postInputID:'_msinput', postArrowID:'_arrow', postInputhidden:'_inp'}; styles = {dd:'dd', ddTitle:'ddTitle', arrow:'arrow', ddChild:'ddChild', disbaled:.30}; attributes = {actions:"onfocus,onblur,onchange,onclick,ondblclick,onmousedown,onmouseup,onmouseover,onmousemove,onmouseout,onkeypress,onkeydown,onkeyup", prop:"size,multiple,disabled,tabindex"}; var elementid = $(this).attr("id"); var inlineCSS = $(this).attr("style"); options.style += (inlineCSS==undefined) ? "" : inlineCSS; var allOptions = $(this).children(); ddList = ($(this).attr("size")>0 || $(this).attr("multiple")==true) ? true : false; if(ddList) {options.visibleRows = $(this).attr("size");}; var a_array = {};//stores id, html & value etc //create wrapper createDropDown(); function getPostID(id) { return elementid+config[id]; }; function getOptionsProperties(option) { var currentOption = option; var styles = $(currentOption).attr("style"); return styles; }; function matchIndex(index) { var selectedIndex = $("#"+elementid+" option:selected"); if(selectedIndex.length>1) { for(var i=0;i"; var optChild = $(currentOption).children(); optChild.each(function(currentopt){ var currentOptOption = optChild[currentopt]; var aid = aidoptfix+"_"+(current)+"_"+(currentopt); var arrow = $(currentOptOption).attr("title"); arrow = (arrow.length==0) ? "" : ' '; var sText = $(currentOptOption).text(); var sValue = $(currentOptOption).val(); var sEnabledClass = ($(currentOptOption).attr("disabled")==true) ? "disabled" : "enabled"; a_array[aid] = {html:arrow + sText, value:sValue, text:sText, index:currentOptOption.index, id:aid}; var innerStyle = getOptionsProperties(currentOptOption); if(matchIndex(currentOptOption.index)==true) { aTag += ''; aTag += arrow + sText+''; }); aTag += ""; } else { var aid = aidfix+"_"+(current); var arrow = $(currentOption).attr("title"); arrow = (arrow.length==0) ? "" : ' '; var sText = $(currentOption).text(); var sValue = $(currentOption).val(); var sEnabledClass = ($(currentOption).attr("disabled")==true) ? "disabled" : "enabled"; a_array[aid] = {html:arrow + sText, value:sValue, text:sText, index:currentOption.index, id:aid}; var innerStyle = getOptionsProperties(currentOption); if(matchIndex(currentOption.index)==true) { aTag += ''; aTag += arrow + sText+''; }; }); return aTag; }; function createChildDiv() { var id = getPostID("postID"); var childid = getPostID("postChildID"); var sStyle = options.style; sDiv = ""; sDiv += '
'; var sDiv = '
'+arrow + sText+'
'; return sDiv; }; function createDropDown() { var changeInsertionPoint = false; var id = getPostID("postID"); var titleid = getPostID("postTitleID"); var titletextid = getPostID("postTitleTextID"); var childid = getPostID("postChildID"); var arrowid = getPostID("postArrowID"); var iWidth = $("#"+elementid).width(); var sStyle = options.style; if($("#"+id).length>0) { $("#"+id).remove(); changeInsertionPoint = true; } var sDiv = '
options.visibleRows) { var margin = parseInt($("#"+childid+" a:first").css("padding-bottom")) + parseInt($("#"+childid+" a:first").css("padding-top")); var iHeight = ((options.rowHeight)*options.visibleRows) - margin; $("#"+childid).css("height", iHeight+"px"); } //set out of vision if(changeInsertionPoint==false) { setOutOfVision(); addNewEvents(elementid); } if($("#"+elementid).attr("disabled")==true) { $("#"+id).css("opacity", styles.disbaled); } else { applyEvents(); //add events //arrow hightlight if(!ddList) { $("#"+titleid).bind("mouseover", function(event) { hightlightArrow(1); }); $("#"+titleid).bind("mouseout", function(event) { hightlightArrow(0); }); }; //open close events $("#"+childid+ " a.enabled").bind("click", function(event) { event.preventDefault(); manageSelection(this); if(!ddList) { $("#"+childid).unbind("mouseover"); setInsideWindow(false); var sText = (options.showIcon==false) ? $(this).text() : $(this).html(); setTitleText(sText); closeMe(); }; setValue(); //actionSettings.oldIndex = a_array[$(this).attr("id")].index; }); $("#"+childid+ " a.disabled").css("opacity", styles.disbaled); if(ddList) { $("#"+childid).bind("mouseover", function(event) {if(!actionSettings.keyboardAction) { actionSettings.keyboardAction = true; $(document).bind("keydown", function(event) { var keyCode = event.keyCode; actionSettings.currentKey = keyCode; if(keyCode==39 || keyCode==40) { //move to next event.preventDefault(); event.stopPropagation(); next(); setValue(); }; if(keyCode==37 || keyCode==38) { event.preventDefault(); event.stopPropagation(); //move to previous previous(); setValue(); }; }); }}); }; $("#"+childid).bind("mouseout", function(event) {setInsideWindow(false);$(document).unbind("keydown");actionSettings.keyboardAction = false;actionSettings.currentKey=null;}); if(!ddList) { $("#"+titleid).bind("click", function(event) { setInsideWindow(false); if($("#"+childid+":visible").length==1) { $("#"+childid).unbind("mouseover"); } else { $("#"+childid).bind("mouseover", function(event) {setInsideWindow(true);}); openMe(); }; }); }; $("#"+titleid).bind("mouseout", function(evt) { setInsideWindow(false); }) }; }; function getByIndex(index) { for(var i in a_array) { if(a_array[i].index==index) { return a_array[i]; } } } function manageSelection(obj) { var childid = getPostID("postChildID"); if(!ddList) { $("#"+childid+ " a.selected").removeClass("selected"); } var selectedA = $("#"+childid + " a.selected").attr("id"); if(selectedA!=undefined) { var oldIndex = (actionSettings.oldIndex==undefined || actionSettings.oldIndex==null) ? a_array[selectedA].index : actionSettings.oldIndex; }; if(obj && !ddList) { $(obj).addClass("selected"); }; if(ddList) { var keyCode = actionSettings.currentKey; if($("#"+elementid).attr("multiple")==true) { if(keyCode == 17) { //control actionSettings.oldIndex = a_array[$(obj).attr("id")].index; $(obj).toggleClass("selected"); //multiple } else if(keyCode==16) { $("#"+childid+ " a.selected").removeClass("selected"); $(obj).addClass("selected"); //shift var currentSelected = $(obj).attr("id"); var currentIndex = a_array[currentSelected].index; for(var i=Math.min(oldIndex, currentIndex);i<=Math.max(oldIndex, currentIndex);i++) { $("#"+getByIndex(i).id).addClass("selected"); } } else { $("#"+childid+ " a.selected").removeClass("selected"); $(obj).addClass("selected"); actionSettings.oldIndex = a_array[$(obj).attr("id")].index; }; } else { $("#"+childid+ " a.selected").removeClass("selected"); $(obj).addClass("selected"); actionSettings.oldIndex = a_array[$(obj).attr("id")].index; }; }; }; function addNewEvents(id) { document.getElementById(id).refresh = function(e) { $("#"+this.id).dd(options); }; }; function setInsideWindow(val) { actionSettings.insideWindow = val; }; function getInsideWindow() { return actionSettings.insideWindow; }; function applyEvents() { var mainid = getPostID("postID"); var actions_array = attributes.actions.split(","); for(var iCount=0;iCount
"); $("#"+elementid).appendTo($("#"+sId)); }; function setTitleText(sText) { var titletextid = getPostID("postTitleTextID"); $("#"+titletextid).html(sText); }; function next() { var titletextid = getPostID("postTitleTextID"); var childid = getPostID("postChildID"); var allAs = $("#"+childid + " a.enabled"); for(var current=0;current=parseInt($("#"+childid).height())) { $("#"+childid).scrollTop(($("#"+childid).scrollTop())+$("#"+selectedA).height()+$("#"+selectedA).height()); }; break; }; }; }; function previous() { var titletextid = getPostID("postTitleTextID"); var childid = getPostID("postChildID"); var allAs = $("#"+childid + " a.enabled"); for(var current=0;current1) { var alls = $("#"+elementid +" > option:selected").removeAttr("selected"); for(var i=0;i