Skip to content

Commit 2bace01

Browse files
committed
Merge branch 'maintenance/JavaScript-cleanup' into develop
Significant refactoring and cleanup of JavaScript files and dependencies in order to reduce the payload and improve both maintenance and performance. Functionality - Established new `InlineScript` section and moved all inline scripts to it; this ensures scripts don't fire until the DOM is ready (efd1931) - Ensured all sidecar scripts relying on JavaScript waited for `$(document).ready()`—this was missing for most view-based scripts (b29ce46) Performance - Imported each Foundation plugin individually, instead of as a comprehensive bundle, thus reducing the overall payload (5705a4c, a694fbd) - Marked (nearly) all JavaScript references as `defer` so that they aren't blocking the initial page rendering (569509f, 844b5bc) - Imported only the DASH Media Player, instead of the comprehensive bundle, thus reducing the payload by a small amount (cc34e1b) - Moved Application Insights into a local file so it can be aggressively cached and to reduce the inline code (a4eef2d, 07f344a) Removal - Removed legacy Headroom and Simple Pagination (1437040, 787b325, 1e81bed) - Removed legacy Image Zoom capabilities, which are not currently used on the site (2039e6a) - Removed legacy full-height pane JavaScript and CSS, a feature originally used on the homepage (1042d7e) Refactoring - Refactored search script into external file structured as a jQuery plugin (3409dfe, c102a8c) - Refactored slideshow script into external file structured as a jQuery plugin (086da48) - Standardized Immediately Invoked Function Expressions (IIFE) across most scripts (1d26094)
2 parents 323d8dd + 1042d7e commit 2bace01

36 files changed

+600
-616
lines changed

Areas/Administration/Views/Invoices/Edit.cshtml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@
5757

5858
@section Scripts {
5959
@{await Html.RenderPartialAsync("_ValidationScriptsPartial");}
60-
<script src="~/Shared/Scripts/Views/LicenseAdministration.js"></script>
60+
<script defer src="~/Shared/Scripts/Views/LicenseAdministration.js"></script>
6161
}
6262

6363
@section CallsToActionSection {}

Areas/Administration/Views/Invoices/Index.cshtml

Lines changed: 12 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -70,17 +70,18 @@
7070
}
7171

7272
@section Scripts {
73-
<script src="//cdn.datatables.net/1.10.11/js/jquery.dataTables.min.js"></script>
74-
<script src="~/Shared/Scripts/Views/Administration.js"></script>
75-
<script>
76-
$('table[id*="Records"]').DataTable({
77-
pageLength : 75,
78-
//'paging' : false,
79-
lengthMenu : [[10, 25, 50, -1], [10, 25, 50, "All"]],
80-
order : [[1, 'desc']],
81-
stateSave : false
82-
});
83-
</script>
73+
<script defer src="//cdn.datatables.net/1.10.11/js/jquery.dataTables.min.js"></script>
74+
<script defer src="~/Shared/Scripts/Views/Administration.js"></script>
75+
}
76+
77+
@section InlineScript {
78+
$('table[id*="Records"]').DataTable({
79+
pageLength : 75,
80+
//'paging' : false,
81+
lengthMenu : [[10, 25, 50, -1], [10, 25, 50, "All"]],
82+
order : [[1, 'desc']],
83+
stateSave : false
84+
});
8485
}
8586

8687
@section CallsToActionSection {}

Areas/Administration/Views/Licenses/Index.cshtml

Lines changed: 12 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -76,17 +76,18 @@
7676
}
7777

7878
@section Scripts {
79-
<script src="//cdn.datatables.net/1.10.11/js/jquery.dataTables.min.js"></script>
80-
<script src="~/Shared/Scripts/Views/Administration.js"></script>
81-
<script>
82-
$('table[id*="Records"]').DataTable({
83-
pageLength : 75,
84-
//'paging' : false,
85-
lengthMenu : [[10, 25, 50, -1], [10, 25, 50, "All"]],
86-
order : [[4, 'asc']],
87-
stateSave : false
88-
});
89-
</script>
79+
<script defer src="//cdn.datatables.net/1.10.11/js/jquery.dataTables.min.js"></script>
80+
<script defer src="~/Shared/Scripts/Views/Administration.js"></script>
81+
}
82+
83+
@section InlineScript {
84+
$('table[id*="Records"]').DataTable({
85+
pageLength : 75,
86+
//'paging' : false,
87+
lengthMenu : [[10, 25, 50, -1], [10, 25, 50, "All"]],
88+
order : [[4, 'asc']],
89+
stateSave : false
90+
});
9091
}
9192

9293
@section CallsToActionSection {}

