2007-01-16 18:52:13 +01:00
|
|
|
/**
|
2010-10-02 07:14:12 +02:00
|
|
|
* form_utils.js
|
2007-01-16 18:52:13 +01:00
|
|
|
*
|
2010-10-02 07:14:12 +02:00
|
|
|
* Copyright 2009, Moxiecode Systems AB
|
|
|
|
* Released under LGPL License.
|
2007-01-16 18:52:13 +01:00
|
|
|
*
|
2010-10-02 07:14:12 +02:00
|
|
|
* License: http://tinymce.moxiecode.com/license
|
|
|
|
* Contributing: http://tinymce.moxiecode.com/contributing
|
2007-01-16 18:52:13 +01:00
|
|
|
*/
|
|
|
|
|
2008-01-17 16:44:05 +01:00
|
|
|
var themeBaseURL = tinyMCEPopup.editor.baseURI.toAbsolute('themes/' + tinyMCEPopup.getParam("theme"));
|
2007-01-16 18:52:13 +01:00
|
|
|
|
|
|
|
function getColorPickerHTML(id, target_form_element) {
|
2011-04-10 20:36:05 +02:00
|
|
|
var h = "", dom = tinyMCEPopup.dom;
|
2007-01-16 18:52:13 +01:00
|
|
|
|
2011-04-10 20:36:05 +02:00
|
|
|
if (label = dom.select('label[for=' + target_form_element + ']')[0]) {
|
|
|
|
label.id = label.id || dom.uniqueId();
|
|
|
|
}
|
|
|
|
|
|
|
|
h += '<a role="button" aria-labelledby="' + id + '_label" id="' + id + '_link" href="javascript:;" onclick="tinyMCEPopup.pickColor(event,\'' + target_form_element +'\');" onmousedown="return false;" class="pickcolor">';
|
|
|
|
h += '<span id="' + id + '" title="' + tinyMCEPopup.getLang('browse') + '"> <span id="' + id + '_label" class="mceVoiceLabel mceIconOnly" style="display:none;">' + tinyMCEPopup.getLang('browse') + '</span></span></a>';
|
2007-01-16 18:52:13 +01:00
|
|
|
|
|
|
|
return h;
|
|
|
|
}
|
|
|
|
|
|
|
|
function updateColor(img_id, form_element_id) {
|
|
|
|
document.getElementById(img_id).style.backgroundColor = document.forms[0].elements[form_element_id].value;
|
|
|
|
}
|
|
|
|
|
|
|
|
function setBrowserDisabled(id, state) {
|
|
|
|
var img = document.getElementById(id);
|
|
|
|
var lnk = document.getElementById(id + "_link");
|
|
|
|
|
|
|
|
if (lnk) {
|
|
|
|
if (state) {
|
|
|
|
lnk.setAttribute("realhref", lnk.getAttribute("href"));
|
|
|
|
lnk.removeAttribute("href");
|
2008-01-17 16:44:05 +01:00
|
|
|
tinyMCEPopup.dom.addClass(img, 'disabled');
|
2007-01-16 18:52:13 +01:00
|
|
|
} else {
|
2008-02-21 22:40:25 +01:00
|
|
|
if (lnk.getAttribute("realhref"))
|
|
|
|
lnk.setAttribute("href", lnk.getAttribute("realhref"));
|
|
|
|
|
2008-01-17 16:44:05 +01:00
|
|
|
tinyMCEPopup.dom.removeClass(img, 'disabled');
|
2007-01-16 18:52:13 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
function getBrowserHTML(id, target_form_element, type, prefix) {
|
2008-01-17 16:44:05 +01:00
|
|
|
var option = prefix + "_" + type + "_browser_callback", cb, html;
|
2007-01-16 18:52:13 +01:00
|
|
|
|
2008-01-17 16:44:05 +01:00
|
|
|
cb = tinyMCEPopup.getParam(option, tinyMCEPopup.getParam("file_browser_callback"));
|
2007-01-16 18:52:13 +01:00
|
|
|
|
2008-01-17 16:44:05 +01:00
|
|
|
if (!cb)
|
|
|
|
return "";
|
|
|
|
|
|
|
|
html = "";
|
|
|
|
html += '<a id="' + id + '_link" href="javascript:openBrowser(\'' + id + '\',\'' + target_form_element + '\', \'' + type + '\',\'' + option + '\');" onmousedown="return false;" class="browse">';
|
2009-03-15 17:55:49 +01:00
|
|
|
html += '<span id="' + id + '" title="' + tinyMCEPopup.getLang('browse') + '"> </span></a>';
|
2007-01-16 18:52:13 +01:00
|
|
|
|
|
|
|
return html;
|
|
|
|
}
|
|
|
|
|
2008-01-17 16:44:05 +01:00
|
|
|
function openBrowser(img_id, target_form_element, type, option) {
|
2007-01-16 18:52:13 +01:00
|
|
|
var img = document.getElementById(img_id);
|
|
|
|
|
|
|
|
if (img.className != "mceButtonDisabled")
|
|
|
|
tinyMCEPopup.openBrowser(target_form_element, type, option);
|
|
|
|
}
|
|
|
|
|
|
|
|
function selectByValue(form_obj, field_name, value, add_custom, ignore_case) {
|
|
|
|
if (!form_obj || !form_obj.elements[field_name])
|
|
|
|
return;
|
|
|
|
|
2011-04-10 20:36:05 +02:00
|
|
|
if (!value)
|
|
|
|
value = "";
|
|
|
|
|
2007-01-16 18:52:13 +01:00
|
|
|
var sel = form_obj.elements[field_name];
|
|
|
|
|
|
|
|
var found = false;
|
|
|
|
for (var i=0; i<sel.options.length; i++) {
|
|
|
|
var option = sel.options[i];
|
|
|
|
|
|
|
|
if (option.value == value || (ignore_case && option.value.toLowerCase() == value.toLowerCase())) {
|
|
|
|
option.selected = true;
|
|
|
|
found = true;
|
|
|
|
} else
|
|
|
|
option.selected = false;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!found && add_custom && value != '') {
|
|
|
|
var option = new Option(value, value);
|
|
|
|
option.selected = true;
|
|
|
|
sel.options[sel.options.length] = option;
|
|
|
|
sel.selectedIndex = sel.options.length - 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
return found;
|
|
|
|
}
|
|
|
|
|
|
|
|
function getSelectValue(form_obj, field_name) {
|
|
|
|
var elm = form_obj.elements[field_name];
|
|
|
|
|
2009-09-26 10:33:16 +02:00
|
|
|
if (elm == null || elm.options == null || elm.selectedIndex === -1)
|
2007-01-16 18:52:13 +01:00
|
|
|
return "";
|
|
|
|
|
|
|
|
return elm.options[elm.selectedIndex].value;
|
|
|
|
}
|
|
|
|
|
|
|
|
function addSelectValue(form_obj, field_name, name, value) {
|
|
|
|
var s = form_obj.elements[field_name];
|
|
|
|
var o = new Option(name, value);
|
|
|
|
s.options[s.options.length] = o;
|
|
|
|
}
|
|
|
|
|
|
|
|
function addClassesToList(list_id, specific_option) {
|
|
|
|
// Setup class droplist
|
|
|
|
var styleSelectElm = document.getElementById(list_id);
|
2008-01-17 16:44:05 +01:00
|
|
|
var styles = tinyMCEPopup.getParam('theme_advanced_styles', false);
|
|
|
|
styles = tinyMCEPopup.getParam(specific_option, styles);
|
2007-01-16 18:52:13 +01:00
|
|
|
|
|
|
|
if (styles) {
|
|
|
|
var stylesAr = styles.split(';');
|
|
|
|
|
|
|
|
for (var i=0; i<stylesAr.length; i++) {
|
|
|
|
if (stylesAr != "") {
|
|
|
|
var key, value;
|
|
|
|
|
|
|
|
key = stylesAr[i].split('=')[0];
|
|
|
|
value = stylesAr[i].split('=')[1];
|
|
|
|
|
|
|
|
styleSelectElm.options[styleSelectElm.length] = new Option(key, value);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
} else {
|
2008-01-17 16:44:05 +01:00
|
|
|
tinymce.each(tinyMCEPopup.editor.dom.getClasses(), function(o) {
|
|
|
|
styleSelectElm.options[styleSelectElm.length] = new Option(o.title || o['class'], o['class']);
|
|
|
|
});
|
2007-01-16 18:52:13 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
function isVisible(element_id) {
|
|
|
|
var elm = document.getElementById(element_id);
|
|
|
|
|
|
|
|
return elm && elm.style.display != "none";
|
|
|
|
}
|
|
|
|
|
|
|
|
function convertRGBToHex(col) {
|
|
|
|
var re = new RegExp("rgb\\s*\\(\\s*([0-9]+).*,\\s*([0-9]+).*,\\s*([0-9]+).*\\)", "gi");
|
|
|
|
|
|
|
|
var rgb = col.replace(re, "$1,$2,$3").split(',');
|
|
|
|
if (rgb.length == 3) {
|
|
|
|
r = parseInt(rgb[0]).toString(16);
|
|
|
|
g = parseInt(rgb[1]).toString(16);
|
|
|
|
b = parseInt(rgb[2]).toString(16);
|
|
|
|
|
|
|
|
r = r.length == 1 ? '0' + r : r;
|
|
|
|
g = g.length == 1 ? '0' + g : g;
|
|
|
|
b = b.length == 1 ? '0' + b : b;
|
|
|
|
|
|
|
|
return "#" + r + g + b;
|
|
|
|
}
|
|
|
|
|
|
|
|
return col;
|
|
|
|
}
|
|
|
|
|
|
|
|
function convertHexToRGB(col) {
|
|
|
|
if (col.indexOf('#') != -1) {
|
|
|
|
col = col.replace(new RegExp('[^0-9A-F]', 'gi'), '');
|
|
|
|
|
|
|
|
r = parseInt(col.substring(0, 2), 16);
|
|
|
|
g = parseInt(col.substring(2, 4), 16);
|
|
|
|
b = parseInt(col.substring(4, 6), 16);
|
|
|
|
|
|
|
|
return "rgb(" + r + "," + g + "," + b + ")";
|
|
|
|
}
|
|
|
|
|
|
|
|
return col;
|
|
|
|
}
|
|
|
|
|
|
|
|
function trimSize(size) {
|
2011-04-10 20:36:05 +02:00
|
|
|
return size.replace(/([0-9\.]+)(px|%|in|cm|mm|em|ex|pt|pc)/i, '$1$2');
|
2007-01-16 18:52:13 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
function getCSSSize(size) {
|
|
|
|
size = trimSize(size);
|
|
|
|
|
|
|
|
if (size == "")
|
|
|
|
return "";
|
|
|
|
|
2008-03-12 23:47:11 +01:00
|
|
|
// Add px
|
|
|
|
if (/^[0-9]+$/.test(size))
|
|
|
|
size += 'px';
|
2011-04-10 20:36:05 +02:00
|
|
|
// Sanity check, IE doesn't like broken values
|
|
|
|
else if (!(/^[0-9\.]+(px|%|in|cm|mm|em|ex|pt|pc)$/i.test(size)))
|
|
|
|
return "";
|
2008-03-12 23:47:11 +01:00
|
|
|
|
|
|
|
return size;
|
2007-01-16 18:52:13 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
function getStyle(elm, attrib, style) {
|
2008-01-17 16:44:05 +01:00
|
|
|
var val = tinyMCEPopup.dom.getAttrib(elm, attrib);
|
2007-01-16 18:52:13 +01:00
|
|
|
|
|
|
|
if (val != '')
|
|
|
|
return '' + val;
|
|
|
|
|
|
|
|
if (typeof(style) == 'undefined')
|
|
|
|
style = attrib;
|
|
|
|
|
2008-01-17 16:44:05 +01:00
|
|
|
return tinyMCEPopup.dom.getStyle(elm, style);
|
2007-01-16 18:52:13 +01:00
|
|
|
}
|