7743e0e5 |
1 | /*************************************************************************** |
5ddeb07c |
2 | * Copyright (C) 2003-2007 Polytechnique.org * |
7743e0e5 |
3 | * http://opensource.polytechnique.org/ * |
4 | * * |
5 | * This program is free software; you can redistribute it and/or modify * |
6 | * it under the terms of the GNU General Public License as published by * |
7 | * the Free Software Foundation; either version 2 of the License, or * |
8 | * (at your option) any later version. * |
9 | * * |
10 | * This program is distributed in the hope that it will be useful, * |
11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of * |
12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * |
13 | * GNU General Public License for more details. * |
14 | * * |
15 | * You should have received a copy of the GNU General Public License * |
16 | * along with this program; if not, write to the Free Software * |
17 | * Foundation, Inc., * |
18 | * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA * |
19 | ***************************************************************************/ |
20 | |
21 | Ajax = { |
22 | xml_client: null, |
23 | init: false, |
24 | |
25 | prepare_client: function() |
26 | { |
27 | if (!Ajax.init) { |
28 | if (window.XMLHttpRequest) { |
29 | Ajax.xml_client = new XMLHttpRequest(); |
30 | } else if (window.ActiveXObject) { |
31 | try { |
32 | Ajax.xml_client = new ActiveXObject("Msxml2.XMLHTTP"); |
33 | } catch (e) { |
34 | Ajax.xml_client = new ActiveXObject("Microsoft.XMLHTTP"); |
35 | } |
36 | } |
37 | if (Ajax.xml_client == null) { |
a14159bf |
38 | alert("Ton client ne supporte pas Ajax, nécessaire pour certaines fonctionalités de cette page"); |
7743e0e5 |
39 | } |
40 | } |
41 | Ajax.init = true; |
42 | }, |
43 | |
cdafa49e |
44 | update_html: function(obj, src, func) |
7743e0e5 |
45 | { |
46 | Ajax.prepare_client(); |
47 | if (Ajax.xml_client == null) { |
48 | return true; |
49 | } |
29c930c0 |
50 | Ajax.xml_client.abort(); |
51 | Ajax.xml_client.onreadystatechange = function() |
7743e0e5 |
52 | { |
53 | if(Ajax.xml_client.readyState == 4) { |
94c63478 |
54 | if (Ajax.xml_client.status == 200) { |
b7582015 |
55 | if (obj != null) { |
56 | document.getElementById(obj).innerHTML = Ajax.xml_client.responseText; |
57 | } |
db3bd146 |
58 | if (func != null) { |
cdafa49e |
59 | func(Ajax.xml_client.responseText); |
60 | } |
29c930c0 |
61 | } else if (Ajax.xml_client.status == 403) { |
62 | window.location.reload(); |
94c63478 |
63 | } |
7743e0e5 |
64 | } |
65 | }; |
66 | Ajax.xml_client.open ('GET', src, true); |
67 | Ajax.xml_client.send (null); |
68 | return false; |
69 | } |
70 | } |
71 | |
b9dcbddd |
72 | var currentTempMessage = 0; |
73 | function setOpacity(obj, opacity) |
74 | { |
75 | opacity = (opacity == 100)?99:opacity; |
76 | // IE |
77 | obj.style.filter = "alpha(opacity:"+opacity+")"; |
78 | // Safari < 1.2, Konqueror |
79 | obj.style.KHTMLOpacity = opacity/100; |
80 | // Old Mozilla |
81 | obj.style.MozOpacity = opacity/100; |
82 | // Safari >= 1.2, Firefox and Mozilla, CSS3 |
83 | obj.style.opacity = opacity/100 |
84 | } |
85 | |
86 | function _showTempMessage(id, state, back) |
87 | { |
88 | var obj = document.getElementById(id); |
89 | if (currentTempMessage != state) { |
90 | return; |
91 | } |
92 | setOpacity(obj, back * 5); |
93 | if (back > 0) { |
94 | setTimeout("_showTempMessage('" + id + "', " + currentTempMessage + "," + (back-1) + ")", 100); |
95 | } else { |
96 | obj.innerHTML = ""; |
97 | } |
98 | } |
99 | |
100 | function showTempMessage(id, message, success) |
101 | { |
102 | var obj = document.getElementById(id); |
103 | obj.innerHTML = (success ? "<img src='images/icons/wand.gif' alt='' /> " |
104 | : "<img src='images/icons/error.gif' alt='' /> ") + message; |
105 | obj.style.fontWeight = "bold"; |
106 | obj.style.color = (success ? "green" : "red");; |
107 | currentTempMessage++; |
108 | setOpacity(obj, 100); |
109 | setTimeout("_showTempMessage('" + id + "', " + currentTempMessage + ", 20)", 700); |
110 | } |
111 | |
fdbeba4f |
112 | function previewWiki(idFrom, idTo, withTitle, idShow) |
113 | { |
114 | var text = encodeURIComponent(document.getElementById(idFrom).value); |
115 | if (text == "") { |
116 | return false; |
117 | } |
118 | var url = "wiki_preview"; |
119 | if (!withTitle) { |
120 | url += "/notitle"; |
121 | } |
122 | Ajax.update_html(idTo, url + "?text=" + text); |
123 | if (idShow != null) { |
124 | document.getElementById(idShow).style.display = ""; |
125 | } |
126 | } |
127 | |
a14159bf |
128 | // vim:set et sw=4 sts=4 sws=4 foldmethod=marker enc=utf-8: |