Subversion Repositories Applications.papyrus

Rev

Rev 1925 | Only display areas with differences | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 1925 Rev 2048
1
/*
1
/*
2
 * FCKeditor - The text editor for Internet - http://www.fckeditor.net
2
 * FCKeditor - The text editor for Internet - http://www.fckeditor.net
3
 * Copyright (C) 2003-2008 Frederico Caldeira Knabben
3
 * Copyright (C) 2003-2009 Frederico Caldeira Knabben
4
 *
4
 *
5
 * == BEGIN LICENSE ==
5
 * == BEGIN LICENSE ==
6
 *
6
 *
7
 * Licensed under the terms of any of the following licenses at your
7
 * Licensed under the terms of any of the following licenses at your
8
 * choice:
8
 * choice:
9
 *
9
 *
10
 *  - GNU General Public License Version 2 or later (the "GPL")
10
 *  - GNU General Public License Version 2 or later (the "GPL")
11
 *    http://www.gnu.org/licenses/gpl.html
11
 *    http://www.gnu.org/licenses/gpl.html
12
 *
12
 *
13
 *  - GNU Lesser General Public License Version 2.1 or later (the "LGPL")
13
 *  - GNU Lesser General Public License Version 2.1 or later (the "LGPL")
14
 *    http://www.gnu.org/licenses/lgpl.html
14
 *    http://www.gnu.org/licenses/lgpl.html
15
 *
15
 *
16
 *  - Mozilla Public License Version 1.1 or later (the "MPL")
16
 *  - Mozilla Public License Version 1.1 or later (the "MPL")
17
 *    http://www.mozilla.org/MPL/MPL-1.1.html
17
 *    http://www.mozilla.org/MPL/MPL-1.1.html
18
 *
18
 *
19
 * == END LICENSE ==
19
 * == END LICENSE ==
20
 *
20
 *
21
 * Scripts for the fck_select.html page.
21
 * Scripts for the fck_select.html page.
22
 */
22
 */
23
 
23
 
24
function Select( combo )
24
function Select( combo )
25
{
25
{
26
	var iIndex = combo.selectedIndex ;
26
	var iIndex = combo.selectedIndex ;
27
 
27
 
28
	oListText.selectedIndex		= iIndex ;
28
	oListText.selectedIndex		= iIndex ;
29
	oListValue.selectedIndex	= iIndex ;
29
	oListValue.selectedIndex	= iIndex ;
30
 
30
 
31
	var oTxtText	= document.getElementById( "txtText" ) ;
31
	var oTxtText	= document.getElementById( "txtText" ) ;
32
	var oTxtValue	= document.getElementById( "txtValue" ) ;
32
	var oTxtValue	= document.getElementById( "txtValue" ) ;
33
 
33
 
34
	oTxtText.value	= oListText.value ;
34
	oTxtText.value	= oListText.value ;
35
	oTxtValue.value	= oListValue.value ;
35
	oTxtValue.value	= oListValue.value ;
36
}
36
}
37
 
37
 
38
function Add()
38
function Add()
39
{
39
{
40
	var oTxtText	= document.getElementById( "txtText" ) ;
40
	var oTxtText	= document.getElementById( "txtText" ) ;
41
	var oTxtValue	= document.getElementById( "txtValue" ) ;
41
	var oTxtValue	= document.getElementById( "txtValue" ) ;
42
 
42
 
43
	AddComboOption( oListText, oTxtText.value, oTxtText.value ) ;
43
	AddComboOption( oListText, oTxtText.value, oTxtText.value ) ;
44
	AddComboOption( oListValue, oTxtValue.value, oTxtValue.value ) ;
44
	AddComboOption( oListValue, oTxtValue.value, oTxtValue.value ) ;
45
 
45
 
46
	oListText.selectedIndex = oListText.options.length - 1 ;
46
	oListText.selectedIndex = oListText.options.length - 1 ;
47
	oListValue.selectedIndex = oListValue.options.length - 1 ;
47
	oListValue.selectedIndex = oListValue.options.length - 1 ;
48
 
48
 
49
	oTxtText.value	= '' ;
49
	oTxtText.value	= '' ;
50
	oTxtValue.value	= '' ;
50
	oTxtValue.value	= '' ;
51
 
51
 
52
	oTxtText.focus() ;
52
	oTxtText.focus() ;
53
}
53
}
54
 
54
 
