From 9e80c75032000859bba3697207cfea22f960c973 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Javi=20Mart=C3=ADn?= Date: Mon, 4 Mar 2019 15:14:36 +0100 Subject: [PATCH] Use string interpolation in CoffeeScript We use it in Ruby, and it will make it easier to change all quotes to double quotes in CoffeeScript files. --- app/assets/javascripts/annotatable.js.coffee | 8 +++---- .../javascripts/check_all_none.js.coffee | 4 ++-- app/assets/javascripts/documentable.js.coffee | 6 ++--- app/assets/javascripts/flaggable.js.coffee | 2 +- app/assets/javascripts/followable.js.coffee | 2 +- app/assets/javascripts/globalize.js.coffee | 10 ++++----- app/assets/javascripts/imageable.js.coffee | 8 +++---- .../investment_report_alert.js.coffee | 2 +- .../javascripts/legislation_admin.js.coffee | 2 +- .../legislation_annotatable.js.coffee | 22 +++++++++---------- app/assets/javascripts/map.js.coffee | 2 +- app/assets/javascripts/polls.js.coffee | 2 +- app/assets/javascripts/tags.js.coffee | 2 +- .../javascripts/tree_navigator.js.coffee | 2 +- 14 files changed, 37 insertions(+), 37 deletions(-) diff --git a/app/assets/javascripts/annotatable.js.coffee b/app/assets/javascripts/annotatable.js.coffee index 49757f16a..fbf7f3862 100644 --- a/app/assets/javascripts/annotatable.js.coffee +++ b/app/assets/javascripts/annotatable.js.coffee @@ -7,9 +7,9 @@ App.Annotatable = annotator.ui.editor.Editor.template = [ '
', '
', - ' ' + _t('Unregistered'), + " #{_t('Unregistered')}", ' ', '
', '
' @@ -23,7 +23,7 @@ App.Annotatable = app = new annotator.App() .include -> beforeAnnotationCreated: (ann) -> - ann[ann_type + "_id"] = ann_id + ann["#{ann_type}_id"] = ann_id ann.permissions = ann.permissions || {} ann.permissions.admin = [] .include(annotator.ui.main, { element: this }) @@ -34,5 +34,5 @@ App.Annotatable = app.ident.identity = current_user_id options = {} - options[ann_type + "_id"] = ann_id + options["#{ann_type}_id"] = ann_id app.annotations.load(options) diff --git a/app/assets/javascripts/check_all_none.js.coffee b/app/assets/javascripts/check_all_none.js.coffee index ffc34ec7f..92a7cc544 100644 --- a/app/assets/javascripts/check_all_none.js.coffee +++ b/app/assets/javascripts/check_all_none.js.coffee @@ -3,8 +3,8 @@ App.CheckAllNone = initialize: -> $('[data-check-all]').on 'click', -> target_name = $(this).data('check-all') - $("[name='" + target_name + "']").prop('checked', true) + $("[name='#{target_name}']").prop('checked', true) $('[data-check-none]').on 'click', -> target_name = $(this).data('check-none') - $("[name='" + target_name + "']").prop('checked', false) + $("[name='#{target_name}']").prop('checked', false) diff --git a/app/assets/javascripts/documentable.js.coffee b/app/assets/javascripts/documentable.js.coffee index a61458150..73bebc4b8 100644 --- a/app/assets/javascripts/documentable.js.coffee +++ b/app/assets/javascripts/documentable.js.coffee @@ -69,7 +69,7 @@ App.Documentable = progress: (e, data) -> progress = parseInt(data.loaded / data.total * 100, 10) - $(data.progressBar).find('.loading-bar').css 'width', progress + '%' + $(data.progressBar).find('.loading-bar').css 'width', "#{progress}%" return buildFileUploadData: (e, data) -> @@ -112,7 +112,7 @@ App.Documentable = $(data.titleField).val(title) setInputErrors: (data) -> - errors = '' + data.jqXHR.responseJSON.errors + '' + errors = "#{data.jqXHR.responseJSON.errors}" $(data.errorContainer).append(errors) lockUploads: -> @@ -157,4 +157,4 @@ App.Documentable = App.Documentable.doDeleteCachedAttachmentRequest(this.href, data) removeDocument: (id) -> - $('#' + id).remove() + $("##{id}").remove() diff --git a/app/assets/javascripts/flaggable.js.coffee b/app/assets/javascripts/flaggable.js.coffee index 7ada75686..411723368 100644 --- a/app/assets/javascripts/flaggable.js.coffee +++ b/app/assets/javascripts/flaggable.js.coffee @@ -1,4 +1,4 @@ App.Flaggable = update: (resource_id, button) -> - $("#" + resource_id + " .js-flag-actions").html(button).foundation() + $("##{resource_id} .js-flag-actions").html(button).foundation() diff --git a/app/assets/javascripts/followable.js.coffee b/app/assets/javascripts/followable.js.coffee index 9fa9aa319..10923d327 100644 --- a/app/assets/javascripts/followable.js.coffee +++ b/app/assets/javascripts/followable.js.coffee @@ -1,7 +1,7 @@ App.Followable = update: (followable_id, button, notice) -> - $("#" + followable_id + " .js-follow").html(button) + $("##{followable_id} .js-follow").html(button) if ($('[data-alert]').length > 0) $('[data-alert]').replaceWith(notice) else diff --git a/app/assets/javascripts/globalize.js.coffee b/app/assets/javascripts/globalize.js.coffee index 5dc30432f..df05b47dc 100644 --- a/app/assets/javascripts/globalize.js.coffee +++ b/app/assets/javascripts/globalize.js.coffee @@ -16,18 +16,18 @@ App.Globalize = else $(this).hide() $('.js-delete-language').hide() - $('#js_delete_' + locale).show() + $("#js_delete_#{locale}").show() highlight_locale: (element) -> $('.js-globalize-locale-link').removeClass('is-active') element.addClass('is-active') remove_language: (locale) -> - $(".js-globalize-attribute[data-locale=" + locale + "]").each -> + $(".js-globalize-attribute[data-locale=#{locale}]").each -> $(this).val('').hide() if CKEDITOR.instances[$(this).attr('id')] CKEDITOR.instances[$(this).attr('id')].setData('') - $(".js-globalize-locale-link[data-locale=" + locale + "]").hide() + $(".js-globalize-locale-link[data-locale=#{locale}]").hide() next = $(".js-globalize-locale-link:visible").first() App.Globalize.highlight_locale(next) App.Globalize.display_translations(next.data("locale")) @@ -48,10 +48,10 @@ App.Globalize = ) destroy_locale_field: (locale) -> - $("input[id$=_destroy][data-locale=" + locale + "]") + $("input[id$=_destroy][data-locale=#{locale}]") site_customization_enable_locale_field: (locale) -> - $("#enabled_translations_" + locale) + $("#enabled_translations_#{locale}") refresh_visible_translations: -> locale = $('.js-globalize-locale-link.is-active').data("locale") diff --git a/app/assets/javascripts/imageable.js.coffee b/app/assets/javascripts/imageable.js.coffee index e029dff52..70fff0f8a 100644 --- a/app/assets/javascripts/imageable.js.coffee +++ b/app/assets/javascripts/imageable.js.coffee @@ -70,7 +70,7 @@ App.Imageable = progress: (e, data) -> progress = parseInt(data.loaded / data.total * 100, 10) - $(data.progressBar).find('.loading-bar').css 'width', progress + '%' + $(data.progressBar).find('.loading-bar').css 'width', "#{progress}%" return buildFileUploadData: (e, data) -> @@ -117,11 +117,11 @@ App.Imageable = $(data.titleField).val(title) setInputErrors: (data) -> - errors = '' + data.jqXHR.responseJSON.errors + '' + errors = "#{data.jqXHR.responseJSON.errors}" $(data.errorContainer).append(errors) setPreview: (data) -> - image_preview = '
' + image_preview = "
" if $(data.preview).length > 0 $(data.preview).replaceWith(image_preview) else @@ -162,5 +162,5 @@ App.Imageable = App.Imageable.doDeleteCachedAttachmentRequest(this.href, data) removeImage: (id) -> - $('#' + id).remove() + $("##{id}").remove() $("#new_image_link").removeClass('hide') diff --git a/app/assets/javascripts/investment_report_alert.js.coffee b/app/assets/javascripts/investment_report_alert.js.coffee index c535f4c09..4a1d1d43b 100644 --- a/app/assets/javascripts/investment_report_alert.js.coffee +++ b/app/assets/javascripts/investment_report_alert.js.coffee @@ -2,6 +2,6 @@ App.InvestmentReportAlert = initialize: -> $('#js-investment-report-alert').on 'click', -> if this.checked && $('#budget_investment_feasibility_unfeasible').is(':checked') - confirm(this.dataset.alert + "\n" + this.dataset.notFeasibleAlert) + confirm("#{this.dataset.alert}\n#{this.dataset.notFeasibleAlert}") else if this.checked confirm(this.dataset.alert) diff --git a/app/assets/javascripts/legislation_admin.js.coffee b/app/assets/javascripts/legislation_admin.js.coffee index 5aa19f083..161881ab7 100644 --- a/app/assets/javascripts/legislation_admin.js.coffee +++ b/app/assets/javascripts/legislation_admin.js.coffee @@ -6,7 +6,7 @@ App.LegislationAdmin = checkbox = $(this) parent = $(this).parents('.row:eq(0)') date_selector = $(this).data('disable-date') - parent.find("input[type='text'][id^='" + date_selector + "']").each -> + parent.find("input[type='text'][id^='#{date_selector}']").each -> if checkbox.is(':checked') $(this).removeAttr("disabled") else diff --git a/app/assets/javascripts/legislation_annotatable.js.coffee b/app/assets/javascripts/legislation_annotatable.js.coffee index 34385bc1e..d201b4f49 100644 --- a/app/assets/javascripts/legislation_annotatable.js.coffee +++ b/app/assets/javascripts/legislation_annotatable.js.coffee @@ -45,7 +45,7 @@ App.LegislationAnnotatable = $.ajax method: "GET" - url: event.annotation_url + "/annotations/" + event.annotation_id + "/comments" + url: "#{event.annotation_url}/annotations/#{event.annotation_id}/comments" dataType: 'script' onClick: (event) -> @@ -54,7 +54,7 @@ App.LegislationAnnotatable = if App.LegislationAnnotatable.isMobile() annotation_url = $(event.target).closest(".legislation-annotatable").data("legislation-annotatable-base-url") - window.location.href = annotation_url + "/annotations/" + $(this).data('annotation-id') + window.location.href = "#{annotation_url}/annotations/#{$(this).data('annotation-id')}" return $('[data-annotation-id]').removeClass('current-annotation') @@ -66,7 +66,7 @@ App.LegislationAnnotatable = $(elem).data("annotation-id") annotation_id = target.data('annotation-id') - $('[data-annotation-id="' + annotation_id + '"]').addClass('current-annotation') + $("[data-annotation-id='#{annotation_id}']").addClass('current-annotation') $('#comments-box').html('') App.LegislationAllegations.show_comments() @@ -101,7 +101,7 @@ App.LegislationAnnotatable = annotation_url = $('[data-legislation-annotatable-base-url]').data('legislation-annotatable-base-url') $.ajax( method: 'GET' - url: annotation_url + '/annotations/new' + url: "#{annotation_url}/annotations/new" dataType: 'script').done (-> $('#new_legislation_annotation #legislation_annotation_quote').val(@annotation.quote) $('#new_legislation_annotation #legislation_annotation_ranges').val(JSON.stringify(@annotation.ranges)) @@ -118,11 +118,11 @@ App.LegislationAnnotatable = $("#comments-box").html("").hide() $.ajax method: "GET" - url: annotation_url + "/annotations/" + data.responseJSON.id + "/comments" + url: "#{annotation_url}/annotations/#{data.responseJSON.id}/comments" dataType: 'script' else $(e.target).find('label').addClass('error') - $('' + data.responseJSON[0] + '').insertAfter($(e.target).find('textarea')) + $("#{data.responseJSON[0]}").insertAfter($(e.target).find('textarea')) return true ) return @@ -138,8 +138,8 @@ App.LegislationAnnotatable = ann_id = anchor.split("-")[-1..] checkExist = setInterval((-> - if $("span[data-annotation-id='" + ann_id + "']").length - el = $("span[data-annotation-id='" + ann_id + "']") + if $("span[data-annotation-id='#{ann_id}']").length + el = $("span[data-annotation-id='#{ann_id}']") el.addClass('current-annotation') $('#comments-box').html('') App.LegislationAllegations.show_comments() @@ -164,11 +164,11 @@ App.LegislationAnnotatable = last_annotation = annotations[annotations.length - 1] checkExist = setInterval((-> - if $("span[data-annotation-id='" + last_annotation.id + "']").length + if $("span[data-annotation-id='#{last_annotation.id}']").length for annotation in annotations ann_weight = App.LegislationAnnotatable.propotionalWeight(annotation.weight, max_weight) - el = $("span[data-annotation-id='" + annotation.id + "']") - el.addClass('weight-' + ann_weight) + el = $("span[data-annotation-id='#{annotation.id}']") + el.addClass("weight-#{ann_weight}") clearInterval checkExist return ), 100) diff --git a/app/assets/javascripts/map.js.coffee b/app/assets/javascripts/map.js.coffee index 1eabfa132..68ec8e943 100644 --- a/app/assets/javascripts/map.js.coffee +++ b/app/assets/javascripts/map.js.coffee @@ -75,7 +75,7 @@ App.Map = openMarkerPopup = (e) -> marker = e.target - $.ajax '/investments/' + marker.options['id'] + '/json_data', + $.ajax "/investments/#{marker.options['id']}/json_data", type: 'GET' dataType: 'json' success: (data) -> diff --git a/app/assets/javascripts/polls.js.coffee b/app/assets/javascripts/polls.js.coffee index 6f3a61859..eb39bf9a2 100644 --- a/app/assets/javascripts/polls.js.coffee +++ b/app/assets/javascripts/polls.js.coffee @@ -23,7 +23,7 @@ App.Polls = click: => token_message = $(".js-token-message") if !token_message.is(':visible') - token_message.html(token_message.html() + "
" + @token + "") + token_message.html("#{token_message.html()}
#{@token}") token_message.show() false diff --git a/app/assets/javascripts/tags.js.coffee b/app/assets/javascripts/tags.js.coffee index e641203f7..b2bb95d4e 100644 --- a/app/assets/javascripts/tags.js.coffee +++ b/app/assets/javascripts/tags.js.coffee @@ -8,7 +8,7 @@ App.Tags = unless $this.data('initialized') is 'yes' $this.on('click', -> - name = '"' + $(this).text() + '"' + name = "\"#{$(this).text()}\"" current_tags = $tag_input.val().split(',').filter(Boolean) if $.inArray(name, current_tags) >= 0 diff --git a/app/assets/javascripts/tree_navigator.js.coffee b/app/assets/javascripts/tree_navigator.js.coffee index 406b156f6..5f984a6d9 100644 --- a/app/assets/javascripts/tree_navigator.js.coffee +++ b/app/assets/javascripts/tree_navigator.js.coffee @@ -30,7 +30,7 @@ App.TreeNavigator = elem.siblings('ul').show() if anchor = $(location).attr('hash') - if link = elem.find('a[href="' + anchor + '"]') + if link = elem.find("a[href='#{anchor}']") link.parents('ul').each -> $(this).show() $(this).siblings('span').removeClass('closed').addClass('open')