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