diff options
author | Alexis Metaireau <alexis@notmyidea.org> | 2017-04-08 13:44:58 +0200 |
---|---|---|
committer | GitHub <noreply@github.com> | 2017-04-08 13:44:58 +0200 |
commit | 88f21b95e3a6dc91c6a344e90ec50afbedc5bdd7 (patch) | |
tree | 6e6c99fab6a0c45ba96bfb501f581b3a71e7917a /ops/static/js/site.js | |
parent | 5ebcbdac1f43f04a47eb121aa3b5a8ee4ae35da6 (diff) | |
parent | 3a009cc2c24552366b823c69e393029c14fe8758 (diff) | |
download | pelican-themes-88f21b95e3a6dc91c6a344e90ec50afbedc5bdd7.tar.gz |
Merge branch 'master' into bricabractheme
Diffstat (limited to 'ops/static/js/site.js')
-rw-r--r-- | ops/static/js/site.js | 94 |
1 files changed, 94 insertions, 0 deletions
diff --git a/ops/static/js/site.js b/ops/static/js/site.js new file mode 100644 index 0000000..3cb76e5 --- /dev/null +++ b/ops/static/js/site.js @@ -0,0 +1,94 @@ +$(document).ready(function() { + + // Variables + var $codeSnippets = $('.code-example-body'), + $nav = $('.navbar'), + $body = $('body'), + $window = $(window), + $popoverLink = $('[data-popover]'), + navOffsetTop = $nav.offset().top, + $document = $(document), + entityMap = { + "&": "&", + "<": "<", + ">": ">", + '"': '"', + "'": ''', + "/": '/' + } + + function init() { + $window.on('scroll', onScroll) + $window.on('resize', resize) + $popoverLink.on('click', openPopover) + $document.on('click', closePopover) + $('a[href^="#"]').on('click', smoothScroll) + buildSnippets(); + } + + function smoothScroll(e) { + e.preventDefault(); + $(document).off("scroll"); + var target = this.hash, + menu = target; + $target = $(target); + $('html, body').stop().animate({ + 'scrollTop': $target.offset().top-40 + }, 0, 'swing', function () { + window.location.hash = target; + $(document).on("scroll", onScroll); + }); + } + + function openPopover(e) { + e.preventDefault() + closePopover(); + var popover = $($(this).data('popover')); + popover.toggleClass('open') + e.stopImmediatePropagation(); + } + + function closePopover(e) { + if($('.popover.open').length > 0) { + $('.popover').removeClass('open') + } + } + + $("#button").click(function() { + $('html, body').animate({ + scrollTop: $("#elementtoScrollToID").offset().top + }, 2000); +}); + + function resize() { + $body.removeClass('has-docked-nav') + navOffsetTop = $nav.offset().top + onScroll() + } + + function onScroll() { + if(navOffsetTop < $window.scrollTop() && !$body.hasClass('has-docked-nav')) { + $body.addClass('has-docked-nav') + } + if(navOffsetTop > $window.scrollTop() && $body.hasClass('has-docked-nav')) { + $body.removeClass('has-docked-nav') + } + } + + function escapeHtml(string) { + return String(string).replace(/[&<>"'\/]/g, function (s) { + return entityMap[s]; + }); + } + + function buildSnippets() { + $codeSnippets.each(function() { + var newContent = escapeHtml($(this).html()) + $(this).html(newContent) + }) + } + + + init(); + +});
\ No newline at end of file |