Open-Source PHP Framework - Designed for rapid development of performance-oriented scalable applications

/webroot/js/tinymce/utils/form_utils.js

[return to app]
1 /**
2  * $Id: form_utils.js 996 2009-02-06 17:32:20Z spocke $
3  *
4  * Various form utilitiy functions.
5  *
6  * @author Moxiecode
7  * @copyright Copyright © 2004-2008, Moxiecode Systems AB, All rights reserved.
8  */
9
10
var themeBaseURL tinyMCEPopup.editor.baseURI.toAbsolute('themes/' tinyMCEPopup.getParam("theme"));
11
12 function 
getColorPickerHTML(idtarget_form_element) {
13     var 
"";
14
15     
+= '<a id="' id '_link" href="javascript:;" onclick="tinyMCEPopup.pickColor(event,\'' target_form_element
 
+'\');" onmousedown="return false;" class="pickcolor">';
16     
+= '<span id="' id '" title="' tinyMCEPopup.getLang('browse') + '">&nbsp;</span></a>';
17
18     return 
h;
19 }
20
21 function 
updateColor(img_idform_element_id) {
22     
document.getElementById(img_id).style.backgroundColor document.forms[0].elements[form_element_id].value;
23 }
24
25 function 
setBrowserDisabled(idstate) {
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");
33             
tinyMCEPopup.dom.addClass(img'disabled');
34         } else {
35             if (
lnk.getAttribute("realhref"))
36                 
lnk.setAttribute("href"lnk.getAttribute("realhref"));
37
38             
tinyMCEPopup.dom.removeClass(img'disabled');
39         }
40     }
41 }
42
43 function 
getBrowserHTML(idtarget_form_elementtypeprefix) {
44     var 
option prefix "_" type "_browser_callback"cbhtml;
45
46     
cb tinyMCEPopup.getParam(optiontinyMCEPopup.getParam("file_browser_callback"));
47
48     if (!
cb)
49         return 
"";
50
51     
html "";
52     
html += '<a id="' id '_link" href="javascript:openBrowser(\'' id '\',\'' target_form_element '\', \''
 
type '\',\'' option '\');" onmousedown="return false;" class="browse">';
53     
html += '<span id="' id '" title="' tinyMCEPopup.getLang('browse') + '">&nbsp;</span></a>';
54
55     return 
html;
56 }
57
58 function 
openBrowser(img_idtarget_form_elementtypeoption) {
59     var 
img document.getElementById(img_id);
60
61     if (
img.className != "mceButtonDisabled")
62         
tinyMCEPopup.openBrowser(target_form_elementtypeoption);
63 }
64
65 function 
selectByValue(form_objfield_namevalueadd_customignore_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=0i<sel.options.lengthi++) {
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(valuevalue);
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_objfield_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_objfield_namenamevalue) {
102     var 
form_obj.elements[field_name];
103     var 
= new Option(namevalue);
104     
s.options[s.options.length] = o;
105 }
106
107 function 
addClassesToList(list_idspecific_option) {
108     
// Setup class droplist
109     
var styleSelectElm document.getElementById(list_id);
110     var 
styles tinyMCEPopup.getParam('theme_advanced_styles'false);
111     
styles tinyMCEPopup.getParam(specific_optionstyles);
112
113     if (
styles) {
114         var 
stylesAr styles.split(';');
115
116         for (var 
i=0i<stylesAr.lengthi++) {
117             if (
stylesAr != "") {
118                 var 
keyvalue;
119
120                 
key stylesAr[i].split('=')[0];
121                 
value stylesAr[i].split('=')[1];
122
123                 
styleSelectElm.options[styleSelectElm.length] = new Option(keyvalue);
124             }
125         }
126     } else {
127         
tinymce.each(tinyMCEPopup.editor.dom.getClasses(), function(o) {
128             
styleSelectElm.options[styleSelectElm.length] = new Option(o.title || o['class'], o['class']);
129         });
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         
parseInt(rgb[0]).toString(16);
145         
parseInt(rgb[1]).toString(16);
146         
parseInt(rgb[2]).toString(16);
147
148         
r.length == '0' r;
149         
g.length == '0' g;
150         
b.length == '0' b;
151
152         return 
"#" 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         
parseInt(col.substring(02), 16);
163         
parseInt(col.substring(24), 16);
164         
parseInt(col.substring(46), 16);
165
166         return 
"rgb(" "," "," ")";
167     }
168
169     return 
col;
170 }
171
172 function 
trimSize(size) {
173     return 
size.replace(/([0-9\.]+)px|(%|in|cm|mm|em|ex|pt|pc)/, '$1$2');
174 }
175
176 function 
getCSSSize(size) {
177     
size trimSize(size);
178
179     if (
size == "")
180         return 
"";
181
182     
// Add px
183     
if (/^[0-9]+$/.test(size))
184         
size += 'px';
185
186     return 
size;
187 }
188
189 function 
getStyle(elmattribstyle) {
190     var 
val tinyMCEPopup.dom.getAttrib(elmattrib);
191
192     if (
val != '')
193         return 
'' val;
194
195     if (
typeof(style) == 'undefined')
196         
style attrib;
197
198     return 
tinyMCEPopup.dom.getStyle(elmstyle);
199 }
200