]> git.ipfire.org Git - thirdparty/bootstrap.git/commitdiff
remove jquery references from list group
authorJohann-S <johann.servoire@gmail.com>
Sun, 4 Aug 2019 09:55:37 +0000 (11:55 +0200)
committerJohann-S <johann.servoire@gmail.com>
Sun, 4 Aug 2019 11:22:47 +0000 (13:22 +0200)
site/content/docs/4.3/components/list-group.md

index 032ef37f5f49ae247d656c4af21b7354d6e3a236..21bab14d779ab4f083db2675cd3878e3173b8871 100644 (file)
@@ -281,19 +281,25 @@ You can activate a list group navigation without writing any JavaScript by simpl
 Enable tabbable list item via JavaScript (each list item needs to be activated individually):
 
 {{< highlight js >}}
-$('#myList 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 list item in several ways:
 
 {{< highlight js >}}
-$('#myList a[href="#profile"]').tab('show') // Select tab by name
-$('#myList a:first-child').tab('show') // Select first tab
-$('#myList a:last-child').tab('show') // Select last tab
-$('#myList a:nth-child(3)').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
@@ -311,7 +317,7 @@ To make tabs panel fade in, add `.fade` to each `.tab-pane`. The first tab pane
 
 ### Methods
 
-#### $().tab
+#### constructor
 
 Activates a list item element and content container. Tab should have either a `data-target` or an `href` targeting a container node in the DOM.
 
@@ -331,18 +337,35 @@ Activates a list item element and content container. Tab should have either a `d
 </div>
 
 <script>
-  $(function () {
-    $('#myList a:last-child').tab('show')
-  })
+  var firstTabEl = document.querySelector('#myTab a:last-child')
+  var firstTab = new bootstrap.Tab(firstTabEl)
+
+  firstTab.show()
 </script>
 {{< /highlight >}}
 
-#### .tab('show')
+#### show
 
 Selects the given list item and shows its associated pane. Any other list item that was previously selected becomes unselected and its associated pane is hidden. **Returns to the caller before the tab pane has actually been shown** (for example, before the `shown.bs.tab` event occurs).
 
 {{< highlight js >}}
-$('#someListItem').tab('show')
+  var someListItemEl = document.querySelector('#someListItem')
+  var tab = new bootstrap.Tab(someListItemEl)
+
+  tab.show()
+{{< /highlight >}}
+
+#### 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
@@ -384,7 +407,8 @@ If no tab was already active, the `hide.bs.tab` and `hidden.bs.tab` events will
 </table>
 
 {{< highlight js >}}
-$('a[data-toggle="list"]').on('shown.bs.tab', function (e) {
+var tabEl = document.querySelector('a[data-toggle="list"]')
+tabEl.addEventListener('shown.bs.tab', function (e) {
   e.target // newly activated tab
   e.relatedTarget // previous active tab
 })