diff options
| author | Mark Otto <[email protected]> | 2011-09-10 13:18:24 -0700 |
|---|---|---|
| committer | Mark Otto <[email protected]> | 2011-09-10 13:18:24 -0700 |
| commit | 6d99ae56591f94327453f5dc51e3ce57c64cb831 (patch) | |
| tree | e996c95e344f6acb772f33f1f08606928bc43cb3 | |
| parent | e5b4a1ced5aef8bd050b48873d3e74fb2dfe799e (diff) | |
| parent | 5bc455d3707b87960d32c0672f5afb3b31173ec8 (diff) | |
| download | bootstrap-6d99ae56591f94327453f5dc51e3ce57c64cb831.tar.xz bootstrap-6d99ae56591f94327453f5dc51e3ce57c64cb831.zip | |
Merge branch '1.3-wip' of github.com:twitter/bootstrap into 1.3-wip
| -rw-r--r-- | docs/index.html | 2 | ||||
| -rw-r--r-- | docs/javascript.html | 8 | ||||
| -rw-r--r-- | js/bootstrap-modal.js | 30 | ||||
| -rw-r--r-- | js/bootstrap-popover.js | 5 | ||||
| -rw-r--r-- | js/bootstrap-twipsy.js | 19 | ||||
| -rw-r--r-- | js/tests/unit/bootstrap-modal.js | 50 | ||||
| -rw-r--r-- | js/tests/unit/bootstrap-popover.js | 71 | ||||
| -rw-r--r-- | js/tests/unit/bootstrap-tabs.js | 49 | ||||
| -rw-r--r-- | js/tests/unit/bootstrap-twipsy.js | 81 |
9 files changed, 272 insertions, 43 deletions
diff --git a/docs/index.html b/docs/index.html index c9a51cd7c..42c548ea3 100644 --- a/docs/index.html +++ b/docs/index.html @@ -21,7 +21,7 @@ <script src="http://autobahn.tablesorter.com/jquery.tablesorter.min.js"></script> <script src="assets/js/google-code-prettify/prettify.js"></script> <script>$(function () { prettyPrint() })</script> - <script src="assets/js/bootstrap-dropdown.js"></script> + <script src="../js/bootstrap-dropdown.js"></script> <script src="assets/js/application.js"></script> <script src="assets/js/application-scrollspy.js"></script> diff --git a/docs/javascript.html b/docs/javascript.html index 7d1c6d6ca..8a4636bb3 100644 --- a/docs/javascript.html +++ b/docs/javascript.html @@ -89,12 +89,12 @@ $('#modal-content').modal({ <h4>modal:toggle</h4> <p> Toggle the modal open state.</p> <pre class="prettyprint linenums">$('#modal-content').trigger('modal:toggle')</pre> - <h4>modal:open</h4> + <h4>modal:show</h4> <p>Opens the modal.</p> - <pre class="prettyprint linenums">$('#modal-content').trigger('modal:open')</pre> - <h4>modal:close</h4> + <pre class="prettyprint linenums">$('#modal-content').trigger('modal:show')</pre> + <h4>modal:hide</h4> <p>Closes the modal.</p> - <pre class="prettyprint linenums">$('#modal-content').trigger('modal:close')</pre> + <pre class="prettyprint linenums">$('#modal-content').trigger('modal:hide')</pre> <h3>Demo</h3> <!-- sample modal content --> diff --git a/js/bootstrap-modal.js b/js/bootstrap-modal.js index 4b4f05ae3..54cbad4b1 100644 --- a/js/bootstrap-modal.js +++ b/js/bootstrap-modal.js @@ -40,10 +40,10 @@ } this.$element = $(content) - .bind('modal:open', $.proxy(this.open, this)) - .bind('modal:close', $.proxy(this.close, this)) + .bind('modal:show', $.proxy(this.show, this)) + .bind('modal:hide', $.proxy(this.hide, this)) .bind('modal:toggle', $.proxy(this.toggle, this)) - .delegate('.close', 'click', $.proxy(this.close, this)) + .delegate('.close', 'click', $.proxy(this.hide, this)) return this } @@ -51,12 +51,12 @@ Modal.prototype = { toggle: function () { - return this[!this.isOpen ? 'open' : 'close']() + return this[!this.isShown ? 'show' : 'hide']() } - , open: function () { + , show: function () { var that = this - this.isOpen = true + this.isShown = true _.escape.call(this) _.backdrop.call(this) @@ -73,12 +73,12 @@ return this } - , close: function (e) { + , hide: function (e) { e && e.preventDefault() var that = this - this.isOpen = false + this.isShown = false _.escape.call(this) _.backdrop.call(this) @@ -108,11 +108,11 @@ backdrop: function () { var that = this , animate = this.$element.hasClass('fade') ? 'fade' : '' - if ( this.isOpen && this.settings.backdrop ) { + if ( this.isShown && this.settings.backdrop ) { this.$backdrop = $('<div class="modal-backdrop ' + animate + '" />') - .click(function () { that.close() }) + .click($.proxy(this.hide, this)) .appendTo(document.body) - } else if ( !this.isOpen && this.$backdrop ) { + } else if ( !this.isShown && this.$backdrop ) { this.$backdrop.removeClass('in') function removeElement() { @@ -128,13 +128,13 @@ , escape: function () { var that = this - if ( this.isOpen && this.settings.closeOnEscape ) { + if ( this.isShown && this.settings.closeOnEscape ) { $('body').bind('keyup.modal.escape', function ( e ) { if ( e.which == 27 ) { - that.close() + that.hide() } }) - } else if ( !this.isOpen ) { + } else if ( !this.isShown ) { $('body').unbind('keyup.modal.escape') } } @@ -156,7 +156,7 @@ $.fn.modal.defaults = { backdrop: false - , closeOnEscape: false + , hideOnEscape: false } })( jQuery || ender )
\ No newline at end of file diff --git a/js/bootstrap-popover.js b/js/bootstrap-popover.js index 53284806f..5928fe8ca 100644 --- a/js/bootstrap-popover.js +++ b/js/bootstrap-popover.js @@ -59,9 +59,10 @@ $.fn.popover = function (options) { if (typeof options == 'object') options = $.extend({}, $.fn.popover.defaults, options) - $.fn.twipsy.initWith.call(this, options, Popover) + $.fn.twipsy.initWith.call(this, options, Popover, 'popover') + return this } - $.fn.popover.defaults = $.extend({}, $.fn.twipsy.defaults, { content: '', placement: 'right'}) + $.fn.popover.defaults = $.extend({} , $.fn.twipsy.defaults, { content: 'content', placement: 'right'}) })( jQuery || ender )
\ No newline at end of file diff --git a/js/bootstrap-twipsy.js b/js/bootstrap-twipsy.js index 3d117a445..ac2f56241 100644 --- a/js/bootstrap-twipsy.js +++ b/js/bootstrap-twipsy.js @@ -187,34 +187,34 @@ * ======================== */ $.fn.twipsy = function (options) { - $.fn.twipsy.initWith.call(this, options, Twipsy) + $.fn.twipsy.initWith.call(this, options, Twipsy, 'twipsy') + return this } - $.fn.twipsy.initWith = function (options, Constructor) { - + $.fn.twipsy.initWith = function (options, Constructor, name) { var twipsy , binder , eventIn , eventOut if (options === true) { - return this.data('twipsy') + return this.data(name) } else if (typeof options == 'string') { - twipsy = this.data('twipsy') + twipsy = this.data(name) if (twipsy) { twipsy[options]() } return this } - options = $.extend({}, $.fn.twipsy.defaults, options) + options = $.extend({}, $.fn[name].defaults, options) function get(ele) { - var twipsy = $.data(ele, 'twipsy') + var twipsy = $.data(ele, name) if (!twipsy) { twipsy = new Constructor(ele, $.fn.twipsy.elementOptions(ele, options)) - $.data(ele, 'twipsy', twipsy) + $.data(ele, name, twipsy) } return twipsy @@ -263,6 +263,9 @@ this[binder](eventIn, enter)[binder](eventOut, leave) } + this.bind(name + ':show', enter) + this.bind(name + ':hide', leave) + return this } diff --git a/js/tests/unit/bootstrap-modal.js b/js/tests/unit/bootstrap-modal.js index 24510664c..cfdf4064d 100644 --- a/js/tests/unit/bootstrap-modal.js +++ b/js/tests/unit/bootstrap-modal.js @@ -3,30 +3,54 @@ $(function () { module("bootstrap-modal") test("should be defined on jquery object", function () { - ok($(document.body).modal, 'modal method is defined') + var div = $("<div id='modal-test'></div>") + ok(div.modal, 'modal method is defined') }) - test("should not return element", function () { - ok(!$(document.body).modal()[0], 'document.body not returned') + test("should return element", function () { + var div = $("<div id='modal-test'></div>") + ok(div.modal() == div, 'document.body returned') }) - test("should return instance of modal class", function () { - ok($(document.body).modal() instanceof $.fn.modal.Modal, 'document.body returned') + test("should expose defaults var for settings", function () { + ok($.fn.modal.defaults, 'default object exposed') }) - test("should expose defaults var for settings", { - ok(!!$.fn.modal.default, 'default object exposed') + test("should insert into dom when modal:show event is called", function () { + $.support.transition = false + var div = $("<div id='modal-test'></div>") + div.modal().trigger("modal:show") + ok($('#modal-test').length, 'modal insterted into dom') + div.remove() }) - test("should insert into dom when open is called", function () { - var div = $("<div></div>") - div.modal().open() + test("should remove from dom when close is called", function () { + $.support.transition = false + var div = $("<div id='modal-test'></div>") + div.modal().trigger("modal:show") + ok($('#modal-test').length, 'modal insterted into dom') + div.trigger("modal:hide") + ok(!$('#modal-test').length, 'modal removed from dom') + div.remove() }) - test("should remove from dom when close is called", function () { + test("should toggle when toggle is called", function () { $.support.transition = false - re + var div = $("<div id='modal-test'></div>") + div.modal().trigger("modal:toggle") + ok($('#modal-test').length, 'modal insterted into dom') + div.trigger("modal:toggle") + ok(!$('#modal-test').length, 'modal removed from dom') + div.remove() }) - test("should remove from dom when click .close") + test("should remove from dom when click .close", function () { + $.support.transition = false + var div = $("<div id='modal-test'><span class='close'></span></div>") + div.modal().trigger("modal:toggle") + ok($('#modal-test').length, 'modal insterted into dom') + div.find('.close').click() + ok(!$('#modal-test').length, 'modal removed from dom') + div.remove() + }) })
\ No newline at end of file diff --git a/js/tests/unit/bootstrap-popover.js b/js/tests/unit/bootstrap-popover.js index e69de29bb..42ecd70ae 100644 --- a/js/tests/unit/bootstrap-popover.js +++ b/js/tests/unit/bootstrap-popover.js @@ -0,0 +1,71 @@ +$(function () { + + module("bootstrap-popover") + + test("should be defined on jquery object", function () { + var div = $('<div></div>') + ok(div.popover, 'popover method is defined') + }) + + test("should return element", function () { + var div = $('<div></div>') + ok(div.popover() == div, 'document.body returned') + }) + + test("should render popover element", function () { + $.support.transition = false + var popover = $('<a href="#" data-title="mdo" data-content="http://twitter.com/mdo">@mdo</a>') + .appendTo('#qunit-runoff') + .popover() + .trigger('popover:show') + + ok($('.popover').length, 'popover was inserted') + popover.trigger('popover:hide') + ok(!$(".popover").length, 'popover removed') + $('#qunit-runoff').empty() + }) + + test("should store popover instance in popover data object", function () { + $.support.transition = false + var popover = $('<a href="#" data-title="mdo" data-content="http://twitter.com/mdo">@mdo</a>') + .popover() + + ok(!!popover.data('popover'), 'popover instance exists') + }) + + test("should get title and content from options", function () { + $.support.transition = false + var popover = $('<a href="#">@fat</a>') + .appendTo('#qunit-runoff') + .popover({ + title: '@fat' + , content: 'loves writing tests (╯°□°)╯︵ ┻━┻' + }) + .trigger('popover:show') + + ok($('.popover').length, 'popover was inserted') + equals($('.popover .title').text(), '@fat', 'title correctly inserted') + equals($('.popover .content').text(), 'loves writing tests (╯°□°)╯︵ ┻━┻', 'content correctly inserted') + + popover.trigger('popover:hide') + ok(!$('.popover').length, 'popover was removed') + $('#qunit-runoff').empty() + }) + + test("should get title and content from attributes", function () { + $.support.transition = false + var popover = $('<a href="#" data-title="@mdo" data-content="loves data attributes (づ。◕‿‿◕。)づ ︵ ┻━┻" >@mdo</a>') + .appendTo('#qunit-runoff') + .popover() + .trigger('popover:show') + + ok($('.popover').length, 'popover was inserted') + equals($('.popover .title').text(), '@mdo', 'title correctly inserted') + equals($('.popover .content').text(), "loves data attributes (づ。◕‿‿◕。)づ ︵ ┻━┻", 'content correctly inserted') + + popover.trigger('popover:hide') + ok(!$('.popover').length, 'popover was removed') + $('#qunit-runoff').empty() + }) + +})
\ No newline at end of file diff --git a/js/tests/unit/bootstrap-tabs.js b/js/tests/unit/bootstrap-tabs.js index e69de29bb..2ee6761ed 100644 --- a/js/tests/unit/bootstrap-tabs.js +++ b/js/tests/unit/bootstrap-tabs.js @@ -0,0 +1,49 @@ +$(function () { + + module("bootstrap-tabs") + + test("should be defined on jquery object", function () { + ok($(document.body).tabs, 'tabs method is defined') + }) + + test("should return element", function () { + ok($(document.body).tabs()[0] == document.body, 'document.body returned') + }) + + test("should activate element by tab id", function () { + var tabsHTML = '<ul class="tabs">' + + '<li class="active"><a href="#home">Home</a></li>' + + '<li><a href="#profile">Profile</a></li>' + + '</ul>' + + + $('<ul><li id="home"></li><li id="profile"></li></ul>').appendTo("#qunit-runoff") + + $(tabsHTML).tabs().find('a').last().click() + equals($("#qunit-runoff").find('.active').attr('id'), "profile") + + $(tabsHTML).tabs().find('a').first().click() + equals($("#qunit-runoff").find('.active').attr('id'), "home") + + $("#qunit-runoff").empty() + }) + + test("should activate element by pill id", function () { + var pillsHTML = '<ul class="pills">' + + '<li class="active"><a href="#home">Home</a></li>' + + '<li><a href="#profile">Profile</a></li>' + + '</ul>' + + + $('<ul><li id="home"></li><li id="profile"></li></ul>').appendTo("#qunit-runoff") + + $(pillsHTML).pills().find('a').last().click() + equals($("#qunit-runoff").find('.active').attr('id'), "profile") + + $(pillsHTML).pills().find('a').first().click() + equals($("#qunit-runoff").find('.active').attr('id'), "home") + + $("#qunit-runoff").empty() + }) + +})
\ No newline at end of file diff --git a/js/tests/unit/bootstrap-twipsy.js b/js/tests/unit/bootstrap-twipsy.js index e69de29bb..05de7e938 100644 --- a/js/tests/unit/bootstrap-twipsy.js +++ b/js/tests/unit/bootstrap-twipsy.js @@ -0,0 +1,81 @@ +$(function () { + + module("bootstrap-twipsy") + + test("should be defined on jquery object", function () { + var div = $("<div></div>") + ok(div.twipsy, 'popover method is defined') + }) + + test("should return element", function () { + var div = $("<div></div>") + ok(div.twipsy() == div, 'document.body returned') + }) + + test("should expose default settings", function () { + ok(!!$.fn.twipsy.defaults, 'defaults is defined') + }) + + test("should remove title attribute", function () { + var twipsy = $('<a href="#" rel="twipsy" title="Another twipsy"></a>').twipsy() + ok(!twipsy.attr('title'), 'title tag was removed') + }) + + test("should add data attribute for referencing original title", function () { + var twipsy = $('<a href="#" rel="twipsy" title="Another twipsy"></a>').twipsy() + equals(twipsy.attr('data-original-title'), 'Another twipsy', 'original title preserved in data attribute') + }) + + test("should place tooltips relative to placement option", function () { + $.support.transition = false + var twipsy = $('<a href="#" rel="twipsy" title="Another twipsy"></a>') + .appendTo('#qunit-runoff') + .twipsy({placement: 'below'}) + .trigger('twipsy:show') + + ok($(".twipsy").hasClass('fade below in'), 'has correct classes applied') + twipsy.trigger('twipsy:hide') + ok(!$(".twipsy").length, 'twipsy removed') + $('#qunit-runoff').empty() + }) + + test("should add a fallback in cases where elements have no title tag", function () { + $.support.transition = false + var twipsy = $('<a href="#" rel="twipsy"></a>') + .appendTo('#qunit-runoff') + .twipsy({fallback: '@fat'}) + .trigger('twipsy:show') + + equals($(".twipsy").text(), "@fat", 'has correct default text') + twipsy.trigger('twipsy:hide') + ok(!$(".twipsy").length, 'twipsy removed') + $('#qunit-runoff').empty() + }) + + test("should not allow html entities", function () { + $.support.transition = false + var twipsy = $('<a href="#" rel="twipsy" title="<b>@fat</b>"></a>') + .appendTo('#qunit-runoff') + .twipsy() + .trigger('twipsy:show') + + ok(!$('.twipsy b').length, 'b tag was not inserted') + twipsy.trigger('twipsy:hide') + ok(!$(".twipsy").length, 'twipsy removed') + $('#qunit-runoff').empty() + }) + + test("should allow html entities if html option set to true", function () { + $.support.transition = false + var twipsy = $('<a href="#" rel="twipsy" title="<b>@fat</b>"></a>') + .appendTo('#qunit-runoff') + .twipsy({html: true}) + .trigger('twipsy:show') + + ok($('.twipsy b').length, 'b tag was inserted') + twipsy.trigger('twipsy:hide') + ok(!$(".twipsy").length, 'twipsy removed') + $('#qunit-runoff').empty() + }) + +})
\ No newline at end of file |
