# I18n #= require i18n #= require i18n/translations 'use strict' $(document).ready -> $('#translation-control form').unbind('submit').bind('submit', (event)-> event.preventDefault() event.stopPropagation() $form = $(this) serialized = $form.serialize() $form.find('select, button, textarea').prop 'disabled', true $.post $form.attr('action'), serialized, (json) -> if json.success $span = $('.translate-me[data-translate-key="' + json.key + '"]') $span.html(json.translation) $span.attr('data-translate-untranslated', json.translation) $span.removeClass 'untranslated' else if json.test console.log json.test $form.find('select, button, textarea').prop 'disabled', false return , 'json' return ) $('.translate-me').click (event)-> if event.altKey event.preventDefault() key = $(this).attr('data-translate-key') $('#translationkey').val key resetTranslation key $('#translationvalue').focus() return #$('#translationvalue, #translationkey').focus -> $('#translation-control *').focus -> key = $('#translationkey').val() selectTranslation key updateTranslation key return $('#translationkey').change (event)-> #$('#translationvalue').val('') key = $('#translationkey').val() selectTranslation key resetTranslation key #$('#translation').focus() #console.log event return # $('#translationvalue, #translationkey').blur -> $('#translation-control *').blur -> selectTranslation() return $('#translationvalue').bind 'input propertychange', ()-> updateTranslation $('#translationkey').val() return return selectTranslation = (key)-> $span = $('.translate-me.selected'); $span.removeClass 'selected' $span.removeClass 'preview' $('#translatevars').hide() $('#translatepluralizations').hide() $('#translatevars ul').html '' $('#translationhascount').val('0') if key $target = $('.translate-me[data-translate-key="' + key + '"]') if !$target || !$target.length return vars = $target.addClass('selected').data().vars if vars keys = Object.keys(vars) if keys.length for i in [0...keys.length] $('#translatevars ul').append ('