Areas/Forms/Views/Layout/_Layout.cshtml

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,8 +38,12 @@
3838

3939
@RenderSection("Scripts", required: false)
4040

41-
<script type="text/javascript" src="~/Shared/Scripts/Views/Forms.js"></script>
41+
<script defer type="text/javascript" src="~/Shared/Scripts/Views/Forms.js" asp-append-version="true"></script>
4242

4343
}
4444

45+
@section InlineScript {
46+
@RenderSection("InlineScript", required: false)
47+
}
48+
4549
@section CallsToActionSection {}

Areas/Forms/Views/Purchase.cshtml

Lines changed: 35 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -64,48 +64,44 @@
6464

6565
}
6666

67-
@section Scripts {
68-
<script>
69-
$(document).ready(function () {
67+
@section InlineScript {
7068

71-
/*------------------------------------------------------------------------------------------------------------------------
72-
| Establish default state
73-
\-----------------------------------------------------------------------------------------------------------------------*/
74-
$("#UserContactForm :input").prop("disabled", true);
75-
$("#PurchaseOrderForm :input").prop("disabled", true);
76-
$("#AccountsPayableForm :input").prop("disabled", true);
69+
/*------------------------------------------------------------------------------------------------------------------------
70+
| Establish default state
71+
\-----------------------------------------------------------------------------------------------------------------------*/
72+
$("#UserContactForm :input").prop("disabled", true);
73+
$("#PurchaseOrderForm :input").prop("disabled", true);
74+
$("#AccountsPayableForm :input").prop("disabled", true);
7775

78-
/*------------------------------------------------------------------------------------------------------------------------
79-
| Handle payment information
80-
\-----------------------------------------------------------------------------------------------------------------------*/
81-
$("input[name='Licensee']").click(function () {
82-
$("#UserContactForm :input").prop("disabled", $(this).val() == "Myself");
83-
});
76+
/*------------------------------------------------------------------------------------------------------------------------
77+
| Handle payment information
78+
\-----------------------------------------------------------------------------------------------------------------------*/
79+
$("input[name='Licensee']").click(function () {
80+
$("#UserContactForm :input").prop("disabled", $(this).val() == "Myself");
81+
});
8482

85-
/*------------------------------------------------------------------------------------------------------------------------
86-
| Handle payment information
87-
\-----------------------------------------------------------------------------------------------------------------------*/
88-
$("input[name='PaymentMethod']").click(function () {
89-
var instructions = $("#PaymentInstructions");
90-
var purchaseOrderForm = $("#PurchaseOrderForm :input").prop("disabled", true);
91-
var accountsPayableForm = $("#AccountsPayableForm :input").prop("disabled", true);
83+
/*------------------------------------------------------------------------------------------------------------------------
84+
| Handle payment information
85+
\-----------------------------------------------------------------------------------------------------------------------*/
86+
$("input[name='PaymentMethod']").click(function () {
87+
var instructions = $("#PaymentInstructions");
88+
var purchaseOrderForm = $("#PurchaseOrderForm :input").prop("disabled", true);
89+
var accountsPayableForm = $("#AccountsPayableForm :input").prop("disabled", true);
9290

93-
instructions.html("If paying by invoice, Purchase Order and Accounts Payable information must be filled out below.");
94-
switch ($(this).val()) {
95-
case "Invoice":
96-
purchaseOrderForm.prop("disabled", false);
97-
break;
98-
case "AccountsPayable":
99-
purchaseOrderForm.prop("disabled", false);
100-
accountsPayableForm.prop("disabled", false);
101-
break;
102-
case "CreditCard":
103-
instructions.html("There is a 2.9% fee when paying by credit card (this is not greater than our cost of acceptance). We will send a URL for entering credit card information.");
104-
break;
105-
}
106-
instructions.show();
107-
});
91+
instructions.html("If paying by invoice, Purchase Order and Accounts Payable information must be filled out below.");
92+
switch ($(this).val()) {
93+
case "Invoice":
94+
purchaseOrderForm.prop("disabled", false);
95+
break;
96+
case "AccountsPayable":
97+
purchaseOrderForm.prop("disabled", false);
98+
accountsPayableForm.prop("disabled", false);
99+
break;
100+
case "CreditCard":
101+
instructions.html("There is a 2.9% fee when paying by credit card (this is not greater than our cost of acceptance). We will send a URL for entering credit card information.");
102+
break;
103+
}
104+
instructions.show();
105+
});
108106

109-
});
110-
</script>
111107
}

Areas/Forms/Views/Training.cshtml

Lines changed: 35 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -40,48 +40,44 @@
4040

4141
}
4242

