~ubuntu-branches/ubuntu/precise/moin/precise-updates

« back to all changes in this revision

Viewing changes to wiki/htdocs/applets/FCKeditor/editor/dialog/fck_select/fck_select.js

  • Committer: Bazaar Package Importer
  • Author(s): Michael Vogt
  • Date: 2008-11-13 16:45:52 UTC
  • mfrom: (0.1.5 sid)
  • Revision ID: james.westby@ubuntu.com-20081113164552-49t6zf2t2o5bqigh
Tags: 1.8.0-1ubuntu1
* Merge from debian unstable, remaining changes:
  - Drop recommendation of python-xml, the packages isn't anymore in
    sys.path.

Show diffs side-by-side

added added

removed removed

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