]> git.ipfire.org Git - thirdparty/bootstrap.git/commitdiff
clean up scrollspy a bit - add public api method
authorJacob Thornton <jacobthornton@gmail.com>
Fri, 25 Nov 2011 04:27:18 +0000 (20:27 -0800)
committerJacob Thornton <jacobthornton@gmail.com>
Fri, 25 Nov 2011 04:27:18 +0000 (20:27 -0800)
docs/javascript.html
js/bootstrap-scrollspy.js

index aa13d523da9b2fe82fcf0bc74a1f603759c9fb2f..f625e2323ca99447f4bb7036975eaae55b0297c9 100644 (file)
           <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>
 <pre class="prettyprint linenums">
-&lt;a class="btn" data-toggle="modal" data-target="my-modal" &gt;Launch Modal&lt;/a&gt;
+&lt;a class="btn" data-toggle="modal" data-target="#myModal" &gt;Launch Modal&lt;/a&gt;
 </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>
           <h3>Methods</h3>
index 91c2dcb1edc94d176dbc5654ab2c03ca0e27dad3..e846fd71822ecd0af2c47d99518ddf0ad6feda85 100644 (file)
  * 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()
         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