Skip to content

Commit

Permalink
Fix on Pull & Refresh
Browse files Browse the repository at this point in the history
Bind / Unbind to preventDefault (scrolls fix)
  • Loading branch information
pinaypunto committed May 3, 2013
1 parent 6ec20d8 commit e83131e
Showing 1 changed file with 9 additions and 1 deletion.
10 changes: 9 additions & 1 deletion src/element/Lungo.Element.Pull.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -87,22 +87,30 @@ Lungo.Element.Pull = (element_selector, config_data) ->
else
hide()

_bindPreventDefault = (event) -> ELEMENT[0].addEventListener "touchmove", _prevent
_unbindPreventDefault = (event) -> ELEMENT[0].removeEventListener "touchmove", _prevent
_prevent = (event) -> do event.preventDefault

(->
STARTED = false
BINDED_TO_PREVENT = false
INI_Y = {}
ELEMENT.bind("touchstart", (event) ->
if ELEMENT[0].scrollTop <= 1
STARTED = true
INI_Y = (if $$.isMobile() then event.touches[0].pageY else event.pageY)
).bind("touchmove", (event) ->
if not REFRESHING and STARTED
do event.preventDefault
current_y = (if $$.isMobile() then event.touches[0].pageY else event.pageY)
CURRENT_DISTANCE = current_y - INI_Y
if CURRENT_DISTANCE >= 0
ELEMENT.style "overflow-y", "hidden"
_bindPreventDefault(event) unless BINDED_TO_PREVENT
BINDED_TO_PREVENT = true
_handlePulling()
).bind "touchend", ->
_unbindPreventDefault(event) if BINDED_TO_PREVENT
BINDED_TO_PREVENT = false
if STARTED
ELEMENT.style "overflow-y", "scroll"
_handlePullEnd()
Expand Down

0 comments on commit e83131e

Please sign in to comment.