1
0
mirror of https://github.com/twbs/bootstrap.git synced 2025-09-27 13:59:06 +02:00

adds popover js

This commit is contained in:
Jacob Thornton
2011-08-27 17:22:49 -07:00
parent 038a9809c4
commit 2ee7c20692
6 changed files with 143 additions and 16 deletions

67
examples/assets/js/bootstrap-popover.js vendored Normal file
View File

@@ -0,0 +1,67 @@
/* EXTENDS BOOTSTRAP-TWIPSY.js
=========================== */
(function( $ ) {
/* POPOVER PUBLIC CLASS DEFINITION
* ============================== */
var Popover = function ( element, options ) {
this.$element = $(element)
this.options = options
this.enabled = true
}
Popover.prototype = $.extend({}, $.fn.twipsy.Twipsy.prototype, {
setContent: function () {
var $tip = this.tip()
$tip.find('.title')[this.options.html ? 'html' : 'text'](this.getTitle())
$tip.find('.content p')[this.options.html ? 'html' : 'text'](this.getContent())
$tip[0].className = 'popover'
}
, fixTitle: function () {}
, getTitle: function () {
var title
if (typeof this.options.title == 'string') {
title = this.options.title || this.$element.attr('data-title')
} else if (typeof this.options.title == 'function') {
title = this.options.title.call(this.$element[0])
}
return title
}
, getContent: function () {content
var content
if (typeof this.options.content == 'string') {
content = this.options.content || this.$element.attr('data-content')
} else if (typeof this.options.content == 'function') {
content = this.options.content.call(this.$element[0])
}
return content
}
, tip: function() {
if (!this.$tip) {
this.$tip = $('<div class="popover" />')
.html('<div class="arrow"></div><div class="inner"><h3 class="title"></h3><div class="content"><p></p></div></div>')
}
return this.$tip
}
})
/* POPOVER PLUGIN DEFINITION
* ======================= */
$.fn.popover = function (options) {
if (typeof options == 'object') options = $.extend({}, $.fn.popover.defaults, options)
$.fn.twipsy.initWith.call(this, options, Popover)
}
$.fn.popover.defaults = $.extend({}, $.fn.twipsy.defaults, { content: '', placement: 'right'})
})( jQuery || ender )

View File

@@ -44,18 +44,16 @@
Twipsy.prototype = {
show: function() {
var title = this.getTitle()
, pos
var pos
, actualWidth
, actualHeight
, placement
, $tip
, tp
if (title && this.enabled) {
if (this.getTitle() && this.enabled) {
$tip = this.tip()
$tip.find('.twipsy-inner')[this.options.html ? 'html' : 'text'](title)
$tip[0].className = 'twipsy'
this.setContent()
$tip
.remove()
.css({ top: 0, left: 0, display: 'block' })
@@ -92,6 +90,12 @@
}
}
, setContent: function () {
var $tip = this.tip()
$tip.find('.twipsy-inner')[this.options.html ? 'html' : 'text'](this.getTitle())
$tip[0].className = 'twipsy'
}
, hide: function() {
var that = this
, $tip = this.tip()
@@ -174,10 +178,14 @@
}
/* MODAL PLUGIN DEFINITION
* ======================= */
/* TWIPSY PLUGIN DEFINITION
* ======================== */
$.fn.twipsy = function(options) {
$.fn.twipsy = function (options) {
$.fn.twipsy.initWith.call(this, options, Twipsy)
}
$.fn.twipsy.initWith = function (options, Constructor) {
var twipsy
, binder
@@ -200,7 +208,7 @@
var twipsy = $.data(ele, 'twipsy')
if (!twipsy) {
twipsy = new Twipsy(ele, $.fn.twipsy.elementOptions(ele, options))
twipsy = new Constructor(ele, $.fn.twipsy.elementOptions(ele, options))
$.data(ele, 'twipsy', twipsy)
}
@@ -253,6 +261,8 @@
return this
}
$.fn.twipsy.Twipsy = Twipsy
$.fn.twipsy.defaults = {
delayIn: 0
, delayOut: 0