Skip to content

Instantly share code, notes, and snippets.

@jenya239
Created April 14, 2017 14:23
Show Gist options
  • Save jenya239/51fafff2639d64402d1559c0ff52f541 to your computer and use it in GitHub Desktop.
Save jenya239/51fafff2639d64402d1559c0ff52f541 to your computer and use it in GitHub Desktop.
delete with confirmation
del = @_element.find 'button#delete'
del2 = @_element.find 'button#delete_confirmation'
del2.hide()
delay1 = null
delay2 = null
effect = [ 'slide', direction: 'left', 500 ]
hide_del2 = -> del2.hide.apply del2, effect
delay_args = [ hide_del2, 4000 ]
del.on 'click mouseenter', ( event ) =>
del2.css
position: 'absolute'
left: del.outerWidth() + 20
top: 0;
del2.toggle.apply del2, effect
delay1 = setTimeout.apply window, delay_args
del2.on 'mouseenter', ( event ) =>
clearTimeout delay1
clearTimeout delay2
del2.on 'mouseout', ( event ) =>
delay2 = setTimeout.apply window, delay_args
del2.on 'click', =>
hide_del2()
url = "/items/#{ @_item.field 'id' }"
await $.ajax
type: 'DELETE'
url: url
cache: false
complete: defer jqXHR, textStatus
return alert textStatus unless textStatus == 'success'
$( 'button#prev_item' ).click()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment