Sha256: 64624099df921872374a6ce9697e00a2aa712dc37e3c61f7f2e993120f79e1a9

Contents?: true

Size: 1.77 KB

Versions: 6

Compression:

Stored size: 1.77 KB

Contents

u = up.util

class up.ExtractPlan

  constructor: (selector, options) ->
    @origin = options.origin
    @selector = up.dom.resolveSelector(selector, options.origin)
    @transition = options.transition || options.animation || 'none'
    @response = options.response
    @oldLayer = options.layer
    @steps = @parseSteps()

  findOld: =>
    u.each @steps, (step) =>
      step.$old = up.dom.first(step.selector, layer: @oldLayer)

  findNew: =>
    u.each @steps, (step) =>
      # The response has no layers. It's always just the page.
      step.$new = @response.first(step.selector)

  oldExists: =>
    @findOld()
    u.all @steps, (step) -> step.$old

  newExists: =>
    @findNew()
    u.all @steps, (step) -> step.$new

  matchExists: =>
    @oldExists() && @newExists()

  ###*
  Example:

      parseSelector('foo, bar:before', transition: 'cross-fade')

      [
        { selector: 'foo', pseudoClass: undefined, transition: 'cross-fade' },
        { selector: 'bar', pseudoClass: 'before', transition: 'cross-fade' }
      ]
  ###
  parseSteps: =>
    if u.isString(@transition)
      transitions = @transition.split(comma)
    else
      transitions = [@transition]

    comma = /\ *,\ */

    disjunction = @selector.split(comma)

    u.map disjunction, (literal, i) ->
      literalParts = literal.match(/^(.+?)(?:\:(before|after))?$/)
      literalParts or up.fail('Could not parse selector literal "%s"', literal)
      selector = literalParts[1]
      if selector == 'html'
        # If someone really asked us to replace the <html> root, the best
        # we can do is replace the <body>.
        selector = 'body'

      pseudoClass = literalParts[2]
      transition = transitions[i] || u.last(transitions)

      selector: selector
      pseudoClass: pseudoClass
      transition: transition

Version data entries

6 entries across 6 versions & 1 rubygems

Version Path
unpoly-rails-0.52.0 lib/assets/javascripts/unpoly/classes/extract_plan.coffee
unpoly-rails-0.51.1 lib/assets/javascripts/unpoly/classes/extract_plan.coffee
unpoly-rails-0.51.0 lib/assets/javascripts/unpoly/classes/extract_plan.coffee
unpoly-rails-0.50.2 lib/assets/javascripts/unpoly/classes/extract_plan.coffee
unpoly-rails-0.50.1 lib/assets/javascripts/unpoly/classes/extract_plan.coffee
unpoly-rails-0.50.0 lib/assets/javascripts/unpoly/classes/extract_plan.coffee