]> git.ipfire.org Git - thirdparty/bootstrap.git/commitdiff
remove jquery in tab docs
authorJohann-S <johann.servoire@gmail.com>
Wed, 31 Jul 2019 19:55:28 +0000 (21:55 +0200)
committerJohann-S <johann.servoire@gmail.com>
Thu, 1 Aug 2019 08:37:27 +0000 (10:37 +0200)
site/content/docs/4.3/components/navs.md

index ea06582ae2597e9ae2e6afc3e529bcc658f2095f..9dbf0fa6193664a082484ec4e45adeb29938b986 100644 (file)
@@ -524,19 +524,25 @@ You can activate a tab or pill navigation without writing any JavaScript by simp
 Enable tabbable tabs via JavaScript (each tab needs to be activated individually):
 
 {{< highlight js >}}
-$('#myTab a').on('click', function (e) {
-  e.preventDefault()
-  $(this).tab('show')
+var triggerTabList = [].slice.call(document.querySelectorAll('#myTab a'))
+triggerTabList.forEach(function (triggerEl) {
+  var tabTrigger = new bootstrap.Tab(triggerEl)
+
+  triggerEl.addEventListener('click', function (e) {
+    e.preventDefault()
+    tabTrigger.show()
+  })
 })
 {{< /highlight >}}
 
 You can activate individual tabs in several ways:
 
 {{< highlight js >}}
-$('#myTab a[href="#profile"]').tab('show') // Select tab by name
-$('#myTab li:first-child a').tab('show') // Select first tab
-$('#myTab li:last-child a').tab('show') // Select last tab
-$('#myTab li:nth-child(3) a').tab('show') // Select third tab
+var triggerEl = document.querySelector('#myTab a[href="#profile"]')
+bootstrap.Tab.getInstance(triggerEl).show() // Select tab by name
+
+var triggerFirstTabEl = document.querySelector('#myTab li:first-child a')
+bootstrap.Tab.getInstance(triggerFirstTabEl).show() // Select first tab
 {{< /highlight >}}
 
 ### Fade effect
@@ -558,7 +564,7 @@ To make tabs fade in, add `.fade` to each `.tab-pane`. The first tab pane must a
 {{< partial "callout-danger-async-methods.md" >}}
 {{< /callout >}}
 
-#### $().tab
+#### constructor
 
 Activates a tab element and content container. Tab should have either a `data-target` or an `href` targeting a container node in the DOM.
 
@@ -586,24 +592,37 @@ Activates a tab element and content container. Tab should have either a `data-ta
 </div>
 
 <script>
-  $(function () {
-    $('#myTab li:last-child a').tab('show')
-  })
+  var firstTabEl = document.querySelector('#myTab li:last-child a')
+  var firstTab = new bootstrap.Tab(firstTabEl)
+
+  firstTab.show()
 </script>
 {{< /highlight >}}
 
-#### .tab('show')
+#### show
 
 Selects the given tab and shows its associated pane. Any other tab that was previously selected becomes unselected and its associated pane is hidden. **Returns to the caller before the tab pane has actually been shown** (i.e. before the `shown.bs.tab` event occurs).
 
 {{< highlight js >}}
-$('#someTab').tab('show')
+  var someTabTriggerEl = document.querySelector('#someTabTrigger')
+  var tab = new bootstrap.Tab(someTabTriggerEl)
+
+  tab.show()
 {{< /highlight >}}
 
-#### .tab('dispose')
+#### dispose
 
 Destroys an element's tab.
 
+#### getInstance
+
+*Static* method which allows you to get the tab instance associated with a DOM element
+
+{{< highlight js >}}
+var triggerEl = document.querySelector('#trigger')
+var tab = bootstrap.Tab.getInstance(triggerEl) // Returns a Bootstrap tab instance
+{{< /highlight >}}
+
 ### Events
 
 When showing a new tab, the events fire in the following order:
@@ -643,7 +662,8 @@ If no tab was already active, then the `hide.bs.tab` and `hidden.bs.tab` events
 </table>
 
 {{< highlight js >}}
-$('a[data-toggle="tab"]').on('shown.bs.tab', function (e) {
+var tabEl = document.querySelector('a[data-toggle="tab"]')
+tabEl.addEventListener('shown.bs.tab', function (e) {
   e.target // newly activated tab
   e.relatedTarget // previous active tab
 })