annotate static/js/tiny_mce/utils/form_utils.js @ 319:c5055573e8d7

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