From 8cda98e0ac6eeedaf05c2dfa9bb0c1570291362c Mon Sep 17 00:00:00 2001 From: Ruben Verweij Date: Fri, 10 May 2019 11:48:58 +0200 Subject: [PATCH 1/3] Show arbitrary number of incremental elements at the same time and add incremental hiding --- template.html | 81 +++++++++++++++++++++++++++++++++++++++------------ 1 file changed, 62 insertions(+), 19 deletions(-) diff --git a/template.html b/template.html index 5a75393..0455126 100644 --- a/template.html +++ b/template.html @@ -51,7 +51,8 @@

Even more incrementals

They can even - appear + appear + disappear in any order @@ -562,7 +563,7 @@

End!

if (cursor.length == 2) { newidx = ~~cursor[1].split(".")[0]; newstep = ~~cursor[1].split(".")[1]; - if (newstep > Dz.slides[newidx - 1].$$('.next').length) { + if (newstep > this.getTotalSlideSteps(Dz.slides[newidx - 1])) { newstep = 0; newidx++; } @@ -583,19 +584,18 @@

End!

if (this.idx == 1) { return; } - this.setCursor(this.idx - 1, - this.slides[this.idx - 2].$$('.next[active]').length); + this.setCursor(this.idx - 1, this.getTotalSlideSteps(this.slides[this.idx - 2])); } Dz.forward = function() { if (this.idx >= this.slides.length && - this.step >= this.slides[this.idx - 1].$$('.next').length) { + this.step >= this.getTotalSlideSteps(this.slides[this.idx - 1])) { return; } if (this.html.classList.contains("view") || - this.step >= this.slides[this.idx - 1].$$('.next').length) { + this.step >= this.getTotalSlideSteps(this.slides[this.idx - 1])) { this.setCursor(this.idx + 1, - this.slides[this.idx].$$('.next[active]').length); + this.getCurrentSlideStep(this.slides[this.idx])); } else { this.setCursor(this.idx, this.step + 1); } @@ -607,7 +607,7 @@

End!

Dz.goEnd = function() { var lastIdx = this.slides.length; - var lastStep = this.slides[lastIdx - 1].$$('.next').length; + var lastStep = this.getTotalSlideSteps(this.slides[lastIdx - 1]); this.setCursor(lastIdx, lastStep); } @@ -647,18 +647,61 @@

End!

} } + Dz.getTotalSlideSteps = function(slide) { + var total = 0; + var incrementals = Array.prototype.slice.call(slide.$$('.next')); + $$.forEach(incrementals, function(a, i) { + var order = i+1; + if (a.hasAttribute('next-order')) { + order = Number(a.getAttribute('next-order')); + } + if (order > total) { + total = order; + } + }); + return total; + } + + Dz.getCurrentSlideStep = function(slide) { + var total = 0; + var incrementals = Array.prototype.slice.call(slide.$$('.next')); + $$.forEach(incrementals, function(a, i) { + if (!a.hasAttribute('active')) { + return; + } + var order = i+1; + if (a.hasAttribute('next-order')) { + order = Number(a.getAttribute('next-order')); + } + if (order > total) { + total = order; + } + }); + return total; + } + Dz.setIncremental = function(aStep) { - this.step = aStep; - var incrementals = Array.prototype.slice.call(this.slides[this.idx - 1].$$('.next')).sort(function(a, b) { - return Number(a.getAttribute('next-order')) - Number(b.getAttribute('next-order')); - }); - var next = incrementals[this.step - 1]; - if (next) { - next.setAttribute('active', true); - } else { - this.setCursor(this.idx, 0); + var self = this; + self.step = aStep; + var incrementals = Array.prototype.slice.call(self.slides[self.idx-1].$$('.next')); + $$.forEach(incrementals, function(a, i) { + var order = i+1; + if (a.hasAttribute('next-order')) { + order = Number(a.getAttribute('next-order')); + } + var show = true; + if (a.hasAttribute('hide-after')) { + show = (Number(a.getAttribute('hide-after')) >= aStep); + } + if((aStep >= order) && show) { + a.setAttribute('active', true); + } else { + a.removeAttribute('active'); + } + }); + if (incrementals.length == 0) { + self.setCursor(self.idx, 0); } - return next; } Dz.goFullscreen = function() { @@ -673,7 +716,7 @@

End!

var slide = $("section:nth-of-type("+ aIdx +")"); if (!slide) return; - var steps = slide.$$('.next').length + 1, + var steps = this.getTotalSlideSteps(slide), slideSize = 100 / (this.slides.length - 1), stepSize = slideSize / steps; this.progressBar.style.width = ((aIdx - 1) * slideSize + aStep * stepSize) + '%'; From 79a6819c1bf44590733e1d00a2cc2ba4af8169fc Mon Sep 17 00:00:00 2001 From: Ruben Verweij Date: Fri, 10 May 2019 13:49:30 +0200 Subject: [PATCH 2/3] Convert to data- attributes for valid html --- template.html | 34 +++++++++++++++++----------------- 1 file changed, 17 insertions(+), 17 deletions(-) diff --git a/template.html b/template.html index 0455126..b83e4c2 100644 --- a/template.html +++ b/template.html @@ -48,15 +48,15 @@

More incrementals

Even more incrementals

- They - can - even - appear - disappear - in - any - order - ! + They + can + even + appear + disappear + in + any + order + !

@@ -652,8 +652,8 @@

End!

var incrementals = Array.prototype.slice.call(slide.$$('.next')); $$.forEach(incrementals, function(a, i) { var order = i+1; - if (a.hasAttribute('next-order')) { - order = Number(a.getAttribute('next-order')); + if (a.hasAttribute('data-next-order')) { + order = Number(a.getAttribute('data-next-order')); } if (order > total) { total = order; @@ -670,8 +670,8 @@

End!

return; } var order = i+1; - if (a.hasAttribute('next-order')) { - order = Number(a.getAttribute('next-order')); + if (a.hasAttribute('data-next-order')) { + order = Number(a.getAttribute('data-next-order')); } if (order > total) { total = order; @@ -686,12 +686,12 @@

End!

var incrementals = Array.prototype.slice.call(self.slides[self.idx-1].$$('.next')); $$.forEach(incrementals, function(a, i) { var order = i+1; - if (a.hasAttribute('next-order')) { - order = Number(a.getAttribute('next-order')); + if (a.hasAttribute('data-next-order')) { + order = Number(a.getAttribute('data-next-order')); } var show = true; - if (a.hasAttribute('hide-after')) { - show = (Number(a.getAttribute('hide-after')) >= aStep); + if (a.hasAttribute('data-hide-after')) { + show = (Number(a.getAttribute('data-hide-after')) >= aStep); } if((aStep >= order) && show) { a.setAttribute('active', true); From 5f2f827a1fcf4d6a56ac78752267f3e5c8b05d25 Mon Sep 17 00:00:00 2001 From: Ruben Verweij Date: Fri, 10 May 2019 14:00:13 +0200 Subject: [PATCH 3/3] Fix getCurrentStep --- template.html | 372 +++++++++++++++++++++++++------------------------- 1 file changed, 185 insertions(+), 187 deletions(-) diff --git a/template.html b/template.html index b83e4c2..6fcb954 100644 --- a/template.html +++ b/template.html @@ -364,7 +364,7 @@

End!