Skip to content

Commit

Permalink
check for existing uswds 2.10.0 via uswdsPresent
Browse files Browse the repository at this point in the history
  • Loading branch information
ryanwoldatwork committed Sep 28, 2022
1 parent 77912c8 commit 55c86ed
Show file tree
Hide file tree
Showing 8 changed files with 32 additions and 7 deletions.
9 changes: 8 additions & 1 deletion app/assets/javascripts/uswds-modal-include.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,11 @@
(function(){function r(e,n,t){function o(i,f){if(!n[i]){if(!e[i]){var c="function"==typeof require&&require;if(!f&&c)return c(i,!0);if(u)return u(i,!0);var a=new Error("Cannot find module '"+i+"'");throw a.code="MODULE_NOT_FOUND",a}var p=n[i]={exports:{}};e[i][0].call(p.exports,function(r){var n=e[i][1][r];return o(n||r)},p,p.exports,r,e,n,t)}return n[i].exports}for(var u="function"==typeof require&&require,i=0;i<t.length;i++)o(t[i]);return o}return r})()({1:[function(require,module,exports){
"use strict";

if (window.uswdsPresent) {
console.log("USWDS 2.10.0+ detected")
return true; // and don't proceed to load USWDS again
}

/*
* classList.js: Cross-browser full element.classList implementation.
* 1.1.20170427
Expand Down Expand Up @@ -4625,7 +4630,9 @@ function toggleModal(event) {


returnFocus.focus();
modal.focusTrap.update(safeActive);
if (modal.focusTrap) {
modal.focusTrap.update(safeActive);
}
}

return safeActive;
Expand Down
2 changes: 2 additions & 0 deletions app/controllers/admin/forms_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -474,6 +474,7 @@ def form_params
:department,
:bureau,
:load_css,
:load_uswds_js,
:ui_truncate_text_responses,
:question_text_01,
:question_text_02,
Expand Down Expand Up @@ -520,6 +521,7 @@ def form_admin_options_params
:status,
:title,
:load_css,
:load_uswds_js,
:omb_approval_number,
:expiration_date,
:service_id,
Expand Down
9 changes: 8 additions & 1 deletion app/views/admin/forms/_admin_options.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -77,12 +77,19 @@
</div>
</fieldset>
<fieldset class="usa-fieldset">
<legend class="usa-sr-only">Load USWDS</legend>
<legend class="usa-sr-only">Load USWDS CSS</legend>
<div class="usa-checkbox">
<%= f.check_box :load_css, class: "usa-checkbox__input" %>
<%= f.label :load_css, "Load USWDS CSS - note: use if your site does not implement USWDS styling.", class: "usa-checkbox__label" %>
</div>
</fieldset>
<fieldset class="usa-fieldset">
<legend class="usa-sr-only">Load USWDS Javascript</legend>
<div class="usa-checkbox">
<%= f.check_box :load_uswds_js, class: "usa-checkbox__input" %>
<%= f.label :load_uswds_js, "Load USWDS .js - note: use if your site does not implement USWDS javascript.", class: "usa-checkbox__label" %>
</div>
</fieldset>
</div>
</div>
<br>
Expand Down
1 change: 1 addition & 0 deletions app/views/admin/forms/example.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
min-height: 300px;
}
</style>
<%#= stylesheet_link_tag 'application', media: 'all', integrity: true %>
<!-- End demo content styles -->

<%= favicon_link_tag asset_path('favicon.ico') %>
Expand Down
2 changes: 1 addition & 1 deletion app/views/components/widget/_fba.js.erb
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
// Form components are namespaced under 'fba' = 'Feedback Analytics'
'use strict';

<% unless form.delivery_method == 'touchpoints-hosted-only' %>
<% unless form.delivery_method == 'touchpoints-hosted-only' || form.load_uswds_js == false %>
<%= raw File.open("#{Rails.root}/app/assets/javascripts/uswds-modal-include.js").read %>
<% end %>

Expand Down
7 changes: 7 additions & 0 deletions db/migrate/20220927213503_load_uswds_js.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
class LoadUswdsJs < ActiveRecord::Migration[7.0]
def change
add_column :forms, :load_uswds_js, :boolean, default: true

Form.update_all(load_uswds_js: true)
end
end
3 changes: 2 additions & 1 deletion db/schema.rb
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
#
# It's strongly recommended that you check this file into your version control system.

ActiveRecord::Schema[7.0].define(version: 2022_09_19_233730) do
ActiveRecord::Schema[7.0].define(version: 2022_09_27_213503) do
# These are extensions that must be enabled in order to support this database
enable_extension "plpgsql"

Expand Down Expand Up @@ -195,6 +195,7 @@
t.string "notification_frequency", default: "instant"
t.integer "service_id"
t.integer "questions_count", default: 0
t.boolean "load_uswds_js", default: true
t.index ["legacy_touchpoint_id"], name: "index_forms_on_legacy_touchpoint_id"
t.index ["legacy_touchpoint_uuid"], name: "index_forms_on_legacy_touchpoint_uuid"
t.index ["organization_id"], name: "index_forms_on_organization_id"
Expand Down
6 changes: 3 additions & 3 deletions db/seeds.rb
Original file line number Diff line number Diff line change
Expand Up @@ -324,7 +324,7 @@ def production_suitable_seeds
is_required: false,
})

open_ended_form_with_contact_information = Form.create({
open_ended_form_with_contact_information = Form.create!({
organization: example_gov,
template: true,
kind: 'open ended with contact information',
Expand Down Expand Up @@ -352,7 +352,7 @@ def production_suitable_seeds
form_section: open_ended_form_with_contact_information.form_sections.first,
text: 'Name',
question_type: 'text_field',
position: 1,
position: 2,
answer_field: :answer_02,
is_required: false,
})
Expand All @@ -361,7 +361,7 @@ def production_suitable_seeds
form_section: open_ended_form_with_contact_information.form_sections.first,
text: 'Email',
question_type: 'text_field',
position: 2,
position: 3,
answer_field: :answer_03,
is_required: false,
})
Expand Down

0 comments on commit 55c86ed

Please sign in to comment.