From 8545fe97877dc275df40ab98d408f21ce9a362cf Mon Sep 17 00:00:00 2001 From: Jacob Thornton Date: Wed, 19 Oct 2011 21:56:06 -0700 Subject: greatly simply js plugins - remove js api where reasonable --- js/bootstrap-scrollspy.js | 25 +------------------------ 1 file changed, 1 insertion(+), 24 deletions(-) (limited to 'js/bootstrap-scrollspy.js') diff --git a/js/bootstrap-scrollspy.js b/js/bootstrap-scrollspy.js index 4b146e580..23bdf59e9 100644 --- a/js/bootstrap-scrollspy.js +++ b/js/bootstrap-scrollspy.js @@ -75,30 +75,7 @@ } - /* SCROLLSPY PLUGIN DEFINITION - * =========================== */ - - $.fn.scrollSpy = function( options ) { - var scrollspy = this.data('scrollspy') - - if (!scrollspy) { - return this.each(function () { - $(this).data('scrollspy', new ScrollSpy( this, options )) - }) - } - - if ( options === true ) { - return scrollspy - } - - if ( typeof options == 'string' ) { - scrollspy[options]() - } - - return this - } - - $(document).ready(function () { + $(function () { $('body').scrollSpy('[data-scrollspy] li > a') }) -- cgit v1.2.3 From 523e02f7df3bb706654b43cf604e61c9396212e1 Mon Sep 17 00:00:00 2001 From: Jacob Thornton Date: Wed, 19 Oct 2011 23:12:50 -0700 Subject: fix scrollspy simplify stuff more - break everything. --- js/bootstrap-scrollspy.js | 33 ++++++++++++++++++++------------- 1 file changed, 20 insertions(+), 13 deletions(-) (limited to 'js/bootstrap-scrollspy.js') diff --git a/js/bootstrap-scrollspy.js b/js/bootstrap-scrollspy.js index 23bdf59e9..1269d91ec 100644 --- a/js/bootstrap-scrollspy.js +++ b/js/bootstrap-scrollspy.js @@ -1,5 +1,5 @@ /* ============================================================= - * bootstrap-scrollspy.js v1.3.0 + * bootstrap-scrollspy.js v2.0.0 * http://twitter.github.com/bootstrap/javascript.html#scrollspy * ============================================================= * Copyright 2011 Twitter, Inc. @@ -22,14 +22,14 @@ var $window = $(window) - function ScrollSpy( topbar, selector ) { - var processScroll = $.proxy(this.processScroll, this) - this.$topbar = $(topbar) - this.selector = selector || 'li > a' + function ScrollSpy() { + var process = $.proxy(this.process, this) + this.$topbar = $('body') + this.selector = '[data-scrollspy] li > a' this.refresh() - this.$topbar.delegate(this.selector, 'click', processScroll) - $window.scroll(processScroll) - this.processScroll() + this.$topbar.delegate(this.selector, 'click', process) + $window.scroll(process) + this.process() } ScrollSpy.prototype = { @@ -45,7 +45,7 @@ }) } - , processScroll: function () { + , process: function () { var scrollTop = $window.scrollTop() + 10 , offsets = this.offsets , targets = this.targets @@ -56,27 +56,34 @@ activeTarget != targets[i] && scrollTop >= offsets[i] && (!offsets[i + 1] || scrollTop <= offsets[i + 1]) - && this.activateButton( targets[i] ) + && this.activate( targets[i] ) } } - , activateButton: function (target) { + , activate: function (target) { + var active + this.activeTarget = target this.$topbar .find(this.selector).parent('.active') .removeClass('active') - this.$topbar + active = this.$topbar .find(this.selector + '[href="' + target + '"]') .parent('li') .addClass('active') + + if ( active.parent('.dropdown-menu') ) { + active.closest('li.dropdown').addClass('active') + } + } } $(function () { - $('body').scrollSpy('[data-scrollspy] li > a') + new ScrollSpy() }) }( window.jQuery || window.ender ) \ No newline at end of file -- cgit v1.2.3 From bc65b58551575c9dfb2e4d9f4f7af97009e39432 Mon Sep 17 00:00:00 2001 From: Jacob Thornton Date: Sun, 20 Nov 2011 20:58:04 -0800 Subject: merge in js from 1.4... start working through js docs --- js/bootstrap-scrollspy.js | 33 ++++++++++++++++----------------- 1 file changed, 16 insertions(+), 17 deletions(-) (limited to 'js/bootstrap-scrollspy.js') diff --git a/js/bootstrap-scrollspy.js b/js/bootstrap-scrollspy.js index 1269d91ec..91c2dcb1e 100644 --- a/js/bootstrap-scrollspy.js +++ b/js/bootstrap-scrollspy.js @@ -20,33 +20,34 @@ !function ( $ ) { - var $window = $(window) - function ScrollSpy() { var process = $.proxy(this.process, this) - this.$topbar = $('body') - this.selector = '[data-scrollspy] li > a' + this.selector = '.nav li > a' + + this.$body = $('body').delegate(this.selector, 'click', process) + this.$scrollElement = $('[data-spy="scroll"]').bind('scroll', process) + this.refresh() - this.$topbar.delegate(this.selector, 'click', process) - $window.scroll(process) this.process() } ScrollSpy.prototype = { refresh: function () { - this.targets = this.$topbar.find(this.selector).map(function () { - var href = $(this).attr('href') - return /^#\w/.test(href) && $(href).length ? href : null - }) + this.targets = this.$body + .find(this.selector) + .map(function () { + var href = $(this).attr('href') + return /^#\w/.test(href) && $(href).length ? href : null + }) this.offsets = $.map(this.targets, function (id) { - return $(id).offset().top + return $(id).position().top }) } , process: function () { - var scrollTop = $window.scrollTop() + 10 + var scrollTop = this.$scrollElement.scrollTop() + 10 , offsets = this.offsets , targets = this.targets , activeTarget = this.activeTarget @@ -65,11 +66,11 @@ this.activeTarget = target - this.$topbar + this.$body .find(this.selector).parent('.active') .removeClass('active') - active = this.$topbar + active = this.$body .find(this.selector + '[href="' + target + '"]') .parent('li') .addClass('active') @@ -82,8 +83,6 @@ } - $(function () { - new ScrollSpy() - }) + $(function () { new ScrollSpy() }) }( window.jQuery || window.ender ) \ No newline at end of file -- cgit v1.2.3 From 53ff2682cd95dd96fc1fbf234d7b0530127a464b Mon Sep 17 00:00:00 2001 From: Jacob Thornton Date: Thu, 24 Nov 2011 20:27:18 -0800 Subject: clean up scrollspy a bit - add public api method --- js/bootstrap-scrollspy.js | 34 ++++++++++++++++++++++++++++------ 1 file changed, 28 insertions(+), 6 deletions(-) (limited to 'js/bootstrap-scrollspy.js') diff --git a/js/bootstrap-scrollspy.js b/js/bootstrap-scrollspy.js index 91c2dcb1e..e846fd718 100644 --- a/js/bootstrap-scrollspy.js +++ b/js/bootstrap-scrollspy.js @@ -17,15 +17,19 @@ * limitations under the License. * ============================================================== */ - !function ( $ ) { - function ScrollSpy() { + "use strict" + + /* SCROLLSPY CLASS DEFINITION + * ========================== */ + + function ScrollSpy( element ) { var process = $.proxy(this.process, this) this.selector = '.nav li > a' - this.$body = $('body').delegate(this.selector, 'click', process) - this.$scrollElement = $('[data-spy="scroll"]').bind('scroll', process) + this.$body = $('body').delegate(this.selector, 'click.scroll.data-api', process) + this.$scrollElement = $(element).bind('scroll.scroll.data-api', process) this.refresh() this.process() @@ -78,11 +82,29 @@ if ( active.parent('.dropdown-menu') ) { active.closest('li.dropdown').addClass('active') } - } } - $(function () { new ScrollSpy() }) + + /* SCROLLSPY PLUGIN DEFINITION + * =========================== */ + + $.fn.scrollspy = function ( option ) { + return this.each(function () { + var $this = $(this) + , data = $this.data('scrollspy') + if (!data) $this.data('scrollspy', (data = new ScrollSpy(this))) + if (typeof option == 'string') data[option]() + }) + } + + $.fn.alert.ScrollSpy = ScrollSpy + + + /* SCROLLSPY DATA-API + * ============== */ + + $(function () { $('[data-spy="scroll"]').scrollspy() }) }( window.jQuery || window.ender ) \ No newline at end of file -- cgit v1.2.3 From 96adf8f91811a71bf2fbd6737c8bd80fe400b8c2 Mon Sep 17 00:00:00 2001 From: Jacob Thornton Date: Thu, 24 Nov 2011 20:27:55 -0800 Subject: fix copy paste bug --- js/bootstrap-scrollspy.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'js/bootstrap-scrollspy.js') diff --git a/js/bootstrap-scrollspy.js b/js/bootstrap-scrollspy.js index e846fd718..ac9477d0e 100644 --- a/js/bootstrap-scrollspy.js +++ b/js/bootstrap-scrollspy.js @@ -99,7 +99,7 @@ }) } - $.fn.alert.ScrollSpy = ScrollSpy + $.fn.scrollspy.ScrollSpy = ScrollSpy /* SCROLLSPY DATA-API -- cgit v1.2.3 From bd8745a98b93fb55e4c1c08a34e97bd30a16798c Mon Sep 17 00:00:00 2001 From: Jacob Thornton Date: Fri, 25 Nov 2011 17:30:52 -0800 Subject: allow scrollspy to target a specific nav --- js/bootstrap-scrollspy.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'js/bootstrap-scrollspy.js') diff --git a/js/bootstrap-scrollspy.js b/js/bootstrap-scrollspy.js index ac9477d0e..e4bfea483 100644 --- a/js/bootstrap-scrollspy.js +++ b/js/bootstrap-scrollspy.js @@ -26,10 +26,10 @@ function ScrollSpy( element ) { var process = $.proxy(this.process, this) - this.selector = '.nav li > a' - this.$body = $('body').delegate(this.selector, 'click.scroll.data-api', process) this.$scrollElement = $(element).bind('scroll.scroll.data-api', process) + this.selector = (this.$scrollElement.attr('data-target') || '') + ' .nav li > a' + this.$body = $('body').delegate(this.selector, 'click.scroll.data-api', process) this.refresh() this.process() -- cgit v1.2.3 From 46fe38386afce7149810b1feb534726735ce28b2 Mon Sep 17 00:00:00 2001 From: Jacob Thornton Date: Sun, 27 Nov 2011 17:04:55 -0800 Subject: rename tabs to tab - clean up lots of api stuff make href acceptable target val --- js/bootstrap-scrollspy.js | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) (limited to 'js/bootstrap-scrollspy.js') diff --git a/js/bootstrap-scrollspy.js b/js/bootstrap-scrollspy.js index e4bfea483..fe34019ff 100644 --- a/js/bootstrap-scrollspy.js +++ b/js/bootstrap-scrollspy.js @@ -28,7 +28,9 @@ var process = $.proxy(this.process, this) this.$scrollElement = $(element).bind('scroll.scroll.data-api', process) - this.selector = (this.$scrollElement.attr('data-target') || '') + ' .nav li > a' + this.selector = (this.$scrollElement.attr('data-target') + || this.$scrollElement.attr('href') + || '') + ' .nav li > a' this.$body = $('body').delegate(this.selector, 'click.scroll.data-api', process) this.refresh() -- cgit v1.2.3 From cee2f61898f4807311402fed747a93ee68a31f8f Mon Sep 17 00:00:00 2001 From: Jacob Thornton Date: Wed, 30 Nov 2011 22:42:22 -0800 Subject: define constructor on prototypes --- js/bootstrap-scrollspy.js | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) (limited to 'js/bootstrap-scrollspy.js') diff --git a/js/bootstrap-scrollspy.js b/js/bootstrap-scrollspy.js index fe34019ff..8248b6cbd 100644 --- a/js/bootstrap-scrollspy.js +++ b/js/bootstrap-scrollspy.js @@ -39,7 +39,9 @@ ScrollSpy.prototype = { - refresh: function () { + constructor: ScrollSpy + + , refresh: function () { this.targets = this.$body .find(this.selector) .map(function () { -- cgit v1.2.3 From 1ef5fa7d6b4e50230c0c12919b0a06a9a2ac07f1 Mon Sep 17 00:00:00 2001 From: Jacob Thornton Date: Tue, 20 Dec 2011 18:02:47 -0800 Subject: giant refactor - all spec passing again... --- js/bootstrap-scrollspy.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'js/bootstrap-scrollspy.js') diff --git a/js/bootstrap-scrollspy.js b/js/bootstrap-scrollspy.js index 8248b6cbd..3c271793c 100644 --- a/js/bootstrap-scrollspy.js +++ b/js/bootstrap-scrollspy.js @@ -31,7 +31,7 @@ this.selector = (this.$scrollElement.attr('data-target') || this.$scrollElement.attr('href') || '') + ' .nav li > a' - this.$body = $('body').delegate(this.selector, 'click.scroll.data-api', process) + this.$body = $('body').on('click.scroll.data-api', this.selector, process) this.refresh() this.process() @@ -111,4 +111,4 @@ $(function () { $('[data-spy="scroll"]').scrollspy() }) -}( window.jQuery || window.ender ) \ No newline at end of file +}( window.jQuery ) \ No newline at end of file -- cgit v1.2.3 From 0980a33b4703677e1aaf3cd949c0437512fa6f33 Mon Sep 17 00:00:00 2001 From: Jacob Thornton Date: Tue, 20 Dec 2011 19:37:41 -0800 Subject: update all to new on api + add animation support to tabs --- js/bootstrap-scrollspy.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'js/bootstrap-scrollspy.js') diff --git a/js/bootstrap-scrollspy.js b/js/bootstrap-scrollspy.js index 3c271793c..041cfcb45 100644 --- a/js/bootstrap-scrollspy.js +++ b/js/bootstrap-scrollspy.js @@ -27,7 +27,7 @@ function ScrollSpy( element ) { var process = $.proxy(this.process, this) - this.$scrollElement = $(element).bind('scroll.scroll.data-api', process) + this.$scrollElement = $(element).on('scroll.scroll.data-api', process) this.selector = (this.$scrollElement.attr('data-target') || this.$scrollElement.attr('href') || '') + ' .nav li > a' -- cgit v1.2.3 From f72a94ae2879ebfc5206dd40d5db175e13113850 Mon Sep 17 00:00:00 2001 From: Jacob Thornton Date: Tue, 20 Dec 2011 23:28:48 -0800 Subject: update more readme changes - introduce target specificty convention to more plugins --- js/bootstrap-scrollspy.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'js/bootstrap-scrollspy.js') diff --git a/js/bootstrap-scrollspy.js b/js/bootstrap-scrollspy.js index 041cfcb45..6201d4cef 100644 --- a/js/bootstrap-scrollspy.js +++ b/js/bootstrap-scrollspy.js @@ -103,7 +103,7 @@ }) } - $.fn.scrollspy.ScrollSpy = ScrollSpy + $.fn.scrollspy.Constructor = ScrollSpy /* SCROLLSPY DATA-API -- cgit v1.2.3 From 16eccc43d9fa6317818b5d1621d0477150214488 Mon Sep 17 00:00:00 2001 From: Mark Otto Date: Sat, 14 Jan 2012 23:28:48 -0800 Subject: dates updated to 2012 --- js/bootstrap-scrollspy.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'js/bootstrap-scrollspy.js') diff --git a/js/bootstrap-scrollspy.js b/js/bootstrap-scrollspy.js index 6201d4cef..63195b4bd 100644 --- a/js/bootstrap-scrollspy.js +++ b/js/bootstrap-scrollspy.js @@ -2,7 +2,7 @@ * bootstrap-scrollspy.js v2.0.0 * http://twitter.github.com/bootstrap/javascript.html#scrollspy * ============================================================= - * Copyright 2011 Twitter, Inc. + * Copyright 2012 Twitter, Inc. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. -- cgit v1.2.3 From 2187e0838f522c102a8b5104970a9f129cdd001a Mon Sep 17 00:00:00 2001 From: Jacob Thornton Date: Sat, 21 Jan 2012 21:35:20 -0800 Subject: change scrollspy offset to be option + fix typo in scrollspy --- js/bootstrap-scrollspy.js | 19 +++++++++++++------ 1 file changed, 13 insertions(+), 6 deletions(-) (limited to 'js/bootstrap-scrollspy.js') diff --git a/js/bootstrap-scrollspy.js b/js/bootstrap-scrollspy.js index 63195b4bd..5049bfdf9 100644 --- a/js/bootstrap-scrollspy.js +++ b/js/bootstrap-scrollspy.js @@ -24,15 +24,14 @@ /* SCROLLSPY CLASS DEFINITION * ========================== */ - function ScrollSpy( element ) { + function ScrollSpy( element, options) { var process = $.proxy(this.process, this) - + this.options = $.extend({}, $.fn.scrollspy.defaults, options) this.$scrollElement = $(element).on('scroll.scroll.data-api', process) this.selector = (this.$scrollElement.attr('data-target') || this.$scrollElement.attr('href') || '') + ' .nav li > a' this.$body = $('body').on('click.scroll.data-api', this.selector, process) - this.refresh() this.process() } @@ -55,7 +54,7 @@ } , process: function () { - var scrollTop = this.$scrollElement.scrollTop() + 10 + var scrollTop = this.$scrollElement.scrollTop() + this.options.offset , offsets = this.offsets , targets = this.targets , activeTarget = this.activeTarget @@ -98,17 +97,25 @@ return this.each(function () { var $this = $(this) , data = $this.data('scrollspy') - if (!data) $this.data('scrollspy', (data = new ScrollSpy(this))) + , options = typeof option == 'object' && option + if (!data) $this.data('scrollspy', (data = new ScrollSpy(this, options))) if (typeof option == 'string') data[option]() }) } $.fn.scrollspy.Constructor = ScrollSpy + $.fn.scrollspy.defaults = { + offset: 10 + } + /* SCROLLSPY DATA-API * ============== */ - $(function () { $('[data-spy="scroll"]').scrollspy() }) + $(function () { + var $spy = $('[data-spy="scroll"]') + $spy.scrollspy($spy.data()) + }) }( window.jQuery ) \ No newline at end of file -- cgit v1.2.3 From 5e5e87fbd0f577256d8a2b479bb9ed2187ff7f91 Mon Sep 17 00:00:00 2001 From: Jacob Thornton Date: Tue, 24 Jan 2012 22:33:33 -0800 Subject: scrollspy working for sub navs --- js/bootstrap-scrollspy.js | 15 +++++++++------ 1 file changed, 9 insertions(+), 6 deletions(-) (limited to 'js/bootstrap-scrollspy.js') diff --git a/js/bootstrap-scrollspy.js b/js/bootstrap-scrollspy.js index 5049bfdf9..91c49f32e 100644 --- a/js/bootstrap-scrollspy.js +++ b/js/bootstrap-scrollspy.js @@ -26,10 +26,11 @@ function ScrollSpy( element, options) { var process = $.proxy(this.process, this) + , $element = $(element).is('body') ? $(window) : $(element) this.options = $.extend({}, $.fn.scrollspy.defaults, options) - this.$scrollElement = $(element).on('scroll.scroll.data-api', process) - this.selector = (this.$scrollElement.attr('data-target') - || this.$scrollElement.attr('href') + this.$scrollElement = $element.on('scroll.scroll.data-api', process) + this.selector = (this.options.target + || $(element).attr('href') || '') + ' .nav li > a' this.$body = $('body').on('click.scroll.data-api', this.selector, process) this.refresh() @@ -111,11 +112,13 @@ /* SCROLLSPY DATA-API - * ============== */ + * ================== */ $(function () { - var $spy = $('[data-spy="scroll"]') - $spy.scrollspy($spy.data()) + $('[data-spy="scroll"]').each(function () { + var $spy = $(this) + $spy.scrollspy($spy.data()) + }) }) }( window.jQuery ) \ No newline at end of file -- cgit v1.2.3 From 5844aa550d5a2d22d527d80cfa42443914d28c1f Mon Sep 17 00:00:00 2001 From: Mark Otto Date: Thu, 26 Jan 2012 15:00:59 -0800 Subject: consistent new lines at ends of files --- js/bootstrap-scrollspy.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'js/bootstrap-scrollspy.js') diff --git a/js/bootstrap-scrollspy.js b/js/bootstrap-scrollspy.js index 91c49f32e..dcb52456e 100644 --- a/js/bootstrap-scrollspy.js +++ b/js/bootstrap-scrollspy.js @@ -121,4 +121,4 @@ }) }) -}( window.jQuery ) \ No newline at end of file +}( window.jQuery ) -- cgit v1.2.3 From e61164e67a048c20c512e99335e3adfcc3b63604 Mon Sep 17 00:00:00 2001 From: Jacob Thornton Date: Sat, 28 Jan 2012 01:35:13 -0800 Subject: all unit tests passing in ie7 --- js/bootstrap-scrollspy.js | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) (limited to 'js/bootstrap-scrollspy.js') diff --git a/js/bootstrap-scrollspy.js b/js/bootstrap-scrollspy.js index dcb52456e..e8bd0715c 100644 --- a/js/bootstrap-scrollspy.js +++ b/js/bootstrap-scrollspy.js @@ -27,10 +27,11 @@ function ScrollSpy( element, options) { var process = $.proxy(this.process, this) , $element = $(element).is('body') ? $(window) : $(element) + , href this.options = $.extend({}, $.fn.scrollspy.defaults, options) this.$scrollElement = $element.on('scroll.scroll.data-api', process) this.selector = (this.options.target - || $(element).attr('href') + || ((href = $(element).attr('href')) && href.replace(/.*(?=#[^\s]+$)/, '')) //strip for ie7 || '') + ' .nav li > a' this.$body = $('body').on('click.scroll.data-api', this.selector, process) this.refresh() -- cgit v1.2.3