Class: TouchAction::ScriptGenerator

Inherits:
Object
  • Object
show all
Defined in:
lib/touch_action/script_generator.rb

Constant Summary collapse

ACTIONS_WITH_DEFAULT_OPTIONS =
{
  tap: {},
  doubletap: {},
  flick: {axis: 'x', distance: 100,  duration: 500},
  pinch: {r1: 50, r2: 100},
  press: {hold: 2000},
  move: {path: {xdist: 70, ydist: -50},  duration: 500},
  rotate: {rotation: -75}
}

Class Method Summary collapse

Class Method Details

.generate_javascript(action, options = {}) ⇒ Object

Raises:

  • (ArgumentError)


16
17
18
19
20
21
22
23
# File 'lib/touch_action/script_generator.rb', line 16

def self.generate_javascript action, options = {}
  action = :flick if action == :swipe
  raise ArgumentError, "The touch action #{action} doesn't exist" unless ACTIONS_WITH_DEFAULT_OPTIONS[action]
  script = File.read(File.expand_path("../javascripts/touch_action.js.erb", __FILE__))
  default_options = ACTIONS_WITH_DEFAULT_OPTIONS[action]
  arguments = {gesture: action.to_s, options: default_options.merge(options)}
  render_erb(script, arguments)
end