includes/clientside/tinymce/utils/form_utils.js
changeset 335 67bd3121a12e
parent 1 fe660c52c48f
child 395 fa4c5ecb7c9a
equal deleted inserted replaced
334:c72b545f1304 335:67bd3121a12e
     1 /**
     1 /**
     2  * $Id: form_utils.js 162 2007-01-03 16:16:52Z spocke $
     2  * $Id: form_utils.js 453 2007-11-27 17:36:55Z spocke $
     3  *
     3  *
     4  * Various form utilitiy functions.
     4  * Various form utilitiy functions.
     5  *
     5  *
     6  * @author Moxiecode
     6  * @author Moxiecode
     7  * @copyright Copyright © 2004-2007, Moxiecode Systems AB, All rights reserved.
     7  * @copyright Copyright © 2004-2007, Moxiecode Systems AB, All rights reserved.
     8  */
     8  */
     9 
     9 
    10 var themeBaseURL = tinyMCE.baseURL + '/themes/' + tinyMCE.getParam("theme");
    10 var themeBaseURL = tinyMCEPopup.editor.baseURI.toAbsolute('themes/' + tinyMCEPopup.getParam("theme"));
    11 
    11 
    12 function getColorPickerHTML(id, target_form_element) {
    12 function getColorPickerHTML(id, target_form_element) {
    13 	var h = "";
    13 	var h = "";
    14 
    14 
    15 	h += '<a id="' + id + '_link" href="javascript:void(0);" onkeydown="pickColor(event,\'' + target_form_element +'\');" onmousedown="pickColor(event,\'' + target_form_element +'\');return false;">';
    15 	h += '<a id="' + id + '_link" href="javascript:;" onclick="tinyMCEPopup.pickColor(event,\'' + target_form_element +'\');" onmousedown="return false;" class="pickcolor">';
    16 	h += '<img id="' + id + '" src="' + themeBaseURL + '/images/color.gif"';
    16 	h += '<span id="' + id + '" title="' + tinyMCEPopup.getLang('browse') + '"></span></a>';
    17 	h += ' onmouseover="this.className=\'mceButtonOver\'"';
       
    18 	h += ' onmouseout="this.className=\'mceButtonNormal\'"';
       
    19 	h += ' onmousedown="this.className=\'mceButtonDown\'"';
       
    20 	h += ' width="20" height="16" border="0" title="' + tinyMCE.getLang('lang_browse') + '"';
       
    21 	h += ' class="mceButtonNormal" alt="' + tinyMCE.getLang('lang_browse') + '" /></a>';
       
    22 
    17 
    23 	return h;
    18 	return h;
    24 }
       
    25 
       
    26 function pickColor(e, target_form_element) {
       
    27 	if ((e.keyCode == 32 || e.keyCode == 13) || e.type == "mousedown")
       
    28 		tinyMCEPopup.pickColor(e, target_form_element);
       
    29 }
    19 }
    30 
    20 
    31 function updateColor(img_id, form_element_id) {
    21 function updateColor(img_id, form_element_id) {
    32 	document.getElementById(img_id).style.backgroundColor = document.forms[0].elements[form_element_id].value;
    22 	document.getElementById(img_id).style.backgroundColor = document.forms[0].elements[form_element_id].value;
    33 }
    23 }
    38 
    28 
    39 	if (lnk) {
    29 	if (lnk) {
    40 		if (state) {
    30 		if (state) {
    41 			lnk.setAttribute("realhref", lnk.getAttribute("href"));
    31 			lnk.setAttribute("realhref", lnk.getAttribute("href"));
    42 			lnk.removeAttribute("href");
    32 			lnk.removeAttribute("href");
    43 			tinyMCE.switchClass(img, 'mceButtonDisabled', true);
    33 			tinyMCEPopup.dom.addClass(img, 'disabled');
    44 		} else {
    34 		} else {
    45 			lnk.setAttribute("href", lnk.getAttribute("realhref"));
    35 			lnk.setAttribute("href", lnk.getAttribute("realhref"));
    46 			tinyMCE.switchClass(img, 'mceButtonNormal', false);
    36 			tinyMCEPopup.dom.removeClass(img, 'disabled');
    47 		}
    37 		}
    48 	}
    38 	}
    49 }
    39 }
    50 
    40 
    51 function getBrowserHTML(id, target_form_element, type, prefix) {
    41 function getBrowserHTML(id, target_form_element, type, prefix) {
    52 	var option = prefix + "_" + type + "_browser_callback";
    42 	var option = prefix + "_" + type + "_browser_callback", cb, html;
    53 	var cb = tinyMCE.getParam(option, tinyMCE.getParam("file_browser_callback"));
    43 
    54 	if (cb == null)
    44 	cb = tinyMCEPopup.getParam(option, tinyMCEPopup.getParam("file_browser_callback"));
       
    45 
       
    46 	if (!cb)
    55 		return "";
    47 		return "";
    56 
    48 
    57 	var html = "";
    49 	html = "";
    58 
    50 	html += '<a id="' + id + '_link" href="javascript:openBrowser(\'' + id + '\',\'' + target_form_element + '\', \'' + type + '\',\'' + option + '\');" onmousedown="return false;" class="browse">';
    59 	html += '<a id="' + id + '_link" href="javascript:openBrower(\'' + id + '\',\'' + target_form_element + '\', \'' + type + '\',\'' + option + '\');" onmousedown="return false;">';
    51 	html += '<span id="' + id + '" title="' + tinyMCEPopup.getLang('browse') + '"></span></a>';
    60 	html += '<img id="' + id + '" src="' + themeBaseURL + '/images/browse.gif"';
       
    61 	html += ' onmouseover="this.className=\'mceButtonOver\';"';
       
    62 	html += ' onmouseout="this.className=\'mceButtonNormal\';"';
       
    63 	html += ' onmousedown="this.className=\'mceButtonDown\';"';
       
    64 	html += ' width="20" height="18" border="0" title="' + tinyMCE.getLang('lang_browse') + '"';
       
    65 	html += ' class="mceButtonNormal" alt="' + tinyMCE.getLang('lang_browse') + '" /></a>';
       
    66 
    52 
    67 	return html;
    53 	return html;
    68 }
    54 }
    69 
    55 
    70 function openBrower(img_id, target_form_element, type, option) {
    56 function openBrowser(img_id, target_form_element, type, option) {
    71 	var img = document.getElementById(img_id);
    57 	var img = document.getElementById(img_id);
    72 
    58 
    73 	if (img.className != "mceButtonDisabled")
    59 	if (img.className != "mceButtonDisabled")
    74 		tinyMCEPopup.openBrowser(target_form_element, type, option);
    60 		tinyMCEPopup.openBrowser(target_form_element, type, option);
    75 }
    61 }
   117 }
   103 }
   118 
   104 
   119 function addClassesToList(list_id, specific_option) {
   105 function addClassesToList(list_id, specific_option) {
   120 	// Setup class droplist
   106 	// Setup class droplist
   121 	var styleSelectElm = document.getElementById(list_id);
   107 	var styleSelectElm = document.getElementById(list_id);
   122 	var styles = tinyMCE.getParam('theme_advanced_styles', false);
   108 	var styles = tinyMCEPopup.getParam('theme_advanced_styles', false);
   123 	styles = tinyMCE.getParam(specific_option, styles);
   109 	styles = tinyMCEPopup.getParam(specific_option, styles);
   124 
   110 
   125 	if (styles) {
   111 	if (styles) {
   126 		var stylesAr = styles.split(';');
   112 		var stylesAr = styles.split(';');
   127 
   113 
   128 		for (var i=0; i<stylesAr.length; i++) {
   114 		for (var i=0; i<stylesAr.length; i++) {
   134 
   120 
   135 				styleSelectElm.options[styleSelectElm.length] = new Option(key, value);
   121 				styleSelectElm.options[styleSelectElm.length] = new Option(key, value);
   136 			}
   122 			}
   137 		}
   123 		}
   138 	} else {
   124 	} else {
   139 		// Use auto impored classes
   125 		tinymce.each(tinyMCEPopup.editor.dom.getClasses(), function(o) {
   140 		var csses = tinyMCE.getCSSClasses(tinyMCE.getWindowArg('editor_id'));
   126 			styleSelectElm.options[styleSelectElm.length] = new Option(o.title || o['class'], o['class']);
   141 		for (var i=0; i<csses.length; i++)
   127 		});
   142 			styleSelectElm.options[styleSelectElm.length] = new Option(csses[i], csses[i]);
       
   143 	}
   128 	}
   144 }
   129 }
   145 
   130 
   146 function isVisible(element_id) {
   131 function isVisible(element_id) {
   147 	var elm = document.getElementById(element_id);
   132 	var elm = document.getElementById(element_id);
   194 
   179 
   195 	return size.indexOf('%') != -1 ? size : size + "px";
   180 	return size.indexOf('%') != -1 ? size : size + "px";
   196 }
   181 }
   197 
   182 
   198 function getStyle(elm, attrib, style) {
   183 function getStyle(elm, attrib, style) {
   199 	var val = tinyMCE.getAttrib(elm, attrib);
   184 	var val = tinyMCEPopup.dom.getAttrib(elm, attrib);
   200 
   185 
   201 	if (val != '')
   186 	if (val != '')
   202 		return '' + val;
   187 		return '' + val;
   203 
   188 
   204 	if (typeof(style) == 'undefined')
   189 	if (typeof(style) == 'undefined')
   205 		style = attrib;
   190 		style = attrib;
   206 
   191 
   207 	val = eval('elm.style.' + style);
   192 	return tinyMCEPopup.dom.getStyle(elm, style);
   208 
       
   209 	return val == null ? '' : '' + val;
       
   210 }
   193 }