From a8d776e1d06679dff4059733462a07208fda9f21 Mon Sep 17 00:00:00 2001 From: len0rd Date: Sun, 5 Aug 2018 13:07:12 -0400 Subject: [PATCH] dynamic scrollspy for projects works. ideally will tweak a bit more to make it look nicer --- assets/script/dynamicscrollspy.min.js | 5 +++++ views/pages/index.ejs | 2 +- views/pages/projects/project_template.ejs | 12 +++++++++--- 3 files changed, 15 insertions(+), 4 deletions(-) create mode 100644 assets/script/dynamicscrollspy.min.js diff --git a/assets/script/dynamicscrollspy.min.js b/assets/script/dynamicscrollspy.min.js new file mode 100644 index 0000000..a3d976a --- /dev/null +++ b/assets/script/dynamicscrollspy.min.js @@ -0,0 +1,5 @@ +/** +* AutoScrollspy v 0.2.0 +* https://github.com/psalmody/dynamic-scrollspy +*/ +!function($){$.fn.DynamicScrollspy=function(opts){function encodeHTML(value){return $("
").text(value).html()}function selectAllH(){for(var st=[],i=self.options.tH;i<=self.options.bH;i++)st.push("H"+i);return $(st.join(",")).not(self.options.exclude)}function randID(){function rand(){r=Math.floor(900*Math.random())+100}var r;for(rand();self.rands.indexOf(r)>=0;)rand();return self.rands.push(r),r}function genIDs(){selectAllH().prop("id",function(){return""===$(this).prop("id")?$(this).prop("tagName")+randID():$(this).prop("id")})}function checkIDs(){var missing=0;if(selectAllH().each(function(){if(""===$(this).prop("id"))missing++;else if($('[id="'+$(this).prop("id")+'"]').length>1)throw new Error("DynamicScrollspy: Error! Duplicate id "+$(this).prop("id"))}),missing>0){var msg="DynamicScrollspy: Not all headers have ids and genIDs: false.";throw new Error(msg)}return missing}function showTesting(){selectAllH().append(function(){return" ("+$(this).prop("tagName")+", "+$(this).prop("id")+")"})}function makeTree(){var tree=self.tree;return $("H"+self.options.tH).not(self.options.exclude).each(function(){tree[$(this).prop("id")]={dstext:encodeHTML($(this).text()),jqel:$(this)}}),self.options.tH+1<=self.options.bH&&itCreateTree(tree),tree}function itCreateTree(what){for(var k in what)if(""!==k&&"dstext"!=k&&"jqel"!=k){var lvl=Number($("#"+k).prop("tagName").replace("H",""));if(lvl>=self.options.bH)return!1;$("#"+k).nextUntil("H"+lvl).filter("H"+(lvl+1)).not(self.options.exclude).each(function(){what[k][$(this).prop("id")]={dstext:encodeHTML($(this).text()),jqel:$(this)}}),lvl');return self.append(ul),$.each(self.tree,function(k){var c=self.tree[k],li='";ul.append(li),itRenderTree(self.tree[k])}),self}function itRenderTree(what){if(Object.keys(what).length<3)return!1;var parent=$("#dsli"+what.jqel.prop("id")),ul=$("");parent.append(ul);for(var k in what)if("dstext"!=k&&"jqel"!=k){var c=what[k];ul.append('"),itRenderTree(what[k])}}function init(){if(self.isinit===!1){if(self.options.genIDs?genIDs():checkIDs(),self.options.testing&&showTesting(),makeTree(),renderTree(),self.options.affix&&"function"==typeof self.children("ul").affix){var ul=self.children("ul");self.children("ul").affix({offset:{top:function(){var c=ul.offset().top,d=parseInt(ul.children(0).css("margin-top"),10),e=$(self).height();return this.top=c-e-d},bottom:function(){return this.bottom=$(self).outerHeight(!0)}}})}$("body").attr("data-spy","true").scrollspy({target:"#"+self.prop("id"),offset:self.options.offset}),self.isinit=!0}else makeTree(),renderTree(),$('[data-spy="scroll"]').each(function(){$(this).scrollspy("refresh")});return self}if(opts="undefined"==typeof opts?{}:opts,this.isinit="undefined"!=typeof this.isinit&&self.isinit,"destroy"==opts)return this.isinit=!1,this.empty(),this.off("activate.bs.scrollspy"),$("body").removeAttr("data-spy"),this;this.options=$.extend({},{affix:!0,tH:2,bH:6,exclude:!1,genIDs:!1,offset:100,ulClassNames:"hidden-print",activeClass:"",testing:!1},this.options,opts);var self=this;return this.tree={},this.rands=[],init()}}(jQuery); \ No newline at end of file diff --git a/views/pages/index.ejs b/views/pages/index.ejs index 9c8b9cb..004414f 100644 --- a/views/pages/index.ejs +++ b/views/pages/index.ejs @@ -65,7 +65,7 @@

Tbh, idk what other project to put here, we'll have to figure it our later

diff --git a/views/pages/projects/project_template.ejs b/views/pages/projects/project_template.ejs index 632af3f..46137b3 100644 --- a/views/pages/projects/project_template.ejs +++ b/views/pages/projects/project_template.ejs @@ -15,10 +15,10 @@
-
- <%- include(rootPath + page + navExt) %> +
+
-
+
<%- include(rootPath + page) %>
@@ -26,5 +26,11 @@ <%- include(rootPath + 'partials/footer') %> <%- include(rootPath + 'partials/post_html_include') %> + + \ No newline at end of file