123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767 |
- <!--/******************************************************************
- ** 文件名: KDComboBox.htc
- ** Copyright (c) 2005 金蝶国际软件集团有限公司 研发中心
- ** http://www.kingdee.com
- **
- ** 创建人: 叶汉良
- ** 日 期: 2005.06.01
- **
- ** 描述:下拉选择框控件
- ** 版 本:Web V1.0
- ******************************************************************/-->
- <public:component tagName="KDComboBox">
- <public:attach event="oncontentready" onevent="kdComboBoxReady()" />
- <public:attach event="onpropertychange" onevent="kdComboBoxPropertyChange()"/>
- <public:event name="onEvtIndexChange" id="evtIndexChange"/>
- <public:event name="onEvtClick" id="evtClick"/>
- <public:event name="onEvtDblClick" id="evtDblClick"/>
- <public:event name="onEvtMouseDown" id="evtMouseDown"/>
- <public:event name="onEvtMouseUp" id="evtMouseUp"/>
- <public:event name="onEvtMouseOver" id="evtMouseOver"/>
- <public:event name="onEvtMouseOut" id="evtMouseOut"/>
- <public:event name="onEvtMouseMove" id="evtMouseMove"/>
- <public:event name="onEvtFocus" id="evtFocus"/>
- <public:event name="onEvtBlur" id="evtBlur"/>
- <public:event name="onEvtKeyDown" id="evtKeyDown"/>
- <public:event name="onEvtKeyUp" id="evtKeyUp"/>
- <public:event name="onEvtKeyPress" id="evtKeyPress"/>
- <public:event name="onEvtChange" id="evtChange"/>
- <public:event name="onEvtBeforePaste" id="evtBeforePaste"/>
- <public:event name="onEvtSelectStart" id="evtSelectStart"/>
- <public:property name="initializeBorderColor" value="#B4B4B4"/>
- <public:property name="initializeBGColor" value="#FFFFFF"/>
- <public:property name="initializeTextFontColor" value="#000000"/>
- <public:property name="focusBorderColor" value="#5C85B3"/>
- <public:property name="focusBGColor" value="#255EA2"/>
- <public:property name="focusTextFontColor" value="#FFFFFF"/>
- <public:property name="readonlyBorderColor" value="#B4B4B4"/>
- <public:property name="readonlyBGColor" value="#FFFFFF"/>
- <public:property name="readonlyTextFontColor" value="#777777"/>
- <public:property name="disableBorderColor" value="#B4B4B4"/>
- <public:property name="disableBGColor" value="#D9D9D0"/>
- <public:property name="disableTextFontColor" value="#777777"/>
- <public:property name="mustBorderColor" value="#B4B4B4"/>
- <public:property name="mustBGColor" value="#FCFBDF"/>
- <public:property name="mustTextFontColor" value="#000000"/>
- <public:property name="width" value="170"/>
- <public:property name="height" value="19"/>
- <public:property name="dropHeight" value=""/>
- <public:property name="useDropHeight" value="false"/>
- <public:property name="cellHeight" value="16"/>
- <public:property name="readonly" value="false"/>
- <public:property name="disable" value="false"/>
- <public:property name="canEdit" value="false"/>
- <public:property name="mustInput" value="false"/>
- <public:property name="mustInputMsg" value=""/>
- <public:property name="name" value=""/>
- <public:property name="value" value=""/>
- <public:property name="id" value=""/>
- <public:property name="IDName" value=""/>
- <public:property name="IDValue" value=""/>
- <public:property name="maxLength" value=""/>
- <public:property name="fontSize" value="9pt"/>
- <public:property name="fontFamily" value="宋体"/>
- <public:property name="tabIndex1" value=""/>
- <public:property name="imagePath" value="../images/"/>
- <public:property name="cssPath" value=""/>
- <public:property name="tips" value=""/>
- <public:property name="align" value="left"/>
- <public:property name="iconWidth" value="18"/>
- <public:method name="focus"/>
- <public:method name="loadXML"/>
- <public:method name="addItem"/>
- <public:method name="insertItem"/>
- <public:method name="delItem"/>
- <public:method name="clearItems"/>
- <public:method name="updateItem"/>
- <public:method name="getCount"/>
- <public:method name="getSelectedIndex"/>
- <public:method name="setSelectedIndex"/>
- <public:method name="getIndexByID"/>
- <public:method name="getIndexByDesc"/>
- <public:method name="getItemID"/>
- <public:method name="setItemID"/>
- <public:method name="getItemDesc"/>
- <public:method name="setItemDesc"/>
- <public:method name="getItemData"/>
- <public:method name="setItemData"/>
- <script language="Javascript">
- var sTable = "<table border=0 style='table-layout:fixed;display:inline;' cellspacing=0 cellpadding=0>";
- var sListDiv = "<div style='border-style:solid;border-width:0;>";
- var sListTable = "<table style='table-layout:fixed;' border='0' cellpadding='1' cellspacing='1'>";
- var sInput = "<input type='text' style='border-width:0;padding-left:3;'>";
- var sHidden = "<input type='hidden' value=''>";
- var oTableE;
- var oTdInputE;
- var oTdDropE;
- var oImgE;
- var oInputE;
- var oHiddenE;
- var oListDivE = window.document.createElement(sListDiv);
- var oListTableE = window.document.createElement(sListTable);
- var sImageInit = "";
- var sImageForbit = "";
- var sImageDrop = "";
- //下拉菜单是否已经打开
- var isOpened = false;
- //弹出窗口
- var popWin = window.createPopup();
- //时间处理对象
- var oTimer = null;
- //当前选择的项
- var iSelectedIndex = -1;
- //是否全选
- var isSelectStart = false;
- /**
- *控件初始化
- *
- */
- function kdComboBoxReady()
- {
- initCss();
-
- var sItems = "";
- if (element.children(0).tagName == "ITEMS")
- {
- sItems = element.innerHTML;
- }
- else
- {
- sItems = element.itemHTML;
- }
-
- var sInnerHTML = "";
- sInnerHTML += sTable + "<tr>";
- sInnerHTML += "<td valign='top'>" + sInput + sHidden + "</td>";
- sInnerHTML += "<td><img></td>";
- sInnerHTML += "</tr></table>";
- element.innerHTML = sInnerHTML;
- element.itemHTML = sItems;
-
- oTableE = element.children(0);
- element.style.borderWidth = 0;
- oTableE.style.borderWidth = 1;
- oTableE.style.borderStyle = "solid";
- oTableE.style.width = width;
-
- //操作的左右单元格
- oTdInputE = element.children(0).rows(0).cells(0);
- oTdInputE.style.paddingTop = 0;
- oTdDropE = element.children(0).rows(0).cells(1);
- oInputE = oTdInputE.children(0);
- oHiddenE = oTdInputE.children(1);
- oImgE = oTdDropE.children(0);
-
- //初始化的时候的相关边框颜色设置
- oTableE.borderColor = initializeBorderColor;
- oTableE.style.backgroundColor = initializeBGColor;
-
- oTdInputE.style.width = width - iconWidth - 3;
- //表格有宽度,所以需要单元格高度-2
- oTdInputE.style.height = height - 2;
- oTdInputE.style.paddingLeft = 1;
-
- oTdDropE.style.width = iconWidth;
- oTdDropE.style.height = height - 2;
-
- oImgE.style.width = iconWidth;
- oImgE.style.height = height - 2;
-
- //不可用状态(注意不直接使用text的disabled属性,否则修改不了颜色
- if (eval(disable) == true)
- {
- oTableE.borderColor = disableBorderColor;
- oTableE.style.backgroundColor = disableBGColor;
- oInputE.style.backgroundColor = disableBGColor;
- oInputE.style.color = disableTextFontColor;
-
- //此处不使用disabled这个属性,否则文字的颜色无法进行修改
- oInputE.readOnly = true;
- oImgE.src = sImageForbit;
- oInputE.tabIndex = "";
- }
- else
- {
- //只读状态
- if (eval(readonly) == true)
- {
- oTableE.borderColor = readonlyBorderColor;
- oTableE.style.backgroundColor = readonlyBGColor;
- oInputE.style.backgroundColor = readonlyBGColor;
- oInputE.style.color = readonlyTextFontColor;
- oInputE.readOnly = true;
- }
- else
- {
- //初始状态
- if (eval(mustInput) == false)
- {
- oTableE.borderColor = initializeBorderColor;
- oTableE.style.backgroundColor = initializeBGColor;
- oInputE.style.backgroundColor = initializeBGColor;
- oInputE.style.color = initializeTextFontColor;
- }
- else
- {
- oTableE.borderColor = mustBorderColor;
- oTableE.style.backgroundColor = mustBGColor;
- oInputE.style.backgroundColor = mustBGColor;
- oInputE.style.color = mustTextFontColor;
- }
- //可编辑状态
- if (eval(canEdit) != true)
- {
- oInputE.readOnly = true;
- }
- }
- oImgE.src = sImageInit;
- oInputE.tabIndex = tabIndex1;
- }
-
- //向下偏移计算值的像素
- if (height >= 19)
- {
- oInputE.style.paddingTop = 2 + (height - 19) / 5;
- }
-
- oInputE.style.fontSize = fontSize;
- oInputE.value = value;
- oInputE.name = name;
- oInputE.id = id;
- oInputE.valueChanged = false;
- oInputE.isInit = true;
- oInputE.style.width = width - iconWidth - 4;
- oInputE.style.height = height - 4;
- oInputE.title = tips;
- oInputE.style.textAlign = align;
- oInputE.style.fontFamily = fontFamily;
-
- if (maxLength != null && maxLength != "")
- {
- element.children(0).maxLength = maxLength;
- }
-
- oHiddenE.name = IDName;
- oHiddenE.value = IDValue;
-
- loadXML(sItems,true);
- oListDivE.appendChild(oListTableE);
- doEvents();
- setPop(popWin.document.body);
- }
- /**
- *事件处理
- *
- */
- function doEvents()
- {
- oTableE.attachEvent("onclick",function(){execute("click")});
- oTableE.attachEvent("onmousedown",function(){execute("mousedown")});
- oTableE.attachEvent("onmouseover",function(){execute("mouseover")});
- oTableE.attachEvent("onmouseout",function(){execute("mouseout")});
- oTableE.attachEvent("onmouseup",function(){execute("mouseup")});
- oTableE.attachEvent("onmousemove",function(){execute("mousemove")});
- oTableE.attachEvent("onchange",function(){execute("change")});
- oTableE.attachEvent("oncontextmenu",function(){return false});
-
- oInputE.attachEvent("onfocus",function(){execute("focus")});
- oInputE.attachEvent("onblur",function(){execute("blur")});
- oInputE.attachEvent("onkeydown",function(){execute("keydown")});
- oInputE.attachEvent("onkeyup",function(){execute("keyup")});
- oInputE.attachEvent("onkeypress",function(){return execute("keypress")});
- oInputE.attachEvent("onselectstart",function(){return execute("selectstart")});
- oInputE.attachEvent("onbeforepaste",function(){return execute("beforepaste")});
- oInputE.attachEvent("ondblclick",function(){execute("dblclick")});
-
- }
- /**
- *属性值发生相关变化的时候处理方式
- *
- */
- function kdComboBoxPropertyChange()
- {
- switch(event.propertyName.toString().toLowerCase())
- {
- case "width":
- {
- oTableE.style.width = width;
- oTdInputE.style.width = width - iconWidth - 3;
- oInputE.style.width = width - iconWidth - 4;
- break;
- }
- case "height":
- {
- oTdInputE.style.height = height - 2;
- oInputE.style.height = height - 4;
- oImgE.style.height = height - 2;
- if (height >= 19)
- {
- oInputE.style.paddingTop = 3 + (height - 19) / 5;
- }
- else
- {
- oInputE.style.paddingTop = 0;
- }
- break;
- }
-
- //初始化颜色发生了变化
- case "initializebordercolor":
- {
- if (eval(disable) != true && eval(readonly) != true)
- {
- oTableE.borderColor = initializeBorderColor;
- }
- break;
- }
- case "initializebgcolor":
- {
- if (eval(disable) != true && eval(readonly) != true)
- {
- oInputE.style.backgroundColor = initializeBGColor;
- }
- break;
- }
- case "initializetextfontColor":
- {
- if (eval(disable) != true && eval(readonly) != true)
- {
- oInputE.style.color = initializeTextFontColor;
- }
- break;
- }
-
- //只读颜色发生了变化
- case "readonlybordercolor":
- {
- if (eval(disable) != true && eval(readonly) == true)
- {
- oTableE.borderColor = readonlyBorderColor;
- }
- break;
- }
- case "readonlybgcolor":
- {
- if (eval(disable) != true && eval(readonly) == true)
- {
- oInputE.style.backgroundColor = readonlyBGColor;
- }
- break;
- }
- case "readonlytextfontcolor":
- {
- if (eval(disable) != true && eval(readonly) == true)
- {
- oInputE.style.color = readonlyTextFontColor;
- }
- break;
- }
-
- //disable的时候颜色发生了变化
- case "disablebordercolor":
- {
- if (eval(disable) == true)
- {
- oTableE.borderColor = disableBorderColor;
- }
- break;
- }
- case "disablebgcolor":
- {
- if (eval(disable) == true)
- {
- oInputE.style.backgroundColor = disableBGColor;
- }
- break;
- }
- case "disabletextfontcolor":
- {
- if (eval(disable) == true)
- {
- oInputE.style.color = disableTextFontColor;
- }
- break;
- }
- //值发生了变化
- case "value":
- {
- doValueChange();
- break;
- }
- //只读发生了变化
- case "readonly":
- {
- if (eval(disable) != true)
- {
- //变化为只读状态
- if (eval(readonly) == true)
- {
-
- oTableE.borderColor = readonlyBorderColor;
- oTableE.style.backgroundColor = readonlyBGColor;
- oInputE.style.backgroundColor = readonlyBGColor;
- oInputE.style.color = readonlyTextFontColor;
- oInputE.readOnly = true;
- }
- else
- {
- oTableE.borderColor = initializeBorderColor;
- oTableE.style.backgroundColor = initializeBGColor;
- oInputE.style.backgroundColor = initializeBGColor;
- oInputE.style.color = initializeTextFontColor;
- oInputE.readOnly = false;
- }
- }
- break;
- }
-
- //不可使用发生了变化
- case "disable":
- {
- if (eval(disable) == true)
- {
- oTableE.borderColor = disableBorderColor;
- oTableE.style.backgroundColor = disableBGColor;
- oInputE.style.backgroundColor = disableBGColor;
- oInputE.style.color = disableTextFontColor;
- oTdDropE.children(0).src = sImageForbit;
- oInputE.readOnly = true;
- oInputE.tabIndex = "";
- }
- else
- {
- //变化为只读状态
- if (eval(readonly) == true)
- {
- oTableE.borderColor = readonlyBorderColor;
- oTableE.style.backgroundColor = readonlyBGColor;
- oInputE.style.backgroundColor = readonlyBGColor;
- oInputE.style.color = readonlyTextFontColor;
- oInputE.readOnly = true;
- }
- else
- {
- if (eval(mustInput) == true)
- {
- oTableE.borderColor = mustBorderColor;
- oTableE.style.backgroundColor = mustBGColor;
- oInputE.style.backgroundColor = mustBGColor;
- oInputE.style.color = mustTextFontColor;
- }
- else
- {
- oTableE.borderColor = initializeBorderColor;
- oTableE.style.backgroundColor = initializeBGColor;
- oInputE.style.backgroundColor = initializeBGColor;
- oInputE.style.color = initializeTextFontColor;
- }
-
- if (eval(canEdit) == true)
- {
- oInputE.readOnly = false;
- }
- else
- {
- oInputE.readOnly = true;
- }
-
- }
- oTdDropE.children(0).src = sImageInit;
- oInputE.tabIndex = tabIndex1;
- }
- break;
- }
- case "fontsize":
- {
- oInputE.style.fontSize = fontSize;
- break;
- }
- case "tips":
- {
- oInputE.title = tips;
- }
-
- default:
- break;
- }
- }
- //执行相关的事件
- function execute(sEvent)
- {
- //不可处理状态下,不能进行处理
- if (eval(disable) == true || eval(readonly) == true)
- {
- return false;
- }
-
- if (sEvent == "click")
- {
- evtClick.fire();
- }
- else if (sEvent == "mouseup")
- {
- return doMouseUp();
- }
- else if (sEvent == "mousedown")
- {
- return doMouseDown();
- }
- else if (sEvent == "mousemove")
- {
- evtMouseMove.fire();
- }
- else if (sEvent == "mouseover")
- {
- evtMouseOver.fire();
- }
- else if (sEvent == "mouseout")
- {
- evtMouseOut.fire();
- }
- else if (sEvent == "keyup")
- {
- return doKeyUp();
- }
- else if (sEvent == "keydown")
- {
- return doKeyDown();
- }
- else if (sEvent == "keypress")
- {
- return doKeyPress();
- }
- else if (sEvent == "change")
- {
- evtChange.fire();
- }
- else if (sEvent == "beforepaste")
- {
- return doBeforePaste();
- }
- else if (sEvent == "selectstart")
- {
- return doSelectStart();
- }
- //可以修改边框的相关的颜色
- else if (sEvent == "focus")
- {
- oTableE.borderColor = focusBorderColor;
- oInputE.style.backgroundColor = focusBGColor;
- oInputE.style.color = focusTextFontColor;
- moveCursor(oInputE,oInputE.value.length);
- evtFocus.fire();
- }
- else if (sEvent == "blur")
- {
- if (eval(mustInput) == false)
- {
- oTableE.borderColor = initializeBorderColor;
- oInputE.style.backgroundColor = initializeBGColor;
- oInputE.style.color = initializeTextFontColor;
- }
- else
- {
- oTableE.borderColor = mustBorderColor;
- oInputE.style.backgroundColor = mustBGColor;
- oInputE.style.color = mustTextFontColor;
- if (oInputE.value == "" && mustInputMsg != "")
- {
- alert(mustInputMsg);
- }
- }
- evtBlur.fire();
- }
- else if (sEvent == "dblclick")
- {
- evtDblClick.fire();
- }
- }
- //得到焦点
- function focus()
- {
- if (eval(disable) == true)
- {
- return;
- }
- execute("focus");
- oInputE.focus();
- }
- /**
- *
- *处理鼠标按下的时候的事件
- */
- function doMouseDown()
- {
- oImgE.src = sImageDrop;
- if (isOpened)
- {
- popWin.hide();
- isOpened = false;
- return;
- }
-
- var oBody = popWin.document.body;
- oBody.innerHTML = oListDivE.outerHTML;
- popWin.show(getComLeft(element),getComTop(element),width,calcHeight(),window.document.body);
- popEvent(popWin);
- gotoCell(iSelectedIndex);
- oTimer = window.setInterval(onTimer,100);
- isOpened = true;
- evtMouseDown.fire();
- event.cancelBubble = true;
- return false;
- }
- /**
- *键盘keydown事件处理
- *
- */
- function doKeyDown()
- {
- var iOldIndex = iSelectedIndex;
- //索引是否发生改变
- var isIndexChange = false;
- var popTable = null;
- if (iSelectedIndex != -1)
- {
- popTable = getPopTable(popWin);
- if (popTable != null)
- {
- updateStyle(popTable.rows[iSelectedIndex].cells[0],initializeBGColor,initializeTextFontColor);
- }
- }
- switch (event.keyCode)
- {
- //Down
- case 40:
- if (getCount() != 0)
- {
- if (iSelectedIndex < getCount() - 1)
- {
- iSelectedIndex ++;
- }
- }
- else
- {
- iSelectedIndex = -1;
- }
- break;
- //Up
- case 38:
- if (getCount() != 0)
- {
- if (iSelectedIndex > 0)
- {
- iSelectedIndex --;
- }
- }
- else
- {
- iSelectedIndex = -1;
- }
- break;
- //Page Up
- case 33:
- if (getCount() != 0)
- {
- //向上滚动5行(如果达到最顶,则取第一项
- if (iSelectedIndex - 5 > 0)
- {
- iSelectedIndex -= 5;
- }
- else
- {
- iSelectedIndex = 0;
- }
- }
- else
- {
- iSelectedIndex = -1;
- }
- break;
- //Page Down
- case 34:
- if (getCount() != 0)
- {
- //向下滚动5行,如果到达尾,则取最后一项
- if (iSelectedIndex + 5 < getCount() -1)
- {
- iSelectedIndex += 5;
- }
- else
- {
- iSelectedIndex = getCount() - 1;
- }
- }
- else
- {
- iSelectedIndex = -1;
- }
- break;
- //End
- case 35:
- //在不可编辑状态下才支持end键操作
- if (canEdit == "false")
- {
- if (getCount() != 0)
- {
- iSelectedIndex = getCount() - 1;
- }
- else
- {
- iSelectedIndex = -1;
- }
- }
- break;
- //Home
- case 36:
- //在不可编辑下才支持home键操作
- if (canEdit == "false")
- {
- if (getCount() != 0)
- {
- iSelectedIndex = 0;
- }
- else
- {
- iSelectedIndex = -1;
- }
- }
- break;
- //Enter
- case 13:
- if (isOpened == true)
- {
- popWin.hide();
- isOpened = false;
- }
- break;
- //ESC
- case 27:
- if (isOpened == true)
- {
- popWin.hide();
- isOpened = false;
- }
- break;
- default:
- break;
- }
-
- //如果下拉列表已经打开,则需要把位置定在相关的位置上
- if (event.keyCode == 40 || event.keyCode == 38 || event.keyCode == 33 ||
- event.keyCode == 34 || event.keyCode == 35 || event.keyCode == 36 ||
- event.keyCode == 13 || event.keyCode == 27)
- {
- if (isOpened == true)
- {
- gotoCell(iSelectedIndex);
- }
-
- if (iSelectedIndex != -1)
- {
- //home,end键应该根据canEdit做特殊的处理
- if (event.keyCode == 35 || event.keyCode == 36)
- {
- if (canEdit == "false")
- {
- setSelectedItem(oListTableE.rows[iSelectedIndex].cells[0]);
- moveCursor(oInputE,oInputE.value.length);
- }
- }
- else
- {
- setSelectedItem(oListTableE.rows[iSelectedIndex].cells[0]);
- moveCursor(oInputE,oInputE.value.length);
- }
- }
- if (iOldIndex != iSelectedIndex)
- {
- isIndexChange = true;
- }
- }
- oInputE.oldValue = oInputE.value;
- evtKeyDown.fire();
-
- if (eval(canEdit) == false)
- {
- if (event.keyCode != 9)
- {
- event.returnValue = false;
- }
- }
- event.cancelBubble = true;
-
- //索引发生了变化,触发
- if (isIndexChange == true)
- {
- //索引发生了变化
- evtIndexChange.fire();
- //数据发生了变化
- evtChange.fire();
- }
- doEnterGo();
- }
- /**
- *键盘keyup处理
- *
- */
- function doKeyUp()
- {
- var iOldIndex = iSelectedIndex;
- //是否是控制键,up,down,home,end,enter,esc,page up,page down
- var isControlKey = true;
- var iCurPos = getCursorPosition();
- if (!(event.keyCode == 40 || event.keyCode == 38 || event.keyCode == 33 ||
- event.keyCode == 34 || event.keyCode == 35 || event.keyCode == 36 ||
- event.keyCode == 13 || event.keyCode == 27))
- {
- isControlKey = false;
- iSelectedIndex = getIndexByDesc(oInputE.value);
- }
-
- if (iSelectedIndex != -1)
- {
- setSelectedItem(oListTableE.rows[iSelectedIndex].cells[0],true);
-
- if (isOpened == true)
- {
- gotoCell(iSelectedIndex);
- }
- }
- else
- {
- oInputE.itemid = null;
- oInputE.desc = oInputE.value;
- oInputE.data = null;
- oInputE.selected = null;
- oInputE.valueChanged = true;
- oHiddenE.value = null;
- value = oInputE.value;
- }
-
- if (isControlKey == false && isSelectStart == false)
- {
- moveCursor(oInputE,iCurPos);
- isSelectStart = false;
- }
-
- evtKeyUp.fire();
- if (canEdit == "false")
- {
- event.returnValue = false;
- }
- event.cancelBubble = true;
- //非控制键发生变化的时候也需要处理索引变化事件
- if (isControlKey == false && iOldIndex != iSelectedIndex)
- {
- evtIndexChange.fire();
- }
- //数据发生了变化,数据变化处理事件
- if (isControlKey == false && oInputE.value != oInputE.oldValue)
- {
- evtChange.fire();
- }
- }
- /**
- *鼠标按键按着的时候处理事件
- *
- */
- function doKeyPress()
- {
- event.cancelBubble = true;
- evtKeyPress.fire();
- return true;
- }
- /**
- *value属性的值发生变化的时候处理的函数
- *
- */
- function doValueChange()
- {
- //加载KDComboBox的时候不处理doValueChange
- if (oInputE.isInit)
- {
- oInputE.isInit = false;
- return;
- }
-
- //如果先改变oInputE.value,则不能再次修改oInputE的值
- if (oInputE.valueChanged != true)
- {
- iSelectedIndex = getIndexByDesc(value);
- if (iSelectedIndex != -1)
- {
- var oCell = oListTableE.rows[iSelectedIndex].cells[0];
- oInputE.itemid = oCell.itemid;
- oInputE.desc = oCell.desc;
- oInputE.data = oCell.data;
- oInputE.selected = oCell.selected;
- oHiddenE.value = oCell.itemid;
- if (isOpened == true)
- {
- gotoCell(iSelectedIndex);
- }
- }
- else
- {
- oInputE.itemid = null;
- oInputE.desc = value;
- oInputE.data = null;
- oInputE.value = value;
- oInputE.selected = null;
- oHiddenE.value = null;
- }
- evtChange.fire();
- }
- oInputE.valueChange = false;
- }
- /**
- *处理粘贴前的动作
- *
- */
- function doBeforePaste()
- {
- if (eval(disable) == true || eval(readonly) == true || eval(canEdit) == false)
- {
- return false;
- }
-
- clipboardData.setData('text',clipboardData.getData('text'));
- iSelectedIndex = getIndexByDesc(oInputE.value);
- if (iSelectedIndex != -1)
- {
- setSelectedItem(oListTableE.rows[iSelectedIndex].cells[0],true);
-
- if (isOpened == true)
- {
- gotoCell(iSelectedIndex);
- }
- }
- else
- {
- oInputE.itemid = null;
- oInputE.desc = oInputE.value;
- oInputE.data = null;
- oInputE.selected = null;
- oInputE.valueChanged = true;
- oHiddenE.value = null;
- value = oInputE.value;
- }
- evtBeforePaste.fire();
- return true;
- }
- /**
- *选中某一块时的事件
- *
- */
- function doSelectStart()
- {
- evtSelectStart.fire();
- isSelectStart = true;
- if (canEdit == "false")
- {
- return false;
- }
- else
- {
- return true;
- }
- }
- /**
- *回车键的时候跳到其他焦点
- *
- */
- function doEnterGo()
- {
- if (event.keyCode == 13 && isOpened == false)
- {
- event.keyCode = 9;
- }
- }
- //处理鼠标放开的时候的事件
- function doMouseUp()
- {
- oImgE.src = sImageInit;
- if (event.srcElement.tagName == "IMG")
- {
- oInputE.focus();
- }
- evtMouseUp.fire();
- }
- function doMouseOut()
- {
- oImgE.src = sImageInit;
- evtMouseMove.fire();
- }
- /**
- *
- *定位到某个单元格
- *@rowId是表格行号
- */
- function gotoCell(rowIndex)
- {
- if (!oListDivE)
- {
- return false;
- }
- //非表格行
- if (!isTableRow(rowIndex))
- {
- return false;
- }
-
- var tbl = getPopTable(popWin);
-
- if (tbl == null)
- {
- return false;
- }
-
- if (tbl.tagName == "TABLE")
- {
- var oRow;
- var iTop;
- oRow = tbl.rows[rowIndex];
- updateStyle(oRow.cells[0],focusBGColor,focusTextFontColor);
- var iTop = oRow.offsetTop - element.scrollTop;
- if (iTop > 0 && (iTop + oRow.offsetHeight) > oListDivE.offsetHeight)
- {
- oRow.scrollIntoView(false);
- }
- else if (iTop <= 0)
- {
- oRow.scrollIntoView(true);
- }
- }
- }
- /**
- * rowId是否是表格中的行
- *
- */
- function isTableRow(rowId)
- {
- if (!oListDivE)
- {
- return false;
- }
- var tbl = oListDivE.childNodes[0];
- if (!tbl)
- {
- return false;
- }
-
- if (rowId >= 0 && rowId < tbl.rows.length)
- {
- return true;
- }
- else
- {
- return false;
- }
- }
- /**
- *得到控件oCom的绝对坐标x
- *
- */
- function getComLeft(oCom)
- {
- var iLeft = 0;
- while (oCom.offsetParent)
- {
- iLeft += oCom.offsetLeft - oCom.scrollLeft;
- oCom = oCom.offsetParent;
- }
- iLeft += oCom.clientLeft - oCom.scrollLeft;
- return iLeft;
- }
- /**
- *得到控件oCom的绝对坐标y
- *
- */
- function getComTop(oCom)
- {
- var iScrollTop;
- var iTop = oCom.offsetTop;
- var iCalcHight = calcHeight();
-
- while (oCom.offsetParent)
- {
- iTop += oCom.offsetTop - oCom.scrollTop;
- oCom = oCom.offsetParent;
- }
- iTop += oCom.clientTop - oCom.scrollTop;
-
- //如果下拉的窗体超出了最底的显示宽度,则向上弹出列表
- if (iTop + parseInt(height) + 3 + iCalcHight + window.screenTop > screen.height)
- {
- iTop = iTop - iCalcHight - 2;
- }
- else
- {
- iTop += parseInt(height);
- }
-
- return iTop;
- }
- /**
- *时钟处理(目的为了能够在其他地方关闭了下拉列表的时候,能够把isOpened参数设置为false)
- *
- */
-
- function onTimer()
- {
- if (popWin.isOpen == false)
- {
- isOpened = false;
- window.clearInterval(oTimer);
- }
- }
- /**
- *加载数据,oData为对象,isClear表明是否清楚原来的数据
- *
- */
- function loadData(oData,isClear)
- {
- if (!oData)
- {
- return;
- }
- if (isClear && isClear == true)
- {
- clearItems();
- }
- for (var i = 0; i < oData.length; i ++)
- {
- addItem(oData[i].itemid,oData[i].desc,oData[i].data,oData[i].selected);
- }
- }
- /**
- *往下来框中增加一项(itemID是标识本项,desc显示在下拉框中的信息,
- *data为其他需要填充的信息,selected表示加入的是选择项)
- *
- */
- function addItem(itemID,desc,data,selected)
- {
- var oRow = oListTableE.insertRow();
- var oCell = oRow.insertCell();
- setCellProperty(oCell,itemID,desc,data,selected);
-
- if (selected && eval(selected) == true)
- {
- iSelectedIndex = oRow.rowIndex;
- setSelectedItem(oListTableE.rows[iSelectedIndex].cells[0]);
- }
- }
- /**
- *在index指定的索引前增加一项
- *
- */
- function insertItem(index,itemID,desc,data,selected)
- {
- if (isTableRow(index) == false)
- {
- return;
- }
- var oRow = oListTableE.insertRow(index);
- var oCell = oRow.insertCell();
- setCellProperty(oCell,itemID,desc,data,selected);
-
- if (selected && selected == true)
- {
- iSelectedIndex = oRow.rowIndex;
- setSelectedItem(oListTableE.rows[iSelectedIndex].cells[0]);
- }
- }
- /**
- *设置单元格的属性
- *
- */
- function setCellProperty(oCell,itemID,desc,data,selected)
- {
- oCell.itemid = itemID;
- oCell.desc = desc;
- oCell.data = data;
- oCell.selected = selected;
- oCell.innerHTML = "<font size='2'>" + desc + "</font>";
- oCell.title = desc;
- oCell.fontSize = "9px";
- oCell.style.height = cellHeight;
- oCell.style.paddingTop = 2;
- oCell.style.cursor = "hand";
- oCell.style.paddingLeft = 3;
- oCell.style.backgroundColor = initializeBGColor;
- oCell.style.color = initializeTextFontColor;
- }
- /**
- *清空下拉框中的所有数据
- *
- */
- function clearItems()
- {
- //这种处理速度比较快
- for (var i = getCount() - 1; i >= 0; i --)
- {
- delItem(i);
- }
- //setNoSelectItem();
- }
- /**
- *删除指定的项(index为需要删除的索引)
- *
- */
- function delItem(index)
- {
- if (isTableRow(index) == false)
- {
- return;
- }
- if (isOpened == true)
- {
- isOpened = false;
- popWin.hide();
- }
- oListTableE.deleteRow(index);
- if (index == iSelectedIndex)
- {
- setNoSelectItem();
- }
- }
- /**
- *当没有选中的时候,设置空值
- *
- */
- function setNoSelectItem()
- {
- iSelectedIndex = -1;
- oInputE.itemID = null;
- oInputE.desc = null;
- oInputE.data = null;
- oInputE.selected = null;
- oInputE.value = "";
- oHiddenE.value = null;
- value = "";
- }
- /**
- *得到下拉框的项数
- *
- */
- function getCount()
- {
- return oListTableE.rows.length;
- }
- /**
- *得到当前选择的下拉的选择索引
- *
- */
- function getSelectedIndex()
- {
- return iSelectedIndex;
- }
- /**
- *设置当前的选择项
- *
- */
- function setSelectedIndex(index)
- {
- if (isTableRow(index) == false)
- {
- return;
- }
- setSelectedItem(oListTableE.rows[index].cells[0]);
- }
- /**
- *根据人机工程规范计算下拉框的显示高度
- *
- */
- function calcHeight()
- {
- //通过dropHeight属性强行设置下拉框的高度
- if (eval(useDropHeight) == false)
- {
- if (getCount() >= 7)
- {
- return (parseInt(cellHeight) + 1) * 7 + 3;
- }
- else
- {
- return (getCount() * (parseInt(cellHeight) + 1) + 3);
- }
- }
- else
- {
- return parseInt(dropHeight);
- }
- }
- /**
- *设置弹出的下拉列表的属性
- *
- */
- function setPop(popBody)
- {
- popBody.style.borderStyle = "solid";
- popBody.style.borderWidth = "1px";
- popBody.style.borderColor = focusBorderColor;
- popBody.style.overflowX = "hidden";
- popBody.style.overflowY = "auto";
- popBody.style.scrollbarFaceColor = "#e3e3d1";
- popBody.style.fontSize = "9pt";
- popBody.style.scrollbarShadowColor = "#d5d2c4";
- popBody.style.scrollbarArrowColor = "0f59dd";
- popBody.style.scrollbarTrackColor = "#d5d2c4";;
- //popBody.style.backgroundColor = "#ecece8";
- }
- /**
- *弹出的下拉列表中的mouseover,mouseout,mousedown事件处理
- *
- */
- function popEvent(pop)
- {
- var popTable = getPopTable(pop);
- if (popTable == null)
- {
- return;
- }
- for (var i = 0; i < popTable.rows.length; i ++)
- {
- popTable.rows[i].cells[0].onmousedown = popMouseDown;
- popTable.rows[i].cells[0].onmouseover = popMouseOver;
- popTable.rows[i].cells[0].onmouseout = popMouseOut;
- }
- }
- /**
- *弹出的下拉框中的mousedown事件
- *
- */
- function popMouseDown()
- {
- var iOldIndex = iSelectedIndex;
-
- iSelectedIndex = this.parentElement.rowIndex;
- oInputE.itemid = this.itemid;
- oInputE.desc = this.desc;
- oInputE.data = this.data;
- oHiddenE.value = this.itemid;
- oInputE.valueChanged = true;
- oInputE.value = this.desc;
- value = this.desc;
-
- popWin.hide();
- if (iOldIndex != iSelectedIndex)
- {
- evtIndexChange.fire();
- evtChange.fire();
- }
- }
- /**
- *弹出的下拉框中的mouseover事件
- *
- */
- function popMouseOver()
- {
- //修改已经选择项的数据
- if (iSelectedIndex != -1)
- {
- updateStyle(this.parentElement.parentElement.rows[iSelectedIndex].cells[0],initializeBGColor,initializeTextFontColor);
- }
- updateStyle(this,focusBGColor,focusTextFontColor);
- }
- /**
- *弹出的下拉框中的mouseout事件
- *
- */
- function popMouseOut()
- {
- updateStyle(this,initializeBGColor,initializeTextFontColor);
- }
- /**
- *把下拉列表中选中的item设置到input输入框中,isKeyUp表示是按键按下了
- *
- */
- function setSelectedItem(cell,isKeyUp)
- {
- if (cell == null || !cell.tagName)
- {
- return;
- }
-
- if (cell.tagName != "TD")
- {
- return;
- }
- iSelectedIndex = cell.parentElement.rowIndex;
- oInputE.itemid = cell.itemid;
- oInputE.desc = cell.desc;
- oInputE.data = cell.data;
- oHiddenE.value = cell.itemid;
- //如果按键按下,则不能设置oInputE.value的值,否则造成循环
- if (isKeyUp == true)
- {
- oInputE.valueChanged = true;
- }
- else
- {
- oInputE.value = cell.desc;
- }
- value = cell.desc;
- }
- /**
- *得到光标的位置
- *
- */
- function getCursorPosition()
- {
- var oSrc = event.srcElement;
- var textRange = element.document.selection.createRange();
- textRange.collapse(false);
- textRange.setEndPoint("StartToStart", oInputE.createTextRange());
- return textRange.text.length;
- }
- /**
- *移动光标到指定位置
- *
- */
- function moveCursor(oInput,iPos)
- {
- if (iPos > oInput.value.length)
- {
- return;
- }
- var textRange = oInput.createTextRange();
- textRange.moveStart('character',iPos);
- textRange.collapse(true);
- textRange.select();
- }
- /**
- *修改显示风格
- */
- function updateStyle(cell,bgcolor,forecolor)
- {
- cell.style.backgroundColor = bgcolor;
- cell.style.color = forecolor;
- }
- /**
- *得到弹出的下拉框中的Table对象
- *
- */
- function getPopTable(pop)
- {
- for (var i = 0 ; i < pop.document.all.length; i ++)
- {
- if (pop.document.all[i].tagName == "TABLE")
- {
- return pop.document.all[i];
- }
- }
- return null;
- }
- /**
- *使用xml格式加载数据项
- *
- */
- function loadXML(sData,isClear)
- {
- if (!sData)
- {
- return;
- }
- var xmlDOM = null;
- var xmlData = null;
- try
- {
- var xmlDOM = new ActiveXObject("Microsoft.XMLDOM");
- xmlDOM.loadXML(sData);
- var xmlData = xmlDOM.documentElement;
- }
- catch(e)
- {
- return;
- }
-
- if (xmlData == null)
- {
- return;
- }
-
- if (isClear == true)
- {
- clearItems();
- }
-
- for (var i = 0; i < xmlData.childNodes.length; i ++)
- {
- addItem(getProperty(xmlData.childNodes[i],"itemid"),
- getProperty(xmlData.childNodes[i],"desc"),
- getProperty(xmlData.childNodes[i],"data"),
- getProperty(xmlData.childNodes[i],"selected")
- );
- }
- }
- /**
- * 得到xml项中的属性(node为节点,name为属性名称)
- *
- */
- function getProperty(node,propname)
- {
- var propList = node.attributes;
- var propLength = propList.length;
- if (propLength == 0)
- {
- return null;
- }
-
- for (var i = 0; i < propLength; i ++)
- {
- if(propList.item(i).name == propname)
- {
- return propList.item(i).value;
- }
- }
- return null;
- }
- /**
- *根据index得到itemid
- *
- */
- function getItemID(index)
- {
- if (!isTableRow(index))
- {
- return;
- }
- return (oListTableE.rows[index].cells[0].itemid);
- }
- /**
- *根据index,设置id
- *
- */
- function setItemID(index,itemid)
- {
- if (!isTableRow(index))
- {
- return;
- }
- oListTableE.rows[index].cells[0].itemid = itemid;
- if (index == iSelectedIndex)
- {
- setSelectedItem(oListTableE.rows[index].cells[0]);
- }
- }
- /**
- *根据index得到desc
- *
- */
- function getItemDesc(index)
- {
- if (!isTableRow(index))
- {
- return;
- }
- return (oListTableE.rows[index].cells[0].desc);
- }
- /**
- *根据index设置desc
- *
- */
- function setItemDesc(index,desc)
- {
- if (!isTableRow(index))
- {
- return;
- }
- oListTableE.rows[index].cells[0].desc = desc;
- if (index == iSelectedIndex)
- {
- setSelectedItem(oListTableE.rows[index].cells[0]);
- }
- }
- /**
- *根据index得到data
- *
- */
- function getItemData(index)
- {
- if (!isTableRow(index))
- {
- return;
- }
- return (oListTableE.rows[index].cells[0].data);
- }
- /**
- *根据index设置data
- *
- */
- function setItemData(index,data)
- {
- if (!isTableRow(index))
- {
- return;
- }
- oListTableE.rows[index].cells[0].data = data;
- if (index == iSelectedIndex)
- {
- setSelectedItem(oListTableE.rows[index].cells[0]);
- }
- }
- /**
- *根据id值找到index值(只找第一项符合条件的)
- *
- */
- function getIndexByID(itemid)
- {
- //返回-1表示没有找到
- if (itemid == null)
- {
- return -1;
- }
- for (var i = 0; i < getCount(); i ++)
- {
- if (oListTableE.rows[i].cells[0].itemid == itemid)
- {
- return oListTableE.rows[i].rowIndex;
- }
- }
- return -1;
- }
- /**
- *根据desc的值找到index值(只找第一个符合条件的)
- *
- */
- function getIndexByDesc(desc)
- {
- //返回-1表示没有找到
- if (desc == null)
- {
- return -1;
- }
- for (var i = 0; i < getCount(); i ++)
- {
- if (oListTableE.rows[i].cells[0].desc == desc)
- {
- return oListTableE.rows[i].rowIndex;
- }
- }
- return -1;
- }
- /**
- *根据index更新数据项的值
- *
- */
- function updateItem(index,itemid,desc,data,selected)
- {
- if (!isTableRow(index))
- {
- return;
- }
- oListTableE.rows[index].cells[0].itemid = itemid;
- oListTableE.rows[index].cells[0].desc = desc;
- oListTableE.rows[index].cells[0].data = data;
- oListTableE.rows[index].cells[0].selected = selected;
- if (index == iSelectedIndex)
- {
- setSelectedItem(oListTableE.rows[index].cells[0]);
- }
- }
- /**
- *设置 css相关的属性
- *
- */
- function initCss()
- {
- if (element.currentStyle.textbox_btn_1 != null)
- {
- sImageInit = cssPath + element.currentStyle.textbox_btn_1;
- }
- else
- {
- sImageInit = imagePath + "textbox_btn_1.gif";
- }
-
- if (element.currentStyle.textbox_btnforbit != null)
- {
- sImageForbit = cssPath + element.currentStyle.textbox_btnforbit;
- }
- else
- {
- sImageForbit = imagePath + "textbox_btnforbit.gif";
- }
-
- if (element.currentStyle.textbox_btn_2 != null)
- {
- sImageDrop = cssPath + element.currentStyle.textbox_btn_2;
- }
- else
- {
- sImageDrop = imagePath + "textbox_btn_2.gif";
- }
- }
- </script>
- </public:component>
|