43-
@section Scripts {
44-
<script>
45-
$(document).ready(function () {
43+
@section InlineScript {
4644

47-
/*------------------------------------------------------------------------------------------------------------------------
48-
| Establish default state
49-
\-----------------------------------------------------------------------------------------------------------------------*/
50-
$("#UserContactForm :input").prop("disabled", true);
51-
$("#PurchaseOrderForm :input").prop("disabled", true);
52-
$("#AccountsPayableForm :input").prop("disabled", true);
45+
/*------------------------------------------------------------------------------------------------------------------------
46+
| Establish default state
47+
\-----------------------------------------------------------------------------------------------------------------------*/
48+
$("#UserContactForm :input").prop("disabled", true);
49+
$("#PurchaseOrderForm :input").prop("disabled", true);
50+
$("#AccountsPayableForm :input").prop("disabled", true);
5351

54-
/*------------------------------------------------------------------------------------------------------------------------
55-
| Handle payment information
56-
\-----------------------------------------------------------------------------------------------------------------------*/
57-
$("input[name='Licensee']").click(function () {
58-
$("#UserContactForm :input").prop("disabled", $(this).val() == "Myself");
59-
});
52+
/*------------------------------------------------------------------------------------------------------------------------
53+
| Handle payment information
54+
\-----------------------------------------------------------------------------------------------------------------------*/
55+
$("input[name='Licensee']").click(function () {
56+
$("#UserContactForm :input").prop("disabled", $(this).val() == "Myself");
57+
});
6058

61-
/*------------------------------------------------------------------------------------------------------------------------
62-
| Handle payment information
63-
\-----------------------------------------------------------------------------------------------------------------------*/
64-
$("input[name='PaymentMethod']").click(function () {
65-
var instructions = $("#PaymentInstructions");
66-
var purchaseOrderForm = $("#PurchaseOrderForm :input").prop("disabled", true);
67-
var accountsPayableForm = $("#AccountsPayableForm :input").prop("disabled", true);
59+
/*------------------------------------------------------------------------------------------------------------------------
60+
| Handle payment information
61+
\-----------------------------------------------------------------------------------------------------------------------*/
62+
$("input[name='PaymentMethod']").click(function () {
63+
var instructions = $("#PaymentInstructions");
64+
var purchaseOrderForm = $("#PurchaseOrderForm :input").prop("disabled", true);
65+
var accountsPayableForm = $("#AccountsPayableForm :input").prop("disabled", true);
6866

69-
instructions.html("If paying by invoice, Purchase Order and Accounts Payable information must be filled out below.");
70-
switch ($(this).val()) {
71-
case "Invoice":
72-
purchaseOrderForm.prop("disabled", false);
73-
break;
74-
case "AccountsPayable":
75-
purchaseOrderForm.prop("disabled", false);
76-
accountsPayableForm.prop("disabled", false);
77-
break;
78-
case "CreditCard":
79-
instructions.html("There is a 2.9% fee when paying by credit card (this is not greater than our cost of acceptance). We will send a URL for entering credit card information.");
80-
break;
81-
}
82-
instructions.show();
83-
});
67+
instructions.html("If paying by invoice, Purchase Order and Accounts Payable information must be filled out below.");
68+
switch ($(this).val()) {
69+
case "Invoice":
70+
purchaseOrderForm.prop("disabled", false);
71+
break;
72+
case "AccountsPayable":
73+
purchaseOrderForm.prop("disabled", false);
74+
accountsPayableForm.prop("disabled", false);
75+
break;
76+
case "CreditCard":
77+
instructions.html("There is a 2.9% fee when paying by credit card (this is not greater than our cost of acceptance). We will send a URL for entering credit card information.");
78+
break;
79+
}
80+
instructions.show();
81+
});
8482

85-
});
86-
</script>
8783
}

Areas/Forms/Views/Trial.cshtml

Lines changed: 14 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -55,22 +55,18 @@
5555

5656
}
5757

58-
@section Scripts {
59-
<script>
60-
$(document).ready(function () {
61-
62-
/*------------------------------------------------------------------------------------------------------------------------
63-
| Establish default state
64-
\-----------------------------------------------------------------------------------------------------------------------*/
65-
$("#TrainerContactForm :input").prop("disabled", true);
66-
67-
/*------------------------------------------------------------------------------------------------------------------------
68-
| Handle trainer form
69-
\-----------------------------------------------------------------------------------------------------------------------*/
70-
$("input[name='IsTrainingCourse']").click(function () {
71-
$("#TrainerContactForm :input").prop("disabled", !$(this).is(":checked"));
72-
});
73-
74-
});
75-
</script>
58+
@section InlineScript {
59+
60+
/*------------------------------------------------------------------------------------------------------------------------
61+
| Establish default state
62+
\-----------------------------------------------------------------------------------------------------------------------*/
63+
$("#TrainerContactForm :input").prop("disabled", true);
64+
65+
/*------------------------------------------------------------------------------------------------------------------------
66+
| Handle trainer form
67+
\-----------------------------------------------------------------------------------------------------------------------*/
68+
$("input[name='IsTrainingCourse']").click(function () {
69+
$("#TrainerContactForm :input").prop("disabled", !$(this).is(":checked"));
70+
});
71+
7672
}

Areas/Forms/Views/UserConference.cshtml

Lines changed: 22 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -92,34 +92,30 @@
9292

9393
}
9494

