danielstocks / jQuery-Collapse

A lightweight (~1kb) jQuery plugin that enables expanding and collapsing content
http://webcloud.se/jQuery-Collapse/
MIT License
679 stars 153 forks source link

Incompatibility with bootstrap datetimepicker plugin #101

Closed itajackass closed 4 years ago

itajackass commented 4 years ago

Hi, If I insert jquery-collapse in the same page where I have plugin: boostrap-datetimepicker I can't change HOUR

See demo: https://jsfiddle.net/0t4mgLak/

danielstocks commented 4 years ago

Hi, so I think the issue here is that bootstrap also extends the jQuery object with a method called collapse. eg $.collapse().

So from the code that you pasted in your example:

  // Expose in jQuery API
  $.fn.extend({
    // This conflicts with Bootstrap  <-----------
    collapse: function(options, scan) {
      var nodes = (scan) ? $("body").find("[data-collapse]") : $(this);
      return nodes.each(function() {
        var settings = (scan) ? {} : options,
          values = $(this).attr("data-collapse") || "";
        $.each(values.split(" "), function(i,v) {
          if(v) settings[v] = true;
        });
        new Collapse($(this), settings);
      });
    }
  });

  ...

  //jQuery DOM Ready
  $(function() {
    // This conflicts with Bootsrap <-----------
    $.fn.collapse(false, true);
  });

If you rename collapse to jQueryCollapse it might work in this instance, and it won't conflict with Bootstrap anymore.

itajackass commented 4 years ago

Thank you. It works now. Do you update your code? thanks

danielstocks commented 4 years ago

Yeah, I might update the code to do a check if collapse is already defined by another plugin it should throw a warning and use jqueryCollapse instead. That way I will keep backwards compatibility.