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