Skip to content

Commit

Permalink
fix: #3. reveal-header works with embed-resources now
Browse files Browse the repository at this point in the history
  • Loading branch information
shafayetShafee committed Feb 15, 2023
1 parent ac0106a commit 77bade5
Show file tree
Hide file tree
Showing 229 changed files with 6,452 additions and 14,435 deletions.
2 changes: 1 addition & 1 deletion _extensions/reveal-header/_extension.yml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
title: Reveal-header
author: Shafayet Khan Shafee
version: 1.1.0
version: 1.2.0
quarto-required: ">=1.2.0"
contributes:
filters:
Expand Down
142 changes: 75 additions & 67 deletions _extensions/reveal-header/resources/js/add_header.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,76 +6,84 @@
* Copyright (c) 2023 Shafayet Khan Shafee.
*/

function add_header() {
let header = document.querySelector("div.reveal-header");
let reveal = document.querySelector(".reveal");
reveal.insertBefore(header, reveal.firstChild);
function header() {

logo_img = document.querySelector('.header-logo img');
if (logo_img.getAttribute('src') == null) {
if (logo_img?.getAttribute('data-src') != null) {
logo_img.src = logo_img?.getAttribute('data-src') || "";
logo_img.removeAttribute('data-src');
}
}
}

window.onload = add_header();

// Reveal API

// Get the default header text element and innner HTML (i.e. literal text)
let header_text = document.querySelector("div.header-text p");
const header_inner_html = header_text.innerHTML;

// add the class inverse-header for slide with has-dark-background class
// otherwise remove it.
function add_class(has_dark, header_paras) {
header_paras.forEach(el => {
el.classList.remove('inverse-header');
if(has_dark) {
el.classList.add('inverse-header');
// add the header structure as the firstChild of div.reveal-header
function add_header() {
let header = document.querySelector("div.reveal-header");
let reveal = document.querySelector(".reveal");
reveal.insertBefore(header, reveal.firstChild);

logo_img = document.querySelector('.header-logo img');
if (logo_img.getAttribute('src') == null) {
if (logo_img?.getAttribute('data-src') != null) {
logo_img.src = logo_img?.getAttribute('data-src') || "";
logo_img.removeAttribute('data-src');
};
};
});
};

// add the class inverse-header for slide with has-dark-background class
// otherwise remove it.
function add_class(has_dark, header_paras) {
header_paras.forEach(el => {
el.classList.remove('inverse-header');
if(has_dark) {
el.classList.add('inverse-header');
};
});
};


// dynamically changing the header
function change_header(dheader, cheader, ctext) {
// dhead => dynamic header
// chead => constant header
// ctext => contstant header_text inner html
if (dheader !== null) {
cheader.innerHTML = dheader.innerHTML;
} else {
cheader.innerHTML = ctext;
};
};


if (Reveal.isReady()) {

add_header();

// Get the default header text element and innner HTML (i.e. literal text)
var header_text = document.querySelector("div.header-text p");
const header_inner_html = header_text.innerHTML;

var header_paras = document.querySelectorAll("div.reveal-header p");
var dark = Reveal.getCurrentSlide().classList.contains('has-dark-background');
add_class(dark, header_paras);

Reveal.on( 'slidechanged', event => {
var has_dark = event.currentSlide.classList.contains('has-dark-background');
add_class(has_dark, header_paras);
});

// make the visibility of slide specific header text defined in slide body none
document.querySelectorAll('div.header').forEach(el => {
el.style.display = 'none';
});


// change the header if currently loaded slide has the header div defined
// which won't be captured by slidechanged event unless we change slides.
let dynamic_header = Reveal.getCurrentSlide().querySelector('div.header p');
change_header(dynamic_header, header_text, header_inner_html);

Reveal.on( 'slidechanged', event => {
let dyn_header = event.currentSlide.querySelector('div.header p');
change_header(dyn_header, header_text, header_inner_html);
});
};
};

var header_paras = document.querySelectorAll("div.reveal-header p");

if (Reveal.isReady()) {
let dark = Reveal.getCurrentSlide().classList.contains('has-dark-background');
add_class(dark, header_paras);
}

Reveal.on( 'slidechanged', event => {
let has_dark = event.currentSlide.classList.contains('has-dark-background');
add_class(has_dark, header_paras);
});

// make the visibility of header text defined in slide body none
document.querySelectorAll('div.header').forEach(el => {
el.style.display = 'none';
window.addEventListener("load", (event) => {
header();
});

// dynamically changing the header
function change_header(dheader, cheader, ctext) {
// dhead => dynamic header
// chead => constant header
// ctext => contstant header_text inner html
if (dheader !== null) {
cheader.innerHTML = dheader.innerHTML;
} else {
cheader.innerHTML = ctext;
}
}

// change the header if currently loaded slide has the header div defined
// which won't be captured by slidechanged event unless we change slides.
if (Reveal.isReady()) {
let dynamic_header = Reveal.getCurrentSlide().querySelector('div.header p');
change_header(dynamic_header, header_text, header_inner_html)
}

Reveal.on( 'slidechanged', event => {
let dyn_header = event.currentSlide.querySelector('div.header p');
change_header(dyn_header, header_text, header_inner_html);
});
145 changes: 78 additions & 67 deletions _extensions/reveal-header/resources/js/sc_sb_title.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,78 +5,89 @@
* MIT License
* Copyright (c) 2023 Shafayet Khan Shafee.
*/

if (document.querySelector('div.reveal-header img').getAttribute('src').length == 0) {
document.querySelector('div.reveal-header').classList.add('no-logo')
}


function get_title() {
var h1_arr = [];
var h2_arr = [];

Reveal.getSlides().forEach(el => {
if (!el.matches('#title-slide')) {
var h1 = el.querySelector('.title-slide h1')?.innerText;
var h2 = el.querySelector('.title-slide h2')?.innerText;
h1_arr.push(h1);
h2_arr.push(h2);
};
});

function add_sc_sb_title() {

function get_title() {
var h1_arr = [];
var h2_arr = [];

return [h1_arr, h2_arr]
}

function fill_array(ar) {
let last_val = ar[0] || " ";
for (let i = 1; i < ar.length; i++) {
if (typeof ar[i] === 'undefined') {
ar[i] = last_val;
} else {
last_val = ar[i];
Reveal.getSlides().forEach(el => {
if (!el.matches('#title-slide')) {
var h1 = el.querySelector('.title-slide h1')?.innerText;
var h2 = el.querySelector('.title-slide h2')?.innerText;
h1_arr.push(h1);
h2_arr.push(h2);
};
});

return [h1_arr, h2_arr]
};

function fill_array(ar) {
let last_val = ar[0] || " ";
for (let i = 1; i < ar.length; i++) {
if (typeof ar[i] === 'undefined') {
ar[i] = last_val;
} else {
last_val = ar[i];
}
}
}
return ar
}

var [h1_array, h2_array] = get_title();
var filled_h1_array = fill_array(h1_array);
var filled_h2_array = fill_array(h2_array);

Reveal.getSlides().forEach((el, idx) => {
if (!el.matches('#title-slide')) {
el.setAttribute('data-sc-title', filled_h1_array[(idx - 1)])
el.setAttribute('data-sb-title', filled_h2_array[(idx - 1)])
}
});


Reveal.on( 'slidechanged', event => {
let sp = Reveal.getSlidesElement().querySelector('.stack.present');
return ar
};

if (sp != null) {
let header = document.querySelector("div.reveal-header");

// handling h1 section title (`.sc-title`)
var section_text = event.currentSlide.getAttribute('data-sc-title') || " ";
if (event.currentSlide.matches('.title-slide.level1')) {
header.querySelector('.sc-title p').innerText = "";
} else if (event.currentSlide.matches('.title-slide.level2')) {
header.querySelector('.sc-title p').innerText = section_text;
} else {
header.querySelector('.sc-title p').innerText = section_text;
};

if (Reveal.isReady()) {

if (document.querySelector('div.reveal-header img').getAttribute('src').length == 0) {
document.querySelector('div.reveal-header').classList.add('no-logo')
}

var [h1_array, h2_array] = get_title();
var filled_h1_array = fill_array(h1_array);
var filled_h2_array = fill_array(h2_array);

// handling h2 section title (`.sb-title`)
var sbsection_text = event.currentSlide.getAttribute('data-sb-title') || " ";
if (event.currentSlide.matches('.title-slide.level1')) {
header.querySelector('.sb-title p').innerText = "";
} else if (event.currentSlide.matches('.title-slide.level2')) {
header.querySelector('.sb-title p').innerText = "";
} else {
header.querySelector('.sb-title p').innerText = sbsection_text;
};
Reveal.getSlides().forEach((el, idx) => {
if (!el.matches('#title-slide')) {
el.setAttribute('data-sc-title', filled_h1_array[(idx - 1)])
el.setAttribute('data-sb-title', filled_h2_array[(idx - 1)])
}
});

Reveal.on( 'slidechanged', event => {
let sp = Reveal.getSlidesElement().querySelector('.stack.present');

if (sp != null) {
let header = document.querySelector("div.reveal-header");

// handling h1 section title (`.sc-title`)
var section_text = event.currentSlide.getAttribute('data-sc-title') || " ";
if (event.currentSlide.matches('.title-slide.level1')) {
header.querySelector('.sc-title p').innerText = "";
} else if (event.currentSlide.matches('.title-slide.level2')) {
header.querySelector('.sc-title p').innerText = section_text;
} else {
header.querySelector('.sc-title p').innerText = section_text;
};

// handling h2 section title (`.sb-title`)
var sbsection_text = event.currentSlide.getAttribute('data-sb-title') || " ";
if (event.currentSlide.matches('.title-slide.level1')) {
header.querySelector('.sb-title p').innerText = "";
} else if (event.currentSlide.matches('.title-slide.level2')) {
header.querySelector('.sb-title p').innerText = "";
} else {
header.querySelector('.sb-title p').innerText = sbsection_text;
};
};
});
};
};


window.addEventListener("load", (event) => {
add_sc_sb_title();
});



Loading

0 comments on commit 77bade5

Please sign in to comment.