fck_select.js
上传用户:li2971742
上传日期:2021-11-18
资源大小:39096k
文件大小:4k
源码类别:

OA系统

开发平台:

C#

  1. /*
  2.  * FCKeditor - The text editor for internet
  3.  * Copyright (C) 2003-2006 Frederico Caldeira Knabben
  4.  * 
  5.  * Licensed under the terms of the GNU Lesser General Public License:
  6.  *  http://www.opensource.org/licenses/lgpl-license.php
  7.  * 
  8.  * For further information visit:
  9.  *  http://www.fckeditor.net/
  10.  * 
  11.  * "Support Open Source software. What about a donation today?"
  12.  * 
  13.  * File Name: fck_select.js
  14.  *  Scripts for the fck_select.html page.
  15.  * 
  16.  * File Authors:
  17.  *  Frederico Caldeira Knabben (fredck@fckeditor.net)
  18.  */
  19. function Select( combo )
  20. {
  21. var iIndex = combo.selectedIndex ;
  22. oListText.selectedIndex = iIndex ;
  23. oListValue.selectedIndex = iIndex ;
  24. var oTxtText = document.getElementById( "txtText" ) ;
  25. var oTxtValue = document.getElementById( "txtValue" ) ;
  26. oTxtText.value = oListText.value ;
  27. oTxtValue.value = oListValue.value ;
  28. }
  29. function Add()
  30. {
  31. var oTxtText = document.getElementById( "txtText" ) ;
  32. var oTxtValue = document.getElementById( "txtValue" ) ;
  33. AddComboOption( oListText, oTxtText.value, oTxtText.value ) ;
  34. AddComboOption( oListValue, oTxtValue.value, oTxtValue.value ) ;
  35. oListText.selectedIndex = oListText.options.length - 1 ;
  36. oListValue.selectedIndex = oListValue.options.length - 1 ;
  37. oTxtText.value = '' ;
  38. oTxtValue.value = '' ;
  39. oTxtText.focus() ;
  40. }
  41. function Modify()
  42. {
  43. var iIndex = oListText.selectedIndex ;
  44. if ( iIndex < 0 ) return ;
  45. var oTxtText = document.getElementById( "txtText" ) ;
  46. var oTxtValue = document.getElementById( "txtValue" ) ;
  47. oListText.options[ iIndex ].innerHTML = oTxtText.value ;
  48. oListText.options[ iIndex ].value = oTxtText.value ;
  49. oListValue.options[ iIndex ].innerHTML = oTxtValue.value ;
  50. oListValue.options[ iIndex ].value = oTxtValue.value ;
  51. oTxtText.value = '' ;
  52. oTxtValue.value = '' ;
  53. oTxtText.focus() ;
  54. }
  55. function Move( steps )
  56. {
  57. ChangeOptionPosition( oListText, steps ) ;
  58. ChangeOptionPosition( oListValue, steps ) ;
  59. }
  60. function Delete()
  61. {
  62. RemoveSelectedOptions( oListText ) ;
  63. RemoveSelectedOptions( oListValue ) ;
  64. }
  65. function SetSelectedValue()
  66. {
  67. var iIndex = oListValue.selectedIndex ;
  68. if ( iIndex < 0 ) return ;
  69. var oTxtValue = document.getElementById( "txtSelValue" ) ;
  70. oTxtValue.value = oListValue.options[ iIndex ].value ;
  71. }
  72. // Moves the selected option by a number of steps (also negative)
  73. function ChangeOptionPosition( combo, steps )
  74. {
  75. var iActualIndex = combo.selectedIndex ;
  76. if ( iActualIndex < 0 )
  77. return ;
  78. var iFinalIndex = iActualIndex + steps ;
  79. if ( iFinalIndex < 0 )
  80. iFinalIndex = 0 ;
  81. if ( iFinalIndex > ( combo.options.length - 1 ) )
  82. iFinalIndex = combo.options.length - 1 ;
  83. if ( iActualIndex == iFinalIndex )
  84. return ;
  85. var oOption = combo.options[ iActualIndex ] ;
  86. var sText = oOption.innerHTML ;
  87. var sValue = oOption.value ;
  88. combo.remove( iActualIndex ) ;
  89. oOption = AddComboOption( combo, sText, sValue, null, iFinalIndex ) ;
  90. oOption.selected = true ;
  91. }
  92. // Remove all selected options from a SELECT object
  93. function RemoveSelectedOptions(combo)
  94. {
  95. // Save the selected index
  96. var iSelectedIndex = combo.selectedIndex ;
  97. var oOptions = combo.options ;
  98. // Remove all selected options
  99. for ( var i = oOptions.length - 1 ; i >= 0 ; i-- )
  100. {
  101. if (oOptions[i].selected) combo.remove(i) ;
  102. }
  103. // Reset the selection based on the original selected index
  104. if ( combo.options.length > 0 )
  105. {
  106. if ( iSelectedIndex >= combo.options.length ) iSelectedIndex = combo.options.length - 1 ;
  107. combo.selectedIndex = iSelectedIndex ;
  108. }
  109. }
  110. // Add a new option to a SELECT object (combo or list)
  111. function AddComboOption( combo, optionText, optionValue, documentObject, index )
  112. {
  113. var oOption ;
  114. if ( documentObject )
  115. oOption = documentObject.createElement("OPTION") ;
  116. else
  117. oOption = document.createElement("OPTION") ;
  118. if ( index != null )
  119. combo.options.add( oOption, index ) ;
  120. else
  121. combo.options.add( oOption ) ;
  122. oOption.innerHTML = optionText.length > 0 ? optionText : '&nbsp;' ;
  123. oOption.value     = optionValue ;
  124. return oOption ;
  125. }