2 * $Id: form_utils.js 673 2008-03-06 13:26:20Z spocke $
\r
4 * Various form utilitiy functions.
\r
7 * @copyright Copyright © 2004-2008, Moxiecode Systems AB, All rights reserved.
\r
10 var themeBaseURL = tinyMCEPopup.editor.baseURI.toAbsolute('themes/' + tinyMCEPopup.getParam("theme"));
\r
12 function getColorPickerHTML(id, target_form_element) {
\r
15 h += '<a id="' + id + '_link" href="javascript:;" onclick="tinyMCEPopup.pickColor(event,\'' + target_form_element +'\');" onmousedown="return false;" class="pickcolor">';
\r
16 h += '<span id="' + id + '" title="' + tinyMCEPopup.getLang('browse') + '"></span></a>';
\r
21 function updateColor(img_id, form_element_id) {
\r
22 document.getElementById(img_id).style.backgroundColor = document.forms[0].elements[form_element_id].value;
\r
25 function setBrowserDisabled(id, state) {
\r
26 var img = document.getElementById(id);
\r
27 var lnk = document.getElementById(id + "_link");
\r
31 lnk.setAttribute("realhref", lnk.getAttribute("href"));
\r
32 lnk.removeAttribute("href");
\r
33 tinyMCEPopup.dom.addClass(img, 'disabled');
\r
35 if (lnk.getAttribute("realhref"))
\r
36 lnk.setAttribute("href", lnk.getAttribute("realhref"));
\r
38 tinyMCEPopup.dom.removeClass(img, 'disabled');
\r
43 function getBrowserHTML(id, target_form_element, type, prefix) {
\r
44 var option = prefix + "_" + type + "_browser_callback", cb, html;
\r
46 cb = tinyMCEPopup.getParam(option, tinyMCEPopup.getParam("file_browser_callback"));
\r
52 html += '<a id="' + id + '_link" href="javascript:openBrowser(\'' + id + '\',\'' + target_form_element + '\', \'' + type + '\',\'' + option + '\');" onmousedown="return false;" class="browse">';
\r
53 html += '<span id="' + id + '" title="' + tinyMCEPopup.getLang('browse') + '"></span></a>';
\r
58 function openBrowser(img_id, target_form_element, type, option) {
\r
59 var img = document.getElementById(img_id);
\r
61 if (img.className != "mceButtonDisabled")
\r
62 tinyMCEPopup.openBrowser(target_form_element, type, option);
\r
65 function selectByValue(form_obj, field_name, value, add_custom, ignore_case) {
\r
66 if (!form_obj || !form_obj.elements[field_name])
\r
69 var sel = form_obj.elements[field_name];
\r
72 for (var i=0; i<sel.options.length; i++) {
\r
73 var option = sel.options[i];
\r
75 if (option.value == value || (ignore_case && option.value.toLowerCase() == value.toLowerCase())) {
\r
76 option.selected = true;
\r
79 option.selected = false;
\r
82 if (!found && add_custom && value != '') {
\r
83 var option = new Option(value, value);
\r
84 option.selected = true;
\r
85 sel.options[sel.options.length] = option;
\r
86 sel.selectedIndex = sel.options.length - 1;
\r
92 function getSelectValue(form_obj, field_name) {
\r
93 var elm = form_obj.elements[field_name];
\r
95 if (elm == null || elm.options == null)
\r
98 return elm.options[elm.selectedIndex].value;
\r
101 function addSelectValue(form_obj, field_name, name, value) {
\r
102 var s = form_obj.elements[field_name];
\r
103 var o = new Option(name, value);
\r
104 s.options[s.options.length] = o;
\r
107 function addClassesToList(list_id, specific_option) {
\r
108 // Setup class droplist
\r
109 var styleSelectElm = document.getElementById(list_id);
\r
110 var styles = tinyMCEPopup.getParam('theme_advanced_styles', false);
\r
111 styles = tinyMCEPopup.getParam(specific_option, styles);
\r
114 var stylesAr = styles.split(';');
\r
116 for (var i=0; i<stylesAr.length; i++) {
\r
117 if (stylesAr != "") {
\r
120 key = stylesAr[i].split('=')[0];
\r
121 value = stylesAr[i].split('=')[1];
\r
123 styleSelectElm.options[styleSelectElm.length] = new Option(key, value);
\r
127 tinymce.each(tinyMCEPopup.editor.dom.getClasses(), function(o) {
\r
128 styleSelectElm.options[styleSelectElm.length] = new Option(o.title || o['class'], o['class']);
\r
133 function isVisible(element_id) {
\r
134 var elm = document.getElementById(element_id);
\r
136 return elm && elm.style.display != "none";
\r
139 function convertRGBToHex(col) {
\r
140 var re = new RegExp("rgb\\s*\\(\\s*([0-9]+).*,\\s*([0-9]+).*,\\s*([0-9]+).*\\)", "gi");
\r
142 var rgb = col.replace(re, "$1,$2,$3").split(',');
\r
143 if (rgb.length == 3) {
\r
144 r = parseInt(rgb[0]).toString(16);
\r
145 g = parseInt(rgb[1]).toString(16);
\r
146 b = parseInt(rgb[2]).toString(16);
\r
148 r = r.length == 1 ? '0' + r : r;
\r
149 g = g.length == 1 ? '0' + g : g;
\r
150 b = b.length == 1 ? '0' + b : b;
\r
152 return "#" + r + g + b;
\r
158 function convertHexToRGB(col) {
\r
159 if (col.indexOf('#') != -1) {
\r
160 col = col.replace(new RegExp('[^0-9A-F]', 'gi'), '');
\r
162 r = parseInt(col.substring(0, 2), 16);
\r
163 g = parseInt(col.substring(2, 4), 16);
\r
164 b = parseInt(col.substring(4, 6), 16);
\r
166 return "rgb(" + r + "," + g + "," + b + ")";
\r
172 function trimSize(size) {
\r
173 return size.replace(/([0-9\.]+)px|(%|in|cm|mm|em|ex|pt|pc)/, '$1$2');
\r
176 function getCSSSize(size) {
\r
177 size = trimSize(size);
\r
183 if (/^[0-9]+$/.test(size))
\r
189 function getStyle(elm, attrib, style) {
\r
190 var val = tinyMCEPopup.dom.getAttrib(elm, attrib);
\r
195 if (typeof(style) == 'undefined')
\r
198 return tinyMCEPopup.dom.getStyle(elm, style);
\r