]> git.ipfire.org Git - thirdparty/bootstrap.git/commitdiff
refactor alerts + add new readme which idefientifies goals for 2.0 js
authorJacob Thornton <jacobthornton@gmail.com>
Fri, 25 Nov 2011 02:55:44 +0000 (18:55 -0800)
committerJacob Thornton <jacobthornton@gmail.com>
Fri, 25 Nov 2011 02:55:44 +0000 (18:55 -0800)
docs/javascript.html
js/README.md [new file with mode: 0644]
js/bootstrap-alerts.js
js/bootstrap-buttons.js
js/bootstrap-collapsible.js [new file with mode: 0644]
js/bootstrap-dropdown.js
js/bootstrap-modal.js

index 28f5e303564e09b22c593d686b9135d055619a36..f5f0520c3a832ecfe01fe0dd941fdc407d372b3f 100644 (file)
@@ -39,7 +39,6 @@
     <script src="../js/bootstrap-buttons.js"></script>
     <script>
       $(function () {
-
         // twipsy demo
         $("a[rel=twipsy]").twipsy({
           live: true
             </tbody>
           </table>
           <h3>Markup</h3>
-          <p>You can activate modals on your page easily without having to write a single line of javascript. Just give an element a <code>data-controls-modal</code> attribute which corresponds to a modal element id, and when clicked, it will launch your modal. To add modal options, just include them as 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">
-&lt;a class="btn" data-controls-modal="my-modal" data-backdrop="true" &gt;Launch Modal&lt;/a&gt;
+&lt;a class="btn" data-toggle="modal" data-target="my-modal" &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>
@@ -269,7 +268,9 @@ $('#my-modal').bind('hidden', function () {
               <a href="#" class="btn" data-modal-dismiss="true" >Close</a>
             </div>
           </div>
-          <button data-controls-modal="modal-from-dom" class="btn danger">Launch Modal</button>
+          <button data-toggle="modal" data-target="modal-from-dom" class="btn danger">
+            Launch Modal
+          </button>
         </div>
       </div>
     </section>
@@ -849,6 +850,39 @@ $('.tabs a').bind('change', function (e) {
     </section>
 
 
+    <!-- Collapsible
+    ================================================== -->
+
+    <section id="collapsible">
+      <div class="page-header">
+        <h1>Collapsible <small>bootstrap-collapsible.js</small></h1>
+      </div>
+      <div class="row">
+        <div class="span3 columns">
+          <p>collapsible collapsible collapsible bitches.</p>
+          <a href="../js/bootstrap-collapsible.js" target="_blank" class="btn primary">Download</a>
+        </div>
+        <div class="span9 columns">
+          <h3>Using bootstrap-collapsible.js</h3>
+          <pre class="prettyprint linenums">$(".collapsible").collapsible()</pre>
+          <h3>Markup</h3>
+          <p>Just add <code>data-dismiss="alert"</code> to your close button to automatically give an alert close functionality.</p>
+          <pre class="prettyprint linenums">&lt;a class="close" data-dismiss="alert" href="#"&gt;&amp;times;&lt;/a&gt;</pre>
+          <h3>Methods</h3>
+
+          <h3>Demo</h3>
+
+          <button data-toggle="collapse"></butotn>
+          <div>
+
+          </div>
+
+
+        </div>
+      </div>
+    </section>
+
+
       <!-- Footer
       ================================================== -->
       <footer class="footer">
diff --git a/js/README.md b/js/README.md
new file mode 100644 (file)
index 0000000..98be754
--- /dev/null
@@ -0,0 +1,89 @@
+2.0 BOOTSTRAP JS PHILSOPHY
+These are the highlevel design rules which guide the developement of Bootstrap's js plugins.
+
+---
+
+### DATA-ATTRIBUTE API
+
+We believe you should be able to use all plugins provided by bootstrap purely through the markup api without writing a single line of javascript.
+
+We acknoledge that this isn't always the most performant and sometimes it may be desirable to turn this functionality off altogether. Therefore, as of 2.0 we provide the ability to disable the data attribute api by unbinding all events on the body namespaced with `'data-api'`. This looks like this:
+
+    $('body').unbind('.data-api')
+
+To target a specific plugin, just include the plugins name as a namespace along with the data-api namespace like this:
+
+    $('body').unbind('.alert.data-api')
+
+---
+
+### PROGRAMATIC API
+
+We also believe you should be able to use all plugins provided by bootstrap purely through the JS api.
+
+All pubilc APIs should be a single, chainable method, and return the collection acted upon.
+
+    $(".btn.danger").button("toggle").addClass("fat")
+
+All methods should accept an optional options object, a string which targets a particular method, or null which innitiates the default behavior:
+
+    $("#myModal").modal() // initialized with defaults
+
+---
+
+### PLUGIN OPTIONS
+
+Options should be sparse and add universal value. We should pick the right defaults.
+
+All plugins should have a default object which can be modified to effect all instance's default options. The defaults object should be available via `$.fn.plugin.defaults`.
+
+    $.fn.modal.defaults = { … }
+
+An options definiton should take the following form:
+
+    *noun*: *adjective* - describes or modifies a quality of an instance
+
+examples:
+
+    backdrop: true
+    keyboard: false
+    placement: 'above'
+
+---
+
+### PLUGIN EVENTS
+
+All events should have an infinitive and past participle form. The infinitive is fired just before an action takes place, the past participle on completion of the action.
+
+    show | shown
+    hide | hidden
+    change | changed
+
+---
+
+
+### DATA ATTRIBUTES
+
+Data attributes should take the following form:
+
+data-*(verb)* - defines main interaction
+data-target - defined on controller element (if element interacts with an element other than self)
+data-*(noun)* - defines options for element invocation
+
+examples:
+
+    // control other targets
+    data-toggle="modal" data-target="#foo"
+    data-toggle="view" data-target="#foo"
+
+    // defined on element they control
+    data-spy="scroll"
+
+    data-dismiss="modal"
+    data-dismiss="alert"
+
+    data-toggle="dropdown"
+
+    data-toggle="button"
+    data-toggle="buttons-checkbox"
+    data-toggle="buttons-radio"
\ No newline at end of file
index 600440e40eb7c884c51117ad4726f9f19f5e3605..565f83193640a8bb41cbc981ec62b48ad0b1d89a 100644 (file)
  /* ALERT CLASS DEFINITION
   * ====================== */
 
-  var Alert = function ( content, options ) {
-    if (options == 'close') return this.close.call(content)
-    this.settings = $.extend({}, $.fn.alert.defaults, options)
-    this.$element = $(content)
-      .delegate(this.settings.selector, 'click', this.close)
-  }
+  var dismiss = '[data-dismiss="alert"]'
+    , Alert = function ( el, close ) {
+        $(el).delegate(dismiss, 'click', this.close)
+      }
 
   Alert.prototype = {
 
-    close: function (e) {
+    close: function ( e ) {
       var $element = $(this)
-        , className = 'alert-message'
 
-      $element = $element.hasClass(className) ? $element : $element.parent()
+      $element = $element.hasClass('alert-message') ? $element : $element.parent()
 
       e && e.preventDefault()
       $element.removeClass('in')
 
-      function removeElement () {
+      function removeElement() {
         $element.remove()
       }
 
   * ======================= */
 
   $.fn.alert = function ( options ) {
-
     return this.each(function () {
       var $this = $(this)
-        , data
-
-      if ( typeof options == 'string' ) {
-
-        data = $this.data('alert')
-
-        if (typeof data == 'object') {
-          return data[options].call( $this )
-        }
-
-      }
-
-      $(this).data('alert', new Alert( this, options ))
-
+        , data = $this.data('alert')
+      if (!data) $this.data('alert', (data = new Alert(this)))
+      if (typeof options == 'string') data[options].call($this)
     })
   }
 
-  $.fn.alert.defaults = {
-    selector: '[data-dismiss="alert"]'
-  }
+  $.fn.alert.Alert = Alert
+
+
+ /* ALERT DATA-API
+  * ============== */
 
   $(function () {
-    new Alert( $('body') )
+    $('body').delegate(dismiss, 'click.alert.data-api', Alert.prototype.close)
   })
 
 }( window.jQuery || window.ender );
\ No newline at end of file
index 759a65f8423ad039b5f9537b1714a47362596f3b..5ca678df8bb745fe7e480915c3e0136383c6efe3 100644 (file)
 
   "use strict"
 
+ /* BUTTON PUBLIC CLASS DEFINITION
+  * ============================== */
+
+  var Button
+
   function setState(el, state) {
     var d = 'disabled'
       , $el = $(el)
     var $el = $(el)
       , $parent = $el.parent('[data-toggle="buttons-radio"]')
 
-    if ($parent) {
-      $parent
-        .find('.active')
-        .removeClass('active')
-    }
+    $parent && $parent
+      .find('.active')
+      .removeClass('active')
 
     $el.toggleClass('active')
   }
 
+
+ /* BUTTON PLUGIN DEFINITION
+  * ======================== */
+
   $.fn.button = function(options) {
     return this.each(function () {
       if (options == 'toggle') return toggle(this)
     loadingText: 'loading...'
   }
 
+  $.fn.button.Button = Button
+
+
+ /* BUTTON DATA-API
+  * =============== */
+
   $(function () {
-    $('body').delegate('[data-toggle^=button]', 'click', function (e) {
+    $('body').delegate('[data-toggle^=button]', 'click.button.data-api', function (e) {
       $(e.srcElement).button('toggle')
     })
   })
diff --git a/js/bootstrap-collapsible.js b/js/bootstrap-collapsible.js
new file mode 100644 (file)
index 0000000..273eb22
--- /dev/null
@@ -0,0 +1,37 @@
+/* =============================================================
+ * bootstrap-collapsible.js v2.0.0
+ * http://twitter.github.com/bootstrap/javascript.html#collapsible
+ * =============================================================
+ * Copyright 2011 Twitter, Inc.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ * ============================================================ */
+
+(function( $ ){
+
+  var Collapsible = function ( element, options ) {}
+
+  Collapsible.prototype = {}
+
+  /* collapsible PLUGIN DEFINITION
+   * ======================= */
+
+  $.fn.collapsible = function ( options ) {
+
+    return this.each(function () {
+      new Collapsible(this, options)
+    })
+  }
+
+
+})( window.jQuery || window.ender )
\ No newline at end of file
index bb7d11b1fa0c607e7ee74cdd8c4e9c39f870b6c1..ef243fc6f641d2af587fcbe16b3d95bc7caab17f 100644 (file)
@@ -59,7 +59,7 @@
    * =================================== */
 
   $(function () {
-    $('html').bind("click", clearMenus)
+    $('html').bind("click.dropdown.data-api", clearMenus)
     $('body').dropdown(s)
   })
 
index e15b1237ceb698fed99b136db82a13b78fe4ebf1..16c805a4e7fd90844b5327b86d907a1a2089972b 100644 (file)
       })
     }
 
-    if ( options === true ) {
-      return modal
-    }
-
     if ( typeof options == 'string' ) {
       modal[options]()
     } else if ( modal ) {
   * ========================== */
 
   $(document).ready(function () {
-    $('body').delegate('[data-controls-modal]', 'click', function (e) {
+    $('body').delegate('[data-controls-modal]', 'click.modal.data-api', function (e) {
       e.preventDefault()
       var $this = $(this)
       $('#' + $this.attr('data-controls-modal')).modal( $this.data() )