src/polemictweet/static/js/tiny_mce/utils/editable_selects.js
author grandjoncl
Fri, 08 Feb 2013 18:00:04 +0100
changeset 1 5a91860c5535
permissions -rw-r--r--
first commit of polemictweet
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
1
5a91860c5535 first commit of polemictweet
grandjoncl
parents:
diff changeset
     1
/**
5a91860c5535 first commit of polemictweet
grandjoncl
parents:
diff changeset
     2
 * editable_selects.js
5a91860c5535 first commit of polemictweet
grandjoncl
parents:
diff changeset
     3
 *
5a91860c5535 first commit of polemictweet
grandjoncl
parents:
diff changeset
     4
 * Copyright 2009, Moxiecode Systems AB
5a91860c5535 first commit of polemictweet
grandjoncl
parents:
diff changeset
     5
 * Released under LGPL License.
5a91860c5535 first commit of polemictweet
grandjoncl
parents:
diff changeset
     6
 *
5a91860c5535 first commit of polemictweet
grandjoncl
parents:
diff changeset
     7
 * License: http://tinymce.moxiecode.com/license
5a91860c5535 first commit of polemictweet
grandjoncl
parents:
diff changeset
     8
 * Contributing: http://tinymce.moxiecode.com/contributing
5a91860c5535 first commit of polemictweet
grandjoncl
parents:
diff changeset
     9
 */
5a91860c5535 first commit of polemictweet
grandjoncl
parents:
diff changeset
    10
5a91860c5535 first commit of polemictweet
grandjoncl
parents:
diff changeset
    11
