From 1f1f4d29b97289fa29b50b7f9123a6063bc61823 Mon Sep 17 00:00:00 2001 From: ThibaudD Date: Sun, 23 Feb 2014 16:33:29 +0100 Subject: [PATCH 1/2] Add classNameSize --- bootbox.js | 5 +++++ tests/defaults.test.js | 33 +++++++++++++++++++++++++++++++++ 2 files changed, 38 insertions(+) diff --git a/bootbox.js b/bootbox.js index cbefb471..8e44dd44 100644 --- a/bootbox.js +++ b/bootbox.js @@ -572,6 +572,7 @@ options = sanitize(options); var dialog = $(templates.dialog); + var dialogSize = dialog.find(".modal-dialog"); var body = dialog.find(".modal-body"); var buttons = options.buttons; var buttonStr = ""; @@ -598,6 +599,10 @@ dialog.addClass(options.className); } + if (options.classNameSize) { + dialogSize.addClass(options.classNameSize); + } + if (options.title) { body.before(templates.header); } diff --git a/tests/defaults.test.js b/tests/defaults.test.js index 6fb671a5..5e82fd30 100644 --- a/tests/defaults.test.js +++ b/tests/defaults.test.js @@ -58,6 +58,25 @@ describe("bootbox.setDefaults", function() { }); }); + describe("classNameSize", function() { + describe("when passed as a string", function() { + beforeEach(function() { + bootbox.setDefaults({ + classNameSize: "my-class-size" + }); + + this.dialog = bootbox.dialog({ + message: "test" + }); + }); + + it("adds the extra size class to the dialog", function() { + expect(this.dialog.children(":first").hasClass("modal-dialog")).to.be.true; + expect(this.dialog.children(":first").hasClass("my-class-size")).to.be.true; + }); + }); + }); + describe("backdrop", function() { describe("when set to false", function() { beforeEach(function() { @@ -90,6 +109,20 @@ describe("bootbox.setDefaults", function() { }); }); + describe("when passed two arguments", function() { + beforeEach(function() { + bootbox.setDefaults("classNameSize", "my-class-size"); + this.dialog = bootbox.dialog({ + message: "test" + }); + }); + + it("applies the arguments as a key/value pair", function() { + expect(this.dialog.children(":first").hasClass("modal-dialog")).to.be.true; + expect(this.dialog.children(":first").hasClass("my-class-size")).to.be.true; + }); + }); + describe("container", function () { describe("when not explicitly set", function() { beforeEach(function() { From d5adcd227baa32022e201eac023bfff28ebd8a70 Mon Sep 17 00:00:00 2001 From: ThibaudD Date: Sat, 1 Mar 2014 14:16:51 +0100 Subject: [PATCH 2/2] Size option instead of classNameSize --- bootbox.js | 10 +++++++--- tests/defaults.test.js | 40 +++++++++++++++++++++------------------- tests/dialog.test.coffee | 19 +++++++++++++++++++ 3 files changed, 47 insertions(+), 22 deletions(-) diff --git a/bootbox.js b/bootbox.js index 8e44dd44..2adbfbf4 100644 --- a/bootbox.js +++ b/bootbox.js @@ -572,7 +572,7 @@ options = sanitize(options); var dialog = $(templates.dialog); - var dialogSize = dialog.find(".modal-dialog"); + var innerDialog = dialog.find(".modal-dialog"); var body = dialog.find(".modal-body"); var buttons = options.buttons; var buttonStr = ""; @@ -599,8 +599,12 @@ dialog.addClass(options.className); } - if (options.classNameSize) { - dialogSize.addClass(options.classNameSize); + if (options.size === "large") { + innerDialog.addClass("modal-lg"); + } + + if (options.size === "small") { + innerDialog.addClass("modal-sm"); } if (options.title) { diff --git a/tests/defaults.test.js b/tests/defaults.test.js index 5e82fd30..9bffc76e 100644 --- a/tests/defaults.test.js +++ b/tests/defaults.test.js @@ -58,11 +58,27 @@ describe("bootbox.setDefaults", function() { }); }); - describe("classNameSize", function() { - describe("when passed as a string", function() { + describe("size", function() { + describe("when set to large", function() { + beforeEach(function() { + bootbox.setDefaults({ + size: "large" + }); + + this.dialog = bootbox.dialog({ + message: "test" + }); + }); + + it("adds the large class to the innerDialog", function() { + expect(this.dialog.children(":first").hasClass("modal-dialog")).to.be.true; + expect(this.dialog.children(":first").hasClass("modal-lg")).to.be.true; + }); + }); + describe("when set to small", function() { beforeEach(function() { bootbox.setDefaults({ - classNameSize: "my-class-size" + size: "small" }); this.dialog = bootbox.dialog({ @@ -70,9 +86,9 @@ describe("bootbox.setDefaults", function() { }); }); - it("adds the extra size class to the dialog", function() { + it("adds the small class to the innerDialog", function() { expect(this.dialog.children(":first").hasClass("modal-dialog")).to.be.true; - expect(this.dialog.children(":first").hasClass("my-class-size")).to.be.true; + expect(this.dialog.children(":first").hasClass("modal-sm")).to.be.true; }); }); }); @@ -109,20 +125,6 @@ describe("bootbox.setDefaults", function() { }); }); - describe("when passed two arguments", function() { - beforeEach(function() { - bootbox.setDefaults("classNameSize", "my-class-size"); - this.dialog = bootbox.dialog({ - message: "test" - }); - }); - - it("applies the arguments as a key/value pair", function() { - expect(this.dialog.children(":first").hasClass("modal-dialog")).to.be.true; - expect(this.dialog.children(":first").hasClass("my-class-size")).to.be.true; - }); - }); - describe("container", function () { describe("when not explicitly set", function() { beforeEach(function() { diff --git a/tests/dialog.test.coffee b/tests/dialog.test.coffee index c65e6dfa..aa17e289 100644 --- a/tests/dialog.test.coffee +++ b/tests/dialog.test.coffee @@ -313,3 +313,22 @@ describe "bootbox.dialog", -> it "should not hide the modal", -> expect(@hidden).not.to.have.been.called + + describe "with size option", -> + describe "when the size option is set to large", -> + beforeEach -> + @dialog = bootbox.dialog + message: "test" + size: "large" + + it "adds the large class to the innerDialog", -> + expect(@dialog.children(":first").hasClass("modal-lg")).to.be.true + + describe "when the size option is set to small", -> + beforeEach -> + @dialog = bootbox.dialog + message: "test" + size: "small" + + it "adds the large class to the innerDialog", -> + expect(@dialog.children(":first").hasClass("modal-sm")).to.be.true