SHARE
TWEET

photo

a guest Jul 20th, 2019 98 in 94 days
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. # Этот кусок отрабатывает при нажатии на input с классом
  2.   $(document).on 'click', '.work-orders__photo-attachment-upload', ->
  3.     $uploadFile = $(this)
  4.     return if !@files?.length or !window.FileReader
  5.  
  6.     # Add file name
  7.     $uploadFile.closest('.nested-fields').find('.work-orders__photo-title-truncated').text('file name: ' + @files[0].name);
  8.  
  9.     if /^image/.test(@files[0].type)
  10.       reader = new FileReader
  11.       reader.readAsDataURL @files[0]
  12.  
  13.       # Set an image as background in div block.
  14.       reader.onloadend = ->
  15.         $uploadFile.closest('.nested-fields').find('.work-orders__photo-attachment-preview').css 'background-image', 'url(' + @result + ')'
  16.     else
  17.       # Remove an image if file isn't an image.
  18.       $uploadFile.closest('.nested-fields').find('.work-orders__photo-attachment-preview').css 'background-image', 'none'
  19.  
  20. # Этот кусок отрабатывает во время after+insert события для вложенного элемента
  21.   $(document).on 'cocoon:after-insert', (e, addedPhoto) ->
  22.     rest = $(this)
  23.     addedPhoto.closest('.nested-fields').find('.work-orders__photo-attachment-upload').trigger('click')
  24.     #test = $('p.work-orders__photo-attachment-upload').text()
  25.     test = $('.index-photo').closest('.nested-fields').find('p.work-orders__photo-title-truncated')
  26.     console.log(addedPhoto.find('p')[0])
  27.     console.log(e.target)
  28.     #test = $('.index-photo').closest('.nested-fields').find('p.work-orders__photo-title-truncated').text()
  29.     #console.log $('p.work-orders__photo-title-truncated').text()
  30.     #test = $('.index-photo' > 'p.work-orders__photo-title-truncated')
  31.     #console.log(test.text())
  32.     #console.log(addedPhoto.find(".work-orders__photo-attachment-upload").text())
  33.     #if addedPhoto[0].innerText.includes('No file selected')
  34.     #  addedPhoto.closest('.nested-fields').remove()
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top