diff --git a/bootbox.js b/bootbox.js index cbefb471..2adbfbf4 100644 --- a/bootbox.js +++ b/bootbox.js @@ -572,6 +572,7 @@ options = sanitize(options); var dialog = $(templates.dialog); + var innerDialog = dialog.find(".modal-dialog"); var body = dialog.find(".modal-body"); var buttons = options.buttons; var buttonStr = ""; @@ -598,6 +599,14 @@ dialog.addClass(options.className); } + if (options.size === "large") { + innerDialog.addClass("modal-lg"); + } + + if (options.size === "small") { + innerDialog.addClass("modal-sm"); + } + if (options.title) { body.before(templates.header); } diff --git a/tests/defaults.test.js b/tests/defaults.test.js index 6fb671a5..9bffc76e 100644 --- a/tests/defaults.test.js +++ b/tests/defaults.test.js @@ -58,6 +58,41 @@ describe("bootbox.setDefaults", 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({ + size: "small" + }); + + this.dialog = bootbox.dialog({ + message: "test" + }); + }); + + 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("modal-sm")).to.be.true; + }); + }); + }); + describe("backdrop", function() { describe("when set to false", 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