PageRenderTime 123ms CodeModel.GetById 60ms app.highlight 5ms RepoModel.GetById 55ms app.codeStats 0ms

/static/scripts/tiny_mce/utils/editable_selects.js

http://n23.googlecode.com/
JavaScript | 61 lines | 42 code | 11 blank | 8 comment | 8 complexity | 50cacc03ac0a11eff49e746e9f008609 MD5 | raw file
 1/**
 2 * $Id: editable_selects.js 520 2008-01-07 16:30:32Z spocke $
 3 *
 4 * Makes select boxes editable.
 5 *
 6 * @author Moxiecode
 7 * @copyright Copyright Š 2004-2008, Moxiecode Systems AB, All rights reserved.
 8 */
 9
10var TinyMCE_EditableSelects = {
11	editSelectElm : null,
12
13	init : function() {
14		var nl = document.getElementsByTagName("select"), i, d = document, o;
15
16		for (i=0; i<nl.length; i++) {
17			if (nl[i].className.indexOf('mceEditableSelect') != -1) {
18				o = new Option('(value)', '__mce_add_custom__');
19
20				o.className = 'mceAddSelectValue';
21
22				nl[i].options[nl[i].options.length] = o;
23				nl[i].onchange = TinyMCE_EditableSelects.onChangeEditableSelect;
24			}
25		}
26	},
27
28	onChangeEditableSelect : function(e) {
29		var d = document, ne, se = window.event ? window.event.srcElement : e.target;
30
31		if (se.options[se.selectedIndex].value == '__mce_add_custom__') {
32			ne = d.createElement("input");
33			ne.id = se.id + "_custom";
34			ne.name = se.name + "_custom";
35			ne.type = "text";
36
37			ne.style.width = se.offsetWidth + 'px';
38			se.parentNode.insertBefore(ne, se);
39			se.style.display = 'none';
40			ne.focus();
41			ne.onblur = TinyMCE_EditableSelects.onBlurEditableSelectInput;
42			TinyMCE_EditableSelects.editSelectElm = se;
43		}
44	},
45
46	onBlurEditableSelectInput : function() {
47		var se = TinyMCE_EditableSelects.editSelectElm;
48
49		if (se) {
50			if (se.previousSibling.value != '') {
51				addSelectValue(document.forms[0], se.id, se.previousSibling.value, se.previousSibling.value);
52				selectByValue(document.forms[0], se.id, se.previousSibling.value);
53			} else
54				selectByValue(document.forms[0], se.id, '');
55
56			se.style.display = 'inline';
57			se.parentNode.removeChild(se.previousSibling);
58			TinyMCE_EditableSelects.editSelectElm = null;
59		}
60	}
61};