From: Jacob Thornton Date: Fri, 25 Nov 2011 04:27:18 +0000 (-0800) Subject: clean up scrollspy a bit - add public api method X-Git-Tag: v2.0.0~6^2~415^2~14 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=53ff2682cd95dd96fc1fbf234d7b0530127a464b;p=thirdparty%2Fbootstrap.git clean up scrollspy a bit - add public api method --- diff --git a/docs/javascript.html b/docs/javascript.html index aa13d523da..f625e2323c 100644 --- a/docs/javascript.html +++ b/docs/javascript.html @@ -201,7 +201,7 @@

Markup

You can activate modals on your page easily without having to write a single line of javascript. Just set data-toggle="modal" on a controller element with a data-target="#foo" which corresponds to a modal element id, and when clicked, it will launch your modal. To add modal options, just include them as additoinal data attributes.

-<a class="btn" data-toggle="modal" data-target="my-modal" >Launch Modal</a>
+<a class="btn" data-toggle="modal" data-target="#myModal" >Launch Modal</a>
 

Notice If you want your modal to animate in and out, just add a .fade class to the .modal element (refer to the demo to see this in action).

Methods

diff --git a/js/bootstrap-scrollspy.js b/js/bootstrap-scrollspy.js index 91c2dcb1ed..e846fd7182 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