Permalink
Browse files

Added Tishos scroll/drag fix for mobile

  • Loading branch information...
koenbok committed Jun 19, 2014
1 parent 9a0f05e commit e3e38a1fa94e3208165bf3fc2ad5f20af0cdaed3
Showing with 64 additions and 7 deletions.
  1. +5 −0 framer/Config.coffee
  2. +2 −0 framer/Extras/Extras.coffee
  3. +45 −0 framer/Extras/MobileScrollFix.coffee
  4. +4 −1 framer/Framer.coffee
  5. +8 −6 framer/Layer.coffee
@@ -7,6 +7,11 @@ exports.Config =
rootBaseCSS:
"-webkit-perspective": 1000
"position": "absolute"
"left": 0
"top": 0
"right": 0
"bottom": 0
layerBaseCSS:
"display": "block"
@@ -0,0 +1,2 @@
# exports.Hints = require "./Hints"
exports.MobileScrollFix = require "./MobileScrollFix"
@@ -0,0 +1,45 @@
Utils = require "../Utils"
exports.enable = ->
handleScrollingLayerTouchMove = (event) ->
event.stopPropagation()
handleScrollingLayerTouchStart = (event) ->
element = @_element
startTopScroll = element.scrollTop
if startTopScroll <= 0
element.scrollTop = 1
if startTopScroll + element.offsetHeight >= element.scrollHeight
element.scrollTop = element.scrollHeight - element.offsetHeight - 1
class MobileScrollFixLayer extends Framer.Layer
constructor: (options) ->
super options
@on "change:scrollVertical", @_updateScrollListeners
_updateScrollListeners: =>
if @scrollVertical is true
@on "touchmove", handleScrollingLayerTouchMove
@on "touchstart", handleScrollingLayerTouchStart
else
@off "touchmove", handleScrollingLayerTouchMove
@off "touchstart", handleScrollingLayerTouchStart
__createRootElement: =>

This comment has been minimized.

@tisho

tisho Jun 19, 2014

Contributor

This probably doesn't need to be a bound function, so you can replace the => with ->.

element = super
element.addEventListener "touchmove", (event) ->
event.preventDefault()
return element
# Override the standard window Layer with this patched one
window.Layer = window.Framer.Layer = MobileScrollFixLayer
@@ -16,7 +16,6 @@ Framer.print = (require "./Print").print
_.extend window, Framer if window
# Framer level modules
Framer.Config = (require "./Config").Config
Framer.EventEmitter = (require "./EventEmitter").EventEmitter
Framer.BaseClass = (require "./BaseClass").BaseClass
@@ -29,12 +28,16 @@ Framer.SpringRK4Animator = (require "./Animators/SpringRK4Animator").SpringRK4An
Framer.Importer = (require "./Importer").Importer
Framer.Debug = (require "./Debug").Debug
Framer.Session = (require "./Session").Session
Framer.Extras = require "./Extras/Extras"
window.Framer = Framer if window
# Compatibility for Framer 2
require "./Compat"
# Fix for mobile scrolling
Framer.Extras.MobileScrollFix.enable() if Utils.isMobile
# Set the defaults
Defaults = (require "./Defaults").Defaults
Framer.resetDefaults = Defaults.reset
@@ -279,13 +279,15 @@ class exports.Layer extends BaseClass
_insertElement: ->
Utils.domComplete @__insertElement
__insertElement: =>
if not Session._RootElement
Session._RootElement = document.createElement "div"
Session._RootElement.id = "FramerRoot"
_.extend Session._RootElement.style, Config.rootBaseCSS
document.body.appendChild Session._RootElement
__createRootElement: =>
element = document.createElement "div"
element.id = "FramerRoot"
_.extend element.style, Config.rootBaseCSS
document.body.appendChild element
element
__insertElement: =>
Session._RootElement ?= @__createRootElement()
Session._RootElement.appendChild @_element
destroy: ->

0 comments on commit e3e38a1

Please sign in to comment.