diff options
| author | roninro <liumy.f@foxmail.com> | 2022-07-28 17:32:43 +0800 |
|---|---|---|
| committer | roninro <liumy.f@foxmail.com> | 2022-07-28 17:32:43 +0800 |
| commit | c953d353194ae038f1815290337a82c1cb65272c (patch) | |
| tree | 6494ad04f8907cf1136972e2a0b7f6b27d206873 /assets/js | |
init
Diffstat (limited to 'assets/js')
| -rw-r--r-- | assets/js/archive.js | 143 | ||||
| -rw-r--r-- | assets/js/hux-blog.js | 78 | ||||
| -rw-r--r-- | assets/js/jquery.nav.js | 224 |
3 files changed, 445 insertions, 0 deletions
diff --git a/assets/js/archive.js b/assets/js/archive.js new file mode 100644 index 0000000..8e90633 --- /dev/null +++ b/assets/js/archive.js @@ -0,0 +1,143 @@ +/* +Credits: this script is shamelessly borrowed from +https://github.com/kitian616/jekyll-TeXt-theme +*/ +(function() { + function queryString() { + // This function is anonymous, is executed immediately and + // the return value is assigned to QueryString! + var i = 0, queryObj = {}, pair; + var queryStr = window.location.search.substring(1); + var queryArr = queryStr.split('&'); + for (i = 0; i < queryArr.length; i++) { + pair = queryArr[i].split('='); + // If first entry with this name + if (typeof queryObj[pair[0]] === 'undefined') { + queryObj[pair[0]] = pair[1]; + // If second entry with this name + } else if (typeof queryObj[pair[0]] === 'string') { + queryObj[pair[0]] = [queryObj[pair[0]], pair[1]]; + // If third or later entry with this name + } else { + queryObj[pair[0]].push(pair[1]); + } + } + return queryObj; + } + + var setUrlQuery = (function() { + var baseUrl = window.location.href.split('?')[0]; + return function(query) { + if (typeof query === 'string') { + window.history.replaceState(null, '', baseUrl + query); + } else { + window.history.replaceState(null, '', baseUrl); + } + }; + })(); + + $(document).ready(function() { + var $tags = $('.js-tags'); + var $articleTags = $tags.find('.tag-button'); + var $tagShowAll = $tags.find('.tag-button--all'); + var $result = $('.js-result'); + var $sections = $result.find('section'); + var sectionArticles = [] + var $lastFocusButton = null; + var sectionTopArticleIndex = []; + var hasInit = false; + + $sections.each(function() { + sectionArticles.push($(this).find('.item')); + }); + + function init() { + var i, index = 0; + for (i = 0; i < $sections.length; i++) { + sectionTopArticleIndex.push(index); + index += $sections.eq(i).find('.item').length; + } + sectionTopArticleIndex.push(index); + } + + function searchButtonsByTag(_tag/*raw tag*/) { + if (!_tag) { + return $tagShowAll; + } + var _buttons = $articleTags.filter('[data-encode="' + _tag + '"]'); + if (_buttons.length === 0) { + return $tagShowAll; + } + return _buttons; + } + + function buttonFocus(target) { + if (target) { + target.addClass('focus'); + $lastFocusButton && !$lastFocusButton.is(target) && $lastFocusButton.removeClass('focus'); + $lastFocusButton = target; + } + } + + function tagSelect (tag/*raw tag*/, target) { + var result = {}, $articles; + var i, j, k, _tag; + + for (i = 0; i < sectionArticles.length; i++) { + $articles = sectionArticles[i]; + for (j = 0; j < $articles.length; j++) { + if (tag === '' || tag === undefined) { + result[i] || (result[i] = {}); + result[i][j] = true; + } else { + var tags = $articles.eq(j).data('tags').split(','); + for (k = 0; k < tags.length; k++) { + if (tags[k] === tag) { + result[i] || (result[i] = {}); + result[i][j] = true; break; + } + } + } + } + } + + for (i = 0; i < sectionArticles.length; i++) { + result[i] && $sections.eq(i).removeClass('d-none'); + result[i] || $sections.eq(i).addClass('d-none'); + for (j = 0; j < sectionArticles[i].length; j++) { + if (result[i] && result[i][j]) { + sectionArticles[i].eq(j).removeClass('d-none'); + } else { + sectionArticles[i].eq(j).addClass('d-none'); + } + } + } + + hasInit || ($result.removeClass('d-none'), hasInit = true); + + + if (target) { + buttonFocus(target); + _tag = target.attr('data-encode'); + if (_tag === '' || typeof _tag !== 'string') { + setUrlQuery(); + } else { + setUrlQuery('?tag=' + _tag); + } + } else { + buttonFocus(searchButtonsByTag(tag)); + } + } + + var query = queryString(), + _tag = query.tag; + + init(); + tagSelect(_tag); + + $tags.on('click', 'a', function() { /* only change */ + tagSelect($(this).data('encode'), $(this)); + }); + + }); +})(); diff --git a/assets/js/hux-blog.js b/assets/js/hux-blog.js new file mode 100644 index 0000000..ab6effa --- /dev/null +++ b/assets/js/hux-blog.js @@ -0,0 +1,78 @@ + /*! + * Hux Blog v1.6.0 (http://startbootstrap.com) + * Copyright 2016 @huxpro + * Licensed under Apache 2.0 + */ + +// Tooltip Init +// Unuse by Hux since V1.6: Titles now display by default so there is no need for tooltip +// $(function() { +// $("[data-toggle='tooltip']").tooltip(); +// }); + + +// make all images responsive +/* + * Unuse by Hux + * actually only Portfolio-Pages can't use it and only post-img need it. + * so I modify the _layout/post and CSS to make post-img responsive! + */ +// $(function() { +// $("img").addClass("img-responsive"); +// }); + +// responsive tables +$(document).ready(function() { + $("table").wrap("<div class='table-responsive'></div>"); + $("table").addClass("table"); +}); + +// responsive embed videos +$(document).ready(function() { + $('iframe[src*="youtube.com"]').wrap('<div class="embed-responsive embed-responsive-16by9"></div>'); + $('iframe[src*="youtube.com"]').addClass('embed-responsive-item'); + $('iframe[src*="vimeo.com"]').wrap('<div class="embed-responsive embed-responsive-16by9"></div>'); + $('iframe[src*="vimeo.com"]').addClass('embed-responsive-item'); +}); + +// Navigation Scripts to Show Header on Scroll-Up +jQuery(document).ready(function($) { + var MQL = 1170; + + //primary navigation slide-in effect + if ($(window).width() > MQL) { + var headerHeight = $('.navbar-custom').height(), + bannerHeight = $('.intro-header .container').height(); + $(window).on('scroll', { + previousTop: 0 + }, + function() { + var currentTop = $(window).scrollTop(), + $catalog = $('.side-catalog'); + + //check if user is scrolling up by mouse or keyborad + if (currentTop < this.previousTop) { + //if scrolling up... + if (currentTop > 0 && $('.navbar-custom').hasClass('is-fixed')) { + $('.navbar-custom').addClass('is-visible'); + } else { + $('.navbar-custom').removeClass('is-visible is-fixed'); + } + } else { + //if scrolling down... + $('.navbar-custom').removeClass('is-visible'); + if (currentTop > headerHeight && !$('.navbar-custom').hasClass('is-fixed')) $('.navbar-custom').addClass('is-fixed'); + } + this.previousTop = currentTop; + + + //adjust the appearance of side-catalog + $catalog.show() + if (currentTop > (bannerHeight + 41)) { + $catalog.addClass('fixed') + } else { + $catalog.removeClass('fixed') + } + }); + } +});
\ No newline at end of file diff --git a/assets/js/jquery.nav.js b/assets/js/jquery.nav.js new file mode 100644 index 0000000..a4ad012 --- /dev/null +++ b/assets/js/jquery.nav.js @@ -0,0 +1,224 @@ +/* + * jQuery One Page Nav Plugin + * http://github.com/davist11/jQuery-One-Page-Nav + * + * Copyright (c) 2010 Trevor Davis (http://trevordavis.net) + * Dual licensed under the MIT and GPL licenses. + * Uses the same license as jQuery, see: + * http://jquery.org/license + * + * @version 3.0.0 + * + * Example usage: + * $('#nav').onePageNav({ + * currentClass: 'current', + * changeHash: false, + * scrollSpeed: 750 + * }); + */ + +;(function($, window, document, undefined){ + + // our plugin constructor + var OnePageNav = function(elem, options){ + this.elem = elem; + this.$elem = $(elem); + this.options = options; + this.metadata = this.$elem.data('plugin-options'); + this.$win = $(window); + this.sections = {}; + this.didScroll = false; + this.$doc = $(document); + this.docHeight = this.$doc.height(); + }; + + // the plugin prototype + OnePageNav.prototype = { + defaults: { + navItems: 'a', + currentClass: 'current', + changeHash: false, + easing: 'swing', + filter: '', + scrollSpeed: 750, + scrollThreshold: 0.5, + begin: false, + end: false, + scrollChange: false, + padding: 0 + }, + + init: function() { + // Introduce defaults that can be extended either + // globally or using an object literal. + this.config = $.extend({}, this.defaults, this.options, this.metadata); + + this.$nav = this.$elem.find(this.config.navItems); + + //Filter any links out of the nav + if(this.config.filter !== '') { + this.$nav = this.$nav.filter(this.config.filter); + } + + //Handle clicks on the nav + this.$nav.on('click.onePageNav', $.proxy(this.handleClick, this)); + + //Get the section positions + this.getPositions(); + + //Handle scroll changes + this.bindInterval(); + + //Update the positions on resize too + this.$win.on('resize.onePageNav', $.proxy(this.getPositions, this)); + + return this; + }, + + adjustNav: function(self, $parent) { + self.$elem.find('.' + self.config.currentClass).removeClass(self.config.currentClass); + $parent.addClass(self.config.currentClass); + }, + + bindInterval: function() { + var self = this; + var docHeight; + + self.$win.on('scroll.onePageNav', function() { + self.didScroll = true; + }); + + self.t = setInterval(function() { + docHeight = self.$doc.height(); + + //If it was scrolled + if(self.didScroll) { + self.didScroll = false; + self.scrollChange(); + } + + //If the document height changes + if(docHeight !== self.docHeight) { + self.docHeight = docHeight; + self.getPositions(); + } + }, 250); + }, + + getHash: function($link) { + return $link.attr('href').split('#')[1]; + }, + + getPositions: function() { + var self = this; + var linkHref; + var topPos; + var $target; + + self.$nav.each(function() { + linkHref = self.getHash($(this)); + $target = $('#' + linkHref); + + if($target.length) { + topPos = $target.offset().top; + self.sections[linkHref] = Math.round(topPos); + } + }); + }, + + getSection: function(windowPos) { + var returnValue = null; + var windowHeight = Math.round(this.$win.height() * this.config.scrollThreshold); + + for(var section in this.sections) { + if((this.sections[section] - windowHeight) < windowPos) { + returnValue = section; + } + } + + return returnValue; + }, + + handleClick: function(e) { + var self = this; + var $link = $(e.currentTarget); + var $parent = $link.parent(); + var newLoc = '#' + self.getHash($link); + + if(!$parent.hasClass(self.config.currentClass)) { + //Start callback + if(self.config.begin) { + self.config.begin(); + } + + //Change the highlighted nav item + self.adjustNav(self, $parent); + + //Removing the auto-adjust on scroll + self.unbindInterval(); + + //Scroll to the correct position + self.scrollTo(newLoc, function() { + //Do we need to change the hash? + if(self.config.changeHash) { + window.location.hash = newLoc; + } + + //Add the auto-adjust on scroll back in + self.bindInterval(); + + //End callback + if(self.config.end) { + self.config.end(); + } + }); + } + + e.preventDefault(); + }, + + scrollChange: function() { + var windowTop = this.$win.scrollTop(); + var position = this.getSection(windowTop); + var $parent; + + //If the position is set + if(position !== null) { + $parent = this.$elem.find('a[href$="#' + position + '"]').parent(); + + //If it's not already the current section + if(!$parent.hasClass(this.config.currentClass)) { + //Change the highlighted nav item + this.adjustNav(this, $parent); + + //If there is a scrollChange callback + if(this.config.scrollChange) { + this.config.scrollChange($parent); + } + } + } + }, + + scrollTo: function(target, callback) { + var offset = $(target).offset().top - this.config.padding; + + $('html, body').animate({ + scrollTop: offset + }, this.config.scrollSpeed, this.config.easing, callback); + }, + + unbindInterval: function() { + clearInterval(this.t); + this.$win.unbind('scroll.onePageNav'); + } + }; + + OnePageNav.defaults = OnePageNav.prototype.defaults; + + $.fn.onePageNav = function(options) { + return this.each(function() { + new OnePageNav(this, options).init(); + }); + }; + +})( jQuery, window , document );
\ No newline at end of file |
