From 257d1f88491929727b85b9d3e0c1d0964c89f774 Mon Sep 17 00:00:00 2001 From: Andrew Teich Date: Fri, 28 Feb 2014 15:32:14 -0500 Subject: [PATCH 1/7] Update jquery.smint.js Resolved issue where last nav item and second to last nav item would quickly alternate being active when scrolling past the bottom of screen by changing the window position check to be >= window height instead of == --- jquery.smint.js | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/jquery.smint.js b/jquery.smint.js index 30c60e9..4a7b533 100644 --- a/jquery.smint.js +++ b/jquery.smint.js @@ -94,7 +94,13 @@ If you like Smint, or have suggestions on how it could be improved, send me a tw // Check if at bottom of page, if so, add class to last as sometimes the last div // isnt long enough to scroll to the top of the page and trigger the active state. - if ($(window).scrollTop() + $(window).height() == $(document).height()) { + + /* Using >= instead of == prevents last item from being + * un-highlighted when the window bounces back in browser + * + * -Andrew Teich + */ + if ($(window).scrollTop() + $(window).height() => $(document).height()) { $smintItems.removeClass('active'); $smintItems.last().addClass('active'); } From 4ac5698209969182dbf97eb8c91779b451f3c8ce Mon Sep 17 00:00:00 2001 From: Andrew Teich Date: Fri, 28 Feb 2014 15:40:55 -0500 Subject: [PATCH 2/7] Fix for nav items flickering when scrolling past bottom of window Resolved issue where last nav item and second to last nav item would quickly alternate being active when scrolling past the bottom of screen by changing the window position check to be >= window height instead of == --- demo/js/jquery.smint.js | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/demo/js/jquery.smint.js b/demo/js/jquery.smint.js index 38f54bd..3cff353 100644 --- a/demo/js/jquery.smint.js +++ b/demo/js/jquery.smint.js @@ -84,7 +84,12 @@ If you like Smint, or have suggestions on how it could be improved, send me a tw // Check if at bottom of page, if so, add class to last as sometimes the last div // isnt long enough to scroll to the top of the page and trigger the active state. - if($window.scrollTop() + $window.height() == $(document).height()) { + /* Using >= instead of == prevents last item from being + * un-highlighted when the window bounces back in browser + * + * -Andrew Teich + */ + if($window.scrollTop() + $window.height() >= $(document).height()) { $smintItems.removeClass('active'); $smintItems.last().addClass('active'); } From 77c15cc6bd52f17d1fb935ef482559b0b4d6c3b2 Mon Sep 17 00:00:00 2001 From: Andrew Teich Date: Fri, 28 Feb 2014 16:04:04 -0500 Subject: [PATCH 3/7] fixed smint-disable itmes from highlighting Fixed issue where if a nav item of class smint-disable was the last nav item, it would become active (highlighted) when the user scrolled to the bottom of the window. $smintItems no longer includes items of class smint-disable. (line 20) --- jquery.smint.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/jquery.smint.js b/jquery.smint.js index 4a7b533..2ef3b1f 100644 --- a/jquery.smint.js +++ b/jquery.smint.js @@ -17,7 +17,7 @@ If you like Smint, or have suggestions on how it could be improved, send me a tw $.fn.smint = function( options ) { var $smint = this, - $smintItems = $smint.find('a'), + $smintItems = $smint.find('a:not([class="smint-disable"])'), //remove smint-disabled items $window = $(window), settings = $.extend({}, $.fn.smint.defaults, options), // Set the variables needed From ca0023c4c8a75711f826e4690da898327e7e8851 Mon Sep 17 00:00:00 2001 From: Andrew Teich Date: Fri, 28 Feb 2014 16:05:27 -0500 Subject: [PATCH 4/7] fixed smint-disable items from highlighting Fixed issue where if a nav item of class smint-disable was the last nav item, it would become active (highlighted) when the user scrolled to the bottom of the window. $smintItems no longer includes items of class smint-disable. (line 20) --- demo/js/jquery.smint.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/demo/js/jquery.smint.js b/demo/js/jquery.smint.js index 3cff353..82da2a7 100644 --- a/demo/js/jquery.smint.js +++ b/demo/js/jquery.smint.js @@ -17,7 +17,7 @@ If you like Smint, or have suggestions on how it could be improved, send me a tw $.fn.smint = function( options ) { var $smint = this, - $smintItems = $smint.find('a'), + $smintItems = $smint.find('a:not([class="smint-disable"])'), $window = $(window), settings = $.extend({}, $.fn.smint.defaults, options), // Set the variables needed From 08bccd7ad70b90420945c1eb5db30118f2a4969a Mon Sep 17 00:00:00 2001 From: Andrew Teich Date: Fri, 28 Feb 2014 16:22:54 -0500 Subject: [PATCH 5/7] Added catch for uncaught Type Error Resolved "Uncaught TypeError: Cannot read property 'id' of undefined" with a check for null value of optionLocs[index+1] on line 67. --- demo/js/jquery.smint.js | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/demo/js/jquery.smint.js b/demo/js/jquery.smint.js index 82da2a7..0a41ec1 100644 --- a/demo/js/jquery.smint.js +++ b/demo/js/jquery.smint.js @@ -64,10 +64,13 @@ If you like Smint, or have suggestions on how it could be improved, send me a tw if(optionLocs[index].top <= scrollTop && scrollTop <= optionLocs[index].bottom){ $smintItems.removeClass("active"); $("#"+id).addClass("active"); - if(!scrollingDown){ - $("#"+optionLocs[index+1].id).removeClass("active"); - } else if(index > 0) { - $("#"+optionLocs[index-1].id).removeClass("active"); + if(optionLocs[index+1]) + { + if(!scrollingDown){ + $("#"+optionLocs[index+1].id).removeClass("active"); + } else if(index > 0) { + $("#"+optionLocs[index-1].id).removeClass("active"); + } } } }; From c187472e4b3455871f8fb5b6abb1d0546ea3464d Mon Sep 17 00:00:00 2001 From: Andrew Teich Date: Fri, 28 Feb 2014 16:30:12 -0500 Subject: [PATCH 6/7] Delete jquery.smint.js from main folder Deleted jquery.smint.js, which has errors, from main folder as there is a different jquery.smint.js in the demo folder which has no errors. --- jquery.smint.js | 158 ------------------------------------------------ 1 file changed, 158 deletions(-) delete mode 100644 jquery.smint.js diff --git a/jquery.smint.js b/jquery.smint.js deleted file mode 100644 index 2ef3b1f..0000000 --- a/jquery.smint.js +++ /dev/null @@ -1,158 +0,0 @@ -/* - -SMINT V1.0 by Robert McCracken -SMINT V2.0 by robert McCracken with some awesome help from Ryan Clarke (@clarkieryan) and mcpacosy (@mcpacosy) - -SMINT is my first dabble into jQuery plugins! - -http://www.outyear.co.uk/smint/ - -If you like Smint, or have suggestions on how it could be improved, send me a tweet @rabmyself - -*/ - - -(function($) { - - $.fn.smint = function( options ) { - - var $smint = this, - $smintItems = $smint.find('a:not([class="smint-disable"])'), //remove smint-disabled items - $window = $(window), - settings = $.extend({}, $.fn.smint.defaults, options), - // Set the variables needed - optionLocs = [], - lastScrollTop = 0, - lastHash = '', - menuHeight = $smint.height(), - curi = 0, - stickyTop = $smint.offset().top; - - var stickyMenu = function(scrollingDown) { - // current distance top - var scrollTop = $(window).scrollTop(); - - // if we scroll more than the navigation, change its position to fixed and add class 'fxd', otherwise change it back to absolute and remove the class - if (scrollTop > stickyTop) { - //Check if he has scrolled horizontally also. - if ($(window).scrollLeft()) { - $smint.css({ 'position': 'fixed', 'top': 0, 'left': -$(window).scrollLeft() }).addClass('fxd'); - } - else { - $smint.css({ 'position': 'fixed', 'top': 0, 'left': 'auto' }).addClass('fxd'); - } - } - else { - $smint.css({ 'position': 'absolute', 'top': stickyTop, 'left': 'auto' }).removeClass('fxd'); - } - - if (!scrollingDown) { - while (true) { - if (scrollTop >= optionLocs[curi].top) { - $smintItems.removeClass('active'); - $('#' + optionLocs[curi].id).addClass('active'); - // The foll. makes the page very slow. - /*if(optionLocs[curi].hash != null && optionLocs[curi].hash != lastHash) { - window.location.hash = optionLocs[curi].hash; - lastHash = optionLocs[curi].hash; - }*/ - break; - } - curi--; - } - } - else { - while (true) { - if (scrollTop < optionLocs[curi].bottom) { - $smintItems.removeClass('active'); - $('#' + optionLocs[curi].id).addClass('active'); - // The foll. makes the page very slow. - /*if(optionLocs[curi].hash != null && optionLocs[curi].hash != lastHash) { - window.location.hash = optionLocs[curi].hash; - lastHash = optionLocs[curi].hash; - }*/ - break; - } - curi++; - //Added as failsafe, should not be needed. - /* - if(curi > optionLocs.length) { - break; - } - */ - } - } - }; - - // run function every time you scroll but not needed to be run for each of the $smintItems - $(window).scroll(function() { - //Get the direction of scroll - var st = $(this).scrollTop(), - scrollingDown = (st > lastScrollTop); - lastScrollTop = st; - stickyMenu(scrollingDown); - - // Check if at bottom of page, if so, add class to last as sometimes the last div - // isnt long enough to scroll to the top of the page and trigger the active state. - - /* Using >= instead of == prevents last item from being - * un-highlighted when the window bounces back in browser - * - * -Andrew Teich - */ - if ($(window).scrollTop() + $(window).height() => $(document).height()) { - $smintItems.removeClass('active'); - $smintItems.last().addClass('active'); - } - }); - - $smintItems.first().addClass('active'); - - // This function assumes that the elements are already in a sorted manner. - $smintItems.each(function() { - // No need to even add to optionLocs - if ($(this).hasClass("smint-disableAll")) { - return; - } - //Fill the menu - var id = this.id, - matchingSection = $("."+id), - sectionTop = matchingSection.position().top, - hash = null; - if($(this).attr("href").indexOf('#') >= 0) { - hash = $(this).attr("href").substr($(this).attr("href").indexOf('#') + 1); - } - optionLocs.push({ - top: sectionTop - menuHeight, - bottom: parseInt(matchingSection.height() * 0.9) + sectionTop - menuHeight, //Added so that if he is scrolling down and has reached 90% of the section. - id: id, - hash: hash - }); - - // if the link has the smint-disable class it will be ignored - // Courtesy of mcpacosy(@mcpacosy) - // No need to add listener if this is the case. - if ($(this).hasClass("smint-disable")) { - return; - } - - $(this).on('click', function(e) { - // stops empty hrefs making the page jump when clicked - // Added after the check of smint-disableAll so that if its an external href it will work. - //e.preventDefault(); - - // Scroll the page to the desired position! - $("html, body").animate({ scrollTop: sectionTop - menuHeight}, settings.scrollSpeed); - }) - }); - - if( (window.location.hash) && (window.location.hash != "#") ) { - // Scroll to the set hash. - $('a[href=' + window.location.hash + ']').trigger('click'); - } - - } - - $.fn.smint.defaults = { 'scrollSpeed': 500}; - -})(jQuery); From 2f91eed8097f64f67634c9249b557c64e947021b Mon Sep 17 00:00:00 2001 From: Andrew Teich Date: Fri, 28 Feb 2014 16:55:25 -0500 Subject: [PATCH 7/7] Allow smint-disable to have other classes Will now check if classes contain smint-disable, as opposed to if the class is exactly "smint-disable" --- demo/js/jquery.smint.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/demo/js/jquery.smint.js b/demo/js/jquery.smint.js index 0a41ec1..0773551 100644 --- a/demo/js/jquery.smint.js +++ b/demo/js/jquery.smint.js @@ -17,7 +17,7 @@ If you like Smint, or have suggestions on how it could be improved, send me a tw $.fn.smint = function( options ) { var $smint = this, - $smintItems = $smint.find('a:not([class="smint-disable"])'), + $smintItems = $smint.find('a:not([class*="smint-disable"])'), $window = $(window), settings = $.extend({}, $.fn.smint.defaults, options), // Set the variables needed