source: branches/rsr.v5.1/web/app/plugins/tinymce/jscripts/tiny_mce/utils/form_utils.js @ 1

Last change on this file since 1 was 1, checked in by dj3c1t, 12 years ago

import initial

File size: 5.3 KB
Line 
1/**
2 * $Id: form_utils.js 520 2008-01-07 16:30:32Z spocke $
3 *
4 * Various form utilitiy functions.
5 *
6 * @author Moxiecode
7 * @copyright Copyright © 2004-2008, Moxiecode Systems AB, All rights reserved.
8 */
9
10var themeBaseURL = tinyMCEPopup.editor.baseURI.toAbsolute('themes/' + tinyMCEPopup.getParam("theme"));
11
12function getColorPickerHTML(id, target_form_element) {
13        var h = "";
14
15        h += '<a id="' + id + '_link" href="javascript:;" onclick="tinyMCEPopup.pickColor(event,\'' + target_form_element +'\');" onmousedown="return false;" class="pickcolor">';
16        h += '<span id="' + id + '" title="' + tinyMCEPopup.getLang('browse') + '"></span></a>';
17
18        return h;
19}
20
21function updateColor(img_id, form_element_id) {
22        document.getElementById(img_id).style.backgroundColor = document.forms[0].elements[form_element_id].value;
23}
24
25function 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");
33                        tinyMCEPopup.dom.addClass(img, 'disabled');
34                } else {
35                        lnk.setAttribute("href", lnk.getAttribute("realhref"));
36                        tinyMCEPopup.dom.removeClass(img, 'disabled');
37                }
38        }
39}
40
41function getBrowserHTML(id, target_form_element, type, prefix) {
42        var option = prefix + "_" + type + "_browser_callback", cb, html;
43
44        cb = tinyMCEPopup.getParam(option, tinyMCEPopup.getParam("file_browser_callback"));
45
46        if (!cb)
47                return "";
48
49        html = "";
50        html += '<a id="' + id + '_link" href="javascript:openBrowser(\'' + id + '\',\'' + target_form_element + '\', \'' + type + '\',\'' + option + '\');" onmousedown="return false;" class="browse">';
51        html += '<span id="' + id + '" title="' + tinyMCEPopup.getLang('browse') + '"></span></a>';
52
53        return html;
54}
55
56function openBrowser(img_id, target_form_element, type, option) {
57        var img = document.getElementById(img_id);
58
59        if (img.className != "mceButtonDisabled")
60                tinyMCEPopup.openBrowser(target_form_element, type, option);
61}
62
63function 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
90function 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
99function 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
105function addClassesToList(list_id, specific_option) {
106        // Setup class droplist
107        var styleSelectElm = document.getElementById(list_id);
108        var styles = tinyMCEPopup.getParam('theme_advanced_styles', false);
109        styles = tinyMCEPopup.getParam(specific_option, styles);
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 {
125                tinymce.each(tinyMCEPopup.editor.dom.getClasses(), function(o) {
126                        styleSelectElm.options[styleSelectElm.length] = new Option(o.title || o['class'], o['class']);
127                });
128        }
129}
130
131function isVisible(element_id) {
132        var elm = document.getElementById(element_id);
133
134        return elm && elm.style.display != "none";
135}
136
137function 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
156function 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
170function trimSize(size) {
171        return size.replace(new RegExp('[^0-9%]', 'gi'), '');
172}
173
174function getCSSSize(size) {
175        size = trimSize(size);
176
177        if (size == "")
178                return "";
179
180        return size.indexOf('%') != -1 ? size : size + "px";
181}
182
183function getStyle(elm, attrib, style) {
184        var val = tinyMCEPopup.dom.getAttrib(elm, attrib);
185
186        if (val != '')
187                return '' + val;
188
189        if (typeof(style) == 'undefined')
190                style = attrib;
191
192        return tinyMCEPopup.dom.getStyle(elm, style);
193}
Note: See TracBrowser for help on using the repository browser.