var TinyMCE_EditableSelects = {
5a91860c5535 first commit of polemictweet
grandjoncl
parents:
diff changeset
    12
	editSelectElm : null,
5a91860c5535 first commit of polemictweet
grandjoncl
parents:
diff changeset
    13
5a91860c5535 first commit of polemictweet
grandjoncl
parents:
diff changeset
    14
	init : function() {
5a91860c5535 first commit of polemictweet
grandjoncl
parents:
diff changeset
    15
		var nl = document.getElementsByTagName("select"), i, d = document, o;
5a91860c5535 first commit of polemictweet
grandjoncl
parents:
diff changeset
    16
5a91860c5535 first commit of polemictweet
grandjoncl
parents:
diff changeset
    17
		for (i=0; i<nl.length; i++) {
5a91860c5535 first commit of polemictweet
grandjoncl
parents:
diff changeset
    18
			if (nl[i].className.indexOf('mceEditableSelect') != -1) {
5a91860c5535 first commit of polemictweet
grandjoncl
parents:
diff changeset
    19
				o = new Option(tinyMCEPopup.editor.translate('value'), '__mce_add_custom__');
5a91860c5535 first commit of polemictweet
grandjoncl
parents:
diff changeset
    20
5a91860c5535 first commit of polemictweet
grandjoncl
parents:
diff changeset
    21
				o.className = 'mceAddSelectValue';
5a91860c5535 first commit of polemictweet
grandjoncl
parents:
diff changeset
    22
5a91860c5535 first commit of polemictweet
grandjoncl
parents:
diff changeset
    23
				nl[i].options[nl[i].options.length] = o;
5a91860c5535 first commit of polemictweet
grandjoncl
parents:
diff changeset
    24
				nl[i].onchange = TinyMCE_EditableSelects.onChangeEditableSelect;
5a91860c5535 first commit of polemictweet
grandjoncl
parents:
diff changeset
    25
			}
5a91860c5535 first commit of polemictweet
grandjoncl
parents:
diff changeset
    26
		}
5a91860c5535 first commit of polemictweet
grandjoncl
parents:
diff changeset
    27
	},
5a91860c5535 first commit of polemictweet
grandjoncl
parents:
diff changeset
    28
5a91860c5535 first commit of polemictweet
grandjoncl
parents:
diff changeset
    29
	onChangeEditableSelect : function(e) {
5a91860c5535 first commit of polemictweet
grandjoncl
parents:
diff changeset
    30
		var d = document, ne, se = window.event ? window.event.srcElement : e.target;
5a91860c5535 first commit of polemictweet
grandjoncl
parents:
diff changeset
    31
5a91860c5535 first commit of polemictweet
grandjoncl
parents:
diff changeset
    32
		if (se.options[se.selectedIndex].value == '__mce_add_custom__') {
5a91860c5535 first commit of polemictweet
grandjoncl
parents:
diff changeset
    33
			ne = d.createElement("input");
5a91860c5535 first commit of polemictweet
grandjoncl
parents:
diff changeset
    34
			ne.id = se.id + "_custom";
5a91860c5535 first commit of polemictweet
grandjoncl
parents:
diff changeset
    35
			ne.name = se.name + "_custom";
5a91860c5535 first commit of polemictweet
grandjoncl
parents:
diff changeset
    36
			ne.type = "text";
5a91860c5535 first commit of polemictweet
grandjoncl
parents:
diff changeset
    37
5a91860c5535 first commit of polemictweet
grandjoncl
parents:
diff changeset
    38
			ne.style.width = se.offsetWidth + 'px';
5a91860c5535 first commit of polemictweet
grandjoncl
parents:
diff changeset
    39
			se.parentNode.insertBefore(ne, se);
5a91860c5535 first commit of polemictweet
grandjoncl
parents:
diff changeset
    40
			se.style.display = 'none';
5a91860c5535 first commit of polemictweet
grandjoncl
parents:
diff changeset
    41
			ne.focus();
5a91860c5535 first commit of polemictweet
grandjoncl
parents:
diff changeset
    42
			ne.onblur = TinyMCE_EditableSelects.onBlurEditableSelectInput;
5a91860c5535 first commit of polemictweet
grandjoncl
parents:
diff changeset
    43
			ne.onkeydown = TinyMCE_EditableSelects.onKeyDown;
5a91860c5535 first commit of polemictweet
grandjoncl
parents:
diff changeset
    44
			TinyMCE_EditableSelects.editSelectElm = se;
5a91860c5535 first commit of polemictweet
grandjoncl
parents:
diff changeset
    45
		}
5a91860c5535 first commit of polemictweet
grandjoncl
parents:
diff changeset
    46
	},
5a91860c5535 first commit of polemictweet
grandjoncl
parents:
diff changeset
    47
5a91860c5535 first commit of polemictweet
grandjoncl
parents:
diff changeset
    48
	onBlurEditableSelectInput : function() {
5a91860c5535 first commit of polemictweet
grandjoncl
parents:
diff changeset
    49
		var se = TinyMCE_EditableSelects.editSelectElm;
5a91860c5535 first commit of polemictweet
grandjoncl
parents:
diff changeset
    50
5a91860c5535 first commit of polemictweet
grandjoncl
parents:
diff changeset
    51
		if (se) {
5a91860c5535 first commit of polemictweet
grandjoncl
parents:
diff changeset
    52
			if (se.previousSibling.value != '') {
5a91860c5535 first commit of polemictweet
grandjoncl
parents:
diff changeset
    53
				addSelectValue(document.forms[0], se.id, se.previousSibling.value, se.previousSibling.value);
5a91860c5535 first commit of polemictweet
grandjoncl
parents:
diff changeset
    54
				selectByValue(document.forms[0], se.id, se.previousSibling.value);
5a91860c5535 first commit of polemictweet
grandjoncl
parents:
diff changeset
    55
			} else
5a91860c5535 first commit of polemictweet
grandjoncl
parents:
diff changeset
    56
				selectByValue(document.forms[0], se.id, '');
5a91860c5535 first commit of polemictweet
grandjoncl
parents:
diff changeset
    57
5a91860c5535 first commit of polemictweet
grandjoncl
parents:
diff changeset
    58
			se.style.display = 'inline';
5a91860c5535 first commit of polemictweet
grandjoncl
parents:
diff changeset
    59
			se.parentNode.removeChild(se.previousSibling);
5a91860c5535 first commit of polemictweet
grandjoncl
parents:
diff changeset
    60
			TinyMCE_EditableSelects.editSelectElm = null;
5a91860c5535 first commit of polemictweet
grandjoncl
parents:
diff changeset
    61
		}
5a91860c5535 first commit of polemictweet
grandjoncl
parents:
diff changeset
    62
	},
5a91860c5535 first commit of polemictweet
grandjoncl
parents:
diff changeset
    63
5a91860c5535 first commit of polemictweet
grandjoncl
parents:
diff changeset
    64
	onKeyDown : function(e) {
5a91860c5535 first commit of polemictweet
grandjoncl
parents:
diff changeset
    65
		e = e || window.event;
5a91860c5535 first commit of polemictweet
grandjoncl
parents:
diff changeset
    66
5a91860c5535 first commit of polemictweet
grandjoncl
parents:
diff changeset
    67
		if (e.keyCode == 13)
5a91860c5535 first commit of polemictweet
grandjoncl
parents:
diff changeset
    68
			TinyMCE_EditableSelects.onBlurEditableSelectInput();
5a91860c5535 first commit of polemictweet
grandjoncl
parents:
diff changeset
    69
	}
5a91860c5535 first commit of polemictweet
grandjoncl
parents:
diff changeset
    70
};