6 * Various form utilitiy functions.
9 * @copyright Copyright © 2004-2006, Moxiecode Systems AB, All rights reserved.
12 function getColorPickerHTML(id, target_form_element) {
15 html += '<a id="' + id + '_link" href="javascript:void(0);" onkeydown="pickColor(event,\'' + target_form_element +'\');" onmousedown="pickColor(event,\'' + target_form_element +'\');return false;">';
16 html += '<img id="' + id + '" src="../../themes/advanced/images/color.gif"';
17 html += ' onmouseover="this.className=\'mceButtonOver\'"';
18 html += ' onmouseout="this.className=\'mceButtonNormal\'"';
19 html += ' onmousedown="this.className=\'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 pickColor(e, target_form_element) {
27 if ((e.keyCode == 32 || e.keyCode == 13) || e.type == "mousedown")
28 tinyMCEPopup.pickColor(e, target_form_element);
31 function updateColor(img_id, form_element_id) {
32 document.getElementById(img_id).style.backgroundColor = document.forms[0].elements[form_element_id].value;
35 function setBrowserDisabled(id, state) {
36 var img = document.getElementById(id);
37 var lnk = document.getElementById(id + "_link");
41 lnk.setAttribute("realhref", lnk.getAttribute("href"));
42 lnk.removeAttribute("href");
43 tinyMCE.switchClass(img, 'mceButtonDisabled', true);
45 lnk.setAttribute("href", lnk.getAttribute("realhref"));
46 tinyMCE.switchClass(img, 'mceButtonNormal', false);
51 function getBrowserHTML(id, target_form_element, type, prefix) {
52 var option = prefix + "_" + type + "_browser_callback";
53 var cb = tinyMCE.getParam(option, tinyMCE.getParam("file_browser_callback"));
59 html += '<a id="' + id + '_link" href="javascript:openBrower(\'' + id + '\',\'' + target_form_element + '\', \'' + type + '\',\'' + option + '\');" onmousedown="return false;">';
60 html += '<img id="' + id + '" src="../../themes/advanced/images/browse.gif"';
61 html += ' onmouseover="this.className=\'mceButtonOver\';"';
62 html += ' onmouseout="this.className=\'mceButtonNormal\';"';
63 html += ' onmousedown="this.className=\'mceButtonDown\';"';
64 html += ' width="20" height="18" border="0" title="' + tinyMCE.getLang('lang_browse') + '"';
65 html += ' class="mceButtonNormal" alt="' + tinyMCE.getLang('lang_browse') + '" /></a>';
70 function openBrower(img_id, target_form_element, type, option) {
71 var img = document.getElementById(img_id);
73 if (img.className != "mceButtonDisabled")
74 tinyMCEPopup.openBrowser(target_form_element, type, option);
77 function selectByValue(form_obj, field_name, value, add_custom, ignore_case) {
78 if (!form_obj || !form_obj.elements[field_name])
81 var sel = form_obj.elements[field_name];
84 for (var i=0; i<sel.options.length; i++) {
85 var option = sel.options[i];
87 if (option.value == value || (ignore_case && option.value.toLowerCase() == value.toLowerCase())) {
88 option.selected = true;
91 option.selected = false;
94 if (!found && add_custom && value != '') {
95 var option = new Option('Value: ' + value, value);
96 option.selected = true;
97 sel.options[sel.options.length] = option;
103 function getSelectValue(form_obj, field_name) {
104 var elm = form_obj.elements[field_name];
106 if (elm == null || elm.options == null)
109 return elm.options[elm.selectedIndex].value;
112 function addSelectValue(form_obj, field_name, name, value) {
113 var s = form_obj.elements[field_name];
114 var o = new Option(name, value);
115 s.options[s.options.length] = o;
118 function addClassesToList(list_id, specific_option) {
119 // Setup class droplist
120 var styleSelectElm = document.getElementById(list_id);
121 var styles = tinyMCE.getParam('theme_advanced_styles', false);
122 styles = tinyMCE.getParam(specific_option, styles);
125 var stylesAr = styles.split(';');
127 for (var i=0; i<stylesAr.length; i++) {
128 if (stylesAr != "") {
131 key = stylesAr[i].split('=')[0];
132 value = stylesAr[i].split('=')[1];
134 styleSelectElm.options[styleSelectElm.length] = new Option(key, value);
138 // Use auto impored classes
139 var csses = tinyMCE.getCSSClasses(tinyMCE.getWindowArg('editor_id'));
140 for (var i=0; i<csses.length; i++)
141 styleSelectElm.options[styleSelectElm.length] = new Option(csses[i], csses[i]);
145 function isVisible(element_id) {
146 var elm = document.getElementById(element_id);
148 return elm && elm.style.display != "none";
151 function convertRGBToHex(col) {
152 var re = new RegExp("rgb\\s*\\(\\s*([0-9]+).*,\\s*([0-9]+).*,\\s*([0-9]+).*\\)", "gi");
154 var rgb = col.replace(re, "$1,$2,$3").split(',');
155 if (rgb.length == 3) {
156 r = parseInt(rgb[0]).toString(16);
157 g = parseInt(rgb[1]).toString(16);
158 b = parseInt(rgb[2]).toString(16);
160 r = r.length == 1 ? '0' + r : r;
161 g = g.length == 1 ? '0' + g : g;
162 b = b.length == 1 ? '0' + b : b;
164 return "#" + r + g + b;
170 function convertHexToRGB(col) {
171 if (col.indexOf('#') != -1) {
172 col = col.replace(new RegExp('[^0-9A-F]', 'gi'), '');
174 r = parseInt(col.substring(0, 2), 16);
175 g = parseInt(col.substring(2, 4), 16);
176 b = parseInt(col.substring(4, 6), 16);
178 return "rgb(" + r + "," + g + "," + b + ")";
184 function trimSize(size) {
185 return size.replace(new RegExp('[^0-9%]', 'gi'), '');
188 function getCSSSize(size) {
189 size = trimSize(size);
194 return size.indexOf('%') != -1 ? size : size + "px";
197 function getStyle(elm, attrib, style) {
198 var val = tinyMCE.getAttrib(elm, attrib);
203 if (typeof(style) == 'undefined')
206 val = eval('elm.style.' + style);
208 return val == null ? '' : '' + val;