author | Dan |
Thu, 21 Feb 2008 17:18:25 -0500 | |
changeset 437 | b66f029ae12d |
parent 395 | fa4c5ecb7c9a |
child 459 | 31c23016ab62 |
permissions | -rw-r--r-- |
1 | 1 |
/** |
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
|
2 |
* $Id: form_utils.js 520 2008-01-07 16:30:32Z 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 { |
35 |
lnk.setAttribute("href", lnk.getAttribute("realhref")); |
|
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
|
36 |
tinyMCEPopup.dom.removeClass(img, 'disabled'); |
1 | 37 |
} |
38 |
} |
|
39 |
} |
|
40 |
||
41 |
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
|
42 |
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
|
43 |
|
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 |
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
|
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 |
if (!cb) |
1 | 47 |
return ""; |
48 |
||
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
|
49 |
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
|
50 |
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
|
51 |
html += '<span id="' + id + '" title="' + tinyMCEPopup.getLang('browse') + '"></span></a>'; |
1 | 52 |
|
53 |
return html; |
|
54 |
} |
|
55 |
||
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
|
56 |
function openBrowser(img_id, target_form_element, type, option) { |
1 | 57 |
var img = document.getElementById(img_id); |
58 |
||
59 |
if (img.className != "mceButtonDisabled") |
|
60 |
tinyMCEPopup.openBrowser(target_form_element, type, option); |
|
61 |
} |
|
62 |
||
63 |
function selectByValue(form_obj, field_name, value, add_custom, ignore_case) { |
|
64 |
if (!form_obj || !form_obj.elements[field_name]) |
|
65 |
return; |
|
66 |
||
67 |
var sel = form_obj.elements[field_name]; |
|
68 |
||
69 |
var found = false; |
|
70 |
for (var i=0; i<sel.options.length; i++) { |
|
71 |
var option = sel.options[i]; |
|
72 |
||
73 |
if (option.value == value || (ignore_case && option.value.toLowerCase() == value.toLowerCase())) { |
|
74 |
option.selected = true; |
|
75 |
found = true; |
|
76 |
} else |
|
77 |
option.selected = false; |
|
78 |
} |
|
79 |
||
80 |
if (!found && add_custom && value != '') { |
|
81 |
var option = new Option(value, value); |
|
82 |
option.selected = true; |
|
83 |
sel.options[sel.options.length] = option; |
|
84 |
sel.selectedIndex = sel.options.length - 1; |
|
85 |
} |
|
86 |
||
87 |
return found; |
|
88 |
} |
|
89 |
||
90 |
function getSelectValue(form_obj, field_name) { |
|
91 |
var elm = form_obj.elements[field_name]; |
|
92 |
||
93 |
if (elm == null || elm.options == null) |
|
94 |
return ""; |
|
95 |
||
96 |
return elm.options[elm.selectedIndex].value; |
|
97 |
} |
|
98 |
||
99 |
function addSelectValue(form_obj, field_name, name, value) { |
|
100 |
var s = form_obj.elements[field_name]; |
|
101 |
var o = new Option(name, value); |
|
102 |
s.options[s.options.length] = o; |
|
103 |
} |
|
104 |
||
105 |
function addClassesToList(list_id, specific_option) { |
|
106 |
// Setup class droplist |
|
107 |
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
|
108 |
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
|
109 |
styles = tinyMCEPopup.getParam(specific_option, styles); |
1 | 110 |
|
111 |
if (styles) { |
|
112 |
var stylesAr = styles.split(';'); |
|
113 |
||
114 |
for (var i=0; i<stylesAr.length; i++) { |
|
115 |
if (stylesAr != "") { |
|
116 |
var key, value; |
|
117 |
||
118 |
key = stylesAr[i].split('=')[0]; |
|
119 |
value = stylesAr[i].split('=')[1]; |
|
120 |
||
121 |
styleSelectElm.options[styleSelectElm.length] = new Option(key, value); |
|
122 |
} |
|
123 |
} |
|
124 |
} 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
|
125 |
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
|
126 |
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
|
127 |
}); |
1 | 128 |
} |
129 |
} |
|
130 |
||
131 |
function isVisible(element_id) { |
|
132 |
var elm = document.getElementById(element_id); |
|
133 |
||
134 |
return elm && elm.style.display != "none"; |
|
135 |
} |
|
136 |
||
137 |
function convertRGBToHex(col) { |
|
138 |
var re = new RegExp("rgb\\s*\\(\\s*([0-9]+).*,\\s*([0-9]+).*,\\s*([0-9]+).*\\)", "gi"); |
|
139 |
||
140 |
var rgb = col.replace(re, "$1,$2,$3").split(','); |
|
141 |
if (rgb.length == 3) { |
|
142 |
r = parseInt(rgb[0]).toString(16); |
|
143 |
g = parseInt(rgb[1]).toString(16); |
|
144 |
b = parseInt(rgb[2]).toString(16); |
|
145 |
||
146 |
r = r.length == 1 ? '0' + r : r; |
|
147 |
g = g.length == 1 ? '0' + g : g; |
|
148 |
b = b.length == 1 ? '0' + b : b; |
|
149 |
||
150 |
return "#" + r + g + b; |
|
151 |
} |
|
152 |
||
153 |
return col; |
|
154 |
} |
|
155 |
||
156 |
function convertHexToRGB(col) { |
|
157 |
if (col.indexOf('#') != -1) { |
|
158 |
col = col.replace(new RegExp('[^0-9A-F]', 'gi'), ''); |
|
159 |
||
160 |
r = parseInt(col.substring(0, 2), 16); |
|
161 |
g = parseInt(col.substring(2, 4), 16); |
|
162 |
b = parseInt(col.substring(4, 6), 16); |
|
163 |
||
164 |
return "rgb(" + r + "," + g + "," + b + ")"; |
|
165 |
} |
|
166 |
||
167 |
return col; |
|
168 |
} |
|
169 |
||
170 |
function trimSize(size) { |
|
171 |
return size.replace(new RegExp('[^0-9%]', 'gi'), ''); |
|
172 |
} |
|
173 |
||
174 |
function getCSSSize(size) { |
|
175 |
size = trimSize(size); |
|
176 |
||
177 |
if (size == "") |
|
178 |
return ""; |
|
179 |
||
180 |
return size.indexOf('%') != -1 ? size : size + "px"; |
|
181 |
} |
|
182 |
||
183 |
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
|
184 |
var val = tinyMCEPopup.dom.getAttrib(elm, attrib); |
1 | 185 |
|
186 |
if (val != '') |
|
187 |
return '' + val; |
|
188 |
||
189 |
if (typeof(style) == 'undefined') |
|
190 |
style = attrib; |
|
191 |
||
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
|
192 |
return tinyMCEPopup.dom.getStyle(elm, style); |
1 | 193 |
} |