$.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
* ======================== */
$.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
this[binder](eventIn, enter)[binder](eventOut, leave)
}
- this.bind('twipsy:show', enter)
- this.bind('twipsy:hide', leave)
+ this.bind(name + ':show', enter)
+ this.bind(name + ':hide', leave)
return this
}
-// $(function () {
-//
-// module("bootstrap-popover")
-//
-// test("should be defined on jquery object", function () {
-// ok($(document.body).popover, 'popover method is defined')
-// })
-//
-// test("should return element", function () {
-// ok($(document.body).popover()[0] == document.body, 'document.body returned')
-// })
-//
-// })
\ No newline at end of file
+$(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