|
|
@ -78,9 +78,19 @@ |
|
|
|
|
|
|
|
<div class="row"> |
|
|
|
<div class="col-md-8 col-12"> |
|
|
|
<div class="card"> |
|
|
|
<div id="previewPost"></div> |
|
|
|
<div class="blogPost"> |
|
|
|
<div id=POST_PICTURE> |
|
|
|
</div> |
|
|
|
|
|
|
|
<div class="p-4"> |
|
|
|
<b><h3 id="POST_TITLE"></h3></b> |
|
|
|
<h5> |
|
|
|
<span class="w3-opacity"><div id="POST_PUBLISHED"></div></span> |
|
|
|
</h5> |
|
|
|
<div id="POST_BODY"></div> |
|
|
|
</div> |
|
|
|
</div> |
|
|
|
<br> |
|
|
|
<br><br> |
|
|
|
</div> |
|
|
|
<div class="col-md-4 col-12"> |
|
|
@ -95,7 +105,9 @@ |
|
|
|
|
|
|
|
<script type="text/javascript"> |
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
* Runs a get request using ajax |
|
|
|
*/ |
|
|
|
function runAjax(url, successCallBack, errorCallBack) |
|
|
|
{ |
|
|
|
console.log(url); |
|
|
@ -110,6 +122,83 @@ |
|
|
|
}); |
|
|
|
} |
|
|
|
|
|
|
|
/** Lazy loads youtube videos on the page |
|
|
|
*/ |
|
|
|
function lazyLoad() |
|
|
|
{ |
|
|
|
var youtube = document.querySelectorAll( ".youtube" ); |
|
|
|
|
|
|
|
for (var i = 0; i < youtube.length; i++) { |
|
|
|
|
|
|
|
var source = "https://img.youtube.com/vi/"+ youtube[i].dataset.embed +"/sddefault.jpg"; |
|
|
|
|
|
|
|
var image = new Image(); |
|
|
|
image.src = source; |
|
|
|
image.addEventListener( "load", function() { |
|
|
|
youtube[ i ].appendChild( image ); |
|
|
|
}( i ) ); |
|
|
|
|
|
|
|
youtube[i].addEventListener( "click", function() { |
|
|
|
|
|
|
|
var iframe = document.createElement( "iframe" ); |
|
|
|
|
|
|
|
iframe.setAttribute( "frameborder", "0" ); |
|
|
|
iframe.setAttribute( "allowfullscreen", "" ); |
|
|
|
iframe.setAttribute( "src", "https://www.youtube.com/embed/"+ this.dataset.embed +"?rel=0&showinfo=0&autoplay=1" ); |
|
|
|
|
|
|
|
this.innerHTML = ""; |
|
|
|
this.appendChild( iframe ); |
|
|
|
} ); |
|
|
|
}; |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
function renderPostOnPage(postID) |
|
|
|
{ |
|
|
|
runAjax("api/render/" + postID, |
|
|
|
(html)=> |
|
|
|
{ |
|
|
|
//uses ajax to update blog page |
|
|
|
$('#POST_TITLE').text(html.name); |
|
|
|
$('#POST_PUBLISHED').text(html.published); |
|
|
|
$('#POST_BODY').html(html.blogBody); |
|
|
|
$('#POST_PICTURE').html(html.hasPicture ? |
|
|
|
'<img src="/blogContent/headerImages/' + html.picture_url + '" style="width:100%;">' : |
|
|
|
''); |
|
|
|
|
|
|
|
//lazy loads youtube videos |
|
|
|
lazyLoad(); |
|
|
|
|
|
|
|
//highlights code |
|
|
|
document.querySelectorAll('pre code').forEach((block) => { |
|
|
|
hljs.highlightBlock(block); |
|
|
|
}); |
|
|
|
//renders latex math |
|
|
|
MathJax.Hub.Queue(["Typeset",MathJax.Hub]); |
|
|
|
}, |
|
|
|
(err)=> |
|
|
|
{ |
|
|
|
console.log(err); |
|
|
|
}); |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
* After a timeline event gets clicked this will |
|
|
|
* query the api for the blog post content and |
|
|
|
* display it on the page. |
|
|
|
*/ |
|
|
|
function timeLineClick(properties) |
|
|
|
{ |
|
|
|
if(properties.item !== null) |
|
|
|
{ |
|
|
|
renderPostOnPage(properties.item); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
/** |
|
|
|
* Fetches all the |
|
|
|
*/ |
|
|
|
function fetchPosts() |
|
|
|
{ |
|
|
|
return new Promise((resolve, reject)=> |
|
|
@ -123,11 +212,13 @@ |
|
|
|
datasetContents.push( |
|
|
|
{ |
|
|
|
start: new Date(data[i].published), |
|
|
|
content: data[i].name |
|
|
|
content: data[i].name, |
|
|
|
id: data[i].post_id |
|
|
|
} |
|
|
|
); |
|
|
|
} |
|
|
|
resolve(datasetContents); |
|
|
|
renderPostOnPage(data[0].post_id); |
|
|
|
}, |
|
|
|
(error)=> |
|
|
|
{ |
|
|
@ -156,6 +247,7 @@ |
|
|
|
|
|
|
|
var items = new vis.DataSet(data); |
|
|
|
var timeline = new vis.Timeline(container, items, options); |
|
|
|
timeline.on('click', timeLineClick); |
|
|
|
}); |
|
|
|
}); |
|
|
|
|
|
|
|