home *** CD-ROM | disk | FTP | other *** search
/ PC World Komputer 2010 April / PCWorld0410.iso / WindowsServerTrial / server.iso / sources / install.wim / 1 / Windows / System32 / mshtmler.dll / HTML / FORCHAR.JS < prev    next >
Text (UTF-16)  |  2006-11-02  |  25KB  |  580 lines

  1. function callHelp(elm)
  2. {
  3. if (null != elm.helpid)
  4. {
  5. window.showHelp(elm.helpfile, "" + parseInt(elm.helpid),
  6. "popup");
  7. }
  8. else
  9. {
  10. if ("BODY" != elm.tagName)
  11. {
  12. callHelp(elm.parentElement);
  13. }
  14. }
  15. }
  16. function btnCancelClick()
  17. {
  18. window.close();
  19. }
  20. function getTextRange(elm)
  21. {
  22. var r = elm.parentTextEdit.createTextRange();
  23. r.moveToElementText(elm);
  24. return r;
  25. }
  26. function mouseClick()
  27. {
  28. if (window.event.srcElement.id.substring(0,3)
  29. == "txt")
  30. {
  31. return;
  32. }
  33. if (window.event.button == 2)
  34. {
  35. callHelp(window.event.srcElement);
  36. }
  37. }
  38. function txtDefaultESC()
  39. {
  40. if (event.keyCode == 27)
  41. {
  42. window.close();
  43. return;
  44. }
  45. }
  46. var g_bSearchList = false;
  47. var g_nTimeoutID;
  48. var g_szLastFound = "";
  49. var g_nLastFoundIndex = 0;
  50. var g_nMatchLength = 0;
  51. function loadBdy()
  52. {
  53. var doc = window.dialogArguments;
  54. if (doc.parentWindow.frames.length > 0 &&
  55. doc.all.tags("IFRAME").length == 0)
  56. {
  57. alert(L_InsideFrameset_ErrorMessage);
  58. window.close();
  59. }
  60. var rngCurrent = doc;
  61. document.onhelp = new Function("callHelp(window.event.srcElement)");
  62. document.onmouseup = new Function("mouseClick()");
  63. txtFontName.onblur = new
  64. Function("syncSelect(cmdFontName, txtFontName)");
  65. txtFontName.onfocus = new Function("txtFontName.select()");
  66. txtFontName.onchange = new
  67. Function("setFont(getTextRange(elmSample))");
  68. txtFontName.onkeyup = new Function("syncTextFont()");
  69. txtFontName.onfocus = new Function("txtFontName.select()");
  70. txtFontName.onkeypress = new Function("txtDefaultESC()");
  71. txtFontStyle.onblur = new
  72. Function("syncSelect(selFontStyle, txtFontStyle)");
  73. txtFontStyle.onfocus = new Function("txtFontStyle.select()");
  74. txtFontStyle.onchange = new Function("setFontStyle" +
  75. "(getTextRange(elmSample))");
  76. txtFontStyle.onkeyup = new Function("synchText()");
  77. txtFontStyle.onfocus = new Function("txtFontStyle.select()");
  78. txtFontStyle.onkeypress = new Function("txtDefaultESC()");
  79. txtFontSize.onblur = new
  80. Function("syncSelect(cmdFontSize, txtFontSize)");
  81. txtFontSize.onfocus = new Function("txtFontSize.select()");
  82. txtFontSize.onchange = new
  83. Function("setSelectStateCmd(cmdFontSize, " +
  84. "getTextRange(elmSample))");
  85. txtFontSize.onkeyup = new Function("synchText()");
  86. txtFontSize.onfocus = new Function("txtFontSize.select()");
  87. txtFontSize.onkeypress = new Function("txtDefaultESC()");
  88. cmdFontName.onchange = new Function("syncSelect2(cmdFontName, txtFontName);" +
  89. "setFont(getTextRange(elmSample))");
  90. selFontStyle.onchange = new Function("syncSelect2(selFontStyle," +
  91. "txtFontStyle);" +
  92. "setFontStyle(getTextRange(elmSample))");
  93. cmdFontSize.onchange = new Function("syncSelect2(cmdFontSize, txtFontSize);" +
  94. "setSelectStateCmd(cmdFontSize, getTextRange(elmSample))");
  95. chkUnderline.onclick = new Function("setCheckStateCmd(chkUnderline," +
  96. "getTextRange(elmSample))");
  97. selColor.onchange = new Function("setFontColor(getTextRange(elmSample))");
  98. btnCustom.onclick = new Function("btnCustomClick()");
  99. btnOK.onclick = new Function("btnOKClick()");
  100. btnCancel.onclick = new Function("btnCancelClick()");
  101. fillFontSelect(cmdFontName);
  102. getCheckStateCmd(chkUnderline, rngCurrent);
  103. getSelectStateCmd(cmdFontName, rngCurrent);
  104. getSelectStateCmd(cmdFontSize, rngCurrent);
  105. getFontStyle();
  106. selColor.customColor = 0;
  107. getFontColor();
  108. syncSelect2(cmdFontName, txtFontName);
  109. syncSelect2(selFontStyle, txtFontStyle);
  110. syncSelect2(cmdFontSize, txtFontSize);
  111. txtFontName.select();
  112. g_szLastFound = txtFontName.value;
  113. updateSample();
  114. txtFontName.focus();
  115. }
  116. function GetSampleString()
  117. {
  118. var strReturn = "AaBbYyZz";
  119. if (txtFontName.value != "")
  120. {
  121. switch (dialogHelper.getCharset(txtFontName.value))
  122. {
  123. case 2:
  124. {
  125. strReturn = "Symbol";
  126. break;
  127. }
  128. case 128:
  129. {
  130. strReturn = "Aa\u3042\u3041\u30a2\u30a1\u4e9c\u5b87";
  131. break;
  132. }
  133. case 129:
  134. case 130:
  135. {
  136. strReturn = "\uac00\ub098\ub2e4\u0041\u0061\u0042\u0062\u0059\u0079\u005a\u007a";
  137. break;
  138. }
  139. case 136:
  140. {
  141. strReturn = "\u4e2d\u6587\u5b57\u578b\u7bc4\u4f8b";
  142. break;
  143. }
  144. case 161:
  145. {
  146. strReturn = "AaBb\u0391\u03b1\u0392\u03b2";
  147. break;
  148. }
  149. case 162:
  150. {
  151. strReturn = "AaBb\u011e\u011f\u015e\u015f";
  152. break;
  153. }
  154. case 177:
  155. {
  156. strReturn = "AaBb\u05e0\u05e1\u05e9\u05ea";
  157. break;
  158. }
  159. case 178:
  160. case 179:
  161. {
  162. strReturn = "AaBb\u0639\u0645\u0646\u062e\u0631\u0648\u0643\u0645";
  163. break;
  164. }
  165. case 204:
  166. {
  167. strReturn = "AaBb\u0411\u0431\u0424\u0444";
  168. break;
  169. }
  170. case 238:
  171. {
  172. strReturn = "AaBb\u00c1\u00e1\u00d4\u00f4";
  173. break;
  174. }
  175. case 255:
  176. {
  177. strReturn = "Aa\u00f8\u00f1\u00fd";
  178. break;
  179. }
  180. }
  181. }
  182. return strReturn;
  183. }
  184. function getCheckStateCmd(checkbox, range)
  185. {
  186. checkbox.checked = (true == range.queryCommandState(checkbox.value));
  187. }
  188. function getSelectStateCmd(select, range)
  189. {
  190. var index;
  191. if (null != range.queryCommandValue(select.id.substring(3)))
  192. {
  193. for (index = 0; index < select.options.length; index++)
  194. {
  195. if (select.options[index].value ==
  196. range.queryCommandValue(select.id.substring(3)))
  197. {
  198. select.selectedIndex = index;
  199. break;
  200. }
  201. }
  202. }
  203. else
  204. {
  205. select.selectedIndex = -1;
  206. }
  207. }
  208. function setCheckStateCmd(checkbox, range)
  209. {
  210. if (checkbox.checked !=
  211. (true == range.queryCommandState(checkbox.value)))
  212. {
  213. range.execCommand(checkbox.value, false);
  214. }
  215. }
  216. function setSelectStateCmd(select, range)
  217. {
  218. if (-1 != select.selectedIndex)
  219. {
  220. range.execCommand(select.id.substring(3), false,
  221. select.options[select.selectedIndex].value);
  222. }
  223. }
  224. function NoCaseCompare(str1, str2)
  225. {
  226. var ideo1 = 1 != escape(str1.charAt(0)).length;
  227. var ideo2 = 1 != escape(str2.charAt(0)).length;
  228. if (ideo1 != ideo2)
  229. return ideo1 ? -1 : 1;
  230. if (str1.toLowerCase() < str2.toLowerCase())
  231. return -1;
  232. if (str1.toLowerCase() > str2.toLowerCase())
  233. return 1;
  234. return 0;
  235. }
  236. function fillFontSelect(select)
  237. {
  238. var index;
  239. var fontList = new Array();
  240. var optFontName;
  241. var len = dialogHelper.fonts.length;
  242. for (index = 0; index < len; index++)
  243. {
  244. fontList[index] =
  245. dialogHelper.fonts.item(index);
  246. }
  247. fontList.sort(NoCaseCompare);
  248. for (index = 0; index < fontList.length; index++)
  249. {
  250. optFontName = new Option();
  251. optFontName.value = fontList[index];
  252. optFontName.text = fontList[index];
  253. select.options[index] = optFontName;
  254. }
  255. }
  256. function setFont(range)
  257. {
  258. var FontNameCommand = "FontName";
  259. if (window.event.srcElement == txtFontName ||
  260. window.event.srcElement == cmdFontName)
  261. {
  262. range.text = GetSampleString();
  263. range = getTextRange(elmSample);
  264. }
  265. if (-1 != cmdFontName.selectedIndex)
  266. {
  267. range.execCommand(FontNameCommand, false, txtFontName.value);
  268. }
  269. }
  270. function getFontStyle()
  271. {
  272. var cmdBold = "Bold";
  273. var cmdItalic = "Italic";
  274. var globalDoc = window.dialogArguments;
  275. var range = globalDoc;
  276. with (range)
  277. {
  278. if (queryCommandState(cmdBold) && queryCommandState(cmdItalic))
  279. {
  280. selFontStyle.value = "Bold-Italic";
  281. }
  282. else if (queryCommandState(cmdBold))
  283. {
  284. selFontStyle.value = "Bold";
  285. }
  286. else if (queryCommandState(cmdItalic))
  287. {
  288. selFontStyle.value = "Italic";
  289. }
  290. else
  291. {
  292. selFontStyle.value = "Regular";
  293. }
  294. }
  295. }
  296. function setFontStyle(range)
  297. {
  298. var cmdBold = "Bold";
  299. var cmdItalic = "Italic";
  300. with (range)
  301. {
  302. if ("Bold-Italic" == selFontStyle.value)
  303. {
  304. if (true != queryCommandState(cmdBold))
  305. {
  306. execCommand(cmdBold, false);
  307. }
  308. if (true != queryCommandState(cmdItalic))
  309. {
  310. execCommand(cmdItalic, false);
  311. }
  312. }
  313. else if ("Bold" == selFontStyle.value)
  314. {
  315. if (true != queryCommandState(cmdBold))
  316. {
  317. execCommand(cmdBold, false);
  318. }
  319. if (true == queryCommandState(cmdItalic))
  320. {
  321. execCommand(cmdItalic, false);
  322. }
  323. }
  324. else if ("Italic" == selFontStyle.value)
  325. {
  326. if (true == queryCommandState(cmdBold))
  327. {
  328. execCommand(cmdBold, false);
  329. }
  330. if (true != queryCommandState(cmdItalic))
  331. {
  332. execCommand(cmdItalic, false);
  333. }
  334. }
  335. else
  336. {
  337. if (true == queryCommandState(cmdBold))
  338. {
  339. execCommand(cmdBold, false);
  340. }
  341. if (true == queryCommandState(cmdItalic))
  342. {
  343. execCommand(cmdItalic, false);
  344. }
  345. }
  346. }
  347. }
  348. function getFontColor()
  349. {
  350. var cmdForeColor = "ForeColor";
  351. var globalDoc = window.dialogArguments;
  352. var range = globalDoc;
  353. var intColor = range.queryCommandValue(cmdForeColor);
  354. if (null != intColor)
  355. {
  356. selColor.value = intColor;
  357. if (parseInt(selColor.value) != parseInt(intColor))
  358. {
  359. selColor.customColor = intColor;
  360. selColor.value = "custom";
  361. }
  362. }
  363. else
  364. {
  365. selColor.selectedIndex = -1;
  366. }
  367. }
  368. function setFontColor(range)
  369. {
  370. var cmdForeColor = "ForeColor";
  371. var intDefaultColor = 0;
  372. if (-1 != selColor.selectedIndex)
  373. {
  374. if ("custom" == selColor.value)
  375. {
  376. range.execCommand(cmdForeColor, false,
  377. parseInt(selColor.customColor));
  378. return;
  379. }
  380. else
  381. {
  382. range.execCommand(cmdForeColor, false,
  383. parseInt(selColor.value));
  384. }
  385. }
  386. }
  387. function syncSelect(ctlSelect, ctlText)
  388. {
  389. if (-1 != ctlSelect.selectedIndex)
  390. {
  391. if (ctlText.value.toLowerCase()
  392. == ctlSelect.options[ctlSelect.selectedIndex]
  393. .text.toLowerCase())
  394. {
  395. ctlText.value = ctlSelect.options[ctlSelect.selectedIndex].text;
  396. }
  397. }
  398. }
  399. function syncSelect2(ctlSelect, ctlText)
  400. {
  401. if (-1 != ctlSelect.selectedIndex)
  402. {
  403. ctlText.value = ctlSelect.options[ctlSelect.selectedIndex].text;
  404. }
  405. }
  406. function findMatch (strMatch, optionsList)
  407. {
  408. var index;
  409. var index2;
  410. var bestChar = 0;
  411. var bestMatch = 0;
  412. var strOptText;
  413. for (index = 0; index < optionsList.length; index++)
  414. {
  415. strOptText = optionsList.options[index].text;
  416. for (index2 = bestChar; index2 < strMatch.length; index2++)
  417. {
  418. if (strMatch.substring(0, index2 + 1).toLowerCase() ==
  419. strOptText.substring(0, index2 + 1)
  420. .toLowerCase())
  421. {
  422. bestChar = index2 + 1;
  423. bestMatch = index;
  424. }
  425. else
  426. {
  427. break;
  428. }
  429. }
  430. }
  431. return bestMatch;
  432. }
  433. function updateSample()
  434. {
  435. var rngSample = getTextRange(elmSample);
  436. setCheckStateCmd(chkUnderline, rngSample);
  437. rngSample.text = GetSampleString();
  438. rngSample = getTextRange(elmSample);
  439. setFont(rngSample);
  440. setSelectStateCmd(cmdFontSize, rngSample);
  441. setFontStyle(rngSample);
  442. setFontColor(rngSample);
  443. }
  444. function searchText()
  445. {
  446. var index;
  447. var index2;
  448. var bestChar = g_nMatchLength;
  449. var bestMatch = g_nLastFoundIndex;
  450. var strOptText;
  451. var optionsList = cmdFontName.options;
  452. var strMatch = txtFontName.value;
  453. if (strMatch.length == 0)
  454. {
  455. cmdFontName.selectedIndex = -1;
  456. g_nMatchLength = 0;
  457. g_nLastFoundIndex = 0;
  458. g_bSearchList = false;
  459. g_szLastFound = "";
  460. return;
  461. }
  462. if (strMatch.length >= g_szLastFound.length
  463. && (strMatch.substring(0, g_nMatchLength).toLowerCase()
  464. == g_szLastFound.substring(0, g_nMatchLength).toLowerCase()))
  465. {
  466. index = g_nLastFoundIndex;
  467. }
  468. else
  469. {
  470. index = 0;
  471. bestChar = 0;
  472. }
  473. for (; index < optionsList.length; index++)
  474. {
  475. strOptText = optionsList.options[index].text;
  476. for (index2 = bestChar; index2 < strMatch.length; index2++)
  477. {
  478. if (strMatch.substring(index2, index2 + 1).toLowerCase() ==
  479. strOptText.substring(index2, index2 + 1)
  480. .toLowerCase())
  481. {
  482. bestChar = index2 + 1;
  483. bestMatch = index;
  484. g_nLastFoundIndex = bestMatch;
  485. g_nMatchLegth = bestChar;
  486. }
  487. else
  488. {
  489. break;
  490. }
  491. }
  492. if (bestChar > 0 && index < optionsList.options.length - 2 &&
  493. optionsList.options[index + 1].text
  494. .substring(bestChar - 1, bestChar).toLowerCase()
  495. != strMatch.substring(bestChar - 1, bestChar).toLowerCase())
  496. {
  497. break;
  498. }
  499. }
  500. cmdFontName.selectedIndex = bestMatch;
  501. g_bSearchList = false;
  502. g_szLastFound = txtFontName.value;
  503. }
  504. function TextboxKeyDown(textbox, select, iKeyCode)
  505. {
  506. var fReturn = false;
  507. if (38 == iKeyCode || 40 ==iKeyCode)
  508. {
  509. var iDirection = (iKeyCode == 38) ? -1 : 1;
  510. if (!((iDirection == 1 &&
  511. !(select.selectedIndex < select.options.length - 1))
  512. || (iDirection == -1 && !select.selectedIndex)))
  513. {
  514. select.selectedIndex = select.selectedIndex + iDirection;
  515. textbox.value =
  516. select.options(select.selectedIndex).text;
  517. textbox.select();
  518. updateSample(getTextRange(elmSample));
  519. }
  520. fReturn = true;
  521. }
  522. return fReturn;
  523. }
  524. function syncTextFont()
  525. {
  526. if (TextboxKeyDown(txtFontName, cmdFontName, window.event.keyCode))
  527. return;
  528. if (g_szLastFound.toLowerCase() == txtFontName.value.toLowerCase())
  529. {
  530. return;
  531. }
  532. if (g_bSearchList)
  533. {
  534. window.clearTimeout(g_nTimeoutID);
  535. }
  536. g_bSearchList = true;
  537. g_nTimeoutID = window.setTimeout("searchText()", 200);
  538. }
  539. function btnCustomClick()
  540. {
  541. var result = dialogHelper.choosecolordlg(selColor.customColor);
  542. if (result != 0)
  543. {
  544. selColor.customColor = result;
  545. selColor.value = "custom";
  546. setFontColor(getTextRange(elmSample));
  547. }
  548. }
  549. function btnOKClick()
  550. {
  551. var globalDoc = window.dialogArguments;
  552. var range = globalDoc;
  553. setCheckStateCmd(chkUnderline, range);
  554. setSelectStateCmd(cmdFontSize, range);
  555. setFont(range);
  556. setFontColor(range);
  557. setFontStyle(range);
  558. window.close();
  559. }
  560. function synchText()
  561. {
  562. var index;
  563. var elmSource = window.event.srcElement;
  564. var arrSelect = new Array();
  565. var elmSelect;
  566. var elmOptions;
  567. arrSelect["txtFontName"] = cmdFontName;
  568. arrSelect["txtFontStyle"] = selFontStyle;
  569. arrSelect["txtFontSize"] = cmdFontSize;
  570. elmSelect = arrSelect[elmSource.id];
  571. elmOptions = elmSelect.options;
  572. if (TextboxKeyDown(elmSource, elmSelect, window.event.keyCode))
  573. return;
  574. if ("" != elmSource.value)
  575. {
  576. elmSelect.selectedIndex = findMatch(elmSource.value,
  577. elmOptions);
  578. }
  579. }
  580.