KDTextPassword.htc 19 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647
  1. <!--/******************************************************************
  2. ** 文件名: KDTextPassword.htc
  3. ** Copyright (c) 2005 金蝶国际软件集团有限公司 研发中心
  4. ** http://www.kingdee.com
  5. **
  6. ** 创建人: 叶汉良
  7. ** 日 期: 2005.06.13
  8. **
  9. ** 描述:密码输入控件
  10. ** 版 本:Web V1.0
  11. ******************************************************************/-->
  12. <public:component tagName="KDTextPassword" lightWeight=true>
  13. <public:attach event="oncontentready" onevent="kdTextPasswordReady()" />
  14. <public:attach event="onpropertychange" onevent="kdTextPasswordPropertyChange()"/>
  15. <public:event name="onEvtClick" id = "evtClick">
  16. <public:event name="onEvtMouseDown" id = "evtMouseDown">
  17. <public:event name="onEvtMouseUp" id = "evtMouseUp">
  18. <public:event name="onEvtMouseOver" id = "evtMouseOver">
  19. <public:event name="onEvtMouseOut" id = "evtMouseOut">
  20. <public:event name="onEvtMouseMove" id = "evtMouseMove">
  21. <public:event name="onEvtFocus" id = "evtFocus">
  22. <public:event name="onEvtBlur" id = "evtBlur">
  23. <public:event name="onEvtKeyDown" id = "evtKeyDown">
  24. <public:event name="onEvtKeyUp" id = "evtKeyUp">
  25. <public:event name="onEvtKeyPress" id = "evtKeyPress">
  26. <public:event name="onEvtChange" id = "evtChange">
  27. <public:event name="onEvtBeforePaste" id = "evtBeforePaste">
  28. <public:property name="initializeBorderColor" value="#B4B4B4"/>
  29. <public:property name="initializeBGColor" value="#FFFFFF"/>
  30. <public:property name="initializeTextFontColor" value="#000000"/>
  31. <public:property name="focusBorderColor" value="#5C85B3"/>
  32. <public:property name="focusBGColor" value="#F9F9F9"/>
  33. <public:property name="focusTextFontColor" value="#000000"/>
  34. <public:property name="readonlyBorderColor" value="#B4B4B4"/>
  35. <public:property name="readonlyBGColor" value="#FFFFFF"/>
  36. <public:property name="readonlyTextFontColor" value="#777777"/>
  37. <public:property name="disableBorderColor" value="#B4B4B4"/>
  38. <public:property name="disableBGColor" value="#D9D9D0"/>
  39. <public:property name="disableTextFontColor" value="#777777"/>
  40. <public:property name="mustBorderColor" value="#B4B4B4"/>
  41. <public:property name="mustBGColor" value="#FCFBCE"/>
  42. <public:property name="mustTextFontColor" value="#000000"/>
  43. <public:property name="width" value="170"/>
  44. <public:property name="height" value="19"/>
  45. <public:property name="readonly" value="false"/>
  46. <public:property name="disable" value="false"/>
  47. <public:property name="name" value=""/>
  48. <public:property name="value" get="getValue" put="putValue"/>
  49. <public:property name="IDName" value=""/>
  50. <public:property name="IDValue" value=""/>
  51. <public:property name="maxLength" value=""/>
  52. <public:property name="fontSize1" value="9pt"/>
  53. <public:property name="fontFamily1" value="arial"/>
  54. <public:property name="dataType" value=""/>
  55. <public:property name="tabIndex1" value=""/>
  56. <public:property name="tips" value=""/>
  57. <public:property name="mustInput" value="false"/>
  58. <public:property name="mustInputMsg" value=""/>
  59. <public:property name="align" value="left"/>
  60. <public:property name="enter2tab" value="true"/>
  61. <public:method name="focus"/>
  62. </public:component>
  63. <script language="javascript">
  64. var sValue = "";
  65. /**
  66. *初始化处理的相关内容
  67. *
  68. */
  69. function kdTextPasswordReady()
  70. {
  71. element.innerHTML = "<input type='password'/><input type='hidden'>";
  72. initCss();
  73. var oInputE = element.children(0);
  74. var oStyle = oInputE.style;
  75. oStyle.paddingLeft = 3;
  76. oStyle.width = width;
  77. oStyle.height = height;
  78. if (height >= 19)
  79. {
  80. oStyle.paddingTop = 2 + (parseInt(height) - 19) / 5;
  81. }
  82. else
  83. {
  84. oStyle.paddingTop = 0;
  85. }
  86. oStyle.borderStyle = "solid";
  87. oStyle.borderWidth = 1;
  88. element.children(0).value = sValue;
  89. oStyle.fontSize = fontSize1;
  90. oInputE.name = name;
  91. oInputE.title = tips;
  92. oStyle.textAlign = align;
  93. oStyle.fontFamily = fontFamily1;
  94. if (maxLength != null && maxLength != "")
  95. {
  96. oInputE.maxLength = maxLength;
  97. }
  98. oInputE.valueChanged = false;
  99. //不可用状态
  100. if (eval(disable) == true)
  101. {
  102. oStyle.borderColor = disableBorderColor;
  103. oStyle.backgroundColor = disableBGColor;
  104. oStyle.color = disableTextFontColor;
  105. //此处不使用disabled这个属性,否则文字的颜色无法进行修改
  106. oInputE.readOnly = true;
  107. oInputE.tabIndex = "";
  108. }
  109. else
  110. {
  111. //只读状态
  112. if (eval(readonly) == true)
  113. {
  114. oStyle.borderColor = readonlyBorderColor;
  115. oStyle.backgroundColor = readonlyBGColor;
  116. oStyle.color = readonlyTextFontColor;
  117. oInputE.readOnly = true;
  118. }
  119. //必录项
  120. else if (eval(mustInput) == true)
  121. {
  122. oStyle.borderColor = mustBorderColor;
  123. oStyle.backgroundColor = mustBGColor;
  124. oStyle.color = mustTextFontColor;
  125. }
  126. else
  127. {
  128. oStyle.borderColor = initializeBorderColor;
  129. oStyle.backgroundColor = initializeBGColor;
  130. oStyle.color = initializeTextFontColor;
  131. }
  132. oInputE.tabIndex = tabIndex1;
  133. }
  134. element.children(1).name = IDName;
  135. element.children(1).value = IDValue;
  136. oInputE.attachEvent("onclick",function(){execute("click")});
  137. oInputE.attachEvent("onmousedown",function(){execute("mousedown")});
  138. oInputE.attachEvent("onmouseover",function(){execute("mouseover")});
  139. oInputE.attachEvent("onmouseout",function(){execute("mouseout")});
  140. oInputE.attachEvent("onmouseup",function(){execute("mouseup")});
  141. oInputE.attachEvent("onmousemove",function(){execute("mousemove")});
  142. oInputE.attachEvent("onfocus",function(){execute("focus")});
  143. oInputE.attachEvent("onblur",function(){execute("blur")});
  144. oInputE.attachEvent("onkeypress",function(){return execute("keypress");});
  145. oInputE.attachEvent("onkeydown",function(){execute("keydown")});
  146. oInputE.attachEvent("onkeyup",function(){execute("keyup")});
  147. oInputE.attachEvent("onchange",function(){execute("change")});
  148. oInputE.attachEvent("onbeforepaste",function(){return execute("beforepaste");});
  149. oInputE.attachEvent("onselectstart",function(){return execute("selectstart");});
  150. }
  151. /**
  152. *属性改变时相关的属性设置
  153. *
  154. */
  155. function kdTextPasswordPropertyChange()
  156. {
  157. if (element.initcssing == true)
  158. {
  159. return;
  160. }
  161. var oStyle = element.children(0).style;
  162. switch(event.propertyName.toString().toLowerCase())
  163. {
  164. case "width":
  165. {
  166. oStyle.width = width;
  167. break;
  168. }
  169. case "height":
  170. {
  171. oStyle.height = height;
  172. break;
  173. }
  174. //初始化颜色发生了变化
  175. case "initializebordercolor":
  176. {
  177. if (eval(disable) != true && eval(readonly) != true && eval(mustInput) != true)
  178. {
  179. oStyle.borderColor = initializeBorderColor;
  180. }
  181. break;
  182. }
  183. case "initializebgcolor":
  184. {
  185. if (eval(disable) != true && eval(readonly) != true && eval(mustInput) != true)
  186. {
  187. oStyle.backgroundColor = initializeBGColor;
  188. }
  189. break;
  190. }
  191. case "initializetextfontcolor":
  192. {
  193. if (eval(disable) != true && eval(readonly) != true && eval(mustInput) != true)
  194. {
  195. oStyle.color = initializeTextFontColor;
  196. }
  197. break;
  198. }
  199. //只读颜色发生了变化
  200. case "readonlybordercolor":
  201. {
  202. if (eval(disable) != true && eval(readonly) == true)
  203. {
  204. oStyle.borderColor = readonlyBorderColor;
  205. }
  206. break;
  207. }
  208. case "readonlybgcolor":
  209. {
  210. if (eval(disable) != true && eval(readonly) == true)
  211. {
  212. oStyle.backgroundColor = readonlyBGColor;
  213. }
  214. break;
  215. }
  216. case "readonlytextfontcolor":
  217. {
  218. if (eval(disable) != true && eval(readonly) == true)
  219. {
  220. oStyle.color = readonlyTextFontColor;
  221. }
  222. break;
  223. }
  224. //disable的时候颜色发生了变化
  225. case "disablebordercolor":
  226. {
  227. if (eval(disable) == true)
  228. {
  229. oStyle.borderColor = disableBorderColor;
  230. }
  231. break;
  232. }
  233. case "disablebgcolor":
  234. {
  235. if (eval(disable) == true)
  236. {
  237. oStyle.backgroundColor = disableBGColor;
  238. }
  239. break;
  240. }
  241. case "disabletextfontcolor":
  242. {
  243. if (eval(disable) == true)
  244. {
  245. oStyle.color = disableTextFontColor;
  246. }
  247. break;
  248. }
  249. //只读发生了变化
  250. case "readonly":
  251. {
  252. if (eval(disable) != true)
  253. {
  254. //变化为只读状态
  255. if (eval(readonly) == true)
  256. {
  257. oStyle.borderColor = readonlyBorderColor;
  258. oStyle.backgroundColor = readonlyBGColor;
  259. oStyle.color = readonlyTextFontColor;
  260. element.children(0).readOnly = true;
  261. }
  262. else
  263. {
  264. if (eval(mustInput) == false)
  265. {
  266. oStyle.borderColor = initializeBorderColor;
  267. oStyle.backgroundColor = initializeBGColor;
  268. oStyle.color = initializeTextFontColor;
  269. }
  270. else
  271. {
  272. oStyle.borderColor = mustBorderColor;
  273. oStyle.backgroundColor = mustBGColor;
  274. oStyle.color = mustTextFontColor;
  275. }
  276. element.children(0).readOnly = false;
  277. }
  278. }
  279. break;
  280. }
  281. //不可使用发生了变化
  282. case "disable":
  283. {
  284. if (eval(disable) == true)
  285. {
  286. oStyle.borderColor = disableBorderColor;
  287. oStyle.backgroundColor = disableBGColor;
  288. oStyle.color = disableTextFontColor;
  289. element.children(0).readOnly = true;
  290. element.children(0).tabIndex = "";
  291. }
  292. else
  293. {
  294. if (eval(readonly) == true)
  295. {
  296. oStyle.borderColor = readonlyBorderColor;
  297. oStyle.backgroundColor = readonlyBGColor;
  298. oStyle.color = readonlyTextFontColor;
  299. element.children(0).readOnly = true;
  300. }
  301. else
  302. {
  303. if (eval(mustInput) == false)
  304. {
  305. oStyle.borderColor = initializeBorderColor;
  306. oStyle.backgroundColor = initializeBGColor;
  307. oStyle.color = initializeTextFontColor;
  308. }
  309. else
  310. {
  311. oStyle.borderColor = mustBorderColor;
  312. oStyle.backgroundColor = mustBGColor;
  313. oStyle.color = mustTextFontColor;
  314. }
  315. element.children(0).readOnly = false;
  316. }
  317. if (tabIndex1 != "")
  318. {
  319. element.children(0).tabIndex = tabIndex1;
  320. }
  321. }
  322. break;
  323. }
  324. case "fontsize1":
  325. {
  326. oStyle.fontSize = fontSize1;
  327. break;
  328. }
  329. case "tips":
  330. {
  331. element.children(0).title = tips;
  332. break;
  333. }
  334. default:
  335. break;
  336. }
  337. }
  338. /**
  339. *处理相关事件
  340. *
  341. */
  342. function execute(sEvent)
  343. {
  344. //不可处理状态下,不能进行处理
  345. if (eval(disable) == true)
  346. {
  347. return false;
  348. }
  349. var evt = window.document.createEventObject(event);
  350. if (sEvent == "click")
  351. {
  352. evtClick.fire(evt);
  353. }
  354. else if (sEvent == "mouseup")
  355. {
  356. evtMouseUp.fire(evt);
  357. }
  358. else if (sEvent == "mousedown")
  359. {
  360. element.isMouseDown = true;
  361. evtMouseDown.fire(evt);
  362. }
  363. else if (sEvent == "mousemove")
  364. {
  365. evtMouseMove.fire(evt);
  366. }
  367. else if (sEvent == "mouseover")
  368. {
  369. evtMouseOver.fire(evt);
  370. }
  371. else if (sEvent == "mouseout")
  372. {
  373. evtMouseOut.fire(evt);
  374. }
  375. else if (sEvent == "keyup")
  376. {
  377. evtKeyUp.fire(evt);
  378. }
  379. else if (sEvent == "keydown")
  380. {
  381. doKeyDown(evt);
  382. }
  383. else if (sEvent == "keypress")
  384. {
  385.  evtKeyPress.fire(evt);
  386. }
  387. else if (sEvent == "change")
  388. {
  389. evtChange.fire(evt);
  390. }
  391. else if (sEvent == "beforepaste")
  392. {
  393. return doBeforePaste(evt);
  394. }
  395. else if (sEvent == "selectstart")
  396. {
  397. return doSelectStart(evt);
  398. }
  399. //可编辑状态下,可以修改边框的相关的颜色
  400. if (eval(readonly) != true)
  401. {
  402. if (sEvent == "focus")
  403. {
  404. doFocus(evt);
  405. }
  406. else if (sEvent == "blur")
  407. {
  408. if (eval(mustInput) == true)
  409. {
  410. element.children(0).style.borderColor = mustBorderColor;
  411. element.children(0).style.backgroundColor = mustBGColor;
  412. element.children(0).style.color = mustTextFontColor;
  413. if (element.children(0).value == "" && mustInputMsg != "")
  414. {
  415. alert(mustInputMsg);
  416. }
  417. }
  418. else
  419. {
  420. element.children(0).style.borderColor = initializeBorderColor;
  421. element.children(0).style.backgroundColor = initializeBGColor;
  422. element.children(0).style.color = initializeTextFontColor;
  423. }
  424. evtBlur.fire(evt);
  425. }
  426. }
  427. }
  428. /**
  429. *得到光标指定位置
  430. *
  431. */
  432. function getCursorPosition()
  433. {
  434. var oSrc = event.srcElement;
  435. var textRange = document.selection.createRange();
  436. textRange.collapse(false);
  437. textRange.setEndPoint("StartToStart", oSrc.createTextRange());
  438. return textRange.text.length;
  439. }
  440. /**
  441. *移动光标到指定位置
  442. *
  443. */
  444. function moveCursor(iPosition)
  445. {
  446. var oSrc = event.srcElement;
  447. if (!iPosition)
  448. {
  449. return;
  450. }
  451. if(isNaN(iPosition))
  452. {
  453. return;
  454. }
  455. var oRange = oSrc.createTextRange();
  456. oRange.moveStart("character",iPosition);
  457. oRange.collapse(true);
  458. oRange.select();
  459. }
  460. /**
  461. *得到焦点
  462. *
  463. */
  464. function focus()
  465. {
  466. if (eval(disable) == true)
  467. {
  468. return;
  469. }
  470. element.children(0).focus();
  471. }
  472. /**
  473. *选择部分的时候修改显示的颜色
  474. *
  475. */
  476. function doSelectStart(evt)
  477. {
  478. if (eval(disable) == true)
  479. {
  480. return false;
  481. }
  482. }
  483. /**
  484. *处理keyDown事件,主要按下enter键的时候,类似tab键按下
  485. *
  486. */
  487. function doKeyDown(evt)
  488. {
  489. if (event.keyCode == 13 && eval(enter2tab) == true)
  490. {
  491. evtKeyDown.fire(evt);
  492. event.keyCode = 9;
  493. return;
  494. }
  495. evtKeyDown.fire(evt);
  496. }
  497. /**
  498. *处理beforePaste事件,如果设置了maxlength的时候,不能随意粘贴
  499. *
  500. */
  501. function doBeforePaste(evt)
  502. {
  503. evtBeforePaste.fire(evt);
  504. return true;
  505. }
  506. /**
  507. *处理focus事件
  508. *
  509. */
  510. function doFocus(evt)
  511. {
  512. var oStyle = element.children(0).style;
  513. if (eval(mustInput) == false)
  514. {
  515. oStyle.borderColor = focusBorderColor;
  516. oStyle.backgroundColor = focusBGColor;
  517. oStyle.color = focusTextFontColor;
  518. }
  519. else
  520. {
  521. oStyle.borderColor = focusBorderColor;
  522. oStyle.backgroundColor = mustBGColor;
  523. oStyle.color = focusTextFontColor;
  524. }
  525. if (element.isMouseDown != true)
  526. {
  527. element.children(0).select();
  528. }
  529. element.isMouseDown = false;
  530. evtFocus.fire(evt);
  531. }
  532. /**
  533. *得到控件的值
  534. *
  535. */
  536. function getValue()
  537. {
  538. return element.children(0).value;
  539. }
  540. /**
  541. *设置控件的值
  542. *
  543. */
  544. function putValue(sValue1)
  545. {
  546. if (!element.children(0))
  547. {
  548. sValue = sValue1;
  549. }
  550. else
  551. {
  552. sValue = sValue1;
  553. element.children(0).value = sValue;
  554. }
  555. }
  556. /**
  557. *初始样式
  558. *
  559. */
  560. function initCss()
  561. {
  562. element.initcssing = true;
  563. var os = element.currentStyle;
  564. initializeBorderColor = getCssStyle(initializeBorderColor,"#B4B4B4",os.initializeBorderColor);
  565. initializeBGColor = getCssStyle(initializeBGColor,"#FFFFFF",os.initializeBGColor);
  566. initializeTextFontColor = getCssStyle(initializeTextFontColor,"#000000",os.initializeTextFontColor);
  567. focusBorderColor = getCssStyle(focusBorderColor,"#5C85B3",os.focusBorderColor);
  568. focusBGColor = getCssStyle(focusBGColor,"#F9F9F9",os.focusBGColor);
  569. focusTextFontColor = getCssStyle(focusTextFontColor,"#000000",os.focusTextFontColor);
  570. readonlyBorderColor = getCssStyle(readonlyBorderColor,"#B4B4B4",os.readonlyBorderColor);
  571. readonlyBGColor = getCssStyle(readonlyBGColor,"#FFFFFF",os.readonlyBGColor);
  572. readonlyTextFontColor = getCssStyle(readonlyTextFontColor,"#777777",os.readonlyTextFontColor);
  573. disableBorderColor = getCssStyle(disableBorderColor,"#B4B4B4",os.disableBorderColor);
  574. disableBGColor = getCssStyle(disableBGColor,"#D9D9D0",os.disableBGColor);
  575. disableTextFontColor = getCssStyle(disableTextFontColor,"#777777",os.disableTextFontColor);
  576. mustBorderColor = getCssStyle(mustBorderColor,"#B4B4B4",os.mustBorderColor);
  577. mustBGColor = getCssStyle(mustBGColor,"#FCFBCE",os.mustBGColor);
  578. mustTextFontColor = getCssStyle(mustTextFontColor,"#000000",os.mustTextFontColor);
  579. fontSize1 = getCssStyle(fontSize1,"9pt",os.fontSize1);
  580. fontFamily1 = getCssStyle(fontFamily1,"arial",os.fontFamily1);
  581. element.initcssing = false;
  582. }
  583. </script>