2012-05-17 14 views
5

Estoy tratando de configurar el indicador autoUpload en jQuery File Upload. así que trato de edición jquery.fileupload.js de esta manera:Cómo configurar la opción autoUpload en Jquery File Upload

(function (factory) { 
    'use strict'; 
    if (typeof define === 'function' && define.amd) { 
     // Register as an anonymous AMD module: 
     define([ 
      'jquery', 
      'jquery.ui.widget' 
     ], factory); 
    } else { 
     // Browser globals: 
     factory(window.jQuery); 
    } 
}(function ($) { 
    'use strict'; 

    // The FileReader API is not actually used, but works as feature detection, 
    // as e.g. Safari supports XHR file uploads via the FormData API, 
    // but not non-multipart XHR file uploads: 
    $.support.xhrFileUpload = !!(window.XMLHttpRequestUpload && window.FileReader); 
    $.support.xhrFormDataFileUpload = !!window.FormData; 

    // The fileupload widget listens for change events on file input fields defined 
    // via fileInput setting and paste or drop events of the given dropZone. 
    // In addition to the default jQuery Widget methods, the fileupload widget 
    // exposes the "add" and "send" methods, to add or directly send files using 
    // the fileupload API. 
    // By default, files added via file input selection, paste, drag & drop or 
    // "add" method are uploaded immediately, but it is possible to override 
    // the "add" callback option to queue file uploads. 
    $.widget('blueimp.fileupload', { 

     options: { 
      // The namespace used for event handler binding on the dropZone and 
      // fileInput collections.   
      // If not set, the name of the widget ("fileupload") is used. 
      namespace: undefined, 
      autoUpload:true, 
      . 
      . 
      . 

y main.js de esta manera:

$(function() { 
    'use strict'; 

    // Initialize the jQuery File Upload widget: 
    $('#fileupload').fileupload(); 

    // Enable iframe cross-domain access via redirect option: 
    $('#fileupload').fileupload(
     'option', 
     'redirect', 
     window.location.href.replace(
      /\/[^\/]*$/, 
      '/cors/result.html?%s' 
     ) 
    ); 

    if (window.location.hostname === 'blueimp.github.com') { 
     // Demo settings: 
     $('#fileupload').fileupload('option', { 
      url: '//jquery-file-upload.appspot.com/', 
      maxFileSize: 5000000, 
      autoUpload:true, 
      . 
      . 
      . 

puedo ver a través de este

<td class="start">{% if (!o.options.autoUpload) { %} 
    <button class="btn btn-primary"> 
     <i class="icon-upload icon-white"></i> 
     <span>{%=locale.fileupload.start%}</span> 
    </button> 
{% } %}</td> 

que se inicia aparece el botón, por lo que o. options.autoUpload es false, pero lo configuré en true. ¿Qué puedo hacer? ¿De qué manera puedo configurar la carga automática para cargar imágenes directamente cuando se selecciona? gracias !!!!

Respuesta

13

Solucioné tomando el ejemplo originales descargado desde el sitio plugin y puedo cambiar la bandera autoUpload:true y funciona :)

+2

Gracias Jack. Tu respuesta realmente me ayudó. Simplemente agregué $ ('# fileupload'). Fileupload ('option', {autoUpload: true \t}); a main.js y funcionó. Tenga cuidado de no ponerlo dentro del bloque if (window.location.hostname === 'blueimp.github.com'). – clone45

+0

Esto no funcionará para mí en absoluto. La opción autoUpload solo aparece en 'jquery.fileupload-ui.js', por lo que la cambié a' true' sin éxito. También probé el método de clone45 y tampoco funcionó. ¿Algunas ideas? – vertigoelectric

+1

Encontré mi propia solución. En la página donde quitas las cargas, agregué un 'setInterval' que comprueba cada medio segundo para ver si existe un botón 'Inicio' y hace clic en él. Hasta ahora parece funcionar bien. – vertigoelectric

Cuestiones relacionadas