/** * jqUploader (http://www.pixeline.be/experiments/jqUploader/) * A jQuery plugin to replace html-based file upload input fields with richer flash-based upload progress bar UI. * * Version 1.0.2.2 * September 2007 * * Copyright (c) 2007 Alexandre Plennevaux (http://www.pixeline.be) * Dual licensed under the MIT and GPL licenses. * http://www.opensource.org/licenses/mit-license.php * http://www.opensource.org/licenses/gpl-license.php * * using plugin "Flash" by Luke Lutman (http://jquery.lukelutman.com/plugins/flash) * * IMPORTANT: * The packed version of jQuery breaks ActiveX control * activation in Internet Explorer. Use JSMin to minifiy * jQuery (see: http://jquery.lukelutman.com/plugins/flash#activex). * * *BENCI : ReplayJQUploader(ID du div ou span encadrant votre input file) --> réinitialise le flash * **/ jQuery.fn.jqUploader = function(options) { return this.each(function(index) { var $this = jQuery(this); // fetch label value if any, otherwise set a default one var $thisForm = $this.parents("form"); var $thisInput = $("input[type='file']",$this); var $thisLabel = $("label",$this); var containerId = $this.attr("id") || 'jqUploader-'+index; var ctrl_fic_async = ""; var ctrl_fic_present = ""; var startMessage = ($thisLabel.text() =='') ? 'Veuillez choisir un fichier' : $thisLabel.text(); // get form action attribute value as upload script, appending to it a variable telling the script that this is an upload only functionality //var actionURL = $thisForm.attr("action"); // adds a var setting jqUploader to 1, so you can use it for serverside processing //var prepender = (actionURL.lastIndexOf("?") != -1) ? "&": "?"; //actionURL = actionURL+prepender+'jqUploader=1'; // check if max file size is set in html form // correction benci var maxFileSize = $("input[name='MAX_FILE_SIZE']", $(this.form)).val(); var maxFileSize = $("input[name='MAX_FILE_SIZE']", $this).val(); var opts = jQuery.extend({ width:450, height:40, version: 8, // version 8+ of flash player required to run jqUploader background: 'FFFFFF', // background color of flash file src: '/inc/jq/upload/jqUploader.swf', srcimgdel: '', // cherche par defaut dans le repertoire "src" définissant ou est le flash , le fichier delete.png srcimgview: '', // cherche par defaut dans le repertoire "src" définissant ou est le flash , le fichier view.png // uploadScript: actionURL, //!!!!!! Bien mettre http:// car filereference de flash qui upload ne sait pas le faire en ssl donc si on met /..... sans http alors bug uploadScript: 'https://www.marches-ardennes.fr/inc/jq/upload/flash_upload.php?jqUploader=1', uploadDir: '/var/www/tmp/', afterScript: undefined, // if this is empty, jqUploader will replace the upload swf by a hidden input element varName: $thisInput.attr("name"), //this holds the variable name of the file input field in your html form allowedExt: '*.jpg; *.jpeg; *.png', // allowed extensions allowedExtDescr: 'Images (*.jpg; *.jpeg; *.png)', params: {menu:false}, flashvars: {}, wmode: 'opaque', autostart: false, alea: false, hideSubmit: false, barColor: '0000CC', okColor: '0000CC', okMsgAv: '', okMsgAp: '', maxFileSize: maxFileSize, startMessage: startMessage, errorSizeMessage: 'Fichier trop gros!', validFileMessage: 'Cliquer sur Envoyer', progressMessage: 'Envoi en cours', endMessage: 'Envoi avec succès' }, options || {} ); // disable form submit button if (opts.hideSubmit==true) { $("*[type='submit']",this.form).hide(); } // Sera exécuter sauf si redirection une fois upload terminé TerminateJQUploader = function(containerId,fileori,filename,varname){ // $this= $('#'+containerId).empty(); $this= $('#'+containerId); // equivalent au code commenté juste au dessus $('#'+containerId + ' embed').hide(); // cache le flash $('#'+containerId + ' :not(embed)').remove(); // vire tout le reste // gestion logo de suppression imgdel = opts.srcimgdel; if (imgdel == "") imgdel = location.protocol + "//" + location.host + "/" + opts.src.substr(1,opts.src.lastIndexOf("/")) + "delete.png"; // gestion logo de visualisation imgview = opts.srcimgview; if (imgview == "") imgview = location.protocol + "//" + location.host + "/" + opts.src.substr(1,opts.src.lastIndexOf("/")) + "view.png"; // $this.text('').append(''+opts.okMsgAv+''+fileori.replace(/'/g,"\'")+''+opts.okMsgAp+''); // $this.append(''+opts.okMsgAv+''+fileori.replace(/'/g,"\'")+''+opts.okMsgAp+' '); $this.append('  '+opts.okMsgAv+''+fileori.replace(/'/g,"\'")+''+opts.okMsgAp+''); var myForm = $this.parents("form"); // myForm.submit(function(){return true}); $("*[type='submit']",myForm).show(); } // Sera executer quand upload commence EncoursJQUploader = function(containerId,filename,varname){ $this= $('#'+containerId); $this.append(''); } ReplayJQUploader = function(containerId) { $('#'+containerId + ' :not(embed)').remove(); var tmp = $('#'+containerId).html(); $('#'+containerId + ' embed').remove(); $('#'+containerId).append(tmp); $('#'+containerId + ' embed').show(); } var myParams = ''; for (var p in opts.params){ myParams += p+'='+opts.params[p]+','; } myParams = myParams.substring(0, myParams.length-1); // this function interfaces with the jquery flash plugin jQuery(this).flash( { src: opts.src, width: opts.width, height: opts.height, id:'movie_player-'+index, bgcolor:'#'+opts.background, wmode: opts.wmode, flashvars: { containerId: containerId, uploadScript: opts.uploadScript, uploadDir: opts.uploadDir, afterScript: opts.afterScript, autostart: (opts.autostart) ? "-1" : "0", alea: (opts.alea) ? "-1" : "0", allowedExt: opts.allowedExt, allowedExtDescr: opts.allowedExtDescr, varName : opts.varName, barColor : opts.barColor, maxFileSize :opts.maxFileSize, startMessage : opts.startMessage, errorSizeMessage : opts.errorSizeMessage, validFileMessage : opts.validFileMessage, progressMessage : opts.progressMessage, endMessage: opts.endMessage }, params: myParams }, { version: opts.version, update: false }, function(htmlOptions){ var ctrl_actif = ""; var ctrl_fic_async = ""; var ctrl_fic_present = ""; var ctrl_fic_extension = ""; var ctrl_fic_extension_message = ""; if ($("input[type='file'][ctrl_actif]",$this).length > 0) //permet de vérifier qu'un attribut existe meme s'il est affecté à vide et sur IE7 et IE6 { ctrl_actif = $("input[type='file']",$this).attr("ctrl_actif"); if (ctrl_actif == 'undefined') // cas IE7 et IE6 quand affectation attribut à vide ctrl_actif = 'ctrl_actif=""'; else ctrl_actif = 'ctrl_actif="' + ctrl_actif + '"'; } if ($("input[type='file'][ctrl_fic_async]",$this).length > 0) //permet de vérifier qu'un attribut existe meme s'il est affecté à vide et sur IE7 et IE6 { ctrl_fic_async = $("input[type='file']",$this).attr("ctrl_fic_async"); if (ctrl_fic_async == 'undefined') // cas IE7 et IE6 quand affectation attribut à vide ctrl_fic_async = 'ctrl_fic_async=""'; else ctrl_fic_async = 'ctrl_fic_async="' + ctrl_fic_async + '"'; } if ($("input[type='file'][ctrl_fic_present]",$this).length > 0) //permet de vérifier qu'un attribut existe meme s'il est affecté à vide et sur IE7 et IE6 { ctrl_fic_present = $("input[type='file']",$this).attr("ctrl_fic_present"); if (ctrl_fic_present == 'undefined') ctrl_fic_present = 'ctrl_fic_present=""'; else ctrl_fic_present = 'ctrl_fic_present="' + ctrl_fic_present + '"'; } if ($("input[type='file'][ctrl_fic_extension]",$this).length > 0) //permet de vérifier qu'un attribut existe meme s'il est affecté à vide et sur IE7 et IE6 { ctrl_fic_extension = $("input[type='file']",$this).attr("ctrl_fic_extension"); if (ctrl_fic_extension == 'undefined') ctrl_fic_extension = 'ctrl_fic_extension=""'; else ctrl_fic_extension = 'ctrl_fic_extension="' + ctrl_fic_extension + '"'; } if ($("input[type='file'][ctrl_fic_extension_message]",$this).length > 0) //permet de vérifier qu'un attribut existe meme s'il est affecté à vide et sur IE7 et IE6 { ctrl_fic_extension_message = $("input[type='file']",$this).attr("ctrl_fic_extension_message"); if (ctrl_fic_extension_message == 'undefined') ctrl_fic_extension_message = 'ctrl_fic_extension_message=""'; else ctrl_fic_extension_message = 'ctrl_fic_extension_message="' + ctrl_fic_extension_message + '"'; } var $el = $('
'+this.innerHTML+'
'); $el.prepend($.fn.flash.transform(htmlOptions)); $('div.alt',$el).remove(); $(this).after($el).remove(); } ); }); };