Sha256: deef4514af02b256ae2b164d14de5d094a3881485af63cc3466792f55b94b75a

Contents?: true

Size: 1.27 KB

Versions: 1

Compression:

Stored size: 1.27 KB

Contents

ObserveJS.bind 'Posts.Filter.Tags', class
  loaded: =>
    @on 'tags:index', @show
    @on 'click', @action
    @element().appendChild(@retrieve('svg.placeholder'))

  show: (e) =>
    document.body.appendChild(e.HTML)
    @on 'click', e.HTML, @select

  select: (e) =>
    el = e.target
    while el && !(el instanceof HTMLLIElement)
      el = el.parentElement

    return unless el?

    input = @element().querySelector('input[type=hidden]')
    span = @retrieve('span.tag')
    span.textContent = el.textContent
    input.value = el.getAttribute('oid')

    @retrieve('svg.placeholder').remove()
    @element().appendChild(span)
    @element().appendChild(@retrieve('svg.clear'))
    @element().classList.add 'tagged'

    document.querySelector("[as='Overlay']").instance.remove()

    @changed(input)

  action: =>
    input = @element().querySelector('input[type=hidden]')
    if @element().classList.contains('tagged')
      @retrieve('svg.clear').remove()
      @retrieve('span.tag').remove()
      @element().appendChild(@retrieve('svg.placeholder'))
      @element().classList.remove('tagged')
      input.value = null
      @changed(input)
    else
      xhr = new ObserveJS.XHR(@element())
      xhr.send()


  changed: (el) =>
    event = new Event('input')
    el.dispatchEvent(event)

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
ecrire-0.29.0 lib/ecrire/app/assets/javascripts/admin/posts/filters/tags.js.coffee