]> git.ipfire.org Git - thirdparty/bootstrap.git/commitdiff
Backport search from v4 and adapt it for v3.4.0.
authorXhmikosR <xhmikosr@gmail.com>
Thu, 20 Sep 2018 09:07:38 +0000 (12:07 +0300)
committerXhmikosR <xhmikosr@gmail.com>
Sat, 20 Oct 2018 11:03:59 +0000 (14:03 +0300)
docs/_includes/footer.html
docs/_includes/header.html
docs/assets/js/src/search.js [new file with mode: 0644]
grunt/configBridge.json

index c31f1f4645d780643666ee2d650dbcb13a21209b..e7a5bf955ede5cbf867071fbb23b66f54dd0348d 100644 (file)
   <script src="{{ site.baseurl }}/dist/js/bootstrap.js"></script>
 {% endif %}
 
+{% if page.layout == "default" %}
+<script src="https://cdn.jsdelivr.net/docsearch.js/2/docsearch.min.js"></script>
+{% endif %}
+
 {% if site.github %}
   <script src="{{ site.baseurl }}/assets/js/docs.min.js"></script>
 {% else %}
   {% endfor %}
 {% endif %}
 
-{% if page.slug == "getting-started" or page.slug == "css" or page.slug == "components" or page.slug == "js" %}
-<script src="https://cdn.jsdelivr.net/docsearch.js/2/docsearch.min.js"></script>
-<script>
-  var docsearch = docsearch({
-    apiKey: 'c6aa63796ef2f94c7e7e7f0b93b4a223',
-    indexName: 'bootstrap-v3',
-    inputSelector: '#search-input',
-    transformData: function (hits) {
-      return hits.map(function (hit) {
-        hit.url = hit.url.replace('https://getbootstrap.com/', '');
-        return hit;
-      });
-    },
-    debug: false // Set debug to true if you want to inspect the dropdown
-  });
-</script>
-{% endif %}
-
 {% if page.slug == "customize" %}
   <script>var __configBridge = {{ site.data.configBridge.config | jsonify }}</script>
   {% if site.github %}
index f63e9e3f3cd6e5baaf3a7bed55d267c95d845a2f..7446ba886706bcc7cf956b25506f57c666c6f404 100644 (file)
@@ -28,7 +28,7 @@
   {% endif %}
 {% endif %}
 
-{% if page.slug == "getting-started" or page.slug == "css" or page.slug == "components" or page.slug == "js" %}
+{% if page.layout == "default" %}
   <link rel="stylesheet" href="https://cdn.jsdelivr.net/docsearch.js/2/docsearch.min.css">
 {% endif %}
 
diff --git a/docs/assets/js/src/search.js b/docs/assets/js/src/search.js
new file mode 100644 (file)
index 0000000..53fec2a
--- /dev/null
@@ -0,0 +1,51 @@
+// NOTICE!! DO NOT USE ANY OF THIS JAVASCRIPT
+// IT'S ALL JUST JUNK FOR OUR DOCS!
+// ++++++++++++++++++++++++++++++++++++++++++
+
+(function () {
+  'use strict'
+
+  var inputElement = document.getElementById('search-input')
+
+  if (!window.docsearch || !inputElement) {
+    return
+  }
+
+  function getOrigin() {
+    var location = window.location
+    var origin = location.origin
+
+    if (!origin) {
+      var port = location.port ? ':' + location.port : ''
+
+      origin = location.protocol + '//' + location.hostname + port
+    }
+
+    return origin
+  }
+
+  window.docsearch({
+    apiKey: 'c8948afa20e6437a6e829f7e87b9ac11',
+    indexName: 'bootstrap-v3',
+    inputSelector: '#search-input',
+    handleSelected: function (input, event, suggestion) {
+      var url = suggestion.url
+      url = suggestion.isLvl1 ? url.split('#')[0] : url
+      // If it's a title we remove the anchor so it does not jump.
+      window.location.href = url
+    },
+    transformData: function (hits) {
+      return hits.map(function (hit) {
+        var siteurl = getOrigin()
+        var urlRE = /^https?:\/\/getbootstrap\.com/
+
+        // When in production, return the result as is,
+        // otherwise remove our url from it.
+        hit.url = siteurl.match(urlRE) ? hit.url : hit.url.replace(urlRE, '')
+
+        return hit
+      })
+    },
+    debug: false // Set debug to true if you want to inspect the dropdown
+  })
+}())
index f7f991c6b29560f874acd620c035d79a5da40e8e..956311fed082a5e1b81fbcd5bd56e77d02af1774 100644 (file)
@@ -14,7 +14,8 @@
       "/docs/3.4/assets/js/vendor/holder.min.js",
       "/docs/3.4/assets/js/vendor/clipboard.min.js",
       "/docs/3.4/assets/js/vendor/anchor.min.js",
-      "/docs/3.4/assets/js/src/application.js"
+      "/docs/3.4/assets/js/src/application.js",
+      "/docs/3.4/assets/js/src/search.js"
     ]
   },
   "config": {