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

Fix #11464 - JS noConflict() mode not working in 3.0.x #11966

Merged
merged 1 commit into from
May 1, 2014
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 5 additions & 4 deletions js/affix.js
Original file line number Diff line number Diff line change
Expand Up @@ -90,9 +90,7 @@
// AFFIX PLUGIN DEFINITION
// =======================

var old = $.fn.affix

$.fn.affix = function (option) {
function Plugin(option) {
return this.each(function () {
var $this = $(this)
var data = $this.data('bs.affix')
Expand All @@ -103,6 +101,9 @@
})
}

var old = $.fn.affix

$.fn.affix = Plugin
$.fn.affix.Constructor = Affix
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

could you change these to:

  var old = $.fn.affix

  $.fn.affix             = Plugin
  $.fn.affix.Constructor = Affix



Expand All @@ -128,7 +129,7 @@
if (data.offsetBottom) data.offset.bottom = data.offsetBottom
if (data.offsetTop) data.offset.top = data.offsetTop

$spy.affix(data)
Plugin.call($spy, data)
})
})

Expand Down
7 changes: 4 additions & 3 deletions js/alert.js
Original file line number Diff line number Diff line change
Expand Up @@ -56,9 +56,7 @@
// ALERT PLUGIN DEFINITION
// =======================

var old = $.fn.alert

$.fn.alert = function (option) {
function Plugin(option) {
return this.each(function () {
var $this = $(this)
var data = $this.data('bs.alert')
Expand All @@ -68,6 +66,9 @@
})
}

var old = $.fn.alert

$.fn.alert = Plugin
$.fn.alert.Constructor = Alert
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

spacing looks a bit weird and the = aren't lined up… so it doesn't really match the style of these plugins



Expand Down
9 changes: 5 additions & 4 deletions js/button.js
Original file line number Diff line number Diff line change
Expand Up @@ -67,9 +67,7 @@
// BUTTON PLUGIN DEFINITION
// ========================

var old = $.fn.button

$.fn.button = function (option) {
function Plugin(option) {
return this.each(function () {
var $this = $(this)
var data = $this.data('bs.button')
Expand All @@ -82,6 +80,9 @@
})
}

var old = $.fn.button

$.fn.button = Plugin
$.fn.button.Constructor = Button


Expand All @@ -100,7 +101,7 @@
$(document).on('click.bs.button.data-api', '[data-toggle^="button"]', function (e) {
var $btn = $(e.target)
if (!$btn.hasClass('btn')) $btn = $btn.closest('.btn')
$btn.button('toggle')
Plugin.call($btn, 'toggle')
e.preventDefault()
})

Expand Down
11 changes: 6 additions & 5 deletions js/carousel.js
Original file line number Diff line number Diff line change
Expand Up @@ -148,9 +148,7 @@
// CAROUSEL PLUGIN DEFINITION
// ==========================

var old = $.fn.carousel

$.fn.carousel = function (option) {
function Plugin(option) {
return this.each(function () {
var $this = $(this)
var data = $this.data('bs.carousel')
Expand All @@ -164,6 +162,9 @@
})
}

var old = $.fn.carousel

$.fn.carousel = Plugin
$.fn.carousel.Constructor = Carousel


Expand All @@ -186,7 +187,7 @@
var slideIndex = $this.attr('data-slide-to')
if (slideIndex) options.interval = false

$target.carousel(options)
Plugin.call($target, options)

if (slideIndex = $this.attr('data-slide-to')) {
$target.data('bs.carousel').to(slideIndex)
Expand All @@ -198,7 +199,7 @@
$(window).on('load', function () {
$('[data-ride="carousel"]').each(function () {
var $carousel = $(this)
$carousel.carousel($carousel.data())
Plugin.call($carousel, $carousel.data())
})
})

Expand Down
11 changes: 6 additions & 5 deletions js/collapse.js
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@
if (actives && actives.length) {
var hasData = actives.data('bs.collapse')
if (hasData && hasData.transitioning) return
actives.collapse('hide')
Plugin.call(actives, 'hide')
hasData || actives.data('bs.collapse', null)
}

Expand Down Expand Up @@ -124,9 +124,7 @@
// COLLAPSE PLUGIN DEFINITION
// ==========================

var old = $.fn.collapse

$.fn.collapse = function (option) {
function Plugin(option) {
return this.each(function () {
var $this = $(this)
var data = $this.data('bs.collapse')
Expand All @@ -138,6 +136,9 @@
})
}

var old = $.fn.collapse

$.fn.collapse = Plugin
$.fn.collapse.Constructor = Collapse


Expand Down Expand Up @@ -169,7 +170,7 @@
$this[$target.hasClass('in') ? 'addClass' : 'removeClass']('collapsed')
}

$target.collapse(option)
Plugin.call($target, option)
})

}(jQuery);
7 changes: 4 additions & 3 deletions js/dropdown.js
Original file line number Diff line number Diff line change
Expand Up @@ -112,9 +112,7 @@
// DROPDOWN PLUGIN DEFINITION
// ==========================

var old = $.fn.dropdown

$.fn.dropdown = function (option) {
function Plugin(option) {
return this.each(function () {
var $this = $(this)
var data = $this.data('bs.dropdown')
Expand All @@ -124,6 +122,9 @@
})
}

var old = $.fn.dropdown

$.fn.dropdown = Plugin
$.fn.dropdown.Constructor = Dropdown


Expand Down
16 changes: 8 additions & 8 deletions js/modal.js
Original file line number Diff line number Diff line change
Expand Up @@ -228,9 +228,7 @@
// MODAL PLUGIN DEFINITION
// =======================

var old = $.fn.modal

$.fn.modal = function (option, _relatedTarget) {
function Plugin(option, _relatedTarget) {
return this.each(function () {
var $this = $(this)
var data = $this.data('bs.modal')
Expand All @@ -242,6 +240,9 @@
})
}

var old = $.fn.modal

$.fn.modal = Plugin
$.fn.modal.Constructor = Modal


Expand All @@ -265,11 +266,10 @@

if ($this.is('a')) e.preventDefault()

$target
.modal(option, this)
.one('hide', function () {
$this.is(':visible') && $this.trigger('focus')
})
Plugin.call($target, option, this)
$target.one('hide', function () {
$this.is(':visible') && $this.trigger('focus')
})
})

}(jQuery);
7 changes: 4 additions & 3 deletions js/popover.js
Original file line number Diff line number Diff line change
Expand Up @@ -82,9 +82,7 @@
// POPOVER PLUGIN DEFINITION
// =========================

var old = $.fn.popover

$.fn.popover = function (option) {
function Plugin(option) {
return this.each(function () {
var $this = $(this)
var data = $this.data('bs.popover')
Expand All @@ -96,6 +94,9 @@
})
}

var old = $.fn.popover

$.fn.popover = Plugin
$.fn.popover.Constructor = Popover


Expand Down
9 changes: 5 additions & 4 deletions js/scrollspy.js
Original file line number Diff line number Diff line change
Expand Up @@ -116,9 +116,7 @@
// SCROLLSPY PLUGIN DEFINITION
// ===========================

var old = $.fn.scrollspy

$.fn.scrollspy = function (option) {
function Plugin(option) {
return this.each(function () {
var $this = $(this)
var data = $this.data('bs.scrollspy')
Expand All @@ -129,6 +127,9 @@
})
}

var old = $.fn.scrollspy

$.fn.scrollspy = Plugin
$.fn.scrollspy.Constructor = ScrollSpy


Expand All @@ -147,7 +148,7 @@
$(window).on('load.bs.scrollspy.data-api', function () {
$('[data-spy="scroll"]').each(function () {
var $spy = $(this)
$spy.scrollspy($spy.data())
Plugin.call($spy, $spy.data())
})
})

Expand Down
9 changes: 5 additions & 4 deletions js/tab.js
Original file line number Diff line number Diff line change
Expand Up @@ -90,9 +90,7 @@
// TAB PLUGIN DEFINITION
// =====================

var old = $.fn.tab

$.fn.tab = function ( option ) {
function Plugin( option ) {
return this.each(function () {
var $this = $(this)
var data = $this.data('bs.tab')
Expand All @@ -102,6 +100,9 @@
})
}

var old = $.fn.tab

$.fn.tab = Plugin
$.fn.tab.Constructor = Tab


Expand All @@ -119,7 +120,7 @@

$(document).on('click.bs.tab.data-api', '[data-toggle="tab"], [data-toggle="pill"]', function (e) {
e.preventDefault()
$(this).tab('show')
Plugin.call($(this), 'show')
})

}(jQuery);
29 changes: 19 additions & 10 deletions js/tests/unit/affix.js
Original file line number Diff line number Diff line change
@@ -1,23 +1,32 @@
$(function () {

module('affix')

test('should provide no conflict', function () {
var affix = $.fn.affix.noConflict()
ok(!$.fn.affix, 'affix was set back to undefined (org value)')
$.fn.affix = affix
})
module('affix plugin')

test('should be defined on jquery object', function () {
ok($(document.body).affix, 'affix method is defined')
})

module('affix', {
setup: function() {
// Run all tests in noConflict mode -- it's the only way to ensure that the plugin works in noConflict mode
$.fn.bootstrapAffix = $.fn.affix.noConflict()
},
teardown: function() {
$.fn.affix = $.fn.bootstrapAffix
delete $.fn.bootstrapAffix
}
})

test('should provide no conflict', function () {
ok(!$.fn.affix, 'affix was set back to undefined (org value)')
})

test('should return element', function () {
ok($(document.body).affix()[0] == document.body, 'document.body returned')
ok($(document.body).bootstrapAffix()[0] == document.body, 'document.body returned')
})

test('should exit early if element is not visible', function () {
var $affix = $('<div style="display: none"></div>').affix()
var $affix = $('<div style="display: none"></div>').bootstrapAffix()
$affix.data('bs.affix').checkPosition()
ok(!$affix.hasClass('affix'), 'affix class was not added')
})
Expand All @@ -28,7 +37,7 @@ $(function () {
var template = $('<div id="affixTarget"><ul><li>Please affix</li><li>And unaffix</li></ul></div><div id="affixAfter" style="height: 20000px; display:block;"></div>')
template.appendTo('body')

$('#affixTarget').affix({
$('#affixTarget').bootstrapAffix({
offset: $('#affixTarget ul').position()
})

Expand Down
Loading