Глядя на код плагина , кажется, что он вызывает ваш обратный вызов рендеринга для событий onload
и onerror
объекта изображения.Возможно, Firefox ошибочно считает масштабирование изображения как событие загрузки или что-то в этом роде?Или, возможно, событие ошибки вызывается без веской причины.
В любом случае, быстрое исправление может выглядеть примерно так:
# Builds a function to show the loaded image
# The function stores the last img object it received,
# and doesn't try to show the same one twice in a row
createRenderCallback = ->
lastImg = null
(img) ->
return if img is lastImg # don't handle the same img twice
# Note that if the image failed to load, `img` will be undefined
# You may want to check for that before trying to append it
$('#display_pic_preview > img').remove()
$('#display_pic_preview').append(img)
lastImg = img # remember the img
# Attach the file input's change handler (pretty much the same as before)
$('#project_display_pic').change (e) ->
value = $(this).val().replace("C:\\fakepath\\","")
$('#display_pic_uploader > p').text(value)
loadImage e.target.files[0], createRenderCallback(), { maxWidth: 212 }
Вы можете сделать что-то подобное в коде плагина, чтобыизбежать повторного вызова обратного вызова.Или вы можете записать некоторые вещи из плагина, чтобы точно увидеть, что происходит.
Редактировать: Поскольку вставка изображения в DOM вызывает запуск обратного вызова рендеринга, вы можете попробоватьэто:
createRenderCallback = ->
lastImg = null
(img) ->
return if img is lastImg
lastImg = img # <-- Move this line to here, i.e. before inserting the image
$('#display_pic_preview > img').remove()
$('#display_pic_preview').append(img)
или , вы можете просто удалить прослушиватели событий вместо того, чтобы вести запись lastImg
renderCallback = ->
if img? # this function was called from an onload event
img.onload = img.onerror = null
else # called from an onerror event
@onload = @onerror = null
$('#display_pic_preview > img').remove()
$('#display_pic_preview').append(img) if img?
$('#project_display_pic').change (e) ->
value = $(this).val().replace("C:\\fakepath\\","")
$('#display_pic_uploader > p').text(value)
loadImage e.target.files[0], renderCallback, { maxWidth: 212 }