* Removed the Kevin Roth rich text editor and replaced it with TinyMCE.
[citadel.git] / webcit / tiny_mce / utils / form_utils.js
1 /**
2  * $RCSfile$
3  * $Revision$
4  * $Date$
5  *
6  * Various form utilitiy functions.
7  *
8  * @author Moxiecode
9  * @copyright Copyright © 2005, Moxiecode Systems AB, All rights reserved.
10  */
11
12 function renderColorPicker(id, target_form_element) {
13         var html = "";
14
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>';
22
23         document.write(html);
24 }
25
26 function updateColor(img_id, form_element_id) {
27         document.getElementById(img_id).style.backgroundColor = document.forms[0].elements[form_element_id].value;
28 }
29
30 function setBrowserDisabled(id, state) {
31         var img = document.getElementById(id);
32         var lnk = document.getElementById(id + "_link");
33
34         if (lnk) {
35                 if (state) {
36                         lnk.setAttribute("realhref", lnk.getAttribute("href"));
37                         lnk.removeAttribute("href");
38                         tinyMCE.switchClass(img, 'mceButtonDisabled', true);
39                 } else {
40                         lnk.setAttribute("href", lnk.getAttribute("realhref"));
41                         tinyMCE.switchClass(img, 'mceButtonNormal', false);
42                 }
43         }
44 }
45
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"));
49         if (cb == null)
50                 return;
51
52         var html = "";
53
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>';
61
62         document.write(html);
63 }
64
65 function openBrower(img_id, target_form_element, type, option) {
66         var img = document.getElementById(img_id);
67
68         if (img.className != "mceButtonDisabled")
69                 tinyMCEPopup.openBrowser(target_form_element, type, option);
70 }
71
72 function selectByValue(form_obj, field_name, value, add_custom) {
73         if (!form_obj || !form_obj.elements[field_name])
74                 return;
75
76         var sel = form_obj.elements[field_name];
77
78         var found = false;
79         for (var i=0; i<sel.options.length; i++) {
80                 var option = sel.options[i];
81
82                 if (option.value == value) {
83                         option.selected = true;
84                         found = true;
85                 } else
86                         option.selected = false;
87         }
88
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;
93         }
94
95         return found;
96 }
97
98 function getSelectValue(form_obj, field_name) {
99         var elm = form_obj.elements[field_name];
100
101         if (elm == null || elm.options == null)
102                 return "";
103
104         return elm.options[elm.selectedIndex].value;
105 }
106
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);
112
113         if (styles) {
114                 var stylesAr = styles.split(';');
115
116                 for (var i=0; i<stylesAr.length; i++) {
117                         if (stylesAr != "") {
118                                 var key, value;
119
120                                 key = stylesAr[i].split('=')[0];
121                                 value = stylesAr[i].split('=')[1];
122
123                                 styleSelectElm.options[styleSelectElm.length] = new Option(key, value);
124                         }
125                 }
126         } else {
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]);
131         }
132 }
133
134 function isVisible(element_id) {
135         var elm = document.getElementById(element_id);
136
137         return elm && elm.style.display != "none";
138 }