summaryrefslogtreecommitdiff
path: root/doc/_themes/sphinx_bootstrap_theme/bootstrap/static/bootstrap-sphinx.js_t
diff options
context:
space:
mode:
authorxmo-odoo <xmo-odoo@users.noreply.github.com>2014-05-19 09:55:22 +0200
committerxmo-odoo <xmo-odoo@users.noreply.github.com>2014-05-19 09:55:22 +0200
commit3571a3dcc3ee6b09bdd186b88ec0945f5c36b17b (patch)
treeb150edb15d3cda3c6841c5c8ea882be8dd74676e /doc/_themes/sphinx_bootstrap_theme/bootstrap/static/bootstrap-sphinx.js_t
parent5313714530d4ccc3ae0557bf05e08ffb1431e3b1 (diff)
parentcab23933e3a08c804a0b0b6748f0b46895fd6ffd (diff)
Merge pull request #43 from xmo-odoo/website-tutorial
First howto: tutorial to basic website features (dev-wise)
Diffstat (limited to 'doc/_themes/sphinx_bootstrap_theme/bootstrap/static/bootstrap-sphinx.js_t')
-rw-r--r--doc/_themes/sphinx_bootstrap_theme/bootstrap/static/bootstrap-sphinx.js_t168
1 files changed, 168 insertions, 0 deletions
diff --git a/doc/_themes/sphinx_bootstrap_theme/bootstrap/static/bootstrap-sphinx.js_t b/doc/_themes/sphinx_bootstrap_theme/bootstrap/static/bootstrap-sphinx.js_t
new file mode 100644
index 00000000000..9eb03fbf95a
--- /dev/null
+++ b/doc/_themes/sphinx_bootstrap_theme/bootstrap/static/bootstrap-sphinx.js_t
@@ -0,0 +1,168 @@
+(function ($) {
+ /**
+ * Patch TOC list.
+ *
+ * Will mutate the underlying span to have a correct ul for nav.
+ *
+ * @param $span: Span containing nested UL's to mutate.
+ * @param minLevel: Starting level for nested lists. (1: global, 2: local).
+ */
+ var patchToc = function ($ul, minLevel) {
+ var findA,
+ patchTables,
+ $localLi;
+
+ // Find all a "internal" tags, traversing recursively.
+ findA = function ($elem, level) {
+ level = level || 0;
+ var $items = $elem.find("> li > a.internal, > ul, > li > ul");
+
+ // Iterate everything in order.
+ $items.each(function (index, item) {
+ var $item = $(item),
+ tag = item.tagName.toLowerCase(),
+ $childrenLi = $item.children('li'),
+ $parentLi = $($item.parent('li'), $item.parent().parent('li'));
+
+ // Add dropdowns if more children and above minimum level.
+ if (tag === 'ul' && level >= minLevel && $childrenLi.length > 0) {
+ $parentLi
+ .addClass('dropdown-submenu')
+ .children('a').first().attr('tabindex', -1);
+
+ $item.addClass('dropdown-menu');
+ }
+
+ findA($item, level + 1);
+ });
+ };
+
+ findA($ul);
+ };
+
+ /**
+ * Patch all tables to remove ``docutils`` class and add Bootstrap base
+ * ``table`` class.
+ */
+ patchTables = function () {
+ $("table.docutils")
+ .removeClass("docutils")
+ .addClass("table")
+ .attr("border", 0);
+ };
+
+ $(window).load(function () {
+ /*
+ * Scroll the window to avoid the topnav bar
+ * https://github.com/twitter/bootstrap/issues/1768
+ */
+ if ($("#navbar.navbar-fixed-top").length > 0) {
+ var navHeight = $("#navbar").height(),
+ shiftWindow = function() { scrollBy(0, -navHeight - 10); };
+
+ if (location.hash) {
+ setTimeout(shiftWindow, 1);
+ }
+
+ window.addEventListener("hashchange", shiftWindow);
+ }
+ });
+
+ $(document).ready(function () {
+ // Add styling, structure to TOC's.
+ $(".dropdown-menu").each(function () {
+ $(this).find("ul").each(function (index, item){
+ var $item = $(item);
+ $item.addClass('unstyled');
+ });
+ });
+
+ // Global TOC.
+ if ($("ul.globaltoc li").length) {
+ patchToc($("ul.globaltoc"), 1);
+ } else {
+ // Remove Global TOC.
+ $(".globaltoc-container").remove();
+ }
+
+ // Local TOC.
+ $(".bs-sidenav ul").addClass("nav nav-list");
+ $(".bs-sidenav > ul > li > a").addClass("nav-header");
+
+ {% if theme_bootstrap_version == "3" %}
+ // back to top
+ setTimeout(function () {
+ var $sideBar = $('.bs-sidenav');
+
+ $sideBar.affix({
+ offset: {
+ top: function () {
+ var offsetTop = $sideBar.offset().top;
+ var sideBarMargin = parseInt($sideBar.children(0).css('margin-top'), 10);
+ var navOuterHeight = $('#navbar').height();
+
+ return (this.top = offsetTop - navOuterHeight - sideBarMargin);
+ }
+ , bottom: function () {
+ // add 25 because the footer height doesn't seem to be enough
+ return (this.bottom = $('.footer').outerHeight(true) + 25);
+ }
+ }
+ });
+ }, 100);
+ {% endif %}
+
+ // Local TOC.
+ patchToc($("ul.localtoc"), 2);
+
+ // Mutate sub-lists (for bs-2.3.0).
+ $(".dropdown-menu ul").not(".dropdown-menu").each(function () {
+ var $ul = $(this),
+ $parent = $ul.parent(),
+ tag = $parent[0].tagName.toLowerCase(),
+ $kids = $ul.children().detach();
+
+ // Replace list with items if submenu header.
+ if (tag === "ul") {
+ $ul.replaceWith($kids);
+ } else if (tag === "li") {
+ // Insert into previous list.
+ $parent.after($kids);
+ $ul.remove();
+ }
+ });
+
+ // Add divider in page TOC.
+ $localLi = $("ul.localtoc li");
+ if ($localLi.length > 2) {
+ $localLi.first().after('<li class="divider"></li>');
+ }
+
+ // Manually add dropdown.
+ // Appears unnecessary as of:
+ // https://github.com/ryan-roemer/sphinx-bootstrap-theme/pull/90
+ // Remove next time around...
+ // a.dropdown-toggle class needed in globaltoc.html
+ //$('.dropdown-toggle').dropdown();
+
+ // Patch tables.
+ patchTables();
+
+ // Add Note, Warning styles. (BS v2,3 compatible).
+ $('div.note').addClass('alert alert-info');
+ $('div.warning').addClass('alert alert-danger alert-error');
+
+ // Inline code styles to Bootstrap style.
+ $('tt.docutils.literal').not(".xref").each(function (i, e) {
+ // ignore references
+ if (!$(e).parent().hasClass("reference")) {
+ $(e).replaceWith(function () {
+ return $("<code />").html($(this).html());
+ });
+ }});
+
+ // Update sourcelink to remove outerdiv (fixes appearance in navbar).
+ var $srcLink = $(".nav #sourcelink");
+ $srcLink.parent().html($srcLink.html());
+ });
+}(window.$jqTheme || window.jQuery));