mp-wp_genesis 1 /**
mp-wp_genesis 2 * $Id: editable_selects.js 867 2008-06-09 20:33:40Z spocke $
mp-wp_genesis 3 *
mp-wp_genesis 4 * Makes select boxes editable.
mp-wp_genesis 5 *
mp-wp_genesis 6 * @author Moxiecode
mp-wp_genesis 7 */
mp-wp_genesis 8
mp-wp_genesis 9 var TinyMCE_EditableSelects = {
mp-wp_genesis 10 editSelectElm : null,
mp-wp_genesis 11
mp-wp_genesis 12 init : function() {
mp-wp_genesis 13 var nl = document.getElementsByTagName("select"), i, d = document, o;
mp-wp_genesis 14
mp-wp_genesis 15 for (i=0; i<nl.length; i++) {
mp-wp_genesis 16 if (nl[i].className.indexOf('mceEditableSelect') != -1) {
mp-wp_genesis 17 o = new Option('(value)', '__mce_add_custom__');
mp-wp_genesis 18
mp-wp_genesis 19 o.className = 'mceAddSelectValue';
mp-wp_genesis 20
mp-wp_genesis 21 nl[i].options[nl[i].options.length] = o;
mp-wp_genesis 22 nl[i].onchange = TinyMCE_EditableSelects.onChangeEditableSelect;
mp-wp_genesis 23 }
mp-wp_genesis 24 }
mp-wp_genesis 25 },
mp-wp_genesis 26
mp-wp_genesis 27 onChangeEditableSelect : function(e) {
mp-wp_genesis 28 var d = document, ne, se = window.event ? window.event.srcElement : e.target;
mp-wp_genesis 29
mp-wp_genesis 30 if (se.options[se.selectedIndex].value == '__mce_add_custom__') {
mp-wp_genesis 31 ne = d.createElement("input");
mp-wp_genesis 32 ne.id = se.id + "_custom";
mp-wp_genesis 33 ne.name = se.name + "_custom";
mp-wp_genesis 34 ne.type = "text";
mp-wp_genesis 35
mp-wp_genesis 36 ne.style.width = se.offsetWidth + 'px';
mp-wp_genesis 37 se.parentNode.insertBefore(ne, se);
mp-wp_genesis 38 se.style.display = 'none';
mp-wp_genesis 39 ne.focus();
mp-wp_genesis 40 ne.onblur = TinyMCE_EditableSelects.onBlurEditableSelectInput;
mp-wp_genesis 41 ne.onkeydown = TinyMCE_EditableSelects.onKeyDown;
mp-wp_genesis 42 TinyMCE_EditableSelects.editSelectElm = se;
mp-wp_genesis 43 }
mp-wp_genesis 44 },
mp-wp_genesis 45
mp-wp_genesis 46 onBlurEditableSelectInput : function() {
mp-wp_genesis 47 var se = TinyMCE_EditableSelects.editSelectElm;
mp-wp_genesis 48
mp-wp_genesis 49 if (se) {
mp-wp_genesis 50 if (se.previousSibling.value != '') {
mp-wp_genesis 51 addSelectValue(document.forms[0], se.id, se.previousSibling.value, se.previousSibling.value);
mp-wp_genesis 52 selectByValue(document.forms[0], se.id, se.previousSibling.value);
mp-wp_genesis 53 } else
mp-wp_genesis 54 selectByValue(document.forms[0], se.id, '');
mp-wp_genesis 55
mp-wp_genesis 56 se.style.display = 'inline';
mp-wp_genesis 57 se.parentNode.removeChild(se.previousSibling);
mp-wp_genesis 58 TinyMCE_EditableSelects.editSelectElm = null;
mp-wp_genesis 59 }
mp-wp_genesis 60 },
mp-wp_genesis 61
mp-wp_genesis 62 onKeyDown : function(e) {
mp-wp_genesis 63 e = e || window.event;
mp-wp_genesis 64
mp-wp_genesis 65 if (e.keyCode == 13)
mp-wp_genesis 66 TinyMCE_EditableSelects.onBlurEditableSelectInput();
mp-wp_genesis 67 }
mp-wp_genesis 68 };