fonctions CRUD par defaut
[mtweb] / mw / libs / tiny_mce / utils / editable_selects.js
1 /**\r
2  * editable_selects.js\r
3  *\r
4  * Copyright 2009, Moxiecode Systems AB\r
5  * Released under LGPL License.\r
6  *\r
7  * License: http://tinymce.moxiecode.com/license\r
8  * Contributing: http://tinymce.moxiecode.com/contributing\r
9  */\r
10 \r
11 var TinyMCE_EditableSelects = {\r
12         editSelectElm : null,\r
13 \r
14         init : function() {\r
15                 var nl = document.getElementsByTagName("select"), i, d = document, o;\r
16 \r
17                 for (i=0; i<nl.length; i++) {\r
18                         if (nl[i].className.indexOf('mceEditableSelect') != -1) {\r
19                                 o = new Option('(value)', '__mce_add_custom__');\r
20 \r
21                                 o.className = 'mceAddSelectValue';\r
22 \r
23                                 nl[i].options[nl[i].options.length] = o;\r
24                                 nl[i].onchange = TinyMCE_EditableSelects.onChangeEditableSelect;\r
25                         }\r
26                 }\r
27         },\r
28 \r
29         onChangeEditableSelect : function(e) {\r
30                 var d = document, ne, se = window.event ? window.event.srcElement : e.target;\r
31 \r
32                 if (se.options[se.selectedIndex].value == '__mce_add_custom__') {\r
33                         ne = d.createElement("input");\r
34                         ne.id = se.id + "_custom";\r
35                         ne.name = se.name + "_custom";\r
36                         ne.type = "text";\r
37 \r
38                         ne.style.width = se.offsetWidth + 'px';\r
39                         se.parentNode.insertBefore(ne, se);\r
40                         se.style.display = 'none';\r
41                         ne.focus();\r
42                         ne.onblur = TinyMCE_EditableSelects.onBlurEditableSelectInput;\r
43                         ne.onkeydown = TinyMCE_EditableSelects.onKeyDown;\r
44                         TinyMCE_EditableSelects.editSelectElm = se;\r
45                 }\r
46         },\r
47 \r
48         onBlurEditableSelectInput : function() {\r
49                 var se = TinyMCE_EditableSelects.editSelectElm;\r
50 \r
51                 if (se) {\r
52                         if (se.previousSibling.value != '') {\r
53                                 addSelectValue(document.forms[0], se.id, se.previousSibling.value, se.previousSibling.value);\r
54                                 selectByValue(document.forms[0], se.id, se.previousSibling.value);\r
55                         } else\r
56                                 selectByValue(document.forms[0], se.id, '');\r
57 \r
58                         se.style.display = 'inline';\r
59                         se.parentNode.removeChild(se.previousSibling);\r
60                         TinyMCE_EditableSelects.editSelectElm = null;\r
61                 }\r
62         },\r
63 \r
64         onKeyDown : function(e) {\r
65                 e = e || window.event;\r
66 \r
67                 if (e.keyCode == 13)\r
68                         TinyMCE_EditableSelects.onBlurEditableSelectInput();\r
69         }\r
70 };\r