Skip to content

Instantly share code, notes, and snippets.

@jeremy-farrance
Last active January 5, 2022 23:13
Show Gist options
  • Save jeremy-farrance/989bbadd060df970342ad0835f1598a1 to your computer and use it in GitHub Desktop.
Save jeremy-farrance/989bbadd060df970342ad0835f1598a1 to your computer and use it in GitHub Desktop.
2sxc Content/App Enhanced Asset loading (deprecated, pre-v12)
This utility is now deprecated (Dec 2022), leaving it here for reference (public).
Newew version is part of [AccuCUE](https://github.com/Accuraty/AccuCUE) (not public yet) and
is renamed _Assets.cshtml and resides within the 2sxc Content App in /Accu.
--- cut here ---
@using DotNetNuke.Framework.JavaScriptLibraries;
@* original copied from 2sxc/Content/Shared/_Assets.cshtml ~v11.00.03+ and given some TLC
- added fontawesome, copied from 2sxc v13+ 20211229 JDT
- added glide 20210821 JRF
- reduced all @version to major only (e.g. @3.5.7 to just @3) 20210821 JRF
- added a way to request jQuery if needed
- added clipboard-copy 20210612 JRF
- added sweetalerts2 20210527 JRF
- added datatables 20210517 JRF
- insured all CDN assets are .min. and have optimizations
- hard coded path to 2sxc Content-Apps styles and scripts?
- added slickjs 20200804 JRF
>> FontAwesome Pro is on the page thanks to the theme, so we do not add it
>>> Optimize your Asset placement
https://docs.2sxc.org/how-to/output/assets.html
*@
@*
This sub template just places all the very-often used
style and link tags into the code.
We put this in a sub-template because we use it so often, and want to make sure
nobody accidentally uses the wrong url or forgets data-enableoptimizations
*@
@{
string partList = PageData["parts"];
var parts = partList.Split(',').Select(s => ((string)s).ToLower().Trim()).ToArray();
var all = parts.Contains("all");
var styles = all || parts.Contains("styles"); // these are 2sxc Content App stuff
var scripts = all || parts.Contains("scripts"); // these are 2sxc Content App stuff
// not included in `all`
var fancybox = parts.Contains("fancybox");
var glidejs = parts.Contains("glidejs"); // untested
var slickjs = parts.Contains("slickjs");
var sweetalerts = parts.Contains("sweetalerts") || parts.Contains("sweetalerts2");
var datatables = parts.Contains("datatables");
var clipboard = parts.Contains("clipboard");
var fontawesome = parts.Contains("fontawesome");
// var tailwind = parts.Contains("tailwind"); // not recommended to use it this way; https://tailwindcss.com/docs/installation#using-tailwind-via-cdn
@*
<pre>
datatables: @datatables
sweetalerts: @sweetalerts
slickjs: @slickjs
fancybox: @fancybox
</pre>
*@
}
@if (styles)
{
<link rel="stylesheet" href="/Portals/0/2sxc/Content/dist/styles.css"
data-enableoptimizations="true" />
}
@if (scripts)
{
<script type="text/javascript" src="/Portals/0/2sxc/Content/dist/scripts.js"
data-enableoptimizations="true">
</script>
}
@if (glidejs)
{
/// https://glidejs.com/
/// https://github.com/glidejs/glide
<link rel="stylesheet" href="//cdn.jsdelivr.net/npm/glidejs@2/dist/css/glide.core.min.css"
crossorigin="anonymous" data-enableoptimizations="true" >
<script src="//cdn.jsdelivr.net/npm/glidejs@2/dist/glide.min.js"
crossorigin="anonymous" data-enableoptimizations="true" >
</script>
}
@if (fancybox)
{
/// http://fancyapps.com/fancybox/3/
/// https://github.com/fancyapps/fancybox
<link rel="stylesheet" href="//cdn.jsdelivr.net/npm/@("@")fancyapps/fancybox@3/dist/jquery.fancybox.min.css"
integrity="sha256-7qiTu3a8qjjWtcX9w+f2ulVUZSUdCZFEK62eRlmLmCE="
crossorigin="anonymous" data-enableoptimizations="true" >
<script src="//cdn.jsdelivr.net/npm/@("@")fancyapps/fancybox@3/dist/jquery.fancybox.min.js"
integrity="sha256-yt2kYMy0w8AbtF89WXb2P1rfjcP/HTHLT7097U8Y5b8="
crossorigin="anonymous" data-enableoptimizations="true" >
</script>
}
@if (slickjs)
{
/// https://kenwheeler.github.io/slick/
/// https://github.com/kenwheeler/slick/
// needs jQuery so let us insure we have it
JavaScript.RequestRegistration(CommonJs.jQuery);
<link rel="stylesheet" href="//cdn.jsdelivr.net/npm/slick-carousel@1/slick/slick.min.css"
integrity="sha256-3h45mwconzsKjTUULjY+EoEkoRhXcOIU4l5YAw2tSOU="
crossorigin="anonymous" data-enableoptimizations="true" />
<link rel="stylesheet" href="//cdn.jsdelivr.net/npm/slick-carousel@1/slick/slick-theme.min.css"
integrity="sha256-etrwgFLGpqD4oNAFW08ZH9Bzif5ByXK2lXNHKy7LQGo="
crossorigin="anonymous" data-enableoptimizations="150" />
<script type="text/javascript" src="//cdn.jsdelivr.net/npm/slick-carousel@1/slick/slick.min.js"
integrity="sha256-DHF4zGyjT7GOMPBwpeehwoey18z8uiz98G4PRu2lV0A="
crossorigin="anonymous" data-enableoptimizations="200:bottom">
</script>
}
@if (clipboard)
{
/// https://github.com/github/clipboard-copy-element
/// https://github.com/github/clipboard-copy-element/blob/main/examples/index.html
<script defer="defer" src="//unpkg.com/@("@")github/clipboard-copy-element@latest" data-enableoptimizations="true">
</script>
}
@if (sweetalerts)
{
/// https://sweetalert2.github.io/
/// https://github.com/sweetalert2/sweetalert2
<link rel="stylesheet" href="//cdn.jsdelivr.net/npm/sweetalert2@11/dist/sweetalert2.min.css"
data-enableoptimizations="true">
<script src="//cdn.jsdelivr.net/npm/sweetalert2@11/dist/sweetalert2.min.js"
data-enableoptimizations="true">
</script>
}
@if (datatables)
{
/// https://datatables.net/
/// ht tps://github.com/DataTables/DataTables
<link rel="stylesheet" href="//cdn.datatables.net/1.10.25/css/dataTables.bootstrap4.min.css"
data-enableoptimizations="true">
<script src="//cdn.datatables.net/1.10.25/js/jquery.dataTables.min.js"
data-enableoptimizations="true">
</script>
<script src="//cdn.datatables.net/1.10.25/js/dataTables.bootstrap4.min.js"
data-enableoptimizations="true">
</script>
}
@if (fontawesome)
{
/// https://fontawesome.com/
<script defer async
src="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/5.15.3/js/all.min.js"
integrity="sha512-RXf+QSDCUQs5uwRKaDoXt55jygZZm2V++WUZduaU/Ui/9EGp3f/2KZVahFZBKGH0s774sd3HmrhUy+SgOFQLVQ=="
crossorigin="anonymous"
referrerpolicy="no-referrer"
>
</script>
}
@*
@if (tailwind)
{
/// https://tailwindcss.com/docs/installation#using-tailwind-via-cdn
/// https://github.com/tailwindlabs/tailwindcss
<link rel="stylesheet" href="//unpkg.com/tailwindcss@("@")^2/dist/tailwind.min.css"
data-enableoptimizations="true">
}
*@
@jeremy-farrance
Copy link
Author

This utility is now deprecated (Dec 2022), leaving it here for reference (public).

Newew version is part of AccuCUE (not public yet) and
is renamed _Assets.cshtml and resides within the 2sxc Content App in /Accu.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment