From fbb97c3db897b5bf4187b227ad843d74c8b84bb5 Mon Sep 17 00:00:00 2001 From: Matt-Yorkley <9029026+Matt-Yorkley@users.noreply.github.com> Date: Tue, 2 Jul 2019 11:53:49 +0100 Subject: [PATCH] Fix JS render-blocking in Darkswarm --- app/views/checkout/_form.html.haml | 9 ++--- app/views/checkout/edit.html.haml | 5 +-- app/views/enterprises/shop.html.haml | 3 +- app/views/groups/index.html.haml | 3 +- app/views/groups/show.html.haml | 3 +- app/views/layouts/darkswarm.html.haml | 36 ++++++++++--------- app/views/layouts/registration.html.haml | 18 +++++----- app/views/map/index.html.haml | 3 +- app/views/producers/index.html.haml | 3 +- app/views/registration/index.html.haml | 7 ++-- .../shopping_shared/_order_cycles.html.haml | 4 ++- app/views/shops/index.html.haml | 3 +- app/views/spree/orders/edit.html.haml | 3 +- app/views/spree/orders/show.html.haml | 3 +- app/views/spree/users/show.html.haml | 4 +-- 15 files changed, 62 insertions(+), 45 deletions(-) diff --git a/app/views/checkout/_form.html.haml b/app/views/checkout/_form.html.haml index 0fdfe267b8..901fe64a00 100644 --- a/app/views/checkout/_form.html.haml +++ b/app/views/checkout/_form.html.haml @@ -1,13 +1,14 @@ +- content_for :injection_data do + = inject_available_shipping_methods + = inject_available_payment_methods + = inject_saved_credit_cards + = f_form_for current_order, html: {name: "checkout", id: "checkout_form", novalidate: true, "ng-submit" => "purchase($event, checkout)"} do |f| - = inject_available_shipping_methods - = inject_available_payment_methods - = inject_saved_credit_cards - = render "checkout/details", f: f = render "checkout/billing", f: f = render "checkout/shipping", f: f diff --git a/app/views/checkout/edit.html.haml b/app/views/checkout/edit.html.haml index ab5253538b..1c5765243b 100644 --- a/app/views/checkout/edit.html.haml +++ b/app/views/checkout/edit.html.haml @@ -1,8 +1,9 @@ - content_for(:title) do = t :checkout_title -= inject_enterprise_and_relatives -= inject_available_countries +- content_for :injection_data do + = inject_enterprise_and_relatives + = inject_available_countries .darkswarm.footer-pad - content_for :order_cycle_form do diff --git a/app/views/enterprises/shop.html.haml b/app/views/enterprises/shop.html.haml index 108ad893e9..96df8b89ff 100644 --- a/app/views/enterprises/shop.html.haml +++ b/app/views/enterprises/shop.html.haml @@ -5,7 +5,8 @@ - content_for(:image) do = current_distributor.logo.url -= inject_enterprise_shopfront(@enterprise) +- content_for :injection_data do + = inject_enterprise_shopfront(@enterprise) %shop.darkswarm - if @shopfront_layout == 'embedded' diff --git a/app/views/groups/index.html.haml b/app/views/groups/index.html.haml index dabfd70b6c..1994d30fee 100644 --- a/app/views/groups/index.html.haml +++ b/app/views/groups/index.html.haml @@ -1,7 +1,8 @@ - content_for(:title) do = t :groups_title -= inject_groups +- content_for :injection_data do + = inject_groups #groups.pad-top.footer-pad{"ng-controller" => "GroupsCtrl"} .row diff --git a/app/views/groups/show.html.haml b/app/views/groups/show.html.haml index 48ba7df8b2..76a83fd734 100644 --- a/app/views/groups/show.html.haml +++ b/app/views/groups/show.html.haml @@ -5,7 +5,8 @@ - content_for(:image) do = @group.logo.url -= inject_group_enterprises +- content_for :injection_data do + = inject_group_enterprises #group-page.row.pad-top.footer-pad{"ng-controller" => "GroupPageCtrl"} .small-12.columns.pad-top diff --git a/app/views/layouts/darkswarm.html.haml b/app/views/layouts/darkswarm.html.haml index 79d78c67ea..fd2edfdc54 100644 --- a/app/views/layouts/darkswarm.html.haml +++ b/app/views/layouts/darkswarm.html.haml @@ -14,16 +14,7 @@ = favicon_link_tag "/favicon-staging.ico" %link{href: "https://fonts.googleapis.com/css?family=Roboto:400,300italic,400italic,300,700,700italic|Oswald:300,400,700", rel: "stylesheet", type: "text/css"} - = yield :scripts - %script{:src => "https://js.stripe.com/v3/", :type => "text/javascript"} - %script{src: "//maps.googleapis.com/maps/api/js?libraries=places,geometry#{ ENV['GOOGLE_MAPS_API_KEY'] ? '&key=' + ENV['GOOGLE_MAPS_API_KEY'] : ''} "} = stylesheet_link_tag "darkswarm/all" - = javascript_include_tag "darkswarm/all" - = javascript_include_tag "web/all" - - = render "layouts/i18n_script" - = render "layouts/bugherd_script" - = render "layouts/matomo_tag" = csrf_meta_tags %body{class: body_classes, ng: {app: "Darkswarm"}} @@ -33,14 +24,6 @@ = render "layouts/shopfront_script" if @shopfront_layout - = inject_current_hub - = inject_json "user", "current_user" - = inject_json "railsFlash", "flash" - = inject_taxons - = inject_properties - = inject_current_order - = inject_currency_config - .off-canvas-wrap{offcanvas: true} .inner-wrap = render "shared/menu/menu" unless @hide_menu @@ -50,4 +33,23 @@ #footer %loading + + %script{:src => "https://js.stripe.com/v3/", :type => "text/javascript"} + %script{src: "//maps.googleapis.com/maps/api/js?libraries=places,geometry#{ ENV['GOOGLE_MAPS_API_KEY'] ? '&key=' + ENV['GOOGLE_MAPS_API_KEY'] : ''} "} + = javascript_include_tag "darkswarm/all" + = javascript_include_tag "web/all" + = render "layouts/i18n_script" + = yield :scripts + + = inject_current_hub + = inject_json "user", "current_user" + = inject_json "railsFlash", "flash" + = inject_taxons + = inject_properties + = inject_current_order + = inject_currency_config + = yield :injection_data + + = render "layouts/bugherd_script" + = render "layouts/matomo_tag" = render 'spree/shared/google_analytics' diff --git a/app/views/layouts/registration.html.haml b/app/views/layouts/registration.html.haml index ba4078147c..0221b1ce3a 100644 --- a/app/views/layouts/registration.html.haml +++ b/app/views/layouts/registration.html.haml @@ -10,13 +10,7 @@ = favicon_link_tag "/favicon-staging.ico" %link{href: "https://fonts.googleapis.com/css?family=Roboto:400,300italic,400italic,300,700,700italic|Oswald:300,400,700", rel: "stylesheet", type: "text/css"} - = yield :scripts - %script{src: "//maps.googleapis.com/maps/api/js?libraries=places"} = stylesheet_link_tag "darkswarm/all" - = javascript_include_tag "darkswarm/all" - - = render "layouts/i18n_script" - = render "layouts/bugherd_script" = csrf_meta_tags %body.off-canvas{"ng-app" => "Darkswarm", style: 'background-image: url("/assets/tile-wide.png")' } @@ -24,8 +18,6 @@ = render partial: "shared/ie_warning" = javascript_include_tag "iehack" - = inject_json "user", "current_user" - .off-canvas-wrap{offcanvas: true} .inner-wrap @@ -34,3 +26,13 @@ #footer %loading + + %script{src: "//maps.googleapis.com/maps/api/js?libraries=places"} + = javascript_include_tag "darkswarm/all" + = yield :scripts + + = inject_json "user", "current_user" + = yield :injection_data + + = render "layouts/i18n_script" + = render "layouts/bugherd_script" diff --git a/app/views/map/index.html.haml b/app/views/map/index.html.haml index b66df8429f..48e05d2d0a 100644 --- a/app/views/map/index.html.haml +++ b/app/views/map/index.html.haml @@ -1,7 +1,8 @@ - content_for(:title) do = t :label_map -= inject_enterprise_shopfront_list +- content_for :injection_data do + = inject_enterprise_shopfront_list .map-container{"fill-vertical" => true} %map{"ng-controller" => "MapCtrl"} diff --git a/app/views/producers/index.html.haml b/app/views/producers/index.html.haml index c6b62b2725..c192c12dc3 100644 --- a/app/views/producers/index.html.haml +++ b/app/views/producers/index.html.haml @@ -1,7 +1,8 @@ - content_for(:title) do = t :producers_title -= inject_enterprises(@enterprises) +- content_for :injection_data do + = inject_enterprises(@enterprises) .producers{"ng-controller" => "EnterprisesCtrl", "ng-cloak" => true} .row diff --git a/app/views/registration/index.html.haml b/app/views/registration/index.html.haml index fbfb0c175c..5c2e63f0e4 100644 --- a/app/views/registration/index.html.haml +++ b/app/views/registration/index.html.haml @@ -1,9 +1,10 @@ - content_for(:title) do = t :register_title -= inject_spree_api_key -= inject_available_countries -= inject_enterprise_attributes +- content_for :injection_data do + = inject_spree_api_key + = inject_available_countries + = inject_enterprise_attributes - steps = %w{about contact details finished images introduction} - steps += %w{logo promo social steps type} diff --git a/app/views/shopping_shared/_order_cycles.html.haml b/app/views/shopping_shared/_order_cycles.html.haml index 99483d9a19..7a8fe772f9 100644 --- a/app/views/shopping_shared/_order_cycles.html.haml +++ b/app/views/shopping_shared/_order_cycles.html.haml @@ -1,7 +1,9 @@ -%ordercycle{"ng-controller" => "OrderCycleCtrl"} +- content_for :scripts do :javascript angular.module('Darkswarm').value('orderCycleData', #{render "json/order_cycle"}) +%ordercycle{"ng-controller" => "OrderCycleCtrl"} + - if @order_cycles and @order_cycles.empty? %h4 %i.ofn-i_012-warning diff --git a/app/views/shops/index.html.haml b/app/views/shops/index.html.haml index f38a1c6797..d436b85e5e 100644 --- a/app/views/shops/index.html.haml +++ b/app/views/shops/index.html.haml @@ -1,7 +1,8 @@ - content_for(:title) do = t :shops_title -= inject_enterprises(@enterprises) +- content_for :injection_data do + = inject_enterprises(@enterprises) #panes #shops.pane diff --git a/app/views/spree/orders/edit.html.haml b/app/views/spree/orders/edit.html.haml index 31574b37d3..c05e644fac 100644 --- a/app/views/spree/orders/edit.html.haml +++ b/app/views/spree/orders/edit.html.haml @@ -1,7 +1,8 @@ - content_for(:title) do = t :orders_edit_title -= inject_enterprise_and_relatives +- content_for :injection_data do + = inject_enterprise_and_relatives .darkswarm - content_for :order_cycle_form do diff --git a/app/views/spree/orders/show.html.haml b/app/views/spree/orders/show.html.haml index 24d058db49..5abbc1c2ed 100644 --- a/app/views/spree/orders/show.html.haml +++ b/app/views/spree/orders/show.html.haml @@ -1,7 +1,8 @@ - content_for(:title) do = t :orders_show_title -= inject_enterprise_and_relatives if current_distributor.present? +- content_for :injection_data do + = inject_enterprise_and_relatives if current_distributor.present? .darkswarm = render "shopping_shared/details" if current_distributor.present? diff --git a/app/views/spree/users/show.html.haml b/app/views/spree/users/show.html.haml index 23de4fd744..9b18322f86 100644 --- a/app/views/spree/users/show.html.haml +++ b/app/views/spree/users/show.html.haml @@ -1,12 +1,12 @@ -.darkswarm +- content_for :injection_data do = inject_orders = inject_shops = inject_saved_credit_cards - - if Stripe.publishable_key :javascript angular.module('Darkswarm').value("stripeObject", Stripe("#{Stripe.publishable_key}")) +.darkswarm .row.pad-top .small-12.columns.pad-top %h2