annotate media/js/tiny_mce/utils/editable_selects.js @ 201:bc958bc3c6eb

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