Set up bundling and move blog JS to JS file.

This commit is contained in:
Robert Marshall 2020-04-04 12:50:20 +01:00
parent 1b13e22bce
commit a375a4356a
6 changed files with 15 additions and 11 deletions

View file

@ -8,6 +8,4 @@
@Html.Raw(Model.ContentHtml) @Html.Raw(Model.ContentHtml)
</article> </article>
<small>Posted on @Model.Timestamp</small> <small>Posted on @Model.Timestamp</small>
<partial name="_BlogImageJs" />

View file

@ -20,6 +20,4 @@
@if (Model.Page < Model.MaxPages) { @if (Model.Page < Model.MaxPages) {
<a href="/blog/page/@(Model.Page + 1)" class="round-button blog-navigation__next"><img src="/images/next.svg" alt="Next"/></a> <a href="/blog/page/@(Model.Page + 1)" class="round-button blog-navigation__next"><img src="/images/next.svg" alt="Next"/></a>
} }
</div> </div>
<partial name="_BlogImageJs" />

View file

@ -5,6 +5,7 @@
<meta name="viewport" content="width=device-width, initial-scale=1.0" /> <meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>@ViewData["Title"] | Robware</title> <title>@ViewData["Title"] | Robware</title>
<link href="/css/style.css" rel="stylesheet" defer/> <link href="/css/style.css" rel="stylesheet" defer/>
<script type="text/javascript" src="/js/javascript.min.js"></script>
</head> </head>
<body> <body>
<header class="header"> <header class="header">

View file

@ -2,7 +2,8 @@
{ {
"outputFileName": "wwwroot/js/javascript.min.js", "outputFileName": "wwwroot/js/javascript.min.js",
"inputFiles": [ "inputFiles": [
"wwwroot/js/javascript.js" "wwwroot/js/javascript.js",
"wwwroot/js/blog.js"
], ],
"minify": { "minify": {
"enabled": true, "enabled": true,

View file

@ -1,4 +1,4 @@
<script type="text/javascript"> documentReady(() => {
function adornImage(image, append) { function adornImage(image, append) {
var parent = image.parentNode; var parent = image.parentNode;
parent.removeChild(image); parent.removeChild(image);
@ -23,7 +23,6 @@
parent.prepend(containerContainer); parent.prepend(containerContainer);
} }
document.querySelectorAll("p>img:only-child,p>img:first-child").forEach(image => adornImage(image, false)); document.querySelectorAll("p>img:only-child,p>img:first-child").forEach(image => adornImage(image, false));
document.querySelectorAll("p>img:last-child").forEach(image => adornImage(image, true)); document.querySelectorAll("p>img:last-child").forEach(image => adornImage(image, true));
</script> });

View file

@ -57,4 +57,11 @@ Number.prototype.toString=function(input, shouldRound){
return this.oldToString(input); return this.oldToString(input);
return round(this, input); return round(this, input);
}; };
function documentReady(callback) {
if (document.readyState === "complete" || document.readyState === "interactive")
setTimeout(callback, 1);
else
document.addEventListener("DOMContentLoaded", callback);
}