[SPIP Zone] r4797 - in /_plugins_/_ze_laboratoire_/spiip: img_pack/layer.js img_pack/presentation.js inc/presentation.php

Author: renatoformato@virgilio.it
Date: Mon Aug 21 20:54:18 2006
New Revision: 4797

Log:
All ajax request managed by AjaxSqueeze; search image goes automatically on and off; fix verifform bug called on all browser instead of mozilla only

Modified:
    _plugins_/_ze_laboratoire_/spiip/img_pack/layer.js
    _plugins_/_ze_laboratoire_/spiip/img_pack/presentation.js
    _plugins_/_ze_laboratoire_/spiip/inc/presentation.php

Modified: _plugins_/_ze_laboratoire_/spiip/img_pack/layer.js

--- _plugins_/_ze_laboratoire_/spiip/img_pack/layer.js (original)
+++ _plugins_/_ze_laboratoire_/spiip/img_pack/layer.js Mon Aug 21 20:54:18 2006
@@ -127,6 +127,7 @@
     return new ActiveXObject("Microsoft.XMLHTTP");
}

+/*
function ajah(method, url, flux, rappel)
{
   var xhr = createXmlHttp();
@@ -150,6 +151,7 @@
                 else { f(xhr.responseText); }
         }
}
+*/

// Si Ajax est disponible, cette fonction envoie la requete en Ajax.
// Si le premier argument n'est pas une url, ce doit etre un formulaire.
@@ -160,18 +162,39 @@
// Toutefois il y toujours un coup de retard dans la pose d'un cookie:
// eviter de se loger avec redirection vers un telle page

-function AjaxSqueeze(trig, id)
+function AjaxSqueeze(trig, id, callback, img)
{
+ var reqObj;
+ callback = callback || function(){};
+ //needs a better way to display error to the user
   if(trig.constructor == String) {
- $('#'+id).prepend(ajax_image_searching).load(trig);
+ reqObj = $('#'+id).imgOn(img).load(trig,function(res,status){
+ imgOff(reqObj);
+ if(status=='error') this.html('Erreur HTTP');
+ callback(res,status);
+ });
   } else {
- //needs error checking and a way to display it to the user
- //uses form plugin
- $(trig).prepend(ajax_image_searching).ajaxSubmit('#'+id,function(res,status){
- if(status=='success') verifForm(this);
+ //submit a form. Uses form plugin
+ reqObj = $(trig).imgOn(img).ajaxSubmit('#'+id,function(res,status){
+ if(status=='success' && browser_verifForm) verifForm(this);
+ if(status=='error') this.html('Erreur HTTP');
+ imgOff(reqObj);
+ callback(res,status);
     });
+ }
     return false;
   }
+
+//jQuery helper function to show and hide an image as the first children of a jQuery object
+//if no id is passed or the image with the id specified
+jQuery.fn.imgOn = function(img) {
+ if(img) this.ajaxImg = $('#'+img).css('visibility','visible');
+ else this.prepend(ajax_image_searching);
+ return this
+ }
+imgOff = function(reqObj) {
+ if(reqObj.ajaxImg) reqObj.ajaxImg.css('visibility','hidden');
+ reqObj.ajaxImg = null;
}

Modified: _plugins_/_ze_laboratoire_/spiip/img_pack/presentation.js

--- _plugins_/_ze_laboratoire_/spiip/img_pack/presentation.js (original)
+++ _plugins_/_ze_laboratoire_/spiip/img_pack/presentation.js Mon Aug 21 20:54:18 2006
@@ -61,16 +61,12 @@
         find('a.ajax').click(execAjaxLinks).not('[@href]').css({'cursor':'pointer','visibility':'visible'});
         return false;
       }
- var img = $('#img_'+params[2]).css('visibility','visible');
- $('#'+params[2]).load(url,function(res,status){
+ return AjaxSqueeze(url,params[2],function(res,status){
         if(status=='success') {
           url_chargee['mem_'+url]=res;
- img.css('visibility','hidden');
           $('a.ajax',this).click(execAjaxLinks).not('[@href]').css({'cursor':'pointer','visibility':'visible'});
         }
- });
- //charger_id_url(url,params[2]);
- return false;
+ },'img_'+params[2]);
}

var accepter_change_statut;

Modified: _plugins_/_ze_laboratoire_/spiip/inc/presentation.php

--- _plugins_/_ze_laboratoire_/spiip/inc/presentation.php (original)
+++ _plugins_/_ze_laboratoire_/spiip/inc/presentation.php Mon Aug 21 20:54:18 2006
@@ -2034,7 +2034,8 @@
       '<link rel="stylesheet" href="' . entites_html($css)
       . '" type="text/css" />'. "\n"
     ) ) ."\n"
- ."<script type='text/javascript'>$(document).ready(function(){ $browser_verifForm$onLoad });var largeur_icone = $largeur_icone_bandeau_principal; </script>\n"
+ ."<script type='text/javascript'>".($browser_verifForm?"var browser_verifForm = true;":"")
+ ."$(document).ready(function(){ $browser_verifForm$onLoad });var largeur_icone = $largeur_icone_bandeau_principal; </script>\n"
     ."<style type='text/css'>.boutons_admin {width:{$largeur_icone_bandeau_principal}px}</style>\n";
   echo pipeline('header_prive', $head)
     . "</head>\n";