[ Index ] |
|
Code source de Drupal 5.3 |
1 // $Id: upload.js,v 1.11 2006/08/31 23:31:25 unconed Exp $ 2 3 /** 4 * Attaches the upload behaviour to the upload form. 5 */ 6 Drupal.uploadAutoAttach = function() { 7 $('input.upload').each(function () { 8 var uri = this.value; 9 // Extract the base name from the id (edit-attach-url -> attach). 10 var base = this.id.substring(5, this.id.length - 4); 11 var button = base + '-button'; 12 var wrapper = base + '-wrapper'; 13 var hide = base + '-hide'; 14 var upload = new Drupal.jsUpload(uri, button, wrapper, hide); 15 }); 16 } 17 18 /** 19 * JS upload object. 20 */ 21 Drupal.jsUpload = function(uri, button, wrapper, hide) { 22 // Note: these elements are replaced after an upload, so we re-select them 23 // everytime they are needed. 24 this.button = '#'+ button; 25 this.wrapper = '#'+ wrapper; 26 this.hide = '#'+ hide; 27 Drupal.redirectFormButton(uri, $(this.button).get(0), this); 28 } 29 30 /** 31 * Handler for the form redirection submission. 32 */ 33 Drupal.jsUpload.prototype.onsubmit = function () { 34 // Insert progressbar and stretch to take the same space. 35 this.progress = new Drupal.progressBar('uploadprogress'); 36 this.progress.setProgress(-1, 'Uploading file'); 37 38 var hide = this.hide; 39 var el = this.progress.element; 40 var offset = $(hide).get(0).offsetHeight; 41 $(el).css({ 42 width: '28em', 43 height: offset +'px', 44 paddingTop: '10px', 45 display: 'none' 46 }); 47 $(hide).css('position', 'absolute'); 48 49 $(hide).after(el); 50 $(el).fadeIn('slow'); 51 $(hide).fadeOut('slow'); 52 } 53 54 /** 55 * Handler for the form redirection completion. 56 */ 57 Drupal.jsUpload.prototype.oncomplete = function (data) { 58 // Remove old form 59 Drupal.freezeHeight(); // Avoid unnecessary scrolling 60 $(this.wrapper).html(''); 61 62 // Place HTML into temporary div 63 var div = document.createElement('div'); 64 $(div).html(data); 65 66 // If uploading the first attachment fade in everything 67 if ($('tr', div).size() == 2) { 68 // Replace form and re-attach behaviour 69 $(div).hide(); 70 $(this.wrapper).append(div); 71 $(div).fadeIn('slow'); 72 Drupal.uploadAutoAttach(); 73 } 74 // Else fade in only the last table row 75 else { 76 // Hide form and last table row 77 $('table tr:last-of-type td', div).hide(); 78 79 // Note: workaround because jQuery's #id selector does not work outside of 'document' 80 // Should be: $(this.hide, div).hide(); 81 var hide = this.hide; 82 $('div', div).each(function() { 83 if (('#'+ this.id) == hide) { 84 this.style.display = 'none'; 85 } 86 }); 87 88 // Replace form, fade in items and re-attach behaviour 89 $(this.wrapper).append(div); 90 $('table tr:last-of-type td', div).fadeIn('slow'); 91 $(this.hide, div).fadeIn('slow'); 92 Drupal.uploadAutoAttach(); 93 } 94 Drupal.unfreezeHeight(); 95 } 96 97 /** 98 * Handler for the form redirection error. 99 */ 100 Drupal.jsUpload.prototype.onerror = function (error) { 101 alert('An error occurred:\n\n'+ error); 102 // Remove progressbar 103 $(this.progress.element).remove(); 104 this.progress = null; 105 // Undo hide 106 $(this.hide).css({ 107 position: 'static', 108 left: '0px' 109 }); 110 } 111 112 113 // Global killswitch 114 if (Drupal.jsEnabled) { 115 $(document).ready(Drupal.uploadAutoAttach); 116 }
titre
Description
Corps
titre
Description
Corps
titre
Description
Corps
titre
Corps
Généré le : Fri Nov 30 16:20:15 2007 | par Balluche grâce à PHPXref 0.7 |
![]() |