window.Activa = class Activa @slug_was_edited = false constructor: (@options) -> @original_slug = @options.slug_input.val() @options.toggle_btn.click (e) => @toggle(e) @options.done_btn.click (e) => @done(e) @options.cancel_btn.click (e) => @cancel(e) @options.title_input.blur (e) => @update(e) @options.slug_input.keyup (e) => @slug_was_edited = true if @options.slug_input.val().length > 0 # Update slug field update: (e) -> return if @slug_was_edited params = title: @options.title_input.val() $.post(@options.update_uri, params, (data) => @options.slug_input.val(data.slug) ) # Toggle slug control toggle: (e) -> e.preventDefault() @options.toggle_wrapper.toggleClass('hidden') @options.slug_input.focus() # Apply slug done: (e) -> @toggle(e) # Cancel slug cancel: (e) -> @options.slug_input.val(@original_slug) @slug_was_edited = false @toggle(e)