javascript - How can I detect a click and hold in Coffeescript and then return instead of running what's next? -



javascript - How can I detect a click and hold in Coffeescript and then return instead of running what's next? -

i have simple tasks app has tasks can check off. in html, each task li, , checkbox within label this:

<li class="task"> <label class="left"><input type="checkbox" id="task6">a sample task</label> <span class="right drag-handle"></span> <span class="priority right" type="priority" priority="minor">minor</span> </li>

when click on label, checkbox triggered. desirable since makes checkbox target area much larger, since can drag , drop tasks, don't want them checked off when user clicks , holds on label.

this function marks task done:

$(document).on 'click', '#task-list li label input', (e) -> li = $(this).closest('li') li.slidetoggle -> task.markdone(views.getid(li))

i'd add together code @ start of function says "don't execute next code if user has clicked , holding longer 500ms" indicate they're dragging task.

i found few other stackoverflow answers like one detecting click , hold can't figure out how implement in coffeescript.

i managed working.

i needed alter function utilize $(document).on 'mousedown'. ended looking this, little code handle checkbox beingness checked or unchecked:

# we'll manage checking checkbox give thanks much $(document).on 'click', '.task > label', (e) -> e.preventdefault() # clicking on checkbox or label mark task completed $(document).on 'mousedown', '.task > label', -> holding = false # if haven't released mouse after 250 milliseconds, # they're dragging , don't want (un)check settimeout (-> holding = true ), 250 $(this).one 'mouseup', -> checkbox = undefined unless holding # they're not dragging, check checkbox checkbox = $('input', this) checkbox.prop 'checked', not checkbox.prop('checked') # task li li = $(this).closest('li') # slide , hide # utilize views.getid(li) task id # pass task.markdone() checked off li.slidetoggle -> task.markdone(views.getid(li))

javascript jquery coffeescript

Comments

Popular posts from this blog

c# - ASP.NET MVC Sequence contains no matching element -

java - Parsing XML, skip certain tags -

rest - How to invalidate user session on inactivity in a stateless server? -