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: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="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 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 renderBrowser(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="tinyMCE.switchClass(this,\'mceButtonOver\');"';
62 html += ' onmouseout="tinyMCE.restoreClass(this);"';
63 html += ' onmousedown="tinyMCE.restoreAndSwitchClass(this,\'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) {
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) {
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 addClassesToList(list_id, specific_option) {
113 // Setup class droplist
114 var styleSelectElm = document.getElementById(list_id);
115 var styles = tinyMCE.getParam('theme_advanced_styles', false);
116 styles = tinyMCE.getParam(specific_option, styles);
119 var stylesAr = styles.split(';');
121 for (var i=0; i<stylesAr.length; i++) {
122 if (stylesAr != "") {
125 key = stylesAr[i].split('=')[0];
126 value = stylesAr[i].split('=')[1];
128 styleSelectElm.options[styleSelectElm.length] = new Option(key, value);
132 // Use auto impored classes
133 var csses = tinyMCE.getCSSClasses(tinyMCE.getWindowArg('editor_id'));
134 for (var i=0; i<csses.length; i++)
135 styleSelectElm.options[styleSelectElm.length] = new Option(csses[i], csses[i]);
139 function isVisible(element_id) {
140 var elm = document.getElementById(element_id);
142 return elm && elm.style.display != "none";
145 function convertRGBToHex(col) {
146 var re = new RegExp("rgb\\s*\\(\\s*([0-9]+).*,\\s*([0-9]+).*,\\s*([0-9]+).*\\)", "gi");
148 var rgb = col.replace(re, "$1,$2,$3").split(',');
149 if (rgb.length == 3) {
150 r = parseInt(rgb[0]).toString(16);
151 g = parseInt(rgb[1]).toString(16);
152 b = parseInt(rgb[2]).toString(16);
154 r = r.length == 1 ? '0' + r : r;
155 g = g.length == 1 ? '0' + g : g;
156 b = b.length == 1 ? '0' + b : b;
158 return "#" + r + g + b;
164 function convertHexToRGB(col) {
165 if (col.indexOf('#') != -1) {
166 col = col.replace(new RegExp('[^0-9A-F]', 'gi'), '');
168 r = parseInt(col.substring(0, 2), 16);
169 g = parseInt(col.substring(2, 4), 16);
170 b = parseInt(col.substring(4, 6), 16);
172 return "rgb(" + r + "," + g + "," + b + ")";
178 function trimSize(size) {
179 return size.replace(new RegExp('[^0-9%]', 'gi'), '');
182 function getCSSSize(size) {
183 size = trimSize(size);
188 return size.indexOf('%') != -1 ? size : size + "px";
191 function getStyle(elm, attrib, style) {
192 var val = tinyMCE.getAttrib(elm, attrib);
197 if (typeof(style) == 'undefined')
200 val = eval('elm.style.' + style);
202 return val == null ? '' : '' + val;