author | Dan |
Sun, 25 Jan 2009 20:35:32 -0500 | |
changeset 824 | 28d9fbcd4f0d |
parent 543 | dffcbfbc4e59 |
child 1193 | e3b94bd055dc |
permissions | -rw-r--r-- |
1 | 1 |
/** |
543 | 2 |
* $Id: form_utils.js 673 2008-03-06 13:26:20Z spocke $ |
1 | 3 |
* |
4 |
* Various form utilitiy functions. |
|
5 |
* |
|
6 |
* @author Moxiecode |
|
395
fa4c5ecb7c9a
Fixed splitting bug (really the same issue from stable) in get_pageid_from_url(); upgraded TinyMCE to version 3.0-stable
Dan
parents:
335
diff
changeset
|
7 |
* @copyright Copyright © 2004-2008, Moxiecode Systems AB, All rights reserved. |
1 | 8 |
*/ |
9 |
||
335
67bd3121a12e
Replaced TinyMCE 2.x with 3.0 beta 3. Supports everything but IE. Also rewrote the editor interface completely from the ground up.
Dan
parents:
1
diff
changeset
|
10 |
var themeBaseURL = tinyMCEPopup.editor.baseURI.toAbsolute('themes/' + tinyMCEPopup.getParam("theme")); |
1 | 11 |
|
12 |
function getColorPickerHTML(id, target_form_element) { |
|
13 |
var h = ""; |
|
14 |
||
335
67bd3121a12e
Replaced TinyMCE 2.x with 3.0 beta 3. Supports everything but IE. Also rewrote the editor interface completely from the ground up.
Dan
parents:
1
diff
changeset
|
15 |
h += '<a id="' + id + '_link" href="javascript:;" onclick="tinyMCEPopup.pickColor(event,\'' + target_form_element +'\');" onmousedown="return false;" class="pickcolor">'; |
67bd3121a12e
Replaced TinyMCE 2.x with 3.0 beta 3. Supports everything but IE. Also rewrote the editor interface completely from the ground up.
Dan
parents:
1
diff
changeset
|
16 |
h += '<span id="' + id + '" title="' + tinyMCEPopup.getLang('browse') + '"></span></a>'; |
1 | 17 |
|
18 |
return h; |
|
19 |
} |
|
20 |
||
21 |
function updateColor(img_id, form_element_id) { |
|
22 |
document.getElementById(img_id).style.backgroundColor = document.forms[0].elements[form_element_id].value; |
|
23 |
} |
|
24 |
||
25 |
function setBrowserDisabled(id, state) { |
|
26 |
var img = document.getElementById(id); |
|
27 |
var lnk = document.getElementById(id + "_link"); |
|
28 |
||
29 |
if (lnk) { |
|
30 |
if (state) { |
|
31 |
lnk.setAttribute("realhref", lnk.getAttribute("href")); |
|
32 |
lnk.removeAttribute("href"); |
|
335
67bd3121a12e
Replaced TinyMCE 2.x with 3.0 beta 3. Supports everything but IE. Also rewrote the editor interface completely from the ground up.
Dan
parents:
1
diff
changeset
|
33 |
tinyMCEPopup.dom.addClass(img, 'disabled'); |
1 | 34 |
} else { |
459
31c23016ab62
Upgraded tinyMCE to 3.0.1 in hopes of fixing IE race conditions. Fixed a couple minor syntax errors in Javascript objects declared in various places.
Dan
parents:
395
diff
changeset
|
35 |
if (lnk.getAttribute("realhref")) |
31c23016ab62
Upgraded tinyMCE to 3.0.1 in hopes of fixing IE race conditions. Fixed a couple minor syntax errors in Javascript objects declared in various places.
Dan
parents:
395
diff
changeset
|
36 |
lnk.setAttribute("href", lnk.getAttribute("realhref")); |
31c23016ab62
Upgraded tinyMCE to 3.0.1 in hopes of fixing IE race conditions. Fixed a couple minor syntax errors in Javascript objects declared in various places.
Dan
parents:
395
diff
changeset
|
37 |
|
335
67bd3121a12e
Replaced TinyMCE 2.x with 3.0 beta 3. Supports everything but IE. Also rewrote the editor interface completely from the ground up.
Dan
parents:
1
diff
changeset
|
38 |
tinyMCEPopup.dom.removeClass(img, 'disabled'); |
1 | 39 |
} |
40 |
} |
|
41 |
} |
|
42 |
||
43 |
function getBrowserHTML(id, target_form_element, type, prefix) { |
|
335
67bd3121a12e
Replaced TinyMCE 2.x with 3.0 beta 3. Supports everything but IE. Also rewrote the editor interface completely from the ground up.
Dan
parents:
1
diff
changeset
|
44 |
var option = prefix + "_" + type + "_browser_callback", cb, html; |
67bd3121a12e
Replaced TinyMCE 2.x with 3.0 beta 3. Supports everything but IE. Also rewrote the editor interface completely from the ground up.
Dan
parents:
1
diff
changeset
|
45 |
|
67bd3121a12e
Replaced TinyMCE 2.x with 3.0 beta 3. Supports everything but IE. Also rewrote the editor interface completely from the ground up.
Dan
parents:
1
diff
changeset
|
46 |
cb = tinyMCEPopup.getParam(option, tinyMCEPopup.getParam("file_browser_callback")); |
67bd3121a12e
Replaced TinyMCE 2.x with 3.0 beta 3. Supports everything but IE. Also rewrote the editor interface completely from the ground up.
Dan
parents:
1
diff
changeset
|
47 |
|
67bd3121a12e
Replaced TinyMCE 2.x with 3.0 beta 3. Supports everything but IE. Also rewrote the editor interface completely from the ground up.
Dan
parents:
1
diff
changeset
|
48 |
if (!cb) |
1 | 49 |
return ""; |
50 |
||
335
67bd3121a12e
Replaced TinyMCE 2.x with 3.0 beta 3. Supports everything but IE. Also rewrote the editor interface completely from the ground up.
Dan
parents:
1
diff
changeset
|
51 |
html = ""; |
67bd3121a12e
Replaced TinyMCE 2.x with 3.0 beta 3. Supports everything but IE. Also rewrote the editor interface completely from the ground up.
Dan
parents:
1
diff
changeset
|
52 |
html += '<a id="' + id + '_link" href="javascript:openBrowser(\'' + id + '\',\'' + target_form_element + '\', \'' + type + '\',\'' + option + '\');" onmousedown="return false;" class="browse">'; |
67bd3121a12e
Replaced TinyMCE 2.x with 3.0 beta 3. Supports everything but IE. Also rewrote the editor interface completely from the ground up.
Dan
parents:
1
diff
changeset
|
53 |
html += '<span id="' + id + '" title="' + tinyMCEPopup.getLang('browse') + '"></span></a>'; |
1 | 54 |
|
55 |
return html; |
|
56 |
} |
|
57 |
||
335
67bd3121a12e
Replaced TinyMCE 2.x with 3.0 beta 3. Supports everything but IE. Also rewrote the editor interface completely from the ground up.
Dan
parents:
1
diff
changeset
|
58 |
function openBrowser(img_id, target_form_element, type, option) { |
1 | 59 |
var img = document.getElementById(img_id); |
60 |
||
61 |
if (img.className != "mceButtonDisabled") |
|
62 |
tinyMCEPopup.openBrowser(target_form_element, type, option); |
|
63 |
} |
|
64 |
||
65 |
function selectByValue(form_obj, field_name, value, add_custom, ignore_case) { |
|
66 |
if (!form_obj || !form_obj.elements[field_name]) |
|
67 |
return; |
|
68 |
||
69 |
var sel = form_obj.elements[field_name]; |
|
70 |
||
71 |
var found = false; |
|
72 |
for (var i=0; i<sel.options.length; i++) { |
|
73 |
var option = sel.options[i]; |
|
74 |
||
75 |
if (option.value == value || (ignore_case && option.value.toLowerCase() == value.toLowerCase())) { |
|
76 |
option.selected = true; |
|
77 |
found = true; |
|
78 |
} else |
|
79 |
option.selected = false; |
|
80 |
} |
|
81 |
||
82 |
if (!found && add_custom && value != '') { |
|
83 |
var option = new Option(value, value); |
|
84 |
option.selected = true; |
|
85 |
sel.options[sel.options.length] = option; |
|
86 |
sel.selectedIndex = sel.options.length - 1; |
|
87 |
} |
|
88 |
||
89 |
return found; |
|
90 |
} |
|
91 |
||
92 |
function getSelectValue(form_obj, field_name) { |
|
93 |
var elm = form_obj.elements[field_name]; |
|
94 |
||
95 |
if (elm == null || elm.options == null) |
|
96 |
return ""; |
|
97 |
||
98 |
return elm.options[elm.selectedIndex].value; |
|
99 |
} |
|
100 |
||
101 |
function addSelectValue(form_obj, field_name, name, value) { |
|
102 |
var s = form_obj.elements[field_name]; |
|
103 |
var o = new Option(name, value); |
|
104 |
s.options[s.options.length] = o; |
|
105 |
} |
|
106 |
||
107 |
function addClassesToList(list_id, specific_option) { |
|
108 |
// Setup class droplist |
|
109 |
var styleSelectElm = document.getElementById(list_id); |
|
335
67bd3121a12e
Replaced TinyMCE 2.x with 3.0 beta 3. Supports everything but IE. Also rewrote the editor interface completely from the ground up.
Dan
parents:
1
diff
changeset
|
110 |
var styles = tinyMCEPopup.getParam('theme_advanced_styles', false); |
67bd3121a12e
Replaced TinyMCE 2.x with 3.0 beta 3. Supports everything but IE. Also rewrote the editor interface completely from the ground up.
Dan
parents:
1
diff
changeset
|
111 |
styles = tinyMCEPopup.getParam(specific_option, styles); |
1 | 112 |
|
113 |
if (styles) { |
|
114 |
var stylesAr = styles.split(';'); |
|
115 |
||
116 |
for (var i=0; i<stylesAr.length; i++) { |
|
117 |
if (stylesAr != "") { |
|
118 |
var key, value; |
|
119 |
||
120 |
key = stylesAr[i].split('=')[0]; |
|
121 |
value = stylesAr[i].split('=')[1]; |
|
122 |
||
123 |
styleSelectElm.options[styleSelectElm.length] = new Option(key, value); |
|
124 |
} |
|
125 |
} |
|
126 |
} else { |
|
335
67bd3121a12e
Replaced TinyMCE 2.x with 3.0 beta 3. Supports everything but IE. Also rewrote the editor interface completely from the ground up.
Dan
parents:
1
diff
changeset
|
127 |
tinymce.each(tinyMCEPopup.editor.dom.getClasses(), function(o) { |
67bd3121a12e
Replaced TinyMCE 2.x with 3.0 beta 3. Supports everything but IE. Also rewrote the editor interface completely from the ground up.
Dan
parents:
1
diff
changeset
|
128 |
styleSelectElm.options[styleSelectElm.length] = new Option(o.title || o['class'], o['class']); |
67bd3121a12e
Replaced TinyMCE 2.x with 3.0 beta 3. Supports everything but IE. Also rewrote the editor interface completely from the ground up.
Dan
parents:
1
diff
changeset
|
129 |
}); |
1 | 130 |
} |
131 |
} |
|
132 |
||
133 |
function isVisible(element_id) { |
|
134 |
var elm = document.getElementById(element_id); |
|
135 |
||
136 |
return elm && elm.style.display != "none"; |
|
137 |
} |
|
138 |
||
139 |
function convertRGBToHex(col) { |
|
140 |
var re = new RegExp("rgb\\s*\\(\\s*([0-9]+).*,\\s*([0-9]+).*,\\s*([0-9]+).*\\)", "gi"); |
|
141 |
||
142 |
var rgb = col.replace(re, "$1,$2,$3").split(','); |
|
143 |
if (rgb.length == 3) { |
|
144 |
r = parseInt(rgb[0]).toString(16); |
|
145 |
g = parseInt(rgb[1]).toString(16); |
|
146 |
b = parseInt(rgb[2]).toString(16); |
|
147 |
||
148 |
r = r.length == 1 ? '0' + r : r; |
|
149 |
g = g.length == 1 ? '0' + g : g; |
|
150 |
b = b.length == 1 ? '0' + b : b; |
|
151 |
||
152 |
return "#" + r + g + b; |
|
153 |
} |
|
154 |
||
155 |
return col; |
|
156 |
} |
|
157 |
||
158 |
function convertHexToRGB(col) { |
|
159 |
if (col.indexOf('#') != -1) { |
|
160 |
col = col.replace(new RegExp('[^0-9A-F]', 'gi'), ''); |
|
161 |
||
162 |
r = parseInt(col.substring(0, 2), 16); |
|
163 |
g = parseInt(col.substring(2, 4), 16); |
|
164 |
b = parseInt(col.substring(4, 6), 16); |
|
165 |
||
166 |
return "rgb(" + r + "," + g + "," + b + ")"; |
|
167 |
} |
|
168 |
||
169 |
return col; |
|
170 |
} |
|
171 |
||
172 |
function trimSize(size) { |
|
543 | 173 |
return size.replace(/([0-9\.]+)px|(%|in|cm|mm|em|ex|pt|pc)/, '$1$2'); |
1 | 174 |
} |
175 |
||
176 |
function getCSSSize(size) { |
|
177 |
size = trimSize(size); |
|
178 |
||
179 |
if (size == "") |
|
180 |
return ""; |
|
181 |
||
543 | 182 |
// Add px |
183 |
if (/^[0-9]+$/.test(size)) |
|
184 |
size += 'px'; |
|
185 |
||
186 |
return size; |
|
1 | 187 |
} |
188 |
||
189 |
function getStyle(elm, attrib, style) { |
|
335
67bd3121a12e
Replaced TinyMCE 2.x with 3.0 beta 3. Supports everything but IE. Also rewrote the editor interface completely from the ground up.
Dan
parents:
1
diff
changeset
|
190 |
var val = tinyMCEPopup.dom.getAttrib(elm, attrib); |
1 | 191 |
|
192 |
if (val != '') |
|
193 |
return '' + val; |
|
194 |
||
195 |
if (typeof(style) == 'undefined') |
|
196 |
style = attrib; |
|
197 |
||
335
67bd3121a12e
Replaced TinyMCE 2.x with 3.0 beta 3. Supports everything but IE. Also rewrote the editor interface completely from the ground up.
Dan
parents:
1
diff
changeset
|
198 |
return tinyMCEPopup.dom.getStyle(elm, style); |
1 | 199 |
} |