4 * Copyright 2009, Moxiecode Systems AB
5 * Released under LGPL License.
7 * License: http://tinymce.moxiecode.com/license
8 * Contributing: http://tinymce.moxiecode.com/contributing
11 var themeBaseURL = tinyMCEPopup.editor.baseURI.toAbsolute('themes/' + tinyMCEPopup.getParam("theme"));
13 function getColorPickerHTML(id, target_form_element) {
16 h += '<a id="' + id + '_link" href="javascript:;" onclick="tinyMCEPopup.pickColor(event,\'' + target_form_element +'\');" onmousedown="return false;" class="pickcolor">';
17 h += '<span id="' + id + '" title="' + tinyMCEPopup.getLang('browse') + '"> </span></a>';
22 function updateColor(img_id, form_element_id) {
23 document.getElementById(img_id).style.backgroundColor = document.forms[0].elements[form_element_id].value;
26 function setBrowserDisabled(id, state) {
27 var img = document.getElementById(id);
28 var lnk = document.getElementById(id + "_link");
32 lnk.setAttribute("realhref", lnk.getAttribute("href"));
33 lnk.removeAttribute("href");
34 tinyMCEPopup.dom.addClass(img, 'disabled');
36 if (lnk.getAttribute("realhref"))
37 lnk.setAttribute("href", lnk.getAttribute("realhref"));
39 tinyMCEPopup.dom.removeClass(img, 'disabled');
44 function getBrowserHTML(id, target_form_element, type, prefix) {
45 var option = prefix + "_" + type + "_browser_callback", cb, html;
47 cb = tinyMCEPopup.getParam(option, tinyMCEPopup.getParam("file_browser_callback"));
53 html += '<a id="' + id + '_link" href="javascript:openBrowser(\'' + id + '\',\'' + target_form_element + '\', \'' + type + '\',\'' + option + '\');" onmousedown="return false;" class="browse">';
54 html += '<span id="' + id + '" title="' + tinyMCEPopup.getLang('browse') + '"> </span></a>';
59 function openBrowser(img_id, target_form_element, type, option) {
60 var img = document.getElementById(img_id);
62 if (img.className != "mceButtonDisabled")
63 tinyMCEPopup.openBrowser(target_form_element, type, option);
66 function selectByValue(form_obj, field_name, value, add_custom, ignore_case) {
67 if (!form_obj || !form_obj.elements[field_name])
70 var sel = form_obj.elements[field_name];
73 for (var i=0; i<sel.options.length; i++) {
74 var option = sel.options[i];
76 if (option.value == value || (ignore_case && option.value.toLowerCase() == value.toLowerCase())) {
77 option.selected = true;
80 option.selected = false;
83 if (!found && add_custom && value != '') {
84 var option = new Option(value, value);
85 option.selected = true;
86 sel.options[sel.options.length] = option;
87 sel.selectedIndex = sel.options.length - 1;
93 function getSelectValue(form_obj, field_name) {
94 var elm = form_obj.elements[field_name];
96 if (elm == null || elm.options == null || elm.selectedIndex === -1)
99 return elm.options[elm.selectedIndex].value;
102 function addSelectValue(form_obj, field_name, name, value) {
103 var s = form_obj.elements[field_name];
104 var o = new Option(name, value);
105 s.options[s.options.length] = o;
108 function addClassesToList(list_id, specific_option) {
109 // Setup class droplist
110 var styleSelectElm = document.getElementById(list_id);
111 var styles = tinyMCEPopup.getParam('theme_advanced_styles', false);
112 styles = tinyMCEPopup.getParam(specific_option, styles);
115 var stylesAr = styles.split(';');
117 for (var i=0; i<stylesAr.length; i++) {
118 if (stylesAr != "") {
121 key = stylesAr[i].split('=')[0];
122 value = stylesAr[i].split('=')[1];
124 styleSelectElm.options[styleSelectElm.length] = new Option(key, value);
128 tinymce.each(tinyMCEPopup.editor.dom.getClasses(), function(o) {
129 styleSelectElm.options[styleSelectElm.length] = new Option(o.title || o['class'], o['class']);
134 function isVisible(element_id) {
135 var elm = document.getElementById(element_id);
137 return elm && elm.style.display != "none";
140 function convertRGBToHex(col) {
141 var re = new RegExp("rgb\\s*\\(\\s*([0-9]+).*,\\s*([0-9]+).*,\\s*([0-9]+).*\\)", "gi");
143 var rgb = col.replace(re, "$1,$2,$3").split(',');
144 if (rgb.length == 3) {
145 r = parseInt(rgb[0]).toString(16);
146 g = parseInt(rgb[1]).toString(16);
147 b = parseInt(rgb[2]).toString(16);
149 r = r.length == 1 ? '0' + r : r;
150 g = g.length == 1 ? '0' + g : g;
151 b = b.length == 1 ? '0' + b : b;
153 return "#" + r + g + b;
159 function convertHexToRGB(col) {
160 if (col.indexOf('#') != -1) {
161 col = col.replace(new RegExp('[^0-9A-F]', 'gi'), '');
163 r = parseInt(col.substring(0, 2), 16);
164 g = parseInt(col.substring(2, 4), 16);
165 b = parseInt(col.substring(4, 6), 16);
167 return "rgb(" + r + "," + g + "," + b + ")";
173 function trimSize(size) {
174 return size.replace(/([0-9\.]+)px|(%|in|cm|mm|em|ex|pt|pc)/, '$1$2');
177 function getCSSSize(size) {
178 size = trimSize(size);
184 if (/^[0-9]+$/.test(size))
190 function getStyle(elm, attrib, style) {
191 var val = tinyMCEPopup.dom.getAttrib(elm, attrib);
196 if (typeof(style) == 'undefined')
199 return tinyMCEPopup.dom.getStyle(elm, style);