applied my changes - initial import
[boxroom-stian.git] / public / javascripts / tiny_mce / utils / editable_selects.js
blob5f300b49b90079a8494d524a3448a6a0085e5d1d
1 /**\r
2  * $Id: editable_selects.js 18 2006-06-29 14:11:23Z spocke $\r
3  *\r
4  * Makes select boxes editable.\r
5  *\r
6  * @author Moxiecode\r
7  * @copyright Copyright © 2004-2006, Moxiecode Systems AB, All rights reserved.\r
8  */\r
9 \r
10 var TinyMCE_EditableSelects = {\r
11         editSelectElm : null,\r
13         init : function() {\r
14                 var nl = document.getElementsByTagName("select"), i, d = document, o;\r
16                 for (i=0; i<nl.length; i++) {\r
17                         if (nl[i].className.indexOf('mceEditableSelect') != -1) {\r
18                                 o = new Option('(value)', '__mce_add_custom__');\r
20                                 o.className = 'mceAddSelectValue';\r
22                                 nl[i].options[nl[i].options.length] = o;\r
23                                 nl[i].setAttribute('onchange', 'TinyMCE_EditableSelects.onChangeEditableSelect(this);');\r
24                         }\r
25                 }\r
26         },\r
28         onChangeEditableSelect : function(se) {\r
29                 var d = document, ne;\r
31                 if (se.options[se.selectedIndex].value == '__mce_add_custom__') {\r
32                         ne = d.createElement("input");\r
33                         ne.id = se.id + "_custom";\r
34                         ne.name = se.name + "_custom";\r
35                         ne.type = "text";\r
37                         ne.style.width = se.clientWidth;\r
38                         se.parentNode.insertBefore(ne, se);\r
39                         se.style.display = 'none';\r
40                         ne.focus();\r
41                         ne.onblur = TinyMCE_EditableSelects.onBlurEditableSelectInput;\r
42                         TinyMCE_EditableSelects.editSelectElm = se;\r
43                 }\r
44         },\r
46         onBlurEditableSelectInput : function() {\r
47                 var se = TinyMCE_EditableSelects.editSelectElm;\r
49                 if (se) {\r
50                         if (se.previousSibling.value != '') {\r
51                                 addSelectValue(document.forms[0], se.id, se.previousSibling.value, se.previousSibling.value);\r
52                                 selectByValue(document.forms[0], se.id, se.previousSibling.value);\r
53                         } else\r
54                                 selectByValue(document.forms[0], se.id, '');\r
56                         se.style.display = 'inline';\r
57                         se.parentNode.removeChild(se.previousSibling);\r
58                         TinyMCE_EditableSelects.editSelectElm = null;\r
59                 }\r
60         }\r
61 };\r