aboutsummaryrefslogtreecommitdiff
path: root/examples/assets
diff options
context:
space:
mode:
authorJacob Thornton <[email protected]>2011-08-27 17:22:49 -0700
committerJacob Thornton <[email protected]>2011-08-27 17:22:49 -0700
commit2ee7c206924ac616eeb9ae3d6eb6811a818af015 (patch)
tree209b6d4958c2ae822a2945241f4d6a33a649b243 /examples/assets
parent038a9809c4301344e5cc3f8f6a32c796b9b1a438 (diff)
downloadbootstrap-2ee7c206924ac616eeb9ae3d6eb6811a818af015.tar.xz
bootstrap-2ee7c206924ac616eeb9ae3d6eb6811a818af015.zip
adds popover js
Diffstat (limited to 'examples/assets')
-rw-r--r--examples/assets/js/bootstrap-popover.js67
-rw-r--r--examples/assets/js/bootstrap-twipsy.js28
2 files changed, 86 insertions, 9 deletions
diff --git a/examples/assets/js/bootstrap-popover.js b/examples/assets/js/bootstrap-popover.js
new file mode 100644
index 000000000..ca1b8d8f2
--- /dev/null
+++ b/examples/assets/js/bootstrap-popover.js
@@ -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 ) \ No newline at end of file
diff --git a/examples/assets/js/bootstrap-twipsy.js b/examples/assets/js/bootstrap-twipsy.js
index cff27115e..4047f910d 100644
--- a/examples/assets/js/bootstrap-twipsy.js
+++ b/examples/assets/js/bootstrap-twipsy.js
@@ -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