select.html 13 KB

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