1 /***************************************************************************
2 * Copyright (C) 2003-2011 Polytechnique.org *
3 * http://opensource.polytechnique.org/ *
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. *
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. *
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 *
18 * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA *
19 ***************************************************************************/
21 // {{{ jQuery object extension
24 /* Add new functions to jQuery namesapce */
26 /* The goal of the following functions is to provide an AJAX API that
27 * take a different callback in case of HTTP success code (2XX) and in
31 xajax
: function(source
, method
, data
, onSuccess
, onError
, type
) {
33 if ($.isFunction(data
)) {
34 type
= type
|| onError
;
39 if (onError
!= null && !$.isFunction(onError
)) {
40 type
= type
|| onError
;
44 function ajaxHandler(data
, textStatus
, xhr
) {
45 if (textStatus
== 'success') {
47 onSuccess(data
, textStatus
, xhr
);
49 } else if (textStatus
== 'error') {
51 onError(data
, textStatus
, xhr
);
53 alert("Une error s'est produite lors du traitement de la requête.\n"
54 + "Ta session a peut-être expiré");
67 xget
: function(source
, data
, onSuccess
, onError
, type
) {
68 return $.xajax(source
, 'GET', data
, onSuccess
, onError
, type
);
71 xgetJSON
: function(source
, data
, onSuccess
, onError
) {
72 return $.xget(source
, data
, onSuccess
, onError
, 'json');
75 xgetScript
: function(source
, onSuccess
, onError
) {
76 return $.xget(source
, null, onSuccess
, onError
, 'script');
79 xgetText
: function(source
, data
, onSuccess
, onError
) {
80 return $.xget(source
, data
, onSuccess
, onError
, 'text');
83 xpost
: function(source
, data
, onSuccess
, onError
, type
) {
84 return $.xajax(source
, 'POST', data
, onSuccess
, onError
, type
);
87 closeOnEsc
: function() {
88 return $(window
).keydown(function (e
) {
89 if (e
.keyCode
== 27) {
95 dynPost
: function(action
, key
, value
) {
97 if (!$.isArray(key
)) {
103 var form
= $('<form>', {
107 for (var k
in values
) {
114 $('body').appendTo(form
);
119 /* Add new functions to jQuery objects */
121 tmpMessage
: function(message
, success
) {
123 this.html("<img src='images/icons/wand.gif' alt='' /> " + message
)
124 .css('color', 'green');
126 this.html("<img src='images/icons/error.gif' alt='' /> " + message
)
127 .css('color', 'red');
129 return this.css('fontWeight', 'bold')
135 updateHtml
: function(source
, callback
) {
137 function handler(data
) {
143 $.xget(source
, handler
, 'text');
147 successMessage
: function(source
, message
) {
149 $.xget(source
, function() {
150 elements
.tmpMessage(message
, true);
155 wiki
: function(text
, withTitle
) {
157 return this.html('');
159 var url
= 'wiki_preview';
164 $.post(url
, { text
: text
},
171 popWin
: function(w
, h
) {
172 return this.click(function() {
173 window
.open(this.href
, '_blank',
174 'toolbar=0,location=0,directories=0,status=0,'
175 +'menubar=0,scrollbars=1,resizable=1,'
176 +'width='+w
+',height='+h
);
184 // {{{ function RegExp.escape()
186 RegExp
.escape
= function(text
) {
187 if (!arguments
.callee
.sRE
) {
189 '/', '.', '*', '+', '?', '|',
190 '(', ')', '[', ']', '{', '}',
193 arguments
.callee
.sRE
= new RegExp(
194 '(\\' + specials
.join('|\\') + ')', 'g'
197 return text
.replace(arguments
.callee
.sRE
, '\\$1');
201 // {{{ PmWiki decoding
205 convert
: function(a
) {
208 for (i
= 0; i
< a
.length
; i
++) {
210 s
+= ((b
>= 'A' && b
<= 'Z') || (b
>= 'a' && b
<= 'z') ? Nix
.map
[b
] : b
);
217 var map
= new Array();
218 var s
='abcdefghijklmnopqrstuvwxyz';
219 for (i
= 0; i
< s
.length
; i
++)
220 map
[s
.charAt(i
)] = s
.charAt((i
+13)%26);
221 for (i
=0; i
<s
.length
; i
++)map
[s
.charAt(i
).toUpperCase()] = s
.charAt((i
+13)%26).toUpperCase();
224 decode
: function(a
) {
225 document
.write(Nix
.convert(a
));
232 function previewWiki(idFrom
, idTo
, withTitle
, idShow
)
234 $('#' + idTo
).wiki($('#' + idFrom
).val(), withTitle
);
235 if (idShow
!= null) {
236 $('#' + idShow
).show();
242 // vim:set et sw=4 sts=4 sws=4 foldmethod=marker enc=utf-8: