select.html
11.4 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<title>下拉菜单</title>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>
<meta http-equiv="X-UA-Compatible" content="IE=Edge,chrome=1" >
<meta name="generator" content="www.leipi.org" />
<link rel="stylesheet" href="bootstrap/css/bootstrap.css">
<!--[if lte IE 6]>
<link rel="stylesheet" type="text/css" href="bootstrap/css/bootstrap-ie6.css">
<![endif]-->
<!--[if lte IE 7]>
<link rel="stylesheet" type="text/css" href="bootstrap/css/ie.css">
<![endif]-->
<link rel="stylesheet" href="leipi.style.css">
<script type="text/javascript" src="../dialogs/internal.js"></script>
<script type="text/javascript">
function createElement(type, name)
{
var element = null;
try {
element = document.createElement('<'+type+' name="'+name+'">');
} catch (e) {}
if(element==null) {
element = document.createElement(type);
element.name = name;
}
return element;
}
function fnSelect( combo ) {
var iIndex = combo.selectedIndex ;
oListText.selectedIndex = iIndex ;
var olistText = document.getElementById( "orgtext" ) ;
olistText.value = oListText.value ;
}
function fnAdd() {
var olistText = document.getElementById( "orgtext" ) ;
fnAddComboOption( oListText, olistText.value, olistText.value ) ;
oListText.selectedIndex = oListText.options.length - 1 ;
olistText.value = '' ;
olistText.focus() ;
}
function fnModify() {
var iIndex = oListText.selectedIndex ;
if ( iIndex < 0 ) return ;
var olistText = document.getElementById( "orgtext" ) ;
oListText.options[ iIndex ].innerHTML = fnHTMLEncode( olistText.value ) ;
oListText.options[ iIndex ].value = olistText.value ;
olistText.value = '' ;
olistText.focus() ;
}
function fnMove( steps ) {
fnChangeOptionPosition( oListText, steps ) ;
}
function fnDelete() {
fnRemoveSelectedOptions( oListText ) ;
}
function fnSetSelectedValue() {
var iIndex = oListText.selectedIndex ;
if ( iIndex < 0 ) return ;
var olistText = document.getElementById( "orgvalue" ) ;
olistText.innerHTML = oListText.options[ iIndex ].value ;
}
// Moves the selected option by a number of steps (also negative)
function fnChangeOptionPosition( combo, steps ) {
var iActualIndex = combo.selectedIndex ;
if ( iActualIndex < 0 ){
return ;
}
var iFinalIndex = iActualIndex + steps ;
if ( iFinalIndex < 0 ){
iFinalIndex = 0 ;
}
if ( iFinalIndex > ( combo.options.length - 1 ) ) {
iFinalIndex = combo.options.length - 1 ;
}
if ( iActualIndex == iFinalIndex ) {
return ;
}
var oOption = combo.options[ iActualIndex ] ;
if(oOption.value=="") {
var sText = fnHTMLDecode( oOption.value ) ;
} else {
var sText = fnHTMLDecode( oOption.innerHTML ) ;
}
combo.remove( iActualIndex ) ;
oOption = fnAddComboOption( combo, sText, sText, null, iFinalIndex ) ;
oOption.selected = true ;
}
// Remove all selected options from a SELECT object
function fnRemoveSelectedOptions( combo ) {
// Save the selected index
var iSelectedIndex = combo.selectedIndex ;
var oOptions = combo.options ;
// Remove all selected options
for ( var i = oOptions.length - 1 ; i >= 0 ; i-- ) {
if (oOptions[i].selected) combo.remove(i) ;
}
// Reset the selection based on the original selected index
if ( combo.options.length > 0 ) {
if ( iSelectedIndex >= combo.options.length ) iSelectedIndex = combo.options.length - 1 ;
combo.selectedIndex = iSelectedIndex ;
}
}
// Add a new option to a SELECT object (combo or list)
function fnAddComboOption( combo, optionText, optionValue, documentObject, index ) {
var oOption ;
if ( documentObject ) {
oOption = documentObject.createElement("option") ;
} else {
oOption = document.createElement("option") ;
}
if ( index != null ) {
combo.options.add( oOption, index ) ;
} else {
combo.options.add( oOption ) ;
}
oOption.innerHTML = optionText.length > 0 ? fnHTMLEncode( optionText ) : ' ' ;
oOption.value = optionValue ;
return oOption ;
}
function fnHTMLEncode( text ) {
if ( !text ) {
return '' ;
}
text = text.replace( /&/g, '&' ) ;
text = text.replace( /</g, '<' ) ;
text = text.replace( />/g, '>' ) ;
return text ;
}
function fnHTMLDecode( text ) {
if ( !text ) {
return '' ;
}
text = text.replace( />/g, '>' ) ;
text = text.replace( /</g, '<' ) ;
text = text.replace( /&/g, '&' ) ;
return text ;
}
function fnSetAttribute( element, attName, attValue ) {
if ( attValue == null || attValue.length == 0 ){
element.removeAttribute( attName, 0 ) ;
} else {
element.setAttribute( attName, attValue, 0 ) ;
}
}
</script>
</head>
<body>
<div class="content">
<table class="table table-bordered table-striped table-hover">
<tr>
<th><span>控件名称</span><span class="label label-important">*</span></th>
<th><span>控件样式</span> </th>
</tr>
<tr>
<td><input id="orgname" placeholder="必填项" type="text"/></td>
<td> 宽:<input id="orgwidth" type="text" value="150" class="input-small span1"/> px 高:<input id="orgsize" type="text" class="input-small span1" value="1"/> 行</td>
</tr>
<tr style="display: none;">
<th>
<span>关联子菜单名称</span> <a id="showTips" data-content="若关联子菜单,需要子下拉菜单设置的时候在每个选项后加上特殊标记以记录与父菜单关系,形如“子菜单项目|父菜单项目”,则父菜单发生变化,子菜单会随之自动刷新筛选" rel="popover" data-original-title="说明"><i class="icon-info-sign"></i></a> </th>
<td><input id="orgChild" type="text" size="20" > </td>
</tr>
<tr>
<th><span class="pull-right">初始选定</span></th>
<td> <span id="orgvalue" class="uneditable-input" style="height:20px;"></span> </td>
</tr>
<tr>
<th colspan="2">
<span>列表值</span> <span class="label label-important">*</span>
</th>
</tr>
<tr>
<td colspan="2">
<select id="orglist" multiple="multiple" class="span14"></select>
</td>
</tr>
<tr>
<td>
<div class="btn-group pull-right">
<a title="新增" onclick="fnAdd();" class="btn btn-primary"><i class="icon-white icon-plus"></i></a>
<a title="修改" onclick="fnModify();" class="btn btn-default"><i class="icon-edit"></i></a>
</div>
<input type="text" placeholder="输入列表值..." class="span2" id="orgtext">
</td>
<td>
<div class="btn-group">
<button title="上移" onclick="fnMove(-1);" class="btn btn-default"><i class="icon-arrow-up"></i></button>
<button title="下移" onclick="fnMove(1);" class="btn btn-default"><i class="icon-arrow-down"></i></button>
<button title="设为初始化时选定值" onclick="fnSetSelectedValue();" class="btn btn-default"><i class="icon-ok-circle"></i></button>
<button title="删除" onclick="fnDelete();" class="btn btn-default"><i class="icon-ban-circle"></i></button>
</div>
</td>
</tr>
</table>
</div>
<script type="text/javascript">
var oNode = null,oListText='',thePlugins = 'select';
window.onload = function() {
oListText = $G('orglist');
if( UE.plugins[thePlugins].editdom ){
oNode = UE.plugins[thePlugins].editdom;
var gTitle=oNode.getAttribute('title').replace(/"/g,"\""),gWidth=oNode.getAttribute('orgwidth'),gSize=oNode.getAttribute('size');
gTitle = gTitle==null ? '' : gTitle;
$G('orgvalue').innerHTML = oNode.value;
$G('orgname').value = gTitle;
$G('orgsize').value = gSize;
$G('orgwidth').value = gWidth;
for ( var i = 0 ; i < oNode.options.length ; i++ ) {
var sText = oNode.options[i].value ;
fnAddComboOption( oListText, sText, sText ) ;
}
}
/*$('#showTips').popover();*/
}
dialog.oncancel = function () {
if( UE.plugins[thePlugins].editdom ) {
delete UE.plugins[thePlugins].editdom;
}
};
dialog.onok = function (){
if( $G('orgname').value == '') {
alert('控件名称不能为空');
return false;
}
if( oListText.options.length == 0 ) {
alert('请添加下拉菜单选项!');
return false;
}
var gSize = $G('orgsize').value ;
if ( gSize == null || isNaN( gSize ) || gSize < 1 ) {
gSize = '' ;
}
var gWidth=$G('orgwidth').value;
if( !oNode ) {
try {
//oNode = document.createElement("select");
oNode = createElement('select','leipiNewField');
oNode.setAttribute('title',$G('orgname').value);
oNode.setAttribute('leipiPlugins',thePlugins );
oNode.setAttribute('size',gSize);
if ( $G('orgwidth').value!= '' ) {
oNode.style.width = $G('orgwidth').value+ 'px';
//oNode.setAttribute('style','width:'+ $G('orgwidth').value + 'px;');
}
if( gWidth != '' ) {
oNode.style.width = gWidth + 'px';
oNode.setAttribute('orgwidth',gWidth );
}
// Add all available options.
for ( var i = 0 ; i < oListText.options.length ; i++ ) {
var sText = oListText.options[i].value ;
if ( sText.length == 0 ) {
sText = sText ;
}
var oOption = fnAddComboOption( oNode, sText, sText ) ;
if ( sText == $G('orgvalue').innerHTML ) {
fnSetAttribute( oOption, 'selected', 'selected' ) ;
oOption.selected = true ;
}
}
//firefox要利用span
editor.execCommand('insertHtml','{|-<span leipiplugins="select">'+oNode.outerHTML+' </span>-|}');
return true ;
} catch ( e ) {
try {
editor.execCommand('error');
} catch ( e ) {
alert('控件异常,请到 [雷劈网] 反馈或寻求帮助!');
}
return false;
}
} else {
oNode.setAttribute('title', $G('orgname').value);
oNode.setAttribute('size',gSize);
if( gWidth != '' ) {
oNode.style.width = gWidth + 'px';
oNode.setAttribute('orgwidth',gWidth );
}
// Remove all options.
while ( oNode.options.length > 0 ){
oNode.remove(0) ;
}
for ( var i = 0 ; i < $G('orglist').options.length ; i++ ) {
var sText = $G('orglist').options[i].value ;
if ( sText.length == 0 ) {
sText = sText ;
}
var oOption = fnAddComboOption( oNode, sText, sText ) ;
if ( sText == $G('orgvalue').innerHTML ) {
fnSetAttribute( oOption, 'selected', 'selected' ) ;
oOption.selected = true ;
}
}
delete UE.plugins[thePlugins].editdom;
}
};
</script>
</body>
</html>