Skip to content

armgit / anime

Public Imported from GitHub
0

JavaScript animation engine

Add demos navigation links

Julian Garnier6b1a184270f9
diff --git a/documentation/assets/css/styles.css b/documentation/assets/css/styles.css
index f5718cc0..b9fe5da8 100644
--- a/documentation/assets/css/styles.css
+++ b/documentation/assets/css/styles.css
@@ -97,11 +97,57 @@ header {
}
.navigation {
- width: 200px;
+ width: 280px;
height: 100%;
+ padding: 20px 10px;
border-right: 1px solid #09090B;
}
+.navigation ul {
+ margin-bottom: 10px;
+}
+
+.navigation li {
+ padding-left: 15px;
+}
+
+.navigation li:before {
+ content: "";
+ display: block;
+ position: absolute;
+ margin-top: 5px;
+ margin-left: -12px;
+ width: 1px;
+ height: 9px;
+ background: currentColor;
+}
+
+.navigation li:first-child {
+ padding-left: 0;
+}
+
+.navigation li:first-child:before {
+ display: none;
+}
+
+.navigation a {
+ opacity: .6;
+ color: #FFF;
+ text-decoration: none;
+ font-size: 12px;
+ line-height: 20px;
+ text-transform: uppercase;
+}
+
+.navigation a:hover {
+ color: currentColor;
+}
+
+.navigation a.active {
+ opacity: 1;
+ color: currentColor;
+}
+
pre {
overflow-x: auto;
font-family: 'Space Mono', monospace;
@@ -168,6 +214,7 @@ article {
align-items: center;
justify-content: center;
min-height: 200px;
+ width: 50%;
padding-top: 35px;
border-right: 1px solid #09090B;
border-bottom: 1px solid #09090B;
diff --git a/documentation/assets/js/scripts.js b/documentation/assets/js/scripts.js
index e410161a..cf408d8d 100644
--- a/documentation/assets/js/scripts.js
+++ b/documentation/assets/js/scripts.js
@@ -1,4 +1,5 @@
-var demoEls = document.querySelectorAll('.demo');
+var navigationEl = document.querySelector('.navigation');
+var articleEls = document.querySelectorAll('article');
var codeOutputEl = document.querySelector('.code-output');
var demos = [];
@@ -17,13 +18,17 @@ function createDemo(el) {
var demoAnim = window[id];
function highlightDemo() {
if (!el.classList.contains('active')) {
+ var linkEls = document.querySelectorAll('.demo-link');
for (var i = 0; i < demos.length; i++) {
var d = demos[i];
d.el.classList.remove('active');
+ linkEls[i].classList.remove('active');
d.anim.pause();
}
history.pushState(null, null, '#'+id);
outputCode(code);
+ var linkEl = document.querySelector('a[href="#'+id+'"]');
+ linkEl.classList.add('active');
el.classList.add('active');
}
demoAnim.restart();
@@ -43,16 +48,55 @@ function createDemo(el) {
el.addEventListener('mouseenter', enterDemo);
el.addEventListener('mouseleave', leaveDemo);
demoAnim.pause();
- demo.el = el;
- demo.id = id;
- demo.anim = demoAnim;
- demo.highlight = highlightDemo;
- demos.push(demo);
+ return {
+ el: el,
+ title: title,
+ id: id,
+ anim: demoAnim,
+ highlight: highlightDemo
+ }
+}
+
+function createLinksSection(articleEl) {
+ var articleId = articleEl.id;
+ var articleTitle = articleEl.querySelector('h2').innerHTML;
+ var colorClass = articleEl.classList[0];
+ var ulEl = document.createElement('ul');
+ var liEl = document.createElement('li');
+ var sectionLinkEl = document.createElement('a');
+ sectionLinkEl.setAttribute('href', '#'+articleId);
+ sectionLinkEl.innerHTML = articleTitle;
+ liEl.appendChild(sectionLinkEl);
+ ulEl.appendChild(liEl);
+ ulEl.classList.add(colorClass);
+ return ulEl;
}
-for (var i = 0; i < demoEls.length; i++) {
- createDemo(demoEls[i]);
+function createDemoLink(demo) {
+ var liEl = document.createElement('li');
+ var demoLinkEl = document.createElement('a');
+ demoLinkEl.setAttribute('href', '#'+demo.id);
+ demoLinkEl.innerHTML = demo.title;
+ demoLinkEl.classList.add('demo-link');
+ demoLinkEl.addEventListener('click', demo.highlight);
+ liEl.appendChild(demoLinkEl);
+ return liEl;
+}
+
+var fragment = document.createDocumentFragment();
+for (var i = 0; i < articleEls.length; i++) {
+ var articleEl = articleEls[i];
+ var linksSectionEl = createLinksSection(articleEl);
+ var demoEls = articleEl.querySelectorAll('.demo');
+ for (var d = 0; d < demoEls.length; d++) {
+ var demo = createDemo(demoEls[d]);
+ var demoLinkEl = createDemoLink(demo);
+ linksSectionEl.appendChild(demoLinkEl);
+ demos.push(demo);
+ }
+ fragment.appendChild(linksSectionEl);
}
+navigationEl.appendChild(fragment);
(function updateDemos() {
var hash = window.location.hash;