55
function Modify()
55
function Modify()
56
{
56
{
57
	var iIndex = oListText.selectedIndex ;
57
	var iIndex = oListText.selectedIndex ;
58
 
58
 
59
	if ( iIndex < 0 ) return ;
59
	if ( iIndex < 0 ) return ;
60
 
60
 
61
	var oTxtText	= document.getElementById( "txtText" ) ;
61
	var oTxtText	= document.getElementById( "txtText" ) ;
62
	var oTxtValue	= document.getElementById( "txtValue" ) ;
62
	var oTxtValue	= document.getElementById( "txtValue" ) ;
63
 
63
 
64
	oListText.options[ iIndex ].innerHTML	= HTMLEncode( oTxtText.value ) ;
64
	oListText.options[ iIndex ].innerHTML	= HTMLEncode( oTxtText.value ) ;
65
	oListText.options[ iIndex ].value		= oTxtText.value ;
65
	oListText.options[ iIndex ].value		= oTxtText.value ;
66
 
66
 
67
	oListValue.options[ iIndex ].innerHTML	= HTMLEncode( oTxtValue.value ) ;
67
	oListValue.options[ iIndex ].innerHTML	= HTMLEncode( oTxtValue.value ) ;
68
	oListValue.options[ iIndex ].value		= oTxtValue.value ;
68
	oListValue.options[ iIndex ].value		= oTxtValue.value ;
69
 
69
 
70
	oTxtText.value	= '' ;
70
	oTxtText.value	= '' ;
71
	oTxtValue.value	= '' ;
71
	oTxtValue.value	= '' ;
72
 
72
 
73
	oTxtText.focus() ;
73
	oTxtText.focus() ;
74
}
74
}
75
 
75
 
76
function Move( steps )
76
function Move( steps )
77
{
77
{
78
	ChangeOptionPosition( oListText, steps ) ;
78
	ChangeOptionPosition( oListText, steps ) ;
79
	ChangeOptionPosition( oListValue, steps ) ;
79
	ChangeOptionPosition( oListValue, steps ) ;
80
}
80
}
81
 
81
 
82
function Delete()
82
function Delete()
83
{
83
{
84
	RemoveSelectedOptions( oListText ) ;
84
	RemoveSelectedOptions( oListText ) ;
85
	RemoveSelectedOptions( oListValue ) ;
85
	RemoveSelectedOptions( oListValue ) ;
86
}
86
}
87
 
87
 
88
function SetSelectedValue()
88
function SetSelectedValue()
89
{
89
{
90
	var iIndex = oListValue.selectedIndex ;
90
	var iIndex = oListValue.selectedIndex ;
91
	if ( iIndex < 0 ) return ;
91
	if ( iIndex < 0 ) return ;
92
 
92
 
93
	var oTxtValue = document.getElementById( "txtSelValue" ) ;
93
	var oTxtValue = document.getElementById( "txtSelValue" ) ;
94
 
94
 
95
	oTxtValue.value = oListValue.options[ iIndex ].value ;
95
	oTxtValue.value = oListValue.options[ iIndex ].value ;
96
}
96
}
97
 
97
 
98
// Moves the selected option by a number of steps (also negative)
98
// Moves the selected option by a number of steps (also negative)
99
function ChangeOptionPosition( combo, steps )
99
function ChangeOptionPosition( combo, steps )
100
{
100
{
101
	var iActualIndex = combo.selectedIndex ;
101
	var iActualIndex = combo.selectedIndex ;
102
 
102
 
103
	if ( iActualIndex < 0 )
103
	if ( iActualIndex < 0 )
104
		return ;
104
		return ;
105
 
105
 
106
	var iFinalIndex = iActualIndex + steps ;
106
	var iFinalIndex = iActualIndex + steps ;
107
 
107
 
108
	if ( iFinalIndex < 0 )
108
	if ( iFinalIndex < 0 )
109
		iFinalIndex = 0 ;
109
		iFinalIndex = 0 ;
110
 
110
 
111
	if ( iFinalIndex > ( combo.options.length - 1 ) )
111
	if ( iFinalIndex > ( combo.options.length - 1 ) )
112
		iFinalIndex = combo.options.length - 1 ;
112
		iFinalIndex = combo.options.length - 1 ;
113
 
113
 
114
	if ( iActualIndex == iFinalIndex )
114
	if ( iActualIndex == iFinalIndex )
115
		return ;
115
		return ;
116
 
116
 
117
	var oOption = combo.options[ iActualIndex ] ;
117
	var oOption = combo.options[ iActualIndex ] ;
118
	var sText	= HTMLDecode( oOption.innerHTML ) ;
118
	var sText	= HTMLDecode( oOption.innerHTML ) ;
119
	var sValue	= oOption.value ;
119
	var sValue	= oOption.value ;
120
 
120
 
121
	combo.remove( iActualIndex ) ;
121
	combo.remove( iActualIndex ) ;
122
 
122
 
123
	oOption = AddComboOption( combo, sText, sValue, null, iFinalIndex ) ;
123
	oOption = AddComboOption( combo, sText, sValue, null, iFinalIndex ) ;
124
 
124
 
125
	oOption.selected = true ;
125
	oOption.selected = true ;
126
}
126
}
127
 
