<commit_before>###**
Fragment update API
===================
  
The `up.fragment` module exposes a high-level Javascript API to [update](/up.replace) or
[destroy](/up.destroy) page fragments.

Fragments are [compiled](/up.compiler) elements that can be updated from a server URL.
They also exist on a layer (page, modal, popup).

Most of Unpoly's functionality (like [fragment links](/up.link) or [modals](/up.modal))
is built from `up.fragment` functions. You may use them to extend Unpoly from your
[custom Javascript](/up.syntax).

@module up.fragment
###
up.fragment = do ->
  
  u = up.util
  e = up.element

  reset = ->
    config.reset()

  setSource = (element, sourceUrl) ->
    unless sourceUrl is false
      sourceUrl = u.normalizeUrl(sourceUrl) if u.isPresent(sourceUrl)
      element.setAttribute("up-source", sourceUrl)

  ###**
  Returns the URL the given element was retrieved from.

  @method up.fragment.source
  @param {string|Element|jQuery} selectorOrElement
  @experimental
  ###
  source = (selectorOrElement) ->
    element = e.get(selectorOrElement)
    if element = e.closest(element, '[up-source]')
      element.getAttribute("up-source")
    else
      up.browser.url()

  setSource = (selectorOrElement, sourceUrl) ->
    if sourceUrl
      sourceUrl = u.normalizeUrl(sourceUrl)
      element.setAttribute('up-source', sourceUrl)

  # TODO: Documentation
  makeChange = (options) ->
    if options.content || options.document
      change = new up.Change.FromContent(options)
    else
      options.url ?= up.browser.url()
      change =new up.Change.FromURL(options)
    return change.execute()

  ###**
  Replaces elements on the current page with corresponding elements
  from a new page fetched from the server.

  The current and new elements must both match the given CSS selector.

  The unobtrusive variant of this is the [`a[up-target]`](/a-up-target) selector.

  \#\#\# Example

  Let's say your curent HTML looks like this:

      <div class="one">old one</div>
      <div class="two">old two</div>

  We now replace the second `<div>`:

      up.replace('.two', '/new')

  The server renders a response for `/new`:

      <div class="one">new one</div><commit_msg>up.change: Don't default to current { url }<commit_after>###**
Fragment update API
===================
  
The `up.fragment` module exposes a high-level Javascript API to [update](/up.replace) or
[destroy](/up.destroy) page fragments.

Fragments are [compiled](/up.compiler) elements that can be updated from a server URL.
They also exist on a layer (page, modal, popup).

Most of Unpoly's functionality (like [fragment links](/up.link) or [modals](/up.modal))
is built from `up.fragment` functions. You may use them to extend Unpoly from your
[custom Javascript](/up.syntax).

@module up.fragment
###
up.fragment = do ->
  
  u = up.util
  e = up.element

  reset = ->
    config.reset()

  setSource = (element, sourceUrl) ->
    unless sourceUrl is false
      sourceUrl = u.normalizeUrl(sourceUrl) if u.isPresent(sourceUrl)
      element.setAttribute("up-source", sourceUrl)

  ###**
  Returns the URL the given element was retrieved from.

  @method up.fragment.source
  @param {string|Element|jQuery} selectorOrElement
  @experimental
  ###
  source = (selectorOrElement) ->
    element = e.get(selectorOrElement)
    if element = e.closest(element, '[up-source]')
      element.getAttribute("up-source")
    else
      up.browser.url()

  setSource = (selectorOrElement, sourceUrl) ->
    if sourceUrl
      sourceUrl = u.normalizeUrl(sourceUrl)
      element.setAttribute('up-source', sourceUrl)

  # TODO: Documentation
  makeChange = (options) ->
    if options.content || options.document
      change = new up.Change.FromContent(options)
    else if options.url
      change = new up.Change.FromURL(options)
    else
      up.fail('up.change() requires either { content }, { document } or { url } option')
    return change.execute()

  ###**
  Replaces elements on the current page with corresponding elements
  from a new page fetched from the server.

  The current and new elements must both match the given CSS selector.

  The unobtrusive variant of this is the [`a[up-target]`](/a-up-target) selector.

  \#\#\# Example

  Let's say your curent HTML looks like this:

      <div class="one">old one</div>
      <div class="two">old two</div>

  We now replace the second `<div>`:

      up.replace('.two', '/new')

  The server renders a response for `/new`:

      <div class="one">new one</div>
{'fraction_non_alphanumeric': 0.13003095975232198, 'fraction_numerical': 0.0, 'mean_word_length': 3.4169921875, 'pattern_counts': {'":': 0, '<': 17, '<?xml version=': 0, '>': 29, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2006369', 'n_tokens_mistral': 1396, 'n_tokens_neox': 1328, 'n_words': 436}