mirror of
https://github.com/twbs/bootstrap.git
synced 2025-01-18 10:52:19 +01:00
clean up scrollspy a bit - add public api method
This commit is contained in:
parent
b14f551c9c
commit
53ff2682cd
@ -201,7 +201,7 @@
|
|||||||
<h3>Markup</h3>
|
<h3>Markup</h3>
|
||||||
<p>You can activate modals on your page easily without having to write a single line of javascript. Just set <code>data-toggle="modal"</code> on a controller element with a <code>data-target="#foo"</code> 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.</p>
|
<p>You can activate modals on your page easily without having to write a single line of javascript. Just set <code>data-toggle="modal"</code> on a controller element with a <code>data-target="#foo"</code> 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.</p>
|
||||||
<pre class="prettyprint linenums">
|
<pre class="prettyprint linenums">
|
||||||
<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>
|
||||||
</pre>
|
</pre>
|
||||||
<p><span class="label notice">Notice</span> If you want your modal to animate in and out, just add a <code>.fade</code> class to the <code>.modal</code> element (refer to the demo to see this in action).</p>
|
<p><span class="label notice">Notice</span> If you want your modal to animate in and out, just add a <code>.fade</code> class to the <code>.modal</code> element (refer to the demo to see this in action).</p>
|
||||||
<h3>Methods</h3>
|
<h3>Methods</h3>
|
||||||
|
34
js/bootstrap-scrollspy.js
vendored
34
js/bootstrap-scrollspy.js
vendored
@ -17,15 +17,19 @@
|
|||||||
* limitations under the License.
|
* limitations under the License.
|
||||||
* ============================================================== */
|
* ============================================================== */
|
||||||
|
|
||||||
|
|
||||||
!function ( $ ) {
|
!function ( $ ) {
|
||||||
|
|
||||||
function ScrollSpy() {
|
"use strict"
|
||||||
|
|
||||||
|
/* SCROLLSPY CLASS DEFINITION
|
||||||
|
* ========================== */
|
||||||
|
|
||||||
|
function ScrollSpy( element ) {
|
||||||
var process = $.proxy(this.process, this)
|
var process = $.proxy(this.process, this)
|
||||||
this.selector = '.nav li > a'
|
this.selector = '.nav li > a'
|
||||||
|
|
||||||
this.$body = $('body').delegate(this.selector, 'click', process)
|
this.$body = $('body').delegate(this.selector, 'click.scroll.data-api', process)
|
||||||
this.$scrollElement = $('[data-spy="scroll"]').bind('scroll', process)
|
this.$scrollElement = $(element).bind('scroll.scroll.data-api', process)
|
||||||
|
|
||||||
this.refresh()
|
this.refresh()
|
||||||
this.process()
|
this.process()
|
||||||
@ -78,11 +82,29 @@
|
|||||||
if ( active.parent('.dropdown-menu') ) {
|
if ( active.parent('.dropdown-menu') ) {
|
||||||
active.closest('li.dropdown').addClass('active')
|
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 )
|
}( window.jQuery || window.ender )
|
Loading…
x
Reference in New Issue
Block a user