Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

noConflict does not work for Modal due to hardcoded reference to $.fn.modal.defaults #6458

Closed
jbwyme opened this issue Jan 5, 2013 · 1 comment

Comments

@jbwyme
Copy link

jbwyme commented Jan 5, 2013

When attempting to use noConflict with the bootstrap modal, it causes a js error due to a hard coded reference to $.fn.modal.defaults in the $.fn.modal function definition.

Problem:

$.fn.modal = function (option) {
    return this.each(function () {
      var $this = $(this)
        , data = $this.data('modal')
        , options = $.extend({}, $.fn.modal.defaults, $this.data(), typeof option == 'object' && option)
      if (!data) $this.data('modal', (data = new Modal(this, options)))
      if (typeof option == 'string') data[option]()
      else if (options.show) data.show()
    })
  }

  $.fn.modal.defaults = {
      backdrop: true
    , keyboard: true
    , show: true
  }

Solution (although figuring out a better way to namespace the defaults may be the correct solution):

$.fn.modal = function (option) {
    return this.each(function () {
      var $this = $(this)
        , data = $this.data('modal')
        , options = $.extend({}, modalDefaults, $this.data(), typeof option == 'object' && option)
      if (!data) $this.data('modal', (data = new Modal(this, options)))
      if (typeof option == 'string') data[option]()
      else if (options.show) data.show()
    })
  }

 var modalDefaults = $.fn.modal.defaults = {
      backdrop: true
    , keyboard: true
    , show: true
  }
@fat
Copy link
Member

fat commented Feb 8, 2013

yeah sucks – if you're using this with jquery-ui – i'd just use their bridge for now – we need to work this out in a few plugins

@fat fat closed this as completed Feb 8, 2013
@twbs twbs locked and limited conversation to collaborators Mar 16, 2015
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

3 participants