chniter / bstreeview

Bootstrap Treeview, A very simple plugin to build a basic and elegant Treeview with bootstrap 4. See the demo:
https://chniter.github.io/bstreeview/
Apache License 2.0
366 stars 53 forks source link

Bootstrap 5 #21

Open ScotsScripts opened 3 years ago

ScotsScripts commented 3 years ago

Just a quick note on bootstrap 5 usage. All that needs to be done is change data-toggle to data-bs-toggle in the js and this plugin works for bs5. Great plugin, wish I would have found it sooner!

dkarelov commented 3 years ago

Not only - also data-target to data-bs-target

ghost commented 3 years ago

Thanks for the workaround for bootstrap v5! I can confirm these 2 changes have fixed it.

data-toggle -> data-bs-toggle
data-target -> data-bs-target

Any ETA on a new release ?

asticore commented 3 years ago

Not really. You need to remove Jquery to be satisfactory

Khuthaily commented 2 years ago

Please check my pull request. @m-peterman, the issue is not in jQuery. As @ScotsScripts and @k3kc suggested, it is because Bootstrap 5 uses data-bs-* instead of data-*. So, this pull request simply checks for the Bootstrap version and then uses the right attribute names based on the version. It works fine for me on both Bootstrap 4 and Bootstrap 5.

Khuthaily commented 2 years ago

Till the pull request is merged, you can do these steps to provide support for Bootstrap 4 and Bootstrap 5:

  1. add

    /**
    * Define Bootstrap 4 attributes
    */
    let dataToggleAttr = 'data-toggle';
    let dataTargetAttr = 'data-target';
    /**
    * get Bootstrap version
    */
    let bootstrapVersion = (bootstrap.Tooltip.VERSION).charAt(0);
    /**
    * If Bootstrap 5, redefine attributes
    */
    if (bootstrapVersion === '5') {
    dataToggleAttr = 'data-bs-toggle';
    dataTargetAttr = 'data-bs-target';
    }

    before the var templates line.

  2. replace the line

    treeviewItem: '<div role="treeitem" class="list-group-item" data-toggle="collapse"></div>',

    with

    treeviewItem: '<div role="treeitem" class="list-group-item" ' + dataToggleAttr + '="collapse"></div>',
  3. replace the line

    .attr('data-target', "#" + _this.itemIdPrefix + node.nodeId)

    with

    .attr(dataTargetAttr, "#" + _this.itemIdPrefix + node.nodeId)

    Done! Enjoy.