Changeset 49010 in spip-zone
- Timestamp:
- Jun 23, 2011, 7:18:08 AM (10 years ago)
- Location:
- _plugins_/formulaire_upload
- Files:
-
- 4 edited
Legend:
- Unmodified
- Added
- Removed
-
_plugins_/formulaire_upload/javascript/jquery.MultiFile.js
r13505 r49010 1 1 /* 2 ### jQuery Multiple File Upload Plugin ### 3 By Diego A., http://www.fyneworks.com, diego@fyneworks.com 4 5 Website: 6 http://www.fyneworks.com/jquery/multiple-file-upload/ 7 Project Page: 8 http://jquery.com/plugins/project/MultiFile/ 9 Forums: 10 http://www.nabble.com/jQuery-Multiple-File-Upload-f20931.html 11 Blog: 12 http://fyneworks.blogspot.com/2007/04/jquery-multiple-file-upload-plugin-v11.html 13 (old) http://fyneworks.blogspot.com/2007/04/multiple-file-upload-plugin-for-jquery.html 14 15 12-April-2007: v1.1 16 Added events and file extension validation 17 See website for details. 18 19 06-June-2007: v1.2 20 Now works in Opera. 21 22 12-June-2007: v1.21 23 Preserves name of file input so all current server-side 24 functions don't need to be changed on new installations. 25 26 24-June-2007: v1.22 27 Now works perfectly in Opera, thanks to Adrian Wróbel <adrian [dot] wrobel [at] gmail.com> 2 ### jQuery Multiple File Upload Plugin v1.47 - 2010-03-26 ### 3 * Home: http://www.fyneworks.com/jquery/multiple-file-upload/ 4 * Code: http://code.google.com/p/jquery-multifile-plugin/ 5 * 6 * Dual licensed under the MIT and GPL licenses: 7 * http://www.opensource.org/licenses/mit-license.php 8 * http://www.gnu.org/licenses/gpl.html 9 ### 28 10 */ 29 11 30 12 /*# AVOID COLLISIONS #*/ 31 if(jQuery) (function($){13 ;if(window.jQuery) (function($){ 32 14 /*# AVOID COLLISIONS #*/ 33 34 // Fix for Opera: 6-June-2007 35 // Stop confusion between null, 'null' and 'undefined' 36 function IsNull(i){ 37 return (i==null || i=='null' || i=='' || i=='undefined'); 38 }; 39 40 // extend jQuery - $.MultiFile hook 41 $.extend($, { 42 MultiFile: function( o /* Object */ ){ 43 return $("INPUT[@type='file'].multi").MultiFile(o); 44 } 45 }); 46 47 // extend jQuery function library 48 $.extend($.fn, { 15 16 // plugin initialization 17 $.fn.MultiFile = function(options){ 18 if(this.length==0) return this; // quick fail 19 20 // Handle API methods 21 if(typeof arguments[0]=='string'){ 22 // Perform API methods on individual elements 23 if(this.length>1){ 24 var args = arguments; 25 return this.each(function(){ 26 $.fn.MultiFile.apply($(this), args); 27 }); 28 }; 29 // Invoke API method handler 30 $.fn.MultiFile[arguments[0]].apply(this, $.makeArray(arguments).slice(1) || []); 31 // Quick exit... 32 return this; 33 }; 34 35 // Initialize options for this call 36 var options = $.extend( 37 {}/* new object */, 38 $.fn.MultiFile.options/* default options */, 39 options || {} /* just-in-time options */ 40 ); 41 42 // Empty Element Fix!!! 43 // this code will automatically intercept native form submissions 44 // and disable empty file elements 45 $('form') 46 .not('MultiFile-intercepted') 47 .addClass('MultiFile-intercepted') 48 .submit($.fn.MultiFile.disableEmpty); 49 50 //### http://plugins.jquery.com/node/1363 51 // utility method to integrate this plugin with others... 52 if($.fn.MultiFile.options.autoIntercept){ 53 $.fn.MultiFile.intercept( $.fn.MultiFile.options.autoIntercept /* array of methods to intercept */ ); 54 $.fn.MultiFile.options.autoIntercept = null; /* only run this once */ 55 }; 56 57 // loop through each matched element 58 this 59 .not('.MultiFile-applied') 60 .addClass('MultiFile-applied') 61 .each(function(){ 62 //##################################################################### 63 // MAIN PLUGIN FUNCTIONALITY - START 64 //##################################################################### 49 65 50 // MultiFile function 51 MultiFile: function( o /* Object */ ){ 52 if(this._MultiFile){ return $(this); } 53 this._MultiFile = true; 54 55 // DEBUGGING: disable plugin 56 //return false; 57 58 // Bind to each element in current jQuery object 59 return $(this).each(function(i){ 60 // Remember our ancestors... 61 var d = this; 62 var x = $(d); 66 // BUG 1251 FIX: http://plugins.jquery.com/project/comments/add/1251 67 // variable group_count would repeat itself on multiple calls to the plugin. 68 // this would cause a conflict with multiple elements 69 // changes scope of variable to global so id will be unique over n calls 70 window.MultiFile = (window.MultiFile || 0) + 1; 71 var group_count = window.MultiFile; 72 73 // Copy parent attributes - Thanks to Jonas Wagner 74 // we will use this one to create new input elements 75 var MultiFile = {e:this, E:$(this), clone:$(this).clone()}; 76 77 //=== 78 79 //# USE CONFIGURATION 80 if(typeof options=='number') options = {max:options}; 81 var o = $.extend({}, 82 $.fn.MultiFile.options, 83 options || {}, 84 ($.metadata? MultiFile.E.metadata(): ($.meta?MultiFile.E.data():null)) || {}, /* metadata options */ 85 {} /* internals */ 86 ); 87 // limit number of files that can be selected? 88 if(!(o.max>0) /*IsNull(MultiFile.max)*/){ 89 o.max = MultiFile.E.attr('maxlength'); 90 if(!(o.max>0) /*IsNull(MultiFile.max)*/){ 91 o.max = (String(MultiFile.e.className.match(/\b(max|limit)\-([0-9]+)\b/gi) || ['']).match(/[0-9]+/gi) || [''])[0]; 92 if(!(o.max>0)) o.max = -1; 93 else o.max = String(o.max).match(/[0-9]+/gi)[0]; 94 } 95 }; 96 o.max = new Number(o.max); 97 // limit extensions? 98 o.accept = o.accept || MultiFile.E.attr('accept') || ''; 99 if(!o.accept){ 100 o.accept = (MultiFile.e.className.match(/\b(accept\-[\w\|]+)\b/gi)) || ''; 101 o.accept = new String(o.accept).replace(/^(accept|ext)\-/i,''); 102 }; 103 104 //=== 105 106 // APPLY CONFIGURATION 107 $.extend(MultiFile, o || {}); 108 MultiFile.STRING = $.extend({},$.fn.MultiFile.options.STRING,MultiFile.STRING); 109 110 //=== 111 112 //######################################### 113 // PRIVATE PROPERTIES/METHODS 114 $.extend(MultiFile, { 115 n: 0, // How many elements are currently selected? 116 slaves: [], files: [], 117 instanceKey: MultiFile.e.id || 'MultiFile'+String(group_count), // Instance Key? 118 generateID: function(z){ return MultiFile.instanceKey + (z>0 ?'_F'+String(z):''); }, 119 trigger: function(event, element){ 120 var handler = MultiFile[event], value = $(element).attr('value'); 121 if(handler){ 122 var returnValue = handler(element, value, MultiFile); 123 if( returnValue!=null ) return returnValue; 124 } 125 return true; 126 } 127 }); 128 129 //=== 130 131 // Setup dynamic regular expression for extension validation 132 // - thanks to John-Paul Bader: http://smyck.de/2006/08/11/javascript-dynamic-regular-expresions/ 133 if(String(MultiFile.accept).length>1){ 134 MultiFile.accept = MultiFile.accept.replace(/\W+/g,'|').replace(/^\W|\W$/g,''); 135 MultiFile.rxAccept = new RegExp('\\.('+(MultiFile.accept?MultiFile.accept:'')+')$','gi'); 136 }; 137 138 //=== 139 140 // Create wrapper to hold our file list 141 MultiFile.wrapID = MultiFile.instanceKey+'_wrap'; // Wrapper ID? 142 MultiFile.E.wrap('<div class="MultiFile-wrap" id="'+MultiFile.wrapID+'"></div>'); 143 MultiFile.wrapper = $('#'+MultiFile.wrapID+''); 144 145 //=== 146 147 // MultiFile MUST have a name - default: file1[], file2[], file3[] 148 MultiFile.e.name = MultiFile.e.name || 'file'+ group_count +'[]'; 149 150 //=== 151 152 if(!MultiFile.list){ 153 // Create a wrapper for the list 154 // * OPERA BUG: NO_MODIFICATION_ALLOWED_ERR ('list' is a read-only property) 155 // this change allows us to keep the files in the order they were selected 156 MultiFile.wrapper.append( '<div class="MultiFile-list" id="'+MultiFile.wrapID+'_list"></div>' ); 157 MultiFile.list = $('#'+MultiFile.wrapID+'_list'); 158 }; 159 MultiFile.list = $(MultiFile.list); 63 160 64 //######################################### 65 // Find basic configuration in class string 66 // debug??? 67 d.debug = (d.className.indexOf('debug')>0); 68 // limit number of files that can be selected? 69 if(IsNull(d.max)){ 70 d.max = x.attr('maxlength'); 71 if(IsNull(d.max)){ 72 d.max = ((d.className.match(/\b((max|limit)\-[0-9]+)\b/gi) || [''])[0]); 73 if(IsNull(d.max)){ 74 d.max = -1; 75 }else{ 76 d.max = d.max.match(/[0-9]+/gi)[0]; 77 } 78 } 79 } 80 d.max = new Number(d.max); 81 // limit extensions? 82 if(!d.accept){ 83 d.accept = (d.className.match(/\b(accept\-[\w\|]+)\b/gi)) || ''; 84 d.accept = new String(d.accept).replace(/^(accept|ext)\-/i,''); 85 } 86 //######################################### 87 88 89 // Attach a bunch of events, jQuery style ;-) 90 $.each("on,after".split(","), function(i,o){ 91 $.each("FileSelect,FileRemove,FileAppend".split(","), function(j,event){ 92 d[o+event] = function(e, v, m){ // default functions do absolutelly nothing... 93 // if(d.debug) alert(''+o+event+'' +'\nElement:' +e.name+ '\nValue: ' +v+ '\nMaster: ' +m.name+ ''); 94 }; 95 }); 96 }); 97 // Setup a global event handler 98 d.trigger = function(event, e){ 99 var f = d[event]; 100 if(f){ 101 var v = $(this).attr('value'); 102 var r = f(e, v, d); 103 if(r!=null) return r; 104 } 105 return true; 106 }; 107 108 109 // Initialize options 110 if( typeof o == 'number' ){ o = {max:o}; }; 111 $.extend(d, d.data || {}, o); 112 113 // Default properties - INTERNAL USE ONLY 114 $.extend(d, { 115 STRING: d.STRING || {}, // used to hold string constants 116 n: 0, // How many elements are currently selected? 117 k: 'multi', // Instance Key? 118 f: function(z){ return d.k+'_'+String(i)+'_'+String(z); } 119 }); 120 121 // Visible text strings... 122 // $file = file name (with path), $ext = file extension 123 d.STRING = $.extend({ 124 remove:'remove', 125 denied:'You cannot select a $ext file.\nTry again...', 126 selected:'File selected: $file' 127 }, d.STRING); 128 129 130 // Setup dynamic regular expression for extension validation 131 // - thanks to John-Paul Bader: http://smyck.de/2006/08/11/javascript-dynamic-regular-expresions/ 132 if(String(d.accept).length>1){ 133 d.rxAccept = new RegExp('\\.('+(d.accept?d.accept:'')+')$','gi'); 134 }; 135 136 // Create wrapper to hold our file list 137 d.w = d.k+'multi'+'_'+i; // Wrapper ID? 138 x.wrap('<div id="'+d.w+'"></div>'); 139 140 // Bind a new element 141 d.add = function( e, ii ){ 142 143 // Keep track of how many elements have been displayed 144 d.n++; 145 146 // Add reference to master element 147 e.d = d; 148 149 // Define element's ID and name (upload components need this!) 150 e.i = ii;//d.I; 151 e.id = d.f(e.i); 152 e.name = (e.name || x.attr('name') || 'file') + (e.i>0?e.i:''); // same name as master element 153 154 // If we've reached maximum number, disable input e 155 if( (d.max != -1) && ((d.n-1) > (d.max)) ){ // d.n Starts at 1, so subtract 1 to find true count 156 e.disabled = true; 157 }; 158 159 // Remember most recent e 160 d.current = e; 161 162 /// now let's use jQuery 163 e = $(e); 164 165 // Triggered when a file is selected 166 e.change(function(){ 167 168 //# Trigger Event! onFileSelect 169 if(!d.trigger('onFileSelect', this, d)) return false; 170 //# End Event! 171 172 // check extension 173 if(d.accept){ 174 var v = String(e.attr('value')); 175 if(!v.match(d.rxAccept)){ 176 // Clear element value 177 e.val('').attr('value', ''); 178 e.get(0).value = ''; 161 //=== 162 163 // Bind a new element 164 MultiFile.addSlave = function( slave, slave_count ){ 165 //if(window.console) console.log('MultiFile.addSlave',slave_count); 166 167 // Keep track of how many elements have been displayed 168 MultiFile.n++; 169 // Add reference to master element 170 slave.MultiFile = MultiFile; 171 172 // BUG FIX: http://plugins.jquery.com/node/1495 173 // Clear identifying properties from clones 174 if(slave_count>0) slave.id = slave.name = ''; 175 176 // Define element's ID and name (upload components need this!) 177 //slave.id = slave.id || MultiFile.generateID(slave_count); 178 if(slave_count>0) slave.id = MultiFile.generateID(slave_count); 179 //FIX for: http://code.google.com/p/jquery-multifile-plugin/issues/detail?id=23 180 181 // 2008-Apr-29: New customizable naming convention (see url below) 182 // http://groups.google.com/group/jquery-dev/browse_frm/thread/765c73e41b34f924# 183 slave.name = String(MultiFile.namePattern 184 /*master name*/.replace(/\$name/gi,$(MultiFile.clone).attr('name')) 185 /*master id */.replace(/\$id/gi, $(MultiFile.clone).attr('id')) 186 /*group count*/.replace(/\$g/gi, group_count)//(group_count>0?group_count:'')) 187 /*slave count*/.replace(/\$i/gi, slave_count)//(slave_count>0?slave_count:'')) 188 ); 189 190 // If we've reached maximum number, disable input slave 191 if( (MultiFile.max > 0) && ((MultiFile.n-1) > (MultiFile.max)) )//{ // MultiFile.n Starts at 1, so subtract 1 to find true count 192 slave.disabled = true; 193 //}; 194 195 // Remember most recent slave 196 MultiFile.current = MultiFile.slaves[slave_count] = slave; 197 198 // We'll use jQuery from now on 199 slave = $(slave); 200 201 // Clear value 202 slave.val('').attr('value','')[0].value = ''; 203 204 // Stop plugin initializing on slaves 205 slave.addClass('MultiFile-applied'); 206 207 // Triggered when a file is selected 208 slave.change(function(){ 209 //if(window.console) console.log('MultiFile.slave.change',slave_count); 210 211 // Lose focus to stop IE7 firing onchange again 212 $(this).blur(); 213 214 //# Trigger Event! onFileSelect 215 if(!MultiFile.trigger('onFileSelect', this, MultiFile)) return false; 216 //# End Event! 217 218 //# Retrive value of selected file from element 219 var ERROR = '', v = String(this.value || ''/*.attr('value)*/); 220 221 // check extension 222 if(MultiFile.accept && v && !v.match(MultiFile.rxAccept))//{ 223 ERROR = MultiFile.STRING.denied.replace('$ext', String(v.match(/\.\w{1,4}$/gi))); 224 //} 225 //}; 226 227 // Disallow duplicates 228 for(var f in MultiFile.slaves)//{ 229 if(MultiFile.slaves[f] && MultiFile.slaves[f]!=this)//{ 230 //console.log(MultiFile.slaves[f],MultiFile.slaves[f].value); 231 if(MultiFile.slaves[f].value==v)//{ 232 ERROR = MultiFile.STRING.duplicate.replace('$file', v.match(/[^\/\\]+$/gi)); 233 //}; 234 //}; 235 //}; 236 237 // Create a new file input element 238 var newEle = $(MultiFile.clone).clone();// Copy parent attributes - Thanks to Jonas Wagner 239 //# Let's remember which input we've generated so 240 // we can disable the empty ones before submission 241 // See: http://plugins.jquery.com/node/1495 242 newEle.addClass('MultiFile'); 243 244 // Handle error 245 if(ERROR!=''){ 246 // Handle error 247 MultiFile.error(ERROR); 179 248 180 // OPERA BUG FIX - 2007-06-24 181 // Thanks to Adrian Wróbel <adrian [dot] wrobel [at] gmail.com> 182 // we add new input element and remove present one for browsers that can't clear value of input element 183 var f = $('<input name="'+(x.attr('name') || '')+'" type="file"/>'); 184 d.n--; 185 d.add(f.get(0), this.i); 186 e.parent().prepend(f); 187 e.remove(); 188 189 // Show error message 190 // TO-DO: Some people have suggested alternative methods for displaying this message 191 // such as inline HTML, lightbox, etc... maybe integrate with blockUI plugin? 192 alert(d.STRING.denied.replace('$ext', String(v.match(/\.\w{1,4}$/gi)))); 193 194 return false; 195 } 196 }; 197 198 // Hide this element: display:none is evil! 199 //this.style.display = 'block'; 200 this.style.position = 'absolute'; 201 this.style.left = '-1000px'; 202 203 // Create a new file input element 204 var f = $('<input name="'+(x.attr('name') || '')+'" type="file"/>'); 205 206 // Add it to the form 207 $(this).parent().prepend(f); 208 209 // Update list 210 d.list( this ); 211 212 // Bind functionality 213 d.add( f.get(0), this.i+1 ); 214 215 //# Trigger Event! afterFileSelect 216 if(!d.trigger('afterFileSelect', this, d)) return false; 217 //# End Event! 218 219 }); 220 221 }; 222 // Bind a new element 223 224 // Add a new file to the list 225 d.list = function( y ){ 226 227 //# Trigger Event! onFileAppend 228 if(!d.trigger('onFileAppend', y, d)) return false; 229 //# End Event! 230 231 // Insert HTML 232 var 233 t = $('#'+d.w), 234 r = $('<div></div>'), 235 v = $(y).attr('value')+'', 236 a = $('<span class="file" title="'+d.STRING.selected.replace('$file', v)+'">'+v.match(/[^\/\\]+$/gi)[0]+'</span>'), 237 b = $('<a href="#'+d.w+'">'+d.STRING.remove+'</a>'); 238 t.append(r); 239 r.append('[',b,'] ',a);//.prepend(y.i+': '); 240 b.click(function(){ 241 242 //# Trigger Event! onFileRemove 243 if(!d.trigger('onFileRemove', y, d)) return false; 244 //# End Event! 245 246 d.n--; 247 d.current.disabled = false; 248 $('#'+d.f(y.i)).remove(); 249 // 2007-06-24: BUG FIX - Thanks to Adrian Wróbel <adrian [dot] wrobel [at] gmail.com> 250 // Ditch the trouble maker and add a fresh new element 251 MultiFile.n--; 252 MultiFile.addSlave(newEle[0], slave_count); 253 slave.parent().prepend(newEle); 254 slave.remove(); 255 return false; 256 }; 257 258 // Hide this element (NB: display:none is evil!) 259 $(this).css({ position:'absolute', top: '-3000px' }); 260 261 // Add new element to the form 262 slave.after(newEle); 263 264 // Update list 265 MultiFile.addToList( this, slave_count ); 266 267 // Bind functionality 268 MultiFile.addSlave( newEle[0], slave_count+1 ); 269 270 //# Trigger Event! afterFileSelect 271 if(!MultiFile.trigger('afterFileSelect', this, MultiFile)) return false; 272 //# End Event! 273 274 }); // slave.change() 275 276 // Save control to element 277 $(slave).data('MultiFile', MultiFile); 278 279 };// MultiFile.addSlave 280 // Bind a new element 281 282 283 284 // Add a new file to the list 285 MultiFile.addToList = function( slave, slave_count ){ 286 //if(window.console) console.log('MultiFile.addToList',slave_count); 287 288 //# Trigger Event! onFileAppend 289 if(!MultiFile.trigger('onFileAppend', slave, MultiFile)) return false; 290 //# End Event! 291 292 // Create label elements 293 var 294 r = $('<div class="MultiFile-label"></div>'), 295 v = String(slave.value || ''/*.attr('value)*/), 296 a = $('<span class="MultiFile-title" title="'+MultiFile.STRING.selected.replace('$file', v)+'">'+MultiFile.STRING.file.replace('$file', v.match(/[^\/\\]+$/gi)[0])+'</span>'), 297 b = $('<a class="MultiFile-remove" href="#'+MultiFile.wrapID+'">'+MultiFile.STRING.remove+'</a>'); 298 299 // Insert label 300 MultiFile.list.append( 301 r.append(b, ' ', a) 302 ); 303 304 b 305 .click(function(){ 306 307 //# Trigger Event! onFileRemove 308 if(!MultiFile.trigger('onFileRemove', slave, MultiFile)) return false; 309 //# End Event! 310 311 MultiFile.n--; 312 MultiFile.current.disabled = false; 313 314 // Remove element, remove label, point to current 315 MultiFile.slaves[slave_count] = null; 316 $(slave).remove(); 249 317 $(this).parent().remove(); 250 318 251 //# Trigger Event! afterFileRemove 252 if(!d.trigger('afterFileRemove', y, d)) return false; 253 //# End Event! 319 // Show most current element again (move into view) and clear selection 320 $(MultiFile.current).css({ position:'', top: '' }); 321 $(MultiFile.current).reset().val('').attr('value', '')[0].value = ''; 322 323 //# Trigger Event! afterFileRemove 324 if(!MultiFile.trigger('afterFileRemove', slave, MultiFile)) return false; 325 //# End Event! 254 326 255 return false; 256 }); 257 258 //# Trigger Event! afterFileAppend 259 if(!d.trigger('afterFileAppend', y, d)) return false; 260 //# End Event! 261 262 }; 327 return false; 328 }); 329 330 //# Trigger Event! afterFileAppend 331 if(!MultiFile.trigger('afterFileAppend', slave, MultiFile)) return false; 332 //# End Event! 333 334 }; // MultiFile.addToList 335 // Add element to selected files list 336 337 338 339 // Bind functionality to the first element 340 if(!MultiFile.MultiFile) MultiFile.addSlave(MultiFile.e, 0); 341 342 // Increment control count 343 //MultiFile.I++; // using window.MultiFile 344 MultiFile.n++; 263 345 264 // Bind first file element 265 if(!d.ft){ d.add(d, 0); d.ft = true; } 266 d.I++; 267 d.n++; 346 // Save control to element 347 MultiFile.E.data('MultiFile', MultiFile); 268 348 349 350 //##################################################################### 351 // MAIN PLUGIN FUNCTIONALITY - END 352 //##################################################################### 353 }); // each element 354 }; 355 356 /*--------------------------------------------------------*/ 357 358 /* 359 ### Core functionality and API ### 360 */ 361 $.extend($.fn.MultiFile, { 362 /** 363 * This method removes all selected files 364 * 365 * Returns a jQuery collection of all affected elements. 366 * 367 * @name reset 368 * @type jQuery 369 * @cat Plugins/MultiFile 370 * @author Diego A. (http://www.fyneworks.com/) 371 * 372 * @example $.fn.MultiFile.reset(); 373 */ 374 reset: function(){ 375 var settings = $(this).data('MultiFile'); 376 //if(settings) settings.wrapper.find('a.MultiFile-remove').click(); 377 if(settings) settings.list.find('a.MultiFile-remove').click(); 378 return $(this); 379 }, 380 381 382 /** 383 * This utility makes it easy to disable all 'empty' file elements in the document before submitting a form. 384 * It marks the affected elements so they can be easily re-enabled after the form submission or validation. 385 * 386 * Returns a jQuery collection of all affected elements. 387 * 388 * @name disableEmpty 389 * @type jQuery 390 * @cat Plugins/MultiFile 391 * @author Diego A. (http://www.fyneworks.com/) 392 * 393 * @example $.fn.MultiFile.disableEmpty(); 394 * @param String class (optional) A string specifying a class to be applied to all affected elements - Default: 'mfD'. 395 */ 396 disableEmpty: function(klass){ klass = (typeof(klass)=='string'?klass:'')||'mfD'; 397 var o = []; 398 $('input:file.MultiFile').each(function(){ if($(this).val()=='') o[o.length] = this; }); 399 return $(o).each(function(){ this.disabled = true }).addClass(klass); 400 }, 401 402 403 /** 404 * This method re-enables 'empty' file elements that were disabled (and marked) with the $.fn.MultiFile.disableEmpty method. 405 * 406 * Returns a jQuery collection of all affected elements. 407 * 408 * @name reEnableEmpty 409 * @type jQuery 410 * @cat Plugins/MultiFile 411 * @author Diego A. (http://www.fyneworks.com/) 412 * 413 * @example $.fn.MultiFile.reEnableEmpty(); 414 * @param String klass (optional) A string specifying the class that was used to mark affected elements - Default: 'mfD'. 415 */ 416 reEnableEmpty: function(klass){ klass = (typeof(klass)=='string'?klass:'')||'mfD'; 417 return $('input:file.'+klass).removeClass(klass).each(function(){ this.disabled = false }); 418 }, 419 420 421 /** 422 * This method will intercept other jQuery plugins and disable empty file input elements prior to form submission 423 * 424 425 * @name intercept 426 * @cat Plugins/MultiFile 427 * @author Diego A. (http://www.fyneworks.com/) 428 * 429 * @example $.fn.MultiFile.intercept(); 430 * @param Array methods (optional) Array of method names to be intercepted 431 */ 432 intercepted: {}, 433 intercept: function(methods, context, args){ 434 var method, value; args = args || []; 435 if(args.constructor.toString().indexOf("Array")<0) args = [ args ]; 436 if(typeof(methods)=='function'){ 437 $.fn.MultiFile.disableEmpty(); 438 value = methods.apply(context || window, args); 439 //SEE-http://code.google.com/p/jquery-multifile-plugin/issues/detail?id=27 440 setTimeout(function(){ $.fn.MultiFile.reEnableEmpty() },1000); 441 return value; 442 }; 443 if(methods.constructor.toString().indexOf("Array")<0) methods = [methods]; 444 for(var i=0;i<methods.length;i++){ 445 method = methods[i]+''; // make sure that we have a STRING 446 if(method) (function(method){ // make sure that method is ISOLATED for the interception 447 $.fn.MultiFile.intercepted[method] = $.fn[method] || function(){}; 448 $.fn[method] = function(){ 449 $.fn.MultiFile.disableEmpty(); 450 value = $.fn.MultiFile.intercepted[method].apply(this, arguments); 451 //SEE-http://code.google.com/p/jquery-multifile-plugin/issues/detail?id=27 452 setTimeout(function(){ $.fn.MultiFile.reEnableEmpty() },1000); 453 return value; 454 }; // interception 455 })(method); // MAKE SURE THAT method IS ISOLATED for the interception 456 };// for each method 457 } // $.fn.MultiFile.intercept 458 459 }); 460 461 /*--------------------------------------------------------*/ 462 463 /* 464 ### Default Settings ### 465 eg.: You can override default control like this: 466 $.fn.MultiFile.options.accept = 'gif|jpg'; 467 */ 468 $.fn.MultiFile.options = { //$.extend($.fn.MultiFile, { options: { 469 accept: '', // accepted file extensions 470 max: -1, // maximum number of selectable files 471 472 // name to use for newly created elements 473 namePattern: '$name', // same name by default (which creates an array) 474 475 // STRING: collection lets you show messages in different languages 476 STRING: { 477 remove:'x', 478 denied:'You cannot select a $ext file.\nTry again...', 479 file:'$file', 480 selected:'File selected: $file', 481 duplicate:'This file has already been selected:\n$file' 482 }, 483 484 // name of methods that should be automcatically intercepted so the plugin can disable 485 // extra file elements that are empty before execution and automatically re-enable them afterwards 486 autoIntercept: [ 'submit', 'ajaxSubmit', 'ajaxForm', 'validate', 'valid' /* array of methods to intercept */ ], 487 488 // error handling function 489 error: function(s){ 490 /* 491 ERROR! blockUI is not currently working in IE 492 if($.blockUI){ 493 $.blockUI({ 494 message: s.replace(/\n/gi,'<br/>'), 495 css: { 496 border:'none', padding:'15px', size:'12.0pt', 497 backgroundColor:'#900', color:'#fff', 498 opacity:'.8','-webkit-border-radius': '10px','-moz-border-radius': '10px' 499 } 269 500 }); 270 // each element 271 501 window.setTimeout($.unblockUI, 2000); 272 502 } 273 // MultiFile function 274 275 }); 276 // extend jQuery function library 277 278 279 280 /* 281 ### Default implementation ### 282 The plugin will attach itself to file inputs 283 with the class 'multi' when the page loads 284 285 Use the jQuery start plugin to 286 */ 287 if($.start){ $.start($.MultiFile) } 288 else $(function(){ $.MultiFile() }); 289 290 291 503 else//{// save a byte! 504 */ 505 alert(s); 506 //}// save a byte! 507 } 508 }; //} }); 509 510 /*--------------------------------------------------------*/ 511 512 /* 513 ### Additional Methods ### 514 Required functionality outside the plugin's scope 515 */ 516 517 // Native input reset method - because this alone doesn't always work: $(element).val('').attr('value', '')[0].value = ''; 518 $.fn.reset = function(){ return this.each(function(){ try{ this.reset(); }catch(e){} }); }; 519 520 /*--------------------------------------------------------*/ 521 522 /* 523 ### Default implementation ### 524 The plugin will attach itself to file inputs 525 with the class 'multi' when the page loads 526 */ 527 $(function(){ 528 //$("input:file.multi").MultiFile(); 529 $("input[type=file].multi").MultiFile(); 530 }); 531 532 533 292 534 /*# AVOID COLLISIONS #*/ 293 535 })(jQuery); -
_plugins_/formulaire_upload/javascript/jquery.upload_attach.js
r16909 r49010 37 37 // si multifile est la, on l'utilise (trop bien) 38 38 if ($.fn.MultiFile) 39 $('form input[ @type=file]',self).MultiFile({39 $('form input[type=file]',self).MultiFile({ 40 40 max: 5, 41 41 STRING: {'remove': 'x', 'selected': '$file'} -
_plugins_/formulaire_upload/lang/formupload_fr.php
r32289 r49010 11 11 'cfg_inf_files_number' => 'L\'utilisateur ne pourra uploader que ce nombre de fichiers au maximum', 12 12 'cfg_titre_formupload' => 'Formulaire upload', 13 'choosefiles' => 'Choisir les fichiers àajouter :',13 'choosefiles' => 'Choisir les fichiers à ajouter :', 14 14 'nodocs' => 'Pas encore de document sur la zone de téléchargement', 15 15 'insert_code' => 'Code à insérer dans la zone de texte :', -
_plugins_/formulaire_upload/plugin.xml
r40264 r49010 10 10 </auteur> 11 11 <version> 12 0.3 12 0.3.1 13 13 </version> 14 14 <etat>
Note: See TracChangeset
for help on using the changeset viewer.