/**
*@class:SelectPane
*@depends:global.js,ActivePane.js
*@version:1.0
*@author:TOY (toy@fortuneduck.com)
*@description:fix some bugs
*/
function SelectPane(targetInput,array,propArray)
{
if(propArray==null||array==null||targetInput==null)
{
return ;
}
var target=targetInput;
//var listener;
var targetFocused=false;
var visible=false;
var main=new ActivePane();
var objects=array;
var valueProp=propArray[0];
var textProps=propArray[1];
var selectedOption=null;
var filteredOptions=new Array();
var selectedValue="";
var selectedBgColor="#003366";
var selectedColor="#ffffff";
var originBgColor="#ffffff";
var originColor="#000000";
var mouseOnThePane=false;
var bottomPointer=0;
var trTop;
var trBottom;
var table=null;
var setSelected=function(tr,value)
{
main.removeHeight();
try
{
selectedOption.style.backgroundColor=originBgColor;
selectedOption.style.color=originColor;
}
catch(ex){}
selectedOption=tr;
selectedValue=value;
originBgColor=tr.style.backgroundColor;
originColor=tr.style.color=tr.style.color;
tr.style.backgroundColor=selectedBgColor;
tr.style.color=selectedColor;
}
var setTargetValue=function(v)
{
/*try
{
listener.doNotListen();
}
catch(ex)
{
}*/
target.value=v;
/*try
{
listener.listen();
}
catch(ex)
{
}*/
}
var moveSelectedUp=function()
{
if(!visible)
{
return;
}
var option=selectedOption;
var length=filteredOptions.length;
if(length<0)
{
return;
}
if(length>8&&bottomPointer>8)
{
filteredOptions[bottomPointer-8].style.display="";
}
var position=0;
if(option==null)
{
position=length>1?length-1:0;
option=filteredOptions[position];
}
else
{
for(var i=0;i<filteredOptions.length;i++)
{
var o=filteredOptions[i];
if(o==option)
{
position=(i>0)?i-1:filteredOptions.length-1;
option=filteredOptions[position];
break;
}
}
}
if(position>bottomPointer)
{
bottomPointer=position+1;
}
else if(position<=bottomPointer-8-1)
{
bottomPointer--;
}
if(length>8)
{
var top=bottomPointer-8;
for(var i=length-1;i>=0;i--)
{
var tr=filteredOptions[i];
if(i<bottomPointer&&i>=bottomPointer-8)
{
tr.style.display="";
}
else
{
tr.style.display="none";
}
}
if(bottomPointer>=length)
{
trBottom.style.backgroundColor="#ffffff";
}
else
{
trBottom.style.backgroundColor="#969696";//eaeaea
}
if(bottomPointer==8)
{
trTop.style.backgroundColor="#ffffff";
}
else
{
trTop.style.backgroundColor="#969696";//eaeaea
}
}
setSelected(option);
}
var moveSelectedDown=function()
{
if(!visible)
{
return;
}
var option=selectedOption;
var length=filteredOptions.length;
if(length<0)
{
return;
}
var position=0;
if(option==null)
{
option=filteredOptions[0];
}
else
{
for(var i=0;i<filteredOptions.length;i++)
{
var o=filteredOptions[i];
if(o==option)
{
var position=(i<filteredOptions.length-1)?i+1:0;
option=filteredOptions[position];
break;
}
}
}
if(position==0)
{
bottomPointer=8;
}
else if(position>=bottomPointer)
{
bottomPointer++;
}
if(length>8)
{
var top=bottomPointer-8;
for(var i=length-1;i>=0;i--)
{
var tr=filteredOptions[i];
if(i<bottomPointer&&i>=bottomPointer-8)
{
tr.style.display="";
}
else
{
tr.style.display="none";
}
}
if(bottomPointer>=length)
{
trBottom.style.backgroundColor="#ffffff";
}
else
{
trBottom.style.backgroundColor="#969696";//eaeaea
}
if(bottomPointer==8)
{
trTop.style.backgroundColor="#ffffff";
}
else
{
trTop.style.backgroundColor="#969696";//eaeaea
}
}
setSelected(option);
}
var show=function(x,y,width,height)
{
if(targetFocused!=true)
{
return;
}
main.show(x,y);
visible=true;
var w=main.getClientWidth();
var h=main.getClientHeight();
var nx=0;
var ny=0;
if(x+w>parseInt((document.body.clientWidth)))
{
nx=x-w+target.clientWidth;
}
else
{
nx=x;
}
if(y+h>parseInt(document.body.clientHeight))
{
ny=y-h-target.clientHeight;
}
else
{
ny=y;
}
main.setPosition(nx,ny);
}
var hidden=function()
{
filteredOptions=new Array();
selectedOption=null;
visible=false;
main.hidden();
}
var showOptions=function(value)
{
selectedOption=null;
var srcTarget=target;
table=document.createElement("table");
table.style.borderCollapse="collapse";
table.border="1";
table.style.backgroundColor="#eaeaea";
table.borderColor="#808080";
table.onmouseover=function(){mouseOnThePane=true;};
table.onmouseout=function(){mouseOnThePane=false;};
var tbody=document.createElement("tbody");
table.appendChild(tbody);
main.hidden();
if(!value)
{
value=srcTarget.value;
}
if(value==null)
{
value="";
}
filteredOptions=new Array();
var filtereds=0;
for(var i=0;i<objects.length;i++)
{
var o=objects[i];
var v=""+o[valueProp];
if(v.indexOf(value)==0)
{
var tr=document.createElement("tr");
var td=document.createElement("td");
var text=""+v+" - ";
for(var j=0;j<textProps.length;)
{
var tp=textProps[j];
- 1
- 2
- 3
- 4
- 5
前往页