annotate static/js/tinymce/jscripts/tiny_mce/utils/form_utils.js @ 174:e3eb365ab5a0

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