2 * FCKeditor - The text editor for Internet - http://www.fckeditor.net
\r
3 * Copyright (C) 2003-2010 Frederico Caldeira Knabben
\r
5 * == BEGIN LICENSE ==
\r
7 * Licensed under the terms of any of the following licenses at your
\r
10 * - GNU General Public License Version 2 or later (the "GPL")
\r
11 * http://www.gnu.org/licenses/gpl.html
\r
13 * - GNU Lesser General Public License Version 2.1 or later (the "LGPL")
\r
14 * http://www.gnu.org/licenses/lgpl.html
\r
16 * - Mozilla Public License Version 1.1 or later (the "MPL")
\r
17 * http://www.mozilla.org/MPL/MPL-1.1.html
\r
21 * Scripts for the fck_select.html page.
\r
24 function Select( combo )
\r
26 var iIndex = combo.selectedIndex ;
\r
28 oListText.selectedIndex = iIndex ;
\r
29 oListValue.selectedIndex = iIndex ;
\r
31 var oTxtText = document.getElementById( "txtText" ) ;
\r
32 var oTxtValue = document.getElementById( "txtValue" ) ;
\r
34 oTxtText.value = oListText.value ;
\r
35 oTxtValue.value = oListValue.value ;
\r
40 var oTxtText = document.getElementById( "txtText" ) ;
\r
41 var oTxtValue = document.getElementById( "txtValue" ) ;
\r
43 AddComboOption( oListText, oTxtText.value, oTxtText.value ) ;
\r
44 AddComboOption( oListValue, oTxtValue.value, oTxtValue.value ) ;
\r
46 oListText.selectedIndex = oListText.options.length - 1 ;
\r
47 oListValue.selectedIndex = oListValue.options.length - 1 ;
\r
49 oTxtText.value = '' ;
\r
50 oTxtValue.value = '' ;
\r
57 var iIndex = oListText.selectedIndex ;
\r
59 if ( iIndex < 0 ) return ;
\r
61 var oTxtText = document.getElementById( "txtText" ) ;
\r
62 var oTxtValue = document.getElementById( "txtValue" ) ;
\r
64 oListText.options[ iIndex ].innerHTML = HTMLEncode( oTxtText.value ) ;
\r
65 oListText.options[ iIndex ].value = oTxtText.value ;
\r
67 oListValue.options[ iIndex ].innerHTML = HTMLEncode( oTxtValue.value ) ;
\r
68 oListValue.options[ iIndex ].value = oTxtValue.value ;
\r
70 oTxtText.value = '' ;
\r
71 oTxtValue.value = '' ;
\r
76 function Move( steps )
\r
78 ChangeOptionPosition( oListText, steps ) ;
\r
79 ChangeOptionPosition( oListValue, steps ) ;
\r
84 RemoveSelectedOptions( oListText ) ;
\r
85 RemoveSelectedOptions( oListValue ) ;
\r
88 function SetSelectedValue()
\r
90 var iIndex = oListValue.selectedIndex ;
\r
91 if ( iIndex < 0 ) return ;
\r
93 var oTxtValue = document.getElementById( "txtSelValue" ) ;
\r
95 oTxtValue.value = oListValue.options[ iIndex ].value ;
\r
98 // Moves the selected option by a number of steps (also negative)
\r
99 function ChangeOptionPosition( combo, steps )
\r
101 var iActualIndex = combo.selectedIndex ;
\r
103 if ( iActualIndex < 0 )
\r
106 var iFinalIndex = iActualIndex + steps ;
\r
108 if ( iFinalIndex < 0 )
\r
111 if ( iFinalIndex > ( combo.options.length - 1 ) )
\r
112 iFinalIndex = combo.options.length - 1 ;
\r
114 if ( iActualIndex == iFinalIndex )
\r
117 var oOption = combo.options[ iActualIndex ] ;
\r
118 var sText = HTMLDecode( oOption.innerHTML ) ;
\r
119 var sValue = oOption.value ;
\r
121 combo.remove( iActualIndex ) ;
\r
123 oOption = AddComboOption( combo, sText, sValue, null, iFinalIndex ) ;
\r
125 oOption.selected = true ;
\r
128 // Remove all selected options from a SELECT object
\r
129 function RemoveSelectedOptions(combo)
\r
131 // Save the selected index
\r
132 var iSelectedIndex = combo.selectedIndex ;
\r
134 var oOptions = combo.options ;
\r
136 // Remove all selected options
\r
137 for ( var i = oOptions.length - 1 ; i >= 0 ; i-- )
\r
139 if (oOptions[i].selected) combo.remove(i) ;
\r
142 // Reset the selection based on the original selected index
\r
143 if ( combo.options.length > 0 )
\r
145 if ( iSelectedIndex >= combo.options.length ) iSelectedIndex = combo.options.length - 1 ;
\r
146 combo.selectedIndex = iSelectedIndex ;
\r
150 // Add a new option to a SELECT object (combo or list)
\r
151 function AddComboOption( combo, optionText, optionValue, documentObject, index )
\r
155 if ( documentObject )
\r
156 oOption = documentObject.createElement("OPTION") ;
\r
158 oOption = document.createElement("OPTION") ;
\r
160 if ( index != null )
\r
161 combo.options.add( oOption, index ) ;
\r
163 combo.options.add( oOption ) ;
\r
165 oOption.innerHTML = optionText.length > 0 ? HTMLEncode( optionText ) : ' ' ;
\r
166 oOption.value = optionValue ;
\r
171 function HTMLEncode( text )
\r
176 text = text.replace( /&/g, '&' ) ;
\r
177 text = text.replace( /</g, '<' ) ;
\r
178 text = text.replace( />/g, '>' ) ;
\r
184 function HTMLDecode( text )
\r
189 text = text.replace( />/g, '>' ) ;
\r
190 text = text.replace( /</g, '<' ) ;
\r
191 text = text.replace( /&/g, '&' ) ;
\r