Skip to content

Commit

Permalink
Added script for opening embeded pdf on page load
Browse files Browse the repository at this point in the history
If the url has a file specified as argument
  • Loading branch information
matiboux committed Nov 26, 2019
1 parent 574fa21 commit da79996
Showing 1 changed file with 7 additions and 2 deletions.
9 changes: 7 additions & 2 deletions _assets/js/script.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,13 @@ $(document).ready(function() {
$link.addClass('active');

/** Epidocs / Past-Exams JS */

$('.embed').click(function(e) {
e.preventDefault();

var $this = $(this);
var url = $this.attr('href').replace(/#/g, '%23'); // Encode all '#' characters
// console.log(url);

loadPdfEmbed($this.text(), url, $this);

history.pushState({embedUrl: url}, $this.text(), "?" + url.substr(url.lastIndexOf('/') + 1));
Expand All @@ -27,6 +27,11 @@ $(document).ready(function() {
window.onpopstate = function(e) {
$('#embed').hide();
};

// Check if an embeded pdf should be opened
var matches = window.location.href.match(/(.+)\?(.+\..+)&?/);
if(matches)
$('.embed[href="' + matches[1] + matches[2] + '"]').click();
});

function loadPdfEmbed(title, url, $this) {
Expand Down

0 comments on commit da79996

Please sign in to comment.