mirror of
https://github.com/twbs/bootstrap.git
synced 2025-02-20 17:54:23 +01:00
finish up rounding out tests for all js plugins
This commit is contained in:
parent
48aa209348
commit
1041977d0a
4
js/bootstrap-popover.js
vendored
4
js/bootstrap-popover.js
vendored
@ -59,10 +59,10 @@
|
|||||||
|
|
||||||
$.fn.popover = function (options) {
|
$.fn.popover = function (options) {
|
||||||
if (typeof options == 'object') options = $.extend({}, $.fn.popover.defaults, 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
|
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 )
|
})( jQuery || ender )
|
19
js/bootstrap-twipsy.js
vendored
19
js/bootstrap-twipsy.js
vendored
@ -187,35 +187,34 @@
|
|||||||
* ======================== */
|
* ======================== */
|
||||||
|
|
||||||
$.fn.twipsy = function (options) {
|
$.fn.twipsy = function (options) {
|
||||||
$.fn.twipsy.initWith.call(this, options, Twipsy)
|
$.fn.twipsy.initWith.call(this, options, Twipsy, 'twipsy')
|
||||||
return this
|
return this
|
||||||
}
|
}
|
||||||
|
|
||||||
$.fn.twipsy.initWith = function (options, Constructor) {
|
$.fn.twipsy.initWith = function (options, Constructor, name) {
|
||||||
|
|
||||||
var twipsy
|
var twipsy
|
||||||
, binder
|
, binder
|
||||||
, eventIn
|
, eventIn
|
||||||
, eventOut
|
, eventOut
|
||||||
|
|
||||||
if (options === true) {
|
if (options === true) {
|
||||||
return this.data('twipsy')
|
return this.data(name)
|
||||||
} else if (typeof options == 'string') {
|
} else if (typeof options == 'string') {
|
||||||
twipsy = this.data('twipsy')
|
twipsy = this.data(name)
|
||||||
if (twipsy) {
|
if (twipsy) {
|
||||||
twipsy[options]()
|
twipsy[options]()
|
||||||
}
|
}
|
||||||
return this
|
return this
|
||||||
}
|
}
|
||||||
|
|
||||||
options = $.extend({}, $.fn.twipsy.defaults, options)
|
options = $.extend({}, $.fn[name].defaults, options)
|
||||||
|
|
||||||
function get(ele) {
|
function get(ele) {
|
||||||
var twipsy = $.data(ele, 'twipsy')
|
var twipsy = $.data(ele, name)
|
||||||
|
|
||||||
if (!twipsy) {
|
if (!twipsy) {
|
||||||
twipsy = new Constructor(ele, $.fn.twipsy.elementOptions(ele, options))
|
twipsy = new Constructor(ele, $.fn.twipsy.elementOptions(ele, options))
|
||||||
$.data(ele, 'twipsy', twipsy)
|
$.data(ele, name, twipsy)
|
||||||
}
|
}
|
||||||
|
|
||||||
return twipsy
|
return twipsy
|
||||||
@ -264,8 +263,8 @@
|
|||||||
this[binder](eventIn, enter)[binder](eventOut, leave)
|
this[binder](eventIn, enter)[binder](eventOut, leave)
|
||||||
}
|
}
|
||||||
|
|
||||||
this.bind('twipsy:show', enter)
|
this.bind(name + ':show', enter)
|
||||||
this.bind('twipsy:hide', leave)
|
this.bind(name + ':hide', leave)
|
||||||
|
|
||||||
return this
|
return this
|
||||||
}
|
}
|
||||||
|
84
js/tests/unit/bootstrap-popover.js
vendored
84
js/tests/unit/bootstrap-popover.js
vendored
@ -1,13 +1,71 @@
|
|||||||
// $(function () {
|
$(function () {
|
||||||
//
|
|
||||||
// module("bootstrap-popover")
|
module("bootstrap-popover")
|
||||||
//
|
|
||||||
// test("should be defined on jquery object", function () {
|
test("should be defined on jquery object", function () {
|
||||||
// ok($(document.body).popover, 'popover method is defined')
|
var div = $('<div></div>')
|
||||||
// })
|
ok(div.popover, 'popover method is defined')
|
||||||
//
|
})
|
||||||
// test("should return element", function () {
|
|
||||||
// ok($(document.body).popover()[0] == document.body, 'document.body returned')
|
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()
|
||||||
|
})
|
||||||
|
|
||||||
|
})
|
Loading…
x
Reference in New Issue
Block a user