annotate WebContent/jscripts/tiny_mce/utils/form_utils.js @ 20:6629e8422760

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