From 3e8b34be2fdeccf16c8b46f1ee518f970853768d Mon Sep 17 00:00:00 2001 From: Mitch Riedstra Date: Tue, 24 Oct 2017 16:59:48 -0400 Subject: Adding in materialize source and templates --- app/dispatch/static/materialize/js/pushpin.js | 71 +++++++++++++++++++++++++++ 1 file changed, 71 insertions(+) create mode 100644 app/dispatch/static/materialize/js/pushpin.js (limited to 'app/dispatch/static/materialize/js/pushpin.js') diff --git a/app/dispatch/static/materialize/js/pushpin.js b/app/dispatch/static/materialize/js/pushpin.js new file mode 100644 index 0000000..4fef6c3 --- /dev/null +++ b/app/dispatch/static/materialize/js/pushpin.js @@ -0,0 +1,71 @@ +(function ($) { + $.fn.pushpin = function (options) { + // Defaults + var defaults = { + top: 0, + bottom: Infinity, + offset: 0 + }; + + // Remove pushpin event and classes + if (options === "remove") { + this.each(function () { + if (id = $(this).data('pushpin-id')) { + $(window).off('scroll.' + id); + $(this).removeData('pushpin-id').removeClass('pin-top pinned pin-bottom').removeAttr('style'); + } + }); + return false; + } + + options = $.extend(defaults, options); + + + $index = 0; + return this.each(function() { + var $uniqueId = Materialize.guid(), + $this = $(this), + $original_offset = $(this).offset().top; + + function removePinClasses(object) { + object.removeClass('pin-top'); + object.removeClass('pinned'); + object.removeClass('pin-bottom'); + } + + function updateElements(objects, scrolled) { + objects.each(function () { + // Add position fixed (because its between top and bottom) + if (options.top <= scrolled && options.bottom >= scrolled && !$(this).hasClass('pinned')) { + removePinClasses($(this)); + $(this).css('top', options.offset); + $(this).addClass('pinned'); + } + + // Add pin-top (when scrolled position is above top) + if (scrolled < options.top && !$(this).hasClass('pin-top')) { + removePinClasses($(this)); + $(this).css('top', 0); + $(this).addClass('pin-top'); + } + + // Add pin-bottom (when scrolled position is below bottom) + if (scrolled > options.bottom && !$(this).hasClass('pin-bottom')) { + removePinClasses($(this)); + $(this).addClass('pin-bottom'); + $(this).css('top', options.bottom - $original_offset); + } + }); + } + + $(this).data('pushpin-id', $uniqueId); + updateElements($this, $(window).scrollTop()); + $(window).on('scroll.' + $uniqueId, function () { + var $scrolled = $(window).scrollTop() + options.offset; + updateElements($this, $scrolled); + }); + + }); + + }; +}( jQuery )); \ No newline at end of file -- cgit v1.2.3