refactor modal code - improve resizing - move hero out of sections
parent
328149ed51
commit
052bbf5708
|
@ -5,10 +5,10 @@
|
||||||
{{ if ne .Site.Params.navbar.hidden true }}
|
{{ if ne .Site.Params.navbar.hidden true }}
|
||||||
{{ partial "navbar.html" . }}
|
{{ partial "navbar.html" . }}
|
||||||
{{ end }}
|
{{ end }}
|
||||||
<main id="page">
|
|
||||||
{{ if ne .Site.Params.hero.custom_hero true }}
|
{{ if ne .Site.Params.hero.custom_hero true }}
|
||||||
{{ partial "hero.html" . }}
|
{{ partial "hero.html" . }}
|
||||||
{{ end }}
|
{{ end }}
|
||||||
|
<main class="sections">
|
||||||
{{ partial "sections.html" . }}
|
{{ partial "sections.html" . }}
|
||||||
{{ partial "modals.html" . }}
|
{{ partial "modals.html" . }}
|
||||||
</main>
|
</main>
|
||||||
|
|
|
@ -1,6 +1,7 @@
|
||||||
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
|
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
|
||||||
<meta http-equiv="X-UA-Compatible" content="IE=edge">
|
<meta http-equiv="X-UA-Compatible" content="IE=edge">
|
||||||
<meta name="viewport" content="width=device-width, initial-scale=1">
|
<meta name="viewport" content="width=device-width, initial-scale=1">
|
||||||
<meta name="description" content="">
|
<meta name="description" content="">
|
||||||
<meta name="author" content="">
|
<meta name="author" content="">
|
||||||
|
<meta http-equiv="Cache-Control" content="max-age= {{ .Params.cache_timeout | default "3600"}}" />
|
||||||
<base href="{{ .Site.BaseURL }}">
|
<base href="{{ .Site.BaseURL }}">
|
||||||
|
|
|
@ -19,7 +19,7 @@ body {
|
||||||
font-family: 'Roboto', sans-serif;
|
font-family: 'Roboto', sans-serif;
|
||||||
font-size: 1.4rem;
|
font-size: 1.4rem;
|
||||||
flex-direction: column;
|
flex-direction: column;
|
||||||
width: 100%;
|
width: 100vw;
|
||||||
/* 14px default before jquery scalling */
|
/* 14px default before jquery scalling */
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -29,6 +29,7 @@ body {
|
||||||
padding-bottom: 1em;
|
padding-bottom: 1em;
|
||||||
align-items: center;
|
align-items: center;
|
||||||
flex-direction: column;
|
flex-direction: column;
|
||||||
|
width: 100vw;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* mobile first column */
|
/* mobile first column */
|
||||||
|
|
|
@ -7,7 +7,7 @@
|
||||||
top: 0;
|
top: 0;
|
||||||
left: 0;
|
left: 0;
|
||||||
z-index: 10000;
|
z-index: 10000;
|
||||||
width: 100%;
|
width: 100vw;
|
||||||
color: black;
|
color: black;
|
||||||
background-color: white;
|
background-color: white;
|
||||||
border-bottom: 1px solid grey;
|
border-bottom: 1px solid grey;
|
||||||
|
|
|
@ -85,7 +85,7 @@
|
||||||
/* modal */
|
/* modal */
|
||||||
|
|
||||||
.section--modal {
|
.section--modal {
|
||||||
display: flex;
|
display: none;
|
||||||
color: white;
|
color: white;
|
||||||
justify-content: center;
|
justify-content: center;
|
||||||
position: fixed;
|
position: fixed;
|
||||||
|
@ -131,7 +131,7 @@
|
||||||
overflow-y: auto;
|
overflow-y: auto;
|
||||||
position: relative;
|
position: relative;
|
||||||
align-items: flex-start;
|
align-items: flex-start;
|
||||||
font-size: .9em;
|
font-size: 0.9em;
|
||||||
padding: 1em;
|
padding: 1em;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -144,6 +144,7 @@
|
||||||
display: flex;
|
display: flex;
|
||||||
align-items: center;
|
align-items: center;
|
||||||
justify-content: center;
|
justify-content: center;
|
||||||
|
width: 100vw;
|
||||||
}
|
}
|
||||||
|
|
||||||
#hero .section-content--hero {
|
#hero .section-content--hero {
|
||||||
|
|
|
@ -1,23 +1,22 @@
|
||||||
// requires jquery
|
(function initialze() {
|
||||||
$(document).ready(function () {
|
|
||||||
|
|
||||||
// initialize
|
|
||||||
navbarSpacer();
|
navbarSpacer();
|
||||||
// $('#page').css("width", $(window).width());
|
|
||||||
heroResize();
|
heroResize();
|
||||||
itemResize('iframe');
|
itemResize('iframe');
|
||||||
typeResize(); // for section content
|
typeResize(); // for section content
|
||||||
hljs.initHighlightingOnLoad();
|
hljs.initHighlightingOnLoad();
|
||||||
$('.section__content--modal').perfectScrollbar();
|
$('.section__content--modal').perfectScrollbar();
|
||||||
|
})();
|
||||||
|
|
||||||
// resize elements on change
|
// requires jquery
|
||||||
$(window).resize(function () {
|
$(document).ready(function () {
|
||||||
// $('#page').css("width", $(window).width());
|
|
||||||
navbarSpacer();
|
|
||||||
heroResize();
|
|
||||||
itemResize('iframe');
|
|
||||||
typeResize();
|
|
||||||
$('.section__content--modal').perfectScrollbar('update');
|
|
||||||
});
|
|
||||||
|
|
||||||
});;
|
});
|
||||||
|
|
||||||
|
// resize elements on change
|
||||||
|
$(window).resize(function () {
|
||||||
|
navbarSpacer();
|
||||||
|
heroResize();
|
||||||
|
itemResize('iframe');
|
||||||
|
typeResize();
|
||||||
|
$('.section__content--modal').perfectScrollbar('update');
|
||||||
|
});
|
||||||
|
|
|
@ -3,7 +3,6 @@
|
||||||
* Copyright 2013-2014, Simple Focus http://simplefocus.com/
|
* Copyright 2013-2014, Simple Focus http://simplefocus.com/
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
|
|
||||||
$.fn.flowtype = function (options) {
|
$.fn.flowtype = function (options) {
|
||||||
|
|
||||||
// Establish default settings/variables
|
// Establish default settings/variables
|
||||||
|
|
|
@ -36,7 +36,7 @@ function navbarSpacer() {
|
||||||
}
|
}
|
||||||
|
|
||||||
// hero resizer
|
// hero resizer
|
||||||
function heroResize(bfr = 15) {
|
function heroResize(bfr = 30) {
|
||||||
var h = $(window).height() - $(".nav-bar__header").outerHeight(true),
|
var h = $(window).height() - $(".nav-bar__header").outerHeight(true),
|
||||||
w = $(window).width(),
|
w = $(window).width(),
|
||||||
fr = bfr * h / w
|
fr = bfr * h / w
|
||||||
|
@ -44,7 +44,7 @@ function heroResize(bfr = 15) {
|
||||||
// minimum base font ratio
|
// minimum base font ratio
|
||||||
fr = (fr > bfr) ? bfr : fr
|
fr = (fr > bfr) ? bfr : fr
|
||||||
// adjust for short viewport height
|
// adjust for short viewport height
|
||||||
fr = (w / h > 1 && h < 600) ? 15 * w / h : fr
|
fr = (w / h > 1 && h < 700) ? 30 * w / h : fr
|
||||||
//console.log('fr after', fr)
|
//console.log('fr after', fr)
|
||||||
|
|
||||||
$('#hero').css({
|
$('#hero').css({
|
||||||
|
@ -52,14 +52,17 @@ function heroResize(bfr = 15) {
|
||||||
height: h / w > 1.5 ? w * 1.5 : h,
|
height: h / w > 1.5 ? w * 1.5 : h,
|
||||||
});
|
});
|
||||||
|
|
||||||
|
var mf = w / h > 1 ? 0 : 12
|
||||||
|
|
||||||
$('#hero').flowtype({
|
$('#hero').flowtype({
|
||||||
maxFont: 50,
|
maxFont: 30,
|
||||||
minFont: 18,
|
minFont: mf,
|
||||||
fontRatio: fr
|
fontRatio: fr
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
// child item resize based on parent container (i.e. flexbox)
|
// child item resize based on parent container (i.e. flexbox)
|
||||||
|
// Especially good for iframes
|
||||||
function itemResize(item, maxWidth = 450, widthPadding = 30) {
|
function itemResize(item, maxWidth = 450, widthPadding = 30) {
|
||||||
let windowWidth = $(window).width()
|
let windowWidth = $(window).width()
|
||||||
let width = (windowWidth > maxWidth) ? maxWidth : windowWidth - widthPadding
|
let width = (windowWidth > maxWidth) ? maxWidth : windowWidth - widthPadding
|
||||||
|
@ -73,12 +76,12 @@ function itemResize(item, maxWidth = 450, widthPadding = 30) {
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
function typeResize() {
|
function typeResize(fr = 20) {
|
||||||
$('.section').flowtype({
|
$('main:not(#hero)').flowtype({
|
||||||
// maximum: 1000,
|
// maximum: 1000,
|
||||||
minFont: 12,
|
minFont: 12,
|
||||||
maxFont: 25,
|
maxFont: 25,
|
||||||
fontRatio: 20
|
fontRatio: fr
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -107,39 +110,67 @@ function lightgallery(id) {
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Modal
|
// Modal tool. Must use modal template for content
|
||||||
// hide all the modals before displaying
|
(function ($) {
|
||||||
$('.section--modal').each(function () {
|
|
||||||
$(this).hide();
|
|
||||||
});
|
|
||||||
|
|
||||||
// all but inside the modal box
|
// extend jquery so remove handlers can be added and removed at the right time in a group
|
||||||
$(document).on('click', function (event) {
|
$.fn.modalHandlers = function (state = 'on') {
|
||||||
var container = $(".section__container--modal");
|
|
||||||
if (!container.is(event.target) && // If the target of the click isn't the container...
|
if (state === 'on') {
|
||||||
container.has(event.target).length === 0) // ... nor a descendant of the container
|
$(document).on('click', modalClickOutside);
|
||||||
{
|
$(document).keypress(modalEsc);
|
||||||
$('.section--modal.current').hide().removeClass("current");
|
this.find('a[modal-close]').on('click', modalClickCloser);
|
||||||
|
return this
|
||||||
|
}
|
||||||
|
|
||||||
|
if (state === 'off') {
|
||||||
|
$(document).off('click', modalClickOutside);
|
||||||
|
$(document).off('keypress', modalEsc);
|
||||||
|
this.find('a[modal-close]').off('click', modalClickCloser);
|
||||||
|
return this
|
||||||
|
}
|
||||||
|
|
||||||
|
return false;
|
||||||
|
|
||||||
|
};
|
||||||
|
|
||||||
|
// modal event handlers - add more if you want - add them to extension above
|
||||||
|
function modalEsc(event) {
|
||||||
|
if (event.key === "Escape") { modalHide() }
|
||||||
}
|
}
|
||||||
});
|
|
||||||
|
|
||||||
$('.section__container--modal').click(function () {
|
function modalClickOutside(event) {
|
||||||
$('.section--modal.current').hide().removeClass("current");
|
var container = $(".section__container--modal");
|
||||||
$('a[modal-close]').remove();
|
if (!container.is(event.target) && // If the target of the click isn't the container...
|
||||||
});
|
container.has(event.target).length === 0) // ... nor a descendant of the container
|
||||||
|
{ modalHide(); }
|
||||||
|
}
|
||||||
|
|
||||||
// register click for modal link
|
function modalClickCloser(event) {
|
||||||
$("a[modal]").click(function () {
|
modalHide();
|
||||||
if (location.pathname.replace(/^\//, '') == this.pathname.replace(/^\//, '') && location.hostname == this.hostname) {
|
}
|
||||||
var target = this.hash;
|
|
||||||
$(target).addClass("current").show()
|
// modal show and hide
|
||||||
target = target + " > .section__container > .section__headline"
|
function modalShow(modal_hash) {
|
||||||
var closer = "<a modal-close class='fa-stack fa-2x' ><i class='fa fa-circle-thin fa-stack-2x'></i><i class='fa fa-close fa-stack-1x'></i></a>"
|
var closer = "<a modal-close class='fa-stack fa-2x' ><i class='fa fa-circle-thin fa-stack-2x'></i><i class='fa fa-close fa-stack-1x'></i></a>"
|
||||||
$(target).append(closer);
|
$(modal_hash).find('.section__headline').append(closer).end().modalHandlers().addClass("current").css('display', 'flex');
|
||||||
} else {
|
|
||||||
var target = this;
|
|
||||||
}
|
}
|
||||||
// alert(`I clicked on modal link ${target}`);
|
|
||||||
return false;
|
function modalHide() {
|
||||||
});
|
$('.section--modal.current').hide().modalHandlers("off").removeClass("current").find('a[modal-close]').remove;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Register click event for all modal links on page
|
||||||
|
$("a[modal]").click(function () {
|
||||||
|
if (location.pathname.replace(/^\//, '') == this.pathname.replace(/^\//, '') && location.hostname == this.hostname) {
|
||||||
|
var target = this.hash;
|
||||||
|
modalShow(target);
|
||||||
|
} else {
|
||||||
|
alert(`modal display of off page content not supported`);
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
});
|
||||||
|
|
||||||
|
}(jQuery));
|
||||||
|
|
||||||
// end modal
|
// end modal
|
||||||
|
|
Loading…
Reference in New Issue