Sha256: bcb865c346379b26233feca5d32487343892f1ec51469842a60bc6eec9f5170e

Contents?: true

Size: 1.48 KB

Versions: 15

Compression:

Stored size: 1.48 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...) =>
      u.muteRejection @onClick(args...)
    up.on 'mousedown', @fullSelector('[up-instant]'), (args...) =>
      u.muteRejection @onMousedown(args...)

  followLink: ($link, options = {}) =>
    up.bus.whenEmitted('up:link:follow', $element: $link).then =>
      up.feedback.start $link, options, =>
        @followNow($link, options)

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

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

Version data entries

15 entries across 15 versions & 1 rubygems

Version Path
unpoly-rails-0.56.7 lib/assets/javascripts/unpoly/classes/follow_variant.coffee
unpoly-rails-0.56.6 lib/assets/javascripts/unpoly/classes/follow_variant.coffee
unpoly-rails-0.56.5 lib/assets/javascripts/unpoly/classes/follow_variant.coffee
unpoly-rails-0.56.4 lib/assets/javascripts/unpoly/classes/follow_variant.coffee
unpoly-rails-0.56.3 lib/assets/javascripts/unpoly/classes/follow_variant.coffee
unpoly-rails-0.56.2 lib/assets/javascripts/unpoly/classes/follow_variant.coffee
unpoly-rails-0.56.1 lib/assets/javascripts/unpoly/classes/follow_variant.coffee
unpoly-rails-0.56.0 lib/assets/javascripts/unpoly/classes/follow_variant.coffee
unpoly-rails-0.55.1 lib/assets/javascripts/unpoly/classes/follow_variant.coffee
unpoly-rails-0.55.0 lib/assets/javascripts/unpoly/classes/follow_variant.coffee
unpoly-rails-0.54.1 lib/assets/javascripts/unpoly/classes/follow_variant.coffee
unpoly-rails-0.54.0 lib/assets/javascripts/unpoly/classes/follow_variant.coffee
unpoly-rails-0.53.4 lib/assets/javascripts/unpoly/classes/follow_variant.coffee
unpoly-rails-0.53.3 lib/assets/javascripts/unpoly/classes/follow_variant.coffee
unpoly-rails-0.53.2 lib/assets/javascripts/unpoly/classes/follow_variant.coffee