# ----------------------------------------------------------------------------- # Author: Alexander Kravets , # Slate Studio (http://www.slatestudio.com) # # Coding Guide: # https://github.com/thoughtbot/guides/tree/master/style/coffeescript # ----------------------------------------------------------------------------- # ----------------------------------------------------------------------------- # INPUT INVERTER LINK # - depends on Loft character plugin for assets management # ----------------------------------------------------------------------------- class @InputInverterLink extends InputString # PRIVATE =============================================== _has_empty_value: -> return ($(@value).attr('href') == '' && $(@value).html() == '') _normalize_value: -> if ! (@value.indexOf(' -1) @value = "" _add_input: -> @$input =$ "" @$el.append @$input @$input.val(@value) @_normalize_value() @_add_title() @_add_url() @_add_actions() _update_value: (url, title) -> $wrapper =$ "
#{ @value }
" $wrapper.children().attr('href', url).attr('title', title).html(title) @updateValue($wrapper.html()) _title: -> $(@value).html() _url: -> $(@value).attr('href') _add_title: -> @$titleInput =$ "" @$el.append @$titleInput @$titleInput.val(@_title()) @$titleInput.on 'change', (e) => newTitle = $(e.target).val() @_update_value(@_url(), newTitle) _add_url: -> @$urlInput =$ "" @$el.append @$urlInput @$urlInput.val(@_url()) @$urlInput.on 'change', (e) => newUrl = $(e.target).val() @_update_value(newUrl, @_title()) _add_actions: -> @$actions =$ "" @$label.append @$actions @_add_choose_button() @_add_remove_button() _add_choose_button: -> @$chooseBtn =$ "Choose or upload a file" @$actions.append @$chooseBtn @$chooseBtn.on 'click', (e) => e.preventDefault() chr.modules.loft.showModal 'all', false, (objects) => url = objects[0].file.url title = @_title() || objects[0].name @_update_value(url, title) _add_remove_button: -> @$removeBtn =$ "Remove" @$actions.append @$removeBtn @$removeBtn.on 'click', (e) => e.preventDefault() @_update_value('', '') # PUBLIC ================================================ updateValue: (@value) -> @_normalize_value() @$titleInput.val(@_title()) @$urlInput.val(@_url()) if @_has_empty_value() @$input.val('') else @$input.val(@value) @$input.trigger('change') chr.formInputs['inverter-link'] = InputInverterLink