ObserveJS.bind 'Post.Header', class loaded: => @on 'click', @element().querySelector('p.browse'), @open @on 'click', @element().querySelector('svg.clear'), @remove @on 'change', @element().querySelector('input[type=file]'), @submit @on 'dragover', @over @on 'dragleave', @cancel @on 'drop', @drop @when 'ObserveJS:XHR:Failed', @failed @on 'images:create', @refresh @on 'images:destroy', @refresh @when 'scroll', @resize @maxHeight = parseFloat(window.getComputedStyle(this.element())['height']) @resize() resize: => if document.querySelector('main').classList.contains('overlayed') return height = @maxHeight - document.body.scrollTop if height < 0 height = 0 if height != @maxHeight @element().querySelector('nav').classList.add 'hidden' else @element().querySelector('nav').classList.remove 'hidden' @element().style.height = "#{height}px" show: (el) => @show.container ||= @element().querySelector('div.drop') unless el.parentElement? @element().querySelector('div.drop').appendChild(el) for child in @show.container.children child.classList.add 'hidden' el.classList.remove('hidden') hide: (el) => el.classList.add('hidden') outside: (e, rect) -> e.x >= (rect.left + rect.width) || e.x <= rect.left || e.y >= (rect.top + rect.height) || e.y <= rect.top progress: (e) => return unless e.lengthComputable percentComplete = e.loaded / e.total * 100.0; progressBar = @element().querySelector('div.status.uploading .progressbar') progressBar.firstElementChild.style.width = "#{percentComplete}%"; failed: (e) => errors = JSON.parse(e.response.target.responseText) @hide(@template('div.status.uploading')) @show(@template('div.error.status')) ul = @template('div.error.status').querySelector('ul') @on 'click', @template('div.error.status').querySelector('button'), @clear for error in errors ul.insertAdjacentHTML('beforeend', "