2 jQuery
.fn
.async_upload = function(add_function
) {
4 beforeSubmit
:async_upload_before_submit
,
10 // Safari plante quand on utilise clone() -> on utilise html()
11 // Mais FF a un bug sur les urls contenant ~ quand on utilise html() -> on utilise clone()
12 jQuery
.fn
.clone2
= jQuery
.browser
.mozilla
? jQuery
.fn
.clone
: jQuery
.fn
.html
;
14 var iframeHandler = function(data
,jForm
,success
) {
15 //remove the previous message
16 jQuery("div.upload_message",$(jForm
).parent()).remove();
17 var res
= jQuery(data
).filter(".upload_answer");
19 //upload_document_added
20 if(res
.is(".upload_document_added")) {
24 if(res
.is(".upload_error")) {
25 var msg
= jQuery("<div class='upload_message'>")
31 if(res
.is(".upload_zip_list")) {
32 var zip_form
= jQuery("<div class='upload_message'>").append(res
.html());
35 .async_upload(function(res
,s
){
38 jForm
.after(zip_form
[0]);
44 function async_upload_before_submit(data
,form
) {
45 form
.before(jQuery("<div class='upload_message' style='height:1%'>").append(ajax_image_searching
)[0]);
46 //if not present add the iframe input
47 if(!form
.find("input[name=iframe]").length
)
48 form
.append("<input type='hidden' name='iframe' value='iframe'>");
49 //reset the redirect input
51 .find("input[name='redirect']")
55 function async_upload_article_edit(res
,s
,jForm
){
56 res
= iframeHandler(res
,jForm
,async_upload_article_edit
);
59 //verify if a new document or a customized vignette
60 var bloc
= jQuery(res
.find(">div:first[id^=document]"));
61 if(jQuery("#"+bloc
.attr('id')).size()) {
62 cont
= jQuery("#"+bloc
.attr('id')).html(bloc
.html());
64 //add a class to new documents
67 .addClass("documents_added")
68 .css("display","none");
69 if (jForm
.find("input[name='arg']").val().search("/0/image")!=-1){
70 cont
= jQuery("#liste_images");
71 // cas de l'interface document unifiee
73 cont
= jQuery("#liste_documents");
76 cont
= jQuery("#liste_documents");
78 .prepend(res
.clone2());
79 //find added documents, remove label and show them nicely
81 find("div.documents_added")
82 .removeClass("documents_added")
83 .show("slow",function(){
84 var anim
= jQuery(this).css("height","");
85 //bug explorer-opera-safari
86 if(!jQuery
.browser
.mozilla
)
87 anim
.css('width', jQuery(this).width()-2);
88 a
= jQuery(anim
).find("img[onclick]")
89 if (a
.length
) a
.get(0).onclick();
93 jQuery("form.form_upload",cont
).async_upload(async_upload_article_edit
);
98 function async_upload_icon(res
,s
,jForm
) {
99 res
= iframeHandler(res
,jForm
);
100 if(!res
) return true;
101 res
.find(">div").each(function(){
102 var cont
= jQuery("#"+this.id
);
103 verifForm(cont
.html(jQuery(this).html()));
104 jQuery("form.form_upload_icon",cont
).async_upload(async_upload_icon
);
105 cont
.find("img[onclick]").each(function(){this.onclick();});
110 function async_upload_portfolio_documents(res
,s
,jForm
){
111 res
= iframeHandler(res
,jForm
,async_upload_portfolio_documents
);
113 if(!res
) return true;
115 // on dirait que ca passe mieux sur Safari avec un setTimeout cf #1408
116 setTimeout(function() {
117 res
.find(">div").each(function(){
118 // this.id = documenter--id_article ou documenter-id_article
119 var cont
= jQuery("#"+this.id
);
120 var self
= jQuery(this);
122 cont
= jQuery(this.id
.search(/--/)!=-1 ? "#portfolio":"#documents")
123 .append(self
.clone2());
125 verifForm(cont
.html(self
.html()));
126 jQuery("form.form_upload",cont
).async_upload(async_upload_portfolio_documents
);