d6ddb57922382c7d232ad362fe17638014fb7ec7
1 var memo_obj
= new Array();
2 var url_chargee
= new Array();
5 function findObj_test_forcer(n
, forcer
) {
8 // Voir si on n'a pas deja memorise cet element
9 if (memo_obj
[n
] && !forcer
) {
14 if((p
= n
.indexOf("?"))>0 && parent
.frames
.length
) {
15 d
= parent
.frames
[n
.substring(p
+1)].document
;
18 if(!(x
= d
[n
]) && d
.all
) {
21 for (i
= 0; !x
&& i
<d
.forms
.length
; i
++) {
24 for(i
=0; !x
&& d
.layers
&& i
<d
.layers
.length
; i
++) x
= findObj(n
,d
.layers
[i
].document
);
25 if(!x
&& document
.getElementById
) x
= document
.getElementById(n
);
27 // Memoriser l'element
28 if (!forcer
) memo_obj
[n
] = x
;
33 return findObj_test_forcer(n
, false);
35 // findObj sans memorisation de l'objet - avec Ajax, les elements se deplacent dans DOM
36 function findObj_forcer(n
) {
37 return findObj_test_forcer(n
, true);
41 // Fonctions pour mini_nav
44 function slide_horizontal (couche
, slide
, align
, depart
, etape
) {
46 var obj
= findObj_forcer(couche
);
50 if (align
== 'left') depart
= obj
.scrollLeft
;
51 else depart
= obj
.firstChild
.offsetWidth
- obj
.scrollLeft
;
54 etape
= Math
.round(etape
) + 1;
55 pos
= Math
.round(depart
) + Math
.round(((slide
- depart
) / 10) * etape
);
57 if (align
== 'left') obj
.scrollLeft
= pos
;
58 else obj
.scrollLeft
= obj
.firstChild
.offsetWidth
- pos
;
59 if (etape
< 10) setTimeout("slide_horizontal('"+couche
+"', '"+slide
+"', '"+align
+"', '"+depart
+"', '"+etape
+"')", 60);
60 //else obj.scrollLeft = slide;
63 function changerhighlight (couche
) {
69 jQuery('.petite-racine.on').removeClass('on');
72 function aff_selection (arg
, idom
, url
, event
) {
73 noeud
= findObj_forcer(idom
);
75 noeud
.style
.display
= "none";
76 charger_node_url(url
+arg
, noeud
, '','',event
);
81 // selecteur de rubrique et affichage de son titre dans le bandeau
83 function aff_selection_titre(titre
, id
, idom
, nid
)
85 t
= findObj_forcer('titreparent');
87 t
=findObj_forcer(nid
);
89 jQuery(t
).trigger('change'); // declencher le onchange
90 t
=findObj_forcer(idom
);
91 t
.style
.display
='none';
92 p
= $(t
).parents('form');
93 if (p
.is('.submit_plongeur')) p
.get(p
.length
-1).submit();
98 * Utilise dans inc/plonger
107 function aff_selection_provisoire(id
, racine
, url
, col
, sens
,informer
,event
)
109 charger_id_url(url
.href
,
110 racine
+ '_col_' + (col
+1),
112 slide_horizontal(racine
+ '_principal', ((col
-1)*150), sens
);
113 aff_selection (id
, racine
+ "_selection", informer
);
116 // empecher le chargement non Ajax
121 * Lanche une requete Ajax a chaque frappe au clavier dans une balise de saisie.
122 * Si l'entree redevient vide, rappeler l'URL initiale si dispo.
123 * Sinon, controler au retour si le resultat est unique,
124 * auquel cas forcer la selection.
125 * utlise dans inc/selectionner
133 function onkey_rechercher(valeur
, rac
, url
, img
, nid
, init
) {
134 var Field
= findObj_forcer(rac
);
135 if (!valeur
.length
) {
136 init
= findObj_forcer(init
);
137 if (init
&& init
.href
) { charger_node_url(init
.href
, Field
);}
139 charger_node_url(url
+valeur
,
142 var n
= Field
.childNodes
.length
- 1;
143 // Safari = 0 & Firefox = 1 !
144 // et gare aux negatifs en cas d'abort
146 noeud
= Field
.childNodes
[n
].firstChild
;
148 // cas de la rubrique, pas des auteurs
149 aff_selection_titre(noeud
.firstChild
.nodeValue
, noeud
.title
, rac
, nid
);
158 // Recupere tous les formulaires de la page
159 // (ou du fragment qu'on vient de recharger en ajax)
160 // et leur applique les comportements js souhaites
162 // * utiliser ctrl-s, F8 etc comme touches de sauvegarde
163 var verifForm_clicked
=false;
164 function verifForm(racine
) {
165 verifForm_clicked
= false; // rearmer quand on passe ici (il y a eu de l'ajax par exemple)
166 if (!jQuery
) return; // appels ajax sur iframe
167 // Clavier pour sauver (cf. crayons)
168 // cf http://www.quirksmode.org/js/keys.html
169 if (!jQuery
.browser
.msie
)
170 // keypress renvoie le charcode correspondant au caractere frappe (ici s)
171 jQuery('form:not(.bouton_action_post)', racine
||document
).not('.verifformok')
172 .keypress(function(e
){
175 /* ctrl-s ou ctrl-maj-S, firefox */
176 (((e
.charCode
||e
.keyCode
) == 115) || ((e
.charCode
||e
.keyCode
) == 83))
178 || (e
.charCode
==19 && e
.keyCode
==19)
180 ) /* ctrl-s, Opera Mac */
181 || (e
.keyCode
==19 && jQuery
.browser
.opera
))
182 && !verifForm_clicked
184 verifForm_clicked
= true;
185 jQuery(this).find('input[type=submit]')
189 }).addClass('verifformok');
191 // keydown renvoie le keycode correspondant a la touche pressee (ici F8)
192 jQuery('form:not(.bouton_action_post)', racine
||document
).not('.verifformok')
193 .keydown(function(e
){
194 //jQuery('#ps').after("<div>ctrl:"+e.ctrlKey+"<br />charcode:"+e.charCode+"<br />keycode:"+e.keyCode+"<hr /></div>");
195 if (!e
.charCode
&& e
.keyCode
== 119 /* F8, windows */ && !verifForm_clicked
){
196 verifForm_clicked
= true;
197 jQuery(this).find('input[type=submit]')
201 }).addClass('verifformok');
204 // La fonction qui fait vraiment le travail decrit ci-dessus.
205 // Son premier argument est deja le noeud du DOM
206 // et son resultat booleen est inverse ce qui lui permet de retourner
207 // le gestionnaire Ajax comme valeur non fausse
209 function AjaxSqueezeNode(trig
, target
, f
, event
)
213 // retour std si pas precise: affecter ce noeud avec ce retour
215 callback = function() { verifForm(this);}
218 callback = function(res
,status
) {
219 f
.apply(this,[res
,status
]);
225 if (typeof(window
['_OUTILS_DEVELOPPEURS']) != 'undefined'){
226 if (!(navigator
.userAgent
.toLowerCase().indexOf("firefox/1.0")))
227 valid
= (typeof event
== 'object') && (event
.altKey
|| event
.metaKey
);
230 if (typeof(trig
) == 'string') {
231 // laisser le choix de la touche enfoncee au moment du clic
232 // car beaucoup de systemes en prenne une a leur usage
234 window
.open(trig
+'&transformer_xml=valider_xml');
236 jQuery(target
).animeajax();
240 "complete": function(r
,s
) {
241 AjaxRet(r
,s
,target
, callback
);
249 //open a blank window
250 var doc
= window
.open("","valider").document
;
251 //create a document to enable receiving the result of the ajax post
254 //set the element receiving the ajax post
258 jQuery(target
).animeajax();
261 jQuery(trig
).ajaxSubmit({
263 "success": function(res
,status
) {
264 if(status
=='error') return this.html('Erreur HTTP');
265 callback
.apply(this,[res
,status
]);
267 "beforeSubmit":function (vars
) {
269 vars
.push({"name":"transformer_xml","value":"valider_xml"});
277 function AjaxRet(res
,status
, target
, callback
) {
278 if (res
.aborted
) return;
279 if (status
=='error') return jQuery(target
).html('HTTP Error');
281 // Inject the HTML into all the matched elements
283 .html(res
.responseText
)
285 .each(callback
, [res
.responseText
, status
]);
289 // Comme AjaxSqueeze,
290 // mais avec un cache sur le noeud et un cache sur la reponse
291 // et une memorisation des greffes en attente afin de les abandonner
292 // (utile surtout a la frappe interactive au clavier)
293 // De plus, la fonction optionnelle n'a pas besoin de greffer la reponse.
295 function charger_id_url(myUrl
, myField
, jjscript
, event
)
297 var Field
= findObj_forcer(myField
);
298 if (!Field
) return true;
301 jQuery(Field
).empty();
302 retour_id_url(Field
, jjscript
);
303 return true; // url vide, c'est un self complet
304 } else return charger_node_url(myUrl
, Field
, jjscript
, findObj_forcer('img_' + myField
), event
);
309 function charger_node_url(myUrl
, Field
, jjscript
, img
, event
)
311 // disponible en cache ?
312 if (url_chargee
[myUrl
]) {
313 var el
= jQuery(Field
).html(url_chargee
[myUrl
])[0];
314 retour_id_url(el
, jjscript
);
315 jQuery
.spip
.triggerAjaxLoad(el
);
319 if (img
) img
.style
.visibility
= "visible";
320 if (xhr_actifs
[Field
]) { xhr_actifs
[Field
].aborted
= true;xhr_actifs
[Field
].abort(); }
321 xhr_actifs
[Field
] = AjaxSqueezeNode(myUrl
,
324 xhr_actifs
[Field
] = undefined;
325 if (img
) img
.style
.visibility
= "hidden";
326 url_chargee
[myUrl
] = r
;
327 retour_id_url(Field
, jjscript
);
328 slide_horizontal($(Field
).children().attr("id")+'_principal', $(Field
).width() , $(Field
).css("text-align"));
335 function retour_id_url(Field
, jjscript
)
337 jQuery(Field
).css({'visibility':'visible','display':'block'});
338 if (jjscript
) jjscript();
341 function charger_node_url_si_vide(url
, noeud
, gifanime
, jjscript
,event
) {
343 if (noeud
.style
.display
!='none') {
344 noeud
.style
.display
='none';}
346 if (noeud
.innerHTML
!= "") {
347 noeud
.style
.visibility
= "visible";
348 noeud
.style
.display
= "block";
350 charger_node_url(url
, noeud
,'',gifanime
,event
);
357 jQuery(document
).ready(function(){
359 onAjaxLoad(verifForm
);