source: temp/test-xoops.ec-cube.net/html/include/xoops.js @ 405

Revision 405, 13.1 KB checked in by root, 20 years ago (diff)
Line 
1function xoopsGetElementById(id){
2    if (document.getElementById) {
3        return (document.getElementById(id));
4    } else if (document.all) {
5        return (document.all[id]);
6    } else {
7        if ((navigator.appname.indexOf("Netscape") != -1) && parseInt(navigator.appversion == 4)) {
8            return (document.layers[id]);
9        }
10    }
11}
12
13function xoopsSetElementProp(name, prop, val) {
14    var elt=xoopsGetElementById(name);
15    if (elt) elt[prop]=val;
16}
17
18function xoopsSetElementStyle(name, prop, val) {
19    var elt=xoopsGetElementById(name);
20    if (elt && elt.style) elt.style[prop]=val;
21}
22
23function xoopsGetFormElement(fname, ctlname) {
24    var frm=document.forms[fname];
25    return frm?frm.elements[ctlname]:null;
26}
27
28function justReturn() {
29    return;
30}
31
32function openWithSelfMain(url, name, width, height, returnwindow) {
33    var options = "width=" + width + ",height=" + height + "toolbar=no,location=no,directories=no,status=no,menubar=no,scrollbars=yes,resizable=yes,copyhistory=no";
34    new_window = window.open(url, name, options);
35    window.self.name = "main";
36    new_window.document.clear();
37    new_window.focus();
38    if (returnwindow != null) {
39        return new_window;
40    }
41}
42
43function setElementColor(id, color){
44    xoopsGetElementById(id).style.color = "#" + color;
45}
46
47function setElementFont(id, font){
48    xoopsGetElementById(id).style.fontFamily = font;
49}
50
51function setElementSize(id, size){
52    xoopsGetElementById(id).style.fontSize = size;
53}
54
55function changeDisplay(id){
56    var elestyle = xoopsGetElementById(id).style;
57    if (elestyle.display == "") {
58        elestyle.display = "none";
59    } else {
60        elestyle.display = "block";
61    }
62}
63
64function setVisible(id){
65    xoopsGetElementById(id).style.visibility = "visible";
66}
67
68function setHidden(id){
69    xoopsGetElementById(id).style.visibility = "hidden";
70}
71
72function makeBold(id){
73    var eleStyle = xoopsGetElementById(id).style;
74    if (eleStyle.fontWeight != "bold" && eleStyle.fontWeight != "700") {
75        eleStyle.fontWeight = "bold";
76    } else {
77        eleStyle.fontWeight = "normal";
78    }
79}
80
81function makeItalic(id){
82    var eleStyle = xoopsGetElementById(id).style;
83    if (eleStyle.fontStyle != "italic") {
84        eleStyle.fontStyle = "italic";
85    } else {
86        eleStyle.fontStyle = "normal";
87    }
88}
89
90function makeUnderline(id){
91    var eleStyle = xoopsGetElementById(id).style;
92    if (eleStyle.textDecoration != "underline") {
93        eleStyle.textDecoration = "underline";
94    } else {
95        eleStyle.textDecoration = "none";
96    }
97}
98
99function makeLineThrough(id){
100    var eleStyle = xoopsGetElementById(id).style;
101    if (eleStyle.textDecoration != "line-through") {
102        eleStyle.textDecoration = "line-through";
103    } else {
104        eleStyle.textDecoration = "none";
105    }
106}
107
108function appendSelectOption(selectMenuId, optionName, optionValue){
109    var selectMenu = xoopsGetElementById(selectMenuId);
110    var newoption = new Option(optionName, optionValue);
111    selectMenu.options[selectMenu.length] = newoption;
112    selectMenu.options[selectMenu.length].selected = true;
113}
114
115function disableElement(target){
116    var targetDom = xoopsGetElementById(target);
117    if (targetDom.disabled != true) {
118        targetDom.disabled = true;
119    } else {
120        targetDom.disabled = false;
121    }
122}
123function xoopsCheckAll(formname, switchid) {
124    var ele = document.forms[formname].elements;
125    var switch_cbox = xoopsGetElementById(switchid);
126    for (var i = 0; i < ele.length; i++) {
127        var e = ele[i];
128        if ( (e.name != switch_cbox.name) && (e.type == 'checkbox') ) {
129            e.checked = switch_cbox.checked;
130        }
131    }
132}
133
134function xoopsCheckGroup(formname, switchid, groupid) {
135    var ele = document.forms[formname].elements;
136    var switch_cbox = xoopsGetElementById(switchid);
137    for (var i = 0; i < ele.length; i++) {
138        var e = ele[i];
139        if ( (e.type == 'checkbox') && (e.id == groupid) ) {
140            e.checked = switch_cbox.checked;
141            e.click(); e.click();  // Click to activate subgroups
142                                    // Twice so we don't reverse effect
143        }
144    }
145}
146
147function xoopsCheckAllElements(elementIds, switchId) {
148    var switch_cbox = xoopsGetElementById(switchId);
149    for (var i = 0; i < elementIds.length; i++) {
150        var e = xoopsGetElementById(elementIds[i]);
151        if ((e.name != switch_cbox.name) && (e.type == 'checkbox')) {
152            e.checked = switch_cbox.checked;
153        }
154    }
155}
156
157function xoopsSavePosition(id)
158{
159    var textareaDom = xoopsGetElementById(id);
160    if (textareaDom.createTextRange) {
161        textareaDom.caretPos = document.selection.createRange().duplicate();
162    }
163}
164
165function xoopsInsertText(domobj, text)
166{
167    if (domobj.createTextRange && domobj.caretPos){
168        var caretPos = domobj.caretPos;
169        caretPos.text = caretPos.text.charAt(caretPos.text.length - 1)
170== ' ' ? text + ' ' : text;
171    } else if (domobj.getSelection && domobj.caretPos){
172        var caretPos = domobj.caretPos;
173        caretPos.text = caretPos.text.charat(caretPos.text.length - 1)
174== ' ' ? text + ' ' : text;
175    } else {
176        domobj.value = domobj.value + text;
177    }
178}
179
180function xoopsCodeSmilie(id, smilieCode) {
181    var revisedMessage;
182    var textareaDom = xoopsGetElementById(id);
183    xoopsInsertText(textareaDom, smilieCode);
184    textareaDom.focus();
185    return;
186}
187
188function showImgSelected(imgId, selectId, imgDir, extra, xoopsUrl) {
189    if (xoopsUrl == null) {
190        xoopsUrl = "./";
191    }
192    imgDom = xoopsGetElementById(imgId);
193    selectDom = xoopsGetElementById(selectId);
194    imgDom.src = xoopsUrl + "/"+ imgDir + "/" + selectDom.options[selectDom.selectedIndex].value + extra;
195}
196
197function xoopsCodeUrl(id, enterUrlPhrase, enterWebsitePhrase){
198    if (enterUrlPhrase == null) {
199        enterUrlPhrase = "Enter the URL of the link you want to add:";
200    }
201    var text = prompt(enterUrlPhrase, "");
202    var domobj = xoopsGetElementById(id);
203    if ( text != null && text != "" ) {
204        if (enterWebsitePhrase == null) {
205            enterWebsitePhrase = "Enter the web site title:";
206        }
207        var text2 = prompt(enterWebsitePhrase, "");
208        if ( text2 != null ) {
209            if ( text2 == "" ) {
210                var result = "[url=" + text + "]" + text + "[/url]";
211            } else {
212                var pos = text2.indexOf(unescape('%00'));
213                if(0 < pos){
214                    text2 = text2.substr(0,pos);
215                }
216                var result = "[url=" + text + "]" + text2 + "[/url]";
217            }
218            xoopsInsertText(domobj, result);
219        }
220    }
221    domobj.focus();
222}
223
224function xoopsCodeImg(id, enterImgUrlPhrase, enterImgPosPhrase, imgPosRorLPhrase, errorImgPosPhrase){
225    if (enterImgUrlPhrase == null) {
226        enterImgUrlPhrase = "Enter the URL of the image you want to add:";
227    }
228    var text = prompt(enterImgUrlPhrase, "");
229    var domobj = xoopsGetElementById(id);
230    if ( text != null && text != "" ) {
231        if (enterImgPosPhrase == null) {
232            enterImgPosPhrase = "Now, enter the position of the image.";
233        }
234        if (imgPosRorLPhrase == null) {
235            imgPosRorLPhrase = "'R' or 'r' for right, 'L' or 'l' for left, or leave it blank.";
236        }
237        if (errorImgPosPhrase == null) {
238            errorImgPosPhrase = "ERROR! Enter the position of the image:";
239        }
240        var text2 = prompt(enterImgPosPhrase + "\n" + imgPosRorLPhrase, "");
241        while ( ( text2 != "" ) && ( text2 != "r" ) && ( text2 != "R" ) && ( text2 != "l" ) && ( text2 != "L" ) && ( text2 != null ) ) {
242            text2 = prompt(errorImgPosPhrase + "\n" + imgPosRorLPhrase,"");
243        }
244        if ( text2 == "l" || text2 == "L" ) {
245            text2 = " align=left";
246        } else if ( text2 == "r" || text2 == "R" ) {
247            text2 = " align=right";
248        } else {
249            text2 = "";
250        }
251        var result = "[img" + text2 + "]" + text + "[/img]";
252        xoopsInsertText(domobj, result);
253    }
254    domobj.focus();
255}
256
257function xoopsCodeEmail(id, enterEmailPhrase){
258    if (enterEmailPhrase == null) {
259        enterEmailPhrase = "Enter the email address you want to add:";
260    }
261    var text = prompt(enterEmailPhrase, "");
262    var domobj = xoopsGetElementById(id);
263    if ( text != null && text != "" ) {
264        var result = "[email]" + text + "[/email]";
265        xoopsInsertText(domobj, result);
266    }
267    domobj.focus();
268}
269
270function xoopsCodeQuote(id, enterQuotePhrase){
271    if (enterQuotePhrase == null) {
272        enterQuotePhrase = "Enter the text that you want to be quoted:";
273    }
274    var text = prompt(enterQuotePhrase, "");
275    var domobj = xoopsGetElementById(id);
276    if ( text != null && text != "" ) {
277        var pos = text.indexOf(unescape('%00'));
278        if(0 < pos){
279            text = text.substr(0,pos);
280        }
281        var result = "[quote]" + text + "[/quote]";
282        xoopsInsertText(domobj, result);
283    }
284    domobj.focus();
285}
286
287function xoopsCodeCode(id, enterCodePhrase){
288    if (enterCodePhrase == null) {
289        enterCodePhrase = "Enter the codes that you want to add.";
290    }
291    var text = prompt(enterCodePhrase, "");
292    var domobj = xoopsGetElementById(id);
293    if ( text != null && text != "" ) {
294        var result = "[code]" + text + "[/code]";
295        xoopsInsertText(domobj, result);
296    }
297    domobj.focus();
298}
299
300function xoopsCodeText(id, hiddentext, enterTextboxPhrase){
301    var textareaDom = xoopsGetElementById(id);
302    var textDom = xoopsGetElementById(id + "Addtext");
303    var fontDom = xoopsGetElementById(id + "Font");
304    var colorDom = xoopsGetElementById(id + "Color");
305    var sizeDom = xoopsGetElementById(id + "Size");
306    var xoopsHiddenTextDomStyle = xoopsGetElementById(hiddentext).style;
307    var textDomValue = textDom.value;
308    var fontDomValue = fontDom.options[fontDom.options.selectedIndex].value;
309    var colorDomValue = colorDom.options[colorDom.options.selectedIndex].value;
310    var sizeDomValue = sizeDom.options[sizeDom.options.selectedIndex].value;
311    if ( textDomValue == "" ) {
312        if (enterTextboxPhrase == null) {
313            enterTextboxPhrase = "Please input text into the textbox.";
314        }
315        alert(enterTextboxPhrase);
316        textDom.focus();
317    } else {
318        if ( fontDomValue != "FONT") {
319            textDomValue = "[font=" + fontDomValue + "]" + textDomValue + "[/font]";
320            fontDom.options[0].selected = true;
321        }
322        if ( colorDomValue != "COLOR") {
323            textDomValue = "[color=" + colorDomValue + "]" + textDomValue + "[/color]";
324            colorDom.options[0].selected = true;
325        }
326        if ( sizeDomValue != "SIZE") {
327            textDomValue = "[size=" + sizeDomValue + "]" + textDomValue + "[/size]";
328            sizeDom.options[0].selected = true;
329        }
330        if (xoopsHiddenTextDomStyle.fontWeight == "bold" || xoopsHiddenTextDomStyle.fontWeight == "700") {
331            textDomValue = "[b]" + textDomValue + "[/b]";
332            xoopsHiddenTextDomStyle.fontWeight = "normal";
333        }
334        if (xoopsHiddenTextDomStyle.fontStyle == "italic") {
335            textDomValue = "[i]" + textDomValue + "[/i]";
336            xoopsHiddenTextDomStyle.fontStyle = "normal";
337        }
338        if (xoopsHiddenTextDomStyle.textDecoration == "underline") {
339            textDomValue = "[u]" + textDomValue + "[/u]";
340            xoopsHiddenTextDomStyle.textDecoration = "none";
341        }
342        if (xoopsHiddenTextDomStyle.textDecoration == "line-through") {
343            textDomValue = "[d]" + textDomValue + "[/d]";
344            xoopsHiddenTextDomStyle.textDecoration = "none";
345        }
346        xoopsInsertText(textareaDom, textDomValue);
347        textDom.value = "";
348        xoopsHiddenTextDomStyle.color = "#000000";
349        xoopsHiddenTextDomStyle.fontFamily = "";
350        xoopsHiddenTextDomStyle.fontSize = "12px";
351        xoopsHiddenTextDomStyle.visibility = "hidden";
352        textareaDom.focus();
353    }
354}
355
356function xoopsValidate(subjectId, textareaId, submitId, plzCompletePhrase, msgTooLongPhrase, allowedCharPhrase, currCharPhrase) {
357    var maxchars = 65535;
358    var subjectDom = xoopsGetElementById(subjectId);
359    var textareaDom = xoopsGetElementById(textareaId);
360    var submitDom = xoopsGetElementById(submitId);
361    if (textareaDom.value == "" || subjectDom.value == "") {
362        if (plzCompletePhrase == null) {
363            plzCompletePhrase = "Please complete the subject and message fields.";
364        }
365        alert(plzCompletePhrase);
366        return false;
367    }
368    if (maxchars != 0) {
369        if (textareaDom.value.length > maxchars) {
370            if (msgTooLongPhrase == null) {
371                msgTooLongPhrase = "Your message is too long.";
372            }
373            if (allowedCharPhrase == null) {
374                allowedCharPhrase = "Allowed max chars length: ";
375            }
376            if (currCharPhrase == null) {
377                currCharPhrase = "Current chars length: ";
378            }
379            alert(msgTooLongPhrase + "\n\n" + allowedCharPhrase + maxchars + "\n" + currCharPhrase + textareaDom.value.length + "");
380            textareaDom.focus();
381            return false;
382        } else {
383            submitDom.disabled = true;
384            return true;
385        }
386    } else {
387        submitDom.disabled = true;
388        return true;
389    }
390}
391
392function chgImg(fileName,imgName){
393    document.images[imgName].src = fileName;
394}
395
Note: See TracBrowser for help on using the repository browser.