[ Index ]
 

Code source de SPIP 1.9.2c

Accédez au Source d'autres logiciels libres

title

Body

[fermer]

/dist/javascript/ -> async_upload.js (source)

   1  // JavaScript Document
   2  jQuery.async_upload_count = 0;
   3  jQuery.fn.async_upload = function(add_function) {
   4    return this.submit(function(){
   5      return do_async_upload(this);
   6    });
   7    
   8    function do_async_upload(form) {
   9      jQuery.async_upload_count++;
  10      var num = jQuery.async_upload_count;
  11      var jForm = jQuery(form);
  12      var par = jQuery(jForm).parent();
  13      jQuery("div.upload_message",par)
  14      .remove();
  15      if(!form.async_init) {
  16        form.async_init = true
  17        jForm
  18        .append("<input type='hidden' name='iframe' value='iframe'>")
  19        .find("input[@name='redirect']")
  20          .val("")
  21        .end();
  22      }
  23      
  24          jForm.attr("target","upload_frame"+num);
  25      var jFrame = jQuery("<iframe id='upload_frame"+num+"' name='upload_frame"+num+"' frameborder='0' marginwidth='0' marginheight='0' scrolling='no' style='position:absolute;width:1px;height:1px;' onload='this.iframeload("+num+")'></iframe>")
  26        .appendTo("body");
  27      
  28      //IE apparently do not write anything in an iframe onload event handler 
  29      jFrame[0].iframeload = function(num) {
  30          //remove the previous message
  31          jQuery("div.upload_message",par).remove();
  32          var res = jQuery(".upload_answer",this.contentDocument || document.frames(this.name).document.body);
  33          //possible classes 
  34          //upload_document_added
  35          if(res.is(".upload_document_added")) {
  36            return add_function(res,jForm);
  37          }
  38          //upload_error
  39          if(res.is(".upload_error")) {
  40            var msg = jQuery("<div class='upload_message'>")
  41            .append(res.html())
  42            jForm.after(msg[0]);
  43            return true;
  44          } 
  45          //upload_zip_list
  46          if(res.is(".upload_zip_list")) {
  47            var zip_form = jQuery("<div class='upload_message'>").append(res.html());
  48            zip_form
  49            .find("form")
  50              .attr("target","upload_frame"+num)
  51              .append("<input type='hidden' name='iframe' value='iframe'>")
  52            .end();
  53            jForm.after(zip_form[0]);
  54            return true;  
  55          }
  56      };
  57      
  58      jForm.before(jQuery("<div class='upload_message' style='height:1%'>").append(ajax_image_searching)[0]);
  59      return true;
  60    }
  61  }
  62  
  63  // Safari plante quand on utilise clone() -> on utilise html()
  64  // Mais FF a un bug sur les urls contenant ~ quand on utilise html() -> on utilise clone()
  65  jQuery.fn.clone2 = jQuery.browser.mozilla ? jQuery.fn.clone : jQuery.fn.html;
  66  
  67  
  68  function async_upload_article_edit(res,jForm){
  69        var cont;
  70        //verify if a new document or a customized vignette
  71        var anchor = jQuery(res.find(">a:first"));
  72              if(jQuery("#"+anchor.attr('id')).size()) {
  73                  cont = jQuery("#"+anchor.attr('id')).next().next().html(anchor.next().next().html());
  74              } else {
  75            //add a class to new documents
  76            res.
  77            find(">div[@class]")
  78            .addClass("documents_added")
  79            .css("display","none");
  80            if (jForm.find("input[@name='arg']").val().search("/0/vignette")!=-1)
  81              cont = jQuery("#liste_images");
  82            else
  83              cont = jQuery("#liste_documents");
  84            cont
  85            .prepend(res.clone2());
  86            //find added documents, remove label and show them nicely
  87            cont.
  88            find("div.documents_added")
  89              .removeClass("documents_added")
  90              .show("slow",function(){
  91                  var anim = jQuery(this).css("height","");
  92                  //bug explorer-opera-safari
  93                  if(!jQuery.browser.mozilla) anim.css('width', this.orig.width-2);
  94                  jQuery(anim).find("img[@onclick]").get(0).onclick();
  95              })
  96              .css('overflow','');
  97          }
  98              jQuery("form.form_upload",cont).async_upload(async_upload_article_edit);
  99        verifForm(cont);
 100        return true;
 101  }
 102  
 103  function async_upload_icon(res) {
 104    res.find(">div").each(function(){
 105      var cont = jQuery("#"+this.id);
 106      verifForm(cont.html(jQuery(this).html()));
 107      jQuery("form.form_upload_icon",cont).async_upload(async_upload_icon);
 108          cont.find("img[@onclick]").each(function(){this.onclick();});
 109    });
 110    return true;                     
 111  }
 112  
 113  function async_upload_portfolio_documents(res){
 114    res.find(">div").each(function(){
 115      var cont = jQuery("#"+this.id);
 116      var self = jQuery(this);
 117      if(!cont.size()) {
 118        cont = jQuery(this.id.search(/--/)!=-1 ? "#portfolio":"#documents")
 119        .append(self.clone2());
 120      }
 121      verifForm(cont.html(self.html()));
 122      jQuery("form.form_upload",cont).async_upload(async_upload_portfolio_documents);
 123    });
 124    return true;             
 125  }


Généré le : Wed Nov 21 10:20:27 2007 par Balluche grâce à PHPXref 0.7
  Clicky Web Analytics