2 * editable_selects.js
\r
4 * Copyright 2009, Moxiecode Systems AB
\r
5 * Released under LGPL License.
\r
7 * License: http://tinymce.moxiecode.com/license
\r
8 * Contributing: http://tinymce.moxiecode.com/contributing
\r
11 var TinyMCE_EditableSelects = {
\r
12 editSelectElm : null,
\r
15 var nl = document.getElementsByTagName("select"), i, d = document, o;
\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
21 o.className = 'mceAddSelectValue';
\r
23 nl[i].options[nl[i].options.length] = o;
\r
24 nl[i].onchange = TinyMCE_EditableSelects.onChangeEditableSelect;
\r
29 onChangeEditableSelect : function(e) {
\r
30 var d = document, ne, se = window.event ? window.event.srcElement : e.target;
\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
38 ne.style.width = se.offsetWidth + 'px';
\r
39 se.parentNode.insertBefore(ne, se);
\r
40 se.style.display = 'none';
\r
42 ne.onblur = TinyMCE_EditableSelects.onBlurEditableSelectInput;
\r
43 ne.onkeydown = TinyMCE_EditableSelects.onKeyDown;
\r
44 TinyMCE_EditableSelects.editSelectElm = se;
\r
48 onBlurEditableSelectInput : function() {
\r
49 var se = TinyMCE_EditableSelects.editSelectElm;
\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
56 selectByValue(document.forms[0], se.id, '');
\r
58 se.style.display = 'inline';
\r
59 se.parentNode.removeChild(se.previousSibling);
\r
60 TinyMCE_EditableSelects.editSelectElm = null;
\r
64 onKeyDown : function(e) {
\r
65 e = e || window.event;
\r
67 if (e.keyCode == 13)
\r
68 TinyMCE_EditableSelects.onBlurEditableSelectInput();
\r