From 0b1d5d9189ea82cde5e848e5a8771a8f4850e21f Mon Sep 17 00:00:00 2001 From: Jacob Thornton Date: Sun, 20 Nov 2011 18:19:50 -0800 Subject: revert all js stuff back to 1.4 :/ --- js/bootstrap-alerts.js | 104 ++++++++++++++++++++++++++++++++----- js/bootstrap-buttons.js | 62 ++++++++++++++++++++++ js/bootstrap-dropdown.js | 37 ++++++++----- js/bootstrap-modal.js | 131 +++++++++++++++++++++++++++++++---------------- js/bootstrap-popover.js | 24 +++++++-- js/bootstrap-tabs.js | 15 ++++-- js/bootstrap-twipsy.js | 75 +++++++++++++++++++++------ 7 files changed, 353 insertions(+), 95 deletions(-) create mode 100644 js/bootstrap-buttons.js (limited to 'js') diff --git a/js/bootstrap-alerts.js b/js/bootstrap-alerts.js index 4f1acfa3d..3ef1672bc 100644 --- a/js/bootstrap-alerts.js +++ b/js/bootstrap-alerts.js @@ -1,5 +1,5 @@ /* ========================================================== - * bootstrap-alerts.js v2.0.0 + * bootstrap-alerts.js v1.4.0 * http://twitter.github.com/bootstrap/javascript.html#alerts * ========================================================== * Copyright 2011 Twitter, Inc. @@ -17,32 +17,108 @@ * limitations under the License. * ========================================================== */ -(function( $ ){ + +!function( $ ){ + + "use strict" + + /* CSS TRANSITION SUPPORT (https://gist.github.com/373874) + * ======================================================= */ + + var transitionEnd + + $(document).ready(function () { + + $.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 + })() + + // set CSS transition event type + if ( $.support.transition ) { + transitionEnd = "TransitionEnd" + if ( $.browser.webkit ) { + transitionEnd = "webkitTransitionEnd" + } else if ( $.browser.mozilla ) { + transitionEnd = "transitionend" + } else if ( $.browser.opera ) { + transitionEnd = "oTransitionEnd" + } + } + + }) /* ALERT CLASS DEFINITION * ====================== */ - function close(e) { - var $element = $(this).parent('.alert-message') + var Alert = function ( content, options ) { + if (options == 'close') return this.close.call(content) + this.settings = $.extend({}, $.fn.alert.defaults, options) + this.$element = $(content) + .delegate(this.settings.selector, 'click', this.close) + } + + Alert.prototype = { + + close: function (e) { + var $element = $(this) + , className = 'alert-message' + + $element = $element.hasClass(className) ? $element : $element.parent() + + e && e.preventDefault() + $element.removeClass('in') - e && e.preventDefault() - $element.removeClass('in') + function removeElement () { + $element.remove() + } - function removeElement () { - $element.remove() + $.support.transition && $element.hasClass('fade') ? + $element.bind(transitionEnd, removeElement) : + removeElement() } - $.support.transition && $element.hasClass('fade') ? - $element.bind($.support.transition.end, removeElement) : - removeElement() } /* ALERT PLUGIN DEFINITION * ======================= */ - $(function () { - $('body').delegate('[data-alert-dismiss]', 'click', close) + $.fn.alert = function ( options ) { + + if ( options === true ) { + return this.data('alert') + } + + return this.each(function () { + var $this = $(this) + , data + + if ( typeof options == 'string' ) { + + data = $this.data('alert') + + if (typeof data == 'object') { + return data[options].call( $this ) + } + + } + + $(this).data('alert', new Alert( this, options )) + + }) + } + + $.fn.alert.defaults = { + selector: '.close' + } + + $(document).ready(function () { + new Alert($('body'), { + selector: '.alert-message[data-alert] .close' + }) }) -})( window.jQuery || window.ender ) \ No newline at end of file +}( window.jQuery || window.ender ); \ No newline at end of file diff --git a/js/bootstrap-buttons.js b/js/bootstrap-buttons.js new file mode 100644 index 000000000..16fa161cb --- /dev/null +++ b/js/bootstrap-buttons.js @@ -0,0 +1,62 @@ +/* ============================================================ + * bootstrap-buttons.js v1.4.0 + * http://twitter.github.com/bootstrap/javascript.html#buttons + * ============================================================ + * 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( $ ){ + + "use strict" + + function setState(el, state) { + var d = 'disabled' + , $el = $(el) + , data = $el.data() + + state = state + 'Text' + data.resetText || $el.data('resetText', $el.html()) + + $el.html( data[state] || $.fn.button.defaults[state] ) + + state == 'loadingText' ? + $el.addClass(d).attr(d, d) : + $el.removeClass(d).removeAttr(d) + } + + function toggle(el) { + $(el).toggleClass('active') + } + + $.fn.button = function(options) { + return this.each(function () { + if (options == 'toggle') { + return toggle(this) + } + options && setState(this, options) + }) + } + + $.fn.button.defaults = { + loadingText: 'loading...' + } + + $(function () { + $('body').delegate('.btn[data-toggle]', 'click', function () { + $(this).button('toggle') + }) + }) + +}( window.jQuery || window.ender ); \ No newline at end of file diff --git a/js/bootstrap-dropdown.js b/js/bootstrap-dropdown.js index d12fe48cb..cab0ec27e 100644 --- a/js/bootstrap-dropdown.js +++ b/js/bootstrap-dropdown.js @@ -1,5 +1,5 @@ /* ============================================================ - * bootstrap-dropdown.js v2.0.0 + * bootstrap-dropdown.js v1.4.0 * http://twitter.github.com/bootstrap/javascript.html#dropdown * ============================================================ * Copyright 2011 Twitter, Inc. @@ -18,25 +18,38 @@ * ============================================================ */ -(function( $ ){ +!function( $ ){ + + "use strict" + + /* DROPDOWN PLUGIN DEFINITION + * ========================== */ + + $.fn.dropdown = function ( selector ) { + return this.each(function () { + $(this).delegate(selector || d, 'click', function (e) { + var li = $(this).parent('li') + , isActive = li.hasClass('open') + + clearMenus() + !isActive && li.toggleClass('open') + return false + }) + }) + } /* APPLY TO STANDARD DROPDOWN ELEMENTS * =================================== */ - var selector = '[data-dropdown]' + + var d = 'a.menu, .dropdown-toggle' function clearMenus() { - $(selector).parent('li').removeClass('open') + $(d).parent('li').removeClass('open') } $(function () { $('html').bind("click", clearMenus) - $('body').delegate(selector, 'click', function (e) { - var li = $(this).parent('li') - , isActive = li.hasClass('open') - clearMenus() - !isActive && li.toggleClass('open') - return false - }) + $('body').dropdown( '[data-dropdown] a.menu, [data-dropdown] .dropdown-toggle' ) }) -})( window.jQuery || window.ender ) \ No newline at end of file +}( window.jQuery || window.ender ); \ No newline at end of file diff --git a/js/bootstrap-modal.js b/js/bootstrap-modal.js index 984b091d6..be2315afb 100644 --- a/js/bootstrap-modal.js +++ b/js/bootstrap-modal.js @@ -1,5 +1,5 @@ /* ========================================================= - * bootstrap-modal.js v2.0.0 + * bootstrap-modal.js v1.4.0 * http://twitter.github.com/bootstrap/javascript.html#modal * ========================================================= * Copyright 2011 Twitter, Inc. @@ -20,13 +20,44 @@ !function( $ ){ + "use strict" + + /* CSS TRANSITION SUPPORT (https://gist.github.com/373874) + * ======================================================= */ + + var transitionEnd + + $(document).ready(function () { + + $.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 + })() + + // set CSS transition event type + if ( $.support.transition ) { + transitionEnd = "TransitionEnd" + if ( $.browser.webkit ) { + transitionEnd = "webkitTransitionEnd" + } else if ( $.browser.mozilla ) { + transitionEnd = "transitionend" + } else if ( $.browser.opera ) { + transitionEnd = "oTransitionEnd" + } + } + + }) + + /* MODAL PUBLIC CLASS DEFINITION * ============================= */ var Modal = function ( content, options ) { this.settings = $.extend({}, $.fn.modal.defaults, options) this.$element = $(content) - .delegate('[data-modal-dismiss]', 'click', $.proxy(this.hide, this)) + .delegate('.close', 'click.modal', $.proxy(this.hide, this)) if ( this.settings.show ) { this.show() @@ -47,7 +78,24 @@ this.$element.trigger('show') escape.call(this) - backdrop.call(this) + backdrop.call(this, function () { + var transition = $.support.transition && that.$element.hasClass('fade') + + that.$element + .appendTo(document.body) + .show() + + if (transition) { + that.$element[0].offsetWidth // force reflow + } + + that.$element.addClass('in') + + transition ? + that.$element.one(transitionEnd, function () { that.$element.trigger('shown') }) : + that.$element.trigger('shown') + + }) return this } @@ -68,17 +116,9 @@ .trigger('hide') .removeClass('in') - function removeElement () { - that.$element - .hide() - .trigger('hidden') - - backdrop.call(that) - } - $.support.transition && this.$element.hasClass('fade') ? - this.$element.one($.support.transition.end, removeElement) : - removeElement() + hideWithTransition.call(this) : + hideModal.call(this) return this } @@ -89,11 +129,31 @@ /* MODAL PRIVATE METHODS * ===================== */ - function backdrop () { + function hideWithTransition() { + // firefox drops transitionEnd events :{o var that = this - , animate = this.$element.hasClass('fade') ? 'fade' : '' - , callback = $.proxy(show, this) + , timeout = setTimeout(function () { + that.$element.unbind(transitionEnd) + hideModal.call(that) + }, 500) + + this.$element.one(transitionEnd, function () { + clearTimeout(timeout) + hideModal.call(that) + }) + } + + function hideModal (that) { + this.$element + .hide() + .trigger('hidden') + + backdrop.call(this) + } + function backdrop ( callback ) { + var that = this + , animate = this.$element.hasClass('fade') ? 'fade' : '' if ( this.isShown && this.settings.backdrop ) { var doAnimate = $.support.transition && animate @@ -111,43 +171,24 @@ this.$backdrop.addClass('in') doAnimate ? - this.$backdrop.one($.support.transition.end, callback) : + this.$backdrop.one(transitionEnd, callback) : callback() } else if ( !this.isShown && this.$backdrop ) { this.$backdrop.removeClass('in') - function removeElement() { - that.$backdrop.remove() - that.$backdrop = null - } - $.support.transition && this.$element.hasClass('fade')? - this.$backdrop.one($.support.transition.end, removeElement) : - removeElement() + this.$backdrop.one(transitionEnd, $.proxy(removeBackdrop, this)) : + removeBackdrop.call(this) + } else if ( callback ) { callback() } } - function show() { - var transition = $.support.transition && that.$element.hasClass('fade') - , that = this - - this.$element - .appendTo(document.body) - .show() - - if (transition) { - this.$element[0].offsetWidth // force reflow - } - - this.$element - .addClass('in') - - transition ? - this.$element.one($.support.transition.end, function () { that.$element.trigger('shown') }) : - this.$element.trigger('shown') + function removeBackdrop() { + this.$backdrop.remove() + this.$backdrop = null } function escape() { @@ -205,10 +246,10 @@ } - /* MODAL DATA-IMPLEMENTATION - * ========================= */ + /* MODAL DATA- IMPLEMENTATION + * ========================== */ - $(function () { + $(document).ready(function () { $('body').delegate('[data-controls-modal]', 'click', function (e) { e.preventDefault() var $this = $(this).data('show', true) diff --git a/js/bootstrap-popover.js b/js/bootstrap-popover.js index 3fdde19b5..c23741735 100644 --- a/js/bootstrap-popover.js +++ b/js/bootstrap-popover.js @@ -1,5 +1,5 @@ /* =========================================================== - * bootstrap-popover.js v2.0.0 + * bootstrap-popover.js v1.4.0 * http://twitter.github.com/bootstrap/javascript.html#popover * =========================================================== * Copyright 2011 Twitter, Inc. @@ -20,6 +20,8 @@ !function( $ ) { + "use strict" + var Popover = function ( element, options ) { this.$element = $(element) this.options = options @@ -35,33 +37,39 @@ 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.find('.content > *')[this.options.html ? 'html' : 'text'](this.getContent()) $tip[0].className = 'popover' } + , hasContent: function () { + return this.getTitle() || this.getContent() + } + , getContent: function () { var content , $e = this.$element , o = this.options if (typeof this.options.content == 'string') { - content = $e.attr(o.content) + content = $e.attr(this.options.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 = $('
') - .html('

') + .html(this.options.template) } return this.$tip } }) + /* POPOVER PLUGIN DEFINITION * ======================= */ @@ -71,6 +79,12 @@ return this } - $.fn.popover.defaults = $.extend({} , $.fn.twipsy.defaults, { content: 'data-content', placement: 'right'}) + $.fn.popover.defaults = $.extend({} , $.fn.twipsy.defaults, { + placement: 'right' + , content: 'data-content' + , template: '

' + }) + + $.fn.twipsy.rejectAttrOptions.push( 'content' ) }( window.jQuery || window.ender ); \ No newline at end of file diff --git a/js/bootstrap-tabs.js b/js/bootstrap-tabs.js index 86bd4784f..790180ca2 100644 --- a/js/bootstrap-tabs.js +++ b/js/bootstrap-tabs.js @@ -1,5 +1,5 @@ /* ======================================================== - * bootstrap-tabs.js v2.0.0 + * bootstrap-tabs.js v1.4.0 * http://twitter.github.com/bootstrap/javascript.html#tabs * ======================================================== * Copyright 2011 Twitter, Inc. @@ -20,6 +20,8 @@ !function( $ ){ + "use strict" + function activate ( element, container ) { container .find('> .active') @@ -39,6 +41,7 @@ , $ul = $this.closest('ul:not(.dropdown-menu)') , href = $this.attr('href') , previous + , $href if ( /^#\w+/.test(href) ) { e.preventDefault() @@ -64,8 +67,14 @@ /* TABS/PILLS PLUGIN DEFINITION * ============================ */ - $(function () { - $('body').delegate('ul[data-tabs] > li > a, ul[data-pills] > li > a', 'click', tab) + $.fn.tabs = $.fn.pills = function ( selector ) { + return this.each(function () { + $(this).delegate(selector || '.tabs li > a, .pills > li > a', 'click', tab) + }) + } + + $(document).ready(function () { + $('body').tabs('ul[data-tabs] li > a, ul[data-pills] > li > a') }) }( window.jQuery || window.ender ); \ No newline at end of file diff --git a/js/bootstrap-twipsy.js b/js/bootstrap-twipsy.js index 7c195fbc7..fc22d0218 100644 --- a/js/bootstrap-twipsy.js +++ b/js/bootstrap-twipsy.js @@ -1,5 +1,5 @@ /* ========================================================== - * bootstrap-twipsy.js v2.0.0 + * bootstrap-twipsy.js v1.4.0 * http://twitter.github.com/bootstrap/javascript.html#twipsy * Adapted from the original jQuery.tipsy by Jason Frame * ========================================================== @@ -21,6 +21,37 @@ !function( $ ) { + "use strict" + + /* CSS TRANSITION SUPPORT (https://gist.github.com/373874) + * ======================================================= */ + + var transitionEnd + + $(document).ready(function () { + + $.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 + })() + + // set CSS transition event type + if ( $.support.transition ) { + transitionEnd = "TransitionEnd" + if ( $.browser.webkit ) { + transitionEnd = "webkitTransitionEnd" + } else if ( $.browser.mozilla ) { + transitionEnd = "transitionend" + } else if ( $.browser.opera ) { + transitionEnd = "oTransitionEnd" + } + } + + }) + + /* TWIPSY PUBLIC CLASS DEFINITION * ============================== */ @@ -41,7 +72,7 @@ , $tip , tp - if (this.getTitle() && this.enabled) { + if (this.hasContent() && this.enabled) { $tip = this.tip() this.setContent() @@ -61,7 +92,8 @@ actualWidth = $tip[0].offsetWidth actualHeight = $tip[0].offsetHeight - placement = _.maybeCall(this.options.placement, this.$element[0]) + + placement = maybeCall(this.options.placement, this, [ $tip[0], this.$element[0] ]) switch (placement) { case 'below': @@ -102,7 +134,7 @@ } $.support.transition && this.$tip.hasClass('fade') ? - $tip.bind($.support.transition.end, removeElement) : + $tip.bind(transitionEnd, removeElement) : removeElement() } @@ -113,6 +145,10 @@ } } + , hasContent: function () { + return this.getTitle() + } + , getTitle: function() { var title , $e = this.$element @@ -132,10 +168,7 @@ } , tip: function() { - if (!this.$tip) { - this.$tip = $('
').html('
') - } - return this.$tip + return this.$tip = this.$tip || $('
').html(this.options.template) } , validate: function() { @@ -158,21 +191,20 @@ this.enabled = !this.enabled } + , toggle: function () { + this[this.tip().hasClass('in') ? 'hide' : 'show']() + } + } /* TWIPSY PRIVATE METHODS * ====================== */ - var _ = { - - maybeCall: function ( thing, ctx ) { - return (typeof thing == 'function') ? (thing.call(ctx)) : thing - } - + function maybeCall ( thing, ctx, args ) { + return typeof thing == 'function' ? thing.apply(ctx, args) : thing } - /* TWIPSY PLUGIN DEFINITION * ======================== */ @@ -269,10 +301,21 @@ , offset: 0 , title: 'title' , trigger: 'hover' + , template: '
' } + $.fn.twipsy.rejectAttrOptions = [ 'title' ] + $.fn.twipsy.elementOptions = function(ele, options) { - return $.metadata ? $.extend({}, options, $(ele).metadata()) : 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 ); \ No newline at end of file -- cgit v1.2.3 From bc65b58551575c9dfb2e4d9f4f7af97009e39432 Mon Sep 17 00:00:00 2001 From: Jacob Thornton Date: Sun, 20 Nov 2011 20:58:04 -0800 Subject: merge in js from 1.4... start working through js docs --- js/bootstrap-alerts.js | 44 ++++------------------------- js/bootstrap-dropdown.js | 43 +++++++++++++++++----------- js/bootstrap-modal.js | 48 ++++++-------------------------- js/bootstrap-popover.js | 6 ++-- js/bootstrap-scrollspy.js | 33 +++++++++++----------- js/bootstrap-tabs.js | 2 +- js/bootstrap-transitions.js | 2 +- js/bootstrap-twipsy.js | 68 +++++++++++++-------------------------------- 8 files changed, 81 insertions(+), 165 deletions(-) (limited to 'js') diff --git a/js/bootstrap-alerts.js b/js/bootstrap-alerts.js index 3ef1672bc..600440e40 100644 --- a/js/bootstrap-alerts.js +++ b/js/bootstrap-alerts.js @@ -1,5 +1,5 @@ /* ========================================================== - * bootstrap-alerts.js v1.4.0 + * bootstrap-alerts.js v2.0.0 * http://twitter.github.com/bootstrap/javascript.html#alerts * ========================================================== * Copyright 2011 Twitter, Inc. @@ -22,34 +22,6 @@ "use strict" - /* CSS TRANSITION SUPPORT (https://gist.github.com/373874) - * ======================================================= */ - - var transitionEnd - - $(document).ready(function () { - - $.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 - })() - - // set CSS transition event type - if ( $.support.transition ) { - transitionEnd = "TransitionEnd" - if ( $.browser.webkit ) { - transitionEnd = "webkitTransitionEnd" - } else if ( $.browser.mozilla ) { - transitionEnd = "transitionend" - } else if ( $.browser.opera ) { - transitionEnd = "oTransitionEnd" - } - } - - }) - /* ALERT CLASS DEFINITION * ====================== */ @@ -76,7 +48,7 @@ } $.support.transition && $element.hasClass('fade') ? - $element.bind(transitionEnd, removeElement) : + $element.bind($.support.transition.end, removeElement) : removeElement() } @@ -88,10 +60,6 @@ $.fn.alert = function ( options ) { - if ( options === true ) { - return this.data('alert') - } - return this.each(function () { var $this = $(this) , data @@ -112,13 +80,11 @@ } $.fn.alert.defaults = { - selector: '.close' + selector: '[data-dismiss="alert"]' } - $(document).ready(function () { - new Alert($('body'), { - selector: '.alert-message[data-alert] .close' - }) + $(function () { + new Alert( $('body') ) }) }( window.jQuery || window.ender ); \ No newline at end of file diff --git a/js/bootstrap-dropdown.js b/js/bootstrap-dropdown.js index cab0ec27e..bb7d11b1f 100644 --- a/js/bootstrap-dropdown.js +++ b/js/bootstrap-dropdown.js @@ -1,5 +1,5 @@ /* ============================================================ - * bootstrap-dropdown.js v1.4.0 + * bootstrap-dropdown.js v2.0.0 * http://twitter.github.com/bootstrap/javascript.html#dropdown * ============================================================ * Copyright 2011 Twitter, Inc. @@ -22,34 +22,45 @@ "use strict" + /* SIMPLE DROPDOWN LOGIC + * ===================== */ + + var s = '[data-toggle="dropdown"]' + + function clearMenus() { + $(s).parent('li').removeClass('open') + } + + function toggle(e) { + var li = $(this).parent('li') + , isActive = li.hasClass('open') + + clearMenus() + !isActive && li.toggleClass('open') + + return false + } + + /* DROPDOWN PLUGIN DEFINITION * ========================== */ $.fn.dropdown = function ( selector ) { return this.each(function () { - $(this).delegate(selector || d, 'click', function (e) { - var li = $(this).parent('li') - , isActive = li.hasClass('open') - - clearMenus() - !isActive && li.toggleClass('open') - return false - }) + var args = ['click', toggle] + , $this = $(this) + selector && args.unshift(selector) + $this[selector ? 'delegate' : 'bind'].apply($this, args) }) } + /* APPLY TO STANDARD DROPDOWN ELEMENTS * =================================== */ - var d = 'a.menu, .dropdown-toggle' - - function clearMenus() { - $(d).parent('li').removeClass('open') - } - $(function () { $('html').bind("click", clearMenus) - $('body').dropdown( '[data-dropdown] a.menu, [data-dropdown] .dropdown-toggle' ) + $('body').dropdown(s) }) }( window.jQuery || window.ender ); \ No newline at end of file diff --git a/js/bootstrap-modal.js b/js/bootstrap-modal.js index be2315afb..ccc7b133b 100644 --- a/js/bootstrap-modal.js +++ b/js/bootstrap-modal.js @@ -22,35 +22,6 @@ "use strict" - /* CSS TRANSITION SUPPORT (https://gist.github.com/373874) - * ======================================================= */ - - var transitionEnd - - $(document).ready(function () { - - $.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 - })() - - // set CSS transition event type - if ( $.support.transition ) { - transitionEnd = "TransitionEnd" - if ( $.browser.webkit ) { - transitionEnd = "webkitTransitionEnd" - } else if ( $.browser.mozilla ) { - transitionEnd = "transitionend" - } else if ( $.browser.opera ) { - transitionEnd = "oTransitionEnd" - } - } - - }) - - /* MODAL PUBLIC CLASS DEFINITION * ============================= */ @@ -92,7 +63,7 @@ that.$element.addClass('in') transition ? - that.$element.one(transitionEnd, function () { that.$element.trigger('shown') }) : + that.$element.one($.support.transition.end, function () { that.$element.trigger('shown') }) : that.$element.trigger('shown') }) @@ -130,14 +101,13 @@ * ===================== */ function hideWithTransition() { - // firefox drops transitionEnd events :{o var that = this , timeout = setTimeout(function () { - that.$element.unbind(transitionEnd) + that.$element.unbind($.support.transition.end) hideModal.call(that) }, 500) - this.$element.one(transitionEnd, function () { + this.$element.one($.support.transition.end, function () { clearTimeout(timeout) hideModal.call(that) }) @@ -171,14 +141,14 @@ this.$backdrop.addClass('in') doAnimate ? - this.$backdrop.one(transitionEnd, callback) : + this.$backdrop.one($.support.transition.end, callback) : callback() } else if ( !this.isShown && this.$backdrop ) { this.$backdrop.removeClass('in') $.support.transition && this.$element.hasClass('fade')? - this.$backdrop.one(transitionEnd, $.proxy(removeBackdrop, this)) : + this.$backdrop.one($.support.transition.end, $.proxy(removeBackdrop, this)) : removeBackdrop.call(this) } else if ( callback ) { @@ -240,9 +210,9 @@ $.fn.modal.Modal = Modal $.fn.modal.defaults = { - backdrop: false - , keyboard: false - , show: false + backdrop: true + , keyboard: true + , show: true } @@ -252,7 +222,7 @@ $(document).ready(function () { $('body').delegate('[data-controls-modal]', 'click', function (e) { e.preventDefault() - var $this = $(this).data('show', true) + var $this = $(this) $('#' + $this.attr('data-controls-modal')).modal( $this.data() ) }) }) diff --git a/js/bootstrap-popover.js b/js/bootstrap-popover.js index c23741735..d0bd83131 100644 --- a/js/bootstrap-popover.js +++ b/js/bootstrap-popover.js @@ -1,5 +1,5 @@ /* =========================================================== - * bootstrap-popover.js v1.4.0 + * bootstrap-popover.js v2.0.0 * http://twitter.github.com/bootstrap/javascript.html#popover * =========================================================== * Copyright 2011 Twitter, Inc. @@ -36,8 +36,8 @@ setContent: function () { var $tip = this.tip() - $tip.find('.title')[this.options.html ? 'html' : 'text'](this.getTitle()) - $tip.find('.content > *')[this.options.html ? 'html' : 'text'](this.getContent()) + $tip.find('.title')['html'](this.getTitle()) + $tip.find('.content > *')['html'](this.getContent()) $tip[0].className = 'popover' } diff --git a/js/bootstrap-scrollspy.js b/js/bootstrap-scrollspy.js index 1269d91ec..91c2dcb1e 100644 --- a/js/bootstrap-scrollspy.js +++ b/js/bootstrap-scrollspy.js @@ -20,33 +20,34 @@ !function ( $ ) { - var $window = $(window) - function ScrollSpy() { var process = $.proxy(this.process, this) - this.$topbar = $('body') - this.selector = '[data-scrollspy] li > a' + this.selector = '.nav li > a' + + this.$body = $('body').delegate(this.selector, 'click', process) + this.$scrollElement = $('[data-spy="scroll"]').bind('scroll', process) + this.refresh() - this.$topbar.delegate(this.selector, 'click', process) - $window.scroll(process) this.process() } ScrollSpy.prototype = { refresh: function () { - this.targets = this.$topbar.find(this.selector).map(function () { - var href = $(this).attr('href') - return /^#\w/.test(href) && $(href).length ? href : null - }) + this.targets = this.$body + .find(this.selector) + .map(function () { + var href = $(this).attr('href') + return /^#\w/.test(href) && $(href).length ? href : null + }) this.offsets = $.map(this.targets, function (id) { - return $(id).offset().top + return $(id).position().top }) } , process: function () { - var scrollTop = $window.scrollTop() + 10 + var scrollTop = this.$scrollElement.scrollTop() + 10 , offsets = this.offsets , targets = this.targets , activeTarget = this.activeTarget @@ -65,11 +66,11 @@ this.activeTarget = target - this.$topbar + this.$body .find(this.selector).parent('.active') .removeClass('active') - active = this.$topbar + active = this.$body .find(this.selector + '[href="' + target + '"]') .parent('li') .addClass('active') @@ -82,8 +83,6 @@ } - $(function () { - new ScrollSpy() - }) + $(function () { new ScrollSpy() }) }( window.jQuery || window.ender ) \ No newline at end of file diff --git a/js/bootstrap-tabs.js b/js/bootstrap-tabs.js index 790180ca2..35418fd44 100644 --- a/js/bootstrap-tabs.js +++ b/js/bootstrap-tabs.js @@ -1,5 +1,5 @@ /* ======================================================== - * bootstrap-tabs.js v1.4.0 + * bootstrap-tabs.js v2.0.0 * http://twitter.github.com/bootstrap/javascript.html#tabs * ======================================================== * Copyright 2011 Twitter, Inc. diff --git a/js/bootstrap-transitions.js b/js/bootstrap-transitions.js index 49b5338a8..25f8b111f 100644 --- a/js/bootstrap-transitions.js +++ b/js/bootstrap-transitions.js @@ -38,7 +38,7 @@ $(function () { transitionEnd = "oTransitionEnd" } return transitionEnd - })() + }()) } })() diff --git a/js/bootstrap-twipsy.js b/js/bootstrap-twipsy.js index fc22d0218..19e43a723 100644 --- a/js/bootstrap-twipsy.js +++ b/js/bootstrap-twipsy.js @@ -1,5 +1,5 @@ /* ========================================================== - * bootstrap-twipsy.js v1.4.0 + * bootstrap-twipsy.js v2.0.0 * http://twitter.github.com/bootstrap/javascript.html#twipsy * Adapted from the original jQuery.tipsy by Jason Frame * ========================================================== @@ -18,40 +18,10 @@ * limitations under the License. * ========================================================== */ - !function( $ ) { "use strict" - /* CSS TRANSITION SUPPORT (https://gist.github.com/373874) - * ======================================================= */ - - var transitionEnd - - $(document).ready(function () { - - $.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 - })() - - // set CSS transition event type - if ( $.support.transition ) { - transitionEnd = "TransitionEnd" - if ( $.browser.webkit ) { - transitionEnd = "webkitTransitionEnd" - } else if ( $.browser.mozilla ) { - transitionEnd = "transitionend" - } else if ( $.browser.opera ) { - transitionEnd = "oTransitionEnd" - } - } - - }) - - /* TWIPSY PUBLIC CLASS DEFINITION * ============================== */ @@ -119,7 +89,7 @@ , setContent: function () { var $tip = this.tip() - $tip.find('.twipsy-inner')[this.options.html ? 'html' : 'text'](this.getTitle()) + $tip.find('.twipsy-inner').html(this.getTitle()) $tip[0].className = 'twipsy' } @@ -134,7 +104,7 @@ } $.support.transition && this.$tip.hasClass('fade') ? - $tip.bind(transitionEnd, removeElement) : + $tip.bind( $.support.transition.end, removeElement) : removeElement() } @@ -164,7 +134,7 @@ title = ('' + title).replace(/(^\s*|\s*$)/, "") - return title || o.fallback + return title } , tip: function() { @@ -219,18 +189,21 @@ , eventIn , eventOut - if (options === true) { - return this.data(name) - } else if (typeof options == 'string') { + if (typeof options == 'string') { twipsy = this.data(name) - if (twipsy) { - twipsy[options]() - } + if (twipsy) twipsy[options]() return this } 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) @@ -246,7 +219,7 @@ var twipsy = get(this) twipsy.hoverState = 'in' - if (options.delayIn == 0) { + if (!options.delay || !options.delay.show) { twipsy.show() } else { twipsy.fixTitle() @@ -254,21 +227,21 @@ if (twipsy.hoverState == 'in') { twipsy.show() } - }, options.delayIn) + }, options.delay.show) } } function leave() { var twipsy = get(this) twipsy.hoverState = 'out' - if (options.delayOut == 0) { + if (!options.delay || !options.delay.hide) { twipsy.hide() } else { setTimeout(function() { if (twipsy.hoverState == 'out') { twipsy.hide() } - }, options.delayOut) + }, options.delay.hide) } } @@ -292,15 +265,12 @@ $.fn.twipsy.defaults = { animate: true - , delayIn: 0 - , delayOut: 0 - , fallback: '' + , delay: 0 , placement: 'above' - , html: false , live: false , offset: 0 - , title: 'title' , trigger: 'hover' + , title: 'title' , template: '
' } -- cgit v1.2.3 From 8a891f2a7b9720845932c0be8853fc25c6e49eed Mon Sep 17 00:00:00 2001 From: Jacob Thornton Date: Sun, 20 Nov 2011 21:06:32 -0800 Subject: act on all twipsy instances --- js/bootstrap-twipsy.js | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) (limited to 'js') diff --git a/js/bootstrap-twipsy.js b/js/bootstrap-twipsy.js index 19e43a723..3cb9841c5 100644 --- a/js/bootstrap-twipsy.js +++ b/js/bootstrap-twipsy.js @@ -190,9 +190,10 @@ , eventOut if (typeof options == 'string') { - twipsy = this.data(name) - if (twipsy) twipsy[options]() - return this + return this.each(function (){ + twipsy = $.data(this, name) + if (twipsy) twipsy[options]() + }) } options = $.extend({}, $.fn[name].defaults, options) -- cgit v1.2.3 From 47c7f655ac455cf76a4865f129a523a91486d3ad Mon Sep 17 00:00:00 2001 From: Jacob Thornton Date: Sun, 20 Nov 2011 21:13:28 -0800 Subject: update comment numbers --- js/bootstrap-buttons.js | 2 +- js/bootstrap-modal.js | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) (limited to 'js') diff --git a/js/bootstrap-buttons.js b/js/bootstrap-buttons.js index 16fa161cb..2fe1a7352 100644 --- a/js/bootstrap-buttons.js +++ b/js/bootstrap-buttons.js @@ -1,5 +1,5 @@ /* ============================================================ - * bootstrap-buttons.js v1.4.0 + * bootstrap-buttons.js v2.0.0 * http://twitter.github.com/bootstrap/javascript.html#buttons * ============================================================ * Copyright 2011 Twitter, Inc. diff --git a/js/bootstrap-modal.js b/js/bootstrap-modal.js index ccc7b133b..e15b1237c 100644 --- a/js/bootstrap-modal.js +++ b/js/bootstrap-modal.js @@ -1,5 +1,5 @@ /* ========================================================= - * bootstrap-modal.js v1.4.0 + * bootstrap-modal.js v2.0.0 * http://twitter.github.com/bootstrap/javascript.html#modal * ========================================================= * Copyright 2011 Twitter, Inc. -- cgit v1.2.3 From 36a7eb3851855b608266f301a63b561ac316bca9 Mon Sep 17 00:00:00 2001 From: Jacob Thornton Date: Sun, 20 Nov 2011 21:36:26 -0800 Subject: add build script for minified files and allow elements to be returned to getContent and title in popovers --- js/bootstrap-popover.js | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) (limited to 'js') diff --git a/js/bootstrap-popover.js b/js/bootstrap-popover.js index d0bd83131..934ab0545 100644 --- a/js/bootstrap-popover.js +++ b/js/bootstrap-popover.js @@ -36,8 +36,12 @@ setContent: function () { var $tip = this.tip() - $tip.find('.title')['html'](this.getTitle()) - $tip.find('.content > *')['html'](this.getContent()) + , title = this.getTitle() + , content = this.getContent() + + $tip.find('.title')[ $.type(title) == 'object' ? 'append' : 'html' ](title) + $tip.find('.content > *')[ $.type(content) == 'object' ? 'append' : 'html' ](content) + $tip[0].className = 'popover' } -- cgit v1.2.3 From b2650859d6c6dcb0665311b6e983d230fee1111f Mon Sep 17 00:00:00 2001 From: Jacob Thornton Date: Thu, 24 Nov 2011 14:43:26 -0800 Subject: update buttons js for button groups --- js/bootstrap-buttons.js | 32 +++++++++++++++++++++----------- 1 file changed, 21 insertions(+), 11 deletions(-) (limited to 'js') diff --git a/js/bootstrap-buttons.js b/js/bootstrap-buttons.js index 2fe1a7352..759a65f84 100644 --- a/js/bootstrap-buttons.js +++ b/js/bootstrap-buttons.js @@ -25,26 +25,36 @@ var d = 'disabled' , $el = $(el) , data = $el.data() + , val = $el.is('input') ? 'val' : 'html' state = state + 'Text' - data.resetText || $el.data('resetText', $el.html()) + data.resetText || $el.data('resetText', $el[val]()) - $el.html( data[state] || $.fn.button.defaults[state] ) + $el[val]( data[state] || $.fn.button.defaults[state] ) - state == 'loadingText' ? - $el.addClass(d).attr(d, d) : - $el.removeClass(d).removeAttr(d) + setTimeout(function () { + state == 'loadingText' ? + $el.addClass(d).attr(d, d) : + $el.removeClass(d).removeAttr(d) + }, 0) } function toggle(el) { - $(el).toggleClass('active') + var $el = $(el) + , $parent = $el.parent('[data-toggle="buttons-radio"]') + + if ($parent) { + $parent + .find('.active') + .removeClass('active') + } + + $el.toggleClass('active') } $.fn.button = function(options) { return this.each(function () { - if (options == 'toggle') { - return toggle(this) - } + if (options == 'toggle') return toggle(this) options && setState(this, options) }) } @@ -54,8 +64,8 @@ } $(function () { - $('body').delegate('.btn[data-toggle]', 'click', function () { - $(this).button('toggle') + $('body').delegate('[data-toggle^=button]', 'click', function (e) { + $(e.srcElement).button('toggle') }) }) -- cgit v1.2.3 From 71654cbf69333c3cf6f0bb373121640c6f061d68 Mon Sep 17 00:00:00 2001 From: Jacob Thornton Date: Thu, 24 Nov 2011 18:55:44 -0800 Subject: refactor alerts + add new readme which idefientifies goals for 2.0 js --- js/README.md | 89 +++++++++++++++++++++++++++++++++++++++++++++ js/bootstrap-alerts.js | 45 ++++++++--------------- js/bootstrap-buttons.js | 25 ++++++++++--- js/bootstrap-collapsible.js | 37 +++++++++++++++++++ js/bootstrap-dropdown.js | 2 +- js/bootstrap-modal.js | 6 +-- 6 files changed, 163 insertions(+), 41 deletions(-) create mode 100644 js/README.md create mode 100644 js/bootstrap-collapsible.js (limited to 'js') diff --git a/js/README.md b/js/README.md new file mode 100644 index 000000000..98be75421 --- /dev/null +++ b/js/README.md @@ -0,0 +1,89 @@ +2.0 BOOTSTRAP JS PHILSOPHY +These are the highlevel design rules which guide the developement of Bootstrap's js plugins. + +--- + +### DATA-ATTRIBUTE API + +We believe you should be able to use all plugins provided by bootstrap purely through the markup api without writing a single line of javascript. + +We acknoledge that this isn't always the most performant and sometimes it may be desirable to turn this functionality off altogether. Therefore, as of 2.0 we provide the ability to disable the data attribute api by unbinding all events on the body namespaced with `'data-api'`. This looks like this: + + $('body').unbind('.data-api') + +To target a specific plugin, just include the plugins name as a namespace along with the data-api namespace like this: + + $('body').unbind('.alert.data-api') + +--- + +### PROGRAMATIC API + +We also believe you should be able to use all plugins provided by bootstrap purely through the JS api. + +All pubilc APIs should be a single, chainable method, and return the collection acted upon. + + $(".btn.danger").button("toggle").addClass("fat") + +All methods should accept an optional options object, a string which targets a particular method, or null which innitiates the default behavior: + + $("#myModal").modal() // initialized with defaults + +--- + +### PLUGIN OPTIONS + +Options should be sparse and add universal value. We should pick the right defaults. + +All plugins should have a default object which can be modified to effect all instance's default options. The defaults object should be available via `$.fn.plugin.defaults`. + + $.fn.modal.defaults = { … } + +An options definiton should take the following form: + + *noun*: *adjective* - describes or modifies a quality of an instance + +examples: + + backdrop: true + keyboard: false + placement: 'above' + +--- + +### PLUGIN EVENTS + +All events should have an infinitive and past participle form. The infinitive is fired just before an action takes place, the past participle on completion of the action. + + show | shown + hide | hidden + change | changed + +--- + + +### DATA ATTRIBUTES + +Data attributes should take the following form: + +data-*(verb)* - defines main interaction +data-target - defined on controller element (if element interacts with an element other than self) +data-*(noun)* - defines options for element invocation + +examples: + + // control other targets + data-toggle="modal" data-target="#foo" + data-toggle="view" data-target="#foo" + + // defined on element they control + data-spy="scroll" + + data-dismiss="modal" + data-dismiss="alert" + + data-toggle="dropdown" + + data-toggle="button" + data-toggle="buttons-checkbox" + data-toggle="buttons-radio" \ No newline at end of file diff --git a/js/bootstrap-alerts.js b/js/bootstrap-alerts.js index 600440e40..565f83193 100644 --- a/js/bootstrap-alerts.js +++ b/js/bootstrap-alerts.js @@ -25,25 +25,22 @@ /* ALERT CLASS DEFINITION * ====================== */ - var Alert = function ( content, options ) { - if (options == 'close') return this.close.call(content) - this.settings = $.extend({}, $.fn.alert.defaults, options) - this.$element = $(content) - .delegate(this.settings.selector, 'click', this.close) - } + var dismiss = '[data-dismiss="alert"]' + , Alert = function ( el, close ) { + $(el).delegate(dismiss, 'click', this.close) + } Alert.prototype = { - close: function (e) { + close: function ( e ) { var $element = $(this) - , className = 'alert-message' - $element = $element.hasClass(className) ? $element : $element.parent() + $element = $element.hasClass('alert-message') ? $element : $element.parent() e && e.preventDefault() $element.removeClass('in') - function removeElement () { + function removeElement() { $element.remove() } @@ -59,32 +56,22 @@ * ======================= */ $.fn.alert = function ( options ) { - return this.each(function () { var $this = $(this) - , data - - if ( typeof options == 'string' ) { - - data = $this.data('alert') - - if (typeof data == 'object') { - return data[options].call( $this ) - } - - } - - $(this).data('alert', new Alert( this, options )) - + , data = $this.data('alert') + if (!data) $this.data('alert', (data = new Alert(this))) + if (typeof options == 'string') data[options].call($this) }) } - $.fn.alert.defaults = { - selector: '[data-dismiss="alert"]' - } + $.fn.alert.Alert = Alert + + + /* ALERT DATA-API + * ============== */ $(function () { - new Alert( $('body') ) + $('body').delegate(dismiss, 'click.alert.data-api', Alert.prototype.close) }) }( window.jQuery || window.ender ); \ No newline at end of file diff --git a/js/bootstrap-buttons.js b/js/bootstrap-buttons.js index 759a65f84..5ca678df8 100644 --- a/js/bootstrap-buttons.js +++ b/js/bootstrap-buttons.js @@ -21,6 +21,11 @@ "use strict" + /* BUTTON PUBLIC CLASS DEFINITION + * ============================== */ + + var Button + function setState(el, state) { var d = 'disabled' , $el = $(el) @@ -43,15 +48,17 @@ var $el = $(el) , $parent = $el.parent('[data-toggle="buttons-radio"]') - if ($parent) { - $parent - .find('.active') - .removeClass('active') - } + $parent && $parent + .find('.active') + .removeClass('active') $el.toggleClass('active') } + + /* BUTTON PLUGIN DEFINITION + * ======================== */ + $.fn.button = function(options) { return this.each(function () { if (options == 'toggle') return toggle(this) @@ -63,8 +70,14 @@ loadingText: 'loading...' } + $.fn.button.Button = Button + + + /* BUTTON DATA-API + * =============== */ + $(function () { - $('body').delegate('[data-toggle^=button]', 'click', function (e) { + $('body').delegate('[data-toggle^=button]', 'click.button.data-api', function (e) { $(e.srcElement).button('toggle') }) }) diff --git a/js/bootstrap-collapsible.js b/js/bootstrap-collapsible.js new file mode 100644 index 000000000..273eb2272 --- /dev/null +++ b/js/bootstrap-collapsible.js @@ -0,0 +1,37 @@ +/* ============================================================= + * bootstrap-collapsible.js v2.0.0 + * http://twitter.github.com/bootstrap/javascript.html#collapsible + * ============================================================= + * 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( $ ){ + + var Collapsible = function ( element, options ) {} + + Collapsible.prototype = {} + + /* collapsible PLUGIN DEFINITION + * ======================= */ + + $.fn.collapsible = function ( options ) { + + return this.each(function () { + new Collapsible(this, options) + }) + } + + +})( window.jQuery || window.ender ) \ No newline at end of file diff --git a/js/bootstrap-dropdown.js b/js/bootstrap-dropdown.js index bb7d11b1f..ef243fc6f 100644 --- a/js/bootstrap-dropdown.js +++ b/js/bootstrap-dropdown.js @@ -59,7 +59,7 @@ * =================================== */ $(function () { - $('html').bind("click", clearMenus) + $('html').bind("click.dropdown.data-api", clearMenus) $('body').dropdown(s) }) diff --git a/js/bootstrap-modal.js b/js/bootstrap-modal.js index e15b1237c..16c805a4e 100644 --- a/js/bootstrap-modal.js +++ b/js/bootstrap-modal.js @@ -194,10 +194,6 @@ }) } - if ( options === true ) { - return modal - } - if ( typeof options == 'string' ) { modal[options]() } else if ( modal ) { @@ -220,7 +216,7 @@ * ========================== */ $(document).ready(function () { - $('body').delegate('[data-controls-modal]', 'click', function (e) { + $('body').delegate('[data-controls-modal]', 'click.modal.data-api', function (e) { e.preventDefault() var $this = $(this) $('#' + $this.attr('data-controls-modal')).modal( $this.data() ) -- cgit v1.2.3 From 69372701cfe58876623c89a0bdeca5ce91dd839b Mon Sep 17 00:00:00 2001 From: Jacob Thornton Date: Thu, 24 Nov 2011 19:40:25 -0800 Subject: refactor dropdown in accordance with readme --- js/bootstrap-accordion.js | 41 ------------------------------- js/bootstrap-alerts.js | 7 +++--- js/bootstrap-buttons.js | 61 ++++++++++++++++++++++++++++------------------- js/bootstrap-dropdown.js | 45 +++++++++++++++++++--------------- 4 files changed, 65 insertions(+), 89 deletions(-) delete mode 100644 js/bootstrap-accordion.js (limited to 'js') diff --git a/js/bootstrap-accordion.js b/js/bootstrap-accordion.js deleted file mode 100644 index 9a24b5ddf..000000000 --- a/js/bootstrap-accordion.js +++ /dev/null @@ -1,41 +0,0 @@ -/* ============================================================= - * bootstrap-accordion.js v2.0.0 - * http://twitter.github.com/bootstrap/javascript.html#accordion - * ============================================================= - * 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( $ ){ - - var Accordion = function ( element, options ) {} - - Accordion.prototype = {} - - /* ALERT PLUGIN DEFINITION - * ======================= */ - - $.fn.accordion = function ( options ) { - - if ( options === true ) { - return this.data('accordion') - } - - return this.each(function () { - new Accordion(this, options) - }) - } - - -})( window.jQuery || window.ender ) \ No newline at end of file diff --git a/js/bootstrap-alerts.js b/js/bootstrap-alerts.js index 565f83193..fabafa4f9 100644 --- a/js/bootstrap-alerts.js +++ b/js/bootstrap-alerts.js @@ -26,7 +26,7 @@ * ====================== */ var dismiss = '[data-dismiss="alert"]' - , Alert = function ( el, close ) { + , Alert = function ( el ) { $(el).delegate(dismiss, 'click', this.close) } @@ -36,7 +36,6 @@ var $element = $(this) $element = $element.hasClass('alert-message') ? $element : $element.parent() - e && e.preventDefault() $element.removeClass('in') @@ -55,12 +54,12 @@ /* ALERT PLUGIN DEFINITION * ======================= */ - $.fn.alert = function ( options ) { + $.fn.alert = function ( option ) { return this.each(function () { var $this = $(this) , data = $this.data('alert') if (!data) $this.data('alert', (data = new Alert(this))) - if (typeof options == 'string') data[options].call($this) + if (typeof option == 'string') data[option].call($this) }) } diff --git a/js/bootstrap-buttons.js b/js/bootstrap-buttons.js index 5ca678df8..82d80df2d 100644 --- a/js/bootstrap-buttons.js +++ b/js/bootstrap-buttons.js @@ -24,45 +24,56 @@ /* BUTTON PUBLIC CLASS DEFINITION * ============================== */ - var Button + var Button = function (element, options) { + this.$element = $(element) + this.settings = $.extend({}, $.fn.button.defaults, options) + } - function setState(el, state) { - var d = 'disabled' - , $el = $(el) - , data = $el.data() - , val = $el.is('input') ? 'val' : 'html' + Button.prototype = { - state = state + 'Text' - data.resetText || $el.data('resetText', $el[val]()) + setState: function (state) { + var d = 'disabled' + , $el = this.$element + , data = $el.data() + , val = $el.is('input') ? 'val' : 'html' - $el[val]( data[state] || $.fn.button.defaults[state] ) + state = state + 'Text' + data.resetText || $el.data('resetText', $el[val]()) - setTimeout(function () { - state == 'loadingText' ? - $el.addClass(d).attr(d, d) : - $el.removeClass(d).removeAttr(d) - }, 0) - } + $el[val](data[state] || this.settings[state]) + + // push to event loop to allow forms to submit + setTimeout(function () { + state == 'loadingText' ? + $el.addClass(d).attr(d, d) : + $el.removeClass(d).removeAttr(d) + }, 0) + } + + , toggle: function () { + var $parent = this.$element.parent('[data-toggle="buttons-radio"]') - function toggle(el) { - var $el = $(el) - , $parent = $el.parent('[data-toggle="buttons-radio"]') + $parent && $parent + .find('.active') + .removeClass('active') - $parent && $parent - .find('.active') - .removeClass('active') + this.$element.toggleClass('active') + } - $el.toggleClass('active') } /* BUTTON PLUGIN DEFINITION * ======================== */ - $.fn.button = function(options) { + $.fn.button = function ( option ) { return this.each(function () { - if (options == 'toggle') return toggle(this) - options && setState(this, options) + var $this = $(this) + , data = $this.data('button') + , options = typeof option == 'object' && option + if (!data) $this.data('button', (data = new Button(this, options))) + if (option == 'toggle') data.toggle() + else if (option) data.setState(option) }) } diff --git a/js/bootstrap-dropdown.js b/js/bootstrap-dropdown.js index ef243fc6f..4526a9203 100644 --- a/js/bootstrap-dropdown.js +++ b/js/bootstrap-dropdown.js @@ -22,35 +22,42 @@ "use strict" - /* SIMPLE DROPDOWN LOGIC - * ===================== */ + /* DROPDOWN CLASS DEFINITION + * ========================= */ - var s = '[data-toggle="dropdown"]' + var toggle = '[data-toggle="dropdown"]' + , Dropdown = function ( element ) { + $(element).bind('click', this.toggle) + } - function clearMenus() { - $(s).parent('li').removeClass('open') - } + Dropdown.prototype = { + + toggle: function ( e ) { + var li = $(this).parent('li') + , isActive = li.hasClass('open') - function toggle(e) { - var li = $(this).parent('li') - , isActive = li.hasClass('open') + clearMenus() + !isActive && li.toggleClass('open') - clearMenus() - !isActive && li.toggleClass('open') + return false + } - return false + } + + function clearMenus() { + $(toggle).parent('li').removeClass('open') } /* DROPDOWN PLUGIN DEFINITION * ========================== */ - $.fn.dropdown = function ( selector ) { + $.fn.dropdown = function ( option ) { return this.each(function () { - var args = ['click', toggle] - , $this = $(this) - selector && args.unshift(selector) - $this[selector ? 'delegate' : 'bind'].apply($this, args) + var $this = $(this) + , data = $this.data('dropdown') + if (!data) $this.data('dropdown', (data = new Dropdown(this))) + if (typeof option == 'string') data[option].call($this) }) } @@ -59,8 +66,8 @@ * =================================== */ $(function () { - $('html').bind("click.dropdown.data-api", clearMenus) - $('body').dropdown(s) + $('html').bind('click.dropdown.data-api', clearMenus) + $('body').delegate(toggle, 'click.dropdown.data-api', Dropdown.prototype.toggle) }) }( window.jQuery || window.ender ); \ No newline at end of file -- cgit v1.2.3 From 1fa02fbda2bb3710a9f26a487da2c34565e8c406 Mon Sep 17 00:00:00 2001 From: Jacob Thornton Date: Thu, 24 Nov 2011 20:04:07 -0800 Subject: refactor modal --- js/bootstrap-modal.js | 104 +++++++++++++++++++------------------------------- 1 file changed, 39 insertions(+), 65 deletions(-) (limited to 'js') diff --git a/js/bootstrap-modal.js b/js/bootstrap-modal.js index 16c805a4e..14c03e6a3 100644 --- a/js/bootstrap-modal.js +++ b/js/bootstrap-modal.js @@ -22,19 +22,14 @@ "use strict" - /* MODAL PUBLIC CLASS DEFINITION - * ============================= */ + /* MODAL CLASS DEFINITION + * ====================== */ var Modal = function ( content, options ) { this.settings = $.extend({}, $.fn.modal.defaults, options) this.$element = $(content) - .delegate('.close', 'click.modal', $.proxy(this.hide, this)) - - if ( this.settings.show ) { - this.show() - } - - return this + .delegate('[data-dismiss="modal"]', 'click.dismiss.modal', $.proxy(this.hide, this)) + this.settings.show && this.show() } Modal.prototype = { @@ -45,6 +40,9 @@ , show: function () { var that = this + + if (this.isShown) return + this.isShown = true this.$element.trigger('show') @@ -67,16 +65,12 @@ that.$element.trigger('shown') }) - - return this } - , hide: function (e) { + , hide: function ( e ) { e && e.preventDefault() - if ( !this.isShown ) { - return this - } + if (!this.isShown) return var that = this this.isShown = false @@ -90,8 +84,6 @@ $.support.transition && this.$element.hasClass('fade') ? hideWithTransition.call(this) : hideModal.call(this) - - return this } } @@ -124,19 +116,18 @@ function backdrop ( callback ) { var that = this , animate = this.$element.hasClass('fade') ? 'fade' : '' - if ( this.isShown && this.settings.backdrop ) { + + if (this.isShown && this.settings.backdrop) { var doAnimate = $.support.transition && animate this.$backdrop = $('