Sha256: 4c50d73fb28d09c7c1e6b0a56a16aa9b3dc82ba03c7debbd4c3eaa3ee94623f5

Contents?: true

Size: 1.26 KB

Versions: 1

Compression:

Stored size: 1.26 KB

Contents

#= require _dom_parser

# if server responds with 304, sometimes you may get
# full page source instead of just wiselinks part, so
# you need to use different content extract strategies
class Response
  @_document_parser: null

  @_get_document_parser: ->
    Response._document_parser ?= new window._Wiselinks.DOMParser


  constructor: (@html, @xhr, @$target) ->

  url: ->
    @xhr.getResponseHeader('X-Wiselinks-Url')

  assets_digest: ->
    if @_is_full_document_response()
      $('meta[name="assets-digest"]', @_get_doc()).attr('content')
    else
      @xhr.getResponseHeader('X-Wiselinks-Assets-Digest')

  content: ->
    @_content ?= @_extract_content()

  title: ->
    @_title ?= @_extract_title()

  _extract_title: ->
    if @_is_full_document_response()
      $('title', @_get_doc()).text()
    else
      @xhr.getResponseHeader('X-Wiselinks-Title')

  _extract_content: ->
    if @_is_full_document_response()
      @_get_doc_target_node().html()
    else
      @html

  _is_full_document_response: ->
    @_get_doc_target_node().length is 1

  _get_doc_target_node: ->
    @$doc_target_node ?= $(@$target.selector, @_get_doc())

  _get_doc: ->
    @_doc ?= Response._get_document_parser().parse(@html)



window._Wiselinks ?= {}
window._Wiselinks.Response = Response

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
wiselinks-1.2.0 lib/assets/javascripts/_response.js.coffee