95-
@section Scripts {
96-
<script>
97-
$(document).ready(function () {
95+
@section InlineScript {
9896

99-
/*------------------------------------------------------------------------------------------------------------------------
100-
| Establish default state
101-
\-----------------------------------------------------------------------------------------------------------------------*/
102-
var instructions = $("#PaymentInstructions");
103-
var purchaseOrderForm = $("#@Html.IdFor(m => m.BindingModel.PurchaseOrderNumber)").prop("disabled", true);
97+
/*------------------------------------------------------------------------------------------------------------------------
98+
| Establish default state
99+
\-----------------------------------------------------------------------------------------------------------------------*/
100+
var instructions = $("#PaymentInstructions");
101+
var purchaseOrderForm = $("#@Html.IdFor(m => m.BindingModel.PurchaseOrderNumber)").prop("disabled", true);
104102

105-
/*------------------------------------------------------------------------------------------------------------------------
106-
| Handle payment information
107-
\-----------------------------------------------------------------------------------------------------------------------*/
108-
$("input[name='PaymentMethod']").click(function () {
103+
/*------------------------------------------------------------------------------------------------------------------------
104+
| Handle payment information
105+
\-----------------------------------------------------------------------------------------------------------------------*/
106+
$("input[name='PaymentMethod']").click(function () {
107+
purchaseOrderForm.prop("disabled", true);
108+
switch ($(this).val()) {
109+
case "Invoice":
110+
purchaseOrderForm.prop("disabled", false);
111+
instructions.html("");
112+
break;
113+
case "CreditCard":
109114
purchaseOrderForm.prop("disabled", true);
110-
switch ($(this).val()) {
111-
case "Invoice":
112-
purchaseOrderForm.prop("disabled", false);
113-
instructions.html("");
114-
break;
115-
case "CreditCard":
116-
purchaseOrderForm.prop("disabled", true);
117-
instructions.html("If paying by credit card, call 1-425-295-6985 (-8 hours GMT) or fax 1-425-642-8073 to complete transaction.");
118-
break;
119-
}
120-
instructions.show();
121-
});
115+
instructions.html("If paying by credit card, call 1-425-295-6985 (-8 hours GMT) or fax 1-425-642-8073 to complete transaction.");
116+
break;
117+
}
118+
instructions.show();
119+
});
122120

123-
});
124-
</script>
125121
}

Areas/Payments/Views/ContentTypes/Payments.cshtml

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -121,18 +121,18 @@
121121
@{await Html.RenderPartialAsync("_ValidationScriptsPartial");}
122122

123123
<!-- Braintree -->
124-
<script src="https://js.braintreegateway.com/web/3.39.0/js/client.min.js"></script>
125-
<script src="https://js.braintreegateway.com/web/3.39.0/js/hosted-fields.min.js"></script>
126-
<script src="~/Shared/Scripts/Views/Payments.js" asp-append-version="true"></script>
127-
<script src="~/Shared/Scripts/Views/Forms.js" asp-append-version="true"></script>
124+
<script defer src="https://js.braintreegateway.com/web/3.39.0/js/client.min.js"></script>
125+
<script defer src="https://js.braintreegateway.com/web/3.39.0/js/hosted-fields.min.js"></script>
126+
<script defer src="~/Shared/Scripts/Views/Payments.js" asp-append-version="true"></script>
127+
<script defer src="~/Shared/Scripts/Views/Forms.js" asp-append-version="true"></script>
128128

129-
<script>
129+
}
130130

131-
/**
132-
* Initializes the Braintree Javascript v3 SDK and dynamically creates the primary Braintree form fields.
133-
*/
134-
executeBraintree("@Model.ClientToken");
131+
@section InlineScript {
135132

136-
</script>
133+
/**
134+
* Initializes the Braintree Javascript v3 SDK and dynamically creates the primary Braintree form fields.
135+
*/
136+
executeBraintree("@Model.ClientToken");
137137

138138
}

0 commit comments

Comments
 (0)