127
 
128
// Remove all selected options from a SELECT object
128
// Remove all selected options from a SELECT object
129
function RemoveSelectedOptions(combo)
129
function RemoveSelectedOptions(combo)
130
{
130
{
131
	// Save the selected index
131
	// Save the selected index
132
	var iSelectedIndex = combo.selectedIndex ;
132
	var iSelectedIndex = combo.selectedIndex ;
133
 
133
 
134
	var oOptions = combo.options ;
134
	var oOptions = combo.options ;
135
 
135
 
136
	// Remove all selected options
136
	// Remove all selected options
137
	for ( var i = oOptions.length - 1 ; i >= 0 ; i-- )
137
	for ( var i = oOptions.length - 1 ; i >= 0 ; i-- )
138
	{
138
	{
139
		if (oOptions[i].selected) combo.remove(i) ;
139
		if (oOptions[i].selected) combo.remove(i) ;
140
	}
140
	}
141
 
141
 
142
	// Reset the selection based on the original selected index
142
	// Reset the selection based on the original selected index
143
	if ( combo.options.length > 0 )
143
	if ( combo.options.length > 0 )
144
	{
144
	{
145
		if ( iSelectedIndex >= combo.options.length ) iSelectedIndex = combo.options.length - 1 ;
145
		if ( iSelectedIndex >= combo.options.length ) iSelectedIndex = combo.options.length - 1 ;
146
		combo.selectedIndex = iSelectedIndex ;
146
		combo.selectedIndex = iSelectedIndex ;
147
	}
147
	}
148
}
148
}
149
 
149
 
150
// Add a new option to a SELECT object (combo or list)
150
// Add a new option to a SELECT object (combo or list)
151
function AddComboOption( combo, optionText, optionValue, documentObject, index )
151
function AddComboOption( combo, optionText, optionValue, documentObject, index )
152
{
152
{
153
	var oOption ;
153
	var oOption ;
154
 
154
 
155
	if ( documentObject )
155
	if ( documentObject )
156
		oOption = documentObject.createElement("OPTION") ;
156
		oOption = documentObject.createElement("OPTION") ;
157
	else
157
	else
158
		oOption = document.createElement("OPTION") ;
158
		oOption = document.createElement("OPTION") ;
159
 
159
 
160
	if ( index != null )
160
	if ( index != null )
161
		combo.options.add( oOption, index ) ;
161
		combo.options.add( oOption, index ) ;
162
	else
162
	else
163
		combo.options.add( oOption ) ;
163
		combo.options.add( oOption ) ;
164
 
164
 
165
	oOption.innerHTML = optionText.length > 0 ? HTMLEncode( optionText ) : '&nbsp;' ;
165
	oOption.innerHTML = optionText.length > 0 ? HTMLEncode( optionText ) : '&nbsp;' ;
166
	oOption.value     = optionValue ;
166
	oOption.value     = optionValue ;
167
 
167
 
168
	return oOption ;
168
	return oOption ;
169
}
169
}
170
 
170
 
171
function HTMLEncode( text )
171
function HTMLEncode( text )
172
{
172
{
173
	if ( !text )
173
	if ( !text )
174
		return '' ;
174
		return '' ;
175
 
175
 
176
	text = text.replace( /&/g, '&amp;' ) ;
176
	text = text.replace( /&/g, '&amp;' ) ;
177
	text = text.replace( /</g, '&lt;' ) ;
177
	text = text.replace( /</g, '&lt;' ) ;
178
	text = text.replace( />/g, '&gt;' ) ;
178
	text = text.replace( />/g, '&gt;' ) ;
179
 
179
 
180
	return text ;
180
	return text ;
181
}
181
}
182
 
182
 
183
 
183
 
184
function HTMLDecode( text )
184
function HTMLDecode( text )
185
{
185
{
186
	if ( !text )
186
	if ( !text )
187
		return '' ;
187
		return '' ;
188
 
188
 
189
	text = text.replace( /&gt;/g, '>' ) ;
189
	text = text.replace( /&gt;/g, '>' ) ;
190
	text = text.replace( /&lt;/g, '<' ) ;
190
	text = text.replace( /&lt;/g, '<' ) ;
191
	text = text.replace( /&amp;/g, '&' ) ;
191
	text = text.replace( /&amp;/g, '&' ) ;
192
 
192
 
193
	return text ;
193
	return text ;
194
}
194
}