diff --git a/CHANGELOG.md b/CHANGELOG.md index 227c1b2..5f66ef4 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,3 +1,7 @@ +## Changes in 0.0.2 + + * @edwardoparearyee: Fix: Error in docs (#4) + ## Changes in 0.0.1 * @edwardoparearyee: First release diff --git a/Gruntfile.js b/Gruntfile.js index 9986a73..804943b 100644 --- a/Gruntfile.js +++ b/Gruntfile.js @@ -182,7 +182,7 @@ module.exports = function (grunt) { concat: { options: { - sourceMap: true, + sourceMap: false, separator: ';', banner: '/*! <%= pkg.name %> - v<%= pkg.version %> - ' + '<%= grunt.template.today(\'yyyy-mm-dd\') %> */\n' @@ -195,8 +195,7 @@ module.exports = function (grunt) { uglify: { options: { - sourceMap: true, - sourceMapIncludeSources: true, + sourceMap: false, enclose: { window: 'window' }, banner: '/*! <%= pkg.name %> - v<%= pkg.version %> - ' + '<%= grunt.template.today(\'yyyy-mm-dd\') %> */\n' diff --git a/README.md b/README.md index e5c3dda..844069a 100644 --- a/README.md +++ b/README.md @@ -56,7 +56,7 @@ nav.scrolling-down { opacity: 0; } nav.scrolling-up { - opacity: 0; + opacity: 1; } ``` diff --git a/dist/angular-smart-nav.js b/dist/angular-smart-nav.js new file mode 100644 index 0000000..6ece62e --- /dev/null +++ b/dist/angular-smart-nav.js @@ -0,0 +1,125 @@ +/*! angular-smart-nav - v0.0.1 - 2015-11-03 */ +'use strict'; +/** + * Module that detects the last scroll direction and + * current scroll position to then add classes for + * when the user is scrolling up or down the page + * to show/hide the nav when scrolling in any particular + * direction. Also when the user has scrolled beyond the + * height of header adds a class to allow the nav to be + * minimized or hidden. + * + * When the user has scrolled down the page the class + * `scrolling-down` will be added, when scrolling up + * `scrolling-up`. If the user has scrolled beyond the + * height of the nav the class `minimised-mode`. + * + * @module sn.smartNav + * @main sn.smartNav + * @author SOON_ + */ +angular.module('sn.smartNav', [ + +]) +/** + * @example + * `` + * @class snSmartNav + * @param {Service} $window : Angular.js wrapper for window Object + * @param {Service} $document : Angular.js wrapper for document Object + */ +.directive('snSmartNav',[ + '$window', + '$document', + function ($window, $document){ + return { + restrict: 'A', + scope: {}, + link: function($scope, $element){ + /** + * The last recorded scrollTop position + * @private + * @property lastScrollTop + * @type {Number} + */ + var lastScrollTop = 0; + /** + * True if the last scroll direction was down the page + * @private + * @property scrollingDown + * @type {Boolean} + */ + var scrollingDown = false; + /** + * @method isScrollingDown + * @private + * @param {Number} currentScrollTop + * @return {Boolean} True if last scroll direction is down + */ + var isScrollingDown = function isScrollingDown(currentScrollTop){ + return currentScrollTop > lastScrollTop; + }; + /** + * @method isScrollingUp + * @private + * @param {Number} currentScrollTop + * @return {Boolean} True if last scroll direction is up + */ + var isScrollingUp = function isScrollingUp(currentScrollTop){ + return currentScrollTop < lastScrollTop; + }; + /** + * Calulate the current scroll direction and add relevent classes + * @private + * @method calScrollDir + * @param {Number} scrollTop + */ + var calScrollDir = function calScrollDir(scrollTop){ + if ( scrollingDown && isScrollingUp(scrollTop) ) { + scrollingDown = false; + $element.removeClass('scrolling-down'); + $element.addClass('scrolling-up'); + } else if ( !scrollingDown && isScrollingDown(scrollTop) ){ + scrollingDown = true; + $element.removeClass('scrolling-up'); + $element.addClass('scrolling-down'); + } + }; + /** + * Calulate if the user has scrolled beyond the height of the element + * @private + * @method calMinimisedMode + * @param {Number} scrollTop + */ + var calMinimisedMode = function calMinimisedMode(scrollTop){ + if (scrollTop > $element[0].offsetHeight) { + $element.addClass('minimised-mode'); + } else { + $element.removeClass('minimised-mode'); + } + }; + /** + * window `scroll` event handler. + * Gets the current scroll postion and calulates + * scroll direction and whether to enable minimise mode + * @private + * @method onScroll + */ + var onScroll = function onScroll() { + var doc = $document[0].documentElement, + body = $document[0].body, + scrollTop = ( (doc && doc.scrollTop) || (body && body.scrollTop) || 0 ); + + calScrollDir(scrollTop); + calMinimisedMode(scrollTop); + + lastScrollTop = scrollTop; + }; + + angular.element($window).on('scroll', onScroll); + } + }; + } +]); + +//# sourceMappingURL=angular-smart-nav.js.map \ No newline at end of file diff --git a/dist/angular-smart-nav.min.js b/dist/angular-smart-nav.min.js new file mode 100644 index 0000000..95a35a9 --- /dev/null +++ b/dist/angular-smart-nav.min.js @@ -0,0 +1,4 @@ +/*! angular-smart-nav - v0.0.1 - 2015-11-03 */ + +!function(a){"use strict";angular.module("sn.smartNav",[]).directive("snSmartNav",["$window","$document",function(a,b){return{restrict:"A",scope:{},link:function(c,d){var e=0,f=!1,g=function(a){return a>e},h=function(a){return e>a},i=function(a){f&&h(a)?(f=!1,d.removeClass("scrolling-down"),d.addClass("scrolling-up")):!f&&g(a)&&(f=!0,d.removeClass("scrolling-up"),d.addClass("scrolling-down"))},j=function(a){a>d[0].offsetHeight?d.addClass("minimised-mode"):d.removeClass("minimised-mode")},k=function(){var a=b[0].documentElement,c=b[0].body,d=a&&a.scrollTop||c&&c.scrollTop||0;i(d),j(d),e=d};angular.element(a).on("scroll",k)}}}])}(window); +//# sourceMappingURL=angular-smart-nav.min.js.map \ No newline at end of file