Sha256: e1a81bd027752ed8bd7bdf573814a54801a790b2f43647ae5371073f0e22cc11

Contents?: true

Size: 1.38 KB

Versions: 3

Compression:

Stored size: 1.38 KB

Contents

u = up.util

class up.FollowVariant

  constructor: (selector, options) ->
    @followNow = options.follow
    @preloadNow = options.preload
    @selectors = selector.split(/\s*,\s*/)

  onClick: (event, $link) =>
    if up.link.shouldProcessEvent(event, $link)
      if $link.is('[up-instant]')
        # If the link was already processed on mousedown, we still need
        # to prevent this later click event's chain.
        up.bus.haltEvent(event)
      else
        up.bus.consumeAction(event)
        @followLink($link)
    else
      # For tests
      up.link.allowDefault(event)

  onMousedown: (event, $link) =>
    if up.link.shouldProcessEvent(event, $link)
      up.bus.consumeAction(event)
      @followLink($link)

  fullSelector: (additionalClause = '') =>
    parts = []
    @selectors.forEach (variantSelector) ->
      ['a', '[up-href]'].forEach (tagSelector) ->
        parts.push "#{tagSelector}#{variantSelector}#{additionalClause}"
    parts.join(', ')

  registerEvents: ->
    up.on 'click', @fullSelector(), (args...) =>
      @onClick(args...)
    up.on 'mousedown', @fullSelector('[up-instant]'), (args...) =>
      @onMousedown(args...)

  followLink: ($link, options = {}) =>
    up.feedback.start $link, options, =>
      @followNow($link, options)

  preloadLink: ($link, options = {}) =>
    @preloadNow($link, options)

  matchesLink: ($link) =>
    $link.is(@fullSelector())

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
unpoly-rails-0.51.1 lib/assets/javascripts/unpoly/classes/follow_variant.coffee
unpoly-rails-0.51.0 lib/assets/javascripts/unpoly/classes/follow_variant.coffee
unpoly-rails-0.50.2 lib/assets/javascripts/unpoly/classes/follow_variant.coffee