Javascript JQuery文件上载客户端图像大小调整coffeescript

Javascript JQuery文件上载客户端图像大小调整coffeescript,javascript,ruby-on-rails,coffeescript,jquery-file-upload,Javascript,Ruby On Rails,Coffeescript,Jquery File Upload,我想使用以下方法实现客户端图像大小调整: 不过,我想在coffeescript中实现它,以便与我在railscast中找到的一些文件上载代码一起使用: 我不知道如何将disableImageResize示例与coffeescript结合起来。这就是我所拥有的,但不起作用(我可以运行该应用程序,但它似乎没有进行任何大小调整): jQuery-> $(“#新建#图像”)。文件上载 数据类型:“脚本” disableImageResize:/Android(?。*Chrome)| Opera/ .

我想使用以下方法实现客户端图像大小调整:

不过,我想在coffeescript中实现它,以便与我在railscast中找到的一些文件上载代码一起使用:

我不知道如何将disableImageResize示例与coffeescript结合起来。这就是我所拥有的,但不起作用(我可以运行该应用程序,但它似乎没有进行任何大小调整):

jQuery->
$(“#新建#图像”)。文件上载
数据类型:“脚本”
disableImageResize:/Android(?。*Chrome)| Opera/
.test(window.navigator&&navigator.userAgent),
imageMaxWidth:667,
图像最大高度:667
加:(e,数据)->
类型=/(\.\/)(gif | jpe?g | png)$/i
文件=数据。文件[0]
if types.test(file.type)| types.test(file.name)
$(“#图像”)。追加(“”);
$('.placeholder').hide();
data.context=$(tmpl(“模板上传”,文件))
$('#imageUploadProgress').append(data.context)
数据提交()
其他的
警报(#{file.name}不是gif、jpeg或png图像文件)
进展:(e,数据)->
if data.context
进度=parseInt(data.loaded/data.total*100,10)
data.context.find('.bar').css('width',progress+'%'))
如果进度==100
$('.placeholder').show();
#滚动至“拇指库”底部,以显示最近上载的图像
document.getElementById(“图像”).scrollTop=document.getElementById(“图像”).scrollHeight
有人能告诉我我做错了什么吗?我发现了关于同一主题的其他问题,但都没有答案:


简单的方法是删除add回调。否则,您将负责手动触发调整大小,我还没有找到该如何做

这样做的诀窍-将很好地保持添加回调然而
jQuery ->
  $('#new_image').fileupload
    dataType: "script"     
    disableImageResize: /Android(?!.*Chrome)|Opera/
                .test(window.navigator && navigator.userAgent),
            imageMaxWidth: 667,
            imageMaxHeight: 667
    add: (e, data) ->
      types = /(\.|\/)(gif|jpe?g|png)$/i
      file = data.files[0]
      if types.test(file.type) || types.test(file.name)
        $('#images').append('<div class="placeholder"></div>');
        $('.placeholder').hide();
        data.context = $(tmpl("template-upload", file))
        $('#imageUploadProgress').append(data.context)
        data.submit()       
      else
        alert("#{file.name} is not a gif, jpeg, or png image file")
    progress: (e, data) ->
      if data.context
        progress = parseInt(data.loaded / data.total * 100, 10)
        data.context.find('.bar').css('width', progress + '%')
        if progress == 100
           $('.placeholder').show();
           # scroll to the bottom of the thumbGallery to show recently uploaded image
           document.getElementById("images").scrollTop = document.getElementById("images").scrollHeight