| [ Index ] |
PHP Cross Reference of Moodle 1.9.3 [Build 15-Oct-2008] |
[Summary view] [Print] [Text view]
1 /** 2 * $RCSfile: form_utils.js,v $ 3 * $Revision: 1.1 $ 4 * $Date: 2006/03/04 15:57:32 $ 5 * 6 * Various form utilitiy functions. 7 * 8 * @author Moxiecode 9 * @copyright Copyright © 2004-2006, Moxiecode Systems AB, All rights reserved. 10 */ 11 12 function getColorPickerHTML(id, target_form_element) { 13 var html = ""; 14 15 html += '<a id="' + id + '_link" href="javascript:void(0);" onkeydown="pickColor(event,\'' + target_form_element +'\');" onmousedown="pickColor(event,\'' + target_form_element +'\');return false;">'; 16 html += '<img id="' + id + '" src="../../themes/advanced/images/color.gif"'; 17 html += ' onmouseover="this.className=\'mceButtonOver\'"'; 18 html += ' onmouseout="this.className=\'mceButtonNormal\'"'; 19 html += ' onmousedown="this.className=\'mceButtonDown\'"'; 20 html += ' width="20" height="16" border="0" title="' + tinyMCE.getLang('lang_browse') + '"'; 21 html += ' class="mceButtonNormal" alt="' + tinyMCE.getLang('lang_browse') + '" /></a>'; 22 23 return html; 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 } 30 31 function updateColor(img_id, form_element_id) { 32 document.getElementById(img_id).style.backgroundColor = document.forms[0].elements[form_element_id].value; 33 } 34 35 function setBrowserDisabled(id, state) { 36 var img = document.getElementById(id); 37 var lnk = document.getElementById(id + "_link"); 38 39 if (lnk) { 40 if (state) { 41 lnk.setAttribute("realhref", lnk.getAttribute("href")); 42 lnk.removeAttribute("href"); 43 tinyMCE.switchClass(img, 'mceButtonDisabled', true); 44 } else { 45 lnk.setAttribute("href", lnk.getAttribute("realhref")); 46 tinyMCE.switchClass(img, 'mceButtonNormal', false); 47 } 48 } 49 } 50 51 function getBrowserHTML(id, target_form_element, type, prefix) { 52 var option = prefix + "_" + type + "_browser_callback"; 53 var cb = tinyMCE.getParam(option, tinyMCE.getParam("file_browser_callback")); 54 if (cb == null) 55 return ""; 56 57 var html = ""; 58 59 html += '<a id="' + id + '_link" href="javascript:openBrower(\'' + id + '\',\'' + target_form_element + '\', \'' + type + '\',\'' + option + '\');" onmousedown="return false;">'; 60 html += '<img id="' + id + '" src="../../themes/advanced/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 67 return html; 68 } 69 70 function openBrower(img_id, target_form_element, type, option) { 71 var img = document.getElementById(img_id); 72 73 if (img.className != "mceButtonDisabled") 74 tinyMCEPopup.openBrowser(target_form_element, type, option); 75 } 76 77 function selectByValue(form_obj, field_name, value, add_custom, ignore_case) { 78 if (!form_obj || !form_obj.elements[field_name]) 79 return; 80 81 var sel = form_obj.elements[field_name]; 82 83 var found = false; 84 for (var i=0; i<sel.options.length; i++) { 85 var option = sel.options[i]; 86 87 if (option.value == value || (ignore_case && option.value.toLowerCase() == value.toLowerCase())) { 88 option.selected = true; 89 found = true; 90 } else 91 option.selected = false; 92 } 93 94 if (!found && add_custom && value != '') { 95 var option = new Option('Value: ' + value, value); 96 option.selected = true; 97 sel.options[sel.options.length] = option; 98 } 99 100 return found; 101 } 102 103 function getSelectValue(form_obj, field_name) { 104 var elm = form_obj.elements[field_name]; 105 106 if (elm == null || elm.options == null) 107 return ""; 108 109 return elm.options[elm.selectedIndex].value; 110 } 111 112 function addSelectValue(form_obj, field_name, name, value) { 113 var s = form_obj.elements[field_name]; 114 var o = new Option(name, value); 115 s.options[s.options.length] = o; 116 } 117 118 function addClassesToList(list_id, specific_option) { 119 // Setup class droplist 120 var styleSelectElm = document.getElementById(list_id); 121 var styles = tinyMCE.getParam('theme_advanced_styles', false); 122 styles = tinyMCE.getParam(specific_option, styles); 123 124 if (styles) { 125 var stylesAr = styles.split(';'); 126 127 for (var i=0; i<stylesAr.length; i++) { 128 if (stylesAr != "") { 129 var key, value; 130 131 key = stylesAr[i].split('=')[0]; 132 value = stylesAr[i].split('=')[1]; 133 134 styleSelectElm.options[styleSelectElm.length] = new Option(key, value); 135 } 136 } 137 } else { 138 // Use auto impored classes 139 var csses = tinyMCE.getCSSClasses(tinyMCE.getWindowArg('editor_id')); 140 for (var i=0; i<csses.length; i++) 141 styleSelectElm.options[styleSelectElm.length] = new Option(csses[i], csses[i]); 142 } 143 } 144 145 function isVisible(element_id) { 146 var elm = document.getElementById(element_id); 147 148 return elm && elm.style.display != "none"; 149 } 150 151 function convertRGBToHex(col) { 152 var re = new RegExp("rgb\\s*\\(\\s*([0-9]+).*,\\s*([0-9]+).*,\\s*([0-9]+).*\\)", "gi"); 153 154 var rgb = col.replace(re, "$1,$2,$3").split(','); 155 if (rgb.length == 3) { 156 r = parseInt(rgb[0]).toString(16); 157 g = parseInt(rgb[1]).toString(16); 158 b = parseInt(rgb[2]).toString(16); 159 160 r = r.length == 1 ? '0' + r : r; 161 g = g.length == 1 ? '0' + g : g; 162 b = b.length == 1 ? '0' + b : b; 163 164 return "#" + r + g + b; 165 } 166 167 return col; 168 } 169 170 function convertHexToRGB(col) { 171 if (col.indexOf('#') != -1) { 172 col = col.replace(new RegExp('[^0-9A-F]', 'gi'), ''); 173 174 r = parseInt(col.substring(0, 2), 16); 175 g = parseInt(col.substring(2, 4), 16); 176 b = parseInt(col.substring(4, 6), 16); 177 178 return "rgb(" + r + "," + g + "," + b + ")"; 179 } 180 181 return col; 182 } 183 184 function trimSize(size) { 185 return size.replace(new RegExp('[^0-9%]', 'gi'), ''); 186 } 187 188 function getCSSSize(size) { 189 size = trimSize(size); 190 191 if (size == "") 192 return ""; 193 194 return size.indexOf('%') != -1 ? size : size + "px"; 195 } 196 197 function getStyle(elm, attrib, style) { 198 var val = tinyMCE.getAttrib(elm, attrib); 199 200 if (val != '') 201 return '' + val; 202 203 if (typeof(style) == 'undefined') 204 style = attrib; 205 206 val = eval('elm.style.' + style); 207 208 return val == null ? '' : '' + val; 209 }
title
Description
Body
title
Description
Body
title
Description
Body
title
Body
| Generated: Wed Jan 14 11:33:29 2009 | Cross-referenced by PHPXref 0.7 |