Sha256: 2603d1b8c4cd3d3b54295710524e855db3f3c2aca0e228e94763ec18a5e2d12e

Contents?: true

Size: 1.57 KB

Versions: 4

Compression:

Stored size: 1.57 KB

Contents

u = up.util

class up.ExtractPlan

  constructor: (selector, options) ->
    @origin = options.origin
    @selector = up.dom.resolveSelector(selector, options.origin)
    @transition = options.transition
    @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: =>
    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]

      selector: selector
      pseudoClass: pseudoClass
      transition: @transition

Version data entries

4 entries across 4 versions & 1 rubygems

Version Path
unpoly-rails-0.53.3 lib/assets/javascripts/unpoly/classes/extract_plan.coffee
unpoly-rails-0.53.2 lib/assets/javascripts/unpoly/classes/extract_plan.coffee
unpoly-rails-0.53.1 lib/assets/javascripts/unpoly/classes/extract_plan.coffee
unpoly-rails-0.53.0 lib/assets/javascripts/unpoly/classes/extract_plan.coffee