Source code of Windows XP (NT5)
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

169 lines
4.6 KiB

  1. <PUBLIC:HTC URN="shellctls">
  2. //------------------------------------------------------------------------
  3. // Public methods
  4. //------------------------------------------------------------------------
  5. //------------------------------------------------------------------------
  6. // Events
  7. //------------------------------------------------------------------------
  8. //------------------------------------------------------------------------
  9. // Attach to element events
  10. //------------------------------------------------------------------------
  11. <ATTACH event="oncontentready" handler=_OnContentReady />
  12. //------------------------------------------------------------------------
  13. // The code...
  14. //------------------------------------------------------------------------
  15. <SCRIPT language="javascript">
  16. var _bLoading = true; // true if the behavior is still loading
  17. var _idFor = null;
  18. var _szText = null;
  19. var _ichAccel = 0;
  20. var _chAccel;
  21. var c_szAccelStyle = "style = 'text-decoration:underline; accelerator:true'";
  22. // This code is run when the behavior is instantiated...
  23. element.attachEvent("onerror", _OnError);
  24. _GetPropertyDefaults();
  25. // **********************************************************************
  26. // PROPERTY GET/SET FUNCTIONS
  27. // **********************************************************************
  28. // Property: forElem = idElem
  29. //
  30. // Sets the 'for' attribute of the inserted LABEL element
  31. //
  32. function get_forCtl() { return _idFor; }
  33. function put_forCtl(id)
  34. {
  35. if (_bLoading)
  36. return;
  37. _idFor = id;
  38. }
  39. // **********************************************************************
  40. // EVENT HANDLERS
  41. // **********************************************************************
  42. /*-------------------------------------------------------------------------
  43. Purpose: When the behavior is completely loaded, set the loading flag to false.
  44. To improve load time, we don't want the put methods on the properties
  45. to be called. We also need to keep events from getting fired while
  46. the behavior is loading.
  47. */
  48. function _OnContentReady()
  49. {
  50. _bLoading = false;
  51. _ScanForAccelerator();
  52. _CreateHTML();
  53. }
  54. // **********************************************************************
  55. // HELPER FUNCTIONS
  56. // **********************************************************************
  57. /*-------------------------------------------------------------------------
  58. Purpose: Called when the behavior is instantiated. Sets up the internal
  59. property values.
  60. */
  61. function _GetPropertyDefaults()
  62. {
  63. if (element.forElem)
  64. _idFor = element.forElem;
  65. }
  66. /*-------------------------------------------------------------------------
  67. Purpose: Walk thru the element's innertext and find which letter is tagged as
  68. the accelerator (as indicated by '&' -- Win32 style).
  69. */
  70. function _ScanForAccelerator()
  71. {
  72. // Pick off first '&'
  73. var sz = element.innerText;
  74. _ichAccel = sz.indexOf('&');
  75. _szText = sz.substring(0, _ichAccel);
  76. if (_ichAccel < sz.length - 1)
  77. _szText = _szText + sz.substring(_ichAccel+1, sz.length);
  78. if (0 <= _ichAccel)
  79. _chAccel = sz.charAt(_ichAccel+1);
  80. }
  81. /*-------------------------------------------------------------------------
  82. Purpose: Adds the HTML code to the main document to display the accelerator.
  83. Given this innertext: "Cl&ose", this behavior inserts text like
  84. the following:
  85. <LABEL id=idxxxx for=idyyyyy accesskey="o">
  86. Cl<SPAN class=Accelerator>o</SPAN>se
  87. </LABEL>
  88. */
  89. function _CreateHTML()
  90. {
  91. // Construct the html
  92. element.innerHTML =
  93. '<LABEL id=idLblAccel_' + uniqueID + ' for=' + _idFor + ' accesskey="' + _chAccel + '">' +
  94. _szText.substring(0, _ichAccel) +
  95. '<SPAN ' + c_szAccelStyle + '>' +
  96. _szText.substring(_ichAccel, _ichAccel+1) +
  97. '</SPAN>' +
  98. _szText.substring(_ichAccel+1, _szText.length) +
  99. '</LABEL>';
  100. }
  101. /*-------------------------------------------------------------------------
  102. Purpose: Handle the onerror event
  103. */
  104. function _OnError(szMsg, szUrl, iLine)
  105. {
  106. // Prevent scripting errors from displaying ugly messages
  107. alert("An unexpected error occurred.\n\n" + szMsg + "\n" + szUrl + "\nLine: " + iLine);
  108. return true; // Suppress IE error messaging
  109. }
  110. </SCRIPT>
  111. //------------------------------------------------------------------------
  112. // Properties
  113. //------------------------------------------------------------------------
  114. <PROPERTY name="forElem" get=get_forCtl put=put_forCtl />
  115. </PUBLIC:HTC>