1
0
mirror of https://github.com/twbs/bootstrap.git synced 2025-08-18 03:11:19 +02:00

add build tool for js + rename twipsy to tooltip + lots of little doc cleanup

This commit is contained in:
Jacob Thornton
2012-01-11 21:42:55 -08:00
parent 51e4e77034
commit 6f2f947a43
17 changed files with 297 additions and 172 deletions

View File

@@ -26,10 +26,10 @@
this.init('popover', element, options)
}
/* NOTE: POPOVER EXTENDS BOOTSTRAP-TWIPSY.js
========================================= */
/* NOTE: POPOVER EXTENDS BOOTSTRAP-TOOLTIP.js
========================================== */
Popover.prototype = $.extend({}, $.fn.twipsy.Constructor.prototype, {
Popover.prototype = $.extend({}, $.fn.tooltip.Constructor.prototype, {
constructor: Popover
@@ -86,7 +86,7 @@
$.fn.popover.Constructor = Popover
$.fn.popover.defaults = $.extend({} , $.fn.twipsy.defaults, {
$.fn.popover.defaults = $.extend({} , $.fn.tooltip.defaults, {
placement: 'right'
, content: ''
, template: '<div class="popover"><div class="arrow"></div><div class="inner"><h3 class="title"></h3><div class="content"><p></p></div></div></div>'

View File

@@ -1,8 +1,8 @@
/* ==========================================================
* bootstrap-twipsy.js v2.0.0
* http://twitter.github.com/bootstrap/javascript.html#twipsy
/* ===========================================================
* bootstrap-tooltip.js v2.0.0
* http://twitter.github.com/bootstrap/javascript.html#tooltip
* Inspired by the original jQuery.tipsy by Jason Frame
* ==========================================================
* ===========================================================
* Copyright 2011 Twitter, Inc.
*
* Licensed under the Apache License, Version 2.0 (the "License");
@@ -22,16 +22,16 @@
"use strict"
/* TWIPSY PUBLIC CLASS DEFINITION
* ============================== */
/* TOOLTIP PUBLIC CLASS DEFINITION
* =============================== */
var Twipsy = function ( element, options ) {
this.init('twipsy', element, options)
var Tooltip = function ( element, options ) {
this.init('tooltip', element, options)
}
Twipsy.prototype = {
Tooltip.prototype = {
constructor: Twipsy
constructor: Tooltip
, init: function ( type, element, options ) {
var eventIn
@@ -154,7 +154,7 @@
, setContent: function () {
var $tip = this.tip()
$tip.find('.twipsy-inner').html(this.getTitle())
$tip.find('.tooltip-inner').html(this.getTitle())
$tip.removeClass('fade in top bottom left right')
}
@@ -242,29 +242,29 @@
}
/* TWIPSY PLUGIN DEFINITION
* ======================== */
/* TOOLTIP PLUGIN DEFINITION
* ========================= */
$.fn.twipsy = function ( option ) {
$.fn.tooltip = function ( option ) {
return this.each(function () {
var $this = $(this)
, data = $this.data('twipsy')
, data = $this.data('tooltip')
, options = typeof option == 'object' && option
if (!data) $this.data('twipsy', (data = new Twipsy(this, options)))
if (!data) $this.data('tooltip', (data = new Tooltip(this, options)))
if (typeof option == 'string') data[option]()
})
}
$.fn.twipsy.Constructor = Twipsy
$.fn.tooltip.Constructor = Tooltip
$.fn.twipsy.defaults = {
$.fn.tooltip.defaults = {
animation: true
, delay: 0
, selector: false
, placement: 'top'
, trigger: 'hover'
, title: ''
, template: '<div class="twipsy"><div class="twipsy-arrow"></div><div class="twipsy-inner"></div></div>'
, template: '<div class="tooltip"><div class="tooltip-arrow"></div><div class="tooltip-inner"></div></div>'
}
}( window.jQuery )

View File

@@ -156,11 +156,13 @@
break
case 38: // up arrow
if (!this.shown) return
e.preventDefault()
this.prev()
break
case 40: // down arrow
if (!this.shown) return
e.preventDefault()
this.next()
break

View File

@@ -20,7 +20,7 @@
<script src="../../js/bootstrap-modal.js"></script>
<script src="../../js/bootstrap-scrollspy.js"></script>
<script src="../../js/bootstrap-tab.js"></script>
<script src="../../js/bootstrap-twipsy.js"></script>
<script src="../../js/bootstrap-tooltip.js"></script>
<script src="../../js/bootstrap-popover.js"></script>
<script src="../../js/bootstrap-typeahead.js"></script>
@@ -33,7 +33,7 @@
<script src="unit/bootstrap-modal.js"></script>
<script src="unit/bootstrap-scrollspy.js"></script>
<script src="unit/bootstrap-tab.js"></script>
<script src="unit/bootstrap-twipsy.js"></script>
<script src="unit/bootstrap-tooltip.js"></script>
<script src="unit/bootstrap-popover.js"></script>
<script src="unit/bootstrap-typeahead.js"></script>

View File

@@ -1,62 +1,62 @@
$(function () {
module("bootstrap-twipsy")
module("bootstrap-tooltip")
test("should be defined on jquery object", function () {
var div = $("<div></div>")
ok(div.twipsy, 'popover method is defined')
ok(div.tooltip, 'popover method is defined')
})
test("should return element", function () {
var div = $("<div></div>")
ok(div.twipsy() == div, 'document.body returned')
ok(div.tooltip() == div, 'document.body returned')
})
test("should expose default settings", function () {
ok(!!$.fn.twipsy.defaults, 'defaults is defined')
ok(!!$.fn.tooltip.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')
var tooltip = $('<a href="#" rel="tooltip" title="Another tooltip"></a>').tooltip()
ok(!tooltip.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')
var tooltip = $('<a href="#" rel="tooltip" title="Another tooltip"></a>').tooltip()
equals(tooltip.attr('data-original-title'), 'Another tooltip', '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>')
var tooltip = $('<a href="#" rel="tooltip" title="Another tooltip"></a>')
.appendTo('#qunit-fixture')
.twipsy({placement: 'bottom'})
.twipsy('show')
.tooltip({placement: 'bottom'})
.tooltip('show')
ok($(".twipsy").hasClass('fade bottom in'), 'has correct classes applied')
twipsy.twipsy('hide')
ok($(".tooltip").hasClass('fade bottom in'), 'has correct classes applied')
tooltip.tooltip('hide')
})
test("should always allow html entities", function () {
$.support.transition = false
var twipsy = $('<a href="#" rel="twipsy" title="<b>@fat</b>"></a>')
var tooltip = $('<a href="#" rel="tooltip" title="<b>@fat</b>"></a>')
.appendTo('#qunit-fixture')
.twipsy('show')
.tooltip('show')
ok($('.twipsy b').length, 'b tag was inserted')
twipsy.twipsy('hide')
ok(!$(".twipsy").length, 'twipsy removed')
ok($('.tooltip b').length, 'b tag was inserted')
tooltip.tooltip('hide')
ok(!$(".tooltip").length, 'tooltip removed')
})
test("should respect custom classes", function () {
var twipsy = $('<a href="#" rel="twipsy" title="Another twipsy"></a>')
var tooltip = $('<a href="#" rel="tooltip" title="Another tooltip"></a>')
.appendTo('#qunit-fixture')
.twipsy({ template: '<div class="twipsy some-class"><div class="twipsy-arrow"/><div class="twipsy-inner"/></div>'})
.twipsy('show')
.tooltip({ template: '<div class="tooltip some-class"><div class="tooltip-arrow"/><div class="tooltip-inner"/></div>'})
.tooltip('show')
ok($('.twipsy').hasClass('some-class'), 'custom class is present')
twipsy.twipsy('hide')
ok(!$(".twipsy").length, 'twipsy removed')
ok($('.tooltip').hasClass('some-class'), 'custom class is present')
tooltip.tooltip('hide')
ok(!$(".tooltip").length, 'tooltip removed')
})
})