From a7eb9c294a575b5471ddec45ae75e1d09f7ace4c Mon Sep 17 00:00:00 2001 From: fat Date: Fri, 7 Dec 2012 17:06:01 -0500 Subject: add noConflict functionality to all bootstrap plugins --- js/bootstrap-affix.js | 11 +++++++++++ js/bootstrap-alert.js | 11 +++++++++++ js/bootstrap-button.js | 11 +++++++++++ js/bootstrap-carousel.js | 10 ++++++++++ js/bootstrap-collapse.js | 17 ++++++++++++++--- js/bootstrap-dropdown.js | 11 +++++++++++ js/bootstrap-modal.js | 11 +++++++++++ js/bootstrap-popover.js | 13 ++++++++++++- js/bootstrap-scrollspy.js | 11 +++++++++++ js/bootstrap-tab.js | 11 +++++++++++ js/bootstrap-tooltip.js | 11 +++++++++++ js/bootstrap-typeahead.js | 13 ++++++++++++- js/tests/unit/bootstrap-affix.js | 6 ++++++ js/tests/unit/bootstrap-alert.js | 6 ++++++ js/tests/unit/bootstrap-button.js | 6 ++++++ js/tests/unit/bootstrap-carousel.js | 6 ++++++ js/tests/unit/bootstrap-collapse.js | 6 ++++++ js/tests/unit/bootstrap-dropdown.js | 10 ++++++++-- js/tests/unit/bootstrap-modal.js | 6 ++++++ js/tests/unit/bootstrap-popover.js | 12 +++++++++--- js/tests/unit/bootstrap-scrollspy.js | 6 ++++++ js/tests/unit/bootstrap-tab.js | 6 ++++++ js/tests/unit/bootstrap-tooltip.js | 6 ++++++ js/tests/unit/bootstrap-typeahead.js | 6 ++++++ 24 files changed, 213 insertions(+), 10 deletions(-) (limited to 'js') diff --git a/js/bootstrap-affix.js b/js/bootstrap-affix.js index 18d4fc9ad2..6020a19a58 100644 --- a/js/bootstrap-affix.js +++ b/js/bootstrap-affix.js @@ -68,6 +68,8 @@ /* AFFIX PLUGIN DEFINITION * ======================= */ + var old = $.fn.affix + $.fn.affix = function (option) { return this.each(function () { var $this = $(this) @@ -85,6 +87,15 @@ } + /* AFFIX NO CONFLICT + * ================= */ + + $.fn.affix.noConflict = function () { + $.fn.affix = old + return this + } + + /* AFFIX DATA-API * ============== */ diff --git a/js/bootstrap-alert.js b/js/bootstrap-alert.js index dda647ec22..5bc0264491 100644 --- a/js/bootstrap-alert.js +++ b/js/bootstrap-alert.js @@ -68,6 +68,8 @@ /* ALERT PLUGIN DEFINITION * ======================= */ + var old = $.fn.alert + $.fn.alert = function (option) { return this.each(function () { var $this = $(this) @@ -80,6 +82,15 @@ $.fn.alert.Constructor = Alert + /* ALERT NO CONFLICT + * ================= */ + + $.fn.alert.noConflict = function () { + $.fn.alert = old + return this + } + + /* ALERT DATA-API * ============== */ diff --git a/js/bootstrap-button.js b/js/bootstrap-button.js index 619423bbc8..39b83399e9 100644 --- a/js/bootstrap-button.js +++ b/js/bootstrap-button.js @@ -64,6 +64,8 @@ /* BUTTON PLUGIN DEFINITION * ======================== */ + var old = $.fn.button + $.fn.button = function (option) { return this.each(function () { var $this = $(this) @@ -82,6 +84,15 @@ $.fn.button.Constructor = Button + /* BUTTON NO CONFLICT + * ================== */ + + $.fn.button.noConflict = function () { + $.fn.button = old + return this + } + + /* BUTTON DATA-API * =============== */ diff --git a/js/bootstrap-carousel.js b/js/bootstrap-carousel.js index 099b669308..ba26a5cd49 100644 --- a/js/bootstrap-carousel.js +++ b/js/bootstrap-carousel.js @@ -141,6 +141,8 @@ /* CAROUSEL PLUGIN DEFINITION * ========================== */ + var old = $.fn.carousel + $.fn.carousel = function (option) { return this.each(function () { var $this = $(this) @@ -162,6 +164,14 @@ $.fn.carousel.Constructor = Carousel + /* CAROUSEL NO CONFLICT + * ==================== */ + + $.fn.carousel.noConflict = function () { + $.fn.carousel = old + return this + } + /* CAROUSEL DATA-API * ================= */ diff --git a/js/bootstrap-collapse.js b/js/bootstrap-collapse.js index a09ce10048..6ac0191a50 100644 --- a/js/bootstrap-collapse.js +++ b/js/bootstrap-collapse.js @@ -120,8 +120,10 @@ } - /* COLLAPSIBLE PLUGIN DEFINITION - * ============================== */ + /* COLLAPSE PLUGIN DEFINITION + * ========================== */ + + var old = $.fn.collapse $.fn.collapse = function (option) { return this.each(function () { @@ -140,9 +142,18 @@ $.fn.collapse.Constructor = Collapse - /* COLLAPSIBLE DATA-API + /* COLLAPSE NO CONFLICT * ==================== */ + $.fn.collapse.noConflict = function () { + $.fn.collapse = old + return this + } + + + /* COLLAPSE DATA-API + * ================= */ + $(document).on('click.collapse.data-api', '[data-toggle=collapse]', function (e) { var $this = $(this), href , target = $this.attr('data-target') diff --git a/js/bootstrap-dropdown.js b/js/bootstrap-dropdown.js index 84e1dedb84..61f3b941a2 100644 --- a/js/bootstrap-dropdown.js +++ b/js/bootstrap-dropdown.js @@ -124,6 +124,8 @@ /* DROPDOWN PLUGIN DEFINITION * ========================== */ + var old = $.fn.dropdown + $.fn.dropdown = function (option) { return this.each(function () { var $this = $(this) @@ -136,6 +138,15 @@ $.fn.dropdown.Constructor = Dropdown + /* DROPDOWN NO CONFLICT + * ==================== */ + + $.fn.dropdown.noConflict = function () { + $.fn.dropdown = old + return this + } + + /* APPLY TO STANDARD DROPDOWN ELEMENTS * =================================== */ diff --git a/js/bootstrap-modal.js b/js/bootstrap-modal.js index 6fae364366..689a414ed6 100644 --- a/js/bootstrap-modal.js +++ b/js/bootstrap-modal.js @@ -193,6 +193,8 @@ /* MODAL PLUGIN DEFINITION * ======================= */ + var old = $.fn.modal + $.fn.modal = function (option) { return this.each(function () { var $this = $(this) @@ -213,6 +215,15 @@ $.fn.modal.Constructor = Modal + /* MODAL NO CONFLICT + * ================= */ + + $.fn.modal.noConflict = function () { + $.fn.modal = old + return this + } + + /* MODAL DATA-API * ============== */ diff --git a/js/bootstrap-popover.js b/js/bootstrap-popover.js index 56a63d4a24..1a4f532aa8 100644 --- a/js/bootstrap-popover.js +++ b/js/bootstrap-popover.js @@ -81,6 +81,8 @@ /* POPOVER PLUGIN DEFINITION * ======================= */ + var old = $.fn.popover + $.fn.popover = function (option) { return this.each(function () { var $this = $(this) @@ -100,4 +102,13 @@ , template: '

' }) -}(window.jQuery); + + /* POPOVER NO CONFLICT + * =================== */ + + $.fn.popover.noConflict = function () { + $.fn.popover = old + return this + } + +}(window.jQuery); \ No newline at end of file diff --git a/js/bootstrap-scrollspy.js b/js/bootstrap-scrollspy.js index 34f7748684..fd82872c5c 100644 --- a/js/bootstrap-scrollspy.js +++ b/js/bootstrap-scrollspy.js @@ -121,6 +121,8 @@ /* SCROLLSPY PLUGIN DEFINITION * =========================== */ + var old = $.fn.scrollspy + $.fn.scrollspy = function (option) { return this.each(function () { var $this = $(this) @@ -138,6 +140,15 @@ } + /* SCROLLSPY NO CONFLICT + * ===================== */ + + $.fn.scrollspy.noConflict = function () { + $.fn.scrollspy = old + return this + } + + /* SCROLLSPY DATA-API * ================== */ diff --git a/js/bootstrap-tab.js b/js/bootstrap-tab.js index 059b39b351..84d4834a23 100644 --- a/js/bootstrap-tab.js +++ b/js/bootstrap-tab.js @@ -110,6 +110,8 @@ /* TAB PLUGIN DEFINITION * ===================== */ + var old = $.fn.tab + $.fn.tab = function ( option ) { return this.each(function () { var $this = $(this) @@ -122,6 +124,15 @@ $.fn.tab.Constructor = Tab + /* TAB NO CONFLICT + * =============== */ + + $.fn.tab.noConflict = function () { + $.fn.tab = old + return this + } + + /* TAB DATA-API * ============ */ diff --git a/js/bootstrap-tooltip.js b/js/bootstrap-tooltip.js index b3325b2380..a08952a4cf 100644 --- a/js/bootstrap-tooltip.js +++ b/js/bootstrap-tooltip.js @@ -250,6 +250,8 @@ /* TOOLTIP PLUGIN DEFINITION * ========================= */ + var old = $.fn.tooltip + $.fn.tooltip = function ( option ) { return this.each(function () { var $this = $(this) @@ -273,4 +275,13 @@ , html: false } + + /* TOOLTIP NO CONFLICT + * =================== */ + + $.fn.tooltip.noConflict = function () { + $.fn.tooltip = old + return this + } + }(window.jQuery); \ No newline at end of file diff --git a/js/bootstrap-typeahead.js b/js/bootstrap-typeahead.js index 512d91acb4..9b123fb3fb 100644 --- a/js/bootstrap-typeahead.js +++ b/js/bootstrap-typeahead.js @@ -276,6 +276,8 @@ /* TYPEAHEAD PLUGIN DEFINITION * =========================== */ + var old = $.fn.typeahead + $.fn.typeahead = function (option) { return this.each(function () { var $this = $(this) @@ -297,7 +299,16 @@ $.fn.typeahead.Constructor = Typeahead - /* TYPEAHEAD DATA-API + /* TYPEAHEAD NO CONFLICT + * =================== */ + + $.fn.typeahead.noConflict = function () { + $.fn.typeahead = old + return this + } + + + /* TYPEAHEAD DATA-API * ================== */ $(document).on('focus.typeahead.data-api', '[data-provide="typeahead"]', function (e) { diff --git a/js/tests/unit/bootstrap-affix.js b/js/tests/unit/bootstrap-affix.js index bc25df9917..c978878903 100644 --- a/js/tests/unit/bootstrap-affix.js +++ b/js/tests/unit/bootstrap-affix.js @@ -2,6 +2,12 @@ $(function () { module("bootstrap-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 + }) + test("should be defined on jquery object", function () { ok($(document.body).affix, 'affix method is defined') }) diff --git a/js/tests/unit/bootstrap-alert.js b/js/tests/unit/bootstrap-alert.js index 7f24e0e6be..9a6b514c47 100644 --- a/js/tests/unit/bootstrap-alert.js +++ b/js/tests/unit/bootstrap-alert.js @@ -2,6 +2,12 @@ $(function () { module("bootstrap-alerts") + test("should provide no conflict", function () { + var alert = $.fn.alert.noConflict() + ok(!$.fn.alert, 'alert was set back to undefined (org value)') + $.fn.alert = alert + }) + test("should be defined on jquery object", function () { ok($(document.body).alert, 'alert method is defined') }) diff --git a/js/tests/unit/bootstrap-button.js b/js/tests/unit/bootstrap-button.js index b5d0834999..e23ff9e302 100644 --- a/js/tests/unit/bootstrap-button.js +++ b/js/tests/unit/bootstrap-button.js @@ -2,6 +2,12 @@ $(function () { module("bootstrap-buttons") + test("should provide no conflict", function () { + var button = $.fn.button.noConflict() + ok(!$.fn.button, 'button was set back to undefined (org value)') + $.fn.button = button + }) + test("should be defined on jquery object", function () { ok($(document.body).button, 'button method is defined') }) diff --git a/js/tests/unit/bootstrap-carousel.js b/js/tests/unit/bootstrap-carousel.js index 8bd1b62ba0..13b8f721fc 100644 --- a/js/tests/unit/bootstrap-carousel.js +++ b/js/tests/unit/bootstrap-carousel.js @@ -2,6 +2,12 @@ $(function () { module("bootstrap-carousel") + test("should provide no conflict", function () { + var carousel = $.fn.carousel.noConflict() + ok(!$.fn.carousel, 'carousel was set back to undefined (org value)') + $.fn.carousel = carousel + }) + test("should be defined on jquery object", function () { ok($(document.body).carousel, 'carousel method is defined') }) diff --git a/js/tests/unit/bootstrap-collapse.js b/js/tests/unit/bootstrap-collapse.js index 6cc7ac7a44..4c5916ecd9 100644 --- a/js/tests/unit/bootstrap-collapse.js +++ b/js/tests/unit/bootstrap-collapse.js @@ -2,6 +2,12 @@ $(function () { module("bootstrap-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 + }) + test("should be defined on jquery object", function () { ok($(document.body).collapse, 'collapse method is defined') }) diff --git a/js/tests/unit/bootstrap-dropdown.js b/js/tests/unit/bootstrap-dropdown.js index 3788209ecc..2f0d2d29ec 100644 --- a/js/tests/unit/bootstrap-dropdown.js +++ b/js/tests/unit/bootstrap-dropdown.js @@ -2,6 +2,12 @@ $(function () { module("bootstrap-dropdowns") + test("should provide no conflict", function () { + var dropdown = $.fn.dropdown.noConflict() + ok(!$.fn.dropdown, 'dropdown was set back to undefined (org value)') + $.fn.dropdown = dropdown + }) + test("should be defined on jquery object", function () { ok($(document.body).dropdown, 'dropdown method is defined') }) @@ -104,7 +110,7 @@ $(function () { }) test("should remove open class if body clicked, with multiple drop downs", function () { - var dropdownHTML = + var dropdownHTML = '