1
0
mirror of https://github.com/twbs/bootstrap.git synced 2025-01-18 05:58:25 +01:00

giant refactor - all spec passing again...

This commit is contained in:
Jacob Thornton 2011-12-20 18:02:47 -08:00
parent 7df0d1c7d1
commit 1ef5fa7d6b
27 changed files with 9618 additions and 390 deletions

View File

@ -25,7 +25,8 @@
<!-- Le javascript -->
<!-- placed up here so that the inline demos can be next to their markup -->
<script src="http://code.jquery.com/jquery-1.7.min.js"></script>
<!-- <script src="http://code.jquery.com/jquery-1.7.min.js"></script> -->
<script src="../js/tests/vendor/jquery.js"></script>
<script type="text/javascript">
// NOT FINAL BY ANY MEANS, JUST MAH JANK CODE BRO
@ -52,15 +53,13 @@
<script>
$(function () {
// twipsy demo
$("a[rel=twipsy]").twipsy({
live: true
$('.twipsy-demo.well').twipsy({
selector: "a[rel=twipsy]"
})
//popover demo
$("a[rel=popover]")
.popover({
offset: 10
})
.popover()
.click(function(e) {
e.preventDefault()
})
@ -94,7 +93,7 @@
================================================== -->
<header class="jumbotron subhead" id="overview">
<h1>Javascript for Bootstrap</h1>
<p class="lead">Bring Bootstrap's components to life with flexible, custom javascript plugins for many of our custom components that work with <a href="http://jquery.com/" target="_blank">jQuery</a> and <a href="http://ender.no.de" target="_blank">Ender</a>.</p>
<p class="lead">Bring Bootstrap's components to life with 12 custom, flexible <a href="http://jquery.com/" target="_blank">jQuery</a> plugins.
</header>
@ -112,7 +111,7 @@
</div>
<div class="span9">
<h3>What's included</h3>
<p>Bring some of Bootstrap's primary components to life with new custom plugins that work with <a href="http://jquery.com/" target="_blank">jQuery</a> and <a href="http://ender.no.de" target="_blank">Ender</a>. We encourage you to extend and modify them to fit your specific development needs.</p>
<p>Bring some of Bootstrap's primary components to life with custom <a href="http://jquery.com/" target="_blank">jQuery</a> plugins. We encourage you to extend and modify them to fit your specific development needs.</p>
<table class="striped-table">
<thead>
<tr>
@ -138,7 +137,7 @@
<td>The ScrollSpy plugin is for adding an auto updating nav based on scroll position to the bootstrap navbar.</td>
</tr>
<tr>
<td><a href="./javascript.html#tabs">bootstrap-tab.js</a></td>
<td><a href="./javascript.html#tab">bootstrap-tab.js</a></td>
<td>This plugin adds quick, dynamic tab and pill functionality for cycling through local content.</td>
</tr>
<tr>
@ -444,9 +443,9 @@ $('#myModal').bind('hidden', function () {
<!-- Tabs
================================================== -->
<section id="tabs">
<section id="tab">
<div class="page-header">
<h1>Tabs <small>bootstrap-tab.js</small></h1>
<h1>Tab <small>bootstrap-tab.js</small></h1>
</div>
<div class="row">
<div class="span3 columns">
@ -467,7 +466,7 @@ $('#myModal').bind('hidden', function () {
<h3>Methods</h3>
<h4>$().tab</h4>
<p>
Activates tab functionality for a given element controller. Tab should have either a `data-target` or an `href` referencing a node in the dom.
Activates a tab element and content container. Tab should have either a `data-target` or an `href` targeting a container node in the dom.
</p>
<pre class="prettyprint linenums">
&lt;ul class="tabs"&gt;
@ -504,7 +503,7 @@ $('#myModal').bind('hidden', function () {
<td>This event fires on tab show, but before the new tab has been shown. Use <code>event.target</code> and <code>event.relatedTarget</code> to target the active tab and the previous active tab (if available) respectively.</td>
</tr>
<tr>
<td>show</td>
<td>shown</td>
<td>This event fires on tab show after a tab has been shown. Use <code>event.target</code> and <code>event.relatedTarget</code> to target the active tab and the previous active tab (if available) respectively.</td>
</tr>
</tbody>
@ -634,8 +633,8 @@ $('a[data-toggle="tab"]').bind('shown', function (e) {
<p>Hides an elements twipsy.</p>
<pre class="prettyprint linenums">$('#element').twipsy('hide')</pre>
<h3>Demo</h3>
<div class="well">
<p class="muted">Tight pants next level keffiyeh <a href="#" rel='twipsy' title='Some title text'>you probably</a> haven't heard of them. Photo booth beard raw denim letterpress vegan messenger bag stumptown. Farm-to-table seitan, mcsweeney's fixie sustainable quinoa 8-bit american apparel <a href="#" rel='twipsy' title='Another twipsy'>have a</a> terry richardson vinyl chambray. Beard stumptown, cardigans banh mi lomo thundercats. Tofu biodiesel williamsburg marfa, four loko mcsweeney's cleanse vegan chambray. A <a href="#" rel='twipsy' title='Another one here too'>really ironic</a> artisan whatever keytar, scenester farm-to-table banksy Austin <a href="#" rel='twipsy' title='The last tip!'>twitter handle</a> freegan cred raw denim single-origin coffee viral.
<div class="twipsy-demo well">
<p class="muted">Tight pants next level keffiyeh <a href="#" rel='twipsy' title="first twipsy">you probably</a> haven't heard of them. Photo booth beard raw denim letterpress vegan messenger bag stumptown. Farm-to-table seitan, mcsweeney's fixie sustainable quinoa 8-bit american apparel <a href="#" rel='twipsy' title='Another twipsy'>have a</a> terry richardson vinyl chambray. Beard stumptown, cardigans banh mi lomo thundercats. Tofu biodiesel williamsburg marfa, four loko mcsweeney's cleanse vegan chambray. A <a href="#" rel='twipsy' title='Another one here too'>really ironic</a> artisan whatever keytar, scenester farm-to-table banksy Austin <a href="#" rel='twipsy' title='The last tip!'>twitter handle</a> freegan cred raw denim single-origin coffee viral.
</p>
</div>
</div>

View File

@ -21,7 +21,7 @@ To target a specific plugin, just include the plugins name as a namespace along
We also believe you should be able to use all plugins provided by Bootstrap purely through the JS API.
All public APIs should be a single, chainable method, and return the collection acted upon.
All public APIs should be single, chainable methods, and return the collection acted upon.
$(".btn.danger").button("toggle").addClass("fat")
@ -73,7 +73,7 @@ examples:
// control other targets
data-toggle="modal" data-target="#foo"
data-toggle="collapse" data-target="#foo" data-parent="#foo"
data-toggle="collapse" data-target="#foo" data-parent="#bar"
// defined on element they control
data-spy="scroll"

View File

@ -27,7 +27,7 @@
var dismiss = '[data-dismiss="alert"]'
, Alert = function ( el ) {
$(el).delegate(dismiss, 'click', this.close)
$(el).on('click', dismiss, this.close)
}
Alert.prototype = {
@ -72,7 +72,7 @@
* ============== */
$(function () {
$('body').delegate(dismiss, 'click.alert.data-api', Alert.prototype.close)
$('body').on('click.alert.data-api', dismiss, Alert.prototype.close)
})
}( window.jQuery || window.ender )
}( window.jQuery )

View File

@ -24,16 +24,16 @@
/* BUTTON PUBLIC CLASS DEFINITION
* ============================== */
var Button = function (element, options) {
var Button = function ( element, options ) {
this.$element = $(element)
this.settings = $.extend({}, $.fn.button.defaults, options)
this.options = $.extend({}, $.fn.button.defaults, options)
}
Button.prototype = {
constructor: Button
, setState: function (state) {
, setState: function ( state ) {
var d = 'disabled'
, $el = this.$element
, data = $el.data()
@ -42,7 +42,7 @@
state = state + 'Text'
data.resetText || $el.data('resetText', $el[val]())
$el[val](data[state] || this.settings[state])
$el[val](data[state] || this.options[state])
// push to event loop to allow forms to submit
setTimeout(function () {
@ -90,9 +90,9 @@
* =============== */
$(function () {
$('body').delegate('[data-toggle^=button]', 'click.button.data-api', function (e) {
$('body').on('click.button.data-api', '[data-toggle^=button]', function ( e ) {
$(e.srcElement).button('toggle')
})
})
}( window.jQuery || window.ender )
}( window.jQuery )

View File

@ -25,8 +25,8 @@
/* CAROUSEL CLASS DEFINITION
* ========================= */
var Carousel = function ( el ) {
$(el).delegate(dismiss, 'click', this.close)
var Carousel = function () {
}
Carousel.prototype = {
@ -40,20 +40,12 @@
$.fn.carousel = function ( option ) {
return this.each(function () {
var $this = $(this)
, data = $this.data('alert')
if (!data) $this.data('alert', (data = new Alert(this)))
, data = $this.data('carousel')
if (!data) $this.data('carousel', (data = new Carousel(this)))
if (typeof option == 'string') data[option].call($this)
})
}
$.fn.carousel.Carousel = Carousel
/* CAROUSEL DATA-API
* ================= */
// $(function () {
// $('body').delegate(dismiss, 'click.alert.data-api', Alert.prototype.close)
// })
}( window.jQuery || window.ender )
}( window.jQuery )

View File

@ -23,13 +23,13 @@
var Collapse = function ( element, options ) {
this.$element = $(element)
this.settings = $.extend({}, $.fn.collapse.defaults, options)
this.options = $.extend({}, $.fn.collapse.defaults, options)
if (this.settings["parent"]) {
this.$parent = $(this.settings["parent"])
if (this.options["parent"]) {
this.$parent = $(this.options["parent"])
}
this.settings.toggle && this.toggle()
this.options.toggle && this.toggle()
}
Collapse.prototype = {
@ -123,13 +123,13 @@
* ==================== */
$(function () {
$('body').delegate('[data-toggle=collapse]', 'click.collapse.data-api', function ( e ) {
$('body').on('click.collapse.data-api', '[data-toggle=collapse]', function ( e ) {
var $this = $(this)
, target = $this.attr('data-target') || $this.attr('href')
, option = $(target).data('collapse') ? 'toggle' : $this.data()
e.preventDefault()
e.preventDefault()
$(target).collapse(option)
})
})
})( window.jQuery || window.ender )
})( window.jQuery )

View File

@ -68,8 +68,8 @@
* =================================== */
$(function () {
$('html').bind('click.dropdown.data-api', clearMenus)
$('body').delegate(toggle, 'click.dropdown.data-api', Dropdown.prototype.toggle)
$('html').on('click.dropdown.data-api', clearMenus)
$('body').on('click.dropdown.data-api', toggle, Dropdown.prototype.toggle)
})
}( window.jQuery || window.ender )
}( window.jQuery )

20
js/bootstrap-modal.js vendored
View File

@ -26,10 +26,9 @@
* ====================== */
var Modal = function ( content, options ) {
this.settings = $.extend({}, $.fn.modal.defaults, options)
this.options = $.extend({}, $.fn.modal.defaults, options)
this.$element = $(content)
.delegate('[data-dismiss="modal"]', 'click.dismiss.modal', $.proxy(this.hide, this))
this.settings.show && this.show()
}
Modal.prototype = {
@ -107,7 +106,7 @@
})
}
function hideModal (that) {
function hideModal( that ) {
this.$element
.hide()
.trigger('hidden')
@ -115,17 +114,17 @@
backdrop.call(this)
}
function backdrop ( callback ) {
function backdrop( callback ) {
var that = this
, animate = this.$element.hasClass('fade') ? 'fade' : ''
if (this.isShown && this.settings.backdrop) {
if (this.isShown && this.options.backdrop) {
var doAnimate = $.support.transition && animate
this.$backdrop = $('<div class="modal-backdrop ' + animate + '" />')
.appendTo(document.body)
if (this.settings.backdrop != 'static') {
if (this.options.backdrop != 'static') {
this.$backdrop.click($.proxy(this.hide, this))
}
@ -156,7 +155,7 @@
function escape() {
var that = this
if (this.isShown && this.settings.keyboard) {
if (this.isShown && this.options.keyboard) {
$(document).bind('keyup.dismiss.modal', function ( e ) {
e.which == 27 && that.hide()
})
@ -176,6 +175,7 @@
, options = typeof option == 'object' && option
if (!data) $this.data('modal', (data = new Modal(this, options)))
if (typeof option == 'string') data[option]()
else if (data.options.show) data.show()
})
}
@ -191,8 +191,8 @@
/* MODAL DATA-API
* ============== */
$(document).ready(function () {
$('body').delegate('[data-toggle="modal"]', 'click.modal.data-api', function ( e ) {
$(function () {
$('body').on('click.modal.data-api', '[data-toggle="modal"]', function ( e ) {
var $this = $(this)
, target = $this.attr('data-target') || $this.attr('href')
, option = $(target).data('modal') ? 'toggle' : $this.data()
@ -201,4 +201,4 @@
})
})
}( window.jQuery || window.ender )
}( window.jQuery )

View File

@ -23,10 +23,7 @@
"use strict"
var Popover = function ( element, options ) {
this.$element = $(element)
this.options = options
this.enabled = true
this.fixTitle()
this.init('popover', element, options)
}
/* NOTE: POPOVER EXTENDS BOOTSTRAP-TWIPSY.js
@ -53,14 +50,13 @@
, getContent: function () {
var content
, $e = this.$element
, o = this.options
, $e = this.$element
, o = this.options
if (typeof this.options.content == 'string') {
content = $e.attr(this.options.content)
} else if (typeof this.options.content == 'function') {
content = this.options.content.call(this.$element[0])
}
content = $e.attr('data-content')
|| (typeof o.content == 'function' ? o.content.call($e[0]) : o.content)
content = content.toString().replace(/(^\s*|\s*$)/, "")
return content
}
@ -79,18 +75,22 @@
/* POPOVER PLUGIN DEFINITION
* ======================= */
$.fn.popover = function (options) {
if (typeof options == 'object') options = $.extend({}, $.fn.popover.defaults, options)
$.fn.twipsy.initWith.call(this, options, Popover, 'popover')
return this
$.fn.popover = function ( option ) {
return this.each(function () {
var $this = $(this)
, data = $this.data('popover')
, options = typeof option == 'object' && option
if (!data) $this.data('popover', (data = new Popover(this, options)))
if (typeof option == 'string') data[option]()
})
}
$.fn.popover.Popover = Popover
$.fn.popover.defaults = $.extend({} , $.fn.twipsy.defaults, {
placement: 'right'
, content: 'data-content'
, content: ''
, template: '<div class="arrow"></div><div class="inner"><h3 class="title"></h3><div class="content"><p></p></div></div>'
})
$.fn.twipsy.rejectAttrOptions.push( 'content' )
}( window.jQuery || window.ender )
}( window.jQuery )

View File

@ -31,7 +31,7 @@
this.selector = (this.$scrollElement.attr('data-target')
|| this.$scrollElement.attr('href')
|| '') + ' .nav li > a'
this.$body = $('body').delegate(this.selector, 'click.scroll.data-api', process)
this.$body = $('body').on('click.scroll.data-api', this.selector, process)
this.refresh()
this.process()
@ -111,4 +111,4 @@
$(function () { $('[data-spy="scroll"]').scrollspy() })
}( window.jQuery || window.ender )
}( window.jQuery )

8
js/bootstrap-tab.js vendored
View File

@ -79,7 +79,7 @@
/* TAB PLUGIN DEFINITION
* ===================== */
$.fn.tab = function (option) {
$.fn.tab = function ( option ) {
return this.each(function () {
var $this = $(this)
, data = $this.data('tab')
@ -94,11 +94,11 @@
/* TAB DATA-API
* ============ */
$(document).ready(function () {
$('body').delegate('[data-toggle="tab"], [data-toggle="pill"]', 'click.tab.data-api', function (e) {
$(function () {
$('body').on('click.tab.data-api', '[data-toggle="tab"], [data-toggle="pill"]', function (e) {
e.preventDefault()
$(this).tab('show')
})
})
}( window.jQuery || window.ender )
}( window.jQuery )

View File

@ -1,45 +0,0 @@
/* ===================================================
* bootstrap-transitions.js v2.0.0
* http://twitter.github.com/bootstrap/javascript.html
* ===================================================
* Copyright 2011 Twitter, Inc.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
* ========================================================== */
$(function () {
/* CSS TRANSITION SUPPORT (https://gist.github.com/373874)
* ======================================================= */
$.support.transition = (function () {
var thisBody = document.body || document.documentElement
, thisStyle = thisBody.style
, support = thisStyle.transition !== undefined || thisStyle.WebkitTransition !== undefined || thisStyle.MozTransition !== undefined || thisStyle.MsTransition !== undefined || thisStyle.OTransition !== undefined
return support && {
end: (function () {
var transitionEnd = "TransitionEnd"
if ( $.browser.webkit ) {
transitionEnd = "webkitTransitionEnd"
} else if ( $.browser.mozilla ) {
transitionEnd = "transitionend"
} else if ( $.browser.opera ) {
transitionEnd = "oTransitionEnd"
}
return transitionEnd
}())
}
})()
})

226
js/bootstrap-twipsy.js vendored
View File

@ -1,7 +1,7 @@
/* ==========================================================
* bootstrap-twipsy.js v2.0.0
* http://twitter.github.com/bootstrap/javascript.html#twipsy
* Adapted from the original jQuery.tipsy by Jason Frame
* Inspired by the original jQuery.tipsy by Jason Frame
* ==========================================================
* Copyright 2011 Twitter, Inc.
*
@ -26,22 +26,83 @@
* ============================== */
var Twipsy = function ( element, options ) {
this.$element = $(element)
this.options = options
this.enabled = true
this.fixTitle()
this.init('twipsy', element, options)
}
Twipsy.prototype = {
constructor: Twipsy
, show: function() {
var pos
, init: function ( type, element, options ) {
var eventIn
, eventOut
this.type = type
this.$element = $(element)
this.options = this.getOptions(options)
this.enabled = true
if (this.options.trigger != 'manual') {
eventIn = this.options.trigger == 'hover' ? 'mouseenter' : 'focus'
eventOut = this.options.trigger == 'hover' ? 'mouseleave' : 'blur'
this.$element.on(eventIn, this.options.selector, $.proxy(this.enter, this))
this.$element.on(eventOut, this.options.selector, $.proxy(this.leave, this))
}
this.options.selector ?
(this._options = $.extend({}, this.options, { trigger: 'manual', selector: '' })) :
this.fixTitle()
}
, getOptions: function ( options ) {
options = $.extend({}, $.fn[this.type].defaults, options, this.$element.data())
if (options.delay && typeof options.delay == 'number') {
options.delay = {
show: options.delay
, hide: options.delay
}
}
return options
}
, enter: function ( e ) {
var self = $(e.currentTarget)[this.type](this._options).data(this.type)
if (!self.options.delay || !self.options.delay.show) {
self.show()
} else {
self.hoverState = 'in'
setTimeout(function() {
if (self.hoverState == 'in') {
self.show()
}
}, self.options.delay.show)
}
}
, leave: function ( e ) {
var self = $(e.currentTarget)[this.type](this._options).data(this.type)
if (!self.options.delay || !self.options.delay.hide) {
self.hide()
} else {
setTimeout(function() {
self.hoverState = 'out'
if (self.hoverState == 'out') {
self.hide()
}
}, self.options.delay.hide)
}
}
, show: function () {
var $tip
, pos
, actualWidth
, actualHeight
, placement
, $tip
, tp
if (this.hasContent() && this.enabled) {
@ -69,16 +130,16 @@
switch (placement) {
case 'below':
tp = {top: pos.top + pos.height + this.options.offset, left: pos.left + pos.width / 2 - actualWidth / 2}
tp = {top: pos.top + pos.height, left: pos.left + pos.width / 2 - actualWidth / 2}
break
case 'above':
tp = {top: pos.top - actualHeight - this.options.offset, left: pos.left + pos.width / 2 - actualWidth / 2}
tp = {top: pos.top - actualHeight, left: pos.left + pos.width / 2 - actualWidth / 2}
break
case 'left':
tp = {top: pos.top + pos.height / 2 - actualHeight / 2, left: pos.left - actualWidth - this.options.offset}
tp = {top: pos.top + pos.height / 2 - actualHeight / 2, left: pos.left - actualWidth}
break
case 'right':
tp = {top: pos.top + pos.height / 2 - actualHeight / 2, left: pos.left + pos.width + this.options.offset}
tp = {top: pos.top + pos.height / 2 - actualHeight / 2, left: pos.left + pos.width}
break
}
@ -95,7 +156,7 @@
$tip[0].className = 'twipsy'
}
, hide: function() {
, hide: function () {
var that = this
, $tip = this.tip()
@ -110,7 +171,7 @@
removeElement()
}
, fixTitle: function() {
, fixTitle: function () {
var $e = this.$element
if ($e.attr('title') || typeof($e.attr('data-original-title')) != 'string') {
$e.attr('data-original-title', $e.attr('title') || '').removeAttr('title')
@ -121,29 +182,24 @@
return this.getTitle()
}
, getTitle: function() {
, getTitle: function () {
var title
, $e = this.$element
, o = this.options
this.fixTitle()
title = $e.attr('data-original-title')
|| (typeof o.title == 'function' ? o.title.call($e[0]) : o.title)
if (typeof o.title == 'string') {
title = $e.attr(o.title == 'title' ? 'data-original-title' : o.title)
} else if (typeof o.title == 'function') {
title = o.title.call($e[0])
}
title = title.toString().replace(/(^\s*|\s*$)/, "")
title = ('' + title).replace(/(^\s*|\s*$)/, "")
return title
return title
}
, tip: function() {
, tip: function () {
return this.$tip = this.$tip || $('<div class="twipsy" />').html(this.options.template)
}
, validate: function() {
, validate: function () {
if (!this.$element[0].parentNode) {
this.hide()
this.$element = null
@ -151,15 +207,15 @@
}
}
, enable: function() {
, enable: function () {
this.enabled = true
}
, disable: function() {
, disable: function () {
this.enabled = false
}
, toggleEnabled: function() {
, toggleEnabled: function () {
this.enabled = !this.enabled
}
@ -177,91 +233,18 @@
return typeof thing == 'function' ? thing.apply(ctx, args) : thing
}
/* TWIPSY PLUGIN DEFINITION
* ======================== */
$.fn.twipsy = function (options) {
$.fn.twipsy.initWith.call(this, options, Twipsy, 'twipsy')
return this
}
$.fn.twipsy.initWith = function (options, Base, name) {
var twipsy
, binder
, eventIn
, eventOut
if (typeof options == 'string') {
return this.each(function (){
twipsy = $.data(this, name)
if (twipsy) twipsy[options]()
})
}
options = $.extend({}, $.fn[name].defaults, options)
if (options.delay && typeof options.delay == 'number') {
options.delay = {
show: options.delay
, hide: options.delay
}
}
function get(ele) {
var twipsy = $.data(ele, name)
if (!twipsy) {
twipsy = new Base(ele, $.fn.twipsy.elementOptions(ele, options))
$.data(ele, name, twipsy)
}
return twipsy
}
function enter() {
var twipsy = get(this)
twipsy.hoverState = 'in'
if (!options.delay || !options.delay.show) {
twipsy.show()
} else {
twipsy.fixTitle()
setTimeout(function() {
if (twipsy.hoverState == 'in') {
twipsy.show()
}
}, options.delay.show)
}
}
function leave() {
var twipsy = get(this)
twipsy.hoverState = 'out'
if (!options.delay || !options.delay.hide) {
twipsy.hide()
} else {
setTimeout(function() {
if (twipsy.hoverState == 'out') {
twipsy.hide()
}
}, options.delay.hide)
}
}
if (!options.live) {
this.each(function() {
get(this)
})
}
if (options.trigger != 'manual') {
binder = options.live ? 'live' : 'bind'
eventIn = options.trigger == 'hover' ? 'mouseenter' : 'focus'
eventOut = options.trigger == 'hover' ? 'mouseleave' : 'blur'
this[binder](eventIn, enter)[binder](eventOut, leave)
}
return this
$.fn.twipsy = function ( option ) {
return this.each(function () {
var $this = $(this)
, data = $this.data('twipsy')
, options = typeof option == 'object' && option
if (!data) $this.data('twipsy', (data = new Twipsy(this, options)))
if (typeof option == 'string') data[option]()
})
}
$.fn.twipsy.Twipsy = Twipsy
@ -269,26 +252,11 @@
$.fn.twipsy.defaults = {
animate: true
, delay: 0
, selector: false
, placement: 'above'
, live: false
, offset: 0
, trigger: 'hover'
, title: 'title'
, title: ''
, template: '<div class="twipsy-arrow"></div><div class="twipsy-inner"></div>'
}
$.fn.twipsy.rejectAttrOptions = [ 'title' ]
$.fn.twipsy.elementOptions = function(ele, options) {
var data = $(ele).data()
, rejects = $.fn.twipsy.rejectAttrOptions
, i = rejects.length
while (i--) {
delete data[rejects[i]]
}
return $.extend({}, options, data)
}
}( window.jQuery || window.ender )
}( window.jQuery )

View File

@ -4,28 +4,36 @@
<title>Bootstrap Plugin Test Suite</title>
<!-- jquery -->
<script src="http://code.jquery.com/jquery-1.5.2.min.js"></script>
<!--<script src="http://code.jquery.com/jquery-1.7.min.js"></script>-->
<script src="vendor/jquery.js"></script>
<!-- qunit -->
<link rel="stylesheet" href="vendor/qunit.css" type="text/css" media="screen" />
<script src="vendor/qunit.js"></script>
<!-- plugin sources -->
<script src="../../js/bootstrap-transitions.js"></script>
<script src="../../js/bootstrap-alerts.js"></script>
<script src="../../js/bootstrap-transition.js"></script>
<script src="../../js/bootstrap-alert.js"></script>
<script src="../../js/bootstrap-button.js"></script>
<script src="../../js/bootstrap-collapse.js"></script>
<script src="../../js/bootstrap-dropdown.js"></script>
<script src="../../js/bootstrap-modal.js"></script>
<script src="../../js/bootstrap-tabs.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-popover.js"></script>
<!-- unit tests -->
<script src="unit/bootstrap-alerts.js"></script>
<script src="unit/bootstrap-transition.js"></script>
<script src="unit/bootstrap-alert.js"></script>
<script src="unit/bootstrap-button.js"></script>
<script src="unit/bootstrap-collapse.js"></script>
<script src="unit/bootstrap-dropdown.js"></script>
<script src="unit/bootstrap-modal.js"></script>
<script src="unit/bootstrap-popover.js"></script>
<script src="unit/bootstrap-tabs.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-popover.js"></script>
<body>
<div>
@ -33,7 +41,7 @@
<h2 id="qunit-banner"></h2>
<h2 id="qunit-userAgent"></h2>
<ol id="qunit-tests"></ol>
<div id="qunit-runoff"></div>
<div id="qunit-fixture"></div>
</div>
</body>
</html>

View File

@ -12,7 +12,7 @@ $(function () {
test("should fade element out on clicking .close", function () {
var alertHTML = '<div class="alert-message warning fade in">'
+ '<a class="close" href="#">×</a>'
+ '<a class="close" href="#" data-dismiss="alert">×</a>'
+ '<p><strong>Holy guacamole!</strong> Best check yo self, youre not looking too good.</p>'
+ '</div>'
, alert = $(alertHTML).alert()
@ -26,16 +26,16 @@ $(function () {
$.support.transition = false
var alertHTML = '<div class="alert-message warning fade in">'
+ '<a class="close" href="#">×</a>'
+ '<a class="close" href="#" data-dismiss="alert">×</a>'
+ '<p><strong>Holy guacamole!</strong> Best check yo self, youre not looking too good.</p>'
+ '</div>'
, alert = $(alertHTML).appendTo('#qunit-runoff').alert()
, alert = $(alertHTML).appendTo('#qunit-fixture').alert()
ok($('#qunit-runoff').find('.alert-message').length, 'element added to dom')
ok($('#qunit-fixture').find('.alert-message').length, 'element added to dom')
alert.find('.close').click()
ok(!$('#qunit-runoff').find('.alert-message').length, 'element removed from dom')
ok(!$('#qunit-fixture').find('.alert-message').length, 'element removed from dom')
})
})

54
js/tests/unit/bootstrap-button.js vendored Normal file
View File

@ -0,0 +1,54 @@
$(function () {
module("bootstrap-buttons")
test("should be defined on jquery object", function () {
ok($(document.body).button, 'tabs method is defined')
})
test("should return element", function () {
ok($(document.body).button()[0] == document.body, 'document.body returned')
})
test("should return set state to loading", function () {
var btn = $('<button class="btn" data-loading-text="fat">mdo</button>')
equals(btn.html(), 'mdo', 'btn text equals mdo')
btn.button('loading')
equals(btn.html(), 'fat', 'btn text equals fat')
stop()
setTimeout(function () {
ok(btn.attr('disabled'), 'btn is disabled')
ok(btn.hasClass('disabled'), 'btn has disabled class')
start()
}, 0)
})
test("should return reset state", function () {
var btn = $('<button class="btn" data-loading-text="fat">mdo</button>')
equals(btn.html(), 'mdo', 'btn text equals mdo')
btn.button('loading')
equals(btn.html(), 'fat', 'btn text equals fat')
stop()
setTimeout(function () {
ok(btn.attr('disabled'), 'btn is disabled')
ok(btn.hasClass('disabled'), 'btn has disabled class')
start()
stop()
}, 0)
btn.button('reset')
equals(btn.html(), 'mdo', 'btn text equals mdo')
setTimeout(function () {
ok(!btn.attr('disabled'), 'btn is not disabled')
ok(!btn.hasClass('disabled'), 'btn does not have disabled class')
start()
}, 0)
})
test("should toggle active", function () {
var btn = $('<button class="btn" data-loading-text="fat">mdo</button>')
ok(!btn.hasClass('active'), 'btn does not have active class')
btn.button('toggle')
ok(btn.hasClass('active'), 'btn has class active')
})
})

25
js/tests/unit/bootstrap-collapse.js vendored Normal file
View File

@ -0,0 +1,25 @@
$(function () {
module("bootstrap-collapse")
test("should be defined on jquery object", function () {
ok($(document.body).collapse, 'collapse method is defined')
})
test("should return element", function () {
ok($(document.body).collapse()[0] == document.body, 'document.body returned')
})
test("should show a collapsed element", function () {
var el = $('<div class="collapse"></div>').collapse('show')
ok(el.hasClass('in'), 'has class in')
ok(/height/.test(el.attr('style')), 'has height set')
})
test("should hide a collapsed element", function () {
var el = $('<div class="collapse"></div>').collapse('hide')
ok(!el.hasClass('in'), 'does not have class in')
ok(/height/.test(el.attr('style')), 'has height set')
})
})

View File

@ -13,7 +13,7 @@ $(function () {
test("should add class open to menu if clicked", function () {
var dropdownHTML = '<ul class="tabs">'
+ '<li class="dropdown">'
+ '<a href="#" class="dropdown-toggle">Dropdown</a>'
+ '<a href="#" class="dropdown-toggle" data-toggle="dropdown">Dropdown</a>'
+ '<ul class="dropdown-menu">'
+ '<li><a href="#">Secondary link</a></li>'
+ '<li><a href="#">Something else here</a></li>'
@ -22,16 +22,15 @@ $(function () {
+ '</ul>'
+ '</li>'
+ '</ul>'
, dropdown = $(dropdownHTML).dropdown()
, dropdown = $(dropdownHTML).find('[data-toggle="dropdown"]').dropdown().click()
dropdown.find('.dropdown-toggle').click()
ok(dropdown.find('.dropdown').hasClass('open'), 'open class added on click')
ok(dropdown.parent('.dropdown').hasClass('open'), 'open class added on click')
})
test("should remove open class if body clicked", function () {
var dropdownHTML = '<ul class="tabs">'
+ '<li class="dropdown">'
+ '<a href="#" class="dropdown-toggle">Dropdown</a>'
+ '<a href="#" class="dropdown-toggle" data-toggle="dropdown">Dropdown</a>'
+ '<ul class="dropdown-menu">'
+ '<li><a href="#">Secondary link</a></li>'
+ '<li><a href="#">Something else here</a></li>'
@ -40,12 +39,14 @@ $(function () {
+ '</ul>'
+ '</li>'
+ '</ul>'
, dropdown = $(dropdownHTML).dropdown().appendTo('#qunit-runoff')
dropdown.find('.dropdown-toggle').click()
ok(dropdown.find('.dropdown').hasClass('open'), 'open class added on click')
, dropdown = $(dropdownHTML)
.appendTo('#qunit-fixture')
.find('[data-toggle="dropdown"]')
.dropdown()
.click()
ok(dropdown.parent('.dropdown').hasClass('open'), 'open class added on click')
$('body').click()
ok(!dropdown.find('.dropdown').hasClass('open'), 'open class removed')
ok(!dropdown.parent('.dropdown').hasClass('open'), 'open class removed')
dropdown.remove()
})

View File

@ -10,6 +10,7 @@ $(function () {
test("should return element", function () {
var div = $("<div id='modal-test'></div>")
ok(div.modal() == div, 'document.body returned')
$('#modal-test').remove()
})
test("should expose defaults var for settings", function () {
@ -19,32 +20,29 @@ $(function () {
test("should insert into dom when show method is called", function () {
stop()
$.support.transition = false
var div = $("<div id='modal-test'></div>")
div
.modal()
.modal("show")
$("<div id='modal-test'></div>")
.bind("shown", function () {
ok($('#modal-test').length, 'modal insterted into dom')
$(this).remove()
start()
div.remove()
})
.modal("show")
})
test("should hide modal when hide is called", function () {
stop()
$.support.transition = false
var div = $("<div id='modal-test'></div>")
div
.modal()
$("<div id='modal-test'></div>")
.bind("shown", function () {
ok($('#modal-test').is(":visible"), 'modal visible')
ok($('#modal-test').length, 'modal insterted into dom')
div.modal("hide")
$(this).modal("hide")
})
.bind("hidden", function() {
ok(!$('#modal-test').is(":visible"), 'modal hidden')
$('#modal-test').remove()
start()
div.remove()
})
.modal("show")
})
@ -54,7 +52,6 @@ $(function () {
$.support.transition = false
var div = $("<div id='modal-test'></div>")
div
.modal()
.bind("shown", function () {
ok($('#modal-test').is(":visible"), 'modal visible')
ok($('#modal-test').length, 'modal insterted into dom')
@ -62,18 +59,17 @@ $(function () {
})
.bind("hidden", function() {
ok(!$('#modal-test').is(":visible"), 'modal hidden')
start()
div.remove()
start()
})
.modal("toggle")
})
test("should remove from dom when click .close", function () {
test("should remove from dom when click [data-dismiss=modal]", function () {
stop()
$.support.transition = false
var div = $("<div id='modal-test'><span class='close'></span></div>")
var div = $("<div id='modal-test'><span class='close' data-dismiss='modal'></span></div>")
div
.modal()
.bind("shown", function () {
ok($('#modal-test').is(":visible"), 'modal visible')
ok($('#modal-test').length, 'modal insterted into dom')
@ -81,8 +77,8 @@ $(function () {
})
.bind("hidden", function() {
ok(!$('#modal-test').is(":visible"), 'modal hidden')
start()
div.remove()
start()
})
.modal("toggle")
})

View File

@ -15,14 +15,12 @@ $(function () {
test("should render popover element", function () {
$.support.transition = false
var popover = $('<a href="#" title="mdo" data-content="http://twitter.com/mdo">@mdo</a>')
.appendTo('#qunit-runoff')
.popover()
.appendTo('#qunit-fixture')
.popover('show')
ok($('.popover').length, 'popover was inserted')
popover.popover('hide')
ok(!$(".popover").length, 'popover removed')
$('#qunit-runoff').empty()
})
test("should store popover instance in popover data object", function () {
@ -36,7 +34,7 @@ $(function () {
test("should get title and content from options", function () {
$.support.transition = false
var popover = $('<a href="#">@fat</a>')
.appendTo('#qunit-runoff')
.appendTo('#qunit-fixture')
.popover({
title: function () {
return '@fat'
@ -54,13 +52,13 @@ $(function () {
popover.popover('hide')
ok(!$('.popover').length, 'popover was removed')
$('#qunit-runoff').empty()
$('#qunit-fixture').empty()
})
test("should get title and content from attributes", function () {
$.support.transition = false
var popover = $('<a href="#" title="@mdo" data-content="loves data attributes (づ。◕‿‿◕。)づ ︵ ┻━┻" >@mdo</a>')
.appendTo('#qunit-runoff')
.appendTo('#qunit-fixture')
.popover()
.popover('show')
@ -70,7 +68,7 @@ $(function () {
popover.popover('hide')
ok(!$('.popover').length, 'popover was removed')
$('#qunit-runoff').empty()
$('#qunit-fixture').empty()
})
})

View File

@ -12,7 +12,7 @@ $(function () {
test("should switch active class on scroll", function () {
var sectionHTML = '<div id="masthead"></div>'
, $section = $(sectionHTML).append('#qunit-runoff')
, $section = $(sectionHTML).append('#qunit-fixture')
, topbarHTML ='<div class="topbar">'
+ '<div class="topbar-inner">'
+ '<div class="container">'
@ -23,9 +23,9 @@ $(function () {
+ '</div>'
+ '</div>'
+ '</div>'
, $topbar = $(topbarHTML).topbar()
, $topbar = $(topbarHTML).scrollspy()
ok(topbar.find('.active', true)
ok($topbar.find('.active', true))
})
})

46
js/tests/unit/bootstrap-tab.js vendored Normal file
View File

@ -0,0 +1,46 @@
$(function () {
module("bootstrap-tabs")
test("should be defined on jquery object", function () {
ok($(document.body).tab, 'tabs method is defined')
})
test("should return element", function () {
ok($(document.body).tab()[0] == document.body, 'document.body returned')
})
test("should activate element by tab id", function () {
var tabsHTML =
'<ul class="tabs">'
+ '<li><a href="#home">Home</a></li>'
+ '<li><a href="#profile">Profile</a></li>'
+ '</ul>'
$('<ul><li id="home"></li><li id="profile"></li></ul>').appendTo("#qunit-fixture")
$(tabsHTML).find('li:last a').tab('show')
equals($("#qunit-fixture").find('.active').attr('id'), "profile")
$(tabsHTML).find('li:first a').tab('show')
equals($("#qunit-fixture").find('.active').attr('id'), "home")
})
test("should activate element by tab id", function () {
var pillsHTML =
'<ul class="pills">'
+ '<li><a href="#home">Home</a></li>'
+ '<li><a href="#profile">Profile</a></li>'
+ '</ul>'
$('<ul><li id="home"></li><li id="profile"></li></ul>').appendTo("#qunit-fixture")
$(pillsHTML).find('li:last a').tab('show')
equals($("#qunit-fixture").find('.active').attr('id'), "profile")
$(pillsHTML).find('li:first a').tab('show')
equals($("#qunit-fixture").find('.active').attr('id'), "home")
})
})

View File

@ -1,49 +0,0 @@
$(function () {
module("bootstrap-tabs")
test("should be defined on jquery object", function () {
ok($(document.body).tabs, 'tabs method is defined')
})
test("should return element", function () {
ok($(document.body).tabs()[0] == document.body, 'document.body returned')
})
test("should activate element by tab id", function () {
var tabsHTML = '<ul class="tabs">'
+ '<li class="active"><a href="#home">Home</a></li>'
+ '<li><a href="#profile">Profile</a></li>'
+ '</ul>'
$('<ul><li id="home"></li><li id="profile"></li></ul>').appendTo("#qunit-runoff")
$(tabsHTML).tabs().find('a').last().click()
equals($("#qunit-runoff").find('.active').attr('id'), "profile")
$(tabsHTML).tabs().find('a').first().click()
equals($("#qunit-runoff").find('.active').attr('id'), "home")
$("#qunit-runoff").empty()
})
test("should activate element by pill id", function () {
var pillsHTML = '<ul class="pills">'
+ '<li class="active"><a href="#home">Home</a></li>'
+ '<li><a href="#profile">Profile</a></li>'
+ '</ul>'
$('<ul><li id="home"></li><li id="profile"></li></ul>').appendTo("#qunit-runoff")
$(pillsHTML).pills().find('a').last().click()
equals($("#qunit-runoff").find('.active').attr('id'), "profile")
$(pillsHTML).pills().find('a').first().click()
equals($("#qunit-runoff").find('.active').attr('id'), "home")
$("#qunit-runoff").empty()
})
})

13
js/tests/unit/bootstrap-transition.js vendored Normal file
View File

@ -0,0 +1,13 @@
$(function () {
module("bootstrap-transition")
test("should be defined on jquery support object", function () {
ok($.support.transition != undefined, 'transition object is defined')
})
test("should provide an end object", function () {
ok($.support.transition.end, 'end string is defined')
})
})

View File

@ -29,53 +29,23 @@ $(function () {
test("should place tooltips relative to placement option", function () {
$.support.transition = false
var twipsy = $('<a href="#" rel="twipsy" title="Another twipsy"></a>')
.appendTo('#qunit-runoff')
.appendTo('#qunit-fixture')
.twipsy({placement: 'below'})
.twipsy('show')
ok($(".twipsy").hasClass('fade below in'), 'has correct classes applied')
twipsy.twipsy('hide')
ok(!$(".twipsy").length, 'twipsy removed')
$('#qunit-runoff').empty()
})
test("should add a fallback in cases where elements have no title tag", function () {
$.support.transition = false
var twipsy = $('<a href="#" rel="twipsy"></a>')
.appendTo('#qunit-runoff')
.twipsy({fallback: '@fat'})
.twipsy('show')
equals($(".twipsy").text(), "@fat", 'has correct default text')
twipsy.twipsy('hide')
ok(!$(".twipsy").length, 'twipsy removed')
$('#qunit-runoff').empty()
})
test("should not allow html entities", function () {
test("should always allow html entities", function () {
$.support.transition = false
var twipsy = $('<a href="#" rel="twipsy" title="<b>@fat</b>"></a>')
.appendTo('#qunit-runoff')
.twipsy()
.twipsy('show')
ok(!$('.twipsy b').length, 'b tag was not inserted')
twipsy.twipsy('hide')
ok(!$(".twipsy").length, 'twipsy removed')
$('#qunit-runoff').empty()
})
test("should allow html entities if html option set to true", function () {
$.support.transition = false
var twipsy = $('<a href="#" rel="twipsy" title="<b>@fat</b>"></a>')
.appendTo('#qunit-runoff')
.twipsy({html: true})
.appendTo('#qunit-fixture')
.twipsy('show')
ok($('.twipsy b').length, 'b tag was inserted')
twipsy.twipsy('hide')
ok(!$(".twipsy").length, 'twipsy removed')
$('#qunit-runoff').empty()
})
})

9252
js/tests/vendor/jquery.js vendored Normal file

File diff suppressed because it is too large Load Diff

View File

@ -227,6 +227,6 @@
/** Runoff */
#qunit-runoff {
#qunit-fixture {
display:none;
}