2
0
mirror of https://github.com/tenrok/bootstrap.git synced 2026-06-08 17:22:31 +03:00

#11464 - Fix JS noConflict mode - Refactor all plugins to use an internal reference to the jQuery plugin, because in noConflict mode you can never expect to be defined on the jQuery object

This commit is contained in:
Collin Donahue-Oponski
2014-04-21 23:03:33 -06:00
parent 9c4afc5772
commit a9f2b6ce0f
22 changed files with 415 additions and 288 deletions
+21 -12
View File
@@ -1,29 +1,38 @@
$(function () {
module('collapse')
test('should provide no conflict', function () {
var collapse = $.fn.collapse.noConflict()
ok(!$.fn.collapse, 'collapse was set back to undefined (org value)')
$.fn.collapse = collapse
})
module('collapse plugin')
test('should be defined on jquery object', function () {
ok($(document.body).collapse, 'collapse method is defined')
})
module('collapse', {
setup: function() {
// Run all tests in noConflict mode -- it's the only way to ensure that the plugin works in noConflict mode
$.fn.bootstrapCollapse = $.fn.collapse.noConflict()
},
teardown: function() {
$.fn.collapse = $.fn.bootstrapCollapse
delete $.fn.bootstrapCollapse
}
})
test('should provide no conflict', function () {
ok(!$.fn.collapse, 'collapse was set back to undefined (org value)')
})
test('should return element', function () {
ok($(document.body).collapse()[0] == document.body, 'document.body returned')
ok($(document.body).bootstrapCollapse()[0] == document.body, 'document.body returned')
})
test('should show a collapsed element', function () {
var el = $('<div class="collapse"></div>').collapse('show')
var el = $('<div class="collapse"></div>').bootstrapCollapse('show')
ok(el.hasClass('in'), 'has class in')
ok(!/height/.test(el.attr('style')), 'has height reset')
})
test('should hide a collapsed element', function () {
var el = $('<div class="collapse"></div>').collapse('hide')
var el = $('<div class="collapse"></div>').bootstrapCollapse('hide')
ok(!el.hasClass('in'), 'does not have class in')
ok(/height/.test(el.attr('style')), 'has height set')
})
@@ -40,7 +49,7 @@ $(function () {
.on('shown.bs.collapse', function () {
ok(false)
})
.collapse('show')
.bootstrapCollapse('show')
})
test('should reset style to auto after finishing opening collapse', function () {
@@ -54,7 +63,7 @@ $(function () {
ok(this.style.height === '')
start()
})
.collapse('show')
.bootstrapCollapse('show')
})
test('should add active class to target when collapse shown', function () {