annotate media/js/tiny_mce/utils/form_utils.js @ 136:d203a4a986d2

Markitup preview function wasn't working correctly due to the user data being escaped before going into the markdown and smiley filters.
author Brian Neal <bgneal@gmail.com>
date Fri, 27 Nov 2009 03:50:34 +0000
parents a5b4c5ce0658
children 149c3567fec1
rev   line source
bgneal@45 1 /**
bgneal@45 2 * $Id: form_utils.js 996 2009-02-06 17:32:20Z spocke $
bgneal@45 3 *
bgneal@45 4 * Various form utilitiy functions.
bgneal@45 5 *
bgneal@45 6 * @author Moxiecode
bgneal@45 7 * @copyright Copyright © 2004-2008, Moxiecode Systems AB, All rights reserved.
bgneal@45 8 */
bgneal@45 9
bgneal@45 10 var themeBaseURL = tinyMCEPopup.editor.baseURI.toAbsolute('themes/' + tinyMCEPopup.getParam("theme"));
bgneal@45 11
bgneal@45 12 function getColorPickerHTML(id, target_form_element) {
bgneal@45 13 var h = "";
bgneal@45 14
bgneal@45 15 h += '<a id="' + id + '_link" href="javascript:;" onclick="tinyMCEPopup.pickColor(event,\'' + target_form_element +'\');" onmousedown="return false;" class="pickcolor">';
bgneal@45 16 h += '<span id="' + id + '" title="' + tinyMCEPopup.getLang('browse') + '">&nbsp;</span></a>';
bgneal@45 17
bgneal@45 18 return h;
bgneal@45 19 }
bgneal@45 20
bgneal@45 21 function updateColor(img_id, form_element_id) {
bgneal@45 22 document.getElementById(img_id).style.backgroundColor = document.forms[0].elements[form_element_id].value;
bgneal@45 23 }
bgneal@45 24
bgneal@45 25 function setBrowserDisabled(id, state) {
bgneal@45 26 var img = document.getElementById(id);
bgneal@45 27 var lnk = document.getElementById(id + "_link");
bgneal@45 28
bgneal@45 29 if (lnk) {
bgneal@45 30 if (state) {
bgneal@45 31 lnk.setAttribute("realhref", lnk.getAttribute("href"));
bgneal@45 32 lnk.removeAttribute("href");
bgneal@45 33 tinyMCEPopup.dom.addClass(img, 'disabled');
bgneal@45 34 } else {
bgneal@45 35 if (lnk.getAttribute("realhref"))
bgneal@45 36 lnk.setAttribute("href", lnk.getAttribute("realhref"));
bgneal@45 37
bgneal@45 38 tinyMCEPopup.dom.removeClass(img, 'disabled');
bgneal@45 39 }
bgneal@45 40 }
bgneal@45 41 }
bgneal@45 42
bgneal@45 43 function getBrowserHTML(id, target_form_element, type, prefix) {
bgneal@45 44 var option = prefix + "_" + type + "_browser_callback", cb, html;
bgneal@45 45
bgneal@45 46 cb = tinyMCEPopup.getParam(option, tinyMCEPopup.getParam("file_browser_callback"));
bgneal@45 47
bgneal@45 48 if (!cb)
bgneal@45 49 return "";
bgneal@45 50
bgneal@45 51 html = "";
bgneal@45 52 html += '<a id="' + id + '_link" href="javascript:openBrowser(\'' + id + '\',\'' + target_form_element + '\', \'' + type + '\',\'' + option + '\');" onmousedown="return false;" class="browse">';
bgneal@45 53 html += '<span id="' + id + '" title="' + tinyMCEPopup.getLang('browse') + '">&nbsp;</span></a>';
bgneal@45 54
bgneal@45 55 return html;
bgneal@45 56 }
bgneal@45 57
bgneal@45 58 function openBrowser(img_id, target_form_element, type, option) {
bgneal@45 59 var img = document.getElementById(img_id);
bgneal@45 60
bgneal@45 61 if (img.className != "mceButtonDisabled")
bgneal@45 62 tinyMCEPopup.openBrowser(target_form_element, type, option);
bgneal@45 63 }
bgneal@45 64
bgneal@45 65 function selectByValue(form_obj, field_name, value, add_custom, ignore_case) {
bgneal@45 66 if (!form_obj || !form_obj.elements[field_name])
bgneal@45 67 return;
bgneal@45 68
bgneal@45 69 var sel = form_obj.elements[field_name];
bgneal@45 70
bgneal@45 71 var found = false;
bgneal@45 72 for (var i=0; i<sel.options.length; i++) {
bgneal@45 73 var option = sel.options[i];
bgneal@45 74
bgneal@45 75 if (option.value == value || (ignore_case && option.value.toLowerCase() == value.toLowerCase())) {
bgneal@45 76 option.selected = true;
bgneal@45 77 found = true;
bgneal@45 78 } else
bgneal@45 79 option.selected = false;
bgneal@45 80 }
bgneal@45 81
bgneal@45 82 if (!found && add_custom && value != '') {
bgneal@45 83 var option = new Option(value, value);
bgneal@45 84 option.selected = true;
bgneal@45 85 sel.options[sel.options.length] = option;
bgneal@45 86 sel.selectedIndex = sel.options.length - 1;
bgneal@45 87 }
bgneal@45 88
bgneal@45 89 return found;
bgneal@45 90 }
bgneal@45 91
bgneal@45 92 function getSelectValue(form_obj, field_name) {
bgneal@45 93 var elm = form_obj.elements[field_name];
bgneal@45 94
bgneal@45 95 if (elm == null || elm.options == null)
bgneal@45 96 return "";
bgneal@45 97
bgneal@45 98 return elm.options[elm.selectedIndex].value;
bgneal@45 99 }
bgneal@45 100
bgneal@45 101 function addSelectValue(form_obj, field_name, name, value) {
bgneal@45 102 var s = form_obj.elements[field_name];
bgneal@45 103 var o = new Option(name, value);
bgneal@45 104 s.options[s.options.length] = o;
bgneal@45 105 }
bgneal@45 106
bgneal@45 107 function addClassesToList(list_id, specific_option) {
bgneal@45 108 // Setup class droplist
bgneal@45 109 var styleSelectElm = document.getElementById(list_id);
bgneal@45 110 var styles = tinyMCEPopup.getParam('theme_advanced_styles', false);
bgneal@45 111 styles = tinyMCEPopup.getParam(specific_option, styles);
bgneal@45 112
bgneal@45 113 if (styles) {
bgneal@45 114 var stylesAr = styles.split(';');
bgneal@45 115
bgneal@45 116 for (var i=0; i<stylesAr.length; i++) {
bgneal@45 117 if (stylesAr != "") {
bgneal@45 118 var key, value;
bgneal@45 119
bgneal@45 120 key = stylesAr[i].split('=')[0];
bgneal@45 121 value = stylesAr[i].split('=')[1];
bgneal@45 122
bgneal@45 123 styleSelectElm.options[styleSelectElm.length] = new Option(key, value);
bgneal@45 124 }
bgneal@45 125 }
bgneal@45 126 } else {
bgneal@45 127 tinymce.each(tinyMCEPopup.editor.dom.getClasses(), function(o) {
bgneal@45 128 styleSelectElm.options[styleSelectElm.length] = new Option(o.title || o['class'], o['class']);
bgneal@45 129 });
bgneal@45 130 }
bgneal@45 131 }
bgneal@45 132
bgneal@45 133 function isVisible(element_id) {
bgneal@45 134 var elm = document.getElementById(element_id);
bgneal@45 135
bgneal@45 136 return elm && elm.style.display != "none";
bgneal@45 137 }
bgneal@45 138
bgneal@45 139 function convertRGBToHex(col) {
bgneal@45 140 var re = new RegExp("rgb\\s*\\(\\s*([0-9]+).*,\\s*([0-9]+).*,\\s*([0-9]+).*\\)", "gi");
bgneal@45 141
bgneal@45 142 var rgb = col.replace(re, "$1,$2,$3").split(',');
bgneal@45 143 if (rgb.length == 3) {
bgneal@45 144 r = parseInt(rgb[0]).toString(16);
bgneal@45 145 g = parseInt(rgb[1]).toString(16);
bgneal@45 146 b = parseInt(rgb[2]).toString(16);
bgneal@45 147
bgneal@45 148 r = r.length == 1 ? '0' + r : r;
bgneal@45 149 g = g.length == 1 ? '0' + g : g;
bgneal@45 150 b = b.length == 1 ? '0' + b : b;
bgneal@45 151
bgneal@45 152 return "#" + r + g + b;
bgneal@45 153 }
bgneal@45 154
bgneal@45 155 return col;
bgneal@45 156 }
bgneal@45 157
bgneal@45 158 function convertHexToRGB(col) {
bgneal@45 159 if (col.indexOf('#') != -1) {
bgneal@45 160 col = col.replace(new RegExp('[^0-9A-F]', 'gi'), '');
bgneal@45 161
bgneal@45 162 r = parseInt(col.substring(0, 2), 16);
bgneal@45 163 g = parseInt(col.substring(2, 4), 16);
bgneal@45 164 b = parseInt(col.substring(4, 6), 16);
bgneal@45 165
bgneal@45 166 return "rgb(" + r + "," + g + "," + b + ")";
bgneal@45 167 }
bgneal@45 168
bgneal@45 169 return col;
bgneal@45 170 }
bgneal@45 171
bgneal@45 172 function trimSize(size) {
bgneal@45 173 return size.replace(/([0-9\.]+)px|(%|in|cm|mm|em|ex|pt|pc)/, '$1$2');
bgneal@45 174 }
bgneal@45 175
bgneal@45 176 function getCSSSize(size) {
bgneal@45 177 size = trimSize(size);
bgneal@45 178
bgneal@45 179 if (size == "")
bgneal@45 180 return "";
bgneal@45 181
bgneal@45 182 // Add px
bgneal@45 183 if (/^[0-9]+$/.test(size))
bgneal@45 184 size += 'px';
bgneal@45 185
bgneal@45 186 return size;
bgneal@45 187 }
bgneal@45 188
bgneal@45 189 function getStyle(elm, attrib, style) {
bgneal@45 190 var val = tinyMCEPopup.dom.getAttrib(elm, attrib);
bgneal@45 191
bgneal@45 192 if (val != '')
bgneal@45 193 return '' + val;
bgneal@45 194
bgneal@45 195 if (typeof(style) == 'undefined')
bgneal@45 196 style = attrib;
bgneal@45 197
bgneal@45 198 return tinyMCEPopup.dom.getStyle(elm, style);
bgneal@45 199 }