Sha256: 26252584ddab227797476463a23415513740cbbf25a2f1e9199f4fc60be76455

Contents?: true

Size: 1.46 KB

Versions: 26

Compression:

Stored size: 1.46 KB

Contents

@Trigger = (->
  
  u = up.util
  
  mousedown = ($element, options) ->
    event = createMouseEvent('mousedown', options)
    dispatch($element, event)
  
  mouseup = ($element, options) ->
    event = createMouseEvent('mouseup', options)
    dispatch($element, event)
    
  click = ($element, options) ->
    event = createMouseEvent('click', options)
    dispatch($element, event)

  # Can't use the new MouseEvent constructor in IE11 because computer.
  # http://www.codeproject.com/Tips/893254/JavaScript-Triggering-Event-Manually-in-Internet-E
  createMouseEvent = (type, options) ->
    options = u.options(options,
      view: window,
      cancelable: true,
      bubbles: true,
      detail: 0,
      screenX: 0,
      screenY: 0,
      clientX: 0,
      clientY: 0,
      ctrlKey: false,
      altKey: false,
      shiftKey: false,
      metaKey: false,
      button: 0,
      relatedTarget: null
    )
    event = document.createEvent('MouseEvent')
    event.initMouseEvent(type,
      options.view,
      options.bubbles,
      options.cancelable,
      options.detail,
      options.screenX,
      options.screenY,
      options.clientX,
      options.clientY,
      options.ctrlKey,
      options.altKey,
      options.shiftKey,
      options.metaKey,
      options.button,
      options.relatedTarget
    )
    event

  dispatch = ($element, event) ->
    $element.each ->
      this.dispatchEvent(event)
      
  mousedown: mousedown
  mouseup: mouseup
  click: click
  
)()

Version data entries

26 entries across 26 versions & 1 rubygems

Version Path
upjs-rails-0.10.2 spec_app/spec/javascripts/helpers/trigger.js.coffee
upjs-rails-0.10.1 spec_app/spec/javascripts/helpers/trigger.js.coffee
upjs-rails-0.10.0 spec_app/spec/javascripts/helpers/trigger.js.coffee
upjs-rails-0.9.1 spec_app/spec/javascripts/helpers/trigger.js.coffee
upjs-rails-0.9.0 spec_app/spec/javascripts/helpers/trigger.js.coffee
upjs-rails-0.8.2 spec_app/spec/javascripts/helpers/trigger.js.coffee
upjs-rails-0.8.1 spec_app/spec/javascripts/helpers/trigger.js.coffee
upjs-rails-0.8.0 spec_app/spec/javascripts/helpers/trigger.js.coffee
upjs-rails-0.7.8 spec_app/spec/javascripts/helpers/trigger.js.coffee
upjs-rails-0.7.7 spec_app/spec/javascripts/helpers/trigger.js.coffee
upjs-rails-0.7.6 spec_app/spec/javascripts/helpers/trigger.js.coffee
upjs-rails-0.7.5 spec_app/spec/javascripts/helpers/trigger.js.coffee
upjs-rails-0.7.4 spec_app/spec/javascripts/helpers/trigger.js.coffee
upjs-rails-0.7.3 spec_app/spec/javascripts/helpers/trigger.js.coffee
upjs-rails-0.7.2 spec_app/spec/javascripts/helpers/trigger.js.coffee
upjs-rails-0.7.1 spec_app/spec/javascripts/helpers/trigger.js.coffee
upjs-rails-0.7.0 spec_app/spec/javascripts/helpers/trigger.js.coffee
upjs-rails-0.6.5 spec_app/spec/javascripts/helpers/trigger.js.coffee
upjs-rails-0.6.4 spec_app/spec/javascripts/helpers/trigger.js.coffee
upjs-rails-0.6.3 spec_app/spec/javascripts/helpers/trigger.js.coffee