]> git.ipfire.org Git - thirdparty/bootstrap.git/commitdiff
add offcanvas layout example based on bradfrost/this-is-responsive
authorWilliam Ghelfi <trumbitta@gmail.com>
Mon, 6 May 2013 13:58:04 +0000 (15:58 +0200)
committerWilliam Ghelfi <trumbitta@gmail.com>
Mon, 6 May 2013 13:58:18 +0000 (15:58 +0200)
docs/_includes/footer.html
docs/assets/img/examples/bootstrap-example-offcanvas.png [new file with mode: 0644]
docs/assets/js/examples/bootstrap-offcanvas.js [new file with mode: 0644]
docs/docs.html
docs/examples/offcanvas.html [new file with mode: 0644]

index 048f3135964963bec708caf7bde21b903a9441d0..81cd6f947cf123e6b8e894922cd8722214f21777 100644 (file)
 <script src="/assets/js/bootstrap-typeahead.js"></script>
 <script src="/assets/js/bootstrap-affix.js"></script>
 
+<!-- Offcanvas example
+================================================== -->
+<script src="/assets/js/examples/bootstrap-offcanvas.js"></script>
+
 <script type="text/javascript" src="http://platform.twitter.com/widgets.js"></script>
 <script src="/assets/js/holder/holder.js"></script>
 
diff --git a/docs/assets/img/examples/bootstrap-example-offcanvas.png b/docs/assets/img/examples/bootstrap-example-offcanvas.png
new file mode 100644 (file)
index 0000000..7e213f2
Binary files /dev/null and b/docs/assets/img/examples/bootstrap-example-offcanvas.png differ
diff --git a/docs/assets/js/examples/bootstrap-offcanvas.js b/docs/assets/js/examples/bootstrap-offcanvas.js
new file mode 100644 (file)
index 0000000..0752279
--- /dev/null
@@ -0,0 +1,100 @@
+/* ============================================================
+ * bootstrap-offcanvas.js v3.0.0
+ * http://twitter.github.com/bootstrap/javascript.html#offcanvas
+ * ============================================================
+ * 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.
+ * 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.
+ * ============================================================ */
+
+/* ============================================================
+ * This shouldn't be a plugin, because it's too simple.
+ * BTW, having it as a plugin, makes for a simpler dev cycle.
+ * ============================================================ */
+
+!function ($) {
+
+  "use strict"; // jshint ;_;
+
+
+ /* OFFCANVAS CLASS DEFINITION
+  * ========================= */
+
+  var toggle = '[data-toggle=offcanvas]'
+    , Offcanvas = function (element) {
+        var $el = $(element).on('click.offcanvas.data-api', this.toggle)
+      }
+
+  Offcanvas.prototype = {
+
+    constructor: Offcanvas
+
+  , toggle: function (e) {
+      var $this = $(this)
+        , $parent
+
+      $parent = $this.parents('.row-offcanvas')
+
+      $parent.toggleClass('active')
+      $this.toggleClass('active')
+
+      return false
+    }
+
+  , keydown: function (e) {
+      $(this).toggle
+      // TODO
+      // This should be enough to provide the basic functionality.
+      // In the future I'd like to have the following behaviour:
+      //
+      // * on active via keyboard, give focus to the sidebar
+      // * while in sidebar: ESC gives back focus to the toggler anchor/button
+    }
+
+  }
+
+
+  /* OFFCANVAS PLUGIN DEFINITION
+   * ========================== */
+
+  var old = $.fn.offcanvas
+
+  $.fn.offcanvas = function (option) {
+    return this.each(function () {
+      var $this = $(this)
+        , data = $this.data('offcanvas')
+      if (!data) $this.data('offcanvas', (data = new Offcanvas(this)))
+      if (typeof option == 'string') data[option].call($this)
+    })
+  }
+
+  $.fn.offcanvas.Constructor = Offcanvas
+
+
+ /* OFFCANVAS NO CONFLICT
+  * ==================== */
+
+  $.fn.offcanvas.noConflict = function () {
+    $.fn.offcanvas = old
+    return this
+  }
+
+
+  /* APPLY TO OFFCANVAS ELEMENTS
+   * =================================== */
+
+  $(document)
+    .on('click.offcanvas.data-api touchstart.offcanvas.data-api'  , toggle, Offcanvas.prototype.toggle)
+    .on('keydown.offcanvas.data-api touchstart.offcanvas.data-api', toggle, Offcanvas.prototype.keydown)
+
+}(window.jQuery);
\ No newline at end of file
index 3467252154caf7fae094d6caeee038407257fb74..f02f75fb50877cc878f7f3edff6d1ac84dd7a292 100644 (file)
@@ -208,6 +208,13 @@ title: Bootstrap Documentation
         <h4>Fixed top navbar</h4>
         <p>Basic template for showcasing the fixed navbar variation.</p>
       </div>
