Sha256: 996f00ce09b1a065edd86e9342c527c67a6b79224056301588fe15f0407e52b2

Contents?: true

Size: 1.68 KB

Versions: 10

Compression:

Stored size: 1.68 KB

Contents

u = up.util

class up.dom.ExtractPlan

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

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

  findNew: =>
    u.each @steps, (step) =>
      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

10 entries across 10 versions & 1 rubygems

Version Path
unpoly-rails-0.36.2 lib/assets/javascripts/unpoly/dom/extract_plan.coffee
unpoly-rails-0.36.1 lib/assets/javascripts/unpoly/dom/extract_plan.coffee
unpoly-rails-0.36.0 lib/assets/javascripts/unpoly/dom/extract_plan.coffee
unpoly-rails-0.35.2 lib/assets/javascripts/unpoly/dom/extract_plan.coffee
unpoly-rails-0.35.1 lib/assets/javascripts/unpoly/dom/extract_plan.coffee
unpoly-rails-0.35.0 lib/assets/javascripts/unpoly/dom/extract_plan.coffee
unpoly-rails-0.34.2 lib/assets/javascripts/unpoly/dom/extract_plan.coffee
unpoly-rails-0.34.1 lib/assets/javascripts/unpoly/dom/extract_plan.coffee
unpoly-rails-0.34.0 lib/assets/javascripts/unpoly/dom/extract_plan.coffee
unpoly-rails-0.33.0 lib/assets/javascripts/unpoly/dom/extract_plan.coffee