Skip to content
This repository has been archived by the owner on Jun 18, 2022. It is now read-only.

Added jshint support. Issue#12 #17

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 17 additions & 0 deletions .jshintrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
{
"undef": true,
"curly": true,
"eqeqeq": true,
"browser": true,
"bitwise": true,
"forin": true,
"indent": 4,
"newcap": true,
"nonbsp": true,
"nonew": true,
"trailing": true,
"devel": true, // This is not totally OK for production, but mehhh!!
"globals": {
"jQuery": true
}
}
225 changes: 114 additions & 111 deletions stickUp.js
Original file line number Diff line number Diff line change
@@ -1,122 +1,125 @@
jQuery(
function($) {

$(document).ready(function(){
var contentButton = [];
var contentTop = [];
var content = [];
var lastScrollTop = 0;
var scrollDir = '';
var itemClass = '';
var itemHover = '';
var menuSize = null;
var stickyHeight = 0;
var stickyMarginB = 0;
var currentMarginT = 0;
var topMargin = 0;
$(window).scroll(function(event){
var st = $(this).scrollTop();
if (st > lastScrollTop){
scrollDir = 'down';
} else {
scrollDir = 'up';
}
lastScrollTop = st;
});
$.fn.stickUp = function( options ) {
// adding a class to users div
$(this).addClass('stuckMenu');
//getting options
var objn = 0;
if(options != null) {
for(var o in options.parts) {
if (options.parts.hasOwnProperty(o)){
content[objn] = options.parts[objn];
objn++;
}
}
if(objn == 0) {
console.log('error:needs arguments');
}

$(document).ready(function(){
var contentTop = [];
var content = [];
var lastScrollTop = 0;
var scrollDir = '';
var itemClass = '';
var itemHover = '';
var menuSize = null;
var stickyHeight = 0;
var stickyMarginB = 0;
var currentMarginT = 0;
var topMargin = 0;
var vartop = 0;
var varscroll = 0;

itemClass = options.itemClass;
itemHover = options.itemHover;
if(options.topMargin != null) {
if(options.topMargin == 'auto') {
topMargin = parseInt($('.stuckMenu').css('margin-top'));
} else {
if(isNaN(options.topMargin) && options.topMargin.search("px") > 0){
topMargin = parseInt(options.topMargin.replace("px",""));
} else if(!isNaN(parseInt(options.topMargin))) {
topMargin = parseInt(options.topMargin);
} else {
console.log("incorrect argument, ignored.");
topMargin = 0;
}
}
} else {
topMargin = 0;
}
menuSize = $('.'+itemClass).size();
}
stickyHeight = parseInt($(this).height());
stickyMarginB = parseInt($(this).css('margin-bottom'));
currentMarginT = parseInt($(this).next().closest('div').css('margin-top'));
vartop = parseInt($(this).offset().top);
//$(this).find('*').removeClass(itemHover);
}
$(document).on('scroll', function() {
varscroll = parseInt($(document).scrollTop());
if(menuSize != null){
for(var i=0;i < menuSize;i++)
{
contentTop[i] = $('#'+content[i]+'').offset().top;
function bottomView(i) {
contentView = $('#'+content[i]+'').height()*.4;
testView = contentTop[i] - contentView;
//console.log(varscroll);
if(varscroll > testView){
$('.'+itemClass).removeClass(itemHover);
$('.'+itemClass+':eq('+i+')').addClass(itemHover);
} else if(varscroll < 50){
$('.'+itemClass).removeClass(itemHover);
$('.'+itemClass+':eq(0)').addClass(itemHover);
}
}
if(scrollDir == 'down' && varscroll > contentTop[i]-50 && varscroll < contentTop[i]+50) {
$('.'+itemClass).removeClass(itemHover);
$('.'+itemClass+':eq('+i+')').addClass(itemHover);
}
if(scrollDir == 'up') {
bottomView(i);
}
}
}
$(window).scroll(function(event){
var st = $(this).scrollTop();
if (st > lastScrollTop){
scrollDir = 'down';
} else {
scrollDir = 'up';
}
lastScrollTop = st;
});
$.fn.stickUp = function( options ) {
// adding a class to users div
$(this).addClass('stuckMenu');
//getting options
var objn = 0;
if (options) {
for(var o in options.parts) {
if (options.parts.hasOwnProperty(o)){
content[objn] = options.parts[objn];
objn++;
}
}

if (objn) {
console.log('error:needs arguments');
}

itemClass = options.itemClass;
itemHover = options.itemHover;
if(options.topMargin) {
if(options.topMargin === 'auto') {
topMargin = parseInt($('.stuckMenu').css('margin-top'));
} else {
if(isNaN(options.topMargin) && options.topMargin.search("px") > 0){
topMargin = parseInt(options.topMargin.replace("px",""));
} else if(!isNaN(parseInt(options.topMargin))) {
topMargin = parseInt(options.topMargin);
} else {
console.log("incorrect argument, ignored.");
topMargin = 0;
}
}
} else {
topMargin = 0;
}
menuSize = $('.'+itemClass).size();
}
stickyHeight = parseInt($(this).height());
stickyMarginB = parseInt($(this).css('margin-bottom'));
currentMarginT = parseInt($(this).next().closest('div').css('margin-top'));
vartop = parseInt($(this).offset().top);
//$(this).find('*').removeClass(itemHover);
};

if(vartop < varscroll + topMargin){
$('.stuckMenu').addClass('isStuck');
$('.stuckMenu').next().closest('div').css({
'margin-top': stickyHeight + stickyMarginB + currentMarginT + 'px'
}, 10);
$('.stuckMenu').css("position","fixed");
$('.isStuck').css({
top: '0px'
}, 10, function(){
function bottomView(i) {
var contentView = $('#'+content[i]+'').height() * 0.4,
testView = contentTop[i] - contentView;

});
};
//console.log(varscroll);
if(varscroll > testView){
$('.'+itemClass).removeClass(itemHover);
$('.'+itemClass+':eq('+i+')').addClass(itemHover);
} else if(varscroll < 50){
$('.'+itemClass).removeClass(itemHover);
$('.'+itemClass+':eq(0)').addClass(itemHover);
}
}

if(varscroll + topMargin < vartop){
$('.stuckMenu').removeClass('isStuck');
$('.stuckMenu').next().closest('div').css({
'margin-top': currentMarginT + 'px'
}, 10);
$('.stuckMenu').css("position","relative");
};
$(document).on('scroll', function() {
if (menuSize) {
for (var i=0;i < menuSize;i++) {
contentTop[i] = $('#'+content[i]+'').offset().top;

if(scrollDir === 'down' && varscroll > contentTop[i]-50 && varscroll < contentTop[i]+50) {
$('.'+itemClass).removeClass(itemHover);
$('.'+itemClass+':eq('+i+')').addClass(itemHover);
}
if(scrollDir === 'up') {
bottomView(i);
}
}
}

});
});
if (vartop < varscroll + topMargin) {
$('.stuckMenu').addClass('isStuck');
$('.stuckMenu').next().closest('div').css({
'margin-top': stickyHeight + stickyMarginB + currentMarginT + 'px'
}, 10);
$('.stuckMenu').css("position","fixed");
$('.isStuck').css({
top: '0px'
}, 10, function(){

});
}

if (varscroll + topMargin < vartop) {
$('.stuckMenu').removeClass('isStuck');
$('.stuckMenu').next().closest('div').css({
'margin-top': currentMarginT + 'px'
}, 10);
$('.stuckMenu').css("position","relative");
}

});
});

});
2 changes: 1 addition & 1 deletion stickUp.min.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.