+      <div class="col col-lg-4">
+        <a class="thumbnail" href="/examples/offcanvas/" target="_blank">
+          <img src="/assets/img/examples/bootstrap-example-offcanvas.png" alt="">
+        </a>
+        <h4>Offcanvas layout</h4>
+        <p>An offcanvas layout based on <a href="https://github.com/bradfrost/this-is-responsive/blob/gh-pages/patterns/layout-offcanvas-right.html" target="_blank">This Is Responsive</a> by <a href="https://github.com/bradfrost" target="_blank">Brad Frost</a>.</p>
+      </div>
     </div>
   </div>
 
diff --git a/docs/examples/offcanvas.html b/docs/examples/offcanvas.html
new file mode 100644 (file)
index 0000000..cfc182a
--- /dev/null
@@ -0,0 +1,195 @@
+---
+layout: example
+title: Static navbar template
+---
+
+<!-- Custom styles for this template -->
+<style>
+  body {
+    padding-top: 80px;
+  }
+
+  /*
+   * Off canvas
+   * -------------------------------------------------- */
+
+  .row-offcanvas {
+    position: relative;
+    overflow: hidden;
+    .transition(all 0.25s ease-out);
+  }
+  .row-offcanvas.active {
+    overflow: visible;
+  }
+  .row-offcanvas-right .sidebar-offcanvas {
+    right: -210px; /* 60px * 3.5 = very small phones like 240x320 HTC Wildfire */
+  }
+  .row-offcanvas-left .sidebar-offcanvas {
+    left: -210px; /* 60px * 3.5 = very small phones like 240x320 HTC Wildfire */
+  }
+  .row-offcanvas-right.active {
+    right: 210px; /* 60px * 3.5 = very small phones like 240x320 HTC Wildfire */
+  }
+  .row-offcanvas-left.active {
+    left: 210px; /* 60px * 3.5 = very small phones like 240x320 HTC Wildfire */
+  }
+  .sidebar-offcanvas {
+    position: absolute;
+    top: 0;
+  }
+
+  @media screen and (max-width: 319px) {
+    /* This is here instead of being outside the media queries because when
+     * we exit "mobile land", the sidebar needs to be able to restore its
+     * originally authored ".col-lg-X" width. */
+    .sidebar-offcanvas {
+      width: 210px; /* 60px * 3.5 = very small phones like 240x320 HTC Wildfire */
+    }
+  }
+
+  @media screen and (min-width: 320px) and (max-width: 480px) {
+
+    .row-offcanvas-right .sidebar-offcanvas {
+      right: -270px; /* 60px * 4.5 = average iPhones and Android phones */
+    }
+    .row-offcanvas-left .sidebar-offcanvas {
+      left: -270px; /* 60px * 4.5 = average iPhones and Android phones */
+    }
+    .row-offcanvas-right.active {
+      right: 270px; /* 60px * 4.5 = average iPhones and Android phones */
+    }
+    .row-offcanvas-left.active {
+      left: 270px; /* 60px * 4.5 = average iPhones and Android phones */
+    }
+    .sidebar-offcanvas {
+      width: 270px; /* 60px * 4.5 = average iPhones and Android phones */
+    }
+
+  }
+
+  /* Landscape phone to tablets
+   * -------------------------- */
+  @media screen and (min-width: 481px) and (max-width: 767px) {
+
+    .row-offcanvas-right .sidebar-offcanvas {
+      right: -480px; /* 60px * 8 = Tablets and wider */
+    }
+    .row-offcanvas-left .sidebar-offcanvas {
+      left: -480px; /* 60px * 8 = Tablets and wider */
+    }
+    .row-offcanvas-right.active {
+      right: 480px; /* 60px * 8 = Tablets and wider */
+    }
+    .row-offcanvas-left.active {
+      left: 480px; /* 60px * 8 = Tablets and wider */
+    }
+    .sidebar-offcanvas {
+      width: 480px; /* 60px * 8 = Tablets and wider */
+    }
+
+  }
+
+  /* Tablets & above
+   * ---------------- */
+  @media screen and (min-width: 768px) {
+
+    .row-offcanvas {
+      position: static;
+      overflow: visible;
+    }
+
+    .sidebar-offcanvas {
+      position: static;
+    }
+
+  }
+</style>
+
+<div class="navbar navbar-inverse navbar-fixed-top">
+  <div class="container">
+    <button type="button" class="navbar-toggle" data-toggle="collapse" data-target=".nav-collapse">
+      <span class="icon-bar"></span>
+      <span class="icon-bar"></span>
+      <span class="icon-bar"></span>
+    </button>
+    <a class="navbar-brand" href="#">Project name</a>
+    <div class="nav-collapse collapse">
+      <ul class="nav navbar-nav">
+        <li class="active"><a href="#">Home</a></li>
+        <li><a href="#about">About</a></li>
+        <li><a href="#contact">Contact</a></li>
+      </ul>
+    </div><!--/.nav-collapse -->
+  </div>
+</div>
+
+<div class="container">
+
+  <div class="row row-offcanvas row-offcanvas-right">
+    <div class="col col-lg-9">
+      <p class="pull-right visible-phone"><a href="#sidebar" class="btn btn-primary btn-offcanvas" data-toggle="offcanvas"><i class="glyphicon glyphicon-resize-horizontal"></i></a></p>
+      <div class="jumbotron">
+        <h1>Hello, world!</h1>
+        <p>This is an example to show the potential of an offcanvas layout pattern in Bootstrap. Try some responsive-range viewport sizes to see it in action.</p>
+      </div>
+      <div class="row">
+        <div class="col col-lg-4">
+          <h2>Heading</h2>
+          <p>Donec id elit non mi porta gravida at eget metus. Fusce dapibus, tellus ac cursus commodo, tortor mauris condimentum nibh, ut fermentum massa justo sit amet risus. Etiam porta sem malesuada magna mollis euismod. Donec sed odio dui. </p>
+          <p><a class="btn" href="#">View details &raquo;</a></p>
+        </div><!--/span-->
+        <div class="col col-lg-4">
+          <h2>Heading</h2>
+          <p>Donec id elit non mi porta gravida at eget metus. Fusce dapibus, tellus ac cursus commodo, tortor mauris condimentum nibh, ut fermentum massa justo sit amet risus. Etiam porta sem malesuada magna mollis euismod. Donec sed odio dui. </p>
+          <p><a class="btn" href="#">View details &raquo;</a></p>
+        </div><!--/span-->
+        <div class="col col-lg-4">
+          <h2>Heading</h2>
+          <p>Donec id elit non mi porta gravida at eget metus. Fusce dapibus, tellus ac cursus commodo, tortor mauris condimentum nibh, ut fermentum massa justo sit amet risus. Etiam porta sem malesuada magna mollis euismod. Donec sed odio dui. </p>
+          <p><a class="btn" href="#">View details &raquo;</a></p>
+        </div><!--/span-->
+      </div><!--/row-->
+      <div class="row">
+        <div class="col col-lg-4">
+          <h2>Heading</h2>
+          <p>Donec id elit non mi porta gravida at eget metus. Fusce dapibus, tellus ac cursus commodo, tortor mauris condimentum nibh, ut fermentum massa justo sit amet risus. Etiam porta sem malesuada magna mollis euismod. Donec sed odio dui. </p>
+          <p><a class="btn" href="#">View details &raquo;</a></p>
+        </div><!--/span-->
+        <div class="col col-lg-4">
+          <h2>Heading</h2>
+          <p>Donec id elit non mi porta gravida at eget metus. Fusce dapibus, tellus ac cursus commodo, tortor mauris condimentum nibh, ut fermentum massa justo sit amet risus. Etiam porta sem malesuada magna mollis euismod. Donec sed odio dui. </p>
+          <p><a class="btn" href="#">View details &raquo;</a></p>
+        </div><!--/span-->
+        <div class="col col-lg-4">
+          <h2>Heading</h2>
+          <p>Donec id elit non mi porta gravida at eget metus. Fusce dapibus, tellus ac cursus commodo, tortor mauris condimentum nibh, ut fermentum massa justo sit amet risus. Etiam porta sem malesuada magna mollis euismod. Donec sed odio dui. </p>
+          <p><a class="btn" href="#">View details &raquo;</a></p>
+        </div><!--/span-->
+      </div><!--/row-->
+    </div><!--/span-->
+    <nav class="col col-lg-3 sidebar-offcanvas" id="sidebar" role="navigation">
+      <div class="well sidebar-nav">
+        <ul class="nav nav-list">
+          <li class="nav-header">Sidebar</li>
+          <li class="active"><a href="#">Link</a></li>
+          <li><a href="#">Link</a></li>
+          <li><a href="#">Link</a></li>
+          <li class="nav-header">Sidebar</li>
+          <li><a href="#">Link</a></li>
+          <li><a href="#">Link</a></li>
+          <li><a href="#">Link</a></li>
+          <li class="nav-header">Sidebar</li>
+          <li><a href="#">Link</a></li>
+          <li><a href="#">Link</a></li>
+        </ul>
+      </div><!--/.well -->
+    </nav><!--/span-->
+  </div><!--/row-->
+
+  <hr>
+
+  <footer>
+    <p>&copy; Company 2012</p>
+  </footer>
+
+</div><!--/.container-->
\ No newline at end of file