6 * Various form utilitiy functions.
9 * @copyright Copyright © 2005, Moxiecode Systems AB, All rights reserved.
12 function renderColorPicker(id, target_form_element) {
15 html += '<a id="' + id + '_link" href="javascript:tinyMCEPopup.pickColor(event,\'' + target_form_element +'\');" onmousedown="return false;">';
16 html += '<img id="' + id + '" src="../../themes/advanced/images/color.gif"';
17 html += ' onmouseover="tinyMCE.switchClass(this,\'mceButtonOver\');"';
18 html += ' onmouseout="tinyMCE.restoreClass(this);"';
19 html += ' onmousedown="tinyMCE.restoreAndSwitchClass(this,\'mceButtonDown\');"';
20 html += ' width="20" height="16" border="0" title="' + tinyMCE.getLang('lang_browse') + '"';
21 html += ' class="mceButtonNormal" alt="' + tinyMCE.getLang('lang_browse') + '" /></a>';
26 function updateColor(img_id, form_element_id) {
27 document.getElementById(img_id).style.backgroundColor = document.forms[0].elements[form_element_id].value;
30 function setBrowserDisabled(id, state) {
31 var img = document.getElementById(id);
32 var lnk = document.getElementById(id + "_link");
36 lnk.setAttribute("realhref", lnk.getAttribute("href"));
37 lnk.removeAttribute("href");
38 tinyMCE.switchClass(img, 'mceButtonDisabled', true);
40 lnk.setAttribute("href", lnk.getAttribute("realhref"));
41 tinyMCE.switchClass(img, 'mceButtonNormal', false);
46 function renderBrowser(id, target_form_element, type, prefix) {
47 var option = prefix + "_" + type + "_browser_callback";
48 var cb = tinyMCE.getParam(option, tinyMCE.getParam("file_browser_callback"));
54 html += '<a id="' + id + '_link" href="javascript:openBrower(\'' + id + '\',\'' + target_form_element + '\', \'' + type + '\',\'' + option + '\');" onmousedown="return false;">';
55 html += '<img id="' + id + '" src="../../themes/advanced/images/browse.gif"';
56 html += ' onmouseover="tinyMCE.switchClass(this,\'mceButtonOver\');"';
57 html += ' onmouseout="tinyMCE.restoreClass(this);"';
58 html += ' onmousedown="tinyMCE.restoreAndSwitchClass(this,\'mceButtonDown\');"';
59 html += ' width="20" height="18" border="0" title="' + tinyMCE.getLang('lang_browse') + '"';
60 html += ' class="mceButtonNormal" alt="' + tinyMCE.getLang('lang_browse') + '" /></a>';
65 function openBrower(img_id, target_form_element, type, option) {
66 var img = document.getElementById(img_id);
68 if (img.className != "mceButtonDisabled")
69 tinyMCEPopup.openBrowser(target_form_element, type, option);
72 function selectByValue(form_obj, field_name, value, add_custom) {
73 if (!form_obj || !form_obj.elements[field_name])
76 var sel = form_obj.elements[field_name];
79 for (var i=0; i<sel.options.length; i++) {
80 var option = sel.options[i];
82 if (option.value == value) {
83 option.selected = true;
86 option.selected = false;
89 if (!found && add_custom && value != '') {
90 var option = new Option('Value: ' + value, value);
91 option.selected = true;
92 sel.options[sel.options.length] = option;
98 function getSelectValue(form_obj, field_name) {
99 var elm = form_obj.elements[field_name];
101 if (elm == null || elm.options == null)
104 return elm.options[elm.selectedIndex].value;
107 function addClassesToList(list_id, specific_option) {
108 // Setup class droplist
109 var styleSelectElm = document.getElementById(list_id);
110 var styles = tinyMCE.getParam('theme_advanced_styles', false);
111 styles = tinyMCE.getParam(specific_option, styles);
114 var stylesAr = styles.split(';');
116 for (var i=0; i<stylesAr.length; i++) {
117 if (stylesAr != "") {
120 key = stylesAr[i].split('=')[0];
121 value = stylesAr[i].split('=')[1];
123 styleSelectElm.options[styleSelectElm.length] = new Option(key, value);
127 // Use auto impored classes
128 var csses = tinyMCE.getCSSClasses(tinyMCE.getWindowArg('editor_id'));
129 for (var i=0; i<csses.length; i++)
130 styleSelectElm.options[styleSelectElm.length] = new Option(csses[i], csses[i]);
134 function isVisible(element_id) {
135 var elm = document.getElementById(element_id);
137 return elm && elm.style.display != "none";