Sha256: 88d13f316d87437a3114436a4a734693cfafd97c17eb3674f88b17a7195def48

Contents?: true

Size: 1.28 KB

Versions: 4

Compression:

Stored size: 1.28 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.dataset.name
    input.value = el.getAttribute('oid')

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

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

    @changed(input)

  action: (e) =>
    if @retrieve('svg.clear').contains(e.target)
      @retrieve('svg.clear').remove()
      @retrieve('span').remove()
      @element().appendChild(@retrieve('svg.placeholder'))
      @element().classList.remove 'tagged'
      input = @element().querySelector('input[type=hidden]')
      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

4 entries across 4 versions & 1 rubygems

Version Path
ecrire-0.30.3 lib/ecrire/app/assets/javascripts/admin/posts/filters/tags.coffee
ecrire-0.30.2 lib/ecrire/app/assets/javascripts/admin/posts/filters/tags.coffee
ecrire-0.30.1 lib/ecrire/app/assets/javascripts/admin/posts/filters/tags.coffee
ecrire-0.30.0 lib/ecrire/app/assets/javascripts/admin/posts/filters/tags.coffee