Skip to content
This repository was archived by the owner on Jun 9, 2021. It is now read-only.

Update jquery bower version and add gitignore #141

Open
wants to merge 4 commits 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
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
node_modules
bower_components
4 changes: 2 additions & 2 deletions bower.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,6 @@
"*.css"
],
"dependencies": {
"jquery": "~1.8.0"
"jquery": ">=1.11.0"
}
}
}
37 changes: 36 additions & 1 deletion jquery.nav.js
Original file line number Diff line number Diff line change
Expand Up @@ -129,6 +129,9 @@
var returnValue = null;
var windowHeight = Math.round(this.$win.height() * this.config.scrollThreshold);

// Sort Sections by Position
this.sections = this.sortSectionsByPosition(this.sections);

for(var section in this.sections) {
if((this.sections[section] - windowHeight) < windowPos) {
returnValue = section;
Expand All @@ -138,6 +141,38 @@
return returnValue;
},

/**
* Sort Sections by its position value
* based on http://am.aurlien.net/post/1221493460/sorting-javascript-objects
* @param {Object} obj Object to sort
* @return {Object} sorted Object
*/
sortSectionsByPosition: function (obj) {
var tempArray = [];
var tempObj = {};

// Transform Object in Array
for (var key in obj) {
if (obj.hasOwnProperty(key)) {
tempArray.push(key);
}
}

tempArray.sort(function(a,b) {
var x = obj[a];
var y = obj[b];

return ((x < y) ? -1 : ((x > y) ? 1 : 0));
});

// Transform sorted tempArray back into Object
for (var i=0; i<tempArray.length; i++) {
tempObj[tempArray[i]] = obj[tempArray[i]];
}

return tempObj;
},

handleClick: function(e) {
var self = this;
var $link = $(e.currentTarget);
Expand Down Expand Up @@ -220,4 +255,4 @@
});
};

})( jQuery, window , document );
})( jQuery, window , document );