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