summaryrefslogtreecommitdiff
path: root/js
diff options
context:
space:
mode:
authorThomas Park <thomas@thomaspark.me>2013-02-09 18:45:05 -0500
committerThomas Park <thomas@thomaspark.me>2013-02-09 18:45:05 -0500
commitb169fbeea6819a511498ee4ad42ad4f66eaa3e0a (patch)
treeeec06706eb0bed5bfc5e964f132093f3140a31d5 /js
parent0a291e362337e267b105cda80d39a700c8221036 (diff)
added smooth scrolling
Diffstat (limited to 'js')
-rwxr-xr-xjs/application.js35
-rw-r--r--js/bootswatch.js95
2 files changed, 94 insertions, 36 deletions
diff --git a/js/application.js b/js/application.js
deleted file mode 100755
index 8daeebf6..00000000
--- a/js/application.js
+++ /dev/null
@@ -1,35 +0,0 @@
-(function ($) {
-
- $(function(){
-
- // fix sub nav on scroll
- var $win = $(window),
- $body = $('body'),
- $nav = $('.subnav'),
- navHeight = $('.navbar').first().height(),
- subnavHeight = $('.subnav').first().height(),
- subnavTop = $('.subnav').length && $('.subnav').offset().top - navHeight,
- marginTop = parseInt($body.css('margin-top'), 10);
- isFixed = 0;
-
- processScroll();
-
- $win.on('scroll', processScroll);
-
- function processScroll() {
- var i, scrollTop = $win.scrollTop();
-
- if (scrollTop >= subnavTop && !isFixed) {
- isFixed = 1;
- $nav.addClass('subnav-fixed');
- $body.css('margin-top', marginTop + subnavHeight + 'px');
- } else if (scrollTop <= subnavTop && isFixed) {
- isFixed = 0;
- $nav.removeClass('subnav-fixed');
- $body.css('margin-top', marginTop + 'px');
- }
- }
-
- });
-
-})(window.jQuery); \ No newline at end of file
diff --git a/js/bootswatch.js b/js/bootswatch.js
index 231ad8f9..66b67b28 100644
--- a/js/bootswatch.js
+++ b/js/bootswatch.js
@@ -1,7 +1,11 @@
+// tooltips
+
$('a[rel=tooltip]').tooltip({
'placement': 'bottom'
});
+// recent news
+
function parseRSS(url, callback) {
$.ajax({
url: 'http://ajax.googleapis.com/ajax/services/feed/load?v=1.0&num=10&callback=?&q=' + encodeURIComponent(url),
@@ -10,4 +14,93 @@ function parseRSS(url, callback) {
callback(data.responseData.feed);
}
});
-} \ No newline at end of file
+}
+
+// smooth scroll
+
+$(document).ready(function() {
+ function filterPath(string) {
+ return string
+ .replace(/^\//,'')
+ .replace(/(index|default).[a-zA-Z]{3,4}$/,'')
+ .replace(/\/$/,'');
+ }
+ var locationPath = filterPath(location.pathname);
+ var scrollElem = scrollableElement('html', 'body');
+
+ $('a[href*=#]').each(function() {
+ var thisPath = filterPath(this.pathname) || locationPath;
+ if ( locationPath == thisPath
+ && (location.hostname == this.hostname || !this.hostname)
+ && this.hash.replace(/#/,'') ) {
+ var $target = $(this.hash), target = this.hash;
+ if (target) {
+ var targetOffset = $target.offset().top;
+ $(this).click(function(event) {
+ event.preventDefault();
+ $(scrollElem).animate({scrollTop: targetOffset}, 400, function() {
+ location.hash = target;
+ });
+ });
+ }
+ }
+ });
+
+ // use the first element that is "scrollable"
+ function scrollableElement(els) {
+ for (var i = 0, argLength = arguments.length; i <argLength; i++) {
+ var el = arguments[i],
+ $scrollElement = $(el);
+ if ($scrollElement.scrollTop()> 0) {
+ return el;
+ } else {
+ $scrollElement.scrollTop(1);
+ var isScrollable = $scrollElement.scrollTop()> 0;
+ $scrollElement.scrollTop(0);
+ if (isScrollable) {
+ return el;
+ }
+ }
+ }
+ return [];
+ }
+
+});
+
+// subnav
+
+(function ($) {
+
+ $(function(){
+
+ // fix sub nav on scroll
+ var $win = $(window),
+ $body = $('body'),
+ $nav = $('.subnav'),
+ navHeight = $('.navbar').first().height(),
+ subnavHeight = $('.subnav').first().height(),
+ subnavTop = $('.subnav').length && $('.subnav').offset().top - navHeight,
+ marginTop = parseInt($body.css('margin-top'), 10);
+ isFixed = 0;
+
+ processScroll();
+
+ $win.on('scroll', processScroll);
+
+ function processScroll() {
+ var i, scrollTop = $win.scrollTop();
+
+ if (scrollTop >= subnavTop && !isFixed) {
+ isFixed = 1;
+ $nav.addClass('subnav-fixed');
+ $body.css('margin-top', marginTop + subnavHeight + 'px');
+ } else if (scrollTop <= subnavTop && isFixed) {
+ isFixed = 0;
+ $nav.removeClass('subnav-fixed');
+ $body.css('margin-top', marginTop + 'px');
+ }
+ }
+
+ });
+
+})(window.jQuery); \ No newline at end of file