/**\r
- * $RCSfile: form_utils.js,v $\r
- * $Revision: 1.5 $\r
- * $Date: 2005/10/25 16:01:51 $\r
+ * form_utils.js\r
*\r
- * Various form utilitiy functions.\r
+ * Copyright 2009, Moxiecode Systems AB\r
+ * Released under LGPL License.\r
*\r
- * @author Moxiecode\r
- * @copyright Copyright © 2005, Moxiecode Systems AB, All rights reserved.\r
+ * License: http://tinymce.moxiecode.com/license\r
+ * Contributing: http://tinymce.moxiecode.com/contributing\r
*/\r
\r
+var themeBaseURL = tinyMCEPopup.editor.baseURI.toAbsolute('themes/' + tinyMCEPopup.getParam("theme"));\r
+\r
function getColorPickerHTML(id, target_form_element) {\r
- var html = "";\r
+ var h = "", dom = tinyMCEPopup.dom;\r
\r
- html += '<a id="' + id + '_link" href="javascript:void(0);" onkeydown="pickColor(event,\'' + target_form_element +'\');" onmousedown="pickColor(event,\'' + target_form_element +'\');return false;">';\r
- html += '<img id="' + id + '" src="../../themes/advanced/images/color.gif"';\r
- html += ' onmouseover="tinyMCE.switchClass(this,\'mceButtonOver\');"';\r
- html += ' onmouseout="tinyMCE.restoreClass(this);"';\r
- html += ' onmousedown="tinyMCE.restoreAndSwitchClass(this,\'mceButtonDown\');"';\r
- html += ' width="20" height="16" border="0" title="' + tinyMCE.getLang('lang_browse') + '"';\r
- html += ' class="mceButtonNormal" alt="' + tinyMCE.getLang('lang_browse') + '" /></a>';\r
+ if (label = dom.select('label[for=' + target_form_element + ']')[0]) {\r
+ label.id = label.id || dom.uniqueId();\r
+ }\r
\r
- return html;\r
-}\r
+ 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">';\r
+ h += '<span id="' + id + '" title="' + tinyMCEPopup.getLang('browse') + '"> <span id="' + id + '_label" class="mceVoiceLabel mceIconOnly" style="display:none;">' + tinyMCEPopup.getLang('browse') + '</span></span></a>';\r
\r
-function pickColor(e, target_form_element) {\r
- if ((e.keyCode == 32 || e.keyCode == 13) || e.type == "mousedown")\r
- tinyMCEPopup.pickColor(e, target_form_element);\r
+ return h;\r
}\r
\r
function updateColor(img_id, form_element_id) {\r
if (state) {\r
lnk.setAttribute("realhref", lnk.getAttribute("href"));\r
lnk.removeAttribute("href");\r
- tinyMCE.switchClass(img, 'mceButtonDisabled', true);\r
+ tinyMCEPopup.dom.addClass(img, 'disabled');\r
} else {\r
- lnk.setAttribute("href", lnk.getAttribute("realhref"));\r
- tinyMCE.switchClass(img, 'mceButtonNormal', false);\r
+ if (lnk.getAttribute("realhref"))\r
+ lnk.setAttribute("href", lnk.getAttribute("realhref"));\r
+\r
+ tinyMCEPopup.dom.removeClass(img, 'disabled');\r
}\r
}\r
}\r
\r
function getBrowserHTML(id, target_form_element, type, prefix) {\r
- var option = prefix + "_" + type + "_browser_callback";\r
- var cb = tinyMCE.getParam(option, tinyMCE.getParam("file_browser_callback"));\r
- if (cb == null)\r
- return "";\r
+ var option = prefix + "_" + type + "_browser_callback", cb, html;\r
+\r
+ cb = tinyMCEPopup.getParam(option, tinyMCEPopup.getParam("file_browser_callback"));\r
\r
- var html = "";\r
+ if (!cb)\r
+ return "";\r
\r
- html += '<a id="' + id + '_link" href="javascript:openBrower(\'' + id + '\',\'' + target_form_element + '\', \'' + type + '\',\'' + option + '\');" onmousedown="return false;">';\r
- html += '<img id="' + id + '" src="../../themes/advanced/images/browse.gif"';\r
- html += ' onmouseover="tinyMCE.switchClass(this,\'mceButtonOver\');"';\r
- html += ' onmouseout="tinyMCE.restoreClass(this);"';\r
- html += ' onmousedown="tinyMCE.restoreAndSwitchClass(this,\'mceButtonDown\');"';\r
- html += ' width="20" height="18" border="0" title="' + tinyMCE.getLang('lang_browse') + '"';\r
- html += ' class="mceButtonNormal" alt="' + tinyMCE.getLang('lang_browse') + '" /></a>';\r
+ html = "";\r
+ html += '<a id="' + id + '_link" href="javascript:openBrowser(\'' + id + '\',\'' + target_form_element + '\', \'' + type + '\',\'' + option + '\');" onmousedown="return false;" class="browse">';\r
+ html += '<span id="' + id + '" title="' + tinyMCEPopup.getLang('browse') + '"> </span></a>';\r
\r
return html;\r
}\r
\r
-function openBrower(img_id, target_form_element, type, option) {\r
+function openBrowser(img_id, target_form_element, type, option) {\r
var img = document.getElementById(img_id);\r
\r
if (img.className != "mceButtonDisabled")\r
tinyMCEPopup.openBrowser(target_form_element, type, option);\r
}\r
\r
-function selectByValue(form_obj, field_name, value, add_custom) {\r
+function selectByValue(form_obj, field_name, value, add_custom, ignore_case) {\r
if (!form_obj || !form_obj.elements[field_name])\r
return;\r
\r
+ if (!value)\r
+ value = "";\r
+\r
var sel = form_obj.elements[field_name];\r
\r
var found = false;\r
for (var i=0; i<sel.options.length; i++) {\r
var option = sel.options[i];\r
\r
- if (option.value == value) {\r
+ if (option.value == value || (ignore_case && option.value.toLowerCase() == value.toLowerCase())) {\r
option.selected = true;\r
found = true;\r
} else\r
}\r
\r
if (!found && add_custom && value != '') {\r
- var option = new Option('Value: ' + value, value);\r
+ var option = new Option(value, value);\r
option.selected = true;\r
sel.options[sel.options.length] = option;\r
+ sel.selectedIndex = sel.options.length - 1;\r
}\r
\r
return found;\r
function getSelectValue(form_obj, field_name) {\r
var elm = form_obj.elements[field_name];\r
\r
- if (elm == null || elm.options == null)\r
+ if (elm == null || elm.options == null || elm.selectedIndex === -1)\r
return "";\r
\r
return elm.options[elm.selectedIndex].value;\r
}\r
\r
+function addSelectValue(form_obj, field_name, name, value) {\r
+ var s = form_obj.elements[field_name];\r
+ var o = new Option(name, value);\r
+ s.options[s.options.length] = o;\r
+}\r
+\r
function addClassesToList(list_id, specific_option) {\r
// Setup class droplist\r
var styleSelectElm = document.getElementById(list_id);\r
- var styles = tinyMCE.getParam('theme_advanced_styles', false);\r
- styles = tinyMCE.getParam(specific_option, styles);\r
+ var styles = tinyMCEPopup.getParam('theme_advanced_styles', false);\r
+ styles = tinyMCEPopup.getParam(specific_option, styles);\r
\r
if (styles) {\r
var stylesAr = styles.split(';');\r
}\r
}\r
} else {\r
- // Use auto impored classes\r
- var csses = tinyMCE.getCSSClasses(tinyMCE.getWindowArg('editor_id'));\r
- for (var i=0; i<csses.length; i++)\r
- styleSelectElm.options[styleSelectElm.length] = new Option(csses[i], csses[i]);\r
+ tinymce.each(tinyMCEPopup.editor.dom.getClasses(), function(o) {\r
+ styleSelectElm.options[styleSelectElm.length] = new Option(o.title || o['class'], o['class']);\r
+ });\r
}\r
}\r
\r
}\r
\r
function trimSize(size) {\r
- return size.replace(new RegExp('[^0-9%]', 'gi'), '');\r
+ return size.replace(/([0-9\.]+)(px|%|in|cm|mm|em|ex|pt|pc)/i, '$1$2');\r
}\r
\r
function getCSSSize(size) {\r
if (size == "")\r
return "";\r
\r
- return size.indexOf('%') != -1 ? size : size + "px";\r
+ // Add px\r
+ if (/^[0-9]+$/.test(size))\r
+ size += 'px';\r
+ // Sanity check, IE doesn't like broken values\r
+ else if (!(/^[0-9\.]+(px|%|in|cm|mm|em|ex|pt|pc)$/i.test(size)))\r
+ return "";\r
+\r
+ return size;\r
}\r
\r
function getStyle(elm, attrib, style) {\r
- var val = tinyMCE.getAttrib(elm, attrib);\r
+ var val = tinyMCEPopup.dom.getAttrib(elm, attrib);\r
\r
if (val != '')\r
return '' + val;\r
if (typeof(style) == 'undefined')\r
style = attrib;\r
\r
- val = eval('elm.style.' + style);\r
-\r
- return val == null ? '' : '' + val;\r
+ return tinyMCEPopup.dom.getStyle(elm, style);\r
}\r