thomascube
2006-09-24 3381d45ef674884897efddb1c87a0aa2b777214f
commit | author | age
a0109c 1 /**
S 2  * $RCSfile: editable_selects.js,v $
3  * $Revision: 1.1 $
4  * $Date: 2006/04/10 09:30:19 $
5  *
6  * Makes select boxes editable.
7  *
8  * @author Moxiecode
9  * @copyright Copyright © 2004-2006, Moxiecode Systems AB, All rights reserved.
10  */
11
12 var TinyMCE_EditableSelects = {
13     editSelectElm : null,
14
15     init : function() {
16         var nl = document.getElementsByTagName("select"), i, d = document, o;
17
18         for (i=0; i<nl.length; i++) {
19             if (nl[i].className.indexOf('mceEditableSelect') != -1) {
20                 o = new Option('(value)', '__mce_add_custom__');
21
22                 o.className = 'mceAddSelectValue';
23
24                 nl[i].options[nl[i].options.length] = o;
25                 nl[i].setAttribute('onchange', 'TinyMCE_EditableSelects.onChangeEditableSelect(this);');
26             }
27         }
28     },
29
30     onChangeEditableSelect : function(se) {
31         var d = document, ne;
32
33         if (se.options[se.selectedIndex].value == '__mce_add_custom__') {
34             ne = d.createElement("input");
35             ne.id = se.id + "_custom";
36             ne.name = se.name + "_custom";
37             ne.type = "text";
38
39             ne.style.width = se.clientWidth;
40             se.parentNode.insertBefore(ne, se);
41             se.style.display = 'none';
42             ne.focus();
43             ne.onblur = TinyMCE_EditableSelects.onBlurEditableSelectInput;
44             TinyMCE_EditableSelects.editSelectElm = se;
45         }
46     },
47
48     onBlurEditableSelectInput : function() {
49         var se = TinyMCE_EditableSelects.editSelectElm;
50
51         if (se) {
52             if (se.previousSibling.value != '') {
53                 addSelectValue(document.forms[0], se.id, se.previousSibling.value, se.previousSibling.value);
54                 selectByValue(document.forms[0], se.id, se.previousSibling.value);
55             } else
56                 selectByValue(document.forms[0], se.id, '');
57
58             se.style.display = 'inline';
59             se.parentNode.removeChild(se.previousSibling);
60             TinyMCE_EditableSelects.editSelectElm = null;
61         }
62     }
63 };